@gearbox-protocol/sdk 3.0.0-next.236 → 3.0.0-next.238
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/contracts/index.sol +4 -0
- package/lib/apy/index.d.ts +0 -1
- package/lib/apy/index.js +0 -1
- package/lib/core/creditAccount.d.ts +5 -5
- package/lib/core/creditAccount.js +11 -13
- package/lib/core/creditManager.d.ts +16 -0
- package/lib/core/creditManager.js +154 -0
- package/lib/core/pool.d.ts +6 -0
- package/lib/core/pool.js +11 -0
- package/lib/core/protocols.js +4 -0
- package/lib/core/{rewardClaimer.d.ts → rewardClaimer/index.d.ts} +10 -5
- package/lib/core/rewardClaimer/index.js +34 -0
- package/lib/core/{rewardConvex.d.ts → rewardClaimer/rewardConvex.d.ts} +3 -3
- package/lib/core/{rewardConvex.js → rewardClaimer/rewardConvex.js} +7 -8
- package/lib/core/{rewardConvex.spec.js → rewardClaimer/rewardConvex.spec.js} +1 -2
- package/lib/core/rewardClaimer/stakingRewards.d.ts +34 -0
- package/lib/core/rewardClaimer/stakingRewards.js +133 -0
- package/lib/core/trade.d.ts +38 -0
- package/lib/core/trade.js +110 -0
- package/lib/gearboxRewards/api.d.ts +2 -8
- package/lib/gearboxRewards/api.js +15 -31
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/parsers/ERC20Parser.d.ts +8 -0
- package/lib/parsers/ERC20Parser.js +36 -0
- package/lib/parsers/aaveV2LendingPoolAdapterParser.d.ts +8 -0
- package/lib/parsers/aaveV2LendingPoolAdapterParser.js +21 -0
- package/lib/parsers/aaveV2WrappedATokenAdapterParser.d.ts +8 -0
- package/lib/parsers/aaveV2WrappedATokenAdapterParser.js +21 -0
- package/lib/parsers/abstractParser.d.ts +30 -0
- package/lib/parsers/abstractParser.js +61 -0
- package/lib/parsers/balancerV2VaultParser.d.ts +8 -0
- package/lib/parsers/balancerV2VaultParser.js +32 -0
- package/lib/parsers/compoundV2CTokenAdapterParser.d.ts +8 -0
- package/lib/parsers/compoundV2CTokenAdapterParser.js +21 -0
- package/lib/parsers/convexBaseRewardPoolAdapterParser.d.ts +10 -0
- package/lib/parsers/convexBaseRewardPoolAdapterParser.js +50 -0
- package/lib/parsers/convexBoosterAdapterParser.d.ts +10 -0
- package/lib/parsers/convexBoosterAdapterParser.js +44 -0
- package/lib/parsers/convextRewardPoolParser.d.ts +8 -0
- package/lib/parsers/convextRewardPoolParser.js +21 -0
- package/lib/parsers/creditFacadeParser.d.ts +11 -0
- package/lib/parsers/creditFacadeParser.js +84 -0
- package/lib/parsers/creditManagerParser.d.ts +7 -0
- package/lib/parsers/creditManagerParser.js +22 -0
- package/lib/parsers/curveAdapterParser.d.ts +13 -0
- package/lib/parsers/curveAdapterParser.js +124 -0
- package/lib/parsers/erc626AdapterParser.d.ts +8 -0
- package/lib/parsers/erc626AdapterParser.js +21 -0
- package/lib/parsers/iParser.d.ts +6 -0
- package/lib/parsers/iParser.js +2 -0
- package/lib/parsers/lidoAdapterParser.d.ts +8 -0
- package/lib/parsers/lidoAdapterParser.js +29 -0
- package/lib/parsers/lidoSTETHParser.d.ts +8 -0
- package/lib/parsers/lidoSTETHParser.js +36 -0
- package/lib/parsers/priceOracleParser.d.ts +7 -0
- package/lib/parsers/priceOracleParser.js +23 -0
- package/lib/parsers/stakingRewardsAdapterParser.d.ts +10 -0
- package/lib/parsers/stakingRewardsAdapterParser.js +35 -0
- package/lib/parsers/txParser.d.ts +37 -0
- package/lib/parsers/txParser.js +174 -0
- package/lib/parsers/uniV2AdapterParser.d.ts +8 -0
- package/lib/parsers/uniV2AdapterParser.js +51 -0
- package/lib/parsers/uniV2AdapterParser.spec.d.ts +1 -0
- package/lib/parsers/uniV2AdapterParser.spec.js +59 -0
- package/lib/parsers/uniV3AdapterParser.d.ts +10 -0
- package/lib/parsers/uniV3AdapterParser.js +101 -0
- package/lib/parsers/uniV3AdapterParser.spec.d.ts +1 -0
- package/lib/parsers/uniV3AdapterParser.spec.js +96 -0
- package/lib/parsers/wstETHAdapterParser.d.ts +8 -0
- package/lib/parsers/wstETHAdapterParser.js +50 -0
- package/lib/parsers/wstETHAdapterParser.spec.d.ts +1 -0
- package/lib/parsers/wstETHAdapterParser.spec.js +37 -0
- package/lib/parsers/yearnAdapterParser.spec.d.ts +1 -0
- package/lib/parsers/yearnAdapterParser.spec.js +54 -0
- package/lib/parsers/yearnV2AdapterParser.d.ts +8 -0
- package/lib/parsers/yearnV2AdapterParser.js +57 -0
- package/lib/pathfinder/balancerVault.d.ts +33 -0
- package/lib/pathfinder/balancerVault.js +59 -0
- package/lib/pathfinder/core.d.ts +14 -0
- package/lib/pathfinder/core.js +7 -0
- package/lib/pathfinder/index.d.ts +3 -0
- package/lib/pathfinder/index.js +3 -0
- package/lib/pathfinder/pathOptions.d.ts +16 -0
- package/lib/pathfinder/pathOptions.js +93 -0
- package/lib/pathfinder/pathOptions.spec.d.ts +1 -0
- package/lib/pathfinder/pathOptions.spec.js +138 -0
- package/lib/pathfinder/pathfinder.d.ts +72 -0
- package/lib/pathfinder/pathfinder.js +176 -0
- package/lib/pathfinder/pathfinder.spec.d.ts +1 -0
- package/lib/pathfinder/pathfinder.spec.js +52 -0
- package/lib/pathfinder/utils.d.ts +34 -0
- package/lib/pathfinder/utils.js +186 -0
- package/lib/payload/creditAccount.d.ts +1 -4
- package/lib/payload/pool.d.ts +6 -0
- package/lib/redstone/api.d.ts +0 -5
- package/lib/redstone/api.js +29 -94
- package/lib/types/IERC20ZapperDeposits.d.ts +80 -0
- package/lib/types/IERC20ZapperDeposits.js +35 -0
- package/lib/types/IStakingRewardsAdapter.d.ts +197 -0
- package/lib/types/IStakingRewardsAdapter.js +139 -0
- package/lib/types/IZapper.d.ts +38 -0
- package/lib/types/IZapper.js +17 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +6 -6
- package/lib/core/rewardClaimer.js +0 -10
- /package/lib/{apy/auraAPY.d.ts → core/rewardClaimer/aura.d.ts} +0 -0
- /package/lib/{apy/auraAPY.js → core/rewardClaimer/aura.js} +0 -0
- /package/lib/{apy → core/rewardClaimer}/auraAbi.d.ts +0 -0
- /package/lib/{apy → core/rewardClaimer}/auraAbi.js +0 -0
- /package/lib/{apy/convexAPY.d.ts → core/rewardClaimer/convex.d.ts} +0 -0
- /package/lib/{apy/convexAPY.js → core/rewardClaimer/convex.js} +0 -0
- /package/lib/core/{rewardConvex.spec.d.ts → rewardClaimer/rewardConvex.spec.d.ts} +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const uniV3AdapterParser_1 = require("./uniV3AdapterParser");
|
|
8
|
+
const pathToUniV3Path = (path) => {
|
|
9
|
+
const pathWithFees = [];
|
|
10
|
+
const types = [];
|
|
11
|
+
path.forEach((p, num) => {
|
|
12
|
+
pathWithFees.push(p);
|
|
13
|
+
types.push("address");
|
|
14
|
+
if (num !== path.length - 1) {
|
|
15
|
+
pathWithFees.push(3000);
|
|
16
|
+
types.push("uint24");
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return (0, viem_1.encodePacked)(types, pathWithFees);
|
|
20
|
+
};
|
|
21
|
+
describe("UniswapV3AdapterParser test", () => {
|
|
22
|
+
it("swap functions works well", () => {
|
|
23
|
+
let parser = new uniV3AdapterParser_1.UniswapV3AdapterParser("UNISWAP_V3_ROUTER", false);
|
|
24
|
+
let parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
25
|
+
abi: types_1.iUniswapV3AdapterAbi,
|
|
26
|
+
functionName: "exactInput",
|
|
27
|
+
args: [
|
|
28
|
+
{
|
|
29
|
+
path: pathToUniV3Path([
|
|
30
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.AAVE,
|
|
31
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.LINK,
|
|
32
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.USDC,
|
|
33
|
+
]),
|
|
34
|
+
recipient: sdk_gov_1.DUMB_ADDRESS,
|
|
35
|
+
deadline: 1232131n,
|
|
36
|
+
amountIn: sdk_gov_1.WAD * 12399n,
|
|
37
|
+
amountOutMinimum: BigInt(1e6) * 122n,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
}));
|
|
41
|
+
(0, chai_1.expect)(parsed).to.be.eq("UniswapV3Adapter[UNISWAP_V3_ROUTER].exactInput(amountIn: 12.39K [12399000000000000000000], amountOutMinimum: 122.00 [122000000], path: AAVE ==(fee: 3000)==> LINK ==(fee: 3000)==> USDC", "Incorrect parse swapExactTokensForTokens");
|
|
42
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
43
|
+
abi: types_1.iUniswapV3AdapterAbi,
|
|
44
|
+
functionName: "exactDiffInput",
|
|
45
|
+
args: [
|
|
46
|
+
{
|
|
47
|
+
path: pathToUniV3Path([
|
|
48
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.AAVE,
|
|
49
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.LINK,
|
|
50
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.USDC,
|
|
51
|
+
]),
|
|
52
|
+
leftoverAmount: sdk_gov_1.WAD * 12399n,
|
|
53
|
+
rateMinRAY: sdk_gov_1.RAY * 1200n,
|
|
54
|
+
deadline: 1232131n,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
}));
|
|
58
|
+
(0, chai_1.expect)(parsed).to.be.eq("UniswapV3Adapter[UNISWAP_V3_ROUTER].exactDiffInput(leftoverAmount: 12.39K [12399000000000000000000], rate: 1.20K, path: AAVE ==(fee: 3000)==> LINK ==(fee: 3000)==> USDC", "Incorrect parse swapExactTokensForTokens");
|
|
59
|
+
// parsed = parser.parse(
|
|
60
|
+
// ifc.encodeFunctionData("exactOutputSingle", [
|
|
61
|
+
// {
|
|
62
|
+
// tokenIn: tokenDataByNetwork.Arbitrum["1INCH"],
|
|
63
|
+
// tokenOut: tokenDataByNetwork.Arbitrum.USDC,
|
|
64
|
+
// fee: 10000,
|
|
65
|
+
// recipient: DUMB_ADDRESS,
|
|
66
|
+
// deadline: 12300,
|
|
67
|
+
// amountInMaximum: (WAD * 149n) / 1000n,
|
|
68
|
+
// amountOut: 102e6,
|
|
69
|
+
// sqrtPriceLimitX96: 0,
|
|
70
|
+
// },
|
|
71
|
+
// ]),
|
|
72
|
+
// );
|
|
73
|
+
// expect(parsed).to.be.eq(
|
|
74
|
+
// "UniswapV3Adapter[UNISWAP_V3_ROUTER].exactOutputSingle(amountInMaximum: 0.14 [149000000000000000], amountOut: 102.00 [102000000], path: 1INCH ==(fee: 10000)==> USDC)",
|
|
75
|
+
// "Incorrect parse swapExactTokensForTokens",
|
|
76
|
+
// );
|
|
77
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
78
|
+
abi: types_1.iUniswapV3AdapterAbi,
|
|
79
|
+
functionName: "exactOutput",
|
|
80
|
+
args: [
|
|
81
|
+
{
|
|
82
|
+
path: pathToUniV3Path([
|
|
83
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.AAVE,
|
|
84
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.LINK,
|
|
85
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.USDC,
|
|
86
|
+
]),
|
|
87
|
+
recipient: sdk_gov_1.DUMB_ADDRESS,
|
|
88
|
+
deadline: 1232131n,
|
|
89
|
+
amountInMaximum: 123000000n,
|
|
90
|
+
amountOut: sdk_gov_1.WAD * 122n,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
}));
|
|
94
|
+
(0, chai_1.expect)(parsed).to.be.eq("UniswapV3Adapter[UNISWAP_V3_ROUTER].exactOutput(amountInMaximum: 123.00 [123000000], amountOut: 122.00 [122000000000000000000], path: USDC ==(fee: 3000)==> LINK ==(fee: 3000)==> AAVE", "Incorrect parse swapExactTokensForTokens");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SupportedContract } from "@gearbox-protocol/sdk-gov";
|
|
2
|
+
import { Address } from "viem";
|
|
3
|
+
import { AbstractParser } from "./abstractParser";
|
|
4
|
+
import { IParser } from "./iParser";
|
|
5
|
+
export declare class WstETHAdapterParser extends AbstractParser implements IParser {
|
|
6
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
7
|
+
parse(calldata: Address): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WstETHAdapterParser = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const abstractParser_1 = require("./abstractParser");
|
|
7
|
+
class WstETHAdapterParser extends abstractParser_1.AbstractParser {
|
|
8
|
+
constructor(contract, isContract) {
|
|
9
|
+
super(contract);
|
|
10
|
+
this.abi = !isContract ? types_1.iwstEthv1AdapterAbi : types_1.iwstEthAbi;
|
|
11
|
+
if (!isContract)
|
|
12
|
+
this.adapterName = "wstETHAdapter";
|
|
13
|
+
}
|
|
14
|
+
parse(calldata) {
|
|
15
|
+
const { functionData, functionName } = this.parseSelector(calldata);
|
|
16
|
+
switch (functionData.functionName) {
|
|
17
|
+
case "wrap": {
|
|
18
|
+
const [amount] = functionData.args || [];
|
|
19
|
+
return `${functionName}(amount: ${this.formatBN(amount, "STETH")})`;
|
|
20
|
+
}
|
|
21
|
+
case "wrapDiff": {
|
|
22
|
+
const [leftoverAmount] = functionData.args || [];
|
|
23
|
+
return `${functionName}(leftoverAmount: ${this.formatBN(leftoverAmount, "STETH")})`;
|
|
24
|
+
}
|
|
25
|
+
case "unwrap": {
|
|
26
|
+
const [amount] = functionData.args || [];
|
|
27
|
+
return `${functionName}(amount: ${this.formatBN(amount, "wstETH")})`;
|
|
28
|
+
}
|
|
29
|
+
case "unwrapDiff": {
|
|
30
|
+
const [leftoverAmount] = functionData.args || [];
|
|
31
|
+
return `${functionName}(leftoverAmount: ${this.formatBN(leftoverAmount, "STETH")})`;
|
|
32
|
+
}
|
|
33
|
+
case "balanceOf": {
|
|
34
|
+
const [address] = functionData.args || [];
|
|
35
|
+
return `${functionName}(${address})`;
|
|
36
|
+
}
|
|
37
|
+
case "allowance": {
|
|
38
|
+
const [account, to] = functionData.args || [];
|
|
39
|
+
return `${functionName}(account: ${account}, to: ${to})`;
|
|
40
|
+
}
|
|
41
|
+
case "approve": {
|
|
42
|
+
const [spender, amount] = functionData.args || [];
|
|
43
|
+
return `${functionName}(${spender}, [${(0, sdk_gov_1.toBigInt)(amount).toString()}])`;
|
|
44
|
+
}
|
|
45
|
+
default:
|
|
46
|
+
return this.reportUnknownFragment(this.adapterName || this.contract, functionName, calldata);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.WstETHAdapterParser = WstETHAdapterParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const wstETHAdapterParser_1 = require("./wstETHAdapterParser");
|
|
8
|
+
describe("WstETHAdapterParser test", () => {
|
|
9
|
+
it("wrap / unwrap function works well", () => {
|
|
10
|
+
let parser = new wstETHAdapterParser_1.WstETHAdapterParser("LIDO_WSTETH", false);
|
|
11
|
+
let parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
12
|
+
abi: types_1.iwstEthv1AdapterAbi,
|
|
13
|
+
functionName: "wrapDiff",
|
|
14
|
+
args: [sdk_gov_1.WAD * 1020n],
|
|
15
|
+
}));
|
|
16
|
+
(0, chai_1.expect)(parsed).to.be.eq("wstETHAdapter[LIDO_WSTETH].wrapDiff(leftoverAmount: 1.02K [1020000000000000000000])", "Incorrect parse wrapDiff()");
|
|
17
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
18
|
+
abi: types_1.iwstEthv1AdapterAbi,
|
|
19
|
+
functionName: "unwrapDiff",
|
|
20
|
+
args: [sdk_gov_1.WAD * 1020n],
|
|
21
|
+
}));
|
|
22
|
+
(0, chai_1.expect)(parsed).to.be.eq("wstETHAdapter[LIDO_WSTETH].unwrapDiff(leftoverAmount: 1.02K [1020000000000000000000])", "Incorrect parse unwrapDiff()");
|
|
23
|
+
parser = new wstETHAdapterParser_1.WstETHAdapterParser("LIDO_WSTETH", true);
|
|
24
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
25
|
+
abi: types_1.iwstEthv1AdapterAbi,
|
|
26
|
+
functionName: "wrap",
|
|
27
|
+
args: [sdk_gov_1.WAD * 1020n],
|
|
28
|
+
}));
|
|
29
|
+
(0, chai_1.expect)(parsed).to.be.eq("Contract[LIDO_WSTETH].wrap(amount: 1.02K [1020000000000000000000])", "Incorrect parse wrap(amount)");
|
|
30
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
31
|
+
abi: types_1.iwstEthv1AdapterAbi,
|
|
32
|
+
functionName: "unwrap",
|
|
33
|
+
args: [sdk_gov_1.WAD * 1020n],
|
|
34
|
+
}));
|
|
35
|
+
(0, chai_1.expect)(parsed).to.be.eq("Contract[LIDO_WSTETH].unwrap(amount: 1.02K [1020000000000000000000])", "Incorrect parse unwrap(amount)");
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const yearnV2AdapterParser_1 = require("./yearnV2AdapterParser");
|
|
8
|
+
describe("YearnV2AdapterParser test", () => {
|
|
9
|
+
it("deposit / withdraw functions works well", () => {
|
|
10
|
+
const parser = new yearnV2AdapterParser_1.YearnV2AdapterParser("YEARN_CURVE_STETH_VAULT", false);
|
|
11
|
+
let parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
12
|
+
abi: types_1.iYearnV2AdapterAbi,
|
|
13
|
+
functionName: "depositDiff",
|
|
14
|
+
args: [sdk_gov_1.WAD * 19000n],
|
|
15
|
+
}));
|
|
16
|
+
(0, chai_1.expect)(parsed).to.be.eq("YearnV2Adapter[YEARN_CURVE_STETH_VAULT].depositDiff(leftoverAmount: 19.00K [19000000000000000000000])", "Incorrect parse depositDiff");
|
|
17
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
18
|
+
abi: types_1.iYearnV2AdapterAbi,
|
|
19
|
+
functionName: "deposit",
|
|
20
|
+
args: [sdk_gov_1.WAD * 19000n],
|
|
21
|
+
}));
|
|
22
|
+
(0, chai_1.expect)(parsed).to.be.eq("YearnV2Adapter[YEARN_CURVE_STETH_VAULT].deposit(amount: 19.00K [19000000000000000000000])", "Incorrect parse deposit(amount)");
|
|
23
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
24
|
+
abi: types_1.iYearnV2AdapterAbi,
|
|
25
|
+
functionName: "deposit",
|
|
26
|
+
args: [sdk_gov_1.WAD * 19000n, sdk_gov_1.DUMB_ADDRESS],
|
|
27
|
+
}));
|
|
28
|
+
(0, chai_1.expect)(parsed).to.be.eq(`YearnV2Adapter[YEARN_CURVE_STETH_VAULT].deposit(amount: 19.00K [19000000000000000000000], address: ${sdk_gov_1.DUMB_ADDRESS})`, "Incorrect parse deposit(amount,address)");
|
|
29
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
30
|
+
abi: types_1.iYearnV2AdapterAbi,
|
|
31
|
+
functionName: "withdrawDiff",
|
|
32
|
+
args: [sdk_gov_1.WAD * 19000n],
|
|
33
|
+
}));
|
|
34
|
+
(0, chai_1.expect)(parsed).to.be.eq("YearnV2Adapter[YEARN_CURVE_STETH_VAULT].withdrawDiff(leftoverAmount: 19.00K [19000000000000000000000])", "Incorrect parse withdrawDiff");
|
|
35
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
36
|
+
abi: types_1.iYearnV2AdapterAbi,
|
|
37
|
+
functionName: "withdraw",
|
|
38
|
+
args: [sdk_gov_1.WAD * 19000n],
|
|
39
|
+
}));
|
|
40
|
+
(0, chai_1.expect)(parsed).to.be.eq("YearnV2Adapter[YEARN_CURVE_STETH_VAULT].withdraw(amount: 19.00K [19000000000000000000000])", "Incorrect parse withdraw(amount)");
|
|
41
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
42
|
+
abi: types_1.iYearnV2AdapterAbi,
|
|
43
|
+
functionName: "withdraw",
|
|
44
|
+
args: [sdk_gov_1.WAD * 19000n, sdk_gov_1.DUMB_ADDRESS],
|
|
45
|
+
}));
|
|
46
|
+
(0, chai_1.expect)(parsed).to.be.eq(`YearnV2Adapter[YEARN_CURVE_STETH_VAULT].withdraw(amount: 19.00K [19000000000000000000000], address: ${sdk_gov_1.DUMB_ADDRESS})`, "Incorrect parse withdraw(amount,address)");
|
|
47
|
+
parsed = parser.parse((0, viem_1.encodeFunctionData)({
|
|
48
|
+
abi: types_1.iYearnV2AdapterAbi,
|
|
49
|
+
functionName: "withdraw",
|
|
50
|
+
args: [sdk_gov_1.WAD * 19000n, sdk_gov_1.DUMB_ADDRESS, 555n],
|
|
51
|
+
}));
|
|
52
|
+
(0, chai_1.expect)(parsed).to.be.eq(`YearnV2Adapter[YEARN_CURVE_STETH_VAULT].withdraw(amount: 19.00K [19000000000000000000000], address: ${sdk_gov_1.DUMB_ADDRESS}, maxLoss: 555)`, "Incorrect parse withdraw(amount,address,uint256)");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SupportedContract } from "@gearbox-protocol/sdk-gov";
|
|
2
|
+
import { Address } from "viem";
|
|
3
|
+
import { AbstractParser } from "./abstractParser";
|
|
4
|
+
import { IParser } from "./iParser";
|
|
5
|
+
export declare class YearnV2AdapterParser extends AbstractParser implements IParser {
|
|
6
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
7
|
+
parse(calldata: Address): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.YearnV2AdapterParser = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const abstractParser_1 = require("./abstractParser");
|
|
7
|
+
class YearnV2AdapterParser extends abstractParser_1.AbstractParser {
|
|
8
|
+
constructor(contract, isContract) {
|
|
9
|
+
super(contract);
|
|
10
|
+
this.abi = types_1.iYearnV2AdapterAbi;
|
|
11
|
+
if (!isContract)
|
|
12
|
+
this.adapterName = "YearnV2Adapter";
|
|
13
|
+
}
|
|
14
|
+
parse(calldata) {
|
|
15
|
+
const { functionName, functionData } = this.parseSelector(calldata);
|
|
16
|
+
switch (functionData.functionName) {
|
|
17
|
+
case "deposit":
|
|
18
|
+
case "withdraw":
|
|
19
|
+
case "withdraw(uint256,address,uint256)": {
|
|
20
|
+
const [amount, address, maxLoss] = functionData.args || [];
|
|
21
|
+
const yvSym = this.tokenSymbol(sdk_gov_1.contractsByNetwork.Mainnet[this.contract]);
|
|
22
|
+
const amountStr = amount
|
|
23
|
+
? `amount: ${this.formatBN(amount, yvSym)}`
|
|
24
|
+
: "";
|
|
25
|
+
const addressStr = address ? `, address: ${address}` : "";
|
|
26
|
+
const maxLossStr = maxLoss ? `, maxLoss: ${maxLoss}` : "";
|
|
27
|
+
return `${functionName}(${amountStr}${addressStr}${maxLossStr})`;
|
|
28
|
+
}
|
|
29
|
+
case "depositDiff": {
|
|
30
|
+
const [leftoverAmount] = functionData.args || [];
|
|
31
|
+
const yvSym = this.tokenSymbol(sdk_gov_1.contractsByNetwork.Mainnet[this.contract]);
|
|
32
|
+
const leftoverAmountStr = this.formatBN(leftoverAmount, yvSym);
|
|
33
|
+
return `${functionName}(leftoverAmount: ${leftoverAmountStr})`;
|
|
34
|
+
}
|
|
35
|
+
case "withdrawDiff": {
|
|
36
|
+
const [leftoverAmount] = functionData.args || [];
|
|
37
|
+
const yvSym = this.tokenSymbol(sdk_gov_1.contractsByNetwork.Mainnet[this.contract]);
|
|
38
|
+
const leftoverAmountStr = this.formatBN(leftoverAmount, yvSym);
|
|
39
|
+
return `${functionName}(leftoverAmount: ${leftoverAmountStr})`;
|
|
40
|
+
}
|
|
41
|
+
case "pricePerShare": {
|
|
42
|
+
return `${functionName}()`;
|
|
43
|
+
}
|
|
44
|
+
case "balanceOf": {
|
|
45
|
+
const [address] = functionData.args || [];
|
|
46
|
+
return `${functionName}(${address})`;
|
|
47
|
+
}
|
|
48
|
+
case "allowance": {
|
|
49
|
+
const [account, to] = functionData.args || [];
|
|
50
|
+
return `${functionName}(account: ${account}, to: ${to})`;
|
|
51
|
+
}
|
|
52
|
+
default:
|
|
53
|
+
return this.reportUnknownFragment(this.adapterName || this.contract, functionName, calldata);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.YearnV2AdapterParser = YearnV2AdapterParser;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare enum PoolSpecialization {
|
|
2
|
+
GeneralPool = 0,
|
|
3
|
+
MinimalSwapInfoPool = 1,
|
|
4
|
+
TwoTokenPool = 2
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Splits a poolId into its components, i.e. pool address, pool specialization and its nonce
|
|
8
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
9
|
+
* @returns an object with the decomposed poolId
|
|
10
|
+
*/
|
|
11
|
+
export declare const splitPoolId: (poolId: string) => {
|
|
12
|
+
address: string;
|
|
13
|
+
specialization: PoolSpecialization;
|
|
14
|
+
nonce: bigint;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Extracts a pool's address from its poolId
|
|
18
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
19
|
+
* @returns the pool's address
|
|
20
|
+
*/
|
|
21
|
+
export declare const getPoolAddress: (poolId: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts a pool's specialization from its poolId
|
|
24
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
25
|
+
* @returns the pool's specialization
|
|
26
|
+
*/
|
|
27
|
+
export declare const getPoolSpecialization: (poolId: string) => PoolSpecialization;
|
|
28
|
+
/**
|
|
29
|
+
* Extracts a pool's nonce from its poolId
|
|
30
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
31
|
+
* @returns the pool's nonce
|
|
32
|
+
*/
|
|
33
|
+
export declare const getPoolNonce: (poolId: string) => bigint;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPoolNonce = exports.getPoolSpecialization = exports.getPoolAddress = exports.splitPoolId = exports.PoolSpecialization = void 0;
|
|
4
|
+
var PoolSpecialization;
|
|
5
|
+
(function (PoolSpecialization) {
|
|
6
|
+
PoolSpecialization[PoolSpecialization["GeneralPool"] = 0] = "GeneralPool";
|
|
7
|
+
PoolSpecialization[PoolSpecialization["MinimalSwapInfoPool"] = 1] = "MinimalSwapInfoPool";
|
|
8
|
+
PoolSpecialization[PoolSpecialization["TwoTokenPool"] = 2] = "TwoTokenPool";
|
|
9
|
+
})(PoolSpecialization = exports.PoolSpecialization || (exports.PoolSpecialization = {}));
|
|
10
|
+
/**
|
|
11
|
+
* Splits a poolId into its components, i.e. pool address, pool specialization and its nonce
|
|
12
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
13
|
+
* @returns an object with the decomposed poolId
|
|
14
|
+
*/
|
|
15
|
+
const splitPoolId = (poolId) => {
|
|
16
|
+
return {
|
|
17
|
+
address: (0, exports.getPoolAddress)(poolId),
|
|
18
|
+
specialization: (0, exports.getPoolSpecialization)(poolId),
|
|
19
|
+
nonce: (0, exports.getPoolNonce)(poolId),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.splitPoolId = splitPoolId;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts a pool's address from its poolId
|
|
25
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
26
|
+
* @returns the pool's address
|
|
27
|
+
*/
|
|
28
|
+
const getPoolAddress = (poolId) => {
|
|
29
|
+
if (poolId.length !== 66)
|
|
30
|
+
throw new Error("Invalid poolId length");
|
|
31
|
+
return poolId.slice(0, 42);
|
|
32
|
+
};
|
|
33
|
+
exports.getPoolAddress = getPoolAddress;
|
|
34
|
+
/**
|
|
35
|
+
* Extracts a pool's specialization from its poolId
|
|
36
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
37
|
+
* @returns the pool's specialization
|
|
38
|
+
*/
|
|
39
|
+
const getPoolSpecialization = (poolId) => {
|
|
40
|
+
if (poolId.length !== 66)
|
|
41
|
+
throw new Error("Invalid poolId length");
|
|
42
|
+
// Only have 3 pool specializations so we can just pull the relevant character
|
|
43
|
+
const specializationCode = parseInt(poolId[45], 10);
|
|
44
|
+
if (specializationCode >= 3)
|
|
45
|
+
throw new Error("Invalid pool specialization");
|
|
46
|
+
return specializationCode;
|
|
47
|
+
};
|
|
48
|
+
exports.getPoolSpecialization = getPoolSpecialization;
|
|
49
|
+
/**
|
|
50
|
+
* Extracts a pool's nonce from its poolId
|
|
51
|
+
* @param poolId - a bytes32 string of the pool's ID
|
|
52
|
+
* @returns the pool's nonce
|
|
53
|
+
*/
|
|
54
|
+
const getPoolNonce = (poolId) => {
|
|
55
|
+
if (poolId.length !== 66)
|
|
56
|
+
throw new Error("Invalid poolId length");
|
|
57
|
+
return BigInt(`0x${poolId.slice(46)}`);
|
|
58
|
+
};
|
|
59
|
+
exports.getPoolNonce = getPoolNonce;
|
package/lib/pathfinder/core.d.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { Address } from "viem";
|
|
2
|
+
export declare enum SwapOperation {
|
|
3
|
+
EXACT_INPUT = 0,
|
|
4
|
+
EXACT_INPUT_ALL = 1,
|
|
5
|
+
EXACT_OUTPUT = 2
|
|
6
|
+
}
|
|
2
7
|
export interface MultiCall {
|
|
3
8
|
target: Address;
|
|
4
9
|
callData: Address;
|
|
5
10
|
}
|
|
11
|
+
export interface SwapTask {
|
|
12
|
+
swapOperation: number;
|
|
13
|
+
creditAccount: Address;
|
|
14
|
+
tokenIn: Address;
|
|
15
|
+
tokenOut: Address;
|
|
16
|
+
connectors: Address[];
|
|
17
|
+
amount: bigint;
|
|
18
|
+
leftoverAmount: bigint;
|
|
19
|
+
}
|
|
6
20
|
export interface PathFinderResult {
|
|
7
21
|
amount: bigint;
|
|
8
22
|
minAmount: bigint;
|
package/lib/pathfinder/core.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapOperation = void 0;
|
|
4
|
+
var SwapOperation;
|
|
5
|
+
(function (SwapOperation) {
|
|
6
|
+
SwapOperation[SwapOperation["EXACT_INPUT"] = 0] = "EXACT_INPUT";
|
|
7
|
+
SwapOperation[SwapOperation["EXACT_INPUT_ALL"] = 1] = "EXACT_INPUT_ALL";
|
|
8
|
+
SwapOperation[SwapOperation["EXACT_OUTPUT"] = 2] = "EXACT_OUTPUT";
|
|
9
|
+
})(SwapOperation = exports.SwapOperation || (exports.SwapOperation = {}));
|
package/lib/pathfinder/index.js
CHANGED
|
@@ -15,3 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./core"), exports);
|
|
18
|
+
__exportStar(require("./pathfinder"), exports);
|
|
19
|
+
__exportStar(require("./pathOptions"), exports);
|
|
20
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BalancerLPToken, CurveLPToken, NetworkType } from "@gearbox-protocol/sdk-gov";
|
|
2
|
+
import { Address } from "viem";
|
|
3
|
+
import { CaTokenBalance } from "../payload/creditAccount";
|
|
4
|
+
export interface PathOption {
|
|
5
|
+
target: Address;
|
|
6
|
+
option: number;
|
|
7
|
+
totalOptions: number;
|
|
8
|
+
}
|
|
9
|
+
export type PathOptionSerie = Array<PathOption>;
|
|
10
|
+
export type BalanceInterface = Pick<CaTokenBalance, "balance">;
|
|
11
|
+
export declare class PathOptionFactory {
|
|
12
|
+
static generatePathOptions(balances: Record<Address, BalanceInterface>, loopsInTx: number, network: NetworkType): Array<PathOptionSerie>;
|
|
13
|
+
static getCurvePools(balances: Record<Address, BalanceInterface>): Array<CurveLPToken>;
|
|
14
|
+
static getBalancerPools(balances: Record<Address, BalanceInterface>): Array<BalancerLPToken>;
|
|
15
|
+
static next(path: PathOptionSerie): PathOptionSerie;
|
|
16
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PathOptionFactory = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const aura_1 = require("@gearbox-protocol/sdk-gov/lib/tokens/aura");
|
|
6
|
+
class PathOptionFactory {
|
|
7
|
+
static generatePathOptions(balances, loopsInTx, network) {
|
|
8
|
+
const curvePools = PathOptionFactory.getCurvePools(balances);
|
|
9
|
+
const balancerPools = PathOptionFactory.getBalancerPools(balances);
|
|
10
|
+
const curveInitPO = curvePools.map(symbol => {
|
|
11
|
+
return {
|
|
12
|
+
target: sdk_gov_1.tokenDataByNetwork[network][symbol],
|
|
13
|
+
option: 0,
|
|
14
|
+
totalOptions: sdk_gov_1.contractParams[sdk_gov_1.curveTokens[symbol].pool]
|
|
15
|
+
.tokens.length,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
const balancerInitPO = balancerPools.map(symbol => {
|
|
19
|
+
return {
|
|
20
|
+
target: sdk_gov_1.tokenDataByNetwork[network][symbol],
|
|
21
|
+
option: 0,
|
|
22
|
+
totalOptions: sdk_gov_1.balancerLpTokens[symbol].underlying.length,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const initPO = [...curveInitPO, ...balancerInitPO];
|
|
26
|
+
const totalLoops = initPO.reduce((acc, item) => acc * item.totalOptions, 1);
|
|
27
|
+
const result = [];
|
|
28
|
+
let currentPo = [...initPO];
|
|
29
|
+
for (let i = 0; i < totalLoops; i++) {
|
|
30
|
+
if (i % loopsInTx === 0) {
|
|
31
|
+
result.push(currentPo);
|
|
32
|
+
}
|
|
33
|
+
if (i < totalLoops - 1) {
|
|
34
|
+
currentPo = PathOptionFactory.next(currentPo);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
static getCurvePools(balances) {
|
|
40
|
+
const nonZeroBalances = Object.entries(balances).filter(([, balance]) => balance.balance > 1);
|
|
41
|
+
const curvePools = nonZeroBalances
|
|
42
|
+
.map(([token]) => sdk_gov_1.tokenSymbolByAddress[token.toLowerCase()])
|
|
43
|
+
.filter(symbol => (0, sdk_gov_1.isCurveLPToken)(symbol));
|
|
44
|
+
const yearnCurveTokens = Object.entries(sdk_gov_1.yearnTokens)
|
|
45
|
+
.filter(([, data]) => (0, sdk_gov_1.isCurveLPToken)(data.underlying))
|
|
46
|
+
.map(([token]) => token);
|
|
47
|
+
const curvePoolsFromYearn = nonZeroBalances
|
|
48
|
+
.map(([token]) => sdk_gov_1.tokenSymbolByAddress[token.toLowerCase()])
|
|
49
|
+
.filter(symbol => yearnCurveTokens.includes(symbol))
|
|
50
|
+
.map(symbol => sdk_gov_1.yearnTokens[symbol].underlying);
|
|
51
|
+
const convexCurveTokens = Object.entries(sdk_gov_1.convexTokens)
|
|
52
|
+
.filter(([, data]) => (0, sdk_gov_1.isCurveLPToken)(data.underlying))
|
|
53
|
+
.map(([token]) => token);
|
|
54
|
+
const curvePoolsFromConvex = nonZeroBalances
|
|
55
|
+
.map(([token]) => sdk_gov_1.tokenSymbolByAddress[token.toLowerCase()])
|
|
56
|
+
.filter(symbol => convexCurveTokens.includes(symbol))
|
|
57
|
+
.map(symbol => sdk_gov_1.convexTokens[symbol].underlying);
|
|
58
|
+
const curveSet = new Set([
|
|
59
|
+
...curvePools,
|
|
60
|
+
...curvePoolsFromYearn,
|
|
61
|
+
...curvePoolsFromConvex,
|
|
62
|
+
]);
|
|
63
|
+
return Array.from(curveSet.values());
|
|
64
|
+
}
|
|
65
|
+
static getBalancerPools(balances) {
|
|
66
|
+
const nonZeroBalances = Object.entries(balances).filter(([, balance]) => balance.balance > 1);
|
|
67
|
+
const balancerPools = nonZeroBalances
|
|
68
|
+
.map(([token]) => sdk_gov_1.tokenSymbolByAddress[token.toLowerCase()])
|
|
69
|
+
.filter(symbol => (0, sdk_gov_1.isBalancerLPToken)(symbol));
|
|
70
|
+
const balancerAuraTokens = Object.entries(aura_1.auraTokens)
|
|
71
|
+
.filter(([, data]) => (0, sdk_gov_1.isBalancerLPToken)(data.underlying))
|
|
72
|
+
.map(([token]) => token);
|
|
73
|
+
const balancerTokensFromAura = nonZeroBalances
|
|
74
|
+
.map(([token]) => sdk_gov_1.tokenSymbolByAddress[token.toLowerCase()])
|
|
75
|
+
.filter(symbol => balancerAuraTokens.includes(symbol))
|
|
76
|
+
.map(symbol => aura_1.auraTokens[symbol].underlying);
|
|
77
|
+
const balancerSet = new Set([...balancerPools, ...balancerTokensFromAura]);
|
|
78
|
+
return Array.from(balancerSet.values());
|
|
79
|
+
}
|
|
80
|
+
static next(path) {
|
|
81
|
+
let newPath = [...path];
|
|
82
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
83
|
+
const po = { ...newPath[i] };
|
|
84
|
+
po.option++;
|
|
85
|
+
newPath[i] = po;
|
|
86
|
+
if (po.option < po.totalOptions)
|
|
87
|
+
return newPath;
|
|
88
|
+
po.option = 0;
|
|
89
|
+
}
|
|
90
|
+
throw new Error("Path options overflow");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.PathOptionFactory = PathOptionFactory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|