@parchment-trade/sdk 0.0.0-stage → 1.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/LICENSE +202 -0
- package/README.md +192 -2
- package/REFERENCE.md +338 -0
- package/SECURITY.md +23 -0
- package/dist/general/providers/index.d.ts +2 -0
- package/dist/general/providers/index.js +2 -0
- package/dist/general/providers/parchment.d.ts +1 -0
- package/dist/general/providers/parchment.js +1 -0
- package/dist/general/providers/parchmentSdk.d.ts +23 -0
- package/dist/general/providers/parchmentSdk.js +11 -0
- package/dist/general/types/configTypes.d.ts +62 -0
- package/dist/general/types/configTypes.js +1 -0
- package/dist/general/types/index.d.ts +1 -0
- package/dist/general/types/index.js +1 -0
- package/dist/general/utils/address.d.ts +49 -0
- package/dist/general/utils/address.js +110 -0
- package/dist/general/utils/caller.d.ts +58 -0
- package/dist/general/utils/caller.js +182 -0
- package/dist/general/utils/errors.d.ts +16 -0
- package/dist/general/utils/errors.js +26 -0
- package/dist/general/utils/index.d.ts +4 -0
- package/dist/general/utils/index.js +4 -0
- package/dist/general/utils/jsBigInt.d.ts +26 -0
- package/dist/general/utils/jsBigInt.js +74 -0
- package/dist/general/utils/txShape.d.ts +8 -0
- package/dist/general/utils/txShape.js +39 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/packages/index.d.ts +11 -0
- package/dist/packages/index.js +5 -0
- package/dist/packages/parchment/abortCodes.d.ts +196 -0
- package/dist/packages/parchment/abortCodes.js +522 -0
- package/dist/packages/parchment/batchClose.d.ts +268 -0
- package/dist/packages/parchment/batchClose.js +524 -0
- package/dist/packages/parchment/eventGuard.d.ts +106 -0
- package/dist/packages/parchment/eventGuard.js +119 -0
- package/dist/packages/parchment/gameCounterEvents.d.ts +59 -0
- package/dist/packages/parchment/gameCounterEvents.js +56 -0
- package/dist/packages/parchment/index.d.ts +52 -0
- package/dist/packages/parchment/index.js +30 -0
- package/dist/packages/parchment/liquidationCredit.d.ts +28 -0
- package/dist/packages/parchment/liquidationCredit.js +25 -0
- package/dist/packages/parchment/lockedMintEvents.d.ts +42 -0
- package/dist/packages/parchment/lockedMintEvents.js +46 -0
- package/dist/packages/parchment/monitoring.d.ts +369 -0
- package/dist/packages/parchment/monitoring.js +259 -0
- package/dist/packages/parchment/notes.d.ts +6 -0
- package/dist/packages/parchment/notes.js +1 -0
- package/dist/packages/parchment/onboarding.d.ts +50 -0
- package/dist/packages/parchment/onboarding.js +48 -0
- package/dist/packages/parchment/orderEffects.d.ts +207 -0
- package/dist/packages/parchment/orderEffects.js +268 -0
- package/dist/packages/parchment/orderParams.d.ts +72 -0
- package/dist/packages/parchment/orderParams.js +71 -0
- package/dist/packages/parchment/packageIds.d.ts +53 -0
- package/dist/packages/parchment/packageIds.js +149 -0
- package/dist/packages/parchment/parchment.d.ts +442 -0
- package/dist/packages/parchment/parchment.js +975 -0
- package/dist/packages/parchment/parchmentAccount.d.ts +189 -0
- package/dist/packages/parchment/parchmentAccount.js +273 -0
- package/dist/packages/parchment/parchmentMarket.d.ts +58 -0
- package/dist/packages/parchment/parchmentMarket.js +86 -0
- package/dist/packages/parchment/parchmentTypes.d.ts +2031 -0
- package/dist/packages/parchment/parchmentTypes.js +65 -0
- package/dist/packages/parchment/publicInts.d.ts +45 -0
- package/dist/packages/parchment/publicInts.js +383 -0
- package/dist/packages/parchment/reconcileEvents.d.ts +24 -0
- package/dist/packages/parchment/reconcileEvents.js +30 -0
- package/dist/packages/parchment/retainedFee.d.ts +43 -0
- package/dist/packages/parchment/retainedFee.js +68 -0
- package/dist/packages/parchment/sessionClose.d.ts +68 -0
- package/dist/packages/parchment/sessionClose.js +50 -0
- package/dist/packages/parchment/sessionKey.d.ts +78 -0
- package/dist/packages/parchment/sessionKey.js +154 -0
- package/dist/packages/parchment/slippage.d.ts +23 -0
- package/dist/packages/parchment/slippage.js +27 -0
- package/dist/packages/parchment/sponsor.d.ts +39 -0
- package/dist/packages/parchment/sponsor.js +48 -0
- package/dist/packages/parchment/stakingCalls.d.ts +33 -0
- package/dist/packages/parchment/stakingCalls.js +21 -0
- package/dist/packages/parchment/stakingEvents.d.ts +53 -0
- package/dist/packages/parchment/stakingEvents.js +71 -0
- package/dist/packages/parchment/triggerCalls.d.ts +46 -0
- package/dist/packages/parchment/triggerCalls.js +36 -0
- package/dist/packages/parchment/triggerEvents.d.ts +22 -0
- package/dist/packages/parchment/triggerEvents.js +33 -0
- package/dist/packages/parchment/triggers.d.ts +113 -0
- package/dist/packages/parchment/triggers.js +183 -0
- package/dist/packages/parchment/txBodies.d.ts +111 -0
- package/dist/packages/parchment/txBodies.js +683 -0
- package/dist/packages/parchment/txIntent.d.ts +99 -0
- package/dist/packages/parchment/txIntent.js +611 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/package.json +55 -4
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const TX_ACTIONS = [
|
|
2
|
+
"open-account",
|
|
3
|
+
"deposit",
|
|
4
|
+
"withdraw",
|
|
5
|
+
"request-open",
|
|
6
|
+
"request-open-as-delegate",
|
|
7
|
+
"request-close",
|
|
8
|
+
"request-close-as-delegate",
|
|
9
|
+
"cancel-order",
|
|
10
|
+
"cancel-order-as-delegate",
|
|
11
|
+
"expire-order",
|
|
12
|
+
"emergency-close",
|
|
13
|
+
"emergency-close-as-delegate",
|
|
14
|
+
"close-retired",
|
|
15
|
+
"close-retired-as-delegate",
|
|
16
|
+
"liquidate",
|
|
17
|
+
"liquidate-retired",
|
|
18
|
+
"sweep",
|
|
19
|
+
"sweep-surplus",
|
|
20
|
+
"claim-pending-mint",
|
|
21
|
+
"harvest",
|
|
22
|
+
"bind-referrer",
|
|
23
|
+
"bind-trading-referrer",
|
|
24
|
+
"transfer-account",
|
|
25
|
+
"stake",
|
|
26
|
+
"unstake",
|
|
27
|
+
"claim",
|
|
28
|
+
"grant-delegate",
|
|
29
|
+
"revoke-delegate",
|
|
30
|
+
"register-builder",
|
|
31
|
+
"set-builder-payout",
|
|
32
|
+
"create-builder",
|
|
33
|
+
"set-builder-fee",
|
|
34
|
+
"pause-builder",
|
|
35
|
+
"resume-builder",
|
|
36
|
+
"transfer-builder",
|
|
37
|
+
"approve-builder",
|
|
38
|
+
"revoke-builder-approval",
|
|
39
|
+
"set-builder-create-fee",
|
|
40
|
+
"install-treasury",
|
|
41
|
+
"auth-register",
|
|
42
|
+
"game-attach",
|
|
43
|
+
"claim-daily",
|
|
44
|
+
"open-crate",
|
|
45
|
+
"open-crates",
|
|
46
|
+
"claim-quest",
|
|
47
|
+
"collect-mint",
|
|
48
|
+
"release-unlocked",
|
|
49
|
+
"exit-early",
|
|
50
|
+
"exit-early-bounded",
|
|
51
|
+
"grant-close-delegate",
|
|
52
|
+
"grant-session-and-trigger",
|
|
53
|
+
"revoke-session-and-trigger",
|
|
54
|
+
];
|
|
55
|
+
export const PARCHMENT_CANDLES_BATCH_MAX_MARKETS = 12;
|
|
56
|
+
export const LEADERBOARD_PERIODS = ["daily", "weekly", "all", "season"];
|
|
57
|
+
export const LEADERBOARD_METRICS = ["pnl", "pnlPct", "volume", "winStreak", "xp"];
|
|
58
|
+
export const LOCKED_LEDGER_STATUSES = ["current", "rebuilding", "failed"];
|
|
59
|
+
export const PARCHMENT_SPONSORED_ACTIONS = [
|
|
60
|
+
"request-open-as-delegate",
|
|
61
|
+
"request-close-as-delegate",
|
|
62
|
+
"cancel-order-as-delegate",
|
|
63
|
+
"emergency-close-as-delegate",
|
|
64
|
+
"close-retired-as-delegate",
|
|
65
|
+
];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { IntPaths } from "../../general/utils/jsBigInt.js";
|
|
2
|
+
export declare const PUBLIC_INTS: {
|
|
3
|
+
readonly config: readonly ["pins[].sourceId", "pins[].lazerFeedId", ...string[]];
|
|
4
|
+
readonly markets: string[];
|
|
5
|
+
readonly market: string[];
|
|
6
|
+
readonly marketStats: readonly ["sinceMs", "untilMs", ...string[]];
|
|
7
|
+
readonly priceHistory: readonly ["points[].timestampMs", "points[].priceWad", "points[].twapWad"];
|
|
8
|
+
readonly livePrice: readonly ["priceWad", "timestampMs:u64"];
|
|
9
|
+
readonly trade: readonly ["id:i64", "positionId:u64", "notional:u64", "margin:u64", "pnl:i128", "timestampMs:i64"];
|
|
10
|
+
readonly candles: string[];
|
|
11
|
+
readonly candlesBatch: readonly ["serverTimeMs", ...string[]];
|
|
12
|
+
readonly prices: readonly string[];
|
|
13
|
+
readonly account: readonly [...string[], "queue.aheadCount", "queue.aheadNet"];
|
|
14
|
+
readonly positions: string[];
|
|
15
|
+
readonly position: string[];
|
|
16
|
+
readonly equityHistory: readonly ["bucketMs", "fromMs:i64", "toMs:i64", ...string[]];
|
|
17
|
+
readonly history: readonly ["items[].id", "items[].positionId", "items[].timestampMs", "items[].triggerPriceWad", ...string[]];
|
|
18
|
+
readonly trigger: IntPaths;
|
|
19
|
+
readonly triggers: string[];
|
|
20
|
+
readonly orders: string[];
|
|
21
|
+
readonly order: string[];
|
|
22
|
+
readonly tradingReferral: readonly ["refereeCount", "totalEarned", "pending"];
|
|
23
|
+
readonly accountQueue: readonly ["net", "rank", ...string[], "queueLength", "totalOwed", "lpCash"];
|
|
24
|
+
readonly previewOpen: readonly ["fillWad", "suggestedBoundWad", "margin", "fee", "locked", "notional", "winningExposure", "factorBps", "entryWad", "oneStepWad", "oneStepSpreadBps", "bustWad", "confWad", "takerFeeBps", "minPayoutFactorBps", "suggestedAcceptablePriceWad", "maxFeeBps", "execFee", "fillWindowMs", "signedWindowMs", "cancelDelayMs"];
|
|
25
|
+
readonly previewClose: readonly ["positionId", ...string[], "exitWad", "fillWad", "suggestedBoundWad", "oneStepWad", "oneStepSpreadBps", "confWad", "suggestedAcceptablePriceWad", "maxFeeBps", "execFee", "fillWindowMs", "signedWindowMs", "cancelDelayMs", "emergencyAfterMs", "feeOwed"];
|
|
26
|
+
readonly builder: IntPaths;
|
|
27
|
+
readonly builders: string[];
|
|
28
|
+
readonly builderApprovals: string[];
|
|
29
|
+
readonly builderAllowance: readonly ["created", "limit", "remaining"];
|
|
30
|
+
readonly referrals: readonly ["asReferee.boundAtMs", ...string[]];
|
|
31
|
+
readonly stakingPool: readonly ["totalStaked", "streamRemaining", "streamLastMs", "streamEndMs", "streamVestedNow", "rewardStreamMs", "minStakeLockMs", "rewards", "referralReserve", "nowMs", "parchDripRemaining", "parchDripNow", "parchDripLastMs", "parchDripEndMs", "totalWeight", "lockedWeight", "lockedWeightBps", "lockedOwedTotal"];
|
|
32
|
+
readonly staker: readonly ["staked", "stakedAtMs", "unlockAtMs", "pendingReward", "parchPending", "nowMs", "lockedWeight", "lockedSyncedBalance", "lockedPending", "lockedOwed", "totalWeight"];
|
|
33
|
+
readonly sponsored: readonly ["gasBudget", "gasPrice", "estimatedGas", "validEpoch"];
|
|
34
|
+
readonly queue: readonly ["length", "totalOwed", "lpCash", "instantlyPayable", "owedToLpCashBps"];
|
|
35
|
+
readonly lp: readonly string[];
|
|
36
|
+
readonly lpQueue: readonly ["queueLength", "totalOwed", "lpCash", ...string[]];
|
|
37
|
+
readonly protocol: readonly ["openPositions", "openNotional", "volumeNotional", "equity", "lpCash", "queueLength"];
|
|
38
|
+
readonly gameDefinitions: readonly [...string[], "cosmetics[].id", "achievementMintFractionBps"];
|
|
39
|
+
readonly game: readonly ["xp", "seasonXp", "seasonId", "tier", "streak", "winStreak", "crates", "trades", "achievements[]", "questsDone[]", "cosmetics[]", "minted", "mintedToday", "pendingMint", "lastDailyDay", "feeCredit", "feeCreditUsed", "achievementMintFractionBps", ...string[], "lockedBalance", "lockWindowBalance", "nextUnlockMs", "vestingBalance", "releasableNow", "earlyExitPaidNow", "earlyExitPenaltyNow", "earlyExitUnlocks[]"];
|
|
40
|
+
readonly leaderboard: readonly [...string[], "nextCursor"];
|
|
41
|
+
readonly feed: string[];
|
|
42
|
+
readonly pnlCard: readonly ["positionId", "pnl:i128", "pnlPct:i128"];
|
|
43
|
+
readonly recentPositions: string[];
|
|
44
|
+
readonly none: readonly [];
|
|
45
|
+
};
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
const under = (prefix, paths) => paths.map((p) => `${prefix}.${p}`);
|
|
2
|
+
const PRICE = ["priceWad", "twapWad", "timestampMs", "spreadWad", "ageMs:i64", "maxAgeMs", "confWad"];
|
|
3
|
+
const MARKET = [
|
|
4
|
+
"kind",
|
|
5
|
+
"status",
|
|
6
|
+
"takerFeeBps",
|
|
7
|
+
"winFeeBps",
|
|
8
|
+
"oracle.sourceId",
|
|
9
|
+
"oracle.lazerFeedId",
|
|
10
|
+
"oracle.maxAgeMs",
|
|
11
|
+
"oracle.maxConfAgeMs",
|
|
12
|
+
"oracle.maxFutureMs",
|
|
13
|
+
"oracle.maxTwapDevBps",
|
|
14
|
+
"oracle.minSpreadBps",
|
|
15
|
+
"risk.*",
|
|
16
|
+
"impact.*",
|
|
17
|
+
"timing.*",
|
|
18
|
+
"longOi",
|
|
19
|
+
"shortOi",
|
|
20
|
+
"longLockedExposure",
|
|
21
|
+
"shortLockedExposure",
|
|
22
|
+
"lastOracleTsMs",
|
|
23
|
+
"lastOracleSequence",
|
|
24
|
+
"lastOracleSlot",
|
|
25
|
+
"maxLongOi",
|
|
26
|
+
"maxShortOi",
|
|
27
|
+
"maxLongExposure",
|
|
28
|
+
"maxShortExposure",
|
|
29
|
+
"oneStepSpreadBps",
|
|
30
|
+
"cancelDelayMs",
|
|
31
|
+
"sessionEndsAtMs",
|
|
32
|
+
"nextSessionOpenMs",
|
|
33
|
+
...under("price", PRICE),
|
|
34
|
+
];
|
|
35
|
+
const POSITION = [
|
|
36
|
+
"positionId",
|
|
37
|
+
"midWad",
|
|
38
|
+
"confWad",
|
|
39
|
+
"entryWad",
|
|
40
|
+
"bustWad",
|
|
41
|
+
"margin",
|
|
42
|
+
"notional",
|
|
43
|
+
"leverage",
|
|
44
|
+
"factorBps",
|
|
45
|
+
"winningExposure",
|
|
46
|
+
"winFeeBps",
|
|
47
|
+
"deadbandPpm",
|
|
48
|
+
"closeFeePpm",
|
|
49
|
+
"openedAtMs",
|
|
50
|
+
"autoCloseAtMs",
|
|
51
|
+
"takeProfitWad",
|
|
52
|
+
"stopLossWad",
|
|
53
|
+
"fillBustWad",
|
|
54
|
+
];
|
|
55
|
+
const CANDLE = ["timeMs", "openWad", "highWad", "lowWad", "closeWad"];
|
|
56
|
+
const TRIGGER = ["positionId", "takeProfitWad", "stopLossWad", "stopLossDropped.ms", "stopLossDropped.wad"];
|
|
57
|
+
const ACCOUNT = [
|
|
58
|
+
"free",
|
|
59
|
+
"openNotional",
|
|
60
|
+
"pendingMintBasis",
|
|
61
|
+
"pendingMint",
|
|
62
|
+
"delegates[].expiryMs",
|
|
63
|
+
"delegatesCount",
|
|
64
|
+
"pendingOrders",
|
|
65
|
+
"pendingOpenOrders",
|
|
66
|
+
"nonce",
|
|
67
|
+
];
|
|
68
|
+
const CLAIM = ["claimId", "positionId", "net", "timestampMs", "remaining", "feeRemaining", "onTopRemaining"];
|
|
69
|
+
const BUILDER = ["id:u32", "feeBps:u16", "pending:u64", "totalEarned:u64"];
|
|
70
|
+
const ORDER = [
|
|
71
|
+
"margin",
|
|
72
|
+
"leverage",
|
|
73
|
+
"positionId",
|
|
74
|
+
"acceptablePriceWad",
|
|
75
|
+
"minFactorBps",
|
|
76
|
+
"maxFeeBps",
|
|
77
|
+
"execFee",
|
|
78
|
+
"requestedMs",
|
|
79
|
+
"fillDeadlineMs",
|
|
80
|
+
"cancelAfterMs",
|
|
81
|
+
"emergencyAfterMs",
|
|
82
|
+
"feeOwed",
|
|
83
|
+
"fillPriceWad",
|
|
84
|
+
"fillPriceTsMs",
|
|
85
|
+
"fillLatencyMs:i64",
|
|
86
|
+
"refund",
|
|
87
|
+
"execFeeRefunded",
|
|
88
|
+
"finalizedMs",
|
|
89
|
+
];
|
|
90
|
+
const HISTORY_PAYLOAD = [
|
|
91
|
+
"amount",
|
|
92
|
+
"builderId",
|
|
93
|
+
"builderAmount",
|
|
94
|
+
"positionId",
|
|
95
|
+
"midWad",
|
|
96
|
+
"confWad",
|
|
97
|
+
"entryWad",
|
|
98
|
+
"bustWad",
|
|
99
|
+
"margin",
|
|
100
|
+
"notional",
|
|
101
|
+
"factorBps",
|
|
102
|
+
"winningExposure",
|
|
103
|
+
"winFeeBps",
|
|
104
|
+
"deadbandPpm",
|
|
105
|
+
"closeFeePpm",
|
|
106
|
+
"gross",
|
|
107
|
+
"haircut",
|
|
108
|
+
"fee",
|
|
109
|
+
"net",
|
|
110
|
+
"bounty",
|
|
111
|
+
"toLp",
|
|
112
|
+
"exitWad",
|
|
113
|
+
];
|
|
114
|
+
const LEADERBOARD_ROW = [
|
|
115
|
+
"rank",
|
|
116
|
+
"value:i128",
|
|
117
|
+
...under("stats", ["trades", "closes", "wins", "volume", "pnl:i128", "winRateBps", "xp", "tier", "winStreak"]),
|
|
118
|
+
];
|
|
119
|
+
export const PUBLIC_INTS = {
|
|
120
|
+
config: [
|
|
121
|
+
"pins[].sourceId",
|
|
122
|
+
"pins[].lazerFeedId",
|
|
123
|
+
...under("gameRewards", [
|
|
124
|
+
"decimals",
|
|
125
|
+
"walletMintCapPerDay",
|
|
126
|
+
"globalMintCapPerDay",
|
|
127
|
+
"winMint",
|
|
128
|
+
"achievementMintFractionBps",
|
|
129
|
+
"dailyDrop.base",
|
|
130
|
+
"dailyDrop.step",
|
|
131
|
+
"dailyDrop.max",
|
|
132
|
+
"dailyDrop.streakCap",
|
|
133
|
+
]),
|
|
134
|
+
"maxPendingOrders",
|
|
135
|
+
"pauseMask",
|
|
136
|
+
"trim.maxShareBps",
|
|
137
|
+
"trim.cPpm",
|
|
138
|
+
"refereeDiscountBps",
|
|
139
|
+
...under("builders", ["ownerFeeLimitBps:u16", "maxFeeBps:u16", "hardCapBps:u16", "createFee:u64"]),
|
|
140
|
+
],
|
|
141
|
+
markets: under("markets[]", MARKET),
|
|
142
|
+
market: under("market", MARKET),
|
|
143
|
+
marketStats: [
|
|
144
|
+
"sinceMs",
|
|
145
|
+
"untilMs",
|
|
146
|
+
...under("markets[]", [
|
|
147
|
+
"volume24h",
|
|
148
|
+
"openedNotional24h",
|
|
149
|
+
"closedNotional24h",
|
|
150
|
+
"opens24h",
|
|
151
|
+
"closes24h",
|
|
152
|
+
"openInterestLong",
|
|
153
|
+
"openInterestShort",
|
|
154
|
+
"price24hAgoWad",
|
|
155
|
+
"price24hAgoTsMs",
|
|
156
|
+
]),
|
|
157
|
+
],
|
|
158
|
+
priceHistory: ["points[].timestampMs", "points[].priceWad", "points[].twapWad"],
|
|
159
|
+
livePrice: ["priceWad", "timestampMs:u64"],
|
|
160
|
+
trade: ["id:i64", "positionId:u64", "notional:u64", "margin:u64", "pnl:i128", "timestampMs:i64"],
|
|
161
|
+
candles: under("candles[]", CANDLE),
|
|
162
|
+
candlesBatch: ["serverTimeMs", ...under("series[].candles[]", CANDLE)],
|
|
163
|
+
prices: [
|
|
164
|
+
...under("markets[]", PRICE),
|
|
165
|
+
...under("pins[]", ["sourceId:u64", "lazerFeedId:u32", "ageMs:i64", "priceWad", "twapWad", "timestampMs"]),
|
|
166
|
+
],
|
|
167
|
+
account: [
|
|
168
|
+
...under("accounts[]", ACCOUNT),
|
|
169
|
+
"nextAccountNonce",
|
|
170
|
+
...under("positions[]", POSITION),
|
|
171
|
+
...under("queue.claims[]", CLAIM),
|
|
172
|
+
"queue.aheadCount",
|
|
173
|
+
"queue.aheadNet",
|
|
174
|
+
],
|
|
175
|
+
positions: under("positions[]", POSITION),
|
|
176
|
+
position: under("position", POSITION),
|
|
177
|
+
equityHistory: [
|
|
178
|
+
"bucketMs",
|
|
179
|
+
"fromMs:i64",
|
|
180
|
+
"toMs:i64",
|
|
181
|
+
...under("points[]", ["tsMs:i64", "equity", "free", "margin", "unrealizedPnl:i128", "openPositions", "unpricedPositions"]),
|
|
182
|
+
...under("current", ["tsMs:i64", "equity", "free", "margin", "unrealizedPnl:i128", "openPositions", "unpricedPositions"]),
|
|
183
|
+
],
|
|
184
|
+
history: ["items[].id", "items[].positionId", "items[].timestampMs", "items[].triggerPriceWad", ...under("items[].payload", HISTORY_PAYLOAD)],
|
|
185
|
+
trigger: TRIGGER,
|
|
186
|
+
triggers: under("triggers[]", TRIGGER),
|
|
187
|
+
orders: under("orders[]", ORDER),
|
|
188
|
+
order: under("order", ORDER),
|
|
189
|
+
tradingReferral: ["refereeCount", "totalEarned", "pending"],
|
|
190
|
+
accountQueue: [
|
|
191
|
+
"net",
|
|
192
|
+
"rank",
|
|
193
|
+
...under("claims[]", ["claimId", "position", "owed", "owedAhead"]),
|
|
194
|
+
"queueLength",
|
|
195
|
+
"totalOwed",
|
|
196
|
+
"lpCash",
|
|
197
|
+
],
|
|
198
|
+
previewOpen: [
|
|
199
|
+
"fillWad",
|
|
200
|
+
"suggestedBoundWad",
|
|
201
|
+
"margin",
|
|
202
|
+
"fee",
|
|
203
|
+
"locked",
|
|
204
|
+
"notional",
|
|
205
|
+
"winningExposure",
|
|
206
|
+
"factorBps",
|
|
207
|
+
"entryWad",
|
|
208
|
+
"oneStepWad",
|
|
209
|
+
"oneStepSpreadBps",
|
|
210
|
+
"bustWad",
|
|
211
|
+
"confWad",
|
|
212
|
+
"takerFeeBps",
|
|
213
|
+
"minPayoutFactorBps",
|
|
214
|
+
"suggestedAcceptablePriceWad",
|
|
215
|
+
"maxFeeBps",
|
|
216
|
+
"execFee",
|
|
217
|
+
"fillWindowMs",
|
|
218
|
+
"signedWindowMs",
|
|
219
|
+
"cancelDelayMs",
|
|
220
|
+
],
|
|
221
|
+
previewClose: [
|
|
222
|
+
"positionId",
|
|
223
|
+
...under("pnl", [
|
|
224
|
+
"loss",
|
|
225
|
+
"raw",
|
|
226
|
+
"trimmed",
|
|
227
|
+
"adjusted",
|
|
228
|
+
"winFee",
|
|
229
|
+
"closeToll",
|
|
230
|
+
"net",
|
|
231
|
+
"closeTollFromProfit",
|
|
232
|
+
"closeTollFromMargin",
|
|
233
|
+
"userProfit",
|
|
234
|
+
"marginReturned",
|
|
235
|
+
"payout",
|
|
236
|
+
"payoutBeforeRefund",
|
|
237
|
+
"refereeRefund",
|
|
238
|
+
"feesCollectedNow",
|
|
239
|
+
"builderFee",
|
|
240
|
+
"builderFeeBps:u16",
|
|
241
|
+
"trimMaxShareBps",
|
|
242
|
+
"trimCPpm",
|
|
243
|
+
]),
|
|
244
|
+
"exitWad",
|
|
245
|
+
"fillWad",
|
|
246
|
+
"suggestedBoundWad",
|
|
247
|
+
"oneStepWad",
|
|
248
|
+
"oneStepSpreadBps",
|
|
249
|
+
"confWad",
|
|
250
|
+
"suggestedAcceptablePriceWad",
|
|
251
|
+
"maxFeeBps",
|
|
252
|
+
"execFee",
|
|
253
|
+
"fillWindowMs",
|
|
254
|
+
"signedWindowMs",
|
|
255
|
+
"cancelDelayMs",
|
|
256
|
+
"emergencyAfterMs",
|
|
257
|
+
"feeOwed",
|
|
258
|
+
],
|
|
259
|
+
builder: BUILDER,
|
|
260
|
+
builders: under("[]", BUILDER),
|
|
261
|
+
builderApprovals: under("[]", ["builderId:u32", "maxFeeBps:u16"]),
|
|
262
|
+
builderAllowance: ["created", "limit", "remaining"],
|
|
263
|
+
referrals: [
|
|
264
|
+
"asReferee.boundAtMs",
|
|
265
|
+
...under("asReferrer", [
|
|
266
|
+
"direct[].boundAtMs",
|
|
267
|
+
"directCount",
|
|
268
|
+
"secondLevel[].boundAtMs",
|
|
269
|
+
"secondLevelCount",
|
|
270
|
+
"refereeClaimVolume",
|
|
271
|
+
"estimatedDirectBonus",
|
|
272
|
+
"estimatedSecondBonus",
|
|
273
|
+
]),
|
|
274
|
+
],
|
|
275
|
+
stakingPool: [
|
|
276
|
+
"totalStaked",
|
|
277
|
+
"streamRemaining",
|
|
278
|
+
"streamLastMs",
|
|
279
|
+
"streamEndMs",
|
|
280
|
+
"streamVestedNow",
|
|
281
|
+
"rewardStreamMs",
|
|
282
|
+
"minStakeLockMs",
|
|
283
|
+
"rewards",
|
|
284
|
+
"referralReserve",
|
|
285
|
+
"nowMs",
|
|
286
|
+
"parchDripRemaining",
|
|
287
|
+
"parchDripNow",
|
|
288
|
+
"parchDripLastMs",
|
|
289
|
+
"parchDripEndMs",
|
|
290
|
+
"totalWeight",
|
|
291
|
+
"lockedWeight",
|
|
292
|
+
"lockedWeightBps",
|
|
293
|
+
"lockedOwedTotal",
|
|
294
|
+
],
|
|
295
|
+
staker: [
|
|
296
|
+
"staked",
|
|
297
|
+
"stakedAtMs",
|
|
298
|
+
"unlockAtMs",
|
|
299
|
+
"pendingReward",
|
|
300
|
+
"parchPending",
|
|
301
|
+
"nowMs",
|
|
302
|
+
"lockedWeight",
|
|
303
|
+
"lockedSyncedBalance",
|
|
304
|
+
"lockedPending",
|
|
305
|
+
"lockedOwed",
|
|
306
|
+
"totalWeight",
|
|
307
|
+
],
|
|
308
|
+
sponsored: ["gasBudget", "gasPrice", "estimatedGas", "validEpoch"],
|
|
309
|
+
queue: ["length", "totalOwed", "lpCash", "instantlyPayable", "owedToLpCashBps"],
|
|
310
|
+
lp: [
|
|
311
|
+
...under("sweep", [
|
|
312
|
+
"floorBps:u64", "maxBps:u64", "intervalMs:u64", "capBps:u64",
|
|
313
|
+
"cashFloor:u64", "stakerBps:u64", "treasuryBps:u64", "growthBps:u64",
|
|
314
|
+
]),
|
|
315
|
+
"lpCash",
|
|
316
|
+
"trackedLp",
|
|
317
|
+
"equity",
|
|
318
|
+
"totalOwed",
|
|
319
|
+
"queueLength",
|
|
320
|
+
"feeLp",
|
|
321
|
+
"feeStaker",
|
|
322
|
+
"feeDev",
|
|
323
|
+
"userFree",
|
|
324
|
+
"lockedMargin",
|
|
325
|
+
"tailProgress",
|
|
326
|
+
"feeGrowth",
|
|
327
|
+
"stakerShareBps",
|
|
328
|
+
"stakerShareMinBps",
|
|
329
|
+
"stakerShareMaxBps",
|
|
330
|
+
"stakerCovLowBps",
|
|
331
|
+
"stakerCovHighBps",
|
|
332
|
+
"reserveUpnl",
|
|
333
|
+
"reserveStress",
|
|
334
|
+
"reserve",
|
|
335
|
+
"lastSurplusMs",
|
|
336
|
+
"reserveEpoch",
|
|
337
|
+
"oiMarkets",
|
|
338
|
+
...under("head", CLAIM),
|
|
339
|
+
...under("claims[]", CLAIM),
|
|
340
|
+
],
|
|
341
|
+
lpQueue: ["queueLength", "totalOwed", "lpCash", ...under("head", CLAIM), ...under("claims[]", CLAIM)],
|
|
342
|
+
protocol: ["openPositions", "openNotional", "volumeNotional", "equity", "lpCash", "queueLength"],
|
|
343
|
+
gameDefinitions: [
|
|
344
|
+
...under("quests[]", ["id", "kind", "param", "xp", "cosmetic", "startMs", "endMs", "seasonId"]),
|
|
345
|
+
...under("achievements[]", ["id", "kind", "param", "xp", "mintAmount", "cosmetic"]),
|
|
346
|
+
"cosmetics[].id",
|
|
347
|
+
"achievementMintFractionBps",
|
|
348
|
+
],
|
|
349
|
+
game: [
|
|
350
|
+
"xp",
|
|
351
|
+
"seasonXp",
|
|
352
|
+
"seasonId",
|
|
353
|
+
"tier",
|
|
354
|
+
"streak",
|
|
355
|
+
"winStreak",
|
|
356
|
+
"crates",
|
|
357
|
+
"trades",
|
|
358
|
+
"achievements[]",
|
|
359
|
+
"questsDone[]",
|
|
360
|
+
"cosmetics[]",
|
|
361
|
+
"minted",
|
|
362
|
+
"mintedToday",
|
|
363
|
+
"pendingMint",
|
|
364
|
+
"lastDailyDay",
|
|
365
|
+
"feeCredit",
|
|
366
|
+
"feeCreditUsed",
|
|
367
|
+
"achievementMintFractionBps",
|
|
368
|
+
...under("feeAchievements[]", ["id", "mintAtUnlock", "feesRequired", "feesNeeded", "xp", "mintAmount", "eligibleMint"]),
|
|
369
|
+
"lockedBalance",
|
|
370
|
+
"lockWindowBalance",
|
|
371
|
+
"nextUnlockMs",
|
|
372
|
+
"vestingBalance",
|
|
373
|
+
"releasableNow",
|
|
374
|
+
"earlyExitPaidNow",
|
|
375
|
+
"earlyExitPenaltyNow",
|
|
376
|
+
"earlyExitUnlocks[]",
|
|
377
|
+
],
|
|
378
|
+
leaderboard: [...under("rows[]", LEADERBOARD_ROW), ...under("viewer", LEADERBOARD_ROW), "nextCursor"],
|
|
379
|
+
feed: under("entries[]", ["positionId", "pnl:i128", "notional", "atMs", "leverage", "exitWad"]),
|
|
380
|
+
pnlCard: ["positionId", "pnl:i128", "pnlPct:i128"],
|
|
381
|
+
recentPositions: under("entries[]", ["positionId", "atMs", "notional", "margin", "leverage", "entryWad", "exitWad", "priceWad"]),
|
|
382
|
+
none: [],
|
|
383
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BCS for `parchment::events::Event<PositionsReconciledEventV1>`: one
|
|
3
|
+
* reconcile call (`trade::reconcile`, or the one an open, fill, retired close or emergency close
|
|
4
|
+
* runs first) removed these swept / liquidated positions of `market_id` from `account_id`, at most
|
|
5
|
+
* `max_reconcile` (32), in removal order. Never emitted with no positions.
|
|
6
|
+
*/
|
|
7
|
+
export declare const POSITIONS_RECONCILED_EVENT_BCS: import("@mysten/sui/bcs").BcsStruct<{
|
|
8
|
+
account_id: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
9
|
+
market_id: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
10
|
+
position_ids: import("@mysten/sui/bcs").BcsType<string[], Iterable<string | number | bigint> & {
|
|
11
|
+
length: number;
|
|
12
|
+
}, string>;
|
|
13
|
+
}, string>;
|
|
14
|
+
/** BCS for the per-position `Event<PositionReconciledEventV1>` (`account_id`, `position_id`). */
|
|
15
|
+
export declare const POSITION_RECONCILED_EVENT_BCS: import("@mysten/sui/bcs").BcsStruct<{
|
|
16
|
+
account_id: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
17
|
+
position_id: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
18
|
+
}, string>;
|
|
19
|
+
export type PositionsReconciledEvent = ReturnType<typeof POSITIONS_RECONCILED_EVENT_BCS.parse>;
|
|
20
|
+
export type PositionReconciledEvent = ReturnType<typeof POSITION_RECONCILED_EVENT_BCS.parse>;
|
|
21
|
+
/** Decode event bytes supplied by the API; null when they are not this event (or list no position). */
|
|
22
|
+
export declare function decodePositionsReconciledEvent(bytes: Uint8Array): PositionsReconciledEvent | null;
|
|
23
|
+
/** Decode the pre-2026-10-30 per-position event; null when the bytes are not that event. */
|
|
24
|
+
export declare function decodePositionReconciledEvent(bytes: Uint8Array): PositionReconciledEvent | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
2
|
+
export const POSITIONS_RECONCILED_EVENT_BCS = bcs.struct("PositionsReconciledEventV1", {
|
|
3
|
+
account_id: bcs.Address,
|
|
4
|
+
market_id: bcs.Address,
|
|
5
|
+
position_ids: bcs.vector(bcs.u64()),
|
|
6
|
+
});
|
|
7
|
+
export const POSITION_RECONCILED_EVENT_BCS = bcs.struct("PositionReconciledEventV1", {
|
|
8
|
+
account_id: bcs.Address,
|
|
9
|
+
position_id: bcs.u64(),
|
|
10
|
+
});
|
|
11
|
+
export function decodePositionsReconciledEvent(bytes) {
|
|
12
|
+
try {
|
|
13
|
+
const event = POSITIONS_RECONCILED_EVENT_BCS.parse(bytes);
|
|
14
|
+
if (event.position_ids.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
return POSITIONS_RECONCILED_EVENT_BCS.serialize(event).toBytes().length === bytes.length ? event : null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function decodePositionReconciledEvent(bytes) {
|
|
23
|
+
try {
|
|
24
|
+
const event = POSITION_RECONCILED_EVENT_BCS.parse(bytes);
|
|
25
|
+
return POSITION_RECONCILED_EVENT_BCS.serialize(event).toBytes().length === bytes.length ? event : null;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import type { ApiParchmentLpResponse } from "./parchmentTypes.js";
|
|
3
|
+
/**
|
|
4
|
+
* The retained-fee staker share curve (`config::set_retained_fee_curve`):
|
|
5
|
+
* stakers get `minShareBps` of each retained fee at pool coverage (pool cash / R) <= `lowCovBps`,
|
|
6
|
+
* `maxShareBps` at >= `highCovBps`, linear between; the treasury keeps the rest. Always split, never
|
|
7
|
+
* paused, never to the pool.
|
|
8
|
+
*/
|
|
9
|
+
export interface ParchmentRetainedFeeCurve {
|
|
10
|
+
minShareBps: bigint;
|
|
11
|
+
maxShareBps: bigint;
|
|
12
|
+
lowCovBps: bigint;
|
|
13
|
+
highCovBps: bigint;
|
|
14
|
+
}
|
|
15
|
+
/** Launch defaults (`constants.move`): stakers 30% at <= 100% coverage, rising to 70% at >= 200%. */
|
|
16
|
+
export declare const RETAINED_FEE_CURVE_DEFAULTS: Readonly<ParchmentRetainedFeeCurve>;
|
|
17
|
+
/** `constants::max_ratio_bps!()`: the highest coverage the curve may reference. */
|
|
18
|
+
export declare const RETAINED_FEE_CURVE_MAX_COV_BPS = 30000n;
|
|
19
|
+
/**
|
|
20
|
+
* Checks a setter input against the contract's bounds (`EBadEconParam` otherwise):
|
|
21
|
+
* `min_share_bps <= max_share_bps <= 10_000` and `low_cov_bps < high_cov_bps <= 30_000`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function retainedFeeCurve(curve: ParchmentRetainedFeeCurve): ParchmentRetainedFeeCurve;
|
|
24
|
+
/** Stakers' share (bps) of a retained fee, exactly as `safety::retained_staker_bps` (floored; R = 0 gives the max). */
|
|
25
|
+
export declare function retainedStakerShareBps(pool: {
|
|
26
|
+
lpCash: bigint;
|
|
27
|
+
reserve: bigint;
|
|
28
|
+
}, curve?: ParchmentRetainedFeeCurve): bigint;
|
|
29
|
+
/** The served curve from `getLp()`, or null while any of its four fields is unindexed or not served. */
|
|
30
|
+
export declare function lpRetainedFeeCurve(lp: Pick<ApiParchmentLpResponse, "stakerShareMinBps" | "stakerShareMaxBps" | "stakerCovLowBps" | "stakerCovHighBps">): ParchmentRetainedFeeCurve | null;
|
|
31
|
+
export interface SetRetainedFeeCurveCall {
|
|
32
|
+
/** The core `parchment` package (where `config` lives). */
|
|
33
|
+
packageId: string;
|
|
34
|
+
configId: string | TransactionObjectArgument;
|
|
35
|
+
/** `AuthorityCap<PACKAGE, ADMIN>`. */
|
|
36
|
+
adminCapId: string | TransactionObjectArgument;
|
|
37
|
+
curve: ParchmentRetainedFeeCurve;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Admin: `config::set_retained_fee_curve(config, cap, min_share_bps, max_share_bps, low_cov_bps,
|
|
41
|
+
* high_cov_bps)` (admin action 83). The curve is checked with `retainedFeeCurve` first.
|
|
42
|
+
*/
|
|
43
|
+
export declare function addSetRetainedFeeCurveCall(tx: Transaction, input: SetRetainedFeeCurveCall): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ParchmentApiError } from "../../general/utils/errors.js";
|
|
2
|
+
export const RETAINED_FEE_CURVE_DEFAULTS = Object.freeze({
|
|
3
|
+
minShareBps: 3000n,
|
|
4
|
+
maxShareBps: 7000n,
|
|
5
|
+
lowCovBps: 10000n,
|
|
6
|
+
highCovBps: 20000n,
|
|
7
|
+
});
|
|
8
|
+
export const RETAINED_FEE_CURVE_MAX_COV_BPS = 30000n;
|
|
9
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
10
|
+
function u64(value, field) {
|
|
11
|
+
if (typeof value !== "bigint" || value < 0n || value > U64_MAX) {
|
|
12
|
+
throw new ParchmentApiError(0, "bad_request", `${field} must be a u64`);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export function retainedFeeCurve(curve) {
|
|
17
|
+
const minShareBps = u64(curve.minShareBps, "min_share_bps");
|
|
18
|
+
const maxShareBps = u64(curve.maxShareBps, "max_share_bps");
|
|
19
|
+
const lowCovBps = u64(curve.lowCovBps, "low_cov_bps");
|
|
20
|
+
const highCovBps = u64(curve.highCovBps, "high_cov_bps");
|
|
21
|
+
if (minShareBps > maxShareBps)
|
|
22
|
+
throw new ParchmentApiError(0, "bad_request", "min_share_bps must not exceed max_share_bps");
|
|
23
|
+
if (maxShareBps > 10000n)
|
|
24
|
+
throw new ParchmentApiError(0, "bad_request", "max_share_bps must be at most 10000");
|
|
25
|
+
if (lowCovBps >= highCovBps)
|
|
26
|
+
throw new ParchmentApiError(0, "bad_request", "low_cov_bps must be below high_cov_bps");
|
|
27
|
+
if (highCovBps > RETAINED_FEE_CURVE_MAX_COV_BPS) {
|
|
28
|
+
throw new ParchmentApiError(0, "bad_request", `high_cov_bps must be at most ${RETAINED_FEE_CURVE_MAX_COV_BPS}`);
|
|
29
|
+
}
|
|
30
|
+
return { minShareBps, maxShareBps, lowCovBps, highCovBps };
|
|
31
|
+
}
|
|
32
|
+
export function retainedStakerShareBps(pool, curve = RETAINED_FEE_CURVE_DEFAULTS) {
|
|
33
|
+
if (pool.reserve === 0n)
|
|
34
|
+
return curve.maxShareBps;
|
|
35
|
+
const c = pool.lpCash * 10000n;
|
|
36
|
+
const lo = pool.reserve * curve.lowCovBps;
|
|
37
|
+
const hi = pool.reserve * curve.highCovBps;
|
|
38
|
+
if (c <= lo)
|
|
39
|
+
return curve.minShareBps;
|
|
40
|
+
if (c >= hi)
|
|
41
|
+
return curve.maxShareBps;
|
|
42
|
+
return curve.minShareBps + ((c - lo) * (curve.maxShareBps - curve.minShareBps)) / (hi - lo);
|
|
43
|
+
}
|
|
44
|
+
export function lpRetainedFeeCurve(lp) {
|
|
45
|
+
const { stakerShareMinBps, stakerShareMaxBps, stakerCovLowBps, stakerCovHighBps } = lp;
|
|
46
|
+
if (typeof stakerShareMinBps !== "bigint" ||
|
|
47
|
+
typeof stakerShareMaxBps !== "bigint" ||
|
|
48
|
+
typeof stakerCovLowBps !== "bigint" ||
|
|
49
|
+
typeof stakerCovHighBps !== "bigint") {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return { minShareBps: stakerShareMinBps, maxShareBps: stakerShareMaxBps, lowCovBps: stakerCovLowBps, highCovBps: stakerCovHighBps };
|
|
53
|
+
}
|
|
54
|
+
export function addSetRetainedFeeCurveCall(tx, input) {
|
|
55
|
+
const curve = retainedFeeCurve(input.curve);
|
|
56
|
+
const obj = (o) => (typeof o === "string" ? tx.object(o) : o);
|
|
57
|
+
tx.moveCall({
|
|
58
|
+
target: `${input.packageId}::config::set_retained_fee_curve`,
|
|
59
|
+
arguments: [
|
|
60
|
+
obj(input.configId),
|
|
61
|
+
obj(input.adminCapId),
|
|
62
|
+
tx.pure.u64(curve.minShareBps),
|
|
63
|
+
tx.pure.u64(curve.maxShareBps),
|
|
64
|
+
tx.pure.u64(curve.lowCovBps),
|
|
65
|
+
tx.pure.u64(curve.highCovBps),
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
}
|