@gearbox-protocol/sdk 7.5.0-next.1 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/sdk/router/RouterV310Contract.js +24 -1
- package/dist/cjs/sdk/sdk-legacy/core/creditAccount.js +5 -4
- package/dist/cjs/sdk/sdk-legacy/core/creditManager.js +0 -4
- package/dist/cjs/sdk/sdk-legacy/core/pool.js +11 -4
- package/dist/cjs/sdk/sdk-legacy/core/transactions.js +0 -28
- package/dist/cjs/sdk/sdk-legacy/gearboxRewards/extraAPY.js +4 -5
- package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +10 -0
- package/dist/esm/sdk/router/RouterV310Contract.js +24 -1
- package/dist/esm/sdk/sdk-legacy/core/creditAccount.js +5 -4
- package/dist/esm/sdk/sdk-legacy/core/creditManager.js +0 -4
- package/dist/esm/sdk/sdk-legacy/core/pool.js +11 -4
- package/dist/esm/sdk/sdk-legacy/core/transactions.js +0 -27
- package/dist/esm/sdk/sdk-legacy/gearboxRewards/extraAPY.js +4 -5
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +10 -0
- package/dist/types/sdk/router/RouterV310Contract.d.ts +11 -0
- package/dist/types/sdk/sdk-legacy/core/creditAccount.d.ts +2 -3
- package/dist/types/sdk/sdk-legacy/core/creditManager.d.ts +0 -3
- package/dist/types/sdk/sdk-legacy/core/pool.d.ts +4 -3
- package/dist/types/sdk/sdk-legacy/core/transactions.d.ts +1 -15
- package/dist/types/sdk/sdk-legacy/payload/creditAccount.d.ts +0 -3
- package/dist/types/sdk/sdk-legacy/payload/creditManager.d.ts +0 -3
- package/dist/types/sdk/sdk-legacy/payload/pool.d.ts +0 -3
- package/package.json +1 -1
|
@@ -31,6 +31,8 @@ var import_helpers = require("./helpers.js");
|
|
|
31
31
|
const abi = import_routerV310.iGearboxRouterV310Abi;
|
|
32
32
|
const ERR_NOT_IMPLEMENTED = new Error("Not implemented in router v3.1");
|
|
33
33
|
class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterContract {
|
|
34
|
+
#numSplits = new import_AddressMap.AddressMap();
|
|
35
|
+
#defaultNumSplits = 4n;
|
|
34
36
|
constructor(sdk, address, version) {
|
|
35
37
|
super(sdk, {
|
|
36
38
|
addr: address,
|
|
@@ -199,6 +201,21 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
199
201
|
calls: [...result.calls]
|
|
200
202
|
};
|
|
201
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* v310-specific method to set explicitly number of splits for a token
|
|
206
|
+
* @param token
|
|
207
|
+
* @param numSplits
|
|
208
|
+
*/
|
|
209
|
+
setNumSplits(token, numSplits) {
|
|
210
|
+
this.#numSplits.upsert(token, numSplits);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* v310-specific method to set default number of splits for a token
|
|
214
|
+
* @param numSplits
|
|
215
|
+
*/
|
|
216
|
+
setDefaultNumSplits(numSplits) {
|
|
217
|
+
this.#defaultNumSplits = numSplits;
|
|
218
|
+
}
|
|
202
219
|
#numSplitsGetter(creditManager, assets) {
|
|
203
220
|
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(
|
|
204
221
|
creditManager.address
|
|
@@ -223,8 +240,14 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
223
240
|
"balances in usd"
|
|
224
241
|
);
|
|
225
242
|
const map = new import_AddressMap.AddressMap(
|
|
226
|
-
inUSD.map(({ token }, i) => [
|
|
243
|
+
inUSD.map(({ token }, i) => [
|
|
244
|
+
token,
|
|
245
|
+
i === 0 ? this.#defaultNumSplits : 1n
|
|
246
|
+
])
|
|
227
247
|
);
|
|
248
|
+
for (const [token, numSplits] of this.#numSplits.entries()) {
|
|
249
|
+
map.upsert(token, numSplits);
|
|
250
|
+
}
|
|
228
251
|
return (token) => map.get(token) ?? 1n;
|
|
229
252
|
}
|
|
230
253
|
#debugTokenData(tData) {
|
|
@@ -28,8 +28,6 @@ var import_price = require("../utils/price.js");
|
|
|
28
28
|
const MAX_UINT16 = 65535;
|
|
29
29
|
class CreditAccountData_Legacy {
|
|
30
30
|
isSuccessful;
|
|
31
|
-
chainId;
|
|
32
|
-
network;
|
|
33
31
|
creditAccount;
|
|
34
32
|
borrower;
|
|
35
33
|
creditManager;
|
|
@@ -40,6 +38,7 @@ class CreditAccountData_Legacy {
|
|
|
40
38
|
version;
|
|
41
39
|
enabledTokensMask;
|
|
42
40
|
healthFactor;
|
|
41
|
+
isDeleting;
|
|
43
42
|
baseBorrowRateWithoutFee;
|
|
44
43
|
borrowedAmount;
|
|
45
44
|
accruedInterest;
|
|
@@ -57,8 +56,6 @@ class CreditAccountData_Legacy {
|
|
|
57
56
|
quotedTokens = {};
|
|
58
57
|
constructor(payload) {
|
|
59
58
|
this.isSuccessful = payload.isSuccessful;
|
|
60
|
-
this.chainId = payload.chainId;
|
|
61
|
-
this.network = payload.network;
|
|
62
59
|
this.creditAccount = payload.addr.toLowerCase();
|
|
63
60
|
this.borrower = payload.borrower.toLowerCase();
|
|
64
61
|
this.creditManager = payload.creditManager.toLowerCase();
|
|
@@ -71,6 +68,7 @@ class CreditAccountData_Legacy {
|
|
|
71
68
|
(payload.healthFactor || 0n) * import_constants.PERCENTAGE_FACTOR / import_constants.WAD
|
|
72
69
|
);
|
|
73
70
|
this.enabledTokensMask = payload.enabledTokensMask;
|
|
71
|
+
this.isDeleting = false;
|
|
74
72
|
this.borrowedAmount = payload.debt;
|
|
75
73
|
this.accruedInterest = payload.accruedInterest || 0n;
|
|
76
74
|
this.accruedFees = payload.accruedFees || 0n;
|
|
@@ -109,6 +107,9 @@ class CreditAccountData_Legacy {
|
|
|
109
107
|
this.tokens[token] = balance;
|
|
110
108
|
});
|
|
111
109
|
}
|
|
110
|
+
setDeleteInProgress(d) {
|
|
111
|
+
this.isDeleting = d;
|
|
112
|
+
}
|
|
112
113
|
static sortBalances(balances, prices, tokens) {
|
|
113
114
|
return Object.entries(balances).sort(
|
|
114
115
|
([addr1, amount1], [addr2, amount2]) => {
|
|
@@ -26,8 +26,6 @@ var import_constants = require("../../constants/index.js");
|
|
|
26
26
|
var import_utils = require("../../utils/index.js");
|
|
27
27
|
class CreditManagerData_Legacy {
|
|
28
28
|
address;
|
|
29
|
-
chainId;
|
|
30
|
-
network;
|
|
31
29
|
underlyingToken;
|
|
32
30
|
pool;
|
|
33
31
|
creditFacade;
|
|
@@ -69,8 +67,6 @@ class CreditManagerData_Legacy {
|
|
|
69
67
|
quotas;
|
|
70
68
|
constructor(payload) {
|
|
71
69
|
this.address = payload.addr.toLowerCase();
|
|
72
|
-
this.chainId = payload.chainId;
|
|
73
|
-
this.network = payload.network;
|
|
74
70
|
this.underlyingToken = payload.underlying.toLowerCase();
|
|
75
71
|
this.name = payload.name;
|
|
76
72
|
this.pool = payload.pool.toLowerCase();
|
|
@@ -30,8 +30,7 @@ var import_utils = require("../../utils/index.js");
|
|
|
30
30
|
var import_formatter = require("../utils/formatter.js");
|
|
31
31
|
class PoolData_Legacy {
|
|
32
32
|
address;
|
|
33
|
-
|
|
34
|
-
network;
|
|
33
|
+
type;
|
|
35
34
|
underlyingToken;
|
|
36
35
|
dieselToken;
|
|
37
36
|
stakedDieselToken;
|
|
@@ -63,8 +62,7 @@ class PoolData_Legacy {
|
|
|
63
62
|
lastBaseInterestUpdate;
|
|
64
63
|
constructor(payload, extra) {
|
|
65
64
|
this.address = payload.addr.toLowerCase();
|
|
66
|
-
this.
|
|
67
|
-
this.network = payload.network;
|
|
65
|
+
this.type = PoolData_Legacy.getPoolType(payload.name || "");
|
|
68
66
|
this.underlyingToken = payload.underlying.toLowerCase();
|
|
69
67
|
this.dieselToken = payload.dieselToken.toLowerCase();
|
|
70
68
|
this.stakedDieselToken = (extra.stakedDieselToken || []).map(
|
|
@@ -153,6 +151,13 @@ class PoolData_Legacy {
|
|
|
153
151
|
});
|
|
154
152
|
return model.read.calcBorrowRate([expectedLiquidity, availableLiquidity]);
|
|
155
153
|
}
|
|
154
|
+
static getPoolType(name) {
|
|
155
|
+
const [identity = ""] = name.split(" ") || [];
|
|
156
|
+
const lc = identity.toLowerCase();
|
|
157
|
+
if (lc === "farm") return "farm";
|
|
158
|
+
if (lc === "trade") return "trade";
|
|
159
|
+
return "universal";
|
|
160
|
+
}
|
|
156
161
|
static calculateUtilization(expected, available) {
|
|
157
162
|
if (expected === 0n) return 0;
|
|
158
163
|
const borrowed = expected - available;
|
|
@@ -164,6 +169,7 @@ class ChartsPoolData {
|
|
|
164
169
|
address;
|
|
165
170
|
underlyingToken;
|
|
166
171
|
dieselToken;
|
|
172
|
+
type;
|
|
167
173
|
version;
|
|
168
174
|
name;
|
|
169
175
|
addLiqCount;
|
|
@@ -216,6 +222,7 @@ class ChartsPoolData {
|
|
|
216
222
|
this.address = (payload.addr || "").toLowerCase();
|
|
217
223
|
this.underlyingToken = (payload.underlyingToken || "").toLowerCase();
|
|
218
224
|
this.dieselToken = (payload.dieselToken || "").toLowerCase();
|
|
225
|
+
this.type = PoolData_Legacy.getPoolType(payload.name || "");
|
|
219
226
|
this.version = payload.version || 1;
|
|
220
227
|
this.name = payload.name || "";
|
|
221
228
|
this.earned7D = payload.earned7D || 0;
|
|
@@ -28,7 +28,6 @@ __export(transactions_exports, {
|
|
|
28
28
|
TxCloseAccount: () => TxCloseAccount,
|
|
29
29
|
TxDecreaseBorrowAmount: () => TxDecreaseBorrowAmount,
|
|
30
30
|
TxEnableTokens: () => TxEnableTokens,
|
|
31
|
-
TxFillOrder: () => TxFillOrder,
|
|
32
31
|
TxGaugeClaim: () => TxGaugeClaim,
|
|
33
32
|
TxGaugeStake: () => TxGaugeStake,
|
|
34
33
|
TxGaugeUnstake: () => TxGaugeUnstake,
|
|
@@ -106,8 +105,6 @@ class TxSerializer {
|
|
|
106
105
|
return new TxUnstakeDiesel(params);
|
|
107
106
|
case "TxEnableTokens":
|
|
108
107
|
return new TxEnableTokens(params);
|
|
109
|
-
case "TxFillOrder":
|
|
110
|
-
return new TxFillOrder(params);
|
|
111
108
|
default:
|
|
112
109
|
throw new Error(`Unknown transaction for parsing: ${e.type}`);
|
|
113
110
|
}
|
|
@@ -644,30 +641,6 @@ class TxEnableTokens extends import_eventOrTx.EVMTx {
|
|
|
644
641
|
};
|
|
645
642
|
}
|
|
646
643
|
}
|
|
647
|
-
class TxFillOrder extends import_eventOrTx.EVMTx {
|
|
648
|
-
amount;
|
|
649
|
-
token;
|
|
650
|
-
network;
|
|
651
|
-
constructor(opts) {
|
|
652
|
-
super(opts);
|
|
653
|
-
this.amount = opts.amount;
|
|
654
|
-
this.token = opts.tokensList[opts.token];
|
|
655
|
-
this.network = opts.network;
|
|
656
|
-
}
|
|
657
|
-
toString() {
|
|
658
|
-
const { title, decimals = 18 } = this.token;
|
|
659
|
-
return `Order opened [${this.network}]: ${(0, import_utils.formatBN)(
|
|
660
|
-
this.amount,
|
|
661
|
-
decimals
|
|
662
|
-
)} ${title}`;
|
|
663
|
-
}
|
|
664
|
-
serialize() {
|
|
665
|
-
return {
|
|
666
|
-
type: "TxFillOrder",
|
|
667
|
-
content: JSON.stringify(this)
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
644
|
// Annotate the CommonJS export names for ESM import in node:
|
|
672
645
|
0 && (module.exports = {
|
|
673
646
|
TXSwap,
|
|
@@ -680,7 +653,6 @@ class TxFillOrder extends import_eventOrTx.EVMTx {
|
|
|
680
653
|
TxCloseAccount,
|
|
681
654
|
TxDecreaseBorrowAmount,
|
|
682
655
|
TxEnableTokens,
|
|
683
|
-
TxFillOrder,
|
|
684
656
|
TxGaugeClaim,
|
|
685
657
|
TxGaugeStake,
|
|
686
658
|
TxGaugeUnstake,
|
|
@@ -86,7 +86,7 @@ class GearboxRewardsExtraApy {
|
|
|
86
86
|
pointsInfo2
|
|
87
87
|
);
|
|
88
88
|
if (points !== null) {
|
|
89
|
-
acc2.push({ balance: points, token:
|
|
89
|
+
acc2.push({ balance: points, token: tokenBalance.token });
|
|
90
90
|
}
|
|
91
91
|
return acc2;
|
|
92
92
|
},
|
|
@@ -98,15 +98,14 @@ class GearboxRewardsExtraApy {
|
|
|
98
98
|
return r;
|
|
99
99
|
}
|
|
100
100
|
static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
|
|
101
|
-
if (!tokenBalanceInPool
|
|
102
|
-
return null;
|
|
101
|
+
if (!tokenBalanceInPool) return null;
|
|
103
102
|
if (pool.expectedLiquidity <= 0) return 0n;
|
|
104
|
-
const { decimals = 18 } = tokensList[
|
|
103
|
+
const { decimals = 18 } = tokensList[tokenBalanceInPool.token] || {};
|
|
105
104
|
const targetFactor = 10n ** BigInt(decimals);
|
|
106
105
|
const { decimals: underlyingDecimals = 18 } = tokensList[pool.underlyingToken] || {};
|
|
107
106
|
const underlyingFactor = 10n ** BigInt(underlyingDecimals);
|
|
108
107
|
const defaultPoints = pointsInfo.amount * targetFactor / import_constants.PERCENTAGE_FACTOR;
|
|
109
|
-
const points = pointsInfo.estimation === "absolute" ? defaultPoints :
|
|
108
|
+
const points = pointsInfo.estimation === "absolute" ? defaultPoints : tokenBalanceInPool.balance * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
|
|
110
109
|
return import_math.BigIntMath.min(points, defaultPoints);
|
|
111
110
|
}
|
|
112
111
|
static getPoolPointsTip(poolRewards, pool, token) {
|
|
@@ -157,6 +157,16 @@ function getSimulateWithPriceUpdatesError(cause, priceUpdates, calls, results, r
|
|
|
157
157
|
const call = calls[i];
|
|
158
158
|
return [extractCallError(c), `${call.address}.${call.functionName}`].filter(Boolean).join(" ");
|
|
159
159
|
});
|
|
160
|
+
if (results[0]?.status === "failure") {
|
|
161
|
+
prettyCalls.unshift(
|
|
162
|
+
`get timestamp failed: ${extractCallError(results[0])}`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
if (results[1]?.status === "failure") {
|
|
166
|
+
prettyCalls.unshift(
|
|
167
|
+
`get block number failed: ${extractCallError(results[1])}`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
160
170
|
return new SimulateWithPriceUpdatesError(cause, {
|
|
161
171
|
timestamp,
|
|
162
172
|
priceUpdates: prettyPriceUpdates,
|
|
@@ -8,6 +8,8 @@ import { assetsMap, balancesMap } from "./helpers.js";
|
|
|
8
8
|
const abi = iGearboxRouterV310Abi;
|
|
9
9
|
const ERR_NOT_IMPLEMENTED = new Error("Not implemented in router v3.1");
|
|
10
10
|
class RouterV310Contract extends AbstractRouterContract {
|
|
11
|
+
#numSplits = new AddressMap();
|
|
12
|
+
#defaultNumSplits = 4n;
|
|
11
13
|
constructor(sdk, address, version) {
|
|
12
14
|
super(sdk, {
|
|
13
15
|
addr: address,
|
|
@@ -176,6 +178,21 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
176
178
|
calls: [...result.calls]
|
|
177
179
|
};
|
|
178
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* v310-specific method to set explicitly number of splits for a token
|
|
183
|
+
* @param token
|
|
184
|
+
* @param numSplits
|
|
185
|
+
*/
|
|
186
|
+
setNumSplits(token, numSplits) {
|
|
187
|
+
this.#numSplits.upsert(token, numSplits);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* v310-specific method to set default number of splits for a token
|
|
191
|
+
* @param numSplits
|
|
192
|
+
*/
|
|
193
|
+
setDefaultNumSplits(numSplits) {
|
|
194
|
+
this.#defaultNumSplits = numSplits;
|
|
195
|
+
}
|
|
179
196
|
#numSplitsGetter(creditManager, assets) {
|
|
180
197
|
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(
|
|
181
198
|
creditManager.address
|
|
@@ -200,8 +217,14 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
200
217
|
"balances in usd"
|
|
201
218
|
);
|
|
202
219
|
const map = new AddressMap(
|
|
203
|
-
inUSD.map(({ token }, i) => [
|
|
220
|
+
inUSD.map(({ token }, i) => [
|
|
221
|
+
token,
|
|
222
|
+
i === 0 ? this.#defaultNumSplits : 1n
|
|
223
|
+
])
|
|
204
224
|
);
|
|
225
|
+
for (const [token, numSplits] of this.#numSplits.entries()) {
|
|
226
|
+
map.upsert(token, numSplits);
|
|
227
|
+
}
|
|
205
228
|
return (token) => map.get(token) ?? 1n;
|
|
206
229
|
}
|
|
207
230
|
#debugTokenData(tData) {
|
|
@@ -14,8 +14,6 @@ import { PriceUtils } from "../utils/price.js";
|
|
|
14
14
|
const MAX_UINT16 = 65535;
|
|
15
15
|
class CreditAccountData_Legacy {
|
|
16
16
|
isSuccessful;
|
|
17
|
-
chainId;
|
|
18
|
-
network;
|
|
19
17
|
creditAccount;
|
|
20
18
|
borrower;
|
|
21
19
|
creditManager;
|
|
@@ -26,6 +24,7 @@ class CreditAccountData_Legacy {
|
|
|
26
24
|
version;
|
|
27
25
|
enabledTokensMask;
|
|
28
26
|
healthFactor;
|
|
27
|
+
isDeleting;
|
|
29
28
|
baseBorrowRateWithoutFee;
|
|
30
29
|
borrowedAmount;
|
|
31
30
|
accruedInterest;
|
|
@@ -43,8 +42,6 @@ class CreditAccountData_Legacy {
|
|
|
43
42
|
quotedTokens = {};
|
|
44
43
|
constructor(payload) {
|
|
45
44
|
this.isSuccessful = payload.isSuccessful;
|
|
46
|
-
this.chainId = payload.chainId;
|
|
47
|
-
this.network = payload.network;
|
|
48
45
|
this.creditAccount = payload.addr.toLowerCase();
|
|
49
46
|
this.borrower = payload.borrower.toLowerCase();
|
|
50
47
|
this.creditManager = payload.creditManager.toLowerCase();
|
|
@@ -57,6 +54,7 @@ class CreditAccountData_Legacy {
|
|
|
57
54
|
(payload.healthFactor || 0n) * PERCENTAGE_FACTOR / WAD
|
|
58
55
|
);
|
|
59
56
|
this.enabledTokensMask = payload.enabledTokensMask;
|
|
57
|
+
this.isDeleting = false;
|
|
60
58
|
this.borrowedAmount = payload.debt;
|
|
61
59
|
this.accruedInterest = payload.accruedInterest || 0n;
|
|
62
60
|
this.accruedFees = payload.accruedFees || 0n;
|
|
@@ -95,6 +93,9 @@ class CreditAccountData_Legacy {
|
|
|
95
93
|
this.tokens[token] = balance;
|
|
96
94
|
});
|
|
97
95
|
}
|
|
96
|
+
setDeleteInProgress(d) {
|
|
97
|
+
this.isDeleting = d;
|
|
98
|
+
}
|
|
98
99
|
static sortBalances(balances, prices, tokens) {
|
|
99
100
|
return Object.entries(balances).sort(
|
|
100
101
|
([addr1, amount1], [addr2, amount2]) => {
|
|
@@ -6,8 +6,6 @@ import {
|
|
|
6
6
|
import { toBigInt } from "../../utils/index.js";
|
|
7
7
|
class CreditManagerData_Legacy {
|
|
8
8
|
address;
|
|
9
|
-
chainId;
|
|
10
|
-
network;
|
|
11
9
|
underlyingToken;
|
|
12
10
|
pool;
|
|
13
11
|
creditFacade;
|
|
@@ -49,8 +47,6 @@ class CreditManagerData_Legacy {
|
|
|
49
47
|
quotas;
|
|
50
48
|
constructor(payload) {
|
|
51
49
|
this.address = payload.addr.toLowerCase();
|
|
52
|
-
this.chainId = payload.chainId;
|
|
53
|
-
this.network = payload.network;
|
|
54
50
|
this.underlyingToken = payload.underlying.toLowerCase();
|
|
55
51
|
this.name = payload.name;
|
|
56
52
|
this.pool = payload.pool.toLowerCase();
|
|
@@ -8,8 +8,7 @@ import { toBigInt } from "../../utils/index.js";
|
|
|
8
8
|
import { rayToNumber } from "../utils/formatter.js";
|
|
9
9
|
class PoolData_Legacy {
|
|
10
10
|
address;
|
|
11
|
-
|
|
12
|
-
network;
|
|
11
|
+
type;
|
|
13
12
|
underlyingToken;
|
|
14
13
|
dieselToken;
|
|
15
14
|
stakedDieselToken;
|
|
@@ -41,8 +40,7 @@ class PoolData_Legacy {
|
|
|
41
40
|
lastBaseInterestUpdate;
|
|
42
41
|
constructor(payload, extra) {
|
|
43
42
|
this.address = payload.addr.toLowerCase();
|
|
44
|
-
this.
|
|
45
|
-
this.network = payload.network;
|
|
43
|
+
this.type = PoolData_Legacy.getPoolType(payload.name || "");
|
|
46
44
|
this.underlyingToken = payload.underlying.toLowerCase();
|
|
47
45
|
this.dieselToken = payload.dieselToken.toLowerCase();
|
|
48
46
|
this.stakedDieselToken = (extra.stakedDieselToken || []).map(
|
|
@@ -131,6 +129,13 @@ class PoolData_Legacy {
|
|
|
131
129
|
});
|
|
132
130
|
return model.read.calcBorrowRate([expectedLiquidity, availableLiquidity]);
|
|
133
131
|
}
|
|
132
|
+
static getPoolType(name) {
|
|
133
|
+
const [identity = ""] = name.split(" ") || [];
|
|
134
|
+
const lc = identity.toLowerCase();
|
|
135
|
+
if (lc === "farm") return "farm";
|
|
136
|
+
if (lc === "trade") return "trade";
|
|
137
|
+
return "universal";
|
|
138
|
+
}
|
|
134
139
|
static calculateUtilization(expected, available) {
|
|
135
140
|
if (expected === 0n) return 0;
|
|
136
141
|
const borrowed = expected - available;
|
|
@@ -142,6 +147,7 @@ class ChartsPoolData {
|
|
|
142
147
|
address;
|
|
143
148
|
underlyingToken;
|
|
144
149
|
dieselToken;
|
|
150
|
+
type;
|
|
145
151
|
version;
|
|
146
152
|
name;
|
|
147
153
|
addLiqCount;
|
|
@@ -194,6 +200,7 @@ class ChartsPoolData {
|
|
|
194
200
|
this.address = (payload.addr || "").toLowerCase();
|
|
195
201
|
this.underlyingToken = (payload.underlyingToken || "").toLowerCase();
|
|
196
202
|
this.dieselToken = (payload.dieselToken || "").toLowerCase();
|
|
203
|
+
this.type = PoolData_Legacy.getPoolType(payload.name || "");
|
|
197
204
|
this.version = payload.version || 1;
|
|
198
205
|
this.name = payload.name || "";
|
|
199
206
|
this.earned7D = payload.earned7D || 0;
|
|
@@ -58,8 +58,6 @@ class TxSerializer {
|
|
|
58
58
|
return new TxUnstakeDiesel(params);
|
|
59
59
|
case "TxEnableTokens":
|
|
60
60
|
return new TxEnableTokens(params);
|
|
61
|
-
case "TxFillOrder":
|
|
62
|
-
return new TxFillOrder(params);
|
|
63
61
|
default:
|
|
64
62
|
throw new Error(`Unknown transaction for parsing: ${e.type}`);
|
|
65
63
|
}
|
|
@@ -596,30 +594,6 @@ class TxEnableTokens extends EVMTx {
|
|
|
596
594
|
};
|
|
597
595
|
}
|
|
598
596
|
}
|
|
599
|
-
class TxFillOrder extends EVMTx {
|
|
600
|
-
amount;
|
|
601
|
-
token;
|
|
602
|
-
network;
|
|
603
|
-
constructor(opts) {
|
|
604
|
-
super(opts);
|
|
605
|
-
this.amount = opts.amount;
|
|
606
|
-
this.token = opts.tokensList[opts.token];
|
|
607
|
-
this.network = opts.network;
|
|
608
|
-
}
|
|
609
|
-
toString() {
|
|
610
|
-
const { title, decimals = 18 } = this.token;
|
|
611
|
-
return `Order opened [${this.network}]: ${formatBN(
|
|
612
|
-
this.amount,
|
|
613
|
-
decimals
|
|
614
|
-
)} ${title}`;
|
|
615
|
-
}
|
|
616
|
-
serialize() {
|
|
617
|
-
return {
|
|
618
|
-
type: "TxFillOrder",
|
|
619
|
-
content: JSON.stringify(this)
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
597
|
export {
|
|
624
598
|
TXSwap,
|
|
625
599
|
TxAddBot,
|
|
@@ -631,7 +605,6 @@ export {
|
|
|
631
605
|
TxCloseAccount,
|
|
632
606
|
TxDecreaseBorrowAmount,
|
|
633
607
|
TxEnableTokens,
|
|
634
|
-
TxFillOrder,
|
|
635
608
|
TxGaugeClaim,
|
|
636
609
|
TxGaugeStake,
|
|
637
610
|
TxGaugeUnstake,
|
|
@@ -53,7 +53,7 @@ class GearboxRewardsExtraApy {
|
|
|
53
53
|
pointsInfo2
|
|
54
54
|
);
|
|
55
55
|
if (points !== null) {
|
|
56
|
-
acc2.push({ balance: points, token:
|
|
56
|
+
acc2.push({ balance: points, token: tokenBalance.token });
|
|
57
57
|
}
|
|
58
58
|
return acc2;
|
|
59
59
|
},
|
|
@@ -65,15 +65,14 @@ class GearboxRewardsExtraApy {
|
|
|
65
65
|
return r;
|
|
66
66
|
}
|
|
67
67
|
static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
|
|
68
|
-
if (!tokenBalanceInPool
|
|
69
|
-
return null;
|
|
68
|
+
if (!tokenBalanceInPool) return null;
|
|
70
69
|
if (pool.expectedLiquidity <= 0) return 0n;
|
|
71
|
-
const { decimals = 18 } = tokensList[
|
|
70
|
+
const { decimals = 18 } = tokensList[tokenBalanceInPool.token] || {};
|
|
72
71
|
const targetFactor = 10n ** BigInt(decimals);
|
|
73
72
|
const { decimals: underlyingDecimals = 18 } = tokensList[pool.underlyingToken] || {};
|
|
74
73
|
const underlyingFactor = 10n ** BigInt(underlyingDecimals);
|
|
75
74
|
const defaultPoints = pointsInfo.amount * targetFactor / PERCENTAGE_FACTOR;
|
|
76
|
-
const points = pointsInfo.estimation === "absolute" ? defaultPoints :
|
|
75
|
+
const points = pointsInfo.estimation === "absolute" ? defaultPoints : tokenBalanceInPool.balance * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
|
|
77
76
|
return BigIntMath.min(points, defaultPoints);
|
|
78
77
|
}
|
|
79
78
|
static getPoolPointsTip(poolRewards, pool, token) {
|
|
@@ -137,6 +137,16 @@ function getSimulateWithPriceUpdatesError(cause, priceUpdates, calls, results, r
|
|
|
137
137
|
const call = calls[i];
|
|
138
138
|
return [extractCallError(c), `${call.address}.${call.functionName}`].filter(Boolean).join(" ");
|
|
139
139
|
});
|
|
140
|
+
if (results[0]?.status === "failure") {
|
|
141
|
+
prettyCalls.unshift(
|
|
142
|
+
`get timestamp failed: ${extractCallError(results[0])}`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (results[1]?.status === "failure") {
|
|
146
|
+
prettyCalls.unshift(
|
|
147
|
+
`get block number failed: ${extractCallError(results[1])}`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
140
150
|
return new SimulateWithPriceUpdatesError(cause, {
|
|
141
151
|
timestamp,
|
|
142
152
|
priceUpdates: prettyPriceUpdates,
|
|
@@ -372,6 +372,17 @@ export declare class RouterV310Contract extends AbstractRouterContract<abi> impl
|
|
|
372
372
|
* Implements {@link IRouterContract.findBestClosePath}
|
|
373
373
|
*/
|
|
374
374
|
findBestClosePath(props: FindBestClosePathProps): Promise<RouterCloseResult>;
|
|
375
|
+
/**
|
|
376
|
+
* v310-specific method to set explicitly number of splits for a token
|
|
377
|
+
* @param token
|
|
378
|
+
* @param numSplits
|
|
379
|
+
*/
|
|
380
|
+
setNumSplits(token: Address, numSplits: bigint): void;
|
|
381
|
+
/**
|
|
382
|
+
* v310-specific method to set default number of splits for a token
|
|
383
|
+
* @param numSplits
|
|
384
|
+
*/
|
|
385
|
+
setDefaultNumSplits(numSplits: bigint): void;
|
|
375
386
|
/**
|
|
376
387
|
* Implements {@link IRouterContract.findAllSwaps}
|
|
377
388
|
* @deprecated v3.0 legacy method
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { NetworkType } from "../../chain/chains.js";
|
|
3
2
|
import type { Asset } from "../../router/index.js";
|
|
4
3
|
import type { TokensAPYList } from "../apy/index.js";
|
|
5
4
|
import type { CaTokenBalance, CreditAccountDataPayload } from "../payload/creditAccount.js";
|
|
@@ -104,8 +103,6 @@ export interface BotDataLegacy {
|
|
|
104
103
|
}
|
|
105
104
|
export declare class CreditAccountData_Legacy {
|
|
106
105
|
readonly isSuccessful: boolean;
|
|
107
|
-
readonly chainId: number;
|
|
108
|
-
readonly network: NetworkType;
|
|
109
106
|
readonly creditAccount: Address;
|
|
110
107
|
readonly borrower: Address;
|
|
111
108
|
readonly creditManager: Address;
|
|
@@ -116,6 +113,7 @@ export declare class CreditAccountData_Legacy {
|
|
|
116
113
|
readonly version: number;
|
|
117
114
|
readonly enabledTokensMask: bigint;
|
|
118
115
|
readonly healthFactor: number;
|
|
116
|
+
isDeleting: boolean;
|
|
119
117
|
readonly baseBorrowRateWithoutFee: number;
|
|
120
118
|
readonly borrowedAmount: bigint;
|
|
121
119
|
readonly accruedInterest: bigint;
|
|
@@ -132,6 +130,7 @@ export declare class CreditAccountData_Legacy {
|
|
|
132
130
|
readonly forbiddenTokens: Record<Address, true>;
|
|
133
131
|
readonly quotedTokens: Record<Address, true>;
|
|
134
132
|
constructor(payload: CreditAccountDataPayload);
|
|
133
|
+
setDeleteInProgress(d: boolean): void;
|
|
135
134
|
static sortBalances(balances: Record<Address, bigint>, prices: Record<Address, bigint>, tokens: Record<Address, TokenData>): Array<[Address, bigint]>;
|
|
136
135
|
static sortAssets(balances: Array<Asset>, prices: Record<Address, bigint>, tokens: Record<Address, TokenData>): Asset[];
|
|
137
136
|
static tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1 | 0;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { NetworkType } from "../../chain/chains.js";
|
|
3
2
|
import type { ChartsCreditManagerPayload, CreditManagerDataPayload, QuotaInfo } from "../payload/creditManager.js";
|
|
4
3
|
export declare class CreditManagerData_Legacy {
|
|
5
4
|
readonly address: Address;
|
|
6
|
-
readonly chainId: number;
|
|
7
|
-
readonly network: NetworkType;
|
|
8
5
|
readonly underlyingToken: Address;
|
|
9
6
|
readonly pool: Address;
|
|
10
7
|
readonly creditFacade: Address;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Address, PublicClient } from "viem";
|
|
2
|
-
import type { NetworkType } from "../../chain/chains.js";
|
|
3
2
|
import type { ChartsPoolDataPayload, LinearModel, PoolDataExtraPayload, PoolDataPayload, UserPoolPayload } from "../payload/pool.js";
|
|
3
|
+
export type PoolType = "universal" | "trade" | "farm";
|
|
4
4
|
export declare class PoolData_Legacy {
|
|
5
5
|
readonly address: Address;
|
|
6
|
-
readonly
|
|
7
|
-
readonly network: NetworkType;
|
|
6
|
+
readonly type: PoolType;
|
|
8
7
|
readonly underlyingToken: Address;
|
|
9
8
|
readonly dieselToken: Address;
|
|
10
9
|
readonly stakedDieselToken: Array<Address>;
|
|
@@ -46,6 +45,7 @@ export declare class PoolData_Legacy {
|
|
|
46
45
|
readonly lastBaseInterestUpdate: bigint;
|
|
47
46
|
constructor(payload: PoolDataPayload, extra: PoolDataExtraPayload);
|
|
48
47
|
calculateBorrowRate({ provider, expectedLiquidity, availableLiquidity, }: CalculateBorrowRateProps): Promise<bigint>;
|
|
48
|
+
static getPoolType(name: string): PoolType;
|
|
49
49
|
static calculateUtilization(expected: bigint, available: bigint): number;
|
|
50
50
|
}
|
|
51
51
|
interface CalculateBorrowRateProps {
|
|
@@ -57,6 +57,7 @@ export declare class ChartsPoolData {
|
|
|
57
57
|
readonly address: Address;
|
|
58
58
|
readonly underlyingToken: Address;
|
|
59
59
|
readonly dieselToken: Address;
|
|
60
|
+
readonly type: PoolType;
|
|
60
61
|
readonly version: number;
|
|
61
62
|
readonly name: string;
|
|
62
63
|
readonly addLiqCount: number;
|
|
@@ -4,7 +4,7 @@ import type { TokenData } from "../tokens/tokenData.js";
|
|
|
4
4
|
import type { EVMTxProps } from "./eventOrTx.js";
|
|
5
5
|
import { EVMTx } from "./eventOrTx.js";
|
|
6
6
|
export interface TxSerialized {
|
|
7
|
-
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxDecreaseBorrowAmount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimNFT" | "TxClaimRewards" | "TxUpdateQuota" | "TxGaugeStake" | "TxGaugeUnstake" | "TxGaugeClaim" | "TxGaugeVote" | "TxWithdrawCollateral" | "TxAddBot" | "TxRemoveBot" | "TxLiquidateAccount" | "TxStakeDiesel" | "TxUnstakeDiesel" | "TxEnableTokens"
|
|
7
|
+
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxDecreaseBorrowAmount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimNFT" | "TxClaimRewards" | "TxUpdateQuota" | "TxGaugeStake" | "TxGaugeUnstake" | "TxGaugeClaim" | "TxGaugeVote" | "TxWithdrawCollateral" | "TxAddBot" | "TxRemoveBot" | "TxLiquidateAccount" | "TxStakeDiesel" | "TxUnstakeDiesel" | "TxEnableTokens";
|
|
8
8
|
content: string;
|
|
9
9
|
}
|
|
10
10
|
export declare class TxSerializer {
|
|
@@ -292,18 +292,4 @@ export declare class TxEnableTokens extends EVMTx {
|
|
|
292
292
|
toString(): string;
|
|
293
293
|
serialize(): TxSerialized;
|
|
294
294
|
}
|
|
295
|
-
interface TxFillOrderProps extends EVMTxProps {
|
|
296
|
-
amount: bigint;
|
|
297
|
-
token: Address;
|
|
298
|
-
network: string;
|
|
299
|
-
tokensList: Record<Address, TokenData>;
|
|
300
|
-
}
|
|
301
|
-
export declare class TxFillOrder extends EVMTx {
|
|
302
|
-
readonly amount: bigint;
|
|
303
|
-
readonly token: TokenData;
|
|
304
|
-
readonly network: string;
|
|
305
|
-
constructor(opts: TxFillOrderProps);
|
|
306
|
-
toString(): string;
|
|
307
|
-
serialize(): TxSerialized;
|
|
308
|
-
}
|
|
309
295
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { NetworkType } from "../../chain/index.js";
|
|
3
2
|
export interface CaTokenBalance {
|
|
4
3
|
success: boolean;
|
|
5
4
|
token: Address;
|
|
@@ -42,6 +41,4 @@ export interface CreditAccountDataPayload {
|
|
|
42
41
|
}[];
|
|
43
42
|
cfVersion: bigint;
|
|
44
43
|
expirationDate: number;
|
|
45
|
-
chainId: number;
|
|
46
|
-
network: NetworkType;
|
|
47
44
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { NetworkType } from "../../chain/chains.js";
|
|
3
2
|
import type { BigNumberish } from "../utils/formatter.js";
|
|
4
3
|
import type { PoolDataPayload } from "./pool.js";
|
|
5
4
|
export interface CreditManagerDebtParamsSDK {
|
|
@@ -55,8 +54,6 @@ export interface CreditManagerDataPayload {
|
|
|
55
54
|
liquidationDiscountExpired: number;
|
|
56
55
|
quotas: PoolDataPayload["quotas"];
|
|
57
56
|
isBorrowingForbidden: boolean;
|
|
58
|
-
chainId: number;
|
|
59
|
-
network: NetworkType;
|
|
60
57
|
}
|
|
61
58
|
export interface ChartsCreditManagerPayload {
|
|
62
59
|
addr: Address;
|
|
@@ -2,7 +2,6 @@ import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"
|
|
|
2
2
|
import type { Address } from "viem";
|
|
3
3
|
import type { iPeripheryCompressorAbi } from "../../../abi/compressors.js";
|
|
4
4
|
import type { Unarray } from "../../base/types.js";
|
|
5
|
-
import type { NetworkType } from "../../chain/chains.js";
|
|
6
5
|
export type ZapperData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof iPeripheryCompressorAbi, "getZappers">["outputs"]>>;
|
|
7
6
|
export interface ZapperDataFull extends ZapperData {
|
|
8
7
|
pool: Address;
|
|
@@ -50,8 +49,6 @@ export interface PoolDataPayload {
|
|
|
50
49
|
isActive: boolean;
|
|
51
50
|
}[];
|
|
52
51
|
zappers: readonly ZapperDataFull[];
|
|
53
|
-
chainId: number;
|
|
54
|
-
network: NetworkType;
|
|
55
52
|
}
|
|
56
53
|
export interface PoolDataExtraPayload {
|
|
57
54
|
stakedDieselToken: Array<Address>;
|