Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions modules/bitgo/test/v2/unit/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3462,6 +3462,32 @@ describe('V2 Wallet:', function () {
args[1]!.should.equal('full');
});

it('should call prebuildTxWithIntent with the correct params for bridgeFunds', async function () {
const intentAmount = { value: '1000000', symbol: 'thypeevm' };
const feeOptions = {
maxFeePerGas: 3000000000,
maxPriorityFeePerGas: 2000000000,
};

const prebuildTxWithIntent = sandbox.stub(ECDSAUtils.EcdsaUtils.prototype, 'prebuildTxWithIntent');
prebuildTxWithIntent.resolves(txRequestFull);

await tssEthWallet.prebuildTransaction({
reqId,
type: 'bridgeFunds',
intentAmount,
feeOptions,
});

sinon.assert.calledOnce(prebuildTxWithIntent);
const args = prebuildTxWithIntent.args[0];
args[0]!.intentType.should.equal('bridgeFunds');
args[0]!.amount!.should.deepEqual(intentAmount);
args[0]!.feeOptions!.should.deepEqual(feeOptions);
args[0]!.should.not.have.property('recipients');
args[1]!.should.equal('full');
});

it('should call prebuildTxWithIntent with the correct feeOptions when passing using the legacy format', async function () {
const recipients = [
{
Expand Down Expand Up @@ -3722,6 +3748,27 @@ describe('V2 Wallet:', function () {
intent.intentType.should.equal('fillNonce');
});

it('populate intent should return valid bridgeFunds intent', async function () {
const mpcUtils = new ECDSAUtils.EcdsaUtils(bitgo, bitgo.coin('hteth'));
const amount = { value: '1000000', symbol: 'thypeevm' };
const feeOptions = {
maxFeePerGas: 3000000000,
maxPriorityFeePerGas: 2000000000,
};

const intent = mpcUtils.populateIntent(bitgo.coin('hteth'), {
reqId,
intentType: 'bridgeFunds',
amount,
feeOptions,
});

intent.intentType.should.equal('bridgeFunds');
intent.amount!.should.deepEqual(amount);
intent.feeOptions!.should.deepEqual(feeOptions);
intent.should.have.property('recipients', undefined);
});

it('should build a single recipient transfer transaction providing apiVersion parameter as "full" ', async function () {
const recipients = [
{
Expand Down
7 changes: 7 additions & 0 deletions modules/sdk-core/src/bitgo/utils/mpcUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export abstract class MpcUtils {
'transferAccept',
'transferReject',
'transferOfferWithdrawn',
'bridgeFunds',
].includes(params.intentType)
) {
assert(params.recipients, `'recipients' is a required parameter for ${params.intentType} intent`);
Expand Down Expand Up @@ -224,6 +225,12 @@ export abstract class MpcUtils {
tokenName: params.tokenName,
feeOptions: params.feeOptions,
};
case 'bridgeFunds':
return {
...baseIntent,
amount: params.amount,
feeOptions: params.feeOptions,
};
default:
throw new Error(`Unsupported intent type ${params.intentType}`);
}
Expand Down
8 changes: 8 additions & 0 deletions modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ export interface PrebuildTransactionWithIntentOptions extends IntentOptionsBase
txRequestId?: string;
isTestTransaction?: boolean;
contractId?: string;
/**
* Amount for intents that use a top-level amount instead of recipients (e.g. bridgeFunds).
*/
amount?: { value: string; symbol: string };
}
export interface IntentRecipient {
address: {
Expand Down Expand Up @@ -342,6 +346,10 @@ export interface PopulatedIntent extends PopulatedIntentBase {
txRequestId?: string;
isTestTransaction?: boolean;
contractId?: string;
/**
* Amount for intents that use a top-level amount instead of recipients (e.g. bridgeFunds).
*/
amount?: { value: string; symbol: string };
}

export type TxRequestState =
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/iWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ export interface PrebuildTransactionOptions {
txRequestId?: string;
isTestTransaction?: boolean;
contractId?: string;
/**
* Amount for intents that use a top-level amount instead of recipients (e.g. bridgeFunds).
* Named intentAmount to avoid collision with SendOptions.amount which is string | number.
*/
intentAmount?: { value: string; symbol: string };
}

export interface PrebuildAndSignTransactionOptions extends PrebuildTransactionOptions, WalletSignTransactionOptions {
Expand Down
15 changes: 15 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3746,6 +3746,21 @@ export class Wallet implements IWallet {
params.preview
);
break;
case 'bridgeFunds':
txRequest = await this.tssUtils!.prebuildTxWithIntent(
{
reqId,
intentType: 'bridgeFunds',
sequenceId: params.sequenceId,
comment: params.comment,
amount: params.intentAmount,
nonce: params.nonce,
feeOptions,
},
apiVersion,
params.preview
);
break;
default:
throw new Error(`transaction type not supported: ${params.type}`);
}
Expand Down