@waterx/sdk 2.1.0 → 2.3.1-dev.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/README.md +75 -169
- package/dist/src/client.d.ts +52 -2
- package/dist/src/client.js +76 -6
- package/dist/src/config.d.ts +57 -3
- package/dist/src/config.js +10 -4
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.js +6 -0
- package/dist/src/core/waterx-account.d.ts +31 -0
- package/dist/src/core/waterx-account.js +26 -0
- package/dist/src/fetch.d.ts +110 -0
- package/dist/src/fetch.js +149 -4
- package/dist/src/generated/bucket_v2_framework/account.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/double.d.ts +77 -77
- package/dist/src/generated/bucket_v2_framework/float.d.ts +73 -73
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +33 -33
- package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/linked_table.js +2 -2
- package/dist/src/generated/bucket_v2_framework/sheet.d.ts +57 -57
- package/dist/src/generated/bucket_v2_framework/sheet.js +5 -11
- package/dist/src/generated/native_custody/custody_vault.d.ts +46 -32
- package/dist/src/generated/native_custody/custody_vault.js +19 -10
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/native_custody/events.js +1 -2
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +7 -7
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +1 -2
- package/dist/src/generated/utils/index.d.ts +7 -7
- package/dist/src/generated/utils/index.js +9 -6
- package/dist/src/generated/waterx_account/account.d.ts +124 -71
- package/dist/src/generated/waterx_account/account.js +64 -29
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_account/direct_rule.d.ts +5 -5
- package/dist/src/generated/waterx_account/events.d.ts +10 -0
- package/dist/src/generated/waterx_account/events.js +31 -50
- package/dist/src/generated/waterx_constant_rule/constant_rule.d.ts +68 -0
- package/dist/src/generated/waterx_constant_rule/constant_rule.js +59 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_credit/credit_registry.d.ts +9 -9
- package/dist/src/generated/waterx_credit/credit_registry.js +1 -2
- package/dist/src/generated/waterx_credit/limited_supply.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/aggregator.js +1 -2
- package/dist/src/generated/waterx_oracle/collector.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/collector.js +1 -1
- package/dist/src/generated/waterx_oracle/oracle.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.js +1 -2
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_perp/events.d.ts +181 -181
- package/dist/src/generated/waterx_perp/events.js +87 -173
- package/dist/src/generated/waterx_perp/global_config.d.ts +3 -3
- package/dist/src/generated/waterx_perp/global_config.js +6 -12
- package/dist/src/generated/waterx_perp/keyed_big_vector.d.ts +9 -9
- package/dist/src/generated/waterx_perp/keyed_big_vector.js +1 -2
- package/dist/src/generated/waterx_perp/lp_pool.d.ts +115 -115
- package/dist/src/generated/waterx_perp/lp_pool.js +11 -22
- package/dist/src/generated/waterx_perp/market_config.d.ts +61 -43
- package/dist/src/generated/waterx_perp/market_config.js +29 -22
- package/dist/src/generated/waterx_perp/math.d.ts +7 -7
- package/dist/src/generated/waterx_perp/order_book.d.ts +47 -47
- package/dist/src/generated/waterx_perp/position.d.ts +99 -99
- package/dist/src/generated/waterx_perp/position.js +6 -12
- package/dist/src/generated/waterx_perp/request.d.ts +67 -67
- package/dist/src/generated/waterx_perp/request.js +2 -3
- package/dist/src/generated/waterx_perp/response.d.ts +35 -35
- package/dist/src/generated/waterx_perp/response.js +1 -2
- package/dist/src/generated/waterx_perp/trading.d.ts +303 -179
- package/dist/src/generated/waterx_perp/trading.js +99 -14
- package/dist/src/generated/waterx_perp_view/view.js +5 -10
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +5 -5
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +1 -2
- package/dist/src/generated/waterx_referral/referral_table.d.ts +5 -5
- package/dist/src/generated/waterx_referral/referral_table.js +1 -2
- package/dist/src/generated/waterx_staking/waterx_staking.d.ts +19 -19
- package/dist/src/generated/waterx_staking/waterx_staking.js +10 -20
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +158 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +148 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +444 -4
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +417 -4
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.d.ts +214 -74
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.js +158 -29
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.js +3 -2
- package/dist/src/prediction/account.d.ts +96 -0
- package/dist/src/prediction/account.js +230 -0
- package/dist/src/prediction/admin.d.ts +47 -0
- package/dist/src/prediction/admin.js +105 -0
- package/dist/src/prediction/bcs.d.ts +22 -0
- package/dist/src/prediction/bcs.js +240 -0
- package/dist/src/prediction/client.d.ts +75 -0
- package/dist/src/prediction/client.js +164 -0
- package/dist/src/prediction/config.d.ts +60 -0
- package/dist/src/prediction/config.js +75 -0
- package/dist/src/prediction/constants.d.ts +44 -0
- package/dist/src/prediction/constants.js +46 -0
- package/dist/src/prediction/fetch.d.ts +82 -0
- package/dist/src/prediction/fetch.js +270 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +100 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +129 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +466 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +362 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +440 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +193 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +205 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +384 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +344 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +338 -0
- package/dist/src/prediction/generated/utils/index.d.ts +30 -0
- package/dist/src/prediction/generated/utils/index.js +160 -0
- package/dist/src/prediction/generated/waterx_account/account.d.ts +1589 -0
- package/dist/src/prediction/generated/waterx_account/account.js +1758 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +13 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +12 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +75 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +78 -0
- package/dist/src/prediction/generated/waterx_account/events.d.ts +33 -0
- package/dist/src/prediction/generated/waterx_account/events.js +137 -0
- package/dist/src/prediction/generated/waterx_account/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.d.ts +327 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.js +405 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.d.ts +5 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.js +9 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +60 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +83 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.js +18 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +22 -0
- package/dist/src/prediction/generated/waterx_prediction/events.js +179 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.d.ts +116 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.js +141 -0
- package/dist/src/prediction/generated/waterx_prediction/order.d.ts +200 -0
- package/dist/src/prediction/generated/waterx_prediction/order.js +284 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.d.ts +58 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.js +73 -0
- package/dist/src/prediction/generated/waterx_prediction/position.d.ts +160 -0
- package/dist/src/prediction/generated/waterx_prediction/position.js +214 -0
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/view.d.ts +353 -0
- package/dist/src/prediction/generated/waterx_prediction/view.js +432 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.d.ts +1698 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.js +1733 -0
- package/dist/src/prediction/gift-link.d.ts +6 -0
- package/dist/src/prediction/gift-link.js +5 -0
- package/dist/src/prediction/gift.d.ts +223 -0
- package/dist/src/prediction/gift.js +451 -0
- package/dist/src/prediction/index.d.ts +29 -0
- package/dist/src/prediction/index.js +21 -0
- package/dist/src/prediction/prediction.d.ts +104 -0
- package/dist/src/prediction/prediction.js +317 -0
- package/dist/src/prediction/tx-builders.d.ts +44 -0
- package/dist/src/prediction/tx-builders.js +52 -0
- package/dist/src/prediction/types.d.ts +93 -0
- package/dist/src/prediction/types.js +1 -0
- package/dist/src/prediction/user/account.d.ts +2 -0
- package/dist/src/prediction/user/account.js +1 -0
- package/dist/src/prediction/user/admin.d.ts +6 -0
- package/dist/src/prediction/user/admin.js +3 -0
- package/dist/src/prediction/user/gift.d.ts +2 -0
- package/dist/src/prediction/user/gift.js +1 -0
- package/dist/src/prediction/user/index.d.ts +5 -0
- package/dist/src/prediction/user/index.js +3 -0
- package/dist/src/prediction/user/keeper.d.ts +2 -0
- package/dist/src/prediction/user/keeper.js +1 -0
- package/dist/src/prediction/user/order.d.ts +2 -0
- package/dist/src/prediction/user/order.js +1 -0
- package/dist/src/prediction/user/position.d.ts +2 -0
- package/dist/src/prediction/user/position.js +1 -0
- package/dist/src/prediction/utils/bcs.d.ts +1 -0
- package/dist/src/prediction/utils/bcs.js +1 -0
- package/dist/src/prediction/utils/index.d.ts +1 -0
- package/dist/src/prediction/utils/index.js +1 -0
- package/dist/src/prediction/utils.d.ts +30 -0
- package/dist/src/prediction/utils.js +177 -0
- package/dist/src/sdk.d.ts +18 -0
- package/dist/src/sdk.js +17 -0
- package/dist/src/tx-builders.d.ts +54 -0
- package/dist/src/tx-builders.js +141 -0
- package/dist/src/unified-client.d.ts +407 -0
- package/dist/src/unified-client.js +123 -0
- package/dist/src/user/account.d.ts +27 -0
- package/dist/src/user/account.js +34 -8
- package/dist/src/user/credit.d.ts +8 -14
- package/dist/src/user/credit.js +9 -23
- package/dist/src/user/custody.d.ts +4 -18
- package/dist/src/user/custody.js +14 -25
- package/dist/src/utils/consolidate-balance.d.ts +37 -0
- package/dist/src/utils/consolidate-balance.js +89 -0
- package/dist/src/utils/math.d.ts +86 -0
- package/dist/src/utils/math.js +100 -0
- package/dist/src/utils/pyth.d.ts +35 -3
- package/dist/src/utils/pyth.js +145 -14
- package/package.json +129 -34
package/dist/src/fetch.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { WaterXClient } from "./client.ts";
|
|
9
9
|
import { AccountData, GlobalConfigData, MarketData, OrderData, PoolData, PositionData, RedeemRequestData, TokenPoolData } from "./generated/waterx_perp_view/view.ts";
|
|
10
|
+
import { type ParkedBackingAssetBalance } from "./utils/consolidate-balance.ts";
|
|
10
11
|
export type AccountDataView = ReturnType<typeof AccountData.parse>;
|
|
11
12
|
/**
|
|
12
13
|
* Look up the registered AccountData for a given wxa account ID.
|
|
@@ -114,6 +115,30 @@ export declare function getAccountsByOwner(client: WaterXClient, owner: string):
|
|
|
114
115
|
* balance available to withdraw. Returns `0n` for an unknown coin type.
|
|
115
116
|
*/
|
|
116
117
|
export declare function getAccountBalance(client: WaterXClient, accountId: string, coinType?: string): Promise<bigint>;
|
|
118
|
+
/**
|
|
119
|
+
* Inclusive wxUSD credit an account can spend after the default async tx-builder
|
|
120
|
+
* pre-sweep ({@link appendConsolidateForSpend}).
|
|
121
|
+
*
|
|
122
|
+
* - `internalRaw` — stored `Balance<CREDIT>` (`getAccountBalance`).
|
|
123
|
+
* - `pendingBackingRaw` — native-custody backing assets (USDC, USDSUI, …)
|
|
124
|
+
* parked at the account's Sui address, rescaled to CREDIT decimals at the
|
|
125
|
+
* 1:1 PSM peg (same probe as {@link appendConsolidateToUsd}).
|
|
126
|
+
* - `pendingCreditAtAddressRaw` — CREDIT at the account address (accumulator +
|
|
127
|
+
* owned coins). Swept into the internal slot by
|
|
128
|
+
* {@link appendConsolidateAddressCredit} via `consumeDepositDirect`.
|
|
129
|
+
* - `totalRaw` — sum of the three components; matches post-
|
|
130
|
+
* {@link appendConsolidateForSpend} spendable balance for predict / perp
|
|
131
|
+
* builders with `consolidateToUsd: true` (default).
|
|
132
|
+
*/
|
|
133
|
+
export interface SpendableCreditBalance {
|
|
134
|
+
internalRaw: bigint;
|
|
135
|
+
pendingBackingRaw: bigint;
|
|
136
|
+
pendingCreditAtAddressRaw: bigint;
|
|
137
|
+
totalRaw: bigint;
|
|
138
|
+
/** Per-asset breakdown for the backing-asset probe (empty when nothing parked). */
|
|
139
|
+
parkedBacking: ParkedBackingAssetBalance[];
|
|
140
|
+
}
|
|
141
|
+
export declare function getSpendableCreditBalance(client: WaterXClient, accountId: string): Promise<SpendableCreditBalance>;
|
|
117
142
|
/** Vault-wide native-custody state. */
|
|
118
143
|
export interface CustodyVaultData {
|
|
119
144
|
/** Total CREDIT minted by the custody vault (`credit_supply`). */
|
|
@@ -142,3 +167,88 @@ export interface CustodyAssetData {
|
|
|
142
167
|
* `&SingleVault<T>` reference, which a PTB simulate cannot read.
|
|
143
168
|
*/
|
|
144
169
|
export declare function getCustodyAssetData(client: WaterXClient, assetType: string): Promise<CustodyAssetData>;
|
|
170
|
+
/**
|
|
171
|
+
* Live rate-limit / cap snapshot read from the `wormhole_bridge::Bridge`
|
|
172
|
+
* shared object. All amounts are raw base units of the bridged credit coin.
|
|
173
|
+
*
|
|
174
|
+
* `dailyMinted` / `dailyBurned` are the sliding-window sums as the on-chain
|
|
175
|
+
* `daily_minted` / `daily_burned` views report them — buckets that rotated
|
|
176
|
+
* out of the trailing window are evicted lazily on the next mint/burn, so
|
|
177
|
+
* these can read slightly high until then (conservative).
|
|
178
|
+
*/
|
|
179
|
+
export interface BridgeLimitsView {
|
|
180
|
+
paused: boolean;
|
|
181
|
+
dailyMintLimit: bigint;
|
|
182
|
+
dailyMinted: bigint;
|
|
183
|
+
maxMintPerTx: bigint;
|
|
184
|
+
dailyBurnLimit: bigint;
|
|
185
|
+
dailyBurned: bigint;
|
|
186
|
+
maxBurnPerTx: bigint;
|
|
187
|
+
/** Per-account 24h burn cap; 0n means the gate is disabled. */
|
|
188
|
+
personalBurnCapAmount: bigint;
|
|
189
|
+
/** Present only when `accountId` is supplied — burn counted in that
|
|
190
|
+
* account's current window (the per-account cap key is the account id). */
|
|
191
|
+
personalBurned?: bigint;
|
|
192
|
+
/** Present only when `backing` is supplied — `minted_for(chainId, token)`,
|
|
193
|
+
* the amount currently withdrawable to that EVM (chain, token). */
|
|
194
|
+
backingMinted?: bigint;
|
|
195
|
+
}
|
|
196
|
+
export interface BridgeLimitsArgs {
|
|
197
|
+
/** wxa trading account id — enables the per-account `personalBurned` read. */
|
|
198
|
+
accountId?: string;
|
|
199
|
+
/** Wormhole destination chain id + 20-byte EVM token — enables the
|
|
200
|
+
* `mintedFor` backing read. */
|
|
201
|
+
backing?: {
|
|
202
|
+
wormholeChainId: number;
|
|
203
|
+
token: Uint8Array | number[];
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Batched read of the bridge's rate-limit / cap state in a single simulate.
|
|
208
|
+
* Pass `accountId` to also fetch the per-account burn usage, and `backing`
|
|
209
|
+
* to also fetch the destination-chain backing (`minted_for`).
|
|
210
|
+
*
|
|
211
|
+
* Throws if `wormhole_bridge` (or its `Bridge` object id) is absent from the
|
|
212
|
+
* canonical config — e.g. on a network where the Sui bridge isn't published.
|
|
213
|
+
*/
|
|
214
|
+
export declare function getBridgeLimits(client: WaterXClient, args?: BridgeLimitsArgs): Promise<BridgeLimitsView>;
|
|
215
|
+
export interface BridgeFeeView {
|
|
216
|
+
/** Raw fee charged on a wormhole (Sui → EVM) exit of `amount`:
|
|
217
|
+
* `max(ceil(effectiveRate * amount), effectiveMinFee)`. */
|
|
218
|
+
feeAmount: bigint;
|
|
219
|
+
/** Whether the exit clears the on-chain net-zero guard — i.e. a strictly
|
|
220
|
+
* positive amount remains after the fee. Gate "estimated fee" UI on THIS,
|
|
221
|
+
* not `feeAmount` alone: a dust `amount`, or a min-fee floor ≥ `amount`,
|
|
222
|
+
* makes `feeAmount >= amount` and the exit would abort (audit L1). */
|
|
223
|
+
wouldExecute: boolean;
|
|
224
|
+
/** Effective % rate for the chain (per-chain override → default → 0),
|
|
225
|
+
* 1e9-scaled (the `Float`-as-`u128` ABI convention). */
|
|
226
|
+
effectiveRate: bigint;
|
|
227
|
+
/** Effective minimum-fee floor for the chain (override → default → 0),
|
|
228
|
+
* in CREDIT base units. */
|
|
229
|
+
effectiveMinFee: bigint;
|
|
230
|
+
/** Net CREDIT the recipient receives after the fee; `0n` when the exit
|
|
231
|
+
* wouldn't execute (`wouldExecute === false`). */
|
|
232
|
+
netAmount: bigint;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Estimate the bridge fee for a wormhole (Sui → EVM) CREDIT exit of `amount`
|
|
236
|
+
* to `evmDestinationChain`, read in a single simulate from the on-chain
|
|
237
|
+
* `withdrawal_queue` views. The charged fee is
|
|
238
|
+
* `max(ceil(effectiveRate * amount), effectiveMinFee)`.
|
|
239
|
+
*
|
|
240
|
+
* Surface UI off `wouldExecute`, NOT `feeAmount` alone — `feeAmount` is the raw
|
|
241
|
+
* fee and can equal/exceed `amount` (ceil rounding on a dust entry, or a min-fee
|
|
242
|
+
* floor larger than the entry), in which case the on-chain exit aborts its
|
|
243
|
+
* net-zero guard (audit L1). `netAmount` is `0n` whenever `wouldExecute` is
|
|
244
|
+
* false.
|
|
245
|
+
*
|
|
246
|
+
* @param args.amount CREDIT base units (the bridged coin's smallest unit).
|
|
247
|
+
* @param args.evmDestinationChain WORMHOLE chain id of the destination EVM.
|
|
248
|
+
* @param args.creditType CREDIT coin type; defaults to `client.creditType()`.
|
|
249
|
+
*/
|
|
250
|
+
export declare function getBridgeFee(client: WaterXClient, args: {
|
|
251
|
+
evmDestinationChain: number;
|
|
252
|
+
amount: bigint | number;
|
|
253
|
+
creditType?: string;
|
|
254
|
+
}): Promise<BridgeFeeView>;
|
package/dist/src/fetch.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { fromBase64 } from "@mysten/bcs";
|
|
9
9
|
import { bcs } from "@mysten/sui/bcs";
|
|
10
10
|
import { Transaction } from "@mysten/sui/transactions";
|
|
11
|
-
import { DRY_RUN_SENDER } from "./constants.js";
|
|
11
|
+
import { COLLATERAL_DECIMALS, DRY_RUN_SENDER } from "./constants.js";
|
|
12
12
|
import { burnFeeRate as burnFeeRateCall, creditSupply as creditSupplyCall, hasAsset as hasAssetCall, mintFeeRate as mintFeeRateCall, } from "./generated/native_custody/custody_vault.js";
|
|
13
13
|
import { accountBalance as accountBalanceCall, accountIds as accountIdsCall, } from "./generated/waterx_account/account.js";
|
|
14
14
|
import { AccountData, accountData as accountDataCall, getAccountOrders as getAccountOrdersCall, getAccountPositions as getAccountPositionsCall, getMarketOrders as getMarketOrdersCall, getMarketPositions as getMarketPositionsCall, getRedeemRequests as getRedeemRequestsCall, GlobalConfigData, globalConfigData as globalConfigDataCall, MarketData, marketData as marketDataCall, OrderData, orderData as orderDataCall, PoolData, poolData as poolDataCall, PositionData, positionData as positionDataCall, positionExists as positionExistsCall, RedeemRequestData, TokenPoolData, tokenPoolData as tokenPoolDataCall, } from "./generated/waterx_perp_view/view.js";
|
|
@@ -16,6 +16,9 @@ import { AccountData, accountData as accountDataCall, getAccountOrders as getAcc
|
|
|
16
16
|
// Referral queries (waterx_referral::referral_table)
|
|
17
17
|
// ============================================================================
|
|
18
18
|
import { isValidReferralCode as isValidReferralCodeCall, referralCodeExists as referralCodeExistsCall, tryGetRefer as tryGetReferCall, } from "./generated/waterx_referral/referral_table.js";
|
|
19
|
+
import { bridgeFeeAmount as bridgeFeeAmountCall, bridgeFeeRate as bridgeFeeRateCall, bridgeMinFee as bridgeMinFeeCall, wouldExecuteWormhole as wouldExecuteWormholeCall, } from "./generated/withdrawal_queue/withdrawal_queue.js";
|
|
20
|
+
import { dailyBurned as dailyBurnedCall, dailyBurnLimit as dailyBurnLimitCall, dailyMinted as dailyMintedCall, dailyMintLimit as dailyMintLimitCall, maxBurnPerTx as maxBurnPerTxCall, maxMintPerTx as maxMintPerTxCall, mintedFor as mintedForCall, paused as pausedCall, personalBurnCapAmount as personalBurnCapAmountCall, personalBurned as personalBurnedCall, } from "./generated/wormhole_bridge/wormhole_bridge.js";
|
|
21
|
+
import { probeAddressCreditBalance, probeParkedBackingAssets, sumParkedBackingAsCreditRaw, } from "./utils/consolidate-balance.js";
|
|
19
22
|
function toBytes(b) {
|
|
20
23
|
if (!b)
|
|
21
24
|
return undefined;
|
|
@@ -27,21 +30,27 @@ function toBytes(b) {
|
|
|
27
30
|
return b;
|
|
28
31
|
return new Uint8Array(Object.values(b));
|
|
29
32
|
}
|
|
30
|
-
async function
|
|
33
|
+
async function simulateRaw(client, tx) {
|
|
31
34
|
tx.setSender(DRY_RUN_SENDER);
|
|
32
35
|
const sim = (await client.simulate(tx));
|
|
33
36
|
if (sim.$kind === "FailedTransaction") {
|
|
34
37
|
const err = sim.FailedTransaction?.status?.error?.message ?? "FailedTransaction";
|
|
35
38
|
throw new Error(`simulate aborted: ${err}`);
|
|
36
39
|
}
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
return sim;
|
|
41
|
+
}
|
|
42
|
+
function extractAt(sim, commandIndex, returnIndex = 0) {
|
|
43
|
+
const ret = sim.commandResults?.[commandIndex]?.returnValues?.[returnIndex];
|
|
39
44
|
const bytes = toBytes(ret?.bcs) ?? toBytes(ret?.value?.bcs);
|
|
40
45
|
if (!bytes) {
|
|
41
46
|
throw new Error(`simulate returned no BCS value at commandResults[${commandIndex}].returnValues[${returnIndex}]`);
|
|
42
47
|
}
|
|
43
48
|
return bytes;
|
|
44
49
|
}
|
|
50
|
+
async function simulateAndExtract(client, tx, commandIndex = 0, returnIndex = 0) {
|
|
51
|
+
const sim = await simulateRaw(client, tx);
|
|
52
|
+
return extractAt(sim, commandIndex, returnIndex);
|
|
53
|
+
}
|
|
45
54
|
function withLp(client, lpType) {
|
|
46
55
|
return lpType ?? client.wlpType();
|
|
47
56
|
}
|
|
@@ -360,6 +369,24 @@ export async function getAccountBalance(client, accountId, coinType) {
|
|
|
360
369
|
const bytes = await simulateAndExtract(client, tx);
|
|
361
370
|
return BigInt(bcs.u64().parse(bytes));
|
|
362
371
|
}
|
|
372
|
+
export async function getSpendableCreditBalance(client, accountId) {
|
|
373
|
+
const creditType = client.creditType();
|
|
374
|
+
const [internalRaw, parkedBacking, addressCredit] = await Promise.all([
|
|
375
|
+
getAccountBalance(client, accountId, creditType),
|
|
376
|
+
probeParkedBackingAssets(client, accountId),
|
|
377
|
+
probeAddressCreditBalance(client, accountId),
|
|
378
|
+
]);
|
|
379
|
+
const pendingBackingRaw = sumParkedBackingAsCreditRaw(parkedBacking, COLLATERAL_DECIMALS);
|
|
380
|
+
const pendingCreditAtAddressRaw = addressCredit.fundsRaw + addressCredit.coinsRaw;
|
|
381
|
+
const totalRaw = internalRaw + pendingBackingRaw + pendingCreditAtAddressRaw;
|
|
382
|
+
return {
|
|
383
|
+
internalRaw,
|
|
384
|
+
pendingBackingRaw,
|
|
385
|
+
pendingCreditAtAddressRaw,
|
|
386
|
+
totalRaw,
|
|
387
|
+
parkedBacking,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
363
390
|
// ============================================================================
|
|
364
391
|
// Native custody (custody_vault)
|
|
365
392
|
// ============================================================================
|
|
@@ -417,3 +444,121 @@ export async function getCustodyAssetData(client, assetType) {
|
|
|
417
444
|
const burnFeeRate = BigInt(bcs.u128().parse(await simulateAndExtract(client, burnTx)));
|
|
418
445
|
return { registered: true, mintFeeRate, burnFeeRate };
|
|
419
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Batched read of the bridge's rate-limit / cap state in a single simulate.
|
|
449
|
+
* Pass `accountId` to also fetch the per-account burn usage, and `backing`
|
|
450
|
+
* to also fetch the destination-chain backing (`minted_for`).
|
|
451
|
+
*
|
|
452
|
+
* Throws if `wormhole_bridge` (or its `Bridge` object id) is absent from the
|
|
453
|
+
* canonical config — e.g. on a network where the Sui bridge isn't published.
|
|
454
|
+
*/
|
|
455
|
+
export async function getBridgeLimits(client, args = {}) {
|
|
456
|
+
const pkg = client.config.packages.wormhole_bridge;
|
|
457
|
+
if (!pkg?.bridge) {
|
|
458
|
+
throw new Error("wormhole_bridge is not deployed on this network (no `bridge` object id in config)");
|
|
459
|
+
}
|
|
460
|
+
const packageId = pkg.published_at;
|
|
461
|
+
const bridge = pkg.bridge;
|
|
462
|
+
const tx = new Transaction();
|
|
463
|
+
// Fixed-order view calls; indices tracked below.
|
|
464
|
+
pausedCall({ package: packageId, arguments: { bridge } })(tx); // 0
|
|
465
|
+
dailyMintLimitCall({ package: packageId, arguments: { bridge } })(tx); // 1
|
|
466
|
+
dailyMintedCall({ package: packageId, arguments: { bridge } })(tx); // 2
|
|
467
|
+
maxMintPerTxCall({ package: packageId, arguments: { bridge } })(tx); // 3
|
|
468
|
+
dailyBurnLimitCall({ package: packageId, arguments: { bridge } })(tx); // 4
|
|
469
|
+
dailyBurnedCall({ package: packageId, arguments: { bridge } })(tx); // 5
|
|
470
|
+
maxBurnPerTxCall({ package: packageId, arguments: { bridge } })(tx); // 6
|
|
471
|
+
personalBurnCapAmountCall({ package: packageId, arguments: { bridge } })(tx); // 7
|
|
472
|
+
let backingIdx = -1;
|
|
473
|
+
if (args.backing) {
|
|
474
|
+
backingIdx = 8;
|
|
475
|
+
mintedForCall({
|
|
476
|
+
package: packageId,
|
|
477
|
+
arguments: {
|
|
478
|
+
bridge,
|
|
479
|
+
chainId: args.backing.wormholeChainId,
|
|
480
|
+
token: Array.from(args.backing.token),
|
|
481
|
+
},
|
|
482
|
+
})(tx);
|
|
483
|
+
}
|
|
484
|
+
let personalIdx = -1;
|
|
485
|
+
if (args.accountId) {
|
|
486
|
+
personalIdx = backingIdx === -1 ? 8 : 9;
|
|
487
|
+
// Clock (0x6) is auto-injected by the generated wrapper.
|
|
488
|
+
personalBurnedCall({
|
|
489
|
+
package: packageId,
|
|
490
|
+
arguments: { bridge, user: args.accountId },
|
|
491
|
+
})(tx);
|
|
492
|
+
}
|
|
493
|
+
const sim = await simulateRaw(client, tx);
|
|
494
|
+
const u64At = (i) => BigInt(bcs.u64().parse(extractAt(sim, i)));
|
|
495
|
+
const view = {
|
|
496
|
+
paused: bcs.bool().parse(extractAt(sim, 0)),
|
|
497
|
+
dailyMintLimit: u64At(1),
|
|
498
|
+
dailyMinted: u64At(2),
|
|
499
|
+
maxMintPerTx: u64At(3),
|
|
500
|
+
dailyBurnLimit: u64At(4),
|
|
501
|
+
dailyBurned: u64At(5),
|
|
502
|
+
maxBurnPerTx: u64At(6),
|
|
503
|
+
personalBurnCapAmount: u64At(7),
|
|
504
|
+
};
|
|
505
|
+
if (backingIdx >= 0)
|
|
506
|
+
view.backingMinted = u64At(backingIdx);
|
|
507
|
+
if (personalIdx >= 0)
|
|
508
|
+
view.personalBurned = u64At(personalIdx);
|
|
509
|
+
return view;
|
|
510
|
+
}
|
|
511
|
+
function requireWithdrawalQueue(client) {
|
|
512
|
+
const wq = client.config.packages.withdrawal_queue;
|
|
513
|
+
if (!wq?.queue) {
|
|
514
|
+
throw new Error("withdrawal_queue is not deployed on this network (no `queue` object id in config)");
|
|
515
|
+
}
|
|
516
|
+
return { pkg: wq.published_at, queue: wq.queue };
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Estimate the bridge fee for a wormhole (Sui → EVM) CREDIT exit of `amount`
|
|
520
|
+
* to `evmDestinationChain`, read in a single simulate from the on-chain
|
|
521
|
+
* `withdrawal_queue` views. The charged fee is
|
|
522
|
+
* `max(ceil(effectiveRate * amount), effectiveMinFee)`.
|
|
523
|
+
*
|
|
524
|
+
* Surface UI off `wouldExecute`, NOT `feeAmount` alone — `feeAmount` is the raw
|
|
525
|
+
* fee and can equal/exceed `amount` (ceil rounding on a dust entry, or a min-fee
|
|
526
|
+
* floor larger than the entry), in which case the on-chain exit aborts its
|
|
527
|
+
* net-zero guard (audit L1). `netAmount` is `0n` whenever `wouldExecute` is
|
|
528
|
+
* false.
|
|
529
|
+
*
|
|
530
|
+
* @param args.amount CREDIT base units (the bridged coin's smallest unit).
|
|
531
|
+
* @param args.evmDestinationChain WORMHOLE chain id of the destination EVM.
|
|
532
|
+
* @param args.creditType CREDIT coin type; defaults to `client.creditType()`.
|
|
533
|
+
*/
|
|
534
|
+
export async function getBridgeFee(client, args) {
|
|
535
|
+
const { pkg, queue } = requireWithdrawalQueue(client);
|
|
536
|
+
const amount = BigInt(args.amount);
|
|
537
|
+
const common = {
|
|
538
|
+
package: pkg,
|
|
539
|
+
typeArguments: [args.creditType ?? client.creditType()],
|
|
540
|
+
};
|
|
541
|
+
const chain = args.evmDestinationChain;
|
|
542
|
+
const tx = new Transaction();
|
|
543
|
+
// Fixed-order view calls; indices tracked below.
|
|
544
|
+
bridgeFeeAmountCall({
|
|
545
|
+
...common,
|
|
546
|
+
arguments: { queue, evmDestinationChain: chain, amount },
|
|
547
|
+
})(tx); // 0
|
|
548
|
+
wouldExecuteWormholeCall({
|
|
549
|
+
...common,
|
|
550
|
+
arguments: { queue, evmDestinationChain: chain, amount },
|
|
551
|
+
})(tx); // 1
|
|
552
|
+
bridgeFeeRateCall({ ...common, arguments: { queue, evmDestinationChain: chain } })(tx); // 2
|
|
553
|
+
bridgeMinFeeCall({ ...common, arguments: { queue, evmDestinationChain: chain } })(tx); // 3
|
|
554
|
+
const sim = await simulateRaw(client, tx);
|
|
555
|
+
const feeAmount = BigInt(bcs.u64().parse(extractAt(sim, 0)));
|
|
556
|
+
const wouldExecute = bcs.bool().parse(extractAt(sim, 1));
|
|
557
|
+
return {
|
|
558
|
+
feeAmount,
|
|
559
|
+
wouldExecute,
|
|
560
|
+
effectiveRate: BigInt(bcs.u128().parse(extractAt(sim, 2))),
|
|
561
|
+
effectiveMinFee: BigInt(bcs.u64().parse(extractAt(sim, 3))),
|
|
562
|
+
netAmount: wouldExecute ? amount - feeAmount : 0n,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
**************************************************************/
|
|
4
4
|
/** Module for Account Abstraction */
|
|
5
5
|
import { MoveStruct, type RawTransactionArgument } from '../utils/index.ts';
|
|
6
|
-
import { type Transaction } from '@mysten/sui/transactions';
|
|
6
|
+
import { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';
|
|
7
7
|
export declare const ACCOUNT: MoveStruct<{
|
|
8
8
|
dummy_field: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
9
9
|
}, "@bucket/framework::account::ACCOUNT">;
|
|
@@ -43,13 +43,13 @@ export interface RequestWithAccountOptions {
|
|
|
43
43
|
export declare function requestWithAccount(options: RequestWithAccountOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
44
44
|
export interface ReceiveArguments {
|
|
45
45
|
account: RawTransactionArgument<string>;
|
|
46
|
-
receiving:
|
|
46
|
+
receiving: TransactionArgument;
|
|
47
47
|
}
|
|
48
48
|
export interface ReceiveOptions {
|
|
49
49
|
package?: string;
|
|
50
50
|
arguments: ReceiveArguments | [
|
|
51
51
|
account: RawTransactionArgument<string>,
|
|
52
|
-
receiving:
|
|
52
|
+
receiving: TransactionArgument
|
|
53
53
|
];
|
|
54
54
|
typeArguments: [
|
|
55
55
|
string
|
|
@@ -90,12 +90,12 @@ export interface AccountAddressOptions {
|
|
|
90
90
|
}
|
|
91
91
|
export declare function accountAddress(options: AccountAddressOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
92
92
|
export interface RequestAddressArguments {
|
|
93
|
-
req:
|
|
93
|
+
req: TransactionArgument;
|
|
94
94
|
}
|
|
95
95
|
export interface RequestAddressOptions {
|
|
96
96
|
package?: string;
|
|
97
97
|
arguments: RequestAddressArguments | [
|
|
98
|
-
req:
|
|
98
|
+
req: TransactionArgument
|
|
99
99
|
];
|
|
100
100
|
}
|
|
101
101
|
export declare function requestAddress(options: RequestAddressOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|