@gearbox-protocol/sdk 13.3.0-next.3 → 13.3.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/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/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/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/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 +96 -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
|
@@ -28,7 +28,6 @@ const COMPRESSORS = {
|
|
|
28
28
|
[chains.Mainnet.id]: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023",
|
|
29
29
|
[chains.Monad.id]: "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023"
|
|
30
30
|
};
|
|
31
|
-
const INVESTORS = new AddressMap([], "investors");
|
|
32
31
|
function getWithdrawalCompressorAddress(chainId) {
|
|
33
32
|
return COMPRESSORS[chainId];
|
|
34
33
|
}
|
|
@@ -90,23 +89,6 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
90
89
|
});
|
|
91
90
|
return cad;
|
|
92
91
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns credit account data for a single account with the investor address resolved.
|
|
95
|
-
* Loads CA via getCreditAccountData; for KYC underlyings fetches the investor from the KYC factory's getInvestor(creditAccount), otherwise uses the account owner.
|
|
96
|
-
* @param account - Credit account address
|
|
97
|
-
* @param blockNumber - Optional block number for the read
|
|
98
|
-
* @returns CreditAccountDataWithInvestor (CA data + investor address), or undefined if the account is not found
|
|
99
|
-
*/
|
|
100
|
-
async getCreditAccountDataWithInvestor(account, blockNumber) {
|
|
101
|
-
const ca = await this.getCreditAccountData(account, blockNumber);
|
|
102
|
-
if (!ca) return ca;
|
|
103
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
104
|
-
ca.creditManager
|
|
105
|
-
);
|
|
106
|
-
const factory = await marketSuite.getKYCFactory();
|
|
107
|
-
const investor = factory ? await factory.getInvestor(ca.creditAccount, true) : void 0;
|
|
108
|
-
return { ...ca, investor: investor ?? ca.owner };
|
|
109
|
-
}
|
|
110
92
|
/**
|
|
111
93
|
* Methods to get all credit accounts with some optional filtering
|
|
112
94
|
* Performs all necessary price feed updates under the hood
|
|
@@ -115,7 +97,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
115
97
|
* @param blockNumber
|
|
116
98
|
* @returns returned credit accounts are sorted by health factor in ascending order
|
|
117
99
|
*/
|
|
118
|
-
async getCreditAccounts(options, blockNumber
|
|
100
|
+
async getCreditAccounts(options, blockNumber) {
|
|
119
101
|
const {
|
|
120
102
|
creditManager,
|
|
121
103
|
includeZeroDebt = false,
|
|
@@ -137,7 +119,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
137
119
|
maxHealthFactor,
|
|
138
120
|
reverting: false
|
|
139
121
|
};
|
|
140
|
-
const { txs: priceUpdateTxs } =
|
|
122
|
+
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
141
123
|
ignoreReservePrices ? { main: true } : void 0
|
|
142
124
|
);
|
|
143
125
|
const allCAs = [];
|
|
@@ -166,75 +148,6 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
166
148
|
);
|
|
167
149
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
168
150
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Returns all credit accounts matching the filter, with investor set on each item.
|
|
171
|
-
* 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.
|
|
172
|
-
* @param options - Filter options (owner, creditManager, health factor, etc.)
|
|
173
|
-
* @param blockNumber - Optional block number for the read
|
|
174
|
-
* @returns Array of credit accounts (with investor field), sorted by health factor ascending
|
|
175
|
-
*/
|
|
176
|
-
async getCreditAccountsWithInvestor(options, blockNumber) {
|
|
177
|
-
const { owner, ignoreReservePrices = false } = options ?? {};
|
|
178
|
-
const priceUpdate = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
179
|
-
ignoreReservePrices ? { main: true } : void 0
|
|
180
|
-
);
|
|
181
|
-
const { txs: priceUpdateTxs } = priceUpdate;
|
|
182
|
-
const [common, kyc] = await Promise.all([
|
|
183
|
-
this.getCreditAccounts(options, blockNumber),
|
|
184
|
-
owner ? this.getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) : void 0
|
|
185
|
-
]);
|
|
186
|
-
const allCAs = common.map(
|
|
187
|
-
(ca) => ({
|
|
188
|
-
...ca,
|
|
189
|
-
investor: owner || ca.owner
|
|
190
|
-
})
|
|
191
|
-
);
|
|
192
|
-
allCAs.push(...kyc || []);
|
|
193
|
-
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
194
|
-
}
|
|
195
|
-
async getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) {
|
|
196
|
-
const suites = this.marketConfigurators.map((mc) => {
|
|
197
|
-
const suite = this.sdk.marketRegister.markets.find(
|
|
198
|
-
(m) => m.configurator.address === mc
|
|
199
|
-
);
|
|
200
|
-
return suite;
|
|
201
|
-
});
|
|
202
|
-
const kycCAAddresses = await this.getKYCCaOfInvestor(owner, suites);
|
|
203
|
-
const kycCAs = await this.loadSpecifiedAccounts(
|
|
204
|
-
kycCAAddresses,
|
|
205
|
-
priceUpdateTxs,
|
|
206
|
-
blockNumber
|
|
207
|
-
);
|
|
208
|
-
return kycCAs.map((ca) => ({
|
|
209
|
-
...ca,
|
|
210
|
-
investor: owner
|
|
211
|
-
}));
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Loads credit account data for the given addresses using simulateWithPriceUpdates.
|
|
215
|
-
* Applies the provided price update txs before reading, so returned data is consistent with up-to-date prices.
|
|
216
|
-
* @param accounts - Credit account addresses to load
|
|
217
|
-
* @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
|
|
218
|
-
* @param blockNumber - Optional block number for the read
|
|
219
|
-
* @returns Array of CreditAccountData in the same order as accounts (throws if any getCreditAccountData call reverts)
|
|
220
|
-
*/
|
|
221
|
-
async loadSpecifiedAccounts(accounts, priceUpdateTxs, blockNumber) {
|
|
222
|
-
if (accounts.length === 0) return [];
|
|
223
|
-
const list = await simulateWithPriceUpdates(this.client, {
|
|
224
|
-
priceUpdates: priceUpdateTxs,
|
|
225
|
-
contracts: accounts.map(
|
|
226
|
-
(account) => ({
|
|
227
|
-
abi: creditAccountCompressorAbi,
|
|
228
|
-
address: this.#compressor,
|
|
229
|
-
functionName: "getCreditAccountData",
|
|
230
|
-
args: [account]
|
|
231
|
-
})
|
|
232
|
-
),
|
|
233
|
-
blockNumber,
|
|
234
|
-
gas: this.sdk.gasLimit
|
|
235
|
-
});
|
|
236
|
-
return list;
|
|
237
|
-
}
|
|
238
151
|
/**
|
|
239
152
|
* Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
|
|
240
153
|
Assosiates rewards by adapter + stakedPhantomToken
|
|
@@ -465,13 +378,6 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
465
378
|
closePath
|
|
466
379
|
}) {
|
|
467
380
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
468
|
-
await this.sdk.tokensMeta.loadTokenData(cm.underlying);
|
|
469
|
-
const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
|
|
470
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
471
|
-
throw new Error(
|
|
472
|
-
"closeCreditAccount is not supported for KYC underlying credit accounts"
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
381
|
const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
|
|
476
382
|
creditAccount: ca,
|
|
477
383
|
creditManager: cm.creditManager,
|
|
@@ -490,12 +396,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
490
396
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t, MAX_UINT256, to)
|
|
491
397
|
)
|
|
492
398
|
];
|
|
493
|
-
const tx =
|
|
494
|
-
cm,
|
|
495
|
-
ca.creditAccount,
|
|
496
|
-
calls,
|
|
497
|
-
operation
|
|
498
|
-
);
|
|
399
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
499
400
|
return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
|
|
500
401
|
}
|
|
501
402
|
/**
|
|
@@ -525,7 +426,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
525
426
|
averageQuota
|
|
526
427
|
})
|
|
527
428
|
];
|
|
528
|
-
const tx =
|
|
429
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
529
430
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
530
431
|
}
|
|
531
432
|
/**
|
|
@@ -567,7 +468,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
567
468
|
averageQuota
|
|
568
469
|
})
|
|
569
470
|
];
|
|
570
|
-
const tx =
|
|
471
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
571
472
|
tx.value = ethAmount.toString(10);
|
|
572
473
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
573
474
|
}
|
|
@@ -584,7 +485,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
584
485
|
async changeDebt({
|
|
585
486
|
creditAccount,
|
|
586
487
|
amount,
|
|
587
|
-
|
|
488
|
+
addCollateral
|
|
588
489
|
}) {
|
|
589
490
|
if (amount === 0n) {
|
|
590
491
|
throw new Error("debt increase or decrease must be non-zero");
|
|
@@ -598,32 +499,22 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
598
499
|
creditManager: creditAccount.creditManager,
|
|
599
500
|
creditAccount
|
|
600
501
|
});
|
|
601
|
-
const addCollateralCalls =
|
|
502
|
+
const addCollateralCalls = addCollateral && isDecrease ? this.prepareAddCollateral(
|
|
602
503
|
creditAccount.creditFacade,
|
|
603
504
|
[
|
|
604
505
|
{
|
|
605
|
-
token:
|
|
606
|
-
balance:
|
|
506
|
+
token: creditAccount.underlying,
|
|
507
|
+
balance: change
|
|
607
508
|
}
|
|
608
509
|
],
|
|
609
510
|
{}
|
|
610
511
|
) : [];
|
|
611
|
-
const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
|
|
612
|
-
collateral[0].balance,
|
|
613
|
-
creditAccount.creditManager
|
|
614
|
-
) || [] : [];
|
|
615
|
-
if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
|
|
616
|
-
throw new Error(
|
|
617
|
-
"Can't use collateral other than underlying for non KYC market"
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
512
|
const calls = [
|
|
621
513
|
...priceUpdatesCalls,
|
|
622
514
|
...addCollateralCalls,
|
|
623
|
-
...unwrapCalls,
|
|
624
515
|
this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
|
|
625
516
|
];
|
|
626
|
-
const tx =
|
|
517
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
627
518
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
628
519
|
}
|
|
629
520
|
/**
|
|
@@ -658,7 +549,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
658
549
|
averageQuota
|
|
659
550
|
})
|
|
660
551
|
];
|
|
661
|
-
const tx =
|
|
552
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
662
553
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
663
554
|
}
|
|
664
555
|
/**
|
|
@@ -774,7 +665,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
774
665
|
averageQuota
|
|
775
666
|
})
|
|
776
667
|
];
|
|
777
|
-
const tx =
|
|
668
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
778
669
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
779
670
|
}
|
|
780
671
|
/**
|
|
@@ -839,63 +730,48 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
839
730
|
compareBalances,
|
|
840
731
|
...quotaCalls
|
|
841
732
|
];
|
|
842
|
-
const tx =
|
|
733
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
843
734
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
844
735
|
}
|
|
845
|
-
/**
|
|
846
|
-
* Returns address to which approval should be given on collateral token
|
|
847
|
-
* It's credit manager for classical markets and special wallet for KYC markets
|
|
848
|
-
* @param options - {@link GetApprovalAddressProps}
|
|
849
|
-
* @returns
|
|
850
|
-
**/
|
|
851
|
-
async getApprovalAddress(options) {
|
|
852
|
-
const { creditManager } = options;
|
|
853
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
854
|
-
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
855
|
-
const factory = await marketSuite.getKYCFactory();
|
|
856
|
-
if (factory) {
|
|
857
|
-
if ("creditAccount" in options) {
|
|
858
|
-
return factory.getWallet(options.creditAccount);
|
|
859
|
-
}
|
|
860
|
-
return factory.precomputeWalletAddress(creditManager, options.borrower);
|
|
861
|
-
}
|
|
862
|
-
return suite.creditManager.address;
|
|
863
|
-
}
|
|
864
736
|
/**
|
|
865
737
|
* Executes swap specified by given calls, update quotas of affected tokens
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
738
|
+
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
|
|
739
|
+
-> update quotas -> (optionally: execute swap path for trading/strategy) ->
|
|
740
|
+
-> (optionally: withdraw debt for lending)
|
|
741
|
+
- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
|
|
742
|
+
- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
|
|
743
|
+
- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
|
|
744
|
+
- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
|
|
745
|
+
* @param {bigint} ethAmount - native token amount to attach to tx
|
|
746
|
+
* @param {Address} creditManager - address of credit manager to open credit account on
|
|
747
|
+
* @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
|
|
748
|
+
* @param {Record<Address, PermitResult>} permits - permits of collateral tokens (in any permittable token is present) {@link PermitResult}
|
|
749
|
+
* @param {bigint} debt - debt to open credit account with
|
|
750
|
+
* @param {boolean} withdrawDebt - flag to withdraw debt to wallet after opening credit account;
|
|
751
|
+
used for borrowing functionality
|
|
752
|
+
* @param {bigint} referralCode - referral code to open credit account with
|
|
753
|
+
* @param {Address} to - wallet address to transfer credit account to\
|
|
754
|
+
* @param {Array<MultiCall>} calls - array of MultiCall from router methods findOpenStrategyPath {@link MultiCall}.
|
|
755
|
+
Used for trading and strategy functionality
|
|
756
|
+
* @param {Array<Asset>} averageQuota - average quota for tokens after open {@link Asset}
|
|
757
|
+
* @param {Array<Asset>} minQuota - minimum quota for tokens after open {@link Asset}
|
|
873
758
|
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
874
|
-
|
|
875
|
-
async openCA(
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
minQuota,
|
|
889
|
-
averageQuota
|
|
890
|
-
} = props;
|
|
759
|
+
*/
|
|
760
|
+
async openCA({
|
|
761
|
+
ethAmount,
|
|
762
|
+
creditManager,
|
|
763
|
+
collateral,
|
|
764
|
+
permits,
|
|
765
|
+
debt,
|
|
766
|
+
withdrawDebt,
|
|
767
|
+
referralCode,
|
|
768
|
+
to,
|
|
769
|
+
calls: openPathCalls,
|
|
770
|
+
minQuota,
|
|
771
|
+
averageQuota
|
|
772
|
+
}) {
|
|
891
773
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
892
774
|
const cm = cmSuite.creditManager;
|
|
893
|
-
let tokenToWithdraw;
|
|
894
|
-
if (withdrawToken === true) {
|
|
895
|
-
tokenToWithdraw = cm.underlying;
|
|
896
|
-
} else if (typeof withdrawToken === "string") {
|
|
897
|
-
tokenToWithdraw = withdrawToken;
|
|
898
|
-
}
|
|
899
775
|
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
900
776
|
creditManager: cm.address,
|
|
901
777
|
desiredQuotas: averageQuota
|
|
@@ -905,27 +781,13 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
905
781
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
906
782
|
...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
|
|
907
783
|
...openPathCalls,
|
|
908
|
-
|
|
909
|
-
...tokenToWithdraw ? [
|
|
910
|
-
this.prepareWithdrawToken(
|
|
911
|
-
cm.creditFacade,
|
|
912
|
-
tokenToWithdraw,
|
|
913
|
-
MAX_UINT256,
|
|
914
|
-
to
|
|
915
|
-
)
|
|
916
|
-
] : [],
|
|
784
|
+
...withdrawDebt ? [this.prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : [],
|
|
917
785
|
...this.prepareUpdateQuotas(cm.creditFacade, {
|
|
918
786
|
minQuota,
|
|
919
787
|
averageQuota
|
|
920
|
-
})
|
|
921
|
-
...callsAfter ?? []
|
|
788
|
+
})
|
|
922
789
|
];
|
|
923
|
-
|
|
924
|
-
if (reopenCreditAccount) {
|
|
925
|
-
tx = await this.multicallTx(cmSuite, reopenCreditAccount, calls);
|
|
926
|
-
} else {
|
|
927
|
-
tx = await this.openCreditAccountTx(cmSuite, to, calls, referralCode);
|
|
928
|
-
}
|
|
790
|
+
const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
|
|
929
791
|
tx.value = ethAmount.toString(10);
|
|
930
792
|
return { calls, tx, creditFacade: cmSuite.creditFacade };
|
|
931
793
|
}
|
|
@@ -1009,130 +871,6 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
1009
871
|
);
|
|
1010
872
|
return resp;
|
|
1011
873
|
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
|
|
1014
|
-
* Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
|
|
1015
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1016
|
-
* @param amount - Number of vault shares (adapter tokens) to redeem
|
|
1017
|
-
* @param creditManager - Credit manager address
|
|
1018
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1019
|
-
*/
|
|
1020
|
-
async getKYCUnwrapCalls(amount, creditManager) {
|
|
1021
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1022
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1023
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1024
|
-
return void 0;
|
|
1025
|
-
}
|
|
1026
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1027
|
-
const adapterAddress = adapter?.address;
|
|
1028
|
-
if (!adapterAddress) {
|
|
1029
|
-
return void 0;
|
|
1030
|
-
}
|
|
1031
|
-
const mc = [
|
|
1032
|
-
{
|
|
1033
|
-
target: adapterAddress,
|
|
1034
|
-
callData: encodeFunctionData({
|
|
1035
|
-
abi: ierc4626AdapterAbi,
|
|
1036
|
-
functionName: "redeem",
|
|
1037
|
-
args: [amount, ADDRESS_0X0, ADDRESS_0X0]
|
|
1038
|
-
})
|
|
1039
|
-
}
|
|
1040
|
-
];
|
|
1041
|
-
return mc;
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
|
|
1045
|
-
* Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
|
|
1046
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1047
|
-
* @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
|
|
1048
|
-
* @param creditManager - Credit manager address
|
|
1049
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1050
|
-
*/
|
|
1051
|
-
async getKYCWrapCalls(amount, creditManager) {
|
|
1052
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1053
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1054
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1055
|
-
return void 0;
|
|
1056
|
-
}
|
|
1057
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1058
|
-
const adapterAddress = adapter?.address;
|
|
1059
|
-
if (!adapterAddress) {
|
|
1060
|
-
return void 0;
|
|
1061
|
-
}
|
|
1062
|
-
const mc = [
|
|
1063
|
-
{
|
|
1064
|
-
target: adapterAddress,
|
|
1065
|
-
callData: encodeFunctionData({
|
|
1066
|
-
abi: ierc4626AdapterAbi,
|
|
1067
|
-
functionName: "deposit",
|
|
1068
|
-
args: [amount, ADDRESS_0X0]
|
|
1069
|
-
})
|
|
1070
|
-
}
|
|
1071
|
-
];
|
|
1072
|
-
return mc;
|
|
1073
|
-
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1076
|
-
* Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
|
|
1077
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1078
|
-
* @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
|
|
1079
|
-
* @param creditManager - Credit manager address
|
|
1080
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1081
|
-
*/
|
|
1082
|
-
async getRedeemDiffCalls(amount, creditManager) {
|
|
1083
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1084
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1085
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1086
|
-
return void 0;
|
|
1087
|
-
}
|
|
1088
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1089
|
-
const adapterAddress = adapter?.address;
|
|
1090
|
-
if (!adapterAddress) {
|
|
1091
|
-
return void 0;
|
|
1092
|
-
}
|
|
1093
|
-
const mc = [
|
|
1094
|
-
{
|
|
1095
|
-
target: adapterAddress,
|
|
1096
|
-
callData: encodeFunctionData({
|
|
1097
|
-
abi: ierc4626AdapterAbi,
|
|
1098
|
-
functionName: "redeemDiff",
|
|
1099
|
-
args: [amount]
|
|
1100
|
-
})
|
|
1101
|
-
}
|
|
1102
|
-
];
|
|
1103
|
-
return mc;
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1107
|
-
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
1108
|
-
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1109
|
-
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
1110
|
-
* @param creditManager - Credit manager address
|
|
1111
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1112
|
-
*/
|
|
1113
|
-
async getDepositDiffCalls(amount, creditManager) {
|
|
1114
|
-
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1115
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1116
|
-
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1117
|
-
return void 0;
|
|
1118
|
-
}
|
|
1119
|
-
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1120
|
-
const adapterAddress = adapter?.address;
|
|
1121
|
-
if (!adapterAddress) {
|
|
1122
|
-
return void 0;
|
|
1123
|
-
}
|
|
1124
|
-
const mc = [
|
|
1125
|
-
{
|
|
1126
|
-
target: adapterAddress,
|
|
1127
|
-
callData: encodeFunctionData({
|
|
1128
|
-
abi: ierc4626AdapterAbi,
|
|
1129
|
-
functionName: "depositDiff",
|
|
1130
|
-
args: [amount]
|
|
1131
|
-
})
|
|
1132
|
-
}
|
|
1133
|
-
];
|
|
1134
|
-
return mc;
|
|
1135
|
-
}
|
|
1136
874
|
/**
|
|
1137
875
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
1138
876
|
*
|
|
@@ -1360,174 +1098,78 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
1360
1098
|
VERSION_RANGE_310
|
|
1361
1099
|
)[0];
|
|
1362
1100
|
}
|
|
1363
|
-
/**
|
|
1364
|
-
* Wrapper that selects between credit facade and KYC factory
|
|
1365
|
-
* @param suite
|
|
1366
|
-
* @param to
|
|
1367
|
-
* @param calls
|
|
1368
|
-
* @param referralCode
|
|
1369
|
-
* @returns
|
|
1370
|
-
*/
|
|
1371
|
-
async openCreditAccountTx(suite, to, calls, referralCode) {
|
|
1372
|
-
const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
|
|
1373
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1374
|
-
if (factory) {
|
|
1375
|
-
const tokensToRegister = await factory.getDSTokens();
|
|
1376
|
-
return factory.openCreditAccount(
|
|
1377
|
-
suite.creditManager.address,
|
|
1378
|
-
calls,
|
|
1379
|
-
tokensToRegister
|
|
1380
|
-
);
|
|
1381
|
-
}
|
|
1382
|
-
return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
|
|
1383
|
-
}
|
|
1384
|
-
/**
|
|
1385
|
-
* Wrapper that selects between credit facade and KYC factory
|
|
1386
|
-
* @param suite
|
|
1387
|
-
* @param creditAccount
|
|
1388
|
-
* @param calls
|
|
1389
|
-
* @returns
|
|
1390
|
-
*/
|
|
1391
|
-
async multicallTx(suite, creditAccount, calls) {
|
|
1392
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1393
|
-
suite.creditManager.address
|
|
1394
|
-
);
|
|
1395
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1396
|
-
if (factory) {
|
|
1397
|
-
const tokensToRegister = [];
|
|
1398
|
-
return factory.multicall(creditAccount, calls, tokensToRegister);
|
|
1399
|
-
}
|
|
1400
|
-
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1401
|
-
}
|
|
1402
|
-
/**
|
|
1403
|
-
* Wrapper that selects between credit facade and KYC factory
|
|
1404
|
-
* @param suite
|
|
1405
|
-
* @param creditAccount
|
|
1406
|
-
* @param calls
|
|
1407
|
-
* @param operation
|
|
1408
|
-
* @returns
|
|
1409
|
-
*/
|
|
1410
|
-
async closeCreditAccountTx(suite, creditAccount, calls, operation) {
|
|
1411
|
-
const marketSuite = this.sdk.marketRegister.findByCreditManager(
|
|
1412
|
-
suite.creditManager.address
|
|
1413
|
-
);
|
|
1414
|
-
const factory = await marketSuite.getKYCFactory();
|
|
1415
|
-
if (operation === "close") {
|
|
1416
|
-
if (factory) {
|
|
1417
|
-
throw new Error(
|
|
1418
|
-
"CloseOptions=close is not supported for KYC underlying credit accounts"
|
|
1419
|
-
);
|
|
1420
|
-
}
|
|
1421
|
-
return suite.creditFacade.closeCreditAccount(creditAccount, calls);
|
|
1422
|
-
}
|
|
1423
|
-
if (factory) {
|
|
1424
|
-
const tokensToRegister = [];
|
|
1425
|
-
return factory.multicall(creditAccount, calls, tokensToRegister);
|
|
1426
|
-
}
|
|
1427
|
-
return suite.creditFacade.multicall(creditAccount, calls);
|
|
1428
|
-
}
|
|
1429
|
-
/**
|
|
1430
|
-
* Returns all KYC credit account addresses for an investor across the given market suites.
|
|
1431
|
-
* Resolves KYC factory per suite, then multicalls each factory's getCreditAccounts(investor).
|
|
1432
|
-
* @param investor - Owner address to query
|
|
1433
|
-
* @param suites - Market suites (KYC factories are resolved for each; undefined entries are skipped)
|
|
1434
|
-
* @returns Flat array of credit account addresses from all KYC markets
|
|
1435
|
-
*/
|
|
1436
|
-
async getKYCCaOfInvestor(investor, suites) {
|
|
1437
|
-
if (suites.length === 0 || investor === ADDRESS_0X0) return [];
|
|
1438
|
-
const factories = await Promise.all(
|
|
1439
|
-
suites.map((suite) => suite ? suite.getKYCFactory() : void 0)
|
|
1440
|
-
);
|
|
1441
|
-
const safeFactories = factories.reduce(
|
|
1442
|
-
(acc, v) => {
|
|
1443
|
-
if (v) {
|
|
1444
|
-
acc.push(v);
|
|
1445
|
-
}
|
|
1446
|
-
return acc;
|
|
1447
|
-
},
|
|
1448
|
-
[]
|
|
1449
|
-
);
|
|
1450
|
-
const allResp = await this.client.multicall({
|
|
1451
|
-
contracts: [
|
|
1452
|
-
...safeFactories.map((factory) => {
|
|
1453
|
-
return {
|
|
1454
|
-
abi: factory.abi,
|
|
1455
|
-
address: factory.address,
|
|
1456
|
-
functionName: "getCreditAccounts",
|
|
1457
|
-
args: [investor]
|
|
1458
|
-
};
|
|
1459
|
-
})
|
|
1460
|
-
],
|
|
1461
|
-
allowFailure: true,
|
|
1462
|
-
batchSize: 0
|
|
1463
|
-
});
|
|
1464
|
-
const caLists = safeFactories.reduce((acc, _, index) => {
|
|
1465
|
-
const response = allResp[index];
|
|
1466
|
-
acc.push(...response.result || []);
|
|
1467
|
-
return acc;
|
|
1468
|
-
}, []);
|
|
1469
|
-
return caLists;
|
|
1470
|
-
}
|
|
1471
1101
|
}
|
|
1472
|
-
const
|
|
1102
|
+
const iMellowClaimerAdapterAbi = [
|
|
1473
1103
|
{
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1104
|
+
type: "function",
|
|
1105
|
+
name: "getMultiVaultSubvaultIndices",
|
|
1106
|
+
inputs: [{ name: "multiVault", type: "address", internalType: "address" }],
|
|
1107
|
+
outputs: [
|
|
1108
|
+
{
|
|
1109
|
+
name: "subvaultIndices",
|
|
1110
|
+
type: "uint256[]",
|
|
1111
|
+
internalType: "uint256[]"
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
name: "withdrawalIndices",
|
|
1115
|
+
type: "uint256[][]",
|
|
1116
|
+
internalType: "uint256[][]"
|
|
1117
|
+
}
|
|
1488
1118
|
],
|
|
1489
|
-
|
|
1490
|
-
outputs: [{ name: "useSafePrices", type: "bool", internalType: "bool" }],
|
|
1491
|
-
stateMutability: "nonpayable",
|
|
1492
|
-
type: "function"
|
|
1119
|
+
stateMutability: "view"
|
|
1493
1120
|
},
|
|
1494
1121
|
{
|
|
1122
|
+
type: "function",
|
|
1123
|
+
name: "getUserSubvaultIndices",
|
|
1495
1124
|
inputs: [
|
|
1496
|
-
{
|
|
1497
|
-
|
|
1498
|
-
type: "uint256",
|
|
1499
|
-
internalType: "uint256"
|
|
1500
|
-
}
|
|
1125
|
+
{ name: "multiVault", type: "address", internalType: "address" },
|
|
1126
|
+
{ name: "user", type: "address", internalType: "address" }
|
|
1501
1127
|
],
|
|
1502
|
-
name: "redeemDiff",
|
|
1503
1128
|
outputs: [
|
|
1504
1129
|
{
|
|
1505
|
-
name: "
|
|
1506
|
-
type: "
|
|
1507
|
-
internalType: "
|
|
1130
|
+
name: "subvaultIndices",
|
|
1131
|
+
type: "uint256[]",
|
|
1132
|
+
internalType: "uint256[]"
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
name: "withdrawalIndices",
|
|
1136
|
+
type: "uint256[][]",
|
|
1137
|
+
internalType: "uint256[][]"
|
|
1508
1138
|
}
|
|
1509
1139
|
],
|
|
1510
|
-
stateMutability: "
|
|
1511
|
-
type: "function"
|
|
1140
|
+
stateMutability: "view"
|
|
1512
1141
|
},
|
|
1513
1142
|
{
|
|
1143
|
+
type: "function",
|
|
1144
|
+
name: "multiAccept",
|
|
1514
1145
|
inputs: [
|
|
1146
|
+
{ name: "multiVault", type: "address", internalType: "address" },
|
|
1515
1147
|
{
|
|
1516
|
-
name: "
|
|
1517
|
-
type: "uint256",
|
|
1518
|
-
internalType: "uint256"
|
|
1519
|
-
}
|
|
1148
|
+
name: "subvaultIndices",
|
|
1149
|
+
type: "uint256[]",
|
|
1150
|
+
internalType: "uint256[]"
|
|
1151
|
+
},
|
|
1152
|
+
{ name: "indices", type: "uint256[][]", internalType: "uint256[][]" }
|
|
1520
1153
|
],
|
|
1521
|
-
name: "
|
|
1522
|
-
|
|
1154
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
1155
|
+
stateMutability: "nonpayable"
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
type: "function",
|
|
1159
|
+
name: "multiAcceptAndClaim",
|
|
1160
|
+
inputs: [
|
|
1161
|
+
{ name: "multiVault", type: "address", internalType: "address" },
|
|
1523
1162
|
{
|
|
1524
|
-
name: "
|
|
1525
|
-
type: "
|
|
1526
|
-
internalType: "
|
|
1527
|
-
}
|
|
1163
|
+
name: "subvaultIndices",
|
|
1164
|
+
type: "uint256[]",
|
|
1165
|
+
internalType: "uint256[]"
|
|
1166
|
+
},
|
|
1167
|
+
{ name: "indices", type: "uint256[][]", internalType: "uint256[][]" },
|
|
1168
|
+
{ name: "", type: "address", internalType: "address" },
|
|
1169
|
+
{ name: "maxAssets", type: "uint256", internalType: "uint256" }
|
|
1528
1170
|
],
|
|
1529
|
-
|
|
1530
|
-
|
|
1171
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
1172
|
+
stateMutability: "nonpayable"
|
|
1531
1173
|
}
|
|
1532
1174
|
];
|
|
1533
1175
|
export {
|