Skip to content

Commit

Permalink
feat(sdk-coin-avaxc): add avaxc support for evm ccr
Browse files Browse the repository at this point in the history
TICKET: COIN-1708
  • Loading branch information
nrjsuthar committed Sep 26, 2024
1 parent 53b14ff commit 208fac5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/abstract-eth/src/abstractEthLikeNewCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
* @param {string[]} paramsArr - The parameters to hash together for the digest
* @returns {Buffer}
*/
private static getHopDigest(paramsArr: string[]): Buffer {
static getHopDigest(paramsArr: string[]): Buffer {
const hash = Keccak('keccak256');
hash.update([AbstractEthLikeNewCoins.hopTransactionSalt, ...paramsArr].join('$'));
return hash.digest();
Expand Down
28 changes: 20 additions & 8 deletions modules/sdk-coin-avaxc/src/avaxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
CoinFamily,
coins,
ethGasConfigs,
BaseNetwork,
EthereumNetwork,
} from '@bitgo/statics';
import {
BaseCoin,
Expand All @@ -33,13 +33,15 @@ import {
VerifyAddressOptions,
} from '@bitgo/sdk-core';
import {
AbstractEthLikeNewCoins,
GetSendMethodArgsOptions,
optionalDeps,
RecoverOptions,
RecoveryInfo,
SendMethodArgs,
TransactionBuilder as EthTransactionBuilder,
TransactionPrebuild,
OfflineVaultTxInfo as AvaxcRecoveryOfflineVaultTxInfo,
} from '@bitgo/sdk-coin-eth';
import { getToken, isValidEthAddress } from './lib/utils';
import { KeyPair as AvaxcKeyPair, TransactionBuilder } from './lib';
Expand All @@ -57,19 +59,25 @@ import {
OfflineVaultTxInfo,
PrecreateBitGoOptions,
PresignTransactionOptions,
SignedTransaction,
SignFinalOptions,
VerifyAvaxcTransactionOptions,
SignedTransaction,
} from './iface';
import { AvaxpLib } from '@bitgo/sdk-coin-avaxp';
import { SignTransactionOptions } from '@bitgo/abstract-eth';

export class AvaxC extends BaseCoin {
/** COIN-1708 : Avaxc is added for CCR in WRW,
* hence adding the feature for AbstractEthLikeNewCoins
* Super class changed from BaseCoin to AbstractEthLikeNewCoins
* @since Sept 2024
*/
export class AvaxC extends AbstractEthLikeNewCoins {
static hopTransactionSalt = 'bitgoHopAddressRequestSalt';

protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;

protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo);
super(bitgo, staticsCoin);

if (!staticsCoin) {
throw new Error('missing required constructor parameter staticsCoin');
Expand All @@ -94,8 +102,8 @@ export class AvaxC extends BaseCoin {
* Method to return the coin's network object
* @returns {BaseNetwork}
*/
getNetwork(): BaseNetwork {
return this._staticsCoin.network;
getNetwork(): EthereumNetwork {
return this._staticsCoin.network as EthereumNetwork;
}

/**
Expand Down Expand Up @@ -544,7 +552,7 @@ export class AvaxC extends BaseCoin {
* @param {string} params.recoveryDestination - target address to send recovered funds to
* @returns {Promise<RecoveryInfo>} - recovery tx info
*/
async recover(params: RecoverOptions): Promise<RecoveryInfo | OfflineVaultTxInfo> {
async recover(params: RecoverOptions): Promise<RecoveryInfo | OfflineVaultTxInfo | AvaxcRecoveryOfflineVaultTxInfo> {
if (_.isUndefined(params.userKey)) {
throw new Error('missing userKey');
}
Expand Down Expand Up @@ -578,6 +586,10 @@ export class AvaxC extends BaseCoin {
throw new Error('invalid recoveryDestination');
}

if (params.bitgoFeeAddress) {
return this.recoverEthLikeforEvmBasedRecovery(params);
}

// TODO (BG-56531): add support for krs
const isUnsignedSweep = getIsUnsignedSweep(params);

Expand Down Expand Up @@ -990,7 +1002,7 @@ export class AvaxC extends BaseCoin {
* Assemble half-sign prebuilt transaction
* @param params
*/
async signTransaction(params: AvaxSignTransactionOptions): Promise<SignedTransaction> {
async signTransaction(params: AvaxSignTransactionOptions | SignTransactionOptions): Promise<SignedTransaction> {
// Normally the SDK provides the first signature for an AVAXC tx,
// but for unsigned sweep recoveries it can provide the second and final one.
if (params.isLastSignature) {
Expand Down

0 comments on commit 208fac5

Please sign in to comment.