@theliem/xmarket-sdk 3.9.0 → 3.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.
package/dist/index.d.mts CHANGED
@@ -1078,6 +1078,18 @@ declare function detectMatchType(a: Order | SignedOrder, b: Order | SignedOrder)
1078
1078
 
1079
1079
  /** Maximum u64 — approve "unlimited" amount. */
1080
1080
  declare const MAX_APPROVE_AMOUNT: BN;
1081
+ /**
1082
+ * Build a Transaction that creates YES and NO Token-2022 ATAs for a user
1083
+ * (idempotent — safe to call even if they already exist).
1084
+ *
1085
+ * Required signer: payer (fee payer). No user signature needed.
1086
+ *
1087
+ * @param condition - condition PDA
1088
+ * @param user - wallet that will own the ATAs
1089
+ * @param payer - fee payer wallet pubkey
1090
+ * @param programIds - network program IDs
1091
+ */
1092
+ declare function buildCreateUserAtasTx(condition: PublicKey, user: PublicKey, payer: PublicKey, programIds: ProgramIds): Transaction;
1081
1093
  /**
1082
1094
  * Build a Transaction that approves the CLOB config PDA to transfer collateral
1083
1095
  * (USDC) from the signer's ATA.
@@ -1099,4 +1111,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1099
1111
  */
1100
1112
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1101
1113
 
1102
- export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1114
+ export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.d.ts CHANGED
@@ -1078,6 +1078,18 @@ declare function detectMatchType(a: Order | SignedOrder, b: Order | SignedOrder)
1078
1078
 
1079
1079
  /** Maximum u64 — approve "unlimited" amount. */
1080
1080
  declare const MAX_APPROVE_AMOUNT: BN;
1081
+ /**
1082
+ * Build a Transaction that creates YES and NO Token-2022 ATAs for a user
1083
+ * (idempotent — safe to call even if they already exist).
1084
+ *
1085
+ * Required signer: payer (fee payer). No user signature needed.
1086
+ *
1087
+ * @param condition - condition PDA
1088
+ * @param user - wallet that will own the ATAs
1089
+ * @param payer - fee payer wallet pubkey
1090
+ * @param programIds - network program IDs
1091
+ */
1092
+ declare function buildCreateUserAtasTx(condition: PublicKey, user: PublicKey, payer: PublicKey, programIds: ProgramIds): Transaction;
1081
1093
  /**
1082
1094
  * Build a Transaction that approves the CLOB config PDA to transfer collateral
1083
1095
  * (USDC) from the signer's ATA.
@@ -1099,4 +1111,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1099
1111
  */
1100
1112
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1101
1113
 
1102
- export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1114
+ export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.js CHANGED
@@ -1619,10 +1619,10 @@ ${logs.join("\n")}`);
1619
1619
  connection.getAccountInfo(clobYesAta),
1620
1620
  connection.getAccountInfo(clobNoAta)
1621
1621
  ]);
1622
- const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction2 } = await import('@solana/spl-token');
1622
+ const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction3 } = await import('@solana/spl-token');
1623
1623
  const ixs = [];
1624
1624
  if (!yesInfo) {
1625
- ixs.push(createAssociatedTokenAccountIdempotentInstruction2(
1625
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction3(
1626
1626
  this.walletPubkey,
1627
1627
  clobYesAta,
1628
1628
  clobConfig,
@@ -1631,7 +1631,7 @@ ${logs.join("\n")}`);
1631
1631
  ));
1632
1632
  }
