@gearbox-protocol/sdk 14.12.0-next.74 → 14.12.0-next.76
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/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +85 -584
- package/dist/cjs/sdk/accounts/bots/AccountBotsService.js +132 -0
- package/dist/cjs/sdk/accounts/bots/PeripheryCompressorV310Contract.js +31 -0
- package/dist/cjs/sdk/accounts/bots/abi.js +19 -0
- package/dist/cjs/sdk/accounts/bots/index.js +6 -0
- package/dist/cjs/sdk/accounts/bots/types.js +1 -0
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +280 -0
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js +141 -0
- package/dist/cjs/sdk/accounts/credit-account-compressor/index.js +6 -0
- package/dist/cjs/sdk/accounts/credit-account-compressor/types.js +1 -0
- package/dist/cjs/sdk/accounts/index.js +10 -0
- package/dist/cjs/sdk/index.js +8 -0
- package/dist/cjs/sdk/market/ZapperRegister.js +1 -1
- package/dist/cjs/sdk/market/credit/CreditSuite.js +31 -0
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +41 -1
- package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +0 -23
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +1 -1
- package/dist/esm/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +87 -586
- package/dist/esm/sdk/accounts/bots/AccountBotsService.js +131 -0
- package/dist/esm/sdk/accounts/bots/PeripheryCompressorV310Contract.js +31 -0
- package/dist/esm/sdk/accounts/bots/abi.js +18 -0
- package/dist/esm/sdk/accounts/bots/index.js +4 -0
- package/dist/esm/sdk/accounts/bots/types.js +1 -0
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +279 -0
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js +141 -0
- package/dist/esm/sdk/accounts/credit-account-compressor/index.js +4 -0
- package/dist/esm/sdk/accounts/credit-account-compressor/types.js +1 -0
- package/dist/esm/sdk/accounts/index.js +7 -1
- package/dist/esm/sdk/index.js +5 -1
- package/dist/esm/sdk/market/ZapperRegister.js +1 -1
- package/dist/esm/sdk/market/credit/CreditSuite.js +31 -0
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +41 -1
- package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +0 -23
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +1 -1
- package/dist/types/new-sdk/AbstractNamespace.d.ts +2 -2
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +1 -1
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +1 -1
- package/dist/types/plugins/accounts/AccountsPlugin.d.ts +1 -1
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +17 -58
- package/dist/types/sdk/accounts/bots/AccountBotsService.d.ts +38 -0
- package/dist/types/sdk/accounts/bots/PeripheryCompressorV310Contract.d.ts +236 -0
- package/dist/types/sdk/accounts/bots/abi.d.ts +18 -0
- package/dist/types/sdk/accounts/bots/index.d.ts +4 -0
- package/dist/types/sdk/accounts/bots/types.d.ts +143 -0
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +60 -0
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.d.ts +879 -0
- package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +4 -0
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +164 -0
- package/dist/types/sdk/accounts/index.d.ts +11 -3
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/types.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +13 -194
- package/dist/types/sdk/base/TokensMeta.d.ts +1 -1
- package/dist/types/sdk/base/index.d.ts +2 -2
- package/dist/types/sdk/base/types.d.ts +6 -1
- package/dist/types/sdk/index.d.ts +11 -5
- package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +1 -1
- package/dist/types/sdk/market/MarketSuite.d.ts +1 -1
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +26 -1
- package/dist/types/sdk/market/credit/types.d.ts +1 -1
- package/dist/types/sdk/market/index.d.ts +2 -2
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +16 -5
- package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +0 -11
- package/dist/types/sdk/market/oracle/index.d.ts +2 -2
- package/dist/types/sdk/market/oracle/types.d.ts +31 -15
- package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/pool/types.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/types.d.ts +1 -1
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +2 -2
- package/dist/types/sdk/pools/types.d.ts +1 -1
- package/dist/types/sdk/positions/MultichainPositionsService.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_abi_iBaseRewardPool = require("../../abi/iBaseRewardPool.js");
|
|
3
3
|
const require_abi_ierc4626Adapter = require("../../abi/ierc4626Adapter.js");
|
|
4
|
-
const require_abi_310_generated = require("../../abi/310/generated.js");
|
|
5
|
-
const require_abi_compressors_creditAccountCompressor = require("../../abi/compressors/creditAccountCompressor.js");
|
|
6
|
-
const require_abi_compressors_peripheryCompressor = require("../../abi/compressors/peripheryCompressor.js");
|
|
7
|
-
const require_abi_compressors_rewardsCompressor = require("../../abi/compressors/rewardsCompressor.js");
|
|
8
|
-
const require_abi_rwa_iRWAFactory = require("../../abi/rwa/iRWAFactory.js");
|
|
9
|
-
const require_sdk_utils_AddressMap = require("../utils/AddressMap.js");
|
|
10
|
-
const require_sdk_utils_AddressSet = require("../utils/AddressSet.js");
|
|
11
4
|
const require_sdk_constants_address_provider = require("../constants/address-provider.js");
|
|
12
5
|
const require_sdk_constants_addresses = require("../constants/addresses.js");
|
|
13
6
|
const require_sdk_constants_math = require("../constants/math.js");
|
|
14
7
|
const require_sdk_constants_versions = require("../constants/versions.js");
|
|
15
8
|
require("../constants/index.js");
|
|
16
|
-
const require_sdk_utils_hex = require("../utils/hex.js");
|
|
17
|
-
require("../utils/index.js");
|
|
18
9
|
const require_sdk_base_SDKConstruct = require("../base/SDKConstruct.js");
|
|
19
10
|
require("../base/index.js");
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
require("
|
|
24
|
-
|
|
25
|
-
require("../market/index.js");
|
|
11
|
+
const require_sdk_accounts_bots_AccountBotsService = require("./bots/AccountBotsService.js");
|
|
12
|
+
require("./bots/index.js");
|
|
13
|
+
const require_abi_compressors_rewardsCompressor = require("../../abi/compressors/rewardsCompressor.js");
|
|
14
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressor = require("./credit-account-compressor/CreditAccountCompressor.js");
|
|
15
|
+
require("./credit-account-compressor/index.js");
|
|
26
16
|
const require_sdk_accounts_multicall_utils = require("./multicall-utils.js");
|
|
27
17
|
let viem = require("viem");
|
|
28
18
|
//#region src/sdk/accounts/CreditAccountsServiceV310.ts
|
|
@@ -37,268 +27,38 @@ let viem = require("viem");
|
|
|
37
27
|
**/
|
|
38
28
|
var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
39
29
|
#compressor;
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
/**
|
|
31
|
+
* {@inheritDoc ICreditAccountsService.bots}
|
|
32
|
+
**/
|
|
33
|
+
bots;
|
|
34
|
+
constructor(sdk) {
|
|
42
35
|
super(sdk);
|
|
43
|
-
this.#
|
|
44
|
-
|
|
45
|
-
setBatchSize(batchSize) {
|
|
46
|
-
this.#batchSize = batchSize;
|
|
36
|
+
this.#compressor = new require_sdk_accounts_credit_account_compressor_CreditAccountCompressor.CreditAccountCompressor(sdk);
|
|
37
|
+
this.bots = new require_sdk_accounts_bots_AccountBotsService.AccountBotsService(sdk);
|
|
47
38
|
}
|
|
48
39
|
/**
|
|
49
40
|
* {@inheritDoc ICreditAccountsService.getCreditAccountData}
|
|
50
41
|
**/
|
|
51
42
|
async getCreditAccountData(account, blockNumber) {
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
raw = await this.client.readContract({
|
|
55
|
-
abi: require_abi_compressors_creditAccountCompressor.creditAccountCompressorAbi,
|
|
56
|
-
address: this.compressor,
|
|
57
|
-
functionName: "getCreditAccountData",
|
|
58
|
-
args: [account],
|
|
59
|
-
blockNumber,
|
|
60
|
-
gas: this.sdk.gasLimit
|
|
61
|
-
});
|
|
62
|
-
} catch (_e) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const factory = this.sdk.marketRegister.findByCreditManager(raw.creditManager).rwaFactory;
|
|
66
|
-
let ca;
|
|
67
|
-
let investor;
|
|
68
|
-
if (raw.success) {
|
|
69
|
-
ca = raw;
|
|
70
|
-
investor = await factory?.getInvestor(raw.creditAccount, false);
|
|
71
|
-
} else {
|
|
72
|
-
const { txs: priceUpdateTxs } = await this.#getUpdateForAccount(raw);
|
|
73
|
-
[ca, investor] = await require_sdk_utils_viem_simulateWithPriceUpdates.simulateWithPriceUpdates(this.client, {
|
|
74
|
-
priceUpdates: priceUpdateTxs,
|
|
75
|
-
contracts: [{
|
|
76
|
-
abi: require_abi_compressors_creditAccountCompressor.creditAccountCompressorAbi,
|
|
77
|
-
address: this.compressor,
|
|
78
|
-
functionName: "getCreditAccountData",
|
|
79
|
-
args: [account]
|
|
80
|
-
}, ...factory ? [{
|
|
81
|
-
abi: require_abi_rwa_iRWAFactory.iRWAFactoryAbi,
|
|
82
|
-
address: factory.address,
|
|
83
|
-
functionName: "getInvestor",
|
|
84
|
-
args: [raw.creditAccount]
|
|
85
|
-
}] : []],
|
|
86
|
-
blockNumber,
|
|
87
|
-
gas: this.sdk.gasLimit
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
...ca,
|
|
92
|
-
investor
|
|
93
|
-
};
|
|
43
|
+
return this.#compressor.getCreditAccountData(account, blockNumber);
|
|
94
44
|
}
|
|
95
45
|
/**
|
|
96
46
|
* {@inheritDoc ICreditAccountsService.getCreditAccounts}
|
|
97
47
|
**/
|
|
98
48
|
async getCreditAccounts(options, blockNumber) {
|
|
99
|
-
|
|
100
|
-
const arg0 = creditManager ?? {
|
|
101
|
-
configurators: this.marketConfigurators,
|
|
102
|
-
creditManagers: [],
|
|
103
|
-
pools: [],
|
|
104
|
-
underlying: "0x0000000000000000000000000000000000000000"
|
|
105
|
-
};
|
|
106
|
-
const caFilter = {
|
|
107
|
-
owner,
|
|
108
|
-
includeZeroDebt,
|
|
109
|
-
minHealthFactor,
|
|
110
|
-
maxHealthFactor,
|
|
111
|
-
reverting: false
|
|
112
|
-
};
|
|
113
|
-
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
114
|
-
const allCAs = [];
|
|
115
|
-
let revertingOffset = 0;
|
|
116
|
-
for (const reverting of [false, true]) {
|
|
117
|
-
let offset = 0n;
|
|
118
|
-
revertingOffset = allCAs.length;
|
|
119
|
-
do {
|
|
120
|
-
const [accounts, newOffset] = await this.#getCreditAccounts(this.#batchSize ? [
|
|
121
|
-
arg0,
|
|
122
|
-
{
|
|
123
|
-
...caFilter,
|
|
124
|
-
reverting
|
|
125
|
-
},
|
|
126
|
-
offset,
|
|
127
|
-
BigInt(this.#batchSize)
|
|
128
|
-
] : [
|
|
129
|
-
arg0,
|
|
130
|
-
{
|
|
131
|
-
...caFilter,
|
|
132
|
-
reverting
|
|
133
|
-
},
|
|
134
|
-
offset
|
|
135
|
-
], priceUpdateTxs, blockNumber);
|
|
136
|
-
allCAs.push(...accounts);
|
|
137
|
-
offset = newOffset;
|
|
138
|
-
} while (offset !== 0n);
|
|
139
|
-
}
|
|
140
|
-
this.logger?.debug(`loaded ${allCAs.length} credit accounts (${allCAs.length - revertingOffset} reverting)`);
|
|
141
|
-
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
49
|
+
return this.#compressor.getCreditAccounts(options, blockNumber);
|
|
142
50
|
}
|
|
143
51
|
/**
|
|
144
52
|
* {@inheritDoc ICreditAccountsService.getBorrowerCreditAccounts}
|
|
145
53
|
**/
|
|
146
54
|
async getBorrowerCreditAccounts(borrower, options, blockNumber) {
|
|
147
|
-
|
|
148
|
-
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
149
|
-
const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
|
|
150
|
-
const cmFilter = creditManager ? {
|
|
151
|
-
configurators: [],
|
|
152
|
-
creditManagers: [creditManager],
|
|
153
|
-
pools: [],
|
|
154
|
-
underlying: require_sdk_constants_addresses.ADDRESS_0X0
|
|
155
|
-
} : {
|
|
156
|
-
configurators: this.marketConfigurators,
|
|
157
|
-
creditManagers: [],
|
|
158
|
-
pools: [],
|
|
159
|
-
underlying: require_sdk_constants_addresses.ADDRESS_0X0
|
|
160
|
-
};
|
|
161
|
-
const permissiveFilter = {
|
|
162
|
-
owner: borrower,
|
|
163
|
-
includeZeroDebt: true,
|
|
164
|
-
minHealthFactor: 0n,
|
|
165
|
-
maxHealthFactor: require_sdk_constants_math.MAX_UINT256,
|
|
166
|
-
reverting: false
|
|
167
|
-
};
|
|
168
|
-
const rwaContracts = rwaAccountAddresses.map((account) => ({
|
|
169
|
-
abi: require_abi_compressors_creditAccountCompressor.creditAccountCompressorAbi,
|
|
170
|
-
address: this.compressor,
|
|
171
|
-
functionName: "getCreditAccountData",
|
|
172
|
-
args: [account]
|
|
173
|
-
}));
|
|
174
|
-
const getCreditAccountsContracts = [false, true].map((reverting) => ({
|
|
175
|
-
abi: require_abi_compressors_creditAccountCompressor.creditAccountCompressorAbi,
|
|
176
|
-
address: this.compressor,
|
|
177
|
-
functionName: "getCreditAccounts",
|
|
178
|
-
args: [
|
|
179
|
-
cmFilter,
|
|
180
|
-
{
|
|
181
|
-
...permissiveFilter,
|
|
182
|
-
reverting
|
|
183
|
-
},
|
|
184
|
-
0n
|
|
185
|
-
]
|
|
186
|
-
}));
|
|
187
|
-
const allContracts = [...rwaContracts, ...getCreditAccountsContracts];
|
|
188
|
-
const results = await require_sdk_utils_viem_simulateWithPriceUpdates.simulateWithPriceUpdates(this.client, {
|
|
189
|
-
priceUpdates: priceUpdateTxs,
|
|
190
|
-
contracts: allContracts,
|
|
191
|
-
blockNumber,
|
|
192
|
-
gas: this.sdk.gasLimit
|
|
193
|
-
});
|
|
194
|
-
const rwaResults = results.slice(0, rwaAccountAddresses.length);
|
|
195
|
-
const normalResults = results.slice(rwaAccountAddresses.length);
|
|
196
|
-
const seen = new require_sdk_utils_AddressSet.AddressSet();
|
|
197
|
-
const allCAs = [];
|
|
198
|
-
for (const ca of rwaResults) if (!seen.has(ca.creditAccount)) {
|
|
199
|
-
seen.add(ca.creditAccount);
|
|
200
|
-
allCAs.push({
|
|
201
|
-
...ca,
|
|
202
|
-
investor: borrower
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
for (const [accounts] of normalResults) for (const ca of accounts) if (!seen.has(ca.creditAccount)) {
|
|
206
|
-
seen.add(ca.creditAccount);
|
|
207
|
-
allCAs.push({
|
|
208
|
-
...ca,
|
|
209
|
-
investor: void 0
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
const filtered = allCAs.filter((ca) => {
|
|
213
|
-
if (!includeZeroDebt && ca.debt === 0n) return false;
|
|
214
|
-
if (ca.healthFactor < minHealthFactor) return false;
|
|
215
|
-
if (ca.healthFactor > maxHealthFactor) return false;
|
|
216
|
-
if (creditManager && !require_sdk_utils_hex.hexEq(ca.creditManager, creditManager)) return false;
|
|
217
|
-
return true;
|
|
218
|
-
});
|
|
219
|
-
this.logger?.debug(`loaded ${allCAs.length} borrower credit accounts (${rwaResults.length} RWA, ${filtered.length} after filter)`);
|
|
220
|
-
return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
55
|
+
return this.#compressor.getBorrowerCreditAccounts(borrower, options, blockNumber);
|
|
221
56
|
}
|
|
222
57
|
/**
|
|
223
58
|
* {@inheritDoc ICreditAccountsService.listPositions}
|
|
224
59
|
**/
|
|
225
60
|
async listPositions(props) {
|
|
226
|
-
|
|
227
|
-
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }), this.sdk.withdrawalCompressor?.loadWithdrawableAssets()]);
|
|
228
|
-
const describable = accounts.filter((ca) => {
|
|
229
|
-
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
230
|
-
return ca.success;
|
|
231
|
-
});
|
|
232
|
-
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca)));
|
|
233
|
-
return describable.map((ca, i) => this.#strategyPosition(ca, withdrawals[i] ?? new require_sdk_utils_AddressMap.AddressMap()));
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Builds one strategy position from an account snapshot.
|
|
237
|
-
*
|
|
238
|
-
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
239
|
-
* phantom token that represents them on it.
|
|
240
|
-
**/
|
|
241
|
-
#strategyPosition(ca, withdrawals) {
|
|
242
|
-
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
243
|
-
const { market } = suite;
|
|
244
|
-
const { priceOracle } = market;
|
|
245
|
-
const { pool } = market.pool;
|
|
246
|
-
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
247
|
-
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
248
|
-
const collateral = require_sdk_market_credit_dominantCollateral.dominantCollateral(ca, market);
|
|
249
|
-
return {
|
|
250
|
-
kind: "strategy",
|
|
251
|
-
chainId: this.sdk.chainId,
|
|
252
|
-
creditManager: ca.creditManager,
|
|
253
|
-
creditAccount: ca.creditAccount,
|
|
254
|
-
name: collateral ? suite.strategyName(collateral) : token.symbol,
|
|
255
|
-
targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
|
|
256
|
-
leverage: require_sdk_market_math.positionLeverage(totalDebtValue, ca.totalValue),
|
|
257
|
-
borrowApy: require_sdk_market_math.borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
258
|
-
totalDebt: {
|
|
259
|
-
token,
|
|
260
|
-
value: totalDebtValue,
|
|
261
|
-
valueUsd: require_sdk_market_math.usdToNumber(ca.totalDebtUSD)
|
|
262
|
-
},
|
|
263
|
-
totalValue: {
|
|
264
|
-
token,
|
|
265
|
-
value: ca.totalValue,
|
|
266
|
-
valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
|
|
267
|
-
},
|
|
268
|
-
healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
|
|
269
|
-
collaterals: ca.tokens.flatMap((t) => {
|
|
270
|
-
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
|
|
271
|
-
return [{
|
|
272
|
-
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
273
|
-
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
274
|
-
withdrawals: withdrawals.get(t.token) ?? []
|
|
275
|
-
}];
|
|
276
|
-
})
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
281
|
-
* represents them on it, so that each collateral row can pick up its own.
|
|
282
|
-
**/
|
|
283
|
-
async #accountWithdrawals(ca) {
|
|
284
|
-
const compressor = this.sdk.withdrawalCompressor;
|
|
285
|
-
const byPhantomToken = new require_sdk_utils_AddressMap.AddressMap(void 0, "accountWithdrawals");
|
|
286
|
-
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
287
|
-
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
288
|
-
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
289
|
-
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount);
|
|
290
|
-
const add = (w, outputs, claimableAt) => {
|
|
291
|
-
const assets = outputs.map((o) => ({
|
|
292
|
-
isDelayed: true,
|
|
293
|
-
...priceOracle.toTokenAmount(o.token, o.amount),
|
|
294
|
-
redeemer: w.redeemer,
|
|
295
|
-
claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
|
|
296
|
-
}));
|
|
297
|
-
byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
|
|
298
|
-
};
|
|
299
|
-
for (const w of claimable) add(w, w.outputs);
|
|
300
|
-
for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
|
|
301
|
-
return byPhantomToken;
|
|
61
|
+
return this.#compressor.listPositions(props);
|
|
302
62
|
}
|
|
303
63
|
/**
|
|
304
64
|
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
@@ -338,76 +98,6 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
338
98
|
return Object.values(r);
|
|
339
99
|
}
|
|
340
100
|
/**
|
|
341
|
-
* {@inheritDoc ICreditAccountsService.getConnectedBots}
|
|
342
|
-
**/
|
|
343
|
-
async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
|
|
344
|
-
const allResp = await this.client.multicall({
|
|
345
|
-
contracts: [
|
|
346
|
-
...accountsToCheck.map((o) => {
|
|
347
|
-
const pool = this.sdk.marketRegister.findByCreditManager(o.creditManager);
|
|
348
|
-
return {
|
|
349
|
-
abi: require_abi_compressors_peripheryCompressor.peripheryCompressorAbi,
|
|
350
|
-
address: this.peripheryCompressor,
|
|
351
|
-
functionName: "getConnectedBots",
|
|
352
|
-
args: [pool.configurator.address, o.creditAccount]
|
|
353
|
-
};
|
|
354
|
-
}),
|
|
355
|
-
...legacyMigrationBot ? accountsToCheck.map((ca) => {
|
|
356
|
-
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
357
|
-
return {
|
|
358
|
-
abi: require_abi_310_generated.iBotListV310Abi,
|
|
359
|
-
address: cm.creditFacade.botList,
|
|
360
|
-
functionName: "getBotStatus",
|
|
361
|
-
args: [legacyMigrationBot, ca.creditAccount]
|
|
362
|
-
};
|
|
363
|
-
}) : [],
|
|
364
|
-
...accountsToCheck.flatMap((ca) => {
|
|
365
|
-
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
366
|
-
return additionalBots.map((bot) => {
|
|
367
|
-
return {
|
|
368
|
-
abi: require_abi_310_generated.iBotListV310Abi,
|
|
369
|
-
address: cm.creditFacade.botList,
|
|
370
|
-
functionName: "getBotStatus",
|
|
371
|
-
args: [bot, ca.creditAccount]
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
})
|
|
375
|
-
],
|
|
376
|
-
allowFailure: true,
|
|
377
|
-
batchSize: 0
|
|
378
|
-
});
|
|
379
|
-
const legacyStart = 0;
|
|
380
|
-
const legacyEnd = accountsToCheck.length;
|
|
381
|
-
const legacy = allResp.slice(legacyStart, legacyEnd);
|
|
382
|
-
const migrationStart = legacyEnd;
|
|
383
|
-
const migrationEnd = legacyMigrationBot ? migrationStart + accountsToCheck.length : migrationStart;
|
|
384
|
-
const migrationResp = allResp.slice(migrationStart, migrationEnd);
|
|
385
|
-
const additionalStart = migrationEnd;
|
|
386
|
-
const additionalResp = allResp.slice(additionalStart);
|
|
387
|
-
return {
|
|
388
|
-
legacy,
|
|
389
|
-
additionalBots: this.#getActiveBots(accountsToCheck, additionalBots, additionalResp),
|
|
390
|
-
legacyMigration: this.#getActiveMigrationBots(accountsToCheck, legacyMigrationBot, migrationResp)
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
#getActiveBots(accountsToCheck, bots, result) {
|
|
394
|
-
if (result.length !== bots.length * accountsToCheck.length) console.error("result length mismatch", result.length, bots.length * accountsToCheck.length);
|
|
395
|
-
return accountsToCheck.reduce((acc, _, index) => {
|
|
396
|
-
const r = result.slice(index * bots.length, (index + 1) * bots.length);
|
|
397
|
-
acc.push({ result: r });
|
|
398
|
-
return acc;
|
|
399
|
-
}, []);
|
|
400
|
-
}
|
|
401
|
-
#getActiveMigrationBots(accountsToCheck, bot, result) {
|
|
402
|
-
if (bot) {
|
|
403
|
-
if (result.length !== accountsToCheck.length) console.error("result length mismatch for migration bots", result.length, accountsToCheck.length);
|
|
404
|
-
return {
|
|
405
|
-
result,
|
|
406
|
-
botAddress: bot
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
101
|
* {@inheritDoc ICreditAccountsService.fullyLiquidate}
|
|
412
102
|
**/
|
|
413
103
|
async fullyLiquidate(props) {
|
|
@@ -420,7 +110,7 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
420
110
|
keepAssets,
|
|
421
111
|
debtOnly
|
|
422
112
|
});
|
|
423
|
-
const calls = await this
|
|
113
|
+
const calls = await this.prependPriceUpdates(account.creditManager, routerCloseResult.calls, account, { ignoreReservePrices });
|
|
424
114
|
let lossPolicyData;
|
|
425
115
|
if (applyLossPolicy) {
|
|
426
116
|
lossPolicyData = await this.sdk.marketRegister.findByCreditManager(account.creditManager).lossPolicy.getLiquidationData(account.creditAccount);
|
|
@@ -534,15 +224,13 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
534
224
|
async getApprovalAddress(options) {
|
|
535
225
|
const { creditManager } = options;
|
|
536
226
|
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
537
|
-
|
|
538
|
-
if (factory) return factory.getApprovalAddress(options);
|
|
539
|
-
return suite.creditManager.address;
|
|
227
|
+
return suite.rwaFactory ? suite.rwaFactory.getApprovalAddress(options) : suite.creditManager.address;
|
|
540
228
|
}
|
|
541
229
|
/**
|
|
542
230
|
* {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
|
|
543
231
|
*/
|
|
544
232
|
async getOpenAccountRequirements(borrower, creditManager, props) {
|
|
545
|
-
const { rwaFactory } = this.sdk.marketRegister.
|
|
233
|
+
const { rwaFactory } = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
546
234
|
if (!rwaFactory) return;
|
|
547
235
|
return rwaFactory.getOpenAccountRequirements(borrower, props);
|
|
548
236
|
}
|
|
@@ -568,170 +256,80 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
568
256
|
}),
|
|
569
257
|
...callsAfter ?? []
|
|
570
258
|
];
|
|
571
|
-
const calls = await this
|
|
572
|
-
|
|
573
|
-
if (reopenCreditAccount) tx = await this.#multicallTx(cmSuite, reopenCreditAccount, calls);
|
|
574
|
-
else tx = await this.#openCreditAccountTx(cmSuite, to, calls, referralCode, rwaOptions);
|
|
259
|
+
const calls = await this.prependPriceUpdates(cm.address, operationCalls);
|
|
260
|
+
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
575
261
|
tx.value = ethAmount.toString(10);
|
|
576
262
|
return tx;
|
|
577
263
|
}
|
|
578
264
|
/**
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* @param
|
|
582
|
-
* @param
|
|
583
|
-
* @returns
|
|
584
|
-
*/
|
|
585
|
-
async #getCreditAccounts(args, priceUpdateTxs, blockNumber) {
|
|
586
|
-
let resp;
|
|
587
|
-
if (priceUpdateTxs?.length) [resp] = await require_sdk_utils_viem_simulateWithPriceUpdates.simulateWithPriceUpdates(this.client, {
|
|
588
|
-
priceUpdates: priceUpdateTxs,
|
|
589
|
-
contracts: [{
|
|
590
|
-
abi: require_abi_compressors_creditAccountCompressor.creditAccountCompressorAbi,
|
|
591
|
-
address: this.compressor,
|
|
592
|
-
functionName: "getCreditAccounts",
|
|
593
|
-
args
|
|
594
|
-
}],
|
|
595
|
-
blockNumber,
|
|
596
|
-
gas: this.sdk.gasLimit
|
|
597
|
-
});
|
|
598
|
-
else resp = await this.client.readContract({
|
|
599
|
-
abi: require_abi_compressors_creditAccountCompressor.creditAccountCompressorAbi,
|
|
600
|
-
address: this.compressor,
|
|
601
|
-
functionName: "getCreditAccounts",
|
|
602
|
-
args,
|
|
603
|
-
blockNumber,
|
|
604
|
-
gas: this.sdk.gasLimit
|
|
605
|
-
});
|
|
606
|
-
this.logger?.debug({
|
|
607
|
-
accounts: resp[0]?.length ?? 0,
|
|
608
|
-
nextOffset: Number(resp[1])
|
|
609
|
-
}, "got credit accounts");
|
|
610
|
-
return resp;
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Returns multicall entries to redeem (unwrap) RWA ERC-4626 vault shares into underlying for the given credit manager.
|
|
614
|
-
* Used when withdrawing debt from a RWA market: redeems adapter vault shares so the underlying can be withdrawn.
|
|
615
|
-
* Only applies when the credit manager's underlying is RWA-gated and has an ERC-4626 adapter configured.
|
|
616
|
-
* @param amount - Number of vault shares (adapter tokens) to redeem
|
|
265
|
+
* Encodes one ERC-4626 adapter call for an RWA market's underlying vault.
|
|
266
|
+
*
|
|
267
|
+
* @param functionName - Adapter function to call
|
|
268
|
+
* @param amount - Amount passed to the adapter, in the units the function expects
|
|
617
269
|
* @param creditManager - Credit manager address
|
|
618
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined
|
|
270
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined
|
|
271
|
+
* if the underlying is not RWA-gated or no adapter is configured for it
|
|
619
272
|
*/
|
|
620
|
-
|
|
273
|
+
#rwaVaultCalls(functionName, amount, creditManager) {
|
|
621
274
|
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
622
275
|
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
623
276
|
if (!this.sdk.tokensMeta.isRWAUnderlying(meta)) return;
|
|
624
|
-
const
|
|
625
|
-
if (!
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
277
|
+
const target = suite.creditManager.adapters.get(meta.addr)?.address;
|
|
278
|
+
if (!target) return;
|
|
279
|
+
let callData;
|
|
280
|
+
switch (functionName) {
|
|
281
|
+
case "deposit":
|
|
282
|
+
callData = (0, viem.encodeFunctionData)({
|
|
283
|
+
abi: require_abi_ierc4626Adapter.ierc4626AdapterAbi,
|
|
284
|
+
functionName,
|
|
285
|
+
args: [amount, require_sdk_constants_addresses.ADDRESS_0X0]
|
|
286
|
+
});
|
|
287
|
+
break;
|
|
288
|
+
case "redeem":
|
|
289
|
+
callData = (0, viem.encodeFunctionData)({
|
|
290
|
+
abi: require_abi_ierc4626Adapter.ierc4626AdapterAbi,
|
|
291
|
+
functionName,
|
|
292
|
+
args: [
|
|
293
|
+
amount,
|
|
294
|
+
require_sdk_constants_addresses.ADDRESS_0X0,
|
|
295
|
+
require_sdk_constants_addresses.ADDRESS_0X0
|
|
296
|
+
]
|
|
297
|
+
});
|
|
298
|
+
break;
|
|
299
|
+
default: callData = (0, viem.encodeFunctionData)({
|
|
629
300
|
abi: require_abi_ierc4626Adapter.ierc4626AdapterAbi,
|
|
630
|
-
functionName
|
|
631
|
-
args: [
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
301
|
+
functionName,
|
|
302
|
+
args: [amount]
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return [{
|
|
306
|
+
target,
|
|
307
|
+
callData
|
|
637
308
|
}];
|
|
638
309
|
}
|
|
639
310
|
/**
|
|
640
|
-
*
|
|
641
|
-
* Used when adding debt on a RWA market: deposits underlying into the adapter vault so shares are minted on the account.
|
|
642
|
-
* Only applies when the credit manager's underlying is RWA-gated and has an ERC-4626 adapter configured.
|
|
643
|
-
* @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
|
|
644
|
-
* @param creditManager - Credit manager address
|
|
645
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not RWA or no adapter is configured
|
|
311
|
+
* {@inheritDoc ICreditAccountsService.assembleRWAUnwrapCalls}
|
|
646
312
|
*/
|
|
647
|
-
async
|
|
648
|
-
|
|
649
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
650
|
-
if (!this.sdk.tokensMeta.isRWAUnderlying(meta)) return;
|
|
651
|
-
const adapterAddress = suite.creditManager.adapters.get(meta.addr)?.address;
|
|
652
|
-
if (!adapterAddress) return;
|
|
653
|
-
return [{
|
|
654
|
-
target: adapterAddress,
|
|
655
|
-
callData: (0, viem.encodeFunctionData)({
|
|
656
|
-
abi: require_abi_ierc4626Adapter.ierc4626AdapterAbi,
|
|
657
|
-
functionName: "deposit",
|
|
658
|
-
args: [amount, require_sdk_constants_addresses.ADDRESS_0X0]
|
|
659
|
-
})
|
|
660
|
-
}];
|
|
313
|
+
async assembleRWAUnwrapCalls(amount, creditManager) {
|
|
314
|
+
return this.#rwaVaultCalls("redeem", amount, creditManager);
|
|
661
315
|
}
|
|
662
316
|
/**
|
|
663
|
-
*
|
|
664
|
-
* Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess RWA vault tokens.
|
|
665
|
-
* Only applies when the credit manager's underlying is RWA-gated and has an ERC-4626 adapter configured.
|
|
666
|
-
* @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
|
|
667
|
-
* @param creditManager - Credit manager address
|
|
668
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not RWA or no adapter is configured
|
|
317
|
+
* {@inheritDoc ICreditAccountsService.assembleRWAWrapCalls}
|
|
669
318
|
*/
|
|
670
|
-
async
|
|
671
|
-
|
|
672
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
673
|
-
if (!this.sdk.tokensMeta.isRWAUnderlying(meta)) return;
|
|
674
|
-
const adapterAddress = suite.creditManager.adapters.get(meta.addr)?.address;
|
|
675
|
-
if (!adapterAddress) return;
|
|
676
|
-
return [{
|
|
677
|
-
target: adapterAddress,
|
|
678
|
-
callData: (0, viem.encodeFunctionData)({
|
|
679
|
-
abi: require_abi_ierc4626Adapter.ierc4626AdapterAbi,
|
|
680
|
-
functionName: "redeemDiff",
|
|
681
|
-
args: [amount]
|
|
682
|
-
})
|
|
683
|
-
}];
|
|
319
|
+
async assembleRWAWrapCalls(amount, creditManager) {
|
|
320
|
+
return this.#rwaVaultCalls("deposit", amount, creditManager);
|
|
684
321
|
}
|
|
685
322
|
/**
|
|
686
|
-
*
|
|
687
|
-
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
688
|
-
* Only applies when the credit manager's underlying is RWA-gated and has an ERC-4626 adapter configured.
|
|
689
|
-
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
690
|
-
* @param creditManager - Credit manager address
|
|
691
|
-
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not RWA or no adapter is configured
|
|
323
|
+
* {@inheritDoc ICreditAccountsService.assembleRedeemDiffCalls}
|
|
692
324
|
*/
|
|
693
|
-
async
|
|
694
|
-
|
|
695
|
-
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
696
|
-
if (!this.sdk.tokensMeta.isRWAUnderlying(meta)) return;
|
|
697
|
-
const adapterAddress = suite.creditManager.adapters.get(meta.addr)?.address;
|
|
698
|
-
if (!adapterAddress) return;
|
|
699
|
-
return [{
|
|
700
|
-
target: adapterAddress,
|
|
701
|
-
callData: (0, viem.encodeFunctionData)({
|
|
702
|
-
abi: require_abi_ierc4626Adapter.ierc4626AdapterAbi,
|
|
703
|
-
functionName: "depositDiff",
|
|
704
|
-
args: [amount]
|
|
705
|
-
})
|
|
706
|
-
}];
|
|
325
|
+
async assembleRedeemDiffCalls(amount, creditManager) {
|
|
326
|
+
return this.#rwaVaultCalls("redeemDiff", amount, creditManager);
|
|
707
327
|
}
|
|
708
328
|
/**
|
|
709
|
-
* {@inheritDoc ICreditAccountsService.
|
|
329
|
+
* {@inheritDoc ICreditAccountsService.assembleDepositDiffCalls}
|
|
710
330
|
*/
|
|
711
|
-
async
|
|
712
|
-
|
|
713
|
-
const permissions = defaultPermissions !== null ? defaultPermissions : await (0, viem.getContract)({
|
|
714
|
-
address: botAddress,
|
|
715
|
-
client: this.sdk.client,
|
|
716
|
-
abi: [{
|
|
717
|
-
type: "function",
|
|
718
|
-
name: "requiredPermissions",
|
|
719
|
-
inputs: [],
|
|
720
|
-
outputs: [{
|
|
721
|
-
name: "",
|
|
722
|
-
type: "uint192",
|
|
723
|
-
internalType: "uint192"
|
|
724
|
-
}],
|
|
725
|
-
stateMutability: "view"
|
|
726
|
-
}]
|
|
727
|
-
}).read.requiredPermissions();
|
|
728
|
-
const addBotCall = cm.creditFacade.prepareSetBotPermissions(botAddress, permissions);
|
|
729
|
-
const calls = targetContract.type === "creditAccount" ? await this.#prependPriceUpdates(targetContract.creditManager, [addBotCall], targetContract) : [addBotCall];
|
|
730
|
-
return {
|
|
731
|
-
tx: targetContract.type === "creditAccount" ? await this.#multicallTx(cm, targetContract.creditAccount, calls) : void 0,
|
|
732
|
-
calls,
|
|
733
|
-
creditFacade: cm.creditFacade
|
|
734
|
-
};
|
|
331
|
+
async assembleDepositDiffCalls(amount, creditManager) {
|
|
332
|
+
return this.#rwaVaultCalls("depositDiff", amount, creditManager);
|
|
735
333
|
}
|
|
736
334
|
/**
|
|
737
335
|
* {@inheritDoc ICreditAccountsService.assembleRepayCreditAccountCalls}
|
|
@@ -772,88 +370,34 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
772
370
|
minQuota,
|
|
773
371
|
averageQuota
|
|
774
372
|
})];
|
|
775
|
-
const calls = await this
|
|
776
|
-
return
|
|
373
|
+
const calls = await this.prependPriceUpdates(ca.creditManager, operationCalls, ca);
|
|
374
|
+
return cm.multicallTx(ca.creditAccount, calls);
|
|
777
375
|
}
|
|
778
376
|
/**
|
|
779
377
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
780
378
|
* {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
|
|
781
379
|
**/
|
|
782
380
|
async getOnDemandPriceUpdates(account, ignoreReservePrices) {
|
|
783
|
-
const {
|
|
784
|
-
|
|
785
|
-
const update = await this.#getUpdateForAccount(account, ignoreReservePrices);
|
|
786
|
-
this.logger?.debug({
|
|
787
|
-
account: creditAccount,
|
|
788
|
-
manager: cm.name
|
|
789
|
-
}, `getting on demand price updates from ${update.txs.length} txs`);
|
|
790
|
-
return require_sdk_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates(update);
|
|
381
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(account.creditManager);
|
|
382
|
+
return priceOracle.priceUpdatesForAccount(account, { reserve: !ignoreReservePrices });
|
|
791
383
|
}
|
|
792
384
|
/**
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
* Deduplicates existing `onDemandPriceUpdates` calls
|
|
796
|
-
*
|
|
797
|
-
* @param creditManager - Address of the credit manager
|
|
798
|
-
* @param calls - The multicall array to prepend price updates to
|
|
799
|
-
* @param ca - Credit account slice, undefined when opening a new account
|
|
800
|
-
* @param options - Optional settings for price update generation
|
|
801
|
-
* @returns A new array with a single consolidated price update call prepended,
|
|
802
|
-
* followed by the non-price-update calls in their original order
|
|
385
|
+
* {@inheritDoc ICreditAccountsService.prependPriceUpdates}
|
|
803
386
|
*/
|
|
804
|
-
async
|
|
805
|
-
const
|
|
387
|
+
async prependPriceUpdates(creditManager, calls, creditAccount, options) {
|
|
388
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
806
389
|
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
807
|
-
const cm = suite.creditManager;
|
|
808
390
|
const { priceUpdates: existingUpdates, remainingCalls } = require_sdk_accounts_multicall_utils.extractPriceUpdates(calls);
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
}
|
|
814
|
-
const
|
|
815
|
-
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens), {
|
|
816
|
-
main: true,
|
|
817
|
-
reserve: !ignoreReservePrices
|
|
818
|
-
});
|
|
819
|
-
const tStr = tokens.map((t) => this.labelAddress(t)).join(", ");
|
|
820
|
-
const remark = ignoreReservePrices ? " main" : "";
|
|
821
|
-
this.logger?.debug({
|
|
822
|
-
account: ca?.creditAccount,
|
|
823
|
-
manager: cm.name
|
|
824
|
-
}, `prependPriceUpdates for ${tStr} from ${priceFeeds.length}${remark} price feeds`);
|
|
825
|
-
const generatedUpdates = await this.sdk.priceFeeds.generatePriceFeedsUpdates(priceFeeds);
|
|
391
|
+
const extraTokens = require_sdk_accounts_multicall_utils.extractQuotaTokens(calls).asArray();
|
|
392
|
+
const opts = {
|
|
393
|
+
reserve: !options?.ignoreReservePrices,
|
|
394
|
+
extraTokens
|
|
395
|
+
};
|
|
396
|
+
const generatedUpdates = creditAccount ? await priceOracle.priceUpdatesForAccount(creditAccount, opts) : await priceOracle.priceUpdatesForTokens([suite.creditManager.underlying, ...extraTokens], opts);
|
|
826
397
|
const merged = require_sdk_accounts_multicall_utils.mergePriceUpdates(existingUpdates, generatedUpdates);
|
|
827
398
|
if (merged.length === 0) return remainingCalls;
|
|
828
399
|
return [suite.creditFacade.prepareOnDemandPriceUpdates(merged), ...remainingCalls];
|
|
829
400
|
}
|
|
830
|
-
async #getUpdateForAccount(account, ignoreReservePrices) {
|
|
831
|
-
const { creditManager, creditAccount, enabledTokensMask } = account;
|
|
832
|
-
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
833
|
-
const cm = this.sdk.marketRegister.findCreditManager(creditManager).creditManager;
|
|
834
|
-
const tokens = new require_sdk_utils_AddressSet.AddressSet([cm.underlying]);
|
|
835
|
-
for (const t of account.tokens) {
|
|
836
|
-
const isEnabled = (t.mask & enabledTokensMask) !== 0n;
|
|
837
|
-
if (t.balance > 10n && isEnabled) tokens.add(t.token);
|
|
838
|
-
}
|
|
839
|
-
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens), {
|
|
840
|
-
main: true,
|
|
841
|
-
reserve: !ignoreReservePrices
|
|
842
|
-
});
|
|
843
|
-
const tStr = tokens.map((t) => this.labelAddress(t)).join(", ");
|
|
844
|
-
const remark = ignoreReservePrices ? " main" : "";
|
|
845
|
-
this.logger?.debug({
|
|
846
|
-
account: creditAccount,
|
|
847
|
-
manager: cm.name
|
|
848
|
-
}, `generating price feed updates for ${tStr} from ${priceFeeds.length}${remark} price feeds`);
|
|
849
|
-
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
850
|
-
}
|
|
851
|
-
/**
|
|
852
|
-
* {@inheritDoc ICreditAccountsService.prependPriceUpdates}
|
|
853
|
-
*/
|
|
854
|
-
async prependPriceUpdates(creditManager, calls, creditAccount, options) {
|
|
855
|
-
return this.#prependPriceUpdates(creditManager, calls, creditAccount, options);
|
|
856
|
-
}
|
|
857
401
|
/**
|
|
858
402
|
* {@inheritDoc ICreditAccountsService.assembleCaOperations}
|
|
859
403
|
*/
|
|
@@ -899,8 +443,8 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
899
443
|
*/
|
|
900
444
|
async executeCaUpdate(creditAccount, calls, options) {
|
|
901
445
|
const cm = this.sdk.marketRegister.findCreditManager(creditAccount.creditManager);
|
|
902
|
-
const callsWithPrices = await this
|
|
903
|
-
const tx =
|
|
446
|
+
const callsWithPrices = await this.prependPriceUpdates(creditAccount.creditManager, calls, creditAccount, { ignoreReservePrices: options?.ignoreReservePrices });
|
|
447
|
+
const tx = cm.multicallTx(creditAccount.creditAccount, callsWithPrices);
|
|
904
448
|
if (options?.ethAmount && options.ethAmount > 0n) tx.value = options.ethAmount.toString(10);
|
|
905
449
|
return tx;
|
|
906
450
|
}
|
|
@@ -934,52 +478,9 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
934
478
|
prepareAddCollateral(creditFacade, assets, permits) {
|
|
935
479
|
return this.sdk.marketRegister.findCreditFacade(creditFacade).prepareAddCollateral(assets, permits);
|
|
936
480
|
}
|
|
937
|
-
/**
|
|
938
|
-
* Returns addresses of market configurators
|
|
939
|
-
*/
|
|
940
|
-
get marketConfigurators() {
|
|
941
|
-
return this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
|
|
942
|
-
}
|
|
943
481
|
get rewardCompressor() {
|
|
944
482
|
return this.sdk.addressProvider.mustGetLatest(require_sdk_constants_address_provider.AP_REWARDS_COMPRESSOR, require_sdk_constants_versions.VERSION_RANGE_310)[0];
|
|
945
483
|
}
|
|
946
|
-
get peripheryCompressor() {
|
|
947
|
-
return this.sdk.addressProvider.mustGetLatest(require_sdk_constants_address_provider.AP_PERIPHERY_COMPRESSOR, require_sdk_constants_versions.VERSION_RANGE_310)[0];
|
|
948
|
-
}
|
|
949
|
-
get compressor() {
|
|
950
|
-
if (!this.#compressor) {
|
|
951
|
-
[this.#compressor] = this.sdk.addressProvider.mustGetLatest(require_sdk_constants_address_provider.AP_CREDIT_ACCOUNT_COMPRESSOR, require_sdk_constants_versions.VERSION_RANGE_310);
|
|
952
|
-
this.logger?.debug(`credit account compressor address: ${this.#compressor}`);
|
|
953
|
-
}
|
|
954
|
-
return this.#compressor;
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* Wrapper that selects between credit facade and RWA factory
|
|
958
|
-
* @param suite
|
|
959
|
-
* @param to
|
|
960
|
-
* @param calls
|
|
961
|
-
* @param referralCode
|
|
962
|
-
* @param rwaOptions
|
|
963
|
-
* @returns
|
|
964
|
-
*/
|
|
965
|
-
async #openCreditAccountTx(suite, to, calls, referralCode, rwaOptions) {
|
|
966
|
-
const factory = this.sdk.marketRegister.findByPool(suite.pool).rwaFactory;
|
|
967
|
-
if (factory) return factory.openCreditAccount(suite.creditManager.address, calls, rwaOptions);
|
|
968
|
-
return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Wrapper that selects between credit facade and RWA factory
|
|
972
|
-
* @param suite
|
|
973
|
-
* @param creditAccount
|
|
974
|
-
* @param calls
|
|
975
|
-
* @param rwaOptions
|
|
976
|
-
* @returns
|
|
977
|
-
*/
|
|
978
|
-
async #multicallTx(suite, creditAccount, calls, rwaOptions) {
|
|
979
|
-
const factory = this.sdk.marketRegister.findByCreditManager(suite.creditManager.address).rwaFactory;
|
|
980
|
-
if (factory) return factory.multicall(creditAccount, calls, rwaOptions);
|
|
981
|
-
return suite.creditFacade.multicall(creditAccount, calls);
|
|
982
|
-
}
|
|
983
484
|
/**
|
|
984
485
|
* Withdrawal compressor of the current chain.
|
|
985
486
|
* @throws If no withdrawal compressor is supported on the current chain.
|