Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Relayer V5 #401

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion balancer-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"node": "npx hardhat node --tsconfig tsconfig.testing.json --fork $(. ./.env && echo $ALCHEMY_URL)",
"node:goerli": "npx hardhat --tsconfig tsconfig.testing.json --config hardhat.config.goerli.ts node --fork $(grep ALCHEMY_URL_GOERLI .env | cut -d '=' -f2 | tail -1) --port 8000",
"node:polygon": "npx hardhat --tsconfig tsconfig.testing.json --config hardhat.config.polygon.ts node --fork $(grep ALCHEMY_URL_POLYGON .env | cut -d '=' -f2 | tail -1) --port 8137",
"typechain:generate": "npx typechain --target ethers-v5 --out-dir src/contracts './src/lib/abi/Vault.json' './src/lib/abi/WeightedPoolFactory.json' './src/lib/abi/ComposableStableFactory.json' './src/lib/abi/BalancerHelpers.json' './src/lib/abi/LidoRelayer.json' './src/lib/abi/WeightedPool.json' './src/lib/abi/ComposableStable.json' './src/lib/abi/ERC4626LinearPoolFactory.json' './src/lib/abi/ERC4626LinearPool.json' './src/lib/abi/AaveLinearPoolFactory.json' './src/lib/abi/AaveLinearPool.json' './src/lib/abi/EulerLinearPoolFactory.json' './src/lib/abi/EulerLinearPool.json' './src/lib/abi/GearboxLinearPoolFactory.json' './src/lib/abi/GearboxLinearPool.json' './src/lib/abi/YearnLinearPoolFactory.json' './src/lib/abi/YearnLinearPool.json'"
"typechain:generate": "npx typechain --target ethers-v5 --out-dir src/contracts './src/lib/abi/Vault.json' './src/lib/abi/WeightedPoolFactory.json' './src/lib/abi/ComposableStableFactory.json' './src/lib/abi/BalancerHelpers.json' './src/lib/abi/LidoRelayer.json' './src/lib/abi/WeightedPool.json' './src/lib/abi/ComposableStable.json' './src/lib/abi/ERC4626LinearPoolFactory.json' './src/lib/abi/ERC4626LinearPool.json' './src/lib/abi/AaveLinearPoolFactory.json' './src/lib/abi/AaveLinearPool.json' './src/lib/abi/EulerLinearPoolFactory.json' './src/lib/abi/EulerLinearPool.json' './src/lib/abi/GearboxLinearPoolFactory.json' './src/lib/abi/GearboxLinearPool.json' './src/lib/abi/YearnLinearPoolFactory.json' './src/lib/abi/YearnLinearPool.json' './src/lib/abi/RelayerV5.json'"
},
"devDependencies": {
"@ethersproject/solidity": "^5.6.1",
Expand Down
38 changes: 38 additions & 0 deletions balancer-js/src/lib/abi/RelayerV5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"inputs": [
{ "internalType": "contract IVault", "name": "vault", "type": "address" },
{ "internalType": "address", "name": "libraryAddress", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "getLibrary",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getVault",
"outputs": [
{ "internalType": "contract IVault", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes[]", "name": "data", "type": "bytes[]" }
],
"name": "multicall",
"outputs": [
{ "internalType": "bytes[]", "name": "results", "type": "bytes[]" }
],
"stateMutability": "payable",
"type": "function"
},
{ "stateMutability": "payable", "type": "receive" }
]
6 changes: 6 additions & 0 deletions balancer-js/src/lib/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
lidoRelayer: '0xdcdbf71A870cc60C6F9B621E28a7D3Ffd6Dd4965',
relayerV3: '0x886A3Ec7bcC508B8795990B60Fa21f85F9dB7948',
johngrantuk marked this conversation as resolved.
Show resolved Hide resolved
relayerV4: '0x2536dfeeCB7A0397CF98eDaDA8486254533b1aFA',
relayerV5: '0xfeA793Aa415061C483D2390414275AD314B3F621',
gaugeController: '0xc128468b7ce63ea702c1f104d55a2566b13d3abd',
feeDistributor: '0xD3cf852898b21fc233251427c2DC93d3d604F3BB',
protocolFeePercentagesProvider:
Expand Down Expand Up @@ -97,6 +98,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
gaugeClaimHelper: '0xaeb406b0e430bf5ea2dc0b9fe62e4e53f74b3a33',
relayerV3: '0xcf6a66E32dCa0e26AcC3426b851FD8aCbF12Dac7',
relayerV4: '0x28A224d9d398a1eBB7BA69BCA515898966Bb1B6b',
relayerV5: '0xd18d5D377eb23362e54Fa496597d7E962d56C554',
balancerHelpers: '0x239e55F427D44C3cc793f49bFB507ebe76638a2b',
weightedPoolFactory: '0x0e39C3D9b2ec765eFd9c5c70BB290B1fCD8536E3',
composableStablePoolFactory:
Expand Down Expand Up @@ -149,6 +151,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
gaugeClaimHelper: '0xa0dabebaad1b243bbb243f933013d560819eb66f',
relayerV3: '0x42E49B48573c725ee32d2579060Ed06894f97002',
relayerV4: '0x5bf3B7c14b10f16939d63Bd679264A1Aa951B4D5',
relayerV5: '0x598ce0f1ab64B27256759ef99d883EE51138b9bd',
balancerHelpers: '0x77d46184d22CA6a3726a2F500c776767b6A3d6Ab',
weightedPoolFactory: '0x8df6EfEc5547e31B0eb7d1291B511FF8a2bf987c',
composableStablePoolFactory:
Expand Down Expand Up @@ -255,6 +258,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
multicall: '0x77dCa2C955b15e9dE4dbBCf1246B4B85b651e50e',
relayerV3: '0x7b9B6f094DC2Bd1c12024b0D9CC63d6993Be1888',
relayerV4: '0x00e695aA8000df01B8DC8401B4C34Fba5D56BBb2',
relayerV5: '0x03F1ab8b19bcE21EB06C364aEc9e40322572a1e9',
gaugeController: '0xBB1CE49b16d55A1f2c6e88102f32144C7334B116',
veBal: '0x33A99Dcc4C85C014cf12626959111D5898bbCAbF',
veBalProxy: '0xA1F107D1cD709514AE8A914eCB757E95f9cedB31',
Expand Down Expand Up @@ -297,6 +301,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
multicall: '0x2dc0e2aa608532da689e89e237df582b783e552c',
relayerV3: '0x195CcCBE464EF9073d1f7A1ba1C9Bf0f56dfFFff',
relayerV4: '0x1a58897Ab366082028ced3740900ecBD765Af738',
relayerV5: '0x03F1ab8b19bcE21EB06C364aEc9e40322572a1e9',
balancerHelpers: '0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9',
weightedPoolFactory: '0x0e39C3D9b2ec765eFd9c5c70BB290B1fCD8536E3',
composableStablePoolFactory:
Expand Down Expand Up @@ -335,6 +340,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
vault: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
multicall: '0xbb6fab6b627947dae0a75808250d8b2652952cb5',
relayerV4: '0xeF606F58A4FD0fCcb066c6203d0994694d3eB2D3',
relayerV5: '0x3536fD480CA495Ac91E698A703248A8915c137a3',
balancerHelpers: '0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9',
weightedPoolFactory: '0xf302f9F50958c5593770FDf4d4812309fF77414f',
composableStablePoolFactory:
Expand Down
8 changes: 8 additions & 0 deletions balancer-js/src/modules/contracts/contracts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Erc4626LinearPoolFactory } from '@/modules/contracts/implementations/fa
import { EulerLinearPoolFactory } from '@/modules/contracts/implementations/factories/euler-linear-pool-factory';
import { YearnLinearPoolFactory } from '@/modules/contracts/implementations/factories/yearn-linear-pool-factory';
import { GearboxLinearPoolFactory } from '@/modules/contracts/implementations/factories/gearbox-linear-pool-factory';
import { RelayerV5, RelayerV5__factory } from '@/contracts';

type ContractFactory = (
address: string,
Expand All @@ -46,6 +47,7 @@ export interface ContractInstances {
multicall: Contract;
relayerV3?: Contract;
relayerV4?: Contract;
relayerV5?: RelayerV5;
johngrantuk marked this conversation as resolved.
Show resolved Hide resolved
vault: Vault;
veBal?: VeBal;
veBalProxy?: VeBalProxy;
Expand All @@ -66,6 +68,7 @@ export class Contracts {
multicall: Contract;
relayerV3?: Contract;
relayerV4?: Contract;
relayerV5?: RelayerV5;
vault: Vault;
veBal?: VeBal;
veBalProxy?: VeBalProxy;
Expand Down Expand Up @@ -108,6 +111,11 @@ export class Contracts {
this.relayerV3 = Relayer(this.contractAddresses.relayerV3, provider, 3);
if (this.contractAddresses.relayerV4)
this.relayerV4 = Relayer(this.contractAddresses.relayerV4, provider, 4);
if (this.contractAddresses.relayerV5)
this.relayerV5 = RelayerV5__factory.connect(
this.contractAddresses.relayerV5,
provider
);

if (this.contractAddresses.veBal) {
this.veBal = new VeBal(this.contractAddresses, provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const TEST_BOOSTED_WEIGHTED_META_GENERAL = true;
* - Uncomment section below:
*/
const network = Network.GOERLI;
const blockNumber = 7890980;
const blockNumber = 8744170;
const { ALCHEMY_URL_GOERLI: jsonRpcUrl } = process.env;
const rpcUrl = 'http://127.0.0.1:8000';

Expand Down Expand Up @@ -113,7 +113,7 @@ const { contracts, contractAddresses } = new Contracts(
network as number,
provider
);
const relayer = contractAddresses.relayerV4 as string;
const relayer = contractAddresses.relayerV5 as string;

const testFlow = async (
pool: { id: string; address: string; slot: number },
Expand Down
14 changes: 6 additions & 8 deletions balancer-js/src/modules/exits/exits.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { cloneDeep } from 'lodash';
import { Interface } from '@ethersproject/abi';
import { BigNumber } from '@ethersproject/bignumber';
import { WeiPerEther, Zero } from '@ethersproject/constants';

Expand All @@ -17,7 +16,6 @@ import { BalancerNetworkConfig, ExitPoolRequest, PoolType } from '@/types';
import { PoolGraph, Node } from '../graph/graph';

import { subSlippage } from '@/lib/utils/slippageHelper';
import balancerRelayerAbi from '@/lib/abi/RelayerV4.json';
import { networkAddresses } from '@/lib/constants/config';
import { AssetHelpers } from '@/lib/utils';
import { getPoolAddress } from '@/pool-utils';
Expand All @@ -29,7 +27,7 @@ import { SwapRequest } from '../vaultModel/poolModel/swap';
import { ExitPoolRequest as ExitPoolModelRequest } from '../vaultModel/poolModel/exit';
import { JsonRpcSigner } from '@ethersproject/providers';

const balancerRelayerInterface = new Interface(balancerRelayerAbi);
import { RelayerV5__factory } from '@/contracts';

export class Exit {
private wrappedNativeAsset: string;
Expand All @@ -42,7 +40,7 @@ export class Exit {
) {
const { tokens, contracts } = networkAddresses(networkConfig.chainId);
this.wrappedNativeAsset = tokens.wrappedNativeAsset;
this.relayer = contracts.relayerV4 as string;
this.relayer = contracts.relayerV5 as string;
}

async exitPool(
Expand Down Expand Up @@ -356,10 +354,10 @@ export class Exit {
);
}

const encodedCall = balancerRelayerInterface.encodeFunctionData(
'multicall',
[calls]
);
const relayerInterface = RelayerV5__factory.createInterface();
const encodedCall = relayerInterface.encodeFunctionData('multicall', [
calls,
]);

return {
multiRequests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const TEST_BOOSTED_WEIGHTED_META_GENERAL = true;
* - Uncomment section below:
*/
const network = Network.GOERLI;
const blockNumber = 8092113;
const blockNumber = 8744170;
const customSubgraphUrl =
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-goerli-v2-beta';
const { ALCHEMY_URL_GOERLI: jsonRpcUrl } = process.env;
Expand Down Expand Up @@ -108,7 +108,7 @@ const { contracts, contractAddresses } = new Contracts(
network as number,
provider
);
const relayer = contractAddresses.relayerV4 as string;
const relayer = contractAddresses.relayerV5 as string;

interface Test {
signer: JsonRpcSigner;
Expand Down
15 changes: 6 additions & 9 deletions balancer-js/src/modules/joins/joins.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { cloneDeep } from 'lodash';
import { Interface } from '@ethersproject/abi';
import { BigNumber, parseFixed } from '@ethersproject/bignumber';
import { AddressZero, WeiPerEther, Zero } from '@ethersproject/constants';

Expand All @@ -16,7 +15,6 @@ import { BalancerNetworkConfig, JoinPoolRequest, PoolType } from '@/types';
import { PoolGraph, Node } from '../graph/graph';

import { subSlippage } from '@/lib/utils/slippageHelper';
import balancerRelayerAbi from '@/lib/abi/RelayerV4.json';
import { networkAddresses } from '@/lib/constants/config';
import { AssetHelpers, isSameAddress } from '@/lib/utils';
import {
Expand All @@ -32,8 +30,7 @@ import { Requests, VaultModel } from '../vaultModel/vaultModel.module';
import { SwapRequest } from '../vaultModel/poolModel/swap';
import { JoinPoolRequest as JoinPoolModelRequest } from '../vaultModel/poolModel/join';
import { JsonRpcSigner } from '@ethersproject/providers';

const balancerRelayerInterface = new Interface(balancerRelayerAbi);
import { RelayerV5__factory } from '@/contracts';

export class Join {
private relayer: string;
Expand All @@ -44,7 +41,7 @@ export class Join {
private simulationService: Simulation
) {
const { tokens, contracts } = networkAddresses(networkConfig.chainId);
this.relayer = contracts.relayerV4 as string;
this.relayer = contracts.relayerV5 as string;
this.wrappedNativeAsset = tokens.wrappedNativeAsset;
}

Expand Down Expand Up @@ -353,10 +350,10 @@ export class Join {
encodedCalls.unshift(this.createSetRelayerApproval(authorisation));
}

const encodedCall = balancerRelayerInterface.encodeFunctionData(
'multicall',
[encodedCalls]
);
const relayerInterface = RelayerV5__factory.createInterface();
const encodedCall = relayerInterface.encodeFunctionData('multicall', [
encodedCalls,
]);

return {
multiRequests,
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 @@ -72,6 +72,7 @@ export interface ContractAddresses {
lidoRelayer?: string;
relayerV3?: string;
relayerV4?: string;
relayerV5?: string;
gaugeController?: string;
feeDistributor?: string;
veBal?: string;
Expand Down