@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,279 @@
|
|
|
1
|
+
import { AddressMap } from "../../utils/AddressMap.js";
|
|
2
|
+
import { AddressSet } from "../../utils/AddressSet.js";
|
|
3
|
+
import { AP_CREDIT_ACCOUNT_COMPRESSOR } from "../../constants/address-provider.js";
|
|
4
|
+
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
5
|
+
import { MAX_UINT256 } from "../../constants/math.js";
|
|
6
|
+
import { VERSION_RANGE_310 } from "../../constants/versions.js";
|
|
7
|
+
import "../../constants/index.js";
|
|
8
|
+
import { hexEq } from "../../utils/hex.js";
|
|
9
|
+
import "../../utils/index.js";
|
|
10
|
+
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
11
|
+
import "../../base/index.js";
|
|
12
|
+
import { iRWAFactoryAbi } from "../../../abi/rwa/iRWAFactory.js";
|
|
13
|
+
import { borrowApyBps, healthFactorBps, positionLeverage, usdToNumber } from "../../market/math.js";
|
|
14
|
+
import { dominantCollateral } from "../../market/credit/dominantCollateral.js";
|
|
15
|
+
import { simulateWithPriceUpdates } from "../../utils/viem/simulateWithPriceUpdates.js";
|
|
16
|
+
import "../../utils/viem/index.js";
|
|
17
|
+
import "../../market/index.js";
|
|
18
|
+
import { CreditAccountCompressorV310Contract } from "./CreditAccountCompressorV310Contract.js";
|
|
19
|
+
//#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressor.ts
|
|
20
|
+
/**
|
|
21
|
+
* Reads credit accounts of the current chain.
|
|
22
|
+
*
|
|
23
|
+
* Stitches the credit account compressor together with the RWA factories (for
|
|
24
|
+
* accounts owned via an investor EOA) and with the withdrawal compressor (for
|
|
25
|
+
* assets that are on their way out of an account), and describes the result
|
|
26
|
+
* either as raw account data or as {@link StrategyPosition}s.
|
|
27
|
+
*
|
|
28
|
+
* TODO: create and deploy new compressor contract onchain to avoid all this stitching
|
|
29
|
+
**/
|
|
30
|
+
var CreditAccountCompressor = class extends SDKConstruct {
|
|
31
|
+
/**
|
|
32
|
+
* Reads data of a single credit account.
|
|
33
|
+
*
|
|
34
|
+
* When the compressor cannot value the account with current prices, the read
|
|
35
|
+
* is retried with price feed updates applied.
|
|
36
|
+
*
|
|
37
|
+
* @param account - Credit account address.
|
|
38
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
39
|
+
* @returns Account data, or `undefined` if the account does not exist.
|
|
40
|
+
**/
|
|
41
|
+
async getCreditAccountData(account, blockNumber) {
|
|
42
|
+
const contract = this.#contract;
|
|
43
|
+
const raw = await contract.getCreditAccountData(account, blockNumber);
|
|
44
|
+
if (!raw) return;
|
|
45
|
+
const marketSuite = this.sdk.marketRegister.findByCreditManager(raw.creditManager);
|
|
46
|
+
const factory = marketSuite.rwaFactory;
|
|
47
|
+
let ca;
|
|
48
|
+
let investor;
|
|
49
|
+
if (raw.success) {
|
|
50
|
+
ca = raw;
|
|
51
|
+
investor = await factory?.getInvestor(raw.creditAccount, false);
|
|
52
|
+
} else {
|
|
53
|
+
const { txs: priceUpdateTxs } = await marketSuite.priceOracle.priceUpdateTxsForAccount(raw);
|
|
54
|
+
[ca, investor] = await simulateWithPriceUpdates(this.client, {
|
|
55
|
+
priceUpdates: priceUpdateTxs,
|
|
56
|
+
contracts: [contract.dataCall(account), ...factory ? [{
|
|
57
|
+
abi: iRWAFactoryAbi,
|
|
58
|
+
address: factory.address,
|
|
59
|
+
functionName: "getInvestor",
|
|
60
|
+
args: [raw.creditAccount]
|
|
61
|
+
}] : []],
|
|
62
|
+
blockNumber,
|
|
63
|
+
gas: this.sdk.gasLimit
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
...ca,
|
|
68
|
+
investor
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reads all credit accounts matching the options, sorted by health factor
|
|
73
|
+
* ascending.
|
|
74
|
+
*
|
|
75
|
+
* @param options - {@link GetCreditAccountsOptions}
|
|
76
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
77
|
+
**/
|
|
78
|
+
async getCreditAccounts(options, blockNumber) {
|
|
79
|
+
const { creditManager, includeZeroDebt = false, maxHealthFactor = MAX_UINT256, minHealthFactor = 0n, owner = ADDRESS_0X0, ignoreReservePrices = false } = options ?? {};
|
|
80
|
+
const target = creditManager ?? {
|
|
81
|
+
configurators: this.#marketConfigurators,
|
|
82
|
+
creditManagers: [],
|
|
83
|
+
pools: [],
|
|
84
|
+
underlying: "0x0000000000000000000000000000000000000000"
|
|
85
|
+
};
|
|
86
|
+
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
87
|
+
return (await this.#contract.getCreditAccounts(target, {
|
|
88
|
+
owner,
|
|
89
|
+
includeZeroDebt,
|
|
90
|
+
minHealthFactor,
|
|
91
|
+
maxHealthFactor
|
|
92
|
+
}, {
|
|
93
|
+
blockNumber,
|
|
94
|
+
priceUpdateTxs
|
|
95
|
+
})).sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Reads all credit accounts of a borrower, sorted by health factor
|
|
99
|
+
* ascending.
|
|
100
|
+
*
|
|
101
|
+
* Covers accounts the borrower owns directly and RWA accounts they own as an
|
|
102
|
+
* investor, which are owned on-chain by an RWA factory.
|
|
103
|
+
*
|
|
104
|
+
* @param borrower - Wallet address.
|
|
105
|
+
* @param options - {@link GetCreditAccountsOptions}
|
|
106
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
107
|
+
**/
|
|
108
|
+
async getBorrowerCreditAccounts(borrower, options, blockNumber) {
|
|
109
|
+
const { creditManager, includeZeroDebt = false, maxHealthFactor = MAX_UINT256, minHealthFactor = 0n, ignoreReservePrices = false } = options ?? {};
|
|
110
|
+
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
111
|
+
const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
|
|
112
|
+
const cmFilter = creditManager ? {
|
|
113
|
+
configurators: [],
|
|
114
|
+
creditManagers: [creditManager],
|
|
115
|
+
pools: [],
|
|
116
|
+
underlying: ADDRESS_0X0
|
|
117
|
+
} : {
|
|
118
|
+
configurators: this.#marketConfigurators,
|
|
119
|
+
creditManagers: [],
|
|
120
|
+
pools: [],
|
|
121
|
+
underlying: ADDRESS_0X0
|
|
122
|
+
};
|
|
123
|
+
const permissiveFilter = {
|
|
124
|
+
owner: borrower,
|
|
125
|
+
includeZeroDebt: true,
|
|
126
|
+
minHealthFactor: 0n,
|
|
127
|
+
maxHealthFactor: MAX_UINT256,
|
|
128
|
+
reverting: false
|
|
129
|
+
};
|
|
130
|
+
const contract = this.#contract;
|
|
131
|
+
const rwaContracts = rwaAccountAddresses.map((account) => contract.dataCall(account));
|
|
132
|
+
const getCreditAccountsContracts = [false, true].map((reverting) => contract.accountsCall([
|
|
133
|
+
cmFilter,
|
|
134
|
+
{
|
|
135
|
+
...permissiveFilter,
|
|
136
|
+
reverting
|
|
137
|
+
},
|
|
138
|
+
0n
|
|
139
|
+
]));
|
|
140
|
+
const allContracts = [...rwaContracts, ...getCreditAccountsContracts];
|
|
141
|
+
const results = await simulateWithPriceUpdates(this.client, {
|
|
142
|
+
priceUpdates: priceUpdateTxs,
|
|
143
|
+
contracts: allContracts,
|
|
144
|
+
blockNumber,
|
|
145
|
+
gas: this.sdk.gasLimit
|
|
146
|
+
});
|
|
147
|
+
const rwaResults = results.slice(0, rwaAccountAddresses.length);
|
|
148
|
+
const normalResults = results.slice(rwaAccountAddresses.length);
|
|
149
|
+
const seen = new AddressSet();
|
|
150
|
+
const allCAs = [];
|
|
151
|
+
for (const ca of rwaResults) if (!seen.has(ca.creditAccount)) {
|
|
152
|
+
seen.add(ca.creditAccount);
|
|
153
|
+
allCAs.push({
|
|
154
|
+
...ca,
|
|
155
|
+
investor: borrower
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
for (const [accounts] of normalResults) for (const ca of accounts) if (!seen.has(ca.creditAccount)) {
|
|
159
|
+
seen.add(ca.creditAccount);
|
|
160
|
+
allCAs.push({
|
|
161
|
+
...ca,
|
|
162
|
+
investor: void 0
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const filtered = allCAs.filter((ca) => {
|
|
166
|
+
if (!includeZeroDebt && ca.debt === 0n) return false;
|
|
167
|
+
if (ca.healthFactor < minHealthFactor) return false;
|
|
168
|
+
if (ca.healthFactor > maxHealthFactor) return false;
|
|
169
|
+
if (creditManager && !hexEq(ca.creditManager, creditManager)) return false;
|
|
170
|
+
return true;
|
|
171
|
+
});
|
|
172
|
+
this.logger?.debug(`loaded ${allCAs.length} borrower credit accounts (${rwaResults.length} RWA, ${filtered.length} after filter)`);
|
|
173
|
+
return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Describes all credit accounts of a wallet as strategy positions.
|
|
177
|
+
*
|
|
178
|
+
* @param props - {@link ListStrategyPositionsProps}
|
|
179
|
+
**/
|
|
180
|
+
async listPositions(props) {
|
|
181
|
+
const { owner, includeZeroDebt } = props;
|
|
182
|
+
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }), this.sdk.withdrawalCompressor?.loadWithdrawableAssets()]);
|
|
183
|
+
const describable = accounts.filter((ca) => {
|
|
184
|
+
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
185
|
+
return ca.success;
|
|
186
|
+
});
|
|
187
|
+
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca)));
|
|
188
|
+
return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new AddressMap()));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Builds one strategy position from an account snapshot.
|
|
192
|
+
*
|
|
193
|
+
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
194
|
+
* phantom token that represents them on it.
|
|
195
|
+
**/
|
|
196
|
+
#toStrategyPosition(ca, withdrawals) {
|
|
197
|
+
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
198
|
+
const { market } = suite;
|
|
199
|
+
const { priceOracle } = market;
|
|
200
|
+
const { pool } = market.pool;
|
|
201
|
+
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
202
|
+
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
203
|
+
const collateral = dominantCollateral(ca, market);
|
|
204
|
+
return {
|
|
205
|
+
kind: "strategy",
|
|
206
|
+
chainId: this.sdk.chainId,
|
|
207
|
+
creditManager: ca.creditManager,
|
|
208
|
+
creditAccount: ca.creditAccount,
|
|
209
|
+
name: collateral ? suite.strategyName(collateral) : token.symbol,
|
|
210
|
+
targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
|
|
211
|
+
leverage: positionLeverage(totalDebtValue, ca.totalValue),
|
|
212
|
+
borrowApy: borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
213
|
+
totalDebt: {
|
|
214
|
+
token,
|
|
215
|
+
value: totalDebtValue,
|
|
216
|
+
valueUsd: usdToNumber(ca.totalDebtUSD)
|
|
217
|
+
},
|
|
218
|
+
totalValue: {
|
|
219
|
+
token,
|
|
220
|
+
value: ca.totalValue,
|
|
221
|
+
valueUsd: usdToNumber(ca.totalValueUSD)
|
|
222
|
+
},
|
|
223
|
+
healthFactor: healthFactorBps(ca.healthFactor),
|
|
224
|
+
collaterals: ca.tokens.flatMap((t) => {
|
|
225
|
+
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
|
|
226
|
+
return [{
|
|
227
|
+
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
228
|
+
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
229
|
+
withdrawals: withdrawals.get(t.token) ?? []
|
|
230
|
+
}];
|
|
231
|
+
})
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
236
|
+
* represents them on it, so that each collateral row can pick up its own.
|
|
237
|
+
**/
|
|
238
|
+
async #accountWithdrawals(ca) {
|
|
239
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
240
|
+
const byPhantomToken = new AddressMap(void 0, "accountWithdrawals");
|
|
241
|
+
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
242
|
+
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
243
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
244
|
+
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount);
|
|
245
|
+
const add = (w, outputs, claimableAt) => {
|
|
246
|
+
const assets = outputs.map((o) => ({
|
|
247
|
+
isDelayed: true,
|
|
248
|
+
...priceOracle.toTokenAmount(o.token, o.amount),
|
|
249
|
+
redeemer: w.redeemer,
|
|
250
|
+
claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
|
|
251
|
+
}));
|
|
252
|
+
byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
|
|
253
|
+
};
|
|
254
|
+
for (const w of claimable) add(w, w.outputs);
|
|
255
|
+
for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
|
|
256
|
+
return byPhantomToken;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Credit account compressor contract of the current chain.
|
|
260
|
+
*
|
|
261
|
+
* Resolved on every access, because the address provider is only populated
|
|
262
|
+
* once the SDK is attached or hydrated. The contracts register acts as the
|
|
263
|
+
* cache: instances register themselves there on construction, and a
|
|
264
|
+
* re-hydrated SDK with a different compressor address simply misses and
|
|
265
|
+
* builds a new wrapper.
|
|
266
|
+
**/
|
|
267
|
+
get #contract() {
|
|
268
|
+
const [address] = this.sdk.addressProvider.mustGetLatest(AP_CREDIT_ACCOUNT_COMPRESSOR, VERSION_RANGE_310);
|
|
269
|
+
return this.sdk.getContract(address) ?? new CreditAccountCompressorV310Contract(this.sdk, address);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Addresses of market configurators the SDK is attached to.
|
|
273
|
+
**/
|
|
274
|
+
get #marketConfigurators() {
|
|
275
|
+
return this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
//#endregion
|
|
279
|
+
export { CreditAccountCompressor };
|
package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
|
+
import "../../base/index.js";
|
|
3
|
+
import { simulateWithPriceUpdates } from "../../utils/viem/simulateWithPriceUpdates.js";
|
|
4
|
+
import "../../utils/viem/index.js";
|
|
5
|
+
import { creditAccountCompressorAbi } from "../../../abi/compressors/creditAccountCompressor.js";
|
|
6
|
+
//#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressorV310Contract.ts
|
|
7
|
+
const abi = 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 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 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
|
+
export { CreditAccountCompressorV310Contract };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { CreditAccountCompressorV310Contract } from "./credit-account-compressor/CreditAccountCompressorV310Contract.js";
|
|
2
|
+
import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
|
|
3
|
+
import "./credit-account-compressor/index.js";
|
|
1
4
|
import { CreditAccountsServiceV310 } from "./CreditAccountsServiceV310.js";
|
|
2
5
|
import { primaryInstantOutput } from "./intents/operations/claim-delayed/index.js";
|
|
3
6
|
import { CreditAccountOperationsService } from "./intents/index.js";
|
|
@@ -18,4 +21,4 @@ import { toWithdrawalStatus } from "./withdrawal-compressor/types.js";
|
|
|
18
21
|
import { WithdrawalCompressorV313Contract } from "./withdrawal-compressor/WithdrawalCompressorV313Contract.js";
|
|
19
22
|
import { createWithdrawalCompressor } from "./withdrawal-compressor/createWithdrawalCompressor.js";
|
|
20
23
|
import "./withdrawal-compressor/index.js";
|
|
21
|
-
export { AbstractWithdrawalCompressorContract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, getWithdrawalCompressorAddress, iCreditAccountAbi, primaryInstantOutput, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|
|
24
|
+
export { AbstractWithdrawalCompressorContract, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, getWithdrawalCompressorAddress, iCreditAccountAbi, primaryInstantOutput, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|
package/dist/esm/sdk/index.js
CHANGED
|
@@ -103,6 +103,8 @@ import { SecuritizeRWAFactory } from "./market/rwa/securitize/SecuritizeRWAFacto
|
|
|
103
103
|
import { RWARegistry } from "./market/rwa/RWARegistry.js";
|
|
104
104
|
import { RWA_FACTORY_TYPES, isRWAFactory } from "./market/rwa/types.js";
|
|
105
105
|
import "./market/index.js";
|
|
106
|
+
import { CreditAccountCompressorV310Contract } from "./accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js";
|
|
107
|
+
import { CreditAccountCompressor } from "./accounts/credit-account-compressor/CreditAccountCompressor.js";
|
|
106
108
|
import { CreditAccountsServiceV310 } from "./accounts/CreditAccountsServiceV310.js";
|
|
107
109
|
import { primaryInstantOutput } from "./accounts/intents/operations/claim-delayed/index.js";
|
|
108
110
|
import { CreditAccountOperationsService } from "./accounts/intents/index.js";
|
|
@@ -143,4 +145,4 @@ import { OnchainSDK, STATE_VERSION } from "./OnchainSDK.js";
|
|
|
143
145
|
import { MultichainSDK } from "./MultichainSDK.js";
|
|
144
146
|
import { attachOptionsSchema, onchainSDKOptionsSchema } from "./options.js";
|
|
145
147
|
import "./types/index.js";
|
|
146
|
-
export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodHex, additionalBorrowApyBps, assetsMap, attachOptionsSchema, borrowApyBps, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, dominantCollateral, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, fetchPythPayloads, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, healthFactorBps, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, maxLeverage, minSeizedAmount, mustGetDominantCollateral, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalRepaidAmount, percentFmt, positionLeverage, primaryInstantOutput, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, usdToNumber, utilizationBps, watchBlocksAsync };
|
|
148
|
+
export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodHex, additionalBorrowApyBps, assetsMap, attachOptionsSchema, borrowApyBps, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, dominantCollateral, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, fetchPythPayloads, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, healthFactorBps, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, maxLeverage, minSeizedAmount, mustGetDominantCollateral, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalRepaidAmount, percentFmt, positionLeverage, primaryInstantOutput, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, usdToNumber, utilizationBps, watchBlocksAsync };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
2
|
+
import { AddressSet } from "../../utils/AddressSet.js";
|
|
2
3
|
import { AP_PRICE_FEED_COMPRESSOR } from "../../constants/address-provider.js";
|
|
4
|
+
import "../../constants/math.js";
|
|
3
5
|
import { VERSION_RANGE_310 } from "../../constants/versions.js";
|
|
4
6
|
import "../../constants/index.js";
|
|
5
7
|
import { formatBN } from "../../utils/formatter.js";
|
|
@@ -7,8 +9,9 @@ import "../../utils/index.js";
|
|
|
7
9
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
8
10
|
import "../../base/index.js";
|
|
9
11
|
import { usdToNumber } from "../math.js";
|
|
10
|
-
import { PriceFeedRef } from "../pricefeeds/PriceFeedRef.js";
|
|
11
12
|
import { priceFeedCompressorAbi } from "../../../abi/compressors/priceFeedCompressor.js";
|
|
13
|
+
import { PriceFeedRef } from "../pricefeeds/PriceFeedRef.js";
|
|
14
|
+
import { getRawPriceUpdates } from "../pricefeeds/getRawPriceUpdates.js";
|
|
12
15
|
import "../pricefeeds/index.js";
|
|
13
16
|
import PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
|
|
14
17
|
import { stringToHex } from "viem";
|
|
@@ -58,6 +61,31 @@ var PriceOracleBaseContract = class extends BaseContract {
|
|
|
58
61
|
return tokens.flatMap((t) => [main ? this.mainPriceFeeds.get(t)?.priceFeed : void 0, reserve ? this.reservePriceFeeds.get(t)?.priceFeed : void 0]).filter((f) => !!f);
|
|
59
62
|
}
|
|
60
63
|
/**
|
|
64
|
+
* {@inheritDoc IPriceOracleContract.priceUpdateTxsForAccount}
|
|
65
|
+
**/
|
|
66
|
+
async priceUpdateTxsForAccount(account, opts) {
|
|
67
|
+
return this.#priceUpdateTxsForTokens(getAccountTokens(account, opts?.extraTokens), opts);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* {@inheritDoc IPriceOracleContract.priceUpdatesForAccount}
|
|
71
|
+
**/
|
|
72
|
+
async priceUpdatesForAccount(account, opts) {
|
|
73
|
+
return getRawPriceUpdates(await this.priceUpdateTxsForAccount(account, opts));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* {@inheritDoc IPriceOracleContract.priceUpdatesForTokens}
|
|
77
|
+
**/
|
|
78
|
+
async priceUpdatesForTokens(tokens, opts) {
|
|
79
|
+
return getRawPriceUpdates(await this.#priceUpdateTxsForTokens(tokens, opts));
|
|
80
|
+
}
|
|
81
|
+
async #priceUpdateTxsForTokens(tokens, opts) {
|
|
82
|
+
const priceFeeds = this.priceFeedsForTokens(tokens, opts);
|
|
83
|
+
const tStr = tokens.map((t) => this.labelAddress(t)).join(", ");
|
|
84
|
+
const remark = opts?.reserve === false ? " main" : "";
|
|
85
|
+
this.logger?.debug(`generating price feed updates for ${tStr} from ${priceFeeds.length}${remark} price feeds`);
|
|
86
|
+
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
61
89
|
* {@inheritDoc IPriceOracleContract.mainPrice}
|
|
62
90
|
**/
|
|
63
91
|
mainPrice(token) {
|
|
@@ -261,6 +289,18 @@ var PriceOracleBaseContract = class extends BaseContract {
|
|
|
261
289
|
}
|
|
262
290
|
}
|
|
263
291
|
};
|
|
292
|
+
/**
|
|
293
|
+
* Tokens of an account that have to be priced: its underlying, every enabled
|
|
294
|
+
* token it holds a non-dust balance of, and any extra tokens the caller adds.
|
|
295
|
+
**/
|
|
296
|
+
function getAccountTokens(account, extraTokens) {
|
|
297
|
+
const tokens = new AddressSet([account.underlying, ...extraTokens ?? []]);
|
|
298
|
+
for (const t of account.tokens) {
|
|
299
|
+
const isEnabled = (t.mask & account.enabledTokensMask) !== 0n;
|
|
300
|
+
if (t.balance > 10n && isEnabled) tokens.add(t.token);
|
|
301
|
+
}
|
|
302
|
+
return tokens.asArray();
|
|
303
|
+
}
|
|
264
304
|
function formatAnswer({ price, success, updatedAt }, raw = true) {
|
|
265
305
|
if (!success) return "failed";
|
|
266
306
|
let priceS = formatBN(price, 8);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { iPriceOracleV310Abi } from "../../../abi/310/generated.js";
|
|
2
2
|
import { simulateWithPriceUpdates } from "../../utils/viem/simulateWithPriceUpdates.js";
|
|
3
|
-
import { getRawPriceUpdates } from "../pricefeeds/getRawPriceUpdates.js";
|
|
4
|
-
import "../pricefeeds/index.js";
|
|
5
3
|
import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
|
|
6
4
|
//#region src/sdk/market/oracle/PriceOracleV310Contract.ts
|
|
7
5
|
const abi = iPriceOracleV310Abi;
|
|
@@ -14,27 +12,6 @@ var PriceOracleV310Contract = class extends PriceOracleBaseContract {
|
|
|
14
12
|
}, data);
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
|
-
* Converts previously obtained price updates into CreditFacade multicall entry
|
|
18
|
-
* @param creditFacade
|
|
19
|
-
* @param updates
|
|
20
|
-
* @returns
|
|
21
|
-
* @throws If `creditFacade` does not belong to a loaded market.
|
|
22
|
-
*/
|
|
23
|
-
onDemandPriceUpdates(creditFacade, updates) {
|
|
24
|
-
if (!updates) {
|
|
25
|
-
this.logger?.debug("empty updates list");
|
|
26
|
-
return {
|
|
27
|
-
multicall: [],
|
|
28
|
-
raw: []
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
const raw = getRawPriceUpdates(updates);
|
|
32
|
-
return {
|
|
33
|
-
raw,
|
|
34
|
-
multicall: [this.sdk.marketRegister.findCreditFacade(creditFacade).prepareOnDemandPriceUpdates(raw)]
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
15
|
* {@inheritDoc IPriceOracleContract.updateAndConvert}
|
|
39
16
|
**/
|
|
40
17
|
async updateAndConvert(from, to, amount) {
|
|
@@ -8,6 +8,7 @@ import "../../constants/index.js";
|
|
|
8
8
|
import "../../utils/index.js";
|
|
9
9
|
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
10
10
|
import "../../base/index.js";
|
|
11
|
+
import { priceFeedCompressorAbi } from "../../../abi/compressors/priceFeedCompressor.js";
|
|
11
12
|
import { PartialPriceFeedInitError } from "./AbstractPriceFeed.js";
|
|
12
13
|
import { BalancerStablePriceFeedContract } from "./BalancerStablePriceFeed.js";
|
|
13
14
|
import { BalancerWeightedPriceFeedContract } from "./BalancerWeightedPriceFeed.js";
|
|
@@ -21,7 +22,6 @@ import { ExternalPriceFeedContract } from "./ExternalPriceFeed.js";
|
|
|
21
22
|
import { getRawPriceUpdates } from "./getRawPriceUpdates.js";
|
|
22
23
|
import { MellowLRTPriceFeedContract } from "./MellowLRTPriceFeed.js";
|
|
23
24
|
import { PendleTWAPPTPriceFeed } from "./PendleTWAPPTPriceFeed.js";
|
|
24
|
-
import { priceFeedCompressorAbi } from "../../../abi/compressors/priceFeedCompressor.js";
|
|
25
25
|
import { Hooks } from "../../utils/internal/Hooks.js";
|
|
26
26
|
import "../../utils/internal/index.js";
|
|
27
27
|
import { ConstantPriceFeedContract } from "./ConstantPriceFeed.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CreditAccountData } from "../../sdk/base/types.js";
|
|
2
2
|
import { BasePlugin } from "../../sdk/plugins/BasePlugin.js";
|
|
3
3
|
import { IOnchainSDKPlugin } from "../../sdk/plugins/types.js";
|
|
4
|
-
import { GetCreditAccountsOptions } from "../../sdk/accounts/types.js";
|
|
4
|
+
import { GetCreditAccountsOptions } from "../../sdk/accounts/credit-account-compressor/types.js";
|
|
5
5
|
import "../../sdk/index.js";
|
|
6
6
|
import { Address } from "viem";
|
|
7
7
|
//#region src/plugins/accounts/AccountsPlugin.d.ts
|