@gearbox-protocol/sdk 3.2.0 → 4.0.0-next.1
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/abi/compressors.js +1124 -518
- package/dist/cjs/adapters/abi/adapters.js +123 -0
- package/dist/cjs/adapters/abi/index.js +1 -3
- package/dist/cjs/dev/AccountOpener.js +1 -1
- package/dist/cjs/dev/setLTZero.js +7 -0
- package/dist/cjs/sdk/GearboxSDK.js +33 -17
- package/dist/cjs/sdk/accounts/CreditAccountsService.js +47 -32
- package/dist/cjs/sdk/accounts/utils.js +38 -0
- package/dist/cjs/sdk/constants/address-provider.js +11 -17
- package/dist/cjs/sdk/market/MarketSuite.js +1 -1
- package/dist/cjs/sdk/market/credit/CreditFacadeV300Contract.js +1 -5
- package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +1 -5
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +6 -5
- package/dist/cjs/sdk/market/pool/PoolSuite.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +4 -4
- package/dist/cjs/sdk/router/createRouter.js +4 -6
- package/dist/cjs/sdk/sdk-legacy/core/creditAccount.js +3 -1
- package/dist/cjs/sdk/utils/index.js +3 -1
- package/dist/cjs/sdk/utils/toAddress.js +36 -0
- package/dist/esm/abi/compressors.js +1124 -513
- package/dist/esm/adapters/abi/adapters.js +120 -0
- package/dist/esm/adapters/abi/index.js +0 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/setLTZero.js +7 -0
- package/dist/esm/sdk/GearboxSDK.js +40 -18
- package/dist/esm/sdk/accounts/CreditAccountsService.js +47 -32
- package/dist/esm/sdk/accounts/utils.js +14 -0
- package/dist/esm/sdk/constants/address-provider.js +11 -15
- package/dist/esm/sdk/market/MarketSuite.js +1 -1
- package/dist/esm/sdk/market/credit/CreditFacadeV300Contract.js +1 -5
- package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +1 -5
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +6 -5
- package/dist/esm/sdk/market/pool/PoolSuite.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +9 -6
- package/dist/esm/sdk/router/createRouter.js +4 -6
- package/dist/esm/sdk/sdk-legacy/core/creditAccount.js +3 -1
- package/dist/esm/sdk/utils/index.js +1 -0
- package/dist/esm/sdk/utils/toAddress.js +12 -0
- package/dist/types/abi/compressors.d.ts +1403 -775
- package/dist/types/adapters/BalancerV3RouterAdapterContract.d.ts +62 -104
- package/dist/types/adapters/abi/adapters.d.ts +213 -0
- package/dist/types/adapters/abi/index.d.ts +0 -1
- package/dist/types/sdk/GearboxSDK.d.ts +12 -3
- package/dist/types/sdk/accounts/CreditAccountsService.d.ts +3 -3
- package/dist/types/sdk/accounts/types.d.ts +15 -2
- package/dist/types/sdk/accounts/utils.d.ts +2 -0
- package/dist/types/sdk/base/types.d.ts +6 -6
- package/dist/types/sdk/constants/address-provider.d.ts +11 -13
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +425 -85
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV300Contract.d.ts +2 -2
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +2 -2
- package/dist/types/sdk/market/pool/createPoolQuotaKeeper.d.ts +2 -2
- package/dist/types/sdk/router/createRouter.d.ts +2 -1
- package/dist/types/sdk/types/state-human.d.ts +1 -3
- package/dist/types/sdk/utils/index.d.ts +1 -0
- package/dist/types/sdk/utils/toAddress.d.ts +3 -0
- package/package.json +1 -1
- package/dist/cjs/adapters/abi/iBalancerV3RouterAdapter.js +0 -153
- package/dist/esm/adapters/abi/iBalancerV3RouterAdapter.js +0 -129
- package/dist/types/adapters/abi/iBalancerV3RouterAdapter.d.ts +0 -230
|
@@ -287,6 +287,123 @@ const iBalancerV2VaultAdapterAbi = [
|
|
|
287
287
|
},
|
|
288
288
|
{ type: "error", inputs: [], name: "PoolNotSupportedException" }
|
|
289
289
|
];
|
|
290
|
+
const iBalancerV3RouterAdapterAbi = [
|
|
291
|
+
{
|
|
292
|
+
type: "function",
|
|
293
|
+
inputs: [],
|
|
294
|
+
name: "contractType",
|
|
295
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
296
|
+
stateMutability: "view"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
type: "function",
|
|
300
|
+
inputs: [],
|
|
301
|
+
name: "creditManager",
|
|
302
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
303
|
+
stateMutability: "view"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
type: "function",
|
|
307
|
+
inputs: [],
|
|
308
|
+
name: "getAllowedPools",
|
|
309
|
+
outputs: [{ name: "pools", internalType: "address[]", type: "address[]" }],
|
|
310
|
+
stateMutability: "view"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
type: "function",
|
|
314
|
+
inputs: [{ name: "pool", internalType: "address", type: "address" }],
|
|
315
|
+
name: "isPoolAllowed",
|
|
316
|
+
outputs: [{ name: "", internalType: "bool", type: "bool" }],
|
|
317
|
+
stateMutability: "view"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
type: "function",
|
|
321
|
+
inputs: [],
|
|
322
|
+
name: "serialize",
|
|
323
|
+
outputs: [{ name: "serializedData", internalType: "bytes", type: "bytes" }],
|
|
324
|
+
stateMutability: "view"
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
type: "function",
|
|
328
|
+
inputs: [
|
|
329
|
+
{ name: "pools", internalType: "address[]", type: "address[]" },
|
|
330
|
+
{ name: "statuses", internalType: "bool[]", type: "bool[]" }
|
|
331
|
+
],
|
|
332
|
+
name: "setPoolStatusBatch",
|
|
333
|
+
outputs: [],
|
|
334
|
+
stateMutability: "nonpayable"
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
type: "function",
|
|
338
|
+
inputs: [
|
|
339
|
+
{ name: "pool", internalType: "address", type: "address" },
|
|
340
|
+
{ name: "tokenIn", internalType: "contract IERC20", type: "address" },
|
|
341
|
+
{ name: "tokenOut", internalType: "contract IERC20", type: "address" },
|
|
342
|
+
{ name: "leftoverAmount", internalType: "uint256", type: "uint256" },
|
|
343
|
+
{ name: "rateMinRAY", internalType: "uint256", type: "uint256" },
|
|
344
|
+
{ name: "deadline", internalType: "uint256", type: "uint256" }
|
|
345
|
+
],
|
|
346
|
+
name: "swapSingleTokenDiffIn",
|
|
347
|
+
outputs: [{ name: "", internalType: "bool", type: "bool" }],
|
|
348
|
+
stateMutability: "nonpayable"
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
type: "function",
|
|
352
|
+
inputs: [
|
|
353
|
+
{ name: "pool", internalType: "address", type: "address" },
|
|
354
|
+
{ name: "tokenIn", internalType: "contract IERC20", type: "address" },
|
|
355
|
+
{ name: "tokenOut", internalType: "contract IERC20", type: "address" },
|
|
356
|
+
{ name: "exactAmountIn", internalType: "uint256", type: "uint256" },
|
|
357
|
+
{ name: "minAmountOut", internalType: "uint256", type: "uint256" },
|
|
358
|
+
{ name: "deadline", internalType: "uint256", type: "uint256" },
|
|
359
|
+
{ name: "wethIsEth", internalType: "bool", type: "bool" },
|
|
360
|
+
{ name: "userData", internalType: "bytes", type: "bytes" }
|
|
361
|
+
],
|
|
362
|
+
name: "swapSingleTokenExactIn",
|
|
363
|
+
outputs: [{ name: "", internalType: "bool", type: "bool" }],
|
|
364
|
+
stateMutability: "nonpayable"
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
type: "function",
|
|
368
|
+
inputs: [],
|
|
369
|
+
name: "targetContract",
|
|
370
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
371
|
+
stateMutability: "view"
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
type: "function",
|
|
375
|
+
inputs: [],
|
|
376
|
+
name: "version",
|
|
377
|
+
outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
378
|
+
stateMutability: "view"
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
type: "event",
|
|
382
|
+
anonymous: false,
|
|
383
|
+
inputs: [
|
|
384
|
+
{ name: "pool", internalType: "address", type: "address", indexed: true },
|
|
385
|
+
{ name: "allowed", internalType: "bool", type: "bool", indexed: false }
|
|
386
|
+
],
|
|
387
|
+
name: "SetPoolStatus"
|
|
388
|
+
},
|
|
389
|
+
{ type: "error", inputs: [], name: "InvalidLengthException" },
|
|
390
|
+
{ type: "error", inputs: [], name: "InvalidPoolException" }
|
|
391
|
+
];
|
|
392
|
+
const iBalancerV3RouterAdapterEventsAbi = [
|
|
393
|
+
{
|
|
394
|
+
type: "event",
|
|
395
|
+
anonymous: false,
|
|
396
|
+
inputs: [
|
|
397
|
+
{ name: "pool", internalType: "address", type: "address", indexed: true },
|
|
398
|
+
{ name: "allowed", internalType: "bool", type: "bool", indexed: false }
|
|
399
|
+
],
|
|
400
|
+
name: "SetPoolStatus"
|
|
401
|
+
}
|
|
402
|
+
];
|
|
403
|
+
const iBalancerV3RouterAdapterExceptionsAbi = [
|
|
404
|
+
{ type: "error", inputs: [], name: "InvalidLengthException" },
|
|
405
|
+
{ type: "error", inputs: [], name: "InvalidPoolException" }
|
|
406
|
+
];
|
|
290
407
|
const iCamelotV3AdapterAbi = [
|
|
291
408
|
{
|
|
292
409
|
type: "function",
|
|
@@ -4198,6 +4315,9 @@ const iwstEthv1AdapterAbi = [
|
|
|
4198
4315
|
];
|
|
4199
4316
|
export {
|
|
4200
4317
|
iBalancerV2VaultAdapterAbi,
|
|
4318
|
+
iBalancerV3RouterAdapterAbi,
|
|
4319
|
+
iBalancerV3RouterAdapterEventsAbi,
|
|
4320
|
+
iBalancerV3RouterAdapterExceptionsAbi,
|
|
4201
4321
|
iCamelotV3AdapterAbi,
|
|
4202
4322
|
iConvexV1BaseRewardPoolAdapterAbi,
|
|
4203
4323
|
iConvexV1BoosterAdapterAbi,
|
|
@@ -179,7 +179,7 @@ class AccountOpener extends SDKConstruct {
|
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
logger?.debug("looking for open strategy");
|
|
182
|
-
const strategy = await this.sdk.
|
|
182
|
+
const strategy = await this.sdk.routerFor(cm).findOpenStrategyPath({
|
|
183
183
|
creditManager: cm.creditManager,
|
|
184
184
|
expectedBalances,
|
|
185
185
|
leftoverBalances,
|
|
@@ -90,6 +90,13 @@ async function setLTZero(anvil, cm, logger) {
|
|
|
90
90
|
address: cm.creditConfigurator
|
|
91
91
|
});
|
|
92
92
|
await anvil.stopImpersonatingAccount({ address: configuratorAddr });
|
|
93
|
+
const lt = await anvil.readContract({
|
|
94
|
+
address: cm.baseParams.addr,
|
|
95
|
+
abi: iCreditManagerV300Abi,
|
|
96
|
+
functionName: "liquidationThresholds",
|
|
97
|
+
args: [cm.underlying]
|
|
98
|
+
});
|
|
99
|
+
logger?.debug(`[${cm.name}] underlying lt: ${lt}`);
|
|
93
100
|
}
|
|
94
101
|
export {
|
|
95
102
|
setLTZero
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
AP_BOT_LIST,
|
|
12
12
|
AP_GEAR_STAKING,
|
|
13
13
|
AP_GEAR_TOKEN,
|
|
14
|
+
AP_ROUTER,
|
|
14
15
|
NO_VERSION
|
|
15
16
|
} from "./constants/index.js";
|
|
16
17
|
import {
|
|
@@ -24,7 +25,12 @@ import {
|
|
|
24
25
|
defaultPlugins
|
|
25
26
|
} from "./plugins/index.js";
|
|
26
27
|
import { createRouter } from "./router/index.js";
|
|
27
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
AddressMap,
|
|
30
|
+
formatBN,
|
|
31
|
+
toAddress,
|
|
32
|
+
TypedObjectUtils
|
|
33
|
+
} from "./utils/index.js";
|
|
28
34
|
import { Hooks } from "./utils/internal/index.js";
|
|
29
35
|
import { getLogsSafe } from "./utils/viem/index.js";
|
|
30
36
|
const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
|
|
@@ -37,7 +43,6 @@ class GearboxSDK {
|
|
|
37
43
|
#currentBlock;
|
|
38
44
|
#timestamp;
|
|
39
45
|
#syncing = false;
|
|
40
|
-
#gear;
|
|
41
46
|
// Collection of core singleton contracts
|
|
42
47
|
#addressProvider;
|
|
43
48
|
#botListContract;
|
|
@@ -45,8 +50,8 @@ class GearboxSDK {
|
|
|
45
50
|
#attachConfig;
|
|
46
51
|
// Collection of markets
|
|
47
52
|
#marketRegister;
|
|
48
|
-
//
|
|
49
|
-
#
|
|
53
|
+
// Routers by address
|
|
54
|
+
#routers = new AddressMap();
|
|
50
55
|
logger;
|
|
51
56
|
/**
|
|
52
57
|
* Interest rate models can be reused across chain (and SDK operates on chain level)
|
|
@@ -185,7 +190,6 @@ class GearboxSDK {
|
|
|
185
190
|
} catch (e) {
|
|
186
191
|
this.logger?.error(e);
|
|
187
192
|
}
|
|
188
|
-
this.#gear = this.#addressProvider.getAddress(AP_GEAR_TOKEN, NO_VERSION);
|
|
189
193
|
const gearStakingAddress = this.#addressProvider.getAddress(
|
|
190
194
|
AP_GEAR_STAKING,
|
|
191
195
|
NO_VERSION
|
|
@@ -199,11 +203,6 @@ class GearboxSDK {
|
|
|
199
203
|
marketConfigurators,
|
|
200
204
|
ignoreUpdateablePrices
|
|
201
205
|
);
|
|
202
|
-
try {
|
|
203
|
-
this.#router = createRouter(this);
|
|
204
|
-
} catch (e) {
|
|
205
|
-
this.logger?.warn("router not found", e);
|
|
206
|
-
}
|
|
207
206
|
const pluginsList = TypedObjectUtils.entries(this.plugins);
|
|
208
207
|
const pluginResponse = await Promise.allSettled(
|
|
209
208
|
pluginsList.map(([name, plugin]) => {
|
|
@@ -405,10 +404,7 @@ class GearboxSDK {
|
|
|
405
404
|
return this.#timestamp;
|
|
406
405
|
}
|
|
407
406
|
get gear() {
|
|
408
|
-
|
|
409
|
-
throw ERR_NOT_ATTACHED;
|
|
410
|
-
}
|
|
411
|
-
return this.#gear;
|
|
407
|
+
return this.addressProvider.getAddress(AP_GEAR_TOKEN, NO_VERSION);
|
|
412
408
|
}
|
|
413
409
|
get addressProvider() {
|
|
414
410
|
if (this.#addressProvider === void 0) {
|
|
@@ -434,11 +430,37 @@ class GearboxSDK {
|
|
|
434
430
|
}
|
|
435
431
|
return this.#marketRegister;
|
|
436
432
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
433
|
+
/**
|
|
434
|
+
* Returns router contract that will work for given credit manager or credit facade
|
|
435
|
+
* @param params
|
|
436
|
+
* @returns
|
|
437
|
+
*/
|
|
438
|
+
routerFor(params) {
|
|
439
|
+
let facadeAddr;
|
|
440
|
+
if ("creditFacade" in params) {
|
|
441
|
+
facadeAddr = toAddress(params.creditFacade);
|
|
442
|
+
} else {
|
|
443
|
+
const cm = this.marketRegister.findCreditManager(
|
|
444
|
+
toAddress(params.creditManager)
|
|
445
|
+
);
|
|
446
|
+
facadeAddr = cm.creditFacade.address;
|
|
447
|
+
}
|
|
448
|
+
const facadeV = this.contracts.mustGet(facadeAddr).version;
|
|
449
|
+
const routerRange = facadeV >= 310 ? [310, 319] : [300, 309];
|
|
450
|
+
const routerEntry = this.addressProvider.getLatestInRange(
|
|
451
|
+
AP_ROUTER,
|
|
452
|
+
routerRange
|
|
453
|
+
);
|
|
454
|
+
if (!routerEntry) {
|
|
455
|
+
throw new Error(
|
|
456
|
+
`router not found for facade v ${facadeV} at ${facadeAddr}`
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
const [routerAddr, routerV] = routerEntry;
|
|
460
|
+
if (!this.#routers.has(routerAddr)) {
|
|
461
|
+
this.#routers.upsert(routerAddr, createRouter(this, routerAddr, routerV));
|
|
440
462
|
}
|
|
441
|
-
return this.#
|
|
463
|
+
return this.#routers.mustGet(routerAddr);
|
|
442
464
|
}
|
|
443
465
|
}
|
|
444
466
|
export {
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
} from "../sdk-gov-legacy/index.js";
|
|
37
37
|
import { childLogger } from "../utils/index.js";
|
|
38
38
|
import { simulateWithPriceUpdates } from "../utils/viem/index.js";
|
|
39
|
+
import { stringifyGetCreditAccountsArgs } from "./utils.js";
|
|
39
40
|
class CreditAccountsService extends SDKConstruct {
|
|
40
41
|
#compressor;
|
|
41
42
|
#batchSize;
|
|
@@ -47,6 +48,9 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
47
48
|
);
|
|
48
49
|
this.#batchSize = options?.batchSize;
|
|
49
50
|
this.#logger = childLogger("CreditAccountsService", sdk.logger);
|
|
51
|
+
this.#logger?.debug(
|
|
52
|
+
`credit account compressor address: ${this.#compressor}`
|
|
53
|
+
);
|
|
50
54
|
}
|
|
51
55
|
/**
|
|
52
56
|
* Returns single credit account data, or undefined if it's not found
|
|
@@ -95,21 +99,21 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
95
99
|
* TODO: do we want to expose pagination?
|
|
96
100
|
* TODO: do we want to expose "reverting"?
|
|
97
101
|
* TODO: do we want to expose MarketFilter in any way? If so, we need to check that the MarketFilter is compatibled with attached markets?
|
|
98
|
-
* @param
|
|
102
|
+
* @param options
|
|
99
103
|
* @param blockNumber
|
|
100
104
|
* @returns returned credit accounts are sorted by health factor in ascending order
|
|
101
105
|
*/
|
|
102
|
-
async getCreditAccounts(
|
|
106
|
+
async getCreditAccounts(options, blockNumber) {
|
|
103
107
|
const {
|
|
104
108
|
creditManager,
|
|
105
109
|
includeZeroDebt = false,
|
|
106
|
-
maxHealthFactor =
|
|
107
|
-
|
|
108
|
-
minHealthFactor = 0,
|
|
110
|
+
maxHealthFactor = MAX_UINT256,
|
|
111
|
+
minHealthFactor = 0n,
|
|
109
112
|
owner = ADDRESS_0X0
|
|
110
|
-
} =
|
|
113
|
+
} = options ?? {};
|
|
111
114
|
const arg0 = creditManager ?? {
|
|
112
115
|
configurators: this.marketConfigurators,
|
|
116
|
+
creditManagers: [],
|
|
113
117
|
pools: [],
|
|
114
118
|
underlying: ADDRESS_0X0
|
|
115
119
|
};
|
|
@@ -117,7 +121,8 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
117
121
|
owner,
|
|
118
122
|
includeZeroDebt,
|
|
119
123
|
minHealthFactor,
|
|
120
|
-
maxHealthFactor
|
|
124
|
+
maxHealthFactor,
|
|
125
|
+
reverting: false
|
|
121
126
|
};
|
|
122
127
|
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
|
|
123
128
|
const allCAs = [];
|
|
@@ -218,7 +223,7 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
218
223
|
*/
|
|
219
224
|
async fullyLiquidate(account, to, slippage = 50n, force = false) {
|
|
220
225
|
const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
|
|
221
|
-
const routerCloseResult = await this.sdk.
|
|
226
|
+
const routerCloseResult = await this.sdk.routerFor(account).findBestClosePath({
|
|
222
227
|
creditAccount: account,
|
|
223
228
|
creditManager: cm.creditManager,
|
|
224
229
|
slippage,
|
|
@@ -262,7 +267,7 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
262
267
|
closePath
|
|
263
268
|
}) {
|
|
264
269
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
265
|
-
const routerCloseResult = closePath || await this.sdk.
|
|
270
|
+
const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
|
|
266
271
|
creditAccount: ca,
|
|
267
272
|
creditManager: cm.creditManager,
|
|
268
273
|
slippage
|
|
@@ -722,31 +727,41 @@ class CreditAccountsService extends SDKConstruct {
|
|
|
722
727
|
* @returns
|
|
723
728
|
*/
|
|
724
729
|
async #getCreditAccounts(args, priceUpdateTxs, blockNumber) {
|
|
730
|
+
this.#logger?.debug(
|
|
731
|
+
{ args: stringifyGetCreditAccountsArgs(args) },
|
|
732
|
+
"getting credit accounts"
|
|
733
|
+
);
|
|
734
|
+
let resp;
|
|
725
735
|
if (priceUpdateTxs?.length) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
736
|
+
[resp] = await simulateWithPriceUpdates(this.provider.publicClient, {
|
|
737
|
+
priceUpdates: priceUpdateTxs,
|
|
738
|
+
contracts: [
|
|
739
|
+
{
|
|
740
|
+
abi: iCreditAccountCompressorAbi,
|
|
741
|
+
address: this.#compressor,
|
|
742
|
+
functionName: "getCreditAccounts",
|
|
743
|
+
args
|
|
744
|
+
}
|
|
745
|
+
],
|
|
746
|
+
blockNumber
|
|
747
|
+
});
|
|
748
|
+
} else {
|
|
749
|
+
resp = await this.provider.publicClient.readContract({
|
|
750
|
+
abi: iCreditAccountCompressorAbi,
|
|
751
|
+
address: this.#compressor,
|
|
752
|
+
functionName: "getCreditAccounts",
|
|
753
|
+
args,
|
|
754
|
+
blockNumber
|
|
755
|
+
});
|
|
742
756
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
757
|
+
this.#logger?.debug(
|
|
758
|
+
{
|
|
759
|
+
accounts: resp[0]?.length ?? 0,
|
|
760
|
+
nextOffset: Number(resp[1])
|
|
761
|
+
},
|
|
762
|
+
"got credit accounts"
|
|
763
|
+
);
|
|
764
|
+
return resp;
|
|
750
765
|
}
|
|
751
766
|
/**
|
|
752
767
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function stringifyGetCreditAccountsArgs(args) {
|
|
2
|
+
const s = JSON.stringify(args, replacer);
|
|
3
|
+
return JSON.parse(s);
|
|
4
|
+
}
|
|
5
|
+
function replacer(_key, value) {
|
|
6
|
+
if (typeof value === "bigint") {
|
|
7
|
+
return value.toString();
|
|
8
|
+
} else {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
stringifyGetCreditAccountsArgs
|
|
14
|
+
};
|
|
@@ -2,32 +2,30 @@ import { NOT_DEPLOYED } from "./addresses.js";
|
|
|
2
2
|
const NO_VERSION = 0;
|
|
3
3
|
const AP_ACCOUNT_FACTORY = "ACCOUNT_FACTORY";
|
|
4
4
|
const AP_ACL = "ACL";
|
|
5
|
-
const AP_ADAPTER_COMPRESSOR = "ADAPTER_COMPRESSOR";
|
|
6
5
|
const AP_BOT_LIST = "BOT_LIST";
|
|
7
6
|
const AP_BYTECODE_REPOSITORY = "BYTECODE_REPOSITORY";
|
|
8
7
|
const AP_CONTRACTS_REGISTER = "CONTRACTS_REGISTER";
|
|
9
8
|
const AP_CONTROLLER_TIMELOCK = "CONTROLLER_TIMELOCK";
|
|
10
|
-
const AP_CREDIT_ACCOUNT_COMPRESSOR = "
|
|
11
|
-
const AP_CREDIT_SUITE_COMPRESSOR = "CREDIT_SUITE_COMPRESSOR";
|
|
9
|
+
const AP_CREDIT_ACCOUNT_COMPRESSOR = "GLOBAL::ACCOUNT_COMPRESSOR";
|
|
10
|
+
const AP_CREDIT_SUITE_COMPRESSOR = "GLOBAL::CREDIT_SUITE_COMPRESSOR";
|
|
12
11
|
const AP_DATA_COMPRESSOR = "DATA_COMPRESSOR";
|
|
13
12
|
const AP_DELEVERAGE_BOT_HV = "DELEVERAGE_BOT_HV";
|
|
14
13
|
const AP_DELEVERAGE_BOT_LV = "DELEVERAGE_BOT_LV";
|
|
15
14
|
const AP_DELEVERAGE_BOT_PEGGED = "DELEVERAGE_BOT_PEGGED";
|
|
16
|
-
const AP_GAUGE_COMPRESSOR = "GAUGE_COMPRESSOR";
|
|
15
|
+
const AP_GAUGE_COMPRESSOR = "GLOBAL::GAUGE_COMPRESSOR";
|
|
17
16
|
const AP_GEAR_STAKING = "GEAR_STAKING";
|
|
18
|
-
const AP_GEAR_TOKEN = "GEAR_TOKEN";
|
|
17
|
+
const AP_GEAR_TOKEN = "GLOBAL::GEAR_TOKEN";
|
|
19
18
|
const AP_INFLATION_ATTACK_BLOCKER = "INFLATION_ATTACK_BLOCKER";
|
|
20
19
|
const AP_INSOLVENCY_CHECKER = "INSOLVENCY_CHECKER";
|
|
21
|
-
const AP_MARKET_COMPRESSOR = "MARKET_COMPRESSOR";
|
|
20
|
+
const AP_MARKET_COMPRESSOR = "GLOBAL::MARKET_COMPRESSOR";
|
|
22
21
|
const AP_MARKET_CONFIGURATOR = "MARKET_CONFIGURATOR";
|
|
23
22
|
const AP_PARTIAL_LIQUIDATION_BOT = "PARTIAL_LIQUIDATION_BOT";
|
|
24
|
-
const AP_PERIPHERY_COMPRESSOR = "PERIPHERY_COMPRESSOR";
|
|
25
|
-
const
|
|
26
|
-
const AP_PRICE_FEED_COMPRESSOR = "PRICE_FEED_COMPRESSOR";
|
|
23
|
+
const AP_PERIPHERY_COMPRESSOR = "GLOBAL::PERIPHERY_COMPRESSOR";
|
|
24
|
+
const AP_PRICE_FEED_COMPRESSOR = "GLOBAL::PRICE_FEED_COMPRESSOR";
|
|
27
25
|
const AP_PRICE_ORACLE = "PRICE_ORACLE";
|
|
28
|
-
const AP_REWARDS_COMPRESSOR = "REWARDS_COMPRESSOR";
|
|
29
|
-
const AP_ROUTER = "
|
|
30
|
-
const AP_TOKEN_COMPRESSOR = "TOKEN_COMPRESSOR";
|
|
26
|
+
const AP_REWARDS_COMPRESSOR = "GLOBAL::REWARDS_COMPRESSOR";
|
|
27
|
+
const AP_ROUTER = "GLOBAL::ROUTER";
|
|
28
|
+
const AP_TOKEN_COMPRESSOR = "GLOBAL::TOKEN_COMPRESSOR";
|
|
31
29
|
const AP_TREASURY = "TREASURY";
|
|
32
30
|
const AP_WETH_GATEWAY = "WETH_GATEWAY";
|
|
33
31
|
const AP_WETH_TOKEN = "WETH_TOKEN";
|
|
@@ -47,13 +45,12 @@ const ADDRESS_PROVIDER = {
|
|
|
47
45
|
BNB: NOT_DEPLOYED,
|
|
48
46
|
WorldChain: NOT_DEPLOYED
|
|
49
47
|
};
|
|
50
|
-
const ADDRESS_PROVIDER_V310 = "
|
|
48
|
+
const ADDRESS_PROVIDER_V310 = "0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38";
|
|
51
49
|
export {
|
|
52
50
|
ADDRESS_PROVIDER,
|
|
53
51
|
ADDRESS_PROVIDER_V310,
|
|
54
52
|
AP_ACCOUNT_FACTORY,
|
|
55
53
|
AP_ACL,
|
|
56
|
-
AP_ADAPTER_COMPRESSOR,
|
|
57
54
|
AP_BOT_LIST,
|
|
58
55
|
AP_BYTECODE_REPOSITORY,
|
|
59
56
|
AP_CONTRACTS_REGISTER,
|
|
@@ -73,7 +70,6 @@ export {
|
|
|
73
70
|
AP_MARKET_CONFIGURATOR,
|
|
74
71
|
AP_PARTIAL_LIQUIDATION_BOT,
|
|
75
72
|
AP_PERIPHERY_COMPRESSOR,
|
|
76
|
-
AP_POOL_COMPRESSOR,
|
|
77
73
|
AP_PRICE_FEED_COMPRESSOR,
|
|
78
74
|
AP_PRICE_ORACLE,
|
|
79
75
|
AP_REWARDS_COMPRESSOR,
|
|
@@ -36,11 +36,7 @@ class CreditFacadeV300Contract extends BaseContract {
|
|
|
36
36
|
botList: this.labelAddress(this.botList),
|
|
37
37
|
minDebt: formatBNvalue(this.minDebt, decimals),
|
|
38
38
|
maxDebt: formatBNvalue(this.maxDebt, decimals),
|
|
39
|
-
|
|
40
|
-
// TODO
|
|
41
|
-
maxCumulativeLoss: "0",
|
|
42
|
-
// TODO
|
|
43
|
-
forbiddenTokenMask: fmtBinaryMask(this.forbiddenTokenMask),
|
|
39
|
+
forbiddenTokensMask: fmtBinaryMask(this.forbiddenTokensMask),
|
|
44
40
|
isPaused: this.isPaused
|
|
45
41
|
};
|
|
46
42
|
}
|
|
@@ -36,11 +36,7 @@ class CreditFacadeV310Contract extends BaseContract {
|
|
|
36
36
|
botList: this.labelAddress(this.botList),
|
|
37
37
|
minDebt: formatBNvalue(this.minDebt, decimals),
|
|
38
38
|
maxDebt: formatBNvalue(this.maxDebt, decimals),
|
|
39
|
-
|
|
40
|
-
// TODO
|
|
41
|
-
maxCumulativeLoss: "0",
|
|
42
|
-
// TODO
|
|
43
|
-
forbiddenTokenMask: fmtBinaryMask(this.forbiddenTokenMask),
|
|
39
|
+
forbiddenTokensMask: fmtBinaryMask(this.forbiddenTokensMask),
|
|
44
40
|
isPaused: this.isPaused
|
|
45
41
|
};
|
|
46
42
|
}
|
|
@@ -42,8 +42,8 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
42
42
|
constructor(sdk, args, data, underlying) {
|
|
43
43
|
super(sdk, args);
|
|
44
44
|
this.underlying = underlying;
|
|
45
|
-
const {
|
|
46
|
-
this.#loadState(
|
|
45
|
+
const { priceFeedMap, priceFeedTree } = data;
|
|
46
|
+
this.#loadState(priceFeedMap, priceFeedTree);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Returns main and reserve price feeds for given tokens
|
|
@@ -216,11 +216,12 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
216
216
|
call: {
|
|
217
217
|
abi: iPriceFeedCompressorAbi,
|
|
218
218
|
address,
|
|
219
|
-
functionName: "
|
|
219
|
+
functionName: "getPriceOracleState",
|
|
220
220
|
args
|
|
221
221
|
},
|
|
222
|
-
onResult: (
|
|
223
|
-
|
|
222
|
+
onResult: (resp) => {
|
|
223
|
+
const { priceFeedMap, priceFeedTree } = resp;
|
|
224
|
+
this.#loadState(priceFeedMap, priceFeedTree);
|
|
224
225
|
}
|
|
225
226
|
};
|
|
226
227
|
}
|
|
@@ -14,7 +14,7 @@ class PoolSuite extends SDKConstruct {
|
|
|
14
14
|
constructor(sdk, data) {
|
|
15
15
|
super(sdk);
|
|
16
16
|
this.pool = createPool(sdk, data.pool);
|
|
17
|
-
this.pqk = createPoolQuotaKeeper(sdk, data.pool, data.
|
|
17
|
+
this.pqk = createPoolQuotaKeeper(sdk, data.pool, data.quotaKeeper);
|
|
18
18
|
this.rateKeeper = createRateKeeper(sdk, data.pool, data.rateKeeper);
|
|
19
19
|
this.interestRateModel = createInterestRateModel(
|
|
20
20
|
sdk,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
|
|
2
2
|
import { SDKConstruct } from "../../base/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ADDRESS_0X0,
|
|
5
|
+
AP_PRICE_FEED_COMPRESSOR
|
|
6
|
+
} from "../../constants/index.js";
|
|
4
7
|
import { AddressMap, bytes32ToString, childLogger } from "../../utils/index.js";
|
|
5
8
|
import { Hooks } from "../../utils/internal/index.js";
|
|
6
9
|
import {
|
|
@@ -106,8 +109,8 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
106
109
|
* This is not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
|
|
107
110
|
*/
|
|
108
111
|
async getPartialUpdatablePriceFeeds(marketConfigurators, pools) {
|
|
109
|
-
const
|
|
110
|
-
|
|
112
|
+
const priceFeedCompressorAddress = this.sdk.addressProvider.getAddress(
|
|
113
|
+
AP_PRICE_FEED_COMPRESSOR,
|
|
111
114
|
310
|
|
112
115
|
);
|
|
113
116
|
const configurators = marketConfigurators ?? this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
|
|
@@ -116,8 +119,8 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
116
119
|
`calling getUpdatablePriceFeeds in block ${this.sdk.currentBlock}`
|
|
117
120
|
);
|
|
118
121
|
const result = await this.provider.publicClient.readContract({
|
|
119
|
-
address:
|
|
120
|
-
abi:
|
|
122
|
+
address: priceFeedCompressorAddress,
|
|
123
|
+
abi: iPriceFeedCompressorAbi,
|
|
121
124
|
functionName: "getUpdatablePriceFeeds",
|
|
122
125
|
args: [
|
|
123
126
|
{
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { AP_ROUTER } from "../constants/index.js";
|
|
2
1
|
import { RouterV300Contract } from "./RouterV300Contract.js";
|
|
3
2
|
import { RouterV310Contract } from "./RouterV310Contract.js";
|
|
4
|
-
function createRouter(sdk) {
|
|
5
|
-
|
|
6
|
-
if (v >= 300 && v < 310) {
|
|
3
|
+
function createRouter(sdk, address, version) {
|
|
4
|
+
if (version >= 300 && version < 310) {
|
|
7
5
|
return new RouterV300Contract(sdk, address);
|
|
8
6
|
}
|
|
9
|
-
if (
|
|
7
|
+
if (version === 310) {
|
|
10
8
|
return new RouterV310Contract(sdk, address);
|
|
11
9
|
}
|
|
12
|
-
throw new Error(`Unsupported router version ${
|
|
10
|
+
throw new Error(`Unsupported router version ${version}`);
|
|
13
11
|
}
|
|
14
12
|
export {
|
|
15
13
|
createRouter
|
|
@@ -50,7 +50,9 @@ class CreditAccountData_Legacy {
|
|
|
50
50
|
this.underlying = payload.underlying.toLowerCase();
|
|
51
51
|
this.expirationDate = Number(payload.expirationDate);
|
|
52
52
|
this.version = Number(payload.cfVersion);
|
|
53
|
-
this.healthFactor = Number(
|
|
53
|
+
this.healthFactor = Number(
|
|
54
|
+
(payload.healthFactor || 0n) * PERCENTAGE_FACTOR / WAD
|
|
55
|
+
);
|
|
54
56
|
this.enabledTokensMask = payload.enabledTokensMask;
|
|
55
57
|
this.isDeleting = false;
|
|
56
58
|
this.borrowedAmount = payload.debt;
|