@dhedge/v2-sdk 1.2.1 → 1.4.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.
Files changed (41) hide show
  1. package/dist/config.d.ts +5 -0
  2. package/dist/entities/pool.d.ts +98 -7
  3. package/dist/entities/utils.d.ts +7 -1
  4. package/dist/services/uniswap/V3Liquidity.d.ts +9 -0
  5. package/dist/services/uniswap/V3Trade.d.ts +4 -0
  6. package/dist/services/uniswap/types.d.ts +3 -0
  7. package/dist/test/constants.d.ts +5 -2
  8. package/dist/test/txOptions.d.ts +1 -0
  9. package/dist/types.d.ts +19 -10
  10. package/dist/v2-sdk.cjs.development.js +3796 -679
  11. package/dist/v2-sdk.cjs.development.js.map +1 -1
  12. package/dist/v2-sdk.cjs.production.min.js +1 -1
  13. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  14. package/dist/v2-sdk.esm.js +3797 -680
  15. package/dist/v2-sdk.esm.js.map +1 -1
  16. package/package.json +4 -1
  17. package/src/abi/IArrakisV1RouterStaking.json +107 -0
  18. package/src/abi/IBalancerRewardsGauge.json +239 -0
  19. package/src/abi/IERC20.json +15 -1
  20. package/src/abi/ILiquidityGaugeV4.json +153 -0
  21. package/src/abi/INonfungiblePositionManager.json +1221 -0
  22. package/src/abi/ISynthetix.json +139 -0
  23. package/src/abi/IUniswapV3Quoter.json +195 -0
  24. package/src/abi/IUniswapV3Router.json +221 -0
  25. package/src/config.ts +35 -8
  26. package/src/entities/dhedge.ts +4 -2
  27. package/src/entities/pool.ts +394 -33
  28. package/src/entities/utils.ts +25 -9
  29. package/src/services/uniswap/V3Liquidity.ts +134 -0
  30. package/src/services/uniswap/V3Trade.ts +47 -0
  31. package/src/services/uniswap/types.ts +16 -0
  32. package/src/test/aave.test.ts +53 -25
  33. package/src/test/arrakis.test.ts +89 -0
  34. package/src/test/balancer.test.ts +115 -10
  35. package/src/test/constants.ts +12 -2
  36. package/src/test/oneInch.test.ts +13 -20
  37. package/src/test/synthetix.test.ts +34 -0
  38. package/src/test/txOptions.ts +15 -0
  39. package/src/test/uniswap.test.ts +125 -0
  40. package/src/test/wallet.ts +4 -0
  41. package/src/types.ts +19 -10
package/dist/config.d.ts CHANGED
@@ -4,6 +4,11 @@ export declare const factoryAddress: AddressNetworkMap;
4
4
  export declare const routerAddress: AddressDappNetworkMap;
5
5
  export declare const dappFactoryAddress: AddressDappNetworkMap;
6
6
  export declare const stakingAddress: AddressDappNetworkMap;
7
+ export declare const nonfungiblePositionManagerAddress: AddressNetworkMap;
7
8
  export declare const networkChainIdMap: NetworkChainIdMap;
8
9
  export declare const balancerSubgraph: AddressNetworkMap;
9
10
  export declare const multiCallAddress: AddressNetworkMap;
11
+ export declare const deadline: number;
12
+ export declare const MaxUint128 = "0xffffffffffffffffffffffffffffffff";
13
+ export declare const UNISWAPV3_QUOTER_ADDRESS = "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6";
14
+ export declare const SYNTHETIX_TRACKING_CODE = "0x4448454447450000000000000000000000000000000000000000000000000000";
@@ -1,14 +1,16 @@
1
1
  import { Contract, Wallet, BigNumber } from "ethers";
2
2
  import { Dapp, FundComposition, AssetEnabled, Network } from "../types";
3
3
  import { Utils } from "./utils";
