@dhedge/v2-sdk 1.5.0 → 1.5.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/dist/config.d.ts +1 -0
- package/dist/entities/pool.d.ts +8 -0
- package/dist/services/aave/assets.d.ts +2 -0
- package/dist/services/aave/incentives.d.ts +2 -0
- package/dist/test/constants.d.ts +1 -0
- package/dist/v2-sdk.cjs.development.js +2877 -78
- package/dist/v2-sdk.cjs.development.js.map +1 -1
- package/dist/v2-sdk.cjs.production.min.js +1 -1
- package/dist/v2-sdk.cjs.production.min.js.map +1 -1
- package/dist/v2-sdk.esm.js +2875 -76
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IAaveV3Incentives.json +614 -0
- package/src/abi/IAaveV3LendingPool.json +1241 -0
- package/src/config.ts +16 -4
- package/src/entities/pool.ts +22 -0
- package/src/services/aave/assets.ts +26 -0
- package/src/services/aave/incentives.ts +23 -0
- package/src/services/chainLink/price.ts +3 -2
- package/src/test/aave.test.ts +40 -13
- package/src/test/constants.ts +2 -1
- package/src/test/wallet.ts +5 -5
package/src/config.ts
CHANGED
|
@@ -26,14 +26,14 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
26
26
|
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
27
27
|
[Dapp.UNISWAPV3]: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
28
28
|
[Dapp.ARRAKIS]: "0xbc91a120cCD8F80b819EAF32F0996daC3Fa76a6C",
|
|
29
|
-
[Dapp.TOROS]: "
|
|
29
|
+
[Dapp.TOROS]: "0x42B1DDcFa1c43E06F483BA0Dd1b9cC923043677f"
|
|
30
30
|
},
|
|
31
31
|
[Network.OPTIMISM]: {
|
|
32
32
|
[Dapp.UNISWAPV3]: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
33
33
|
[Dapp.SYNTHETIX]: "0x8700dAec35aF8Ff88c16BdF0418774CB3D7599B4",
|
|
34
34
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
35
35
|
[Dapp.ONEINCH]: "0x1111111254760F7ab3F16433eea9304126DCd199",
|
|
36
|
-
[Dapp.TOROS]: "
|
|
36
|
+
[Dapp.TOROS]: "0xf8C62BD5f2fEf9E1a329c197F32E77AD6866B022"
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
|
|
@@ -49,11 +49,23 @@ export const stakingAddress: AddressDappNetworkMap = {
|
|
|
49
49
|
[Network.POLYGON]: {
|
|
50
50
|
[Dapp.SUSHISWAP]: "0x0769fd68dFb93167989C6f7254cd0D766Fb2841F",
|
|
51
51
|
[Dapp.BALANCER]: "0x0F3e0c4218b7b0108a3643cFe9D3ec0d4F57c54e",
|
|
52
|
-
[Dapp.AAVE]: "0x357D51124f59836DeD84c8a1730D72B749d8BC23"
|
|
52
|
+
[Dapp.AAVE]: "0x357D51124f59836DeD84c8a1730D72B749d8BC23",
|
|
53
|
+
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
53
54
|
},
|
|
54
|
-
[Network.OPTIMISM]: {
|
|
55
|
+
[Network.OPTIMISM]: {
|
|
56
|
+
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
57
|
+
}
|
|
55
58
|
};
|
|
56
59
|
|
|
60
|
+
export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
61
|
+
[Network.POLYGON]: {
|
|
62
|
+
[Dapp.AAVE]: "0xd05e3E715d945B59290df0ae8eF85c1BdB684744",
|
|
63
|
+
[Dapp.AAVEV3]: "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb"
|
|
64
|
+
},
|
|
65
|
+
[Network.OPTIMISM]: {
|
|
66
|
+
[Dapp.AAVEV3]: "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
57
69
|
export const nonfungiblePositionManagerAddress: AddressNetworkMap = {
|
|
58
70
|
[Network.POLYGON]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
|
|
59
71
|
[Network.OPTIMISM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
package/src/entities/pool.ts
CHANGED
|
@@ -42,6 +42,7 @@ import { FeeAmount } from "@uniswap/v3-sdk";
|
|
|
42
42
|
import { getUniswapV3SwapTxData } from "../services/uniswap/V3Trade";
|
|
43
43
|
import { getEasySwapperTxData } from "../services/toros/easySwapper";
|
|
44
44
|
import { getOneInchProtocols } from "../services/oneInch/protocols";
|
|
45
|
+
import { getAaveV3ClaimTxData } from "../services/aave/incentives";
|
|
45
46
|
|
|
46
47
|
export class Pool {
|
|
47
48
|
public readonly poolLogic: Contract;
|
|
@@ -813,6 +814,27 @@ export class Pool {
|
|
|
813
814
|
return tx;
|
|
814
815
|
}
|
|
815
816
|
|
|
817
|
+
/**
|
|
818
|
+
* Claim rewards from Aave platform
|
|
819
|
+
* @param {string[]} assets Assets invested in Aave
|
|
820
|
+
* @param {string} rewardAssets Reward token address
|
|
821
|
+
* @param {any} options Transaction options
|
|
822
|
+
* @returns {Promise<any>} Transaction
|
|
823
|
+
*/
|
|
824
|
+
async harvestAaveV3Rewards(
|
|
825
|
+
assets: string[],
|
|
826
|
+
rewardAsset: string,
|
|
827
|
+
options: any = null
|
|
828
|
+
): Promise<any> {
|
|
829
|
+
const claimTxData = await getAaveV3ClaimTxData(this, assets, rewardAsset);
|
|
830
|
+
const tx = await this.poolLogic.execTransaction(
|
|
831
|
+
stakingAddress[this.network][Dapp.AAVEV3] as string,
|
|
832
|
+
claimTxData,
|
|
833
|
+
options
|
|
834
|
+
);
|
|
835
|
+
return tx;
|
|
836
|
+
}
|
|
837
|
+
|
|
816
838
|
/**
|
|
817
839
|
* Create UniswapV3 liquidity pool
|
|
818
840
|
* @param {string} assetA First asset
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Dapp, ethers, Pool } from "../..";
|
|
2
|
+
|
|
3
|
+
import ILendingPool from "../../abi/ILendingPool.json";
|
|
4
|
+
import ILendingPoolV3 from "../../abi/IAaveV3LendingPool.json";
|
|
5
|
+
import { routerAddress } from "../../config";
|
|
6
|
+
|
|
7
|
+
export async function getAaveAssetsForUnderlying(
|
|
8
|
+
pool: Pool,
|
|
9
|
+
dapp: Dapp,
|
|
10
|
+
assets: string[]
|
|
11
|
+
): Promise<string[]> {
|
|
12
|
+
const iLendingPool = dapp === Dapp.AAVEV3 ? ILendingPoolV3 : ILendingPool;
|
|
13
|
+
const lendingPool = new ethers.Contract(
|
|
14
|
+
routerAddress[pool.network][dapp] as string,
|
|
15
|
+
iLendingPool.abi,
|
|
16
|
+
pool.signer
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const reserveData = await Promise.all(
|
|
20
|
+
assets.map(e => lendingPool.getReserveData(e))
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const aTokens = reserveData.map(e => e.aTokenAddress);
|
|
24
|
+
const debtTokens = reserveData.map(e => e.variableDebtTokenAddress);
|
|
25
|
+
return aTokens.concat(debtTokens);
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
import { Dapp } from "../../types";
|
|
4
|
+
import IAaveV3Incentives from "../../abi/IAaveV3Incentives.json";
|
|
5
|
+
import { Pool } from "../..";
|
|
6
|
+
import { getAaveAssetsForUnderlying } from "./assets";
|
|
7
|
+
|
|
8
|
+
export async function getAaveV3ClaimTxData(
|
|
9
|
+
pool: Pool,
|
|
10
|
+
assets: string[],
|
|
11
|
+
rewardAsset: string
|
|
12
|
+
): Promise<any> {
|
|
13
|
+
const iAaveIncentives = new ethers.utils.Interface(IAaveV3Incentives.abi);
|
|
14
|
+
const aaveAsset = await getAaveAssetsForUnderlying(pool, Dapp.AAVEV3, assets);
|
|
15
|
+
|
|
16
|
+
const claimTxData = iAaveIncentives.encodeFunctionData("claimRewards", [
|
|
17
|
+
aaveAsset,
|
|
18
|
+
ethers.constants.MaxUint256,
|
|
19
|
+
pool.address,
|
|
20
|
+
rewardAsset
|
|
21
|
+
]);
|
|
22
|
+
return claimTxData;
|
|
23
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ethers, Pool } from "../..";
|
|
1
|
+
import { Dapp, ethers, Pool } from "../..";
|
|
2
2
|
|
|
3
3
|
import IAaveV3PoolAddressProvider from "../../abi/IAaveV3PoolAddressProvider.json";
|
|
4
4
|
import IPriceOracle from "../../abi/IPriceOracle.json";
|
|
5
|
+
import { aaveAddressProvider } from "../../config";
|
|
5
6
|
|
|
6
7
|
export async function getChainlinkPriceInUsd(
|
|
7
8
|
pool: Pool,
|
|
@@ -10,7 +11,7 @@ export async function getChainlinkPriceInUsd(
|
|
|
10
11
|
//Workaround as Chainlink doesn't have feed registry on Polygon/Optimism
|
|
11
12
|
//Use oracle from Aave which uses Chainlink
|
|
12
13
|
const lendingPoolAddressProvider = new ethers.Contract(
|
|
13
|
-
|
|
14
|
+
aaveAddressProvider[pool.network][Dapp.AAVEV3] as string,
|
|
14
15
|
IAaveV3PoolAddressProvider.abi,
|
|
15
16
|
pool.signer
|
|
16
17
|
);
|
package/src/test/aave.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dhedge } from "..";
|
|
2
|
-
import {
|
|
3
|
-
import { TEST_POOL, WETH } from "./constants";
|
|
2
|
+
import { Network } from "../types";
|
|
3
|
+
import { OP, TEST_POOL, USDC, WBTC, WETH } from "./constants";
|
|
4
4
|
|
|
5
5
|
import { wallet } from "./wallet";
|
|
6
6
|
|
|
@@ -51,17 +51,17 @@ describe("pool", () => {
|
|
|
51
51
|
// expect(result).not.toBe(null);
|
|
52
52
|
// });
|
|
53
53
|
|
|
54
|
-
it("borrows 0.001 WETH from Aave lending pool", async () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
54
|
+
// it("borrows 0.001 WETH from Aave lending pool", async () => {
|
|
55
|
+
// let result;
|
|
56
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
57
|
+
// try {
|
|
58
|
+
// result = await pool.borrow(Dapp.AAVEV3, WETH, "1000000000000000");
|
|
59
|
+
// console.log(result);
|
|
60
|
+
// } catch (e) {
|
|
61
|
+
// console.log(e);
|
|
62
|
+
// }
|
|
63
|
+
// expect(result).not.toBe(null);
|
|
64
|
+
// });
|
|
65
65
|
|
|
66
66
|
// it("reapys 1USDC to Aave lending pool", async () => {
|
|
67
67
|
// let result;
|
|
@@ -98,4 +98,31 @@ describe("pool", () => {
|
|
|
98
98
|
// }
|
|
99
99
|
// expect(result).not.toBe(null);
|
|
100
100
|
// });
|
|
101
|
+
|
|
102
|
+
// it("gets Aave assets for underlying", async () => {
|
|
103
|
+
// let result;
|
|
104
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
105
|
+
// try {
|
|
106
|
+
// result = await getAaveAssetsForUnderlying(pool, Dapp.AAVEV3, [
|
|
107
|
+
// USDC,
|
|
108
|
+
// WETH
|
|
109
|
+
// ]);
|
|
110
|
+
// console.log(result);
|
|
111
|
+
// } catch (e) {
|
|
112
|
+
// console.log(e);
|
|
113
|
+
// }
|
|
114
|
+
// expect(result).not.toBe(null);
|
|
115
|
+
// });
|
|
116
|
+
|
|
117
|
+
it("claims rewards from AaveV3", async () => {
|
|
118
|
+
let result;
|
|
119
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
120
|
+
try {
|
|
121
|
+
result = await pool.harvestAaveV3Rewards([USDC, WETH, WBTC], OP);
|
|
122
|
+
console.log(result);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.log(e);
|
|
125
|
+
}
|
|
126
|
+
expect(result).not.toBe(null);
|
|
127
|
+
});
|
|
101
128
|
});
|
package/src/test/constants.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//Polygon
|
|
2
2
|
// export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
3
|
-
//
|
|
3
|
+
// export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
4
4
|
// export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
5
5
|
// export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
6
6
|
// export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
|
|
@@ -25,5 +25,6 @@ export const USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
|
|
|
25
25
|
export const DAI = "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1";
|
|
26
26
|
export const USDy = "0x1ec50880101022c11530a069690f5446d1464592";
|
|
27
27
|
export const WBTC = "0x68f180fcCe6836688e9084f035309E29Bf0A2095";
|
|
28
|
+
export const OP = "4200000000000000000000000000000000000042";
|
|
28
29
|
|
|
29
30
|
export const TEST_POOL = "TEST_POOL";
|
package/src/test/wallet.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { ethers } from "ethers";
|
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
4
|
require("dotenv").config();
|
|
5
5
|
|
|
6
|
-
// const provider = new ethers.providers.JsonRpcProvider(
|
|
7
|
-
// `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
|
|
8
|
-
// );
|
|
9
|
-
|
|
10
6
|
const provider = new ethers.providers.JsonRpcProvider(
|
|
11
|
-
`https://
|
|
7
|
+
`https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
|
|
12
8
|
);
|
|
13
9
|
|
|
10
|
+
// const provider = new ethers.providers.JsonRpcProvider(
|
|
11
|
+
// `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
|
|
12
|
+
// );
|
|
13
|
+
|
|
14
14
|
export const wallet = new ethers.Wallet(
|
|
15
15
|
process.env.PRIVATE_KEY as string,
|
|
16
16
|
provider
|