aftermath-ts-sdk 2.1.0-perps.4 → 2.1.0-perps.6

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/dist/index.d.ts CHANGED
@@ -488,6 +488,7 @@ interface FaucetAddresses {
488
488
  };
489
489
  objects: {
490
490
  faucet: ObjectId;
491
+ config: ObjectId;
491
492
  suiFrensMint: ObjectId;
492
493
  };
493
494
  }
@@ -3465,31 +3466,38 @@ type SdkPerpetualsCreateTwapOrdersInputs = Omit<ApiPerpetualsCreateTwapOrdersBod
3465
3466
  tx?: Transaction;
3466
3467
  };
3467
3468
  /**
3468
- * Request body for creating TWAP orders via the API.
3469
+ * Request body for creating TWAP orders via the API, for an
3470
+ * account or vault.
3469
3471
  */
3470
- interface ApiPerpetualsCreateTwapOrdersBody {
3471
- accountId: PerpetualsAccountId;
3472
- accountCapId?: ObjectId;
3472
+ type ApiPerpetualsCreateTwapOrdersBody = {
3473
3473
  walletAddress: SuiAddress;
3474
3474
  twapOrders: PerpetualsTwapOrderDetails[];
3475
3475
  gasCoinArg?: TransactionObjectArgument;
3476
3476
  txKind?: SerializedTransaction;
3477
3477
  isSponsoredTx?: boolean;
3478
3478
  sponsor?: PerpetualsSponsorConfig;
3479
- }
3479
+ } & ({
3480
+ accountId: PerpetualsAccountId;
3481
+ accountCapId?: ObjectId;
3482
+ } | {
3483
+ vaultId: ObjectId;
3484
+ });
3480
3485
  /**
3481
3486
  * Request body for editing existing TWAP orders via the API.
3482
3487
  *
3483
3488
  * `newTwapOrders` maps each TWAP order object id to the edit to apply.
3484
3489
  */
3485
- interface ApiPerpetualsEditTwapOrdersBody {
3486
- accountId: PerpetualsAccountId;
3487
- accountCapId?: ObjectId;
3490
+ type ApiPerpetualsEditTwapOrdersBody = {
3488
3491
  walletAddress: SuiAddress;
3489
3492
  newTwapOrders: Record<ObjectId, PerpetualsTwapOrderEdit>;
3490
3493
  txKind?: SerializedTransaction;
3491
3494
  sponsor?: PerpetualsSponsorConfig;
3492
- }
3495
+ } & ({
3496
+ accountId: PerpetualsAccountId;
3497
+ accountCapId?: ObjectId;
3498
+ } | {
3499
+ vaultId: ObjectId;
3500
+ });
3493
3501
  /**
3494
3502
  * SDK-level inputs for editing existing TWAP orders — the request body without
3495
3503
  * the auto-filled fields, plus an optional transaction to extend.
@@ -3498,16 +3506,20 @@ type SdkPerpetualsEditTwapOrdersInputs = Omit<ApiPerpetualsEditTwapOrdersBody, P
3498
3506
  tx?: Transaction;
3499
3507
  };
3500
3508
  /**
3501
- * Request body for canceling TWAP orders identified by object IDs.
3509
+ * Request body for canceling TWAP orders identified by object IDs, for an
3510
+ * account or vault.
3502
3511
  */
3503
- interface ApiPerpetualsCancelTwapOrdersBody {
3504
- accountId: PerpetualsAccountId;
3505
- accountCapId?: ObjectId;
3512
+ type ApiPerpetualsCancelTwapOrdersBody = {
3506
3513
  walletAddress: SuiAddress;
3507
3514
  twapOrderIds: ObjectId[];
3508
3515
  txKind?: SerializedTransaction;
3509
3516
  sponsor?: PerpetualsSponsorConfig;
3510
- }
3517
+ } & ({
3518
+ accountId: PerpetualsAccountId;
3519
+ accountCapId?: ObjectId;
3520
+ } | {
3521
+ vaultId: ObjectId;
3522
+ });
3511
3523
  /**
3512
3524
  * SDK-level inputs for canceling TWAP orders — the request body without the
3513
3525
  * auto-filled fields, plus an optional transaction to extend.
@@ -3519,13 +3531,16 @@ type SdkPerpetualsCancelTwapOrdersInputs = Omit<ApiPerpetualsCancelTwapOrdersBod
3519
3531
  * Request body for fetching the TWAP orders of an account, validated using a
3520
3532
  * wallet signature.
3521
3533
  */
