@waterx/sdk 4.3.3 → 5.0.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/.claude/skills/waterx-sdk-integration/SKILL.md +41 -35
- package/README.md +81 -77
- package/dist/cjs/src/account/config.d.ts +3 -5
- package/dist/cjs/src/account/funding/wormhole.d.ts +1 -2
- package/dist/cjs/src/account/funding/wormhole.js +1 -2
- package/dist/cjs/src/oracle/aggregate.d.ts +45 -61
- package/dist/cjs/src/oracle/aggregate.js +138 -138
- package/dist/cjs/src/oracle/config.d.ts +35 -49
- package/dist/cjs/src/oracle/config.js +1 -1
- package/dist/cjs/src/oracle/host.d.ts +14 -19
- package/dist/cjs/src/oracle/host.js +3 -3
- package/dist/cjs/src/oracle/index.d.ts +25 -16
- package/dist/cjs/src/oracle/index.js +79 -66
- package/dist/cjs/src/oracle/price-update-rule.d.ts +104 -66
- package/dist/cjs/src/oracle/price-update-rule.js +24 -16
- package/dist/cjs/src/oracle/pyth-pro-history.d.ts +36 -0
- package/dist/cjs/src/oracle/pyth-pro-history.js +41 -0
- package/dist/cjs/src/oracle/read-plane.d.ts +35 -53
- package/dist/cjs/src/oracle/read-plane.js +26 -48
- package/dist/cjs/src/oracle/read-prices.d.ts +105 -0
- package/dist/cjs/src/oracle/read-prices.js +162 -0
- package/dist/cjs/src/oracle/rule-registry.d.ts +12 -12
- package/dist/cjs/src/oracle/rule-registry.js +12 -14
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.d.ts +24 -3
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.js +40 -20
- package/dist/cjs/src/oracle/rules/waterx-rule.d.ts +137 -12
- package/dist/cjs/src/oracle/rules/waterx-rule.js +318 -55
- package/dist/cjs/src/oracle/schedule.d.ts +109 -0
- package/dist/cjs/src/oracle/schedule.js +991 -0
- package/dist/cjs/src/oracle/source-list.d.ts +31 -27
- package/dist/cjs/src/oracle/source-list.js +43 -45
- package/dist/cjs/src/oracle/symbol-catalog.d.ts +54 -0
- package/dist/cjs/src/oracle/symbol-catalog.js +69 -0
- package/dist/cjs/src/oracle/update-fetch.d.ts +11 -15
- package/dist/cjs/src/oracle/update-fetch.js +12 -19
- package/dist/cjs/src/oracle/validate.d.ts +105 -0
- package/dist/cjs/src/oracle/validate.js +185 -0
- package/dist/cjs/src/oracle/weight-coverage.d.ts +79 -0
- package/dist/cjs/src/oracle/weight-coverage.js +173 -0
- package/dist/cjs/src/perp/client.d.ts +35 -52
- package/dist/cjs/src/perp/client.js +44 -17
- package/dist/cjs/src/perp/config-view.d.ts +5 -14
- package/dist/cjs/src/perp/config-view.js +5 -16
- package/dist/cjs/src/perp/config.d.ts +3 -3
- package/dist/cjs/src/perp/config.js +11 -13
- package/dist/cjs/src/perp/index.d.ts +4 -6
- package/dist/cjs/src/perp/index.js +35 -18
- package/dist/cjs/src/perp/tx-builders/common.d.ts +86 -48
- package/dist/cjs/src/perp/tx-builders/common.js +115 -47
- package/dist/cjs/src/perp/tx-builders/wlp.d.ts +3 -14
- package/dist/cjs/src/perp/tx-builders/wlp.js +6 -35
- package/dist/cjs/src/perp/tx-builders.d.ts +6 -5
- package/dist/cjs/src/perp/tx-builders.js +16 -10
- package/dist/cjs/src/unified-client.d.ts +8 -34
- package/dist/cjs/src/unified-client.js +3 -4
- package/dist/cjs/src/utils/config.d.ts +0 -8
- package/dist/cjs/src/utils/config.js +5 -13
- package/dist/src/account/config.d.ts +3 -5
- package/dist/src/account/funding/wormhole.d.ts +1 -2
- package/dist/src/account/funding/wormhole.js +1 -2
- package/dist/src/oracle/aggregate.d.ts +45 -61
- package/dist/src/oracle/aggregate.js +138 -137
- package/dist/src/oracle/config.d.ts +35 -49
- package/dist/src/oracle/config.js +1 -1
- package/dist/src/oracle/host.d.ts +14 -19
- package/dist/src/oracle/host.js +3 -3
- package/dist/src/oracle/index.d.ts +25 -16
- package/dist/src/oracle/index.js +55 -50
- package/dist/src/oracle/price-update-rule.d.ts +104 -66
- package/dist/src/oracle/price-update-rule.js +23 -16
- package/dist/src/oracle/pyth-pro-history.d.ts +36 -0
- package/dist/src/oracle/pyth-pro-history.js +38 -0
- package/dist/src/oracle/read-plane.d.ts +35 -53
- package/dist/src/oracle/read-plane.js +25 -47
- package/dist/src/oracle/read-prices.d.ts +105 -0
- package/dist/src/oracle/read-prices.js +156 -0
- package/dist/src/oracle/rule-registry.d.ts +12 -12
- package/dist/src/oracle/rule-registry.js +12 -14
- package/dist/src/oracle/rules/pyth-lazer-rule.d.ts +24 -3
- package/dist/src/oracle/rules/pyth-lazer-rule.js +39 -20
- package/dist/src/oracle/rules/waterx-rule.d.ts +137 -12
- package/dist/src/oracle/rules/waterx-rule.js +314 -56
- package/dist/src/oracle/schedule.d.ts +109 -0
- package/dist/src/oracle/schedule.js +985 -0
- package/dist/src/oracle/source-list.d.ts +31 -27
- package/dist/src/oracle/source-list.js +42 -43
- package/dist/src/oracle/symbol-catalog.d.ts +54 -0
- package/dist/src/oracle/symbol-catalog.js +65 -0
- package/dist/src/oracle/update-fetch.d.ts +11 -15
- package/dist/src/oracle/update-fetch.js +12 -18
- package/dist/src/oracle/validate.d.ts +105 -0
- package/dist/src/oracle/validate.js +177 -0
- package/dist/src/oracle/weight-coverage.d.ts +79 -0
- package/dist/src/oracle/weight-coverage.js +166 -0
- package/dist/src/perp/client.d.ts +35 -52
- package/dist/src/perp/client.js +45 -18
- package/dist/src/perp/config-view.d.ts +5 -14
- package/dist/src/perp/config-view.js +5 -16
- package/dist/src/perp/config.d.ts +3 -3
- package/dist/src/perp/config.js +11 -13
- package/dist/src/perp/index.d.ts +4 -6
- package/dist/src/perp/index.js +11 -5
- package/dist/src/perp/tx-builders/common.d.ts +86 -48
- package/dist/src/perp/tx-builders/common.js +114 -48
- package/dist/src/perp/tx-builders/wlp.d.ts +3 -14
- package/dist/src/perp/tx-builders/wlp.js +6 -35
- package/dist/src/perp/tx-builders.d.ts +6 -5
- package/dist/src/perp/tx-builders.js +15 -6
- package/dist/src/unified-client.d.ts +8 -34
- package/dist/src/unified-client.js +3 -4
- package/dist/src/utils/config.d.ts +0 -8
- package/dist/src/utils/config.js +5 -12
- package/package.json +1 -1
- package/dist/cjs/src/generated/pyth_sponsor_rule/deps/sui/balance.d.ts +0 -12
- package/dist/cjs/src/generated/pyth_sponsor_rule/deps/sui/balance.js +0 -17
- package/dist/cjs/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +0 -68
- package/dist/cjs/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +0 -113
- package/dist/cjs/src/generated/waterx_pyth_rule/deps/sui/vec_map.d.ts +0 -36
- package/dist/cjs/src/generated/waterx_pyth_rule/deps/sui/vec_map.js +0 -31
- package/dist/cjs/src/generated/waterx_pyth_rule/pyth_rule.d.ts +0 -192
- package/dist/cjs/src/generated/waterx_pyth_rule/pyth_rule.js +0 -214
- package/dist/cjs/src/oracle/pyth.d.ts +0 -227
- package/dist/cjs/src/oracle/pyth.js +0 -652
- package/dist/cjs/src/oracle/rules/pyth-core-rule.d.ts +0 -15
- package/dist/cjs/src/oracle/rules/pyth-core-rule.js +0 -100
- package/dist/cjs/src/oracle/rules/pyth-rule.d.ts +0 -11
- package/dist/cjs/src/oracle/rules/pyth-rule.js +0 -29
- package/dist/cjs/src/oracle/rules/sponsor.d.ts +0 -32
- package/dist/cjs/src/oracle/rules/sponsor.js +0 -56
- package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.d.ts +0 -12
- package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.js +0 -14
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +0 -68
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +0 -73
- package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.js +0 -27
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +0 -192
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +0 -170
- package/dist/src/oracle/pyth.d.ts +0 -227
- package/dist/src/oracle/pyth.js +0 -638
- package/dist/src/oracle/rules/pyth-core-rule.d.ts +0 -15
- package/dist/src/oracle/rules/pyth-core-rule.js +0 -97
- package/dist/src/oracle/rules/pyth-rule.d.ts +0 -11
- package/dist/src/oracle/rules/pyth-rule.js +0 -26
- package/dist/src/oracle/rules/sponsor.d.ts +0 -32
- package/dist/src/oracle/rules/sponsor.js +0 -52
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `PythCoreRule` — `PriceUpdateRule` wrapper around the existing Pyth Core
|
|
3
|
-
* (Hermes VAA) source in `../pyth.ts`. Delegates to `fetchPriceFeedsUpdateData`
|
|
4
|
-
* / `buildPythPriceUpdateCalls` verbatim; this file only adapts them to the
|
|
5
|
-
* `PriceUpdateRule` port shape (fetch → build) so a future router can select
|
|
6
|
-
* across rules by `kind`. Mechanical wrap only — no on-chain/off-chain logic
|
|
7
|
-
* changes vs `../pyth.ts` / `./pyth-rule.ts`.
|
|
8
|
-
*/
|
|
9
|
-
import { ownEntry } from "../../utils/record.js";
|
|
10
|
-
import { assertRuleUpdateData, } from "../price-update-rule.js";
|
|
11
|
-
import { buildPythPriceUpdateCalls, endpointSupportedFeedIds, fetchPriceFeedsUpdateData, pythCoreHermesEndpoint, } from "../pyth.js";
|
|
12
|
-
/**
|
|
13
|
-
* Shape check ONLY — the `kind` discriminant is checked separately by the
|
|
14
|
-
* caller before this runs, since a same-shaped payload from a different rule
|
|
15
|
-
* (e.g. a hypothetical Lazer payload also carrying `updates`/`feedIds`) must
|
|
16
|
-
* not silently pass as a Pyth Core VAA block.
|
|
17
|
-
*/
|
|
18
|
-
function isPythCoreUpdatePayloadShape(payload) {
|
|
19
|
-
return (typeof payload === "object" &&
|
|
20
|
-
payload !== null &&
|
|
21
|
-
Array.isArray(payload.updates) &&
|
|
22
|
-
Array.isArray(payload.feedIds));
|
|
23
|
-
}
|
|
24
|
-
export const PythCoreRule = {
|
|
25
|
-
kind: "pyth_rule",
|
|
26
|
-
// Charges a per-feed `base_update_fee` via `pyth::update_single_price_feed` —
|
|
27
|
-
// see `PriceUpdateRule.requiresFeeSource`.
|
|
28
|
-
requiresFeeSource: true,
|
|
29
|
-
/** Tickers with a `pyth_rule.feeds` entry (mirrors `refreshOraclePrices`'s filter). */
|
|
30
|
-
supportedTickers(host) {
|
|
31
|
-
return Object.keys(host.config.packages.pyth_rule?.feeds ?? {});
|
|
32
|
-
},
|
|
33
|
-
/** Resolves feed ids for `tickers`, then fetches their Hermes accumulator update. */
|
|
34
|
-
async fetchUpdateData(host, tickers) {
|
|
35
|
-
if (tickers.length === 0)
|
|
36
|
-
return null;
|
|
37
|
-
// Endpoint is this source's own per-network infra (`PYTH_CORE_INFRA`);
|
|
38
|
-
// credential + retry/timeout policy are the caller-supplied `client.pyth`
|
|
39
|
-
// access slice.
|
|
40
|
-
const endpoint = pythCoreHermesEndpoint(host.network);
|
|
41
|
-
const feedIds = tickers.map((ticker) => host.getPythFeed(ticker).feed_id);
|
|
42
|
-
const updates = await fetchPriceFeedsUpdateData(endpoint, feedIds, {
|
|
43
|
-
apiKey: host.pyth.api_key,
|
|
44
|
-
fetch: host.pyth.fetch,
|
|
45
|
-
});
|
|
46
|
-
// `updates` covers only the feeds this endpoint actually served — the fetch
|
|
47
|
-
// drops (and memoizes) any it lacks, e.g. Core feeds absent from Pyth Pro
|
|
48
|
-
// (WTIUSD/BRENTUSD). Align `feedIds` with them: buildPythPriceUpdateCalls
|
|
49
|
-
// emits one moveCall per feedId and must not reference a feed the
|
|
50
|
-
// accumulator blob doesn't cover.
|
|
51
|
-
return {
|
|
52
|
-
kind: "pyth_rule",
|
|
53
|
-
payload: {
|
|
54
|
-
updates,
|
|
55
|
-
feedIds: endpointSupportedFeedIds(endpoint, feedIds, host.pyth.api_key),
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Subsets a (typically whole-universe) payload from {@link fetchUpdateData}
|
|
61
|
-
* down to exactly `tickers`. Pyth Core charges a per-feed update fee (one
|
|
62
|
-
* `update_single_price_feed` moveCall per `feedIds` entry — see
|
|
63
|
-
* `buildPythPriceUpdateCalls`), so serving a full all-registry payload for a
|
|
64
|
-
* 2-ticker build would multiply both the fee and the PTB size ~N× — a
|
|
65
|
-
* per-feed subset is valid input by construction. Narrows `feedIds` only:
|
|
66
|
-
* the single combined Hermes accumulator blob in `updates` already covers
|
|
67
|
-
* every packed feed and needs no re-slicing. A ticker with no
|
|
68
|
-
* `pyth_rule.feeds` entry, or whose feed id is not packed in THIS payload's
|
|
69
|
-
* `feedIds`, is a coverage gap → `null` (miss), never a silent partial.
|
|
70
|
-
*/
|
|
71
|
-
narrowUpdateData(host, data, tickers) {
|
|
72
|
-
const payload = assertRuleUpdateData(data, "pyth_rule", isPythCoreUpdatePayloadShape, "{ updates: Uint8Array[]; feedIds: string[] }");
|
|
73
|
-
if (!payload || tickers.length === 0)
|
|
74
|
-
return null;
|
|
75
|
-
const packedFeedIds = new Set(payload.feedIds);
|
|
76
|
-
const feedIds = [];
|
|
77
|
-
for (const ticker of tickers) {
|
|
78
|
-
// Same lookup as `host.getPythFeed(ticker)` minus its throw — an
|
|
79
|
-
// unlisted ticker is a miss here, not an error.
|
|
80
|
-
const feedId = ownEntry(host.config.packages.pyth_rule?.feeds, ticker)?.feed_id;
|
|
81
|
-
if (feedId === undefined || !packedFeedIds.has(feedId))
|
|
82
|
-
return null;
|
|
83
|
-
feedIds.push(feedId);
|
|
84
|
-
}
|
|
85
|
-
return { kind: "pyth_rule", payload: { updates: payload.updates, feedIds } };
|
|
86
|
-
},
|
|
87
|
-
/** Appends the wormhole/pyth update PTB block for the payload from {@link fetchUpdateData}. */
|
|
88
|
-
async buildUpdateCalls(tx, host, data, opts) {
|
|
89
|
-
const payload = assertRuleUpdateData(data, "pyth_rule", isPythCoreUpdatePayloadShape, "{ updates: Uint8Array[]; feedIds: string[] }");
|
|
90
|
-
if (!payload)
|
|
91
|
-
return;
|
|
92
|
-
await buildPythPriceUpdateCalls(tx, host, payload.updates, payload.feedIds, {
|
|
93
|
-
cache: opts?.cache,
|
|
94
|
-
feeSource: opts?.feeSource,
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `pyth_rule::feed` — feed a refreshed Pyth `PriceInfoObject` into an oracle
|
|
3
|
-
* `PriceCollector`. The rule resolves the on-chain feed by ticker via its
|
|
4
|
-
* `Config.identifier_map`, so it is not typed `<T>`.
|
|
5
|
-
*
|
|
6
|
-
* Caller must run the Pyth on-chain update first (see `../pyth.ts`) so the
|
|
7
|
-
* `PriceInfoObject` is fresh.
|
|
8
|
-
*/
|
|
9
|
-
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
10
|
-
import type { OracleHost } from "../host.ts";
|
|
11
|
-
export declare function feedPythRule(tx: Transaction, host: OracleHost, collector: TransactionArgument, priceInfoObjectId: string): void;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `pyth_rule::feed` — feed a refreshed Pyth `PriceInfoObject` into an oracle
|
|
3
|
-
* `PriceCollector`. The rule resolves the on-chain feed by ticker via its
|
|
4
|
-
* `Config.identifier_map`, so it is not typed `<T>`.
|
|
5
|
-
*
|
|
6
|
-
* Caller must run the Pyth on-chain update first (see `../pyth.ts`) so the
|
|
7
|
-
* `PriceInfoObject` is fresh.
|
|
8
|
-
*/
|
|
9
|
-
import { feed as pythRuleFeed } from "../../generated/waterx_pyth_rule/pyth_rule.js";
|
|
10
|
-
import { PYTH_CORE_INFRA } from "../pyth.js";
|
|
11
|
-
export function feedPythRule(tx, host, collector, priceInfoObjectId) {
|
|
12
|
-
pythRuleFeed({
|
|
13
|
-
package: host.config.packages.pyth_rule.published_at,
|
|
14
|
-
arguments: {
|
|
15
|
-
collector,
|
|
16
|
-
config: tx.object(host.config.packages.pyth_rule.config),
|
|
17
|
-
// The deployed pyth_rule package is compiled against the Core pyth
|
|
18
|
-
// dependency, so its `&PythState` parameter is the Core-package-qualified
|
|
19
|
-
// type and the Core source's own per-network state (`PYTH_CORE_INFRA`)
|
|
20
|
-
// is always the right state to pass. The config's price_info_object
|
|
21
|
-
// entries are Core objects to match.
|
|
22
|
-
pythState: tx.object(PYTH_CORE_INFRA[host.network].state_id),
|
|
23
|
-
pythPriceInfo: tx.object(priceInfoObjectId),
|
|
24
|
-
},
|
|
25
|
-
})(tx);
|
|
26
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `pyth_sponsor_rule` — pay Pyth update fees from a shared sponsor pool AND
|
|
3
|
-
* attach the `PythSponsorRule` witness to a `TradingRequest`. Required when the
|
|
4
|
-
* market's `request_checklist` contains `PythSponsorRule`.
|
|
5
|
-
*
|
|
6
|
-
* Flow: {@link openPythSponsorFund} opens a `Fund` hot potato; the caller wraps
|
|
7
|
-
* the returned `{ fund, packageId }` into an `OracleFeeSource` (`{ kind:
|
|
8
|
-
* 'sponsor', fund, packageId }`) and passes that to the Pyth update path (it
|
|
9
|
-
* draws per-feed fees via `pyth_sponsor_rule::split`); then
|
|
10
|
-
* {@link reimbursePythSponsor} consumes the `Fund`, returns leftover SUI, and
|
|
11
|
-
* attaches the witness.
|
|
12
|
-
*/
|
|
13
|
-
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
14
|
-
import type { OracleHost } from "../host.ts";
|
|
15
|
-
/**
|
|
16
|
-
* Opens a `Fund` hot potato from the shared PythSponsor pool. Wrap the
|
|
17
|
-
* returned `{ fund, packageId }` into an `OracleFeeSource`
|
|
18
|
-
* (`{ kind: 'sponsor', fund, packageId }`) and pass that to
|
|
19
|
-
* `refreshOraclePrices` as `feeSource`, then {@link reimbursePythSponsor} once
|
|
20
|
-
* the TradingRequest is built.
|
|
21
|
-
*/
|
|
22
|
-
export declare function openPythSponsorFund(tx: Transaction, host: OracleHost): {
|
|
23
|
-
fund: TransactionArgument;
|
|
24
|
-
packageId: string;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Consumes the `Fund` hot potato from {@link openPythSponsorFund}, returns any
|
|
28
|
-
* leftover SUI to the sponsor pool, and attaches the `PythSponsorRule` witness to
|
|
29
|
-
* the given `TradingRequest<C_TOKEN>` so `trading::execute` can satisfy a
|
|
30
|
-
* checklist that includes `PythSponsorRule`.
|
|
31
|
-
*/
|
|
32
|
-
export declare function reimbursePythSponsor(tx: Transaction, host: OracleHost, fund: TransactionArgument, tradingRequest: TransactionArgument, collateralType: string): void;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `pyth_sponsor_rule` — pay Pyth update fees from a shared sponsor pool AND
|
|
3
|
-
* attach the `PythSponsorRule` witness to a `TradingRequest`. Required when the
|
|
4
|
-
* market's `request_checklist` contains `PythSponsorRule`.
|
|
5
|
-
*
|
|
6
|
-
* Flow: {@link openPythSponsorFund} opens a `Fund` hot potato; the caller wraps
|
|
7
|
-
* the returned `{ fund, packageId }` into an `OracleFeeSource` (`{ kind:
|
|
8
|
-
* 'sponsor', fund, packageId }`) and passes that to the Pyth update path (it
|
|
9
|
-
* draws per-feed fees via `pyth_sponsor_rule::split`); then
|
|
10
|
-
* {@link reimbursePythSponsor} consumes the `Fund`, returns leftover SUI, and
|
|
11
|
-
* attaches the witness.
|
|
12
|
-
*/
|
|
13
|
-
import { reimburse as sponsorReimburse, request as sponsorRequest, } from "../../generated/pyth_sponsor_rule/pyth_sponsor_rule.js";
|
|
14
|
-
/**
|
|
15
|
-
* Opens a `Fund` hot potato from the shared PythSponsor pool. Wrap the
|
|
16
|
-
* returned `{ fund, packageId }` into an `OracleFeeSource`
|
|
17
|
-
* (`{ kind: 'sponsor', fund, packageId }`) and pass that to
|
|
18
|
-
* `refreshOraclePrices` as `feeSource`, then {@link reimbursePythSponsor} once
|
|
19
|
-
* the TradingRequest is built.
|
|
20
|
-
*/
|
|
21
|
-
export function openPythSponsorFund(tx, host) {
|
|
22
|
-
const entry = host.config.packages.pyth_sponsor_rule;
|
|
23
|
-
if (!entry?.published_at || !entry.pyth_sponsor) {
|
|
24
|
-
throw new Error("pyth_sponsor_rule.{published_at,pyth_sponsor} missing — sponsor flow unavailable");
|
|
25
|
-
}
|
|
26
|
-
const [fund] = sponsorRequest({
|
|
27
|
-
package: entry.published_at,
|
|
28
|
-
arguments: { self: tx.object(entry.pyth_sponsor) },
|
|
29
|
-
})(tx);
|
|
30
|
-
return { fund: fund, packageId: entry.published_at };
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Consumes the `Fund` hot potato from {@link openPythSponsorFund}, returns any
|
|
34
|
-
* leftover SUI to the sponsor pool, and attaches the `PythSponsorRule` witness to
|
|
35
|
-
* the given `TradingRequest<C_TOKEN>` so `trading::execute` can satisfy a
|
|
36
|
-
* checklist that includes `PythSponsorRule`.
|
|
37
|
-
*/
|
|
38
|
-
export function reimbursePythSponsor(tx, host, fund, tradingRequest, collateralType) {
|
|
39
|
-
const entry = host.config.packages.pyth_sponsor_rule;
|
|
40
|
-
if (!entry?.published_at || !entry.pyth_sponsor) {
|
|
41
|
-
throw new Error("pyth_sponsor_rule missing from config");
|
|
42
|
-
}
|
|
43
|
-
sponsorReimburse({
|
|
44
|
-
package: entry.published_at,
|
|
45
|
-
arguments: {
|
|
46
|
-
self: tx.object(entry.pyth_sponsor),
|
|
47
|
-
fund: fund,
|
|
48
|
-
tradingReq: tradingRequest,
|
|
49
|
-
},
|
|
50
|
-
typeArguments: [collateralType],
|
|
51
|
-
})(tx);
|
|
52
|
-
}
|