Skip to content

Commit

Permalink
fix WRAPPED payment
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Dec 22, 2023
1 parent 78b4c41 commit bba29af
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 27 deletions.
39 changes: 34 additions & 5 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
39 changes: 34 additions & 5 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
39 changes: 34 additions & 5 deletions dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
39 changes: 34 additions & 5 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/bsc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/ethereum.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 22 additions & 0 deletions examples/gnosis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
39 changes: 34 additions & 5 deletions src/platforms/evm/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bba29af

Please sign in to comment.