3522
- interface ApiPerpetualsTwapOrderDatasBody {
3523
- accountId: PerpetualsAccountId;
3534
+ type ApiPerpetualsTwapOrderDatasBody = {
3524
3535
  walletAddress: SuiAddress;
3525
3536
  bytes: string;
3526
3537
  signature: string;
3527
3538
  marketIds?: PerpetualsMarketId[];
3528
- }
3539
+ } & ({
3540
+ accountId: PerpetualsAccountId;
3541
+ } | {
3542
+ vaultId: ObjectId;
3543
+ });
3529
3544
  /**
3530
3545
  * Response payload for TWAP-order queries.
3531
3546
  */
@@ -5175,7 +5190,8 @@ interface PerpetualsWsUpdatesMarketSubscriptionType {
5175
5190
  }
5176
5191
  /**
5177
5192
  * Websocket subscription payload for subscribing to user/account updates,
5178
- * optionally including stop-order data (via signature).
5193
+ * optionally including special-order (stop and TWAP order) data (via
5194
+ * signature).
5179
5195
  */
5180
5196
  interface PerpetualsWsUpdatesUserSubscriptionType {
5181
5197
  user: {
@@ -5317,11 +5333,13 @@ interface PerpetualsWsUpdatesTopOfOrderbookPayload {
5317
5333
  maxBidPrice: number | undefined;
5318
5334
  }
5319
5335
  /**
5320
- * Websocket payload for user account and stop-order updates.
5336
+ * Websocket payload for user account and special-order (stop and TWAP order)
5337
+ * updates.
5321
5338
  */
5322
5339
  interface PerpetualsWsUpdatesUserPayload {
5323
5340
  account: PerpetualsAccountObject;
5324
5341
  stopOrders: PerpetualsStopOrderData[] | undefined;
5342
+ twapOrders: PerpetualsTwapOrderData[] | undefined;
5325
5343
  }
5326
5344
  /**
5327
5345
  * Websocket subscription message format sent by clients to manage
@@ -8537,13 +8555,10 @@ declare class Farms extends Caller {
8537
8555
 
8538
8556
  declare class Faucet extends Caller {
8539
8557
  readonly api?: AftermathApi | undefined;
8540
- static readonly constants: {
8541
- defaultRequestAmountUsd: number;
8542
- };
8543
8558
  constructor(config?: CallerConfig, api?: AftermathApi | undefined);
8544
8559
  getSupportedCoins(): Promise<CoinType[]>;
8545
- getRequestCoinTransaction(inputs: ApiFaucetRequestBody): Promise<_mysten_sui_transactions.Transaction>;
8546
- getMintSuiFrenTransaction(inputs: ApiFaucetMintSuiFrenBody): Promise<_mysten_sui_transactions.Transaction>;
8560
+ getRequestCoinTransaction(inputs: ApiFaucetRequestBody): Transaction;
8561
+ getMintSuiFrenTransaction(inputs: ApiFaucetMintSuiFrenBody): Promise<Transaction>;
8547
8562
  private readonly faucetApi;
8548
8563
  }
8549
8564
 
@@ -12268,6 +12283,14 @@ declare class Perpetuals extends Caller {
12268
12283
  priceBucketSize: number;
12269
12284
  bucketsNumber: number;
12270
12285
  }) => void;
12286
+ subscribeMarketCandles: ({ marketId, interval, }: {
12287
+ marketId: PerpetualsMarketId;
12288
+ interval: PerpetualsCandleResolution;
12289
+ }) => void;
12290
+ unsubscribeMarketCandles: ({ marketId, interval, }: {
12291
+ marketId: PerpetualsMarketId;
12292
+ interval: PerpetualsCandleResolution;
12293
+ }) => void;
12271
12294
  close: () => void;
12272
12295
  };
12273
12296
  /**
@@ -16298,6 +16321,11 @@ declare class FaucetApi {
16298
16321
  };
16299
16322
  constructor(api: AftermathApi);
16300
16323
  fetchSupportedCoins: () => Promise<CoinType[]>;
16324
+ /**
16325
+ * Mints `coinType`'s configured default amount and returns the resulting
16326
+ * `Coin<T>`. Use {@link buildRequestCoinTx} to mint and transfer it to a
16327
+ * wallet in one transaction.
16328
+ */
16301
16329
  requestCoinTx: (inputs: {
16302
16330
  tx: Transaction;
16303
16331
  coinType: CoinType;
@@ -16307,12 +16335,7 @@ declare class FaucetApi {
16307
16335
  suiPaymentCoinId: ObjectId | TransactionArgument;
16308
16336
  suiFrenType: AnyObjectType;
16309
16337
  }) => _mysten_sui_transactions.TransactionResult;
16310
- buildRequestCoinTx: (inputs: {
16311
- walletAddress: SuiAddress;
16312
- } & Omit<{
16313
- tx: Transaction;
16314
- coinType: CoinType;
16315
- }, "tx">) => Transaction;
16338
+ buildRequestCoinTx: (inputs: ApiFaucetRequestBody) => Transaction;
16316
16339
  fetchBuildMintSuiFrenTx: (inputs: ApiFaucetMintSuiFrenBody) => Promise<Transaction>;
16317
16340
  fetchMintCoinEvents: (inputs: EventsInputs) => Promise<EventsWithCursor<FaucetMintCoinEvent>>;
16318
16341
  fetchAddCoinEvents: (inputs: EventsInputs) => Promise<EventsWithCursor<FaucetAddCoinEvent>>;
package/dist/index.js CHANGED
@@ -5896,29 +5896,19 @@ var init_faucet = __esm({
5896
5896
  // =========================================================================
5897
5897
  // Inspections
5898
5898
  // =========================================================================
5899
- async getSupportedCoins() {
5899
+ getSupportedCoins() {
5900
5900
  return this.fetchApi("supported-coins");
5901
5901
  }
5902
5902
  // =========================================================================
5903
- // Events
5904
- // =========================================================================
5905
- // TODO: add mint coin event getter ?
5906
- // =========================================================================
5907
5903
  // Transactions
5908
5904
  // =========================================================================
5909
- async getRequestCoinTransaction(inputs) {
5905
+ getRequestCoinTransaction(inputs) {
5910
5906
  return this.faucetApi().buildRequestCoinTx(inputs);
5911
5907
  }
5912
- async getMintSuiFrenTransaction(inputs) {
5908
+ getMintSuiFrenTransaction(inputs) {
5913
5909
  return this.faucetApi().fetchBuildMintSuiFrenTx(inputs);
5914
5910
  }
5915
5911
  };
5916
- // =========================================================================
5917
- // Constants
5918
- // =========================================================================
5919
- Faucet.constants = {
5920
- defaultRequestAmountUsd: 10
5921
- };
5922
5912
  }
5923
5913
  });
5924
5914
 
@@ -9649,18 +9639,21 @@ var init_perpetualsAccount = __esm({
9649
9639
  * @returns Transaction response containing `tx`.
9650
9640
  */
9651
9641
  async getCreateTwapOrdersTx(inputs) {
9652
- if ("vaultId" in this.accountCap) {
9653
- throw new Error("TWAP orders are not yet supported for vault accounts");
9654
- }
9655
9642
  const { tx, ...otherInputs } = inputs;
9656
9643
  return this.fetchApiTxObject(
9657
- "account/transactions/create-twap-orders",
9644
+ `${this.vaultId ? "vault" : "account"}/transactions/create-twap-orders`,
9658
9645
  {
9659
9646
  ...otherInputs,
9660
9647
  txKind: await this.api?.Transactions().fetchBase64TxKindFromTx({ tx }),
9661
9648
  walletAddress: this.ownerAddress(),
9662
- accountId: this.accountCap.accountId,
9663
- accountCapId: this.accountCap.objectId
9649
+ ..."vaultId" in this.accountCap ? {
9650
+ vaultId: this.accountCap.vaultId,
9651
+ accountId: void 0
9652
+ } : {
9653
+ accountId: this.accountCap.accountId,
9654
+ accountCapId: this.accountCap.objectId,
9655
+ vaultId: void 0
9656
+ }
9664
9657
  },
9665
9658
  void 0,
9666
9659
  {
@@ -9678,18 +9671,21 @@ var init_perpetualsAccount = __esm({
9678
9671
  * @returns Transaction response containing `tx`.
9679
9672
  */
9680
9673
  async getEditTwapOrdersTx(inputs) {
9681
- if ("vaultId" in this.accountCap) {
9682
- throw new Error("TWAP orders are not yet supported for vault accounts");
9683
- }
9684
9674
  const { tx, ...otherInputs } = inputs;
9685
9675
  return this.fetchApiTxObject(
9686
- "account/transactions/edit-twap-orders",
9676
+ `${this.vaultId ? "vault" : "account"}/transactions/edit-twap-orders`,
9687
9677
  {
9688
9678
  ...otherInputs,
9689
9679
  txKind: await this.api?.Transactions().fetchBase64TxKindFromTx({ tx }),
9690
9680
  walletAddress: this.ownerAddress(),
9691
- accountId: this.accountCap.accountId,
9692
- accountCapId: this.accountCap.objectId
9681
+ ..."vaultId" in this.accountCap ? {
9682
+ vaultId: this.accountCap.vaultId,
9683
+ accountId: void 0
9684
+ } : {
9685
+ accountId: this.accountCap.accountId,
9686
+ accountCapId: this.accountCap.objectId,
9687
+ vaultId: void 0
9688
+ }
9693
9689
  },
9694
9690
  void 0,
9695
9691
  {
@@ -9707,18 +9703,21 @@ var init_perpetualsAccount = __esm({
9707
9703
  * @returns Transaction response containing `tx`.
9708
9704
  */
9709
9705
  async getCancelTwapOrdersTx(inputs) {
9710
- if ("vaultId" in this.accountCap) {
9711
- throw new Error("TWAP orders are not yet supported for vault accounts");
9712
- }
9713
9706
  const { tx, ...otherInputs } = inputs;
9714
9707
  return this.fetchApiTxObject(
9715
- "account/transactions/cancel-twap-orders",
9708
+ `${this.vaultId ? "vault" : "account"}/transactions/cancel-twap-orders`,
9716
9709
  {
9717
9710
  ...otherInputs,
9718
9711
  txKind: await this.api?.Transactions().fetchBase64TxKindFromTx({ tx }),
9719
9712
  walletAddress: this.ownerAddress(),
9720
- accountId: this.accountCap.accountId,
9721
- accountCapId: this.accountCap.objectId
9713
+ ..."vaultId" in this.accountCap ? {
9714
+ vaultId: this.accountCap.vaultId,
9715
+ accountId: void 0
9716
+ } : {
9717
+ accountId: this.accountCap.accountId,
9718
+ accountCapId: this.accountCap.objectId,
9719
+ vaultId: void 0
9720
+ }
9722
9721
  },
9723
9722
  void 0,
9724
9723
  {
@@ -9736,16 +9735,17 @@ var init_perpetualsAccount = __esm({
9736
9735
  * @returns {@link ApiPerpetualsTwapOrderDatasResponse} containing `twapOrderDatas`.
9737
9736
  */
9738
9737
  async getTwapOrderDatas(inputs) {
9739
- if ("vaultId" in this.accountCap) {
9740
- throw new Error("TWAP orders are not yet supported for vault accounts");
9741
- }
9742
9738
  const { bytes, signature, marketIds } = inputs;
9743
- return await this.fetchApi("account/twap-order-datas", {
9739
+ return await this.fetchApi(`${this.vaultId ? "vault" : "account"}/twap-order-datas`, {
9744
9740
  bytes,
9745
9741
  signature,
9746
9742
  walletAddress: this.ownerAddress(),
9747
9743
  marketIds: marketIds ?? [],
9748
- accountId: this.accountCap.accountId
9744
+ ..."vaultId" in this.accountCap ? {
9745
+ vaultId: this.accountCap.vaultId
9746
+ } : {
9747
+ accountId: this.accountCap.accountId
9748
+ }
9749
9749
  });
9750
9750
  }
9751
9751
  // public async getReduceOrderTx(inputs: {
@@ -12980,6 +12980,20 @@ var init_perpetuals = __esm({
12980
12980
  }
12981
12981
  }
12982
12982
  });
12983
+ const subscribeMarketCandles = ({
12984
+ marketId,
12985
+ interval
12986
+ }) => ctl.send({
12987
+ action: "subscribe",
12988
+ subscriptionType: { marketCandles: { marketId, interval } }
12989
+ });
12990
+ const unsubscribeMarketCandles = ({
12991
+ marketId,
12992
+ interval
12993
+ }) => ctl.send({
12994
+ action: "unsubscribe",
12995
+ subscriptionType: { marketCandles: { marketId, interval } }
12996
+ });
12983
12997
  return {
12984
12998
  ws: ctl.ws,
12985
12999
  subscribeMarket,
@@ -12998,6 +13012,8 @@ var init_perpetuals = __esm({
12998
13012
  unsubscribeUserCollateralChanges,
12999
13013
  subscribeTopOfOrderbook,
13000
13014
  unsubscribeTopOfOrderbook,
13015
+ subscribeMarketCandles,
13016
+ unsubscribeMarketCandles,
13001
13017
  close: ctl.close
13002
13018
  };
13003
13019
  }
@@ -17757,7 +17773,6 @@ var init_faucetApi = __esm({
17757
17773
  "use strict";
17758
17774
  init_eventsApiHelpers();
17759
17775
  init_transactionsApiHelpers();
17760
- init_utils();
17761
17776
  init_coin2();
17762
17777
  init_sui2();
17763
17778
  init_faucetApiCasting();
@@ -17778,35 +17793,24 @@ var init_faucetApi = __esm({
17778
17793
  // =========================================================================
17779
17794
  // Transaction Commands
17780
17795
  // =========================================================================
17781
- // public addCoinTx = (inputs: {
17782
- // tx: Transaction;
17783
- // treasuryCapId: ObjectId;
17784
- // treasuryCapType: AnyObjectType;
17785
- // }) => {
17786
- // const { tx, treasuryCapId, treasuryCapType } = inputs;
17787
- // return tx.moveCall({
17788
- // target: TransactionsApiHelpers.createTxTarget(
17789
- // this.addresses.packages.faucet,
17790
- // FaucetApi.constants.moduleNames.faucet,
17791
- // "add_coin"
17792
- // ),
17793
- // typeArguments: [treasuryCapType],
17794
- // arguments: [
17795
- // tx.object(this.addresses.objects.faucet),
17796
- // tx.object(treasuryCapId),
17797
- // ],
17798
- // });
17799
- // };
17796
+ /**
17797
+ * Mints `coinType`'s configured default amount and returns the resulting
17798
+ * `Coin<T>`. Use {@link buildRequestCoinTx} to mint and transfer it to a
17799
+ * wallet in one transaction.
17800
+ */
17800
17801
  this.requestCoinTx = (inputs) => {
17801
17802
  const { tx, coinType } = inputs;
17802
17803
  return tx.moveCall({
17803
17804
  target: TransactionsApiHelpers.createTxTarget(
17804
17805
  this.addresses.packages.faucet,
17805
17806
  _FaucetApi.constants.moduleNames.faucet,
17806
- "request_default_amount"
17807
+ "mint"
17807
17808
  ),
17808
17809
  typeArguments: [coinType],
17809
- arguments: [tx.object(this.addresses.objects.faucet)]
17810
+ arguments: [
17811
+ tx.object(this.addresses.objects.faucet),
17812
+ tx.object(this.addresses.objects.config)
17813
+ ]
17810
17814
  });
17811
17815
  };
17812
17816
  this.mintSuiFrenTx = (inputs) => {
@@ -17831,9 +17835,14 @@ var init_faucetApi = __esm({
17831
17835
  // =========================================================================
17832
17836
  // Transaction Builders
17833
17837
  // =========================================================================
17834
- this.buildRequestCoinTx = Helpers.transactions.createBuildTxFunc(
17835
- this.requestCoinTx
17836
- );
17838
+ this.buildRequestCoinTx = (inputs) => {
17839
+ const { walletAddress, coinType } = inputs;
17840
+ const tx = new Transaction9();
17841
+ tx.setSender(walletAddress);
17842
+ const coin = this.requestCoinTx({ tx, coinType });
17843
+ tx.transferObjects([coin], walletAddress);
17844
+ return tx;
17845
+ };
17837
17846
  this.fetchBuildMintSuiFrenTx = async (inputs) => {
17838
17847
  const { walletAddress, mintFee, suiFrenType } = inputs;
17839
17848
  const tx = new Transaction9();
@@ -17850,7 +17859,6 @@ var init_faucetApi = __esm({
17850
17859
  // =========================================================================
17851
17860
  // Events
17852
17861
  // =========================================================================
17853
- // TODO: add to indexer
17854
17862
  this.fetchMintCoinEvents = async (inputs) => await this.api.Events().fetchCastEventsWithCursor({
17855
17863
  ...inputs,
17856
17864
  query: {
@@ -17858,7 +17866,6 @@ var init_faucetApi = __esm({
17858
17866
  },
17859
17867
  eventFromEventOnChain: FaucetApiCasting.faucetMintCoinEventFromOnChain
17860
17868
  });
17861
- // TODO: add to indexer
17862
17869
  this.fetchAddCoinEvents = async (inputs) => await this.api.Events().fetchCastEventsWithCursor(
17863
17870
  {
17864
17871
  ...inputs,
@@ -17909,7 +17916,7 @@ var init_faucetApi = __esm({
17909
17916
  },
17910
17917
  eventNames: {
17911
17918
  mintCoin: "MintedCoin",
17912
- addCoin: "AddedCoinEvent"
17919
+ addCoin: "AddedCoin"
17913
17920
  }
17914
17921
  };
17915
17922
  FaucetApi = _FaucetApi;