@gearbox-protocol/sdk 3.0.0-next.236 → 3.0.0-next.237
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/lib/core/creditAccount.d.ts +5 -5
- package/lib/core/creditAccount.js +11 -13
- package/lib/core/creditManager.d.ts +12 -0
- package/lib/core/creditManager.js +114 -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/rewardConvex.js +1 -1
- 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/txParser.d.ts +37 -0
- package/lib/parsers/txParser.js +170 -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/package.json +2 -2
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PathFinderUtils = exports.BALANCER_VAULT_ABI = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const balancerV2VaultParser_1 = require("../parsers/balancerV2VaultParser");
|
|
6
|
+
const curveAdapterParser_1 = require("../parsers/curveAdapterParser");
|
|
7
|
+
const lidoAdapterParser_1 = require("../parsers/lidoAdapterParser");
|
|
8
|
+
const txParser_1 = require("../parsers/txParser");
|
|
9
|
+
const uniV2AdapterParser_1 = require("../parsers/uniV2AdapterParser");
|
|
10
|
+
const uniV3AdapterParser_1 = require("../parsers/uniV3AdapterParser");
|
|
11
|
+
const types_1 = require("../types");
|
|
12
|
+
const balancerVault_1 = require("./balancerVault");
|
|
13
|
+
const CURVE_FEE_DECIMALS = 100000000n;
|
|
14
|
+
const BALANCER_FEE_DECIMALS = 10000000000000000n;
|
|
15
|
+
exports.BALANCER_VAULT_ABI = [
|
|
16
|
+
{
|
|
17
|
+
inputs: [],
|
|
18
|
+
name: "getSwapFeePercentage",
|
|
19
|
+
outputs: [
|
|
20
|
+
{
|
|
21
|
+
internalType: "uint256",
|
|
22
|
+
name: "",
|
|
23
|
+
type: "uint256",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
stateMutability: "view",
|
|
27
|
+
type: "function",
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
class PathFinderUtils {
|
|
31
|
+
static async findPathFees({ calls, provider, contractsByAdapter, }) {
|
|
32
|
+
const pathObjects = txParser_1.TxParser.parseToObjectMultiCall(calls);
|
|
33
|
+
const { simpleFees, curve, balancer } = pathObjects.reduce((acc, pathSegment) => {
|
|
34
|
+
if (!pathSegment)
|
|
35
|
+
return acc;
|
|
36
|
+
const { callObject, parser } = pathSegment;
|
|
37
|
+
switch (true) {
|
|
38
|
+
case parser instanceof uniV2AdapterParser_1.UniswapV2AdapterParser: {
|
|
39
|
+
const f = this.getUniswapV2Fee(callObject);
|
|
40
|
+
if (f)
|
|
41
|
+
acc.simpleFees.push(f);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case parser instanceof uniV3AdapterParser_1.UniswapV3AdapterParser: {
|
|
45
|
+
const f = this.getUniswapV3Fee(callObject);
|
|
46
|
+
if (f)
|
|
47
|
+
acc.simpleFees.push(f);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case parser instanceof lidoAdapterParser_1.LidoAdapterParser: {
|
|
51
|
+
const f = this.getLidoFee();
|
|
52
|
+
if (f)
|
|
53
|
+
acc.simpleFees.push(f);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case parser instanceof curveAdapterParser_1.CurveAdapterParser: {
|
|
57
|
+
const call = this.getCurveFeeCall(callObject, contractsByAdapter);
|
|
58
|
+
if (call)
|
|
59
|
+
acc.curve.push(call);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case parser instanceof balancerV2VaultParser_1.BalancerV2VaultParser: {
|
|
63
|
+
const call = this.getBalancerFeeCall(callObject);
|
|
64
|
+
if (call)
|
|
65
|
+
acc.balancer.push(call);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return acc;
|
|
70
|
+
}, {
|
|
71
|
+
simpleFees: [],
|
|
72
|
+
curve: [],
|
|
73
|
+
balancer: [],
|
|
74
|
+
});
|
|
75
|
+
const response = (await provider.multicall({
|
|
76
|
+
allowFailure: true,
|
|
77
|
+
multicallAddress: sdk_gov_1.MULTICALL_ADDRESS,
|
|
78
|
+
contracts: [...curve, ...balancer],
|
|
79
|
+
}));
|
|
80
|
+
const curveEnds = curve.length;
|
|
81
|
+
const curveResponse = response.slice(0, curveEnds);
|
|
82
|
+
const balancerEnds = balancer.length;
|
|
83
|
+
const balancerResponse = response.slice(curveEnds, balancerEnds);
|
|
84
|
+
const curveFees = curveResponse.map(r => this.getCurveFee(r));
|
|
85
|
+
const balancerFees = balancerResponse.map(r => this.getBalancerFee(r));
|
|
86
|
+
const fees = [...simpleFees, ...curveFees, ...balancerFees];
|
|
87
|
+
return fees;
|
|
88
|
+
}
|
|
89
|
+
static getUniswapV2Fee(callObject) {
|
|
90
|
+
const { functionName } = callObject;
|
|
91
|
+
switch (functionName) {
|
|
92
|
+
case "swapExactTokensForTokens":
|
|
93
|
+
case "swapTokensForExactTokens":
|
|
94
|
+
case "swapDiffTokensForTokens": {
|
|
95
|
+
// 0.3%
|
|
96
|
+
return {
|
|
97
|
+
type: "uniswap_v2",
|
|
98
|
+
value: 3000n,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
static getUniswapV3Fee(callObject) {
|
|
106
|
+
const { functionName, args } = callObject;
|
|
107
|
+
switch (functionName) {
|
|
108
|
+
case "exactInputSingle":
|
|
109
|
+
case "exactDiffInputSingle":
|
|
110
|
+
case "exactOutputSingle": {
|
|
111
|
+
const [first] = args;
|
|
112
|
+
const { fee = 0 } = first || {};
|
|
113
|
+
return {
|
|
114
|
+
type: "uniswap_v3",
|
|
115
|
+
value: (0, sdk_gov_1.toBigInt)(fee),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
default:
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
static getCurveFeeCall(callObject, contractsByAdapter) {
|
|
123
|
+
const { functionName } = callObject;
|
|
124
|
+
switch (functionName) {
|
|
125
|
+
case "exchange":
|
|
126
|
+
case "exchange_underlying":
|
|
127
|
+
case "exchange_diff":
|
|
128
|
+
case "exchange_diff_underlying": {
|
|
129
|
+
const adapter = (callObject.address || "").toLowerCase();
|
|
130
|
+
const contract = contractsByAdapter[adapter];
|
|
131
|
+
return contract
|
|
132
|
+
? {
|
|
133
|
+
address: contract,
|
|
134
|
+
abi: types_1.iCurvePoolAbi,
|
|
135
|
+
functionName: "fee",
|
|
136
|
+
args: [],
|
|
137
|
+
}
|
|
138
|
+
: null;
|
|
139
|
+
}
|
|
140
|
+
default:
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
static getCurveFee({ result }) {
|
|
145
|
+
const feeOriginal = result || 0n;
|
|
146
|
+
return {
|
|
147
|
+
type: "curve",
|
|
148
|
+
value: (feeOriginal * sdk_gov_1.PERCENTAGE_FACTOR) / CURVE_FEE_DECIMALS,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
static getBalancerFeeCall(callObject) {
|
|
152
|
+
const { functionName } = callObject;
|
|
153
|
+
switch (functionName) {
|
|
154
|
+
case "swapDiff":
|
|
155
|
+
case "swap": {
|
|
156
|
+
const [first] = callObject.args;
|
|
157
|
+
const { poolId = "" } = first || {};
|
|
158
|
+
const { address } = (0, balancerVault_1.splitPoolId)(poolId);
|
|
159
|
+
return address
|
|
160
|
+
? {
|
|
161
|
+
address: address,
|
|
162
|
+
abi: exports.BALANCER_VAULT_ABI,
|
|
163
|
+
functionName: "getSwapFeePercentage",
|
|
164
|
+
args: [],
|
|
165
|
+
}
|
|
166
|
+
: null;
|
|
167
|
+
}
|
|
168
|
+
default:
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
static getBalancerFee({ result }) {
|
|
173
|
+
const feeOriginal = result || 0n;
|
|
174
|
+
return {
|
|
175
|
+
type: "balancer",
|
|
176
|
+
value: (feeOriginal * sdk_gov_1.PERCENTAGE_FACTOR) / BALANCER_FEE_DECIMALS,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
static getLidoFee() {
|
|
180
|
+
return {
|
|
181
|
+
type: "lido",
|
|
182
|
+
value: 0n,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.PathFinderUtils = PathFinderUtils;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Address } from "viem";
|
|
2
2
|
export interface CaTokenBalance {
|
|
3
|
-
success: boolean;
|
|
4
3
|
token: Address;
|
|
5
4
|
balance: bigint;
|
|
6
5
|
isForbidden: boolean;
|
|
@@ -8,10 +7,10 @@ export interface CaTokenBalance {
|
|
|
8
7
|
isQuoted: boolean;
|
|
9
8
|
quota: bigint;
|
|
10
9
|
quotaRate: bigint;
|
|
11
|
-
mask: bigint;
|
|
12
10
|
}
|
|
13
11
|
export interface CreditAccountDataPayload {
|
|
14
12
|
isSuccessful: boolean;
|
|
13
|
+
priceFeedsNeeded: readonly Address[];
|
|
15
14
|
addr: Address;
|
|
16
15
|
borrower: Address;
|
|
17
16
|
creditManager: Address;
|
|
@@ -28,7 +27,6 @@ export interface CreditAccountDataPayload {
|
|
|
28
27
|
healthFactor: bigint;
|
|
29
28
|
baseBorrowRate: bigint;
|
|
30
29
|
balances: readonly {
|
|
31
|
-
success: boolean;
|
|
32
30
|
token: Address;
|
|
33
31
|
balance: bigint;
|
|
34
32
|
isForbidden: boolean;
|
|
@@ -36,7 +34,6 @@ export interface CreditAccountDataPayload {
|
|
|
36
34
|
isQuoted: boolean;
|
|
37
35
|
quota: bigint;
|
|
38
36
|
quotaRate: number;
|
|
39
|
-
mask: bigint;
|
|
40
37
|
}[];
|
|
41
38
|
cfVersion: bigint;
|
|
42
39
|
expirationDate: number;
|
package/lib/payload/pool.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ export interface PoolDataPayload {
|
|
|
42
42
|
isActive: boolean;
|
|
43
43
|
}[];
|
|
44
44
|
zappers: readonly PoolZapper[];
|
|
45
|
+
creditManagerDebtParams: readonly {
|
|
46
|
+
creditManager: Address;
|
|
47
|
+
borrowed: bigint;
|
|
48
|
+
limit: bigint;
|
|
49
|
+
availableToBorrow: bigint;
|
|
50
|
+
}[];
|
|
45
51
|
}
|
|
46
52
|
export interface PoolDataExtraPayload {
|
|
47
53
|
stakedDieselToken: Array<Address>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.237",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@gearbox-protocol/bots-v3": "^1.5.1",
|
|
32
|
-
"@gearbox-protocol/sdk-gov": "^2.
|
|
32
|
+
"@gearbox-protocol/sdk-gov": "^2.25.0",
|
|
33
33
|
"@wagmi/cli": "^2.1.13",
|
|
34
34
|
"axios": "^1.2.6",
|
|
35
35
|
"decimal.js-light": "^2.5.1",
|