ault-sdk-ts 0.9.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 (42) hide show
  1. package/README.md +206 -93
  2. package/dist/agent/attach.d.ts +10 -1
  3. package/dist/agent/sign-and-broadcast.d.ts +1 -1
  4. package/dist/agent/tx/vault.d.ts +11 -0
  5. package/dist/client.d.ts +8 -0
  6. package/dist/core/address.d.ts +6 -0
  7. package/dist/core/clob-msgs.d.ts +9 -0
  8. package/dist/core/lending-gas.d.ts +5 -0
  9. package/dist/core/lending-msgs.d.ts +52 -0
  10. package/dist/core/manifest-types.d.ts +52 -0
  11. package/dist/core/margin-account.d.ts +18 -0
  12. package/dist/core/margin-gas.d.ts +7 -0
  13. package/dist/core/margin-msgs.d.ts +52 -0
  14. package/dist/core/network.d.ts +26 -0
  15. package/dist/core/perpetual-msgs.d.ts +0 -16
  16. package/dist/core/vault-gas.d.ts +8 -0
  17. package/dist/core/vault-msgs.d.ts +150 -0
  18. package/dist/eip712/msg.generated.d.ts +19 -106
  19. package/dist/eip712/registry.d.ts +7 -1
  20. package/dist/high-level/tx/lending.d.ts +3 -0
  21. package/dist/high-level/tx/license.d.ts +1 -1
  22. package/dist/high-level/tx/margin.d.ts +3 -0
  23. package/dist/high-level/tx/vault.d.ts +3 -0
  24. package/dist/high-level/types.d.ts +227 -178
  25. package/dist/index.cjs +16049 -20858
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.js +15992 -20813
  29. package/dist/index.js.map +1 -1
  30. package/dist/rest/dex-types.generated.d.ts +1 -1
  31. package/dist/rest/dex.d.ts +34 -1
  32. package/dist/rest/lending.d.ts +46 -0
  33. package/dist/rest/margin.d.ts +33 -0
  34. package/dist/rest/oracle.d.ts +19 -0
  35. package/dist/rest/pagination.d.ts +6 -2
  36. package/dist/rest/portfolio.d.ts +32 -0
  37. package/dist/rest/vault.d.ts +26 -0
  38. package/package.json +1 -1
  39. package/dist/high-level/tx/authority.d.ts +0 -3
  40. package/dist/high-level/tx/market.d.ts +0 -3
  41. package/dist/high-level/tx/ratelimit.d.ts +0 -3
  42. 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
 
@@ -392,57 +394,216 @@ await client.modifyPositionMargin({ marketId, marginDelta: "-500000" }); // isol
392
394
  await client.withdrawPerpCollateral({ amount: "250000000" });
393
395
  ```
394
396
 
395
- A perpetual market carries the config x/perpetual trades it under: margin
396
- tiers, funding caps, the mark price bound and the oracle feed ids. The chain
397
- requires that config on `MsgCreateMarket`, rejects it on a spot market, and
398
- never lets a market change type afterwards. So `createMarket` throws on a
399
- perpetual market type, and `createPerpetualMarket` takes the config. The
400
- deployer can replace the whole config later with `setPerpetualMarketConfig`.
401
- Decimal fields take the same readable strings as every other SDK input
402
- ("0.0001"); packing the config scales them to the chain's 18-place integers.
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).
403
410
 
404
411
  ```typescript
405
- const config = {
406
- isolatedOnly: false,
407
- fundingInterestRate: "0.0001", // per eight-hour interval
408
- fundingInterestAdjustmentCap: "0.0005",
409
- fundingHourlyCap: "0.005",
410
- oracleMaxAgeSeconds: 120,
411
- marginTiers: [
412
- { notionalCap: "100000000000000000000000", maxLeverage: 20 },
413
- { notionalCap: "0", maxLeverage: 10 }, // "0" = unbounded last tier
414
- ],
415
- markPriceMaxChangeRate: "0.05",
416
- maxOpenInterestNotional: "0", // "0" = uncapped
417
- maxPositionNotional: "0",
418
- impactNotional: "10000",
419
- maxImpactLevels: 64,
420
- indexFeedId: "BTC-USD",
421
- externalPerpetualFeedId: "BTC-PERP-USD",
422
- };
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`).
423
437
 
424
- await client.createPerpetualMarket({
425
- baseDenom: "ubtc",
426
- quoteDenom: "uusdc", // the module's collateral denom
427
- tickPrecision: 6,
428
- config,
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 },
429
465
  });
430
466
 
431
- await client.setPerpetualMarketConfig({
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({
432
470
  marketId,
433
- config: { ...config, oracleMaxAgeSeconds: 60 },
471
+ isBuy: false,
472
+ price: "3600",
473
+ quantity: "0.5",
474
+ deadline: new Date(Date.now() + 3_600_000),
475
+ margin: { autoRepay: true },
434
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" });
435
485
  ```
436
486
 
437
- To build the `config` Any by hand, for a raw `msg.market.createMarket` or an
438
- agent tx, use `packPerpetualMarketConfig`. It applies the same scaling.
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.
439
523
 
