diff --git a/modules/sdk-coin-sol/src/lib/tokenTransferBuilder.ts b/modules/sdk-coin-sol/src/lib/tokenTransferBuilder.ts index 0ce0d9f945..b5866957ac 100644 --- a/modules/sdk-coin-sol/src/lib/tokenTransferBuilder.ts +++ b/modules/sdk-coin-sol/src/lib/tokenTransferBuilder.ts @@ -147,7 +147,7 @@ export class TokenTransferBuilder extends TransactionBuilder { }, }; - if (!this._priorityFee) { + if (!this._priorityFee || this._priorityFee === BigInt(0)) { this._instructionsData = [...createAtaInstructions, ...sendInstructions]; } else { // order is important, createAtaInstructions must be before sendInstructions diff --git a/modules/sdk-coin-sol/src/lib/transferBuilderV2.ts b/modules/sdk-coin-sol/src/lib/transferBuilderV2.ts index ead9508e68..e121b320c3 100644 --- a/modules/sdk-coin-sol/src/lib/transferBuilderV2.ts +++ b/modules/sdk-coin-sol/src/lib/transferBuilderV2.ts @@ -170,7 +170,7 @@ export class TransferBuilderV2 extends TransactionBuilder { let addPriorityFeeInstruction: SetPriorityFee; // If there are createAtaInstructions, then token is involved and we need to add a priority fee instruction - if (!this._priorityFee) { + if (!this._priorityFee || this._priorityFee === BigInt(0)) { this._instructionsData = [...createAtaInstructions, ...sendInstructions]; } else if ( createAtaInstructions.length !== 0 || diff --git a/modules/sdk-coin-sol/test/resources/sol.ts b/modules/sdk-coin-sol/test/resources/sol.ts index c30159ea76..d5e8d06099 100644 --- a/modules/sdk-coin-sol/test/resources/sol.ts +++ b/modules/sdk-coin-sol/test/resources/sol.ts @@ -339,7 +339,7 @@ export const MULTI_TOKEN_TRANSFER_SIGNED = export const MULTI_ASSET_TOKEN_TRANSFER_UNSIGNED = 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAUNCoMkjRrCRUK+mb1OrcYVsRHoGOkX5c9n9deT5Gq/d1YY19xOQg+B6cqXSn9ODw0NMlw+NO0os7hLyaFGBpYImBSE0DU4DP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tbw=='; export const MULTI_TOKEN_TRANSFER_UNSIGNED_WITH_UNIQUE_CREATE_ATA_AND_MEMO_AND_DURABLE_NONCE = 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAgNAGymKVqOJEQemBHH67uu8ISJV4rtwTejLrjw7VSeW6dJP1r3FCCofxhWCBv6dIPMrDQrI7IXh1M2k+lzW80KTW/6Eon6nFlovAcYTKTZK+nk98ALlkSL/BgjW09MceFuldLxXAw5t3p9Od8IqufG/BDksWGKlVuIb5qJM0zV4WypGBtS9+2Q6usNrUtxvrRTg2FnYTFxfpMJWBBft6OJ1QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAjJclj04kifG7PRApFI4NgwtaE5na/xCEBI572Nvp+FkDBkZv5SEXMv/srbpyw5vnvIzlu8X3EmssQ5s6QAAAANEDifvO5SjyCGEdzMc0sxCSVAyyuNWNEA8uqizttNpeBUpTWpkpIQZNJOhxYNo4fHw1td28kruB5B+oQEEFRI0Gp9UXGSxWjuCKhF9z0peIzwNcMUWyGrNE2AYuqUAAAAan1RcZLFxRIYzJTD1K8X9Y2u4Im6H9ROPb2YoAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKnjMtr5L6vs6LY/96RABeX9/Zr6FYdWthxalfkEs7jQgQcFAwIKAAQEAAAABwAJA4CWmAAAAAAABgcAAQQIBQwLAAwEAwgEAAoM4JMEAAAAAAAJDAQDCAQACgzgkwQAAAAAAAkMBAMIBAAKDOCTBAAAAAAACQkACXRlc3QgbWVtbw=='; diff --git a/modules/sdk-coin-sol/test/unit/transactionBuilder/tokenTransferBuilder.ts b/modules/sdk-coin-sol/test/unit/transactionBuilder/tokenTransferBuilder.ts index 40d5226009..75fafab09b 100644 --- a/modules/sdk-coin-sol/test/unit/transactionBuilder/tokenTransferBuilder.ts +++ b/modules/sdk-coin-sol/test/unit/transactionBuilder/tokenTransferBuilder.ts @@ -356,6 +356,10 @@ describe('Sol Token Transfer Builder', () => { txBuilder.send({ address: otherAccount.pub, amount, tokenName: nameUSDC }); txBuilder.memo(memo); txBuilder.createAssociatedTokenAccount({ ownerAddress: otherAccount.pub, tokenName: nameUSDC }); + const prioFeeMicroLamports = '0'; + const priorityFee: FeeOptions = { + amount: prioFeeMicroLamports, + }; txBuilder.setPriorityFee(priorityFee); const tx = await txBuilder.build(); tx.inputs.length.should.equal(1); @@ -371,26 +375,26 @@ describe('Sol Token Transfer Builder', () => { coin: nameUSDC, }); const txJson = tx.toJson(); - txJson.instructionsData.length.should.equal(4); - txJson.instructionsData[0].type.should.equal('SetPriorityFee'); - txJson.instructionsData[1].type.should.equal('CreateAssociatedTokenAccount'); - txJson.instructionsData[1].params.should.deepEqual({ + // Since prio fee is 0, we are not adding compute unit price instruction + txJson.instructionsData.length.should.equal(3); + txJson.instructionsData[0].type.should.equal('CreateAssociatedTokenAccount'); + txJson.instructionsData[0].params.should.deepEqual({ mintAddress: mintUSDC, ataAddress: ataAddress, ownerAddress: otherAccount.pub, payerAddress: walletPK, tokenName: nameUSDC, }); - txJson.instructionsData[2].type.should.equal('TokenTransfer'); - txJson.instructionsData[2].params.should.deepEqual({ + txJson.instructionsData[1].type.should.equal('TokenTransfer'); + txJson.instructionsData[1].params.should.deepEqual({ fromAddress: walletPK, toAddress: otherAccount.pub, amount: amount, tokenName: nameUSDC, sourceAddress: 'B5rJjuVi7En63iK6o3ijKdJwAoTe2gwCYmJsVdHQ2aKV', }); - txJson.instructionsData[3].type.should.equal('Memo'); - txJson.instructionsData[3].params.memo.should.equal(memo); + txJson.instructionsData[2].type.should.equal('Memo'); + txJson.instructionsData[2].params.memo.should.equal(memo); const rawTx = tx.toBroadcastFormat(); should.equal(Utils.isValidRawTransaction(rawTx), true);