@dhedge/v2-sdk 1.5.1 → 1.5.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/v2-sdk",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "license": "MIT",
5
5
  "description": "🛠 An SDK for building applications on top of dHEDGE V2",
6
6
  "main": "dist/index.js",
@@ -273,6 +273,12 @@ export class Utils {
273
273
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
274
  ): Promise<any> {
275
275
  const iBalancerV2Vault = new ethers.utils.Interface(IBalancerV2Vault.abi);
276
+ const bptAddress = ethers.utils.getAddress(balancerPoolId.slice(0, 42));
277
+ const bptIndex = assets.findIndex(
278
+ e => e.toLowerCase() === bptAddress.toLocaleLowerCase()
279
+ );
280
+ const poolAssetsAmounts = amountsIn.slice();
281
+ if (bptIndex >= 0) poolAssetsAmounts.splice(bptIndex, 1);
276
282
  const txData = [
277
283
  balancerPoolId,
278
284
  pool.address,
@@ -282,7 +288,7 @@ export class Utils {
282
288
  amountsIn,
283
289
  ethers.utils.defaultAbiCoder.encode(
284
290
  ["uint256", "uint256[]", "uint256"],
285
- [1, amountsIn, 0]
291
+ [1, poolAssetsAmounts, 0]
286
292
  ),
287
293
  false
288
294
  ]
@@ -8,10 +8,16 @@ import { isPool, loadPool } from "./pool";
8
8
 
9
9
  export async function getPoolDepositAsset(
10
10
  pool: Pool,
11
- poolAddress: string
11
+ poolAddress: string,
12
+ investAsset: string
12
13
  ): Promise<string | undefined> {
13
14
  const torosPool = await loadPool(pool, poolAddress);
14
15
  const composition = await torosPool.getComposition();
16
+ if (
17
+ composition.find(e => e.asset.toLowerCase() === investAsset.toLowerCase())
18
+ ?.isDeposit
19
+ )
20
+ return investAsset;
15
21
  return composition.find(e => e.isDeposit)?.asset;
16
22
  }
17
23
 
@@ -90,7 +96,11 @@ export async function getEasySwapperTxData(
90
96
  minAmountOut.mul(10000 - slippage * 100).div(10000)
91
97
  ]);
92
98
  } else {
93
- const depositAsset = await getPoolDepositAsset(pool, torosAsset);
99
+ const depositAsset = await getPoolDepositAsset(
100
+ pool,
101
+ torosAsset,
102
+ investAsset
103
+ );
94
104
  if (!depositAsset) throw new Error("no deposit assets");
95
105
  const minAmountOut = await getEasySwapperDepositQuote(
96
106
  pool,
@@ -1,6 +1,6 @@
1
1
  import { Dhedge } from "..";
2
2
  import { Network } from "../types";
3
- import { STMATIC, TEST_POOL, WMATIC } from "./constants";
3
+ import { TEST_POOL, WMATIC } from "./constants";
4
4
  import { getTxOptions } from "./txOptions";
5
5
 
6
6
  import { wallet } from "./wallet";
@@ -13,7 +13,7 @@ jest.setTimeout(100000);
13
13
  describe("pool", () => {
14
14
  beforeAll(async () => {
15
15
  dhedge = new Dhedge(wallet, Network.POLYGON);
16
- options = await getTxOptions();
16
+ options = await getTxOptions(Network.POLYGON);
17
17
  });
18
18
 
19
19
  // it("approves unlimited USDC on Balancer", async () => {
@@ -105,24 +105,28 @@ describe("pool", () => {
105
105
  // expect(result).not.toBe(null);
106
106
  // });
107
107
 
108
- // it("adds 5 WMATIC to a WMATIC/stMATIC balancer pool", async () => {
109
- // let result;
110
- // const pool = await dhedge.loadPool(TEST_POOL);
111
- // const assets = [WMATIC, STMATIC];
112
- // const amounts = ["5000000000000000000", "0"];
113
- // try {
114
- // result = await pool.joinBalancerPool(
115
- // "0xaf5e0b5425de1f5a630a8cb5aa9d97b8141c908d000200000000000000000366",
116
- // assets,
117
- // amounts,
118
- // options
119
- // );
120
- // console.log("result", result);
121
- // } catch (e) {
122
- // console.log(e);
123
- // }
124
- // expect(result).not.toBe(null);
125
- // });
108
+ it("adds 5 WMATIC to a WMATIC/stMATIC balancer pool", async () => {
109
+ let result;
110
+ const pool = await dhedge.loadPool(TEST_POOL);
111
+ const assets = [
112
+ WMATIC,
113
+ "0xb20fC01D21A50d2C734C4a1262B4404d41fA7BF0",
114
+ "0xfa68FB4628DFF1028CFEc22b4162FCcd0d45efb6"
115
+ ];
116
+ const amounts = ["29500317230801455961187", "0", "0"];
117
+ try {
118
+ result = await pool.joinBalancerPool(
119
+ "0xb20fc01d21a50d2c734c4a1262b4404d41fa7bf000000000000000000000075c",
120
+ assets,
121
+ amounts,
122
+ options
123
+ );
124
+ console.log("result", result);
125
+ } catch (e) {
126
+ console.log(e);
127
+ }
128
+ expect(result).not.toBe(null);
129
+ });
126
130
 
127
131
  // it("allows unlimited WMATIC-stMATIC LP on gauge", async () => {
128
132
  // let result;
@@ -189,26 +193,26 @@ describe("pool", () => {
189
193
  // expect(result).not.toBe(null);
190
194
  // });
191
195
 
192
- it("exits from WMATIC-stMATIC LP into WMATIC", async () => {
193
- let result;
194
- const pool = await dhedge.loadPool(TEST_POOL);
195
- const assets = [WMATIC, STMATIC];
196
- const amount = await dhedge.utils.getBalance(
197
- "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D",
198
- pool.address
199
- );
200
- try {
201
- result = await pool.exitBalancerPool(
202
- "0xaf5e0b5425de1f5a630a8cb5aa9d97b8141c908d000200000000000000000366",
203
- assets,
204
- amount,
205
- 1,
206
- options
207
- );
208
- console.log("result", result);
209
- } catch (e) {
210
- console.log(e);
211
- }
212
- expect(result).not.toBe(null);
213
- });
196
+ // it("exits from WMATIC-stMATIC LP into WMATIC", async () => {
197
+ // let result;
198
+ // const pool = await dhedge.loadPool(TEST_POOL);
199
+ // const assets = [WMATIC, STMATIC];
200
+ // const amount = await dhedge.utils.getBalance(
201
+ // "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D",
202
+ // pool.address
203
+ // );
204
+ // try {
205
+ // result = await pool.exitBalancerPool(
206
+ // "0xaf5e0b5425de1f5a630a8cb5aa9d97b8141c908d000200000000000000000366",
207
+ // assets,
208
+ // amount,
209
+ // 1,
210
+ // options
211
+ // );
212
+ // console.log("result", result);
213
+ // } catch (e) {
214
+ // console.log(e);
215
+ // }
216
+ // expect(result).not.toBe(null);
217
+ // });
214
218
  });