diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 29e9061..63460c8 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -45666,6 +45666,37 @@ const getBlockchainCost = (blockchain) => { } }; +const EXCHANGE_PROXIES = { + 'arbitrum': { + [Blockchains.arbitrum.wrapped.address]: '0x7E655088214d0657251A51aDccE9109CFd23B5B5' + }, + 'avalanche': { + [Blockchains.avalanche.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'base': { + [Blockchains.base.wrapped.address]: '0xD1711710843B125a6a01FfDF9b95fDc3064BeF7A' + }, + 'bsc': { + [Blockchains.bsc.wrapped.address]: '0xeEb80d14abfB058AA78DE38813fe705c3e3b243E' + }, + 'ethereum': { + [Blockchains.ethereum.wrapped.address]: '0x298f4980525594b3b982779cf74ba76819708D43' + }, + 'fantom': { + [Blockchains.fantom.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'gnosis': { + [Blockchains.gnosis.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'optimism': { + [Blockchains.optimism.wrapped.address]: '0x69594057e2C0224deb1180c7a5Df9ec9d5B611B5' + }, + 'polygon': { + [Blockchains.polygon.wrapped.address]: '0xaE59C9d3E055BdFAa583E169aA5Ebe395689476a' + }, + 'solana': {} +}; + const getTransaction$2 = async({ paymentRoute })=> { const transaction = { @@ -45718,10 +45749,8 @@ const transactionMethod = ({ paymentRoute })=> { const getExchangeType = ({ exchangeRoute, blockchain })=> { if( typeof exchangeRoute === 'undefined' ) { return 0 } - if(exchangeRoute.exchange.name === 'uniswap_v3') { + if(exchangeRoute.exchange.name === 'uniswap_v3' || exchangeRoute.exchange[blockchain].router.address === Blockchains[blockchain].wrapped.address) { return 2 // push - } else if(exchangeRoute.exchange[blockchain].address === Blockchains[blockchain].wrapped.address) { - return 0 // do nothing } else { return 1 // pull } @@ -45787,8 +45816,8 @@ const transactionParams = async ({ paymentRoute })=> { ) { // bsc pancakeswap_v3 requries smart router exchange address for converting and paying out BNB/NATIVE exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].smartRouter.address; - } else { - exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].router.address; + } else { // proxy exchange or exchange directly + exchangeAddress = EXCHANGE_PROXIES[exchangeTransaction.blockchain][exchangeRoute.exchange[paymentRoute.blockchain].router.address] || exchangeRoute.exchange[paymentRoute.blockchain].router.address; } } return { diff --git a/dist/esm/index.js b/dist/esm/index.js index ad0871e..1e82bb6 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -1969,6 +1969,37 @@ const getBlockchainCost = (blockchain) => { } }; +const EXCHANGE_PROXIES = { + 'arbitrum': { + [Blockchains.arbitrum.wrapped.address]: '0x7E655088214d0657251A51aDccE9109CFd23B5B5' + }, + 'avalanche': { + [Blockchains.avalanche.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'base': { + [Blockchains.base.wrapped.address]: '0xD1711710843B125a6a01FfDF9b95fDc3064BeF7A' + }, + 'bsc': { + [Blockchains.bsc.wrapped.address]: '0xeEb80d14abfB058AA78DE38813fe705c3e3b243E' + }, + 'ethereum': { + [Blockchains.ethereum.wrapped.address]: '0x298f4980525594b3b982779cf74ba76819708D43' + }, + 'fantom': { + [Blockchains.fantom.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'gnosis': { + [Blockchains.gnosis.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'optimism': { + [Blockchains.optimism.wrapped.address]: '0x69594057e2C0224deb1180c7a5Df9ec9d5B611B5' + }, + 'polygon': { + [Blockchains.polygon.wrapped.address]: '0xaE59C9d3E055BdFAa583E169aA5Ebe395689476a' + }, + 'solana': {} +}; + const getTransaction$2 = async({ paymentRoute })=> { const transaction = { @@ -2021,10 +2052,8 @@ const transactionMethod = ({ paymentRoute })=> { const getExchangeType = ({ exchangeRoute, blockchain })=> { if( typeof exchangeRoute === 'undefined' ) { return 0 } - if(exchangeRoute.exchange.name === 'uniswap_v3') { + if(exchangeRoute.exchange.name === 'uniswap_v3' || exchangeRoute.exchange[blockchain].router.address === Blockchains[blockchain].wrapped.address) { return 2 // push - } else if(exchangeRoute.exchange[blockchain].address === Blockchains[blockchain].wrapped.address) { - return 0 // do nothing } else { return 1 // pull } @@ -2090,8 +2119,8 @@ const transactionParams = async ({ paymentRoute })=> { ) { // bsc pancakeswap_v3 requries smart router exchange address for converting and paying out BNB/NATIVE exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].smartRouter.address; - } else { - exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].router.address; + } else { // proxy exchange or exchange directly + exchangeAddress = EXCHANGE_PROXIES[exchangeTransaction.blockchain][exchangeRoute.exchange[paymentRoute.blockchain].router.address] || exchangeRoute.exchange[paymentRoute.blockchain].router.address; } } return { diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index da17752..abc3b27 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -45672,6 +45672,37 @@ } }; + const EXCHANGE_PROXIES = { + 'arbitrum': { + [Blockchains__default["default"].arbitrum.wrapped.address]: '0x7E655088214d0657251A51aDccE9109CFd23B5B5' + }, + 'avalanche': { + [Blockchains__default["default"].avalanche.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'base': { + [Blockchains__default["default"].base.wrapped.address]: '0xD1711710843B125a6a01FfDF9b95fDc3064BeF7A' + }, + 'bsc': { + [Blockchains__default["default"].bsc.wrapped.address]: '0xeEb80d14abfB058AA78DE38813fe705c3e3b243E' + }, + 'ethereum': { + [Blockchains__default["default"].ethereum.wrapped.address]: '0x298f4980525594b3b982779cf74ba76819708D43' + }, + 'fantom': { + [Blockchains__default["default"].fantom.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'gnosis': { + [Blockchains__default["default"].gnosis.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'optimism': { + [Blockchains__default["default"].optimism.wrapped.address]: '0x69594057e2C0224deb1180c7a5Df9ec9d5B611B5' + }, + 'polygon': { + [Blockchains__default["default"].polygon.wrapped.address]: '0xaE59C9d3E055BdFAa583E169aA5Ebe395689476a' + }, + 'solana': {} + }; + const getTransaction$2 = async({ paymentRoute })=> { const transaction = { @@ -45724,10 +45755,8 @@ const getExchangeType = ({ exchangeRoute, blockchain })=> { if( typeof exchangeRoute === 'undefined' ) { return 0 } - if(exchangeRoute.exchange.name === 'uniswap_v3') { + if(exchangeRoute.exchange.name === 'uniswap_v3' || exchangeRoute.exchange[blockchain].router.address === Blockchains__default["default"][blockchain].wrapped.address) { return 2 // push - } else if(exchangeRoute.exchange[blockchain].address === Blockchains__default["default"][blockchain].wrapped.address) { - return 0 // do nothing } else { return 1 // pull } @@ -45793,8 +45822,8 @@ ) { // bsc pancakeswap_v3 requries smart router exchange address for converting and paying out BNB/NATIVE exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].smartRouter.address; - } else { - exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].router.address; + } else { // proxy exchange or exchange directly + exchangeAddress = EXCHANGE_PROXIES[exchangeTransaction.blockchain][exchangeRoute.exchange[paymentRoute.blockchain].router.address] || exchangeRoute.exchange[paymentRoute.blockchain].router.address; } } return { diff --git a/dist/umd/index.js b/dist/umd/index.js index fb142f3..9a38ad1 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -1974,6 +1974,37 @@ } }; + const EXCHANGE_PROXIES = { + 'arbitrum': { + [Blockchains__default["default"].arbitrum.wrapped.address]: '0x7E655088214d0657251A51aDccE9109CFd23B5B5' + }, + 'avalanche': { + [Blockchains__default["default"].avalanche.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'base': { + [Blockchains__default["default"].base.wrapped.address]: '0xD1711710843B125a6a01FfDF9b95fDc3064BeF7A' + }, + 'bsc': { + [Blockchains__default["default"].bsc.wrapped.address]: '0xeEb80d14abfB058AA78DE38813fe705c3e3b243E' + }, + 'ethereum': { + [Blockchains__default["default"].ethereum.wrapped.address]: '0x298f4980525594b3b982779cf74ba76819708D43' + }, + 'fantom': { + [Blockchains__default["default"].fantom.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'gnosis': { + [Blockchains__default["default"].gnosis.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'optimism': { + [Blockchains__default["default"].optimism.wrapped.address]: '0x69594057e2C0224deb1180c7a5Df9ec9d5B611B5' + }, + 'polygon': { + [Blockchains__default["default"].polygon.wrapped.address]: '0xaE59C9d3E055BdFAa583E169aA5Ebe395689476a' + }, + 'solana': {} + }; + const getTransaction$2 = async({ paymentRoute })=> { const transaction = { @@ -2026,10 +2057,8 @@ const getExchangeType = ({ exchangeRoute, blockchain })=> { if( typeof exchangeRoute === 'undefined' ) { return 0 } - if(exchangeRoute.exchange.name === 'uniswap_v3') { + if(exchangeRoute.exchange.name === 'uniswap_v3' || exchangeRoute.exchange[blockchain].router.address === Blockchains__default["default"][blockchain].wrapped.address) { return 2 // push - } else if(exchangeRoute.exchange[blockchain].address === Blockchains__default["default"][blockchain].wrapped.address) { - return 0 // do nothing } else { return 1 // pull } @@ -2095,8 +2124,8 @@ ) { // bsc pancakeswap_v3 requries smart router exchange address for converting and paying out BNB/NATIVE exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].smartRouter.address; - } else { - exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].router.address; + } else { // proxy exchange or exchange directly + exchangeAddress = EXCHANGE_PROXIES[exchangeTransaction.blockchain][exchangeRoute.exchange[paymentRoute.blockchain].router.address] || exchangeRoute.exchange[paymentRoute.blockchain].router.address; } } return { diff --git a/examples/bsc.md b/examples/bsc.md index 7579177..59bb0b8 100644 --- a/examples/bsc.md +++ b/examples/bsc.md @@ -111,7 +111,7 @@ let routes = await Web3Payments.route({ } }) -let route = routes[0] +let route = routes[1] let transaction = await route.getTransaction() const wallet = (await Web3Wallets.getWallets())[0] diff --git a/examples/ethereum.md b/examples/ethereum.md index 8600408..5085596 100644 --- a/examples/ethereum.md +++ b/examples/ethereum.md @@ -63,7 +63,7 @@ let routes = await Web3Payments.route({ } }) -let route = routes[1] +let route = routes[0] let transaction = await route.getTransaction() const wallet = (await Web3Wallets.getWallets())[0] diff --git a/examples/gnosis.md b/examples/gnosis.md index b0ddae0..d2075de 100644 --- a/examples/gnosis.md +++ b/examples/gnosis.md @@ -45,3 +45,25 @@ let transaction = await route.getTransaction() const wallet = (await Web3Wallets.getWallets())[0] wallet.sendTransaction(transaction) ``` + +```javascript +let routes = await Web3Payments.route({ + accept: [ + { + blockchain: 'gnosis', + token: Web3Blockchains.gnosis.currency.address, + amount: 0.001, + toAddress: '0x08B277154218CCF3380CAE48d630DA13462E3950' + } + ], + from: { + gnosis: '0x317D875cA3B9f8d14f960486C0d1D1913be74e90', + } +}) + +let route = routes[2] +let transaction = await route.getTransaction() + +const wallet = (await Web3Wallets.getWallets())[0] +wallet.sendTransaction(transaction) +``` diff --git a/src/platforms/evm/transaction.js b/src/platforms/evm/transaction.js index d4d1da9..9748a76 100644 --- a/src/platforms/evm/transaction.js +++ b/src/platforms/evm/transaction.js @@ -14,6 +14,37 @@ import Blockchains from '@depay/web3-blockchains' import routers from './routers' import { ethers } from 'ethers' +const EXCHANGE_PROXIES = { + 'arbitrum': { + [Blockchains.arbitrum.wrapped.address]: '0x7E655088214d0657251A51aDccE9109CFd23B5B5' + }, + 'avalanche': { + [Blockchains.avalanche.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'base': { + [Blockchains.base.wrapped.address]: '0xD1711710843B125a6a01FfDF9b95fDc3064BeF7A' + }, + 'bsc': { + [Blockchains.bsc.wrapped.address]: '0xeEb80d14abfB058AA78DE38813fe705c3e3b243E' + }, + 'ethereum': { + [Blockchains.ethereum.wrapped.address]: '0x298f4980525594b3b982779cf74ba76819708D43' + }, + 'fantom': { + [Blockchains.fantom.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'gnosis': { + [Blockchains.gnosis.wrapped.address]: '0x2d0a6275eaDa0d03226919ce6D93661E589B2d59' + }, + 'optimism': { + [Blockchains.optimism.wrapped.address]: '0x69594057e2C0224deb1180c7a5Df9ec9d5B611B5' + }, + 'polygon': { + [Blockchains.polygon.wrapped.address]: '0xaE59C9d3E055BdFAa583E169aA5Ebe395689476a' + }, + 'solana': {} +} + const getTransaction = async({ paymentRoute })=> { const transaction = { @@ -66,10 +97,8 @@ const transactionMethod = ({ paymentRoute })=> { const getExchangeType = ({ exchangeRoute, blockchain })=> { if( typeof exchangeRoute === 'undefined' ) { return 0 } - if(exchangeRoute.exchange.name === 'uniswap_v3') { + if(exchangeRoute.exchange.name === 'uniswap_v3' || exchangeRoute.exchange[blockchain].router.address === Blockchains[blockchain].wrapped.address) { return 2 // push - } else if(exchangeRoute.exchange[blockchain].address === Blockchains[blockchain].wrapped.address) { - return 0 // do nothing } else { return 1 // pull } @@ -135,8 +164,8 @@ const transactionParams = async ({ paymentRoute })=> { ) { // bsc pancakeswap_v3 requries smart router exchange address for converting and paying out BNB/NATIVE exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].smartRouter.address - } else { - exchangeAddress = exchangeRoute.exchange[paymentRoute.blockchain].router.address + } else { // proxy exchange or exchange directly + exchangeAddress = EXCHANGE_PROXIES[exchangeTransaction.blockchain][exchangeRoute.exchange[paymentRoute.blockchain].router.address] || exchangeRoute.exchange[paymentRoute.blockchain].router.address } } return {