@dhedge/v2-sdk 1.10.3 → 1.10.4

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.10.3",
3
+ "version": "1.10.4",
4
4
  "license": "MIT",
5
5
  "description": "🛠 An SDK for building applications on top of dHEDGE V2",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,51 @@
1
+ [
2
+ {
3
+ "inputs": [],
4
+ "name": "baseToken",
5
+ "outputs": [
6
+ {
7
+ "internalType": "address",
8
+ "name": "",
9
+ "type": "address"
10
+ }
11
+ ],
12
+ "stateMutability": "view",
13
+ "type": "function"
14
+ },
15
+ {
16
+ "inputs": [
17
+ {
18
+ "internalType": "address",
19
+ "name": "asset",
20
+ "type": "address"
21
+ },
22
+ {
23
+ "internalType": "uint256",
24
+ "name": "amount",
25
+ "type": "uint256"
26
+ }
27
+ ],
28
+ "name": "supply",
29
+ "outputs": [],
30
+ "stateMutability": "nonpayable",
31
+ "type": "function"
32
+ },
33
+ {
34
+ "inputs": [
35
+ {
36
+ "internalType": "address",
37
+ "name": "asset",
38
+ "type": "address"
39
+ },
40
+ {
41
+ "internalType": "uint256",
42
+ "name": "amount",
43
+ "type": "uint256"
44
+ }
45
+ ],
46
+ "name": "withdraw",
47
+ "outputs": [],
48
+ "stateMutability": "nonpayable",
49
+ "type": "function"
50
+ }
51
+ ]
@@ -72,6 +72,10 @@ import {
72
72
  mintUnitViaFlatMoney,
73
73
  redeemUnitViaFlatMoney
74
74
  } from "../services/flatmoney/stableLp";
75
+ import {
76
+ getCompoundV3LendTxData,
77
+ getCompoundV3WithdrawTxData
78
+ } from "../services/compound/lending";
75
79
 
76
80
  export class Pool {
77
81
  public readonly poolLogic: Contract;
@@ -666,6 +670,7 @@ export class Pool {
666
670
  this.address,
667
671
  referralCode
668
672
  ]);
