Skip to content

Commit

Permalink
Helpers: Implement GetToken(Price|Decimals) for Web3 and TON
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbkmr committed Jun 24, 2024
1 parent b2b26c7 commit 0a26676
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ export interface GetEstimatedTime {
export interface GetBridgeAddress {
bridge: () => Promise<string>;
}

export interface GetTokenPrice {
getTokenPrice: (symbol: string) => Promise<bigint>;
}

export interface GetTokenPriceDecimals {
getPriceDecimals: (symbol: string) => Promise<bigint>;
}
12 changes: 11 additions & 1 deletion src/chains/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import type {
GetProtocolFeeInUSD,
GetProvider,
GetTokenBalance,
GetTokenPrice,
GetTokenPriceDecimals,
GetTxFee,
NativeCoinName,
ProtocolFee,
Expand Down Expand Up @@ -49,7 +51,9 @@ export type TonHelper = GetBalance &
TokenInfo &
GetEstimatedTime &
GetBridgeAddress &
GetProtocolFeeInUSD;
GetProtocolFeeInUSD &
GetTokenPrice &
GetTokenPriceDecimals;

export interface TonParams {
client: TonClient;
Expand Down Expand Up @@ -247,6 +251,12 @@ export function tonHandler({

return {
estimateTime: () => Promise.resolve(undefined),
async getPriceDecimals(_) {
return 0n;
},
async getTokenPrice(_) {
return 0n;
},
async emmetHashFromtx(hash) {
const txs = await client.getTransactions(bridge, {
hash,
Expand Down
14 changes: 13 additions & 1 deletion src/chains/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type {
GetProtocolFeeInUSD,
GetProvider,
GetTokenBalance,
GetTokenPrice,
GetTokenPriceDecimals,
GetTxFee,
NativeCoinName,
PreTransfer,
Expand Down Expand Up @@ -51,7 +53,9 @@ export type Web3Helper = GetBalance &
GetEmmetHashFromTx &
GetEstimatedTime &
GetBridgeAddress &
GetProtocolFeeInUSD;
GetProtocolFeeInUSD &
GetTokenPrice &
GetTokenPriceDecimals;

export interface Web3Params {
provider: Provider;
Expand Down Expand Up @@ -207,5 +211,13 @@ export async function web3Helper({
tx: tx,
};
},
async getTokenPrice(symbol) {
const tokenPrice = data.getTokenPrice(symbol);
return tokenPrice;
},
async getPriceDecimals(symbol) {
const tokenDecimals = data.getPriceDecimals(symbol);
return tokenDecimals;
},
};
}

0 comments on commit 0a26676

Please sign in to comment.