Skip to content

Commit

Permalink
Merge pull request #288 from balancer-labs/develop
Browse files Browse the repository at this point in the history
Release 0.1.46
  • Loading branch information
johngrantuk authored Jan 27, 2023
2 parents 4bedd9e + 4ec3ff2 commit 1fc00bb
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 19 deletions.
15 changes: 15 additions & 0 deletions balancer-js/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
]
},
};
12 changes: 6 additions & 6 deletions balancer-js/examples/swapSor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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!);

Expand Down
4 changes: 2 additions & 2 deletions balancer-js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
48 changes: 48 additions & 0 deletions balancer-js/src/lib/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
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
Expand Down Expand Up @@ -86,6 +100,16 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
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
Expand Down Expand Up @@ -114,6 +138,12 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-one-blocks',
},
pools: {},
sorConnectingTokens: [
{
symbol: 'weth',
address: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
},
],
},
[Network.KOVAN]: {
chainId: Network.KOVAN, //42
Expand Down Expand Up @@ -207,6 +237,12 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
'https://api.thegraph.com/subgraphs/name/blocklytics/goerli-blocks',
},
pools: {},
sorConnectingTokens: [
{
symbol: 'weth',
address: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1',
},
],
},
[Network.OPTIMISM]: {
chainId: Network.OPTIMISM, //10
Expand All @@ -231,6 +267,12 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
gaugesSubgraph: '',
},
pools: {},
sorConnectingTokens: [
{
symbol: 'weth',
address: '0x4200000000000000000000000000000000000006',
},
],
},
[Network.GNOSIS]: {
chainId: Network.GNOSIS, //100
Expand All @@ -254,6 +296,12 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
gaugesSubgraph: '',
},
pools: {},
sorConnectingTokens: [
{
symbol: 'weth',
address: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
},
],
},
};

Expand Down
41 changes: 41 additions & 0 deletions balancer-js/src/lib/constants/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions balancer-js/src/lib/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion balancer-js/src/lib/utils/slippageHelper.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
4 changes: 2 additions & 2 deletions balancer-js/src/modules/data/token-yields/tokens/tranchess.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion balancer-js/src/modules/pools/apr/apr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion balancer-js/src/modules/pools/apr/apr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions balancer-js/src/modules/sor/sor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 43 additions & 0 deletions balancer-js/src/test/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -342,6 +353,11 @@ export const ADDRESSES = {
symbol: 'bb-am-usd',
slot: 0,
},
brz: {
address: '0x491a4eb4f1fc3bff8e1d2fc856a6a46663ad556f',
decimals: 4,
symbol: 'BRZ',
},
},
[Network.ARBITRUM]: {
WETH: {
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions balancer-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface BalancerNetworkConfig {
wETHwstETH?: PoolReference;
};
poolsToIgnore?: string[];
sorConnectingTokens?: { symbol: string; address: string }[];
}

export interface BalancerDataRepositories {
Expand Down
8 changes: 4 additions & 4 deletions balancer-js/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 1fc00bb

Please sign in to comment.