ault-sdk-ts 0.12.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
@@ -410,7 +410,6 @@ __export(index_exports, {
410
410
  getPerpOrderbookQueryDepthDefault: () => getPerpOrderbookQueryDepthDefault,
411
411
  getPerpOrderbookQueryDepthMax: () => getPerpOrderbookQueryDepthMax,
412
412
  getPerpTickerPathMarketIdRegExp: () => getPerpTickerPathMarketIdRegExp,
413
- getPortfolioFlows: () => getPortfolioFlows,
414
413
  getPortfolioHoldings: () => getPortfolioHoldings,
415
414
  getPortfolioPnl: () => getPortfolioPnl,
416
415
  getPortfolioTimeSeries: () => getPortfolioTimeSeries,
@@ -632,7 +631,7 @@ __export(index_exports, {
632
631
  module.exports = __toCommonJS(index_exports);
633
632
 
634
633
  // src/core/user-agent.ts
635
- var SDK_VERSION = "0.12.0";
634
+ var SDK_VERSION = "0.14.0";
636
635
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
637
636
  function isServerRuntime() {
638
637
  if (typeof document !== "undefined") return false;
@@ -1171,13 +1170,13 @@ var GAS_CONSTANTS = {
1171
1170
  VAULT_CREATE_TRADING_BASE: 19e4,
1172
1171
  VAULT_CREATE_PER_MARKET: 9e3,
1173
1172
  VAULT_CREATE_LENDING_BASE: 124e3,
1174
- VAULT_CREATE_PER_LENDING_POOL: 2e3,
1173
+ VAULT_CREATE_PER_LENDING_POOL: 7e3,
1175
1174
  VAULT_UPDATE_MANAGER: 95e3,
1176
1175
  // A config update is priced like creation: per spot market or per pool.
1177
1176
  VAULT_UPDATE_CONFIG_TRADING_BASE: 85e3,
1178
1177
  VAULT_UPDATE_CONFIG_PER_MARKET: 9e3,
1179
1178
  VAULT_UPDATE_CONFIG_LENDING_BASE: 1e5,
1180
- VAULT_UPDATE_CONFIG_PER_POOL: 5e3,
1179
+ VAULT_UPDATE_CONFIG_PER_POOL: 7e3,
1181
1180
  VAULT_CANCEL_CONFIG_UPDATE: 75e3,
1182
1181
  VAULT_SET_STATUS: 78e3,
1183
1182
  VAULT_DEPOSIT: 26e4,
@@ -1695,6 +1694,167 @@ var QueryParamsResponse = {
1695
1694
  return message;
1696
1695
  }
1697
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
+ };
1698
1858
  function isSet3(value) {
1699
1859
  return value !== null && value !== void 0;
1700
1860
  }
@@ -29512,14 +29672,32 @@ function isSet55(value) {
29512
29672
  }
29513
29673
 
29514
29674
  // src/rest/ratelimit.ts
29675
+ var DEFAULT_FEE_FREE_RATE_LIMIT = 1;
29515
29676
  function createRateLimitApi(context) {
29516
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.
29517
29683
  async getRateLimitConfig(msgType) {
29518
- return fetchProtoJson(
29684
+ const typeUrl = msgType.startsWith("/") ? msgType : `/${msgType}`;
29685
+ const { params } = await fetchProtoJson(
29519
29686
  context,
29520
- `/ault/ratelimit/v1/config/${encodeURIComponent(msgType)}`,
29521
- QueryRateLimitConfigResponse
29687
+ "/ault/ratelimit/v1/params",
29688
+ QueryParamsResponse11
29522
29689
  );
29690
+ const config = params?.rateLimitConfigs.find((entry) => entry.msgType === typeUrl);
29691
+ if (config) return QueryRateLimitConfigResponse.fromPartial({ config });
29692
+ const { gasLimits } = await fetchProtoJson(
29693
+ context,
29694
+ "/ault/accountx/v1/fee_free_gas_limits",
29695
+ QueryFeeFreeGasLimitsResponse
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
+ });
29523
29701
  },
29524
29702
  async getParams() {
29525
29703
  return fetchProtoJson(context, "/ault/ratelimit/v1/params", QueryParamsResponse11);
@@ -32470,13 +32648,6 @@ function getPortfolioHoldings(address, options) {
32470
32648
  method: "GET"
32471
32649
  });
32472
32650
  }
32473
- function getPortfolioFlows(address, range, options) {
32474
- const query = range ? `?range=${range}` : "";
32475
- return dexFetch(`/api/v1/portfolio/${enc4(address)}/flows${query}`, {
32476
- ...options,
32477
- method: "GET"
32478
- });
32479
- }
32480
32651
  function getPortfolioPnl(address, range, options) {
32481
32652
  const query = range ? `?range=${range}` : "";
32482
32653
  return dexFetch(`/api/v1/portfolio/${enc4(address)}/pnl${query}`, {
@@ -32529,7 +32700,6 @@ function createDexApi(context) {
32529
32700
  getBalance: bind(context, getBalance),
32530
32701
  getStats: bind(context, getStats),
32531
32702
  getPortfolioHoldings: bind(context, getPortfolioHoldings),
32532
- getPortfolioFlows: bind(context, getPortfolioFlows),
32533
32703
  getPortfolioPnl: bind(context, getPortfolioPnl),
32534
32704
  getPortfolioTimeSeries: bind(context, getPortfolioTimeSeries),
32535
32705
  getUDFConfig: bind(context, getUDFConfig),
@@ -39222,13 +39392,7 @@ function buildVaultManagerSurface(options, ctx) {
39222
39392
  cache: createAccountCache()
39223
39393
  });
39224
39394
  const moduleCtx = { masterAddress: vaultAddress, exec, getGas: ctx.getGas };
39225
- const {
39226
- placeTwapOrder: _twap,
39227
- placeConditionalOrder: _conditional,
39228
- modifyConditionalOrders: _modifyConditional,
39229
- placeGroupOrder: _group,
39230
- ...clob
39231
- } = createAgentClobTxApi(moduleCtx);
39395
+ const { placeTwapOrder: _twap, ...clob } = createAgentClobTxApi(moduleCtx);
39232
39396
  return {
39233
39397
  address: deriveAgentAddress(options.agentPrivateKey),
39234
39398
  vaultAddress,
@@ -40698,13 +40862,13 @@ var ListTradesResponseItem = zod.object({
40698
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"
40699
40863
  );
40700
40864
  var ListTradesResponse = zod.array(ListTradesResponseItem);
40701
- var getTradePathIdMax = 114;
40865
+ var getTradePathIdMax = 125;
40702
40866
  var getTradePathIdRegExp = new RegExp(
40703
- "^(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}))?$"
40704
40868
  );
40705
40869
  var GetTradeParams = zod.object({
40706
40870
  id: zod.string().max(getTradePathIdMax).regex(getTradePathIdRegExp).describe(
40707
- "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"
40708
40872
  )
40709
40873
  });
40710
40874
  var getTradeResponsePriceRegExp = new RegExp("^-?\\d+(\\.\\d+)?$");
@@ -41500,9 +41664,7 @@ var ListPerpMarketsResponseItem = zod.object({
41500
41664
  takerFeeRate: zod.string(),
41501
41665
  marginTiers: zod.array(
41502
41666
  zod.object({
41503
- notionalCap: zod.string().describe(
41504
- 'Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'
41505
- ),
41667
+ notionalCap: zod.string().describe('Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'),
41506
41668
  maxLeverage: zod.number()
41507
41669
  })
41508
41670
  ),
@@ -41532,9 +41694,7 @@ var GetPerpMarketResponse = zod.object({
41532
41694
  takerFeeRate: zod.string(),
41533
41695
  marginTiers: zod.array(
41534
41696
  zod.object({
41535
- notionalCap: zod.string().describe(
41536
- 'Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'
41537
- ),
41697
+ notionalCap: zod.string().describe('Upper notional bound of the tier in quote; "0" marks the unbounded last tier.'),
41538
41698
  maxLeverage: zod.number()
41539
41699
  })
41540
41700
  ),
@@ -41633,7 +41793,9 @@ var ListPerpMarketTradesQueryParams = zod.object({
41633
41793
  )
41634
41794
  });
41635
41795
  var ListPerpMarketTradesResponseItem = zod.object({
41636
- 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
+ ),
41637
41799
  timestamp: zod.number(),
41638
41800
  marketId: zod.string(),
41639
41801
  price: zod.string(),
@@ -42894,7 +43056,6 @@ function createDexWs(url, options) {
42894
43056
  getPerpOrderbookQueryDepthDefault,
42895
43057
  getPerpOrderbookQueryDepthMax,
42896
43058
  getPerpTickerPathMarketIdRegExp,
42897
- getPortfolioFlows,
42898
43059
  getPortfolioHoldings,
42899
43060
  getPortfolioPnl,
42900
43061
  getPortfolioTimeSeries,