Skip to content

Commit cad7c96

Browse files
committed
feat(sdk-coin-sol): support versioned sol transactions with customTx intent
Ticket: SC-3231
1 parent ddcc7e2 commit cad7c96

File tree

16 files changed

+1024
-30
lines changed

16 files changed

+1024
-30
lines changed

modules/bitgo/test/v2/unit/wallet.ts

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5670,7 +5670,7 @@ describe('V2 Wallet:', function () {
56705670
solInstructions: [],
56715671
recipients: testRecipients,
56725672
})
5673-
.should.be.rejectedWith(`'solInstructions' is a required parameter for customTx intent`);
5673+
.should.be.rejectedWith(`'solInstructions' or 'versionedTransactionData' is required for customTx intent`);
56745674
});
56755675

56765676
it('should support solInstruction for cold wallets', async function () {
@@ -5708,6 +5708,203 @@ describe('V2 Wallet:', function () {
57085708
});
57095709
});
57105710
});
5711+
5712+
describe('prebuildTransaction with versionedTransactionData type', function () {
5713+
const testVersionedTransactionData = {
5714+
versionedInstructions: [
5715+
{
5716+
programIdIndex: 10,
5717+
accountKeyIndexes: [0, 1, 2],
5718+
data: '0102030405',
5719+
},
5720+
{
5721+
programIdIndex: 11,
5722+
accountKeyIndexes: [0, 3, 4, 5],
5723+
data: '060708090a',
5724+
},
5725+
],
5726+
addressLookupTables: [
5727+
{
5728+
accountKey: '2sk6bVhjN53hz7sqE72eqHvhPfSc1snZzsJR6yA5hF7j',
5729+
writableIndexes: [0, 1],
5730+
readonlyIndexes: [2, 3],
5731+
},
5732+
],
5733+
staticAccountKeys: [
5734+
'5hr5fisPi6DXNuuRpm5XUbzpiEnmdyxXuBDTwzwZj5Pe',
5735+
'2sk6bVhjN53hz7sqE72eqHvhPfSc1snZzsJR6yA5hF7j',
5736+
'11111111111111111111111111111111',
5737+
],
5738+
messageHeader: {
5739+
numRequiredSignatures: 1,
5740+
numReadonlySignedAccounts: 0,
5741+
numReadonlyUnsignedAccounts: 1,
5742+
},
5743+
};
5744+
5745+
it('should call prebuildTxWithIntent with correct parameters for versioned transaction', async function () {
5746+
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
5747+
prebuildTxWithIntent.resolves(txRequest);
5748+
prebuildTxWithIntent.calledOnceWithExactly({
5749+
reqId,
5750+
intentType: 'customTx',
5751+
versionedTransactionData: testVersionedTransactionData,
5752+
recipients: testRecipients,
5753+
});
5754+
5755+
const txPrebuild = await tssSolWallet.prebuildTransaction({
5756+
reqId,
5757+
type: 'customTx',
5758+
versionedTransactionData: testVersionedTransactionData,
5759+
recipients: testRecipients,
5760+
});
5761+
5762+
txPrebuild.should.deepEqual({
5763+
walletId: tssSolWallet.id(),
5764+
wallet: tssSolWallet,
5765+
txRequestId: 'id',
5766+
txHex: 'ababcdcd',
5767+
buildParams: {
5768+
type: 'customTx',
5769+
versionedTransactionData: testVersionedTransactionData,
5770+
recipients: testRecipients,
5771+
},
5772+
feeInfo: {
5773+
fee: 5000,
5774+
feeString: '5000',
5775+
},
5776+
});
5777+
});
5778+
5779+
it('should handle versionedTransactionData with empty recipients', async function () {
5780+
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
5781+
prebuildTxWithIntent.resolves(txRequest);
5782+
prebuildTxWithIntent.calledOnceWithExactly({
5783+
reqId,
5784+
intentType: 'customTx',
5785+
versionedTransactionData: testVersionedTransactionData,
5786+
recipients: [],
5787+
});
5788+
5789+
const txPrebuild = await tssSolWallet.prebuildTransaction({
5790+
reqId,
5791+
type: 'customTx',
5792+
versionedTransactionData: testVersionedTransactionData,
5793+
});
5794+
5795+
txPrebuild.should.deepEqual({
5796+
walletId: tssSolWallet.id(),
5797+
wallet: tssSolWallet,
5798+
txRequestId: 'id',
5799+
txHex: 'ababcdcd',
5800+
buildParams: {
5801+
type: 'customTx',
5802+
versionedTransactionData: testVersionedTransactionData,
5803+
},
5804+
feeInfo: {
5805+
fee: 5000,
5806+
feeString: '5000',
5807+
},
5808+
});
5809+
});
5810+
5811+
it('should handle versionedTransactionData with memo parameter', async function () {
5812+
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
5813+
prebuildTxWithIntent.resolves(txRequest);
5814+
prebuildTxWithIntent.calledOnceWithExactly({
5815+
reqId,
5816+
intentType: 'customTx',
5817+
versionedTransactionData: testVersionedTransactionData,
5818+
recipients: testRecipients,
5819+
memo: {
5820+
type: 'type',
5821+
value: 'test memo',
5822+
},
5823+
});
5824+
5825+
const txPrebuild = await tssSolWallet.prebuildTransaction({
5826+
reqId,
5827+
type: 'customTx',
5828+
versionedTransactionData: testVersionedTransactionData,
5829+
recipients: testRecipients,
5830+
memo: {
5831+
type: 'type',
5832+
value: 'test memo',
5833+
},
5834+
});
5835+
5836+
txPrebuild.should.deepEqual({
5837+
walletId: tssSolWallet.id(),
5838+
wallet: tssSolWallet,
5839+
txRequestId: 'id',
5840+
txHex: 'ababcdcd',
5841+
buildParams: {
5842+
type: 'customTx',
5843+
versionedTransactionData: testVersionedTransactionData,
5844+
recipients: testRecipients,
5845+
memo: {
5846+
type: 'type',
5847+
value: 'test memo',
5848+
},
5849+
},
5850+
feeInfo: {
5851+
fee: 5000,
5852+
feeString: '5000',
5853+
},
5854+
});
5855+
});
5856+
5857+
it('should handle versionedTransactionData with pending approval ID', async function () {
5858+
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
5859+
prebuildTxWithIntent.resolves({ ...txRequest, state: 'pendingApproval', pendingApprovalId: 'some-id' });
5860+
prebuildTxWithIntent.calledOnceWithExactly({
5861+
reqId,
5862+
intentType: 'customTx',
5863+
versionedTransactionData: testVersionedTransactionData,
5864+
recipients: testRecipients,
5865+
});
5866+
5867+
const txPrebuild = await custodialTssSolWallet.prebuildTransaction({
5868+
reqId,
5869+
type: 'customTx',
5870+
versionedTransactionData: testVersionedTransactionData,
5871+
recipients: testRecipients,
5872+
});
5873+
5874+
txPrebuild.should.deepEqual({
5875+
walletId: custodialTssSolWallet.id(),
5876+
wallet: custodialTssSolWallet,
5877+
txRequestId: 'id',
5878+
txHex: 'ababcdcd',
5879+
pendingApprovalId: 'some-id',
5880+
buildParams: {
5881+
type: 'customTx',
5882+
versionedTransactionData: testVersionedTransactionData,
5883+
recipients: testRecipients,
5884+
},
5885+
feeInfo: {
5886+
fee: 5000,
5887+
feeString: '5000',
5888+
},
5889+
});
5890+
});
5891+
5892+
it('should throw error for empty versionedInstructions array', async function () {
5893+
await tssSolWallet
5894+
.prebuildTransaction({
5895+
reqId,
5896+
type: 'customTx',
5897+
versionedTransactionData: {
5898+
versionedInstructions: [],
5899+
addressLookupTables: [],
5900+
staticAccountKeys: ['test'],
5901+
messageHeader: { numRequiredSignatures: 1, numReadonlySignedAccounts: 0, numReadonlyUnsignedAccounts: 0 },
5902+
},
5903+
recipients: testRecipients,
5904+
})
5905+
.should.be.rejectedWith(`'solInstructions' or 'versionedTransactionData' is required for customTx intent`);
5906+
});
5907+
});
57115908
});
57125909

57135910
describe('Aptos Custom transaction Flow', function () {

modules/sdk-coin-sol/src/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export enum InstructionBuilderTypes {
6161
MintTo = 'MintTo',
6262
Burn = 'Burn',
6363
CustomInstruction = 'CustomInstruction',
64+
VersionedCustomInstruction = 'VersionedCustomInstruction',
6465
Approve = 'Approve',
6566
WithdrawStake = 'WithdrawStake',
6667
}

0 commit comments

Comments
 (0)