ault-sdk-ts 0.8.0 → 0.10.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.
Files changed (91) hide show
  1. package/README.md +267 -51
  2. package/dist/agent/attach.d.ts +10 -1
  3. package/dist/agent/sign-and-broadcast.d.ts +2 -2
  4. package/dist/agent/tx/perpetual.d.ts +10 -0
  5. package/dist/agent/tx/vault.d.ts +11 -0
  6. package/dist/client.d.ts +10 -0
  7. package/dist/core/address.d.ts +6 -0
  8. package/dist/core/clob-msgs.d.ts +21 -3
  9. package/dist/core/lending-gas.d.ts +5 -0
  10. package/dist/core/lending-msgs.d.ts +52 -0
  11. package/dist/core/manifest-types.d.ts +60 -0
  12. package/dist/core/margin-account.d.ts +18 -0
  13. package/dist/core/margin-gas.d.ts +7 -0
  14. package/dist/core/margin-msgs.d.ts +52 -0
  15. package/dist/core/network.d.ts +37 -7
  16. package/dist/core/perpetual-gas.d.ts +12 -0
  17. package/dist/core/perpetual-msgs.d.ts +44 -0
  18. package/dist/core/vault-gas.d.ts +8 -0
  19. package/dist/core/vault-msgs.d.ts +150 -0
  20. package/dist/eip712/msg-encoders.generated.d.ts +8 -0
  21. package/dist/eip712/msg.generated.d.ts +51 -68
  22. package/dist/eip712/registry.d.ts +17 -0
  23. package/dist/eip712/types.d.ts +5 -0
  24. package/dist/high-level/tx/lending.d.ts +3 -0
  25. package/dist/high-level/tx/license.d.ts +1 -1
  26. package/dist/high-level/tx/margin.d.ts +3 -0
  27. package/dist/high-level/tx/perpetual.d.ts +3 -0
  28. package/dist/high-level/tx/vault.d.ts +3 -0
  29. package/dist/high-level/types.d.ts +280 -152
  30. package/dist/index.cjs +23569 -12952
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +9 -0
  33. package/dist/index.js +23364 -13023
  34. package/dist/index.js.map +1 -1
  35. package/dist/perp/decimal.d.ts +39 -0
  36. package/dist/perp/funding.d.ts +18 -0
  37. package/dist/perp/index.d.ts +5 -0
  38. package/dist/perp/margin.d.ts +33 -0
  39. package/dist/perp/orders.d.ts +27 -0
  40. package/dist/perp/position.d.ts +29 -0
  41. package/dist/proto/gen/ault/accountx/v1/query.d.ts +10 -1
  42. package/dist/proto/gen/ault/authority/v1/authority.d.ts +2 -0
  43. package/dist/proto/gen/ault/clob/v1/genesis.d.ts +7 -0
  44. package/dist/proto/gen/ault/clob/v1/twap.d.ts +11 -8
  45. package/dist/proto/gen/ault/clob/v1/tx.d.ts +11 -1
  46. package/dist/proto/gen/ault/common/v1/system.d.ts +31 -0
  47. package/dist/proto/gen/ault/lending/v1/genesis.d.ts +34 -0
  48. package/dist/proto/gen/ault/lending/v1/lending.d.ts +152 -0
  49. package/dist/proto/gen/ault/lending/v1/params.d.ts +42 -0
  50. package/dist/proto/gen/ault/lending/v1/query.d.ts +157 -0
  51. package/dist/proto/gen/ault/lending/v1/tx.d.ts +236 -0
  52. package/dist/proto/gen/ault/margin/v1/genesis.d.ts +102 -0
  53. package/dist/proto/gen/ault/margin/v1/margin.d.ts +130 -0
  54. package/dist/proto/gen/ault/margin/v1/params.d.ts +31 -0
  55. package/dist/proto/gen/ault/margin/v1/query.d.ts +127 -0
  56. package/dist/proto/gen/ault/margin/v1/tx.d.ts +181 -0
  57. package/dist/proto/gen/ault/market/v1/market.d.ts +9 -0
  58. package/dist/proto/gen/ault/market/v1/tx.d.ts +16 -0
  59. package/dist/proto/gen/ault/oracle/v1/genesis.d.ts +69 -0
  60. package/dist/proto/gen/ault/oracle/v1/oracle.d.ts +154 -0
  61. package/dist/proto/gen/ault/oracle/v1/query.d.ts +93 -0
  62. package/dist/proto/gen/ault/oracle/v1/tx.d.ts +151 -0
  63. package/dist/proto/gen/ault/perpetual/v1/genesis.d.ts +119 -0
  64. package/dist/proto/gen/ault/perpetual/v1/order.d.ts +46 -0
  65. package/dist/proto/gen/ault/perpetual/v1/params.d.ts +30 -0
  66. package/dist/proto/gen/ault/perpetual/v1/perpetual.d.ts +192 -0
  67. package/dist/proto/gen/ault/perpetual/v1/query.d.ts +150 -0
  68. package/dist/proto/gen/ault/perpetual/v1/tx.d.ts +97 -0
  69. package/dist/proto/gen/ault/systemtx/v1/genesis.d.ts +37 -0
  70. package/dist/proto/gen/ault/vault/v1/genesis.d.ts +90 -0
  71. package/dist/proto/gen/ault/vault/v1/params.d.ts +55 -0
  72. package/dist/proto/gen/ault/vault/v1/query.d.ts +152 -0
  73. package/dist/proto/gen/ault/vault/v1/tx.d.ts +194 -0
  74. package/dist/proto/gen/ault/vault/v1/vault.d.ts +227 -0
  75. package/dist/rest/dex-types.generated.d.ts +2045 -27
  76. package/dist/rest/dex.d.ts +52 -2
  77. package/dist/rest/dex.generated.d.ts +5097 -1276
  78. package/dist/rest/lending.d.ts +46 -0
  79. package/dist/rest/margin.d.ts +33 -0
  80. package/dist/rest/oracle.d.ts +19 -0
  81. package/dist/rest/pagination.d.ts +6 -2
  82. package/dist/rest/perpetual.d.ts +46 -0
  83. package/dist/rest/portfolio.d.ts +32 -0
  84. package/dist/rest/tokenregistry.d.ts +7 -0
  85. package/dist/rest/vault.d.ts +26 -0
  86. package/dist/utils/cosmos-dec.d.ts +1 -0
  87. package/package.json +1 -1
  88. package/dist/high-level/tx/authority.d.ts +0 -3
  89. package/dist/high-level/tx/market.d.ts +0 -3
  90. package/dist/high-level/tx/ratelimit.d.ts +0 -3
  91. package/dist/high-level/tx/tokenregistry.d.ts +0 -3
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Ault SDK for TypeScript
2
2
 
