diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 64e74aa..dfb31dc 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -44596,6 +44596,7 @@ Token.solana = { }; let currentDeadline; +let currentNonce; const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> { @@ -45070,10 +45071,17 @@ const getPaymentMethod = ({ paymentRoute })=>{ }; const getDeadline = ()=>{ + if(currentDeadline) { return currentDeadline } currentDeadline = Math.ceil(new Date().getTime()/1000)+1800; // 30 Minutes (lower causes wallet simulation issues) return currentDeadline }; +const getNonce = (paymentsAccountData)=>{ + if(currentNonce) { return currentNonce } + currentNonce = paymentsAccountData ? paymentsAccountData.nonce : new BN('0'); + return currentNonce +}; + const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const paymentReceiverPublicKey = new PublicKey(paymentRoute.toAddress); @@ -45090,7 +45098,7 @@ const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(routers$2.solana.api.routeSol.layout.span); routers$2.solana.api.routeSol.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeSol.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -45121,7 +45129,7 @@ const routeToken = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(routers$2.solana.api.routeToken.layout.span); routers$2.solana.api.routeToken.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeToken.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -45189,7 +45197,7 @@ const routeOrcaSwap = async({ paymentRoute, paymentsAccountData, wSolSenderAccou const data = Buffer.alloc(routers$2.solana.api.routeOrcaSwap.layout.span); routers$2.solana.api.routeOrcaSwap.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -45263,7 +45271,7 @@ const routeOrcaSwapSolOut = async({ paymentRoute, paymentsAccountData, wSolEscro const data = Buffer.alloc(routers$2.solana.api.routeOrcaSwapSolOut.layout.span); routers$2.solana.api.routeOrcaSwapSolOut.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -45354,7 +45362,7 @@ const routeOrcaTwoHopSwap = async({ paymentRoute, paymentsAccountData, wSolSende const data = Buffer.alloc(routers$2.solana.api.routeOrcaTwoHopSwap.layout.span); routers$2.solana.api.routeOrcaTwoHopSwap.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaTwoHopSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -45448,7 +45456,7 @@ const routeOrcaTwoHopSwapSolOut = async({ paymentRoute, paymentsAccountData, wSo const data = Buffer.alloc(routers$2.solana.api.routeOrcaTwoHopSwapSolOut.layout.span); routers$2.solana.api.routeOrcaTwoHopSwapSolOut.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaTwoHopSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -45526,6 +45534,7 @@ const getTransaction$3 = async({ paymentRoute })=> { // debug(transaction, paymentRoute) transaction.deadline = currentDeadline; + transaction.nonce = currentNonce.toString(); return transaction }; diff --git a/dist/esm/index.js b/dist/esm/index.js index 4ea7fa1..4ecc8b1 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -902,6 +902,7 @@ const request = async function (url, options) { }; let currentDeadline; +let currentNonce; const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> { @@ -1376,10 +1377,17 @@ const getPaymentMethod = ({ paymentRoute })=>{ }; const getDeadline = ()=>{ + if(currentDeadline) { return currentDeadline } currentDeadline = Math.ceil(new Date().getTime()/1000)+1800; // 30 Minutes (lower causes wallet simulation issues) return currentDeadline }; +const getNonce = (paymentsAccountData)=>{ + if(currentNonce) { return currentNonce } + currentNonce = paymentsAccountData ? paymentsAccountData.nonce : new BN('0'); + return currentNonce +}; + const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const paymentReceiverPublicKey = new PublicKey(paymentRoute.toAddress); @@ -1396,7 +1404,7 @@ const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(solanaRouters.solana.api.routeSol.layout.span); solanaRouters.solana.api.routeSol.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeSol.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -1427,7 +1435,7 @@ const routeToken = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(solanaRouters.solana.api.routeToken.layout.span); solanaRouters.solana.api.routeToken.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeToken.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -1495,7 +1503,7 @@ const routeOrcaSwap = async({ paymentRoute, paymentsAccountData, wSolSenderAccou const data = Buffer.alloc(solanaRouters.solana.api.routeOrcaSwap.layout.span); solanaRouters.solana.api.routeOrcaSwap.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -1569,7 +1577,7 @@ const routeOrcaSwapSolOut = async({ paymentRoute, paymentsAccountData, wSolEscro const data = Buffer.alloc(solanaRouters.solana.api.routeOrcaSwapSolOut.layout.span); solanaRouters.solana.api.routeOrcaSwapSolOut.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -1660,7 +1668,7 @@ const routeOrcaTwoHopSwap = async({ paymentRoute, paymentsAccountData, wSolSende const data = Buffer.alloc(solanaRouters.solana.api.routeOrcaTwoHopSwap.layout.span); solanaRouters.solana.api.routeOrcaTwoHopSwap.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaTwoHopSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -1754,7 +1762,7 @@ const routeOrcaTwoHopSwapSolOut = async({ paymentRoute, paymentsAccountData, wSo const data = Buffer.alloc(solanaRouters.solana.api.routeOrcaTwoHopSwapSolOut.layout.span); solanaRouters.solana.api.routeOrcaTwoHopSwapSolOut.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaTwoHopSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -1832,6 +1840,7 @@ const getTransaction$3 = async({ paymentRoute })=> { // debug(transaction, paymentRoute) transaction.deadline = currentDeadline; + transaction.nonce = currentNonce.toString(); return transaction }; diff --git a/dist/esm/index.solana.js b/dist/esm/index.solana.js index 61a4c2d..11d4018 100644 --- a/dist/esm/index.solana.js +++ b/dist/esm/index.solana.js @@ -2200,6 +2200,7 @@ Token.solana = { }; let currentDeadline; +let currentNonce; const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> { @@ -2674,10 +2675,17 @@ const getPaymentMethod = ({ paymentRoute })=>{ }; const getDeadline = ()=>{ + if(currentDeadline) { return currentDeadline } currentDeadline = Math.ceil(new Date().getTime()/1000)+1800; // 30 Minutes (lower causes wallet simulation issues) return currentDeadline }; +const getNonce = (paymentsAccountData)=>{ + if(currentNonce) { return currentNonce } + currentNonce = paymentsAccountData ? paymentsAccountData.nonce : new BN('0'); + return currentNonce +}; + const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const paymentReceiverPublicKey = new PublicKey(paymentRoute.toAddress); @@ -2694,7 +2702,7 @@ const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(routers$1.solana.api.routeSol.layout.span); routers$1.solana.api.routeSol.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeSol.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -2725,7 +2733,7 @@ const routeToken = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(routers$1.solana.api.routeToken.layout.span); routers$1.solana.api.routeToken.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeToken.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -2793,7 +2801,7 @@ const routeOrcaSwap = async({ paymentRoute, paymentsAccountData, wSolSenderAccou const data = Buffer.alloc(routers$1.solana.api.routeOrcaSwap.layout.span); routers$1.solana.api.routeOrcaSwap.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -2867,7 +2875,7 @@ const routeOrcaSwapSolOut = async({ paymentRoute, paymentsAccountData, wSolEscro const data = Buffer.alloc(routers$1.solana.api.routeOrcaSwapSolOut.layout.span); routers$1.solana.api.routeOrcaSwapSolOut.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -2958,7 +2966,7 @@ const routeOrcaTwoHopSwap = async({ paymentRoute, paymentsAccountData, wSolSende const data = Buffer.alloc(routers$1.solana.api.routeOrcaTwoHopSwap.layout.span); routers$1.solana.api.routeOrcaTwoHopSwap.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaTwoHopSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -3052,7 +3060,7 @@ const routeOrcaTwoHopSwapSolOut = async({ paymentRoute, paymentsAccountData, wSo const data = Buffer.alloc(routers$1.solana.api.routeOrcaTwoHopSwapSolOut.layout.span); routers$1.solana.api.routeOrcaTwoHopSwapSolOut.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaTwoHopSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -3130,6 +3138,7 @@ const getTransaction$2 = async({ paymentRoute })=> { // debug(transaction, paymentRoute) transaction.deadline = currentDeadline; + transaction.nonce = currentNonce.toString(); return transaction }; diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index 23fe0a7..e52bbe4 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -44602,6 +44602,7 @@ }; let currentDeadline; + let currentNonce; const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> { @@ -45076,10 +45077,17 @@ }; const getDeadline = ()=>{ + if(currentDeadline) { return currentDeadline } currentDeadline = Math.ceil(new Date().getTime()/1000)+1800; // 30 Minutes (lower causes wallet simulation issues) return currentDeadline }; + const getNonce = (paymentsAccountData)=>{ + if(currentNonce) { return currentNonce } + currentNonce = paymentsAccountData ? paymentsAccountData.nonce : new BN('0'); + return currentNonce + }; + const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const paymentReceiverPublicKey = new PublicKey(paymentRoute.toAddress); @@ -45096,7 +45104,7 @@ const data = Buffer.alloc(routers$2.solana.api.routeSol.layout.span); routers$2.solana.api.routeSol.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeSol.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -45127,7 +45135,7 @@ const data = Buffer.alloc(routers$2.solana.api.routeToken.layout.span); routers$2.solana.api.routeToken.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeToken.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -45195,7 +45203,7 @@ const data = Buffer.alloc(routers$2.solana.api.routeOrcaSwap.layout.span); routers$2.solana.api.routeOrcaSwap.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -45269,7 +45277,7 @@ const data = Buffer.alloc(routers$2.solana.api.routeOrcaSwapSolOut.layout.span); routers$2.solana.api.routeOrcaSwapSolOut.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -45360,7 +45368,7 @@ const data = Buffer.alloc(routers$2.solana.api.routeOrcaTwoHopSwap.layout.span); routers$2.solana.api.routeOrcaTwoHopSwap.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaTwoHopSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -45454,7 +45462,7 @@ const data = Buffer.alloc(routers$2.solana.api.routeOrcaTwoHopSwapSolOut.layout.span); routers$2.solana.api.routeOrcaTwoHopSwapSolOut.layout.encode({ anchorDiscriminator: routers$2.solana.api.routeOrcaTwoHopSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -45532,6 +45540,7 @@ // debug(transaction, paymentRoute) transaction.deadline = currentDeadline; + transaction.nonce = currentNonce.toString(); return transaction }; diff --git a/dist/umd/index.js b/dist/umd/index.js index 58593ac..f577867 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -907,6 +907,7 @@ }; let currentDeadline; + let currentNonce; const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> { @@ -1381,10 +1382,17 @@ }; const getDeadline = ()=>{ + if(currentDeadline) { return currentDeadline } currentDeadline = Math.ceil(new Date().getTime()/1000)+1800; // 30 Minutes (lower causes wallet simulation issues) return currentDeadline }; + const getNonce = (paymentsAccountData)=>{ + if(currentNonce) { return currentNonce } + currentNonce = paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'); + return currentNonce + }; + const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const paymentReceiverPublicKey = new solanaWeb3_js.PublicKey(paymentRoute.toAddress); @@ -1401,7 +1409,7 @@ const data = solanaWeb3_js.Buffer.alloc(solanaRouters.solana.api.routeSol.layout.span); solanaRouters.solana.api.routeSol.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeSol.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new solanaWeb3_js.BN(paymentRoute.toAmount.toString()), feeAmount: new solanaWeb3_js.BN((paymentRoute.feeAmount || '0').toString()), deadline: new solanaWeb3_js.BN(getDeadline()), @@ -1432,7 +1440,7 @@ const data = solanaWeb3_js.Buffer.alloc(solanaRouters.solana.api.routeToken.layout.span); solanaRouters.solana.api.routeToken.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeToken.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new solanaWeb3_js.BN(paymentRoute.toAmount.toString()), feeAmount: new solanaWeb3_js.BN((paymentRoute.feeAmount || '0').toString()), deadline: new solanaWeb3_js.BN(getDeadline()), @@ -1500,7 +1508,7 @@ const data = solanaWeb3_js.Buffer.alloc(solanaRouters.solana.api.routeOrcaSwap.layout.span); solanaRouters.solana.api.routeOrcaSwap.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -1574,7 +1582,7 @@ const data = solanaWeb3_js.Buffer.alloc(solanaRouters.solana.api.routeOrcaSwapSolOut.layout.span); solanaRouters.solana.api.routeOrcaSwapSolOut.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -1665,7 +1673,7 @@ const data = solanaWeb3_js.Buffer.alloc(solanaRouters.solana.api.routeOrcaTwoHopSwap.layout.span); solanaRouters.solana.api.routeOrcaTwoHopSwap.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaTwoHopSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -1759,7 +1767,7 @@ const data = solanaWeb3_js.Buffer.alloc(solanaRouters.solana.api.routeOrcaTwoHopSwapSolOut.layout.span); solanaRouters.solana.api.routeOrcaTwoHopSwapSolOut.layout.encode({ anchorDiscriminator: solanaRouters.solana.api.routeOrcaTwoHopSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -1837,6 +1845,7 @@ // debug(transaction, paymentRoute) transaction.deadline = currentDeadline; + transaction.nonce = currentNonce.toString(); return transaction }; diff --git a/dist/umd/index.solana.js b/dist/umd/index.solana.js index c2089a5..cee01bb 100644 --- a/dist/umd/index.solana.js +++ b/dist/umd/index.solana.js @@ -2205,6 +2205,7 @@ }; let currentDeadline; + let currentNonce; const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> { @@ -2679,10 +2680,17 @@ }; const getDeadline = ()=>{ + if(currentDeadline) { return currentDeadline } currentDeadline = Math.ceil(new Date().getTime()/1000)+1800; // 30 Minutes (lower causes wallet simulation issues) return currentDeadline }; + const getNonce = (paymentsAccountData)=>{ + if(currentNonce) { return currentNonce } + currentNonce = paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'); + return currentNonce + }; + const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const paymentReceiverPublicKey = new solanaWeb3_js.PublicKey(paymentRoute.toAddress); @@ -2699,7 +2707,7 @@ const data = solanaWeb3_js.Buffer.alloc(routers$1.solana.api.routeSol.layout.span); routers$1.solana.api.routeSol.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeSol.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new solanaWeb3_js.BN(paymentRoute.toAmount.toString()), feeAmount: new solanaWeb3_js.BN((paymentRoute.feeAmount || '0').toString()), deadline: new solanaWeb3_js.BN(getDeadline()), @@ -2730,7 +2738,7 @@ const data = solanaWeb3_js.Buffer.alloc(routers$1.solana.api.routeToken.layout.span); routers$1.solana.api.routeToken.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeToken.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new solanaWeb3_js.BN(paymentRoute.toAmount.toString()), feeAmount: new solanaWeb3_js.BN((paymentRoute.feeAmount || '0').toString()), deadline: new solanaWeb3_js.BN(getDeadline()), @@ -2798,7 +2806,7 @@ const data = solanaWeb3_js.Buffer.alloc(routers$1.solana.api.routeOrcaSwap.layout.span); routers$1.solana.api.routeOrcaSwap.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -2872,7 +2880,7 @@ const data = solanaWeb3_js.Buffer.alloc(routers$1.solana.api.routeOrcaSwapSolOut.layout.span); routers$1.solana.api.routeOrcaSwapSolOut.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -2963,7 +2971,7 @@ const data = solanaWeb3_js.Buffer.alloc(routers$1.solana.api.routeOrcaTwoHopSwap.layout.span); routers$1.solana.api.routeOrcaTwoHopSwap.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaTwoHopSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -3057,7 +3065,7 @@ const data = solanaWeb3_js.Buffer.alloc(routers$1.solana.api.routeOrcaTwoHopSwapSolOut.layout.span); routers$1.solana.api.routeOrcaTwoHopSwapSolOut.layout.encode({ anchorDiscriminator: routers$1.solana.api.routeOrcaTwoHopSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new solanaWeb3_js.BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -3135,6 +3143,7 @@ // debug(transaction, paymentRoute) transaction.deadline = currentDeadline; + transaction.nonce = currentNonce.toString(); return transaction }; diff --git a/package.evm.json b/package.evm.json index 1671efc..560e36b 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-payments-evm", "moduleName": "Web3Payments", - "version": "13.6.8", + "version": "13.6.9", "description": "JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.", "main": "dist/umd/index.evm.js", "module": "dist/esm/index.evm.js", diff --git a/package.json b/package.json index dd30528..c580afd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-payments", "moduleName": "Web3Payments", - "version": "13.6.8", + "version": "13.6.9", "description": "JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index 0783fd3..7c459c7 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-payments-solana", "moduleName": "Web3Payments", - "version": "13.6.8", + "version": "13.6.9", "description": "JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.", "main": "dist/umd/index.solana.js", "module": "dist/esm/index.solana.js", diff --git a/src/platforms/solana/transaction.js b/src/platforms/solana/transaction.js index 124a61e..e3e204b 100644 --- a/src/platforms/solana/transaction.js +++ b/src/platforms/solana/transaction.js @@ -5,6 +5,7 @@ import { request, getProvider } from '@depay/web3-client' import Token from '@depay/web3-tokens' let currentDeadline +let currentNonce const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> { @@ -479,10 +480,17 @@ const getPaymentMethod = ({ paymentRoute })=>{ } const getDeadline = ()=>{ + if(currentDeadline) { return currentDeadline } currentDeadline = Math.ceil(new Date().getTime()/1000)+1800 // 30 Minutes (lower causes wallet simulation issues) return currentDeadline } +const getNonce = (paymentsAccountData)=>{ + if(currentNonce) { return currentNonce } + currentNonce = paymentsAccountData ? paymentsAccountData.nonce : new BN('0') + return currentNonce +} + const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const paymentReceiverPublicKey = new PublicKey(paymentRoute.toAddress) @@ -499,7 +507,7 @@ const routeSol = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(routers.solana.api.routeSol.layout.span) routers.solana.api.routeSol.layout.encode({ anchorDiscriminator: routers.solana.api.routeSol.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -530,7 +538,7 @@ const routeToken = async({ paymentRoute, paymentsAccountData }) =>{ const data = Buffer.alloc(routers.solana.api.routeToken.layout.span) routers.solana.api.routeToken.layout.encode({ anchorDiscriminator: routers.solana.api.routeToken.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), paymentAmount: new BN(paymentRoute.toAmount.toString()), feeAmount: new BN((paymentRoute.feeAmount || '0').toString()), deadline: new BN(getDeadline()), @@ -598,7 +606,7 @@ const routeOrcaSwap = async({ paymentRoute, paymentsAccountData, wSolSenderAccou const data = Buffer.alloc(routers.solana.api.routeOrcaSwap.layout.span) routers.solana.api.routeOrcaSwap.layout.encode({ anchorDiscriminator: routers.solana.api.routeOrcaSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -672,7 +680,7 @@ const routeOrcaSwapSolOut = async({ paymentRoute, paymentsAccountData, wSolEscro const data = Buffer.alloc(routers.solana.api.routeOrcaSwapSolOut.layout.span) routers.solana.api.routeOrcaSwapSolOut.layout.encode({ anchorDiscriminator: routers.solana.api.routeOrcaSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, sqrtPriceLimit: exchangeRouteSwapInstructionData.sqrtPriceLimit, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, @@ -763,7 +771,7 @@ const routeOrcaTwoHopSwap = async({ paymentRoute, paymentsAccountData, wSolSende const data = Buffer.alloc(routers.solana.api.routeOrcaTwoHopSwap.layout.span) routers.solana.api.routeOrcaTwoHopSwap.layout.encode({ anchorDiscriminator: routers.solana.api.routeOrcaTwoHopSwap.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -857,7 +865,7 @@ const routeOrcaTwoHopSwapSolOut = async({ paymentRoute, paymentsAccountData, wSo const data = Buffer.alloc(routers.solana.api.routeOrcaTwoHopSwapSolOut.layout.span) routers.solana.api.routeOrcaTwoHopSwapSolOut.layout.encode({ anchorDiscriminator: routers.solana.api.routeOrcaTwoHopSwapSolOut.anchorDiscriminator, - nonce: paymentsAccountData ? paymentsAccountData.nonce : new BN('0'), + nonce: getNonce(paymentsAccountData), amountIn: exchangeRouteSwapInstructionData.amount, amountSpecifiedIsInput: exchangeRouteSwapInstructionData.amountSpecifiedIsInput, aToBOne: exchangeRouteSwapInstructionData.aToBOne, @@ -935,6 +943,7 @@ const getTransaction = async({ paymentRoute })=> { // debug(transaction, paymentRoute) transaction.deadline = currentDeadline + transaction.nonce = currentNonce.toString() return transaction }