1633
1633
  if (!noInfo) {
1634
- ixs.push(createAssociatedTokenAccountIdempotentInstruction2(
1634
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction3(
1635
1635
  this.walletPubkey,
1636
1636
  clobNoAta,
1637
1637
  clobConfig,
@@ -2156,10 +2156,19 @@ ${logs.join("\n")}`);
2156
2156
  const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
2157
2157
  const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
2158
2158
  if (!allBuy && !allSell) throw new InvalidParamError("MINT/MERGE: all orders must be same side");
2159
- if (t.tokenId !== 1) throw new InvalidParamError("MINT/MERGE: taker must be YES (tokenId=1)");
2160
- if (!makers.every((m) => m.order.tokenId === 0)) throw new InvalidParamError("MINT/MERGE: makers must be NO (tokenId=0)");
2161
- if (allBuy) return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
2162
- return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
2159
+ const takerIsYes = t.tokenId === 1 && makers.every((m) => m.order.tokenId === 0);
2160
+ const takerIsNo = t.tokenId === 0 && makers.every((m) => m.order.tokenId === 1);
2161
+ if (!takerIsYes && !takerIsNo) throw new InvalidParamError("MINT/MERGE: orders must be complementary YES+NO pair");
2162
+ if (takerIsYes) {
2163
+ if (allBuy) return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
2164
+ return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
2165
+ }
2166
+ let lastResult;
2167
+ for (const yesMaker of makers) {
2168
+ if (allBuy) lastResult = await this.matchMintOrders(yesMaker, [taker], collateralMint, feeRecipient, operatorWallet, alt);
2169
+ else lastResult = await this.matchMergeOrders(yesMaker, [taker], collateralMint, feeRecipient, operatorWallet, alt, opts);
2170
+ }
2171
+ return lastResult;
2163
2172
  }
2164
2173
  /**
2165
2174
  * High-level match: caller passes price + quantity + keypair — SDK builds,
@@ -15007,6 +15016,33 @@ var XMarketSDK = class {
15007
15016
  }
15008
15017
  };
15009
15018
  var MAX_APPROVE_AMOUNT = new BN4__default.default("18446744073709551615");
15019
+ function buildCreateUserAtasTx(condition, user, payer, programIds) {
15020
+ const [yesMint] = PDA.yesMint(condition, programIds);
15021
+ const [noMint] = PDA.noMint(condition, programIds);
15022
+ const yesAta = splToken.getAssociatedTokenAddressSync(yesMint, user, false, splToken.TOKEN_2022_PROGRAM_ID);
15023
+ const noAta = splToken.getAssociatedTokenAddressSync(noMint, user, false, splToken.TOKEN_2022_PROGRAM_ID);
15024
+ const tx = new web3_js.Transaction();
15025
+ tx.feePayer = payer;
15026
+ tx.add(
15027
+ splToken.createAssociatedTokenAccountIdempotentInstruction(
15028
+ payer,
15029
+ yesAta,
15030
+ user,
15031
+ yesMint,
15032
+ splToken.TOKEN_2022_PROGRAM_ID,
15033
+ splToken.ASSOCIATED_TOKEN_PROGRAM_ID
15034
+ ),
15035
+ splToken.createAssociatedTokenAccountIdempotentInstruction(
15036
+ payer,
15037
+ noAta,
15038
+ user,
15039
+ noMint,
15040
+ splToken.TOKEN_2022_PROGRAM_ID,
15041
+ splToken.ASSOCIATED_TOKEN_PROGRAM_ID
15042
+ )
15043
+ );
15044
+ return tx;
15045
+ }
15010
15046
  function buildApproveCollateralTx(collateralMint, signer, payer, delegate, amount = MAX_APPROVE_AMOUNT) {
15011
15047
  const ownerAta = splToken.getAssociatedTokenAddressSync(collateralMint, signer, false, splToken.TOKEN_PROGRAM_ID);
15012
15048
  const approveIx = splToken.createApproveInstruction(
@@ -15073,6 +15109,7 @@ exports.XMarketSDK = XMarketSDK;
15073
15109
  exports.buildApproveAllOutcomeTokensTx = buildApproveAllOutcomeTokensTx;
15074
15110
  exports.buildApproveCollateralTx = buildApproveCollateralTx;
15075
15111
  exports.buildBatchedEd25519Instruction = buildBatchedEd25519Instruction;
15112
+ exports.buildCreateUserAtasTx = buildCreateUserAtasTx;
15076
15113
  exports.buildOrder = buildOrder;
15077
15114
  exports.buildOrderFromPrice = buildOrderFromPrice;
15078
15115
  exports.deserializeSignedOrder = deserializeSignedOrder;