From e1a36fcdac2f572eaee8ac1ec55f3b3ced9bc028 Mon Sep 17 00:00:00 2001 From: defifofum Date: Tue, 12 Jul 2022 17:53:35 -0400 Subject: [PATCH 1/5] refactor: Configuration for ApeSwap deployments --- balancer-js/src/lib/constants/config.ts | 128 +++++----------- .../src/lib/constants/configBalancer.ts | 143 ++++++++++++++++++ balancer-js/src/lib/constants/network.ts | 21 ++- .../src/lib/constants/networkBalancer.ts | 10 ++ .../src/modules/contracts/contracts.module.ts | 4 +- balancer-js/src/modules/sdk.helpers.ts | 4 +- 6 files changed, 208 insertions(+), 102 deletions(-) create mode 100644 balancer-js/src/lib/constants/configBalancer.ts create mode 100644 balancer-js/src/lib/constants/networkBalancer.ts diff --git a/balancer-js/src/lib/constants/config.ts b/balancer-js/src/lib/constants/config.ts index 8de2aaaa7..3e0653a5c 100644 --- a/balancer-js/src/lib/constants/config.ts +++ b/balancer-js/src/lib/constants/config.ts @@ -1,99 +1,50 @@ import { Network } from './network'; import { BalancerNetworkConfig } from '@/types'; -export const balancerVault = '0xBA12222222228d8Ba445958a75a0704d566BF2C8'; +export const apeswapVault = '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719'; -export const BALANCER_NETWORK_CONFIG: Record = { - [Network.MAINNET]: { - chainId: Network.MAINNET, //1 - addresses: { - contracts: { - vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', - multicall: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441', - lidoRelayer: '0xdcdbf71A870cc60C6F9B621E28a7D3Ffd6Dd4965', - }, - tokens: { - wrappedNativeAsset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', - lbpRaisingTokens: [ - '0x6B175474E89094C44Da98b954EedeAC495271d0F', - '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', - '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', - ], - stETH: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', - wstETH: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', - }, - }, - urls: { - subgraph: - 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2', - }, - pools: { - wETHwstETH: { - id: '0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080', - address: '0x32296969ef14eb0c6d29669c550d4a0449130230', - }, - }, - }, - [Network.POLYGON]: { - chainId: Network.POLYGON, //137 - addresses: { - contracts: { - vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', - multicall: '0xa1B2b503959aedD81512C37e9dce48164ec6a94d', - }, - tokens: { - wrappedNativeAsset: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', - }, - }, - urls: { - subgraph: - 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2', - }, - pools: {}, - }, - [Network.ARBITRUM]: { - chainId: Network.ARBITRUM, //42161 +export const APESWAP_NETWORK_CONFIG: Record = { + [Network.BSC]: { + chainId: Network.BSC, //56 addresses: { contracts: { - vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', - multicall: '0x269ff446d9892c9e19082564df3f5e8741e190a1', + vault: '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719', + multicall: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D', }, tokens: { - wrappedNativeAsset: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', + wrappedNativeAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', }, }, urls: { - subgraph: - 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-arbitrum-v2', + subgraph: '', }, pools: {}, }, - [Network.KOVAN]: { - chainId: Network.KOVAN, //42 + [Network.BSC_DUMMY]: { + chainId: Network.BSC, //56 addresses: { contracts: { - vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', - multicall: '0x2cc8688C5f75E365aaEEb4ea8D6a480405A48D2A', + vault: '0x42B7888FFf938C54faeDF52485C8323c4Fc8C99B', + multicall: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D', }, tokens: { - wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + wrappedNativeAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', }, }, urls: { - subgraph: - 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-kovan-v2', + subgraph: 'http://65.108.138.33:8000/subgraphs/name/apeswap/balancer-v2', }, pools: {}, }, - [Network.ROPSTEN]: { - chainId: Network.ROPSTEN, //3 + [Network.BSC_TESTNET]: { + chainId: Network.BSC_TESTNET, //97 addresses: { contracts: { - vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', - multicall: '0x53c43764255c17bd724f74c4ef150724ac50a3ed', + vault: '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719', + multicall: '0x7b6838b362f05bA2a0CAA8F9c1B34F3D619e7413', }, tokens: { - wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + wrappedNativeAsset: '0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd', }, }, urls: { @@ -101,43 +52,40 @@ export const BALANCER_NETWORK_CONFIG: Record = { }, pools: {}, }, - [Network.RINKEBY]: { - chainId: Network.RINKEBY, //4 + // NOTE: Balancer mainnet config + [Network.MAINNET]: { + chainId: Network.MAINNET as any, //1 addresses: { contracts: { vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', - multicall: '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821', + multicall: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441', + lidoRelayer: '0xdcdbf71A870cc60C6F9B621E28a7D3Ffd6Dd4965', }, tokens: { - wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + wrappedNativeAsset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + lbpRaisingTokens: [ + '0x6B175474E89094C44Da98b954EedeAC495271d0F', + '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', + '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + ], + stETH: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', + wstETH: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', }, }, urls: { subgraph: - 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-rinkeby-v2', + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2', }, - pools: {}, - }, - [Network.GOERLI]: { - chainId: Network.GOERLI, //5 - addresses: { - contracts: { - vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', - multicall: '0x77dCa2C955b15e9dE4dbBCf1246B4B85b651e50e', - }, - tokens: { - wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + pools: { + wETHwstETH: { + id: '0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080', + address: '0x32296969ef14eb0c6d29669c550d4a0449130230', }, }, - urls: { - subgraph: - 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-goerli-v2', - }, - pools: {}, }, }; export const networkAddresses = ( chainId: number ): BalancerNetworkConfig['addresses'] => - BALANCER_NETWORK_CONFIG[chainId as Network].addresses; + APESWAP_NETWORK_CONFIG[chainId as Network].addresses; diff --git a/balancer-js/src/lib/constants/configBalancer.ts b/balancer-js/src/lib/constants/configBalancer.ts new file mode 100644 index 000000000..e3bd33ee3 --- /dev/null +++ b/balancer-js/src/lib/constants/configBalancer.ts @@ -0,0 +1,143 @@ +import { Network } from './networkBalancer'; +import { BalancerNetworkConfig } from '@/types'; + +export const balancerVault = '0xBA12222222228d8Ba445958a75a0704d566BF2C8'; + +export const BALANCER_NETWORK_CONFIG: Record = { + [Network.MAINNET]: { + chainId: Network.MAINNET as any, //1 + addresses: { + contracts: { + vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', + multicall: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441', + lidoRelayer: '0xdcdbf71A870cc60C6F9B621E28a7D3Ffd6Dd4965', + }, + tokens: { + wrappedNativeAsset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + lbpRaisingTokens: [ + '0x6B175474E89094C44Da98b954EedeAC495271d0F', + '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', + '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + ], + stETH: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', + wstETH: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', + }, + }, + urls: { + subgraph: + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2', + }, + pools: { + wETHwstETH: { + id: '0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080', + address: '0x32296969ef14eb0c6d29669c550d4a0449130230', + }, + }, + }, + [Network.POLYGON]: { + chainId: Network.POLYGON as any, //137 + addresses: { + contracts: { + vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', + multicall: '0xa1B2b503959aedD81512C37e9dce48164ec6a94d', + }, + tokens: { + wrappedNativeAsset: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', + }, + }, + urls: { + subgraph: + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2', + }, + pools: {}, + }, + [Network.ARBITRUM]: { + chainId: Network.ARBITRUM as any, //42161 + addresses: { + contracts: { + vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', + multicall: '0x269ff446d9892c9e19082564df3f5e8741e190a1', + }, + tokens: { + wrappedNativeAsset: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', + }, + }, + urls: { + subgraph: + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-arbitrum-v2', + }, + pools: {}, + }, + [Network.KOVAN]: { + chainId: Network.KOVAN as any, //42 + addresses: { + contracts: { + vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', + multicall: '0x2cc8688C5f75E365aaEEb4ea8D6a480405A48D2A', + }, + tokens: { + wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + }, + }, + urls: { + subgraph: + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-kovan-v2', + }, + pools: {}, + }, + [Network.ROPSTEN]: { + chainId: Network.ROPSTEN as any, //3 + addresses: { + contracts: { + vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', + multicall: '0x53c43764255c17bd724f74c4ef150724ac50a3ed', + }, + tokens: { + wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + }, + }, + urls: { + subgraph: '', + }, + pools: {}, + }, + [Network.RINKEBY]: { + chainId: Network.RINKEBY as any, //4 + addresses: { + contracts: { + vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', + multicall: '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821', + }, + tokens: { + wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + }, + }, + urls: { + subgraph: + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-rinkeby-v2', + }, + pools: {}, + }, + [Network.GOERLI]: { + chainId: Network.GOERLI as any, //5 + addresses: { + contracts: { + vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', + multicall: '0x77dCa2C955b15e9dE4dbBCf1246B4B85b651e50e', + }, + tokens: { + wrappedNativeAsset: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + }, + }, + urls: { + subgraph: + 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-goerli-v2', + }, + pools: {}, + }, +}; + +export const networkAddresses = ( + chainId: number +): BalancerNetworkConfig['addresses'] => + BALANCER_NETWORK_CONFIG[chainId as Network].addresses; diff --git a/balancer-js/src/lib/constants/network.ts b/balancer-js/src/lib/constants/network.ts index 4e8aa5ca7..d8ce9c32f 100644 --- a/balancer-js/src/lib/constants/network.ts +++ b/balancer-js/src/lib/constants/network.ts @@ -1,10 +1,15 @@ export enum Network { MAINNET = 1, - ROPSTEN = 3, - RINKEBY = 4, - GOERLI = 5, - GÖRLI = 5, - KOVAN = 42, - POLYGON = 137, - ARBITRUM = 42161, -} + // ROPSTEN = 3, + // RINKEBY = 4, + // GOERLI = 5, + // GÖRLI = 5, + // KOVAN = 42, + // POLYGON = 137, + // ARBITRUM = 42161, + + // ApeSwap Additions + BSC = 56, + BSC_DUMMY = -56, // Flipping the value to support two vaults on the same network + BSC_TESTNET = 97, +} \ No newline at end of file diff --git a/balancer-js/src/lib/constants/networkBalancer.ts b/balancer-js/src/lib/constants/networkBalancer.ts new file mode 100644 index 000000000..4e8aa5ca7 --- /dev/null +++ b/balancer-js/src/lib/constants/networkBalancer.ts @@ -0,0 +1,10 @@ +export enum Network { + MAINNET = 1, + ROPSTEN = 3, + RINKEBY = 4, + GOERLI = 5, + GÖRLI = 5, + KOVAN = 42, + POLYGON = 137, + ARBITRUM = 42161, +} diff --git a/balancer-js/src/modules/contracts/contracts.module.ts b/balancer-js/src/modules/contracts/contracts.module.ts index 0c4d0a864..3cd85e31a 100644 --- a/balancer-js/src/modules/contracts/contracts.module.ts +++ b/balancer-js/src/modules/contracts/contracts.module.ts @@ -1,8 +1,8 @@ import { Contract } from '@ethersproject/contracts'; import { Provider } from '@ethersproject/providers'; import { ContractAddresses } from '@/types'; -import { Network } from '@/lib/constants/network'; -import { BALANCER_NETWORK_CONFIG } from '@/lib/constants/config'; +import { Network } from '@/lib/constants/networkBalancer'; +import { BALANCER_NETWORK_CONFIG } from '@/lib/constants/configBalancer'; import { Vault__factory, Vault, diff --git a/balancer-js/src/modules/sdk.helpers.ts b/balancer-js/src/modules/sdk.helpers.ts index 038d0ecbc..5bcc177be 100644 --- a/balancer-js/src/modules/sdk.helpers.ts +++ b/balancer-js/src/modules/sdk.helpers.ts @@ -1,11 +1,11 @@ -import { BALANCER_NETWORK_CONFIG } from '@/lib/constants/config'; +import { APESWAP_NETWORK_CONFIG } from '@/lib/constants/config'; import { BalancerNetworkConfig, BalancerSdkConfig } from '@/types'; export function getNetworkConfig( config: BalancerSdkConfig ): BalancerNetworkConfig { if (typeof config.network === 'number') { - const networkConfig = BALANCER_NETWORK_CONFIG[config.network]; + const networkConfig = APESWAP_NETWORK_CONFIG[config.network]; return { ...networkConfig, From 07ad48e4bd869ff7e7913f02741691e9dea82aa6 Mon Sep 17 00:00:00 2001 From: defifofum Date: Wed, 27 Jul 2022 12:18:29 -0400 Subject: [PATCH 2/5] refactor(config): Update constants for BSC_DUMMY deployment --- balancer-js/package.json | 2 +- balancer-js/src/lib/constants/config.ts | 19 +- .../concerns/weighted/join.concern.ts | 4 +- .../src/modules/sor/pool-data/onChainData.ts | 3 +- .../sor/pool-data/subgraphPoolDataService.ts | 13 +- balancer-js/src/modules/swaps/swaps.module.ts | 4 +- balancer-js/src/test/lib/MockProvider.ts | 2 +- balancer-js/src/test/lib/constants.ts | 219 ++++++++---------- balancer-js/src/test/lib/utils.ts | 4 +- 9 files changed, 129 insertions(+), 141 deletions(-) diff --git a/balancer-js/package.json b/balancer-js/package.json index 4c7483047..eabf591d5 100644 --- a/balancer-js/package.json +++ b/balancer-js/package.json @@ -1,6 +1,6 @@ { "name": "@ape.swap/swap-v2-sdk", - "version": "0.1.17", + "version": "0.0.1-alpha.0", "description": "JavaScript SDK for interacting with the Balancer Protocol V2", "license": "GPL-3.0-only", "homepage": "https://github.com/ApeSwapFinance/apeswap-swap-v2-sdk/balancer-js#readme", diff --git a/balancer-js/src/lib/constants/config.ts b/balancer-js/src/lib/constants/config.ts index 3e0653a5c..180afbfa2 100644 --- a/balancer-js/src/lib/constants/config.ts +++ b/balancer-js/src/lib/constants/config.ts @@ -1,7 +1,19 @@ import { Network } from './network'; import { BalancerNetworkConfig } from '@/types'; -export const apeswapVault = '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719'; +/** + * // FIXME: BSC_DUMMY vault address being used currently + * + * Balancer has deployed the same vault address on every chain which allows them to use a single address here around + * the SDK. ApeSwap has deployed a DUMMY vault on BSC along with the production vault for testing along with Ola, + * which makes this singular address tricky. + * + * For testing purposes we are using the DUMMY vault. + */ +// export const apeswapVault = '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719'; +export const apeswapVault = '0x42B7888FFf938C54faeDF52485C8323c4Fc8C99B'; +// TODO: Remove log +console.log(`swap-v2-sdk/config.ts:: using apeswapVault: ${apeswapVault}.`); export const APESWAP_NETWORK_CONFIG: Record = { [Network.BSC]: { @@ -16,6 +28,7 @@ export const APESWAP_NETWORK_CONFIG: Record = { }, }, urls: { + // FIXME: Need to add subgraph url subgraph: '', }, pools: {}, @@ -89,3 +102,7 @@ export const networkAddresses = ( chainId: number ): BalancerNetworkConfig['addresses'] => APESWAP_NETWORK_CONFIG[chainId as Network].addresses; + +// TODO: Dynamic vault address? +// export const apeswapVault = (chainId: number): string => +// APESWAP_NETWORK_CONFIG[chainId as Network].addresses.contracts.vault; diff --git a/balancer-js/src/modules/pools/pool-types/concerns/weighted/join.concern.ts b/balancer-js/src/modules/pools/pool-types/concerns/weighted/join.concern.ts index 6e41207e1..38da2c692 100644 --- a/balancer-js/src/modules/pools/pool-types/concerns/weighted/join.concern.ts +++ b/balancer-js/src/modules/pools/pool-types/concerns/weighted/join.concern.ts @@ -12,7 +12,7 @@ import { import { Pool } from '@/types'; import { subSlippage } from '@/lib/utils/slippageHelper'; import { AssetHelpers } from '@/lib/utils'; -import { balancerVault } from '@/lib/constants/config'; +import { apeswapVault } from '@/lib/constants/config'; import { Vault__factory } from '@balancer-labs/typechain'; import { BigNumber, parseFixed } from '@ethersproject/bignumber'; import { AddressZero } from '@ethersproject/constants'; @@ -108,7 +108,7 @@ export class WeightedPoolJoin implements JoinConcern { minBPTOut ); - const to = balancerVault; + const to = apeswapVault; const functionName = 'joinPool'; const attributes: JoinPool = { poolId: pool.id, diff --git a/balancer-js/src/modules/sor/pool-data/onChainData.ts b/balancer-js/src/modules/sor/pool-data/onChainData.ts index bdc4b7800..aa5ac8199 100644 --- a/balancer-js/src/modules/sor/pool-data/onChainData.ts +++ b/balancer-js/src/modules/sor/pool-data/onChainData.ts @@ -130,7 +130,8 @@ export async function getOnChainBalances( } >; } catch (err) { - throw `Issue with multicall execution.`; + console.dir({ multicallErr: err }, { depth: null }); + throw new Error(`Issue with multicall execution.`); } const onChainPools: SubgraphPoolBase[] = []; diff --git a/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts b/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts index 8e6984e9a..25c3ce981 100644 --- a/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts +++ b/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts @@ -12,11 +12,14 @@ import { BalancerNetworkConfig, BalancerSdkSorConfig } from '@/types'; const NETWORKS_WITH_LINEAR_POOLS = [ Network.MAINNET, - Network.POLYGON, - Network.ROPSTEN, - Network.RINKEBY, - Network.GOERLI, - Network.KOVAN, + // Network.POLYGON, + // Network.ROPSTEN, + // Network.RINKEBY, + // Network.GOERLI, + // Network.KOVAN, + // NOTE: ApeSwap Additions + Network.BSC, + Network.BSC_DUMMY, ]; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/balancer-js/src/modules/swaps/swaps.module.ts b/balancer-js/src/modules/swaps/swaps.module.ts index 633fbab72..67b8dfc78 100644 --- a/balancer-js/src/modules/swaps/swaps.module.ts +++ b/balancer-js/src/modules/swaps/swaps.module.ts @@ -17,7 +17,7 @@ import { queryBatchSwapWithSor, getSorSwapInfo, } from './queryBatchSwap'; -import { balancerVault } from '@/lib/constants/config'; +import { apeswapVault } from '@/lib/constants/config'; import { getLimitsForSlippage } from './helpers'; import { BalancerSdkConfig } from '@/types'; import { SwapInput } from './types'; @@ -48,7 +48,7 @@ export class Swaps { } this.vaultContract = Vault__factory.connect( - balancerVault, + apeswapVault, this.sor.provider ); } diff --git a/balancer-js/src/test/lib/MockProvider.ts b/balancer-js/src/test/lib/MockProvider.ts index 2aa07f74c..1c2082c96 100644 --- a/balancer-js/src/test/lib/MockProvider.ts +++ b/balancer-js/src/test/lib/MockProvider.ts @@ -5,7 +5,7 @@ import { Network } from '../..'; * This MockProvider serves to prevent/catch external calls the Provider might make. */ export default class MockProvider extends BaseProvider { - constructor(network = Network.KOVAN) { + constructor(network = Network.BSC_TESTNET) { super(network); } diff --git a/balancer-js/src/test/lib/constants.ts b/balancer-js/src/test/lib/constants.ts index 73f676152..2a8cd319f 100644 --- a/balancer-js/src/test/lib/constants.ts +++ b/balancer-js/src/test/lib/constants.ts @@ -72,95 +72,62 @@ export const ADDRESSES = { symbol: 'waUSDC', }, }, - [Network.KOVAN]: { + // FIXME: Fill out config below for all networks + [Network.BSC]: { // Visit https://balancer-faucet.on.fleek.co/#/faucet for test tokens BatchRelayer: { - address: '0x41B953164995c11C81DA73D212ED8Af25741b7Ac', + address: '', }, - ETH: { + BNB: { address: AddressZero, decimals: 18, - symbol: 'ETH', + symbol: 'BNB', }, - BAL: { - address: '0x41286Bb1D3E870f3F750eB7E1C25d7E48c8A1Ac7', + // TODO: Check that WBNB is used as the native wrapped token on BSC + WBNB: { + address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', decimals: 18, - symbol: 'BAL', + symbol: 'WBNB', }, - USDC: { - address: '0xc2569dd7d0fd715B054fBf16E75B001E5c0C1115', - decimals: 6, - symbol: 'USDC', - }, - WBTC: { - address: '0x1C8E3Bcb3378a443CC591f154c5CE0EBb4dA9648', - decimals: 8, - symbol: 'WBTC', - }, - WETH: { - address: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + BANANA: { + address: '0x603c7f932ED1fc6575303D8Fb018fDCBb0f39a95', decimals: 18, - symbol: 'WETH', + symbol: 'BANANA', }, - DAI: { - address: '0x04DF6e4121c27713ED22341E7c7Df330F56f289B', + ETH: { + address: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', decimals: 18, - symbol: 'DAI', + symbol: 'ETH', }, - STETH: { - address: '0x4803bb90d18a1cb7a2187344fe4feb0e07878d05', + BTCB: { + address: '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', decimals: 18, - symbol: 'STETH', + symbol: `BTCB`, }, - wSTETH: { - address: '0xa387b91e393cfb9356a460370842bc8dbb2f29af', + BUSD: { + address: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56', decimals: 18, - symbol: 'wSTETH', + symbol: 'BUSD', }, - USDT_from_AAVE: { - address: '0x13512979ade267ab5100878e2e0f485b568328a4', - decimals: 6, - symbol: 'USDT_from_AAVE', - }, - USDT: { - address: '0x13512979ade267ab5100878e2e0f485b568328a4', - decimals: 6, - symbol: 'USDT', - }, - aUSDT: { - address: '0xe8191aacfcdb32260cda25830dc6c9342142f310', - decimals: 6, - symbol: 'aUSDT', - }, - bUSDT: { - address: '0xe667d48618e71c2a02e4a1b66ed9def1426938b6', + USDC: { + address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', decimals: 18, - symbol: 'bUSDT', - }, - USDC_from_AAVE: { - address: '0xe22da380ee6b445bb8273c81944adeb6e8450422', - decimals: 6, - symbol: 'USDC_from_AAVE', - }, - aUSDC: { - address: '0x0fbddc06a4720408a2f5eb78e62bc31ac6e2a3c4', - decimals: 6, - symbol: 'aUSDC', + symbol: 'USDC', }, - DAI_from_AAVE: { - address: '0xff795577d9ac8bd7d90ee22b6c1703490b6512fd', + DAI: { + address: '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', decimals: 18, - symbol: 'DAI_from_AAVE', + symbol: 'DAI', }, - bDAI: { - address: '0xfcccb77a946b6a3bd59d149f083b5bfbb8004d6d', + USDT: { + address: '0x55d398326f99059fF775485246999027B3197955', decimals: 18, - symbol: 'bDAI', + symbol: 'USDT', }, - STABAL3: { - address: '0x8fd162f338b770f7e879030830cde9173367f301', + STETH: { + address: 'N/A', decimals: 18, - symbol: 'STABAL3', + symbol: 'STETH', }, bbausd: { address: 'N/A', @@ -168,107 +135,107 @@ export const ADDRESSES = { symbol: 'bbausd', }, }, - [Network.POLYGON]: { - MATIC: { + [Network.BSC_DUMMY]: { + BNB: { address: AddressZero, decimals: 18, - symbol: 'MATIC', + symbol: 'BNB', }, - LINK: { - address: '0x53E0bca35eC356BD5ddDFebbD1Fc0fD03FaBad39', + WBNB: { + address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', decimals: 18, - symbol: 'LINK', + symbol: 'WBNB', }, - BAL: { - address: '0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3', + BANANA: { + address: '0x603c7f932ED1fc6575303D8Fb018fDCBb0f39a95', decimals: 18, - symbol: 'BAL', + symbol: 'BANANA', }, - USDC: { - address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', - decimals: 6, - symbol: 'USDC', + ETH: { + address: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', + decimals: 18, + symbol: 'ETH', }, - WBTC: { - address: '0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6', - decimals: 8, - symbol: 'WBTC', + BTCB: { + address: '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', + decimals: 18, + symbol: `BTCB`, }, - WETH: { - address: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + BUSD: { + address: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56', decimals: 18, - symbol: 'WETH', + symbol: 'BUSD', + }, + USDC: { + address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', + decimals: 18, + symbol: 'USDC', }, DAI: { - address: '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063', + address: '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', decimals: 18, symbol: 'DAI', }, + USDT: { + address: '0x55d398326f99059fF775485246999027B3197955', + decimals: 18, + symbol: 'USDT', + }, STETH: { - address: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', + address: 'N/A', decimals: 18, symbol: 'STETH', }, - stUSD_PLUS: { - address: '0x5a5c6aa6164750b530b8f7658b827163b3549a4d', - decimals: 6, - symbol: 'stUSD+', - }, - bstUSD_PLUS: { - address: '0x1aafc31091d93c3ff003cff5d2d8f7ba2e728425', + bbausd: { + address: 'N/A', decimals: 18, - symbol: 'bstUSD+', - }, - USD_PLUS: { - address: '0x5d9d8509c522a47d9285b9e4e9ec686e6a580850', - decimals: 6, - symbol: 'USD_PLUS', + symbol: 'bbausd', }, - USDT: { - address: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F', - decimals: 6, - symbol: 'USDT', + }, + [Network.BSC_TESTNET]: { + BNB: { + address: AddressZero, + decimals: 18, + symbol: 'BNB', }, - DHT: { - address: '0x8C92e38eCA8210f4fcBf17F0951b198Dd7668292', + WBNB: { + address: '0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd', decimals: 18, - symbol: 'DHT', + symbol: 'WBNB', }, - dUSD: { - address: '0xbAe28251B2a4E621aA7e20538c06DEe010Bc06DE', + BANANA: { + address: '0x4Fb99590cA95fc3255D9fA66a1cA46c43C34b09a', decimals: 18, - symbol: 'dUSD', + symbol: 'BANANA', }, - bbausd: { + ETH: { address: 'N/A', decimals: 18, - symbol: 'bbausd', + symbol: 'ETH', }, - }, - [Network.ARBITRUM]: { - WETH: { - address: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', + BTCB: { + address: 'N/A', decimals: 18, - symbol: 'WETH', + symbol: `BTCB`, }, - BAL: { - address: '0x040d1edc9569d4bab2d15287dc5a4f10f56a56b8', + BUSD: { + address: '0x9Fac5878Da670aDB06a21ff127C79e0De8BF3c53', decimals: 18, - symbol: 'BAL', + symbol: 'BUSD', }, USDC: { - address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', - decimals: 6, + address: 'N/A', + decimals: 18, symbol: 'USDC', }, DAI: { - address: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', + address: 'N/A', decimals: 18, symbol: 'DAI', }, USDT: { - address: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', - decimals: 6, + address: 'N/A', + decimals: 18, symbol: 'USDT', }, STETH: { diff --git a/balancer-js/src/test/lib/utils.ts b/balancer-js/src/test/lib/utils.ts index f617c75cf..ff6d75fdb 100644 --- a/balancer-js/src/test/lib/utils.ts +++ b/balancer-js/src/test/lib/utils.ts @@ -1,7 +1,7 @@ import { BalancerSDK } from '@/.'; import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers'; import { BigNumber } from '@ethersproject/bignumber'; -import { balancerVault } from '@/lib/constants/config'; +import { apeswapVault } from '@/lib/constants/config'; import { hexlify, zeroPad } from '@ethersproject/bytes'; import { keccak256 } from '@ethersproject/solidity'; @@ -90,5 +90,5 @@ export const approveToken = async ( signer: JsonRpcSigner ): Promise => { const tokenContract = balancer.contracts.ERC20(token, signer.provider); - return await tokenContract.connect(signer).approve(balancerVault, amount); + return await tokenContract.connect(signer).approve(apeswapVault, amount); }; From f291b11e3b1d2ac7a8e63222239b8a5e1a840e39 Mon Sep 17 00:00:00 2001 From: defifofum Date: Wed, 27 Jul 2022 12:22:15 -0400 Subject: [PATCH 3/5] v0.0.1-alpha.1 --- balancer-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/balancer-js/package.json b/balancer-js/package.json index eabf591d5..62b802933 100644 --- a/balancer-js/package.json +++ b/balancer-js/package.json @@ -1,6 +1,6 @@ { "name": "@ape.swap/swap-v2-sdk", - "version": "0.0.1-alpha.0", + "version": "0.0.1-alpha.1", "description": "JavaScript SDK for interacting with the Balancer Protocol V2", "license": "GPL-3.0-only", "homepage": "https://github.com/ApeSwapFinance/apeswap-swap-v2-sdk/balancer-js#readme", From afa052d0282766edcb0c1ab3ba7d45dec625c415 Mon Sep 17 00:00:00 2001 From: defifofum Date: Thu, 28 Jul 2022 14:53:10 -0400 Subject: [PATCH 4/5] refactor: Remove BSC_DUMMY as network type --- balancer-js/package.json | 3 +- balancer-js/src/lib/constants/config.ts | 79 ++++++++++--------- balancer-js/src/lib/constants/network.ts | 3 +- .../sor/pool-data/subgraphPoolDataService.ts | 2 +- balancer-js/src/test/lib/constants.ts | 57 ------------- 5 files changed, 46 insertions(+), 98 deletions(-) diff --git a/balancer-js/package.json b/balancer-js/package.json index 62b802933..eba82904e 100644 --- a/balancer-js/package.json +++ b/balancer-js/package.json @@ -1,6 +1,6 @@ { "name": "@ape.swap/swap-v2-sdk", - "version": "0.0.1-alpha.1", + "version": "0.0.1-alpha.2", "description": "JavaScript SDK for interacting with the Balancer Protocol V2", "license": "GPL-3.0-only", "homepage": "https://github.com/ApeSwapFinance/apeswap-swap-v2-sdk/balancer-js#readme", @@ -20,6 +20,7 @@ "dist/" ], "scripts": { + "prepublish": "yarn build", "build": "rimraf dist && rollup -c", "dev": "rollup -c -w", "test": "ts-mocha --paths --recursive -p tsconfig.testing.json 'src/**/*.spec.ts'", diff --git a/balancer-js/src/lib/constants/config.ts b/balancer-js/src/lib/constants/config.ts index 180afbfa2..f834dd7f8 100644 --- a/balancer-js/src/lib/constants/config.ts +++ b/balancer-js/src/lib/constants/config.ts @@ -2,53 +2,58 @@ import { Network } from './network'; import { BalancerNetworkConfig } from '@/types'; /** - * // FIXME: BSC_DUMMY vault address being used currently - * - * Balancer has deployed the same vault address on every chain which allows them to use a single address here around + * // NOTE: Balancer has deployed the same vault address on every chain which allows them to use a single address here around * the SDK. ApeSwap has deployed a DUMMY vault on BSC along with the production vault for testing along with Ola, * which makes this singular address tricky. - * + * * For testing purposes we are using the DUMMY vault. */ -// export const apeswapVault = '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719'; -export const apeswapVault = '0x42B7888FFf938C54faeDF52485C8323c4Fc8C99B'; -// TODO: Remove log -console.log(`swap-v2-sdk/config.ts:: using apeswapVault: ${apeswapVault}.`); - -export const APESWAP_NETWORK_CONFIG: Record = { - [Network.BSC]: { - chainId: Network.BSC, //56 - addresses: { - contracts: { - vault: '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719', - multicall: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D', - }, - tokens: { - wrappedNativeAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - }, +const BSC_PRODUCTION = { + chainId: Network.BSC, //56 + addresses: { + contracts: { + vault: '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719', + multicall: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D', }, - urls: { - // FIXME: Need to add subgraph url - subgraph: '', + tokens: { + wrappedNativeAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', }, - pools: {}, }, - [Network.BSC_DUMMY]: { - chainId: Network.BSC, //56 - addresses: { - contracts: { - vault: '0x42B7888FFf938C54faeDF52485C8323c4Fc8C99B', - multicall: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D', - }, - tokens: { - wrappedNativeAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - }, + urls: { + // FIXME: Need to add subgraph url + subgraph: '', + }, + pools: {}, +}; + +const BSC_DUMMY = { + chainId: Network.BSC, //56 + addresses: { + contracts: { + vault: '0x42B7888FFf938C54faeDF52485C8323c4Fc8C99B', + multicall: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D', }, - urls: { - subgraph: 'http://65.108.138.33:8000/subgraphs/name/apeswap/balancer-v2', + tokens: { + wrappedNativeAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', }, - pools: {}, }, + urls: { + subgraph: 'http://65.108.138.33:8000/subgraphs/name/apeswap/balancer-v2', + }, + pools: {}, +}; + +// NOTE: Balancer exports a hardcoded vault address +// export const apeswapVault = '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719'; +// export const apeswapVault = '0x42B7888FFf938C54faeDF52485C8323c4Fc8C99B'; +// FIXME: Using BSC_DUMMY config +const bscConfig = BSC_DUMMY; +export const apeswapVault = bscConfig.addresses.contracts.vault; +// TODO: Remove log +console.log(`swap-v2-sdk/config.ts:: using apeswapVault: ${apeswapVault}.`); + +export const APESWAP_NETWORK_CONFIG: Record = { + [Network.BSC]: bscConfig, [Network.BSC_TESTNET]: { chainId: Network.BSC_TESTNET, //97 addresses: { diff --git a/balancer-js/src/lib/constants/network.ts b/balancer-js/src/lib/constants/network.ts index d8ce9c32f..8eec656ad 100644 --- a/balancer-js/src/lib/constants/network.ts +++ b/balancer-js/src/lib/constants/network.ts @@ -10,6 +10,5 @@ export enum Network { // ApeSwap Additions BSC = 56, - BSC_DUMMY = -56, // Flipping the value to support two vaults on the same network BSC_TESTNET = 97, -} \ No newline at end of file +} diff --git a/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts b/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts index 25c3ce981..c5d7504ed 100644 --- a/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts +++ b/balancer-js/src/modules/sor/pool-data/subgraphPoolDataService.ts @@ -19,7 +19,7 @@ const NETWORKS_WITH_LINEAR_POOLS = [ // Network.KOVAN, // NOTE: ApeSwap Additions Network.BSC, - Network.BSC_DUMMY, + Network.BSC_TESTNET, ]; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/balancer-js/src/test/lib/constants.ts b/balancer-js/src/test/lib/constants.ts index 2a8cd319f..52c1279c0 100644 --- a/balancer-js/src/test/lib/constants.ts +++ b/balancer-js/src/test/lib/constants.ts @@ -135,63 +135,6 @@ export const ADDRESSES = { symbol: 'bbausd', }, }, - [Network.BSC_DUMMY]: { - BNB: { - address: AddressZero, - decimals: 18, - symbol: 'BNB', - }, - WBNB: { - address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - decimals: 18, - symbol: 'WBNB', - }, - BANANA: { - address: '0x603c7f932ED1fc6575303D8Fb018fDCBb0f39a95', - decimals: 18, - symbol: 'BANANA', - }, - ETH: { - address: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', - decimals: 18, - symbol: 'ETH', - }, - BTCB: { - address: '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', - decimals: 18, - symbol: `BTCB`, - }, - BUSD: { - address: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56', - decimals: 18, - symbol: 'BUSD', - }, - USDC: { - address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', - decimals: 18, - symbol: 'USDC', - }, - DAI: { - address: '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', - decimals: 18, - symbol: 'DAI', - }, - USDT: { - address: '0x55d398326f99059fF775485246999027B3197955', - decimals: 18, - symbol: 'USDT', - }, - STETH: { - address: 'N/A', - decimals: 18, - symbol: 'STETH', - }, - bbausd: { - address: 'N/A', - decimals: 18, - symbol: 'bbausd', - }, - }, [Network.BSC_TESTNET]: { BNB: { address: AddressZero, From 66a7f80bb134fe3d209eb546aa2684053941bf7d Mon Sep 17 00:00:00 2001 From: defifofum Date: Mon, 22 Aug 2022 14:49:26 -0400 Subject: [PATCH 5/5] fix: Dummy config subgraph --- balancer-js/src/lib/constants/config.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/balancer-js/src/lib/constants/config.ts b/balancer-js/src/lib/constants/config.ts index f834dd7f8..c7c32d3f3 100644 --- a/balancer-js/src/lib/constants/config.ts +++ b/balancer-js/src/lib/constants/config.ts @@ -38,19 +38,21 @@ const BSC_DUMMY = { }, }, urls: { - subgraph: 'http://65.108.138.33:8000/subgraphs/name/apeswap/balancer-v2', + subgraph: + 'https://balancer.apeswapgraphs.com/subgraphs/name/apeswap/balancer-v2', }, pools: {}, }; -// NOTE: Balancer exports a hardcoded vault address -// export const apeswapVault = '0x000a9e000a35f2cBbE4326578E19dd8Fb4913719'; -// export const apeswapVault = '0x42B7888FFf938C54faeDF52485C8323c4Fc8C99B'; -// FIXME: Using BSC_DUMMY config -const bscConfig = BSC_DUMMY; + +const useDummy = Boolean(process.env.VUE_APP_DUMMY); +const bscConfig = process.env.VUE_APP_DUMMY ? BSC_DUMMY : BSC_PRODUCTION; export const apeswapVault = bscConfig.addresses.contracts.vault; // TODO: Remove log console.log(`swap-v2-sdk/config.ts:: using apeswapVault: ${apeswapVault}.`); +if (useDummy) { + console.log(`swap-v2-sdk/config.ts:: using BSC DUMMY config.`); +} export const APESWAP_NETWORK_CONFIG: Record = { [Network.BSC]: bscConfig,