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 all commits
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
8 changes: 4 additions & 4 deletions balancer-js/examples/exitGeneralised.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ dotenv.config();

const network = Network.MAINNET;
const jsonRpcUrl = process.env.ALCHEMY_URL;
const blockNumber = 16685400;
const blockNumber = 16940624;
const rpcUrl = 'http://127.0.0.1:8545';
const customSubgraphUrl =
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2';

const addresses = ADDRESSES[network];

// bb-e-usd
const testPool = addresses.bbeusd;
// bb-a-usd
const testPool = addresses.bbausd2;

// Amount of testPool BPT that will be used to exit
const amount = parseFixed('2', testPool.decimals).toString();
Expand Down Expand Up @@ -146,7 +146,7 @@ const exit = async () => {
provider
);
const relayerAuth = await Relayer.signRelayerApproval(
contractAddresses.relayerV4 as string,
contractAddresses.relayerV5 as string,
signerAddress,
signer,
contracts.vault
Expand Down
39 changes: 20 additions & 19 deletions balancer-js/examples/helpers/print-logs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any */
import dotenv from 'dotenv';
import { ethers } from 'ethers';
import { Contract } from '@ethersproject/contracts';
import { formatEther } from '@ethersproject/units';
import { shortenAddress } from '.';
import { formatEther } from 'ethers/lib/utils'

dotenv.config();
const { ETHERSCAN_API_KEY } = process.env;
Expand All @@ -15,7 +16,7 @@ const abis = new Map<string, any>();

const decodeLog = async (log: any, abi: any) => {
let decoded;
const contract = new ethers.Contract(log.address, abi);
const contract = new Contract(log.address, abi);

try {
decoded = contract.interface.parseLog(log);
Expand All @@ -39,7 +40,7 @@ export const decodeLogs = async (logs: any[]) => {
abis.set(log.address, abi);
}
const decoded = await decodeLog(log, abi);
if (decoded) decodedLogs.push({...decoded, address: log.address});
if (decoded) decodedLogs.push({ ...decoded, address: log.address });
}

return decodedLogs;
Expand All @@ -57,34 +58,34 @@ export const printLogs = async (logs: any[]) => {
amountIn: formatEther(amountIn),
amountOut: formatEther(amountOut),
}))
)
}
);
};

const printPoolBalanceChanged = (log: any) => {
console.log(log.args.poolId)
console.log(log.args.poolId);
console.table({
tokens: log?.args.tokens.map(shortenAddress),
deltas: log?.args.deltas.map((delta: string) => formatEther(delta)),
})
}
});
};

const printTransfer = (log: any) => {
console.log(log.address);
const { from, to, value, src, dst, wad } = log.args
console.log('\x1b[32m%s\x1b[0m', 'From: ', from || src)
console.log('\x1b[32m%s\x1b[0m', 'To: ', to || dst)
console.log('\x1b[32m%s\x1b[0m', 'Value:', formatEther(value || wad))
}
const { from, to, value, src, dst, wad } = log.args;
console.log('\x1b[32m%s\x1b[0m', 'From: ', from || src);
console.log('\x1b[32m%s\x1b[0m', 'To: ', to || dst);
console.log('\x1b[32m%s\x1b[0m', 'Value:', formatEther(value || wad));
};

decodedLogs.map((log) => {
console.log('-'.repeat(80))
console.log(log.name)
console.log('-'.repeat(80));
console.log(log.name);
if (log.name === 'Swap') {
printSwap(log)
printSwap(log);
} else if (log.name === 'PoolBalanceChanged') {
printPoolBalanceChanged(log)
printPoolBalanceChanged(log);
} else if (log.name === 'Transfer') {
printTransfer(log)
printTransfer(log);
}
});
};
4 changes: 2 additions & 2 deletions balancer-js/examples/joinGeneralised.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dotenv.config();
// -- Mainnet network setup --
const network = Network.MAINNET;
const jsonRpcUrl = process.env.ALCHEMY_URL;
const blockNumber = 16075635;
const blockNumber = 16940624;
const rpcUrl = 'http://127.0.0.1:8545';
const customSubgraphUrl =
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2-beta';
Expand Down Expand Up @@ -164,7 +164,7 @@ async function join() {
provider
);
const authorisation = await Relayer.signRelayerApproval(
contractAddresses.relayerV4 as string,
contractAddresses.relayerV5 as string,
signerAddress,
signer,
contracts.vault
Expand Down
26 changes: 16 additions & 10 deletions balancer-js/examples/joinGeneralisedComposableStable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { BalancerSDK, Network } from '@/.';
import { SimulationType } from '@/modules/simulation/simulation.module';

const network = Network.MAINNET;
const blockNumber = 16411000;
const blockNumber = 16940624;
const jsonRpcUrl = 'https://rpc.ankr.com/eth';
const rpcUrl = 'http://127.0.0.1:8545';

Expand All @@ -46,8 +46,8 @@ const balancer = new BalancerSDK({
where: {
address: {
in: [
'0xa13a9247ea42d743238089903570127dda72fe44',
'0xae37d54ae477268b9997d4161b96b8200755935c',
'0xa13a9247ea42d743238089903570127dda72fe44', // bbausd2
'0xae37d54ae477268b9997d4161b96b8200755935c', // bbadai
],
},
},
Expand All @@ -56,7 +56,7 @@ const balancer = new BalancerSDK({
},
});

const { provider, contracts } = balancer;
const { provider, contracts, balancerContracts } = balancer;
const { ERC20 } = contracts;
const signer = (provider as JsonRpcProvider).getSigner();

Expand All @@ -77,15 +77,17 @@ async function getTokens(signerAddress: string): Promise<void> {
},
]);

