Skip to content

Commit c13ffaf

Browse files
TomerHFBa0ngo
authored andcommitted
feat(@fireblocks/recovery-utility): ✨ add trc20 support
1 parent f8d3c97 commit c13ffaf

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

apps/recovery-relay/lib/wallets/ERC20/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export class ERC20 extends EVMBase implements ConnectedWallet {
5050

5151
public setDecimals(decimals: number) {
5252
this.decimals = decimals;
53+
if (!this.decimals) {
54+
this.relayLogger.error(`ERC20 Token decimals are unavailable: ${this.assetId}`);
55+
throw new Error(`ERC20 Token decimals are unavailable: ${this.assetId}`);
56+
}
57+
5358
this.normalizingFactor = (10 ** decimals).toString();
5459
}
5560

apps/recovery-relay/lib/wallets/Jetton/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ export class Jetton extends BaseTon implements LateInitConnectedWallet {
4848
throw new Error(`TON Jettons: wallet's contract address unavailable`);
4949
}
5050

51+
if (!this.decimals) {
52+
this.relayLogger.error(`TON Jettons: token decimals not set`);
53+
throw new Error(`TON Jettons: token decimals not set`);
54+
}
55+
5156
await new Promise((resolve) => setTimeout(resolve, 2000));
5257

5358
const { stack } = await this.client.runMethod(contractAddress, 'get_wallet_data');
54-
const normalizingFactor = 10 ** this.decimals!;
59+
const normalizingFactor = 10 ** this.decimals;
5560

5661
return stack.readNumber() / normalizingFactor;
5762
} else {

apps/recovery-relay/lib/wallets/TRC20/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export class TRC20 extends BaseTron implements ConnectedWallet {
5555
}
5656

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

6165
const extraParams = new Map<string, any>();

apps/recovery-utility/renderer/lib/wallets/TRC20/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export class TRC20 extends BaseTron implements SigningWallet {
2020
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, this.privateKey?.replace('0x', ''));
2121

2222
const decimals = extraParams?.get('d');
23-
if (!decimals) {
24-
this.utilityLogger.error('TRC20: Decimals not set');
25-
}
2623
const tokenAddress = extraParams?.get('t');
2724

2825
const functionSelector = 'transfer(address,uint256)';

packages/asset-config/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,15 @@ To add support for withdrawals of a listed ERC20 on supported EVM chain, make su
5656
The token contract address must be present in the `globalAssets` list as the `address` parameter.
5757
Note: the tool will support ERC20 token withdrawals only on EVM chains that has withdrawal support for the base asset as well.
5858

59+
### Add a new TRC20 token
60+
61+
To add support for withdrawals of a listed TRC20 token, make sure the token is listed in `globalAssets.ts`.
62+
The token contract address must be present in the `globalAssets` list as the `address` parameter, make sure that `decimals` is also updated accordingly.
63+
5964
### Add a new Jetton token
6065

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

6469
### Token or new Base Asset Support
6570

0 commit comments

Comments
 (0)