ault-sdk-ts 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -578,10 +578,15 @@ key's registered agent): the manager for a normal or parent vault, the
578
578
  parent's manager for a child vault. What x/vault accepts depends on the kind
579
579
  of vault:
580
580
 
581
- - A normal trading vault or a child vault can place, modify and cancel
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.
581
+ - A normal trading vault or a child vault can place, modify and cancel orders
582
+ on its configured spot markets and, with the `perpetual` action, on
583
+ perpetual markets, where it also manages its collateral and margin. It can
584
+ also place conditional and group orders (stops, OCO, OTO, OTOCO) and modify
585
+ the waiting ones, but not TWAP orders. While a redemption is queued every
586
+ order must be IOC, and an inactive or redeeming vault can only sell on spot
587
+ and only reduce on perps. A conditional is checked against these rules again
588
+ when it fires, and a redemption cancels the vault's orders, conditionals
589
+ included.
585
590
  - A normal lending vault can move supply between its pools with
586
591
  `reallocateVault`.
587
592
  - A parent vault can create child vaults, update or cancel their config, set
@@ -89,12 +89,12 @@ export declare const GAS_CONSTANTS: {
89
89
  readonly VAULT_CREATE_TRADING_BASE: 190000;
90
90
  readonly VAULT_CREATE_PER_MARKET: 9000;
91
91
  readonly VAULT_CREATE_LENDING_BASE: 124000;
92
- readonly VAULT_CREATE_PER_LENDING_POOL: 2000;
92
+ readonly VAULT_CREATE_PER_LENDING_POOL: 7000;
93
93
  readonly VAULT_UPDATE_MANAGER: 95000;
94
94
  readonly VAULT_UPDATE_CONFIG_TRADING_BASE: 85000;
95
95
  readonly VAULT_UPDATE_CONFIG_PER_MARKET: 9000;
96
96
  readonly VAULT_UPDATE_CONFIG_LENDING_BASE: 100000;
97
- readonly VAULT_UPDATE_CONFIG_PER_POOL: 5000;
97
+ readonly VAULT_UPDATE_CONFIG_PER_POOL: 7000;
98
98
  readonly VAULT_CANCEL_CONFIG_UPDATE: 75000;
99
99
  readonly VAULT_SET_STATUS: 78000;
100
100
  readonly VAULT_DEPOSIT: 260000;
@@ -948,19 +948,22 @@ export interface AgentSurface extends AgentClobTxApi, AgentPerpetualTxApi, Agent
948
948
  * a normal or parent vault, the parent's manager for a child) or that key's
949
949
  * registered agent. Build it with `client.attachVaultManager(...)`.
950
950
  *
951
- * x/vault accepts a different set per vault (v3.0.0-rc.3 account control):
951
+ * x/vault accepts a different set per vault (v3.0.0-rc.4 account control):
952
952
  * - normal trading vault, child vault: limit, market and scale orders,
953
- * modify and cancel, on the vault's configured spot markets and, with the
954
- * perpetual action, on perpetual markets, plus the perpetual collateral and
955
- * margin messages;
953
+ * conditional and group orders, modify and cancel, on the vault's configured
954
+ * spot markets and, with the perpetual action, on perpetual markets, plus the
955
+ * perpetual collateral and margin messages. While a redemption is queued
956
+ * every order must be IOC, and an inactive or redeeming vault may only sell
957
+ * spot and reduce perpetual positions; a conditional order is checked again
958
+ * when it fires, and a redemption cancels the vault's conditional orders too;
956
959
  * - normal lending vault: `reallocateVault`;
957
960
  * - parent vault: `createVault` (children), `updateVaultConfig`,
958
961
  * `cancelVaultConfigUpdate` and `setVaultStatus` on its children,
959
962
  * `transferChildVault` and `backstopTransfer`. A parent vault does not trade.
960
963
  *
961
- * TWAP, conditional and group orders are not available from a vault account.
964
+ * TWAP orders are not available from a vault account.
962
965
  */
963
- export interface VaultManagerSurface extends Omit<AgentClobTxApi, "placeTwapOrder" | "placeConditionalOrder" | "modifyConditionalOrders" | "placeGroupOrder">, AgentPerpetualTxApi, AgentVaultTxApi, VaultAccountTxApi {
966
+ export interface VaultManagerSurface extends Omit<AgentClobTxApi, "placeTwapOrder">, AgentPerpetualTxApi, AgentVaultTxApi, VaultAccountTxApi {
964
967
  /** Address of the signing key (the manager or its agent). */
965
968
  readonly address: string;
966
969
  /** The vault account every message is sent from. */
package/dist/index.cjs CHANGED
@@ -631,7 +631,7 @@ __export(index_exports, {
631
631
  module.exports = __toCommonJS(index_exports);
632
632
 
633
633
  // src/core/user-agent.ts
634
- var SDK_VERSION = "0.13.0";
634
+ var SDK_VERSION = "0.14.0";
635
635
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
636
636
  function isServerRuntime() {
637
637
  if (typeof document !== "undefined") return false;
@@ -1170,13 +1170,13 @@ var GAS_CONSTANTS = {
1170
1170
  VAULT_CREATE_TRADING_BASE: 19e4,
1171
1171
  VAULT_CREATE_PER_MARKET: 9e3,
1172
1172
  VAULT_CREATE_LENDING_BASE: 124e3,
1173
- VAULT_CREATE_PER_LENDING_POOL: 2e3,
1173
+ VAULT_CREATE_PER_LENDING_POOL: 7e3,
1174
1174
  VAULT_UPDATE_MANAGER: 95e3,
1175
1175
  // A config update is priced like creation: per spot market or per pool.
1176
1176
  VAULT_UPDATE_CONFIG_TRADING_BASE: 85e3,
1177
1177
  VAULT_UPDATE_CONFIG_PER_MARKET: 9e3,
1178
1178
  VAULT_UPDATE_CONFIG_LENDING_BASE: 1e5,
1179
- VAULT_UPDATE_CONFIG_PER_POOL: 5e3,
1179
+ VAULT_UPDATE_CONFIG_PER_POOL: 7e3,
1180
1180
  VAULT_CANCEL_CONFIG_UPDATE: 75e3,
1181
1181
  VAULT_SET_STATUS: 78e3,
1182
1182
  VAULT_DEPOSIT: 26e4,
@@ -1694,6 +1694,167 @@ var QueryParamsResponse = {
1694
1694
  return message;
1695
1695
  }
1696
1696
  };
1697
+ function createBaseQueryFeeFreeGasLimitsResponse() {
1698
+ return { gasLimits: [] };
1699
+ }
1700
+ var QueryFeeFreeGasLimitsResponse = {
1701
+ encode(message, writer = new import_wire4.BinaryWriter()) {
1702
+ for (const v of message.gasLimits) {
1703
+ FeeFreeGasLimit.encode(v, writer.uint32(10).fork()).join();
1704
+ }
1705
+ return writer;
1706
+ },
1707
+ decode(input, length) {
1708
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
1709
+ const end = length === void 0 ? reader.len : reader.pos + length;
1710
+ const message = createBaseQueryFeeFreeGasLimitsResponse();
1711
+ while (reader.pos < end) {
1712
+ const tag = reader.uint32();
1713
+ switch (tag >>> 3) {
1714
+ case 1: {
1715
+ if (tag !== 10) {
1716
+ break;
1717
+ }
1718
+ message.gasLimits.push(FeeFreeGasLimit.decode(reader, reader.uint32()));
1719
+ continue;
1720
+ }
1721
+ }
1722
+ if ((tag & 7) === 4 || tag === 0) {
1723
+ break;
1724
+ }
1725
+ reader.skip(tag & 7);
1726
+ }
1727
+ return message;
1728
+ },
1729
+ fromJSON(object2) {
1730
+ return {
1731
+ gasLimits: globalThis.Array.isArray(object2?.gasLimits) ? object2.gasLimits.map((e) => FeeFreeGasLimit.fromJSON(e)) : globalThis.Array.isArray(object2?.gas_limits) ? object2.gas_limits.map((e) => FeeFreeGasLimit.fromJSON(e)) : []
1732
+ };
1733
+ },
1734
+ toJSON(message) {
1735
+ const obj = {};
1736
+ if (message.gasLimits?.length) {
1737
+ obj.gasLimits = message.gasLimits.map((e) => FeeFreeGasLimit.toJSON(e));
1738
+ }
1739
+ return obj;
1740
+ },
1741
+ create(base) {
1742
+ return QueryFeeFreeGasLimitsResponse.fromPartial(base ?? {});
1743
+ },
1744
+ fromPartial(object2) {
1745
+ const message = createBaseQueryFeeFreeGasLimitsResponse();
1746
+ message.gasLimits = object2.gasLimits?.map((e) => FeeFreeGasLimit.fromPartial(e)) || [];
1747
+ return message;
1748
+ }
1749
+ };
1750
+ function createBaseFeeFreeGasLimit() {
1751
+ return { msgTypeUrl: "", baseGasLimit: 0n, perUnitGasLimit: 0n, variant: "" };
1752
+ }
1753
+ var FeeFreeGasLimit = {
1754
+ encode(message, writer = new import_wire4.BinaryWriter()) {
1755
+ if (message.msgTypeUrl !== "") {
1756
+ writer.uint32(10).string(message.msgTypeUrl);
1757
+ }
1758
+ if (message.baseGasLimit !== 0n) {
1759
+ if (BigInt.asUintN(64, message.baseGasLimit) !== message.baseGasLimit) {
1760
+ throw new globalThis.Error(
1761
+ "value provided for field message.baseGasLimit of type uint64 too large"
1762
+ );
1763
+ }
1764
+ writer.uint32(16).uint64(message.baseGasLimit);
1765
+ }
1766
+ if (message.perUnitGasLimit !== 0n) {
1767
+ if (BigInt.asUintN(64, message.perUnitGasLimit) !== message.perUnitGasLimit) {
1768
+ throw new globalThis.Error(
1769
+ "value provided for field message.perUnitGasLimit of type uint64 too large"
1770
+ );
1771
+ }
1772
+ writer.uint32(24).uint64(message.perUnitGasLimit);
1773
+ }
1774
+ if (message.variant !== "") {
1775
+ writer.uint32(34).string(message.variant);
1776
+ }
1777
+ return writer;
1778
+ },
1779
+ decode(input, length) {
1780
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
1781
+ const end = length === void 0 ? reader.len : reader.pos + length;
1782
+ const message = createBaseFeeFreeGasLimit();
1783
+ while (reader.pos < end) {
1784
+ const tag = reader.uint32();
1785
+ switch (tag >>> 3) {
1786
+ case 1: {
1787
+ if (tag !== 10) {
1788
+ break;
1789
+ }
1790
+ message.msgTypeUrl = reader.string();
1791
+ continue;
1792
+ }
1793
+ case 2: {
1794
+ if (tag !== 16) {
1795
+ break;
1796
+ }
1797
+ message.baseGasLimit = reader.uint64();
1798
+ continue;
1799
+ }
1800
+ case 3: {
1801
+ if (tag !== 24) {
1802
+ break;
1803
+ }
1804
+ message.perUnitGasLimit = reader.uint64();
1805
+ continue;
1806
+ }
1807
+ case 4: {
1808
+ if (tag !== 34) {
1809
+ break;
1810
+ }
1811
+ message.variant = reader.string();
1812
+ continue;
1813
+ }
1814
+ }
1815
+ if ((tag & 7) === 4 || tag === 0) {
1816
+ break;
1817
+ }
1818
+ reader.skip(tag & 7);
1819
+ }
1820
+ return message;
1821
+ },
1822
+ fromJSON(object2) {
1823
+ return {
1824
+ msgTypeUrl: isSet3(object2.msgTypeUrl) ? globalThis.String(object2.msgTypeUrl) : isSet3(object2.msg_type_url) ? globalThis.String(object2.msg_type_url) : "",
1825
+ baseGasLimit: isSet3(object2.baseGasLimit) ? BigInt(object2.baseGasLimit) : isSet3(object2.base_gas_limit) ? BigInt(object2.base_gas_limit) : 0n,
1826
+ perUnitGasLimit: isSet3(object2.perUnitGasLimit) ? BigInt(object2.perUnitGasLimit) : isSet3(object2.per_unit_gas_limit) ? BigInt(object2.per_unit_gas_limit) : 0n,
1827
+ variant: isSet3(object2.variant) ? globalThis.String(object2.variant) : ""
1828
+ };
1829
+ },
1830
+ toJSON(message) {
1831
+ const obj = {};
1832
+ if (message.msgTypeUrl !== "") {
1833
+ obj.msgTypeUrl = message.msgTypeUrl;
1834
+ }
1835
+ if (message.baseGasLimit !== 0n) {
1836
+ obj.baseGasLimit = message.baseGasLimit.toString();
1837
+ }
1838
+ if (message.perUnitGasLimit !== 0n) {
1839
+ obj.perUnitGasLimit = message.perUnitGasLimit.toString();
1840
+ }
1841
+ if (message.variant !== "") {
1842
+ obj.variant = message.variant;
1843
+ }
1844
+ return obj;
1845
+ },
1846
+ create(base) {
1847
+ return FeeFreeGasLimit.fromPartial(base ?? {});
1848
+ },
1849
+ fromPartial(object2) {
1850
+ const message = createBaseFeeFreeGasLimit();
1851
+ message.msgTypeUrl = object2.msgTypeUrl ?? "";
1852
+ message.baseGasLimit = object2.baseGasLimit ?? 0n;
1853
+ message.perUnitGasLimit = object2.perUnitGasLimit ?? 0n;
1854
+ message.variant = object2.variant ?? "";
1855
+ return message;
1856
+ }
1857
+ };
1697
1858
  function isSet3(value) {
1698
1859
  return value !== null && value !== void 0;
1699
1860
  }
@@ -29511,14 +29672,32 @@ function isSet55(value) {
29511
29672
  }
29512
29673
 
29513
29674
  // src/rest/ratelimit.ts
29675
+ var DEFAULT_FEE_FREE_RATE_LIMIT = 1;
29514
29676
  function createRateLimitApi(context) {
29515
29677
  return {
29678
+ // The gateway drops the leading "/" of a type URL in the path (it redirects
29679
+ // %2F away), so the config route finds nothing for a real type URL. This
29680
+ // answers what the route would: the rule from the params, else the default
29681
+ // limit for a fee-free message (x/accountx lists them with their gas), else
29682
+ // an empty config, which means the type is not limited.
29516
29683
  async getRateLimitConfig(msgType) {
29517
- return fetchProtoJson(
29684
+ const typeUrl = msgType.startsWith("/") ? msgType : `/${msgType}`;
29685
+ const { params } = await fetchProtoJson(
29686
+ context,
29687
+ "/ault/ratelimit/v1/params",
29688
+ QueryParamsResponse11
29689
+ );
29690
+ const config = params?.rateLimitConfigs.find((entry) => entry.msgType === typeUrl);
29691
+ if (config) return QueryRateLimitConfigResponse.fromPartial({ config });
29692
+ const { gasLimits } = await fetchProtoJson(
29518
29693
  context,
29519
- `/ault/ratelimit/v1/config/${encodeURIComponent(msgType)}`,
29520
- QueryRateLimitConfigResponse
29694
+ "/ault/accountx/v1/fee_free_gas_limits",
29695
+ QueryFeeFreeGasLimitsResponse
29521
29696
  );
29697
+ const feeFree = gasLimits.some((entry) => entry.msgTypeUrl === typeUrl);
29698
+ return QueryRateLimitConfigResponse.fromPartial({
29699
+ config: feeFree ? { msgType: typeUrl, limit: DEFAULT_FEE_FREE_RATE_LIMIT } : {}
29700
+ });
29522
29701
  },
29523
29702
  async getParams() {
29524
29703
  return fetchProtoJson(context, "/ault/ratelimit/v1/params", QueryParamsResponse11);
@@ -39213,13 +39392,7 @@ function buildVaultManagerSurface(options, ctx) {
39213
39392
  cache: createAccountCache()
39214
39393
  });
39215
39394
  const moduleCtx = { masterAddress: vaultAddress, exec, getGas: ctx.getGas };
39216
- const {
39217
- placeTwapOrder: _twap,
39218
- placeConditionalOrder: _conditional,
39219
- modifyConditionalOrders: _modifyConditional,
39220
- placeGroupOrder: _group,
39221
- ...clob
39222
- } = createAgentClobTxApi(moduleCtx);
39395
+ const { placeTwapOrder: _twap, ...clob } = createAgentClobTxApi(moduleCtx);
39223
39396
  return {
39224
39397
  address: deriveAgentAddress(options.agentPrivateKey),
39225
39398
  vaultAddress,
@@ -40689,13 +40862,13 @@ var ListTradesResponseItem = zod.object({
40689
40862
  "All numeric fields are canonical decimal strings \u2014 quantities at any\nmagnitude survive the JSON round-trip without rounding through\nfloat64. Consumers parse with their own bigdecimal.\n"
40690
40863
  );
40691
40864
  var ListTradesResponse = zod.array(ListTradesResponseItem);
40692
- var getTradePathIdMax = 114;
40865
+ var getTradePathIdMax = 125;
40693
40866
  var getTradePathIdRegExp = new RegExp(
40694
- "^(0|[1-9][0-9]*)-[0-9a-f]{32}-(0|[1-9][0-9]*)(\\.[0-9]*[1-9])?$"
40867
+ "^(0|[1-9][0-9]*)-[0-9a-f]{32}-(0|[1-9][0-9]*)(\\.[0-9]*[1-9])?(-(0|[1-9][0-9]{0,9}))?$"
40695
40868
  );
40696
40869
  var GetTradeParams = zod.object({
40697
40870
  id: zod.string().max(getTradePathIdMax).regex(getTradePathIdRegExp).describe(
40698
- "Synthesized trade id in the form\n`<block_height>-<hex(order_id)>-<open_quantity>`, taken verbatim from\na REST trade object's `id` field (not the WebSocket `tid`).\n"
40871
+ "Synthesized trade id in the form\n`<block_height>-<hex(order_id)>-<open_quantity>`, or\n`<block_height>-<hex(order_id)>-<open_quantity>-<event_index>` from\nthe Ault v3.0.0-rc.4 upgrade height, taken verbatim from a REST\ntrade object's `id` field (not the WebSocket `tid`).\n"
40699
40872
  )
40700
40873
  });
40701
40874
  var getTradeResponsePriceRegExp = new RegExp("^-?\\d+(\\.\\d+)?$");
@@ -41491,9 +41664,7 @@ var ListPerpMarketsResponseItem = zod.object({
41491
41664
  takerFeeRate: zod.string(),
41492
41665
  marginTiers: zod.array(
41493
41666
  zod.object({
41494
- notionalCap: zod.string().describe(
41495
- 'Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'
41496
- ),
41667
+ notionalCap: zod.string().describe('Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'),
41497
41668
  maxLeverage: zod.number()
41498
41669
  })
41499
41670
  ),
@@ -41523,9 +41694,7 @@ var GetPerpMarketResponse = zod.object({
41523
41694
  takerFeeRate: zod.string(),
41524
41695
  marginTiers: zod.array(
41525
41696
  zod.object({
41526
- notionalCap: zod.string().describe(
41527
- 'Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'
41528
- ),
41697
+ notionalCap: zod.string().describe('Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'),
41529
41698
  maxLeverage: zod.number()
41530
41699
  })
41531
41700
  ),
@@ -41624,7 +41793,9 @@ var ListPerpMarketTradesQueryParams = zod.object({
41624
41793
  )
41625
41794
  });
41626
41795
  var ListPerpMarketTradesResponseItem = zod.object({
41627
- id: zod.string().describe("`<block_height>-<hex(order_id)>-<open_quantity>`"),
41796
+ id: zod.string().describe(
41797
+ "`<block_height>-<hex(order_id)>-<open_quantity>`, plus `-<event_index>` from the Ault v3.0.0-rc.4 upgrade height"
41798
+ ),
41628
41799
  timestamp: zod.number(),
41629
41800
  marketId: zod.string(),
41630
41801
  price: zod.string(),