@dhedge/v2-sdk 1.11.0 → 1.11.1

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.11.0",
3
+ "version": "1.11.1",
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,27 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ { "internalType": "uint256", "name": "assets_", "type": "uint256" },
5
+ { "internalType": "address", "name": "receiver_", "type": "address" }
6
+ ],
7
+ "name": "deposit",
8
+ "outputs": [
9
+ { "internalType": "uint256", "name": "shares_", "type": "uint256" }
10
+ ],
11
+ "stateMutability": "nonpayable",
12
+ "type": "function"
13
+ },
14
+ {
15
+ "inputs": [
16
+ { "internalType": "uint256", "name": "shares_", "type": "uint256" },
17
+ { "internalType": "address", "name": "receiver_", "type": "address" },
18
+ { "internalType": "address", "name": "owner_", "type": "address" }
19
+ ],
20
+ "name": "redeem",
21
+ "outputs": [
22
+ { "internalType": "uint256", "name": "assets_", "type": "uint256" }
23
+ ],
24
+ "stateMutability": "nonpayable",
25
+ "type": "function"
26
+ }
27
+ ]
@@ -717,8 +717,8 @@ export class Pool {
717
717
  }
718
718
 
719
719
  /**
720
- * Lend asset to a Compound V3 style lending pool
721
- * @param {string} market Address of market e.g cUSDCv3 address
720
+ * Lend asset to a Compound V3 or Fluid lending pool
721
+ * @param {string} market Address of cToken or fToken
722
722
  * @param {string} asset Asset
723
723
  * @param {BigNumber | string} amount Amount of asset to lend
724
724
  * @param {any} options Transaction options
@@ -732,7 +732,12 @@ export class Pool {
732
732
  options: any = null,
733
733
  estimateGas = false
734
734
  ): Promise<any> {
735
- const supplyTxData = getCompoundV3LendTxData(asset, amount);
735
+ const supplyTxData = await getCompoundV3LendTxData(
736
+ this,
737
+ market,
738
+ asset,
739
+ amount
740
+ );
736
741
 
737
742
  const tx = await getPoolTxOrGasEstimate(
738
743
  this,
@@ -773,8 +778,8 @@ export class Pool {
773
778
  }
774
779
 
775
780
  /**
776
- * Witdraw asset from a COmpound V3 style lending pool
777
- * @param {string} market Address of market e.g cUSDCv3 address
781
+ * Witdraw asset from a Compound V3 or Fluid lending pool
782
+ * @param {string} market Address of cToken or fToken
778
783
  * @param {string} asset Asset
779
784
  * @param {BigNumber | string} amount Amount of asset to withdraw
780
785
  * @param {any} options Transaction options
@@ -788,7 +793,12 @@ export class Pool {
788
793
  options: any = null,
789
794
  estimateGas = false
790
795
  ): Promise<any> {
791
- const withdrawTxData = getCompoundV3WithdrawTxData(asset, amount);
796
+ const withdrawTxData = await getCompoundV3WithdrawTxData(
797
+ this,
798
+ market,
799
+ asset,
800
+ amount
801
+ );
792
802
 
793
803
  const tx = await getPoolTxOrGasEstimate(
794
804
  this,
@@ -1,20 +1,59 @@
1
- import { ethers } from "../..";
1
+ import { ethers, Pool } from "../..";
2
2
  import ICompoundV3Comet from "../../abi/compound/ICompoundV3Comet.json";
3
+ import IFToken from "../../abi/fluid/IFToken.json";
3
4
 
4
- export function getCompoundV3LendTxData(
5
+ export async function getCompoundV3LendTxData(
6
+ pool: Pool,
7
+ market: string,
5
8
  asset: string,
6
9
  amount: ethers.BigNumber | string
7
- ): string {
8
- return new ethers.utils.Interface(
9
- ICompoundV3Comet
10
- ).encodeFunctionData("supply", [asset, amount]);
10
+ ): Promise<string> {
11
+ if (await isCompoundV3Market(pool, market)) {
12
+ return new ethers.utils.Interface(
13
+ ICompoundV3Comet
14
+ ).encodeFunctionData("supply", [asset, amount]);
15
+ } else {
16
+ //Fluid lending
17
+ return new ethers.utils.Interface(IFToken).encodeFunctionData("deposit", [
18
+ amount,
19
+ pool.address
20
+ ]);
21
+ }
11
22
  }
12
23
 
13
- export function getCompoundV3WithdrawTxData(
24
+ export async function getCompoundV3WithdrawTxData(
25
+ pool: Pool,
26
+ market: string,
14
27
  asset: string,
15
28
  amount: ethers.BigNumber | string
16
- ): string {
17
- return new ethers.utils.Interface(
18
- ICompoundV3Comet
19
- ).encodeFunctionData("withdraw", [asset, amount]);
29
+ ): Promise<string> {
30
+ if (await isCompoundV3Market(pool, market)) {
31
+ return new ethers.utils.Interface(
32
+ ICompoundV3Comet
33
+ ).encodeFunctionData("withdraw", [asset, amount]);
34
+ } else {
35
+ //Fluid withdrawal
36
+ return new ethers.utils.Interface(IFToken).encodeFunctionData("redeem", [
37
+ amount,
38
+ pool.address,
39
+ pool.address
40
+ ]);
41
+ }
42
+ }
43
+
44
+ export async function isCompoundV3Market(
45
+ pool: Pool,
46
+ market: string
47
+ ): Promise<boolean> {
48
+ const marketContract = new ethers.Contract(
49
+ market,
50
+ ICompoundV3Comet,
51
+ pool.signer
52
+ );
53
+ try {
54
+ await marketContract.baseToken();
55
+ return true;
56
+ } catch (error) {
57
+ return false;
58
+ }
20
59
  }
@@ -63,6 +63,7 @@ export const CONTRACT_ADDRESS = {
63
63
  VELODROME_CL_USDC_WETH_GAUGE: "",
64
64
  VELO: "",
65
65
  COMPOUNDV3_WETH: "",
66
+ FLUID_WETH: "",
66
67
  TOROS: "",
67
68
  UNIT: ""
68
69
  },
@@ -87,6 +88,7 @@ export const CONTRACT_ADDRESS = {
87
88
  VELODROME_CL_USDC_WETH_GAUGE: "0xa75127121d28a9BF848F3B70e7Eea26570aa7700",
88
89
  VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db",
89
90
  COMPOUNDV3_WETH: "",
91
+ FLUID_WETH: "",
90
92
  TOROS: "0x49bf093277bf4dde49c48c6aa55a3bda3eedef68" //USDmny
91
93
  },
92
94
  [Network.ARBITRUM]: {
@@ -113,6 +115,7 @@ export const CONTRACT_ADDRESS = {
113
115
  VELODROME_CL_USDC_WETH_GAUGE: "",
114
116
  VELO: "",
115
117
  COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486",
118
+ FLUID_WETH: "0x45df0656f8adf017590009d2f1898eeca4f0a205",
116
119
  TOROS: ""
117
120
  },
118
121
  [Network.BASE]: {
@@ -133,6 +136,7 @@ export const CONTRACT_ADDRESS = {
133
136
  VELODROME_CL_USDC_WETH_GAUGE: "0xF33a96b5932D9E9B9A0eDA447AbD8C9d48d2e0c8",
134
137
  VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
135
138
  COMPOUNDV3_WETH: "",
139
+ FLUID_WETH: "",
136
140
  TOROS: ""
137
141
  },
138
142
  [Network.ETHEREUM]: {
@@ -152,6 +156,7 @@ export const CONTRACT_ADDRESS = {
152
156
  VELODROME_CL_USDC_WETH_GAUGE: "",
153
157
  VELO: "",
154
158
  COMPOUNDV3_WETH: "",
159
+ FLUID_WETH: "",
155
160
  TOROS: "",
156
161
  UNIT: ""
157
162
  }
@@ -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 testFluid = ({ network, provider }: TestingRunParams) => {
17
+ const WETH = CONTRACT_ADDRESS[network].WETH;
18
+ const FLUID_WETH = CONTRACT_ADDRESS[network].FLUID_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: FLUID_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 fWETH market", async () => {
53
+ await pool.approveSpender(FLUID_WETH, WETH, MAX_AMOUNT);
54
+ const wethAllowanceDelta = await allowanceDelta(
55
+ pool.address,
56
+ WETH,
57
+ FLUID_WETH,
58
+ pool.signer
59
+ );
60
+ await expect(wethAllowanceDelta.gt(0));
61
+ });
62
+
63
+ it("lends WETH to Fluid WETH market", async () => {
64
+ const wethBalance = await pool.utils.getBalance(WETH, pool.address);
65
+ await pool.lendCompoundV3(FLUID_WETH, WETH, wethBalance);
66
+
67
+ const fWETHTokenDelta = await balanceDelta(
68
+ pool.address,
69
+ FLUID_WETH,
70
+ pool.signer
71
+ );
72
+ expect(fWETHTokenDelta.gt(0));
73
+ });
74
+
75
+ it("withdraw WETH from Fluid WETH market", async () => {
76
+ const fWETHBalance = await pool.utils.getBalance(
77
+ FLUID_WETH,
78
+ pool.address
79
+ );
80
+ await pool.withdrawCompoundV3(FLUID_WETH, WETH, fWETHBalance);
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: testFluid
90
+ });