@lightconexyz/lightcone-sdk 0.2.0 → 0.2.2

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 (153) hide show
  1. package/README.md +263 -34
  2. package/dist/auth/client.js.map +1 -1
  3. package/dist/client.d.ts +4 -0
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +8 -0
  6. package/dist/client.js.map +1 -1
  7. package/dist/domain/admin/client.d.ts +3 -1
  8. package/dist/domain/admin/client.d.ts.map +1 -1
  9. package/dist/domain/admin/client.js +8 -0
  10. package/dist/domain/admin/client.js.map +1 -1
  11. package/dist/domain/admin/wire.d.ts +53 -4
  12. package/dist/domain/admin/wire.d.ts.map +1 -1
  13. package/dist/domain/admin/wire.js.map +1 -1
  14. package/dist/domain/deposit_price/client.d.ts +13 -0
  15. package/dist/domain/deposit_price/client.d.ts.map +1 -0
  16. package/dist/domain/deposit_price/client.js +28 -0
  17. package/dist/domain/deposit_price/client.js.map +1 -0
  18. package/dist/domain/deposit_price/index.d.ts +9 -0
  19. package/dist/domain/deposit_price/index.d.ts.map +1 -0
  20. package/dist/domain/deposit_price/index.js +20 -0
  21. package/dist/domain/deposit_price/index.js.map +1 -0
  22. package/dist/domain/deposit_price/state.d.ts +17 -0
  23. package/dist/domain/deposit_price/state.d.ts.map +1 -0
  24. package/dist/domain/deposit_price/state.js +45 -0
  25. package/dist/domain/deposit_price/state.js.map +1 -0
  26. package/dist/domain/deposit_price/wire.d.ts +36 -0
  27. package/dist/domain/deposit_price/wire.d.ts.map +1 -0
  28. package/dist/domain/deposit_price/wire.js +3 -0
  29. package/dist/domain/deposit_price/wire.js.map +1 -0
  30. package/dist/domain/index.d.ts +2 -0
  31. package/dist/domain/index.d.ts.map +1 -1
  32. package/dist/domain/index.js +3 -1
  33. package/dist/domain/index.js.map +1 -1
  34. package/dist/domain/notification/client.d.ts +13 -0
  35. package/dist/domain/notification/client.d.ts.map +1 -0
  36. package/dist/domain/notification/client.js +21 -0
  37. package/dist/domain/notification/client.js.map +1 -0
  38. package/dist/domain/notification/index.d.ts +51 -0
  39. package/dist/domain/notification/index.d.ts.map +1 -0
  40. package/dist/domain/notification/index.js +29 -0
  41. package/dist/domain/notification/index.js.map +1 -0
  42. package/dist/domain/order/client.d.ts +2 -1
  43. package/dist/domain/order/client.d.ts.map +1 -1
  44. package/dist/domain/order/client.js +10 -2
  45. package/dist/domain/order/client.js.map +1 -1
  46. package/dist/domain/order/convert.js +3 -3
  47. package/dist/domain/order/convert.js.map +1 -1
  48. package/dist/domain/order/wire.d.ts +31 -25
  49. package/dist/domain/order/wire.d.ts.map +1 -1
  50. package/dist/domain/order/wire.js.map +1 -1
  51. package/dist/domain/orderbook/state.js +2 -2
  52. package/dist/domain/orderbook/state.js.map +1 -1
  53. package/dist/domain/orderbook/wire.d.ts +2 -0
  54. package/dist/domain/orderbook/wire.d.ts.map +1 -1
  55. package/dist/domain/orderbook/wire.js.map +1 -1
  56. package/dist/domain/position/wire.d.ts +7 -0
  57. package/dist/domain/position/wire.d.ts.map +1 -1
  58. package/dist/domain/position/wire.js.map +1 -1
  59. package/dist/domain/price_history/client.d.ts +2 -1
  60. package/dist/domain/price_history/client.d.ts.map +1 -1
  61. package/dist/domain/price_history/client.js +13 -2
  62. package/dist/domain/price_history/client.js.map +1 -1
  63. package/dist/domain/price_history/wire.d.ts +30 -7
  64. package/dist/domain/price_history/wire.d.ts.map +1 -1
  65. package/dist/domain/price_history/wire.js.map +1 -1
  66. package/dist/domain/trade/client.d.ts +1 -1
  67. package/dist/domain/trade/client.js +3 -3
  68. package/dist/domain/trade/client.js.map +1 -1
  69. package/dist/error.d.ts.map +1 -1
  70. package/dist/error.js +3 -0
  71. package/dist/error.js.map +1 -1
  72. package/dist/http/client.d.ts.map +1 -1
  73. package/dist/http/client.js +5 -4
  74. package/dist/http/client.js.map +1 -1
  75. package/dist/index.d.ts +1 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js.map +1 -1
  78. package/dist/prelude.d.ts +12 -5
  79. package/dist/prelude.d.ts.map +1 -1
  80. package/dist/prelude.js +8 -1
  81. package/dist/prelude.js.map +1 -1
  82. package/dist/privy/client.d.ts +4 -5
  83. package/dist/privy/client.d.ts.map +1 -1
  84. package/dist/privy/client.js +2 -11
  85. package/dist/privy/client.js.map +1 -1
  86. package/dist/privy/index.d.ts +41 -1
  87. package/dist/privy/index.d.ts.map +1 -1
  88. package/dist/privy/index.js +2 -0
  89. package/dist/privy/index.js.map +1 -1
  90. package/dist/program/accounts.d.ts +2 -4
  91. package/dist/program/accounts.d.ts.map +1 -1
  92. package/dist/program/accounts.js +2 -5
  93. package/dist/program/accounts.js.map +1 -1
  94. package/dist/program/builder.d.ts +5 -13
  95. package/dist/program/builder.d.ts.map +1 -1
  96. package/dist/program/builder.js +9 -13
  97. package/dist/program/builder.js.map +1 -1
  98. package/dist/program/client.d.ts +8 -7
  99. package/dist/program/client.d.ts.map +1 -1
  100. package/dist/program/client.js +11 -12
  101. package/dist/program/client.js.map +1 -1
  102. package/dist/program/constants.js +1 -1
  103. package/dist/program/constants.js.map +1 -1
  104. package/dist/program/envelope.d.ts +7 -2
  105. package/dist/program/envelope.d.ts.map +1 -1
  106. package/dist/program/envelope.js +29 -21
  107. package/dist/program/envelope.js.map +1 -1
  108. package/dist/program/index.d.ts +3 -3
  109. package/dist/program/index.d.ts.map +1 -1
  110. package/dist/program/index.js +5 -3
  111. package/dist/program/index.js.map +1 -1
  112. package/dist/program/instructions.d.ts +31 -53
  113. package/dist/program/instructions.d.ts.map +1 -1
  114. package/dist/program/instructions.js +155 -216
  115. package/dist/program/instructions.js.map +1 -1
  116. package/dist/program/orders.d.ts +20 -19
  117. package/dist/program/orders.d.ts.map +1 -1
  118. package/dist/program/orders.js +34 -22
  119. package/dist/program/orders.js.map +1 -1
  120. package/dist/program/types.d.ts +23 -24
  121. package/dist/program/types.d.ts.map +1 -1
  122. package/dist/program/types.js.map +1 -1
  123. package/dist/shared/index.d.ts +1 -1
  124. package/dist/shared/index.d.ts.map +1 -1
  125. package/dist/shared/index.js +2 -1
  126. package/dist/shared/index.js.map +1 -1
  127. package/dist/shared/types.d.ts +10 -3
  128. package/dist/shared/types.d.ts.map +1 -1
  129. package/dist/shared/types.js +6 -1
  130. package/dist/shared/types.js.map +1 -1
  131. package/dist/ws/client.browser.d.ts +46 -0
  132. package/dist/ws/client.browser.d.ts.map +1 -0
  133. package/dist/ws/client.browser.js +245 -0
  134. package/dist/ws/client.browser.js.map +1 -0
  135. package/dist/ws/{client.d.ts → client.node.d.ts} +3 -2
  136. package/dist/ws/client.node.d.ts.map +1 -0
  137. package/dist/ws/{client.js → client.node.js} +3 -3
  138. package/dist/ws/client.node.js.map +1 -0
  139. package/dist/ws/index.d.ts +10 -1
  140. package/dist/ws/index.d.ts.map +1 -1
  141. package/dist/ws/index.js +50 -2
  142. package/dist/ws/index.js.map +1 -1
  143. package/dist/ws/subscriptions.d.ts +8 -0
  144. package/dist/ws/subscriptions.d.ts.map +1 -1
  145. package/dist/ws/subscriptions.js +5 -0
  146. package/dist/ws/subscriptions.js.map +1 -1
  147. package/dist/ws/types.d.ts +23 -0
  148. package/dist/ws/types.d.ts.map +1 -0
  149. package/dist/ws/types.js +3 -0
  150. package/dist/ws/types.js.map +1 -0
  151. package/package.json +10 -4
  152. package/dist/ws/client.d.ts.map +0 -1
  153. package/dist/ws/client.js.map +0 -1