440
- The same four collateral and margin methods exist on `client.asAgent` after `attachAgent`. Read
441
- models (markets, tickers with mark and funding, positions, fills, ledger) come
442
- from the DEX API's `/api/v1/perp` endpoints, `listPerpMarkets` through
443
- `listPerpCloseouts` on `createDexApi`. `src/perp` ports the chain's margin-tier,
444
- funding and position math (`maintenanceMargin`, `initialMargin`, `equity`,
445
- `fundingRate`, ...) with the chain's rounding for client-side previews.
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
+ }
606
+ ```
446
607
 
447
608
  ## DEX API
448
609
 
@@ -764,45 +925,16 @@ Transactions](#market-and-clob-transactions).
764
925
  ### License Transactions
765
926
 
766
927
  ```typescript
767
- // Mint a license
768
- await client.mintLicense({
769
- to: "0x...", // EVM or ault1 address
770
- uri: "https://example.com/metadata.json",
771
- reason: "Minted via SDK", // Optional, defaults to ""
772
- });
773
-
774
- // Batch mint
775
- await client.batchMintLicense({
776
- recipients: [
777
- { to: "0xAddr1...", uri: "https://example.com/1.json" },
778
- { to: "0xAddr2...", uri: "https://example.com/2.json" },
779
- ],
780
- });
781
-
782
- // Transfer
783
928
  await client.transferLicense({
784
929
  licenseId: 123, // bigint, number, or string
785
930
  to: "0x...",
786
931
  });
787
-
788
- // Burn/Revoke (admin only)
789
- await client.burnLicense({ licenseId: 123 });
790
- await client.revokeLicense({ licenseId: 123 });
791
-
792
- // KYC management
793
- await client.approveMember({ member: "0x..." });
794
- await client.revokeMember({ member: "0x..." });
795
- await client.batchApproveMember({ members: ["0x...", "0x..."] });
796
-
797
- // Admin functions
798
- await client.setMinters({ add: ["0x..."], remove: [] });
799
- await client.setKYCApprovers({ add: ["0x..."], remove: [] });
800
932
  ```
801
933
 
802
934
  ### Miner Transactions
803
935
 
804
936
  ```typescript
805
- import { base64ToBytes, MarketType } from "ault-sdk-ts";
937
+ import { base64ToBytes } from "ault-sdk-ts";
806
938
 
807
939
  // Delegate licenses to an operator
