@gearbox-protocol/sdk 3.0.0-next.235 → 3.0.0-next.236
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 +13 -11
- package/lib/core/creditManager.d.ts +0 -12
- package/lib/core/creditManager.js +0 -114
- package/lib/core/pool.d.ts +0 -6
- package/lib/core/pool.js +0 -11
- package/lib/core/rewardConvex.js +1 -1
- package/lib/gearboxRewards/api.d.ts +8 -2
- package/lib/gearboxRewards/api.js +31 -15
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/pathfinder/core.d.ts +0 -14
- package/lib/pathfinder/core.js +0 -7
- package/lib/pathfinder/index.d.ts +0 -3
- package/lib/pathfinder/index.js +0 -3
- package/lib/payload/creditAccount.d.ts +4 -1
- package/lib/payload/pool.d.ts +0 -6
- package/package.json +1 -1
- package/lib/core/trade.d.ts +0 -38
- package/lib/core/trade.js +0 -110
- package/lib/parsers/ERC20Parser.d.ts +0 -8
- package/lib/parsers/ERC20Parser.js +0 -36
- package/lib/parsers/aaveV2LendingPoolAdapterParser.d.ts +0 -8
- package/lib/parsers/aaveV2LendingPoolAdapterParser.js +0 -21
- package/lib/parsers/aaveV2WrappedATokenAdapterParser.d.ts +0 -8
- package/lib/parsers/aaveV2WrappedATokenAdapterParser.js +0 -21
- package/lib/parsers/abstractParser.d.ts +0 -30
- package/lib/parsers/abstractParser.js +0 -61
- package/lib/parsers/balancerV2VaultParser.d.ts +0 -8
- package/lib/parsers/balancerV2VaultParser.js +0 -32
- package/lib/parsers/compoundV2CTokenAdapterParser.d.ts +0 -8
- package/lib/parsers/compoundV2CTokenAdapterParser.js +0 -21
- package/lib/parsers/convexBaseRewardPoolAdapterParser.d.ts +0 -10
- package/lib/parsers/convexBaseRewardPoolAdapterParser.js +0 -50
- package/lib/parsers/convexBoosterAdapterParser.d.ts +0 -10
- package/lib/parsers/convexBoosterAdapterParser.js +0 -44
- package/lib/parsers/convextRewardPoolParser.d.ts +0 -8
- package/lib/parsers/convextRewardPoolParser.js +0 -21
- package/lib/parsers/creditFacadeParser.d.ts +0 -11
- package/lib/parsers/creditFacadeParser.js +0 -84
- package/lib/parsers/creditManagerParser.d.ts +0 -7
- package/lib/parsers/creditManagerParser.js +0 -22
- package/lib/parsers/curveAdapterParser.d.ts +0 -13
- package/lib/parsers/curveAdapterParser.js +0 -124
- package/lib/parsers/erc626AdapterParser.d.ts +0 -8
- package/lib/parsers/erc626AdapterParser.js +0 -21
- package/lib/parsers/iParser.d.ts +0 -6
- package/lib/parsers/iParser.js +0 -2
- package/lib/parsers/lidoAdapterParser.d.ts +0 -8
- package/lib/parsers/lidoAdapterParser.js +0 -29
- package/lib/parsers/lidoSTETHParser.d.ts +0 -8
- package/lib/parsers/lidoSTETHParser.js +0 -36
- package/lib/parsers/priceOracleParser.d.ts +0 -7
- package/lib/parsers/priceOracleParser.js +0 -23
- package/lib/parsers/txParser.d.ts +0 -37
- package/lib/parsers/txParser.js +0 -170
- package/lib/parsers/uniV2AdapterParser.d.ts +0 -8
- package/lib/parsers/uniV2AdapterParser.js +0 -51
- package/lib/parsers/uniV2AdapterParser.spec.d.ts +0 -1
- package/lib/parsers/uniV2AdapterParser.spec.js +0 -59
- package/lib/parsers/uniV3AdapterParser.d.ts +0 -10
- package/lib/parsers/uniV3AdapterParser.js +0 -101
- package/lib/parsers/uniV3AdapterParser.spec.d.ts +0 -1
- package/lib/parsers/uniV3AdapterParser.spec.js +0 -96
- package/lib/parsers/wstETHAdapterParser.d.ts +0 -8
- package/lib/parsers/wstETHAdapterParser.js +0 -50
- package/lib/parsers/wstETHAdapterParser.spec.d.ts +0 -1
- package/lib/parsers/wstETHAdapterParser.spec.js +0 -37
- package/lib/parsers/yearnAdapterParser.spec.d.ts +0 -1
- package/lib/parsers/yearnAdapterParser.spec.js +0 -54
- package/lib/parsers/yearnV2AdapterParser.d.ts +0 -8
- package/lib/parsers/yearnV2AdapterParser.js +0 -57
- package/lib/pathfinder/balancerVault.d.ts +0 -33
- package/lib/pathfinder/balancerVault.js +0 -59
- package/lib/pathfinder/pathOptions.d.ts +0 -16
- package/lib/pathfinder/pathOptions.js +0 -93
- package/lib/pathfinder/pathOptions.spec.d.ts +0 -1
- package/lib/pathfinder/pathOptions.spec.js +0 -138
- package/lib/pathfinder/pathfinder.d.ts +0 -72
- package/lib/pathfinder/pathfinder.js +0 -176
- package/lib/pathfinder/pathfinder.spec.d.ts +0 -1
- package/lib/pathfinder/pathfinder.spec.js +0 -52
- package/lib/pathfinder/utils.d.ts +0 -34
- package/lib/pathfinder/utils.js +0 -186
|
@@ -90,15 +90,14 @@ export interface TimeToLiquidationProps {
|
|
|
90
90
|
}
|
|
91
91
|
export declare class CreditAccountData {
|
|
92
92
|
readonly isSuccessful: boolean;
|
|
93
|
-
readonly
|
|
94
|
-
readonly addr: Address;
|
|
93
|
+
readonly creditAccount: Address;
|
|
95
94
|
readonly borrower: Address;
|
|
96
95
|
readonly creditManager: Address;
|
|
97
96
|
readonly creditFacade: Address;
|
|
98
|
-
readonly
|
|
97
|
+
readonly underlying: Address;
|
|
99
98
|
readonly expirationDate: number;
|
|
100
99
|
readonly version: number;
|
|
101
|
-
readonly
|
|
100
|
+
readonly enabledTokensMask: bigint;
|
|
102
101
|
readonly healthFactor: number;
|
|
103
102
|
isDeleting: boolean;
|
|
104
103
|
readonly baseBorrowRateWithoutFee: number;
|
|
@@ -107,13 +106,14 @@ export declare class CreditAccountData {
|
|
|
107
106
|
readonly accruedFees: bigint;
|
|
108
107
|
readonly totalDebtUSD: bigint;
|
|
109
108
|
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 tokens: Record<Address, CaTokenBalance>;
|
|
117
117
|
readonly forbiddenTokens: Record<Address, true>;
|
|
118
118
|
readonly quotedTokens: Record<Address, true>;
|
|
119
119
|
constructor(payload: CreditAccountDataPayload);
|
|
@@ -10,15 +10,14 @@ exports.MAX_UINT256 = 1157920892373161954235709850086879078532699846656405640394
|
|
|
10
10
|
const MAX_UINT16 = 65535;
|
|
11
11
|
class CreditAccountData {
|
|
12
12
|
isSuccessful;
|
|
13
|
-
|
|
14
|
-
addr;
|
|
13
|
+
creditAccount;
|
|
15
14
|
borrower;
|
|
16
15
|
creditManager;
|
|
17
16
|
creditFacade;
|
|
18
|
-
|
|
17
|
+
underlying;
|
|
19
18
|
expirationDate;
|
|
20
19
|
version;
|
|
21
|
-
|
|
20
|
+
enabledTokensMask;
|
|
22
21
|
healthFactor;
|
|
23
22
|
isDeleting;
|
|
24
23
|
baseBorrowRateWithoutFee;
|
|
@@ -27,31 +26,32 @@ class CreditAccountData {
|
|
|
27
26
|
accruedFees;
|
|
28
27
|
totalDebtUSD;
|
|
29
28
|
borrowedAmountPlusInterestAndFees;
|
|
29
|
+
debt;
|
|
30
30
|
totalValue;
|
|
31
31
|
totalValueUSD;
|
|
32
32
|
twvUSD;
|
|
33
33
|
activeBots;
|
|
34
34
|
balances = {};
|
|
35
35
|
collateralTokens = [];
|
|
36
|
-
|
|
36
|
+
tokens = {};
|
|
37
37
|
forbiddenTokens = {};
|
|
38
38
|
quotedTokens = {};
|
|
39
39
|
constructor(payload) {
|
|
40
40
|
this.isSuccessful = payload.isSuccessful;
|
|
41
|
-
this.
|
|
42
|
-
this.addr = payload.addr.toLowerCase();
|
|
41
|
+
this.creditAccount = payload.addr.toLowerCase();
|
|
43
42
|
this.borrower = payload.borrower.toLowerCase();
|
|
44
43
|
this.creditManager = payload.creditManager.toLowerCase();
|
|
45
44
|
this.creditFacade = payload.creditFacade.toLowerCase();
|
|
46
|
-
this.
|
|
45
|
+
this.underlying = payload.underlying.toLowerCase();
|
|
47
46
|
this.expirationDate = Number(payload.expirationDate);
|
|
48
47
|
this.version = Number(payload.cfVersion);
|
|
49
48
|
this.healthFactor = Number(payload.healthFactor || 0n);
|
|
50
|
-
this.
|
|
49
|
+
this.enabledTokensMask = payload.enabledTokensMask;
|
|
51
50
|
this.isDeleting = false;
|
|
52
51
|
this.borrowedAmount = payload.debt;
|
|
53
52
|
this.accruedInterest = payload.accruedInterest || 0n;
|
|
54
53
|
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,6 +67,7 @@ class CreditAccountData {
|
|
|
67
67
|
payload.balances.forEach(b => {
|
|
68
68
|
const token = b.token.toLowerCase();
|
|
69
69
|
const balance = {
|
|
70
|
+
success: b.success,
|
|
70
71
|
token,
|
|
71
72
|
balance: b.balance,
|
|
72
73
|
isForbidden: b.isForbidden,
|
|
@@ -74,6 +75,7 @@ class CreditAccountData {
|
|
|
74
75
|
isQuoted: b.isQuoted,
|
|
75
76
|
quota: b.quota,
|
|
76
77
|
quotaRate: BigInt(b.quotaRate) * sdk_gov_1.PERCENTAGE_DECIMALS,
|
|
78
|
+
mask: b.mask,
|
|
77
79
|
};
|
|
78
80
|
if (!b.isForbidden) {
|
|
79
81
|
this.balances[token] = balance.balance;
|
|
@@ -85,7 +87,7 @@ class CreditAccountData {
|
|
|
85
87
|
if (b.isQuoted) {
|
|
86
88
|
this.quotedTokens[token] = true;
|
|
87
89
|
}
|
|
88
|
-
this.
|
|
90
|
+
this.tokens[token] = balance;
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
93
|
setDeleteInProgress(d) {
|
|
@@ -146,7 +148,7 @@ class CreditAccountData {
|
|
|
146
148
|
return !!this.quotedTokens[token];
|
|
147
149
|
}
|
|
148
150
|
isTokenEnabled(token) {
|
|
149
|
-
return this.
|
|
151
|
+
return this.tokens[token].isEnabled;
|
|
150
152
|
}
|
|
151
153
|
static calcMaxDebtIncrease(healthFactor, debt, underlyingLT, minHf = Number(sdk_gov_1.PERCENTAGE_FACTOR)) {
|
|
152
154
|
// HF = (TWV + d*lt) / (D + d) => d = (HF*D - TWV) / (l - HF)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Address } from "viem";
|
|
2
|
-
import { MultiCall } from "../pathfinder/core";
|
|
3
2
|
import { ChartsCreditManagerPayload, CreditManagerDataPayload, QuotaInfo } from "../payload/creditManager";
|
|
4
3
|
import { LinearModel } from "../payload/pool";
|
|
5
4
|
export type CreditManagerType = "universal" | "trade" | "farm" | "restaking";
|
|
@@ -39,18 +38,7 @@ export declare class CreditManagerData {
|
|
|
39
38
|
readonly quotas: Record<Address, QuotaInfo>;
|
|
40
39
|
readonly interestModel: LinearModel;
|
|
41
40
|
constructor(payload: CreditManagerDataPayload);
|
|
42
|
-
get id(): Address;
|
|
43
41
|
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;
|
|
54
42
|
static getTier(name: string): number;
|
|
55
43
|
static getType(name: string): CreditManagerType;
|
|
56
44
|
}
|
|
@@ -2,9 +2,6 @@
|
|
|
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");
|
|
8
5
|
class CreditManagerData {
|
|
9
6
|
address;
|
|
10
7
|
type;
|
|
@@ -116,121 +113,10 @@ class CreditManagerData {
|
|
|
116
113
|
this.collateralTokens.push(tLc);
|
|
117
114
|
this.supportedTokens[tLc] = true;
|
|
118
115
|
});
|
|
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;
|
|
130
116
|
}
|
|
131
117
|
isQuoted(token) {
|
|
132
118
|
return !!this.quotas[token];
|
|
133
119
|
}
|
|
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
|
-
}
|
|
234
120
|
static getTier(name) {
|
|
235
121
|
const DEFAULT_TIER = 99;
|
|
236
122
|
const l = name.split(" ") || [];
|
package/lib/core/pool.d.ts
CHANGED
|
@@ -21,12 +21,6 @@ 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
|
-
}>;
|
|
30
24
|
readonly quotas: Record<Address, {
|
|
31
25
|
token: Address;
|
|
32
26
|
rate: bigint;
|
package/lib/core/pool.js
CHANGED
|
@@ -26,7 +26,6 @@ class PoolData {
|
|
|
26
26
|
utilization;
|
|
27
27
|
totalBorrowed;
|
|
28
28
|
totalDebtLimit;
|
|
29
|
-
creditManagerDebtParams;
|
|
30
29
|
quotas;
|
|
31
30
|
zappers;
|
|
32
31
|
totalAssets;
|
|
@@ -62,16 +61,6 @@ class PoolData {
|
|
|
62
61
|
this.utilization = PoolData.calculateUtilization(expected, available);
|
|
63
62
|
this.totalBorrowed = payload.totalBorrowed;
|
|
64
63
|
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
|
-
}, {});
|
|
75
64
|
this.quotas = payload.quotas.reduce((acc, q) => {
|
|
76
65
|
const token = q.token.toLowerCase();
|
|
77
66
|
acc[token] = {
|
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.creditAccount, cm, network);
|
|
14
14
|
if (!prepared)
|
|
15
15
|
return [];
|
|
16
16
|
const { auraCalls, auraDistribution, convexCalls, convexDistribution } = prepared;
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { NetworkType, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { Address, PublicClient, WalletClient } from "viem";
|
|
3
|
+
import { PoolData } from "../core/pool";
|
|
3
4
|
export interface GearboxExtraMerkleLmReward {
|
|
5
|
+
pool: Address;
|
|
4
6
|
poolToken: Address;
|
|
5
7
|
rewardToken: Address;
|
|
6
8
|
amount: bigint;
|
|
7
9
|
type: "extraMerkle";
|
|
8
10
|
}
|
|
9
11
|
export interface GearboxStakedV3LmReward {
|
|
12
|
+
pool: Address;
|
|
10
13
|
poolToken: Address;
|
|
11
14
|
rewardToken: Address;
|
|
12
15
|
amount: bigint;
|
|
13
16
|
type: "stakedV3";
|
|
14
17
|
}
|
|
15
18
|
export interface GearboxMerkleV2LmReward {
|
|
16
|
-
|
|
19
|
+
pool?: undefined;
|
|
20
|
+
poolToken?: undefined;
|
|
17
21
|
rewardToken: Address;
|
|
18
22
|
amount: bigint;
|
|
19
23
|
type: "merkleV2";
|
|
@@ -29,6 +33,7 @@ export interface MerkleDistributorInfo {
|
|
|
29
33
|
}>;
|
|
30
34
|
}
|
|
31
35
|
export interface FarmInfo {
|
|
36
|
+
pool: Address;
|
|
32
37
|
finished: bigint;
|
|
33
38
|
duration: bigint;
|
|
34
39
|
reward: bigint;
|
|
@@ -38,6 +43,7 @@ export interface FarmInfo {
|
|
|
38
43
|
type PoolsWithExtraRewardsList = Record<NetworkType, Array<SupportedToken>>;
|
|
39
44
|
type ReportHandler = (e: unknown, description?: string) => void;
|
|
40
45
|
export interface GetLmRewardsInfoProps {
|
|
46
|
+
pools: Record<Address, PoolData>;
|
|
41
47
|
currentTokenData: Record<SupportedToken, Address>;
|
|
42
48
|
provider: PublicClient;
|
|
43
49
|
multicallAddress: Address;
|
|
@@ -67,7 +73,7 @@ export interface ClaimLmRewardsV3Props {
|
|
|
67
73
|
signer: WalletClient;
|
|
68
74
|
}
|
|
69
75
|
export declare class GearboxRewardsApi {
|
|
70
|
-
static getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards, network, reportError, }: GetLmRewardsInfoProps): Promise<{
|
|
76
|
+
static getLmRewardsInfo({ pools, currentTokenData, provider, multicallAddress, poolsWithExtraRewards, network, reportError, }: GetLmRewardsInfoProps): Promise<{
|
|
71
77
|
rewardPoolsInfo: Record<string, FarmInfo[]>;
|
|
72
78
|
baseRewardPoolsInfo: Record<string, FarmInfo>;
|
|
73
79
|
extraRewardPoolsInfo: Record<string, FarmInfo[]>;
|
|
@@ -19,28 +19,44 @@ const DEFAULT_POOLS_WITH_EXTRA_REWARDS = {
|
|
|
19
19
|
Base: [],
|
|
20
20
|
};
|
|
21
21
|
class GearboxRewardsApi {
|
|
22
|
-
static async getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, reportError, }) {
|
|
23
|
-
const
|
|
24
|
-
|
|
22
|
+
static async getLmRewardsInfo({ pools, currentTokenData, provider, multicallAddress, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, reportError, }) {
|
|
23
|
+
const poolByStakedToken = Object.values(pools).reduce((acc, p) => {
|
|
24
|
+
p.stakedDieselToken.forEach(t => {
|
|
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 => ({
|
|
25
43
|
address,
|
|
26
44
|
abi: types_1.iFarmingPoolAbi,
|
|
27
45
|
functionName: "farmInfo",
|
|
28
46
|
args: [],
|
|
29
47
|
}));
|
|
30
|
-
const farmSupplyCalls = poolTokens.map(
|
|
48
|
+
const farmSupplyCalls = poolTokens.map(address => ({
|
|
31
49
|
address,
|
|
32
50
|
abi: types_1.iFarmingPoolAbi,
|
|
33
51
|
functionName: "totalSupply",
|
|
34
52
|
args: [],
|
|
35
53
|
}));
|
|
36
|
-
const rewardTokenCalls = poolTokens.map(
|
|
54
|
+
const rewardTokenCalls = poolTokens.map(address => ({
|
|
37
55
|
address,
|
|
38
56
|
abi: POOL_REWARDS_ABI,
|
|
39
57
|
functionName: "rewardsToken",
|
|
40
58
|
args: [],
|
|
41
59
|
}));
|
|
42
|
-
const tokenWithExtraRewards = poolsWithExtraRewards[network] || [];
|
|
43
|
-
const chainId = sdk_gov_1.CHAINS[network];
|
|
44
60
|
const [mc, ...extra] = await Promise.allSettled([
|
|
45
61
|
provider.multicall({
|
|
46
62
|
allowFailure: false,
|
|
@@ -57,12 +73,8 @@ class GearboxRewardsApi {
|
|
|
57
73
|
...rewardTokenCalls,
|
|
58
74
|
],
|
|
59
75
|
}),
|
|
60
|
-
...
|
|
76
|
+
...poolTokensWithExtraReward.map(symbol => {
|
|
61
77
|
const addr = currentTokenData[symbol];
|
|
62
|
-
if (!addr)
|
|
63
|
-
return (async () => {
|
|
64
|
-
(0, viem_1.getAddress)(addr);
|
|
65
|
-
})();
|
|
66
78
|
return axios_1.default.get(merklAPI_1.MerkleXYZApi.getRewardsCampaignsUrl({
|
|
67
79
|
params: {
|
|
68
80
|
chainId,
|
|
@@ -81,7 +93,7 @@ class GearboxRewardsApi {
|
|
|
81
93
|
const rewardTokenCallsEnd = farmSupplyCallsEnd + rewardTokenCalls.length;
|
|
82
94
|
const rewardTokens = restMCResponse.slice(farmSupplyCallsEnd, rewardTokenCallsEnd);
|
|
83
95
|
const extraRewards = extra.reduce((acc, r, index) => {
|
|
84
|
-
const stakedSymbol =
|
|
96
|
+
const stakedSymbol = poolTokensWithExtraReward[index];
|
|
85
97
|
const safeResp = this.extractFulfilled(r, reportError, `merkleCampaign: ${stakedSymbol}`);
|
|
86
98
|
const l = safeResp?.data.reduce((infos, d) => {
|
|
87
99
|
const started = (0, sdk_gov_1.toBigInt)(d.startTimestamp || 0);
|
|
@@ -92,6 +104,7 @@ class GearboxRewardsApi {
|
|
|
92
104
|
const reward = (0, formatter_1.toBN)(d.amountDecimal, decimals);
|
|
93
105
|
if (rewardSymbol && reward > 0) {
|
|
94
106
|
infos.push({
|
|
107
|
+
pool: poolByStakedToken[currentTokenData[stakedSymbol]],
|
|
95
108
|
duration: (0, sdk_gov_1.toBigInt)(d.endTimestamp - d.startTimestamp),
|
|
96
109
|
finished,
|
|
97
110
|
reward,
|
|
@@ -107,11 +120,12 @@ class GearboxRewardsApi {
|
|
|
107
120
|
}
|
|
108
121
|
return acc;
|
|
109
122
|
}, {});
|
|
110
|
-
const rewardPoolsInfo = poolTokens.reduce((acc,
|
|
123
|
+
const rewardPoolsInfo = poolTokens.reduce((acc, address, i) => {
|
|
111
124
|
const currentInfo = farmInfo[i];
|
|
112
125
|
const [symbol] = (0, sdk_gov_1.extractTokenData)(rewardTokens[i] || "");
|
|
113
126
|
if (symbol) {
|
|
114
127
|
const baseReward = {
|
|
128
|
+
pool: poolByStakedToken[address],
|
|
115
129
|
duration: BigInt(currentInfo.duration),
|
|
116
130
|
finished: BigInt(currentInfo.finished),
|
|
117
131
|
reward: currentInfo.reward,
|
|
@@ -125,7 +139,7 @@ class GearboxRewardsApi {
|
|
|
125
139
|
}
|
|
126
140
|
return acc;
|
|
127
141
|
}, { base: {}, extra: {}, all: {} });
|
|
128
|
-
const rewardPoolsSupply = poolTokens.reduce((acc,
|
|
142
|
+
const rewardPoolsSupply = poolTokens.reduce((acc, address, i) => {
|
|
129
143
|
acc[address] = farmSupply[i] || 0n;
|
|
130
144
|
return acc;
|
|
131
145
|
}, {});
|
|
@@ -192,6 +206,7 @@ class GearboxRewardsApi {
|
|
|
192
206
|
const poolToken = REWARD_KEYS_RECORD[key];
|
|
193
207
|
if (poolToken && sdk_gov_1.tokenSymbolByAddress[rewardToken]) {
|
|
194
208
|
acc.push({
|
|
209
|
+
pool: baseRewardPoolsInfo[poolToken].pool,
|
|
195
210
|
poolToken,
|
|
196
211
|
rewardToken,
|
|
197
212
|
amount: (0, sdk_gov_1.toBigInt)(reason.unclaimed || 0n),
|
|
@@ -203,6 +218,7 @@ class GearboxRewardsApi {
|
|
|
203
218
|
}, []);
|
|
204
219
|
const gearboxLmRewards = poolTokens.map((address, i) => {
|
|
205
220
|
return {
|
|
221
|
+
pool: baseRewardPoolsInfo[address].pool,
|
|
206
222
|
poolToken: address,
|
|
207
223
|
rewardToken: currentTokenData[baseRewardPoolsInfo[address].symbol],
|
|
208
224
|
amount: gearboxLm[i] || 0n,
|
package/lib/index.d.ts
CHANGED
|
@@ -15,10 +15,8 @@ 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";
|
|
19
18
|
export * from "./core/transactions";
|
|
20
19
|
export * from "./gearboxRewards";
|
|
21
|
-
export * from "./parsers/txParser";
|
|
22
20
|
export * from "./pathfinder";
|
|
23
21
|
export * from "./payload/bot";
|
|
24
22
|
export * from "./payload/creditAccount";
|
package/lib/index.js
CHANGED
|
@@ -31,10 +31,8 @@ __exportStar(require("./core/protocols"), exports);
|
|
|
31
31
|
__exportStar(require("./core/rewardClaimer"), exports);
|
|
32
32
|
__exportStar(require("./core/strategy"), exports);
|
|
33
33
|
__exportStar(require("./core/tokenDistributor"), exports);
|
|
34
|
-
__exportStar(require("./core/trade"), exports);
|
|
35
34
|
__exportStar(require("./core/transactions"), exports);
|
|
36
35
|
__exportStar(require("./gearboxRewards"), exports);
|
|
37
|
-
__exportStar(require("./parsers/txParser"), exports);
|
|
38
36
|
__exportStar(require("./pathfinder"), exports);
|
|
39
37
|
__exportStar(require("./payload/bot"), exports);
|
|
40
38
|
__exportStar(require("./payload/creditAccount"), exports);
|
package/lib/pathfinder/core.d.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
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
|
-
}
|
|
7
2
|
export interface MultiCall {
|
|
8
3
|
target: Address;
|
|
9
4
|
callData: Address;
|
|
10
5
|
}
|
|
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
|
-
}
|
|
20
6
|
export interface PathFinderResult {
|
|
21
7
|
amount: bigint;
|
|
22
8
|
minAmount: bigint;
|
package/lib/pathfinder/core.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
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,6 +15,3 @@ 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);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Address } from "viem";
|
|
2
2
|
export interface CaTokenBalance {
|
|
3
|
+
success: boolean;
|
|
3
4
|
token: Address;
|
|
4
5
|
balance: bigint;
|
|
5
6
|
isForbidden: boolean;
|
|
@@ -7,10 +8,10 @@ export interface CaTokenBalance {
|
|
|
7
8
|
isQuoted: boolean;
|
|
8
9
|
quota: bigint;
|
|
9
10
|
quotaRate: bigint;
|
|
11
|
+
mask: bigint;
|
|
10
12
|
}
|
|
11
13
|
export interface CreditAccountDataPayload {
|
|
12
14
|
isSuccessful: boolean;
|
|
13
|
-
priceFeedsNeeded: readonly Address[];
|
|
14
15
|
addr: Address;
|
|
15
16
|
borrower: Address;
|
|
16
17
|
creditManager: Address;
|
|
@@ -27,6 +28,7 @@ export interface CreditAccountDataPayload {
|
|
|
27
28
|
healthFactor: bigint;
|
|
28
29
|
baseBorrowRate: bigint;
|
|
29
30
|
balances: readonly {
|
|
31
|
+
success: boolean;
|
|
30
32
|
token: Address;
|
|
31
33
|
balance: bigint;
|
|
32
34
|
isForbidden: boolean;
|
|
@@ -34,6 +36,7 @@ export interface CreditAccountDataPayload {
|
|
|
34
36
|
isQuoted: boolean;
|
|
35
37
|
quota: bigint;
|
|
36
38
|
quotaRate: number;
|
|
39
|
+
mask: bigint;
|
|
37
40
|
}[];
|
|
38
41
|
cfVersion: bigint;
|
|
39
42
|
expirationDate: number;
|
package/lib/payload/pool.d.ts
CHANGED
|
@@ -42,12 +42,6 @@ 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
|
-
}[];
|
|
51
45
|
}
|
|
52
46
|
export interface PoolDataExtraPayload {
|
|
53
47
|
stakedDieselToken: Array<Address>;
|
package/package.json
CHANGED
package/lib/core/trade.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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 {};
|