@dhedge/v2-sdk 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +60 -3
  2. package/dist/config.d.ts +2 -0
  3. package/dist/entities/pool.d.ts +32 -0
  4. package/dist/entities/utils.d.ts +4 -0
  5. package/dist/services/claim-balancer/claim.service.d.ts +21 -0
  6. package/dist/services/claim-balancer/claim.worker.d.ts +4 -0
  7. package/dist/services/claim-balancer/ipfs.service.d.ts +4 -0
  8. package/dist/services/claim-balancer/types.d.ts +54 -0
  9. package/dist/test/constants.d.ts +12 -0
  10. package/dist/types.d.ts +5 -2
  11. package/dist/utils/contract.d.ts +14 -0
  12. package/dist/utils/index.d.ts +7 -0
  13. package/dist/utils/merkle.d.ts +22 -0
  14. package/dist/v2-sdk.cjs.development.js +3623 -672
  15. package/dist/v2-sdk.cjs.development.js.map +1 -1
  16. package/dist/v2-sdk.cjs.production.min.js +1 -1
  17. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  18. package/dist/v2-sdk.esm.js +3623 -672
  19. package/dist/v2-sdk.esm.js.map +1 -1
  20. package/package.json +9 -2
  21. package/src/abi/IAaveIncentivesController.json +50 -0
  22. package/src/abi/IBalancerMerkleOrchard.json +353 -0
  23. package/src/abi/IBalancertV2Vault.json +938 -0
  24. package/src/config.ts +16 -3
  25. package/src/entities/pool.ts +140 -1
  26. package/src/entities/utils.ts +135 -0
  27. package/src/services/claim-balancer/MultiTokenClaim.json +115 -0
  28. package/src/services/claim-balancer/claim.service.ts +324 -0
  29. package/src/services/claim-balancer/claim.worker.ts +32 -0
  30. package/src/services/claim-balancer/ipfs.service.ts +12 -0
  31. package/src/services/claim-balancer/types.ts +66 -0
  32. package/src/test/aave.test.ts +73 -0
  33. package/src/test/balancer.test.ts +109 -0
  34. package/src/test/constants.ts +13 -0
  35. package/src/test/oneInch.test.ts +56 -0
  36. package/src/test/pool.test.ts +5 -249
  37. package/src/test/sushi.test.ts +173 -0
  38. package/src/test/utils.test.ts +41 -26
  39. package/src/types.ts +6 -3
  40. package/src/utils/contract.ts +95 -0
  41. package/src/utils/index.ts +38 -0
  42. package/src/utils/merkle.ts +172 -0
