@gearbox-protocol/sdk 14.0.0-next.9 → 14.1.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/kyc/iDSRegistryService.js +149 -0
- package/dist/cjs/abi/kyc/iDSToken.js +71 -0
- package/dist/cjs/abi/kyc/iKYCCompressor.js +196 -0
- package/dist/cjs/abi/kyc/iKYCFactory.js +122 -0
- package/dist/cjs/abi/kyc/iKYCUnderlying.js +401 -0
- package/dist/cjs/abi/kyc/iSecuritizeDegenNFT.js +326 -0
- package/dist/cjs/abi/kyc/iSecuritizeKYCFactory.js +319 -0
- package/dist/cjs/dev/AccountOpener.js +45 -5
- package/dist/cjs/rewards/rewards/extra-apy.js +1 -1
- package/dist/cjs/sdk/MultichainSDK.js +5 -0
- package/dist/cjs/sdk/OnchainSDK.js +55 -6
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +335 -21
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +7 -1
- package/dist/cjs/sdk/base/TokensMeta.js +22 -42
- package/dist/cjs/sdk/base/token-types.js +9 -0
- package/dist/cjs/sdk/chain/chains.js +18 -1
- package/dist/cjs/sdk/constants/address-provider.js +3 -0
- package/dist/cjs/sdk/market/MarketRegister.js +70 -116
- package/dist/cjs/sdk/market/MarketSuite.js +3 -0
- package/dist/cjs/sdk/market/index.js +2 -0
- package/dist/cjs/sdk/market/kyc/KYCRegistry.js +269 -0
- package/dist/cjs/sdk/market/kyc/index.js +26 -0
- package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +242 -0
- package/dist/cjs/sdk/market/kyc/securitize/constants.js +28 -0
- package/dist/cjs/sdk/market/kyc/securitize/index.js +26 -0
- package/dist/cjs/sdk/market/kyc/securitize/types.js +16 -0
- package/dist/cjs/sdk/{accounts/utils.js → market/kyc/types.js} +11 -15
- package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +11 -2
- package/dist/cjs/sdk/market/pool/index.js +2 -0
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
- package/dist/cjs/sdk/options.js +6 -0
- package/dist/cjs/sdk/pools/PoolService.js +104 -12
- package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +38 -0
- package/dist/cjs/sdk/utils/viem/index.js +2 -4
- package/dist/esm/abi/kyc/iDSRegistryService.js +125 -0
- package/dist/esm/abi/kyc/iDSToken.js +47 -0
- package/dist/esm/abi/kyc/iKYCCompressor.js +172 -0
- package/dist/esm/abi/kyc/iKYCFactory.js +98 -0
- package/dist/esm/abi/kyc/iKYCUnderlying.js +377 -0
- package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +302 -0
- package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +295 -0
- package/dist/esm/dev/AccountOpener.js +47 -6
- package/dist/esm/rewards/rewards/extra-apy.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +5 -0
- package/dist/esm/sdk/OnchainSDK.js +58 -7
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +336 -22
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +7 -1
- package/dist/esm/sdk/base/TokensMeta.js +22 -44
- package/dist/esm/sdk/base/token-types.js +6 -0
- package/dist/esm/sdk/chain/chains.js +18 -1
- package/dist/esm/sdk/constants/address-provider.js +2 -0
- package/dist/esm/sdk/market/MarketRegister.js +74 -118
- package/dist/esm/sdk/market/MarketSuite.js +3 -0
- package/dist/esm/sdk/market/index.js +1 -0
- package/dist/esm/sdk/market/kyc/KYCRegistry.js +253 -0
- package/dist/esm/sdk/market/kyc/index.js +3 -0
- package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +218 -0
- package/dist/esm/sdk/market/kyc/securitize/constants.js +4 -0
- package/dist/esm/sdk/market/kyc/securitize/index.js +3 -0
- package/dist/esm/sdk/market/kyc/securitize/types.js +0 -0
- package/dist/esm/sdk/market/kyc/types.js +9 -0
- package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +11 -2
- package/dist/esm/sdk/market/pool/index.js +1 -0
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
- package/dist/esm/sdk/options.js +6 -0
- package/dist/esm/sdk/pools/PoolService.js +109 -13
- package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +14 -0
- package/dist/esm/sdk/utils/viem/index.js +1 -2
- package/dist/types/abi/kyc/iDSRegistryService.d.ts +191 -0
- package/dist/types/abi/kyc/iDSToken.d.ts +67 -0
- package/dist/types/abi/kyc/iKYCCompressor.d.ts +228 -0
- package/dist/types/abi/kyc/iKYCFactory.d.ts +139 -0
- package/dist/types/abi/kyc/iKYCUnderlying.d.ts +548 -0
- package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +404 -0
- package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +376 -0
- package/dist/types/sdk/OnchainSDK.d.ts +19 -1
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +59 -6
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +114 -14
- package/dist/types/sdk/base/TokensMeta.d.ts +14 -3
- package/dist/types/sdk/base/token-types.d.ts +44 -4
- package/dist/types/sdk/base/types.d.ts +116 -2
- package/dist/types/sdk/chain/chains.d.ts +5 -1
- package/dist/types/sdk/constants/address-provider.d.ts +1 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +6 -9
- package/dist/types/sdk/market/MarketSuite.d.ts +2 -0
- package/dist/types/sdk/market/index.d.ts +1 -0
- package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +52 -0
- package/dist/types/sdk/market/kyc/index.d.ts +3 -0
- package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +429 -0
- package/dist/types/sdk/market/kyc/securitize/constants.d.ts +1 -0
- package/dist/types/sdk/market/kyc/securitize/index.d.ts +3 -0
- package/dist/types/sdk/market/kyc/securitize/types.d.ts +136 -0
- package/dist/types/sdk/market/kyc/types.d.ts +171 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +3 -2
- package/dist/types/sdk/market/oracle/types.d.ts +3 -10
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
- package/dist/types/sdk/market/pool/index.d.ts +1 -0
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +1 -1
- package/dist/types/sdk/market/types.d.ts +1 -1
- package/dist/types/sdk/options.d.ts +1 -0
- package/dist/types/sdk/pools/PoolService.d.ts +8 -8
- package/dist/types/sdk/pools/types.d.ts +1 -1
- package/dist/types/sdk/types/state-human.d.ts +2 -0
- package/dist/types/sdk/types/state.d.ts +5 -0
- package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +28 -0
- package/dist/types/sdk/utils/viem/index.d.ts +1 -2
- package/package.json +4 -4
- package/dist/cjs/sdk/utils/viem/getLogsPaginated.js +0 -62
- package/dist/cjs/sdk/utils/viem/getLogsSafe.js +0 -87
- package/dist/esm/sdk/accounts/utils.js +0 -14
- package/dist/esm/sdk/utils/viem/getLogsPaginated.js +0 -38
- package/dist/esm/sdk/utils/viem/getLogsSafe.js +0 -65
- package/dist/types/sdk/accounts/utils.d.ts +0 -2
- package/dist/types/sdk/utils/viem/getLogsPaginated.d.ts +0 -12
- package/dist/types/sdk/utils/viem/getLogsSafe.d.ts +0 -3
|
@@ -22,6 +22,7 @@ __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");
|
|
25
26
|
var import_viem = require("viem");
|
|
26
27
|
var import_generated = require("../../abi/310/generated.js");
|
|
27
28
|
var import_creditAccountCompressor = require("../../abi/compressors/creditAccountCompressor.js");
|
|
@@ -29,6 +30,7 @@ var import_peripheryCompressor = require("../../abi/compressors/peripheryCompres
|
|
|
29
30
|
var import_rewardsCompressor = require("../../abi/compressors/rewardsCompressor.js");
|
|
30
31
|
var import_IWithdrawalCompressorV310 = require("../../abi/IWithdrawalCompressorV310.js");
|
|
31
32
|
var import_iBaseRewardPool = require("../../abi/iBaseRewardPool.js");
|
|
33
|
+
var import_iKYCFactory = require("../../abi/kyc/iKYCFactory.js");
|
|
32
34
|
var import_base = require("../base/index.js");
|
|
33
35
|
var import_chains = require("../chain/chains.js");
|
|
34
36
|
var import_constants = require("../constants/index.js");
|
|
@@ -76,24 +78,40 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
76
78
|
} catch (_e) {
|
|
77
79
|
return void 0;
|
|
78
80
|
}
|
|
81
|
+
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
82
|
+
raw.creditManager
|
|
83
|
+
);
|
|
84
|
+
const factory = marketSuite.kycFactory;
|
|
85
|
+
let ca;
|
|
86
|
+
let investor;
|
|
79
87
|
if (raw.success) {
|
|
80
|
-
|
|
88
|
+
ca = raw;
|
|
89
|
+
investor = await factory?.getInvestor(raw.creditAccount, false);
|
|
90
|
+
} else {
|
|
91
|
+
const { txs: priceUpdateTxs } = await this.getUpdateForAccount(raw);
|
|
92
|
+
[ca, investor] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
|
|
93
|
+
priceUpdates: priceUpdateTxs,
|
|
94
|
+
contracts: [
|
|
95
|
+
{
|
|
96
|
+
abi: import_creditAccountCompressor.creditAccountCompressorAbi,
|
|
97
|
+
address: this.#compressor,
|
|
98
|
+
functionName: "getCreditAccountData",
|
|
99
|
+
args: [account]
|
|
100
|
+
},
|
|
101
|
+
...factory ? [
|
|
102
|
+
{
|
|
103
|
+
abi: import_iKYCFactory.iKYCFactoryAbi,
|
|
104
|
+
address: factory.address,
|
|
105
|
+
functionName: "getInvestor",
|
|
106
|
+
args: [raw.creditAccount]
|
|
107
|
+
}
|
|
108
|
+
] : []
|
|
109
|
+
],
|
|
110
|
+
blockNumber,
|
|
111
|
+
gas: this.sdk.gasLimit
|
|
112
|
+
});
|
|
81
113
|
}
|
|
82
|
-
|
|
83
|
-
const [cad] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
|
|
84
|
-
priceUpdates: priceUpdateTxs,
|
|
85
|
-
contracts: [
|
|
86
|
-
{
|
|
87
|
-
abi: import_creditAccountCompressor.creditAccountCompressorAbi,
|
|
88
|
-
address: this.#compressor,
|
|
89
|
-
functionName: "getCreditAccountData",
|
|
90
|
-
args: [account]
|
|
91
|
-
}
|
|
92
|
-
],
|
|
93
|
-
blockNumber,
|
|
94
|
-
gas: this.sdk.gasLimit
|
|
95
|
-
});
|
|
96
|
-
return cad;
|
|
114
|
+
return { ...ca, investor };
|
|
97
115
|
}
|
|
98
116
|
/**
|
|
99
117
|
* {@inheritDoc ICreditAccountsService.getCreditAccounts}
|
|
@@ -149,6 +167,99 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
149
167
|
);
|
|
150
168
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
151
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* {@inheritDoc ICreditAccountsService.getBorrowerCreditAccounts}
|
|
172
|
+
**/
|
|
173
|
+
async getBorrowerCreditAccounts(borrower, options, blockNumber) {
|
|
174
|
+
const {
|
|
175
|
+
creditManager,
|
|
176
|
+
includeZeroDebt = false,
|
|
177
|
+
maxHealthFactor = import_constants.MAX_UINT256,
|
|
178
|
+
minHealthFactor = 0n,
|
|
179
|
+
ignoreReservePrices = false
|
|
180
|
+
} = options ?? {};
|
|
181
|
+
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
182
|
+
ignoreReservePrices ? { main: true } : void 0
|
|
183
|
+
);
|
|
184
|
+
const investorDataList = await this.sdk.kyc.getInvestorData(borrower);
|
|
185
|
+
const kycAccountAddresses = investorDataList.flatMap(
|
|
186
|
+
(d) => d.creditAccounts.map((ca) => ca.creditAccount)
|
|
187
|
+
);
|
|
188
|
+
const cmFilter = creditManager ? {
|
|
189
|
+
configurators: [],
|
|
190
|
+
creditManagers: [creditManager],
|
|
191
|
+
pools: [],
|
|
192
|
+
underlying: import_constants.ADDRESS_0X0
|
|
193
|
+
} : {
|
|
194
|
+
configurators: this.marketConfigurators,
|
|
195
|
+
creditManagers: [],
|
|
196
|
+
pools: [],
|
|
197
|
+
underlying: import_constants.ADDRESS_0X0
|
|
198
|
+
};
|
|
199
|
+
const permissiveFilter = {
|
|
200
|
+
owner: borrower,
|
|
201
|
+
includeZeroDebt: true,
|
|
202
|
+
minHealthFactor: 0n,
|
|
203
|
+
maxHealthFactor: import_constants.MAX_UINT256,
|
|
204
|
+
reverting: false
|
|
205
|
+
};
|
|
206
|
+
const kycContracts = kycAccountAddresses.map(
|
|
207
|
+
(account) => ({
|
|
208
|
+
abi: import_creditAccountCompressor.creditAccountCompressorAbi,
|
|
209
|
+
address: this.#compressor,
|
|
210
|
+
functionName: "getCreditAccountData",
|
|
211
|
+
args: [account]
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
const getCreditAccountsContracts = [false, true].map(
|
|
215
|
+
(reverting) => ({
|
|
216
|
+
abi: import_creditAccountCompressor.creditAccountCompressorAbi,
|
|
217
|
+
address: this.#compressor,
|
|
218
|
+
functionName: "getCreditAccounts",
|
|
219
|
+
args: [cmFilter, { ...permissiveFilter, reverting }, 0n]
|
|
220
|
+
})
|
|
221
|
+
);
|
|
222
|
+
const allContracts = [...kycContracts, ...getCreditAccountsContracts];
|
|
223
|
+
const results = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
|
|
224
|
+
priceUpdates: priceUpdateTxs,
|
|
225
|
+
contracts: allContracts,
|
|
226
|
+
blockNumber,
|
|
227
|
+
gas: this.sdk.gasLimit
|
|
228
|
+
});
|
|
229
|
+
const kycResults = results.slice(
|
|
230
|
+
0,
|
|
231
|
+
kycAccountAddresses.length
|
|
232
|
+
);
|
|
233
|
+
const normalResults = results.slice(kycAccountAddresses.length);
|
|
234
|
+
const seen = new import_utils.AddressSet();
|
|
235
|
+
const allCAs = [];
|
|
236
|
+
for (const ca of kycResults) {
|
|
237
|
+
if (!seen.has(ca.creditAccount)) {
|
|
238
|
+
seen.add(ca.creditAccount);
|
|
239
|
+
allCAs.push({ ...ca, investor: borrower });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (const [accounts] of normalResults) {
|
|
243
|
+
for (const ca of accounts) {
|
|
244
|
+
if (!seen.has(ca.creditAccount)) {
|
|
245
|
+
seen.add(ca.creditAccount);
|
|
246
|
+
allCAs.push({ ...ca, investor: void 0 });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const filtered = allCAs.filter((ca) => {
|
|
251
|
+
if (!includeZeroDebt && ca.debt === 0n) return false;
|
|
252
|
+
if (ca.healthFactor < minHealthFactor) return false;
|
|
253
|
+
if (ca.healthFactor > maxHealthFactor) return false;
|
|
254
|
+
if (creditManager && !(0, import_utils.hexEq)(ca.creditManager, creditManager))
|
|
255
|
+
return false;
|
|
256
|
+
return true;
|
|
257
|
+
});
|
|
258
|
+
this.logger?.debug(
|
|
259
|
+
`loaded ${allCAs.length} borrower credit accounts (${kycResults.length} KYC, ${filtered.length} after filter)`
|
|
260
|
+
);
|
|
261
|
+
return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
262
|
+
}
|
|
152
263
|
/**
|
|
153
264
|
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
154
265
|
**/
|
|
@@ -358,6 +469,13 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
358
469
|
closePath
|
|
359
470
|
}) {
|
|
360
471
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
472
|
+
await this.sdk.tokensMeta.loadTokenData(cm.underlying);
|
|
473
|
+
const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
|
|
474
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
475
|
+
throw new Error(
|
|
476
|
+
"closeCreditAccount is not supported for KYC underlying credit accounts"
|
|
477
|
+
);
|
|
478
|
+
}
|
|
361
479
|
const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
|
|
362
480
|
creditAccount: ca,
|
|
363
481
|
creditManager: cm.creditManager,
|
|
@@ -463,8 +581,18 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
463
581
|
],
|
|
464
582
|
{}
|
|
465
583
|
) : [];
|
|
584
|
+
const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
|
|
585
|
+
collateral[0].balance,
|
|
586
|
+
creditAccount.creditManager
|
|
587
|
+
) || [] : [];
|
|
588
|
+
if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
|
|
589
|
+
throw new Error(
|
|
590
|
+
"Can't use collateral other than underlying for non KYC market"
|
|
591
|
+
);
|
|
592
|
+
}
|
|
466
593
|
const operationCalls = [
|
|
467
594
|
...addCollateralCalls,
|
|
595
|
+
...unwrapCalls,
|
|
468
596
|
this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
|
|
469
597
|
];
|
|
470
598
|
const calls = await this.prependPriceUpdates(
|
|
@@ -672,6 +800,29 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
672
800
|
const tx = await this.multicallTx(cm, creditAccount.creditAccount, calls);
|
|
673
801
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
674
802
|
}
|
|
803
|
+
/**
|
|
804
|
+
* {@inheritDoc ICreditAccountsService.getApprovalAddress}
|
|
805
|
+
**/
|
|
806
|
+
async getApprovalAddress(options) {
|
|
807
|
+
const { creditManager } = options;
|
|
808
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
809
|
+
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
810
|
+
const factory = marketSuite.kycFactory;
|
|
811
|
+
if (factory) {
|
|
812
|
+
return factory.getApprovalAddress(options);
|
|
813
|
+
}
|
|
814
|
+
return suite.creditManager.address;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
|
|
818
|
+
*/
|
|
819
|
+
async getOpenAccountRequirements(borrower, creditManager, props) {
|
|
820
|
+
const { kycFactory } = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
821
|
+
if (!kycFactory) {
|
|
822
|
+
return void 0;
|
|
823
|
+
}
|
|
824
|
+
return kycFactory.getOpenAccountRequirements(borrower, props);
|
|
825
|
+
}
|
|
675
826
|
/**
|
|
676
827
|
* {@inheritDoc ICreditAccountsService.openCA}
|
|
677
828
|
**/
|
|
@@ -689,7 +840,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
689
840
|
calls: openPathCalls,
|
|
690
841
|
callsAfter,
|
|
691
842
|
minQuota,
|
|
692
|
-
averageQuota
|
|
843
|
+
averageQuota,
|
|
844
|
+
kycOptions
|
|
693
845
|
} = props;
|
|
694
846
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
695
847
|
const cm = cmSuite.creditManager;
|
|
@@ -723,7 +875,13 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
723
875
|
if (reopenCreditAccount) {
|
|
724
876
|
tx = await this.multicallTx(cmSuite, reopenCreditAccount, calls);
|
|
725
877
|
} else {
|
|
726
|
-
tx = await this.openCreditAccountTx(
|
|
878
|
+
tx = await this.openCreditAccountTx(
|
|
879
|
+
cmSuite,
|
|
880
|
+
to,
|
|
881
|
+
calls,
|
|
882
|
+
referralCode,
|
|
883
|
+
kycOptions
|
|
884
|
+
);
|
|
727
885
|
}
|
|
728
886
|
tx.value = ethAmount.toString(10);
|
|
729
887
|
return { calls, tx, creditFacade: cmSuite.creditFacade };
|
|
@@ -806,6 +964,131 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
806
964
|
return resp;
|
|
807
965
|
}
|
|
808
966
|
/**
|
|
967
|
+
* Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
|
|
968
|
+
* Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
|
|
969
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
970
|
+
* @param amount - Number of vault shares (adapter tokens) to redeem
|
|
971
|
+
* @param creditManager - Credit manager address
|
|
972
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
973
|
+
*/
|
|
974
|
+
async getKYCUnwrapCalls(amount, creditManager) {
|
|
975
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
976
|
+
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
977
|
+
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
978
|
+
return void 0;
|
|
979
|
+
}
|
|
980
|
+
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
981
|
+
const adapterAddress = adapter?.address;
|
|
982
|
+
if (!adapterAddress) {
|
|
983
|
+
return void 0;
|
|
984
|
+
}
|
|
985
|
+
const mc = [
|
|
986
|
+
{
|
|
987
|
+
target: adapterAddress,
|
|
988
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
989
|
+
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
990
|
+
functionName: "redeem",
|
|
991
|
+
args: [amount, import_constants.ADDRESS_0X0, import_constants.ADDRESS_0X0]
|
|
992
|
+
})
|
|
993
|
+
}
|
|
994
|
+
];
|
|
995
|
+
return mc;
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
|
|
999
|
+
* Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
|
|
1000
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1001
|
+
* @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
|
|
1002
|
+
* @param creditManager - Credit manager address
|
|
1003
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1004
|
+
*/
|
|
1005
|
+
async getKYCWrapCalls(amount, creditManager) {
|
|
1006
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1007
|
+
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1008
|
+
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1009
|
+
return void 0;
|
|
1010
|
+
}
|
|
1011
|
+
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1012
|
+
const adapterAddress = adapter?.address;
|
|
1013
|
+
if (!adapterAddress) {
|
|
1014
|
+
return void 0;
|
|
1015
|
+
}
|
|
1016
|
+
const mc = [
|
|
1017
|
+
{
|
|
1018
|
+
target: adapterAddress,
|
|
1019
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
1020
|
+
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
1021
|
+
functionName: "deposit",
|
|
1022
|
+
args: [amount, import_constants.ADDRESS_0X0]
|
|
1023
|
+
})
|
|
1024
|
+
}
|
|
1025
|
+
];
|
|
1026
|
+
return mc;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1030
|
+
* Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
|
|
1031
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1032
|
+
* @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
|
|
1033
|
+
* @param creditManager - Credit manager address
|
|
1034
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1035
|
+
*/
|
|
1036
|
+
async getRedeemDiffCalls(amount, creditManager) {
|
|
1037
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1038
|
+
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1039
|
+
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1040
|
+
return void 0;
|
|
1041
|
+
}
|
|
1042
|
+
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1043
|
+
const adapterAddress = adapter?.address;
|
|
1044
|
+
if (!adapterAddress) {
|
|
1045
|
+
return void 0;
|
|
1046
|
+
}
|
|
1047
|
+
const mc = [
|
|
1048
|
+
{
|
|
1049
|
+
target: adapterAddress,
|
|
1050
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
1051
|
+
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
1052
|
+
functionName: "redeemDiff",
|
|
1053
|
+
args: [amount]
|
|
1054
|
+
})
|
|
1055
|
+
}
|
|
1056
|
+
];
|
|
1057
|
+
return mc;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1061
|
+
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
1062
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1063
|
+
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
1064
|
+
* @param creditManager - Credit manager address
|
|
1065
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1066
|
+
*/
|
|
1067
|
+
async getDepositDiffCalls(amount, creditManager) {
|
|
1068
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1069
|
+
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1070
|
+
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1071
|
+
return void 0;
|
|
1072
|
+
}
|
|
1073
|
+
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1074
|
+
const adapterAddress = adapter?.address;
|
|
1075
|
+
if (!adapterAddress) {
|
|
1076
|
+
return void 0;
|
|
1077
|
+
}
|
|
1078
|
+
const mc = [
|
|
1079
|
+
{
|
|
1080
|
+
target: adapterAddress,
|
|
1081
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
1082
|
+
abi: import_integrations_v3.ierc4626AdapterAbi,
|
|
1083
|
+
functionName: "depositDiff",
|
|
1084
|
+
args: [amount]
|
|
1085
|
+
})
|
|
1086
|
+
}
|
|
1087
|
+
];
|
|
1088
|
+
return mc;
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
809
1092
|
* {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
|
|
810
1093
|
**/
|
|
811
1094
|
async getOnDemandPriceUpdates(account, ignoreReservePrices) {
|
|
@@ -1060,9 +1343,19 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1060
1343
|
* @param to
|
|
1061
1344
|
* @param calls
|
|
1062
1345
|
* @param referralCode
|
|
1346
|
+
* @param kycOptions
|
|
1063
1347
|
* @returns
|
|
1064
1348
|
*/
|
|
1065
|
-
async openCreditAccountTx(suite, to, calls, referralCode) {
|
|
1349
|
+
async openCreditAccountTx(suite, to, calls, referralCode, kycOptions) {
|
|
1350
|
+
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
1351
|
+
const factory = marketSuite.kycFactory;
|
|
1352
|
+
if (factory) {
|
|
1353
|
+
return factory.openCreditAccount(
|
|
1354
|
+
suite.creditManager.address,
|
|
1355
|
+
calls,
|
|
1356
|
+
kycOptions
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1066
1359
|
return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
|
|
1067
1360
|
}
|
|
1068
1361
|
/**
|
|
@@ -1070,9 +1363,17 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1070
1363
|
* @param suite
|
|
1071
1364
|
* @param creditAccount
|
|
1072
1365
|
* @param calls
|
|
1366
|
+
* @param kycOptions
|
|
1073
1367
|
* @returns
|
|
1074
1368
|
*/
|
|
1075
|
-
async multicallTx(suite, creditAccount, calls) {
|
|
1369
|
+
async multicallTx(suite, creditAccount, calls, kycOptions) {
|
|
1370
|
+
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1371
|
+
suite.creditManager.address
|
|
1372
|
+
);
|
|
1373
|
+
const factory = marketSuite.kycFactory;
|
|
1374
|
+
if (factory) {
|
|
1375
|
+
return factory.multicall(creditAccount, calls, kycOptions);
|
|
1376
|
+
}
|
|
1076
1377
|
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1077
1378
|
}
|
|
1078
1379
|
/**
|
|
@@ -1081,12 +1382,25 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1081
1382
|
* @param creditAccount
|
|
1082
1383
|
* @param calls
|
|
1083
1384
|
* @param operation
|
|
1385
|
+
* @param kycOptions
|
|
1084
1386
|
* @returns
|
|
1085
1387
|
*/
|
|
1086
|
-
async closeCreditAccountTx(suite, creditAccount, calls, operation) {
|
|
1388
|
+
async closeCreditAccountTx(suite, creditAccount, calls, operation, kycOptions) {
|
|
1389
|
+
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1390
|
+
suite.creditManager.address
|
|
1391
|
+
);
|
|
1392
|
+
const factory = marketSuite.kycFactory;
|
|
1087
1393
|
if (operation === "close") {
|
|
1394
|
+
if (factory) {
|
|
1395
|
+
throw new Error(
|
|
1396
|
+
"CloseOptions=close is not supported for KYC underlying credit accounts"
|
|
1397
|
+
);
|
|
1398
|
+
}
|
|
1088
1399
|
return suite.creditFacade.closeCreditAccount(creditAccount, calls);
|
|
1089
1400
|
}
|
|
1401
|
+
if (factory) {
|
|
1402
|
+
return factory.multicall(creditAccount, calls, kycOptions);
|
|
1403
|
+
}
|
|
1090
1404
|
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1091
1405
|
}
|
|
1092
1406
|
}
|
|
@@ -113,19 +113,23 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
113
113
|
creditAccount: ca,
|
|
114
114
|
permits,
|
|
115
115
|
to,
|
|
116
|
-
tokensToClaim
|
|
116
|
+
tokensToClaim,
|
|
117
|
+
calls: wrapCalls = []
|
|
117
118
|
}) {
|
|
118
119
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
119
120
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
120
121
|
const router = this.sdk.routerFor(ca);
|
|
122
|
+
const unwrapCalls = await this.getRedeemDiffCalls(1n, ca.creditManager) ?? [];
|
|
121
123
|
const claimPath = await router.findClaimAllRewards({
|
|
122
124
|
tokensToClaim,
|
|
123
125
|
creditAccount: ca
|
|
124
126
|
});
|
|
125
127
|
const operationCalls = [
|
|
126
128
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
129
|
+
...wrapCalls,
|
|
127
130
|
...this.prepareDisableQuotas(ca),
|
|
128
131
|
...this.prepareDecreaseDebt(ca),
|
|
132
|
+
...unwrapCalls,
|
|
129
133
|
...claimPath.calls,
|
|
130
134
|
...assetsToWithdraw.map(
|
|
131
135
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
@@ -157,10 +161,12 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
157
161
|
tokensToClaim,
|
|
158
162
|
creditAccount: ca
|
|
159
163
|
});
|
|
164
|
+
const wrapCalls = await this.getDepositDiffCalls(1n, ca.creditManager) ?? [];
|
|
160
165
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
161
166
|
const operationCalls = [
|
|
162
167
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
163
168
|
...claimPath.calls,
|
|
169
|
+
...wrapCalls,
|
|
164
170
|
...assetsToWithdraw.map(
|
|
165
171
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
166
172
|
)
|
|
@@ -21,7 +21,6 @@ __export(TokensMeta_exports, {
|
|
|
21
21
|
TokensMeta: () => TokensMeta
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(TokensMeta_exports);
|
|
24
|
-
var import_viem = require("viem");
|
|
25
24
|
var import_iStateSerializer = require("../../abi/iStateSerializer.js");
|
|
26
25
|
var import_iVersion = require("../../abi/iVersion.js");
|
|
27
26
|
var import_utils = require("../utils/index.js");
|
|
@@ -81,6 +80,14 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
81
80
|
}
|
|
82
81
|
return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
|
|
83
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns true if the token is a KYC underlying token, throws if the token data is not loaded
|
|
85
|
+
* @param t
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
isKYCUnderlying(t) {
|
|
89
|
+
return !!t.contractType?.startsWith("KYC_UNDERLYING::");
|
|
90
|
+
}
|
|
84
91
|
/**
|
|
85
92
|
* Returns a map of all phantom tokens
|
|
86
93
|
* Throws if token data is not loaded
|
|
@@ -94,6 +101,19 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
94
101
|
}
|
|
95
102
|
return result;
|
|
96
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns a map of all KYC underlying tokens
|
|
106
|
+
* Throws if token data is not loaded
|
|
107
|
+
*/
|
|
108
|
+
get kycUnderlyings() {
|
|
109
|
+
const result = new import_utils.AddressMap();
|
|
110
|
+
for (const [token, meta] of this.entries()) {
|
|
111
|
+
if (this.isKYCUnderlying(meta)) {
|
|
112
|
+
result.upsert(token, meta);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
97
117
|
formatBN(arg0, arg1, arg2) {
|
|
98
118
|
const token = typeof arg0 === "object" ? arg0.token : arg0;
|
|
99
119
|
const amount = typeof arg0 === "object" ? arg0.balance : arg1;
|
|
@@ -124,7 +144,7 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
124
144
|
}
|
|
125
145
|
/**
|
|
126
146
|
* Loads token information about phantom tokens
|
|
127
|
-
*
|
|
147
|
+
* In future other custom tokens types that do not have compressors might be handled here
|
|
128
148
|
*
|
|
129
149
|
* @param tokens - tokens to load data for, defaults to all tokens
|
|
130
150
|
*/
|
|
@@ -170,46 +190,6 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
170
190
|
}
|
|
171
191
|
return this.mustGet(token);
|
|
172
192
|
}
|
|
173
|
-
async #loadWithoutCompressor(tokens_) {
|
|
174
|
-
if (tokens_.size === 0) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const tokens = Array.from(tokens_);
|
|
178
|
-
const resp = await this.#client.multicall({
|
|
179
|
-
contracts: tokens.flatMap(
|
|
180
|
-
(t) => [
|
|
181
|
-
{
|
|
182
|
-
address: t,
|
|
183
|
-
abi: import_viem.erc20Abi,
|
|
184
|
-
functionName: "symbol"
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
address: t,
|
|
188
|
-
abi: import_viem.erc20Abi,
|
|
189
|
-
functionName: "name"
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
address: t,
|
|
193
|
-
abi: import_viem.erc20Abi,
|
|
194
|
-
functionName: "decimals"
|
|
195
|
-
}
|
|
196
|
-
]
|
|
197
|
-
),
|
|
198
|
-
allowFailure: false,
|
|
199
|
-
batchSize: 0
|
|
200
|
-
});
|
|
201
|
-
this.#logger?.debug(
|
|
202
|
-
`loaded ${resp.length} basic metadata without compressor`
|
|
203
|
-
);
|
|
204
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
205
|
-
this.upsert(tokens[i], {
|
|
206
|
-
addr: tokens[i],
|
|
207
|
-
symbol: resp[3 * i],
|
|
208
|
-
name: resp[3 * i + 1],
|
|
209
|
-
decimals: resp[3 * i + 2]
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
193
|
}
|
|
214
194
|
// Annotate the CommonJS export names for ESM import in node:
|
|
215
195
|
0 && (module.exports = {
|
|
@@ -18,6 +18,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var token_types_exports = {};
|
|
20
20
|
__export(token_types_exports, {
|
|
21
|
+
KYC_ON_DEMAND_LP_MONOPOLIZED: () => KYC_ON_DEMAND_LP_MONOPOLIZED,
|
|
22
|
+
KYC_UNDERLYING_DEFAULT: () => KYC_UNDERLYING_DEFAULT,
|
|
23
|
+
KYC_UNDERLYING_ON_DEMAND: () => KYC_UNDERLYING_ON_DEMAND,
|
|
21
24
|
PHANTOM_TOKEN_CONTRACT_TYPES: () => PHANTOM_TOKEN_CONTRACT_TYPES
|
|
22
25
|
});
|
|
23
26
|
module.exports = __toCommonJS(token_types_exports);
|
|
@@ -30,7 +33,13 @@ const PHANTOM_TOKEN_CONTRACT_TYPES = [
|
|
|
30
33
|
"PHANTOM_TOKEN::STAKING_REWARDS",
|
|
31
34
|
"PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
|
|
32
35
|
];
|
|
36
|
+
const KYC_UNDERLYING_DEFAULT = "KYC_UNDERLYING::DEFAULT";
|
|
37
|
+
const KYC_UNDERLYING_ON_DEMAND = "KYC_UNDERLYING::ON_DEMAND";
|
|
38
|
+
const KYC_ON_DEMAND_LP_MONOPOLIZED = "ON_DEMAND_LP::MONOPOLIZED";
|
|
33
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
40
|
0 && (module.exports = {
|
|
41
|
+
KYC_ON_DEMAND_LP_MONOPOLIZED,
|
|
42
|
+
KYC_UNDERLYING_DEFAULT,
|
|
43
|
+
KYC_UNDERLYING_ON_DEMAND,
|
|
35
44
|
PHANTOM_TOKEN_CONTRACT_TYPES
|
|
36
45
|
});
|