@gearbox-protocol/sdk 14.12.0-next.74 → 14.12.0-next.75
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 +73 -445
- 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 +5 -0
- package/dist/cjs/sdk/index.js +4 -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 +74 -446
- 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 +4 -1
- package/dist/esm/sdk/index.js +3 -1
- 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/plugins/accounts/AccountsPlugin.d.ts +1 -1
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +10 -44
- 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 +7 -3
- package/dist/types/sdk/accounts/types.d.ts +5 -112
- 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 +8 -5
- package/dist/types/sdk/market/index.d.ts +2 -2
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +15 -4
- 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 +30 -14
- package/package.json +1 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
3
|
+
const require_sdk_utils_AddressSet = require("../../utils/AddressSet.js");
|
|
4
|
+
const require_sdk_constants_address_provider = require("../../constants/address-provider.js");
|
|
5
|
+
const require_sdk_constants_addresses = require("../../constants/addresses.js");
|
|
6
|
+
const require_sdk_constants_math = require("../../constants/math.js");
|
|
7
|
+
const require_sdk_constants_versions = require("../../constants/versions.js");
|
|
8
|
+
require("../../constants/index.js");
|
|
9
|
+
const require_sdk_utils_hex = require("../../utils/hex.js");
|
|
10
|
+
require("../../utils/index.js");
|
|
11
|
+
const require_sdk_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
12
|
+
require("../../base/index.js");
|
|
13
|
+
const require_abi_rwa_iRWAFactory = require("../../../abi/rwa/iRWAFactory.js");
|
|
14
|
+
const require_sdk_market_math = require("../../market/math.js");
|
|
15
|
+
const require_sdk_market_credit_dominantCollateral = require("../../market/credit/dominantCollateral.js");
|
|
16
|
+
const require_sdk_utils_viem_simulateWithPriceUpdates = require("../../utils/viem/simulateWithPriceUpdates.js");
|
|
17
|
+
require("../../utils/viem/index.js");
|
|
18
|
+
require("../../market/index.js");
|
|
19
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract = require("./CreditAccountCompressorV310Contract.js");
|
|
20
|
+
//#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressor.ts
|
|
21
|
+
/**
|
|
22
|
+
* Reads credit accounts of the current chain.
|
|
23
|
+
*
|
|
24
|
+
* Stitches the credit account compressor together with the RWA factories (for
|
|
25
|
+
* accounts owned via an investor EOA) and with the withdrawal compressor (for
|
|
26
|
+
* assets that are on their way out of an account), and describes the result
|
|
27
|
+
* either as raw account data or as {@link StrategyPosition}s.
|
|
28
|
+
*
|
|
29
|
+
* TODO: create and deploy new compressor contract onchain to avoid all this stitching
|
|
30
|
+
**/
|
|
31
|
+
var CreditAccountCompressor = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
32
|
+
/**
|
|
33
|
+
* Reads data of a single credit account.
|
|
34
|
+
*
|
|
35
|
+
* When the compressor cannot value the account with current prices, the read
|
|
36
|
+
* is retried with price feed updates applied.
|
|
37
|
+
*
|
|
38
|
+
* @param account - Credit account address.
|
|
39
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
40
|
+
* @returns Account data, or `undefined` if the account does not exist.
|
|
41
|
+
**/
|
|
42
|
+
async getCreditAccountData(account, blockNumber) {
|
|
43
|
+
const contract = this.#contract;
|
|
44
|
+
const raw = await contract.getCreditAccountData(account, blockNumber);
|
|
45
|
+
if (!raw) return;
|
|
46
|
+
const marketSuite = this.sdk.marketRegister.findByCreditManager(raw.creditManager);
|
|
47
|
+
const factory = marketSuite.rwaFactory;
|
|
48
|
+
let ca;
|
|
49
|
+
let investor;
|
|
50
|
+
if (raw.success) {
|
|
51
|
+
ca = raw;
|
|
52
|
+
investor = await factory?.getInvestor(raw.creditAccount, false);
|
|
53
|
+
} else {
|
|
54
|
+
const { txs: priceUpdateTxs } = await marketSuite.priceOracle.priceUpdateTxsForAccount(raw);
|
|
55
|
+
[ca, investor] = await require_sdk_utils_viem_simulateWithPriceUpdates.simulateWithPriceUpdates(this.client, {
|
|
56
|
+
priceUpdates: priceUpdateTxs,
|
|
57
|
+
contracts: [contract.dataCall(account), ...factory ? [{
|
|
58
|
+
abi: require_abi_rwa_iRWAFactory.iRWAFactoryAbi,
|
|
59
|
+
address: factory.address,
|
|
60
|
+
functionName: "getInvestor",
|
|
61
|
+
args: [raw.creditAccount]
|
|
62
|
+
}] : []],
|
|
63
|
+
blockNumber,
|
|
64
|
+
gas: this.sdk.gasLimit
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
...ca,
|
|
69
|
+
investor
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reads all credit accounts matching the options, sorted by health factor
|
|
74
|
+
* ascending.
|
|
75
|
+
*
|
|
76
|
+
* @param options - {@link GetCreditAccountsOptions}
|
|
77
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
78
|
+
**/
|
|
79
|
+
async getCreditAccounts(options, blockNumber) {
|
|
80
|
+
const { creditManager, includeZeroDebt = false, maxHealthFactor = require_sdk_constants_math.MAX_UINT256, minHealthFactor = 0n, owner = require_sdk_constants_addresses.ADDRESS_0X0, ignoreReservePrices = false } = options ?? {};
|
|
81
|
+
const target = creditManager ?? {
|
|
82
|
+
configurators: this.#marketConfigurators,
|
|
83
|
+
creditManagers: [],
|
|
84
|
+
pools: [],
|
|
85
|
+
underlying: "0x0000000000000000000000000000000000000000"
|
|
86
|
+
};
|
|
87
|
+
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
88
|
+
return (await this.#contract.getCreditAccounts(target, {
|
|
89
|
+
owner,
|
|
90
|
+
includeZeroDebt,
|
|
91
|
+
minHealthFactor,
|
|
92
|
+
maxHealthFactor
|
|
93
|
+
}, {
|
|
94
|
+
blockNumber,
|
|
95
|
+
priceUpdateTxs
|
|
96
|
+
})).sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reads all credit accounts of a borrower, sorted by health factor
|
|
100
|
+
* ascending.
|
|
101
|
+
*
|
|
102
|
+
* Covers accounts the borrower owns directly and RWA accounts they own as an
|
|
103
|
+
* investor, which are owned on-chain by an RWA factory.
|
|
104
|
+
*
|
|
105
|
+
* @param borrower - Wallet address.
|
|
106
|
+
* @param options - {@link GetCreditAccountsOptions}
|
|
107
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
108
|
+
**/
|
|
109
|
+
async getBorrowerCreditAccounts(borrower, options, blockNumber) {
|
|
110
|
+
const { creditManager, includeZeroDebt = false, maxHealthFactor = require_sdk_constants_math.MAX_UINT256, minHealthFactor = 0n, ignoreReservePrices = false } = options ?? {};
|
|
111
|
+
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
112
|
+
const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
|
|
113
|
+
const cmFilter = creditManager ? {
|
|
114
|
+
configurators: [],
|
|
115
|
+
creditManagers: [creditManager],
|
|
116
|
+
pools: [],
|
|
117
|
+
underlying: require_sdk_constants_addresses.ADDRESS_0X0
|
|
118
|
+
} : {
|
|
119
|
+
configurators: this.#marketConfigurators,
|
|
120
|
+
creditManagers: [],
|
|
121
|
+
pools: [],
|
|
122
|
+
underlying: require_sdk_constants_addresses.ADDRESS_0X0
|
|
123
|
+
};
|
|
124
|
+
const permissiveFilter = {
|
|
125
|
+
owner: borrower,
|
|
126
|
+
includeZeroDebt: true,
|
|
127
|
+
minHealthFactor: 0n,
|
|
128
|
+
maxHealthFactor: require_sdk_constants_math.MAX_UINT256,
|
|
129
|
+
reverting: false
|
|
130
|
+
};
|
|
131
|
+
const contract = this.#contract;
|
|
132
|
+
const rwaContracts = rwaAccountAddresses.map((account) => contract.dataCall(account));
|
|
133
|
+
const getCreditAccountsContracts = [false, true].map((reverting) => contract.accountsCall([
|
|
134
|
+
cmFilter,
|
|
135
|
+
{
|
|
136
|
+
...permissiveFilter,
|
|
137
|
+
reverting
|
|
138
|
+
},
|
|
139
|
+
0n
|
|
140
|
+
]));
|
|
141
|
+
const allContracts = [...rwaContracts, ...getCreditAccountsContracts];
|
|
142
|
+
const results = await require_sdk_utils_viem_simulateWithPriceUpdates.simulateWithPriceUpdates(this.client, {
|
|
143
|
+
priceUpdates: priceUpdateTxs,
|
|
144
|
+
contracts: allContracts,
|
|
145
|
+
blockNumber,
|
|
146
|
+
gas: this.sdk.gasLimit
|
|
147
|
+
});
|
|
148
|
+
const rwaResults = results.slice(0, rwaAccountAddresses.length);
|
|
149
|
+
const normalResults = results.slice(rwaAccountAddresses.length);
|
|
150
|
+
const seen = new require_sdk_utils_AddressSet.AddressSet();
|
|
151
|
+
const allCAs = [];
|
|
152
|
+
for (const ca of rwaResults) if (!seen.has(ca.creditAccount)) {
|
|
153
|
+
seen.add(ca.creditAccount);
|
|
154
|
+
allCAs.push({
|
|
155
|
+
...ca,
|
|
156
|
+
investor: borrower
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
for (const [accounts] of normalResults) for (const ca of accounts) if (!seen.has(ca.creditAccount)) {
|
|
160
|
+
seen.add(ca.creditAccount);
|
|
161
|
+
allCAs.push({
|
|
162
|
+
...ca,
|
|
163
|
+
investor: void 0
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const filtered = allCAs.filter((ca) => {
|
|
167
|
+
if (!includeZeroDebt && ca.debt === 0n) return false;
|
|
168
|
+
if (ca.healthFactor < minHealthFactor) return false;
|
|
169
|
+
if (ca.healthFactor > maxHealthFactor) return false;
|
|
170
|
+
if (creditManager && !require_sdk_utils_hex.hexEq(ca.creditManager, creditManager)) return false;
|
|
171
|
+
return true;
|
|
172
|
+
});
|
|
173
|
+
this.logger?.debug(`loaded ${allCAs.length} borrower credit accounts (${rwaResults.length} RWA, ${filtered.length} after filter)`);
|
|
174
|
+
return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Describes all credit accounts of a wallet as strategy positions.
|
|
178
|
+
*
|
|
179
|
+
* @param props - {@link ListStrategyPositionsProps}
|
|
180
|
+
**/
|
|
181
|
+
async listPositions(props) {
|
|
182
|
+
const { owner, includeZeroDebt } = props;
|
|
183
|
+
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }), this.sdk.withdrawalCompressor?.loadWithdrawableAssets()]);
|
|
184
|
+
const describable = accounts.filter((ca) => {
|
|
185
|
+
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
186
|
+
return ca.success;
|
|
187
|
+
});
|
|
188
|
+
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca)));
|
|
189
|
+
return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new require_sdk_utils_AddressMap.AddressMap()));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Builds one strategy position from an account snapshot.
|
|
193
|
+
*
|
|
194
|
+
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
195
|
+
* phantom token that represents them on it.
|
|
196
|
+
**/
|
|
197
|
+
#toStrategyPosition(ca, withdrawals) {
|
|
198
|
+
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
199
|
+
const { market } = suite;
|
|
200
|
+
const { priceOracle } = market;
|
|
201
|
+
const { pool } = market.pool;
|
|
202
|
+
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
203
|
+
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
204
|
+
const collateral = require_sdk_market_credit_dominantCollateral.dominantCollateral(ca, market);
|
|
205
|
+
return {
|
|
206
|
+
kind: "strategy",
|
|
207
|
+
chainId: this.sdk.chainId,
|
|
208
|
+
creditManager: ca.creditManager,
|
|
209
|
+
creditAccount: ca.creditAccount,
|
|
210
|
+
name: collateral ? suite.strategyName(collateral) : token.symbol,
|
|
211
|
+
targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
|
|
212
|
+
leverage: require_sdk_market_math.positionLeverage(totalDebtValue, ca.totalValue),
|
|
213
|
+
borrowApy: require_sdk_market_math.borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
214
|
+
totalDebt: {
|
|
215
|
+
token,
|
|
216
|
+
value: totalDebtValue,
|
|
217
|
+
valueUsd: require_sdk_market_math.usdToNumber(ca.totalDebtUSD)
|
|
218
|
+
},
|
|
219
|
+
totalValue: {
|
|
220
|
+
token,
|
|
221
|
+
value: ca.totalValue,
|
|
222
|
+
valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
|
|
223
|
+
},
|
|
224
|
+
healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
|
|
225
|
+
collaterals: ca.tokens.flatMap((t) => {
|
|
226
|
+
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
|
|
227
|
+
return [{
|
|
228
|
+
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
229
|
+
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
230
|
+
withdrawals: withdrawals.get(t.token) ?? []
|
|
231
|
+
}];
|
|
232
|
+
})
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
237
|
+
* represents them on it, so that each collateral row can pick up its own.
|
|
238
|
+
**/
|
|
239
|
+
async #accountWithdrawals(ca) {
|
|
240
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
241
|
+
const byPhantomToken = new require_sdk_utils_AddressMap.AddressMap(void 0, "accountWithdrawals");
|
|
242
|
+
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
243
|
+
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
244
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
245
|
+
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount);
|
|
246
|
+
const add = (w, outputs, claimableAt) => {
|
|
247
|
+
const assets = outputs.map((o) => ({
|
|
248
|
+
isDelayed: true,
|
|
249
|
+
...priceOracle.toTokenAmount(o.token, o.amount),
|
|
250
|
+
redeemer: w.redeemer,
|
|
251
|
+
claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
|
|
252
|
+
}));
|
|
253
|
+
byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
|
|
254
|
+
};
|
|
255
|
+
for (const w of claimable) add(w, w.outputs);
|
|
256
|
+
for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
|
|
257
|
+
return byPhantomToken;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Credit account compressor contract of the current chain.
|
|
261
|
+
*
|
|
262
|
+
* Resolved on every access, because the address provider is only populated
|
|
263
|
+
* once the SDK is attached or hydrated. The contracts register acts as the
|
|
264
|
+
* cache: instances register themselves there on construction, and a
|
|
265
|
+
* re-hydrated SDK with a different compressor address simply misses and
|
|
266
|
+
* builds a new wrapper.
|
|
267
|
+
**/
|
|
268
|
+
get #contract() {
|
|
269
|
+
const [address] = this.sdk.addressProvider.mustGetLatest(require_sdk_constants_address_provider.AP_CREDIT_ACCOUNT_COMPRESSOR, require_sdk_constants_versions.VERSION_RANGE_310);
|
|
270
|
+
return this.sdk.getContract(address) ?? new require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract.CreditAccountCompressorV310Contract(this.sdk, address);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Addresses of market configurators the SDK is attached to.
|
|
274
|
+
**/
|
|
275
|
+
get #marketConfigurators() {
|
|
276
|
+
return this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
//#endregion
|
|
280
|
+
exports.CreditAccountCompressor = CreditAccountCompressor;
|
package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_base_BaseContract = require("../../base/BaseContract.js");
|
|
3
|
+
require("../../base/index.js");
|
|
4
|
+
const require_sdk_utils_viem_simulateWithPriceUpdates = require("../../utils/viem/simulateWithPriceUpdates.js");
|
|
5
|
+
require("../../utils/viem/index.js");
|
|
6
|
+
//#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.ts
|
|
7
|
+
const abi = require("../../../abi/compressors/creditAccountCompressor.js").creditAccountCompressorAbi;
|
|
8
|
+
/**
|
|
9
|
+
* V3.10 credit account compressor.
|
|
10
|
+
*
|
|
11
|
+
* Wraps the compressor ABI and nothing else: single-account reads, paginated
|
|
12
|
+
* multi-account reads, and call descriptors for callers that need to batch
|
|
13
|
+
* these reads with calls to other contracts.
|
|
14
|
+
**/
|
|
15
|
+
var CreditAccountCompressorV310Contract = class extends require_sdk_base_BaseContract.BaseContract {
|
|
16
|
+
#sdk;
|
|
17
|
+
constructor(sdk, address) {
|
|
18
|
+
super(sdk, {
|
|
19
|
+
addr: address,
|
|
20
|
+
name: "CreditAccountCompressorV310",
|
|
21
|
+
abi,
|
|
22
|
+
version: 310
|
|
23
|
+
});
|
|
24
|
+
this.#sdk = sdk;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reads data of a single credit account.
|
|
28
|
+
*
|
|
29
|
+
* @param account - Credit account address.
|
|
30
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
31
|
+
* @returns Account data, or `undefined` if the compressor reverted, which it
|
|
32
|
+
* does when the account does not exist.
|
|
33
|
+
**/
|
|
34
|
+
async getCreditAccountData(account, blockNumber) {
|
|
35
|
+
try {
|
|
36
|
+
return await this.client.readContract({
|
|
37
|
+
abi,
|
|
38
|
+
address: this.address,
|
|
39
|
+
functionName: "getCreditAccountData",
|
|
40
|
+
args: [account],
|
|
41
|
+
blockNumber,
|
|
42
|
+
gas: this.#sdk.gasLimit
|
|
43
|
+
});
|
|
44
|
+
} catch (_e) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Reads all credit accounts matching the filters, in the order the
|
|
50
|
+
* compressor returns them.
|
|
51
|
+
*
|
|
52
|
+
* Two compressor quirks are handled here: results are paginated, and the
|
|
53
|
+
* `reverting` account filter is exclusive, so accounts whose collateral
|
|
54
|
+
* computation reverts are only returned by a second pass.
|
|
55
|
+
*
|
|
56
|
+
* @param target - Credit managers to query.
|
|
57
|
+
* @param query - Account-level filters, without `reverting`.
|
|
58
|
+
* @param options - Block, price updates and page size.
|
|
59
|
+
**/
|
|
60
|
+
async getCreditAccounts(target, query, options) {
|
|
61
|
+
const { batchSize, blockNumber, priceUpdateTxs } = options ?? {};
|
|
62
|
+
const allCAs = [];
|
|
63
|
+
let revertingOffset = 0;
|
|
64
|
+
for (const reverting of [false, true]) {
|
|
65
|
+
let offset = 0n;
|
|
66
|
+
revertingOffset = allCAs.length;
|
|
67
|
+
do {
|
|
68
|
+
const [accounts, newOffset] = await this.#getCreditAccounts(batchSize ? [
|
|
69
|
+
target,
|
|
70
|
+
{
|
|
71
|
+
...query,
|
|
72
|
+
reverting
|
|
73
|
+
},
|
|
74
|
+
offset,
|
|
75
|
+
batchSize
|
|
76
|
+
] : [
|
|
77
|
+
target,
|
|
78
|
+
{
|
|
79
|
+
...query,
|
|
80
|
+
reverting
|
|
81
|
+
},
|
|
82
|
+
offset
|
|
83
|
+
], priceUpdateTxs, blockNumber);
|
|
84
|
+
allCAs.push(...accounts);
|
|
85
|
+
offset = newOffset;
|
|
86
|
+
} while (offset !== 0n);
|
|
87
|
+
}
|
|
88
|
+
this.logger?.debug(`loaded ${allCAs.length} credit accounts (${allCAs.length - revertingOffset} reverting)`);
|
|
89
|
+
return allCAs;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Descriptor of a `getCreditAccountData` call on this compressor.
|
|
93
|
+
**/
|
|
94
|
+
dataCall(account) {
|
|
95
|
+
return {
|
|
96
|
+
abi,
|
|
97
|
+
address: this.address,
|
|
98
|
+
functionName: "getCreditAccountData",
|
|
99
|
+
args: [account]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Descriptor of a `getCreditAccounts` call on this compressor.
|
|
104
|
+
**/
|
|
105
|
+
accountsCall(args) {
|
|
106
|
+
return {
|
|
107
|
+
abi,
|
|
108
|
+
address: this.address,
|
|
109
|
+
functionName: "getCreditAccounts",
|
|
110
|
+
args
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* One page of `getCreditAccounts`, with price updates applied when the
|
|
115
|
+
* accounts hold tokens with on-demand price feeds.
|
|
116
|
+
**/
|
|
117
|
+
async #getCreditAccounts(args, priceUpdateTxs, blockNumber) {
|
|
118
|
+
let resp;
|
|
119
|
+
if (priceUpdateTxs?.length) [resp] = await require_sdk_utils_viem_simulateWithPriceUpdates.simulateWithPriceUpdates(this.client, {
|
|
120
|
+
priceUpdates: priceUpdateTxs,
|
|
121
|
+
contracts: [this.accountsCall(args)],
|
|
122
|
+
blockNumber,
|
|
123
|
+
gas: this.#sdk.gasLimit
|
|
124
|
+
});
|
|
125
|
+
else resp = await this.client.readContract({
|
|
126
|
+
abi,
|
|
127
|
+
address: this.address,
|
|
128
|
+
functionName: "getCreditAccounts",
|
|
129
|
+
args,
|
|
130
|
+
blockNumber,
|
|
131
|
+
gas: this.#sdk.gasLimit
|
|
132
|
+
});
|
|
133
|
+
this.logger?.debug({
|
|
134
|
+
accounts: resp[0]?.length ?? 0,
|
|
135
|
+
nextOffset: Number(resp[1])
|
|
136
|
+
}, "got credit accounts");
|
|
137
|
+
return resp;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
//#endregion
|
|
141
|
+
exports.CreditAccountCompressorV310Contract = CreditAccountCompressorV310Contract;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract = require("./CreditAccountCompressorV310Contract.js");
|
|
3
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressor = require("./CreditAccountCompressor.js");
|
|
4
|
+
require("./types.js");
|
|
5
|
+
exports.CreditAccountCompressor = require_sdk_accounts_credit_account_compressor_CreditAccountCompressor.CreditAccountCompressor;
|
|
6
|
+
exports.CreditAccountCompressorV310Contract = require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract.CreditAccountCompressorV310Contract;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract = require("./credit-account-compressor/CreditAccountCompressorV310Contract.js");
|
|
3
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressor = require("./credit-account-compressor/CreditAccountCompressor.js");
|
|
4
|
+
require("./credit-account-compressor/index.js");
|
|
2
5
|
const require_sdk_accounts_CreditAccountsServiceV310 = require("./CreditAccountsServiceV310.js");
|
|
3
6
|
const require_sdk_accounts_intents_operations_claim_delayed_index = require("./intents/operations/claim-delayed/index.js");
|
|
4
7
|
const require_sdk_accounts_intents_index = require("./intents/index.js");
|
|
@@ -20,6 +23,8 @@ const require_sdk_accounts_withdrawal_compressor_WithdrawalCompressorV313Contrac
|
|
|
20
23
|
const require_sdk_accounts_withdrawal_compressor_createWithdrawalCompressor = require("./withdrawal-compressor/createWithdrawalCompressor.js");
|
|
21
24
|
require("./withdrawal-compressor/index.js");
|
|
22
25
|
exports.AbstractWithdrawalCompressorContract = require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.AbstractWithdrawalCompressorContract;
|
|
26
|
+
exports.CreditAccountCompressor = require_sdk_accounts_credit_account_compressor_CreditAccountCompressor.CreditAccountCompressor;
|
|
27
|
+
exports.CreditAccountCompressorV310Contract = require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract.CreditAccountCompressorV310Contract;
|
|
23
28
|
exports.CreditAccountOperationsService = require_sdk_accounts_intents_index.CreditAccountOperationsService;
|
|
24
29
|
exports.CreditAccountsServiceV310 = require_sdk_accounts_CreditAccountsServiceV310.CreditAccountsServiceV310;
|
|
25
30
|
exports.DELAYED_INTENT_TYPES = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_TYPES;
|
package/dist/cjs/sdk/index.js
CHANGED
|
@@ -104,6 +104,8 @@ const require_sdk_market_rwa_securitize_SecuritizeRWAFactory = require("./market
|
|
|
104
104
|
const require_sdk_market_rwa_RWARegistry = require("./market/rwa/RWARegistry.js");
|
|
105
105
|
const require_sdk_market_rwa_types = require("./market/rwa/types.js");
|
|
106
106
|
require("./market/index.js");
|
|
107
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract = require("./accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js");
|
|
108
|
+
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressor = require("./accounts/credit-account-compressor/CreditAccountCompressor.js");
|
|
107
109
|
const require_sdk_accounts_CreditAccountsServiceV310 = require("./accounts/CreditAccountsServiceV310.js");
|
|
108
110
|
const require_sdk_accounts_intents_operations_claim_delayed_index = require("./accounts/intents/operations/claim-delayed/index.js");
|
|
109
111
|
const require_sdk_accounts_intents_index = require("./accounts/intents/index.js");
|
|
@@ -200,6 +202,8 @@ exports.ChainNotConfiguredError = require_sdk_core_errors.ChainNotConfiguredErro
|
|
|
200
202
|
exports.CompositePriceFeedContract = require_sdk_market_pricefeeds_CompositePriceFeed.CompositePriceFeedContract;
|
|
201
203
|
exports.Construct = require_sdk_base_Construct.Construct;
|
|
202
204
|
exports.ContractParseError = require_sdk_base_BaseContract.ContractParseError;
|
|
205
|
+
exports.CreditAccountCompressor = require_sdk_accounts_credit_account_compressor_CreditAccountCompressor.CreditAccountCompressor;
|
|
206
|
+
exports.CreditAccountCompressorV310Contract = require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract.CreditAccountCompressorV310Contract;
|
|
203
207
|
exports.CreditAccountOperationsService = require_sdk_accounts_intents_index.CreditAccountOperationsService;
|
|
204
208
|
exports.CreditAccountsServiceV310 = require_sdk_accounts_CreditAccountsServiceV310.CreditAccountsServiceV310;
|
|
205
209
|
exports.CreditConfiguratorV310Contract = require_sdk_market_credit_CreditConfiguratorV310Contract.CreditConfiguratorV310Contract;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
3
|
+
const require_sdk_utils_AddressSet = require("../../utils/AddressSet.js");
|
|
3
4
|
const require_sdk_constants_address_provider = require("../../constants/address-provider.js");
|
|
5
|
+
require("../../constants/math.js");
|
|
4
6
|
const require_sdk_constants_versions = require("../../constants/versions.js");
|
|
5
7
|
require("../../constants/index.js");
|
|
6
8
|
const require_sdk_utils_formatter = require("../../utils/formatter.js");
|
|
@@ -8,8 +10,9 @@ require("../../utils/index.js");
|
|
|
8
10
|
const require_sdk_base_BaseContract = require("../../base/BaseContract.js");
|
|
9
11
|
require("../../base/index.js");
|
|
10
12
|
const require_sdk_market_math = require("../math.js");
|
|
11
|
-
const require_sdk_market_pricefeeds_PriceFeedRef = require("../pricefeeds/PriceFeedRef.js");
|
|
12
13
|
const require_abi_compressors_priceFeedCompressor = require("../../../abi/compressors/priceFeedCompressor.js");
|
|
14
|
+
const require_sdk_market_pricefeeds_PriceFeedRef = require("../pricefeeds/PriceFeedRef.js");
|
|
15
|
+
const require_sdk_market_pricefeeds_getRawPriceUpdates = require("../pricefeeds/getRawPriceUpdates.js");
|
|
13
16
|
require("../pricefeeds/index.js");
|
|
14
17
|
const require_sdk_market_oracle_PriceFeedAnswerMap = require("./PriceFeedAnswerMap.js");
|
|
15
18
|
let viem = require("viem");
|
|
@@ -59,6 +62,31 @@ var PriceOracleBaseContract = class extends require_sdk_base_BaseContract.BaseCo
|
|
|
59
62
|
return tokens.flatMap((t) => [main ? this.mainPriceFeeds.get(t)?.priceFeed : void 0, reserve ? this.reservePriceFeeds.get(t)?.priceFeed : void 0]).filter((f) => !!f);
|
|
60
63
|
}
|
|
61
64
|
/**
|
|
65
|
+
* {@inheritDoc IPriceOracleContract.priceUpdateTxsForAccount}
|
|
66
|
+
**/
|
|
67
|
+
async priceUpdateTxsForAccount(account, opts) {
|
|
68
|
+
return this.#priceUpdateTxsForTokens(getAccountTokens(account, opts?.extraTokens), opts);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* {@inheritDoc IPriceOracleContract.priceUpdatesForAccount}
|
|
72
|
+
**/
|
|
73
|
+
async priceUpdatesForAccount(account, opts) {
|
|
74
|
+
return require_sdk_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates(await this.priceUpdateTxsForAccount(account, opts));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* {@inheritDoc IPriceOracleContract.priceUpdatesForTokens}
|
|
78
|
+
**/
|
|
79
|
+
async priceUpdatesForTokens(tokens, opts) {
|
|
80
|
+
return require_sdk_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates(await this.#priceUpdateTxsForTokens(tokens, opts));
|
|
81
|
+
}
|
|
82
|
+
async #priceUpdateTxsForTokens(tokens, opts) {
|
|
83
|
+
const priceFeeds = this.priceFeedsForTokens(tokens, opts);
|
|
84
|
+
const tStr = tokens.map((t) => this.labelAddress(t)).join(", ");
|
|
85
|
+
const remark = opts?.reserve === false ? " main" : "";
|
|
86
|
+
this.logger?.debug(`generating price feed updates for ${tStr} from ${priceFeeds.length}${remark} price feeds`);
|
|
87
|
+
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
62
90
|
* {@inheritDoc IPriceOracleContract.mainPrice}
|
|
63
91
|
**/
|
|
64
92
|
mainPrice(token) {
|
|
@@ -262,6 +290,18 @@ var PriceOracleBaseContract = class extends require_sdk_base_BaseContract.BaseCo
|
|
|
262
290
|
}
|
|
263
291
|
}
|
|
264
292
|
};
|
|
293
|
+
/**
|
|
294
|
+
* Tokens of an account that have to be priced: its underlying, every enabled
|
|
295
|
+
* token it holds a non-dust balance of, and any extra tokens the caller adds.
|
|
296
|
+
**/
|
|
297
|
+
function getAccountTokens(account, extraTokens) {
|
|
298
|
+
const tokens = new require_sdk_utils_AddressSet.AddressSet([account.underlying, ...extraTokens ?? []]);
|
|
299
|
+
for (const t of account.tokens) {
|
|
300
|
+
const isEnabled = (t.mask & account.enabledTokensMask) !== 0n;
|
|
301
|
+
if (t.balance > 10n && isEnabled) tokens.add(t.token);
|
|
302
|
+
}
|
|
303
|
+
return tokens.asArray();
|
|
304
|
+
}
|
|
265
305
|
function formatAnswer({ price, success, updatedAt }, raw = true) {
|
|
266
306
|
if (!success) return "failed";
|
|
267
307
|
let priceS = require_sdk_utils_formatter.formatBN(price, 8);
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_abi_310_generated = require("../../../abi/310/generated.js");
|
|
3
3
|
const require_sdk_utils_viem_simulateWithPriceUpdates = require("../../utils/viem/simulateWithPriceUpdates.js");
|
|
4
|
-
const require_sdk_market_pricefeeds_getRawPriceUpdates = require("../pricefeeds/getRawPriceUpdates.js");
|
|
5
|
-
require("../pricefeeds/index.js");
|
|
6
4
|
const require_sdk_market_oracle_PriceOracleBaseContract = require("./PriceOracleBaseContract.js");
|
|
7
5
|
//#region src/sdk/market/oracle/PriceOracleV310Contract.ts
|
|
8
6
|
const abi = require_abi_310_generated.iPriceOracleV310Abi;
|
|
@@ -15,27 +13,6 @@ var PriceOracleV310Contract = class extends require_sdk_market_oracle_PriceOracl
|
|
|
15
13
|
}, data);
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
|
-
* Converts previously obtained price updates into CreditFacade multicall entry
|
|
19
|
-
* @param creditFacade
|
|
20
|
-
* @param updates
|
|
21
|
-
* @returns
|
|
22
|
-
* @throws If `creditFacade` does not belong to a loaded market.
|
|
23
|
-
*/
|
|
24
|
-
onDemandPriceUpdates(creditFacade, updates) {
|
|
25
|
-
if (!updates) {
|
|
26
|
-
this.logger?.debug("empty updates list");
|
|
27
|
-
return {
|
|
28
|
-
multicall: [],
|
|
29
|
-
raw: []
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const raw = require_sdk_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates(updates);
|
|
33
|
-
return {
|
|
34
|
-
raw,
|
|
35
|
-
multicall: [this.sdk.marketRegister.findCreditFacade(creditFacade).prepareOnDemandPriceUpdates(raw)]
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
16
|
* {@inheritDoc IPriceOracleContract.updateAndConvert}
|
|
40
17
|
**/
|
|
41
18
|
async updateAndConvert(from, to, amount) {
|
|
@@ -9,6 +9,7 @@ require("../../constants/index.js");
|
|
|
9
9
|
require("../../utils/index.js");
|
|
10
10
|
const require_sdk_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
11
11
|
require("../../base/index.js");
|
|
12
|
+
const require_abi_compressors_priceFeedCompressor = require("../../../abi/compressors/priceFeedCompressor.js");
|
|
12
13
|
const require_sdk_market_pricefeeds_AbstractPriceFeed = require("./AbstractPriceFeed.js");
|
|
13
14
|
const require_sdk_market_pricefeeds_BalancerStablePriceFeed = require("./BalancerStablePriceFeed.js");
|
|
14
15
|
const require_sdk_market_pricefeeds_BalancerWeightedPriceFeed = require("./BalancerWeightedPriceFeed.js");
|
|
@@ -22,7 +23,6 @@ const require_sdk_market_pricefeeds_ExternalPriceFeed = require("./ExternalPrice
|
|
|
22
23
|
const require_sdk_market_pricefeeds_getRawPriceUpdates = require("./getRawPriceUpdates.js");
|
|
23
24
|
const require_sdk_market_pricefeeds_MellowLRTPriceFeed = require("./MellowLRTPriceFeed.js");
|
|
24
25
|
const require_sdk_market_pricefeeds_PendleTWAPPTPriceFeed = require("./PendleTWAPPTPriceFeed.js");
|
|
25
|
-
const require_abi_compressors_priceFeedCompressor = require("../../../abi/compressors/priceFeedCompressor.js");
|
|
26
26
|
const require_sdk_utils_internal_Hooks = require("../../utils/internal/Hooks.js");
|
|
27
27
|
require("../../utils/internal/index.js");
|
|
28
28
|
const require_sdk_market_pricefeeds_ConstantPriceFeed = require("./ConstantPriceFeed.js");
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { creditAccountCompressorAbi } from "../../abi/compressors/creditAccountCompressor.js";
|
|
2
1
|
import { AddressMap } from "../../sdk/utils/AddressMap.js";
|
|
3
2
|
import { TypedObjectUtils } from "../../sdk/utils/mappers.js";
|
|
4
3
|
import { AP_CREDIT_ACCOUNT_COMPRESSOR } from "../../sdk/constants/address-provider.js";
|
|
5
4
|
import { ADDRESS_0X0 } from "../../sdk/constants/addresses.js";
|
|
6
5
|
import { MAX_UINT256 } from "../../sdk/constants/math.js";
|
|
7
6
|
import { VERSION_RANGE_310 } from "../../sdk/constants/versions.js";
|
|
7
|
+
import { creditAccountCompressorAbi } from "../../abi/compressors/creditAccountCompressor.js";
|
|
8
8
|
import { BasePlugin } from "../../sdk/plugins/BasePlugin.js";
|
|
9
9
|
import "../../sdk/index.js";
|
|
10
10
|
//#region src/plugins/accounts-counter/AccountsCounterPlugin.ts
|