@theliem/xmarket-sdk 3.11.0 → 3.13.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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as anchor5 from '@coral-xyz/anchor';
2
- import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, SYSVAR_RENT_PUBKEY, ComputeBudgetProgram, Transaction, TransactionInstruction, Ed25519Program, AddressLookupTableProgram, TransactionMessage, VersionedTransaction, Connection } from '@solana/web3.js';
2
+ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, SYSVAR_RENT_PUBKEY, ComputeBudgetProgram, TransactionMessage, VersionedTransaction, Transaction, TransactionInstruction, Ed25519Program, AddressLookupTableProgram, Connection } from '@solana/web3.js';
3
3
  import { createHash } from 'crypto';
4
4
  import { TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, createAssociatedTokenAccountIdempotentInstruction, createApproveInstruction } from '@solana/spl-token';
5
5
  import BN4 from 'bn.js';
@@ -496,7 +496,7 @@ var QuestionStatus = /* @__PURE__ */ ((QuestionStatus2) => {
496
496
  QuestionStatus2["Resolved"] = "resolved";
497
497
  return QuestionStatus2;
498
498
  })(QuestionStatus || {});
499
- var FEE_DENOMINATOR = 1e6;
499
+ var FEE_DENOMINATOR = 1e4;
500
500
  var XMarketError = class extends Error {
501
501
  constructor(message, code) {
502
502
  super(message);
@@ -561,6 +561,8 @@ var MarketClient = class {
561
561
  const [noMint] = PDA.noMint(conditionPda, this.programIds);
562
562
  const [mintAuthority] = PDA.mintAuthority(conditionPda, this.programIds);
563
563
  const [collateralVault] = PDA.collateralVault(params.collateralMint, this.programIds);
564
+ if (!this.programIds.feeManagement) throw new Error("feeManagement program ID not configured");
565
+ const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
564
566
  const tx = await this.program.methods.createQuestionAdmin({
565
567
  questionId: Array.from(questionId),
566
568
  contentHash: Array.from(contentHash),
@@ -580,6 +582,8 @@ var MarketClient = class {
580
582
  mintAuthority,
581
583
  collateralVault,
582
584
  conditionalTokensProgram: this.programIds.conditionalTokens,
585
+ questionFee: questionFeePda,
586
+ feeManagementProgram: this.programIds.feeManagement,
583
587
  tokenProgram: TOKEN_2022_PROGRAM_ID,
584
588
  systemProgram: SystemProgram.programId,
585
589
  rent: SYSVAR_RENT_PUBKEY
@@ -778,9 +782,25 @@ var MarketClient = class {
778
782
  * @param creator presale creator pubkey (stored in question)
779
783
  * @param currencyMint collateral mint
780
784
  */
781
- async approvePresale(presalePda, contentHash, hookProgram, authorizedClob, expirationTime, creator, currencyMint, caller = this.walletPubkey, payer = caller) {
785
+ async approvePresale(params) {
786
+ const {
787
+ presalePda,
788
+ contentHash,
789
+ hookProgram,
790
+ authorizedClob,
791
+ expirationTime,
792
+ creator,
793
+ currencyMint,
794
+ referralAddress,
795
+ companyAddress,
796
+ adminOwner
797
+ } = params;
798
+ const caller = params.caller ?? this.walletPubkey;
799
+ const payer = params.payer ?? caller;
782
800
  if (!this.programIds.presale) throw new Error("presale program ID not configured");
783
801
  if (!this.programIds.marketOracle) throw new Error("marketOracle program ID not configured");
802
+ if (!this.programIds.feeManagement) throw new Error("feeManagement program ID not configured");
803
+ if (!this.programIds.adminContract) throw new Error("adminContract program ID not configured");
784
804
  const questionId = presalePda.toBytes();
785
805
  const [questionPda] = PDA.question(this.configPda, questionId, this.programIds);
786
806
  const marketConfig = await this.fetchConfig();
@@ -793,7 +813,14 @@ var MarketClient = class {
793
813
  const [collateralVault] = PDA.collateralVault(currencyMint, this.programIds);
794
814
  const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
795
815
  const marketOracleVault = getAssociatedTokenAddressSync(currencyMint, marketOraclePda, true);
796
- const tx = await this.program.methods.approvePresale({
816
+ const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
817
+ const presaleVault = getAssociatedTokenAddressSync(currencyMint, presalePda, true);
818
+ const referralTokenAccount = getAssociatedTokenAddressSync(currencyMint, referralAddress);
819
+ const companyTokenAccount = getAssociatedTokenAddressSync(currencyMint, companyAddress);
820
+ const [adminConfig] = PDA.adminConfig(adminOwner, this.programIds);
821
+ const adminVault = getAssociatedTokenAddressSync(currencyMint, adminConfig, true);
822
+ const [claimRecord] = PDA.claimRecord(conditionPda.toBytes(), this.programIds);
823
+ const builder = this.program.methods.approvePresale({
797
824
  contentHash: Array.from(contentHash),
798
825
  hookProgram,
799
826
  authorizedClob,
@@ -814,15 +841,38 @@ var MarketClient = class {
814
841
  collateralVault,
815
842
  marketOracle: marketOraclePda,
816
843
  marketOracleVault,
844
+ presaleVault,
845
+ referralTokenAccount,
846
+ companyTokenAccount,
847
+ adminVault,
848
+ adminConfig,
849
+ claimRecord,
850
+ questionFee: questionFeePda,
851
+ feeManagementProgram: this.programIds.feeManagement,
817
852
  conditionalTokensProgram: this.programIds.conditionalTokens,
818
853
  presaleProgram: this.programIds.presale,
819
854
  marketOracleProgram: this.programIds.marketOracle,
855
+ adminProgram: this.programIds.adminContract,
820
856
  tokenProgram: TOKEN_PROGRAM_ID,
821
857
  token2022Program: TOKEN_2022_PROGRAM_ID,
822
858
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
823
859
  systemProgram: SystemProgram.programId,
824
860
  rent: SYSVAR_RENT_PUBKEY
825
- }).transaction();
861
+ });
862
+ let tx;
863
+ if (params.lookupTable) {
864
+ const ix = await builder.instruction();
865
+ const cu = ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
866
+ const { blockhash } = await this.provider.connection.getLatestBlockhash();
867
+ const msg = new TransactionMessage({
868
+ payerKey: payer,
869
+ recentBlockhash: blockhash,
870
+ instructions: [cu, ix]
871
+ }).compileToV0Message([params.lookupTable]);
872
+ tx = new VersionedTransaction(msg);
873
+ } else {
874
+ tx = await builder.transaction();
875
+ }
826
876
  return { tx, questionPda, conditionPda, marketOraclePda, marketOracleVault };
827
877
  }
828
878
  /**
@@ -2237,8 +2287,8 @@ ${logs.join("\n")}`);
2237
2287
  * vtx.sign([feePayerKeypair, operatorKeypair]);
2238
2288
  * await connection.sendRawTransaction(vtx.serialize());
2239
2289
  *
2240
- * Returns an array because NO-taker MINT/MERGE decomposes into N txs (one per YES maker).
2241
- * Most direct/single-pair cases return a single-element array.
2290
+ * All match types pack into a single VersionedTransaction same as createQuestionAdmin pattern.
2291
+ * NO-taker MINT/MERGE decomposes into N instructions but all packed in 1 tx.
2242
2292
  *
2243
2293
  * @param operator - Whitelisted CLOB operator pubkey (must sign)
2244
2294
  * @param payer - Fee payer pubkey (must sign, pays tx fee + rent)
@@ -2264,21 +2314,16 @@ ${logs.join("\n")}`);
2264
2314
  this.registerOrderIfNeeded(taker),
2265
2315
  ...makers.map((m) => this.registerOrderIfNeeded(m))
2266
2316
  ]);
2267
- const ixs2 = [];
2268
- for (const buyMaker of makers) {
2269
- const built = await this.buildMatchComplementaryIxs(
2270
- buyMaker,
2271
- [taker],
2272
- collateralMint,
2273
- feeRecipient,
2274
- operator,
2275
- opts,
2276
- true,
2277
- true
2278
- );
2279
- ixs2.push(...built);
2280
- }
2281
- return [await this._buildUnsignedVtx(ixs2, alt, payer)];
2317
+ const ixs3 = await this.buildMatchComplementaryIxs(
2318
+ taker,
2319
+ makers,
2320
+ collateralMint,
2321
+ feeRecipient,
2322
+ operator,
2323
+ opts,
2324
+ false
2325
+ );
2326
+ return this._buildUnsignedVtx(ixs3, alt, payer);
2282
2327
  } else {
2283
2328
  throw new InvalidParamError("COMPLEMENTARY requires one BUY and one or more SELLs on same tokenId");
2284
2329
  }
@@ -2286,7 +2331,7 @@ ${logs.join("\n")}`);
2286
2331
  this.registerOrderIfNeeded(buySignedOrder),
2287
2332
  ...sellCandidates.map((m) => this.registerOrderIfNeeded(m))
2288
2333
  ]);
2289
- const ixs = await this.buildMatchComplementaryIxs(
2334
+ const ixs2 = await this.buildMatchComplementaryIxs(
2290
2335
  buySignedOrder,
2291
2336
  sellCandidates,
2292
2337
  collateralMint,
@@ -2294,7 +2339,7 @@ ${logs.join("\n")}`);
2294
2339
  operator,
2295
2340
  opts
2296
2341
  );
2297
- return [await this._buildUnsignedVtx(ixs, alt, payer)];
2342
+ return this._buildUnsignedVtx(ixs2, alt, payer);
2298
2343
  }
2299
2344
  const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
2300
2345
  const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
@@ -2315,19 +2360,19 @@ ${logs.join("\n")}`);
2315
2360
  ]);
2316
2361
  await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2317
2362
  const ix = allBuy ? await this._buildMintIx(taker, makers, collateralMint, operator, payer) : await this._buildMergeIx(taker, makers, collateralMint, operator, payer, opts);
2318
- return [await this._buildUnsignedVtx([ix], alt, payer)];
2363
+ return this._buildUnsignedVtx([ix], alt, payer);
2319
2364
  }
2320
- const vtxs = [];
2365
+ await Promise.all([
2366
+ this.registerOrderIfNeeded(taker),
2367
+ ...makers.map((m) => this.registerOrderIfNeeded(m))
2368
+ ]);
2369
+ await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2370
+ const ixs = [];
2321
2371
  for (const yesMaker of makers) {
2322
- await Promise.all([
2323
- this.registerOrderIfNeeded(yesMaker),
2324
- this.registerOrderIfNeeded(taker)
2325
- ]);
2326
- await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2327
2372
  const ix = allBuy ? await this._buildMintIx(yesMaker, [taker], collateralMint, operator, payer) : await this._buildMergeIx(yesMaker, [taker], collateralMint, operator, payer, opts);
2328
- vtxs.push(await this._buildUnsignedVtx([ix], alt, payer));
2373
+ ixs.push(ix);
2329
2374
  }
2330
- return vtxs;
2375
+ return this._buildUnsignedVtx(ixs, alt, payer);
2331
2376
  }
2332
2377
  // ─── Queries ─────────────────────────────────────────────────────────────────
2333
2378
  async fetchConfig() {
@@ -2405,9 +2450,14 @@ var FeeManagementClient = class {
2405
2450
  }
2406
2451
  }
2407
2452
  /**
2408
- * Fetch per-question fees for a condition.
2409
- * Returns null if no fees have been set yet.
2453
+ * Fetch per-market fees for a condition.
2454
+ * Returns null if fees have not been initialized yet.
2455
+ * Fees are set automatically via CPI when create_question_admin / approve_presale runs.
2456
+ * Defaults: swapFee=200 (2%), redeemFee=0, mergeFee=2000 (20%), out of FEE_DENOMINATOR=10_000.
2410
2457
  */
2458
+ async getMarketFee(conditionPda) {
2459
+ return this.fetchQuestionFee(conditionPda);
2460
+ }
2411
2461
  async fetchQuestionFee(conditionPda) {
2412
2462
  try {
2413
2463
  const [pda] = PDA.questionFee(conditionPda, this.programIds);
@@ -2424,11 +2474,11 @@ var FeeManagementClient = class {
2424
2474
  }
2425
2475
  }
2426
2476
  /**
2427
- * Set per-question fees for a condition.
2477
+ * Set per-question fees for a condition (whitelist-only edit after market creation).
2428
2478
  * @param conditionPda - condition PDA from the question
2429
- * @param mergeFee - fee out of FEE_DENOMINATOR (1_000_000), e.g. 2_000 = 0.2%
2479
+ * @param mergeFee - fee out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
2430
2480
  * @param redeemFee - fee out of FEE_DENOMINATOR
2431
- * @param swapFee - trading fee out of FEE_DENOMINATOR
2481
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
2432
2482
  * @param feeConfigOwner - pubkey that owns the fee_config PDA (usually market deployer)
2433
2483
  * @param authority - signer authorized in fee_config whitelist / admin / owner
2434
2484
  * @param payer - rent + tx fee payer
@@ -4265,9 +4315,59 @@ var question_market_default = {
4265
4315
  ],
4266
4316
  writable: true
4267
4317
  },
4318
+ {
4319
+ name: "presale_vault",
4320
+ writable: true
4321
+ },
4322
+ {
4323
+ name: "referral_token_account",
4324
+ docs: [
4325
+ "Referral address USDC ATA (receives agents_fee 10%)"
4326
+ ],
4327
+ writable: true
4328
+ },
4329
+ {
4330
+ name: "company_token_account",
4331
+ docs: [
4332
+ "Company address USDC ATA (receives company_fee 10%)"
4333
+ ],
4334
+ writable: true
4335
+ },
4336
+ {
4337
+ name: "admin_vault",
4338
+ docs: [
4339
+ "admin_contract vault ATA (receives botmm_revenue 80%)"
4340
+ ],
4341
+ writable: true
4342
+ },
4343
+ {
4344
+ name: "admin_config",
4345
+ docs: [
4346
+ "admin_contract config PDA (seeds=[ADMIN_CONFIG_SEED, owner] \u2014 validated by admin_contract CPI)"
4347
+ ]
4348
+ },
4349
+ {
4350
+ name: "claim_record",
4351
+ docs: [
4352
+ "ClaimRecord PDA for this presale's conditionId (seeds=[CLAIM_RECORD_SEED, condition_id])",
4353
+ "condition_id computed inside handler \u2014 seeds validated by admin_contract CPI"
4354
+ ],
4355
+ writable: true
4356
+ },
4268
4357
  {
4269
4358
  name: "conditional_tokens_program"
4270
4359
  },
4360
+ {
4361
+ name: "question_fee",
4362
+ docs: [
4363
+ "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management"
4364
+ ],
4365
+ writable: true
4366
+ },
4367
+ {
4368
+ name: "fee_management_program",
4369
+ address: "DuYyXguB5PVSKg6E2p4XPrrXZSCJnuBhoGpkGCBN5bBb"
4370
+ },
4271
4371
  {
4272
4372
  name: "presale_program",
4273
4373
  address: "2Rnw1VoEtsUMQ7wkvYZjDehqSqRob6uNkeymDfvKrquB"
@@ -4276,6 +4376,10 @@ var question_market_default = {
4276
4376
  name: "market_oracle_program",
4277
4377
  address: "ADWF4J3nCJ2kWnCtycuem2jhu7amUqJWQG3oa5xF67QJ"
4278
4378
  },
4379
+ {
4380
+ name: "admin_program",
4381
+ address: "4NdD5962SfGqofmeyjfifJpdGnwTAiKaUKB5Z42UDc9T"
4382
+ },
4279
4383
  {
4280
4384
  name: "token_program",
4281
4385
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -4918,6 +5022,47 @@ var question_market_default = {
4918
5022
  {
4919
5023
  name: "conditional_tokens_program"
4920
5024
  },
5025
+ {
5026
+ name: "question_fee",
5027
+ docs: [
5028
+ "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management.",
5029
+ "Seed uses condition.key() bytes (consistent with existing set_question_fee SDK convention)."
5030
+ ],
5031
+ writable: true,
5032
+ pda: {
5033
+ seeds: [
5034
+ {
5035
+ kind: "const",
5036
+ value: [
5037
+ 113,
5038
+ 117,
5039
+ 101,
5040
+ 115,
5041
+ 116,
5042
+ 105,
5043
+ 111,
5044
+ 110,
5045
+ 95,
5046
+ 102,
5047
+ 101,
5048
+ 101
5049
+ ]
5050
+ },
5051
+ {
5052
+ kind: "account",
5053
+ path: "condition"
5054
+ }
5055
+ ],
5056
+ program: {
5057
+ kind: "account",
5058
+ path: "fee_management_program"
5059
+ }
5060
+ }
5061
+ },
5062
+ {
5063
+ name: "fee_management_program",
5064
+ address: "DuYyXguB5PVSKg6E2p4XPrrXZSCJnuBhoGpkGCBN5bBb"
5065
+ },
4921
5066
  {
4922
5067
  name: "token_program",
4923
5068
  address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
@@ -6034,6 +6179,18 @@ var question_market_default = {
6034
6179
  {
6035
6180
  name: "creator",
6036
6181
  type: "pubkey"
6182
+ },
6183
+ {
6184
+ name: "agents_fee",
6185
+ type: "u64"
6186
+ },
6187
+ {
6188
+ name: "company_fee",
6189
+ type: "u64"
6190
+ },
6191
+ {
6192
+ name: "botmm_revenue",
6193
+ type: "u64"
6037
6194
  }
6038
6195
  ]
6039
6196
  }
@@ -10525,6 +10682,70 @@ var fee_management_default = {
10525
10682
  }
10526
10683
  ]
10527
10684
  },
10685
+ {
10686
+ name: "init_question_fee",
10687
+ discriminator: [
10688
+ 115,
10689
+ 49,
10690
+ 110,
10691
+ 164,
10692
+ 33,
10693
+ 202,
10694
+ 115,
10695
+ 79
10696
+ ],
10697
+ accounts: [
10698
+ {
10699
+ name: "payer",
10700
+ writable: true,
10701
+ signer: true
10702
+ },
10703
+ {
10704
+ name: "question_fee",
10705
+ writable: true,
10706
+ pda: {
10707
+ seeds: [
10708
+ {
10709
+ kind: "const",
10710
+ value: [
10711
+ 113,
10712
+ 117,
10713
+ 101,
10714
+ 115,
10715
+ 116,
10716
+ 105,
10717
+ 111,
10718
+ 110,
10719
+ 95,
10720
+ 102,
10721
+ 101,
10722
+ 101
10723
+ ]
10724
+ },
10725
+ {
10726
+ kind: "arg",
10727
+ path: "condition_id"
10728
+ }
10729
+ ]
10730
+ }
10731
+ },
10732
+ {
10733
+ name: "system_program",
10734
+ address: "11111111111111111111111111111111"
10735
+ }
10736
+ ],
10737
+ args: [
10738
+ {
10739
+ name: "condition_id",
10740
+ type: {
10741
+ array: [
10742
+ "u8",
10743
+ 32
10744
+ ]
10745
+ }
10746
+ }
10747
+ ]
10748
+ },
10528
10749
  {
10529
10750
  name: "initialize",
10530
10751
  discriminator: [
@@ -11219,6 +11440,19 @@ var fee_management_default = {
11219
11440
  235
11220
11441
  ]
11221
11442
  },
11443
+ {
11444
+ name: "QuestionFeeInitialized",
11445
+ discriminator: [
11446
+ 147,
11447
+ 167,
11448
+ 20,
11449
+ 219,
11450
+ 32,
11451
+ 142,
11452
+ 227,
11453
+ 171
11454
+ ]
11455
+ },
11222
11456
  {
11223
11457
  name: "QuestionFeeUpdated",
11224
11458
  discriminator: [
@@ -11601,7 +11835,7 @@ var fee_management_default = {
11601
11835
  {
11602
11836
  name: "merge_fee",
11603
11837
  docs: [
11604
- "Fees out of FEE_DENOMINATOR (1_000_000). E.g. 2_000 = 0.2%"
11838
+ "Fees out of FEE_DENOMINATOR (10_000). E.g. 200 = 2%, 2_000 = 20%"
11605
11839
  ],
11606
11840
  type: "u64"
11607
11841
  },
@@ -11620,6 +11854,35 @@ var fee_management_default = {
11620
11854
  ]
11621
11855
  }
11622
11856
  },
11857
+ {
11858
+ name: "QuestionFeeInitialized",
11859
+ type: {
11860
+ kind: "struct",
11861
+ fields: [
11862
+ {
11863
+ name: "condition_id",
11864
+ type: {
11865
+ array: [
11866
+ "u8",
11867
+ 32
11868
+ ]
11869
+ }
11870
+ },
11871
+ {
11872
+ name: "swap_fee",
11873
+ type: "u64"
11874
+ },
11875
+ {
11876
+ name: "redeem_fee",
11877
+ type: "u64"
11878
+ },
11879
+ {
11880
+ name: "merge_fee",
11881
+ type: "u64"
11882
+ }
11883
+ ]
11884
+ }
11885
+ },
11623
11886
  {
11624
11887
  name: "QuestionFeeUpdated",
11625
11888
  type: {