@theliem/xmarket-sdk 3.12.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
  /**
@@ -2400,9 +2450,14 @@ var FeeManagementClient = class {
2400
2450
  }
2401
2451
  }
2402
2452
  /**
2403
- * Fetch per-question fees for a condition.
2404
- * 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.
2405
2457
  */
2458
+ async getMarketFee(conditionPda) {
2459
+ return this.fetchQuestionFee(conditionPda);
2460
+ }
2406
2461
  async fetchQuestionFee(conditionPda) {
2407
2462
  try {
2408
2463
  const [pda] = PDA.questionFee(conditionPda, this.programIds);
@@ -2419,11 +2474,11 @@ var FeeManagementClient = class {
2419
2474
  }
2420
2475
  }
2421
2476
  /**
2422
- * Set per-question fees for a condition.
2477
+ * Set per-question fees for a condition (whitelist-only edit after market creation).
2423
2478
  * @param conditionPda - condition PDA from the question
2424
- * @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%
2425
2480
  * @param redeemFee - fee out of FEE_DENOMINATOR
2426
- * @param swapFee - trading fee out of FEE_DENOMINATOR
2481
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
2427
2482
  * @param feeConfigOwner - pubkey that owns the fee_config PDA (usually market deployer)
2428
2483
  * @param authority - signer authorized in fee_config whitelist / admin / owner
2429
2484
  * @param payer - rent + tx fee payer
@@ -4260,9 +4315,59 @@ var question_market_default = {
4260
4315
  ],
4261
4316
  writable: true
4262
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
+ },
4263
4357
  {
4264
4358
  name: "conditional_tokens_program"
4265
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
+ },
4266
4371
  {
4267
4372
  name: "presale_program",
4268
4373
  address: "2Rnw1VoEtsUMQ7wkvYZjDehqSqRob6uNkeymDfvKrquB"
@@ -4271,6 +4376,10 @@ var question_market_default = {
4271
4376
  name: "market_oracle_program",
4272
4377
  address: "ADWF4J3nCJ2kWnCtycuem2jhu7amUqJWQG3oa5xF67QJ"
4273
4378
  },
4379
+ {
4380
+ name: "admin_program",
4381
+ address: "4NdD5962SfGqofmeyjfifJpdGnwTAiKaUKB5Z42UDc9T"
4382
+ },
4274
4383
  {
4275
4384
  name: "token_program",
4276
4385
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -4913,6 +5022,47 @@ var question_market_default = {
4913
5022
  {
4914
5023
  name: "conditional_tokens_program"
4915
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
+ },
4916
5066
  {
4917
5067
  name: "token_program",
4918
5068
  address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
@@ -6029,6 +6179,18 @@ var question_market_default = {
6029
6179
  {
6030
6180
  name: "creator",
6031
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"
6032
6194
  }
6033
6195
  ]
6034
6196
  }
@@ -10520,6 +10682,70 @@ var fee_management_default = {
10520
10682
  }
10521
10683
  ]
10522
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
+ },
10523
10749
  {
10524
10750
  name: "initialize",
10525
10751
  discriminator: [
@@ -11214,6 +11440,19 @@ var fee_management_default = {
11214
11440
  235
11215
11441
  ]
11216
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
+ },
11217
11456
  {
11218
11457
  name: "QuestionFeeUpdated",
11219
11458
  discriminator: [
@@ -11596,7 +11835,7 @@ var fee_management_default = {
11596
11835
  {
11597
11836
  name: "merge_fee",
11598
11837
  docs: [
11599
- "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%"
11600
11839
  ],
11601
11840
  type: "u64"
11602
11841
  },
@@ -11615,6 +11854,35 @@ var fee_management_default = {
11615
11854
  ]
11616
11855
  }
11617
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
+ },
11618
11886
  {
11619
11887
  name: "QuestionFeeUpdated",
11620
11888
  type: {