@theliem/xmarket-sdk 3.19.0 → 3.20.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
@@ -421,6 +421,8 @@ declare class MarketClient {
421
421
  readonly configPda: PublicKey;
422
422
  /** Injected by XMarketSDK after construction — enables fetchQuestionBalances. */
423
423
  ctfClient?: CtfClient;
424
+ /** Injected by XMarketSDK — fee config owner (= market owner) for MarketFeeOverride PDA derivation */
425
+ feeConfigOwner?: PublicKey;
424
426
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, ownerPubkey: PublicKey);
425
427
  get walletPubkey(): PublicKey;
426
428
  initialize(admin: PublicKey, oracle: PublicKey, owner?: PublicKey): Promise<Transaction>;
@@ -450,6 +452,7 @@ declare class MarketClient {
450
452
  removeFromWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
451
453
  growConfig(owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
452
454
  restoreConfig(snapshot: Buffer, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
455
+ bumpPresaleCount(count: number, authority: PublicKey): Promise<Transaction>;
453
456
  fetchConfig(): Promise<QuestionMarketConfig | null>;
454
457
  fetchQuestion(questionPda: PublicKey): Promise<Question | null>;
455
458
  questionPda(questionId: Uint8Array): PublicKey;
@@ -626,10 +629,15 @@ declare class ClobClient {
626
629
  /** Injected by XMarketSDK after construction — enables auto fee distribution */
627
630
  feeClient?: FeeManagementClient;
628
631
  feeConfigOwner?: PublicKey;
632
+ /** Injected by XMarketSDK — enables auto-derive of marketOracleVault for presale markets */
633
+ ctfClient?: CtfClient;
634
+ qmConfigPda?: PublicKey;
629
635
  /** Cached company_address from fee_config to avoid repeated RPC calls */
630
636
  private _companyAddress?;
631
637
  /** Cached referral_vault from fee_config */
632
638
  private _referralVault?;
639
+ /** Cache: conditionPda.toBase58() → marketOracleVault ATA */
640
+ private _marketOracleVaultCache;
633
641
  /** ALT cache: condition.toBase58() → loaded ALT account */
634
642
  private _altCache;
635
643
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
@@ -639,6 +647,12 @@ declare class ClobClient {
639
647
  });
640
648
  private companyAddress;
641
649
  private referralVault;
650
+ /**
651
+ * Derive marketOracleVault ATA for a condition, cached per condition.
652
+ * Works for presale markets (market_oracle initialized by approvePresale).
653
+ * Returns undefined if ctfClient/qmConfigPda not injected or marketOracle not configured.
654
+ */
655
+ private getMarketOracleVault;
642
656
  get walletPubkey(): PublicKey;
643
657
  /**
644
658
  * Get or create an ALT for a condition.
package/dist/index.d.ts CHANGED
@@ -421,6 +421,8 @@ declare class MarketClient {
421
421
  readonly configPda: PublicKey;
422
422
  /** Injected by XMarketSDK after construction — enables fetchQuestionBalances. */
423
423
  ctfClient?: CtfClient;
424
+ /** Injected by XMarketSDK — fee config owner (= market owner) for MarketFeeOverride PDA derivation */
425
+ feeConfigOwner?: PublicKey;
424
426
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, ownerPubkey: PublicKey);
425
427
  get walletPubkey(): PublicKey;
426
428
  initialize(admin: PublicKey, oracle: PublicKey, owner?: PublicKey): Promise<Transaction>;
@@ -450,6 +452,7 @@ declare class MarketClient {
450
452
  removeFromWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
451
453
  growConfig(owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
452
454
  restoreConfig(snapshot: Buffer, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
455
+ bumpPresaleCount(count: number, authority: PublicKey): Promise<Transaction>;
453
456
  fetchConfig(): Promise<QuestionMarketConfig | null>;
454
457
  fetchQuestion(questionPda: PublicKey): Promise<Question | null>;
455
458
  questionPda(questionId: Uint8Array): PublicKey;
@@ -626,10 +629,15 @@ declare class ClobClient {
626
629
  /** Injected by XMarketSDK after construction — enables auto fee distribution */
627
630
  feeClient?: FeeManagementClient;
628
631
  feeConfigOwner?: PublicKey;
632
+ /** Injected by XMarketSDK — enables auto-derive of marketOracleVault for presale markets */
633
+ ctfClient?: CtfClient;
634
+ qmConfigPda?: PublicKey;
629
635
  /** Cached company_address from fee_config to avoid repeated RPC calls */
630
636
  private _companyAddress?;
631
637
  /** Cached referral_vault from fee_config */
632
638
  private _referralVault?;
639
+ /** Cache: conditionPda.toBase58() → marketOracleVault ATA */
640
+ private _marketOracleVaultCache;
633
641
  /** ALT cache: condition.toBase58() → loaded ALT account */
634
642
  private _altCache;
635
643
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
@@ -639,6 +647,12 @@ declare class ClobClient {
639
647
  });
640
648
  private companyAddress;
641
649
  private referralVault;
650
+ /**
651
+ * Derive marketOracleVault ATA for a condition, cached per condition.
652
+ * Works for presale markets (market_oracle initialized by approvePresale).
653
+ * Returns undefined if ctfClient/qmConfigPda not injected or marketOracle not configured.
654
+ */
655
+ private getMarketOracleVault;
642
656
  get walletPubkey(): PublicKey;
643
657
  /**
644
658
  * Get or create an ALT for a condition.
package/dist/index.js CHANGED
@@ -597,7 +597,10 @@ var MarketClient = class {
597
597
  const [mintAuthority] = PDA.mintAuthority(conditionPda, this.programIds);
598
598
  const [collateralVault] = PDA.collateralVault(params.collateralMint, this.programIds);
599
599
  if (!this.programIds.feeManagement) throw new Error("feeManagement program ID not configured");
600
+ if (!this.feeConfigOwner) throw new Error("feeConfigOwner not configured");
600
601
  const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
602
+ const [feeConfigPda] = PDA.feeConfig(this.feeConfigOwner, this.programIds);
603
+ const [marketFeeOverride] = PDA.marketFeeOverride(conditionPda, this.programIds);
601
604
  const tx = await this.program.methods.createQuestionAdmin({
602
605
  questionId: Array.from(questionId),
603
606
  contentHash: Array.from(contentHash),
@@ -618,6 +621,8 @@ var MarketClient = class {
618
621
  collateralVault,
619
622
  conditionalTokensProgram: this.programIds.conditionalTokens,
620
623
  questionFee: questionFeePda,
624
+ feeConfig: feeConfigPda,
625
+ marketFeeOverride,
621
626
  feeManagementProgram: this.programIds.feeManagement,
622
627
  tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
623
628
  systemProgram: web3_js.SystemProgram.programId,
@@ -689,6 +694,9 @@ var MarketClient = class {
689
694
  systemProgram: web3_js.SystemProgram.programId
690
695
  }).transaction();
691
696
  }
697
+ async bumpPresaleCount(count, authority) {
698
+ return this.program.methods.bumpPresaleCount(new anchor5__namespace.BN(count)).accounts({ authority, config: this.configPda }).transaction();
699
+ }
692
700
  // ─── Queries ─────────────────────────────────────────────────────────────────
693
701
  async fetchConfig() {
694
702
  try {
@@ -855,6 +863,9 @@ var MarketClient = class {
855
863
  const [adminConfig] = PDA.adminConfig(adminOwner, this.programIds);
856
864
  const adminVault = splToken.getAssociatedTokenAddressSync(currencyMint, adminConfig, true);
857
865
  const [claimRecord] = PDA.claimRecord(conditionPda.toBytes(), this.programIds);
866
+ const feeConfigOwner = this.feeConfigOwner ?? adminOwner;
867
+ const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
868
+ const [marketFeeOverride] = PDA.marketFeeOverride(conditionPda, this.programIds);
858
869
  const builder = this.program.methods.approvePresale({
859
870
  contentHash: Array.from(contentHash),
860
871
  hookProgram,
@@ -883,6 +894,8 @@ var MarketClient = class {
883
894
  adminConfig,
884
895
  claimRecord,
885
896
  questionFee: questionFeePda,
897
+ feeConfig: feeConfigPda,
898
+ marketFeeOverride,
886
899
  feeManagementProgram: this.programIds.feeManagement,
887
900
  conditionalTokensProgram: this.programIds.conditionalTokens,
888
901
  presaleProgram: this.programIds.presale,
@@ -1546,6 +1559,8 @@ function _detectMatchType(a, b) {
1546
1559
  // src/programs/clob.ts
1547
1560
  var ClobClient = class {
1548
1561
  constructor(program, provider, programIds, networkConfig) {
1562
+ /** Cache: conditionPda.toBase58() → marketOracleVault ATA */
1563
+ this._marketOracleVaultCache = /* @__PURE__ */ new Map();
1549
1564
  /** ALT cache: condition.toBase58() → loaded ALT account */
1550
1565
  this._altCache = /* @__PURE__ */ new Map();
1551
1566
  this.program = program;
@@ -1568,6 +1583,24 @@ var ClobClient = class {
1568
1583
  await this.companyAddress();
1569
1584
  return this._referralVault;
1570
1585
  }
1586
+ /**
1587
+ * Derive marketOracleVault ATA for a condition, cached per condition.
1588
+ * Works for presale markets (market_oracle initialized by approvePresale).
1589
+ * Returns undefined if ctfClient/qmConfigPda not injected or marketOracle not configured.
1590
+ */
1591
+ async getMarketOracleVault(condition, collateralMint) {
1592
+ if (!this.ctfClient || !this.qmConfigPda || !this.programIds.marketOracle) return void 0;
1593
+ const key = condition.toBase58();
1594
+ const cached = this._marketOracleVaultCache.get(key);
1595
+ if (cached) return cached;
1596
+ const cond = await this.ctfClient.fetchCondition(condition);
1597
+ if (!cond) return void 0;
1598
+ const [questionPda] = PDA.question(this.qmConfigPda, cond.questionId, this.programIds);
1599
+ const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
1600
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, marketOraclePda, true);
1601
+ this._marketOracleVaultCache.set(key, vault);
1602
+ return vault;
1603
+ }
1571
1604
  get walletPubkey() {
1572
1605
  return this.provider.wallet.publicKey;
1573
1606
  }
@@ -1667,11 +1700,11 @@ var ClobClient = class {
1667
1700
  if (companyAddr) {
1668
1701
  addresses.push(splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr));
1669
1702
  }
1670
- addresses.push(payer);
1703
+ const oracleVaultForAlt = await this.getMarketOracleVault(condition, collateralMint) ?? payer;
1704
+ addresses.push(oracleVaultForAlt);
1671
1705
  if (refVault) {
1672
1706
  addresses.push(refVault);
1673
1707
  }
1674
- addresses.push(splToken.TOKEN_PROGRAM_ID);
1675
1708
  }
1676
1709
  const slot = await connection.getSlot("finalized");
1677
1710
  const [createIx, altAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
@@ -1934,7 +1967,7 @@ ${logs.join("\n")}`);
1934
1967
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
1935
1968
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
1936
1969
  if (feeOverrideExists) {
1937
- const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
1970
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? this.walletPubkey;
1938
1971
  feeAccounts = [
1939
1972
  { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
1940
1973
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
@@ -2190,15 +2223,14 @@ ${logs.join("\n")}`);
2190
2223
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2191
2224
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2192
2225
  if (feeOverrideExists) {
2193
- const oracleVault = opts?.marketOracleVault ?? payer;
2226
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2194
2227
  remainingAccounts.push(
2195
2228
  { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2196
2229
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2197
2230
  { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2198
2231
  { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2199
2232
  { pubkey: oracleVault, isSigner: false, isWritable: true },
2200
- { pubkey: refVault, isSigner: false, isWritable: true },
2201
- { pubkey: splToken.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
2233
+ { pubkey: refVault, isSigner: false, isWritable: true }
2202
2234
  );
2203
2235
  }
2204
2236
  }
@@ -2524,7 +2556,7 @@ ${logs.join("\n")}`);
2524
2556
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2525
2557
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2526
2558
  if (feeOverrideExists) {
2527
- const oracleVault = opts?.marketOracleVault ?? payer;
2559
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2528
2560
  feeAccounts = [
2529
2561
  { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2530
2562
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
@@ -4662,6 +4694,20 @@ var question_market_default = {
4662
4694
  ],
4663
4695
  writable: true
4664
4696
  },
4697
+ {
4698
+ name: "fee_config",
4699
+ docs: [
4700
+ "FeeConfig PDA \u2014 passed to set_market_fee_override CPI."
4701
+ ],
4702
+ writable: true
4703
+ },
4704
+ {
4705
+ name: "market_fee_override",
4706
+ docs: [
4707
+ "MarketFeeOverride PDA \u2014 auto-init with is_admin=false and fee_config defaults."
4708
+ ],
4709
+ writable: true
4710
+ },
4665
4711
  {
4666
4712
  name: "fee_management_program",
4667
4713
  address: "DuYyXguB5PVSKg6E2p4XPrrXZSCJnuBhoGpkGCBN5bBb"
@@ -4767,6 +4813,55 @@ var question_market_default = {
4767
4813
  ],
4768
4814
  args: []
4769
4815
  },
4816
+ {
4817
+ name: "bump_presale_count",
4818
+ discriminator: [
4819
+ 42,
4820
+ 84,
4821
+ 98,
4822
+ 9,
4823
+ 208,
4824
+ 168,
4825
+ 38,
4826
+ 55
4827
+ ],
4828
+ accounts: [
4829
+ {
4830
+ name: "authority",
4831
+ signer: true
4832
+ },
4833
+ {
4834
+ name: "config",
4835
+ writable: true,
4836
+ pda: {
4837
+ seeds: [
4838
+ {
4839
+ kind: "const",
4840
+ value: [
4841
+ 99,
4842
+ 111,
4843
+ 110,
4844
+ 102,
4845
+ 105,
4846
+ 103
4847
+ ]
4848
+ },
4849
+ {
4850
+ kind: "account",
4851
+ path: "config.owner",
4852
+ account: "QuestionMarketConfig"
4853
+ }
4854
+ ]
4855
+ }
4856
+ }
4857
+ ],
4858
+ args: [
4859
+ {
4860
+ name: "count",
4861
+ type: "u64"
4862
+ }
4863
+ ]
4864
+ },
4770
4865
  {
4771
4866
  name: "collect_presale_revenue",
4772
4867
  discriminator: [
@@ -5323,39 +5418,23 @@ var question_market_default = {
5323
5418
  {
5324
5419
  name: "question_fee",
5325
5420
  docs: [
5326
- "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management.",
5327
- "Seed uses condition.key() bytes (consistent with existing set_question_fee SDK convention)."
5421
+ "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management."
5328
5422
  ],
5329
- writable: true,
5330
- pda: {
5331
- seeds: [
5332
- {
5333
- kind: "const",
5334
- value: [
5335
- 113,
5336
- 117,
5337
- 101,
5338
- 115,
5339
- 116,
5340
- 105,
5341
- 111,
5342
- 110,
5343
- 95,
5344
- 102,
5345
- 101,
5346
- 101
5347
- ]
5348
- },
5349
- {
5350
- kind: "account",
5351
- path: "condition"
5352
- }
5353
- ],
5354
- program: {
5355
- kind: "account",
5356
- path: "fee_management_program"
5357
- }
5358
- }
5423
+ writable: true
5424
+ },
5425
+ {
5426
+ name: "fee_config",
5427
+ docs: [
5428
+ "FeeConfig PDA \u2014 passed to set_market_fee_override CPI as authority validator."
5429
+ ],
5430
+ writable: true
5431
+ },
5432
+ {
5433
+ name: "market_fee_override",
5434
+ docs: [
5435
+ "MarketFeeOverride PDA \u2014 init'd by set_market_fee_override CPI (is_admin=true)."
5436
+ ],
5437
+ writable: true
5359
5438
  },
5360
5439
  {
5361
5440
  name: "fee_management_program",
@@ -6921,7 +7000,7 @@ var question_market_default = {
6921
7000
  type: {
6922
7001
  array: [
6923
7002
  "pubkey",
6924
- 30
7003
+ 20
6925
7004
  ]
6926
7005
  }
6927
7006
  },
@@ -6961,7 +7040,7 @@ var question_market_default = {
6961
7040
  type: {
6962
7041
  array: [
6963
7042
  "u8",
6964
- 120
7043
+ 440
6965
7044
  ]
6966
7045
  }
6967
7046
  }
@@ -16312,6 +16391,7 @@ var XMarketSDK = class {
16312
16391
  const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
16313
16392
  this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
16314
16393
  this._market.ctfClient = this.ctf;
16394
+ this._market.feeConfigOwner = this.networkConfig.feeConfigOwner ?? this._marketOwner;
16315
16395
  }
16316
16396
  return this._market;
16317
16397
  }
@@ -16330,6 +16410,8 @@ var XMarketSDK = class {
16330
16410
  this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
16331
16411
  this._clob.feeClient = this.fee;
16332
16412
  }
16413
+ this._clob.ctfClient = this.ctf;
16414
+ this._clob.qmConfigPda = this.market.configPda;
16333
16415
  }
16334
16416
  return this._clob;
16335
16417
  }