@mayanfinance/swap-sdk
Advanced tools
Comparing version 3.3.0 to 4.0.0
define(['exports','cross-fetch','@ethersproject/bytes','ethers','@solana/web3.js','buffer','js-sha3','@solana/buffer-layout'],(function(exports,fetch,bytes,ethers,web3_js,buffer,jsSha3,bufferLayout){'use strict';var addresses = { | ||
"MAYAN_PROGRAM_ID": "9N34KcQXfKjCQcyAXkuCoGgixfi1dj53LtsfFrcBdjNh", | ||
"AUCTION_PROGRAM_ID": "Gqjr8NdrykXUrpPFzZDzsHDNK3NUd3gNhXzgzAvXK2Nh", | ||
"MAYAN_EVM_CONTRACT": "0xB663E1Fc039F83e2dd3Df16f52CB203d615272f5", | ||
"MAYAN_L2_CONTRACT": "0xa2e9add1A212649F06efc21cFa4D7555748d5E40", | ||
"MAYAN_PROGRAM_ID": "8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E", | ||
"AUCTION_PROGRAM_ID": "4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy", | ||
"MAYAN_EVM_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"MAYAN_L2_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"TOKEN_PROGRAM_ID": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", | ||
"ASSOCIATED_TOKEN_PROGRAM_ID": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v2", | ||
"PRICE_URL": "https://price-api.mayan.finance/v2" | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v3", | ||
"PRICE_URL": "https://price-api.mayan.finance/v3" | ||
};const isValidAptosType = (str) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(str); | ||
@@ -75,3 +75,3 @@ function nativeAddressToHexString(address, wChainId) { | ||
} | ||
const sdkVersion = [3, 3, 0]; | ||
const sdkVersion = [4, 0, 0]; | ||
function checkSdkVersionSupport(minimumVersion) { | ||
@@ -97,2 +97,14 @@ //major | ||
return false; | ||
} | ||
function getGasDecimal(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 18; | ||
} | ||
function getGasDecimalsInSolana(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 8; | ||
}async function fetchAllTokenList() { | ||
@@ -118,9 +130,7 @@ const res = await fetch(`${addresses.PRICE_URL}/tokens`, { | ||
async function fetchQuote(params) { | ||
const { customRelayerFees: relayerFees, withReferrer } = params; | ||
const { withReferrer, gasDrop } = params; | ||
const normalizedSlippage = params.slippage / 100; | ||
const baseUrl = `${addresses.PRICE_URL}/quote?`; | ||
const basicQueries = `amountIn=${params.amount}&fromToken=${params.fromToken}&fromChain=${params.fromChain}&toToken=${params.toToken}&toChain=${params.toChain}`; | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}` + (relayerFees ? | ||
`&swapRelayerFee=${relayerFees.swapRelayerFee}&redeemRelayerFee=${relayerFees.redeemRelayerFee}&refundRelayerFee=${relayerFees.refundRelayerFee}` : | ||
''); | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}${gasDrop ? `&gasDrop=${gasDrop}` : ''}`; | ||
const url = baseUrl + basicQueries + criteriaQueries; | ||
@@ -357,2 +367,7 @@ const res = await fetch(url, { | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
} | ||
@@ -378,3 +393,3 @@ ], | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"stateMutability": "payable", | ||
"type": "function" | ||
@@ -484,2 +499,7 @@ }, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -651,2 +671,7 @@ "name": "unwrap", | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -716,2 +741,3 @@ "name": "unwrap", | ||
amountOutMin: getAmountOfFractionalAmount(quote.minAmountOut, Math.min(8, quote.toToken.decimals)), | ||
gasDrop: getAmountOfFractionalAmount(quote.gasDrop, Math.min(8, getGasDecimal(quote.toChain))), | ||
nonce: createNonce().readUInt32LE(0), | ||
@@ -751,3 +777,3 @@ unwrap: unwrapRedeem, | ||
return nonceBuffer; | ||
}const STATE_SIZE = 340; | ||
}const STATE_SIZE = 348; | ||
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID), associatedTokenProgramId = new web3_js.PublicKey(addresses.ASSOCIATED_TOKEN_PROGRAM_ID)) { | ||
@@ -837,2 +863,3 @@ const keys = [ | ||
bufferLayout.nu64('feeCancel'), | ||
bufferLayout.nu64('gasDrop'), | ||
bufferLayout.u16('destinationChain'), | ||
@@ -924,2 +951,3 @@ bufferLayout.blob(32, 'destinationAddress'), | ||
const feeCancel = getAmountOfFractionalAmount(quote.refundRelayerFee, quote.mintDecimals.from); | ||
const gasDrop = getAmountOfFractionalAmount(quote.gasDrop, getGasDecimalsInSolana(quote.toChain)); | ||
const unwrapRedeem = quote.toToken.contract === ethers.ethers.constants.AddressZero; | ||
@@ -938,2 +966,3 @@ const unwrapRefund = quote.fromToken.contract === ethers.ethers.constants.AddressZero; | ||
feeCancel, | ||
gasDrop, | ||
destinationChain: destinationChainId, | ||
@@ -940,0 +969,0 @@ destinationAddress: destAddress, |
'use strict';var fetch=require('cross-fetch'),bytes=require('@ethersproject/bytes'),ethers=require('ethers'),web3_js=require('@solana/web3.js'),buffer=require('buffer'),jsSha3=require('js-sha3'),bufferLayout=require('@solana/buffer-layout');var addresses = { | ||
"MAYAN_PROGRAM_ID": "9N34KcQXfKjCQcyAXkuCoGgixfi1dj53LtsfFrcBdjNh", | ||
"AUCTION_PROGRAM_ID": "Gqjr8NdrykXUrpPFzZDzsHDNK3NUd3gNhXzgzAvXK2Nh", | ||
"MAYAN_EVM_CONTRACT": "0xB663E1Fc039F83e2dd3Df16f52CB203d615272f5", | ||
"MAYAN_L2_CONTRACT": "0xa2e9add1A212649F06efc21cFa4D7555748d5E40", | ||
"MAYAN_PROGRAM_ID": "8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E", | ||
"AUCTION_PROGRAM_ID": "4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy", | ||
"MAYAN_EVM_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"MAYAN_L2_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"TOKEN_PROGRAM_ID": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", | ||
"ASSOCIATED_TOKEN_PROGRAM_ID": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v2", | ||
"PRICE_URL": "https://price-api.mayan.finance/v2" | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v3", | ||
"PRICE_URL": "https://price-api.mayan.finance/v3" | ||
};const isValidAptosType = (str) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(str); | ||
@@ -75,3 +75,3 @@ function nativeAddressToHexString(address, wChainId) { | ||
} | ||
const sdkVersion = [3, 3, 0]; | ||
const sdkVersion = [4, 0, 0]; | ||
function checkSdkVersionSupport(minimumVersion) { | ||
@@ -97,2 +97,14 @@ //major | ||
return false; | ||
} | ||
function getGasDecimal(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 18; | ||
} | ||
function getGasDecimalsInSolana(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 8; | ||
}async function fetchAllTokenList() { | ||
@@ -118,9 +130,7 @@ const res = await fetch(`${addresses.PRICE_URL}/tokens`, { | ||
async function fetchQuote(params) { | ||
const { customRelayerFees: relayerFees, withReferrer } = params; | ||
const { withReferrer, gasDrop } = params; | ||
const normalizedSlippage = params.slippage / 100; | ||
const baseUrl = `${addresses.PRICE_URL}/quote?`; | ||
const basicQueries = `amountIn=${params.amount}&fromToken=${params.fromToken}&fromChain=${params.fromChain}&toToken=${params.toToken}&toChain=${params.toChain}`; | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}` + (relayerFees ? | ||
`&swapRelayerFee=${relayerFees.swapRelayerFee}&redeemRelayerFee=${relayerFees.redeemRelayerFee}&refundRelayerFee=${relayerFees.refundRelayerFee}` : | ||
''); | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}${gasDrop ? `&gasDrop=${gasDrop}` : ''}`; | ||
const url = baseUrl + basicQueries + criteriaQueries; | ||
@@ -357,2 +367,7 @@ const res = await fetch(url, { | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
} | ||
@@ -378,3 +393,3 @@ ], | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"stateMutability": "payable", | ||
"type": "function" | ||
@@ -484,2 +499,7 @@ }, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -651,2 +671,7 @@ "name": "unwrap", | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -716,2 +741,3 @@ "name": "unwrap", | ||
amountOutMin: getAmountOfFractionalAmount(quote.minAmountOut, Math.min(8, quote.toToken.decimals)), | ||
gasDrop: getAmountOfFractionalAmount(quote.gasDrop, Math.min(8, getGasDecimal(quote.toChain))), | ||
nonce: createNonce().readUInt32LE(0), | ||
@@ -751,3 +777,3 @@ unwrap: unwrapRedeem, | ||
return nonceBuffer; | ||
}const STATE_SIZE = 340; | ||
}const STATE_SIZE = 348; | ||
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID), associatedTokenProgramId = new web3_js.PublicKey(addresses.ASSOCIATED_TOKEN_PROGRAM_ID)) { | ||
@@ -837,2 +863,3 @@ const keys = [ | ||
bufferLayout.nu64('feeCancel'), | ||
bufferLayout.nu64('gasDrop'), | ||
bufferLayout.u16('destinationChain'), | ||
@@ -924,2 +951,3 @@ bufferLayout.blob(32, 'destinationAddress'), | ||
const feeCancel = getAmountOfFractionalAmount(quote.refundRelayerFee, quote.mintDecimals.from); | ||
const gasDrop = getAmountOfFractionalAmount(quote.gasDrop, getGasDecimalsInSolana(quote.toChain)); | ||
const unwrapRedeem = quote.toToken.contract === ethers.ethers.constants.AddressZero; | ||
@@ -938,2 +966,3 @@ const unwrapRefund = quote.fromToken.contract === ethers.ethers.constants.AddressZero; | ||
feeCancel, | ||
gasDrop, | ||
destinationChain: destinationChainId, | ||
@@ -940,0 +969,0 @@ destinationAddress: destAddress, |
@@ -26,8 +26,4 @@ import { Transaction, Connection, PublicKey } from '@solana/web3.js'; | ||
slippage: number; | ||
gasDrop?: number; | ||
withReferrer?: boolean; | ||
customRelayerFees?: { | ||
swapRelayerFee: number; | ||
redeemRelayerFee: number; | ||
refundRelayerFee: number; | ||
}; | ||
}; | ||
@@ -43,2 +39,3 @@ type QuoteError = { | ||
minAmountOut: number; | ||
gasDrop: number; | ||
price: number; | ||
@@ -55,4 +52,4 @@ route: Array<{ | ||
toToken: Token; | ||
fromChain: string; | ||
toChain: string; | ||
fromChain: ChainName; | ||
toChain: ChainName; | ||
mintDecimals: { | ||
@@ -81,2 +78,3 @@ from: number; | ||
amountOutMin: ethers.BigNumber; | ||
gasDrop: ethers.BigNumber; | ||
nonce: number; | ||
@@ -83,0 +81,0 @@ unwrap: boolean; |
import fetch from'cross-fetch';import {zeroPad}from'@ethersproject/bytes';import {ethers}from'ethers';import {PublicKey,Connection,Keypair,Transaction,SystemProgram,SYSVAR_CLOCK_PUBKEY,SYSVAR_RENT_PUBKEY,TransactionInstruction}from'@solana/web3.js';import {Buffer as Buffer$1}from'buffer';import {sha3_256}from'js-sha3';import {struct,u8,nu64,u16,blob}from'@solana/buffer-layout';var addresses = { | ||
"MAYAN_PROGRAM_ID": "9N34KcQXfKjCQcyAXkuCoGgixfi1dj53LtsfFrcBdjNh", | ||
"AUCTION_PROGRAM_ID": "Gqjr8NdrykXUrpPFzZDzsHDNK3NUd3gNhXzgzAvXK2Nh", | ||
"MAYAN_EVM_CONTRACT": "0xB663E1Fc039F83e2dd3Df16f52CB203d615272f5", | ||
"MAYAN_L2_CONTRACT": "0xa2e9add1A212649F06efc21cFa4D7555748d5E40", | ||
"MAYAN_PROGRAM_ID": "8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E", | ||
"AUCTION_PROGRAM_ID": "4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy", | ||
"MAYAN_EVM_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"MAYAN_L2_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"TOKEN_PROGRAM_ID": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", | ||
"ASSOCIATED_TOKEN_PROGRAM_ID": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v2", | ||
"PRICE_URL": "https://price-api.mayan.finance/v2" | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v3", | ||
"PRICE_URL": "https://price-api.mayan.finance/v3" | ||
};const isValidAptosType = (str) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(str); | ||
@@ -75,3 +75,3 @@ function nativeAddressToHexString(address, wChainId) { | ||
} | ||
const sdkVersion = [3, 3, 0]; | ||
const sdkVersion = [4, 0, 0]; | ||
function checkSdkVersionSupport(minimumVersion) { | ||
@@ -97,2 +97,14 @@ //major | ||
return false; | ||
} | ||
function getGasDecimal(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 18; | ||
} | ||
function getGasDecimalsInSolana(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 8; | ||
}async function fetchAllTokenList() { | ||
@@ -118,9 +130,7 @@ const res = await fetch(`${addresses.PRICE_URL}/tokens`, { | ||
async function fetchQuote(params) { | ||
const { customRelayerFees: relayerFees, withReferrer } = params; | ||
const { withReferrer, gasDrop } = params; | ||
const normalizedSlippage = params.slippage / 100; | ||
const baseUrl = `${addresses.PRICE_URL}/quote?`; | ||
const basicQueries = `amountIn=${params.amount}&fromToken=${params.fromToken}&fromChain=${params.fromChain}&toToken=${params.toToken}&toChain=${params.toChain}`; | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}` + (relayerFees ? | ||
`&swapRelayerFee=${relayerFees.swapRelayerFee}&redeemRelayerFee=${relayerFees.redeemRelayerFee}&refundRelayerFee=${relayerFees.refundRelayerFee}` : | ||
''); | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}${gasDrop ? `&gasDrop=${gasDrop}` : ''}`; | ||
const url = baseUrl + basicQueries + criteriaQueries; | ||
@@ -357,2 +367,7 @@ const res = await fetch(url, { | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
} | ||
@@ -378,3 +393,3 @@ ], | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"stateMutability": "payable", | ||
"type": "function" | ||
@@ -484,2 +499,7 @@ }, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -651,2 +671,7 @@ "name": "unwrap", | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -716,2 +741,3 @@ "name": "unwrap", | ||
amountOutMin: getAmountOfFractionalAmount(quote.minAmountOut, Math.min(8, quote.toToken.decimals)), | ||
gasDrop: getAmountOfFractionalAmount(quote.gasDrop, Math.min(8, getGasDecimal(quote.toChain))), | ||
nonce: createNonce().readUInt32LE(0), | ||
@@ -751,3 +777,3 @@ unwrap: unwrapRedeem, | ||
return nonceBuffer; | ||
}const STATE_SIZE = 340; | ||
}const STATE_SIZE = 348; | ||
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = new PublicKey(addresses.TOKEN_PROGRAM_ID), associatedTokenProgramId = new PublicKey(addresses.ASSOCIATED_TOKEN_PROGRAM_ID)) { | ||
@@ -837,2 +863,3 @@ const keys = [ | ||
nu64('feeCancel'), | ||
nu64('gasDrop'), | ||
u16('destinationChain'), | ||
@@ -924,2 +951,3 @@ blob(32, 'destinationAddress'), | ||
const feeCancel = getAmountOfFractionalAmount(quote.refundRelayerFee, quote.mintDecimals.from); | ||
const gasDrop = getAmountOfFractionalAmount(quote.gasDrop, getGasDecimalsInSolana(quote.toChain)); | ||
const unwrapRedeem = quote.toToken.contract === ethers.constants.AddressZero; | ||
@@ -938,2 +966,3 @@ const unwrapRefund = quote.fromToken.contract === ethers.constants.AddressZero; | ||
feeCancel, | ||
gasDrop, | ||
destinationChain: destinationChainId, | ||
@@ -940,0 +969,0 @@ destinationAddress: destAddress, |
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports,require('cross-fetch'),require('@ethersproject/bytes'),require('ethers'),require('@solana/web3.js'),require('buffer'),require('js-sha3'),require('@solana/buffer-layout')):typeof define==='function'&&define.amd?define(['exports','cross-fetch','@ethersproject/bytes','ethers','@solana/web3.js','buffer','js-sha3','@solana/buffer-layout'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.MAYAN={},g.fetch,g.bytes,g.ethers,g.web3_js,g.buffer,g.jsSha3,g.bufferLayout));})(this,(function(exports,fetch,bytes,ethers,web3_js,buffer,jsSha3,bufferLayout){'use strict';var addresses = { | ||
"MAYAN_PROGRAM_ID": "9N34KcQXfKjCQcyAXkuCoGgixfi1dj53LtsfFrcBdjNh", | ||
"AUCTION_PROGRAM_ID": "Gqjr8NdrykXUrpPFzZDzsHDNK3NUd3gNhXzgzAvXK2Nh", | ||
"MAYAN_EVM_CONTRACT": "0xB663E1Fc039F83e2dd3Df16f52CB203d615272f5", | ||
"MAYAN_L2_CONTRACT": "0xa2e9add1A212649F06efc21cFa4D7555748d5E40", | ||
"MAYAN_PROGRAM_ID": "8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E", | ||
"AUCTION_PROGRAM_ID": "4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy", | ||
"MAYAN_EVM_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"MAYAN_L2_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"TOKEN_PROGRAM_ID": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", | ||
"ASSOCIATED_TOKEN_PROGRAM_ID": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v2", | ||
"PRICE_URL": "https://price-api.mayan.finance/v2" | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v3", | ||
"PRICE_URL": "https://price-api.mayan.finance/v3" | ||
};const isValidAptosType = (str) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(str); | ||
@@ -75,3 +75,3 @@ function nativeAddressToHexString(address, wChainId) { | ||
} | ||
const sdkVersion = [3, 3, 0]; | ||
const sdkVersion = [4, 0, 0]; | ||
function checkSdkVersionSupport(minimumVersion) { | ||
@@ -97,2 +97,14 @@ //major | ||
return false; | ||
} | ||
function getGasDecimal(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 18; | ||
} | ||
function getGasDecimalsInSolana(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 8; | ||
}async function fetchAllTokenList() { | ||
@@ -118,9 +130,7 @@ const res = await fetch(`${addresses.PRICE_URL}/tokens`, { | ||
async function fetchQuote(params) { | ||
const { customRelayerFees: relayerFees, withReferrer } = params; | ||
const { withReferrer, gasDrop } = params; | ||
const normalizedSlippage = params.slippage / 100; | ||
const baseUrl = `${addresses.PRICE_URL}/quote?`; | ||
const basicQueries = `amountIn=${params.amount}&fromToken=${params.fromToken}&fromChain=${params.fromChain}&toToken=${params.toToken}&toChain=${params.toChain}`; | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}` + (relayerFees ? | ||
`&swapRelayerFee=${relayerFees.swapRelayerFee}&redeemRelayerFee=${relayerFees.redeemRelayerFee}&refundRelayerFee=${relayerFees.refundRelayerFee}` : | ||
''); | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}${gasDrop ? `&gasDrop=${gasDrop}` : ''}`; | ||
const url = baseUrl + basicQueries + criteriaQueries; | ||
@@ -357,2 +367,7 @@ const res = await fetch(url, { | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
} | ||
@@ -378,3 +393,3 @@ ], | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"stateMutability": "payable", | ||
"type": "function" | ||
@@ -484,2 +499,7 @@ }, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -651,2 +671,7 @@ "name": "unwrap", | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -716,2 +741,3 @@ "name": "unwrap", | ||
amountOutMin: getAmountOfFractionalAmount(quote.minAmountOut, Math.min(8, quote.toToken.decimals)), | ||
gasDrop: getAmountOfFractionalAmount(quote.gasDrop, Math.min(8, getGasDecimal(quote.toChain))), | ||
nonce: createNonce().readUInt32LE(0), | ||
@@ -751,3 +777,3 @@ unwrap: unwrapRedeem, | ||
return nonceBuffer; | ||
}const STATE_SIZE = 340; | ||
}const STATE_SIZE = 348; | ||
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID), associatedTokenProgramId = new web3_js.PublicKey(addresses.ASSOCIATED_TOKEN_PROGRAM_ID)) { | ||
@@ -837,2 +863,3 @@ const keys = [ | ||
bufferLayout.nu64('feeCancel'), | ||
bufferLayout.nu64('gasDrop'), | ||
bufferLayout.u16('destinationChain'), | ||
@@ -924,2 +951,3 @@ bufferLayout.blob(32, 'destinationAddress'), | ||
const feeCancel = getAmountOfFractionalAmount(quote.refundRelayerFee, quote.mintDecimals.from); | ||
const gasDrop = getAmountOfFractionalAmount(quote.gasDrop, getGasDecimalsInSolana(quote.toChain)); | ||
const unwrapRedeem = quote.toToken.contract === ethers.ethers.constants.AddressZero; | ||
@@ -938,2 +966,3 @@ const unwrapRefund = quote.fromToken.contract === ethers.ethers.constants.AddressZero; | ||
feeCancel, | ||
gasDrop, | ||
destinationChain: destinationChainId, | ||
@@ -940,0 +969,0 @@ destinationAddress: destAddress, |
export default { | ||
"MAYAN_PROGRAM_ID": "9N34KcQXfKjCQcyAXkuCoGgixfi1dj53LtsfFrcBdjNh", | ||
"AUCTION_PROGRAM_ID": "Gqjr8NdrykXUrpPFzZDzsHDNK3NUd3gNhXzgzAvXK2Nh", | ||
"MAYAN_EVM_CONTRACT": "0xB663E1Fc039F83e2dd3Df16f52CB203d615272f5", | ||
"MAYAN_L2_CONTRACT": "0xa2e9add1A212649F06efc21cFa4D7555748d5E40", | ||
"MAYAN_PROGRAM_ID": "8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E", | ||
"AUCTION_PROGRAM_ID": "4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy", | ||
"MAYAN_EVM_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"MAYAN_L2_CONTRACT": "0x80F53dcf568bE566F99Ab9F37eaa2B3AA10B3C95", | ||
"TOKEN_PROGRAM_ID": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", | ||
"ASSOCIATED_TOKEN_PROGRAM_ID": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v2", | ||
"PRICE_URL": "https://price-api.mayan.finance/v2" | ||
"EXPLORER_URL": "https://explorer-api.mayan.finance/v3", | ||
"PRICE_URL": "https://price-api.mayan.finance/v3" | ||
}; |
@@ -24,9 +24,7 @@ import fetch from 'cross-fetch'; | ||
export async function fetchQuote(params) { | ||
const { customRelayerFees: relayerFees, withReferrer } = params; | ||
const { withReferrer, gasDrop } = params; | ||
const normalizedSlippage = params.slippage / 100; | ||
const baseUrl = `${addresses.PRICE_URL}/quote?`; | ||
const basicQueries = `amountIn=${params.amount}&fromToken=${params.fromToken}&fromChain=${params.fromChain}&toToken=${params.toToken}&toChain=${params.toChain}`; | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}` + (relayerFees ? | ||
`&swapRelayerFee=${relayerFees.swapRelayerFee}&redeemRelayerFee=${relayerFees.redeemRelayerFee}&refundRelayerFee=${relayerFees.refundRelayerFee}` : | ||
''); | ||
const criteriaQueries = `&slippage=${normalizedSlippage}&withReferrer=${!!withReferrer}${gasDrop ? `&gasDrop=${gasDrop}` : ''}`; | ||
const url = baseUrl + basicQueries + criteriaQueries; | ||
@@ -33,0 +31,0 @@ const res = await fetch(url, { |
@@ -13,2 +13,3 @@ import { ethers, Overrides, Signer } from 'ethers'; | ||
amountOutMin: ethers.BigNumber; | ||
gasDrop: ethers.BigNumber; | ||
nonce: number; | ||
@@ -15,0 +16,0 @@ unwrap: boolean; |
import { ethers } from 'ethers'; | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { getCurrentEvmTime, getAssociatedTokenAddress, nativeAddressToHexString, getAmountOfFractionalAmount, getWormholeChainIdByName, getWormholeChainIdById, } from './utils'; | ||
import { getCurrentEvmTime, getAssociatedTokenAddress, nativeAddressToHexString, getAmountOfFractionalAmount, getWormholeChainIdByName, getWormholeChainIdById, getGasDecimal } from './utils'; | ||
import { getCurrentSolanaTime } from './api'; | ||
@@ -40,2 +40,3 @@ import MayanSwapArtifact from './MayanSwapArtifact'; | ||
amountOutMin: getAmountOfFractionalAmount(quote.minAmountOut, Math.min(8, quote.toToken.decimals)), | ||
gasDrop: getAmountOfFractionalAmount(quote.gasDrop, Math.min(8, getGasDecimal(quote.toChain))), | ||
nonce: createNonce().readUInt32LE(0), | ||
@@ -42,0 +43,0 @@ unwrap: unwrapRedeem, |
@@ -202,2 +202,7 @@ export default { | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
} | ||
@@ -223,3 +228,3 @@ ], | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"stateMutability": "payable", | ||
"type": "function" | ||
@@ -329,2 +334,7 @@ }, | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -496,2 +506,7 @@ "name": "unwrap", | ||
{ | ||
"internalType": "uint64", | ||
"name": "gasDrop", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
@@ -498,0 +513,0 @@ "name": "unwrap", |
import { Connection, PublicKey, Keypair, SystemProgram, SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction, } from '@solana/web3.js'; | ||
import { blob, nu64, struct, u16, u8 } from '@solana/buffer-layout'; | ||
import { getAmountOfFractionalAmount, getAssociatedTokenAddress, getWormholeChainIdByName, hexToUint8Array, nativeAddressToHexString } from './utils'; | ||
import { getAmountOfFractionalAmount, getAssociatedTokenAddress, getGasDecimalsInSolana, getWormholeChainIdByName, hexToUint8Array, nativeAddressToHexString } from './utils'; | ||
import { Buffer } from 'buffer'; | ||
@@ -8,3 +8,3 @@ import addresses from './addresses'; | ||
import { getCurrentSolanaTime } from './api'; | ||
const STATE_SIZE = 340; | ||
const STATE_SIZE = 348; | ||
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = new PublicKey(addresses.TOKEN_PROGRAM_ID), associatedTokenProgramId = new PublicKey(addresses.ASSOCIATED_TOKEN_PROGRAM_ID)) { | ||
@@ -94,2 +94,3 @@ const keys = [ | ||
nu64('feeCancel'), | ||
nu64('gasDrop'), | ||
u16('destinationChain'), | ||
@@ -181,2 +182,3 @@ blob(32, 'destinationAddress'), | ||
const feeCancel = getAmountOfFractionalAmount(quote.refundRelayerFee, quote.mintDecimals.from); | ||
const gasDrop = getAmountOfFractionalAmount(quote.gasDrop, getGasDecimalsInSolana(quote.toChain)); | ||
const unwrapRedeem = quote.toToken.contract === ethers.constants.AddressZero; | ||
@@ -195,2 +197,3 @@ const unwrapRefund = quote.fromToken.contract === ethers.constants.AddressZero; | ||
feeCancel, | ||
gasDrop, | ||
destinationChain: destinationChainId, | ||
@@ -197,0 +200,0 @@ destinationAddress: destAddress, |
@@ -23,8 +23,4 @@ import { Transaction } from '@solana/web3.js'; | ||
slippage: number; | ||
gasDrop?: number; | ||
withReferrer?: boolean; | ||
customRelayerFees?: { | ||
swapRelayerFee: number; | ||
redeemRelayerFee: number; | ||
refundRelayerFee: number; | ||
}; | ||
}; | ||
@@ -40,2 +36,3 @@ export type QuoteError = { | ||
minAmountOut: number; | ||
gasDrop: number; | ||
price: number; | ||
@@ -52,4 +49,4 @@ route: Array<{ | ||
toToken: Token; | ||
fromChain: string; | ||
toChain: string; | ||
fromChain: ChainName; | ||
toChain: ChainName; | ||
mintDecimals: { | ||
@@ -56,0 +53,0 @@ from: number; |
import { ethers } from 'ethers'; | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { ChainName } from './types'; | ||
export declare const isValidAptosType: (str: string) => boolean; | ||
@@ -13,1 +14,3 @@ export declare function nativeAddressToHexString(address: string, wChainId: number): string; | ||
export declare function checkSdkVersionSupport(minimumVersion: [number, number, number]): boolean; | ||
export declare function getGasDecimal(chain: ChainName): number; | ||
export declare function getGasDecimalsInSolana(chain: ChainName): number; |
@@ -75,3 +75,3 @@ import { zeroPad } from '@ethersproject/bytes'; | ||
} | ||
const sdkVersion = [3, 3, 0]; | ||
const sdkVersion = [4, 0, 0]; | ||
export function checkSdkVersionSupport(minimumVersion) { | ||
@@ -98,1 +98,13 @@ //major | ||
} | ||
export function getGasDecimal(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 18; | ||
} | ||
export function getGasDecimalsInSolana(chain) { | ||
if (chain === 'solana') { | ||
return 9; | ||
} | ||
return 8; | ||
} |
{ | ||
"name": "@mayanfinance/swap-sdk", | ||
"description": "A SDK to swap with Mayan", | ||
"version": "3.3.0", | ||
"version": "4.0.0", | ||
"source": "src/main.ts", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223095
5395