forked from balancer/balancer-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.ts
112 lines (89 loc) · 3.15 KB
/
create.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import * as dotenv from 'dotenv';
import {
JsonRpcProvider,
Log,
TransactionReceipt,
} from '@ethersproject/providers';
import { BalancerSDK, isSameAddress, Network, PoolType } from 'src';
import composableStableFactoryAbi from '@/lib/abi/ComposableStableFactory.json';
import { ethers } from 'hardhat';
import { Interface, LogDescription } from '@ethersproject/abi';
import { ADDRESSES } from '@/test/lib/constants';
import { forkSetup } from "@/test/lib/utils";
import { BALANCER_NETWORK_CONFIG } from "@/lib/constants/config";
dotenv.config();
const name = 'My-Test-Pool-Name';
const symbol = 'My-Test-Pool-Symbol';
const network = Network.GOERLI;
const rpcUrl = 'http://127.0.0.1:8000';
const alchemyRpcUrl = `${ process.env.ALCHEMY_URL_GOERLI }`;
const blockNumber = 8200000;
const addresses = ADDRESSES[network];
const WETH_address = addresses.WETH.address;
const MAI_address = addresses.MAI.address;
const tokenAddresses = [MAI_address, WETH_address];
const amplificationParameter = '1';
const rateProviders = [
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
];
const tokenRateCacheDurations = ['0', '0'];
const exemptFromYieldProtocolFeeFlags = [false, false];
const swapFee = '0.01';
const owner = '0x817b6923f3cB53536859b1f01262d0E7f513dB78';
const factoryAddress = `${ BALANCER_NETWORK_CONFIG[network].addresses.contracts.composableStablePoolFactory }`;
async function createComposableStablePool() {
// const rpcUrl = `https://mainnet.infura.io/v3/444153f7f8f2499db7be57a11b1f696e`;
// const rpcUrl = 'https://goerli.gateway.tenderly.co/4Rzjgxiyt0WELoXRl1312Q'
const provider: JsonRpcProvider = new ethers.providers.JsonRpcProvider(
rpcUrl,
network,
);
const signer = provider.getSigner();
await forkSetup(signer, [], [], [], alchemyRpcUrl, blockNumber, false);
const sdkConfig = {
network,
rpcUrl,
};
// await forkSetupLocalNode(signer);
const balancer = new BalancerSDK(sdkConfig);
const composableStablePoolFactory = balancer.pools.poolFactory.of(
PoolType.ComposableStable
);
const { to, data } = composableStablePoolFactory.create({
factoryAddress,
name,
symbol,
tokenAddresses,
amplificationParameter,
rateProviders,
tokenRateCacheDurations,
exemptFromYieldProtocolFeeFlags,
swapFee,
owner,
});
const signerAddress = await signer.getAddress();
const tx = await signer.sendTransaction({
from: signerAddress,
to,
data,
gasLimit: 6721975,
});
const receipt: TransactionReceipt = await provider.getTransactionReceipt(
tx.hash
);
const composableStableFactoryInterface = new Interface(
composableStableFactoryAbi
);
const poolCreationEvent: LogDescription | null | undefined = receipt.logs
.filter((log: Log) => {
return isSameAddress(log.address, factoryAddress);
})
.map((log) => {
return composableStableFactoryInterface.parseLog(log);
})
.find((parsedLog) => parsedLog?.name === 'PoolCreated');
if (!poolCreationEvent) return console.error("There's no event");
console.log("poolAddress: " + poolCreationEvent.args.pool);
}
createComposableStablePool().then((r) => r);