@@ -20,10 +20,11 @@ exports.buildWhitelistDepositTokenIx = buildWhitelistDepositTokenIx;
20
20
  exports.buildDepositToGlobalIx = buildDepositToGlobalIx;
21
21
  exports.buildGlobalToMarketDepositIx = buildGlobalToMarketDepositIx;
22
22
  exports.buildInitPositionTokensIx = buildInitPositionTokensIx;
23
- exports.buildDepositAndSwapIx = buildDepositAndSwapIx;
24
23
  exports.buildExtendPositionTokensIx = buildExtendPositionTokensIx;
24
+ exports.buildDepositAndSwapIx = buildDepositAndSwapIx;
25
25
  const web3_js_1 = require("@solana/web3.js");
26
26
  const constants_1 = require("./constants");
27
+ const types_1 = require("./types");
27
28
  const pda_1 = require("./pda");
28
29
  const utils_1 = require("./utils");
29
30
  const orders_1 = require("./orders");
@@ -117,8 +118,9 @@ function serializeOutcomeMetadata(metadata) {
117
118
  * Build AddDepositMint instruction
118
119
  *
119
120
  * Accounts:
120
- * 0. payer (signer)
121
- * 1. market
121
+ * 0. authority (signer)
122
+ * 1. exchange
123
+ * 2. market
122
124
  * 2. deposit_mint
123
125
  * 3. vault
124
126
  * 4. mint_authority
@@ -133,14 +135,14 @@ function buildAddDepositMintIx(params, market, numOutcomes, programId = constant
133
135
  if (params.outcomeMetadata.length !== numOutcomes) {
134
136
  throw new Error(`Outcome metadata count (${params.outcomeMetadata.length}) must match numOutcomes (${numOutcomes})`);
135
137
  }
136
- const [exchange] = (0, pda_1.getExchangePda)(programId);
137
138
  const [vault] = (0, pda_1.getVaultPda)(params.depositMint, market, programId);
138
139
  const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(market, programId);
139
140
  const conditionalMints = (0, pda_1.getAllConditionalMintPdas)(market, params.depositMint, numOutcomes, programId);
141
+ const [exchange] = (0, pda_1.getExchangePda)(programId);
140
142
  const keys = [
141
- signerMut(params.payer),
143
+ signerMut(params.authority),
142
144
  readonly(exchange),
143
- readonly(market),
145
+ writable(market),
144
146
  readonly(params.depositMint),
145
147
  writable(vault),
146
148
  readonly(mintAuthority),
@@ -660,7 +662,7 @@ function buildSetAuthorityIx(params, programId = constants_1.PROGRAM_ID) {
660
662
  * Build CreateOrderbook instruction
661
663
  *
662
664
  * Accounts:
663
- * 0. payer (signer, mut)
665
+ * 0. authority (signer, mut)
664
666
  * 1. market (readonly)
665
667
  * 2. mint_a (readonly)
666
668
  * 3. mint_b (readonly)
@@ -677,7 +679,7 @@ function buildCreateOrderbookIx(params, programId = constants_1.PROGRAM_ID) {
677
679
  const [orderbook] = (0, pda_1.getOrderbookPda)(params.mintA, params.mintB, programId);
678
680
  const [alt] = (0, pda_1.getAltPda)(orderbook, params.recentSlot);
679
681
  const keys = [
680
- signerMut(params.payer),
682
+ signerMut(params.authority),
681
683
  readonly(params.market),
682
684
  readonly(params.mintA),
683
685
  readonly(params.mintB),
@@ -714,7 +716,7 @@ function buildWhitelistDepositTokenIx(params, programId = constants_1.PROGRAM_ID
714
716
  const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(params.mint, programId);
715
717
  const keys = [
716
718
  signerMut(params.authority),
717
- writable(exchange),
719
+ readonly(exchange),
718
720
  readonly(params.mint),
719
721
  writable(globalDepositToken),
720
722
  readonly(constants_1.SYSTEM_PROGRAM_ID),
@@ -737,12 +739,7 @@ function buildWhitelistDepositTokenIx(params, programId = constants_1.PROGRAM_ID
737
739
  * 5. token_program (readonly)
738
740
  * 6. system_program (readonly)
739
741
  *
740
- * Optional (for ALT creation/extension when first deposit to this mint):
741
- * 7. user_nonce (readonly)
742
- * 8. lookup_table (mut)
743
- * 9. alt_program (readonly)
744
- *
745
- * Data: [discriminator, amount (u64), optional recent_slot (u64)]
742
+ * Data: [discriminator, amount (u64)]
746
743
  */
747
744
  function buildDepositToGlobalIx(params, programId = constants_1.PROGRAM_ID) {
748
745
  const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(params.mint, programId);
@@ -757,24 +754,14 @@ function buildDepositToGlobalIx(params, programId = constants_1.PROGRAM_ID) {
757
754
  readonly(constants_1.TOKEN_PROGRAM_ID),
758
755
  readonly(constants_1.SYSTEM_PROGRAM_ID),
759
756
  ];
760
- // Optional ALT accounts
761
- if (params.userNonce && params.lookupTable) {
762
- keys.push(readonly(params.userNonce));
763
- keys.push(writable(params.lookupTable));
764
- keys.push(readonly(constants_1.ALT_PROGRAM_ID));
765
- }
766
- const dataBuffers = [
757
+ const data = Buffer.concat([
767
758
  Buffer.from([constants_1.INSTRUCTION.DEPOSIT_TO_GLOBAL]),
768
759
  (0, utils_1.toU64Le)(params.amount),
769
- ];
770
- // Optional recent_slot for ALT creation
771
- if (params.recentSlot !== undefined) {
772
- dataBuffers.push((0, utils_1.toU64Le)(params.recentSlot));
773
- }
760
+ ]);
774
761
  return new web3_js_1.TransactionInstruction({
775
762
  keys,
776
763
  programId,
777
- data: Buffer.concat(dataBuffers),
764
+ data,
778
765
  });
779
766
  }
780
767
  /**
@@ -840,30 +827,25 @@ function buildGlobalToMarketDepositIx(params, numOutcomes, programId = constants
840
827
  }
841
828
  /**
842
829
  * Build InitPositionTokens instruction
843
- * Permissionless: payer pays, user is position owner (no signature required)
844
830
  *
845
831
  * Accounts:
846
- * 0. payer (signer, mut)
847
- * 1. user (readonly)
848
- * 2. exchange (readonly)
849
- * 3. market (readonly)
850
- * 4. position (mut)
851
- * 5. lookup_table (mut)
852
- * 6. mint_authority (readonly)
853
- * 7. token_2022_program (readonly)
854
- * 8. ata_program (readonly)
855
- * 9. alt_program (readonly)
856
- * 10. system_program (readonly)
857
- *
858
- * Remaining per deposit_mint (in ascending GDT index order):
859
- * deposit_mint, vault, gdt, [conditional_mint[i], position_conditional_ata[i]]*numOutcomes
832
+ * 0. user (signer, mut)
833
+ * 1. exchange (readonly)
834
+ * 2. market (readonly)
835
+ * 3. deposit_mint (readonly)
836
+ * 4. vault (readonly)
837
+ * 5. position (mut)
838
+ * 6. lookup_table (mut)
839
+ * 7. mint_authority (readonly)
840
+ * 8. token_2022_program (readonly)
841
+ * 9. ata_program (readonly)
842
+ * 10. alt_program (readonly)
843
+ * 11. system_program (readonly)
844
+ * + per outcome: conditional_mint[i] (readonly), position_conditional_ata[i] (mut)
860
845
  *
861
- * Data: [discriminator, recent_slot (u64), num_deposit_mints (u8)]
846
+ * Data: [discriminator, recent_slot (u64)]
862
847
  */
863
848
  function buildInitPositionTokensIx(params, numOutcomes, programId = constants_1.PROGRAM_ID) {
864
- if (params.depositMints.length === 0) {
865
- throw new Error("At least one deposit mint is required");
866
- }
867
849
  const [exchange] = (0, pda_1.getExchangePda)(programId);
868
850
  const [position] = (0, pda_1.getPositionPda)(params.user, params.market, programId);
869
851
  const [lookupTable] = (0, pda_1.getPositionAltPda)(position, params.recentSlot);
@@ -881,7 +863,6 @@ function buildInitPositionTokensIx(params, numOutcomes, programId = constants_1.
881
863
  readonly(constants_1.ALT_PROGRAM_ID),
882
864
  readonly(constants_1.SYSTEM_PROGRAM_ID),
883
865
  ];
884
- // Remaining accounts: per deposit_mint group
885
866
  for (const depositMint of params.depositMints) {
886
867
  const [vault] = (0, pda_1.getVaultPda)(depositMint, params.market, programId);
887
868
  const [gdt] = (0, pda_1.getGlobalDepositTokenPda)(depositMint, programId);
@@ -905,166 +886,10 @@ function buildInitPositionTokensIx(params, numOutcomes, programId = constants_1.
905
886
  data,
906
887
  });
907
888
  }
908
- /**
909
- * Build DepositAndSwap instruction.
910
- *
911
- * deposit_bitmask controls per-participant deposit vs swap routing:
912
- * bit 7 = taker deposits, bits 0..n = maker i deposits
913
- *
914
- * Account layout:
915
- * Fixed (5): operator, exchange, market, mint_authority, token_program
916
- * Taker: [order_status], nonce, position, base_mint, quote_mint,
917
- * taker_receive_ata, taker_give_ata, token_2022, system
918
- * Taker deposit (if bit 7): deposit_mint, vault, gdt, user_global_deposit,
919
- * [cond_mint, ata]*numOutcomes
920
- * Per maker:
921
- * Common: [order_status], nonce, position
922
- * If deposit: deposit_mint, vault, gdt, user_global_deposit,
923
- * [cond_mint, ata]*numOutcomes, maker_receive_ata, maker_give_ata
924
- * If swap: maker_receive_ata, maker_give_ata
925
- *
926
- * Data: [disc, takerOrder(29), takerSig(64), numMakers(1),
927
- * fullFillBitmask(1), depositBitmask(1), ...makerData(109*n)]
928
- */
929
- function buildDepositAndSwapIx(params, numOutcomes, programId = constants_1.PROGRAM_ID) {
930
- if (params.makerOrders.length === 0) {
931
- throw new Error("maker_orders is required");
932
- }
933
- if (params.makerOrders.length > constants_1.MAX_MAKERS) {
934
- throw new Error(`Too many makers: ${params.makerOrders.length}`);
935
- }
936
- if (params.makerOrders.length !== params.makerFillAmounts.length) {
937
- throw new Error("maker_fill_amounts length must match maker_orders");
938
- }
939
- if (params.makerOrders.length !== params.takerFillAmounts.length) {
940
- throw new Error("taker_fill_amounts length must match maker_orders");
941
- }
942
- const [exchange] = (0, pda_1.getExchangePda)(programId);
943
- const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(params.market, programId);
944
- const takerOrderHash = (0, orders_1.hashOrder)(params.takerOrder);
945
- const [takerNonce] = (0, pda_1.getUserNoncePda)(params.takerOrder.maker, programId);
946
- const [takerPosition] = (0, pda_1.getPositionPda)(params.takerOrder.maker, params.market, programId);
947
- const takerFullFill = (params.fullFillBitmask & 0x80) !== 0;
948
- const takerIsDeposit = (params.depositBitmask & 0x80) !== 0;
949
- // Determine receive/give mints based on taker side
950
- const takerSide = params.takerOrder.side;
951
- const receiveMint = takerSide === 0 ? params.baseMint : params.quoteMint;
952
- const giveMint = takerSide === 0 ? params.quoteMint : params.baseMint;
953
- const keys = [];
954
- // Fixed accounts (5)
955
- keys.push(signerMut(params.operator));
956
- keys.push(readonly(exchange));
957
- keys.push(readonly(params.market));
958
- keys.push(readonly(mintAuthority));
959
- keys.push(readonly(constants_1.TOKEN_PROGRAM_ID));
960
- // Taker order_status (if not fully filled)
961
- if (!takerFullFill) {
962
- const [takerOrderStatus] = (0, pda_1.getOrderStatusPda)(takerOrderHash, programId);
963
- keys.push(writable(takerOrderStatus));
964
- }
965
- // Taker common block (8 accounts)
966
- keys.push(readonly(takerNonce));
967
- keys.push(writable(takerPosition));
968
- keys.push(readonly(params.baseMint));
969
- keys.push(readonly(params.quoteMint));
970
- const takerReceiveAta = (0, utils_1.getConditionalTokenAta)(receiveMint, takerPosition);
971
- const takerGiveAta = (0, utils_1.getConditionalTokenAta)(giveMint, takerPosition);
972
- keys.push(writable(takerReceiveAta));
973
- keys.push(writable(takerGiveAta));
974
- keys.push(readonly(constants_1.TOKEN_2022_PROGRAM_ID));
975
- keys.push(readonly(constants_1.SYSTEM_PROGRAM_ID));
976
- // Taker deposit block (if taker deposits)
977
- if (takerIsDeposit) {
978
- if (!params.takerDepositMint) {
979
- throw new Error("takerDepositMint is required when taker deposits (depositBitmask bit 7)");
980
- }
981
- const takerDm = params.takerDepositMint;
982
- const [takerVault] = (0, pda_1.getVaultPda)(takerDm, params.market, programId);
983
- const [takerGdt] = (0, pda_1.getGlobalDepositTokenPda)(takerDm, programId);
984
- const [takerUgd] = (0, pda_1.getUserGlobalDepositPda)(params.takerOrder.maker, takerDm, programId);
985
- keys.push(readonly(takerDm));
986
- keys.push(writable(takerVault));
987
- keys.push(readonly(takerGdt));
988
- keys.push(writable(takerUgd));
989
- for (let j = 0; j < numOutcomes; j += 1) {
990
- const [conditionalMint] = (0, pda_1.getAllConditionalMintPdas)(params.market, takerDm, numOutcomes, programId)[j];
991
- keys.push(writable(conditionalMint));
992
- keys.push(writable((0, utils_1.getConditionalTokenAta)(conditionalMint, takerPosition)));
993
- }
994
- }
995
- // Per-maker accounts
996
- for (let i = 0; i < params.makerOrders.length; i += 1) {
997
- const makerOrder = params.makerOrders[i];
998
- const makerFullFill = (params.fullFillBitmask & (1 << i)) !== 0;
999
- const makerIsDeposit = (params.depositBitmask & (1 << i)) !== 0;
1000
- // Maker order_status (if not fully filled)
1001
- if (!makerFullFill) {
1002
- const makerOrderHash = (0, orders_1.hashOrder)(makerOrder);
1003
- const [makerOrderStatus] = (0, pda_1.getOrderStatusPda)(makerOrderHash, programId);
1004
- keys.push(writable(makerOrderStatus));
1005
- }
1006
- const [makerNonce] = (0, pda_1.getUserNoncePda)(makerOrder.maker, programId);
1007
- const [makerPosition] = (0, pda_1.getPositionPda)(makerOrder.maker, params.market, programId);
1008
- // Common: nonce, position
1009
- keys.push(readonly(makerNonce));
1010
- keys.push(writable(makerPosition));
1011
- if (makerIsDeposit) {
1012
- // Maker deposit: deposit_mint, vault, gdt, ugd, [cond_mint, ata]*n, receive_ata, give_ata
1013
- const makerDm = params.makerDepositMints?.[i];
1014
- if (!makerDm) {
1015
- throw new Error(`makerDepositMints[${i}] is required when maker ${i} deposits`);
1016
- }
1017
- const [makerVault] = (0, pda_1.getVaultPda)(makerDm, params.market, programId);
1018
- const [makerGdt] = (0, pda_1.getGlobalDepositTokenPda)(makerDm, programId);
1019
- const [makerUgd] = (0, pda_1.getUserGlobalDepositPda)(makerOrder.maker, makerDm, programId);
1020
- keys.push(readonly(makerDm));
1021
- keys.push(writable(makerVault));
1022
- keys.push(readonly(makerGdt));
1023
- keys.push(writable(makerUgd));
1024
- for (let j = 0; j < numOutcomes; j += 1) {
1025
- const [conditionalMint] = (0, pda_1.getAllConditionalMintPdas)(params.market, makerDm, numOutcomes, programId)[j];
1026
- keys.push(writable(conditionalMint));
1027
- keys.push(writable((0, utils_1.getConditionalTokenAta)(conditionalMint, makerPosition)));
1028
- }
1029
- // Maker swap ATAs (always present after deposit block)
1030
- const makerReceiveAta = (0, utils_1.getConditionalTokenAta)(receiveMint, makerPosition);
1031
- const makerGiveAta = (0, utils_1.getConditionalTokenAta)(giveMint, makerPosition);
1032
- keys.push(writable(makerReceiveAta));
1033
- keys.push(writable(makerGiveAta));
1034
- }
1035
- else {
1036
- // Maker swap: receive_ata, give_ata
1037
- const makerReceiveAta = (0, utils_1.getConditionalTokenAta)(receiveMint, makerPosition);
1038
- const makerGiveAta = (0, utils_1.getConditionalTokenAta)(giveMint, makerPosition);
1039
- keys.push(writable(makerReceiveAta));
1040
- keys.push(writable(makerGiveAta));
1041
- }
1042
- }
1043
- // Build data (96-byte header + 109 per maker)
1044
- const buffers = [
1045
- Buffer.from([constants_1.INSTRUCTION.DEPOSIT_AND_SWAP]),
1046
- (0, orders_1.serializeOrder)((0, orders_1.signedOrderToOrder)(params.takerOrder)),
1047
- params.takerOrder.signature,
1048
- (0, utils_1.toU8)(params.makerOrders.length),
1049
- (0, utils_1.toU8)(params.fullFillBitmask),
1050
- (0, utils_1.toU8)(params.depositBitmask),
1051
- ];
1052
- for (let i = 0; i < params.makerOrders.length; i += 1) {
1053
- const makerOrder = params.makerOrders[i];
1054
- buffers.push((0, orders_1.serializeOrder)((0, orders_1.signedOrderToOrder)(makerOrder)));
1055
- buffers.push(makerOrder.signature);
1056
- buffers.push((0, utils_1.toU64Le)(params.makerFillAmounts[i]));
1057
- buffers.push((0, utils_1.toU64Le)(params.takerFillAmounts[i]));
1058
- }
1059
- return new web3_js_1.TransactionInstruction({
1060
- keys,
1061
- programId,
1062
- data: Buffer.concat(buffers),
1063
- });
1064
- }
1065
889
  /**
1066
890
  * Build ExtendPositionTokens instruction
1067
- * Permissionless: anyone can pay to extend ALTs for any user
891
+ *
892
+ * Extends an existing position's lookup table with new deposit mints.
1068
893
  *
1069
894
  * Accounts:
1070
895
  * 0. payer (signer, mut)
@@ -1077,15 +902,15 @@ function buildDepositAndSwapIx(params, numOutcomes, programId = constants_1.PROG
1077
902
  * 7. ata_program (readonly)
1078
903
  * 8. alt_program (readonly)
1079
904
  * 9. system_program (readonly)
1080
- *
1081
- * Remaining per deposit_mint (in ascending GDT index order):
1082
- * deposit_mint, vault, gdt, [conditional_mint[i], position_conditional_ata[i]]*numOutcomes
905
+ * Per deposit_mint:
906
+ * deposit_mint (readonly), vault (readonly), gdt (readonly),
907
+ * per outcome: conditional_mint (readonly), position_ata (mut)
1083
908
  *
1084
909
  * Data: [discriminator, num_deposit_mints (u8)]
1085
910
  */
1086
- function buildExtendPositionTokensIx(params, numOutcomes, lookupTable, programId = constants_1.PROGRAM_ID) {
911
+ function buildExtendPositionTokensIx(params, numOutcomes, programId = constants_1.PROGRAM_ID) {
1087
912
  if (params.depositMints.length === 0) {
1088
- throw new Error("At least one deposit mint is required");
913
+ throw new Error("deposit_mints is required");
1089
914
  }
1090
915
  const [exchange] = (0, pda_1.getExchangePda)(programId);
1091
916
  const [position] = (0, pda_1.getPositionPda)(params.user, params.market, programId);
@@ -1095,13 +920,12 @@ function buildExtendPositionTokensIx(params, numOutcomes, lookupTable, programId
1095
920
  readonly(exchange),
1096
921
  readonly(params.market),
1097
922
  readonly(position),
1098
- writable(lookupTable),
923
+ writable(params.lookupTable),
1099
924
  readonly(constants_1.TOKEN_2022_PROGRAM_ID),
1100
925
  readonly(constants_1.ASSOCIATED_TOKEN_PROGRAM_ID),
1101
926
  readonly(constants_1.ALT_PROGRAM_ID),
1102
927
  readonly(constants_1.SYSTEM_PROGRAM_ID),
1103
928
  ];
1104
- // Remaining accounts: per deposit_mint group
1105
929
  for (const depositMint of params.depositMints) {
1106
930
  const [vault] = (0, pda_1.getVaultPda)(depositMint, params.market, programId);
1107
931
  const [gdt] = (0, pda_1.getGlobalDepositTokenPda)(depositMint, programId);
@@ -1114,9 +938,9 @@ function buildExtendPositionTokensIx(params, numOutcomes, lookupTable, programId
1114
938
  keys.push(writable((0, utils_1.getConditionalTokenAta)(conditionalMint, position)));
1115
939
  }
1116
940
  }
1117
- const data = Buffer.concat([
1118
- Buffer.from([constants_1.INSTRUCTION.EXTEND_POSITION_TOKENS]),
1119
- (0, utils_1.toU8)(params.depositMints.length),
941
+ const data = Buffer.from([
942
+ constants_1.INSTRUCTION.EXTEND_POSITION_TOKENS,
943
+ params.depositMints.length,
1120
944
  ]);
1121
945
  return new web3_js_1.TransactionInstruction({
1122
946
  keys,
@@ -1124,4 +948,119 @@ function buildExtendPositionTokensIx(params, numOutcomes, lookupTable, programId
1124
948
  data,
1125
949
  });
1126
950
  }
951
+ /**
952
+ * Build DepositAndSwap instruction.
953
+ * Supports a mix of global deposits and token swaps in a single instruction.
954
+ */
955
+ function buildDepositAndSwapIx(params, programId = constants_1.PROGRAM_ID) {
956
+ (0, utils_1.validateOutcomes)(params.numOutcomes);
957
+ if (params.makers.length === 0) {
958
+ throw new Error("makers is required");
959
+ }
960
+ if (params.makers.length > constants_1.MAX_MAKERS) {
961
+ throw new Error(`Too many makers: ${params.makers.length}`);
962
+ }
963
+ const [exchange] = (0, pda_1.getExchangePda)(programId);
964
+ const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(params.market, programId);
965
+ const [takerNonce] = (0, pda_1.getUserNoncePda)(params.takerOrder.maker, programId);
966
+ const [takerPosition] = (0, pda_1.getPositionPda)(params.takerOrder.maker, params.market, programId);
967
+ const [receiveMint, giveMint] = params.takerOrder.side === types_1.OrderSide.BID
968
+ ? [params.baseMint, params.quoteMint]
969
+ : [params.quoteMint, params.baseMint];
970
+ let fullFillBitmask = 0;
971
+ let depositBitmask = 0;
972
+ if (params.takerIsFullFill) {
973
+ fullFillBitmask |= 0x80;
974
+ }
975
+ if (params.takerIsDeposit) {
976
+ depositBitmask |= 0x80;
977
+ }
978
+ for (let i = 0; i < params.makers.length; i += 1) {
979
+ const maker = params.makers[i];
980
+ if (maker.isFullFill) {
981
+ fullFillBitmask |= 1 << i;
982
+ }
983
+ if (maker.isDeposit) {
984
+ depositBitmask |= 1 << i;
985
+ }
986
+ }
987
+ const keys = [
988
+ signerMut(params.operator),
989
+ readonly(exchange),
990
+ readonly(params.market),
991
+ readonly(mintAuthority),
992
+ readonly(constants_1.TOKEN_PROGRAM_ID),
993
+ ];
994
+ if (!params.takerIsFullFill) {
995
+ const takerOrderHash = (0, orders_1.hashOrder)(params.takerOrder);
996
+ const [takerOrderStatus] = (0, pda_1.getOrderStatusPda)(takerOrderHash, programId);
997
+ keys.push(writable(takerOrderStatus));
998
+ }
999
+ keys.push(readonly(takerNonce));
1000
+ keys.push(writable(takerPosition));
1001
+ keys.push(readonly(params.baseMint));
1002
+ keys.push(readonly(params.quoteMint));
1003
+ keys.push(writable((0, utils_1.getConditionalTokenAta)(receiveMint, takerPosition)));
1004
+ keys.push(writable((0, utils_1.getConditionalTokenAta)(giveMint, takerPosition)));
1005
+ keys.push(readonly(constants_1.TOKEN_2022_PROGRAM_ID));
1006
+ keys.push(readonly(constants_1.SYSTEM_PROGRAM_ID));
1007
+ if (params.takerIsDeposit) {
1008
+ const [vault] = (0, pda_1.getVaultPda)(params.takerDepositMint, params.market, programId);
1009
+ const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(params.takerDepositMint, programId);
1010
+ const [takerGlobalDeposit] = (0, pda_1.getUserGlobalDepositPda)(params.takerOrder.maker, params.takerDepositMint, programId);
1011
+ keys.push(readonly(params.takerDepositMint));
1012
+ keys.push(writable(vault));
1013
+ keys.push(readonly(globalDepositToken));
1014
+ keys.push(writable(takerGlobalDeposit));
1015
+ for (const [conditionalMint] of (0, pda_1.getAllConditionalMintPdas)(params.market, params.takerDepositMint, params.numOutcomes, programId)) {
1016
+ keys.push(writable(conditionalMint));
1017
+ keys.push(writable((0, utils_1.getConditionalTokenAta)(conditionalMint, takerPosition)));
1018
+ }
1019
+ }
1020
+ for (const maker of params.makers) {
1021
+ const [makerNonce] = (0, pda_1.getUserNoncePda)(maker.order.maker, programId);
1022
+ const [makerPosition] = (0, pda_1.getPositionPda)(maker.order.maker, params.market, programId);
1023
+ if (!maker.isFullFill) {
1024
+ const makerOrderHash = (0, orders_1.hashOrder)(maker.order);
1025
+ const [makerOrderStatus] = (0, pda_1.getOrderStatusPda)(makerOrderHash, programId);
1026
+ keys.push(writable(makerOrderStatus));
1027
+ }
1028
+ keys.push(readonly(makerNonce));
1029
+ keys.push(writable(makerPosition));
1030
+ if (maker.isDeposit) {
1031
+ const [vault] = (0, pda_1.getVaultPda)(maker.depositMint, params.market, programId);
1032
+ const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(maker.depositMint, programId);
1033
+ const [makerGlobalDeposit] = (0, pda_1.getUserGlobalDepositPda)(maker.order.maker, maker.depositMint, programId);
1034
+ keys.push(readonly(maker.depositMint));
1035
+ keys.push(writable(vault));
1036
+ keys.push(readonly(globalDepositToken));
1037
+ keys.push(writable(makerGlobalDeposit));
1038
+ for (const [conditionalMint] of (0, pda_1.getAllConditionalMintPdas)(params.market, maker.depositMint, params.numOutcomes, programId)) {
1039
+ keys.push(writable(conditionalMint));
1040
+ keys.push(writable((0, utils_1.getConditionalTokenAta)(conditionalMint, makerPosition)));
1041
+ }
1042
+ }
1043
+ keys.push(writable((0, utils_1.getConditionalTokenAta)(receiveMint, makerPosition)));
1044
+ keys.push(writable((0, utils_1.getConditionalTokenAta)(giveMint, makerPosition)));
1045
+ }
1046
+ const buffers = [
1047
+ Buffer.from([constants_1.INSTRUCTION.DEPOSIT_AND_SWAP]),
1048
+ (0, orders_1.serializeOrder)((0, orders_1.signedOrderToOrder)(params.takerOrder)),
1049
+ params.takerOrder.signature,
1050
+ (0, utils_1.toU8)(params.makers.length),
1051
+ (0, utils_1.toU8)(fullFillBitmask),
1052
+ (0, utils_1.toU8)(depositBitmask),
1053
+ ];
1054
+ for (const maker of params.makers) {
1055
+ buffers.push((0, orders_1.serializeOrder)((0, orders_1.signedOrderToOrder)(maker.order)));
1056
+ buffers.push(maker.order.signature);
1057
+ buffers.push((0, utils_1.toU64Le)(maker.makerFillAmount));
1058
+ buffers.push((0, utils_1.toU64Le)(maker.takerFillAmount));
1059
+ }
1060
+ return new web3_js_1.TransactionInstruction({
1061
+ keys,
1062
+ programId,
1063
+ data: Buffer.concat(buffers),
1064
+ });
1065
+ }
1127
1066
  //# sourceMappingURL=instructions.js.map