@gearbox-protocol/sdk 13.5.0-next.1 → 13.5.0-next.2
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/dev/AccountOpener.js +5 -45
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +6 -339
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1 -13
- package/dist/cjs/sdk/base/TokensMeta.js +7 -151
- package/dist/cjs/sdk/base/token-types.js +0 -6
- package/dist/cjs/sdk/chain/chains.js +1 -2
- package/dist/cjs/sdk/constants/addresses.js +3 -0
- package/dist/cjs/sdk/market/MarketRegister.js +0 -3
- package/dist/cjs/sdk/market/MarketSuite.js +0 -3
- package/dist/cjs/sdk/market/ZapperRegister.js +0 -4
- package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -17
- package/dist/cjs/sdk/market/pool/index.js +0 -4
- package/dist/cjs/sdk/pools/PoolService.js +43 -122
- package/dist/cjs/sdk/pools/constants.js +37 -0
- package/dist/esm/dev/AccountOpener.js +6 -47
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +6 -339
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1 -13
- package/dist/esm/sdk/base/TokensMeta.js +7 -155
- package/dist/esm/sdk/base/token-types.js +0 -4
- package/dist/esm/sdk/chain/chains.js +1 -2
- package/dist/esm/sdk/constants/addresses.js +2 -0
- package/dist/esm/sdk/market/MarketRegister.js +0 -3
- package/dist/esm/sdk/market/MarketSuite.js +0 -3
- package/dist/esm/sdk/market/ZapperRegister.js +0 -4
- package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -17
- package/dist/esm/sdk/market/pool/index.js +0 -2
- package/dist/esm/sdk/pools/PoolService.js +32 -115
- package/dist/esm/sdk/pools/constants.js +13 -0
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +5 -103
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +2 -4
- package/dist/types/sdk/accounts/types.d.ts +6 -130
- package/dist/types/sdk/base/TokensMeta.d.ts +3 -20
- package/dist/types/sdk/base/token-types.d.ts +1 -21
- package/dist/types/sdk/base/types.d.ts +3 -0
- package/dist/types/sdk/chain/chains.d.ts +1 -1
- package/dist/types/sdk/constants/addresses.d.ts +4 -0
- package/dist/types/sdk/market/MarketSuite.d.ts +0 -2
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -2
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
- package/dist/types/sdk/market/pool/index.d.ts +0 -2
- package/dist/types/sdk/market/types.d.ts +1 -1
- package/dist/types/sdk/pools/PoolService.d.ts +24 -0
- package/dist/types/sdk/pools/constants.d.ts +7 -0
- package/dist/types/sdk/pools/types.d.ts +9 -8
- package/package.json +1 -1
- package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +0 -263
- package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +0 -278
- package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +0 -97
- package/dist/esm/abi/310/iSecuritizeDegenNFT.js +0 -239
- package/dist/esm/abi/310/iSecuritizeKYCFactory.js +0 -254
- package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +0 -73
- package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +0 -324
- package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +0 -322
- package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +0 -345
|
@@ -52,7 +52,6 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
52
52
|
#minDebtMultiplier;
|
|
53
53
|
#allowMint;
|
|
54
54
|
#leverageDelta;
|
|
55
|
-
#poolService;
|
|
56
55
|
constructor(service, options_ = {}) {
|
|
57
56
|
super(service.sdk);
|
|
58
57
|
const {
|
|
@@ -78,7 +77,6 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
78
77
|
this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
|
|
79
78
|
this.#minDebtMultiplier = BigInt(minDebtMultiplier);
|
|
80
79
|
this.#leverageDelta = BigInt(leverageDelta);
|
|
81
|
-
this.#poolService = new import_sdk.PoolService(service.sdk);
|
|
82
80
|
this.#logger?.info(
|
|
83
81
|
{
|
|
84
82
|
borrower: (0, import_accounts.privateKeyToAccount)(this.borrowerKey).address,
|
|
@@ -116,10 +114,6 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
116
114
|
},
|
|
117
115
|
"opening credit accounts"
|
|
118
116
|
);
|
|
119
|
-
await Promise.all([
|
|
120
|
-
this.sdk.tokensMeta.loadTokenData(),
|
|
121
|
-
this.sdk.marketRegister.loadZappers()
|
|
122
|
-
]);
|
|
123
117
|
let deposits = [];
|
|
124
118
|
if (depositIntoPools) {
|
|
125
119
|
try {
|
|
@@ -471,34 +465,9 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
471
465
|
this.#logger?.debug(
|
|
472
466
|
`depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
|
|
473
467
|
);
|
|
474
|
-
const tokensOut = this.#poolService.getDepositTokensOut(
|
|
475
|
-
address,
|
|
476
|
-
underlying
|
|
477
|
-
);
|
|
478
|
-
this.#logger?.debug(
|
|
479
|
-
{ tokensOut: tokensOut.map((t) => this.labelAddress(t)) },
|
|
480
|
-
"deposit tokens out"
|
|
481
|
-
);
|
|
482
|
-
if (tokensOut.length === 0) {
|
|
483
|
-
throw new Error(`no tokens out found for pool ${poolName}`);
|
|
484
|
-
}
|
|
485
|
-
const tokenOut = tokensOut[0];
|
|
486
|
-
const metadata = this.#poolService.getDepositMetadata(
|
|
487
|
-
address,
|
|
488
|
-
underlying,
|
|
489
|
-
tokenOut
|
|
490
|
-
);
|
|
491
|
-
this.logger?.debug(
|
|
492
|
-
{
|
|
493
|
-
underlying: this.labelAddress(underlying),
|
|
494
|
-
tokenOut: this.labelAddress(tokenOut),
|
|
495
|
-
...metadata
|
|
496
|
-
},
|
|
497
|
-
"pool deposit metadata"
|
|
498
|
-
);
|
|
499
468
|
txHash = await this.#anvil.writeContract({
|
|
500
469
|
account: depositor,
|
|
501
|
-
address:
|
|
470
|
+
address: underlying,
|
|
502
471
|
abi: import_iERC20.ierc20Abi,
|
|
503
472
|
functionName: "approve",
|
|
504
473
|
args: [address, allowance],
|
|
@@ -515,21 +484,12 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
515
484
|
this.#logger?.debug(
|
|
516
485
|
`depositor approved underlying for pool ${poolName}: ${txHash}`
|
|
517
486
|
);
|
|
518
|
-
const depositCall = this.#poolService.addLiquidity({
|
|
519
|
-
collateral: { token: underlying, balance: amount },
|
|
520
|
-
pool: address,
|
|
521
|
-
wallet: depositor.address,
|
|
522
|
-
meta: metadata
|
|
523
|
-
});
|
|
524
|
-
if (!depositCall) {
|
|
525
|
-
throw new Error(`no deposit call could be created for ${poolName}`);
|
|
526
|
-
}
|
|
527
487
|
txHash = await this.#anvil.writeContract({
|
|
528
488
|
account: depositor,
|
|
529
|
-
address
|
|
530
|
-
abi:
|
|
531
|
-
functionName:
|
|
532
|
-
args:
|
|
489
|
+
address,
|
|
490
|
+
abi: import_generated.iPoolV310Abi,
|
|
491
|
+
functionName: "deposit",
|
|
492
|
+
args: [amount, depositor.address],
|
|
533
493
|
chain: this.#anvil.chain
|
|
534
494
|
});
|
|
535
495
|
receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });
|
|
@@ -22,7 +22,6 @@ __export(AbstractCreditAccountsService_exports, {
|
|
|
22
22
|
getWithdrawalCompressorAddress: () => getWithdrawalCompressorAddress
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(AbstractCreditAccountsService_exports);
|
|
25
|
-
var import_integrations_v3 = require("@gearbox-protocol/integrations-v3");
|
|
26
25
|
var import_viem = require("viem");
|
|
27
26
|
var import_generated = require("../../abi/310/generated.js");
|
|
28
27
|
var import_creditAccountCompressor = require("../../abi/compressors/creditAccountCompressor.js");
|
|
@@ -96,23 +95,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
96
95
|
});
|
|
97
96
|
return cad;
|
|
98
97
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns credit account data for a single account with the investor address resolved.
|
|
101
|
-
* Loads CA via getCreditAccountData; for KYC underlyings fetches the investor from the KYC factory's getInvestor(creditAccount), otherwise uses the account owner.
|
|
102
|
-
* @param account - Credit account address
|
|
103
|
-
* @param blockNumber - Optional block number for the read
|
|
104
|
-
* @returns CreditAccountDataWithInvestor (CA data + investor address), or undefined if the account is not found
|
|
105
|
-
*/
|
|
106
|
-
async getCreditAccountDataWithInvestor(account, blockNumber) {
|
|
107
|
-
const ca = await this.getCreditAccountData(account, blockNumber);
|
|
108
|
-
if (!ca) return ca;
|
|
109
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
110
|
-
ca.creditManager
|
|
111
|
-
);
|
|
112
|
-
const factory = await marketSuite.getKYCFactory();
|
|
113
|
-
const investor = factory ? await factory.getInvestor(ca.creditAccount, true) : void 0;
|
|
114
|
-
return { ...ca, investor: investor ?? ca.owner };
|
|
115
|
-
}
|
|
116
98
|
/**
|
|
117
99
|
* {@inheritDoc ICreditAccountsService.getCreditAccounts}
|
|
118
100
|
**/
|
|
@@ -167,75 +149,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
167
149
|
);
|
|
168
150
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
169
151
|
}
|
|
170
|
-
/**
|
|
171
|
-
* Returns all credit accounts matching the filter, with investor set on each item.
|
|
172
|
-
* Delegates to getCreditAccounts; when options.owner is set, also loads KYC credit accounts for that owner and merges them into the list. Result is sorted by health factor ascending.
|
|
173
|
-
* @param options - Filter options (owner, creditManager, health factor, etc.)
|
|
174
|
-
* @param blockNumber - Optional block number for the read
|
|
175
|
-
* @returns Array of credit accounts (with investor field), sorted by health factor ascending
|
|
176
|
-
*/
|
|
177
|
-
async getCreditAccountsWithInvestor(options, blockNumber) {
|
|
178
|
-
const { owner, ignoreReservePrices = false } = options ?? {};
|
|
179
|
-
const priceUpdate = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
180
|
-
ignoreReservePrices ? { main: true } : void 0
|
|
181
|
-
);
|
|
182
|
-
const { txs: priceUpdateTxs } = priceUpdate;
|
|
183
|
-
const [common, kyc] = await Promise.all([
|
|
184
|
-
this.getCreditAccounts(options, blockNumber),
|
|
185
|
-
owner ? this.getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) : void 0
|
|
186
|
-
]);
|
|
187
|
-
const allCAs = common.map(
|
|
188
|
-
(ca) => ({
|
|
189
|
-
...ca,
|
|
190
|
-
investor: owner || ca.owner
|
|
191
|
-
})
|
|
192
|
-
);
|
|
193
|
-
allCAs.push(...kyc || []);
|
|
194
|
-
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
195
|
-
}
|
|
196
|
-
async getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) {
|
|
197
|
-
const suites = this.marketConfigurators.map((mc) => {
|
|
198
|
-
const suite = this.sdk.marketRegister.markets.find(
|
|
199
|
-
(m) => m.configurator.address === mc
|
|
200
|
-
);
|
|
201
|
-
return suite;
|
|
202
|
-
});
|
|
203
|
-
const kycCAAddresses = await this.getKYCCaOfInvestor(owner, suites);
|
|
204
|
-
const kycCAs = await this.loadSpecifiedAccounts(
|
|
205
|
-
kycCAAddresses,
|
|
206
|
-
priceUpdateTxs,
|
|
207
|
-
blockNumber
|
|
208
|
-
);
|
|
209
|
-
return kycCAs.map((ca) => ({
|
|
210
|
-
...ca,
|
|
211
|
-
investor: owner
|
|
212
|
-
}));
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Loads credit account data for the given addresses using simulateWithPriceUpdates.
|
|
216
|
-
* Applies the provided price update txs before reading, so returned data is consistent with up-to-date prices.
|
|
217
|
-
* @param accounts - Credit account addresses to load
|
|
218
|
-
* @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
|
|
219
|
-
* @param blockNumber - Optional block number for the read
|
|
220
|
-
* @returns Array of CreditAccountData in the same order as accounts (throws if any getCreditAccountData call reverts)
|
|
221
|
-
*/
|
|
222
|
-
async loadSpecifiedAccounts(accounts, priceUpdateTxs, blockNumber) {
|
|
223
|
-
if (accounts.length === 0) return [];
|
|
224
|
-
const list = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
|
|
225
|
-
priceUpdates: priceUpdateTxs,
|
|
226
|
-
contracts: accounts.map(
|
|
227
|
-
(account) => ({
|
|
228
|
-
abi: import_creditAccountCompressor.creditAccountCompressorAbi,
|
|
229
|
-
address: this.#compressor,
|
|
230
|
-
functionName: "getCreditAccountData",
|
|
231
|
-
args: [account]
|
|
232
|
-
})
|
|
233
|
-
),
|
|
234
|
-
blockNumber,
|
|
235
|
-
gas: this.sdk.gasLimit
|
|
236
|
-
});
|
|
237
|
-
return list;
|
|
238
|
-
}
|
|
239
152
|
/**
|
|
240
153
|
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
241
154
|
**/
|
|
@@ -340,19 +253,19 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
340
253
|
);
|
|
341
254
|
return {
|
|
342
255
|
legacy,
|
|
343
|
-
additionalBots: this
|
|
256
|
+
additionalBots: this.#getActiveBots(
|
|
344
257
|
accountsToCheck,
|
|
345
258
|
additionalBots,
|
|
346
259
|
additionalResp
|
|
347
260
|
),
|
|
348
|
-
legacyMigration: this
|
|
261
|
+
legacyMigration: this.#getActiveMigrationBots(
|
|
349
262
|
accountsToCheck,
|
|
350
263
|
legacyMigrationBot,
|
|
351
264
|
migrationResp
|
|
352
265
|
)
|
|
353
266
|
};
|
|
354
267
|
}
|
|
355
|
-
getActiveBots(accountsToCheck, bots, result) {
|
|
268
|
+
#getActiveBots(accountsToCheck, bots, result) {
|
|
356
269
|
if (result.length !== bots.length * accountsToCheck.length) {
|
|
357
270
|
console.error(
|
|
358
271
|
"result length mismatch",
|
|
@@ -369,7 +282,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
369
282
|
}, []);
|
|
370
283
|
return botsByCAIndex;
|
|
371
284
|
}
|
|
372
|
-
getActiveMigrationBots(accountsToCheck, bot, result) {
|
|
285
|
+
#getActiveMigrationBots(accountsToCheck, bot, result) {
|
|
373
286
|
if (bot) {
|
|
374
287
|
if (result.length !== accountsToCheck.length) {
|
|
375
288
|
console.error(
|
|
@@ -445,13 +358,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
445
358
|
closePath
|
|
446
359
|
}) {
|
|
447
360
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
448
|
-
await this.sdk.tokensMeta.loadTokenData(cm.underlying);
|
|
449
|
-
const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
|
|
450
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
451
|
-
throw new Error(
|
|
452
|
-
"closeCreditAccount is not supported for KYC underlying credit accounts"
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
361
|
const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
|
|
456
362
|
creditAccount: ca,
|
|
457
363
|
creditManager: cm.creditManager,
|
|
@@ -557,18 +463,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
557
463
|
],
|
|
558
464
|
{}
|
|
559
465
|
) : [];
|
|
560
|
-
const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
|
|
561
|
-
collateral[0].balance,
|
|
562
|
-
creditAccount.creditManager
|
|
563
|
-
) || [] : [];
|
|
564
|
-
if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
|
|
565
|
-
throw new Error(
|
|
566
|
-
"Can't use collateral other than underlying for non KYC market"
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
466
|
const operationCalls = [
|
|
570
467
|
...addCollateralCalls,
|
|
571
|
-
...unwrapCalls,
|
|
572
468
|
this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
|
|
573
469
|
];
|
|
574
470
|
const calls = await this.prependPriceUpdates(
|
|
@@ -776,25 +672,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
776
672
|
const tx = await this.multicallTx(cm, creditAccount.creditAccount, calls);
|
|
777
673
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
778
674
|
}
|
|
779
|
-
/**
|
|
780
|
-
* Returns address to which approval should be given on collateral token
|
|
781
|
-
* It's credit manager for classical markets and special wallet for KYC markets
|
|
782
|
-
* @param options - {@link GetApprovalAddressProps}
|
|
783
|
-
* @returns
|
|
784
|
-
**/
|
|
785
|
-
async getApprovalAddress(options) {
|
|
786
|
-
const { creditManager } = options;
|
|
787
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
788
|
-
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
789
|
-
const factory = await marketSuite.getKYCFactory();
|
|
790
|
-
if (factory) {
|
|
791
|
-
if ("creditAccount" in options) {
|
|
792
|
-
return factory.getWallet(options.creditAccount);
|
|
793
|
-
}
|
|
794
|
-
return factory.precomputeWalletAddress(creditManager, options.borrower);
|
|
795
|
-
}
|
|
796
|
-
return suite.creditManager.address;
|
|
797
|
-
}
|
|
798
675
|
/**
|
|
799
676
|
* {@inheritDoc ICreditAccountsService.openCA}
|
|
800
677
|
**/
|
|
@@ -929,131 +806,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
929
806
|
return resp;
|
|
930
807
|
}
|
|
931
808
|
/**
|
|
932
|
-
* Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
|
|
933
|
-
* Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
|
|
934
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
935
|
-
* @param amount - Number of vault shares (adapter tokens) to redeem
|
|
936
|
-
* @param creditManager - Credit manager address
|
|
937
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
938
|
-
*/
|
|
939
|
-
async getKYCUnwrapCalls(amount, creditManager) {
|
|
940
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
941
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
942
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
943
|
-
return void 0;
|
|
944
|
-
}
|
|
945
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
946
|
-
const adapterAddress = adapter?.address;
|
|
947
|
-
if (!adapterAddress) {
|
|
948
|
-
return void 0;
|
|
949
|
-
}
|
|
950
|
-
const mc = [
|
|
951
|
-
{
|
|
952
|
-
target: adapterAddress,
|
|
953
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
954
|
-
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
955
|
-
functionName: "redeem",
|
|
956
|
-
args: [amount, import_constants.ADDRESS_0X0, import_constants.ADDRESS_0X0]
|
|
957
|
-
})
|
|
958
|
-
}
|
|
959
|
-
];
|
|
960
|
-
return mc;
|
|
961
|
-
}
|
|
962
|
-
/**
|
|
963
|
-
* Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
|
|
964
|
-
* Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
|
|
965
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
966
|
-
* @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
|
|
967
|
-
* @param creditManager - Credit manager address
|
|
968
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
969
|
-
*/
|
|
970
|
-
async getKYCWrapCalls(amount, creditManager) {
|
|
971
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
972
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
973
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
974
|
-
return void 0;
|
|
975
|
-
}
|
|
976
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
977
|
-
const adapterAddress = adapter?.address;
|
|
978
|
-
if (!adapterAddress) {
|
|
979
|
-
return void 0;
|
|
980
|
-
}
|
|
981
|
-
const mc = [
|
|
982
|
-
{
|
|
983
|
-
target: adapterAddress,
|
|
984
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
985
|
-
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
986
|
-
functionName: "deposit",
|
|
987
|
-
args: [amount, import_constants.ADDRESS_0X0]
|
|
988
|
-
})
|
|
989
|
-
}
|
|
990
|
-
];
|
|
991
|
-
return mc;
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
995
|
-
* Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
|
|
996
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
997
|
-
* @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
|
|
998
|
-
* @param creditManager - Credit manager address
|
|
999
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1000
|
-
*/
|
|
1001
|
-
async getRedeemDiffCalls(amount, creditManager) {
|
|
1002
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1003
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1004
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1005
|
-
return void 0;
|
|
1006
|
-
}
|
|
1007
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1008
|
-
const adapterAddress = adapter?.address;
|
|
1009
|
-
if (!adapterAddress) {
|
|
1010
|
-
return void 0;
|
|
1011
|
-
}
|
|
1012
|
-
const mc = [
|
|
1013
|
-
{
|
|
1014
|
-
target: adapterAddress,
|
|
1015
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
1016
|
-
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
1017
|
-
functionName: "redeemDiff",
|
|
1018
|
-
args: [amount]
|
|
1019
|
-
})
|
|
1020
|
-
}
|
|
1021
|
-
];
|
|
1022
|
-
return mc;
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1026
|
-
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
1027
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1028
|
-
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
1029
|
-
* @param creditManager - Credit manager address
|
|
1030
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1031
|
-
*/
|
|
1032
|
-
async getDepositDiffCalls(amount, creditManager) {
|
|
1033
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1034
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1035
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1036
|
-
return void 0;
|
|
1037
|
-
}
|
|
1038
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1039
|
-
const adapterAddress = adapter?.address;
|
|
1040
|
-
if (!adapterAddress) {
|
|
1041
|
-
return void 0;
|
|
1042
|
-
}
|
|
1043
|
-
const mc = [
|
|
1044
|
-
{
|
|
1045
|
-
target: adapterAddress,
|
|
1046
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
1047
|
-
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
1048
|
-
functionName: "depositDiff",
|
|
1049
|
-
args: [amount]
|
|
1050
|
-
})
|
|
1051
|
-
}
|
|
1052
|
-
];
|
|
1053
|
-
return mc;
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
1057
809
|
* {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
|
|
1058
810
|
**/
|
|
1059
811
|
async getOnDemandPriceUpdates(account, ignoreReservePrices) {
|
|
@@ -1148,13 +900,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1148
900
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
1149
901
|
}
|
|
1150
902
|
/**
|
|
1151
|
-
*
|
|
1152
|
-
* necessary on-demand price feed updates.
|
|
1153
|
-
*
|
|
1154
|
-
* @param creditAccount - Credit account to execute multicall on
|
|
1155
|
-
* @param calls - Array of multicall operations (price updates will be inferred)
|
|
1156
|
-
* @param options - Optional settings for price update generation
|
|
1157
|
-
* @returns Raw transaction ready to be signed and sent
|
|
903
|
+
* {@inheritDoc ICreditAccountsService.multicall}
|
|
1158
904
|
*/
|
|
1159
905
|
async multicall(creditAccount, calls, options) {
|
|
1160
906
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
@@ -1172,13 +918,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1172
918
|
);
|
|
1173
919
|
}
|
|
1174
920
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
* necessary on-demand price feed updates.
|
|
1177
|
-
*
|
|
1178
|
-
* @param creditAccount - Credit account to execute bot multicall on
|
|
1179
|
-
* @param calls - Array of multicall operations (price updates will be inferred)
|
|
1180
|
-
* @param options - Optional settings for price update generation
|
|
1181
|
-
* @returns Raw transaction ready to be signed and sent
|
|
921
|
+
* {@inheritDoc ICreditAccountsService.botMulticall}
|
|
1182
922
|
*/
|
|
1183
923
|
async botMulticall(creditAccount, calls, options) {
|
|
1184
924
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
@@ -1323,16 +1063,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1323
1063
|
* @returns
|
|
1324
1064
|
*/
|
|
1325
1065
|
async openCreditAccountTx(suite, to, calls, referralCode) {
|
|
1326
|
-
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
1327
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1328
|
-
if (factory) {
|
|
1329
|
-
const tokensToRegister = await factory.getDSTokens();
|
|
1330
|
-
return factory.openCreditAccount(
|
|
1331
|
-
suite.creditManager.address,
|
|
1332
|
-
calls,
|
|
1333
|
-
tokensToRegister
|
|
1334
|
-
);
|
|
1335
|
-
}
|
|
1336
1066
|
return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
|
|
1337
1067
|
}
|
|
1338
1068
|
/**
|
|
@@ -1343,14 +1073,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1343
1073
|
* @returns
|
|
1344
1074
|
*/
|
|
1345
1075
|
async multicallTx(suite, creditAccount, calls) {
|
|
1346
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1347
|
-
suite.creditManager.address
|
|
1348
|
-
);
|
|
1349
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1350
|
-
if (factory) {
|
|
1351
|
-
const tokensToRegister = [];
|
|
1352
|
-
return factory.multicall(creditAccount, calls, tokensToRegister);
|
|
1353
|
-
}
|
|
1354
1076
|
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1355
1077
|
}
|
|
1356
1078
|
/**
|
|
@@ -1362,66 +1084,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1362
1084
|
* @returns
|
|
1363
1085
|
*/
|
|
1364
1086
|
async closeCreditAccountTx(suite, creditAccount, calls, operation) {
|
|
1365
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1366
|
-
suite.creditManager.address
|
|
1367
|
-
);
|
|
1368
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1369
1087
|
if (operation === "close") {
|
|
1370
|
-
if (factory) {
|
|
1371
|
-
throw new Error(
|
|
1372
|
-
"CloseOptions=close is not supported for KYC underlying credit accounts"
|
|
1373
|
-
);
|
|
1374
|
-
}
|
|
1375
1088
|
return suite.creditFacade.closeCreditAccount(creditAccount, calls);
|
|
1376
1089
|
}
|
|
1377
|
-
if (factory) {
|
|
1378
|
-
const tokensToRegister = [];
|
|
1379
|
-
return factory.multicall(creditAccount, calls, tokensToRegister);
|
|
1380
|
-
}
|
|
1381
1090
|
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1382
1091
|
}
|
|
1383
|
-
/**
|
|
1384
|
-
* Returns all KYC credit account addresses for an investor across the given market suites.
|
|
1385
|
-
* Resolves KYC factory per suite, then multicalls each factory's getCreditAccounts(investor).
|
|
1386
|
-
* @param investor - Owner address to query
|
|
1387
|
-
* @param suites - Market suites (KYC factories are resolved for each; undefined entries are skipped)
|
|
1388
|
-
* @returns Flat array of credit account addresses from all KYC markets
|
|
1389
|
-
*/
|
|
1390
|
-
async getKYCCaOfInvestor(investor, suites) {
|
|
1391
|
-
if (suites.length === 0 || investor === import_constants.ADDRESS_0X0) return [];
|
|
1392
|
-
const factories = await Promise.all(
|
|
1393
|
-
suites.map((suite) => suite ? suite.getKYCFactory() : void 0)
|
|
1394
|
-
);
|
|
1395
|
-
const safeFactories = factories.reduce(
|
|
1396
|
-
(acc, v) => {
|
|
1397
|
-
if (v) {
|
|
1398
|
-
acc.push(v);
|
|
1399
|
-
}
|
|
1400
|
-
return acc;
|
|
1401
|
-
},
|
|
1402
|
-
[]
|
|
1403
|
-
);
|
|
1404
|
-
const allResp = await this.client.multicall({
|
|
1405
|
-
contracts: [
|
|
1406
|
-
...safeFactories.map((factory) => {
|
|
1407
|
-
return {
|
|
1408
|
-
abi: factory.abi,
|
|
1409
|
-
address: factory.address,
|
|
1410
|
-
functionName: "getCreditAccounts",
|
|
1411
|
-
args: [investor]
|
|
1412
|
-
};
|
|
1413
|
-
})
|
|
1414
|
-
],
|
|
1415
|
-
allowFailure: true,
|
|
1416
|
-
batchSize: 0
|
|
1417
|
-
});
|
|
1418
|
-
const caLists = safeFactories.reduce((acc, _, index) => {
|
|
1419
|
-
const response = allResp[index];
|
|
1420
|
-
acc.push(...response.result || []);
|
|
1421
|
-
return acc;
|
|
1422
|
-
}, []);
|
|
1423
|
-
return caLists;
|
|
1424
|
-
}
|
|
1425
1092
|
}
|
|
1426
1093
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1427
1094
|
0 && (module.exports = {
|
|
@@ -113,23 +113,19 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
113
113
|
creditAccount: ca,
|
|
114
114
|
permits,
|
|
115
115
|
to,
|
|
116
|
-
tokensToClaim
|
|
117
|
-
calls: wrapCalls = []
|
|
116
|
+
tokensToClaim
|
|
118
117
|
}) {
|
|
119
118
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
120
119
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
121
120
|
const router = this.sdk.routerFor(ca);
|
|
122
|
-
const unwrapCalls = await this.getRedeemDiffCalls(1n, ca.creditManager) ?? [];
|
|
123
121
|
const claimPath = await router.findClaimAllRewards({
|
|
124
122
|
tokensToClaim,
|
|
125
123
|
creditAccount: ca
|
|
126
124
|
});
|
|
127
125
|
const operationCalls = [
|
|
128
126
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
129
|
-
...wrapCalls,
|
|
130
127
|
...this.prepareDisableQuotas(ca),
|
|
131
128
|
...this.prepareDecreaseDebt(ca),
|
|
132
|
-
...unwrapCalls,
|
|
133
129
|
...claimPath.calls,
|
|
134
130
|
...assetsToWithdraw.map(
|
|
135
131
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
@@ -161,12 +157,10 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
161
157
|
tokensToClaim,
|
|
162
158
|
creditAccount: ca
|
|
163
159
|
});
|
|
164
|
-
const wrapCalls = await this.getDepositDiffCalls(1n, ca.creditManager) ?? [];
|
|
165
160
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
166
161
|
const operationCalls = [
|
|
167
162
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
168
163
|
...claimPath.calls,
|
|
169
|
-
...wrapCalls,
|
|
170
164
|
...assetsToWithdraw.map(
|
|
171
165
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
172
166
|
)
|
|
@@ -217,12 +211,6 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
217
211
|
const tx = await this.multicallTx(cm, ca.creditAccount, calls);
|
|
218
212
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
219
213
|
}
|
|
220
|
-
async previewWithdrawLlamathenaProportionally(_) {
|
|
221
|
-
throw new Error("Not implemented in v310");
|
|
222
|
-
}
|
|
223
|
-
async withdrawLlamathenaProportionally(_) {
|
|
224
|
-
throw new Error("Not implemented in v310");
|
|
225
|
-
}
|
|
226
214
|
}
|
|
227
215
|
// Annotate the CommonJS export names for ESM import in node:
|
|
228
216
|
0 && (module.exports = {
|