Skip to content

Commit 995d202

Browse files
committed
feat(@fireblocks/recovery-utility): ✨ cr fixes
1 parent 1d34bf9 commit 995d202

File tree

11 files changed

+51
-28
lines changed

11 files changed

+51
-28
lines changed

apps/recovery-relay/components/WithdrawModal/CreateTransaction/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export const CreateTransaction = ({ asset, inboundRelayParams, setSignTxResponse
428428
<Typography variant='body1' color={(theme) => theme.palette.error.main}>
429429
Insufficient balance for transaction
430430
</Typography>
431-
) : prepareQuery.data?.insufficientFeeBalance === true && prepareQuery.data?.insufficientBalance !== true ? (
431+
) : prepareQuery.data?.insufficientBalanceForTokenTransfer === true && prepareQuery.data?.insufficientBalance !== true ? (
432432
<Typography variant='body1' color={(theme) => theme.palette.error.main}>
433433
Insufficient fee asset balance for token transaction
434434
</Typography>
@@ -445,8 +445,8 @@ export const CreateTransaction = ({ asset, inboundRelayParams, setSignTxResponse
445445
prepareQuery.data?.insufficientBalance !== undefined &&
446446
prepareQuery.data.insufficientBalance) ||
447447
(prepareQuery.data &&
448-
prepareQuery.data?.insufficientFeeBalance !== undefined &&
449-
prepareQuery.data.insufficientFeeBalance)
448+
prepareQuery.data?.insufficientBalanceForTokenTransfer !== undefined &&
449+
prepareQuery.data.insufficientBalanceForTokenTransfer)
450450
}
451451
>
452452
Prepare Transaction

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Ton as BaseTon } from '@fireblocks/wallet-derivation';
22
import { JettonMaster, TonClient, WalletContractV4 } from '@ton/ton';
3-
import { Address, beginCell, Cell, fromNano, toNano } from '@ton/core';
3+
import { Address, beginCell, Cell, toNano } from '@ton/core';
44
import { AccountData } from '../types';
55
import { defaultTonWalletV4R2code } from '../TON/tonParams';
66
import axios from 'axios';
@@ -28,7 +28,7 @@ export class Jetton extends BaseTon implements LateInitConnectedWallet {
2828
}
2929

3030
public getLateInitLabel(): string {
31-
return 'Ton client wallet';
31+
return 'Ton wallet client';
3232
}
3333

3434
public setRPCUrl(url: string): void {
@@ -136,7 +136,7 @@ export class Jetton extends BaseTon implements LateInitConnectedWallet {
136136
feeRate,
137137
extraParams,
138138
insufficientBalance: jettonBalance <= 0,
139-
insufficientFeeBalance: tonBalance < feeRate,
139+
insufficientBalanceForTokenTransfer: tonBalance < feeRate,
140140
} as AccountData;
141141

142142
return preperedData;

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getAllJettons } from '@fireblocks/asset-config';
12
import { Cardano } from './ADA';
23
import { Cosmos } from './ATOM';
34
import { Bitcoin, BitcoinCash, BitcoinSV, DASH, DogeCoin, LiteCoin, ZCash } from './BTCBased';
@@ -40,6 +41,19 @@ import { Ton } from './TON';
4041
import { Jetton } from './Jetton';
4142
export { ConnectedWallet } from './ConnectedWallet';
4243

