ault-sdk-ts 0.10.0 → 0.12.0-rc.1

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.
Files changed (57) hide show
  1. package/README.md +104 -23
  2. package/dist/client.d.ts +2 -0
  3. package/dist/core/address.d.ts +1 -1
  4. package/dist/core/clob-gas.d.ts +4 -0
  5. package/dist/core/clob-msgs.d.ts +14 -6
  6. package/dist/core/clob-responses.d.ts +4 -1
  7. package/dist/core/conditional-msgs.d.ts +98 -0
  8. package/dist/core/manifest-types.d.ts +22 -2
  9. package/dist/core/margin-account.d.ts +8 -0
  10. package/dist/core/network.d.ts +21 -11
  11. package/dist/core/perpetual-msgs.d.ts +8 -0
  12. package/dist/core/vault-gas.d.ts +3 -1
  13. package/dist/core/vault-msgs.d.ts +46 -28
  14. package/dist/eip712/msg.generated.d.ts +19 -8
  15. package/dist/eip712/types.d.ts +5 -0
  16. package/dist/high-level/types.d.ts +172 -32
  17. package/dist/high-level-client.d.ts +1 -1
  18. package/dist/index.cjs +22007 -18578
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +3 -0
  21. package/dist/index.js +21855 -18453
  22. package/dist/index.js.map +1 -1
  23. package/dist/proto/gen/ault/authority/v1/tx.d.ts +12 -0
  24. package/dist/proto/gen/ault/clob/v1/conditional.d.ts +60 -0
  25. package/dist/proto/gen/ault/clob/v1/genesis.d.ts +13 -0
  26. package/dist/proto/gen/ault/clob/v1/group.d.ts +71 -0
  27. package/dist/proto/gen/ault/clob/v1/params.d.ts +5 -0
  28. package/dist/proto/gen/ault/clob/v1/query.d.ts +16 -0
  29. package/dist/proto/gen/ault/clob/v1/twap.d.ts +8 -4
  30. package/dist/proto/gen/ault/clob/v1/tx.d.ts +90 -1
  31. package/dist/proto/gen/ault/lending/v1/params.d.ts +2 -0
  32. package/dist/proto/gen/ault/lending/v1/tx.d.ts +1 -0
  33. package/dist/proto/gen/ault/margin/v1/genesis.d.ts +10 -48
  34. package/dist/proto/gen/ault/margin/v1/margin.d.ts +14 -64
  35. package/dist/proto/gen/ault/margin/v1/query.d.ts +4 -46
  36. package/dist/proto/gen/ault/margin/v1/tx.d.ts +11 -29
  37. package/dist/proto/gen/ault/miner/v1/miner.d.ts +4 -2
  38. package/dist/proto/gen/ault/oracle/v1/oracle.d.ts +5 -7
  39. package/dist/proto/gen/ault/oracle/v1/tx.d.ts +1 -1
  40. package/dist/proto/gen/ault/perpetual/v1/params.d.ts +6 -0
  41. package/dist/proto/gen/ault/perpetual/v1/perpetual.d.ts +10 -7
  42. package/dist/proto/gen/ault/spot/v1/genesis.d.ts +2 -0
  43. package/dist/proto/gen/ault/spot/v1/params.d.ts +25 -0
  44. package/dist/proto/gen/ault/spot/v1/query.d.ts +29 -0
  45. package/dist/proto/gen/ault/spot/v1/tx.d.ts +30 -0
  46. package/dist/proto/gen/ault/vault/v1/genesis.d.ts +22 -12
  47. package/dist/proto/gen/ault/vault/v1/query.d.ts +4 -18
  48. package/dist/proto/gen/ault/vault/v1/tx.d.ts +25 -5
  49. package/dist/proto/gen/ault/vault/v1/vault.d.ts +29 -57
  50. package/dist/rest/clob.d.ts +35 -3
  51. package/dist/rest/dex-types.generated.d.ts +548 -81
  52. package/dist/rest/dex.d.ts +3 -1
  53. package/dist/rest/dex.generated.d.ts +670 -123
  54. package/dist/rest/margin.d.ts +1 -5
  55. package/dist/rest/portfolio.d.ts +20 -5
  56. package/dist/rest/spot.d.ts +11 -0
  57. package/package.json +1 -1
package/README.md CHANGED
@@ -356,9 +356,13 @@ const impactPrices = await client.perpetual.getImpactPrices(marketId);
356
356
  ## Perpetual markets
357
357
 
358
358
  Perpetual markets (chain v3) trade on the same order book as spot. An order
359
- on a perpetual market is a regular `placeLimitOrder`; the only perp-specific
360
- flag is `reduceOnly`. The chain accepts limit orders only, so a "market
361
- order" is an immediate-or-cancel limit priced through the book:
359
+ on a perpetual market is a regular `placeLimitOrder`, and the chain needs
360
+ `reduceOnly` on every one (`false` for a plain order). Since v3.0.0-rc.3 a
361
+ perpetual market is quoted in "USD" and its base is the id of its index price
362
+ feed (`BTC/USD`), so neither side is a bank denom: prices are in USD and
363
+ quantities in base units with 18 decimals, while margin and fees settle in the
364
+ collateral denom. The chain accepts limit orders only, so a "market order" is
365
+ an immediate-or-cancel limit priced through the book:
362
366
 
363
367
  ```typescript
364
368
  import { iocLimitPrice } from "ault-sdk-ts";
@@ -394,6 +398,16 @@ await client.modifyPositionMargin({ marketId, marginDelta: "-500000" }); // isol
394
398
  await client.withdrawPerpCollateral({ amount: "250000000" });
395
399
  ```
396
400
 
