@theliem/xmarket-sdk 3.18.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.mjs CHANGED
@@ -571,7 +571,10 @@ var MarketClient = class {
571
571
  const [mintAuthority] = PDA.mintAuthority(conditionPda, this.programIds);
572
572
  const [collateralVault] = PDA.collateralVault(params.collateralMint, this.programIds);
573
573
  if (!this.programIds.feeManagement) throw new Error("feeManagement program ID not configured");
574
+ if (!this.feeConfigOwner) throw new Error("feeConfigOwner not configured");
574
575
  const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
576
+ const [feeConfigPda] = PDA.feeConfig(this.feeConfigOwner, this.programIds);
577
+ const [marketFeeOverride] = PDA.marketFeeOverride(conditionPda, this.programIds);
575
578
  const tx = await this.program.methods.createQuestionAdmin({
576
579
  questionId: Array.from(questionId),
577
580
  contentHash: Array.from(contentHash),
@@ -592,6 +595,8 @@ var MarketClient = class {
592
595
  collateralVault,
593
596
  conditionalTokensProgram: this.programIds.conditionalTokens,
594
597
  questionFee: questionFeePda,
598
+ feeConfig: feeConfigPda,
599
+ marketFeeOverride,
595
600
  feeManagementProgram: this.programIds.feeManagement,
596
601
  tokenProgram: TOKEN_2022_PROGRAM_ID,
597
602
  systemProgram: SystemProgram.programId,
@@ -663,6 +668,9 @@ var MarketClient = class {
663
668
  systemProgram: SystemProgram.programId
664
669
  }).transaction();
665
670
  }
671
+ async bumpPresaleCount(count, authority) {
672
+ return this.program.methods.bumpPresaleCount(new anchor5.BN(count)).accounts({ authority, config: this.configPda }).transaction();
673
+ }
666
674
  // ─── Queries ─────────────────────────────────────────────────────────────────
667
675
  async fetchConfig() {
668
676
  try {
@@ -829,6 +837,9 @@ var MarketClient = class {
829
837
  const [adminConfig] = PDA.adminConfig(adminOwner, this.programIds);
830
838
  const adminVault = getAssociatedTokenAddressSync(currencyMint, adminConfig, true);
831
839
  const [claimRecord] = PDA.claimRecord(conditionPda.toBytes(), this.programIds);
840
+ const feeConfigOwner = this.feeConfigOwner ?? adminOwner;
841
+ const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
842
+ const [marketFeeOverride] = PDA.marketFeeOverride(conditionPda, this.programIds);
832
843
  const builder = this.program.methods.approvePresale({
833
844
  contentHash: Array.from(contentHash),
834
845
  hookProgram,
@@ -857,6 +868,8 @@ var MarketClient = class {
857
868
  adminConfig,
858
869
  claimRecord,
859
870
  questionFee: questionFeePda,
871
+ feeConfig: feeConfigPda,
872
+ marketFeeOverride,
860
873
  feeManagementProgram: this.programIds.feeManagement,
861
874
  conditionalTokensProgram: this.programIds.conditionalTokens,
862
875
  presaleProgram: this.programIds.presale,
@@ -1520,6 +1533,8 @@ function _detectMatchType(a, b) {
1520
1533
  // src/programs/clob.ts
1521
1534
  var ClobClient = class {
1522
1535
  constructor(program, provider, programIds, networkConfig) {
1536
+ /** Cache: conditionPda.toBase58() → marketOracleVault ATA */
1537
+ this._marketOracleVaultCache = /* @__PURE__ */ new Map();
1523
1538
  /** ALT cache: condition.toBase58() → loaded ALT account */
1524
1539
  this._altCache = /* @__PURE__ */ new Map();
1525
1540
  this.program = program;
@@ -1542,6 +1557,24 @@ var ClobClient = class {
1542
1557
  await this.companyAddress();
1543
1558
  return this._referralVault;
1544
1559
  }
1560
+ /**
1561
+ * Derive marketOracleVault ATA for a condition, cached per condition.
1562
+ * Works for presale markets (market_oracle initialized by approvePresale).
1563
+ * Returns undefined if ctfClient/qmConfigPda not injected or marketOracle not configured.
1564
+ */
1565
+ async getMarketOracleVault(condition, collateralMint) {
1566
+ if (!this.ctfClient || !this.qmConfigPda || !this.programIds.marketOracle) return void 0;
1567
+ const key = condition.toBase58();
1568
+ const cached = this._marketOracleVaultCache.get(key);
1569
+ if (cached) return cached;
1570
+ const cond = await this.ctfClient.fetchCondition(condition);
1571
+ if (!cond) return void 0;
1572
+ const [questionPda] = PDA.question(this.qmConfigPda, cond.questionId, this.programIds);
1573
+ const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
1574
+ const vault = getAssociatedTokenAddressSync(collateralMint, marketOraclePda, true);
1575
+ this._marketOracleVaultCache.set(key, vault);
1576
+ return vault;
1577
+ }
1545
1578
  get walletPubkey() {
1546
1579
  return this.provider.wallet.publicKey;
1547
1580
  }
@@ -1641,11 +1674,11 @@ var ClobClient = class {
1641
1674
  if (companyAddr) {
1642
1675
  addresses.push(getAssociatedTokenAddressSync(collateralMint, companyAddr));
1643
1676
  }
1644
- addresses.push(payer);
1677
+ const oracleVaultForAlt = await this.getMarketOracleVault(condition, collateralMint) ?? payer;
1678
+ addresses.push(oracleVaultForAlt);
1645
1679
  if (refVault) {
1646
1680
  addresses.push(refVault);
1647
1681
  }
1648
- addresses.push(TOKEN_PROGRAM_ID);
1649
1682
  }
1650
1683
  const slot = await connection.getSlot("finalized");
1651
1684
  const [createIx, altAddress] = AddressLookupTableProgram.createLookupTable({
@@ -1908,7 +1941,7 @@ ${logs.join("\n")}`);
1908
1941
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
1909
1942
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
1910
1943
  if (feeOverrideExists) {
1911
- const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
1944
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? this.walletPubkey;
1912
1945
  feeAccounts = [
1913
1946
  { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
1914
1947
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
@@ -2164,15 +2197,14 @@ ${logs.join("\n")}`);
2164
2197
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2165
2198
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2166
2199
  if (feeOverrideExists) {
2167
- const oracleVault = opts?.marketOracleVault ?? payer;
2200
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2168
2201
  remainingAccounts.push(
2169
2202
  { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2170
2203
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2171
2204
  { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2172
2205
  { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2173
2206
  { pubkey: oracleVault, isSigner: false, isWritable: true },
2174
- { pubkey: refVault, isSigner: false, isWritable: true },
2175
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
2207
+ { pubkey: refVault, isSigner: false, isWritable: true }
2176
2208
  );
2177
2209
  }
2178
2210
  }
@@ -2498,7 +2530,7 @@ ${logs.join("\n")}`);
2498
2530
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2499
2531
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2500
2532
  if (feeOverrideExists) {
2501
- const oracleVault = opts?.marketOracleVault ?? payer;
2533
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2502
2534
  feeAccounts = [
2503
2535
  { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2504
2536
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
@@ -3845,7 +3877,7 @@ var oracle_default = {
3845
3877
 
3846
3878
  // src/idls/hook.json
3847
3879
  var hook_default = {
3848
- address: "F7y5MfW8d5kqR25QHDhUQ9LrKCiZUZVF6Pdnw15q5zZW",
3880
+ address: "5DnFGrt8BGjybNA3EMFKwV1Yvw9iVzJXC7zqP94R7iEV",
3849
3881
  metadata: {
3850
3882
  name: "hook",
3851
3883
  version: "0.1.0",
@@ -3870,12 +3902,7 @@ var hook_default = {
3870
3902
  ],
3871
3903
  accounts: [
3872
3904
  {
3873
- name: "owner",
3874
- signer: true
3875
- },
3876
- {
3877
- name: "payer",
3878
- writable: true,
3905
+ name: "admin",
3879
3906
  signer: true
3880
3907
  },
3881
3908
  {
@@ -4006,12 +4033,7 @@ var hook_default = {
4006
4033
  ],
4007
4034
  accounts: [
4008
4035
  {
4009
- name: "owner",
4010
- signer: true
4011
- },
4012
- {
4013
- name: "payer",
4014
- writable: true,
4036
+ name: "admin",
4015
4037
  signer: true
4016
4038
  },
4017
4039
  {
@@ -4160,7 +4182,7 @@ var hook_default = {
4160
4182
  ],
4161
4183
  accounts: [
4162
4184
  {
4163
- name: "owner",
4185
+ name: "admin",
4164
4186
  writable: true,
4165
4187
  signer: true
4166
4188
  },
@@ -4219,12 +4241,7 @@ var hook_default = {
4219
4241
  ],
4220
4242
  accounts: [
4221
4243
  {
4222
- name: "owner",
4223
- signer: true
4224
- },
4225
- {
4226
- name: "payer",
4227
- writable: true,
4244
+ name: "admin",
4228
4245
  signer: true
4229
4246
  },
4230
4247
  {
@@ -4278,36 +4295,42 @@ var hook_default = {
4278
4295
  types: [
4279
4296
  {
4280
4297
  name: "HookConfig",
4298
+ docs: [
4299
+ "Global config for the Hook program.",
4300
+ "Stores the whitelist of programs allowed to transfer YES/NO Token-2022 tokens."
4301
+ ],
4281
4302
  type: {
4282
4303
  kind: "struct",
4283
4304
  fields: [
4284
4305
  {
4285
- name: "version",
4286
- type: "u8"
4287
- },
4288
- {
4289
- name: "owner",
4306
+ name: "admin",
4307
+ docs: [
4308
+ "Admin who can update the whitelist (should be a multisig)"
4309
+ ],
4290
4310
  type: "pubkey"
4291
4311
  },
4292
4312
  {
4293
4313
  name: "whitelist",
4314
+ docs: [
4315
+ "Programs allowed to initiate or receive YES/NO token transfers.",
4316
+ "Typically: CTF program PDA, CLOB program PDA."
4317
+ ],
4294
4318
  type: {
4295
- array: [
4296
- "pubkey",
4297
- 10
4298
- ]
4319
+ vec: "pubkey"
4299
4320
  }
4300
4321
  },
4301
- {
4302
- name: "whitelist_len",
4303
- type: "u8"
4304
- },
4305
4322
  {
4306
4323
  name: "is_frozen",
4324
+ docs: [
4325
+ "If true, whitelist can no longer be modified (locked forever)"
4326
+ ],
4307
4327
  type: "bool"
4308
4328
  },
4309
4329
  {
4310
4330
  name: "bump",
4331
+ docs: [
4332
+ "Bump for this PDA"
4333
+ ],
4311
4334
  type: "u8"
4312
4335
  },
4313
4336
  {
@@ -4315,7 +4338,7 @@ var hook_default = {
4315
4338
  type: {
4316
4339
  array: [
4317
4340
  "u8",
4318
- 64
4341
+ 32
4319
4342
  ]
4320
4343
  }
4321
4344
  }
@@ -4645,6 +4668,20 @@ var question_market_default = {
4645
4668
  ],
4646
4669
  writable: true
4647
4670
  },
4671
+ {
4672
+ name: "fee_config",
4673
+ docs: [
4674
+ "FeeConfig PDA \u2014 passed to set_market_fee_override CPI."
4675
+ ],
4676
+ writable: true
4677
+ },
4678
+ {
4679
+ name: "market_fee_override",
4680
+ docs: [
4681
+ "MarketFeeOverride PDA \u2014 auto-init with is_admin=false and fee_config defaults."
4682
+ ],
4683
+ writable: true
4684
+ },
4648
4685
  {
4649
4686
  name: "fee_management_program",
4650
4687
  address: "DuYyXguB5PVSKg6E2p4XPrrXZSCJnuBhoGpkGCBN5bBb"
@@ -4750,6 +4787,55 @@ var question_market_default = {
4750
4787
  ],
4751
4788
  args: []
4752
4789
  },
4790
+ {
4791
+ name: "bump_presale_count",
4792
+ discriminator: [
4793
+ 42,
4794
+ 84,
4795
+ 98,
4796
+ 9,
4797
+ 208,
4798
+ 168,
4799
+ 38,
4800
+ 55
4801
+ ],
4802
+ accounts: [
4803
+ {
4804
+ name: "authority",
4805
+ signer: true
4806
+ },
4807
+ {
4808
+ name: "config",
4809
+ writable: true,
4810
+ pda: {
4811
+ seeds: [
4812
+ {
4813
+ kind: "const",
4814
+ value: [
4815
+ 99,
4816
+ 111,
4817
+ 110,
4818
+ 102,
4819
+ 105,
4820
+ 103
4821
+ ]
4822
+ },
4823
+ {
4824
+ kind: "account",
4825
+ path: "config.owner",
4826
+ account: "QuestionMarketConfig"
4827
+ }
4828
+ ]
4829
+ }
4830
+ }
4831
+ ],
4832
+ args: [
4833
+ {
4834
+ name: "count",
4835
+ type: "u64"
4836
+ }
4837
+ ]
4838
+ },
4753
4839
  {
4754
4840
  name: "collect_presale_revenue",
4755
4841
  discriminator: [
@@ -5306,39 +5392,23 @@ var question_market_default = {
5306
5392
  {
5307
5393
  name: "question_fee",
5308
5394
  docs: [
5309
- "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management.",
5310
- "Seed uses condition.key() bytes (consistent with existing set_question_fee SDK convention)."
5395
+ "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management."
5311
5396
  ],
5312
- writable: true,
5313
- pda: {
5314
- seeds: [
5315
- {
5316
- kind: "const",
5317
- value: [
5318
- 113,
5319
- 117,
5320
- 101,
5321
- 115,
5322
- 116,
5323
- 105,
5324
- 111,
5325
- 110,
5326
- 95,
5327
- 102,
5328
- 101,
5329
- 101
5330
- ]
5331
- },
5332
- {
5333
- kind: "account",
5334
- path: "condition"
5335
- }
5336
- ],
5337
- program: {
5338
- kind: "account",
5339
- path: "fee_management_program"
5340
- }
5341
- }
5397
+ writable: true
5398
+ },
5399
+ {
5400
+ name: "fee_config",
5401
+ docs: [
5402
+ "FeeConfig PDA \u2014 passed to set_market_fee_override CPI as authority validator."
5403
+ ],
5404
+ writable: true
5405
+ },
5406
+ {
5407
+ name: "market_fee_override",
5408
+ docs: [
5409
+ "MarketFeeOverride PDA \u2014 init'd by set_market_fee_override CPI (is_admin=true)."
5410
+ ],
5411
+ writable: true
5342
5412
  },
5343
5413
  {
5344
5414
  name: "fee_management_program",
@@ -6311,7 +6381,8 @@ var question_market_default = {
6311
6381
  {
6312
6382
  name: "investors_market_rev",
6313
6383
  docs: [
6314
- "Market revenue split: investors + company (out of FEE_DENOMINATOR = 1_000_000)"
6384
+ "Market revenue split \u2014 three parts must sum to FEE_DENOMINATOR (10_000).",
6385
+ "investors_market_rev + company_market_rev + referral_market_rev == 10_000"
6315
6386
  ],
6316
6387
  type: "u32"
6317
6388
  },
@@ -6322,7 +6393,7 @@ var question_market_default = {
6322
6393
  {
6323
6394
  name: "agents_presale_rev",
6324
6395
  docs: [
6325
- "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 1_000_000)"
6396
+ "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 10_000)"
6326
6397
  ],
6327
6398
  type: "u32"
6328
6399
  },
@@ -6347,12 +6418,26 @@ var question_market_default = {
6347
6418
  name: "bump",
6348
6419
  type: "u8"
6349
6420
  },
6421
+ {
6422
+ name: "referral_market_rev",
6423
+ docs: [
6424
+ "Share of market trading fees routed to referral_vault (e.g. 2_000 = 20%)"
6425
+ ],
6426
+ type: "u32"
6427
+ },
6428
+ {
6429
+ name: "referral_vault",
6430
+ docs: [
6431
+ "ATA of referral program config PDA \u2014 receives referral_market_rev% of trading fees"
6432
+ ],
6433
+ type: "pubkey"
6434
+ },
6350
6435
  {
6351
6436
  name: "_reserved",
6352
6437
  type: {
6353
6438
  array: [
6354
6439
  "u8",
6355
- 64
6440
+ 28
6356
6441
  ]
6357
6442
  }
6358
6443
  }
@@ -6889,7 +6974,7 @@ var question_market_default = {
6889
6974
  type: {
6890
6975
  array: [
6891
6976
  "pubkey",
6892
- 30
6977
+ 20
6893
6978
  ]
6894
6979
  }
6895
6980
  },
@@ -6929,7 +7014,7 @@ var question_market_default = {
6929
7014
  type: {
6930
7015
  array: [
6931
7016
  "u8",
6932
- 120
7017
+ 440
6933
7018
  ]
6934
7019
  }
6935
7020
  }
@@ -16280,6 +16365,7 @@ var XMarketSDK = class {
16280
16365
  const program = new anchor5.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
16281
16366
  this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
16282
16367
  this._market.ctfClient = this.ctf;
16368
+ this._market.feeConfigOwner = this.networkConfig.feeConfigOwner ?? this._marketOwner;
16283
16369
  }
16284
16370
  return this._market;
16285
16371
  }
@@ -16298,6 +16384,8 @@ var XMarketSDK = class {
16298
16384
  this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
16299
16385
  this._clob.feeClient = this.fee;
16300
16386
  }
16387
+ this._clob.ctfClient = this.ctf;
16388
+ this._clob.qmConfigPda = this.market.configPda;
16301
16389
  }
16302
16390
  return this._clob;
16303
16391
  }