44+
const fillJettons = () => {
45+
const jettonsList = getAllJettons();
46+
const jettons = jettonsList.reduce(
47+
(prev, curr) => ({
48+
...prev,
49+
[curr]: Jetton,
50+
}),
51+
{},
52+
) as any;
53+
Object.keys(jettons).forEach((key) => (jettons[key] === undefined ? delete jettons[key] : {}));
54+
return jettons;
55+
};
56+
4357
export const WalletClasses = {
4458
ALGO: Algorand,
4559
ALGO_TEST: Algorand,
@@ -122,9 +136,7 @@ export const WalletClasses = {
122136
CELESTIA_TEST: Celestia,
123137
TON: Ton,
124138
TON_TEST: Ton,
125-
USDT_TON: Jetton,
126-
NOTCOIN_TON: Jetton,
127-
DOGS_TON: Jetton,
139+
...fillJettons(),
128140
} as const;
129141

130142
type WalletClass = (typeof WalletClasses)[keyof typeof WalletClasses];

apps/recovery-relay/lib/wallets/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type AccountData = {
2828
extraParams?: Map<string, any>;
2929
endpoint?: string;
3030
insufficientBalance?: boolean;
31-
insufficientFeeBalance?: boolean;
31+
insufficientBalanceForTokenTransfer?: boolean;
3232
};
3333

3434
export type TxPayload = {

apps/recovery-utility/renderer/components/Modals/WithdrawModal/SignTransaction/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getLogger,
1313
sanatize,
1414
useWrappedState,
15+
getDerivationMapKey,
1516
} from '@fireblocks/recovery-shared';
1617
import { AssetConfig } from '@fireblocks/asset-config';
1718
import { CallMade, CallReceived, LeakAdd, Toll } from '@mui/icons-material';
@@ -75,7 +76,7 @@ export const SignTransaction = ({ txId, account, asset, inboundRelayParams }: Pr
7576

7677
const derivation = account.wallets
7778
.get(asset.id)
78-
?.derivations.get(`${inboundRelayParams?.unsignedTx.assetId}-${inboundRelayParams?.unsignedTx.from}`);
79+
?.derivations.get(getDerivationMapKey(inboundRelayParams?.unsignedTx.assetId, inboundRelayParams?.unsignedTx.from));
7980

8081
if (!derivation) {
8182
throw new Error('Derivation not found');

apps/recovery-utility/renderer/context/Workspace.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ export const WorkspaceProvider = ({ children }: Props) => {
6868
deriveWallet: (input) => {
6969
let transferableToken = false;
7070
const config = getAssetConfig(input.assetId);
71-
if (config?.address && isTransferableToken(input.assetId)) {
71+
if (isTransferableToken(input.assetId)) {
7272
transferableToken = true;
73+
logger.info('Found a transferable token:', input.assetId);
7374
}
7475
const nativeAssetId = (
7576
transferableToken ? input.assetId : config?.nativeAsset ?? input.assetId

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export class Jetton extends BaseTon implements SigningWallet {
1414
throw new Error('Jetton: Missing jetton parameters');
1515
}
1616

17-
const JettonTransferOpcode = 0x0f8a7ea5;
17+
const jettonTransferOpcode = 0x0f8a7ea5;
1818
const decimals = extraParams?.get('decimals');
1919
const normalizingFactor = 10 ** decimals;
2020
const amountToWithdraw = amount * normalizingFactor; // amount is the wallet balance
2121

2222
let internalMessageMemo = undefined;
2323
// create the tx payload
2424
const internalMessageBody = beginCell()
25-
.storeUint(JettonTransferOpcode, 32) // opcode for jetton transfer
25+
.storeUint(jettonTransferOpcode, 32) // opcode for jetton transfer
2626
.storeUint(0, 64) // query id
2727
.storeCoins(amountToWithdraw) // jetton balance
2828
.storeAddress(Address.parse(to)) // tx destination

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import { Bitcoin } from './BTC';
2-
import { assets } from '@fireblocks/asset-config';
2+
import { assets, getAllJettons } from '@fireblocks/asset-config';
33
import { ERC20, ETC } from '@fireblocks/wallet-derivation';
44
import { Ripple } from './XRP';
55
import { Cosmos } from './ATOM';
@@ -41,14 +41,11 @@ const fillEVMs = () => {
4141
};
4242

4343
const fillJettons = () => {
44-
const jettons = Object.keys(assets).reduce(
45-
(o, assetId) => ({
46-
...o,
47-
[assets[assetId].id]: assets[assetId].protocol === 'TON' && assets[assetId].address ? Jetton : undefined,
48-
}),
49-
{},
50-
) as any;
51-
Object.keys(jettons).forEach((key) => (jettons[key] === undefined ? delete jettons[key] : {}));
44+
const jettonsList = getAllJettons();
45+
const jettons: { [key: string]: any } = {};
46+
for (const jetton of jettonsList) {
47+
jettons[jetton] = Jetton;
48+
}
5249
return jettons;
5350
};
5451

@@ -111,9 +108,6 @@ export const WalletClasses = {
111108
HBAR_TEST: Hedera,
112109
TON: Ton,
113110
TON_TEST: Ton,
114-
// USDT_TON: Jetton,
115-
// NOTCOIN_TON: Jetton,
116-
// DOGS_TON: Jetton,
117111

118112
...fillJettons(),
119113
...fillEVMs(),

packages/asset-config/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ For your convinience we have provided base methods for common types of chains:
5050
- `evm(baseExplorerUrl: string, rpcUrl?: string)` to create a basic EVM chain, simply provide the `baseExplorerUrl` (the URL of an explorer) and optionally `rpcUrl` as the URL of the RPC to communicate with
5151
- `btc(baseExplorerUrl: string, segwit: boolean)` to create a basic BTC chain (ZCash, LTC, etc are all considered such) simply provide the `baseExplorerUrl` (the URL of an explorer) and optionally `segwit` should be false, as only BTC is relevant for this field
5252

53+
### Add a new Jetton token
54+
55+
To add support for withdrawals of a listed Jetton, make sure the token is listed in [globalAssets](/Users/tomerhorviz/Documents/recovery/packages/asset-config/data/globalAssets.ts) and in [patches](packages/asset-config/config/patches.ts).
56+
The Jetton master contract address must be present in the 'globalAssets' list as the 'address' parameter.
57+
5358
### Token or new Base Asset Support
5459

5560
In case a token has bad data, alternatively a token is missing or you want to add a new base asset, it can be added by performing the following steps:

packages/asset-config/assets.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ export const assets = globalAssets.reduce<AssetsConfig>(
1212
}),
1313
{},
1414
);
15+
16+
export function getAllJettons(): string[] {
17+
const jettons = [];
18+
for (const asset of globalAssets) {
19+
if (asset.protocol === 'TON' && asset.address) {
20+
jettons.push(asset.id);
21+
}
22+
}
23+
return jettons;
24+
}

0 commit comments

Comments
 (0)