401
+ A perpetual TWAP (`placeTwapOrder` with `reduceOnly`) is sized in base and
402
+ needs ten times the market's minimum order (`dex.getPerpParams()`). A
403
+ perpetual market takes conditional orders as limit orders only, and group
404
+ orders only as an OTOCO; see [Conditional and group orders](#conditional-and-group-orders).
405
+ Liquidation is open to any account: `liquidatePerpAccounts({ accounts })` is a
406
+ paid transaction, so its gas is simulated. It takes perpetual accounts, not
407
+ their owners: `perpAccountAddress(owner)` derives the cross account and
408
+ `perpAccountAddress(owner, marketId)` an isolated one, the way the chain does.
409
+ The chain skips an account that is not liquidatable.
410
+
397
411
  The same four collateral and margin methods exist on `client.asAgent` after `attachAgent`. Read
398
412
  models (markets, tickers with mark and funding, positions, fills, ledger) come
399
413
  from the DEX API's `/api/v1/perp` endpoints, `listPerpMarkets` through
@@ -485,10 +499,7 @@ const orders = await dex.listOrders({ address: account, status: "open" });
485
499
  ```
486
500
 
487
501
  `margin` takes `cross`, `autoBorrow`, `autoRepay` and `autoRepayAtCancel`,
488
- all false by default, and only goes on limit and market orders. Over EIP-712
489
- at least one flag has to be set: an isolated order with every flag false
490
- signs as an empty struct, which the chain hashes differently from wallets,
491
- so send that one through `client.asAgent`. The DEX API's
502
+ all false by default, and only goes on limit and market orders. The DEX API's
492
503
  `getMarginPosition` reports `maxTransferable` per denom; that, not `free`, is
493
504
  what a withdrawal can take.
494
505
 
@@ -516,7 +527,8 @@ repay all of it, or the chain rejects it with "residual debt below minimum".
516
527
 
517
528
  ## Vaults
518
529
 
519
- The vault messages follow v3.0.0-rc.2. B-Harvest says the vault proto is still changing (Lending and Margin are final), so expect vault changes in a later release.
530
+ The vault messages follow v3.0.0-rc.3, which replaced the rc.2 vault model:
531
+ the upgrade retired every rc.2 vault.
520
532
 
521
533
  Depositors put a vault's denom in and get shares; the vault's manager trades
522
534
  (trading vaults) or allocates across Lending pools (lending vaults) with it.
@@ -528,15 +540,15 @@ await client.depositToVault({ vaultAddress, amount: usdc });
528
540
  await client.redeemFromVault({ vaultAddress, shares: "1000000000000000000" });
529
541
  ```
530
542
 
531
- Creating a vault and changing its configuration go through the agent path.
532
- On chain v3.0.0-rc.2 the chain's EIP-712 sign doc for those two messages
533
- leaves out the vault's fee, lockup and config, so a wallet signature would
534
- not cover them. The master's agent can sign them for vaults the master owns:
543
+ A vault you own is created and reconfigured from the wallet or through the
544
+ agent. A lending vault names its denom and a management fee; a trading vault
545
+ holds the chain's perpetual collateral denom, takes a performance and an exit
546
+ fee, and starts with your initial deposit:
535
547
 
536
548
  ```typescript
537
- const agent = client.attachAgent({ agentPrivateKey });
538
- await agent.createVault({
549
+ await client.createVault({
539
550
  vaultDenom: usdc.denom,
551
+ managementFeeBps: 200,
540
552
  config: {
541
553
  lending: {
542
554
  pools: [{ poolId: 1, supplyCap: "5000000000" }],
@@ -544,13 +556,22 @@ await agent.createVault({
544
556
  withdrawalQueue: [1],
545
557
  },
546
558
  },
547
- lockup: { type: "unrestricted" },
548
- fee: { type: "managementDilution", rateBps: 200 },
549
- // Lending vaults start empty. A normal trading vault needs an initialDeposit
550
- // and, with an unrestricted lockup, a positive exitFeeBps.
559
+ });
560
+
561
+ await client.createVault({
562
+ config: { trading: { allowedActions: ["spot", "perpetual"], spotMarketIds: [marketId] } },
563
+ // Without a fund window the exit fee must be positive; with one it is zero.
564
+ exitFeeBps: 50,
565
+ performanceFeeBps: 1000,
566
+ initialDeposit: { denom: collateralDenom, amount: "10000000000000000000" },
551
567
  });
552
568
  ```
553
569
 
570
+ `fundWindow` (`depositOpenTime`, `depositCloseTime`, `redemptionOpenTime`)
571
+ limits when deposits and redemptions happen; a vault without one takes both
572
+ at any time. `vaultAddressKind(address)` reads a vault's type and relationship
573
+ from its address.
574
+
554
575
  Some messages go out from the vault's own account. `attachVaultManager`
555
576
  builds a surface for them, signed by whoever controls the vault (or that
556
577
  key's registered agent): the manager for a normal or parent vault, the
@@ -558,12 +579,16 @@ parent's manager for a child vault. What x/vault accepts depends on the kind
558
579
  of vault:
559
580
 
560
581
  - A normal trading vault or a child vault can place, modify and cancel
561
- orders on its configured spot markets. TWAP orders are rejected.
582
+ orders on its configured spot markets and, with the `perpetual` action, on
583
+ perpetual markets, where it also manages its collateral and margin. TWAP,
584
+ conditional and group orders are rejected.
562
585
  - A normal lending vault can move supply between its pools with
563
586
  `reallocateVault`.
564
587
  - A parent vault can create child vaults, update or cancel their config, set
565
- their status, and move capital to and from them with `transferChildVault`.
566
- It can't trade.
588
+ their status, move capital to and from them with `transferChildVault`, and
589
+ hand a perpetual account that liquidation cannot close (the derived account,
590
+ `perpAccountAddress(owner)`) to a child holding the `backstop` action with
591
+ `backstopTransfer`. It can't trade.
567
592
 
568
593
  Parent vaults belong to x/gov, so only a governance proposal can create one.
569
594
 
@@ -583,8 +608,9 @@ await child.placeLimitOrder({ marketId, isBuy: true, price: "3500", quantity: "1
583
608
 
584
609
  Status changes and config updates come from the vault's owner, not its
585
610
  manager. The builders reject what x/vault would reject before anything is
586
- signed: the wrong fee type or exit fee for the vault kind, a fund window out
587
- of order, bad pool or queue lists, markets not quoted in the vault's denom,
611
+ signed: fees the vault kind doesn't take, an exit fee that doesn't match the
612
+ fund window, a fund window out of order, bad pool or queue lists, actions the
613
+ vault's relationship doesn't allow, spot markets quoted in different denoms,
588
614
  and addresses that can't be vault accounts (or must be).
589
615
 
590
616
  The DEX API serves the vault directory, details with the caller's position
@@ -605,6 +631,61 @@ for await (const page of paginate(
605
631
  }
606
632
  ```
607
633
 
634
+ ## Conditional and group orders
635
+
636
+ Since chain v3.0.0-rc.3 an order can wait for a price. A conditional order
637
+ reserves nothing until the market's last traded price (not the mark or the
638
+ oracle) reaches its trigger, then places its limit or market order as an
639
+ ordinary order with a new id; its cloid moves to that order.
640
+
641
+ ```typescript
642
+ // A stop loss on a long: sell when the last trade falls to 65,000.
643
+ await client.placeConditionalOrder({
644
+ triggerPrice: "65000",
645
+ triggerAbove: false,
646
+ deadline,
647
+ order: { type: "limit", marketId, isBuy: false, price: "64900", quantity, reduceOnly: true },
648
+ });
649
+ ```
650
+
651
+ The chain refuses a trigger the market already sits at and a market with no
652
+ trade yet. `modifyConditionalOrders` replaces the trigger and order of waiting
653
+ orders (by id or cloid), and `cancelOrders` cancels them. Each takes a slot of
654
+ the account's open order limit.
655
+
656
+ Group orders link legs on one market. An OCO pairs a take profit and a stop
657
+ loss of the same side and size, and the first to fire cancels the other. An
658
+ OTO places a limit entry whose fills wake a conditional exit, and an OTOCO
659
+ wakes an OCO pair; the chain resizes the exits to what the entry filled.
660
+ Perpetual markets take only an OTOCO. `tpSlLegs` builds the two exits:
661
+
662
+ ```typescript
663
+ import { tpSlLegs } from "ault-sdk-ts";
664
+
665
+ const [takeProfit, stopLoss] = tpSlLegs({
666
+ isBuy: false, // the exits sell: they close a long
667
+ quantity,
668
+ deadline,
669
+ takeProfit: { triggerPrice: "75000", price: "74900" },
670
+ stopLoss: { triggerPrice: "65000", price: "64600" },
671
+ reduceOnly: true,
672
+ });
673
+ await client.placeGroupOrder({
674
+ marketId,
675
+ type: "otoco",
676
+ primary: { limit: { isBuy: true, price: "70000", quantity, deadline, reduceOnly: false } },
677
+ secondary: takeProfit,
678
+ tertiary: stopLoss,
679
+ });
680
+ ```
681
+
682
+ These sign from the wallet over EIP-712 and from `client.asAgent`. Over
683
+ EIP-712, every entry of a `modifyConditionalOrders` batch must have the same
684
+ shape, since typed data types a list by its first element. The DEX API lists
685
+ waiting orders with the rest (`type` `stop_limit` or `stop_market`, their
686
+ `info.conditional` and the `info.links` of a group), and the chain lists them
687
+ with `client.clob.getConditionalOrders({ orderer })`.
688
+
608
689
  ## DEX API
609
690
 
610
691
  The SDK includes a client for the Ault DEX API — a REST API for market data, order books, trades, balances, and UDF charting. This is a separate service from the on-chain Cosmos REST endpoints.
package/dist/client.d.ts CHANGED
@@ -14,6 +14,7 @@ import { type OracleApi } from "./rest/oracle";
14
14
  import { type PerpetualApi } from "./rest/perpetual";
15
15
  import { type RateLimitApi } from "./rest/ratelimit";
16
16
  import { type RewardApi } from "./rest/reward";
17
+ import { type SpotApi } from "./rest/spot";
17
18
  import { type StakingApi } from "./rest/staking";
18
19
  import { type DexApi } from "./rest/dex";
19
20
  import { DexWsClient } from "./ws/client";
@@ -50,6 +51,7 @@ export interface AultClient {
50
51
  perpetual: PerpetualApi;
51
52
  ratelimit: RateLimitApi;
52
53
  reward: RewardApi;
54
+ spot: SpotApi;
53
55
  staking: StakingApi;
54
56
  dex: DexApi;
55
57
  tokenregistry: TokenRegistryApi;
@@ -6,7 +6,7 @@ export type BigIntLike = bigint | number | string;
6
6
  export declare function normalizeAddress(address: string): string;
7
7
  /**
8
8
  * Like {@link normalizeAddress}, but also accepts the 32-byte module-derived
9
- * accounts (margin, perpetual and vault accounts) that hold Lending positions
9
+ * accounts (margin and perpetual accounts) that hold Lending positions
10
10
  * of their own.
11
11
  */
12
12
  export declare function normalizeAccountAddress(address: string): string;
@@ -12,4 +12,8 @@ export declare function scaleOrderGas(gas: Gas, subOrderCount: number): string;
12
12
  export declare function cancelOrdersGas(gas: Gas, orderCount: number): string;
13
13
  /** Modify gas: per-order minimum with no base (chain `MinGasPerModifyOrder`). */
14
14
  export declare function modifyOrdersGas(gas: Gas, orderCount: number): string;
15
+ export declare function conditionalOrderGas(gas: Gas): string;
16
+ export declare function modifyConditionalOrdersGas(gas: Gas, orderCount: number): string;
17
+ /** Flat: OCO, OTO and OTOCO all share one minimum. */
18
+ export declare function groupOrderGas(gas: Gas): string;
15
19
  export {};
@@ -23,11 +23,13 @@ export declare function buildLimitOrderMsg(sender: string, params: {
23
23
  * of the bank balance.
24
24
  */
25
25
  margin?: MarginOrderOptions;
26
- }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "builderFeeRate" | "cloid" | "postOnly" | "timeInForce" | "options" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "builderFeeRate" | "cloid" | "postOnly" | "timeInForce" | "options" | "builderAddress">>, "/ault.clob.v1.MsgPlaceLimitOrder">;
26
+ }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "timeInForce" | "postOnly" | "options" | "cloid" | "builderFeeRate" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "timeInForce" | "postOnly" | "options" | "cloid" | "builderFeeRate" | "builderAddress">>, "/ault.clob.v1.MsgPlaceLimitOrder">;
27
27
  /**
28
28
  * TWAP order (chain v2.1.0+). `deadline` is the absolute end of the execution
29
- * window; the chain runs one slice every 30s until then. `totalDeposit` must
30
- * be ≥ 10× the market's minimum quote value.
29
+ * window; the chain runs one slice every 30s until then. On spot,
30
+ * `totalDeposit` is quote for a buy and base for a sell; on a perpetual market
31
+ * (v3.0.0-rc.3) it is the base quantity. Either way the order must be worth at
32
+ * least 10× the market's minimum order.
31
33
  */
32
34
  export declare function buildTwapOrderMsg(sender: string, params: {
33
35
  marketId: Uint8Array;
@@ -39,7 +41,13 @@ export declare function buildTwapOrderMsg(sender: string, params: {
39
41
  builderAddress?: string;
40
42
  builderFeeRate?: string;
41
43
  cloid?: Uint8Array;
42
- }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceTwapOrder, "builderFeeRate" | "worstPrice" | "priceTolerance" | "cloid" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceTwapOrder, "builderFeeRate" | "worstPrice" | "priceTolerance" | "cloid" | "builderAddress">>, "/ault.clob.v1.MsgPlaceTwapOrder">;
44
+ /**
45
+ * Perpetual markets only, and required there: the chain needs the
46
+ * `PerpetualOrderOptions` Any on every perp order. A spot TWAP takes no
47
+ * options (no margin funding either).
48
+ */
49
+ reduceOnly?: boolean;
50
+ }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceTwapOrder, "options" | "cloid" | "builderFeeRate" | "builderAddress" | "worstPrice" | "priceTolerance"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceTwapOrder, "options" | "cloid" | "builderFeeRate" | "builderAddress" | "worstPrice" | "priceTolerance">>, "/ault.clob.v1.MsgPlaceTwapOrder">;
43
51
  export declare function buildMarketOrderMsg(sender: string, params: {
44
52
  marketId: Uint8Array;
45
53
  isBuy: boolean;
@@ -51,7 +59,7 @@ export declare function buildMarketOrderMsg(sender: string, params: {
51
59
  cloid?: Uint8Array;
52
60
  /** Spot markets only; see `buildLimitOrderMsg`. */
53
61
  margin?: MarginOrderOptions;
54
- }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "builderFeeRate" | "worstPrice" | "priceTolerance" | "cloid" | "options" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "builderFeeRate" | "worstPrice" | "priceTolerance" | "cloid" | "options" | "builderAddress">>, "/ault.clob.v1.MsgPlaceMarketOrder">;
62
+ }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "options" | "cloid" | "builderFeeRate" | "builderAddress" | "worstPrice" | "priceTolerance"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "options" | "cloid" | "builderFeeRate" | "builderAddress" | "worstPrice" | "priceTolerance">>, "/ault.clob.v1.MsgPlaceMarketOrder">;
55
63
  /** Each `orderIds` entry may be an 8-byte cloid or a 16-byte chain order_id. */
56
64
  export declare function buildCancelOrdersMsg(sender: string, orderIds: Uint8Array[]): import("../index.js").Eip712Msg<import("../proto/gen/ault/clob/v1/tx").MsgCancelOrders, "/ault.clob.v1.MsgCancelOrders">;
57
65
  /**
@@ -91,4 +99,4 @@ export declare function buildScaleOrderMsg(sender: string, params: {
91
99
  builderFeeRate?: string;
92
100
  /** Perpetual markets only; see `buildLimitOrderMsg`. */
93
101
  reduceOnly?: boolean;
94
- }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceScaleOrder, "builderFeeRate" | "postOnly" | "options" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceScaleOrder, "builderFeeRate" | "postOnly" | "options" | "builderAddress">>, "/ault.clob.v1.MsgPlaceScaleOrder">;
102
+ }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceScaleOrder, "postOnly" | "options" | "builderFeeRate" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceScaleOrder, "postOnly" | "options" | "builderFeeRate" | "builderAddress">>, "/ault.clob.v1.MsgPlaceScaleOrder">;
@@ -1,4 +1,4 @@
1
- import type { PlaceOrderResult, PlaceScaleOrderResult, PlaceTwapOrderResult, CancelOrdersResult, ModifyOrdersResult, TxResult } from "../high-level/types";
1
+ import type { PlaceOrderResult, PlaceScaleOrderResult, PlaceTwapOrderResult, CancelOrdersResult, ModifyOrdersResult, PlaceConditionalOrderResult, ModifyConditionalOrdersResult, PlaceGroupOrderResult, TxResult } from "../high-level/types";
2
2
  type MsgResponse = {
3
3
  typeUrl: string;
4
4
  value: Uint8Array;
@@ -18,4 +18,7 @@ export declare function decodeTwapOrderResult(msgResponses: MsgResponse[] | unde
18
18
  export declare function decodeScaleOrderResult(msgResponses: MsgResponse[] | undefined, base: TxResult): PlaceScaleOrderResult;
19
19
  export declare function decodeModifyOrdersResult(msgResponses: MsgResponse[] | undefined, base: TxResult): ModifyOrdersResult;
20
20
  export declare function decodeCancelOrdersResult(msgResponses: MsgResponse[] | undefined, base: TxResult): CancelOrdersResult;
21
+ export declare function decodeConditionalOrderResult(msgResponses: MsgResponse[] | undefined, base: TxResult): PlaceConditionalOrderResult;
22
+ export declare function decodeModifyConditionalOrdersResult(msgResponses: MsgResponse[] | undefined, base: TxResult): ModifyConditionalOrdersResult;
23
+ export declare function decodeGroupOrderResult(msgResponses: MsgResponse[] | undefined, base: TxResult): PlaceGroupOrderResult;
21
24
  export {};
@@ -0,0 +1,98 @@
1
+ import type { MsgPlaceConditionalOrder, OrderLeg } from "../proto/gen/ault/clob/v1/tx";
2
+ import { buildLimitOrderMsg, buildMarketOrderMsg } from "./clob-msgs";
3
+ type LimitParams = Parameters<typeof buildLimitOrderMsg>[1];
4
+ type MarketParams = Parameters<typeof buildMarketOrderMsg>[1];
5
+ /** The limit order a conditional places; its deadline is the condition's. */
6
+ export type ConditionalLimitInput = {
7
+ type: "limit";
8
+ } & Omit<LimitParams, "cloid" | "deadline">;
9
+ /** The market order a conditional places. Spot only: perpetual markets take limit orders. */
10
+ export type ConditionalMarketInput = {
11
+ type: "market";
12
+ } & Omit<MarketParams, "cloid">;
13
+ export interface ConditionalOrderInput {
14
+ /** Fires when the market's last traded price reaches it (not the mark or oracle price). */
15
+ triggerPrice: string;
16
+ /** `true`: fire at or above `triggerPrice`; `false`: at or below. */
17
+ triggerAbove: boolean;
18
+ /** When the waiting order expires; also the deadline of a limit order it places. */
19
+ deadline: Date;
20
+ /** Optional 8-byte client order id. It moves to the placed order once the trigger fires. */
21
+ cloid?: Uint8Array;
22
+ order: ConditionalLimitInput | ConditionalMarketInput;
23
+ }
24
+ /**
25
+ * An order that waits, reserving nothing, until the market's last traded price
26
+ * crosses `triggerPrice`, then places `order` as an ordinary order with a new
27
+ * id (a stop-loss or take-profit). It takes one slot of the account's open
28
+ * order limit and is cancelled with `cancelOrders` like any other order.
29
+ */
30
+ export declare function buildConditionalOrderMsg(sender: string, input: ConditionalOrderInput): import("../index.js").Eip712Msg<Omit<MsgPlaceConditionalOrder, "limit" | "cloid" | "market"> & Partial<Pick<MsgPlaceConditionalOrder, "limit" | "cloid" | "market">>, "/ault.clob.v1.MsgPlaceConditionalOrder">;
31
+ /**
32
+ * Replaces the trigger, deadline and order of waiting conditional orders.
33
+ * `orderRef` is the conditional's 16-byte id or its 8-byte cloid. The market,
34
+ * side and options of the order cannot change.
35
+ */
36
+ export declare function buildModifyConditionalOrdersMsg(sender: string, orders: Array<{
37
+ orderRef: Uint8Array;
38
+ } & Omit<ConditionalOrderInput, "cloid">>): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgModifyConditionalOrders, "orders"> & {
39
+ orders: (Omit<import("../proto/gen/ault/clob/v1/tx").ModifyConditionalOrder, "limit" | "market"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").ModifyConditionalOrder, "limit" | "market">>)[];
40
+ }, "/ault.clob.v1.MsgModifyConditionalOrders">;
41
+ /** A group leg. Market IDs come from the group, so legs omit them. */
42
+ export type GroupLegInput = {
43
+ limit: Omit<LimitParams, "marketId">;
44
+ } | {
45
+ conditional: Omit<ConditionalOrderInput, "order"> & {
46
+ order: Omit<ConditionalLimitInput, "marketId"> | Omit<ConditionalMarketInput, "marketId">;
47
+ };
48
+ }
49
+ /** An order already resting on the book (16-byte id or 8-byte cloid); primary leg only. */
50
+ | {
51
+ existingOrder: Uint8Array;
52
+ };
53
+ export type GroupTypeInput = "oco" | "oto" | "otoco";
54
+ /**
55
+ * Places linked orders on one market:
56
+ *
57
+ * - `oco`: two conditional limit exits on the same side and quantity, a
58
+ * take-profit and a stop-loss; the first to fill or trigger cancels the other.
59
+ * - `oto`: a primary limit order (or an order already resting) and a
60
+ * conditional exit that stays dormant until the primary fills, sized to the
61
+ * filled quantity.
62
+ * - `otoco`: a primary and an OCO pair of exits woken by its fills. The only
63
+ * group a perpetual market takes, so a perp TP/SL is set at entry.
64
+ */
65
+ export declare function buildGroupOrderMsg(sender: string, params: {
66
+ marketId: Uint8Array;
67
+ type: GroupTypeInput;
68
+ primary: GroupLegInput;
69
+ secondary: GroupLegInput;
70
+ tertiary?: GroupLegInput;
71
+ }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceGroupOrder, "tertiary" | "secondary" | "primary"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceGroupOrder, "tertiary">> & {
72
+ primary: Omit<OrderLeg, "limit" | "market" | "conditional" | "existingOrderId"> & Partial<Pick<OrderLeg, "limit" | "market" | "conditional" | "existingOrderId">>;
73
+ } & {
74
+ secondary: Omit<OrderLeg, "limit" | "market" | "conditional" | "existingOrderId"> & Partial<Pick<OrderLeg, "limit" | "market" | "conditional" | "existingOrderId">>;
75
+ }, "/ault.clob.v1.MsgPlaceGroupOrder">;
76
+ /**
77
+ * The two exits of a take-profit / stop-loss pair, ready for the `secondary`
78
+ * and `tertiary` legs of an OTOCO (or the two legs of an OCO). `isBuy` is the
79
+ * exits' side: `false` to close a long, `true` to close a short. Each exit is
80
+ * a limit order at its `price` once its trigger fires; on a perpetual market
81
+ * pass `reduceOnly: true`, which the chain needs on every perp order.
82
+ */
83
+ export declare function tpSlLegs(params: {
84
+ isBuy: boolean;
85
+ quantity: string;
86
+ deadline: Date;
87
+ takeProfit: {
88
+ triggerPrice: string;
89
+ price: string;
90
+ };
91
+ stopLoss: {
92
+ triggerPrice: string;
93
+ price: string;
94
+ timeInForce?: "ioc";
95
+ };
96
+ reduceOnly?: boolean;
97
+ }): [GroupLegInput, GroupLegInput];
98
+ export {};
@@ -29,11 +29,17 @@ export declare const ManifestGasSchema: z.ZodObject<{
29
29
  CANCEL_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
30
30
  CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
31
31
  MODIFY_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
32
+ CONDITIONAL_ORDER: z.ZodOptional<z.ZodNumber>;
33
+ MODIFY_CONDITIONAL_BASE: z.ZodOptional<z.ZodNumber>;
34
+ MODIFY_CONDITIONAL_PER_ORDER: z.ZodOptional<z.ZodNumber>;
35
+ GROUP_ORDER: z.ZodOptional<z.ZodNumber>;
32
36
  OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
33
37
  PERP_DEPOSIT: z.ZodOptional<z.ZodNumber>;
34
38
  PERP_WITHDRAW: z.ZodOptional<z.ZodNumber>;
35
39
  PERP_SET_MARGIN_CONFIG: z.ZodOptional<z.ZodNumber>;
36
40
  PERP_MODIFY_POSITION_MARGIN: z.ZodOptional<z.ZodNumber>;
41
+ PERP_LIQUIDATE_BASE: z.ZodOptional<z.ZodNumber>;
42
+ PERP_LIQUIDATE_PER_ACCOUNT: z.ZodOptional<z.ZodNumber>;
37
43
  LENDING_SUPPLY: z.ZodOptional<z.ZodNumber>;
38
44
  LENDING_WITHDRAW: z.ZodOptional<z.ZodNumber>;
39
45
  LENDING_SUPPLY_COLLATERAL: z.ZodOptional<z.ZodNumber>;
@@ -53,12 +59,16 @@ export declare const ManifestGasSchema: z.ZodObject<{
53
59
  VAULT_CREATE_LENDING_BASE: z.ZodOptional<z.ZodNumber>;
54
60
  VAULT_CREATE_PER_LENDING_POOL: z.ZodOptional<z.ZodNumber>;
55
61
  VAULT_UPDATE_MANAGER: z.ZodOptional<z.ZodNumber>;
56
- VAULT_UPDATE_CONFIG: z.ZodOptional<z.ZodNumber>;
62
+ VAULT_UPDATE_CONFIG_TRADING_BASE: z.ZodOptional<z.ZodNumber>;
63
+ VAULT_UPDATE_CONFIG_PER_MARKET: z.ZodOptional<z.ZodNumber>;
64
+ VAULT_UPDATE_CONFIG_LENDING_BASE: z.ZodOptional<z.ZodNumber>;
65
+ VAULT_UPDATE_CONFIG_PER_POOL: z.ZodOptional<z.ZodNumber>;
57
66
  VAULT_CANCEL_CONFIG_UPDATE: z.ZodOptional<z.ZodNumber>;
58
67
  VAULT_SET_STATUS: z.ZodOptional<z.ZodNumber>;
59
68
  VAULT_DEPOSIT: z.ZodOptional<z.ZodNumber>;
60
69
  VAULT_REDEEM: z.ZodOptional<z.ZodNumber>;
61
70
  VAULT_TRANSFER: z.ZodOptional<z.ZodNumber>;
71
+ VAULT_BACKSTOP_TRANSFER: z.ZodOptional<z.ZodNumber>;
62
72
  VAULT_REALLOCATE: z.ZodOptional<z.ZodNumber>;
63
73
  DELEGATE: z.ZodOptional<z.ZodNumber>;
64
74
  UNDELEGATE: z.ZodOptional<z.ZodNumber>;
@@ -113,11 +123,17 @@ export declare const ManifestSchema: z.ZodObject<{
113
123
  CANCEL_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
114
124
  CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
115
125
  MODIFY_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
126
+ CONDITIONAL_ORDER: z.ZodOptional<z.ZodNumber>;
127
+ MODIFY_CONDITIONAL_BASE: z.ZodOptional<z.ZodNumber>;
128
+ MODIFY_CONDITIONAL_PER_ORDER: z.ZodOptional<z.ZodNumber>;
129
+ GROUP_ORDER: z.ZodOptional<z.ZodNumber>;
116
130
  OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
117
131
  PERP_DEPOSIT: z.ZodOptional<z.ZodNumber>;
118
132
  PERP_WITHDRAW: z.ZodOptional<z.ZodNumber>;
119
133
  PERP_SET_MARGIN_CONFIG: z.ZodOptional<z.ZodNumber>;
120
134
  PERP_MODIFY_POSITION_MARGIN: z.ZodOptional<z.ZodNumber>;
135
+ PERP_LIQUIDATE_BASE: z.ZodOptional<z.ZodNumber>;
136
+ PERP_LIQUIDATE_PER_ACCOUNT: z.ZodOptional<z.ZodNumber>;
121
137
  LENDING_SUPPLY: z.ZodOptional<z.ZodNumber>;
122
138
  LENDING_WITHDRAW: z.ZodOptional<z.ZodNumber>;
123
139
  LENDING_SUPPLY_COLLATERAL: z.ZodOptional<z.ZodNumber>;
@@ -137,12 +153,16 @@ export declare const ManifestSchema: z.ZodObject<{
137
153
  VAULT_CREATE_LENDING_BASE: z.ZodOptional<z.ZodNumber>;
138
154
  VAULT_CREATE_PER_LENDING_POOL: z.ZodOptional<z.ZodNumber>;
139
155
  VAULT_UPDATE_MANAGER: z.ZodOptional<z.ZodNumber>;
140
- VAULT_UPDATE_CONFIG: z.ZodOptional<z.ZodNumber>;
156
+ VAULT_UPDATE_CONFIG_TRADING_BASE: z.ZodOptional<z.ZodNumber>;
157
+ VAULT_UPDATE_CONFIG_PER_MARKET: z.ZodOptional<z.ZodNumber>;
158
+ VAULT_UPDATE_CONFIG_LENDING_BASE: z.ZodOptional<z.ZodNumber>;
159
+ VAULT_UPDATE_CONFIG_PER_POOL: z.ZodOptional<z.ZodNumber>;
141
160
  VAULT_CANCEL_CONFIG_UPDATE: z.ZodOptional<z.ZodNumber>;
142
161
  VAULT_SET_STATUS: z.ZodOptional<z.ZodNumber>;
143
162
  VAULT_DEPOSIT: z.ZodOptional<z.ZodNumber>;
144
163
  VAULT_REDEEM: z.ZodOptional<z.ZodNumber>;
145
164
  VAULT_TRANSFER: z.ZodOptional<z.ZodNumber>;
165
+ VAULT_BACKSTOP_TRANSFER: z.ZodOptional<z.ZodNumber>;
146
166
  VAULT_REALLOCATE: z.ZodOptional<z.ZodNumber>;
147
167
  DELEGATE: z.ZodOptional<z.ZodNumber>;
148
168
  UNDELEGATE: z.ZodOptional<z.ZodNumber>;
@@ -12,6 +12,14 @@ export type MarginMarketIdInput = Uint8Array | MarketId | string;
12
12
  * the same address the same way.
13
13
  */
14
14
  export declare function marginAccountAddress(owner: string, marketId?: MarginMarketIdInput): string;
15
+ /**
16
+ * The perpetual account that holds an owner's collateral and positions: the
17
+ * cross account without `marketId`, an isolated market's account with it.
18
+ * `liquidatePerpAccounts` takes these addresses, not the owner's.
19
+ */
20
+ export declare function perpAccountAddress(owner: string, marketId?: MarginMarketIdInput): string;
21
+ /** True when `address` has the length and prefix every perpetual account has. No store read. */
22
+ export declare function isPerpAccountAddress(address: string): boolean;
15
23
  /** True when `address` has the length and prefix every margin account has. No store read. */
16
24
  export declare function isMarginAccountAddress(address: string): boolean;
17
25
  /** The owner a margin account was derived from, or null when `address` is not one. */
@@ -57,41 +57,51 @@ export declare const GAS_CONSTANTS: {
57
57
  readonly MARKET_ORDER: 145000;
58
58
  readonly TWAP_ORDER: 118000;
59
59
  readonly SCALE_ORDER_BASE: 130000;
60
- readonly SCALE_ORDER_PER_SUB: 23000;
60
+ readonly SCALE_ORDER_PER_SUB: 21000;
61
61
  readonly CANCEL_ORDER_BASE: 52000;
62
62
  readonly CANCEL_ORDER_PER_ID: 29000;
63
63
  readonly MODIFY_ORDER_PER_ID: 155000;
64
+ readonly CONDITIONAL_ORDER: 125000;
65
+ readonly MODIFY_CONDITIONAL_BASE: 55000;
66
+ readonly MODIFY_CONDITIONAL_PER_ORDER: 49000;
67
+ readonly GROUP_ORDER: 222000;
64
68
  readonly OPEN_ACCOUNT: 96000;
65
69
  readonly PERP_DEPOSIT: 250000;
66
70
  readonly PERP_WITHDRAW: 250000;
67
71
  readonly PERP_SET_MARGIN_CONFIG: 250000;
68
72
  readonly PERP_MODIFY_POSITION_MARGIN: 250000;
73
+ readonly PERP_LIQUIDATE_BASE: 100000;
74
+ readonly PERP_LIQUIDATE_PER_ACCOUNT: 1000000;
69
75
  readonly LENDING_SUPPLY: 122000;
70
76
  readonly LENDING_WITHDRAW: 115000;
71
77
  readonly LENDING_SUPPLY_COLLATERAL: 110000;
72
78
  readonly LENDING_WITHDRAW_COLLATERAL: 240000;
73
79
  readonly LENDING_BORROW: 260000;
74
80
  readonly LENDING_REPAY: 100000;
75
- readonly LENDING_LIQUIDATE: 440000;
81
+ readonly LENDING_LIQUIDATE: 430000;
76
82
  readonly LENDING_FUND_INSURANCE_FUND: 150000;
77
83
  readonly MARGIN_DEPOSIT_BASE: 88000;
78
84
  readonly MARGIN_DEPOSIT_PER_COIN: 46000;
79
85
  readonly MARGIN_WITHDRAW_BASE: 74000;
80
86
  readonly MARGIN_WITHDRAW_PER_COIN: 180000;
81
87
  readonly MARGIN_BORROW: 227000;
82
- readonly MARGIN_REPAY: 92000;
88
+ readonly MARGIN_REPAY: 259000;
83
89
  readonly VAULT_CREATE_TRADING_BASE: 190000;
84
- readonly VAULT_CREATE_PER_MARKET: 10000;
90
+ readonly VAULT_CREATE_PER_MARKET: 9000;
85
91
  readonly VAULT_CREATE_LENDING_BASE: 124000;
86
- readonly VAULT_CREATE_PER_LENDING_POOL: 1700;
87
- readonly VAULT_UPDATE_MANAGER: 130000;
88
- readonly VAULT_UPDATE_CONFIG: 1650000;
92
+ readonly VAULT_CREATE_PER_LENDING_POOL: 2000;
93
+ readonly VAULT_UPDATE_MANAGER: 95000;
94
+ readonly VAULT_UPDATE_CONFIG_TRADING_BASE: 85000;
95
+ readonly VAULT_UPDATE_CONFIG_PER_MARKET: 9000;
96
+ readonly VAULT_UPDATE_CONFIG_LENDING_BASE: 100000;
97
+ readonly VAULT_UPDATE_CONFIG_PER_POOL: 5000;
89
98
  readonly VAULT_CANCEL_CONFIG_UPDATE: 75000;
90
99
  readonly VAULT_SET_STATUS: 78000;
91
- readonly VAULT_DEPOSIT: 2000000;
92
- readonly VAULT_REDEEM: 2000000;
93
- readonly VAULT_TRANSFER: 65000;
94
- readonly VAULT_REALLOCATE: 145000;
100
+ readonly VAULT_DEPOSIT: 260000;
101
+ readonly VAULT_REDEEM: 260000;
102
+ readonly VAULT_TRANSFER: 75000;
103
+ readonly VAULT_BACKSTOP_TRANSFER: 110000;
104
+ readonly VAULT_REALLOCATE: 160000;
95
105
  readonly DELEGATE: 220000;
96
106
  readonly UNDELEGATE: 260000;
97
107
  readonly BEGIN_REDELEGATE: 400000;
@@ -42,3 +42,11 @@ export declare function buildModifyPositionMarginMsg(sender: string, params: {
42
42
  marketId: Uint8Array;
43
43
  marginDelta: string;
44
44
  }): import("../index.js").Eip712Msg<import("../proto/gen/ault/perpetual/v1/tx").MsgModifyPositionMargin, "/ault.perpetual.v1.MsgModifyPositionMargin">;
45
+ /**
46
+ * Liquidates perpetual accounts below maintenance (chain v3.0.0-rc.3, open to
47
+ * any sender). `accounts` are derived perpetual accounts (32-byte bech32 or
48
+ * 0x); the chain wants them unique and sorted by their bytes, which this does.
49
+ * At most the module's `max_liquidation_candidates` per message. Not
50
+ * fee-free: the ante charges 100,000 gas plus 1,000,000 per account.
51
+ */
52
+ export declare function buildPerpLiquidateMsg(sender: string, accounts: string[]): import("../index.js").Eip712Msg<import("../proto/gen/ault/perpetual/v1/tx").MsgLiquidate, "/ault.perpetual.v1.MsgLiquidate">;
@@ -1,8 +1,10 @@
1
1
  import { type GAS_CONSTANTS } from "./network";
2
2
  import type { VaultConfigInput } from "./vault-msgs";
3
3
  type Gas = typeof GAS_CONSTANTS;
4
- type VaultGasKey = "VAULT_UPDATE_MANAGER" | "VAULT_UPDATE_CONFIG" | "VAULT_CANCEL_CONFIG_UPDATE" | "VAULT_SET_STATUS" | "VAULT_DEPOSIT" | "VAULT_REDEEM" | "VAULT_TRANSFER" | "VAULT_REALLOCATE";
4
+ type VaultGasKey = "VAULT_UPDATE_MANAGER" | "VAULT_CANCEL_CONFIG_UPDATE" | "VAULT_SET_STATUS" | "VAULT_DEPOSIT" | "VAULT_REDEEM" | "VAULT_TRANSFER" | "VAULT_BACKSTOP_TRANSFER" | "VAULT_REALLOCATE";
5
5
  export declare function vaultGas(gas: Gas, key: VaultGasKey): string;
6
6
  /** A trading vault pays per allowed spot market, a lending vault per pool. */
7
7
  export declare function createVaultGas(gas: Gas, config: VaultConfigInput): string;
8
+ /** A config update pays per spot market (trading) or per pool (lending), like creation. */
9
+ export declare function updateVaultConfigGas(gas: Gas, config: VaultConfigInput): string;
8
10
  export {};