Skip to content

Commit 34fc9b8

Browse files
fix: v4 cold and custody ccr recovery txn
2 parents 6ab0321 + b840f73 commit 34fc9b8

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface SignTransactionOptions extends BaseSignTransactionOptions, Sign
161161
gasPrice?: number;
162162
custodianTransactionId?: string;
163163
common?: EthLikeCommon.default;
164+
walletVersion?: number;
164165
}
165166

166167
export type SignedTransaction = HalfSignedTransaction | FullySignedTransaction;
@@ -196,6 +197,7 @@ export interface OfflineVaultTxInfo {
196197
halfSigned?: HalfSignedTransaction;
197198
feesUsed?: FeesUsed;
198199
isEvmBasedCrossChainRecovery?: boolean;
200+
walletVersion?: number;
199201
}
200202

201203
interface UnformattedTxInfo {
@@ -1005,6 +1007,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
10051007
.transfer()
10061008
.coin(this.staticsCoin?.name as string)
10071009
.key(new KeyPairLib({ prv: params.prv }).getKeys().prv!);
1010+
if (params.walletVersion) {
1011+
txBuilder.walletVersion(params.walletVersion);
1012+
}
10081013
const transaction = await txBuilder.build();
10091014

10101015
const recipients = transaction.outputs.map((output) => ({ address: output.address, amount: output.value }));
@@ -1633,8 +1638,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
16331638
txBuilder.walletVersion(4);
16341639
}
16351640

1636-
// If gasLimit was not passed as a param, then fetch the gasLimit from Explorer
1637-
if (!params.gasLimit && !userKey.startsWith('xpub')) {
1641+
// If gasLimit was not passed as a param or if it is not cold/custody wallet, then fetch the gasLimit from Explorer
1642+
if (!params.gasLimit && userKey && !userKey.startsWith('xpub')) {
16381643
const sendData = txBuilder.getSendData();
16391644
gasLimit = await this.getGasLimitFromExternalAPI(
16401645
params.bitgoFeeAddress as string,
@@ -1671,6 +1676,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
16711676
amount: batchExecutionInfo.totalAmount,
16721677
backupKeyNonce: bitgoFeeAddressNonce,
16731678
eip1559: params.eip1559,
1679+
...(txBuilder.getWalletVersion() === 4 ? { walletVersion: txBuilder.getWalletVersion() } : {}),
16741680
};
16751681
_.extend(response, txInfo);
16761682
response.nextContractSequenceId = response.contractSequenceId;
@@ -1803,7 +1809,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
18031809
txBuilder.walletVersion(4);
18041810
}
18051811

1806-
if (!params.gasLimit && !userKey.startsWith('xpub')) {
1812+
if (!params.gasLimit && userKey && !userKey.startsWith('xpub')) {
18071813
const sendData = txBuilder.getSendData();
18081814
gasLimit = await this.getGasLimitFromExternalAPI(
18091815
params.bitgoFeeAddress as string,
@@ -1840,6 +1846,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
18401846
amount: txAmount.toString(),
18411847
backupKeyNonce: bitgoFeeAddressNonce,
18421848
eip1559: params.eip1559,
1849+
...(txBuilder.getWalletVersion() === 4 ? { walletVersion: txBuilder.getWalletVersion() } : {}),
18431850
};
18441851
_.extend(response, txInfo);
18451852
response.nextContractSequenceId = response.contractSequenceId;

modules/abstract-eth/src/lib/transactionBuilder.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,4 +854,11 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
854854
}
855855
this._feeAddress = address;
856856
}
857+
858+
/**
859+
* Get the wallet version for wallet
860+
*/
861+
public getWalletVersion(): number {
862+
return this._walletVersion;
863+
}
857864
}

modules/sdk-coin-avaxc/src/avaxc.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,22 @@ export class AvaxC extends AbstractEthLikeNewCoins {
358358

359359
/**
360360
* Queries avax.network for the token balance of an address
361-
* @param {string} address - the AVAXC address
361+
* @param {string} walletContractAddress - the AVAXC address
362+
* @param {string} tokenContractAddress - the Token contract address
362363
* @returns {Promise<BigNumber>} address balance
363364
*/
364-
async queryAddressTokenBalance(address: string, contractAddress: string): Promise<BN> {
365+
async queryAddressTokenBalance(tokenContractAddress: string, walletContractAddress: string): Promise<BN> {
365366
// get token balance using contract call
366-
const tokenBalanceData = optionalDeps.ethAbi.simpleEncode('balanceOf(address)', address).toString('hex');
367+
const tokenBalanceData = optionalDeps.ethAbi
368+
.simpleEncode('balanceOf(address)', walletContractAddress)
369+
.toString('hex');
367370
const tokenBalanceDataHex = optionalDeps.ethUtil.addHexPrefix(tokenBalanceData);
368371
const result = await this.recoveryBlockchainExplorerQuery({
369372
jsonrpc: '2.0',
370373
method: 'eth_call',
371374
params: [
372375
{
373-
to: contractAddress,
376+
to: tokenContractAddress,
374377
data: tokenBalanceDataHex,
375378
},
376379
'latest',
@@ -379,7 +382,9 @@ export class AvaxC extends AbstractEthLikeNewCoins {
379382
});
380383
// throw if the result does not exist or the result is not a valid number
381384
if (!result || !result.result || isNaN(result.result)) {
382-
throw new Error(`Could not obtain address token balance for ${address} from avax.network, got: ${result.result}`);
385+
throw new Error(
386+
`Could not obtain address token balance for ${walletContractAddress} from avax.network, got: ${result.result}`
387+
);
383388
}
384389
const tokenBalanceHex = result.result;
385390
return new optionalDeps.ethUtil.BN(tokenBalanceHex.slice(2), 16);
@@ -657,7 +662,7 @@ export class AvaxC extends AbstractEthLikeNewCoins {
657662
let txAmount;
658663
if (params.tokenContractAddress) {
659664
// get token balance of wallet
660-
txAmount = await this.queryAddressTokenBalance(params.walletContractAddress, params.tokenContractAddress);
665+
txAmount = await this.queryAddressTokenBalance(params.tokenContractAddress, params.walletContractAddress);
661666
} else {
662667
// get balance of wallet and deduct fees to get transaction amount
663668
txAmount = await this.queryAddressBalance(params.walletContractAddress);
@@ -1012,6 +1017,9 @@ export class AvaxC extends AbstractEthLikeNewCoins {
10121017
const txBuilder = this.getTransactionBuilder() as TransactionBuilder;
10131018
txBuilder.from(params.txPrebuild.txHex);
10141019
txBuilder.transfer().key(new AvaxcKeyPair({ prv: params.prv }).getKeys().prv!);
1020+
if (params.walletVersion) {
1021+
txBuilder.walletVersion(params.walletVersion);
1022+
}
10151023
const transaction = await txBuilder.build();
10161024

10171025
const recipients = transaction.outputs.map((output) => ({ address: output.address, amount: output.value }));

modules/sdk-coin-avaxc/src/iface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export interface AvaxSignTransactionOptions extends BaseSignTransactionOptions {
172172
prv: string;
173173
custodianTransactionId?: string;
174174
isLastSignature?: boolean;
175+
walletVersion?: number;
175176
}
176177

177178
export interface HalfSignedTransaction extends HalfSignedAccountTransaction {

0 commit comments

Comments
 (0)