@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
|
@@ -90,14 +90,15 @@ export interface TimeToLiquidationProps {
|
|
|
90
90
|
}
|
|
91
91
|
export declare class CreditAccountData {
|
|
92
92
|
readonly isSuccessful: boolean;
|
|
93
|
-
readonly
|
|
93
|
+
readonly priceFeedsNeeded: Address[];
|
|
94
|
+
readonly addr: Address;
|
|
94
95
|
readonly borrower: Address;
|
|
95
96
|
readonly creditManager: Address;
|
|
96
97
|
readonly creditFacade: Address;
|
|
97
|
-
readonly
|
|
98
|
+
readonly underlyingToken: Address;
|
|
98
99
|
readonly expirationDate: number;
|
|
99
100
|
readonly version: number;
|
|
100
|
-
readonly
|
|
101
|
+
readonly enabledTokenMask: bigint;
|
|
101
102
|
readonly healthFactor: number;
|
|
102
103
|
isDeleting: boolean;
|
|
103
104
|
readonly baseBorrowRateWithoutFee: number;
|
|
@@ -106,14 +107,13 @@ export declare class CreditAccountData {
|
|
|
106
107
|
readonly accruedFees: bigint;
|
|
107
108
|
readonly totalDebtUSD: bigint;
|
|
108
109
|
readonly borrowedAmountPlusInterestAndFees: bigint;
|
|
109
|
-
readonly debt: bigint;
|
|
110
110
|
readonly totalValue: bigint;
|
|
111
111
|
readonly totalValueUSD: bigint;
|
|
112
112
|
readonly twvUSD: bigint;
|
|
113
113
|
readonly activeBots: Record<Address, true>;
|
|
114
114
|
readonly balances: Record<Address, bigint>;
|
|
115
115
|
readonly collateralTokens: Array<Address>;
|
|
116
|
-
readonly
|
|
116
|
+
readonly allBalances: Record<Address, CaTokenBalance>;
|
|
117
117
|
readonly forbiddenTokens: Record<Address, true>;
|
|
118
118
|
readonly quotedTokens: Record<Address, true>;
|
|
119
119
|
constructor(payload: CreditAccountDataPayload);
|
|
@@ -10,14 +10,15 @@ exports.MAX_UINT256 = 1157920892373161954235709850086879078532699846656405640394
|
|
|
10
10
|
const MAX_UINT16 = 65535;
|
|
11
11
|
class CreditAccountData {
|
|
12
12
|
isSuccessful;
|
|
13
|
-
|
|
13
|
+
priceFeedsNeeded;
|
|
14
|
+
addr;
|
|
14
15
|
borrower;
|
|
15
16
|
creditManager;
|
|
16
17
|
creditFacade;
|
|
17
|
-
|
|
18
|
+
underlyingToken;
|
|
18
19
|
expirationDate;
|
|
19
20
|
version;
|
|
20
|
-
|
|
21
|
+
enabledTokenMask;
|
|
21
22
|
healthFactor;
|
|
22
23
|
isDeleting;
|
|
23
24
|
baseBorrowRateWithoutFee;
|
|
@@ -26,32 +27,31 @@ class CreditAccountData {
|
|
|
26
27
|
accruedFees;
|
|
27
28
|
totalDebtUSD;
|
|
28
29
|
borrowedAmountPlusInterestAndFees;
|
|
29
|
-
debt;
|
|
30
30
|
totalValue;
|
|
31
31
|
totalValueUSD;
|
|
32
32
|
twvUSD;
|
|
33
33
|
activeBots;
|
|
34
34
|
balances = {};
|
|
35
35
|
collateralTokens = [];
|
|
36
|
-
|
|
36
|
+
allBalances = {};
|
|
37
37
|
forbiddenTokens = {};
|
|
38
38
|
quotedTokens = {};
|
|
39
39
|
constructor(payload) {
|
|
40
40
|
this.isSuccessful = payload.isSuccessful;
|
|
41
|
-
this.
|
|
41
|
+
this.priceFeedsNeeded = payload.priceFeedsNeeded.map(t => t);
|
|
42
|
+
this.addr = payload.addr.toLowerCase();
|
|
42
43
|
this.borrower = payload.borrower.toLowerCase();
|
|
43
44
|
this.creditManager = payload.creditManager.toLowerCase();
|
|
44
45
|
this.creditFacade = payload.creditFacade.toLowerCase();
|
|
45
|
-
this.
|
|
46
|
+
this.underlyingToken = payload.underlying.toLowerCase();
|
|
46
47
|
this.expirationDate = Number(payload.expirationDate);
|
|
47
48
|
this.version = Number(payload.cfVersion);
|
|
48
49
|
this.healthFactor = Number(payload.healthFactor || 0n);
|
|
49
|
-
this.
|
|
50
|
+
this.enabledTokenMask = payload.enabledTokensMask;
|
|
50
51
|
this.isDeleting = false;
|
|
51
52
|
this.borrowedAmount = payload.debt;
|
|
52
53
|
this.accruedInterest = payload.accruedInterest || 0n;
|
|
53
54
|
this.accruedFees = payload.accruedFees || 0n;
|
|
54
|
-
this.debt = this.borrowedAmount;
|
|
55
55
|
this.borrowedAmountPlusInterestAndFees =
|
|
56
56
|
this.borrowedAmount + this.accruedInterest + this.accruedFees;
|
|
57
57
|
this.totalDebtUSD = payload.totalDebtUSD;
|
|
@@ -67,7 +67,6 @@ class CreditAccountData {
|
|
|
67
67
|
payload.balances.forEach(b => {
|
|
68
68
|
const token = b.token.toLowerCase();
|
|
69
69
|
const balance = {
|
|
70
|
-
success: b.success,
|
|
71
70
|
token,
|
|
72
71
|
balance: b.balance,
|
|
73
72
|
isForbidden: b.isForbidden,
|
|
@@ -75,7 +74,6 @@ class CreditAccountData {
|
|
|
75
74
|
isQuoted: b.isQuoted,
|
|
76
75
|
quota: b.quota,
|
|
77
76
|
quotaRate: BigInt(b.quotaRate) * sdk_gov_1.PERCENTAGE_DECIMALS,
|
|
78
|
-
mask: b.mask,
|
|
79
77
|
};
|
|
80
78
|
if (!b.isForbidden) {
|
|
81
79
|
this.balances[token] = balance.balance;
|
|
@@ -87,7 +85,7 @@ class CreditAccountData {
|
|
|
87
85
|
if (b.isQuoted) {
|
|
88
86
|
this.quotedTokens[token] = true;
|
|
89
87
|
}
|
|
90
|
-
this.
|
|
88
|
+
this.allBalances[token] = balance;
|
|
91
89
|
});
|
|
92
90
|
}
|
|
93
91
|
setDeleteInProgress(d) {
|
|
@@ -148,7 +146,7 @@ class CreditAccountData {
|
|
|
148
146
|
return !!this.quotedTokens[token];
|
|
149
147
|
}
|
|
150
148
|
isTokenEnabled(token) {
|
|
151
|
-
return this.
|
|
149
|
+
return this.allBalances[token].isEnabled;
|
|
152
150
|
}
|
|
153
151
|
static calcMaxDebtIncrease(healthFactor, debt, underlyingLT, minHf = Number(sdk_gov_1.PERCENTAGE_FACTOR)) {
|
|
154
152
|
// HF = (TWV + d*lt) / (D + d) => d = (HF*D - TWV) / (l - HF)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Address } from "viem";
|
|
2
|
+
import { MultiCall } from "../pathfinder/core";
|
|
2
3
|
import { ChartsCreditManagerPayload, CreditManagerDataPayload, QuotaInfo } from "../payload/creditManager";
|
|
3
4
|
import { LinearModel } from "../payload/pool";
|
|
4
5
|
export type CreditManagerType = "universal" | "trade" | "farm" | "restaking";
|
|
@@ -38,7 +39,18 @@ export declare class CreditManagerData {
|
|
|
38
39
|
readonly quotas: Record<Address, QuotaInfo>;
|
|
39
40
|
readonly interestModel: LinearModel;
|
|
40
41
|
constructor(payload: CreditManagerDataPayload);
|
|
42
|
+
get id(): Address;
|
|
41
43
|
isQuoted(token: Address): boolean;
|
|
44
|
+
encodeAddCollateralV3(tokenAddress: Address, amount: bigint): MultiCall;
|
|
45
|
+
encodeAddCollateralWithPermitV3(tokenAddress: Address, amount: bigint, deadline: bigint, v: number, r: Address, s: Address): MultiCall;
|
|
46
|
+
encodeIncreaseDebtV3(amount: bigint): MultiCall;
|
|
47
|
+
encodeDecreaseDebtV3(amount: bigint): MultiCall;
|
|
48
|
+
encodeEnableTokenV3(token: Address): MultiCall;
|
|
49
|
+
encodeDisableTokenV3(token: Address): MultiCall;
|
|
50
|
+
encodeUpdateQuotaV3(token: Address, quotaChange: bigint, minQuota: bigint): MultiCall;
|
|
51
|
+
encodeWithdrawCollateralV3(token: Address, amount: bigint, to: Address): MultiCall;
|
|
52
|
+
static withdrawAllAndUnwrap_Convex(address: Address, claim: boolean): MultiCall;
|
|
53
|
+
encodeOnDemandPriceUpdateV3(token: Address, reserve: boolean, data: Address): MultiCall;
|
|
42
54
|
static getTier(name: string): number;
|
|
43
55
|
static getType(name: string): CreditManagerType;
|
|
44
56
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChartsCreditManagerData = exports.CreditManagerData = void 0;
|
|
4
4
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const txParser_1 = require("../parsers/txParser");
|
|
7
|
+
const types_1 = require("../types");
|
|
5
8
|
class CreditManagerData {
|
|
6
9
|
address;
|
|
7
10
|
type;
|
|
@@ -113,10 +116,121 @@ class CreditManagerData {
|
|
|
113
116
|
this.collateralTokens.push(tLc);
|
|
114
117
|
this.supportedTokens[tLc] = true;
|
|
115
118
|
});
|
|
119
|
+
txParser_1.TxParser.addCreditManager(this.address, this.version);
|
|
120
|
+
if (!!this.creditFacade && this.creditFacade !== sdk_gov_1.ADDRESS_0X0) {
|
|
121
|
+
txParser_1.TxParser.addCreditFacade(this.creditFacade, sdk_gov_1.tokenSymbolByAddress[this.underlyingToken], this.version);
|
|
122
|
+
txParser_1.TxParser.addAdapters(payload.adapters.map(a => ({
|
|
123
|
+
adapter: a.adapter,
|
|
124
|
+
contract: a.targetContract,
|
|
125
|
+
})));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
get id() {
|
|
129
|
+
return this.address;
|
|
116
130
|
}
|
|
117
131
|
isQuoted(token) {
|
|
118
132
|
return !!this.quotas[token];
|
|
119
133
|
}
|
|
134
|
+
encodeAddCollateralV3(tokenAddress, amount) {
|
|
135
|
+
return {
|
|
136
|
+
target: this.creditFacade,
|
|
137
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
138
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
139
|
+
functionName: "addCollateral",
|
|
140
|
+
args: [tokenAddress, amount],
|
|
141
|
+
}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
encodeAddCollateralWithPermitV3(tokenAddress, amount, deadline, v, r, s) {
|
|
145
|
+
return {
|
|
146
|
+
target: this.creditFacade,
|
|
147
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
148
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
149
|
+
functionName: "addCollateralWithPermit",
|
|
150
|
+
args: [tokenAddress, amount, deadline, v, r, s],
|
|
151
|
+
}),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
encodeIncreaseDebtV3(amount) {
|
|
155
|
+
return {
|
|
156
|
+
target: this.creditFacade,
|
|
157
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
158
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
159
|
+
functionName: "increaseDebt",
|
|
160
|
+
args: [amount],
|
|
161
|
+
}),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
encodeDecreaseDebtV3(amount) {
|
|
165
|
+
return {
|
|
166
|
+
target: this.creditFacade,
|
|
167
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
168
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
169
|
+
functionName: "decreaseDebt",
|
|
170
|
+
args: [amount],
|
|
171
|
+
}),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
encodeEnableTokenV3(token) {
|
|
175
|
+
return {
|
|
176
|
+
target: this.creditFacade,
|
|
177
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
178
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
179
|
+
functionName: "enableToken",
|
|
180
|
+
args: [token],
|
|
181
|
+
}),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
encodeDisableTokenV3(token) {
|
|
185
|
+
return {
|
|
186
|
+
target: this.creditFacade,
|
|
187
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
188
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
189
|
+
functionName: "disableToken",
|
|
190
|
+
args: [token],
|
|
191
|
+
}),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
encodeUpdateQuotaV3(token, quotaChange, minQuota) {
|
|
195
|
+
return {
|
|
196
|
+
target: this.creditFacade,
|
|
197
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
198
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
199
|
+
functionName: "updateQuota",
|
|
200
|
+
args: [token, quotaChange, minQuota],
|
|
201
|
+
}),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
encodeWithdrawCollateralV3(token, amount, to) {
|
|
205
|
+
return {
|
|
206
|
+
target: this.creditFacade,
|
|
207
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
208
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
209
|
+
functionName: "withdrawCollateral",
|
|
210
|
+
args: [token, amount, to],
|
|
211
|
+
}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
static withdrawAllAndUnwrap_Convex(address, claim) {
|
|
215
|
+
return {
|
|
216
|
+
target: address,
|
|
217
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
218
|
+
abi: types_1.iConvexV1BaseRewardPoolAdapterAbi,
|
|
219
|
+
functionName: "withdrawDiffAndUnwrap",
|
|
220
|
+
args: [1n, claim],
|
|
221
|
+
}),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
encodeOnDemandPriceUpdateV3(token, reserve, data) {
|
|
225
|
+
return {
|
|
226
|
+
target: this.creditFacade,
|
|
227
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
228
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
229
|
+
functionName: "onDemandPriceUpdate",
|
|
230
|
+
args: [token, reserve, data],
|
|
231
|
+
}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
120
234
|
static getTier(name) {
|
|
121
235
|
const DEFAULT_TIER = 99;
|
|
122
236
|
const l = name.split(" ") || [];
|
package/lib/core/pool.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ export declare class PoolData {
|
|
|
21
21
|
readonly utilization: number;
|
|
22
22
|
readonly totalBorrowed: bigint;
|
|
23
23
|
readonly totalDebtLimit: bigint;
|
|
24
|
+
readonly creditManagerDebtParams: Record<Address, {
|
|
25
|
+
creditManager: Address;
|
|
26
|
+
borrowed: bigint;
|
|
27
|
+
limit: bigint;
|
|
28
|
+
availableToBorrow: bigint;
|
|
29
|
+
}>;
|
|
24
30
|
readonly quotas: Record<Address, {
|
|
25
31
|
token: Address;
|
|
26
32
|
rate: bigint;
|
package/lib/core/pool.js
CHANGED
|
@@ -26,6 +26,7 @@ class PoolData {
|
|
|
26
26
|
utilization;
|
|
27
27
|
totalBorrowed;
|
|
28
28
|
totalDebtLimit;
|
|
29
|
+
creditManagerDebtParams;
|
|
29
30
|
quotas;
|
|
30
31
|
zappers;
|
|
31
32
|
totalAssets;
|
|
@@ -61,6 +62,16 @@ class PoolData {
|
|
|
61
62
|
this.utilization = PoolData.calculateUtilization(expected, available);
|
|
62
63
|
this.totalBorrowed = payload.totalBorrowed;
|
|
63
64
|
this.totalDebtLimit = payload.totalDebtLimit;
|
|
65
|
+
this.creditManagerDebtParams = payload.creditManagerDebtParams.reduce((acc, p) => {
|
|
66
|
+
const creditManager = p.creditManager.toLowerCase();
|
|
67
|
+
acc[creditManager] = {
|
|
68
|
+
creditManager,
|
|
69
|
+
borrowed: p.borrowed,
|
|
70
|
+
limit: p.limit,
|
|
71
|
+
availableToBorrow: p.availableToBorrow,
|
|
72
|
+
};
|
|
73
|
+
return acc;
|
|
74
|
+
}, {});
|
|
64
75
|
this.quotas = payload.quotas.reduce((acc, q) => {
|
|
65
76
|
const token = q.token.toLowerCase();
|
|
66
77
|
acc[token] = {
|
package/lib/core/protocols.js
CHANGED
|
@@ -130,6 +130,10 @@ const PROTOCOL_DATA = {
|
|
|
130
130
|
name: "Lombard",
|
|
131
131
|
icon: "/protocols/lombard.svg",
|
|
132
132
|
},
|
|
133
|
+
Sky: {
|
|
134
|
+
name: "Sky",
|
|
135
|
+
icon: "/protocols/sky.svg",
|
|
136
|
+
},
|
|
133
137
|
};
|
|
134
138
|
const isExtendedProtocol = (t) => typeof t === "string" && !!PROTOCOL_DATA[t];
|
|
135
139
|
exports.isExtendedProtocol = isExtendedProtocol;
|
package/lib/core/rewardConvex.js
CHANGED
|
@@ -10,7 +10,7 @@ const types_1 = require("../types");
|
|
|
10
10
|
// convex[totalSupply, ...tokens] aura[totalSupply, multiplier, ...tokens]
|
|
11
11
|
class RewardConvex {
|
|
12
12
|
static async findRewards(ca, cm, network, provider) {
|
|
13
|
-
const prepared = RewardConvex.prepareMultiCalls(ca.
|
|
13
|
+
const prepared = RewardConvex.prepareMultiCalls(ca.addr, cm, network);
|
|
14
14
|
if (!prepared)
|
|
15
15
|
return [];
|
|
16
16
|
const { auraCalls, auraDistribution, convexCalls, convexDistribution } = prepared;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
2
|
+
import { MultiCall, PathFinderResult, SwapOperation } from "../pathfinder/core";
|
|
3
|
+
import { CreditManagerData } from "./creditManager";
|
|
4
|
+
interface Info {
|
|
5
|
+
name: string;
|
|
6
|
+
creditManager: Address;
|
|
7
|
+
creditManagerName: string;
|
|
8
|
+
}
|
|
9
|
+
export type TradeOperations = "farmWithdraw" | "farmDeposit" | "swap";
|
|
10
|
+
export interface GetTradesProps {
|
|
11
|
+
tokenIn: Address;
|
|
12
|
+
tokenOut: Address;
|
|
13
|
+
amount: bigint;
|
|
14
|
+
results: Array<PathFinderResult>;
|
|
15
|
+
creditManager: CreditManagerData;
|
|
16
|
+
swapOperation: SwapOperation;
|
|
17
|
+
swapName: TradeOperations;
|
|
18
|
+
}
|
|
19
|
+
export declare class Trade {
|
|
20
|
+
readonly helper: Info;
|
|
21
|
+
readonly tradePath: PathFinderResult;
|
|
22
|
+
readonly swapOperation: SwapOperation;
|
|
23
|
+
readonly sourceAmount: bigint;
|
|
24
|
+
readonly minExpectedAmount: bigint;
|
|
25
|
+
readonly averageExpectedAmount: bigint;
|
|
26
|
+
readonly rate: bigint;
|
|
27
|
+
readonly tokenIn: Address;
|
|
28
|
+
readonly tokenOut: Address;
|
|
29
|
+
readonly operationName: TradeOperations;
|
|
30
|
+
private constructor();
|
|
31
|
+
getName(): string;
|
|
32
|
+
toString(): string;
|
|
33
|
+
static getTrades({ tokenIn, tokenOut, amount, results, creditManager, swapOperation, swapName, }: GetTradesProps): Trade[];
|
|
34
|
+
static getCallInfo(calls: Array<MultiCall>, creditManager: Address, creditManagerName: string): Info[];
|
|
35
|
+
private static getContractSymbol;
|
|
36
|
+
static sortTrades(trades: Array<Trade>, swapStrategy: string): Trade[];
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trade = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const txParser_1 = require("../parsers/txParser");
|
|
6
|
+
const core_1 = require("../pathfinder/core");
|
|
7
|
+
class Trade {
|
|
8
|
+
helper;
|
|
9
|
+
tradePath;
|
|
10
|
+
swapOperation;
|
|
11
|
+
sourceAmount;
|
|
12
|
+
minExpectedAmount;
|
|
13
|
+
averageExpectedAmount;
|
|
14
|
+
rate;
|
|
15
|
+
tokenIn;
|
|
16
|
+
tokenOut;
|
|
17
|
+
operationName;
|
|
18
|
+
constructor(props) {
|
|
19
|
+
this.helper = props.adapter;
|
|
20
|
+
this.tradePath = props.tradePath;
|
|
21
|
+
this.swapOperation = props.swapOperation;
|
|
22
|
+
this.sourceAmount = props.sourceAmount;
|
|
23
|
+
this.minExpectedAmount = props.minExpectedAmount;
|
|
24
|
+
this.averageExpectedAmount = props.averageExpectedAmount;
|
|
25
|
+
this.rate = (sdk_gov_1.WAD * props.minExpectedAmount) / props.sourceAmount;
|
|
26
|
+
this.tokenIn = props.tokenIn;
|
|
27
|
+
this.tokenOut = props.tokenOut;
|
|
28
|
+
this.operationName = props.swapName;
|
|
29
|
+
}
|
|
30
|
+
getName() {
|
|
31
|
+
return this.helper.name;
|
|
32
|
+
}
|
|
33
|
+
toString() {
|
|
34
|
+
const symbolFrom = sdk_gov_1.tokenSymbolByAddress[this.tokenIn.toLowerCase()];
|
|
35
|
+
const symbolTo = sdk_gov_1.tokenSymbolByAddress[this.tokenOut.toLowerCase()];
|
|
36
|
+
if (!symbolFrom)
|
|
37
|
+
throw new Error(`Unknown token: ${this.tokenIn}`);
|
|
38
|
+
if (!symbolTo)
|
|
39
|
+
throw new Error(`Unknown token: ${this.tokenOut}`);
|
|
40
|
+
const decimalsFrom = sdk_gov_1.decimals[symbolFrom];
|
|
41
|
+
const decimalsTo = sdk_gov_1.decimals[symbolTo];
|
|
42
|
+
return `${this.operationName} ${(0, sdk_gov_1.formatBN)(this.sourceAmount, decimalsFrom)} ${symbolFrom} ⇒ ${(0, sdk_gov_1.formatBN)(this.minExpectedAmount, decimalsTo)} ${symbolTo} on ${this.helper.name}`;
|
|
43
|
+
}
|
|
44
|
+
static getTrades({ tokenIn, tokenOut, amount, results, creditManager, swapOperation, swapName, }) {
|
|
45
|
+
const trades = results.reduce((acc, tradePath) => {
|
|
46
|
+
const { calls } = tradePath;
|
|
47
|
+
const callInfo = Trade.getCallInfo(calls, creditManager.address, creditManager.name);
|
|
48
|
+
const trade = new Trade({
|
|
49
|
+
tradePath,
|
|
50
|
+
adapter: callInfo[0] || {
|
|
51
|
+
name: "unknown",
|
|
52
|
+
contractAddress: calls[0]?.target || "",
|
|
53
|
+
creditManager: creditManager.address,
|
|
54
|
+
creditManagerName: creditManager.name,
|
|
55
|
+
},
|
|
56
|
+
swapOperation,
|
|
57
|
+
sourceAmount: amount,
|
|
58
|
+
minExpectedAmount: tradePath.minAmount,
|
|
59
|
+
averageExpectedAmount: tradePath.amount,
|
|
60
|
+
tokenIn,
|
|
61
|
+
tokenOut,
|
|
62
|
+
swapName,
|
|
63
|
+
});
|
|
64
|
+
acc.push(trade);
|
|
65
|
+
return acc;
|
|
66
|
+
}, []);
|
|
67
|
+
return trades;
|
|
68
|
+
}
|
|
69
|
+
static getCallInfo(calls, creditManager, creditManagerName) {
|
|
70
|
+
const callAdapters = calls.reduce((acc, call) => {
|
|
71
|
+
const contractSymbol = this.getContractSymbol(call.target.toLowerCase());
|
|
72
|
+
if (!(0, sdk_gov_1.isSupportedContract)(contractSymbol)) {
|
|
73
|
+
return acc;
|
|
74
|
+
}
|
|
75
|
+
const { name } = sdk_gov_1.contractParams[contractSymbol];
|
|
76
|
+
acc.push({
|
|
77
|
+
name,
|
|
78
|
+
creditManager,
|
|
79
|
+
creditManagerName,
|
|
80
|
+
});
|
|
81
|
+
return acc;
|
|
82
|
+
}, []);
|
|
83
|
+
return callAdapters;
|
|
84
|
+
}
|
|
85
|
+
static getContractSymbol(address) {
|
|
86
|
+
try {
|
|
87
|
+
const { contract } = txParser_1.TxParser.getParseData(address);
|
|
88
|
+
return contract;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
static sortTrades(trades, swapStrategy) {
|
|
95
|
+
if (trades.length === 0)
|
|
96
|
+
return [];
|
|
97
|
+
const { swapOperation } = trades[0];
|
|
98
|
+
const sorted = [...trades].sort((a, b) => {
|
|
99
|
+
const aSelected = a.getName().toLowerCase().search(swapStrategy.toLowerCase()) >= 0;
|
|
100
|
+
const bSelected = b.getName().toLowerCase().search(swapStrategy.toLowerCase()) >= 0;
|
|
101
|
+
if ((aSelected && bSelected) || (!aSelected && !bSelected)) {
|
|
102
|
+
const sign = a.minExpectedAmount > b.minExpectedAmount ? -1 : 1;
|
|
103
|
+
return swapOperation === core_1.SwapOperation.EXACT_INPUT ? sign : -sign;
|
|
104
|
+
}
|
|
105
|
+
return aSelected ? -1 : 1;
|
|
106
|
+
});
|
|
107
|
+
return sorted;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.Trade = Trade;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { NetworkType, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { Address, PublicClient, WalletClient } from "viem";
|
|
3
|
-
import { PoolData } from "../core/pool";
|
|
4
3
|
export interface GearboxExtraMerkleLmReward {
|
|
5
|
-
pool: Address;
|
|
6
4
|
poolToken: Address;
|
|
7
5
|
rewardToken: Address;
|
|
8
6
|
amount: bigint;
|
|
9
7
|
type: "extraMerkle";
|
|
10
8
|
}
|
|
11
9
|
export interface GearboxStakedV3LmReward {
|
|
12
|
-
pool: Address;
|
|
13
10
|
poolToken: Address;
|
|
14
11
|
rewardToken: Address;
|
|
15
12
|
amount: bigint;
|
|
16
13
|
type: "stakedV3";
|
|
17
14
|
}
|
|
18
15
|
export interface GearboxMerkleV2LmReward {
|
|
19
|
-
|
|
20
|
-
poolToken?: undefined;
|
|
16
|
+
poolToken?: Address;
|
|
21
17
|
rewardToken: Address;
|
|
22
18
|
amount: bigint;
|
|
23
19
|
type: "merkleV2";
|
|
@@ -33,7 +29,6 @@ export interface MerkleDistributorInfo {
|
|
|
33
29
|
}>;
|
|
34
30
|
}
|
|
35
31
|
export interface FarmInfo {
|
|
36
|
-
pool: Address;
|
|
37
32
|
finished: bigint;
|
|
38
33
|
duration: bigint;
|
|
39
34
|
reward: bigint;
|
|
@@ -43,7 +38,6 @@ export interface FarmInfo {
|
|
|
43
38
|
type PoolsWithExtraRewardsList = Record<NetworkType, Array<SupportedToken>>;
|
|
44
39
|
type ReportHandler = (e: unknown, description?: string) => void;
|
|
45
40
|
export interface GetLmRewardsInfoProps {
|
|
46
|
-
pools: Record<Address, PoolData>;
|
|
47
41
|
currentTokenData: Record<SupportedToken, Address>;
|
|
48
42
|
provider: PublicClient;
|
|
49
43
|
multicallAddress: Address;
|
|
@@ -73,7 +67,7 @@ export interface ClaimLmRewardsV3Props {
|
|
|
73
67
|
signer: WalletClient;
|
|
74
68
|
}
|
|
75
69
|
export declare class GearboxRewardsApi {
|
|
76
|
-
static getLmRewardsInfo({
|
|
70
|
+
static getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards, network, reportError, }: GetLmRewardsInfoProps): Promise<{
|
|
77
71
|
rewardPoolsInfo: Record<string, FarmInfo[]>;
|
|
78
72
|
baseRewardPoolsInfo: Record<string, FarmInfo>;
|
|
79
73
|
extraRewardPoolsInfo: Record<string, FarmInfo[]>;
|
|
@@ -19,44 +19,28 @@ const DEFAULT_POOLS_WITH_EXTRA_REWARDS = {
|
|
|
19
19
|
Base: [],
|
|
20
20
|
};
|
|
21
21
|
class GearboxRewardsApi {
|
|
22
|
-
static async getLmRewardsInfo({
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
acc[t] = p.address;
|
|
26
|
-
});
|
|
27
|
-
p.stakedDieselToken_old.forEach(t => {
|
|
28
|
-
acc[t] = p.address;
|
|
29
|
-
});
|
|
30
|
-
return acc;
|
|
31
|
-
}, {});
|
|
32
|
-
const poolTokens = sdk_gov_1.TypedObjectUtils.keys(poolByStakedToken);
|
|
33
|
-
const chainId = sdk_gov_1.CHAINS[network];
|
|
34
|
-
const poolTokensWithExtraReward = (poolsWithExtraRewards[network] || []).filter(symbol => {
|
|
35
|
-
const addr = currentTokenData[symbol];
|
|
36
|
-
if (!addr) {
|
|
37
|
-
console.error(`Pool staked token not found ${symbol}`);
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
});
|
|
42
|
-
const farmInfoCalls = poolTokens.map(address => ({
|
|
22
|
+
static async getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, reportError, }) {
|
|
23
|
+
const poolTokens = sdk_gov_1.TypedObjectUtils.entries(currentTokenData).filter(([symbol]) => (0, sdk_gov_1.isDieselStakedToken)(symbol));
|
|
24
|
+
const farmInfoCalls = poolTokens.map(([, address]) => ({
|
|
43
25
|
address,
|
|
44
26
|
abi: types_1.iFarmingPoolAbi,
|
|
45
27
|
functionName: "farmInfo",
|
|
46
28
|
args: [],
|
|
47
29
|
}));
|
|
48
|
-
const farmSupplyCalls = poolTokens.map(address => ({
|
|
30
|
+
const farmSupplyCalls = poolTokens.map(([, address]) => ({
|
|
49
31
|
address,
|
|
50
32
|
abi: types_1.iFarmingPoolAbi,
|
|
51
33
|
functionName: "totalSupply",
|
|
52
34
|
args: [],
|
|
53
35
|
}));
|
|
54
|
-
const rewardTokenCalls = poolTokens.map(address => ({
|
|
36
|
+
const rewardTokenCalls = poolTokens.map(([, address]) => ({
|
|
55
37
|
address,
|
|
56
38
|
abi: POOL_REWARDS_ABI,
|
|
57
39
|
functionName: "rewardsToken",
|
|
58
40
|
args: [],
|
|
59
41
|
}));
|
|
42
|
+
const tokenWithExtraRewards = poolsWithExtraRewards[network] || [];
|
|
43
|
+
const chainId = sdk_gov_1.CHAINS[network];
|
|
60
44
|
const [mc, ...extra] = await Promise.allSettled([
|
|
61
45
|
provider.multicall({
|
|
62
46
|
allowFailure: false,
|
|
@@ -73,8 +57,12 @@ class GearboxRewardsApi {
|
|
|
73
57
|
...rewardTokenCalls,
|
|
74
58
|
],
|
|
75
59
|
}),
|
|
76
|
-
...
|
|
60
|
+
...tokenWithExtraRewards.map(symbol => {
|
|
77
61
|
const addr = currentTokenData[symbol];
|
|
62
|
+
if (!addr)
|
|
63
|
+
return (async () => {
|
|
64
|
+
(0, viem_1.getAddress)(addr);
|
|
65
|
+
})();
|
|
78
66
|
return axios_1.default.get(merklAPI_1.MerkleXYZApi.getRewardsCampaignsUrl({
|
|
79
67
|
params: {
|
|
80
68
|
chainId,
|
|
@@ -93,7 +81,7 @@ class GearboxRewardsApi {
|
|
|
93
81
|
const rewardTokenCallsEnd = farmSupplyCallsEnd + rewardTokenCalls.length;
|
|
94
82
|
const rewardTokens = restMCResponse.slice(farmSupplyCallsEnd, rewardTokenCallsEnd);
|
|
95
83
|
const extraRewards = extra.reduce((acc, r, index) => {
|
|
96
|
-
const stakedSymbol =
|
|
84
|
+
const stakedSymbol = tokenWithExtraRewards[index];
|
|
97
85
|
const safeResp = this.extractFulfilled(r, reportError, `merkleCampaign: ${stakedSymbol}`);
|
|
98
86
|
const l = safeResp?.data.reduce((infos, d) => {
|
|
99
87
|
const started = (0, sdk_gov_1.toBigInt)(d.startTimestamp || 0);
|
|
@@ -104,7 +92,6 @@ class GearboxRewardsApi {
|
|
|
104
92
|
const reward = (0, formatter_1.toBN)(d.amountDecimal, decimals);
|
|
105
93
|
if (rewardSymbol && reward > 0) {
|
|
106
94
|
infos.push({
|
|
107
|
-
pool: poolByStakedToken[currentTokenData[stakedSymbol]],
|
|
108
95
|
duration: (0, sdk_gov_1.toBigInt)(d.endTimestamp - d.startTimestamp),
|
|
109
96
|
finished,
|
|
110
97
|
reward,
|
|
@@ -120,12 +107,11 @@ class GearboxRewardsApi {
|
|
|
120
107
|
}
|
|
121
108
|
return acc;
|
|
122
109
|
}, {});
|
|
123
|
-
const rewardPoolsInfo = poolTokens.reduce((acc, address, i) => {
|
|
110
|
+
const rewardPoolsInfo = poolTokens.reduce((acc, [, address], i) => {
|
|
124
111
|
const currentInfo = farmInfo[i];
|
|
125
112
|
const [symbol] = (0, sdk_gov_1.extractTokenData)(rewardTokens[i] || "");
|
|
126
113
|
if (symbol) {
|
|
127
114
|
const baseReward = {
|
|
128
|
-
pool: poolByStakedToken[address],
|
|
129
115
|
duration: BigInt(currentInfo.duration),
|
|
130
116
|
finished: BigInt(currentInfo.finished),
|
|
131
117
|
reward: currentInfo.reward,
|
|
@@ -139,7 +125,7 @@ class GearboxRewardsApi {
|
|
|
139
125
|
}
|
|
140
126
|
return acc;
|
|
141
127
|
}, { base: {}, extra: {}, all: {} });
|
|
142
|
-
const rewardPoolsSupply = poolTokens.reduce((acc, address, i) => {
|
|
128
|
+
const rewardPoolsSupply = poolTokens.reduce((acc, [, address], i) => {
|
|
143
129
|
acc[address] = farmSupply[i] || 0n;
|
|
144
130
|
return acc;
|
|
145
131
|
}, {});
|
|
@@ -206,7 +192,6 @@ class GearboxRewardsApi {
|
|
|
206
192
|
const poolToken = REWARD_KEYS_RECORD[key];
|
|
207
193
|
if (poolToken && sdk_gov_1.tokenSymbolByAddress[rewardToken]) {
|
|
208
194
|
acc.push({
|
|
209
|
-
pool: baseRewardPoolsInfo[poolToken].pool,
|
|
210
195
|
poolToken,
|
|
211
196
|
rewardToken,
|
|
212
197
|
amount: (0, sdk_gov_1.toBigInt)(reason.unclaimed || 0n),
|
|
@@ -218,7 +203,6 @@ class GearboxRewardsApi {
|
|
|
218
203
|
}, []);
|
|
219
204
|
const gearboxLmRewards = poolTokens.map((address, i) => {
|
|
220
205
|
return {
|
|
221
|
-
pool: baseRewardPoolsInfo[address].pool,
|
|
222
206
|
poolToken: address,
|
|
223
207
|
rewardToken: currentTokenData[baseRewardPoolsInfo[address].symbol],
|
|
224
208
|
amount: gearboxLm[i] || 0n,
|
package/lib/index.d.ts
CHANGED
|
@@ -15,8 +15,10 @@ export * from "./core/protocols";
|
|
|
15
15
|
export * from "./core/rewardClaimer";
|
|
16
16
|
export * from "./core/strategy";
|
|
17
17
|
export * from "./core/tokenDistributor";
|
|
18
|
+
export * from "./core/trade";
|
|
18
19
|
export * from "./core/transactions";
|
|
19
20
|
export * from "./gearboxRewards";
|
|
21
|
+
export * from "./parsers/txParser";
|
|
20
22
|
export * from "./pathfinder";
|
|
21
23
|
export * from "./payload/bot";
|
|
22
24
|
export * from "./payload/creditAccount";
|