@@ -0,0 +1,324 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import axios from "axios";
3
+ import { chunk, flatten, groupBy } from "lodash";
4
+ import merkleOrchardAbi from "../../abi/IBalancerMerkleOrchard.json";
5
+ import { ethers, Wallet } from "ethers";
6
+
7
+ import { getAddress } from "@ethersproject/address";
8
+
9
+ import { multicall } from "../../utils/contract";
10
+ import { bnum, loadTree, scale } from "../../utils";
11
+
12
+ import { ipfsService } from "./ipfs.service";
13
+
14
+ import MultiTokenClaim from "./MultiTokenClaim.json";
15
+
16
+ import {
17
+ ClaimProofTuple,
18
+ ClaimStatus,
19
+ ComputeClaimProofPayload,
20
+ MultiTokenCurrentRewardsEstimate,
21
+ MultiTokenCurrentRewardsEstimateResponse,
22
+ MultiTokenPendingClaims,
23
+ Report,
24
+ Snapshot,
25
+ TokenClaimInfo
26
+ } from "./types";
27
+
28
+ import { Network } from "../../types";
29
+ import { stakingAddress } from "../../config";
30
+ import { soliditySha3 } from "web3-utils";
31
+ import { Dapp } from "../..";
32
+
33
+ export class ClaimService {
34
+ network: Network;
35
+ signer: ethers.Wallet;
36
+ public constructor(network: Network, signer: Wallet) {
37
+ this.network = network;
38
+ this.signer = signer;
39
+ }
40
+ public async getMultiTokensPendingClaims(
41
+ account: string
42
+ ): Promise<MultiTokenPendingClaims[]> {
43
+ const tokenClaimsInfo = this.getTokenClaimsInfo();
44
+ if (tokenClaimsInfo != null) {
45
+ const multiTokenPendingClaims = await Promise.all(
46
+ tokenClaimsInfo.map(tokenClaimInfo =>
47
+ this.getTokenPendingClaims(tokenClaimInfo, getAddress(account))
48
+ )
49
+ );
50
+
51
+ const multiTokenPendingClaimsWithRewards = multiTokenPendingClaims.filter(
52
+ pendingClaim => Number(pendingClaim.availableToClaim) > 0
53
+ );
54
+
55
+ return multiTokenPendingClaimsWithRewards;
56
+ }
57
+ return [];
58
+ }
59
+
60
+ public async getTokenPendingClaims(
61
+ tokenClaimInfo: TokenClaimInfo,
62
+ account: string
63
+ ): Promise<MultiTokenPendingClaims> {
64
+ const snapshot = await this.getSnapshot(tokenClaimInfo.manifest);
65
+ const weekStart = tokenClaimInfo.weekStart;
66
+ const claimStatus = await this.getClaimStatus(
67
+ Object.keys(snapshot).length,
68
+ account,
69
+ tokenClaimInfo
70
+ );
71
+
72
+ const pendingWeeks = claimStatus
73
+ .map((status, i) => [i + weekStart, status])
74
+ .filter(([, status]) => !status)
75
+ .map(([i]) => i) as number[];
76
+
77
+ const reports = await this.getReports(snapshot, pendingWeeks);
78
+
79
+ const claims = Object.entries(reports)
80
+ .filter((report: Report) => report[1][account])
81
+ .map((report: Report) => {
82
+ return {
83
+ id: report[0],
84
+ amount: report[1][account]
85
+ };
86
+ });
87
+
88
+ //console.log("claims", claims);
89
+
90
+ const availableToClaim = claims
91
+ .map(claim => parseFloat(claim.amount))
92
+ .reduce((total, amount) => total.plus(amount), bnum(0))
93
+ .toString();
94
+
95
+ return {
96
+ claims,
97
+ reports,
98
+ tokenClaimInfo,
99
+ availableToClaim
100
+ };
101
+ }
102
+
103
+ public async getMultiTokensCurrentRewardsEstimate(
104
+ account: string
105
+ ): Promise<{
106
+ data: MultiTokenCurrentRewardsEstimate[];
107
+ timestamp: string | null;
108
+ }> {
109
+ try {
110
+ const response = await axios.get<
111
+ MultiTokenCurrentRewardsEstimateResponse
112
+ >(
113
+ `https://api.balancer.finance/liquidity-mining/v1/liquidity-provider-multitoken/${account}`
114
+ );
115
+ if (response.data.success) {
116
+ const multiTokenLiquidityProviders = response.data.result[
117
+ "liquidity-providers"
118
+ ]
119
+ .filter(incentive => incentive.chain_id === 137)
120
+ .map(incentive => ({
121
+ ...incentive,
122
+ token_address: getAddress(incentive.token_address)
123
+ }));
124
+
125
+ const multiTokenCurrentRewardsEstimate: MultiTokenCurrentRewardsEstimate[] = [];
126
+
127
+ const multiTokenLiquidityProvidersByToken = Object.entries(
128
+ groupBy(multiTokenLiquidityProviders, "token_address")
129
+ );
130
+
131
+ for (const [
132
+ token,
133
+ liquidityProvider
134
+ ] of multiTokenLiquidityProvidersByToken) {
135
+ const rewards = liquidityProvider
136
+ .reduce(
137
+ (total, { current_estimate }) => total.plus(current_estimate),
138
+ bnum(0)
139
+ )
140
+ .toString();
141
+
142
+ const velocity =
143
+ liquidityProvider
144
+ .find(liquidityProvider => Number(liquidityProvider.velocity) > 0)
145
+ ?.velocity.toString() ?? "0";
146
+
147
+ if (Number(rewards) > 0) {
148
+ multiTokenCurrentRewardsEstimate.push({
149
+ rewards,
150
+ velocity,
151
+ token: getAddress(token)
152
+ });
153
+ }
154
+ }
155
+
156
+ return {
157
+ data: multiTokenCurrentRewardsEstimate,
158
+ timestamp: response.data.result.current_timestamp
159
+ };
160
+ }
161
+ } catch (e) {
162
+ console.log("[Claim] Current Rewards Estimate Error", e);
163
+ }
164
+ return {
165
+ data: [],
166
+ timestamp: null
167
+ };
168
+ }
169
+
170
+ public async multiTokenClaimRewards(
171
+ account: string,
172
+ multiTokenPendingClaims: MultiTokenPendingClaims[]
173
+ ): Promise<any> {
174
+ try {
175
+ const multiTokenClaims = await Promise.all(
176
+ multiTokenPendingClaims.map((tokenPendingClaims, tokenIndex) =>
177
+ this.computeClaimProofs(
178
+ tokenPendingClaims,
179
+ getAddress(account),
180
+ tokenIndex
181
+ )
182
+ )
183
+ );
184
+
185
+ return flatten(multiTokenClaims);
186
+ } catch (e) {
187
+ console.log("[Claim] Claim Rewards Error:", e);
188
+ return Promise.reject(e);
189
+ }
190
+ }
191
+
192
+ private async computeClaimProofs(
193
+ tokenPendingClaims: MultiTokenPendingClaims,
194
+ account: string,
195
+ tokenIndex: number
196
+ ): Promise<Promise<ClaimProofTuple[]>> {
197
+ return Promise.all(
198
+ tokenPendingClaims.claims.map(claim => {
199
+ const payload: ComputeClaimProofPayload = {
200
+ account,
201
+ distributor: tokenPendingClaims.tokenClaimInfo.distributor,
202
+ tokenIndex,
203
+ decimals: tokenPendingClaims.tokenClaimInfo.decimals,
204
+ // objects must be cloned
205
+ report: { ...tokenPendingClaims.reports[claim.id] },
206
+ claim: { ...claim }
207
+ };
208
+
209
+ return this.computeClaimProof(payload);
210
+ })
211
+ );
212
+ }
213
+
214
+ private computeClaimProof(
215
+ payload: ComputeClaimProofPayload
216
+ ): ClaimProofTuple {
217
+ const {
218
+ report,
219
+ account,
220
+ claim,
221
+ distributor,
222
+ tokenIndex,
223
+ decimals
224
+ } = payload;
225
+
226
+ const claimAmount = claim.amount;
227
+ const merkleTree = loadTree(report, decimals);
228
+
229
+ const scaledBalance = scale(claimAmount, decimals).toString(10);
230
+
231
+ const proof = merkleTree.getHexProof(
232
+ soliditySha3(
233
+ { t: "address", v: account },
234
+ { t: "uint", v: scaledBalance }
235
+ )
236
+ );
237
+ return [
238
+ parseInt(claim.id),
239
+ scaledBalance,
240
+ distributor,
241
+ tokenIndex,
242
+ proof
243
+ ] as ClaimProofTuple;
244
+ }
245
+
246
+ private getTokenClaimsInfo() {
247
+ const tokenClaims = MultiTokenClaim["137"];
248
+
249
+ if (tokenClaims != null) {
250
+ return (tokenClaims as TokenClaimInfo[]).map(tokenClaim => ({
251
+ ...tokenClaim,
252
+ token: getAddress(tokenClaim.token),
253
+ decimals: 18
254
+ }));
255
+ }
256
+
257
+ return null;
258
+ }
259
+
260
+ private async getSnapshot(manifest: string) {
261
+ try {
262
+ const response = await axios.get<Snapshot>(manifest);
263
+ return response.data || {};
264
+ } catch (error) {
265
+ return {};
266
+ }
267
+ }
268
+
269
+ private async getClaimStatus(
270
+ totalWeeks: number,
271
+ account: string,
272
+ tokenClaimInfo: TokenClaimInfo
273
+ ): Promise<ClaimStatus[]> {
274
+ const { token, distributor, weekStart } = tokenClaimInfo;
275
+
276
+ const claimStatusCalls = Array.from({ length: totalWeeks }).map((_, i) => [
277
+ stakingAddress[this.network][Dapp.BALANCER],
278
+ "isClaimed",
279
+ [token, distributor, weekStart + i, account]
280
+ ]);
281
+
282
+ const rootCalls = Array.from({ length: totalWeeks }).map((_, i) => [
283
+ stakingAddress[this.network][Dapp.BALANCER],
284
+ "getDistributionRoot",
285
+ [token, distributor, weekStart + i]
286
+ ]);
287
+
288
+ try {
289
+ const result = (await multicall<boolean | string>(
290
+ this.network,
291
+ this.signer,
292
+ merkleOrchardAbi.abi,
293
+ [...claimStatusCalls, ...rootCalls],
294
+ {},
295
+ true
296
+ )) as (boolean | string)[];
297
+
298
+ if (result.length > 0) {
299
+ const chunks = chunk(flatten(result), totalWeeks);
300
+
301
+ const claimedResult = chunks[0] as boolean[];
302
+ const distributionRootResult = chunks[1] as string[];
303
+
304
+ return claimedResult.filter(
305
+ (_, index) =>
306
+ distributionRootResult[index] !== ethers.constants.HashZero
307
+ );
308
+ }
309
+ } catch (e) {
310
+ console.log("[Claim] Claim Status Error:", e);
311
+ }
312
+
313
+ return [];
314
+ }
315
+
316
+ private async getReports(snapshot: Snapshot, weeks: number[]) {
317
+ const reports = await Promise.all<Report>(
318
+ weeks
319
+ .filter(week => snapshot[week] != null)
320
+ .map(week => ipfsService.get(snapshot[week]))
321
+ );
322
+ return Object.fromEntries(reports.map((report, i) => [weeks[i], report]));
323
+ }
324
+ }
@@ -0,0 +1,32 @@
1
+ // Shamelessly adapted from OpenZeppelin-contracts test utils
2
+ import { soliditySha3 } from "web3-utils";
3
+ import { loadTree, scale } from "../../utils";
4
+
5
+ import { ComputeClaimProofPayload } from "./types";
6
+
7
+ export class ClaimWorker {
8
+ public calcClaimProof(payload: ComputeClaimProofPayload): any {
9
+ const {
10
+ report,
11
+ account,
12
+ claim,
13
+ distributor,
14
+ tokenIndex,
15
+ decimals
16
+ } = payload;
17
+
18
+ const claimAmount = claim.amount;
19
+ const merkleTree = loadTree(report, decimals);
20
+
21
+ const scaledBalance = scale(claimAmount, decimals).toString(10);
22
+
23
+ const proof = merkleTree.getHexProof(
24
+ soliditySha3(
25
+ { t: "address", v: account },
26
+ { t: "uint", v: scaledBalance }
27
+ )
28
+ );
29
+
30
+ return [parseInt(claim.id), scaledBalance, distributor, tokenIndex, proof];
31
+ }
32
+ }
@@ -0,0 +1,12 @@
1
+ import axios from "axios";
2
+
3
+ export default class IpfsService {
4
+ async get<T>(hash: string, protocol = "ipfs"): Promise<T> {
5
+ const { data } = await axios.get(
6
+ `https://cloudflare-ipfs.com/${protocol}/${hash}`
7
+ );
8
+ return data;
9
+ }
10
+ }
11
+
12
+ export const ipfsService = new IpfsService();
@@ -0,0 +1,66 @@
1
+ export interface Claim {
2
+ id: string;
3
+ amount: string;
4
+ }
5
+
6
+ export type Snapshot = Record<number, string>;
7
+
8
+ export type TokenClaimInfo = {
9
+ label: string;
10
+ distributor: string;
11
+ token: string;
12
+ decimals: number;
13
+ manifest: string;
14
+ weekStart: number;
15
+ };
16
+
17
+ export type MultiTokenPendingClaims = {
18
+ claims: Claim[];
19
+ reports: Report;
20
+ tokenClaimInfo: TokenClaimInfo;
21
+ availableToClaim: string;
22
+ };
23
+
24
+ export type ClaimStatus = boolean;
25
+
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ export type Report = Record<string, any>;
28
+
29
+ export type MultiTokenCurrentRewardsEstimateResponse = {
30
+ success: boolean;
31
+ result: {
32
+ current_timestamp: string;
33
+ "liquidity-providers": Array<{
34
+ snapshot_timestamp: string;
35
+ address: string;
36
+ token_address: string;
37
+ chain_id: number;
38
+ current_estimate: string;
39
+ velocity: string;
40
+ week: number;
41
+ }>;
42
+ };
43
+ };
44
+
45
+ export type MultiTokenCurrentRewardsEstimate = {
46
+ rewards: string;
47
+ velocity: string;
48
+ token: string;
49
+ };
50
+
51
+ export type ClaimProofTuple = [number, string, string, number, string[]]; // claimId, claimAmount, distributor, tokenIndex, proof
52
+
53
+ export type ComputeClaimProofPayload = {
54
+ report: Report;
55
+ account: string;
56
+ claim: Claim;
57
+ distributor: string;
58
+ tokenIndex: number;
59
+ decimals: number;
60
+ };
61
+
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ export type ClaimWorkerMessage<P = any> = {
64
+ type: "computeClaimProof";
65
+ payload: P;
66
+ };
@@ -0,0 +1,73 @@
1
+ import { Dhedge, ethers } from "..";
2
+ import { Network } from "../types";
3
+ import { AMUSDC, TEST_POOL, VDEBTWETH } from "./constants";
4
+
5
+ import { wallet } from "./wallet";
6
+
7
+ let dhedge: Dhedge;
8
+
9
+ jest.setTimeout(100000);
10
+
11
+ const options = {
12
+ gasLimit: 5000000,
13
+ gasPrice: ethers.utils.parseUnits("100", "gwei")
14
+ };
15
+
16
+ describe("pool", () => {
17
+ beforeAll(() => {
18
+ dhedge = new Dhedge(wallet, Network.POLYGON);
19
+ });
20
+
21
+ // it("withdraws 1 USDC from Aave lending pool", async () => {
22
+ // let result;
23
+ // const pool = await dhedge.loadPool(myPool);
24
+ // try {
25
+ // result = await pool.withdrawDeposit(
26
+ // Dapp.AAVE,
27
+ // weth,
28
+ // "86567951006165",
29
+ // options
30
+ // );
31
+ // console.log(result);
32
+ // } catch (e) {
33
+ // console.log(e);
34
+ // }
35
+ // expect(result).not.toBe(null);
36
+ // });
37
+
38
+ // it("borrows 0.0001 WETH from Aave lending pool", async () => {
39
+ // let result;
40
+ // const pool = await dhedge.loadPool(myPool);
41
+ // try {
42
+ // result = await pool.borrow(Dapp.AAVE, weth, "100000000000000");
43
+ // console.log(result);
44
+ // } catch (e) {
45
+ // console.log(e);
46
+ // }
47
+ // expect(result).not.toBe(null);
48
+ // });
49
+
50
+ // it("reapys 0.0001 WETH to Aave lending pool", async () => {
51
+ // let result;
52
+ // const pool = await dhedge.loadPool(myPool);
53
+ // try {
54
+ // result = await pool.repay(Dapp.AAVE, weth, "100000000000000", options);
55
+ // console.log(result);
56
+ // } catch (e) {
57
+ // console.log(e);
58
+ // }
59
+ // expect(result).not.toBe(null);
60
+ // });
61
+
62
+ it("claims rewards from Aave", async () => {
63
+ let result;
64
+ const pool = await dhedge.loadPool(TEST_POOL);
65
+ try {
66
+ result = await pool.harvestAaveRewards([AMUSDC, VDEBTWETH], options);
67
+ console.log(result);
68
+ } catch (e) {
69
+ console.log(e);
70
+ }
71
+ expect(result).not.toBe(null);
72
+ });
73
+ });
@@ -0,0 +1,109 @@
1
+ import { Dhedge, ethers } from "..";
2
+ import { Network } from "../types";
3
+ import { TEST_POOL } from "./constants";
4
+
5
+ import { wallet } from "./wallet";
6
+
7
+ let dhedge: Dhedge;
8
+
9
+ jest.setTimeout(100000);
10
+
11
+ const options = {
12
+ gasLimit: 2000000,
13
+ gasPrice: ethers.utils.parseUnits("1000", "gwei")
14
+ };
15
+
16
+ describe("pool", () => {
17
+ beforeAll(() => {
18
+ dhedge = new Dhedge(wallet, Network.POLYGON);
19
+ });
20
+
21
+ // it("approves unlimited USDC on Balancer", async () => {
22
+ // let result;
23
+ // const pool = await dhedge.loadPool(TEST_POOL);
24
+ // try {
25
+ // result = await pool.approve(
26
+ // Dapp.BALANCER,
27
+ // USDC,
28
+ // ethers.constants.MaxInt256,
29
+ // options
30
+ // );
31
+ // console.log(result);
32
+ // } catch (e) {
33
+ // console.log(e);
34
+ // }
35
+ // expect(result).not.toBe(null);
36
+ // });
37
+
38
+ // it("trades 2 USDC into SUSHI on Balancer", async () => {
39
+ // let result;
40
+ // const pool = await dhedge.loadPool(myPool);
41
+ // try {
42
+ // result = await pool.trade(
43
+ // Dapp.BALANCER,
44
+ // usdc,
45
+ // sushi,
46
+ // "2000000",
47
+ // 0.5,
48
+ // options
49
+ // );
50
+ // console.log(result);
51
+ // } catch (e) {
52
+ // console.log(e);
53
+ // }
54
+ // expect(result).not.toBe(null);
55
+ // });
56
+
57
+ // it("adds 1 USDC to a USDC/TUSD/DAI/USDT balancer pool", async () => {
58
+ // let result;
59
+ // const pool = await dhedge.loadPool(TEST_POOL);
60
+ // const assets = [USDC, TUSD, DAI, USDT];
61
+ // const amounts = ["1000000", "0", "0", "0"];
62
+ // try {
63
+ // result = await pool.joinBalancerPool(
64
+ // "0x0d34e5dd4d8f043557145598e4e2dc286b35fd4f000000000000000000000068",
65
+ // assets,
66
+ // amounts,
67
+ // options
68
+ // );
69
+ // console.log("result", result);
70
+ // } catch (e) {
71
+ // console.log(e);
72
+ // }
73
+ // expect(result).not.toBe(null);
74
+ // });
75
+
76
+ // it("exits entire balance of WBTC/USDC/WETH balancer pool", async () => {
77
+ // let result;
78
+ // const pool = await dhedge.loadPool(myPool);
79
+ // const assets = [wbtc, usdc, weth];
80
+ // const amount = await dhedge.utils.getBalance(
81
+ // "0x03cd191f589d12b0582a99808cf19851e468e6b5",
82
+ // pool.address
83
+ // );
84
+ // try {
85
+ // result = await pool.exitBalancerPool(
86
+ // "0x03cd191f589d12b0582a99808cf19851e468e6b500010000000000000000000a",
87
+ // assets,
88
+ // amount,
89
+ // options
90
+ // );
91
+ // console.log("result", result);
92
+ // } catch (e) {
93
+ // console.log(e);
94
+ // }
95
+ // expect(result).not.toBe(null);
96
+ // });
97
+
98
+ it("claims balancer rewards", async () => {
99
+ let result;
100
+ const pool = await dhedge.loadPool(TEST_POOL);
101
+ try {
102
+ result = await pool.harvestBalancerRewards(options);
103
+ console.log("result", result);
104
+ } catch (e) {
105
+ console.log(e);
106
+ }
107
+ expect(result).not.toBe(null);
108
+ });
109
+ });
@@ -0,0 +1,13 @@
1
+ export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
2
+ export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
3
+ export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
4
+ export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
5
+ export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
6
+ export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
7
+ export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
8
+ export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
9
+ export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
10
+ export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
11
+ export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
12
+
13
+ export const TEST_POOL = "0x3deeba9ca29e2dd98d32eed8dd559dac55014615";
@@ -0,0 +1,56 @@
1
+ import { Dhedge, ethers } from "..";
2
+ import { Dapp, Network } from "../types";
3
+ import { TEST_POOL, USDC, WETH } from "./constants";
4
+
5
+ import { wallet } from "./wallet";
6
+
7
+ let dhedge: Dhedge;
8
+
9
+ jest.setTimeout(100000);
10
+
11
+ const options = {
12
+ gasLimit: 5000000,
13
+ gasPrice: ethers.utils.parseUnits("35", "gwei")
14
+ };
15
+
16
+ describe("pool", () => {
17
+ beforeAll(() => {
18
+ dhedge = new Dhedge(wallet, Network.POLYGON);
19
+ });
20
+
21
+ // it("approves unlimited USDC on 1Inch", async () => {
22
+ // let result;
23
+ // const pool = await dhedge.loadPool(TEST_POOL);
24
+ // try {
25
+ // result = await pool.approve(
26
+ // Dapp.ONEINCH,
27
+ // USDC,
28
+ // ethers.constants.MaxInt256,
29
+ // options
30
+ // );
31
+ // console.log(result);
32
+ // } catch (e) {
33
+ // console.log(e);
34
+ // }
35
+ // expect(result).not.toBe(null);
36
+ // });
37
+
38
+ it("trades 1 USDC into WETH on 1Inch", async () => {
39
+ let result;
40
+ const pool = await dhedge.loadPool(TEST_POOL);
41
+ try {
42
+ result = await pool.trade(
43
+ Dapp.ONEINCH,
44
+ USDC,
45
+ WETH,
46
+ "1000000",
47
+ 0.5,
48
+ options
49
+ );
50
+ console.log("1inch trade", result);
51
+ } catch (e) {
52
+ console.log(e);
53
+ }
54
+ expect(result).not.toBe(null);
55
+ });
56
+ });