@gearbox-protocol/sdk 13.3.0-next.2 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common-utils/charts/credit-manager-payload.js +16 -0
- package/dist/cjs/common-utils/charts/credit-manager.js +134 -0
- package/dist/cjs/common-utils/charts/credit-session.js +257 -0
- package/dist/cjs/common-utils/charts/credit-sessions-payload.js +16 -0
- package/dist/cjs/common-utils/charts/graph-payload.js +16 -0
- package/dist/cjs/common-utils/charts/index.js +36 -0
- package/dist/cjs/common-utils/charts/pool-payload.js +16 -0
- package/dist/cjs/common-utils/charts/pool.js +199 -0
- package/dist/cjs/common-utils/charts/token-data.js +91 -0
- package/dist/cjs/common-utils/index.js +4 -0
- package/dist/cjs/common-utils/static/index.js +28 -0
- package/dist/cjs/common-utils/static/migration-config.js +16 -0
- package/dist/cjs/common-utils/static/pool-config.js +16 -0
- package/dist/cjs/common-utils/static/strategy.js +16 -0
- package/dist/cjs/common-utils/static/trading-pair.js +16 -0
- package/dist/cjs/common-utils/utils/{assetsMath.js → assets-math.js} +13 -13
- package/dist/cjs/common-utils/utils/{bigintMath.js → bigint-math.js} +3 -3
- package/dist/cjs/common-utils/utils/creditAccount/{calcHealthFactor.js → calc-health-factor.js} +9 -9
- package/dist/cjs/common-utils/utils/creditAccount/{calcOverallAPY.js → calc-overall-apy.js} +8 -8
- package/dist/cjs/common-utils/utils/creditAccount/{calcQuotaBorrowRate.js → calc-quota-borrow-rate.js} +3 -3
- package/dist/cjs/common-utils/utils/creditAccount/{calcRelativeBaseBorrowRate.js → calc-relative-base-borrow-rate.js} +3 -3
- package/dist/cjs/common-utils/utils/creditAccount/debt.js +4 -4
- package/dist/cjs/common-utils/utils/creditAccount/{getTimeToLiquidation.js → get-time-to-liquidation.js} +3 -3
- package/dist/cjs/common-utils/utils/creditAccount/index.js +16 -16
- package/dist/cjs/common-utils/utils/creditAccount/{liquidationPrice.js → liquidation-price.js} +3 -3
- package/dist/cjs/common-utils/utils/creditAccount/{quotaUtils.js → quota-utils.js} +8 -8
- package/dist/cjs/common-utils/utils/creditAccount/sort.js +3 -3
- package/dist/cjs/common-utils/utils/index.js +6 -8
- package/dist/cjs/common-utils/utils/{priceMath.js → price-math.js} +3 -3
- package/dist/cjs/dev/AccountOpener.js +5 -45
- package/dist/cjs/dev/index.js +0 -2
- package/dist/cjs/plugins/zappers/ZappersPlugin.js +144 -0
- package/dist/cjs/{sdk/market/ZapperRegister.js → plugins/zappers/extraZappers.js} +6 -110
- package/dist/cjs/plugins/zappers/index.js +26 -0
- package/dist/cjs/plugins/zappers/package.json +1 -0
- package/dist/cjs/rewards/apy/index.js +24 -0
- package/dist/cjs/rewards/apy/output-details.js +16 -0
- package/dist/cjs/rewards/apy/output.js +16 -0
- package/dist/cjs/rewards/index.js +24 -0
- package/dist/cjs/rewards/package.json +1 -0
- package/dist/cjs/rewards/rewards/api.js +226 -0
- package/dist/cjs/rewards/rewards/apy.js +177 -0
- package/dist/cjs/rewards/rewards/common.js +16 -0
- package/dist/cjs/rewards/rewards/extra-apy.js +132 -0
- package/dist/cjs/rewards/rewards/index.js +28 -0
- package/dist/cjs/rewards/rewards/merkl-api.js +52 -0
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +104 -462
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -16
- package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
- package/dist/cjs/sdk/base/TokensMeta.js +32 -255
- package/dist/cjs/sdk/base/index.js +0 -2
- package/dist/cjs/sdk/chain/chains.js +1 -2
- package/dist/cjs/sdk/constants/index.js +2 -0
- package/dist/cjs/sdk/{base/token-types.js → constants/phantom-tokens.js} +3 -9
- package/dist/cjs/sdk/market/MarketRegister.js +2 -2
- package/dist/cjs/sdk/market/MarketSuite.js +0 -6
- package/dist/cjs/sdk/market/index.js +1 -3
- 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/AbstractPoolService.js +137 -0
- package/dist/cjs/{abi/iStateSerializer.js → sdk/pools/PoolServiceV310.js} +8 -14
- package/dist/cjs/sdk/pools/createPoolService.js +35 -0
- package/dist/cjs/sdk/pools/index.js +4 -2
- package/dist/cjs/sdk/utils/AddressMap.js +1 -1
- package/dist/cjs/sdk/utils/viem/sendRawTx.js +0 -16
- package/dist/esm/common-utils/charts/credit-manager.js +115 -0
- package/dist/esm/common-utils/charts/credit-session.js +233 -0
- package/dist/esm/common-utils/charts/credit-sessions-payload.js +0 -0
- package/dist/esm/common-utils/charts/graph-payload.js +0 -0
- package/dist/esm/common-utils/charts/index.js +8 -0
- package/dist/esm/common-utils/charts/pool-payload.js +0 -0
- package/dist/esm/common-utils/charts/pool.js +179 -0
- package/dist/esm/common-utils/charts/token-data.js +67 -0
- package/dist/esm/common-utils/index.js +2 -0
- package/dist/esm/common-utils/static/index.js +4 -0
- package/dist/esm/common-utils/static/migration-config.js +0 -0
- package/dist/esm/common-utils/static/pool-config.js +0 -0
- package/dist/esm/common-utils/static/strategy.js +0 -0
- package/dist/esm/common-utils/static/trading-pair.js +0 -0
- package/dist/esm/common-utils/utils/{assetsMath.js → assets-math.js} +2 -2
- package/dist/esm/common-utils/utils/creditAccount/{calcHealthFactor.js → calc-health-factor.js} +2 -2
- package/dist/esm/common-utils/utils/creditAccount/{calcOverallAPY.js → calc-overall-apy.js} +1 -1
- package/dist/esm/common-utils/utils/creditAccount/debt.js +2 -2
- package/dist/esm/common-utils/utils/creditAccount/index.js +8 -8
- package/dist/esm/common-utils/utils/creditAccount/{quotaUtils.js → quota-utils.js} +1 -1
- package/dist/esm/common-utils/utils/creditAccount/sort.js +1 -1
- package/dist/esm/common-utils/utils/index.js +3 -4
- package/dist/esm/dev/AccountOpener.js +6 -47
- package/dist/esm/dev/index.js +0 -2
- package/dist/esm/plugins/zappers/ZappersPlugin.js +126 -0
- package/dist/esm/{sdk/market/ZapperRegister.js → plugins/zappers/extraZappers.js} +2 -109
- package/dist/esm/plugins/zappers/index.js +3 -0
- package/dist/esm/plugins/zappers/package.json +1 -0
- package/dist/esm/plugins/zappers/types.js +0 -0
- package/dist/esm/rewards/apy/index.js +2 -0
- package/dist/esm/rewards/apy/output-details.js +0 -0
- package/dist/esm/rewards/apy/output.js +0 -0
- package/dist/esm/rewards/index.js +2 -0
- package/dist/esm/rewards/package.json +1 -0
- package/dist/esm/rewards/rewards/api.js +204 -0
- package/dist/esm/rewards/rewards/apy.js +160 -0
- package/dist/esm/rewards/rewards/common.js +0 -0
- package/dist/esm/rewards/rewards/extra-apy.js +101 -0
- package/dist/esm/rewards/rewards/index.js +4 -0
- package/dist/esm/rewards/rewards/merkl-api.js +18 -0
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +104 -462
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -16
- package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +32 -261
- package/dist/esm/sdk/base/index.js +0 -1
- package/dist/esm/sdk/chain/chains.js +1 -2
- package/dist/esm/sdk/constants/index.js +1 -0
- package/dist/esm/sdk/{base/token-types.js → constants/phantom-tokens.js} +0 -4
- package/dist/esm/sdk/market/MarketRegister.js +2 -2
- package/dist/esm/sdk/market/MarketSuite.js +0 -6
- package/dist/esm/sdk/market/index.js +0 -1
- 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/AbstractPoolService.js +113 -0
- package/dist/esm/sdk/pools/PoolServiceV310.js +6 -0
- package/dist/esm/sdk/pools/createPoolService.js +11 -0
- package/dist/esm/sdk/pools/index.js +2 -1
- package/dist/esm/sdk/utils/AddressMap.js +1 -1
- package/dist/esm/sdk/utils/viem/sendRawTx.js +1 -19
- package/dist/types/common-utils/charts/credit-manager-payload.d.ts +50 -0
- package/dist/types/common-utils/charts/credit-manager.d.ts +48 -0
- package/dist/types/common-utils/charts/credit-session.d.ts +111 -0
- package/dist/types/common-utils/charts/credit-sessions-payload.d.ts +111 -0
- package/dist/types/common-utils/charts/graph-payload.d.ts +10 -0
- package/dist/types/common-utils/charts/index.d.ts +8 -0
- package/dist/types/common-utils/charts/pool-payload.d.ts +111 -0
- package/dist/types/common-utils/charts/pool.d.ts +91 -0
- package/dist/types/common-utils/charts/token-data.d.ts +20 -0
- package/dist/types/common-utils/index.d.ts +2 -0
- package/dist/types/common-utils/static/index.d.ts +4 -0
- package/dist/types/common-utils/static/migration-config.d.ts +10 -0
- package/dist/types/common-utils/static/pool-config.d.ts +11 -0
- package/dist/types/common-utils/static/strategy.d.ts +78 -0
- package/dist/types/common-utils/static/trading-pair.d.ts +15 -0
- package/dist/types/common-utils/utils/creditAccount/index.d.ts +8 -8
- package/dist/types/common-utils/utils/index.d.ts +3 -4
- package/dist/types/dev/index.d.ts +1 -1
- package/dist/types/plugins/zappers/ZappersPlugin.d.ts +18 -0
- package/dist/types/plugins/zappers/extraZappers.d.ts +6 -0
- package/dist/types/plugins/zappers/index.d.ts +3 -0
- package/dist/types/plugins/zappers/types.d.ts +12 -0
- package/dist/types/rewards/apy/index.d.ts +2 -0
- package/dist/types/rewards/apy/output-details.d.ts +97 -0
- package/dist/types/rewards/apy/output.d.ts +22 -0
- package/dist/types/rewards/index.d.ts +2 -0
- package/dist/types/rewards/rewards/api.d.ts +49 -0
- package/dist/types/rewards/rewards/apy.d.ts +41 -0
- package/dist/types/rewards/rewards/common.d.ts +16 -0
- package/dist/types/rewards/rewards/extra-apy.d.ts +30 -0
- package/dist/types/rewards/rewards/index.d.ts +4 -0
- package/dist/types/rewards/rewards/merkl-api.d.ts +45 -0
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +27 -123
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +8 -108
- package/dist/types/sdk/base/TokensMeta.d.ts +18 -34
- package/dist/types/sdk/base/index.d.ts +0 -1
- package/dist/types/sdk/base/types.d.ts +1 -0
- package/dist/types/sdk/chain/chains.d.ts +1 -1
- package/dist/types/sdk/constants/index.d.ts +1 -0
- package/dist/types/sdk/constants/phantom-tokens.d.ts +2 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
- package/dist/types/sdk/market/MarketSuite.d.ts +0 -3
- package/dist/types/sdk/market/index.d.ts +0 -1
- 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/pools/AbstractPoolService.d.ts +9 -0
- package/dist/types/sdk/pools/PoolServiceV310.d.ts +4 -0
- package/dist/types/sdk/pools/createPoolService.d.ts +3 -0
- package/dist/types/sdk/pools/index.d.ts +2 -1
- package/dist/types/sdk/pools/types.d.ts +63 -84
- package/dist/types/sdk/utils/AddressMap.d.ts +1 -1
- package/dist/types/sdk/utils/viem/sendRawTx.d.ts +1 -5
- package/package.json +6 -1
- package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +0 -263
- package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +0 -278
- package/dist/cjs/common-utils/utils/endpoints.js +0 -65
- package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +0 -97
- package/dist/cjs/sdk/pools/PoolService.js +0 -391
- package/dist/esm/abi/310/iSecuritizeDegenNFT.js +0 -239
- package/dist/esm/abi/310/iSecuritizeKYCFactory.js +0 -254
- package/dist/esm/abi/iStateSerializer.js +0 -12
- package/dist/esm/common-utils/utils/endpoints.js +0 -41
- package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +0 -73
- package/dist/esm/sdk/pools/PoolService.js +0 -371
- package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +0 -324
- package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +0 -322
- package/dist/types/abi/iStateSerializer.d.ts +0 -11
- package/dist/types/common-utils/utils/endpoints.d.ts +0 -27
- package/dist/types/sdk/base/token-types.d.ts +0 -33
- package/dist/types/sdk/market/ZapperRegister.d.ts +0 -17
- package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +0 -345
- package/dist/types/sdk/market/types.d.ts +0 -10
- package/dist/types/sdk/pools/PoolService.d.ts +0 -14
- /package/dist/cjs/{sdk/market → plugins/zappers}/types.js +0 -0
- /package/dist/esm/{sdk/market/types.js → common-utils/charts/credit-manager-payload.js} +0 -0
- /package/dist/esm/common-utils/utils/{bigintMath.js → bigint-math.js} +0 -0
- /package/dist/esm/common-utils/utils/creditAccount/{calcQuotaBorrowRate.js → calc-quota-borrow-rate.js} +0 -0
- /package/dist/esm/common-utils/utils/creditAccount/{calcRelativeBaseBorrowRate.js → calc-relative-base-borrow-rate.js} +0 -0
- /package/dist/esm/common-utils/utils/creditAccount/{getTimeToLiquidation.js → get-time-to-liquidation.js} +0 -0
- /package/dist/esm/common-utils/utils/creditAccount/{liquidationPrice.js → liquidation-price.js} +0 -0
- /package/dist/esm/common-utils/utils/{priceMath.js → price-math.js} +0 -0
- /package/dist/types/common-utils/utils/{assetsMath.d.ts → assets-math.d.ts} +0 -0
- /package/dist/types/common-utils/utils/{bigintMath.d.ts → bigint-math.d.ts} +0 -0
- /package/dist/types/common-utils/utils/creditAccount/{calcHealthFactor.d.ts → calc-health-factor.d.ts} +0 -0
- /package/dist/types/common-utils/utils/creditAccount/{calcOverallAPY.d.ts → calc-overall-apy.d.ts} +0 -0
- /package/dist/types/common-utils/utils/creditAccount/{calcQuotaBorrowRate.d.ts → calc-quota-borrow-rate.d.ts} +0 -0
- /package/dist/types/common-utils/utils/creditAccount/{calcRelativeBaseBorrowRate.d.ts → calc-relative-base-borrow-rate.d.ts} +0 -0
- /package/dist/types/common-utils/utils/creditAccount/{getTimeToLiquidation.d.ts → get-time-to-liquidation.d.ts} +0 -0
- /package/dist/types/common-utils/utils/creditAccount/{liquidationPrice.d.ts → liquidation-price.d.ts} +0 -0
- /package/dist/types/common-utils/utils/creditAccount/{quotaUtils.d.ts → quota-utils.d.ts} +0 -0
- /package/dist/types/common-utils/utils/{priceMath.d.ts → price-math.d.ts} +0 -0
|
@@ -39,7 +39,6 @@ const COMPRESSORS = {
|
|
|
39
39
|
[import_chains.chains.Mainnet.id]: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023",
|
|
40
40
|
[import_chains.chains.Monad.id]: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023"
|
|
41
41
|
};
|
|
42
|
-
const INVESTORS = new import_utils.AddressMap([], "investors");
|
|
43
42
|
function getWithdrawalCompressorAddress(chainId) {
|
|
44
43
|
return COMPRESSORS[chainId];
|
|
45
44
|
}
|
|
@@ -101,23 +100,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
101
100
|
});
|
|
102
101
|
return cad;
|
|
103
102
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Returns credit account data for a single account with the investor address resolved.
|
|
106
|
-
* Loads CA via getCreditAccountData; for KYC underlyings fetches the investor from the KYC factory's getInvestor(creditAccount), otherwise uses the account owner.
|
|
107
|
-
* @param account - Credit account address
|
|
108
|
-
* @param blockNumber - Optional block number for the read
|
|
109
|
-
* @returns CreditAccountDataWithInvestor (CA data + investor address), or undefined if the account is not found
|
|
110
|
-
*/
|
|
111
|
-
async getCreditAccountDataWithInvestor(account, blockNumber) {
|
|
112
|
-
const ca = await this.getCreditAccountData(account, blockNumber);
|
|
113
|
-
if (!ca) return ca;
|
|
114
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
115
|
-
ca.creditManager
|
|
116
|
-
);
|
|
117
|
-
const factory = await marketSuite.getKYCFactory();
|
|
118
|
-
const investor = factory ? await factory.getInvestor(ca.creditAccount, true) : void 0;
|
|
119
|
-
return { ...ca, investor: investor ?? ca.owner };
|
|
120
|
-
}
|
|
121
103
|
/**
|
|
122
104
|
* Methods to get all credit accounts with some optional filtering
|
|
123
105
|
* Performs all necessary price feed updates under the hood
|
|
@@ -126,7 +108,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
126
108
|
* @param blockNumber
|
|
127
109
|
* @returns returned credit accounts are sorted by health factor in ascending order
|
|
128
110
|
*/
|
|
129
|
-
async getCreditAccounts(options, blockNumber
|
|
111
|
+
async getCreditAccounts(options, blockNumber) {
|
|
130
112
|
const {
|
|
131
113
|
creditManager,
|
|
132
114
|
includeZeroDebt = false,
|
|
@@ -148,7 +130,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
148
130
|
maxHealthFactor,
|
|
149
131
|
reverting: false
|
|
150
132
|
};
|
|
151
|
-
const { txs: priceUpdateTxs } =
|
|
133
|
+
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
152
134
|
ignoreReservePrices ? { main: true } : void 0
|
|
153
135
|
);
|
|
154
136
|
const allCAs = [];
|
|
@@ -177,75 +159,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
177
159
|
);
|
|
178
160
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
179
161
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Returns all credit accounts matching the filter, with investor set on each item.
|
|
182
|
-
* 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.
|
|
183
|
-
* @param options - Filter options (owner, creditManager, health factor, etc.)
|
|
184
|
-
* @param blockNumber - Optional block number for the read
|
|
185
|
-
* @returns Array of credit accounts (with investor field), sorted by health factor ascending
|
|
186
|
-
*/
|
|
187
|
-
async getCreditAccountsWithInvestor(options, blockNumber) {
|
|
188
|
-
const { owner, ignoreReservePrices = false } = options ?? {};
|
|
189
|
-
const priceUpdate = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
190
|
-
ignoreReservePrices ? { main: true } : void 0
|
|
191
|
-
);
|
|
192
|
-
const { txs: priceUpdateTxs } = priceUpdate;
|
|
193
|
-
const [common, kyc] = await Promise.all([
|
|
194
|
-
this.getCreditAccounts(options, blockNumber),
|
|
195
|
-
owner ? this.getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) : void 0
|
|
196
|
-
]);
|
|
197
|
-
const allCAs = common.map(
|
|
198
|
-
(ca) => ({
|
|
199
|
-
...ca,
|
|
200
|
-
investor: owner || ca.owner
|
|
201
|
-
})
|
|
202
|
-
);
|
|
203
|
-
allCAs.push(...kyc || []);
|
|
204
|
-
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
205
|
-
}
|
|
206
|
-
async getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) {
|
|
207
|
-
const suites = this.marketConfigurators.map((mc) => {
|
|
208
|
-
const suite = this.sdk.marketRegister.markets.find(
|
|
209
|
-
(m) => m.configurator.address === mc
|
|
210
|
-
);
|
|
211
|
-
return suite;
|
|
212
|
-
});
|
|
213
|
-
const kycCAAddresses = await this.getKYCCaOfInvestor(owner, suites);
|
|
214
|
-
const kycCAs = await this.loadSpecifiedAccounts(
|
|
215
|
-
kycCAAddresses,
|
|
216
|
-
priceUpdateTxs,
|
|
217
|
-
blockNumber
|
|
218
|
-
);
|
|
219
|
-
return kycCAs.map((ca) => ({
|
|
220
|
-
...ca,
|
|
221
|
-
investor: owner
|
|
222
|
-
}));
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Loads credit account data for the given addresses using simulateWithPriceUpdates.
|
|
226
|
-
* Applies the provided price update txs before reading, so returned data is consistent with up-to-date prices.
|
|
227
|
-
* @param accounts - Credit account addresses to load
|
|
228
|
-
* @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
|
|
229
|
-
* @param blockNumber - Optional block number for the read
|
|
230
|
-
* @returns Array of CreditAccountData in the same order as accounts (throws if any getCreditAccountData call reverts)
|
|
231
|
-
*/
|
|
232
|
-
async loadSpecifiedAccounts(accounts, priceUpdateTxs, blockNumber) {
|
|
233
|
-
if (accounts.length === 0) return [];
|
|
234
|
-
const list = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
|
|
235
|
-
priceUpdates: priceUpdateTxs,
|
|
236
|
-
contracts: accounts.map(
|
|
237
|
-
(account) => ({
|
|
238
|
-
abi: import_creditAccountCompressor.creditAccountCompressorAbi,
|
|
239
|
-
address: this.#compressor,
|
|
240
|
-
functionName: "getCreditAccountData",
|
|
241
|
-
args: [account]
|
|
242
|
-
})
|
|
243
|
-
),
|
|
244
|
-
blockNumber,
|
|
245
|
-
gas: this.sdk.gasLimit
|
|
246
|
-
});
|
|
247
|
-
return list;
|
|
248
|
-
}
|
|
249
162
|
/**
|
|
250
163
|
* Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
|
|
251
164
|
Assosiates rewards by adapter + stakedPhantomToken
|
|
@@ -476,13 +389,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
476
389
|
closePath
|
|
477
390
|
}) {
|
|
478
391
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
479
|
-
await this.sdk.tokensMeta.loadTokenData(cm.underlying);
|
|
480
|
-
const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
|
|
481
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
482
|
-
throw new Error(
|
|
483
|
-
"closeCreditAccount is not supported for KYC underlying credit accounts"
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
392
|
const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
|
|
487
393
|
creditAccount: ca,
|
|
488
394
|
creditManager: cm.creditManager,
|
|
@@ -501,12 +407,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
501
407
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t, import_constants.MAX_UINT256, to)
|
|
502
408
|
)
|
|
503
409
|
];
|
|
504
|
-
const tx =
|
|
505
|
-
cm,
|
|
506
|
-
ca.creditAccount,
|
|
507
|
-
calls,
|
|
508
|
-
operation
|
|
509
|
-
);
|
|
410
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
510
411
|
return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
|
|
511
412
|
}
|
|
512
413
|
/**
|
|
@@ -536,7 +437,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
536
437
|
averageQuota
|
|
537
438
|
})
|
|
538
439
|
];
|
|
539
|
-
const tx =
|
|
440
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
540
441
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
541
442
|
}
|
|
542
443
|
/**
|
|
@@ -578,7 +479,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
578
479
|
averageQuota
|
|
579
480
|
})
|
|
580
481
|
];
|
|
581
|
-
const tx =
|
|
482
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
582
483
|
tx.value = ethAmount.toString(10);
|
|
583
484
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
584
485
|
}
|
|
@@ -595,7 +496,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
595
496
|
async changeDebt({
|
|
596
497
|
creditAccount,
|
|
597
498
|
amount,
|
|
598
|
-
|
|
499
|
+
addCollateral
|
|
599
500
|
}) {
|
|
600
501
|
if (amount === 0n) {
|
|
601
502
|
throw new Error("debt increase or decrease must be non-zero");
|
|
@@ -609,32 +510,22 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
609
510
|
creditManager: creditAccount.creditManager,
|
|
610
511
|
creditAccount
|
|
611
512
|
});
|
|
612
|
-
const addCollateralCalls =
|
|
513
|
+
const addCollateralCalls = addCollateral && isDecrease ? this.prepareAddCollateral(
|
|
613
514
|
creditAccount.creditFacade,
|
|
614
515
|
[
|
|
615
516
|
{
|
|
616
|
-
token:
|
|
617
|
-
balance:
|
|
517
|
+
token: creditAccount.underlying,
|
|
518
|
+
balance: change
|
|
618
519
|
}
|
|
619
520
|
],
|
|
620
521
|
{}
|
|
621
522
|
) : [];
|
|
622
|
-
const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
|
|
623
|
-
collateral[0].balance,
|
|
624
|
-
creditAccount.creditManager
|
|
625
|
-
) || [] : [];
|
|
626
|
-
if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
|
|
627
|
-
throw new Error(
|
|
628
|
-
"Can't use collateral other than underlying for non KYC market"
|
|
629
|
-
);
|
|
630
|
-
}
|
|
631
523
|
const calls = [
|
|
632
524
|
...priceUpdatesCalls,
|
|
633
525
|
...addCollateralCalls,
|
|
634
|
-
...unwrapCalls,
|
|
635
526
|
this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
|
|
636
527
|
];
|
|
637
|
-
const tx =
|
|
528
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
638
529
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
639
530
|
}
|
|
640
531
|
/**
|
|
@@ -669,7 +560,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
669
560
|
averageQuota
|
|
670
561
|
})
|
|
671
562
|
];
|
|
672
|
-
const tx =
|
|
563
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
673
564
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
674
565
|
}
|
|
675
566
|
/**
|
|
@@ -785,7 +676,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
785
676
|
averageQuota
|
|
786
677
|
})
|
|
787
678
|
];
|
|
788
|
-
const tx =
|
|
679
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
789
680
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
790
681
|
}
|
|
791
682
|
/**
|
|
@@ -850,63 +741,48 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
850
741
|
compareBalances,
|
|
851
742
|
...quotaCalls
|
|
852
743
|
];
|
|
853
|
-
const tx =
|
|
744
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
854
745
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
855
746
|
}
|
|
856
|
-
/**
|
|
857
|
-
* Returns address to which approval should be given on collateral token
|
|
858
|
-
* It's credit manager for classical markets and special wallet for KYC markets
|
|
859
|
-
* @param options - {@link GetApprovalAddressProps}
|
|
860
|
-
* @returns
|
|
861
|
-
**/
|
|
862
|
-
async getApprovalAddress(options) {
|
|
863
|
-
const { creditManager } = options;
|
|
864
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
865
|
-
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
866
|
-
const factory = await marketSuite.getKYCFactory();
|
|
867
|
-
if (factory) {
|
|
868
|
-
if ("creditAccount" in options) {
|
|
869
|
-
return factory.getWallet(options.creditAccount);
|
|
870
|
-
}
|
|
871
|
-
return factory.precomputeWalletAddress(creditManager, options.borrower);
|
|
872
|
-
}
|
|
873
|
-
return suite.creditManager.address;
|
|
874
|
-
}
|
|
875
747
|
/**
|
|
876
748
|
* Executes swap specified by given calls, update quotas of affected tokens
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
749
|
+
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
|
|
750
|
+
-> update quotas -> (optionally: execute swap path for trading/strategy) ->
|
|
751
|
+
-> (optionally: withdraw debt for lending)
|
|
752
|
+
- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
|
|
753
|
+
- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
|
|
754
|
+
- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
|
|
755
|
+
- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
|
|
756
|
+
* @param {bigint} ethAmount - native token amount to attach to tx
|
|
757
|
+
* @param {Address} creditManager - address of credit manager to open credit account on
|
|
758
|
+
* @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
|
|
759
|
+
* @param {Record<Address, PermitResult>} permits - permits of collateral tokens (in any permittable token is present) {@link PermitResult}
|
|
760
|
+
* @param {bigint} debt - debt to open credit account with
|
|
761
|
+
* @param {boolean} withdrawDebt - flag to withdraw debt to wallet after opening credit account;
|
|
762
|
+
used for borrowing functionality
|
|
763
|
+
* @param {bigint} referralCode - referral code to open credit account with
|
|
764
|
+
* @param {Address} to - wallet address to transfer credit account to\
|
|
765
|
+
* @param {Array<MultiCall>} calls - array of MultiCall from router methods findOpenStrategyPath {@link MultiCall}.
|
|
766
|
+
Used for trading and strategy functionality
|
|
767
|
+
* @param {Array<Asset>} averageQuota - average quota for tokens after open {@link Asset}
|
|
768
|
+
* @param {Array<Asset>} minQuota - minimum quota for tokens after open {@link Asset}
|
|
884
769
|
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
885
|
-
|
|
886
|
-
async openCA(
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
minQuota,
|
|
900
|
-
averageQuota
|
|
901
|
-
} = props;
|
|
770
|
+
*/
|
|
771
|
+
async openCA({
|
|
772
|
+
ethAmount,
|
|
773
|
+
creditManager,
|
|
774
|
+
collateral,
|
|
775
|
+
permits,
|
|
776
|
+
debt,
|
|
777
|
+
withdrawDebt,
|
|
778
|
+
referralCode,
|
|
779
|
+
to,
|
|
780
|
+
calls: openPathCalls,
|
|
781
|
+
minQuota,
|
|
782
|
+
averageQuota
|
|
783
|
+
}) {
|
|
902
784
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
903
785
|
const cm = cmSuite.creditManager;
|
|
904
|
-
let tokenToWithdraw;
|
|
905
|
-
if (withdrawToken === true) {
|
|
906
|
-
tokenToWithdraw = cm.underlying;
|
|
907
|
-
} else if (typeof withdrawToken === "string") {
|
|
908
|
-
tokenToWithdraw = withdrawToken;
|
|
909
|
-
}
|
|
910
786
|
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
911
787
|
creditManager: cm.address,
|
|
912
788
|
desiredQuotas: averageQuota
|
|
@@ -916,27 +792,13 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
916
792
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
917
793
|
...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
|
|
918
794
|
...openPathCalls,
|
|
919
|
-
|
|
920
|
-
...tokenToWithdraw ? [
|
|
921
|
-
this.prepareWithdrawToken(
|
|
922
|
-
cm.creditFacade,
|
|
923
|
-
tokenToWithdraw,
|
|
924
|
-
import_constants.MAX_UINT256,
|
|
925
|
-
to
|
|
926
|
-
)
|
|
927
|
-
] : [],
|
|
795
|
+
...withdrawDebt ? [this.prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : [],
|
|
928
796
|
...this.prepareUpdateQuotas(cm.creditFacade, {
|
|
929
797
|
minQuota,
|
|
930
798
|
averageQuota
|
|
931
|
-
})
|
|
932
|
-
...callsAfter ?? []
|
|
799
|
+
})
|
|
933
800
|
];
|
|
934
|
-
|
|
935
|
-
if (reopenCreditAccount) {
|
|
936
|
-
tx = await this.multicallTx(cmSuite, reopenCreditAccount, calls);
|
|
937
|
-
} else {
|
|
938
|
-
tx = await this.openCreditAccountTx(cmSuite, to, calls, referralCode);
|
|
939
|
-
}
|
|
801
|
+
const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
|
|
940
802
|
tx.value = ethAmount.toString(10);
|
|
941
803
|
return { calls, tx, creditFacade: cmSuite.creditFacade };
|
|
942
804
|
}
|
|
@@ -1020,130 +882,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1020
882
|
);
|
|
1021
883
|
return resp;
|
|
1022
884
|
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
|
|
1025
|
-
* Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
|
|
1026
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1027
|
-
* @param amount - Number of vault shares (adapter tokens) to redeem
|
|
1028
|
-
* @param creditManager - Credit manager address
|
|
1029
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1030
|
-
*/
|
|
1031
|
-
async getKYCUnwrapCalls(amount, creditManager) {
|
|
1032
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1033
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1034
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1035
|
-
return void 0;
|
|
1036
|
-
}
|
|
1037
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1038
|
-
const adapterAddress = adapter?.address;
|
|
1039
|
-
if (!adapterAddress) {
|
|
1040
|
-
return void 0;
|
|
1041
|
-
}
|
|
1042
|
-
const mc = [
|
|
1043
|
-
{
|
|
1044
|
-
target: adapterAddress,
|
|
1045
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
1046
|
-
abi: ierc4626AdapterAbi,
|
|
1047
|
-
functionName: "redeem",
|
|
1048
|
-
args: [amount, import_constants.ADDRESS_0X0, import_constants.ADDRESS_0X0]
|
|
1049
|
-
})
|
|
1050
|
-
}
|
|
1051
|
-
];
|
|
1052
|
-
return mc;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
|
|
1056
|
-
* Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
|
|
1057
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1058
|
-
* @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
|
|
1059
|
-
* @param creditManager - Credit manager address
|
|
1060
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1061
|
-
*/
|
|
1062
|
-
async getKYCWrapCalls(amount, creditManager) {
|
|
1063
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1064
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1065
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1066
|
-
return void 0;
|
|
1067
|
-
}
|
|
1068
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1069
|
-
const adapterAddress = adapter?.address;
|
|
1070
|
-
if (!adapterAddress) {
|
|
1071
|
-
return void 0;
|
|
1072
|
-
}
|
|
1073
|
-
const mc = [
|
|
1074
|
-
{
|
|
1075
|
-
target: adapterAddress,
|
|
1076
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
1077
|
-
abi: ierc4626AdapterAbi,
|
|
1078
|
-
functionName: "deposit",
|
|
1079
|
-
args: [amount, import_constants.ADDRESS_0X0]
|
|
1080
|
-
})
|
|
1081
|
-
}
|
|
1082
|
-
];
|
|
1083
|
-
return mc;
|
|
1084
|
-
}
|
|
1085
|
-
/**
|
|
1086
|
-
* Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1087
|
-
* Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
|
|
1088
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1089
|
-
* @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
|
|
1090
|
-
* @param creditManager - Credit manager address
|
|
1091
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1092
|
-
*/
|
|
1093
|
-
async getRedeemDiffCalls(amount, creditManager) {
|
|
1094
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1095
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1096
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1097
|
-
return void 0;
|
|
1098
|
-
}
|
|
1099
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1100
|
-
const adapterAddress = adapter?.address;
|
|
1101
|
-
if (!adapterAddress) {
|
|
1102
|
-
return void 0;
|
|
1103
|
-
}
|
|
1104
|
-
const mc = [
|
|
1105
|
-
{
|
|
1106
|
-
target: adapterAddress,
|
|
1107
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
1108
|
-
abi: ierc4626AdapterAbi,
|
|
1109
|
-
functionName: "redeemDiff",
|
|
1110
|
-
args: [amount]
|
|
1111
|
-
})
|
|
1112
|
-
}
|
|
1113
|
-
];
|
|
1114
|
-
return mc;
|
|
1115
|
-
}
|
|
1116
|
-
/**
|
|
1117
|
-
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1118
|
-
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
1119
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1120
|
-
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
1121
|
-
* @param creditManager - Credit manager address
|
|
1122
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1123
|
-
*/
|
|
1124
|
-
async getDepositDiffCalls(amount, creditManager) {
|
|
1125
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1126
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1127
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1128
|
-
return void 0;
|
|
1129
|
-
}
|
|
1130
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1131
|
-
const adapterAddress = adapter?.address;
|
|
1132
|
-
if (!adapterAddress) {
|
|
1133
|
-
return void 0;
|
|
1134
|
-
}
|
|
1135
|
-
const mc = [
|
|
1136
|
-
{
|
|
1137
|
-
target: adapterAddress,
|
|
1138
|
-
callData: (0, import_viem.encodeFunctionData)({
|
|
1139
|
-
abi: ierc4626AdapterAbi,
|
|
1140
|
-
functionName: "depositDiff",
|
|
1141
|
-
args: [amount]
|
|
1142
|
-
})
|
|
1143
|
-
}
|
|
1144
|
-
];
|
|
1145
|
-
return mc;
|
|
1146
|
-
}
|
|
1147
885
|
/**
|
|
1148
886
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
1149
887
|
*
|
|
@@ -1371,174 +1109,78 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1371
1109
|
import_constants.VERSION_RANGE_310
|
|
1372
1110
|
)[0];
|
|
1373
1111
|
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Wrapper that selects between credit facade and KYC factory
|
|
1376
|
-
* @param suite
|
|
1377
|
-
* @param to
|
|
1378
|
-
* @param calls
|
|
1379
|
-
* @param referralCode
|
|
1380
|
-
* @returns
|
|
1381
|
-
*/
|
|
1382
|
-
async openCreditAccountTx(suite, to, calls, referralCode) {
|
|
1383
|
-
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
1384
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1385
|
-
if (factory) {
|
|
1386
|
-
const tokensToRegister = await factory.getDSTokens();
|
|
1387
|
-
return factory.openCreditAccount(
|
|
1388
|
-
suite.creditManager.address,
|
|
1389
|
-
calls,
|
|
1390
|
-
tokensToRegister
|
|
1391
|
-
);
|
|
1392
|
-
}
|
|
1393
|
-
return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
|
|
1394
|
-
}
|
|
1395
|
-
/**
|
|
1396
|
-
* Wrapper that selects between credit facade and KYC factory
|
|
1397
|
-
* @param suite
|
|
1398
|
-
* @param creditAccount
|
|
1399
|
-
* @param calls
|
|
1400
|
-
* @returns
|
|
1401
|
-
*/
|
|
1402
|
-
async multicallTx(suite, creditAccount, calls) {
|
|
1403
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1404
|
-
suite.creditManager.address
|
|
1405
|
-
);
|
|
1406
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1407
|
-
if (factory) {
|
|
1408
|
-
const tokensToRegister = [];
|
|
1409
|
-
return factory.multicall(creditAccount, calls, tokensToRegister);
|
|
1410
|
-
}
|
|
1411
|
-
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* Wrapper that selects between credit facade and KYC factory
|
|
1415
|
-
* @param suite
|
|
1416
|
-
* @param creditAccount
|
|
1417
|
-
* @param calls
|
|
1418
|
-
* @param operation
|
|
1419
|
-
* @returns
|
|
1420
|
-
*/
|
|
1421
|
-
async closeCreditAccountTx(suite, creditAccount, calls, operation) {
|
|
1422
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1423
|
-
suite.creditManager.address
|
|
1424
|
-
);
|
|
1425
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1426
|
-
if (operation === "close") {
|
|
1427
|
-
if (factory) {
|
|
1428
|
-
throw new Error(
|
|
1429
|
-
"CloseOptions=close is not supported for KYC underlying credit accounts"
|
|
1430
|
-
);
|
|
1431
|
-
}
|
|
1432
|
-
return suite.creditFacade.closeCreditAccount(creditAccount, calls);
|
|
1433
|
-
}
|
|
1434
|
-
if (factory) {
|
|
1435
|
-
const tokensToRegister = [];
|
|
1436
|
-
return factory.multicall(creditAccount, calls, tokensToRegister);
|
|
1437
|
-
}
|
|
1438
|
-
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1439
|
-
}
|
|
1440
|
-
/**
|
|
1441
|
-
* Returns all KYC credit account addresses for an investor across the given market suites.
|
|
1442
|
-
* Resolves KYC factory per suite, then multicalls each factory's getCreditAccounts(investor).
|
|
1443
|
-
* @param investor - Owner address to query
|
|
1444
|
-
* @param suites - Market suites (KYC factories are resolved for each; undefined entries are skipped)
|
|
1445
|
-
* @returns Flat array of credit account addresses from all KYC markets
|
|
1446
|
-
*/
|
|
1447
|
-
async getKYCCaOfInvestor(investor, suites) {
|
|
1448
|
-
if (suites.length === 0 || investor === import_constants.ADDRESS_0X0) return [];
|
|
1449
|
-
const factories = await Promise.all(
|
|
1450
|
-
suites.map((suite) => suite ? suite.getKYCFactory() : void 0)
|
|
1451
|
-
);
|
|
1452
|
-
const safeFactories = factories.reduce(
|
|
1453
|
-
(acc, v) => {
|
|
1454
|
-
if (v) {
|
|
1455
|
-
acc.push(v);
|
|
1456
|
-
}
|
|
1457
|
-
return acc;
|
|
1458
|
-
},
|
|
1459
|
-
[]
|
|
1460
|
-
);
|
|
1461
|
-
const allResp = await this.client.multicall({
|
|
1462
|
-
contracts: [
|
|
1463
|
-
...safeFactories.map((factory) => {
|
|
1464
|
-
return {
|
|
1465
|
-
abi: factory.abi,
|
|
1466
|
-
address: factory.address,
|
|
1467
|
-
functionName: "getCreditAccounts",
|
|
1468
|
-
args: [investor]
|
|
1469
|
-
};
|
|
1470
|
-
})
|
|
1471
|
-
],
|
|
1472
|
-
allowFailure: true,
|
|
1473
|
-
batchSize: 0
|
|
1474
|
-
});
|
|
1475
|
-
const caLists = safeFactories.reduce((acc, _, index) => {
|
|
1476
|
-
const response = allResp[index];
|
|
1477
|
-
acc.push(...response.result || []);
|
|
1478
|
-
return acc;
|
|
1479
|
-
}, []);
|
|
1480
|
-
return caLists;
|
|
1481
|
-
}
|
|
1482
1112
|
}
|
|
1483
|
-
const
|
|
1113
|
+
const iMellowClaimerAdapterAbi = [
|
|
1484
1114
|
{
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1115
|
+
type: "function",
|
|
1116
|
+
name: "getMultiVaultSubvaultIndices",
|
|
1117
|
+
inputs: [{ name: "multiVault", type: "address", internalType: "address" }],
|
|
1118
|
+
outputs: [
|
|
1119
|
+
{
|
|
1120
|
+
name: "subvaultIndices",
|
|
1121
|
+
type: "uint256[]",
|
|
1122
|
+
internalType: "uint256[]"
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
name: "withdrawalIndices",
|
|
1126
|
+
type: "uint256[][]",
|
|
1127
|
+
internalType: "uint256[][]"
|
|
1128
|
+
}
|
|
1499
1129
|
],
|
|
1500
|
-
|
|
1501
|
-
outputs: [{ name: "useSafePrices", type: "bool", internalType: "bool" }],
|
|
1502
|
-
stateMutability: "nonpayable",
|
|
1503
|
-
type: "function"
|
|
1130
|
+
stateMutability: "view"
|
|
1504
1131
|
},
|
|
1505
1132
|
{
|
|
1133
|
+
type: "function",
|
|
1134
|
+
name: "getUserSubvaultIndices",
|
|
1506
1135
|
inputs: [
|
|
1507
|
-
{
|
|
1508
|
-
|
|
1509
|
-
type: "uint256",
|
|
1510
|
-
internalType: "uint256"
|
|
1511
|
-
}
|
|
1136
|
+
{ name: "multiVault", type: "address", internalType: "address" },
|
|
1137
|
+
{ name: "user", type: "address", internalType: "address" }
|
|
1512
1138
|
],
|
|
1513
|
-
name: "redeemDiff",
|
|
1514
1139
|
outputs: [
|
|
1515
1140
|
{
|
|
1516
|
-
name: "
|
|
1517
|
-
type: "
|
|
1518
|
-
internalType: "
|
|
1141
|
+
name: "subvaultIndices",
|
|
1142
|
+
type: "uint256[]",
|
|
1143
|
+
internalType: "uint256[]"
|
|
1144
|
+
},
|
|
1145
|
+
{
|
|
1146
|
+
name: "withdrawalIndices",
|
|
1147
|
+
type: "uint256[][]",
|
|
1148
|
+
internalType: "uint256[][]"
|
|
1519
1149
|
}
|
|
1520
1150
|
],
|
|
1521
|
-
stateMutability: "
|
|
1522
|
-
type: "function"
|
|
1151
|
+
stateMutability: "view"
|
|
1523
1152
|
},
|
|
1524
1153
|
{
|
|
1154
|
+
type: "function",
|
|
1155
|
+
name: "multiAccept",
|
|
1525
1156
|
inputs: [
|
|
1157
|
+
{ name: "multiVault", type: "address", internalType: "address" },
|
|
1526
1158
|
{
|
|
1527
|
-
name: "
|
|
1528
|
-
type: "uint256",
|
|
1529
|
-
internalType: "uint256"
|
|
1530
|
-
}
|
|
1159
|
+
name: "subvaultIndices",
|
|
1160
|
+
type: "uint256[]",
|
|
1161
|
+
internalType: "uint256[]"
|
|
1162
|
+
},
|
|
1163
|
+
{ name: "indices", type: "uint256[][]", internalType: "uint256[][]" }
|
|
1531
1164
|
],
|
|
1532
|
-
name: "
|
|
1533
|
-
|
|
1165
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
1166
|
+
stateMutability: "nonpayable"
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
type: "function",
|
|
1170
|
+
name: "multiAcceptAndClaim",
|
|
1171
|
+
inputs: [
|
|
1172
|
+
{ name: "multiVault", type: "address", internalType: "address" },
|
|
1534
1173
|
{
|
|
1535
|
-
name: "
|
|
1536
|
-
type: "
|
|
1537
|
-
internalType: "
|
|
1538
|
-
}
|
|
1174
|
+
name: "subvaultIndices",
|
|
1175
|
+
type: "uint256[]",
|
|
1176
|
+
internalType: "uint256[]"
|
|
1177
|
+
},
|
|
1178
|
+
{ name: "indices", type: "uint256[][]", internalType: "uint256[][]" },
|
|
1179
|
+
{ name: "", type: "address", internalType: "address" },
|
|
1180
|
+
{ name: "maxAssets", type: "uint256", internalType: "uint256" }
|
|
1539
1181
|
],
|
|
1540
|
-
|
|
1541
|
-
|
|
1182
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
1183
|
+
stateMutability: "nonpayable"
|
|
1542
1184
|
}
|
|
1543
1185
|
];
|
|
1544
1186
|
// Annotate the CommonJS export names for ESM import in node:
|