@gearbox-protocol/sdk 18.6.0-next.3 → 18.6.0-next.5
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/permissionless/api/oracles/PermissionlessOracles.js +26 -6
- package/dist/cjs/permissionless/api/oracles/onchain-feed.js +25 -0
- package/dist/cjs/permissionless/bindings/price-feed-store.js +37 -9
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +5 -5
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +6 -6
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +2 -2
- package/dist/esm/onchain/base/TokensMeta.js +4 -4
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +3 -3
- package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +2 -2
- package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +1 -1
- package/dist/esm/permissionless/api/oracles/PermissionlessOracles.js +27 -7
- package/dist/esm/permissionless/api/oracles/onchain-feed.js +25 -1
- package/dist/esm/permissionless/api/transactions/fixedRateWindowFeeds.js +1 -1
- package/dist/esm/permissionless/bindings/price-feed-store.js +38 -10
- package/dist/types/permissionless/api/oracles/PermissionlessOracles.d.ts +5 -0
- package/dist/types/permissionless/api/oracles/onchain-feed.d.ts +14 -1
- package/package.json +1 -1
|
@@ -186,18 +186,25 @@ var PermissionlessOracles = class extends require_offchain_AbstractOffchainNames
|
|
|
186
186
|
/**
|
|
187
187
|
* One feed as the PriceFeedCompressor reads it, or nothing when the chain
|
|
188
188
|
* cannot be read or the compressor does not know the feed.
|
|
189
|
+
*/
|
|
190
|
+
async #onchainNode(chainId, feed) {
|
|
191
|
+
return (await this.#onchainNodes(chainId, feed))?.get(feed);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Every node of the tree under one feed as the PriceFeedCompressor walks
|
|
195
|
+
* it, or nothing when the chain cannot be read.
|
|
189
196
|
*
|
|
190
197
|
* Failures are warnings and not errors: this only ever stands in for a
|
|
191
198
|
* store that did not have the feed, and the caller reports that miss
|
|
192
199
|
* rather than whatever kept the chain from answering in its place.
|
|
193
200
|
*/
|
|
194
|
-
async #
|
|
201
|
+
async #onchainNodes(chainId, feed) {
|
|
195
202
|
try {
|
|
196
203
|
const client = this.#chains.client(chainId);
|
|
197
204
|
const compressor = await new require_permissionless_bindings_address_provider.AddressProviderContract("0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38", client).getLatestVersionAddress(require_onchain_constants_address_provider.AP_PRICE_FEED_COMPRESSOR);
|
|
198
205
|
if (compressor === viem.zeroAddress) return;
|
|
199
206
|
const { nodes } = await require_permissionless_api_oracles_stress_run.readFeedTrees(client, compressor, [feed]);
|
|
200
|
-
return nodes
|
|
207
|
+
return nodes;
|
|
201
208
|
} catch (e) {
|
|
202
209
|
this.logger?.warn(`could not read price feed ${feed} off chain ${chainId}: ${describe(e)}`);
|
|
203
210
|
return;
|
|
@@ -509,18 +516,31 @@ var PermissionlessOracles = class extends require_offchain_AbstractOffchainNames
|
|
|
509
516
|
* composite feed's children are rarely in the store themselves, and a tree
|
|
510
517
|
* that stopped at the first of them would not be one.
|
|
511
518
|
*
|
|
519
|
+
* A feed the backend has not indexed at all is walked through the
|
|
520
|
+
* PriceFeedCompressor instead, the same way {@link feed} reads it.
|
|
521
|
+
*
|
|
512
522
|
* ```ts
|
|
513
523
|
* const tree = await permissionless.oracles.dependencies({
|
|
514
524
|
* chainId: 1,
|
|
515
525
|
* address: feed,
|
|
516
526
|
* });
|
|
517
527
|
* ```
|
|
528
|
+
*
|
|
529
|
+
* @throws When neither the backend nor the chain knows the feed.
|
|
518
530
|
**/
|
|
519
531
|
async dependencies({ chainId, address }) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
532
|
+
try {
|
|
533
|
+
return await this.getData({
|
|
534
|
+
path: `/pfs/${chainId}/price-feed/${address}/graph`,
|
|
535
|
+
schema: require_model_opportunities_schema.priceFeedDataSchema
|
|
536
|
+
});
|
|
537
|
+
} catch (e) {
|
|
538
|
+
const feed = address.toLowerCase();
|
|
539
|
+
const nodes = isNotFound(e) ? await this.#onchainNodes(chainId, feed) : void 0;
|
|
540
|
+
const tree = nodes && require_permissionless_api_oracles_onchain_feed.onchainPriceFeedData(nodes, feed);
|
|
541
|
+
if (!tree) throw e;
|
|
542
|
+
return tree;
|
|
543
|
+
}
|
|
524
544
|
}
|
|
525
545
|
/**
|
|
526
546
|
* What the named feeds price, read off the chain.
|
|
@@ -21,4 +21,29 @@ function onchainPriceFeed(node) {
|
|
|
21
21
|
name: node.description.trim()
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The dependency tree under `feed`, from the nodes the compressor walked, or
|
|
26
|
+
* nothing when it did not reach the feed.
|
|
27
|
+
*
|
|
28
|
+
* Typed the way {@link onchainPriceFeed} types a node, and named after the
|
|
29
|
+
* feed's address when its description is empty, as the backend names a feed
|
|
30
|
+
* it never persisted a name for. A child the walk did not reach is left out,
|
|
31
|
+
* and one already on the path is not re-entered, so a cycle cannot recurse
|
|
32
|
+
* forever.
|
|
33
|
+
*/
|
|
34
|
+
function onchainPriceFeedData(nodes, feed, path = /* @__PURE__ */ new Set()) {
|
|
35
|
+
const node = nodes.get(feed);
|
|
36
|
+
if (!node || path.has(feed)) return;
|
|
37
|
+
const below = new Set(path).add(feed);
|
|
38
|
+
return {
|
|
39
|
+
name: node.description.trim() || node.address,
|
|
40
|
+
type: onchainPriceFeed(node).contractType,
|
|
41
|
+
feedAddress: node.address,
|
|
42
|
+
dependencies: node.underlyingFeeds.flatMap((child) => {
|
|
43
|
+
const data = onchainPriceFeedData(nodes, child, below);
|
|
44
|
+
return data ? [data] : [];
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
}
|
|
24
48
|
exports.onchainPriceFeed = onchainPriceFeed;
|
|
49
|
+
exports.onchainPriceFeedData = onchainPriceFeedData;
|
|
@@ -286,15 +286,43 @@ var PriceFeedStoreContract = class extends require_onchain_base_BaseContract.Bas
|
|
|
286
286
|
case "configurePriceFeeds": {
|
|
287
287
|
const [priceFeedCalls] = params.args;
|
|
288
288
|
const calls = [];
|
|
289
|
-
for (const priceFeedCall of priceFeedCalls)
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
289
|
+
for (const priceFeedCall of priceFeedCalls) {
|
|
290
|
+
const selector = priceFeedCall.callData.slice(0, 10).toLowerCase();
|
|
291
|
+
if (selector === "0xbc489a65") calls.push({
|
|
292
|
+
target: priceFeedCall.target,
|
|
293
|
+
functionName: "setLimiter",
|
|
294
|
+
args: { lowerBound: (0, viem.formatUnits)(BigInt(`0x${priceFeedCall.callData.slice(10)}`), 18) }
|
|
295
|
+
});
|
|
296
|
+
else if (selector === "0x533258de") {
|
|
297
|
+
const { args } = (0, viem.decodeFunctionData)({
|
|
298
|
+
abi: [{
|
|
299
|
+
type: "function",
|
|
300
|
+
name: "setRateAndBounds",
|
|
301
|
+
inputs: [{
|
|
302
|
+
name: "_growthRate",
|
|
303
|
+
type: "uint16"
|
|
304
|
+
}, {
|
|
305
|
+
name: "_lowerBoundBase",
|
|
306
|
+
type: "uint256"
|
|
307
|
+
}],
|
|
308
|
+
outputs: [],
|
|
309
|
+
stateMutability: "nonpayable"
|
|
310
|
+
}],
|
|
311
|
+
data: priceFeedCall.callData
|
|
312
|
+
});
|
|
313
|
+
calls.push({
|
|
314
|
+
target: priceFeedCall.target,
|
|
315
|
+
functionName: "setRateAndBounds",
|
|
316
|
+
args: {
|
|
317
|
+
growthRate: args[0],
|
|
318
|
+
lowerBound: (0, viem.formatUnits)(args[1], 18)
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
} else calls.push({
|
|
322
|
+
target: priceFeedCall.target,
|
|
323
|
+
callData: priceFeedCall.callData
|
|
324
|
+
});
|
|
325
|
+
}
|
|
298
326
|
return { calls: require_onchain_utils_json.json_stringify(calls) };
|
|
299
327
|
}
|
|
300
328
|
default: return super.parseFunctionParams(params);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
1
2
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
2
3
|
import { getWithdrawalCompressorAddress } from "../onchain/accounts/withdrawal-compressor/addresses.js";
|
|
3
|
-
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import "../onchain/index.js";
|
|
5
5
|
import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
|
|
6
6
|
import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
2
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
3
|
+
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
1
4
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
2
5
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
3
6
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
4
7
|
import { VERSION_RANGE_310 } from "../constants/versions.js";
|
|
5
|
-
import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
6
|
-
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
7
|
-
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
8
|
-
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
9
|
-
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
10
8
|
import { openingSignatureParams } from "../../abi/signatureDegenNFT.js";
|
|
9
|
+
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
11
10
|
import "../base/index.js";
|
|
11
|
+
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
12
12
|
import "../constants/index.js";
|
|
13
13
|
import { InvalidOpeningApprovalError } from "../market/credit/errors.js";
|
|
14
14
|
import "../market/index.js";
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
1
2
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
2
3
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
3
4
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
4
5
|
import { PERCENTAGE_FACTOR, WAD } from "../../constants/math.js";
|
|
5
|
-
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
6
|
-
import { hexEq } from "../../utils/hex.js";
|
|
7
6
|
import "../../../model/index.js";
|
|
8
|
-
import {
|
|
7
|
+
import { hexEq } from "../../utils/hex.js";
|
|
9
8
|
import "../../base/index.js";
|
|
9
|
+
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
10
10
|
import "../../constants/index.js";
|
|
11
|
+
import "../../market/index.js";
|
|
11
12
|
import { RWA_LIQUIDATOR_MIDAS } from "../../market/rwa/midas/constants.js";
|
|
12
13
|
import { matchesLiquidatableAccountFilter } from "../../../model/liquidations.js";
|
|
13
|
-
import "../../market/
|
|
14
|
+
import { usdToNumber } from "../../market/math.js";
|
|
14
15
|
import { RWA_LIQUIDATOR_SECURITIZE } from "../../market/rwa/securitize/constants.js";
|
|
15
16
|
import { dominantCollateral } from "../../market/credit/collateralUtils.js";
|
|
16
17
|
import { MidasLiquidatorContract } from "../../market/rwa/midas/MidasLiquidatorContract.js";
|
|
17
|
-
import { usdToNumber } from "../../market/math.js";
|
|
18
|
-
import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/SecuritizeLiquidatorContract.js";
|
|
19
18
|
import "../../market/rwa/midas/index.js";
|
|
19
|
+
import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/SecuritizeLiquidatorContract.js";
|
|
20
20
|
import "../../market/rwa/securitize/index.js";
|
|
21
21
|
import "../../utils/index.js";
|
|
22
22
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
1
|
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
3
|
-
import {
|
|
2
|
+
import { BaseContract } from "../../base/BaseContract.js";
|
|
4
3
|
import "../../../model/index.js";
|
|
4
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
5
|
import "../../base/index.js";
|
|
6
6
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
7
7
|
// src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
|
-
import { AddressSet } from "../utils/AddressSet.js";
|
|
3
|
-
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
4
1
|
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
5
|
-
import { formatBN } from "../utils/formatter.js";
|
|
6
2
|
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
7
3
|
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
4
|
+
import { AddressMap } from "../utils/AddressMap.js";
|
|
5
|
+
import { AddressSet } from "../utils/AddressSet.js";
|
|
6
|
+
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
8
7
|
import { getAssetType } from "../chain/chains.js";
|
|
8
|
+
import { formatBN } from "../utils/formatter.js";
|
|
9
9
|
import { SdkRWADataNotLoadedError } from "../core/errors.js";
|
|
10
10
|
import "../utils/index.js";
|
|
11
11
|
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
1
2
|
import "../constants/address-provider.js";
|
|
2
3
|
import { isV310 } from "../constants/versions.js";
|
|
3
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
4
4
|
import "../constants/index.js";
|
|
5
5
|
import { hexEq } from "../utils/hex.js";
|
|
6
6
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MissingSerializedParamsError } from "../../../base/errors.js";
|
|
2
1
|
import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
|
|
2
|
+
import { MissingSerializedParamsError } from "../../../base/errors.js";
|
|
3
3
|
import "../../../base/index.js";
|
|
4
4
|
import { iERC4626Abi } from "../abi/targetContractAbi.js";
|
|
5
5
|
import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
|
|
2
|
-
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
4
3
|
import { openWithDataAbi } from "../../../abi/signatureDegenNFT.js";
|
|
4
|
+
import { BaseContract } from "../../base/BaseContract.js";
|
|
5
5
|
import "../../base/index.js";
|
|
6
6
|
// src/onchain/market/credit/CreditFacadeV310BaseContract.ts
|
|
7
7
|
const abi = [
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
2
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
3
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
3
4
|
import { RAY } from "../../constants/math.js";
|
|
4
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
5
|
-
import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
|
|
6
5
|
import "../../base/index.js";
|
|
6
|
+
import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
|
|
7
7
|
import "../../constants/index.js";
|
|
8
|
-
import { BaseContract } from "../../base/BaseContract.js";
|
|
9
8
|
import { SdkRWADataNotLoadedError } from "../../core/errors.js";
|
|
9
|
+
import { BaseContract } from "../../base/BaseContract.js";
|
|
10
10
|
import "../../utils/index.js";
|
|
11
11
|
// src/onchain/market/pool/PoolV310Contract.ts
|
|
12
12
|
const abi = [...iPoolV310Abi, ...iPausableAbi];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
2
1
|
import { iVersionAbi } from "../../../abi/iVersion.js";
|
|
2
|
+
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
3
3
|
import { iMidasDegenNFTAbi } from "../../../abi/rwa/iMidasDegenNFT.js";
|
|
4
4
|
import "../../utils/index.js";
|
|
5
5
|
import { DEGEN_NFT_MIDAS } from "./midas/constants.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
1
|
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
3
|
-
import {
|
|
2
|
+
import { BaseContract } from "../../base/BaseContract.js";
|
|
4
3
|
import "../../../model/index.js";
|
|
4
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
5
|
import "../../base/index.js";
|
|
6
6
|
// src/onchain/market/zapper/ZapperContract.ts
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
2
2
|
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
3
|
-
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
4
3
|
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
4
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
5
|
import "../../../model/index.js";
|
|
6
6
|
// src/onchain/preview/preview/previewPoolPositionOperation.ts
|
|
7
7
|
function previewRead(operation) {
|
|
@@ -9,7 +9,7 @@ import { AddressProviderContract } from "../../bindings/address-provider.js";
|
|
|
9
9
|
import "../../deployment/addresses.js";
|
|
10
10
|
import { getFeedDecimals, getLatestPrices, getPrices } from "../../utils/price-update/get-prices.js";
|
|
11
11
|
import { byCentrality, feedKey, pricesByFeed, toCap, totalQuotas } from "./enrich.js";
|
|
12
|
-
import { onchainPriceFeed } from "./onchain-feed.js";
|
|
12
|
+
import { onchainPriceFeed, onchainPriceFeedData } from "./onchain-feed.js";
|
|
13
13
|
import { assetDetailsSchema, assetSummariesSchema, marketSlotsSchema, priceFeedDetailsSchema, priceFeedStoresSchema } from "./schemas.js";
|
|
14
14
|
import { runAssetScores, runFeedPairScore } from "./score/run.js";
|
|
15
15
|
import { readFeedTrees, runStressTest } from "./stress/run.js";
|
|
@@ -185,18 +185,25 @@ var PermissionlessOracles = class extends AbstractOffchainNamespace {
|
|
|
185
185
|
/**
|
|
186
186
|
* One feed as the PriceFeedCompressor reads it, or nothing when the chain
|
|
187
187
|
* cannot be read or the compressor does not know the feed.
|
|
188
|
+
*/
|
|
189
|
+
async #onchainNode(chainId, feed) {
|
|
190
|
+
return (await this.#onchainNodes(chainId, feed))?.get(feed);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Every node of the tree under one feed as the PriceFeedCompressor walks
|
|
194
|
+
* it, or nothing when the chain cannot be read.
|
|
188
195
|
*
|
|
189
196
|
* Failures are warnings and not errors: this only ever stands in for a
|
|
190
197
|
* store that did not have the feed, and the caller reports that miss
|
|
191
198
|
* rather than whatever kept the chain from answering in its place.
|
|
192
199
|
*/
|
|
193
|
-
async #
|
|
200
|
+
async #onchainNodes(chainId, feed) {
|
|
194
201
|
try {
|
|
195
202
|
const client = this.#chains.client(chainId);
|
|
196
203
|
const compressor = await new AddressProviderContract("0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38", client).getLatestVersionAddress(AP_PRICE_FEED_COMPRESSOR);
|
|
197
204
|
if (compressor === zeroAddress) return;
|
|
198
205
|
const { nodes } = await readFeedTrees(client, compressor, [feed]);
|
|
199
|
-
return nodes
|
|
206
|
+
return nodes;
|
|
200
207
|
} catch (e) {
|
|
201
208
|
this.logger?.warn(`could not read price feed ${feed} off chain ${chainId}: ${describe(e)}`);
|
|
202
209
|
return;
|
|
@@ -508,18 +515,31 @@ var PermissionlessOracles = class extends AbstractOffchainNamespace {
|
|
|
508
515
|
* composite feed's children are rarely in the store themselves, and a tree
|
|
509
516
|
* that stopped at the first of them would not be one.
|
|
510
517
|
*
|
|
518
|
+
* A feed the backend has not indexed at all is walked through the
|
|
519
|
+
* PriceFeedCompressor instead, the same way {@link feed} reads it.
|
|
520
|
+
*
|
|
511
521
|
* ```ts
|
|
512
522
|
* const tree = await permissionless.oracles.dependencies({
|
|
513
523
|
* chainId: 1,
|
|
514
524
|
* address: feed,
|
|
515
525
|
* });
|
|
516
526
|
* ```
|
|
527
|
+
*
|
|
528
|
+
* @throws When neither the backend nor the chain knows the feed.
|
|
517
529
|
**/
|
|
518
530
|
async dependencies({ chainId, address }) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
531
|
+
try {
|
|
532
|
+
return await this.getData({
|
|
533
|
+
path: `/pfs/${chainId}/price-feed/${address}/graph`,
|
|
534
|
+
schema: priceFeedDataSchema
|
|
535
|
+
});
|
|
536
|
+
} catch (e) {
|
|
537
|
+
const feed = address.toLowerCase();
|
|
538
|
+
const nodes = isNotFound(e) ? await this.#onchainNodes(chainId, feed) : void 0;
|
|
539
|
+
const tree = nodes && onchainPriceFeedData(nodes, feed);
|
|
540
|
+
if (!tree) throw e;
|
|
541
|
+
return tree;
|
|
542
|
+
}
|
|
523
543
|
}
|
|
524
544
|
/**
|
|
525
545
|
* What the named feeds price, read off the chain.
|
|
@@ -20,4 +20,28 @@ function onchainPriceFeed(node) {
|
|
|
20
20
|
name: node.description.trim()
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The dependency tree under `feed`, from the nodes the compressor walked, or
|
|
25
|
+
* nothing when it did not reach the feed.
|
|
26
|
+
*
|
|
27
|
+
* Typed the way {@link onchainPriceFeed} types a node, and named after the
|
|
28
|
+
* feed's address when its description is empty, as the backend names a feed
|
|
29
|
+
* it never persisted a name for. A child the walk did not reach is left out,
|
|
30
|
+
* and one already on the path is not re-entered, so a cycle cannot recurse
|
|
31
|
+
* forever.
|
|
32
|
+
*/
|
|
33
|
+
function onchainPriceFeedData(nodes, feed, path = /* @__PURE__ */ new Set()) {
|
|
34
|
+
const node = nodes.get(feed);
|
|
35
|
+
if (!node || path.has(feed)) return;
|
|
36
|
+
const below = new Set(path).add(feed);
|
|
37
|
+
return {
|
|
38
|
+
name: node.description.trim() || node.address,
|
|
39
|
+
type: onchainPriceFeed(node).contractType,
|
|
40
|
+
feedAddress: node.address,
|
|
41
|
+
dependencies: node.underlyingFeeds.flatMap((child) => {
|
|
42
|
+
const data = onchainPriceFeedData(nodes, child, below);
|
|
43
|
+
return data ? [data] : [];
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export { onchainPriceFeed, onchainPriceFeedData };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { iPriceFeedAbi } from "../../../abi/iPriceFeed.js";
|
|
1
2
|
import { bytes32ToString } from "../../../onchain/utils/bytes32ToString.js";
|
|
2
3
|
import { createRawTx } from "../../../onchain/utils/createRawTx.js";
|
|
3
4
|
import { PERCENTAGE_FACTOR, SECONDS_PER_YEAR } from "../../../onchain/constants/math.js";
|
|
4
5
|
import { simulateMulticall } from "../../../onchain/utils/viem/simulateMulticall.js";
|
|
5
6
|
import { fixedRateWindowPriceFeedAbi } from "../../../onchain/abi/oracles.js";
|
|
6
|
-
import { iPriceFeedAbi } from "../../../abi/iPriceFeed.js";
|
|
7
7
|
import "../../../onchain/abi/index.js";
|
|
8
8
|
import "../../../onchain/index.js";
|
|
9
9
|
import { nextLowerBound } from "./nextLowerBound.js";
|
|
@@ -4,7 +4,7 @@ import { iPriceFeedStoreAbi } from "../../abi/310/iPriceFeedStore.js";
|
|
|
4
4
|
import "../../onchain/index.js";
|
|
5
5
|
import { PRICE_FEED_STORE } from "../utils/literals.js";
|
|
6
6
|
import { priceFeedSetupParams } from "./pricefeeds/index.js";
|
|
7
|
-
import { encodeAbiParameters, formatUnits, hexToString, recoverTypedDataAddress } from "viem";
|
|
7
|
+
import { decodeFunctionData, encodeAbiParameters, formatUnits, hexToString, recoverTypedDataAddress } from "viem";
|
|
8
8
|
// src/permissionless/bindings/price-feed-store.ts
|
|
9
9
|
const abi = iPriceFeedStoreAbi;
|
|
10
10
|
var PriceFeedStoreContract = class extends BaseContract {
|
|
@@ -285,15 +285,43 @@ var PriceFeedStoreContract = class extends BaseContract {
|
|
|
285
285
|
case "configurePriceFeeds": {
|
|
286
286
|
const [priceFeedCalls] = params.args;
|
|
287
287
|
const calls = [];
|
|
288
|
-
for (const priceFeedCall of priceFeedCalls)
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
288
|
+
for (const priceFeedCall of priceFeedCalls) {
|
|
289
|
+
const selector = priceFeedCall.callData.slice(0, 10).toLowerCase();
|
|
290
|
+
if (selector === "0xbc489a65") calls.push({
|
|
291
|
+
target: priceFeedCall.target,
|
|
292
|
+
functionName: "setLimiter",
|
|
293
|
+
args: { lowerBound: formatUnits(BigInt(`0x${priceFeedCall.callData.slice(10)}`), 18) }
|
|
294
|
+
});
|
|
295
|
+
else if (selector === "0x533258de") {
|
|
296
|
+
const { args } = decodeFunctionData({
|
|
297
|
+
abi: [{
|
|
298
|
+
type: "function",
|
|
299
|
+
name: "setRateAndBounds",
|
|
300
|
+
inputs: [{
|
|
301
|
+
name: "_growthRate",
|
|
302
|
+
type: "uint16"
|
|
303
|
+
}, {
|
|
304
|
+
name: "_lowerBoundBase",
|
|
305
|
+
type: "uint256"
|
|
306
|
+
}],
|
|
307
|
+
outputs: [],
|
|
308
|
+
stateMutability: "nonpayable"
|
|
309
|
+
}],
|
|
310
|
+
data: priceFeedCall.callData
|
|
311
|
+
});
|
|
312
|
+
calls.push({
|
|
313
|
+
target: priceFeedCall.target,
|
|
314
|
+
functionName: "setRateAndBounds",
|
|
315
|
+
args: {
|
|
316
|
+
growthRate: args[0],
|
|
317
|
+
lowerBound: formatUnits(args[1], 18)
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
} else calls.push({
|
|
321
|
+
target: priceFeedCall.target,
|
|
322
|
+
callData: priceFeedCall.callData
|
|
323
|
+
});
|
|
324
|
+
}
|
|
297
325
|
return { calls: json_stringify(calls) };
|
|
298
326
|
}
|
|
299
327
|
default: return super.parseFunctionParams(params);
|
|
@@ -252,12 +252,17 @@ export declare class PermissionlessOracles extends AbstractOffchainNamespace {
|
|
|
252
252
|
* composite feed's children are rarely in the store themselves, and a tree
|
|
253
253
|
* that stopped at the first of them would not be one.
|
|
254
254
|
*
|
|
255
|
+
* A feed the backend has not indexed at all is walked through the
|
|
256
|
+
* PriceFeedCompressor instead, the same way {@link feed} reads it.
|
|
257
|
+
*
|
|
255
258
|
* ```ts
|
|
256
259
|
* const tree = await permissionless.oracles.dependencies({
|
|
257
260
|
* chainId: 1,
|
|
258
261
|
* address: feed,
|
|
259
262
|
* });
|
|
260
263
|
* ```
|
|
264
|
+
*
|
|
265
|
+
* @throws When neither the backend nor the chain knows the feed.
|
|
261
266
|
**/
|
|
262
267
|
dependencies({ chainId, address }: PriceFeedArgs): Promise<PriceFeedData>;
|
|
263
268
|
/**
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { PriceFeedData } from "../../../model/opportunities.js";
|
|
1
2
|
import { PriceFeed } from "../../core/pricefeed.js";
|
|
2
3
|
import { TreeNode } from "./stress/classify.js";
|
|
4
|
+
import { Address } from "viem";
|
|
3
5
|
/**
|
|
4
6
|
* What the store would say about a feed, from what the chain says instead.
|
|
5
7
|
*
|
|
@@ -10,4 +12,15 @@ import { TreeNode } from "./stress/classify.js";
|
|
|
10
12
|
* contract it cannot otherwise place; an empty type is the same thing said
|
|
11
13
|
* less clearly.
|
|
12
14
|
*/
|
|
13
|
-
export declare function onchainPriceFeed(node: TreeNode): PriceFeed;
|
|
15
|
+
export declare function onchainPriceFeed(node: TreeNode): PriceFeed;
|
|
16
|
+
/**
|
|
17
|
+
* The dependency tree under `feed`, from the nodes the compressor walked, or
|
|
18
|
+
* nothing when it did not reach the feed.
|
|
19
|
+
*
|
|
20
|
+
* Typed the way {@link onchainPriceFeed} types a node, and named after the
|
|
21
|
+
* feed's address when its description is empty, as the backend names a feed
|
|
22
|
+
* it never persisted a name for. A child the walk did not reach is left out,
|
|
23
|
+
* and one already on the path is not re-entered, so a cycle cannot recurse
|
|
24
|
+
* forever.
|
|
25
|
+
*/
|
|
26
|
+
export declare function onchainPriceFeedData(nodes: ReadonlyMap<Address, TreeNode>, feed: Address, path?: ReadonlySet<Address>): PriceFeedData | undefined;
|