Skip to content

Commit

Permalink
v13.6.9: pass down used nonce as part of the transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Dec 30, 2023
1 parent b7c5738 commit 0acce83
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 45 deletions.
21 changes: 15 additions & 6 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -44596,6 +44596,7 @@ Token.solana = {
};

let currentDeadline;
let currentNonce;

const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> {

Expand Down Expand Up @@ -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);
Expand All @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -45526,6 +45534,7 @@ const getTransaction$3 = async({ paymentRoute })=> {
// debug(transaction, paymentRoute)

transaction.deadline = currentDeadline;
transaction.nonce = currentNonce.toString();

return transaction
};
Expand Down
21 changes: 15 additions & 6 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ const request = async function (url, options) {
};

let currentDeadline;
let currentNonce;

const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> {

Expand Down Expand Up @@ -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);
Expand All @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1832,6 +1840,7 @@ const getTransaction$3 = async({ paymentRoute })=> {
// debug(transaction, paymentRoute)

transaction.deadline = currentDeadline;
transaction.nonce = currentNonce.toString();

return transaction
};
Expand Down
21 changes: 15 additions & 6 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,7 @@ Token.solana = {
};

let currentDeadline;
let currentNonce;

const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> {

Expand Down Expand Up @@ -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);
Expand All @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -3130,6 +3138,7 @@ const getTransaction$2 = async({ paymentRoute })=> {
// debug(transaction, paymentRoute)

transaction.deadline = currentDeadline;
transaction.nonce = currentNonce.toString();

return transaction
};
Expand Down
21 changes: 15 additions & 6 deletions dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -44602,6 +44602,7 @@
};

let currentDeadline;
let currentNonce;

const getWSolSenderAccountKeypairIfNeeded = async ({ paymentRoute })=> {

Expand Down Expand Up @@ -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);
Expand All @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -45532,6 +45540,7 @@
// debug(transaction, paymentRoute)

transaction.deadline = currentDeadline;
transaction.nonce = currentNonce.toString();

return transaction
};
Expand Down
Loading

0 comments on commit 0acce83

Please sign in to comment.