diff --git a/balancer-js/.eslintrc.js b/balancer-js/.eslintrc.js index 00a9809b5..481cd92f7 100644 --- a/balancer-js/.eslintrc.js +++ b/balancer-js/.eslintrc.js @@ -7,5 +7,20 @@ module.exports = { 'comma-spacing': ['error', { before: false, after: true }], 'prettier/prettier': 'error', 'mocha-no-only/mocha-no-only': ['error'], + 'no-restricted-imports': [ + 'error', + { + patterns: [ + { + // Avoid imports using 'ethers*' because they lead to compilation issues in rollup builds + // Probably related to rollup config not being able to resolve the 'ethers*' + // migrate to: imports (globals: { ethers: 'ethers' }) once we switch to ethers vs individual packages + group: ['ethers*'], + message: + "import from '@ethersproject/*' instead to avoid rollup build issues", + }, + ], + }, + ] }, }; diff --git a/balancer-js/examples/swapSor.ts b/balancer-js/examples/swapSor.ts index 4f3511f3f..7c7f6f40c 100644 --- a/balancer-js/examples/swapSor.ts +++ b/balancer-js/examples/swapSor.ts @@ -16,7 +16,7 @@ import { canUseJoinExit, } from '../src/index'; -import { ADDRESSES } from '../src/test/lib/constants'; +import { ADDRESSES, PROVIDER_URLS } from '../src/test/lib/constants'; dotenv.config(); @@ -119,12 +119,12 @@ async function getAndProcessSwaps( } async function swapExample() { - const network = Network.MAINNET; - const rpcUrl = `https://mainnet.infura.io/v3/${process.env.INFURA}`; - const tokenIn = ADDRESSES[network].WETH.address; - const tokenOut = ADDRESSES[network].auraBal?.address; + const network = Network.POLYGON; + const rpcUrl = PROVIDER_URLS[network]; + const tokenIn = ADDRESSES[network].USDC.address; + const tokenOut = ADDRESSES[network].brz.address; const swapType = SwapTypes.SwapExactIn; - const amount = parseFixed('18', 18); + const amount = parseFixed('200', 6); // Currently Relayer only suitable for ExactIn and non-eth swaps const canUseJoinExitPaths = canUseJoinExit(swapType, tokenIn!, tokenOut!); diff --git a/balancer-js/package.json b/balancer-js/package.json index 4a5142e65..1b78e7cc1 100644 --- a/balancer-js/package.json +++ b/balancer-js/package.json @@ -1,6 +1,6 @@ { "name": "@balancer-labs/sdk", - "version": "0.1.45", + "version": "0.1.46", "description": "JavaScript SDK for interacting with the Balancer Protocol V2", "license": "GPL-3.0-only", "homepage": "https://github.com/balancer-labs/balancer-sdk#readme", @@ -81,7 +81,7 @@ "typescript": "^4.0.2" }, "dependencies": { - "@balancer-labs/sor": "^4.0.1-beta.18", + "@balancer-labs/sor": "^4.1.0-beta.0", "@balancer-labs/typechain": "^1.0.0", "@ethersproject/abi": "^5.4.0", "@ethersproject/abstract-signer": "^5.4.0", diff --git a/balancer-js/src/lib/constants/config.ts b/balancer-js/src/lib/constants/config.ts index 39535d35b..2ef6fda5f 100644 --- a/balancer-js/src/lib/constants/config.ts +++ b/balancer-js/src/lib/constants/config.ts @@ -55,6 +55,20 @@ export const BALANCER_NETWORK_CONFIG: Record = { poolsToIgnore: [ '0xbd482ffb3e6e50dc1c437557c3bea2b68f3683ee', // a pool made by an external dev who was playing with a novel rate provider mechanism in production. ], + sorConnectingTokens: [ + { + symbol: 'wEth', + address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + }, + { + symbol: 'wstEth', + address: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', + }, + { + symbol: 'DOLA', + address: '0x865377367054516e17014CcdED1e7d814EDC9ce4', + }, + ], }, [Network.POLYGON]: { chainId: Network.POLYGON, //137 @@ -86,6 +100,16 @@ export const BALANCER_NETWORK_CONFIG: Record = { poolsToIgnore: [ '0x600bd01b6526611079e12e1ff93aba7a3e34226f', // This pool has rateProviders with incorrect scaling ], + sorConnectingTokens: [ + { + symbol: 'weth', + address: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', + }, + { + symbol: 'bbrz2', + address: '0xe22483774bd8611be2ad2f4194078dac9159f4ba', + }, // Joins Stables<>BRZ via https://app.balancer.fi/#/polygon/pool/0x4a0b73f0d13ff6d43e304a174697e3d5cfd310a400020000000000000000091c + ], }, [Network.ARBITRUM]: { chainId: Network.ARBITRUM, //42161 @@ -114,6 +138,12 @@ export const BALANCER_NETWORK_CONFIG: Record = { 'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-one-blocks', }, pools: {}, + sorConnectingTokens: [ + { + symbol: 'weth', + address: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', + }, + ], }, [Network.KOVAN]: { chainId: Network.KOVAN, //42 @@ -207,6 +237,12 @@ export const BALANCER_NETWORK_CONFIG: Record = { 'https://api.thegraph.com/subgraphs/name/blocklytics/goerli-blocks', }, pools: {}, + sorConnectingTokens: [ + { + symbol: 'weth', + address: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1', + }, + ], }, [Network.OPTIMISM]: { chainId: Network.OPTIMISM, //10 @@ -231,6 +267,12 @@ export const BALANCER_NETWORK_CONFIG: Record = { gaugesSubgraph: '', }, pools: {}, + sorConnectingTokens: [ + { + symbol: 'weth', + address: '0x4200000000000000000000000000000000000006', + }, + ], }, [Network.GNOSIS]: { chainId: Network.GNOSIS, //100 @@ -254,6 +296,12 @@ export const BALANCER_NETWORK_CONFIG: Record = { gaugesSubgraph: '', }, pools: {}, + sorConnectingTokens: [ + { + symbol: 'weth', + address: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', + }, + ], }, }; diff --git a/balancer-js/src/lib/constants/pools.ts b/balancer-js/src/lib/constants/pools.ts index f6049d3ba..74ae43745 100644 --- a/balancer-js/src/lib/constants/pools.ts +++ b/balancer-js/src/lib/constants/pools.ts @@ -545,6 +545,46 @@ const POOLS_ARBITRUM: Pools = { Metadata: {}, }; +const POOLS_GNOSIS: Pools = { + IdsMap: {}, + Pagination: { + PerPage: 10, + PerPool: 10, + PerPoolInitial: 5, + }, + DelegateOwner: '0xba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b', + ZeroAddress: '0x0000000000000000000000000000000000000000', + DynamicFees: { + Gauntlet: [], + }, + BlockList: [''], + ExcludedPoolTypes: [ + 'Element', + 'AaveLinear', + 'Linear', + 'ERC4626Linear', + 'FX', + 'Gyro2', + 'Gyro3', + 'GyroE', + 'HighAmpComposableStable', + ], + Stable: { + AllowList: [ + '0x11884da90fb4221b3aa288a7741c51ec4fc43b2f000000000000000000000004', + '0x707b7d4a1bae449d546dcab869256591bbb3d70b000000000000000000000000', + ], + }, + Investment: { + AllowList: [], + }, + Factories: {}, + Stakable: { + AllowList: [], + }, + Metadata: {}, +}; + const POOLS_GENERIC: Pools = { IdsMap: {}, Pagination: { @@ -642,6 +682,7 @@ const POOLS_MAP = { [Network.MAINNET]: POOLS_MAINNET, [Network.POLYGON]: POOLS_POLYGON, [Network.ARBITRUM]: POOLS_ARBITRUM, + [Network.GNOSIS]: POOLS_GNOSIS, }; export function POOLS(networkId: Network): Pools { diff --git a/balancer-js/src/lib/constants/tokens.ts b/balancer-js/src/lib/constants/tokens.ts index 1c826e02b..141dd3fd5 100644 --- a/balancer-js/src/lib/constants/tokens.ts +++ b/balancer-js/src/lib/constants/tokens.ts @@ -63,6 +63,18 @@ export const TOKENS_ARBITRUM: TokenConstants = { }, }; +export const TOKENS_GNOSIS: TokenConstants = { + Popular: { + Symbols: ['xDAI', 'WXDAI', 'WETH', 'BAL'], + }, + Addresses: { + nativeAsset: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + wNativeAsset: '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d', + WETH: '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1', + BAL: '0x7eF541E2a22058048904fE5744f9c7E4C57AF717', + }, +}; + export const TOKENS_KOVAN: TokenConstants = { Popular: { Symbols: ['WBTC', 'DAI', 'USDC', 'BAL', 'AAVE', 'WETH'], @@ -173,6 +185,7 @@ export const TOKENS_MAP = { [Network.MAINNET]: TOKENS_MAINNET, [Network.POLYGON]: TOKENS_POLYGON, [Network.ARBITRUM]: TOKENS_ARBITRUM, + [Network.GNOSIS]: TOKENS_GNOSIS, }; export function TOKENS(networkId: Network): TokenConstants { diff --git a/balancer-js/src/lib/utils/slippageHelper.spec.ts b/balancer-js/src/lib/utils/slippageHelper.spec.ts index 713361656..26edd9d9a 100644 --- a/balancer-js/src/lib/utils/slippageHelper.spec.ts +++ b/balancer-js/src/lib/utils/slippageHelper.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { BigNumber } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; import { subSlippage, addSlippage } from './slippageHelper'; describe('slippage helper', () => { diff --git a/balancer-js/src/modules/data/token-yields/tokens/tranchess.spec.ts b/balancer-js/src/modules/data/token-yields/tokens/tranchess.spec.ts index 98531c99b..b32fc9048 100644 --- a/balancer-js/src/modules/data/token-yields/tokens/tranchess.spec.ts +++ b/balancer-js/src/modules/data/token-yields/tokens/tranchess.spec.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { tranchess, yieldTokens } from './tranchess'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; -import { parseEther } from 'ethers/lib/utils'; +import { parseEther } from '@ethersproject/units'; const mockedResponse = [ { diff --git a/balancer-js/src/modules/data/token-yields/tokens/tranchess.ts b/balancer-js/src/modules/data/token-yields/tokens/tranchess.ts index 49d0568c5..341a91f78 100644 --- a/balancer-js/src/modules/data/token-yields/tokens/tranchess.ts +++ b/balancer-js/src/modules/data/token-yields/tokens/tranchess.ts @@ -1,5 +1,5 @@ -import { BigNumber } from 'ethers'; -import { formatEther } from 'ethers/lib/utils'; +import { BigNumber } from '@ethersproject/bignumber'; +import { formatEther } from '@ethersproject/units'; import { AprFetcher } from '../repository'; import axios from 'axios'; diff --git a/balancer-js/src/modules/pools/apr/apr.spec.ts b/balancer-js/src/modules/pools/apr/apr.spec.ts index cf073e70e..af86d2860 100644 --- a/balancer-js/src/modules/pools/apr/apr.spec.ts +++ b/balancer-js/src/modules/pools/apr/apr.spec.ts @@ -147,7 +147,7 @@ describe('pool apr', () => { // Notice one token in gauge is worth 40% of it's value it('has bal rewards as ~40% apr', async () => { const now = Math.round(Date.now() / 1000); - const balEmissions = emissions.between(now, now + 365 * 86400); + const balEmissions = (emissions.weekly(now) / 7) * 365; const gauge = { ...baseGauge, diff --git a/balancer-js/src/modules/pools/apr/apr.ts b/balancer-js/src/modules/pools/apr/apr.ts index bce81899c..ad22b42b5 100644 --- a/balancer-js/src/modules/pools/apr/apr.ts +++ b/balancer-js/src/modules/pools/apr/apr.ts @@ -279,7 +279,7 @@ export class PoolApr { } const now = Math.round(new Date().getTime() / 1000); - const totalBalEmissions = emissions.between(now, now + 365 * 86400); + const totalBalEmissions = (emissions.weekly(now) / 7) * 365; const gaugeBalEmissions = totalBalEmissions * gauge.relativeWeight; const gaugeBalEmissionsUsd = gaugeBalEmissions * balPriceUsd; const gaugeSupply = (gauge.workingSupply + 0.4) / 0.4; // Only 40% of LP token staked accrue emissions, totalSupply = workingSupply * 2.5 diff --git a/balancer-js/src/modules/sor/sor.module.ts b/balancer-js/src/modules/sor/sor.module.ts index d1278ca9f..4d359ed94 100644 --- a/balancer-js/src/modules/sor/sor.module.ts +++ b/balancer-js/src/modules/sor/sor.module.ts @@ -59,6 +59,7 @@ export class Sor extends SOR { weth: network.addresses.tokens.wrappedNativeAsset, lbpRaisingTokens: network.addresses.tokens?.lbpRaisingTokens, wETHwstETH: network.pools.wETHwstETH, + connectingTokens: network.sorConnectingTokens, }; } diff --git a/balancer-js/src/modules/swaps/swaps.module.integration.spec.ts b/balancer-js/src/modules/swaps/swaps.module.integration.spec.ts index 3c5338bf9..2aba427e5 100644 --- a/balancer-js/src/modules/swaps/swaps.module.integration.spec.ts +++ b/balancer-js/src/modules/swaps/swaps.module.integration.spec.ts @@ -6,7 +6,7 @@ import { AddressZero, MaxUint256 } from '@ethersproject/constants'; import { SwapInfo } from '@balancer-labs/sor'; import hardhat from 'hardhat'; import { JsonRpcProvider, TransactionReceipt } from '@ethersproject/providers'; -import { BigNumber } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; import { getForkedPools } from '@/test/lib/mainnetPools'; dotenv.config(); diff --git a/balancer-js/src/test/lib/constants.ts b/balancer-js/src/test/lib/constants.ts index 8c4269ced..be53b5094 100644 --- a/balancer-js/src/test/lib/constants.ts +++ b/balancer-js/src/test/lib/constants.ts @@ -1,6 +1,17 @@ +import dotenv from 'dotenv'; import { Network } from '@/lib/constants/network'; import { AddressZero } from '@ethersproject/constants'; +dotenv.config(); + +export const PROVIDER_URLS = { + [Network.MAINNET]: `https://mainnet.infura.io/v3/${process.env.INFURA}`, + [Network.GOERLI]: `https://goerli.infura.io/v3/${process.env.INFURA}`, + [Network.KOVAN]: `https://kovan.infura.io/v3/${process.env.INFURA}`, + [Network.POLYGON]: `https://polygon-mainnet.infura.io/v3/${process.env.INFURA}`, + [Network.ARBITRUM]: `https://arbitrum-mainnet.infura.io/v3/${process.env.INFURA}`, +}; + export const ADDRESSES = { [Network.MAINNET]: { BatchRelayer: { @@ -342,6 +353,11 @@ export const ADDRESSES = { symbol: 'bb-am-usd', slot: 0, }, + brz: { + address: '0x491a4eb4f1fc3bff8e1d2fc856a6a46663ad556f', + decimals: 4, + symbol: 'BRZ', + }, }, [Network.ARBITRUM]: { WETH: { @@ -398,6 +414,33 @@ export const ADDRESSES = { slot: 52, }, }, + [Network.GNOSIS]: { + WETH: { + address: '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1', + decimals: 18, + symbol: 'WETH', + }, + BAL: { + address: '0x7eF541E2a22058048904fE5744f9c7E4C57AF717', + decimals: 18, + symbol: 'BAL', + }, + USDC: { + address: '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83', + decimals: 6, + symbol: 'USDC', + }, + WXDAI: { + address: '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d', + decimals: 18, + symbol: 'DAI', + }, + USDT: { + address: '0x4ECaBa5870353805a9F068101A40E0f32ed605C6', + decimals: 6, + symbol: 'USDT', + }, + }, [Network.GOERLI]: { USDC_old: { address: '0xe0c9275e44ea80ef17579d33c55136b7da269aeb', diff --git a/balancer-js/src/types.ts b/balancer-js/src/types.ts index 934f5edd6..5149799c5 100644 --- a/balancer-js/src/types.ts +++ b/balancer-js/src/types.ts @@ -101,6 +101,7 @@ export interface BalancerNetworkConfig { wETHwstETH?: PoolReference; }; poolsToIgnore?: string[]; + sorConnectingTokens?: { symbol: string; address: string }[]; } export interface BalancerDataRepositories { diff --git a/balancer-js/yarn.lock b/balancer-js/yarn.lock index d9afd62ee..48c6f7745 100644 --- a/balancer-js/yarn.lock +++ b/balancer-js/yarn.lock @@ -503,10 +503,10 @@ "@babel/helper-validator-identifier" "^7.19.1" to-fast-properties "^2.0.0" -"@balancer-labs/sor@^4.0.1-beta.18": - version "4.0.1-beta.18" - resolved "https://registry.yarnpkg.com/@balancer-labs/sor/-/sor-4.0.1-beta.18.tgz#811af4b41f8e9f670c1a38e5f5f2f131d28178ed" - integrity sha512-tNY9OIptCVCysSYY6QKBIpJleM66DMKRK78t1WOG1boJbay3kCm+x9R4+6LN5n05gDYM0PE2QwCPytOxzkrCfA== +"@balancer-labs/sor@^4.1.0-beta.0": + version "4.1.0-beta.0" + resolved "https://registry.yarnpkg.com/@balancer-labs/sor/-/sor-4.1.0-beta.0.tgz#9d22921bd805381b9d78cff5e5e62331b48c4e5e" + integrity sha512-NwnaB307u+3NCwhV4ro/jiyWgsaJQ2F7mcjBnUYrtXjDzGCMCM+0+mW21hnSBprJYZ55T6LEFAQAK0ADDT/uLQ== dependencies: isomorphic-fetch "^2.2.1"