Skip to content

Commit

Permalink
feat(@fireblocks/recovery-utility): ✨ add trc20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHFB authored and a0ngo committed Jan 26, 2025
1 parent f8d3c97 commit c13ffaf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions apps/recovery-relay/lib/wallets/ERC20/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export class ERC20 extends EVMBase implements ConnectedWallet {

public setDecimals(decimals: number) {
this.decimals = decimals;
if (!this.decimals) {
this.relayLogger.error(`ERC20 Token decimals are unavailable: ${this.assetId}`);
throw new Error(`ERC20 Token decimals are unavailable: ${this.assetId}`);
}

this.normalizingFactor = (10 ** decimals).toString();
}

Expand Down
7 changes: 6 additions & 1 deletion apps/recovery-relay/lib/wallets/Jetton/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ export class Jetton extends BaseTon implements LateInitConnectedWallet {
throw new Error(`TON Jettons: wallet's contract address unavailable`);
}

if (!this.decimals) {
this.relayLogger.error(`TON Jettons: token decimals not set`);
throw new Error(`TON Jettons: token decimals not set`);
}

await new Promise((resolve) => setTimeout(resolve, 2000));

const { stack } = await this.client.runMethod(contractAddress, 'get_wallet_data');
const normalizingFactor = 10 ** this.decimals!;
const normalizingFactor = 10 ** this.decimals;

return stack.readNumber() / normalizingFactor;
} else {
Expand Down
6 changes: 5 additions & 1 deletion apps/recovery-relay/lib/wallets/TRC20/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export class TRC20 extends BaseTron implements ConnectedWallet {
}

public async prepare(): Promise<AccountData> {
const balance = ((await this.getBalance()) / 10 ** this.decimals!) as number;
if (!this.decimals) {
this.relayLogger.error('TRC20: Decimals not set');
throw new Error('TRC20: Decimals not set');
}
const balance = ((await this.getBalance()) / 10 ** this.decimals) as number;
const trxBalance = await this.getTrxBalance();

const extraParams = new Map<string, any>();
Expand Down
3 changes: 0 additions & 3 deletions apps/recovery-utility/renderer/lib/wallets/TRC20/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export class TRC20 extends BaseTron implements SigningWallet {
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, this.privateKey?.replace('0x', ''));

const decimals = extraParams?.get('d');
if (!decimals) {
this.utilityLogger.error('TRC20: Decimals not set');
}
const tokenAddress = extraParams?.get('t');

const functionSelector = 'transfer(address,uint256)';
Expand Down
7 changes: 6 additions & 1 deletion packages/asset-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ To add support for withdrawals of a listed ERC20 on supported EVM chain, make su
The token contract address must be present in the `globalAssets` list as the `address` parameter.
Note: the tool will support ERC20 token withdrawals only on EVM chains that has withdrawal support for the base asset as well.

### Add a new TRC20 token

To add support for withdrawals of a listed TRC20 token, make sure the token is listed in `globalAssets.ts`.
The token contract address must be present in the `globalAssets` list as the `address` parameter, make sure that `decimals` is also updated accordingly.

### Add a new Jetton token

To add support for withdrawals of a listed Jetton, make sure the token is listed in `globalAssets.ts`.
The Jetton master contract address must be present in the `globalAssets` list as the `address` parameter.
The Jetton master contract address must be present in the `globalAssets` list as the `address` parameter, make sure that `decimals` is also updated accordingly.

### Token or new Base Asset Support

Expand Down

0 comments on commit c13ffaf

Please sign in to comment.