808
940
  await client.delegateMining({
@@ -916,18 +1048,9 @@ await client.cancelOrders({ orderIds: [cloid] });
916
1048
  // Live orders resolve from the chain; filled/cancelled ones from the indexer.
917
1049
  const found = await client.findOrderByCloid(client.address, cloid);
918
1050
  if (found.source !== "none") console.log(found.source, found.order);
919
-
920
- // Create a spot market. A perpetual market takes its config at creation, so
921
- // createMarket throws on MARKET_TYPE_PERPETUAL — see createPerpetualMarket.
922
- await client.createMarket({
923
- marketType: MarketType.MARKET_TYPE_SPOT,
924
- baseDenom: "uatom",
925
- quoteDenom: "uusdc",
926
- tickPrecision: 6,
927
- });
928
1051
  ```
929
1052
 
930
- ### Reward And TokenRegistry Transactions
1053
+ ### Reward Transactions
931
1054
 
932
1055
  ```typescript
933
1056
  // Create a referral code as an eligible referrer
@@ -940,16 +1063,6 @@ await client.approveBuilder({
940
1063
  builder: "0x0000000000000000000000000000000000000001",
941
1064
  maxFeeRate: "0.005",
942
1065
  });
943
-
944
- // Register an ERC20 token pair
945
- await client.registerTokenPair({
946
- erc20Address: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
947
- enabled: true,
948
- });
949
-
950
- // Toggle module-wide token conversions
951
- await client.disableTokenRegistryTransfers();
952
- await client.enableTokenRegistryTransfers();
953
1066
  ```
954
1067
 
955
1068
  ### Transaction Options
@@ -1123,7 +1236,7 @@ Note: `pnpm gen:eip712` also reads Cosmos SDK protos (staking/distribution) and
1123
1236
  import { ApiError, NetworkError, TimeoutError } from "ault-sdk-ts";
1124
1237
 
1125
1238
  try {
1126
- const result = await client.mintLicense({ to: "0x...", uri: "..." });
1239
+ const result = await client.transferLicense({ licenseId: 1, to: "0x..." });
1127
1240
  if (result.success) {
1128
1241
  console.log(`Transaction committed: ${result.txHash}`);
1129
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;
@@ -4,7 +4,7 @@ import { type FetchFn, type FetchWithRetryOptions } from "../core/http";
4
4
  import type { NetworkConfig } from "../core/network";
5
5
  export declare const AGENT_DEFAULTS: {
6
6
  readonly GAS_LIMIT: "186000";
7
- readonly TIMEOUT_SECONDS: 300;
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,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,12 @@ 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";
11
14
  import { type PerpetualApi } from "./rest/perpetual";
12
15
  import { type RateLimitApi } from "./rest/ratelimit";
13
16
  import { type RewardApi } from "./rest/reward";
@@ -16,6 +19,7 @@ import { type DexApi } from "./rest/dex";
16
19
  import { DexWsClient } from "./ws/client";
17
20
  import type { DexWsOptions } from "./ws/types";
18
21
  import { type TokenRegistryApi } from "./rest/tokenregistry";
22
+ import { type VaultApi } from "./rest/vault";
19
23
  import type { AnyEip712Msg, Eip712TxContext } from "./eip712/builder";
20
24
  import type { SignAndBroadcastParams, SignAndBroadcastResult } from "./eip712/sign-and-broadcast";
21
25
  import { EIP712_MSG_TYPES } from "./eip712/registry";
@@ -37,15 +41,19 @@ export interface AultClient {
37
41
  authority: AuthorityApi;
38
42
  bank: BankApi;
39
43
  clob: ClobApi;
44
+ lending: LendingApi;
40
45
  license: LicenseApi;
46
+ margin: MarginApi;
41
47
  market: MarketApi;
42
48
  miner: MinerApi;
49
+ oracle: OracleApi;
43
50
  perpetual: PerpetualApi;
44
51
  ratelimit: RateLimitApi;
45
52
  reward: RewardApi;
46
53
  staking: StakingApi;
47
54
  dex: DexApi;
48
55
  tokenregistry: TokenRegistryApi;
56
+ vault: VaultApi;
49
57
  };
50
58
  ws: DexWsClient;
51
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;
@@ -16,6 +17,12 @@ export declare function buildLimitOrderMsg(sender: string, params: {
16
17
  * which reject the options.
17
18
  */
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;
19
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">;
20
27
  /**
21
28
  * TWAP order (chain v2.1.0+). `deadline` is the absolute end of the execution
@@ -42,6 +49,8 @@ export declare function buildMarketOrderMsg(sender: string, params: {
42
49
  builderAddress?: string;
43
50
  builderFeeRate?: string;
44
51
  cloid?: Uint8Array;
52
+ /** Spot markets only; see `buildLimitOrderMsg`. */
53
+ margin?: MarginOrderOptions;
45
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">;
46
55
  /** Each `orderIds` entry may be an 8-byte cloid or a 16-byte chain order_id. */
47
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">;
@@ -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">;
@@ -34,6 +34,32 @@ export declare const ManifestGasSchema: z.ZodObject<{
34
34
  PERP_WITHDRAW: z.ZodOptional<z.ZodNumber>;
35
35
  PERP_SET_MARGIN_CONFIG: z.ZodOptional<z.ZodNumber>;
36
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>;
37
63
  DELEGATE: z.ZodOptional<z.ZodNumber>;
38
64
  UNDELEGATE: z.ZodOptional<z.ZodNumber>;
39
65
  BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;
@@ -92,6 +118,32 @@ export declare const ManifestSchema: z.ZodObject<{
92
118
  PERP_WITHDRAW: z.ZodOptional<z.ZodNumber>;
93
119
  PERP_SET_MARGIN_CONFIG: z.ZodOptional<z.ZodNumber>;
94
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>;
95
147
  DELEGATE: z.ZodOptional<z.ZodNumber>;
96
148
  UNDELEGATE: z.ZodOptional<z.ZodNumber>;
97
149
  BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;
@@ -0,0 +1,18 @@
1
+ import { MarketId } from "../utils/opaque-id";
2
+ /** A market id as raw bytes, a `MarketId`, or the hex string the dex-api returns. */
3
+ export type MarginMarketIdInput = Uint8Array | MarketId | string;
4
+ /**
5
+ * The margin account the chain funds a margin order from. Without `marketId`
6
+ * this is the owner's cross account; with one, the isolated account of that
7
+ * market. A `cross: true` order funds from the cross account whatever market
8
+ * it trades, so derive its account without the market id. Orders, fills and wallet flows of a margin account are read through
9
+ * the dex-api address routes with this address, not the owner's.
10
+ *
11
+ * `owner` takes a bech32 or 0x address. Nothing is queried: the chain derives
12
+ * the same address the same way.
13
+ */
14
+ export declare function marginAccountAddress(owner: string, marketId?: MarginMarketIdInput): string;
15
+ /** True when `address` has the length and prefix every margin account has. No store read. */
16
+ export declare function isMarginAccountAddress(address: string): boolean;
17
+ /** The owner a margin account was derived from, or null when `address` is not one. */
18
+ export declare function marginAccountOwner(address: string): string | null;
@@ -0,0 +1,7 @@
1
+ import { type GAS_CONSTANTS } from "./network";
2
+ type Gas = typeof GAS_CONSTANTS;
3
+ export declare function depositMarginGas(gas: Gas, coinCount: number): string;
4
+ export declare function withdrawMarginGas(gas: Gas, coinCount: number): string;
5
+ export declare function borrowMarginGas(gas: Gas): string;
6
+ export declare function repayMarginGas(gas: Gas): string;
7
+ export {};