forked from paraswap/paraswap-dex-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configurable chain configuration
- Loading branch information
Showing
41 changed files
with
474 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import { Config, Address, Token } from './types'; | ||
import { Network } from './constants'; | ||
import { isETHAddress } from './utils'; | ||
|
||
// Hardcoded and envionment values from which actual config is derived | ||
type BaseConfig = { | ||
network: number; | ||
networkName: string; | ||
isTestnet: boolean; | ||
mainnetNetwork?: number; | ||
nativeTokenName?: string; | ||
nativeTokenSymbol: string; | ||
wrappedNativeTokenName?: string; | ||
wrappedNativeTokenSymbol?: string; | ||
wrappedNativeTokenAddress: Address; | ||
hasEIP1559: boolean; | ||
augustusAddress: Address; | ||
tokenTransferProxyAddress: Address; | ||
multicallV2Address: Address; | ||
httpProvider?: string; | ||
adapterAddresses: { [name: string]: Address }; | ||
uniswapV2ExchangeRouterAddress: Address; | ||
}; | ||
|
||
const baseConfigs: { [network: number]: BaseConfig } = { | ||
[Network.MAINNET]: { | ||
network: Network.MAINNET, | ||
networkName: 'Ethereum Mainnet', | ||
isTestnet: false, | ||
nativeTokenName: 'Ether', | ||
nativeTokenSymbol: 'ETH', | ||
wrappedNativeTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', | ||
hasEIP1559: true, | ||
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57', | ||
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae', | ||
multicallV2Address: '0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696', | ||
httpProvider: process.env.HTTP_PROVIDER, | ||
adapterAddresses: { | ||
Adapter01: '0x3a0430bf7cd2633af111ce3204db4b0990857a6f', | ||
Adapter02: '0xFC2Ba6E830a04C25e207B8214b26d8C713F6881F', | ||
Adapter03: '0x9Cf0b60C2133f67443fdf8a1bB952E2e6783d5DF', | ||
BuyAdapter: '0x8D562A7D63248Ebfdd19B26665161cf867e5c10A', | ||
}, | ||
uniswapV2ExchangeRouterAddress: | ||
'0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07', | ||
}, | ||
[Network.ROPSTEN]: { | ||
network: Network.ROPSTEN, | ||
networkName: 'Ethereum Ropsten Testnet', | ||
isTestnet: true, | ||
mainnetNetwork: Network.MAINNET, | ||
nativeTokenName: 'Ether', | ||
nativeTokenSymbol: 'ETH', | ||
wrappedNativeTokenAddress: '0xc778417E063141139Fce010982780140Aa0cD5Ab', | ||
hasEIP1559: true, | ||
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57', | ||
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae', | ||
multicallV2Address: '0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696', | ||
httpProvider: process.env.HTTP_PROVIDER_3, | ||
adapterAddresses: { | ||
RopstenAdapter01: '0x74fF86C61CF66334dCfc999814DE4695B4BaE57b', | ||
RopstenBuyAdapter: '0xDDbaC07C9ef96D6E792c25Ff934E7e111241BFf1', | ||
}, | ||
uniswapV2ExchangeRouterAddress: | ||
'0x53e693c6C7FFC4446c53B205Cf513105Bf140D7b', | ||
}, | ||
[Network.BSC]: { | ||
network: Network.BSC, | ||
networkName: 'Binance Smart Chain Mainnet', | ||
isTestnet: false, | ||
nativeTokenSymbol: 'BNB', | ||
wrappedNativeTokenAddress: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', | ||
hasEIP1559: false, | ||
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57', | ||
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae', | ||
multicallV2Address: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D', | ||
httpProvider: process.env.HTTP_PROVIDER_56, | ||
adapterAddresses: { | ||
BscAdapter01: '0xcEC935682c0b510fb91c0A12275Bb7e14EEBE87c', | ||
BscBuyAdapter: '0xdA0DAFbbC95d96bAb164c847112e15c0299541f6', | ||
}, | ||
uniswapV2ExchangeRouterAddress: | ||
'0x53e693c6C7FFC4446c53B205Cf513105Bf140D7b', | ||
}, | ||
[Network.POLYGON]: { | ||
network: Network.POLYGON, | ||
networkName: 'Polygon Mainnet', | ||
isTestnet: false, | ||
nativeTokenName: 'Matic', | ||
nativeTokenSymbol: 'MATIC', | ||
wrappedNativeTokenAddress: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', | ||
hasEIP1559: true, | ||
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57', | ||
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae', | ||
multicallV2Address: '0x275617327c958bD06b5D6b871E7f491D76113dd8', | ||
httpProvider: process.env.HTTP_PROVIDER_137, | ||
adapterAddresses: { | ||
PolygonAdapter01: '0xD458FA906121d9081970Ed3937df50C8Ba88E9c0', | ||
PolygonAdapter02: '0xe56823aC543c81f747eD95F3f095b5A19224bd3a', | ||
PolygonBuyAdapter: '0x34E0E6448A648Fc0b340679C4F16e5ACC4Bf4c95', | ||
}, | ||
uniswapV2ExchangeRouterAddress: | ||
'0xf3938337F7294fEf84e9B2c6D548A93F956Cc281', | ||
}, | ||
[Network.AVALANCHE]: { | ||
network: Network.AVALANCHE, | ||
networkName: 'Avalanche Mainnet C-Chain', | ||
isTestnet: false, | ||
nativeTokenName: 'Avax', | ||
nativeTokenSymbol: 'AVAX', | ||
wrappedNativeTokenAddress: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', | ||
hasEIP1559: true, | ||
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57', | ||
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae', | ||
multicallV2Address: '0xd7Fc8aD069f95B6e2835f4DEff03eF84241cF0E1', | ||
httpProvider: process.env.HTTP_PROVIDER_43114, | ||
adapterAddresses: { | ||
AvalancheAdapter01: '0xaaD116D3b51893bD00bFBAf337824A15796eD97a', | ||
AvalancheBuyAdapter: '0x05d0c2b58fF6c05bcc3e5F2D797bEB77e0A4CC7b', | ||
}, | ||
uniswapV2ExchangeRouterAddress: | ||
'0x53e693c6C7FFC4446c53B205Cf513105Bf140D7b', | ||
}, | ||
[Network.FANTOM]: { | ||
network: Network.FANTOM, | ||
networkName: 'Fantom Opera Mainnet', | ||
isTestnet: false, | ||
nativeTokenName: 'Fantom', | ||
nativeTokenSymbol: 'FTM', | ||
wrappedNativeTokenAddress: '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83', | ||
hasEIP1559: false, | ||
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57', | ||
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae', | ||
multicallV2Address: '0xdC6E2b14260F972ad4e5a31c68294Fba7E720701', | ||
httpProvider: process.env.HTTP_PROVIDER_250, | ||
adapterAddresses: { | ||
FantomAdapter01: '0x7EE3C983cA38c370F296FE14a31bEaC5b1c9a9FE', | ||
FantomBuyAdapter: '0x3032B8c9CF91C791A8EcC2c7831A11279f419386', | ||
}, | ||
uniswapV2ExchangeRouterAddress: | ||
'0xAB86e2bC9ec5485a9b60E684BA6d49bf4686ACC2', | ||
}, | ||
}; | ||
|
||
// Should not be used, except by configuration service or internal test code | ||
export function generateConfig(network: number): Config { | ||
const baseConfig = baseConfigs[network]; | ||
const nativeTokenName = | ||
baseConfig.nativeTokenName || baseConfig.nativeTokenSymbol; | ||
if (!baseConfig.httpProvider) { | ||
throw new Error(`Missing HTTP Provider for network ${network}`); | ||
} | ||
return { | ||
network: baseConfig.network, | ||
networkName: baseConfig.networkName, | ||
isTestnet: baseConfig.isTestnet, | ||
mainnetNetwork: baseConfig.mainnetNetwork, | ||
nativeTokenName, | ||
nativeTokenSymbol: baseConfig.nativeTokenSymbol, | ||
wrappedNativeTokenName: | ||
baseConfig.wrappedNativeTokenName || `Wrapped ${nativeTokenName}`, | ||
wrappedNativeTokenSymbol: | ||
baseConfig.wrappedNativeTokenSymbol || `W${baseConfig.nativeTokenSymbol}`, | ||
wrappedNativeTokenAddress: baseConfig.wrappedNativeTokenAddress, | ||
hasEIP1559: baseConfig.hasEIP1559, | ||
augustusAddress: baseConfig.augustusAddress, | ||
tokenTransferProxyAddress: baseConfig.tokenTransferProxyAddress, | ||
multicallV2Address: baseConfig.multicallV2Address, | ||
httpProvider: baseConfig.httpProvider, | ||
adapterAddresses: { ...baseConfig.adapterAddresses }, | ||
uniswapV2ExchangeRouterAddress: baseConfig.uniswapV2ExchangeRouterAddress, | ||
}; | ||
} | ||
|
||
export class ConfigHelper { | ||
constructor(public data: Config) {} | ||
|
||
wrapETH(token: Token): Token { | ||
return isETHAddress(token.address) | ||
? { address: this.data.wrappedNativeTokenAddress, decimals: 18 } | ||
: token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.