4
+ import { FeeAmount } from "@uniswap/v3-sdk";
4
5
  export declare class Pool {
5
6
  readonly poolLogic: Contract;
6
7
  readonly managerLogic: Contract;
8
+ readonly factory: Contract;
7
9
  readonly signer: Wallet;
8
10
  readonly address: string;
9
11
  readonly utils: Utils;
10
12
  readonly network: Network;
11
- constructor(network: Network, signer: Wallet, poolLogic: Contract, mangerLogic: Contract, utils: Utils);
13
+ constructor(network: Network, signer: Wallet, poolLogic: Contract, mangerLogic: Contract, utils: Utils, factory: Contract);
12
14
  /**
13
15
  * Return the assets with balances and deposit info of a pool
14
16
  * @returns {Promise<FundComposition[]>} Composition of assets with balance, deposit info
@@ -55,13 +57,31 @@ export declare class Pool {
55
57
  * @returns {Promise<any>} Transaction
56
58
  */
57
59
  approveStaking(dapp: Dapp, asset: string, amount: BigNumber | string, options?: any): Promise<any>;
60
+ /**
61
+ * Approve the liquidity pool token for staking
62
+ * @param {Dapp} dapp Platform like Sushiswap or Uniswap
63
+ * @param {string} asset Address of liquidity pool token
64
+ * @param {BigNumber | string} amount Aamount to be approved
65
+ * @param {any} options Transaction options
66
+ * @returns {Promise<any>} Transaction
67
+ */
68
+ approveUniswapV3Liquidity(asset: string, amount: BigNumber | string, options?: any): Promise<any>;
69
+ /**
70
+ * Approve the asset for provided spender address
71
+ * @param {string} spender Spender address
72
+ * @param {string} asset Address of asset
73
+ * @param {BigNumber | string} amount to be approved
74
+ * @param {any} options Transaction options
75
+ * @returns {Promise<any>} Transaction
76
+ */
77
+ approveSpender(spender: string, asset: string, amount: BigNumber | string, options?: any): Promise<any>;
58
78
  /**
59
79
  * Trade an asset into another asset
60
80
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
61
81
  * @param {string} assetFrom Asset to trade from
62
82
  * @param {string} assetTo Asset to trade into
63
83
  * @param {BigNumber | string} amountIn Amount
64
- * @param {BigNumber | string} minAmountOut Minumum amount to receive
84
+ * @param {number} slippage Slippage tolerance in %
65
85
  * @param {any} options Transaction options
66
86
  * @returns {Promise<any>} Transaction
67
87
  */
@@ -96,6 +116,14 @@ export declare class Pool {
96
116
  * @returns {Promise<any>} Transaction
97
117
  */
98
118
  stake(dapp: Dapp, asset: string, amount: BigNumber | string, options?: any): Promise<any>;
119
+ /**
120
+ * Stake liquidity pool tokens in gauge contract
121
+ * @param {string} gauge Gauge contract address
122
+ * @param {BigNumber | string} amount Amount of liquidity pool tokens
123
+ * @param {any} options Transaction options
124
+ * @returns {Promise<any>} Transaction
125
+ */
126
+ stakeInGauge(gauge: string, amount: BigNumber | string, options?: any): Promise<any>;
99
127
  /**
100
128
  * Unstake liquidity pool tokens from a yield farm
101
129
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
@@ -105,16 +133,24 @@ export declare class Pool {
105
133
  * @returns {Promise<any>} Transaction
106
134
  */
107
135
  unStake(dapp: Dapp, asset: string, amount: BigNumber | string, options?: any): Promise<any>;
136
+ /**
137
+ * Unstake liquidity pool tokens from gauge contract
138
+ * @param {string} gauge Gauge contract address
139
+ * @param {BigNumber | string} amount Amount of liquidity pool tokens
140
+ * @param {any} options Transaction options
141
+ * @returns {Promise<any>} Transaction
142
+ */
143
+ unstakeFromGauge(gauge: string, amount: BigNumber | string, options?: any): Promise<any>;
108
144
  /**
109
145
  * Lend asset to a lending pool
110
146
  * @param {Dapp} dapp Platform like Aave
111
147
  * @param {string} asset Asset
112
148
  * @param {BigNumber | string} amount Amount of asset to lend
113
- * @param {number} referrralCode Code from Aave referral program
149
+ * @param {number} referralCode Code from Aave referral program
114
150
  * @param {any} options Transaction options
115
151
  * @returns {Promise<any>} Transaction
116
152
  */
117
- lend(dapp: Dapp, asset: string, amount: BigNumber | string, referrralCode?: number, options?: any): Promise<any>;
153
+ lend(dapp: Dapp, asset: string, amount: BigNumber | string, referralCode?: number, options?: any): Promise<any>;
118
154
  /**
119
155
  * Witdraw asset from a lending pool
120
156
  * @param {Dapp} dapp Platform like Aave
@@ -129,11 +165,11 @@ export declare class Pool {
129
165
  * @param {Dapp} dapp Platform like Aave
130
166
  * @param {string} asset Asset
131
167
  * @param {BigNumber | string} amount Amount of asset to lend
132
- * @param {number} referrralCode Code from Aave referral program
168
+ * @param {number} referralCode Code from Aave referral program
133
169
  * @param {any} options Transaction options
134
170
  * @returns {Promise<any>} Transaction
135
171
  */
136
- borrow(dapp: Dapp, asset: string, amount: BigNumber | string, referrralCode?: number, options?: any): Promise<any>;
172
+ borrow(dapp: Dapp, asset: string, amount: BigNumber | string, referralCode?: number, options?: any): Promise<any>;
137
173
  /**
138
174
  * Repays borrowed asset to a lending pool
139
175
  * @param {Dapp} dapp Platform like Aave
@@ -179,10 +215,11 @@ export declare class Pool {
179
215
  * @param {string} poolId Balancer pool id
180
216
  * @param {string[] | } assets Array of balancer pool assets
181
217
  * @param {BigNumber | string } amount Amount of pool tokens to withdraw
218
+ * @param { null | number } singleExitAssetIndex Index of asset to withdraw to
182
219
  * @param {any} options Transaction options
183
220
  * @returns {Promise<any>} Transaction
184
221
  */
185
- exitBalancerPool(poolId: string, assets: string[], amount: string | BigNumber, options?: any): Promise<any>;
222
+ exitBalancerPool(poolId: string, assets: string[], amount: string | BigNumber, singleExitAssetIndex?: number | null, options?: any): Promise<any>;
186
223
  /**
187
224
  * Claim rewards from Balancer pools
188
225
  * @param {string[]} assets Array of tokens being claimed
@@ -197,4 +234,58 @@ export declare class Pool {
197
234
  * @returns {Promise<any>} Transaction
198
235
  */
199
236
  harvestAaveRewards(assets: string[], options?: any): Promise<any>;
237
+ /**
238
+ * Create UniswapV3 liquidity pool
239
+ * @param {string} assetA First asset
240
+ * @param {string} assetB Second asset
241
+ * @param {BigNumber | string} amountA Amount first asset
242
+ * @param {BigNumber | string} amountB Amount second asset
243
+ * @param { number } minPrice Lower price range (assetB per assetA)
244
+ * @param { number } maxPrice Upper price range (assetB per assetA)
245
+ * @param { number } minTick Lower tick range
246
+ * @param { number } maxTick Upper tick range
247
+ * @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
248
+ * @param {any} options Transaction options
249
+ * @returns {Promise<any>} Transaction
250
+ */
251
+ addLiquidityUniswapV3(assetA: string, assetB: string, amountA: BigNumber | string, amountB: BigNumber | string, minPrice: number | null, maxPrice: number | null, minTick: number | null, maxTick: number | null, feeAmount: FeeAmount, options?: any): Promise<any>;
252
+ /**
253
+ * Remove liquidity from an UniswapV3 or Arrakis liquidity pool
254
+ * @param {Dapp} dapp Platform either UniswapV3 or Arrakis
255
+ * @param {string} tokenId Token Id of UniswapV3 position
256
+ * @param {number} amount Amount in percent of assets to be removed
257
+ * @param {any} options Transaction options
258
+ * @returns {Promise<any>} Transaction
259
+ */
260
+ decreaseLiquidity(dapp: Dapp, tokenId: string, amount?: number, options?: any): Promise<any>;
261
+ /**
262
+ * Increase liquidity of an UniswapV3 or Arrakis liquidity pool
263
+ * @param {Dapp} dapp Platform either UniswapV3 or Arrakis
264
+ * @param {string} tokenId Token Id of UniswapV3 position
265
+ * @param {BigNumber | string} amountA Amount first asset
266
+ * @param {BigNumber | string} amountB Amount second asset
267
+ * @param {any} options Transaction options
268
+ * @returns {Promise<any>} Transaction
269
+ */
270
+ increaseLiquidity(dapp: Dapp, tokenId: string, amountA: BigNumber | string, amountB: BigNumber | string, options?: any): Promise<any>;
271
+ /**
272
+ * Claim fees of an UniswapV3 liquidity or Arrakis pool
273
+ * @param {Dapp} dapp Platform either UniswapV3 or Arrakis
274
+ * @param {string} tokenId Token Id of UniswapV3 or Gauge address
275
+ * @param {any} options Transaction option
276
+ * @returns {Promise<any>} Transaction
277
+ */
278
+ claimFees(dapp: Dapp, tokenId: string, options?: any): Promise<any>;
279
+ /**
280
+ * Trade an asset into another asset
281
+ * @param {Dapp} dapp Platform like Sushiswap or Uniswap
282
+ * @param {string} assetFrom Asset to trade from
283
+ * @param {string} assetTo Asset to trade into
284
+ * @param {BigNumber | string} amountIn Amount
285
+ * @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
286
+ * @param {number} slippage Slippage tolerance in %
287
+ * @param {any} options Transaction options
288
+ * @returns {Promise<any>} Transaction
289
+ */
290
+ tradeUniswapV3(assetFrom: string, assetTo: string, amountIn: BigNumber | string, feeAmount: FeeAmount, slippage?: number, options?: any): Promise<any>;
200
291
  }
@@ -30,6 +30,12 @@ export declare class Utils {
30
30
  * @returns { BigNumber } Balance of asset
31
31
  */
32
32
  getBalance(asset: string, owner: string): Promise<ethers.BigNumber>;
33
+ /**
34
+ * Returns the decimals of an asset (ERC20) token
35
+ * @param {string} asset string token address
36
+ * @returns { number } Balance of asset
37
+ */
38
+ getDecimals(asset: string): Promise<number>;
33
39
  /**
34
40
  * Return the minimum amount out for a trade between two assets
35
41
  * given the trade amount and slippage
@@ -43,5 +49,5 @@ export declare class Utils {
43
49
  getMinAmountOut(dapp: Dapp, assetFrom: string, assetTo: string, amountIn: string | ethers.BigNumber, slippage: number): Promise<ethers.BigNumber>;
44
50
  getBalancerSwapTx(pool: Pool, assetFrom: string, assetTo: string, amountIn: ethers.BigNumber | string, slippage: number): Promise<any>;
45
51
  getBalancerJoinPoolTx(pool: Pool, balancerPoolId: string, assets: string[], amountsIn: string[] | ethers.BigNumber[]): Promise<any>;
46
- getBalancerExitPoolTx(pool: Pool, balancerPoolId: string, assets: string[], amount: string | ethers.BigNumber): Promise<any>;
52
+ getBalancerExitPoolTx(pool: Pool, balancerPoolId: string, assets: string[], singleExitAssetIndex: null | number, amount: string | ethers.BigNumber): Promise<any>;
47
53
  }
@@ -0,0 +1,9 @@
1
+ import { Price, Token } from "@uniswap/sdk-core";
2
+ import { FeeAmount } from "@uniswap/v3-sdk";
3
+ import { ethers } from "ethers";
4
+ import { Pool } from "../..";
5
+ import { UniswapV3MintParams } from "./types";
6
+ export declare function tryParsePrice(baseToken: Token, quoteToken: Token, value: string): Price<Token, Token>;
7
+ export declare function tryParseTick(baseToken: Token, quoteToken: Token, feeAmount: FeeAmount, value: string): number;
8
+ export declare function getUniswapV3MintParams(pool: Pool, assetA: string, assetB: string, amountA: string | ethers.BigNumber, amountB: string | ethers.BigNumber, minPrice: number | null, maxPrice: number | null, minTick: number | null, maxTick: number | null, feeAmount: FeeAmount): Promise<UniswapV3MintParams>;
9
+ export declare function getUniswapV3Liquidity(tokenId: string, pool: Pool): Promise<ethers.BigNumber>;
@@ -0,0 +1,4 @@
1
+ import { FeeAmount } from "@uniswap/v3-sdk";
2
+ import { ethers } from "ethers";
3
+ import { Pool } from "../..";
4
+ export declare function getUniswapV3SwapTxData(pool: Pool, assetA: string, assetB: string, amountIn: string | ethers.BigNumber, slippage: number, feeAmount: FeeAmount): Promise<any>;
@@ -0,0 +1,3 @@
1
+ import { FeeAmount } from "@uniswap/v3-sdk";
2
+ import { ethers } from "ethers";
3
+ export declare type UniswapV3MintParams = [string, string, FeeAmount, number, number, ethers.BigNumber | string, ethers.BigNumber | string, ethers.BigNumber | string, ethers.BigNumber | string, string, number];
@@ -1,12 +1,15 @@
1
1
  export declare const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
2
+ export declare const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
2
3
  export declare const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
3
4
  export declare const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
4
5
  export declare const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
5
- export declare const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
6
6
  export declare const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
7
7
  export declare const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
8
8
  export declare const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
9
9
  export declare const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
10
10
  export declare const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
11
11
  export declare const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
12
- export declare const TEST_POOL = "0x3deeba9ca29e2dd98d32eed8dd559dac55014615";
12
+ export declare const ARRAKIS_USDC_WETH_GAUGE = "0x33d1ad9Cd88A509397CD924C2d7613C285602C20";
13
+ export declare const STMATIC = "0x3A58a54C066FdC0f2D55FC9C89F0415C92eBf3C4";
14
+ export declare const WMATIC_STMATIC_LP = "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D";
15
+ export declare const TEST_POOL = "TEST_POOL_ADDRESS";
@@ -0,0 +1 @@
1
+ export declare const getTxOptions: () => Promise<any>;
package/dist/types.d.ts CHANGED
@@ -1,14 +1,18 @@
1
- import { ChainId } from "@sushiswap/sdk";
2
1
  import { BigNumber } from "ethers";
3
2
  export declare enum Network {
4
- POLYGON = "polygon"
3
+ POLYGON = "polygon",
4
+ OPTIMISM = "optimism"
5
5
  }
6
6
  export declare enum Dapp {
7
7
  SUSHISWAP = "sushiswap",
8
8
  AAVE = "aave",
9
9
  ONEINCH = "1inch",
10
10
  QUICKSWAP = "quickswap",
11
- BALANCER = "balancer"
11
+ BALANCER = "balancer",
12
+ UNISWAPV3 = "uniswapV3",
13
+ SYNTHETIX = "synthetix",
14
+ AAVEV3 = "aavev3",
15
+ ARRAKIS = "arrakis"
12
16
  }
13
17
  export declare enum Transaction {
14
18
  SWAP = "swapExactTokensForTokens",
@@ -18,17 +22,22 @@ export declare enum Transaction {
18
22
  CLAIM_DISTRIBIUTIONS = "claimDistributions",
19
23
  CLAIM_REWARDS = "claimRewards",
20
24
  REMOVE_LIQUIDITY = "removeLiquidity",
25
+ DECREASE_LIQUIDITY = "decreaseLiquidity",
26
+ INCREASE_LIQUIDITY = "increaseLiquidity",
27
+ COLLECT = "collect",
28
+ MULTI_CALL = "multicall",
21
29
  BORROW = "borrow",
22
30
  REPAY = "repay",
23
- WITHDRAW = "withdraw"
31
+ WITHDRAW = "withdraw",
32
+ MINT = "mint",
33
+ BURN = "burn",
34
+ SWAP_SYNTHS = "exchangeWithTracking",
35
+ ADD_LIQUIDITY_STAKE = "addLiquidityAndStake",
36
+ REMOVE_LIQUIDITY_UNSTAKE = "removeLiquidityAndUnstake"
24
37
  }
25
38
  export declare type AddressNetworkMap = Readonly<Record<Network, string>>;
26
39
  export declare type AddressDappMap = {
27
- [Dapp.SUSHISWAP]?: string;
28
- [Dapp.AAVE]?: string;
29
- [Dapp.ONEINCH]?: string;
30
- [Dapp.QUICKSWAP]?: string;
31
- [Dapp.BALANCER]?: string;
40
+ [key in Dapp]?: string;
32
41
  };
33
42
  export declare type AddressDappNetworkMap = Readonly<Record<Network, AddressDappMap>>;
34
43
  export declare type SupportedAsset = [string, boolean];
@@ -46,4 +55,4 @@ export declare type Reserves = {
46
55
  assetA: BigNumber;
47
56
  assetB: BigNumber;
48
57
  };
49
- export declare type NetworkChainIdMap = Readonly<Record<Network, ChainId>>;
58
+ export declare type NetworkChainIdMap = Readonly<Record<Network, number>>;