// Lets impersonate Binance with loads of DAI and transfer some to the signer
// Lets impersonate an address with loads of DAI and transfer some to the signer
await signer.provider.send('hardhat_impersonateAccount', [
'0xF977814e90dA44bFA03b6295A0616a897441aceC',
'0x60FaAe176336dAb62e284Fe19B885B095d29fB7F',
]);
const binance = signer.provider.getSigner(
'0xF977814e90dA44bFA03b6295A0616a897441aceC'
const impersonatedAddress = signer.provider.getSigner(
'0x60FaAe176336dAb62e284Fe19B885B095d29fB7F'
);

await (await ERC20(dai, binance).transfer(signerAddress, amount)).wait();
await (
await ERC20(dai, impersonatedAddress).transfer(signerAddress, amount)
).wait();

await (
await ERC20(dai, signer).approve(contracts.vault.address, amount)
Expand All @@ -96,9 +98,12 @@ async function join() {
const signerAddress = await signer.getAddress();
await getTokens(signerAddress);

const relayerAddress = balancerContracts.relayerV5?.address as string;
console.log('Relayer address:', relayerAddress);

// Need to sign the approval only once per relayer
const relayerAuth = await Relayer.signRelayerApproval(
contracts.relayerV4?.address as string,
relayerAddress,
signerAddress,
signer,
contracts.vault
Expand Down Expand Up @@ -127,6 +132,7 @@ async function join() {
await signer.sendTransaction({
to: query.to,
data: query.encodedCall,
gasLimit: 8e6,
})
).wait();

Expand Down
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
1 change: 1 addition & 0 deletions balancer-js/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './signatures';
export * from './tokens';
export * from './debouncer';
export * from './math';
export * from './slippageHelper';

export const isSameAddress = (address1: string, address2: string): boolean =>
getAddress(address1) === getAddress(address2);
Expand Down
4 changes: 4 additions & 0 deletions balancer-js/src/modules/contracts/contracts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface ContractInstances {
multicall: Contract;
relayerV3?: Contract;
relayerV4?: Contract;
relayerV5?: Contract;
vault: Vault;
veBal?: VeBal;
veBalProxy?: VeBalProxy;
Expand All @@ -66,6 +67,7 @@ export class Contracts {
multicall: Contract;
relayerV3?: Contract;
relayerV4?: Contract;
relayerV5?: Contract;
vault: Vault;
veBal?: VeBal;
veBalProxy?: VeBalProxy;
Expand Down Expand Up @@ -108,6 +110,8 @@ 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 = Relayer(this.contractAddresses.relayerV5, provider, 5);

if (this.contractAddresses.veBal) {
this.veBal = new VeBal(this.contractAddresses, provider);
Expand Down
5 changes: 4 additions & 1 deletion balancer-js/src/modules/contracts/implementations/relayer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Contract } from '@ethersproject/contracts';
import { Provider } from '@ethersproject/providers';
import RelayerV4ABI from '@/lib/abi/RelayerV4.json';
import RelayerV3ABI from '@/lib/abi/BalancerRelayer.json';
import RelayerV4ABI from '@/lib/abi/RelayerV4.json';
import RelayerV5ABI from '@/lib/abi/RelayerV5.json';

export const Relayer = (
address: string,
Expand All @@ -13,6 +14,8 @@ export const Relayer = (
return new Contract(address, RelayerV3ABI, provider);
case 4:
return new Contract(address, RelayerV4ABI, provider);
case 5:
return new Contract(address, RelayerV5ABI, provider);
default:
throw new Error('relayer not supported');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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 Expand Up @@ -193,7 +193,8 @@ const testFlow = async (
});
};

describe('generalised exit execution', async () => {
// Skipping Euler specific tests while eTokens transactions are paused
describe.skip('generalised exit execution', async () => {
/*
bbeusd: ComposableStable, bbeusdt/bbeusdc/bbedai
bbeusdt: Linear, eUsdt/usdt
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
Loading