@depay/web3-payments-evm
Version:
JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.
1,400 lines (1,328 loc) • 165 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@depay/web3-exchanges-svm'), require('@depay/web3-tokens-svm'), require('@depay/web3-blockchains'), require('ethers'), require('@depay/solana-web3.js'), require('@depay/web3-client')) :
typeof define === 'function' && define.amd ? define(['exports', '@depay/web3-exchanges-svm', '@depay/web3-tokens-svm', '@depay/web3-blockchains', 'ethers', '@depay/solana-web3.js', '@depay/web3-client'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Web3Payments = {}, global.Web3Exchanges, global.Web3Tokens, global.Web3Blockchains, global.ethers, global.SolanaWeb3js, global.Web3Client));
})(this, (function (exports, Exchanges, Token$1, Blockchains, ethers, solanaWeb3_js, web3Client) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var Exchanges__default = /*#__PURE__*/_interopDefaultLegacy(Exchanges);
var Token__default = /*#__PURE__*/_interopDefaultLegacy(Token$1);
var Blockchains__default = /*#__PURE__*/_interopDefaultLegacy(Blockchains);
const config = {
endpoints: {
routesBest: 'https://public.depay.com/routes/best'
}
};
const API = [{"inputs":[{"internalType":"address","name":"_PERMIT2","type":"address"},{"internalType":"address","name":"_FORWARDER","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ExchangeCallFailed","type":"error"},{"inputs":[],"name":"ExchangeCallMissing","type":"error"},{"inputs":[],"name":"ExchangeNotApproved","type":"error"},{"inputs":[],"name":"ForwardingPaymentFailed","type":"error"},{"inputs":[],"name":"InsufficientBalanceInAfterPayment","type":"error"},{"inputs":[],"name":"InsufficientBalanceOutAfterPayment","type":"error"},{"inputs":[],"name":"InsufficientProtocolAmount","type":"error"},{"inputs":[],"name":"NativeFeePaymentFailed","type":"error"},{"inputs":[],"name":"NativePaymentFailed","type":"error"},{"inputs":[],"name":"PaymentDeadlineReached","type":"error"},{"inputs":[],"name":"PaymentToZeroAddressNotAllowed","type":"error"},{"inputs":[],"name":"WrongAmountPaidIn","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"exchange","type":"address"}],"name":"Disabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"exchange","type":"address"}],"name":"Enabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"deadline","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"paymentAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount2","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"slippageInAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"slippageOutAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenInAddress","type":"address"},{"indexed":false,"internalType":"address","name":"tokenOutAddress","type":"address"},{"indexed":false,"internalType":"address","name":"feeReceiverAddress","type":"address"},{"indexed":false,"internalType":"address","name":"feeReceiverAddress2","type":"address"}],"name":"Payment","type":"event"},{"inputs":[],"name":"FORWARDER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"exchange","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"enable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"exchanges","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"paymentAmount","type":"uint256"},{"internalType":"uint256","name":"feeAmount","type":"uint256"},{"internalType":"uint256","name":"feeAmount2","type":"uint256"},{"internalType":"uint256","name":"protocolAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"tokenInAddress","type":"address"},{"internalType":"address","name":"exchangeAddress","type":"address"},{"internalType":"address","name":"tokenOutAddress","type":"address"},{"internalType":"address","name":"paymentReceiverAddress","type":"address"},{"internalType":"address","name":"feeReceiverAddress","type":"address"},{"internalType":"address","name":"feeReceiverAddress2","type":"address"},{"internalType":"uint8","name":"exchangeType","type":"uint8"},{"internalType":"uint8","name":"receiverType","type":"uint8"},{"internalType":"bool","name":"permit2","type":"bool"},{"internalType":"bytes","name":"exchangeCallData","type":"bytes"},{"internalType":"bytes","name":"receiverCallData","type":"bytes"}],"internalType":"struct IDePayRouterV3.Payment","name":"payment","type":"tuple"},{"components":[{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct IPermit2.TokenPermissions","name":"permitted","type":"tuple"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct IPermit2.PermitTransferFrom","name":"permitTransferFrom","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct IDePayRouterV3.PermitTransferFromAndSignature","name":"permitTransferFromAndSignature","type":"tuple"}],"name":"pay","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"paymentAmount","type":"uint256"},{"internalType":"uint256","name":"feeAmount","type":"uint256"},{"internalType":"uint256","name":"feeAmount2","type":"uint256"},{"internalType":"uint256","name":"protocolAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"tokenInAddress","type":"address"},{"internalType":"address","name":"exchangeAddress","type":"address"},{"internalType":"address","name":"tokenOutAddress","type":"address"},{"internalType":"address","name":"paymentReceiverAddress","type":"address"},{"internalType":"address","name":"feeReceiverAddress","type":"address"},{"internalType":"address","name":"feeReceiverAddress2","type":"address"},{"internalType":"uint8","name":"exchangeType","type":"uint8"},{"internalType":"uint8","name":"receiverType","type":"uint8"},{"internalType":"bool","name":"permit2","type":"bool"},{"internalType":"bytes","name":"exchangeCallData","type":"bytes"},{"internalType":"bytes","name":"receiverCallData","type":"bytes"}],"internalType":"struct IDePayRouterV3.Payment","name":"payment","type":"tuple"}],"name":"pay","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"paymentAmount","type":"uint256"},{"internalType":"uint256","name":"feeAmount","type":"uint256"},{"internalType":"uint256","name":"feeAmount2","type":"uint256"},{"internalType":"uint256","name":"protocolAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"tokenInAddress","type":"address"},{"internalType":"address","name":"exchangeAddress","type":"address"},{"internalType":"address","name":"tokenOutAddress","type":"address"},{"internalType":"address","name":"paymentReceiverAddress","type":"address"},{"internalType":"address","name":"feeReceiverAddress","type":"address"},{"internalType":"address","name":"feeReceiverAddress2","type":"address"},{"internalType":"uint8","name":"exchangeType","type":"uint8"},{"internalType":"uint8","name":"receiverType","type":"uint8"},{"internalType":"bool","name":"permit2","type":"bool"},{"internalType":"bytes","name":"exchangeCallData","type":"bytes"},{"internalType":"bytes","name":"receiverCallData","type":"bytes"}],"internalType":"struct IDePayRouterV3.Payment","name":"payment","type":"tuple"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"uint48","name":"expiration","type":"uint48"},{"internalType":"uint48","name":"nonce","type":"uint48"}],"internalType":"struct IPermit2.PermitDetails","name":"details","type":"tuple"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"sigDeadline","type":"uint256"}],"internalType":"struct IPermit2.PermitSingle","name":"permitSingle","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"pay","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}];
var svmRouters = {
ethereum: {
address: '0x365f7B56D2fB16C8Af89D7d33b420E4e013461e8',
api: API
},
bsc: {
address: '0x5F565EDfB9C446976a9F9910631cfeDb6A87220c',
api: API
},
polygon: {
address: '0xe04b08Dfc6CaA0F4Ec523a3Ae283Ece7efE00019',
api: API
},
avalanche: {
address: '0x39E7C98BF4ac3E4C394dD600397f5f7Ee3779BE8',
api: API
},
gnosis: {
address: '0x328FE8bbd30487BB7b5A8eEb909f892E9E229271',
api: API
},
arbitrum: {
address: '0x328FE8bbd30487BB7b5A8eEb909f892E9E229271',
api: API
},
optimism: {
address: '0x558302715e3011Be6695605c11A65526D2ba2245',
api: API
},
base: {
address: '0x48825133EF08327535D0b24d73779E82BE6Ea4d9',
api: API
},
worldchain: {
address: '0x886eb82a7e5E7310F66A0E83748662A17E391eb0',
api: API
},
};
let evmRouters = {};
var routers$1 = {... evmRouters, ...svmRouters};
let supported$1 = ['solana'];
supported$1.evm = [];
supported$1.svm = ['solana'];
let evmGetRouterApprovalTransaction = ()=>{};
let evmGetPermit2ApprovalTransaction = ()=>{};
let evmGetPermit2ApprovalSignature = ()=>{};
const getRouterApprovalTransaction = ({ paymentRoute, options })=>{
if(supported$1.evm.includes(paymentRoute.blockchain)) {
return evmGetRouterApprovalTransaction()
} else if(supported$1.svm.includes(paymentRoute.blockchain)) ; else {
throw('Blockchain not supported!')
}
};
const getPermit2ApprovalTransaction = ({ paymentRoute, options })=>{
if(supported$1.evm.includes(paymentRoute.blockchain)) {
return evmGetPermit2ApprovalTransaction()
} else if(supported$1.svm.includes(paymentRoute.blockchain)) ; else {
throw('Blockchain not supported!')
}
};
const getPermit2ApprovalSignature = ({ paymentRoute, options })=>{
if(supported$1.evm.includes(paymentRoute.blockchain)) {
return evmGetPermit2ApprovalSignature()
} else if(supported$1.svm.includes(paymentRoute.blockchain)) ; else {
throw('Blockchain not supported!')
}
};
var routers = {
solana: {
address: 'DePayR1gQfDmViCPKctnZXNtUgqRwnEqMax8LX9ho1Zg',
exchanges: {
orca: 'whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc',
raydiumCP: 'CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C',
raydiumCL: 'CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK',
},
alt: '8bYq3tcwX1NM2K2JYMjrEqAPtCXFPCjzPazFothc618e',
api: {
createEscrowSolAccount: {
anchorDiscriminator: new solanaWeb3_js.BN("2482112285991870004"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
])
},
createEscrowTokenAccount: {
anchorDiscriminator: new solanaWeb3_js.BN("16156440424245087"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
])
},
routeSol: {
anchorDiscriminator: new solanaWeb3_js.BN("6497164560834983274"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeToken: {
anchorDiscriminator: new solanaWeb3_js.BN("13483873682232752277"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeOrcaSwap: {
anchorDiscriminator: new solanaWeb3_js.BN("9797248061404332986"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.bool("aToB"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeOrcaSwapSolOut: {
anchorDiscriminator: new solanaWeb3_js.BN("13662217913752830165"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.bool("aToB"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeOrcaSwapSolIn: {
anchorDiscriminator: new solanaWeb3_js.BN("16115018480206947614"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.bool("aToB"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeOrcaTwoHopSwap: {
anchorDiscriminator: new solanaWeb3_js.BN("15695720599845325801"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.bool("aToBOne"),
solanaWeb3_js.bool("aToBTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeOrcaTwoHopSwapSolOut: {
anchorDiscriminator: new solanaWeb3_js.BN("15074061855608091530"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.bool("aToBOne"),
solanaWeb3_js.bool("aToBTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeOrcaTwoHopSwapSolIn: {
anchorDiscriminator: new solanaWeb3_js.BN("2678451299937372540"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.bool("aToBOne"),
solanaWeb3_js.bool("aToBTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumClSwap: {
anchorDiscriminator: new solanaWeb3_js.BN("2954182973248174268"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumClSwapSolOut: {
anchorDiscriminator: new solanaWeb3_js.BN("18389700643710627390"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumClSwapSolIn: {
anchorDiscriminator: new solanaWeb3_js.BN("564150378912976829"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumClTwoHopSwap: {
anchorDiscriminator: new solanaWeb3_js.BN("3828760301615328551"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
solanaWeb3_js.u8("remainingAccountsSplit"),
])
},
routeRaydiumClTwoHopSwapSolOut: {
anchorDiscriminator: new solanaWeb3_js.BN("11373220799455718953"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
solanaWeb3_js.u8("remainingAccountsSplit"),
])
},
routeRaydiumClTwoHopSwapSolIn: {
anchorDiscriminator: new solanaWeb3_js.BN("1635173573630140652"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
solanaWeb3_js.u8("remainingAccountsSplit"),
])
},
routeRaydiumCpSwap: {
anchorDiscriminator: new solanaWeb3_js.BN("7437765211943645137"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumCpSwapSolOut: {
anchorDiscriminator: new solanaWeb3_js.BN("9045257739866411286"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumCpSwapSolIn: {
anchorDiscriminator: new solanaWeb3_js.BN("432305509198797158"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountIn"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumCpTwoHopSwap: {
anchorDiscriminator: new solanaWeb3_js.BN("3384279312781294015"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumCpTwoHopSwapSolOut: {
anchorDiscriminator: new solanaWeb3_js.BN("18428464202744806632"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
},
routeRaydiumCpTwoHopSwapSolIn: {
anchorDiscriminator: new solanaWeb3_js.BN("16266677464406446072"),
layout: solanaWeb3_js.struct([
solanaWeb3_js.u64("anchorDiscriminator"),
solanaWeb3_js.u64("amountInOne"),
solanaWeb3_js.u64("amountInTwo"),
solanaWeb3_js.u64("paymentAmount"),
solanaWeb3_js.u64("feeAmount"),
solanaWeb3_js.u64("feeAmount2"),
solanaWeb3_js.u64("protocolAmount"),
solanaWeb3_js.i64("deadline"),
])
}
}
},
};
var allowanceOnEVM = ({ blockchain, address, api, owner, spender })=>{
return web3Client.request(
{
blockchain,
address,
api,
method: 'allowance',
params: [owner, spender],
// no cache for allowance!
},
)
};
var balanceOnEVM = async ({ blockchain, address, account, api, id })=>{
if (address == Blockchains__default["default"][blockchain].currency.address) {
return await web3Client.request(
{
blockchain: blockchain,
address: account,
method: 'balance',
},
)
} else {
return await web3Client.request(
{
blockchain: blockchain,
address: address,
method: 'balanceOf',
api,
params: id ? [account, id] : [account],
},
)
}
};
var decimalsOnEVM = ({ blockchain, address, api })=>{
return web3Client.request({
blockchain,
address,
api,
method: 'decimals',
cache: 86400000, // 1 day
})
};
var ERC1155 = [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "account",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": false,
"internalType": "bool",
"name": "approved",
"type": "bool"
}
],
"name": "ApprovalForAll",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "ids",
"type": "uint256[]"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "values",
"type": "uint256[]"
}
],
"name": "TransferBatch",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "TransferSingle",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "value",
"type": "string"
},
{
"indexed": true,
"internalType": "uint256",
"name": "id",
"type": "uint256"
}
],
"name": "URI",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "accounts",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "ids",
"type": "uint256[]"
}
],
"name": "balanceOfBatch",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "isApprovedForAll",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256[]",
"name": "ids",
"type": "uint256[]"
},
{
"internalType": "uint256[]",
"name": "amounts",
"type": "uint256[]"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "safeBatchTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"internalType": "bool",
"name": "approved",
"type": "bool"
}
],
"name": "setApprovalForAll",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
}
],
"name": "uri",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
];
var ERC20 = [
{
constant: true,
inputs: [],
name: 'name',
outputs: [{ name: '', type: 'string' }],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [
{ name: '_spender', type: 'address' },
{ name: '_value', type: 'uint256' },
],
name: 'approve',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'totalSupply',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [
{ name: '_from', type: 'address' },
{ name: '_to', type: 'address' },
{ name: '_value', type: 'uint256' },
],
name: 'transferFrom',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'decimals',
outputs: [{ name: '', type: 'uint8' }],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [{ name: '_owner', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: 'balance', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'symbol',
outputs: [{ name: '', type: 'string' }],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [
{ name: '_to', type: 'address' },
{ name: '_value', type: 'uint256' },
],
name: 'transfer',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
{
constant: true,
inputs: [
{ name: '_owner', type: 'address' },
{ name: '_spender', type: 'address' },
],
name: 'allowance',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function',
},
{ payable: true, stateMutability: 'payable', type: 'fallback' },
{
anonymous: false,
inputs: [
{ indexed: true, name: 'owner', type: 'address' },
{ indexed: true, name: 'spender', type: 'address' },
{ indexed: false, name: 'value', type: 'uint256' },
],
name: 'Approval',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'from', type: 'address' },
{ indexed: true, name: 'to', type: 'address' },
{ indexed: false, name: 'value', type: 'uint256' },
],
name: 'Transfer',
type: 'event',
},
];
var WETH = [
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "guy",
"type": "address"
},
{
"name": "wad",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "src",
"type": "address"
},
{
"name": "dst",
"type": "address"
},
{
"name": "wad",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "wad",
"type": "uint256"
}
],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "dst",
"type": "address"
},
{
"name": "wad",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "deposit",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"payable": true,
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "src",
"type": "address"
},
{
"indexed": true,
"name": "guy",
"type": "address"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "src",
"type": "address"
},
{
"indexed": true,
"name": "dst",
"type": "address"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "dst",
"type": "address"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
}
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "src",
"type": "address"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
}
],
"name": "Withdrawal",
"type": "event"
}
];
const uriAPI = [{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}];
const uriToName = (tokenURI)=>{
return new Promise((resolve)=>{
if(tokenURI.match(/^ipfs/)) {
tokenURI = `https://ipfs.io/ipfs/${tokenURI.split('://')[1]}`;
}
fetch(tokenURI).then((response) => {
if (response.ok) { return response.json() }
resolve();
})
.then((responseJson) => {
if(responseJson) {
let name = responseJson.name;
if(name){
resolve(name);
} else {
resolve();
}
}
}).catch(()=>resolve());
})
};
var nameOnEVM = ({ blockchain, address, api, id })=>{
if(id) {
return new Promise((resolve)=>{
web3Client.request({ blockchain, address, api: uriAPI, method: 'uri', params: [id] }).then((uri)=>{
uri = uri.match('0x{id}') ? uri.replace('0x{id}', id) : uri;
uriToName(uri).then(resolve);
}).catch((error)=>{
console.log('error', error);
resolve();
});
})
} else {
return web3Client.request(
{
blockchain: blockchain,
address: address,
api,
method: 'name',
cache: 86400000, // 1 day
},
)
}
};
var symbolOnEVM = ({ blockchain, address, api })=>{
return web3Client.request(
{
blockchain,
address,
api,
method: 'symbol',
cache: 86400000, // 1 day
}
)
};
const TOKEN_PROGRAM = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
const ASSOCIATED_TOKEN_PROGRAM = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var findProgramAddress = async ({ token, owner })=>{
const [address] = await solanaWeb3_js.PublicKey.findProgramAddress(
[
(new solanaWeb3_js.PublicKey(owner)).toBuffer(),
(new solanaWeb3_js.PublicKey(TOKEN_PROGRAM)).toBuffer(),
(new solanaWeb3_js.PublicKey(token)).toBuffer()
],
new solanaWeb3_js.PublicKey(ASSOCIATED_TOKEN_PROGRAM)
);
return _optionalChain$4([address, 'optionalAccess', _ => _.toString, 'call', _2 => _2()])
};
const MINT_LAYOUT = solanaWeb3_js.struct([
solanaWeb3_js.u32('mintAuthorityOption'),
solanaWeb3_js.publicKey('mintAuthority'),
solanaWeb3_js.u64('supply'),
solanaWeb3_js.u8('decimals'),
solanaWeb3_js.bool('isInitialized'),
solanaWeb3_js.u32('freezeAuthorityOption'),
solanaWeb3_js.publicKey('freezeAuthority')
]);
const KEY_LAYOUT = solanaWeb3_js.rustEnum([
solanaWeb3_js.struct([], 'uninitialized'),
solanaWeb3_js.struct([], 'editionV1'),
solanaWeb3_js.struct([], 'masterEditionV1'),
solanaWeb3_js.struct([], 'reservationListV1'),
solanaWeb3_js.struct([], 'metadataV1'),
solanaWeb3_js.struct([], 'reservationListV2'),
solanaWeb3_js.struct([], 'masterEditionV2'),
solanaWeb3_js.struct([], 'editionMarker'),
]);
const CREATOR_LAYOUT = solanaWeb3_js.struct([
solanaWeb3_js.publicKey('address'),
solanaWeb3_js.bool('verified'),
solanaWeb3_js.u8('share'),
]);
const DATA_LAYOUT = solanaWeb3_js.struct([
solanaWeb3_js.str('name'),
solanaWeb3_js.str('symbol'),
solanaWeb3_js.str('uri'),
solanaWeb3_js.u16('sellerFeeBasisPoints'),
solanaWeb3_js.option(
solanaWeb3_js.vec(
CREATOR_LAYOUT.replicate('creators')
),
'creators'
)
]);
const METADATA_LAYOUT = solanaWeb3_js.struct([
KEY_LAYOUT.replicate('key'),
solanaWeb3_js.publicKey('updateAuthority'),
solanaWeb3_js.publicKey('mint'),
DATA_LAYOUT.replicate('data'),
solanaWeb3_js.bool('primarySaleHappened'),
solanaWeb3_js.bool('isMutable'),
solanaWeb3_js.option(solanaWeb3_js.u8(), 'editionNonce'),
]);
const TRANSFER_LAYOUT = solanaWeb3_js.struct([
solanaWeb3_js.u8('instruction'),
solanaWeb3_js.u64('amount'),
]);
const TOKEN_LAYOUT = solanaWeb3_js.struct([
solanaWeb3_js.publicKey('mint'),
solanaWeb3_js.publicKey('owner'),
solanaWeb3_js.u64('amount'),
solanaWeb3_js.u32('delegateOption'),
solanaWeb3_js.publicKey('delegate'),
solanaWeb3_js.u8('state'),
solanaWeb3_js.u32('isNativeOption'),
solanaWeb3_js.u64('isNative'),
solanaWeb3_js.u64('delegatedAmount'),
solanaWeb3_js.u32('closeAuthorityOption'),
solanaWeb3_js.publicKey('closeAuthority')
]);
const INITIALIZE_LAYOUT = solanaWeb3_js.struct([
solanaWeb3_js.u8('instruction'),
solanaWeb3_js.publicKey('owner')
]);
const CLOSE_LAYOUT = solanaWeb3_js.struct([
solanaWeb3_js.u8('instruction')
]);
const createTransferInstruction = async ({ token, amount, from, to })=>{
let fromTokenAccount = await findProgramAddress({ token, owner: from });
let toTokenAccount = await findProgramAddress({ token, owner: to });
const keys = [
{ pubkey: new solanaWeb3_js.PublicKey(fromTokenAccount), isSigner: false, isWritable: true },
{ pubkey: new solanaWeb3_js.PublicKey(toTokenAccount), isSigner: false, isWritable: true },
{ pubkey: new solanaWeb3_js.PublicKey(from), isSigner: true, isWritable: false }
];
const data = solanaWeb3_js.Buffer.alloc(TRANSFER_LAYOUT.span);
TRANSFER_LAYOUT.encode({
instruction: 3, // TRANSFER
amount: new solanaWeb3_js.BN(amount)
}, data);
return new solanaWeb3_js.TransactionInstruction({
keys,
programId: new solanaWeb3_js.PublicKey(TOKEN_PROGRAM),
data
})
};
const createAssociatedTokenAccountInstruction = async ({ token, owner, payer }) => {
let associatedToken = await findProgramAddress({ token, owner });
const keys = [
{ pubkey: new solanaWeb3_js.PublicKey(payer), isSigner: true, isWritable: true },
{ pubkey: new solanaWeb3_js.PublicKey(associatedToken), isSigner: false, isWritable: true },
{ pubkey: new solanaWeb3_js.PublicKey(owner), isSigner: false, isWritable: false },
{ pubkey: new solanaWeb3_js.PublicKey(token), isSigner: false, isWritable: false },
{ pubkey: solanaWeb3_js.SystemProgram.programId, isSigner: false, isWritable: false },
{ pubkey: new solanaWeb3_js.PublicKey(TOKEN_PROGRAM), isSigner: false, isWritable: false },
];
return new solanaWeb3_js.TransactionInstruction({
keys,
programId: new solanaWeb3_js.PublicKey(ASSOCIATED_TOKEN_PROGRAM),
data: solanaWeb3_js.Buffer.alloc(0)
})
};
const initializeAccountInstruction = ({ account, token, owner })=>{
const keys = [
{ pubkey: new solanaWeb3_js.PublicKey(account), isSigner: false, isWritable: true },
{ pubkey: new solanaWeb3_js.PublicKey(token), isSigner: false, isWritable: false },
];
const data = solanaWeb3_js.Buffer.alloc(INITIALIZE_LAYOUT.span);
INITIALIZE_LAYOUT.encode({
instruction: 18, // InitializeAccount3
owner: new solanaWeb3_js.PublicKey(owner)
}, data);
return new solanaWeb3_js.TransactionInstruction({ keys, programId: new solanaWeb3_js.PublicKey(TOKEN_PROGRAM), data })
};
const closeAccountInstruction = ({ account, owner })=>{
const keys = [
{ pubkey: new solanaWeb3_js.PublicKey(account), isSigner: false, isWritable: true },
{ pubkey: new solanaWeb3_js.PublicKey(owner), isSigner: false, isWritable: true },
{ pubkey: new solanaWeb3_js.PublicKey(owner), isSigner: true, isWritable: false }
];
const data = solanaWeb3_js.Buffer.alloc(CLOSE_LAYOUT.span);
CLOSE_LAYOUT.encode({
instruction: 9 // CloseAccount
}, data);
return new solanaWeb3_js.TransactionInstruction({ keys, programId: new solanaWeb3_js.PublicKey(TOKEN_PROGRAM), data })
};
var instructions = /*#__PURE__*/Object.freeze({
__proto__: null,
createTransferInstruction: createTransferInstruction,
createAssociatedTokenAccountInstruction: createAssociatedTokenAccountInstruction,
initializeAccountInstruction: initializeAccountInstruction,
closeAccountInstruction: closeAccountInstruction
});
var balanceOnSolana = async ({ blockchain, address, account, api })=>{
if(address == Blockchains__default["default"][blockchain].currency.address) {
return ethers.ethers.BigNumber.from(await web3Client.request(`solana://${account}/balance`))
} else {
const tokenAccountAddress = await