3
- A TypeScript SDK for the Ault blockchain that provides high-level transaction methods and REST query clients for the current Ault modules, including License, Miner, Market, CLOB, Agent, Authority, RateLimit, Reward, and TokenRegistry.
3
+ A TypeScript SDK for the Ault blockchain that provides high-level transaction methods and REST query clients for the current Ault modules, including CLOB, Perpetual, Lending, Margin, Vault, Agent, License, Miner, Reward and Staking, plus read-only clients for Market, Oracle, Authority, RateLimit and TokenRegistry.
4
+
5
+ The SDK only builds messages a user or a vault manager signs. Governance, `x/authority` and role-gated messages (market creation and halts, oracle feeds, token pairs, license minting, every `MsgUpdateParams`, Lending pool administration, ...) are not part of it.
4
6
 
5
7
  ## Features
6
8
 
@@ -340,6 +342,267 @@ const tokenPair = await client.tokenregistry.getTokenPair(
340
342
  "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
341
343
  );
342
344
  const tokenPairs = await client.tokenregistry.getTokenPairs();
345
+
346
+ // Perpetual queries (chain v3)
347
+ const collateralDenom = await client.perpetual.getCollateralDenom();
348
+ const crossAccount = await client.perpetual.getAccount(client.address);
349
+ const risk = await client.perpetual.getAccountRisk(client.address);
350
+ const position = await client.perpetual.getPosition(client.address, marketId, true);
351
+ const funding = await client.perpetual.getFunding(marketId);
352
+ const prices = await client.perpetual.getPrices(marketId);
353
+ const impactPrices = await client.perpetual.getImpactPrices(marketId);
354
+ ```
355
+
356
+ ## Perpetual markets
357
+
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:
362
+
363
+ ```typescript
364
+ import { iocLimitPrice } from "ault-sdk-ts";
365
+
366
+ const book = await client._lowLevel.rest.dex.getPerpOrderbook(marketIdHex, { depth: 5 });
367
+ const { price } = iocLimitPrice({
368
+ side: "buy",
369
+ bestAsk: book.data.asks[0]?.[0],
370
+ bestBid: book.data.bids[0]?.[0],
371
+ slippage: "0.005",
372
+ priceDecimals: 2,
373
+ });
374
+ await client.placeLimitOrder({
375
+ marketId,
376
+ isBuy: true,
377
+ price,
378
+ quantity: "1",
379
+ deadline: new Date(Date.now() + 60_000),
380
+ timeInForce: "ioc",
381
+ reduceOnly: false,
382
+ });
383
+ ```
384
+
385
+ Collateral lives in a per-owner cross account in the chain's single
386
+ collateral denom; isolated markets get their own derived account. Margin mode
387
+ and leverage are set per market and cannot change while a position or resting
388
+ order exists:
389
+
390
+ ```typescript
391
+ await client.depositPerpCollateral({ amount: "1000000000" }); // base units
392
+ await client.setMarginConfig({ marketId, leverage: 10, cross: true });
393
+ await client.modifyPositionMargin({ marketId, marginDelta: "-500000" }); // isolated only
394
+ await client.withdrawPerpCollateral({ amount: "250000000" });
395
+ ```
396
+
397
+ The same four collateral and margin methods exist on `client.asAgent` after `attachAgent`. Read
398
+ models (markets, tickers with mark and funding, positions, fills, ledger) come
399
+ from the DEX API's `/api/v1/perp` endpoints, `listPerpMarkets` through
400
+ `listPerpCloseouts` on `createDexApi`. `src/perp` ports the chain's margin-tier,
401
+ funding and position math (`maintenanceMargin`, `initialMargin`, `equity`,
402
+ `fundingRate`, ...) with the chain's rounding for client-side previews.
403
+
404
+ ## Lending
405
+
406
+ Lending pools take supplies, collateral and borrows per denom. Every amount is
407
+ a coin in the denom's base units; the chain converts to shares. These methods
408
+ move the signer's own funds, so they are wallet-signed only (never by an
409
+ agent).
410
+
411
+ ```typescript
412
+ const usdc = { denom: "erc20:0xd157...", amount: "1000000000" }; // base units
413
+ const weth = { denom: "erc20:0xcC4a...", amount: "500000000000000000" };
414
+
415
+ await client.lendingSupply({ poolId: 1, coin: usdc }); // earns the supply rate
416
+ await client.lendingSupplyCollateral({ poolId: 1, coin: weth }); // backs borrows, earns nothing
417
+ await client.lendingBorrow({ poolId: 1, coin: usdc });
418
+ await client.lendingRepay({ poolId: 1, coin: usdc }); // `borrower` repays someone else's debt
419
+ await client.lendingWithdrawCollateral({ poolId: 1, coin: weth });
420
+ await client.lendingWithdraw({ poolId: 1, coin: usdc });
421
+
422
+ // Liquidating an unhealthy position repays part of its debt and seizes
423
+ // collateral plus the pool's bonus.
424
+ await client.lendingLiquidate({
425
+ poolId: 1,
426
+ borrower: "ault1...",
427
+ repay: usdc,
428
+ seizeDenom: weth.denom,
429
+ });
430
+ ```
431
+
432
+ Reads come from two places. The DEX API (`getLendingParams` through
433
+ `getLendingProtocolRevenue` on `createDexApi`) serves pools, assets, rates,
434
+ APYs, positions with health, history and liquidations. `client.lending`
435
+ queries the chain directly, which is what you want right before a withdrawal
436
+ and the only source for scheduled asset updates (`getPendingAssetUpdates`).
437
+
438
+ Two things to handle in a UI. Health and valuation fields are null when
439
+ `healthError` is set: the chain fails the whole health read if one oracle
440
+ price is stale, so show "unavailable" rather than zero. And debt includes
441
+ accrued interest; the chain has no separate interest figure.
442
+
443
+ ## Margin
444
+
445
+ A margin order is an ordinary spot order funded from a margin account instead
446
+ of the bank balance. Each owner has one cross account and one isolated
447
+ account per market, both derived from the owner's address, and their
448
+ collateral and debt live in the margin Lending pool.
449
+
450
+ ```typescript
451
+ import { marginAccountAddress } from "ault-sdk-ts";
452
+
453
+ // Fund the isolated account of a market (omit marketId for the cross account).
454
+ await client.depositMargin({ marketId, amount: [usdc] });
455
+
456
+ // Open a long: buy with borrowed quote. autoBorrow borrows the shortfall
457
+ // between the order's escrow and the account's free collateral.
458
+ await client.placeLimitOrder({
459
+ marketId,
460
+ isBuy: true,
461
+ price: "3500",
462
+ quantity: "0.5",
463
+ deadline: new Date(Date.now() + 3_600_000),
464
+ margin: { autoBorrow: true },
465
+ });
466
+
467
+ // Close it: the sell's proceeds come in as quote, so autoRepay pays the quote
468
+ // debt back out of them.
469
+ await client.placeLimitOrder({
470
+ marketId,
471
+ isBuy: false,
472
+ price: "3600",
473
+ quantity: "0.5",
474
+ deadline: new Date(Date.now() + 3_600_000),
475
+ margin: { autoRepay: true },
476
+ });
477
+
478
+ // Manual borrow/repay and withdrawal work on the same account.
479
+ await client.repayMargin({ marketId, amount: usdc });
480
+ await client.withdrawMargin({ marketId, amount: [usdc] });
481
+
482
+ // Orders and fills of a margin account are read with its derived address.
483
+ const account = marginAccountAddress(client.address, marketIdHex);
484
+ const orders = await dex.listOrders({ address: account, status: "open" });
485
+ ```
486
+
487
+ `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
492
+ `getMarginPosition` reports `maxTransferable` per denom; that, not `free`, is
493
+ what a withdrawal can take.
494
+
495
+ `autoRepay` pays same-denom debt out of a fill's proceeds. A buy that
496
+ borrowed quote gets base back, so the flag does nothing on that buy; put it on
497
+ the sell that closes the position, whose proceeds come in as quote.
498
+ `autoRepayAtCancel` goes on the order that borrows: when that order is
499
+ cancelled or shrunk, the chain repays what the order itself borrowed, so an
500
+ auto-borrowed order that never filled leaves no debt behind. Without it the
501
+ borrow stays until you repay it.
502
+
503
+ With `cross: true` the order is funded from the owner's cross account. There
504
+ is one per owner, `marginAccountAddress(owner)` with no market id, and it is
505
+ the account `depositMargin` funds when you leave `marketId` out. An isolated
506
+ account holds only its market's two denoms. The cross account can hold any
507
+ collateral the margin pool accepts and backs orders on every margin market. A
508
+ cross `borrowMargin` also has no receive-asset cap, which an isolated one does.
509
+
510
+ A margin account is liquidated like any other Lending borrower once its
511
+ health factor drops below 1: call `lendingLiquidate` with the derived account
512
+ as `borrower`. The chain cancels the account's resting orders before it seizes
513
+ collateral. The pool's minimum residual debt (1000 USD in the e2e setup) only
514
+ matters here. If a liquidation would leave less debt than that, it has to
515
+ repay all of it, or the chain rejects it with "residual debt below minimum".
516
+
517
+ ## Vaults
518
+
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.
520
+
521
+ Depositors put a vault's denom in and get shares; the vault's manager trades
522
+ (trading vaults) or allocates across Lending pools (lending vaults) with it.
523
+
524
+ ```typescript
525
+ await client.depositToVault({ vaultAddress, amount: usdc });
526
+ // Shares are raw units, 10^18 per share. The redemption settles at once when
527
+ // the vault has idle funds, otherwise it is queued.
528
+ await client.redeemFromVault({ vaultAddress, shares: "1000000000000000000" });
529
+ ```
530
+
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:
535
+
536
+ ```typescript
537
+ const agent = client.attachAgent({ agentPrivateKey });
538
+ await agent.createVault({
539
+ vaultDenom: usdc.denom,
540
+ config: {
541
+ lending: {
542
+ pools: [{ poolId: 1, supplyCap: "5000000000" }],
543
+ supplyQueue: [1],
544
+ withdrawalQueue: [1],
545
+ },
546
+ },
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.
551
+ });
552
+ ```
553
+
554
+ Some messages go out from the vault's own account. `attachVaultManager`
555
+ builds a surface for them, signed by whoever controls the vault (or that
556
+ key's registered agent): the manager for a normal or parent vault, the
557
+ parent's manager for a child vault. What x/vault accepts depends on the kind
558
+ of vault:
559
+
560
+ - A normal trading vault or a child vault can place, modify and cancel
561
+ orders on its configured spot markets. TWAP orders are rejected.
562
+ - A normal lending vault can move supply between its pools with
563
+ `reallocateVault`.
564
+ - 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.
567
+
568
+ Parent vaults belong to x/gov, so only a governance proposal can create one.
569
+
570
+ ```typescript
571
+ const lendingVault = client.attachVaultManager({ vaultAddress, agentPrivateKey: managerKey });
572
+ await lendingVault.reallocateVault({ sourcePoolId: 1, destinationPoolId: 2, amount: usdc });
573
+
574
+ // The parent's manager runs the parent and its children.
575
+ const parent = client.attachVaultManager({
576
+ vaultAddress: parentVault,
577
+ agentPrivateKey: managerKey,
578
+ });
579
+ await parent.transferChildVault({ childVault, amount: usdc, isDeposit: true });
580
+ const child = client.attachVaultManager({ vaultAddress: childVault, agentPrivateKey: managerKey });
581
+ await child.placeLimitOrder({ marketId, isBuy: true, price: "3500", quantity: "1", deadline });
582
+ ```
583
+
584
+ Status changes and config updates come from the vault's owner, not its
585
+ 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,
588
+ and addresses that can't be vault accounts (or must be).
589
+
590
+ The DEX API serves the vault directory, details with the caller's position
591
+ (`getVault(address, { user })`), activity, redemptions and a user's positions
592
+ across vaults (`getPortfolioVaults`). TVL, share price, APR and APY stay null
593
+ until the vault worker has run. These feeds wrap their rows in an object, so
594
+ walk them with a row selector:
595
+
596
+ ```typescript
597
+ import { paginate } from "ault-sdk-ts";
598
+
599
+ for await (const page of paginate(
600
+ (p) => dex.listVaults(p),
601
+ {},
602
+ (body) => body.vaults,
603
+ )) {
604
+ // page.rows
605
+ }
343
606
  ```
344
607
 
345
608
  ## DEX API
@@ -662,45 +925,16 @@ Transactions](#market-and-clob-transactions).
662
925
  ### License Transactions
663
926
 
664
927
  ```typescript
665
- // Mint a license
666
- await client.mintLicense({
667
- to: "0x...", // EVM or ault1 address
668
- uri: "https://example.com/metadata.json",
669
- reason: "Minted via SDK", // Optional, defaults to ""
670
- });
671
-
672
- // Batch mint
673
- await client.batchMintLicense({
674
- recipients: [
675
- { to: "0xAddr1...", uri: "https://example.com/1.json" },
676
- { to: "0xAddr2...", uri: "https://example.com/2.json" },
677
- ],
678
- });
679
-
680
- // Transfer
681
928
  await client.transferLicense({
682
929
  licenseId: 123, // bigint, number, or string
683
930
  to: "0x...",
684
931
  });
685
-
686
- // Burn/Revoke (admin only)
687
- await client.burnLicense({ licenseId: 123 });
688
- await client.revokeLicense({ licenseId: 123 });
689
-
690
- // KYC management
691
- await client.approveMember({ member: "0x..." });
692
- await client.revokeMember({ member: "0x..." });
693
- await client.batchApproveMember({ members: ["0x...", "0x..."] });
694
-
695
- // Admin functions
696
- await client.setMinters({ add: ["0x..."], remove: [] });
697
- await client.setKYCApprovers({ add: ["0x..."], remove: [] });
698
932
  ```
699
933
 
700
934
  ### Miner Transactions
701
935
 
702
936
  ```typescript
703
- import { base64ToBytes, MarketType } from "ault-sdk-ts";
937
+ import { base64ToBytes } from "ault-sdk-ts";
704
938
 
705
939
  // Delegate licenses to an operator
706
940
  await client.delegateMining({
@@ -814,17 +1048,9 @@ await client.cancelOrders({ orderIds: [cloid] });
814
1048
  // Live orders resolve from the chain; filled/cancelled ones from the indexer.
815
1049
  const found = await client.findOrderByCloid(client.address, cloid);
816
1050
  if (found.source !== "none") console.log(found.source, found.order);
817
-
818
- // Create a market
819
- await client.createMarket({
820
- marketType: MarketType.MARKET_TYPE_SPOT,
821
- baseDenom: "uatom",
822
- quoteDenom: "uusdc",
823
- tickPrecision: 6,
824
- });
825
1051
  ```
826
1052
 
827
- ### Reward And TokenRegistry Transactions
1053
+ ### Reward Transactions
828
1054
 
829
1055
  ```typescript
830
1056
  // Create a referral code as an eligible referrer
@@ -837,16 +1063,6 @@ await client.approveBuilder({
837
1063
  builder: "0x0000000000000000000000000000000000000001",
838
1064
  maxFeeRate: "0.005",
839
1065
  });
840
-
841
- // Register an ERC20 token pair
842
- await client.registerTokenPair({
843
- erc20Address: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
844
- enabled: true,
845
- });
846
-
847
- // Toggle module-wide token conversions
848
- await client.disableTokenRegistryTransfers();
849
- await client.enableTokenRegistryTransfers();
850
1066
  ```
851
1067
 
852
1068
  ### Transaction Options
@@ -1020,7 +1236,7 @@ Note: `pnpm gen:eip712` also reads Cosmos SDK protos (staking/distribution) and
1020
1236
  import { ApiError, NetworkError, TimeoutError } from "ault-sdk-ts";
1021
1237
 
1022
1238
  try {
1023
- const result = await client.mintLicense({ to: "0x...", uri: "..." });
1239
+ const result = await client.transferLicense({ licenseId: 1, to: "0x..." });
1024
1240
  if (result.success) {
1025
1241
  console.log(`Transaction committed: ${result.txHash}`);
1026
1242
  } else if (result.confirmed === false) {
@@ -1,7 +1,7 @@
1
1
  import type { AccountCache } from "../eip712/sign-and-broadcast";
2
2
  import type { FetchFn, FetchWithRetryOptions } from "../core/http";
3
3
  import type { GAS_CONSTANTS, NetworkConfig } from "../core/network";
4
- import type { AgentSurface, AttachAgentOptions } from "../high-level/types";
4
+ import type { AgentSurface, AttachAgentOptions, AttachVaultManagerOptions, VaultManagerSurface } from "../high-level/types";
5
5
  export { AGENT_DEFAULTS } from "./sign-and-broadcast";
6
6
  /**
7
7
  * Derives the agent's bech32 address from its private key. Mirrors the
@@ -24,3 +24,12 @@ export interface BuildAgentSurfaceContext {
24
24
  * fetch or a duplicate account RPC.
25
25
  */
26
26
  export declare function buildAgentSurface(options: AttachAgentOptions, ctx: BuildAgentSurfaceContext): AgentSurface;
27
+ export type BuildVaultManagerSurfaceContext = Omit<BuildAgentSurfaceContext, "masterAddress" | "cache">;
28
+ /**
29
+ * Builds the surface a vault manager uses to act as the vault. Every message
30
+ * names the vault as its account; x/vault's account control accepts the
31
+ * manager's key (or the manager's registered agent) as the signer, and the
32
+ * agent ante signs with the vault's account number. The vault gets its own
33
+ * account cache: it is a different account from the client's master.
34
+ */
35
+ export declare function buildVaultManagerSurface(options: AttachVaultManagerOptions, ctx: BuildVaultManagerSurfaceContext): VaultManagerSurface;
@@ -3,8 +3,8 @@ import type { AnyEip712Msg } from "../eip712/builder";
3
3
  import { type FetchFn, type FetchWithRetryOptions } from "../core/http";
4
4
  import type { NetworkConfig } from "../core/network";
5
5
  export declare const AGENT_DEFAULTS: {
6
- readonly GAS_LIMIT: "147600";
7
- readonly TIMEOUT_SECONDS: 300;
6
+ readonly GAS_LIMIT: "186000";
7
+ readonly TIMEOUT_SECONDS: 120;
8
8
  readonly EXTENSION_TYPE_URL: "/ault.agent.v1.ExtensionOptionsAgentTx";
9
9
  readonly PUBKEY_TYPE_URL: "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey";
10
10
  };
@@ -0,0 +1,10 @@
1
+ import type { GAS_CONSTANTS } from "../../core/network";
2
+ import type { AgentPerpetualTxApi } from "../../high-level/types";
3
+ import type { AgentTxExecutor } from "../tx-executor";
4
+ export interface AgentPerpetualTxContext {
5
+ masterAddress: string;
6
+ exec: AgentTxExecutor;
7
+ /** Current gas constants (base overlaid with manifest overrides); read per call. */
8
+ getGas: () => typeof GAS_CONSTANTS;
9
+ }
10
+ export declare function createAgentPerpetualTxApi({ masterAddress, exec, getGas, }: AgentPerpetualTxContext): AgentPerpetualTxApi;
@@ -0,0 +1,11 @@
1
+ import type { GAS_CONSTANTS } from "../../core/network";
2
+ import type { AgentVaultTxApi, VaultAccountTxApi } from "../../high-level/types";
3
+ import type { AgentTxExecutor } from "../tx-executor";
4
+ export interface AgentVaultTxContext {
5
+ /** The message account: the master on `asAgent`, the vault on a manager surface. */
6
+ masterAddress: string;
7
+ exec: AgentTxExecutor;
8
+ getGas: () => typeof GAS_CONSTANTS;
9
+ }
10
+ export declare function createAgentVaultTxApi({ masterAddress, exec, getGas, }: AgentVaultTxContext): AgentVaultTxApi;
11
+ export declare function createVaultAccountTxApi({ masterAddress: vaultAddress, exec, getGas, }: AgentVaultTxContext): VaultAccountTxApi;
package/dist/client.d.ts CHANGED
@@ -5,9 +5,13 @@ import { type AgentApi } from "./rest/agent";
5
5
  import { type AuthorityApi } from "./rest/authority";
6
6
  import { type BankApi } from "./rest/bank";
7
7
  import { type ClobApi } from "./rest/clob";
8
+ import { type LendingApi } from "./rest/lending";
8
9
  import { type LicenseApi } from "./rest/license";
10
+ import { type MarginApi } from "./rest/margin";
9
11
  import { type MarketApi } from "./rest/market";
10
12
  import { type MinerApi } from "./rest/miner";
13
+ import { type OracleApi } from "./rest/oracle";
14
+ import { type PerpetualApi } from "./rest/perpetual";
11
15
  import { type RateLimitApi } from "./rest/ratelimit";
12
16
  import { type RewardApi } from "./rest/reward";
13
17
  import { type StakingApi } from "./rest/staking";
@@ -15,6 +19,7 @@ import { type DexApi } from "./rest/dex";
15
19
  import { DexWsClient } from "./ws/client";
16
20
  import type { DexWsOptions } from "./ws/types";
17
21
  import { type TokenRegistryApi } from "./rest/tokenregistry";
22
+ import { type VaultApi } from "./rest/vault";
18
23
  import type { AnyEip712Msg, Eip712TxContext } from "./eip712/builder";
19
24
  import type { SignAndBroadcastParams, SignAndBroadcastResult } from "./eip712/sign-and-broadcast";
20
25
  import { EIP712_MSG_TYPES } from "./eip712/registry";
@@ -36,14 +41,19 @@ export interface AultClient {
36
41
  authority: AuthorityApi;
37
42
  bank: BankApi;
38
43
  clob: ClobApi;
44
+ lending: LendingApi;
39
45
  license: LicenseApi;
46
+ margin: MarginApi;
40
47
  market: MarketApi;
41
48
  miner: MinerApi;
49
+ oracle: OracleApi;
50
+ perpetual: PerpetualApi;
42
51
  ratelimit: RateLimitApi;
43
52
  reward: RewardApi;
44
53
  staking: StakingApi;
45
54
  dex: DexApi;
46
55
  tokenregistry: TokenRegistryApi;
56
+ vault: VaultApi;
47
57
  };
48
58
  ws: DexWsClient;
49
59
  eip712: {
@@ -4,6 +4,12 @@ export type BigIntLike = bigint | number | string;
4
4
  * Accepts: 0x... EVM address or ault1... bech32 address
5
5
  */
6
6
  export declare function normalizeAddress(address: string): string;
7
+ /**
8
+ * Like {@link normalizeAddress}, but also accepts the 32-byte module-derived
9
+ * accounts (margin, perpetual and vault accounts) that hold Lending positions
10
+ * of their own.
11
+ */
12
+ export declare function normalizeAccountAddress(address: string): string;
7
13
  /**
8
14
  * Normalize an array of addresses.
9
15
  */
@@ -1,3 +1,4 @@
1
+ import { type MarginOrderOptions } from "./margin-msgs";
1
2
  export declare function buildLimitOrderMsg(sender: string, params: {
2
3
  marketId: Uint8Array;
3
4
  isBuy: boolean;
@@ -9,7 +10,20 @@ export declare function buildLimitOrderMsg(sender: string, params: {
9
10
  builderAddress?: string;
10
11
  builderFeeRate?: string;
11
12
  cloid?: Uint8Array;
12
- }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "builderFeeRate" | "cloid" | "postOnly" | "timeInForce" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "builderFeeRate" | "cloid" | "postOnly" | "timeInForce" | "builderAddress">>, "/ault.clob.v1.MsgPlaceLimitOrder">;
13
+ /**
14
+ * Perpetual markets only. The chain requires the `PerpetualOrderOptions`
15
+ * Any on every perp order, so pass `false` for a plain perp order and
16
+ * `true` to only shrink the position. Leave it undefined on spot markets,
17
+ * which reject the options.
18
+ */
19
+ reduceOnly?: boolean;
20
+ /**
21
+ * Spot markets only: fund the order from the owner's margin account
22
+ * (Lending collateral, optionally auto-borrowing the shortfall) instead
23
+ * of the bank balance.
24
+ */
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">;
13
27
  /**
14
28
  * TWAP order (chain v2.1.0+). `deadline` is the absolute end of the execution
15
29
  * window; the chain runs one slice every 30s until then. `totalDeposit` must
@@ -35,7 +49,9 @@ export declare function buildMarketOrderMsg(sender: string, params: {
35
49
  builderAddress?: string;
36
50
  builderFeeRate?: string;
37
51
  cloid?: Uint8Array;
38
- }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "builderFeeRate" | "worstPrice" | "priceTolerance" | "cloid" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "builderFeeRate" | "worstPrice" | "priceTolerance" | "cloid" | "builderAddress">>, "/ault.clob.v1.MsgPlaceMarketOrder">;
52
+ /** Spot markets only; see `buildLimitOrderMsg`. */
53
+ 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">;
39
55
  /** Each `orderIds` entry may be an 8-byte cloid or a 16-byte chain order_id. */
40
56
  export declare function buildCancelOrdersMsg(sender: string, orderIds: Uint8Array[]): import("../index.js").Eip712Msg<import("../proto/gen/ault/clob/v1/tx").MsgCancelOrders, "/ault.clob.v1.MsgCancelOrders">;
41
57
  /**
@@ -73,4 +89,6 @@ export declare function buildScaleOrderMsg(sender: string, params: {
73
89
  postOnly?: boolean;
74
90
  builderAddress?: string;
75
91
  builderFeeRate?: string;
76
- }): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceScaleOrder, "builderFeeRate" | "postOnly" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceScaleOrder, "builderFeeRate" | "postOnly" | "builderAddress">>, "/ault.clob.v1.MsgPlaceScaleOrder">;
92
+ /** Perpetual markets only; see `buildLimitOrderMsg`. */
93
+ 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">;
@@ -0,0 +1,5 @@
1
+ import { type GAS_CONSTANTS } from "./network";
2
+ type Gas = typeof GAS_CONSTANTS;
3
+ type LendingGasKey = "LENDING_SUPPLY" | "LENDING_WITHDRAW" | "LENDING_SUPPLY_COLLATERAL" | "LENDING_WITHDRAW_COLLATERAL" | "LENDING_BORROW" | "LENDING_REPAY" | "LENDING_LIQUIDATE";
4
+ export declare function lendingGas(gas: Gas, key: LendingGasKey): string;
5
+ export {};
@@ -0,0 +1,52 @@
1
+ import type { Coin } from "../proto/gen/cosmos/base/v1beta1/coin";
2
+ /** A Lending pool id; the dex-api returns it as a decimal string. */
3
+ export type LendingPoolId = bigint | number | string;
4
+ /** Supplies `coin` to a pool's lending side; it earns the supply rate and can be borrowed. */
5
+ export declare function buildLendingSupplyMsg(supplier: string, params: {
6
+ poolId: LendingPoolId;
7
+ coin: Coin;
8
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgSupply, "/ault.lending.v1.MsgSupply">;
9
+ /** Withdraws supplied `coin` from a pool. Fails when the pool lacks the liquidity. */
10
+ export declare function buildLendingWithdrawMsg(supplier: string, params: {
11
+ poolId: LendingPoolId;
12
+ coin: Coin;
13
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgWithdraw, "/ault.lending.v1.MsgWithdraw">;
14
+ /** Posts `coin` as collateral in a pool. Collateral earns nothing and is not lent out. */
15
+ export declare function buildSupplyCollateralMsg(supplier: string, params: {
16
+ poolId: LendingPoolId;
17
+ coin: Coin;
18
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgSupplyCollateral, "/ault.lending.v1.MsgSupplyCollateral">;
19
+ /** Withdraws collateral. The chain refuses it when the position would become unhealthy. */
20
+ export declare function buildWithdrawCollateralMsg(supplier: string, params: {
21
+ poolId: LendingPoolId;
22
+ coin: Coin;
23
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgWithdrawCollateral, "/ault.lending.v1.MsgWithdrawCollateral">;
24
+ /** Borrows `coin` against the sender's collateral in the pool. */
25
+ export declare function buildBorrowMsg(borrower: string, params: {
26
+ poolId: LendingPoolId;
27
+ coin: Coin;
28
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgBorrow, "/ault.lending.v1.MsgBorrow">;
29
+ /**
30
+ * Repays debt in `coin`'s denom. `borrower` defaults to the payer; set it to
31
+ * repay someone else's debt, including a 32-byte margin or vault account's.
32
+ */
33
+ export declare function buildRepayMsg(payer: string, params: {
34
+ poolId: LendingPoolId;
35
+ coin: Coin;
36
+ borrower?: string;
37
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgRepay, "/ault.lending.v1.MsgRepay">;
38
+ /**
39
+ * Liquidates an unhealthy position: repays up to `repay` of the borrower's
40
+ * debt and seizes collateral in `seizeDenom` plus the pool's bonus. The
41
+ * borrower may be a 32-byte derived account (a margin account, for one).
42
+ */
43
+ export declare function buildLiquidateMsg(liquidator: string, params: {
44
+ poolId: LendingPoolId;
45
+ borrower: string;
46
+ repay: Coin;
47
+ seizeDenom: string;
48
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgLiquidate, "/ault.lending.v1.MsgLiquidate">;
49
+ /** Donates `coin` to the Lending insurance fund. Not fee-free: the sender pays gas. */
50
+ export declare function buildFundInsuranceFundMsg(funder: string, params: {
51
+ coin: Coin;
52
+ }): import("../index.js").Eip712Msg<import("../proto/gen/ault/lending/v1/tx").MsgFundInsuranceFund, "/ault.lending.v1.MsgFundInsuranceFund">;
@@ -30,6 +30,36 @@ export declare const ManifestGasSchema: z.ZodObject<{
30
30
  CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
31
31
  MODIFY_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
32
32
  OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
33
+ PERP_DEPOSIT: z.ZodOptional<z.ZodNumber>;
34
+ PERP_WITHDRAW: z.ZodOptional<z.ZodNumber>;
35
+ PERP_SET_MARGIN_CONFIG: z.ZodOptional<z.ZodNumber>;
36
+ PERP_MODIFY_POSITION_MARGIN: z.ZodOptional<z.ZodNumber>;
37
+ LENDING_SUPPLY: z.ZodOptional<z.ZodNumber>;
38
+ LENDING_WITHDRAW: z.ZodOptional<z.ZodNumber>;
39
+ LENDING_SUPPLY_COLLATERAL: z.ZodOptional<z.ZodNumber>;
40
+ LENDING_WITHDRAW_COLLATERAL: z.ZodOptional<z.ZodNumber>;
41
+ LENDING_BORROW: z.ZodOptional<z.ZodNumber>;
42
+ LENDING_REPAY: z.ZodOptional<z.ZodNumber>;
43
+ LENDING_LIQUIDATE: z.ZodOptional<z.ZodNumber>;
44
+ LENDING_FUND_INSURANCE_FUND: z.ZodOptional<z.ZodNumber>;
45
+ MARGIN_DEPOSIT_BASE: z.ZodOptional<z.ZodNumber>;
46
+ MARGIN_DEPOSIT_PER_COIN: z.ZodOptional<z.ZodNumber>;
47
+ MARGIN_WITHDRAW_BASE: z.ZodOptional<z.ZodNumber>;
48
+ MARGIN_WITHDRAW_PER_COIN: z.ZodOptional<z.ZodNumber>;
49
+ MARGIN_BORROW: z.ZodOptional<z.ZodNumber>;
50
+ MARGIN_REPAY: z.ZodOptional<z.ZodNumber>;
51
+ VAULT_CREATE_TRADING_BASE: z.ZodOptional<z.ZodNumber>;
52
+ VAULT_CREATE_PER_MARKET: z.ZodOptional<z.ZodNumber>;
53
+ VAULT_CREATE_LENDING_BASE: z.ZodOptional<z.ZodNumber>;
54
+ VAULT_CREATE_PER_LENDING_POOL: z.ZodOptional<z.ZodNumber>;
55
+ VAULT_UPDATE_MANAGER: z.ZodOptional<z.ZodNumber>;
56
+ VAULT_UPDATE_CONFIG: z.ZodOptional<z.ZodNumber>;
57
+ VAULT_CANCEL_CONFIG_UPDATE: z.ZodOptional<z.ZodNumber>;
58
+ VAULT_SET_STATUS: z.ZodOptional<z.ZodNumber>;
59
+ VAULT_DEPOSIT: z.ZodOptional<z.ZodNumber>;
60
+ VAULT_REDEEM: z.ZodOptional<z.ZodNumber>;
61
+ VAULT_TRANSFER: z.ZodOptional<z.ZodNumber>;
62
+ VAULT_REALLOCATE: z.ZodOptional<z.ZodNumber>;
33
63
  DELEGATE: z.ZodOptional<z.ZodNumber>;
34
64
  UNDELEGATE: z.ZodOptional<z.ZodNumber>;
35
65
  BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;
@@ -84,6 +114,36 @@ export declare const ManifestSchema: z.ZodObject<{
84
114
  CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
85
115
  MODIFY_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
86
116
  OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
117
+ PERP_DEPOSIT: z.ZodOptional<z.ZodNumber>;
118
+ PERP_WITHDRAW: z.ZodOptional<z.ZodNumber>;
119
+ PERP_SET_MARGIN_CONFIG: z.ZodOptional<z.ZodNumber>;
120
+ PERP_MODIFY_POSITION_MARGIN: z.ZodOptional<z.ZodNumber>;
121
+ LENDING_SUPPLY: z.ZodOptional<z.ZodNumber>;
122
+ LENDING_WITHDRAW: z.ZodOptional<z.ZodNumber>;
123
+ LENDING_SUPPLY_COLLATERAL: z.ZodOptional<z.ZodNumber>;
124
+ LENDING_WITHDRAW_COLLATERAL: z.ZodOptional<z.ZodNumber>;
125
+ LENDING_BORROW: z.ZodOptional<z.ZodNumber>;
126
+ LENDING_REPAY: z.ZodOptional<z.ZodNumber>;
127
+ LENDING_LIQUIDATE: z.ZodOptional<z.ZodNumber>;
128
+ LENDING_FUND_INSURANCE_FUND: z.ZodOptional<z.ZodNumber>;
129
+ MARGIN_DEPOSIT_BASE: z.ZodOptional<z.ZodNumber>;
130
+ MARGIN_DEPOSIT_PER_COIN: z.ZodOptional<z.ZodNumber>;
131
+ MARGIN_WITHDRAW_BASE: z.ZodOptional<z.ZodNumber>;
132
+ MARGIN_WITHDRAW_PER_COIN: z.ZodOptional<z.ZodNumber>;
133
+ MARGIN_BORROW: z.ZodOptional<z.ZodNumber>;
134
+ MARGIN_REPAY: z.ZodOptional<z.ZodNumber>;
135
+ VAULT_CREATE_TRADING_BASE: z.ZodOptional<z.ZodNumber>;
136
+ VAULT_CREATE_PER_MARKET: z.ZodOptional<z.ZodNumber>;
137
+ VAULT_CREATE_LENDING_BASE: z.ZodOptional<z.ZodNumber>;
138
+ VAULT_CREATE_PER_LENDING_POOL: z.ZodOptional<z.ZodNumber>;
139
+ VAULT_UPDATE_MANAGER: z.ZodOptional<z.ZodNumber>;
140
+ VAULT_UPDATE_CONFIG: z.ZodOptional<z.ZodNumber>;
141
+ VAULT_CANCEL_CONFIG_UPDATE: z.ZodOptional<z.ZodNumber>;
142
+ VAULT_SET_STATUS: z.ZodOptional<z.ZodNumber>;
143
+ VAULT_DEPOSIT: z.ZodOptional<z.ZodNumber>;
144
+ VAULT_REDEEM: z.ZodOptional<z.ZodNumber>;
145
+ VAULT_TRANSFER: z.ZodOptional<z.ZodNumber>;
146
+ VAULT_REALLOCATE: z.ZodOptional<z.ZodNumber>;
87
147
  DELEGATE: z.ZodOptional<z.ZodNumber>;
88
148
  UNDELEGATE: z.ZodOptional<z.ZodNumber>;
89
149
  BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;