Skip to content

Commit

Permalink
Merge pull request #48 from dominant-strategies/qi-quai-conversion
Browse files Browse the repository at this point in the history
Qi quai conversion
  • Loading branch information
Denis2626 authored Mar 14, 2024
2 parents 7c6e187 + 9dea34e commit f81cfab
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,21 @@ export type PerformActionRequest = {
method: "getTransactionResult",
hash: string
} | {

method: "getRunningLocations"
} | {
method: "getProtocolTrieExpansionCount"
} | {
method: "getQiRateAtBlock",
blockTag: BlockTag
amt: number
} | {
method: "getQuaiRateAtBlock",
blockTag: BlockTag,
amt: number
};


type _PerformAccountRequest = {
method: "getBalance" | "getTransactionCount" | "getCode"
} | {
Expand Down Expand Up @@ -506,6 +516,42 @@ export class AbstractProvider implements Provider {
this.#disableCcipRead = false;
}

async getLatestQuaiRate(amt: number = 1): Promise<bigint> {
const blockNumber = await this.getBlockNumber();
return this.getQuaiRateAtBlock(blockNumber, amt);
}

async getQuaiRateAtBlock(blockTag: BlockTag, amt: number = 1): Promise<bigint> {
let resolvedBlockTag = this._getBlockTag(blockTag);
if (typeof resolvedBlockTag !== "string") {
resolvedBlockTag = await resolvedBlockTag;
}

return await this.#perform({
method: "getQuaiRateAtBlock",
blockTag: resolvedBlockTag,
amt
});
}

async getLatestQiRate(amt: number = 1): Promise<bigint> {
const blockNumber = await this.getBlockNumber();
return this.getQiRateAtBlock(blockNumber, amt);
}

async getQiRateAtBlock(blockTag: BlockTag, amt: number = 1): Promise<bigint> {
let resolvedBlockTag = this._getBlockTag(blockTag);
if (typeof resolvedBlockTag !== "string") {
resolvedBlockTag = await resolvedBlockTag;
}

return await this.#perform({
method: "getQiRateAtBlock",
blockTag: resolvedBlockTag,
amt
});
}

get pollingInterval(): number { return this.#options.pollingInterval; }

/**
Expand Down
15 changes: 15 additions & 0 deletions src.ts/providers/provider-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type { Networkish } from "./network.js";
import type { Provider, TransactionRequest, TransactionResponse } from "./provider.js";
import type { Signer } from "./signer.js";


type Timer = ReturnType<typeof setTimeout>;

const Primitive = "bigint,boolean,function,number,string,symbol".split(/,/g);
Expand Down Expand Up @@ -936,6 +937,20 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
}
}

case "getQiRateAtBlock": {
return {
method: "quai_qiRateAtBlock",
args: [ req.blockTag, req.amt ]
}
}

case "getQuaiRateAtBlock": {
return {
method: "quai_quaiRateAtBlock",
args: [ req.blockTag, req.amt ]
}
}

case "getLogs":
if (req.filter && req.filter.address != null) {
if (Array.isArray(req.filter.address)) {
Expand Down

0 comments on commit f81cfab

Please sign in to comment.