673
+
669
674
  const tx = await getPoolTxOrGasEstimate(
670
675
  this,
671
676
  [routerAddress[this.network][dapp], depositTxData, options],
@@ -674,6 +679,32 @@ export class Pool {
674
679
  return tx;
675
680
  }
676
681
 
682
+ /**
683
+ * Lend asset to a Compound V3 style lending pool
684
+ * @param {string} market Address of market e.g cUSDCv3 address
685
+ * @param {string} asset Asset
686
+ * @param {BigNumber | string} amount Amount of asset to lend
687
+ * @param {any} options Transaction options
688
+ * @param {boolean} estimateGas Simulate/estimate gas
689
+ * @returns {Promise<any>} Transaction
690
+ */
691
+ async lendCompoundV3(
692
+ market: string,
693
+ asset: string,
694
+ amount: BigNumber | string,
695
+ options: any = null,
696
+ estimateGas = false
697
+ ): Promise<any> {
698
+ const supplyTxData = getCompoundV3LendTxData(asset, amount);
699
+
700
+ const tx = await getPoolTxOrGasEstimate(
701
+ this,
702
+ [market, supplyTxData, options],
703
+ estimateGas
704
+ );
705
+ return tx;
706
+ }
707
+
677
708
  /**
678
709
  * Witdraw asset from a lending pool
679
710
  * @param {Dapp} dapp Platform like Aave
@@ -695,6 +726,7 @@ export class Pool {
695
726
  Transaction.WITHDRAW,
696
727
  [asset, amount, this.address]
697
728
  );
729
+
698
730
  const tx = await getPoolTxOrGasEstimate(
699
731
  this,
700
732
  [routerAddress[this.network][dapp], withdrawTxData, options],
@@ -703,6 +735,32 @@ export class Pool {
703
735
  return tx;
704
736
  }
705
737
 
738
+ /**
739
+ * Witdraw asset from a COmpound V3 style lending pool
740
+ * @param {string} market Address of market e.g cUSDCv3 address
741
+ * @param {string} asset Asset
742
+ * @param {BigNumber | string} amount Amount of asset to withdraw
743
+ * @param {any} options Transaction options
744
+ * @param {boolean} estimateGas Simulate/estimate gas
745
+ * @returns {Promise<any>} Transaction
746
+ */
747
+ async withdrawCompoundV3(
748
+ market: string,
749
+ asset: string,
750
+ amount: BigNumber | string,
751
+ options: any = null,
752
+ estimateGas = false
753
+ ): Promise<any> {
754
+ const withdrawTxData = getCompoundV3WithdrawTxData(asset, amount);
755
+
756
+ const tx = await getPoolTxOrGasEstimate(
757
+ this,
758
+ [market, withdrawTxData, options],
759
+ estimateGas
760
+ );
761
+ return tx;
762
+ }
763
+
706
764
  /**
707
765
  * Borrow asset from a lending pool
708
766
  * @param {Dapp} dapp Platform like Aave
@@ -0,0 +1,20 @@
1
+ import { ethers } from "../..";
2
+ import ICompoundV3Comet from "../../abi/compound/ICompoundV3Comet.json";
3
+
4
+ export function getCompoundV3LendTxData(
5
+ asset: string,
6
+ amount: ethers.BigNumber | string
7
+ ): string {
8
+ return new ethers.utils.Interface(
9
+ ICompoundV3Comet
10
+ ).encodeFunctionData("supply", [asset, amount]);
11
+ }
12
+
13
+ export function getCompoundV3WithdrawTxData(
14
+ asset: string,
15
+ amount: ethers.BigNumber | string
16
+ ): string {
17
+ return new ethers.utils.Interface(
18
+ ICompoundV3Comet
19
+ ).encodeFunctionData("withdraw", [asset, amount]);
20
+ }
@@ -0,0 +1,90 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import BigNumber from "bignumber.js";
4
+ import { Dhedge, Pool } from "..";
5
+ import { AssetEnabled, Network } from "../types";
6
+ import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
+ import {
8
+ TestingRunParams,
9
+ beforeAfterReset,
10
+ setWETHAmount,
11
+ testingHelper
12
+ } from "./utils/testingHelper";
13
+ import { allowanceDelta, balanceDelta } from "./utils/token";
14
+ import { getWalletData } from "./wallet";
15
+
16
+ const testCompoundV3 = ({ network, provider }: TestingRunParams) => {
17
+ const WETH = CONTRACT_ADDRESS[network].WETH;
18
+ const COMPOUNDV3_WETH = CONTRACT_ADDRESS[network].COMPOUNDV3_WETH;
19
+
20
+ let dhedge: Dhedge;
21
+ let pool: Pool;
22
+ jest.setTimeout(100000);
23
+
24
+ describe(`[${network}] compound V3 tests`, () => {
25
+ beforeAll(async () => {
26
+ const { wallet } = getWalletData(network);
27
+ // top up ETH (gas)
28
+ await provider.send("hardhat_setBalance", [
29
+ wallet.address,
30
+ "0x100000000000000"
31
+ ]);
32
+ dhedge = new Dhedge(wallet, network);
33
+ pool = await dhedge.loadPool(TEST_POOL[network]);
34
+ await setWETHAmount({
35
+ amount: new BigNumber(1e18).toFixed(0),
36
+ userAddress: pool.address,
37
+ network,
38
+ provider
39
+ });
40
+
41
+ const newAssets: AssetEnabled[] = [
42
+ { asset: WETH, isDeposit: true },
43
+ {
44
+ asset: COMPOUNDV3_WETH,
45
+ isDeposit: false
46
+ }
47
+ ];
48
+ await pool.managerLogic.changeAssets(newAssets, []);
49
+ });
50
+ beforeAfterReset({ beforeAll, afterAll, provider });
51
+
52
+ it("approves unlimited WETH for cWETHv3 market", async () => {
53
+ await pool.approveSpender(COMPOUNDV3_WETH, WETH, MAX_AMOUNT);
54
+ const UsdcAllowanceDelta = await allowanceDelta(
55
+ pool.address,
56
+ WETH,
57
+ COMPOUNDV3_WETH,
58
+ pool.signer
59
+ );
60
+ await expect(UsdcAllowanceDelta.gt(0));
61
+ });
62
+
63
+ it("lends WETH to CompundV3 WETH market", async () => {
64
+ const wethBalance = await pool.utils.getBalance(WETH, pool.address);
65
+ await pool.lendCompoundV3(COMPOUNDV3_WETH, WETH, wethBalance);
66
+
67
+ const cWETHTokenDelta = await balanceDelta(
68
+ pool.address,
69
+ COMPOUNDV3_WETH,
70
+ pool.signer
71
+ );
72
+ expect(cWETHTokenDelta.gt(0));
73
+ });
74
+
75
+ it("withdraw WETH from CompundV3 WETH market", async () => {
76
+ const cWETHBalance = await pool.utils.getBalance(
77
+ COMPOUNDV3_WETH,
78
+ pool.address
79
+ );
80
+ await pool.withdrawCompoundV3(COMPOUNDV3_WETH, WETH, cWETHBalance);
81
+ const wethBalance = await balanceDelta(pool.address, WETH, pool.signer);
82
+ expect(wethBalance.gt(0));
83
+ });
84
+ });
85
+ };
86
+
87
+ testingHelper({
88
+ network: Network.ARBITRUM,
89
+ testingRun: testCompoundV3
90
+ });
@@ -59,7 +59,8 @@ export const CONTRACT_ADDRESS = {
59
59
  nonfungiblePositionManager: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
60
60
  },
61
61
  VELODROME_CL_USDC_WETH_GAUGE: "",
62
- VELO: ""
62
+ VELO: "",
63
+ COMPOUNDV3_WETH: ""
63
64
  },
64
65
 
65
66
  [Network.OPTIMISM]: {
@@ -79,7 +80,8 @@ export const CONTRACT_ADDRESS = {
79
80
  ARRAKIS_USDC_WETH_GAUGE: "",
80
81
  ARRAKIS_USDC_WETH_LP: "",
81
82
  VELODROME_CL_USDC_WETH_GAUGE: "0xa75127121d28a9BF848F3B70e7Eea26570aa7700",
82
- VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db"
83
+ VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db",
84
+ COMPOUNDV3_WETH: ""
83
85
  },
84
86
  [Network.ARBITRUM]: {
85
87
  USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
@@ -100,7 +102,8 @@ export const CONTRACT_ADDRESS = {
100
102
  ARRAKIS_USDC_WETH_LP: "",
101
103
  WMATIC: "",
102
104
  VELODROME_CL_USDC_WETH_GAUGE: "",
103
- VELO: ""
105
+ VELO: "",
106
+ COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486"
104
107
  },
105
108
  [Network.BASE]: {
106
109
  USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
@@ -116,7 +119,8 @@ export const CONTRACT_ADDRESS = {
116
119
  ARRAKIS_USDC_WETH_LP: "",
117
120
  WMATIC: "",
118
121
  VELODROME_CL_USDC_WETH_GAUGE: "0xF33a96b5932D9E9B9A0eDA447AbD8C9d48d2e0c8",
119
- VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
122
+ VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
123
+ COMPOUNDV3_WETH: ""
120
124
  }
121
125
  };
122
126