Skip to content

Commit 571eef2

Browse files
authored
Merge pull request #411 from balancer/develop
Release 1.0.4
2 parents b871bb8 + a1993bf commit 571eef2

File tree

23 files changed

+1509
-35
lines changed

23 files changed

+1509
-35
lines changed

balancer-js/examples/helpers/print-logs.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const decodeLog = async (log: any, abi: any) => {
2828
};
2929

3030
export const decodeLogs = async (logs: any[]) => {
31-
const decodedLogs = [];
32-
let abi;
31+
const decodedLogs: any[] = [];
32+
let abi: any;
3333

3434
for (const log of logs) {
3535
abi = abis.get(log.address);
@@ -69,21 +69,30 @@ export const printLogs = async (logs: any[]) => {
6969
});
7070
};
7171

72+
const printInternalBalanceChanged = (log: any) => {
73+
const { user, token, delta } = log.args
74+
console.log('\x1b[32m%s\x1b[0m', 'User: ', user)
75+
console.log('\x1b[32m%s\x1b[0m', 'Token:', token)
76+
console.log('\x1b[32m%s\x1b[0m', 'Delta:', formatEther(delta))
77+
}
78+
7279
const printTransfer = (log: any) => {
7380
console.log(log.address);
74-
const { from, to, value, src, dst, wad } = log.args;
75-
console.log('\x1b[32m%s\x1b[0m', 'From: ', from || src);
76-
console.log('\x1b[32m%s\x1b[0m', 'To: ', to || dst);
77-
console.log('\x1b[32m%s\x1b[0m', 'Value:', formatEther(value || wad));
78-
};
81+
const { from, to, value, src, dst, wad, _to, _from, _value } = log.args
82+
console.log('\x1b[32m%s\x1b[0m', 'From: ', from || _from || src)
83+
console.log('\x1b[32m%s\x1b[0m', 'To: ', to || _to || dst)
84+
console.log('\x1b[32m%s\x1b[0m', 'Value:', formatEther(value || _value || wad))
85+
}
7986

80-
decodedLogs.map((log) => {
87+
decodedLogs.map((log: any) => {
8188
console.log('-'.repeat(80));
8289
console.log(log.name);
8390
if (log.name === 'Swap') {
8491
printSwap(log);
8592
} else if (log.name === 'PoolBalanceChanged') {
8693
printPoolBalanceChanged(log);
94+
} else if (log.name === 'InternalBalanceChanged') {
95+
printInternalBalanceChanged(log);
8796
} else if (log.name === 'Transfer') {
8897
printTransfer(log);
8998
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Migrations module contains methods to migrate liquidity between pools
3+
* Run command: yarn examples:run ./examples/liquidity-managment/migrations.ts
4+
*/
5+
import { BalancerSDK } from '@/.'
6+
7+
const sdk = new BalancerSDK({
8+
network: 1,
9+
rpcUrl: 'http://127.0.0.1:8545', // Using a forked mainnet to be able to approve the relayer
10+
})
11+
12+
const { provider, migrationService } = sdk
13+
14+
if (!migrationService) {
15+
throw new Error('No migrationService present')
16+
}
17+
18+
const main = async () => {
19+
const user = '0x783596B9504Ef2752EFB2d4Aed248fDCb0d9FDab'
20+
const from = '0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080'
21+
const to = '0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080'
22+
const balance = await sdk.contracts.ERC20('0x32296969ef14eb0c6d29669c550d4a0449130230', provider).balanceOf(user)
23+
24+
// To be able to perform a migration and a static call, user needs to approve the relayer first
25+
await provider.send('hardhat_impersonateAccount', [user])
26+
const signer = provider.getSigner(user)
27+
await sdk.contracts.vault.connect(signer).setRelayerApproval(user, migrationService.relayerAddress, true)
28+
29+
// Query for the minimum amount of BPT to receive
30+
const peek = await migrationService.pool2pool(user, from, to, balance)
31+
const peekResult = await provider.call({ ...peek, from: user, gasLimit: 8e6 });
32+
const expectedBptOut = migrationService.getMinBptOut(peekResult);
33+
console.log('expectedBptOut', expectedBptOut.toString(), 'BPT')
34+
35+
// Build the migration with the minimum amount of BPT to receive
36+
const txParams = await migrationService.pool2pool(user, from, to, balance, expectedBptOut)
37+
console.log(txParams.data)
38+
}
39+
40+
main()

balancer-js/examples/pools/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function setUpExample(
2121
rpcUrlLocal: string,
2222
network: Network,
2323
tokens: string[],
24-
slots: number[],
24+
slots: number[] | undefined,
2525
balances: string[],
2626
poolId: string,
2727
blockNo: number

balancer-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@balancer-labs/sdk",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "JavaScript SDK for interacting with the Balancer Protocol V2",
55
"license": "GPL-3.0-only",
66
"homepage": "https://github.com/balancer-labs/balancer-sdk#readme",

balancer-js/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ export {
3838
} from '@balancer-labs/sor';
3939
export { SimulationType } from './modules/simulation/simulation.module';
4040
export { BALANCER_NETWORK_CONFIG } from './lib/constants/config';
41+
export { Migrations } from './modules/liquidity-managment/migrations';

balancer-js/src/lib/utils/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const isSameAddress = (address1: string, address2: string): boolean =>
1818
getAddress(address1) === getAddress(address2);
1919

2020
export function insert<T>(arr: T[], index: number, newItem: T): T[] {
21-
if (index < 0 || index >= arr.length) {
21+
if (index < 0 || index > arr.length) {
2222
return arr;
2323
}
2424
return [
@@ -38,6 +38,9 @@ export function insert<T>(arr: T[], index: number, newItem: T): T[] {
3838
* @param newItem
3939
*/
4040
export function replace<T>(arr: T[], index: number, newItem: T): T[] {
41+
if (index < 0 || index >= arr.length) {
42+
return arr;
43+
}
4144
return [
4245
// part of the array before the specified index
4346
...arr.slice(0, index),

0 commit comments

Comments
 (0)