@gearbox-protocol/sdk 18.3.0 → 18.4.0
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/abi/310/iKillSwitchProxy.js +130 -0
- package/dist/cjs/onchain/accounts/intents/maxBorrowAndWithdraw.js +3 -1
- package/dist/cjs/onchain/index.js +18 -0
- package/dist/cjs/onchain/market/adapters/abi/adapters/iTreehouseFastlaneAdapter.js +113 -0
- package/dist/cjs/onchain/market/adapters/abi/adapters/iTreehouseRedemptionGatewayAdapter.js +258 -0
- package/dist/cjs/onchain/market/adapters/abi/adapters/iTreehouseRouterAdapter.js +161 -0
- package/dist/cjs/onchain/market/adapters/abi/adapters/index.js +6 -0
- package/dist/cjs/onchain/market/adapters/abi/index.js +13 -0
- package/dist/cjs/onchain/market/adapters/abi/treehouse/iTreehouseFastlane.js +39 -0
- package/dist/cjs/onchain/market/adapters/abi/treehouse/iTreehouseRedemptionGateway.js +230 -0
- package/dist/cjs/onchain/market/adapters/abi/treehouse/iTreehouseRouter.js +29 -0
- package/dist/cjs/onchain/market/adapters/abi/treehouse/index.js +7 -0
- package/dist/cjs/onchain/market/adapters/contracts/TreehouseFastlaneAdapterContract.js +72 -0
- package/dist/cjs/onchain/market/adapters/contracts/TreehouseRedemptionGatewayAdapterContract.js +117 -0
- package/dist/cjs/onchain/market/adapters/contracts/TreehouseRouterAdapterContract.js +61 -0
- package/dist/cjs/onchain/market/adapters/contracts/index.js +6 -0
- package/dist/cjs/onchain/market/adapters/createAdapter.js +6 -0
- package/dist/cjs/onchain/market/adapters/index.js +18 -0
- package/dist/cjs/onchain/market/index.js +18 -0
- package/dist/cjs/permissionless/api/index.js +31 -0
- package/dist/cjs/permissionless/api/oracles/PermissionlessOracles.js +637 -65
- package/dist/cjs/permissionless/api/oracles/enrich.js +99 -0
- package/dist/cjs/permissionless/api/oracles/index.js +33 -0
- package/dist/cjs/permissionless/api/oracles/onchain-feed.js +25 -0
- package/dist/cjs/permissionless/api/oracles/schemas.js +84 -59
- package/dist/cjs/permissionless/api/oracles/score/formula.js +56 -0
- package/dist/cjs/permissionless/api/oracles/score/index.js +11 -0
- package/dist/cjs/permissionless/api/oracles/score/run.js +252 -0
- package/dist/cjs/permissionless/api/oracles/score/types.js +1 -0
- package/dist/cjs/permissionless/api/oracles/stress/classify.js +258 -0
- package/dist/cjs/permissionless/api/oracles/stress/index.js +24 -0
- package/dist/cjs/permissionless/api/oracles/stress/override.js +125 -0
- package/dist/cjs/permissionless/api/oracles/stress/run.js +485 -0
- package/dist/cjs/permissionless/api/oracles/stress/score.js +98 -0
- package/dist/cjs/permissionless/api/oracles/stress/types.js +1 -0
- package/dist/cjs/permissionless/api/schemas.js +0 -3
- package/dist/cjs/permissionless/api/transactions/InstanceOwnerTransactions.js +14 -3
- package/dist/cjs/permissionless/api/transactions/lp-price-feeds.js +10 -4
- package/dist/cjs/permissionless/bindings/bytecode-repository.js +8 -0
- package/dist/cjs/permissionless/bindings/governance/governor.js +1 -1
- package/dist/cjs/permissionless/bindings/index.js +8 -3
- package/dist/cjs/permissionless/bindings/kill-switch-proxy.js +188 -0
- package/dist/cjs/permissionless/bindings/market-configurator-factory.js +39 -1
- package/dist/cjs/permissionless/bindings/market-configurator.js +142 -0
- package/dist/cjs/permissionless/index.js +42 -3
- package/dist/cjs/permissionless/utils/index.js +3 -0
- package/dist/cjs/permissionless/utils/literals.js +2 -0
- package/dist/cjs/permissionless/utils/price-update/get-prices.js +64 -0
- package/dist/cjs/permissionless/utils/price-update/index.js +2 -0
- package/dist/cjs/testnets/TestnetsAPI.js +179 -0
- package/dist/cjs/testnets/errors/TestnetNotFoundError.js +15 -0
- package/dist/cjs/testnets/errors/TestnetRequestFailedError.js +24 -0
- package/dist/cjs/testnets/errors/TestnetStatusError.js +19 -0
- package/dist/cjs/testnets/errors/TestnetValidationError.js +24 -0
- package/dist/cjs/testnets/errors/TestnetWaitTimeoutError.js +30 -0
- package/dist/cjs/testnets/errors/TestnetsError.js +34 -0
- package/dist/cjs/testnets/errors/index.js +13 -0
- package/dist/cjs/testnets/index.js +32 -0
- package/dist/cjs/testnets/package.json +1 -0
- package/dist/cjs/testnets/schemas.js +242 -0
- package/dist/cjs/testnets/types.js +1 -0
- package/dist/esm/abi/310/iKillSwitchProxy.js +129 -0
- package/dist/esm/onchain/accounts/intents/maxBorrowAndWithdraw.js +3 -1
- package/dist/esm/onchain/index.js +10 -1
- package/dist/esm/onchain/market/adapters/abi/adapters/iTreehouseFastlaneAdapter.js +112 -0
- package/dist/esm/onchain/market/adapters/abi/adapters/iTreehouseRedemptionGatewayAdapter.js +257 -0
- package/dist/esm/onchain/market/adapters/abi/adapters/iTreehouseRouterAdapter.js +160 -0
- package/dist/esm/onchain/market/adapters/abi/adapters/index.js +4 -1
- package/dist/esm/onchain/market/adapters/abi/index.js +8 -1
- package/dist/esm/onchain/market/adapters/abi/treehouse/iTreehouseFastlane.js +38 -0
- package/dist/esm/onchain/market/adapters/abi/treehouse/iTreehouseRedemptionGateway.js +229 -0
- package/dist/esm/onchain/market/adapters/abi/treehouse/iTreehouseRouter.js +28 -0
- package/dist/esm/onchain/market/adapters/abi/treehouse/index.js +4 -0
- package/dist/esm/onchain/market/adapters/contracts/TreehouseFastlaneAdapterContract.js +71 -0
- package/dist/esm/onchain/market/adapters/contracts/TreehouseRedemptionGatewayAdapterContract.js +116 -0
- package/dist/esm/onchain/market/adapters/contracts/TreehouseRouterAdapterContract.js +60 -0
- package/dist/esm/onchain/market/adapters/contracts/index.js +4 -1
- package/dist/esm/onchain/market/adapters/createAdapter.js +6 -0
- package/dist/esm/onchain/market/adapters/index.js +10 -1
- package/dist/esm/onchain/market/index.js +10 -1
- package/dist/esm/permissionless/api/index.js +7 -1
- package/dist/esm/permissionless/api/oracles/PermissionlessOracles.js +639 -67
- package/dist/esm/permissionless/api/oracles/enrich.js +94 -0
- package/dist/esm/permissionless/api/oracles/index.js +10 -1
- package/dist/esm/permissionless/api/oracles/onchain-feed.js +24 -0
- package/dist/esm/permissionless/api/oracles/schemas.js +80 -58
- package/dist/esm/permissionless/api/oracles/score/formula.js +51 -0
- package/dist/esm/permissionless/api/oracles/score/index.js +4 -0
- package/dist/esm/permissionless/api/oracles/score/run.js +250 -0
- package/dist/esm/permissionless/api/oracles/score/types.js +1 -0
- package/dist/esm/permissionless/api/oracles/stress/classify.js +256 -0
- package/dist/esm/permissionless/api/oracles/stress/index.js +6 -0
- package/dist/esm/permissionless/api/oracles/stress/override.js +119 -0
- package/dist/esm/permissionless/api/oracles/stress/run.js +478 -0
- package/dist/esm/permissionless/api/oracles/stress/score.js +95 -0
- package/dist/esm/permissionless/api/oracles/stress/types.js +1 -0
- package/dist/esm/permissionless/api/schemas.js +2 -4
- package/dist/esm/permissionless/api/transactions/InstanceOwnerTransactions.js +14 -3
- package/dist/esm/permissionless/api/transactions/lp-price-feeds.js +10 -4
- package/dist/esm/permissionless/bindings/bytecode-repository.js +8 -0
- package/dist/esm/permissionless/bindings/governance/governor.js +1 -1
- package/dist/esm/permissionless/bindings/index.js +5 -4
- package/dist/esm/permissionless/bindings/kill-switch-proxy.js +184 -0
- package/dist/esm/permissionless/bindings/market-configurator-factory.js +37 -0
- package/dist/esm/permissionless/bindings/market-configurator.js +143 -1
- package/dist/esm/permissionless/index.js +13 -6
- package/dist/esm/permissionless/utils/index.js +3 -3
- package/dist/esm/permissionless/utils/literals.js +2 -1
- package/dist/esm/permissionless/utils/price-update/get-prices.js +63 -1
- package/dist/esm/permissionless/utils/price-update/index.js +2 -2
- package/dist/esm/testnets/TestnetsAPI.js +178 -0
- package/dist/esm/testnets/errors/TestnetNotFoundError.js +14 -0
- package/dist/esm/testnets/errors/TestnetRequestFailedError.js +23 -0
- package/dist/esm/testnets/errors/TestnetStatusError.js +18 -0
- package/dist/esm/testnets/errors/TestnetValidationError.js +23 -0
- package/dist/esm/testnets/errors/TestnetWaitTimeoutError.js +29 -0
- package/dist/esm/testnets/errors/TestnetsError.js +33 -0
- package/dist/esm/testnets/errors/index.js +7 -0
- package/dist/esm/testnets/index.js +11 -0
- package/dist/esm/testnets/package.json +1 -0
- package/dist/esm/testnets/schemas.js +228 -0
- package/dist/esm/testnets/types.js +1 -0
- package/dist/types/abi/310/iKillSwitchProxy.d.ts +114 -0
- package/dist/types/onchain/index.d.ts +10 -1
- package/dist/types/onchain/market/adapters/abi/adapters/iTreehouseFastlaneAdapter.d.ts +101 -0
- package/dist/types/onchain/market/adapters/abi/adapters/iTreehouseRedemptionGatewayAdapter.d.ts +237 -0
- package/dist/types/onchain/market/adapters/abi/adapters/iTreehouseRouterAdapter.d.ts +146 -0
- package/dist/types/onchain/market/adapters/abi/adapters/index.d.ts +4 -1
- package/dist/types/onchain/market/adapters/abi/index.d.ts +8 -1
- package/dist/types/onchain/market/adapters/abi/treehouse/iTreehouseFastlane.d.ts +33 -0
- package/dist/types/onchain/market/adapters/abi/treehouse/iTreehouseRedemptionGateway.d.ts +207 -0
- package/dist/types/onchain/market/adapters/abi/treehouse/iTreehouseRouter.d.ts +27 -0
- package/dist/types/onchain/market/adapters/abi/treehouse/index.d.ts +4 -0
- package/dist/types/onchain/market/adapters/contracts/TreehouseFastlaneAdapterContract.d.ts +156 -0
- package/dist/types/onchain/market/adapters/contracts/TreehouseRedemptionGatewayAdapterContract.d.ts +481 -0
- package/dist/types/onchain/market/adapters/contracts/TreehouseRouterAdapterContract.d.ts +193 -0
- package/dist/types/onchain/market/adapters/contracts/index.d.ts +4 -1
- package/dist/types/onchain/market/adapters/index.d.ts +10 -1
- package/dist/types/onchain/market/index.d.ts +10 -1
- package/dist/types/permissionless/api/index.d.ts +10 -2
- package/dist/types/permissionless/api/oracles/PermissionlessOracles.d.ts +237 -47
- package/dist/types/permissionless/api/oracles/enrich.d.ts +59 -0
- package/dist/types/permissionless/api/oracles/index.d.ts +12 -2
- package/dist/types/permissionless/api/oracles/onchain-feed.d.ts +15 -0
- package/dist/types/permissionless/api/oracles/schemas.d.ts +147 -41
- package/dist/types/permissionless/api/oracles/score/formula.d.ts +36 -0
- package/dist/types/permissionless/api/oracles/score/index.d.ts +4 -0
- package/dist/types/permissionless/api/oracles/score/run.d.ts +42 -0
- package/dist/types/permissionless/api/oracles/score/types.d.ts +118 -0
- package/dist/types/permissionless/api/oracles/stress/classify.d.ts +57 -0
- package/dist/types/permissionless/api/oracles/stress/index.d.ts +6 -0
- package/dist/types/permissionless/api/oracles/stress/override.d.ts +59 -0
- package/dist/types/permissionless/api/oracles/stress/run.d.ts +100 -0
- package/dist/types/permissionless/api/oracles/stress/score.d.ts +57 -0
- package/dist/types/permissionless/api/oracles/stress/types.d.ts +272 -0
- package/dist/types/permissionless/api/oracles/types.d.ts +320 -125
- package/dist/types/permissionless/api/schemas.d.ts +0 -2
- package/dist/types/permissionless/api/transactions/lp-price-feeds.d.ts +9 -1
- package/dist/types/permissionless/bindings/bytecode-repository.d.ts +10 -1
- package/dist/types/permissionless/bindings/index.d.ts +4 -3
- package/dist/types/permissionless/bindings/kill-switch-proxy.d.ts +205 -0
- package/dist/types/permissionless/bindings/market-configurator-factory.d.ts +30 -0
- package/dist/types/permissionless/bindings/market-configurator.d.ts +30 -1
- package/dist/types/permissionless/bindings/types.d.ts +27 -0
- package/dist/types/permissionless/index.d.ts +15 -6
- package/dist/types/permissionless/utils/index.d.ts +3 -3
- package/dist/types/permissionless/utils/literals.d.ts +1 -0
- package/dist/types/permissionless/utils/price-update/get-prices.d.ts +33 -0
- package/dist/types/permissionless/utils/price-update/index.d.ts +2 -2
- package/dist/types/testnets/TestnetsAPI.d.ts +108 -0
- package/dist/types/testnets/errors/TestnetNotFoundError.d.ts +12 -0
- package/dist/types/testnets/errors/TestnetRequestFailedError.d.ts +11 -0
- package/dist/types/testnets/errors/TestnetStatusError.d.ts +15 -0
- package/dist/types/testnets/errors/TestnetValidationError.d.ts +16 -0
- package/dist/types/testnets/errors/TestnetWaitTimeoutError.d.ts +21 -0
- package/dist/types/testnets/errors/TestnetsError.d.ts +47 -0
- package/dist/types/testnets/errors/index.d.ts +7 -0
- package/dist/types/testnets/index.d.ts +11 -0
- package/dist/types/testnets/schemas.d.ts +554 -0
- package/dist/types/testnets/types.d.ts +717 -0
- package/package.json +6 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let viem = require("viem");
|
|
3
|
+
//#region src/permissionless/api/oracles/enrich.ts
|
|
4
|
+
/**
|
|
5
|
+
* What the oracles namespace works out for itself once the backend has
|
|
6
|
+
* answered.
|
|
7
|
+
*
|
|
8
|
+
* All of it used to be the backend's, and all of it needs the chain: a quota
|
|
9
|
+
* is denominated in its market's own underlying and a market cap is a supply
|
|
10
|
+
* times a price, so none of these can be indexed — they can only be read at
|
|
11
|
+
* the block the reader is on. Keeping them here means one description of each
|
|
12
|
+
* rule rather than one per service that wants it, and a backend that holds no
|
|
13
|
+
* viem client at all.
|
|
14
|
+
**/
|
|
15
|
+
/** Identifies a feed across chains, since an address alone does not. */
|
|
16
|
+
function feedKey(chainId, address) {
|
|
17
|
+
return `${chainId}:${address.toLowerCase()}`;
|
|
18
|
+
}
|
|
19
|
+
/** Prices looked up the way {@link totalQuotas} and the caps need them. */
|
|
20
|
+
function pricesByFeed(prices) {
|
|
21
|
+
return new Map(prices.map(({ chainId, address, price }) => [feedKey(chainId, address), price]));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The asset's quota across its markets, totalled in USD.
|
|
25
|
+
*
|
|
26
|
+
* Each market's figures are converted at the price that market's own oracle
|
|
27
|
+
* holds for its underlying, which is the same number that market's accounting
|
|
28
|
+
* uses.
|
|
29
|
+
*
|
|
30
|
+
* Limits count only the markets still running, because a shut down market's
|
|
31
|
+
* limit is not borrowable; what is already quoted counts everywhere, because
|
|
32
|
+
* debt outstanding is exposure either way. A market whose underlying could not
|
|
33
|
+
* be priced is skipped, which makes both figures floors, and `null` is nothing
|
|
34
|
+
* to total rather than a zero.
|
|
35
|
+
*
|
|
36
|
+
* @param priceOf - The price each underlying feed reports, in the 8 decimals
|
|
37
|
+
* every Gearbox feed uses.
|
|
38
|
+
*/
|
|
39
|
+
function totalQuotas(quotas, priceOf) {
|
|
40
|
+
let limit = 0;
|
|
41
|
+
let used = 0;
|
|
42
|
+
let anyLimit = false;
|
|
43
|
+
let anyUsed = false;
|
|
44
|
+
for (const quota of quotas) {
|
|
45
|
+
const raw = quota.underlyingPriceFeed === null ? null : priceOf(quota.underlyingPriceFeed);
|
|
46
|
+
if (raw === null || raw === void 0) continue;
|
|
47
|
+
const price = Number((0, viem.formatUnits)(raw, 8));
|
|
48
|
+
if (quota.quotaUsed !== null) {
|
|
49
|
+
used += quota.quotaUsed * price;
|
|
50
|
+
anyUsed = true;
|
|
51
|
+
}
|
|
52
|
+
if (quota.quotaLimit !== null && !quota.isShutdown) {
|
|
53
|
+
limit += quota.quotaLimit * price;
|
|
54
|
+
anyLimit = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
quotaLimitUsd: anyLimit ? limit : null,
|
|
59
|
+
quotaUsedUsd: anyUsed ? used : null
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* What one feed values one asset's supply at: `price × totalSupply`.
|
|
64
|
+
*
|
|
65
|
+
* Multiplied as integers and formatted once, rather than through two floats:
|
|
66
|
+
* an 8-decimal price times an 18-decimal supply loses its small end to a JS
|
|
67
|
+
* number long before it loses the large one, and the figure is a total rather
|
|
68
|
+
* than an estimate.
|
|
69
|
+
*
|
|
70
|
+
* `null` if either side could not be read — an asset nobody could price is
|
|
71
|
+
* not an asset worth nothing.
|
|
72
|
+
*/
|
|
73
|
+
function toCap(price, totalSupply, decimals) {
|
|
74
|
+
if (price === null || price === void 0 || totalSupply === null || totalSupply === void 0) return null;
|
|
75
|
+
return (0, viem.formatUnits)(price * totalSupply, 8 + decimals);
|
|
76
|
+
}
|
|
77
|
+
/** Larger first, with `null` after every figure including a real zero. */
|
|
78
|
+
function descending(a, b) {
|
|
79
|
+
return (b ?? -1) - (a ?? -1);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Assets ordered the way a reader scans them: what the protocol is built on
|
|
83
|
+
* first, then what is actually borrowed against it, then what it is merely
|
|
84
|
+
* allowed to be borrowed against.
|
|
85
|
+
*
|
|
86
|
+
* Applied here and not by the backend because the two middle terms are the
|
|
87
|
+
* converted quotas, which only exist once the chain has been read. The
|
|
88
|
+
* backend orders by the first term and the tie-breakers, so a caller reading
|
|
89
|
+
* the route directly still gets a stable order; this refines it.
|
|
90
|
+
*/
|
|
91
|
+
function byCentrality(a, b) {
|
|
92
|
+
return b.underlyingMarketCount - a.underlyingMarketCount || descending(a.quotaUsedUsd, b.quotaUsedUsd) || descending(a.quotaLimitUsd, b.quotaLimitUsd) || a.symbol.localeCompare(b.symbol) || a.address.localeCompare(b.address) || a.chainId - b.chainId;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.byCentrality = byCentrality;
|
|
96
|
+
exports.feedKey = feedKey;
|
|
97
|
+
exports.pricesByFeed = pricesByFeed;
|
|
98
|
+
exports.toCap = toCap;
|
|
99
|
+
exports.totalQuotas = totalQuotas;
|
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_permissionless_api_oracles_stress_classify = require("./stress/classify.js");
|
|
3
|
+
const require_permissionless_api_oracles_stress_override = require("./stress/override.js");
|
|
4
|
+
const require_permissionless_api_oracles_stress_score = require("./stress/score.js");
|
|
5
|
+
const require_permissionless_api_oracles_stress_run = require("./stress/run.js");
|
|
6
|
+
const require_permissionless_api_oracles_score_formula = require("./score/formula.js");
|
|
7
|
+
const require_permissionless_api_oracles_score_run = require("./score/run.js");
|
|
2
8
|
const require_permissionless_api_oracles_PermissionlessOracles = require("./PermissionlessOracles.js");
|
|
9
|
+
require("./score/index.js");
|
|
10
|
+
require("./stress/index.js");
|
|
3
11
|
require("./types.js");
|
|
12
|
+
exports.DEFAULT_SCENARIOS = require_permissionless_api_oracles_stress_run.DEFAULT_SCENARIOS;
|
|
4
13
|
exports.GET_PRICES_CHUNK_SIZE = require_permissionless_api_oracles_PermissionlessOracles.GET_PRICES_CHUNK_SIZE;
|
|
5
14
|
exports.GET_PRICES_GAS_LIMIT_BY_CHAIN_ID = require_permissionless_api_oracles_PermissionlessOracles.GET_PRICES_GAS_LIMIT_BY_CHAIN_ID;
|
|
6
15
|
exports.PermissionlessOracles = require_permissionless_api_oracles_PermissionlessOracles.PermissionlessOracles;
|
|
16
|
+
exports.RATE_FEED_TYPE = require_permissionless_api_oracles_stress_run.RATE_FEED_TYPE;
|
|
17
|
+
exports.SCORE_MULTIPLIER = require_permissionless_api_oracles_score_formula.SCORE_MULTIPLIER;
|
|
18
|
+
exports.UNBOUNDED_DOWN = require_permissionless_api_oracles_stress_override.UNBOUNDED_DOWN;
|
|
19
|
+
exports.UNBOUNDED_UP = require_permissionless_api_oracles_stress_override.UNBOUNDED_UP;
|
|
20
|
+
exports.classifySources = require_permissionless_api_oracles_stress_classify.classifySources;
|
|
21
|
+
exports.factorOf = require_permissionless_api_oracles_score_formula.factorOf;
|
|
22
|
+
exports.finalPrice = require_permissionless_api_oracles_score_formula.finalPrice;
|
|
23
|
+
exports.groupOverride = require_permissionless_api_oracles_stress_override.groupOverride;
|
|
24
|
+
exports.perturb = require_permissionless_api_oracles_stress_override.perturb;
|
|
25
|
+
exports.rateStub = require_permissionless_api_oracles_stress_override.rateStub;
|
|
26
|
+
exports.readFeedTrees = require_permissionless_api_oracles_stress_run.readFeedTrees;
|
|
27
|
+
exports.readForest = require_permissionless_api_oracles_stress_run.readForest;
|
|
28
|
+
exports.readRateTargets = require_permissionless_api_oracles_stress_run.readRateTargets;
|
|
29
|
+
exports.readUnder = require_permissionless_api_oracles_stress_run.readUnder;
|
|
30
|
+
exports.roundDataStub = require_permissionless_api_oracles_stress_override.roundDataStub;
|
|
31
|
+
exports.runAssetScores = require_permissionless_api_oracles_score_run.runAssetScores;
|
|
32
|
+
exports.runFeedPairScore = require_permissionless_api_oracles_score_run.runFeedPairScore;
|
|
33
|
+
exports.runStressTest = require_permissionless_api_oracles_stress_run.runStressTest;
|
|
34
|
+
exports.scoreGroup = require_permissionless_api_oracles_stress_score.scoreGroup;
|
|
35
|
+
exports.scoreOfFactor = require_permissionless_api_oracles_score_formula.scoreOfFactor;
|
|
36
|
+
exports.slotHarm = require_permissionless_api_oracles_stress_score.slotHarm;
|
|
37
|
+
exports.sourcesByFeed = require_permissionless_api_oracles_stress_classify.sourcesByFeed;
|
|
38
|
+
exports.verdictOf = require_permissionless_api_oracles_stress_score.verdictOf;
|
|
39
|
+
exports.worstOf = require_permissionless_api_oracles_score_formula.worstOf;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let viem = require("viem");
|
|
3
|
+
//#region src/permissionless/api/oracles/onchain-feed.ts
|
|
4
|
+
/**
|
|
5
|
+
* What the store would say about a feed, from what the chain says instead.
|
|
6
|
+
*
|
|
7
|
+
* Two fields are the store's alone and are answered as unknown rather than
|
|
8
|
+
* guessed: who deployed it is a store row, so it is the zero address, and the
|
|
9
|
+
* staleness period is a store setting a feed that was never added does not
|
|
10
|
+
* have, so it is 0. The compressor reports `PRICE_FEED::EXTERNAL` for a
|
|
11
|
+
* contract it cannot otherwise place; an empty type is the same thing said
|
|
12
|
+
* less clearly.
|
|
13
|
+
*/
|
|
14
|
+
function onchainPriceFeed(node) {
|
|
15
|
+
return {
|
|
16
|
+
address: (0, viem.getAddress)(node.address),
|
|
17
|
+
contractType: node.contractType.trim() || "PRICE_FEED::EXTERNAL",
|
|
18
|
+
version: node.version,
|
|
19
|
+
deployedBy: viem.zeroAddress,
|
|
20
|
+
stalenessPeriod: 0,
|
|
21
|
+
name: node.description.trim()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.onchainPriceFeed = onchainPriceFeed;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_permissionless_api_chains_schemas = require("../chains/schemas.js");
|
|
2
3
|
const require_permissionless_api_schemas = require("../schemas.js");
|
|
3
4
|
let zod_v4 = require("zod/v4");
|
|
4
5
|
//#region src/permissionless/api/oracles/schemas.ts
|
|
@@ -19,111 +20,135 @@ const priceFeedSchema = zod_v4.z.looseObject({
|
|
|
19
20
|
stalenessPeriod: zod_v4.z.number(),
|
|
20
21
|
name: zod_v4.z.string()
|
|
21
22
|
});
|
|
22
|
-
/**
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* {@link PermissionlessPriceFeedAsset}
|
|
25
|
+
*
|
|
26
|
+
* What identifies an asset, which is all a feed's own listing of one says.
|
|
27
|
+
**/
|
|
28
|
+
const priceFeedAssetSchema = zod_v4.z.looseObject({
|
|
24
29
|
address: require_permissionless_api_schemas.addressSchema,
|
|
25
30
|
symbol: zod_v4.z.string(),
|
|
26
31
|
name: zod_v4.z.string(),
|
|
27
|
-
decimals: zod_v4.z.number()
|
|
32
|
+
decimals: zod_v4.z.number()
|
|
33
|
+
});
|
|
34
|
+
/** {@link PermissionlessAsset} — identified as above, plus what prices it. */
|
|
35
|
+
const assetSchema = priceFeedAssetSchema.extend({
|
|
28
36
|
owner: require_permissionless_api_schemas.addressSchema,
|
|
29
37
|
priceFeeds: zod_v4.z.array(priceFeedSchema)
|
|
30
38
|
});
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
/**
|
|
40
|
+
* {@link PermissionlessPriceFeedStore}
|
|
41
|
+
*
|
|
42
|
+
* A store is a chain's, and is described by the same five fields the chain
|
|
43
|
+
* list answers with, so those are extended rather than restated.
|
|
44
|
+
**/
|
|
45
|
+
const priceFeedStoreSchema = require_permissionless_api_chains_schemas.chainSchema.extend({
|
|
38
46
|
assets: zod_v4.z.array(assetSchema),
|
|
39
47
|
priceFeeds: zod_v4.z.array(priceFeedSchema)
|
|
40
48
|
});
|
|
41
|
-
/** {@link
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
decimals: zod_v4.z.number()
|
|
53
|
-
});
|
|
54
|
-
/** {@link PermissionlessPriceFeedMarket} */
|
|
55
|
-
const priceFeedMarketSchema = zod_v4.z.looseObject({
|
|
49
|
+
/** Every chain's {@link PermissionlessPriceFeedStore}, one per chain. */
|
|
50
|
+
const priceFeedStoresSchema = zod_v4.z.array(priceFeedStoreSchema);
|
|
51
|
+
/**
|
|
52
|
+
* What names a market, whichever side it is being listed from.
|
|
53
|
+
*
|
|
54
|
+
* A feed's markets and an asset's markets are different reads, but they
|
|
55
|
+
* answer with the same market: who curates it, what it is denominated in and
|
|
56
|
+
* how much of the quota is taken. Only what the read is about differs, which
|
|
57
|
+
* is what each of the two below adds.
|
|
58
|
+
**/
|
|
59
|
+
const marketSchema = zod_v4.z.looseObject({
|
|
56
60
|
market: require_permissionless_api_schemas.addressSchema,
|
|
57
61
|
marketConfigurator: require_permissionless_api_schemas.addressSchema,
|
|
58
62
|
curatorName: zod_v4.z.string().nullable(),
|
|
59
63
|
marketName: zod_v4.z.string().nullable(),
|
|
60
|
-
token: require_permissionless_api_schemas.addressSchema,
|
|
61
|
-
tokenSymbol: zod_v4.z.string().nullable(),
|
|
62
64
|
underlyingSymbol: zod_v4.z.string().nullable(),
|
|
63
|
-
reserve: zod_v4.z.boolean(),
|
|
64
65
|
isUnderlying: zod_v4.z.boolean(),
|
|
65
66
|
quotaLimit: zod_v4.z.number().nullable(),
|
|
66
|
-
quotaUsed: zod_v4.z.number().nullable()
|
|
67
|
-
|
|
67
|
+
quotaUsed: zod_v4.z.number().nullable()
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* {@link PermissionlessIndexedPriceFeedMarket} — the market as the feed's slot
|
|
71
|
+
* in it, before the oracle is asked what period it holds for the slot.
|
|
72
|
+
**/
|
|
73
|
+
const priceFeedMarketSchema = marketSchema.extend({
|
|
74
|
+
token: require_permissionless_api_schemas.addressSchema,
|
|
75
|
+
tokenSymbol: zod_v4.z.string().nullable(),
|
|
76
|
+
reserve: zod_v4.z.boolean(),
|
|
77
|
+
priceOracle: require_permissionless_api_schemas.addressSchema
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* {@link PermissionlessMarketSlot} — the same slot read from the chain's end,
|
|
81
|
+
* so the feed is a column rather than what was asked for.
|
|
82
|
+
**/
|
|
83
|
+
const marketSlotSchema = priceFeedMarketSchema.extend({
|
|
84
|
+
chainId: zod_v4.z.number(),
|
|
85
|
+
underlyingToken: require_permissionless_api_schemas.addressSchema,
|
|
86
|
+
isShutdown: zod_v4.z.boolean(),
|
|
87
|
+
priceFeed: require_permissionless_api_schemas.addressSchema,
|
|
88
|
+
priceFeedName: zod_v4.z.string().nullable(),
|
|
89
|
+
priceFeedInStore: zod_v4.z.boolean(),
|
|
90
|
+
underlyingPriceFeed: require_permissionless_api_schemas.addressSchema.nullable()
|
|
68
91
|
});
|
|
69
|
-
/**
|
|
92
|
+
/** Every slot in scope, across whichever chains the read covered. */
|
|
93
|
+
const marketSlotsSchema = zod_v4.z.array(marketSlotSchema);
|
|
94
|
+
/** {@link PermissionlessIndexedPriceFeedDetails} */
|
|
70
95
|
const priceFeedDetailsSchema = zod_v4.z.looseObject({
|
|
71
96
|
chainId: zod_v4.z.number(),
|
|
72
97
|
priceFeed: priceFeedSchema,
|
|
73
98
|
assets: zod_v4.z.array(priceFeedAssetSchema),
|
|
74
99
|
markets: zod_v4.z.array(priceFeedMarketSchema)
|
|
75
100
|
});
|
|
76
|
-
/** {@link PermissionlessPriceFeedMarketCaps} */
|
|
77
|
-
const priceFeedMarketCapsSchema = zod_v4.z.looseObject({
|
|
78
|
-
marketCaps: require_permissionless_api_schemas.addressRecord(zod_v4.z.string().nullable()),
|
|
79
|
-
time: zod_v4.z.number()
|
|
80
|
-
});
|
|
81
101
|
/** {@link PermissionlessAssetMarketFeed} */
|
|
82
102
|
const assetMarketFeedSchema = zod_v4.z.looseObject({
|
|
83
103
|
address: require_permissionless_api_schemas.addressSchema,
|
|
84
104
|
name: zod_v4.z.string().nullable(),
|
|
85
105
|
inStore: zod_v4.z.boolean()
|
|
86
106
|
});
|
|
87
|
-
/** {@link PermissionlessAssetMarket} */
|
|
88
|
-
const assetMarketSchema =
|
|
89
|
-
market: require_permissionless_api_schemas.addressSchema,
|
|
90
|
-
marketConfigurator: require_permissionless_api_schemas.addressSchema,
|
|
91
|
-
curatorName: zod_v4.z.string().nullable(),
|
|
92
|
-
marketName: zod_v4.z.string().nullable(),
|
|
107
|
+
/** {@link PermissionlessAssetMarket} — the market as what prices the asset in it. */
|
|
108
|
+
const assetMarketSchema = marketSchema.extend({
|
|
93
109
|
underlyingToken: require_permissionless_api_schemas.addressSchema,
|
|
94
|
-
|
|
95
|
-
isUnderlying: zod_v4.z.boolean(),
|
|
110
|
+
underlyingPriceFeed: require_permissionless_api_schemas.addressSchema.nullable(),
|
|
96
111
|
isShutdown: zod_v4.z.boolean(),
|
|
97
112
|
mainFeed: assetMarketFeedSchema.nullable(),
|
|
98
|
-
reserveFeed: assetMarketFeedSchema.nullable()
|
|
99
|
-
quotaLimit: zod_v4.z.number().nullable(),
|
|
100
|
-
quotaUsed: zod_v4.z.number().nullable()
|
|
113
|
+
reserveFeed: assetMarketFeedSchema.nullable()
|
|
101
114
|
});
|
|
102
|
-
/** {@link
|
|
115
|
+
/** {@link PermissionlessIndexedAssetDetails} */
|
|
103
116
|
const assetDetailsSchema = zod_v4.z.looseObject({
|
|
104
117
|
chainId: zod_v4.z.number(),
|
|
105
118
|
asset: priceFeedAssetSchema,
|
|
106
119
|
priceFeeds: zod_v4.z.array(priceFeedSchema),
|
|
107
|
-
markets: zod_v4.z.array(assetMarketSchema)
|
|
108
|
-
quotaLimitUsd: zod_v4.z.number().nullable(),
|
|
109
|
-
quotaUsedUsd: zod_v4.z.number().nullable()
|
|
120
|
+
markets: zod_v4.z.array(assetMarketSchema)
|
|
110
121
|
});
|
|
111
|
-
/** {@link
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
/** {@link PermissionlessAssetQuota} */
|
|
123
|
+
const assetQuotaSchema = zod_v4.z.looseObject({
|
|
124
|
+
quotaLimit: zod_v4.z.number().nullable(),
|
|
125
|
+
quotaUsed: zod_v4.z.number().nullable(),
|
|
126
|
+
isShutdown: zod_v4.z.boolean(),
|
|
127
|
+
underlyingPriceFeed: require_permissionless_api_schemas.addressSchema.nullable()
|
|
128
|
+
});
|
|
129
|
+
/** {@link PermissionlessIndexedAssetSummary} */
|
|
130
|
+
const assetSummarySchema = zod_v4.z.looseObject({
|
|
131
|
+
chainId: zod_v4.z.number(),
|
|
132
|
+
address: require_permissionless_api_schemas.addressSchema,
|
|
133
|
+
symbol: zod_v4.z.string(),
|
|
134
|
+
underlyingMarketCount: zod_v4.z.number(),
|
|
135
|
+
marketQuotas: zod_v4.z.array(assetQuotaSchema)
|
|
116
136
|
});
|
|
137
|
+
/** The list of {@link PermissionlessAssetSummary}, already ordered. */
|
|
138
|
+
const assetSummariesSchema = zod_v4.z.array(assetSummarySchema);
|
|
117
139
|
//#endregion
|
|
118
140
|
exports.assetDetailsSchema = assetDetailsSchema;
|
|
119
141
|
exports.assetMarketFeedSchema = assetMarketFeedSchema;
|
|
120
142
|
exports.assetMarketSchema = assetMarketSchema;
|
|
121
|
-
exports.
|
|
143
|
+
exports.assetQuotaSchema = assetQuotaSchema;
|
|
122
144
|
exports.assetSchema = assetSchema;
|
|
145
|
+
exports.assetSummariesSchema = assetSummariesSchema;
|
|
146
|
+
exports.assetSummarySchema = assetSummarySchema;
|
|
147
|
+
exports.marketSlotSchema = marketSlotSchema;
|
|
148
|
+
exports.marketSlotsSchema = marketSlotsSchema;
|
|
123
149
|
exports.priceFeedAssetSchema = priceFeedAssetSchema;
|
|
124
150
|
exports.priceFeedDetailsSchema = priceFeedDetailsSchema;
|
|
125
|
-
exports.priceFeedMarketCapsSchema = priceFeedMarketCapsSchema;
|
|
126
151
|
exports.priceFeedMarketSchema = priceFeedMarketSchema;
|
|
127
152
|
exports.priceFeedSchema = priceFeedSchema;
|
|
128
153
|
exports.priceFeedStoreSchema = priceFeedStoreSchema;
|
|
129
|
-
exports.
|
|
154
|
+
exports.priceFeedStoresSchema = priceFeedStoresSchema;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/permissionless/api/oracles/score/formula.ts
|
|
3
|
+
/** What every source of a group is made to answer, as a multiple of now. */
|
|
4
|
+
const SCORE_MULTIPLIER = 10;
|
|
5
|
+
/**
|
|
6
|
+
* How far the final price moved, as a multiple of where it was, either way:
|
|
7
|
+
* 1 for a price that did not move, 1.04 for one 4% off, and
|
|
8
|
+
* {@link SCORE_MULTIPLIER} for one that took the whole lie — the most it can
|
|
9
|
+
* take from one leg, and where a price over two legs of one group, moved
|
|
10
|
+
* further, is held too.
|
|
11
|
+
*
|
|
12
|
+
* `null` for a price that stopped answering, which is not a move.
|
|
13
|
+
*/
|
|
14
|
+
function scoreOfFactor(factor) {
|
|
15
|
+
if (factor === null || !Number.isFinite(factor) || factor <= 0) return null;
|
|
16
|
+
const move = factor >= 1 ? factor : 1 / factor;
|
|
17
|
+
return Math.min(10, move);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The price a market settles on: the lower of main and reserve, or the main
|
|
21
|
+
* feed's alone where there is no reserve to compare it with. `null` where a
|
|
22
|
+
* feed it needs does not answer.
|
|
23
|
+
*/
|
|
24
|
+
function finalPrice(main, reserve) {
|
|
25
|
+
if (main === null || reserve === null) return null;
|
|
26
|
+
if (reserve === void 0) return main;
|
|
27
|
+
return main < reserve ? main : reserve;
|
|
28
|
+
}
|
|
29
|
+
/** `stressed / base` as a float, `null` where the stressed price is gone. */
|
|
30
|
+
function factorOf(base, stressed) {
|
|
31
|
+
if (stressed === null) return null;
|
|
32
|
+
return Number(stressed) / Number(base);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The market's score and the group it comes from: the furthest any group
|
|
36
|
+
* moved its price. 1 where nothing moved it — no group did, or no source
|
|
37
|
+
* feeds the price at all.
|
|
38
|
+
*
|
|
39
|
+
* A group under which the price stops answering moves nothing and does not
|
|
40
|
+
* set the score; it is listed after those that do, for a reader to see.
|
|
41
|
+
*/
|
|
42
|
+
function worstOf(impacts) {
|
|
43
|
+
const sorted = [...impacts].sort((a, b) => (b.score ?? 0) - (a.score ?? 0));
|
|
44
|
+
const worst = sorted.find((impact) => impact.score !== null) ?? null;
|
|
45
|
+
return {
|
|
46
|
+
score: worst?.score ?? 1,
|
|
47
|
+
impacts: sorted,
|
|
48
|
+
worst
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.SCORE_MULTIPLIER = SCORE_MULTIPLIER;
|
|
53
|
+
exports.factorOf = factorOf;
|
|
54
|
+
exports.finalPrice = finalPrice;
|
|
55
|
+
exports.scoreOfFactor = scoreOfFactor;
|
|
56
|
+
exports.worstOf = worstOf;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_permissionless_api_oracles_score_formula = require("./formula.js");
|
|
3
|
+
const require_permissionless_api_oracles_score_run = require("./run.js");
|
|
4
|
+
require("./types.js");
|
|
5
|
+
exports.SCORE_MULTIPLIER = require_permissionless_api_oracles_score_formula.SCORE_MULTIPLIER;
|
|
6
|
+
exports.factorOf = require_permissionless_api_oracles_score_formula.factorOf;
|
|
7
|
+
exports.finalPrice = require_permissionless_api_oracles_score_formula.finalPrice;
|
|
8
|
+
exports.runAssetScores = require_permissionless_api_oracles_score_run.runAssetScores;
|
|
9
|
+
exports.runFeedPairScore = require_permissionless_api_oracles_score_run.runFeedPairScore;
|
|
10
|
+
exports.scoreOfFactor = require_permissionless_api_oracles_score_formula.scoreOfFactor;
|
|
11
|
+
exports.worstOf = require_permissionless_api_oracles_score_formula.worstOf;
|