@theliem/xmarket-sdk 3.25.0 → 3.27.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.js CHANGED
@@ -195,6 +195,14 @@ var PDA = class {
195
195
  programIds.clobExchange
196
196
  );
197
197
  }
198
+ static redeemFeeOrderRecord(user, nonce, programIds) {
199
+ const nonceBuf = Buffer.alloc(8);
200
+ nonceBuf.writeBigUInt64LE(BigInt(nonce.toString()));
201
+ return web3_js.PublicKey.findProgramAddressSync(
202
+ [Buffer.from("redeem_fee_order"), user.toBuffer(), nonceBuf],
203
+ programIds.clobExchange
204
+ );
205
+ }
198
206
  // ─── Fee Management ─────────────────────────────────────────────────────────
199
207
  static feeConfig(owner, programIds) {
200
208
  if (!programIds.feeManagement) throw new Error("feeManagement program ID not configured");
@@ -1504,6 +1512,50 @@ function buildBatchedCollectFeeEd25519Instruction(orders) {
1504
1512
  data
1505
1513
  });
1506
1514
  }
1515
+ function serializeRedeemFeeOrderToBytes(order) {
1516
+ const buf = new Uint8Array(128);
1517
+ buf.set(order.user.toBytes(), 0);
1518
+ buf.set(order.condition.toBytes(), 32);
1519
+ buf.set(order.tokenMint.toBytes(), 64);
1520
+ buf.set(order.amount.toArrayLike(Buffer, "le", 8), 96);
1521
+ buf.set(order.takerAmount.toArrayLike(Buffer, "le", 8), 104);
1522
+ buf.set(order.nonce.toArrayLike(Buffer, "le", 8), 112);
1523
+ buf.set(order.expiry.toArrayLike(Buffer, "le", 8), 120);
1524
+ return buf;
1525
+ }
1526
+ function buildBatchedRedeemFeeEd25519Instruction(orders) {
1527
+ const N = orders.length;
1528
+ if (N === 0) throw new Error("At least 1 order required");
1529
+ const MSG_SIZE = 128;
1530
+ const SIG_SIZE = 64;
1531
+ const PK_SIZE = 32;
1532
+ const HEADER = 2 + N * 14;
1533
+ const sigBase = HEADER;
1534
+ const pkBase = sigBase + N * SIG_SIZE;
1535
+ const msgBase = pkBase + N * PK_SIZE;
1536
+ const totalSize = msgBase + N * MSG_SIZE;
1537
+ const data = Buffer.alloc(totalSize);
1538
+ data[0] = N;
1539
+ data[1] = 0;
1540
+ for (let i = 0; i < N; i++) {
1541
+ const e = 2 + i * 14;
1542
+ data.writeUInt16LE(sigBase + i * SIG_SIZE, e);
1543
+ data.writeUInt16LE(65535, e + 2);
1544
+ data.writeUInt16LE(pkBase + i * PK_SIZE, e + 4);
1545
+ data.writeUInt16LE(65535, e + 6);
1546
+ data.writeUInt16LE(msgBase + i * MSG_SIZE, e + 8);
1547
+ data.writeUInt16LE(MSG_SIZE, e + 10);
1548
+ data.writeUInt16LE(65535, e + 12);
1549
+ data.set(orders[i].signature, sigBase + i * SIG_SIZE);
1550
+ data.set(orders[i].order.user.toBytes(), pkBase + i * PK_SIZE);
1551
+ data.set(serializeRedeemFeeOrderToBytes(orders[i].order), msgBase + i * MSG_SIZE);
1552
+ }
1553
+ return new web3_js.TransactionInstruction({
1554
+ keys: [],
1555
+ programId: web3_js.Ed25519Program.programId,
1556
+ data
1557
+ });
1558
+ }
1507
1559
  function buildOrder(params) {
1508
1560
  return {
1509
1561
  maker: params.maker,
@@ -2749,6 +2801,236 @@ ${logs.join("\n")}`);
2749
2801
  const alt = opts?.lookupTable ?? await this.buildAltForCollectBatch(condition, payer, collateralMint, signedOrders, outcomeIndex);
2750
2802
  return this._buildUnsignedVtx([...hookInitIxs, collectIx], alt, payer);
2751
2803
  }
2804
+ // ─── Register RedeemFeeOrder ─────────────────────────────────────────────────
2805
+ /**
2806
+ * Build a Transaction to register a RedeemFeeOrder on-chain (Ed25519 verify + PDA).
2807
+ * Must be sent before calling buildBatchRedeemWithFeeTx / buildBatchMergeWithFeeTx.
2808
+ *
2809
+ * ix[0]: batched Ed25519 { pubkey=order.user, sig, msg=128 bytes }
2810
+ * ix[1]: register_redeem_fee_order(nonce)
2811
+ */
2812
+ async buildRegisterRedeemFeeOrderTx(signedOrder, payer) {
2813
+ const { order } = signedOrder;
2814
+ const [redeemFeeOrderRecord] = PDA.redeemFeeOrderRecord(order.user, order.nonce, this.programIds);
2815
+ const ed25519Ix = buildBatchedRedeemFeeEd25519Instruction([signedOrder]);
2816
+ const registerIx = await this.program.methods.registerRedeemFeeOrder(order.nonce).accounts({
2817
+ payer,
2818
+ clobConfig: this.configPda(),
2819
+ ixSysvar: IX_SYSVAR,
2820
+ orderSigner: order.user,
2821
+ redeemFeeOrderRecord,
2822
+ systemProgram: anchor5__namespace.web3.SystemProgram.programId
2823
+ }).instruction();
2824
+ const tx = new anchor5__namespace.web3.Transaction();
2825
+ tx.add(ed25519Ix, registerIx);
2826
+ return tx;
2827
+ }
2828
+ // ─── batchRedeemWithFee ───────────────────────────────────────────────────────
2829
+ /**
2830
+ * Build a VersionedTransaction for batchRedeemWithFee.
2831
+ * Each pair has a YES order + NO order for the same user (same signer or different).
2832
+ * After resolution: YES holder taker_amount > 0, NO holder taker_amount = 0 (or vice versa).
2833
+ *
2834
+ * Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
2835
+ */
2836
+ async buildBatchRedeemWithFeeTx(orderPairs, condition, operator, payer, opts) {
2837
+ if (orderPairs.length === 0) throw new InvalidParamError("At least 1 order pair required");
2838
+ const collateralMint = this.networkConfig.defaultCollateral.mint;
2839
+ const cfg = await this.fetchConfig();
2840
+ if (!cfg) throw new InvalidParamError("CLOB config not found on-chain");
2841
+ const clobConfig = this.configPda();
2842
+ const [yesMint] = PDA.yesMint(condition, this.programIds);
2843
+ const [noMint] = PDA.noMint(condition, this.programIds);
2844
+ const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
2845
+ const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
2846
+ const [yesExtraMeta] = PDA.extraAccountMetaList(yesMint, this.programIds);
2847
+ const [noExtraMeta] = PDA.extraAccountMetaList(noMint, this.programIds);
2848
+ const [hookConfig] = PDA.hookConfig(this.programIds);
2849
+ const [clobYesPosition] = PDA.position(condition, 1, clobConfig, this.programIds);
2850
+ const [clobNoPosition] = PDA.position(condition, 0, clobConfig, this.programIds);
2851
+ const clobYesAta = splToken.getAssociatedTokenAddressSync(yesMint, clobConfig, true, splToken.TOKEN_2022_PROGRAM_ID);
2852
+ const clobNoAta = splToken.getAssociatedTokenAddressSync(noMint, clobConfig, true, splToken.TOKEN_2022_PROGRAM_ID);
2853
+ const userAccounts = [];
2854
+ for (const { yes, no } of orderPairs) {
2855
+ const [yesRecord] = PDA.redeemFeeOrderRecord(yes.order.user, yes.order.nonce, this.programIds);
2856
+ const [noRecord] = PDA.redeemFeeOrderRecord(no.order.user, no.order.nonce, this.programIds);
2857
+ const userYesAta = splToken.getAssociatedTokenAddressSync(yesMint, yes.order.user, false, splToken.TOKEN_2022_PROGRAM_ID);
2858
+ const userNoAta = splToken.getAssociatedTokenAddressSync(noMint, no.order.user, false, splToken.TOKEN_2022_PROGRAM_ID);
2859
+ const [userYesPos] = PDA.position(condition, 1, yes.order.user, this.programIds);
2860
+ const [userNoPos] = PDA.position(condition, 0, no.order.user, this.programIds);
2861
+ const yesCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, yes.order.user);
2862
+ const noCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, no.order.user);
2863
+ userAccounts.push(
2864
+ { pubkey: yesRecord, isSigner: false, isWritable: true },
2865
+ { pubkey: noRecord, isSigner: false, isWritable: true },
2866
+ { pubkey: yes.order.user, isSigner: false, isWritable: false },
2867
+ { pubkey: no.order.user, isSigner: false, isWritable: false },
2868
+ { pubkey: userYesAta, isSigner: false, isWritable: true },
2869
+ { pubkey: userNoAta, isSigner: false, isWritable: true },
2870
+ { pubkey: userYesPos, isSigner: false, isWritable: true },
2871
+ { pubkey: userNoPos, isSigner: false, isWritable: true },
2872
+ { pubkey: yesCollateral, isSigner: false, isWritable: true },
2873
+ { pubkey: noCollateral, isSigner: false, isWritable: true }
2874
+ );
2875
+ }
2876
+ const hookAccounts = [
2877
+ { pubkey: yesExtraMeta, isSigner: false, isWritable: false },
2878
+ { pubkey: noExtraMeta, isSigner: false, isWritable: false },
2879
+ { pubkey: hookConfig, isSigner: false, isWritable: false },
2880
+ { pubkey: this.programIds.hook, isSigner: false, isWritable: false }
2881
+ ];
2882
+ let feeAccounts = [];
2883
+ if (this.programIds.feeManagement && this.feeConfigOwner) {
2884
+ const companyAddr = await this.companyAddress();
2885
+ const refVault = await this.referralVault();
2886
+ if (companyAddr && refVault) {
2887
+ const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2888
+ const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2889
+ if (feeOverrideExists) {
2890
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2891
+ feeAccounts = [
2892
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2893
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2894
+ { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2895
+ { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2896
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
2897
+ { pubkey: refVault, isSigner: false, isWritable: true }
2898
+ ];
2899
+ }
2900
+ }
2901
+ }
2902
+ await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2903
+ const hookInitIxs = [];
2904
+ if (this.hookClient) {
2905
+ for (const mint of [yesMint, noMint]) {
2906
+ const ix = await this.hookClient.buildInitHookIxIfNeeded(mint, payer);
2907
+ if (ix) hookInitIxs.push(ix);
2908
+ }
2909
+ }
2910
+ const redeemIx = await this.program.methods.batchRedeemWithFee(orderPairs.length).accounts({
2911
+ operator,
2912
+ payer,
2913
+ clobConfig,
2914
+ condition,
2915
+ collateralVault,
2916
+ vaultTokenAccount,
2917
+ feeRecipient: cfg.feeRecipient,
2918
+ yesMint,
2919
+ noMint,
2920
+ clobYesAta,
2921
+ clobNoAta,
2922
+ clobYesPosition,
2923
+ clobNoPosition,
2924
+ conditionalTokensProgram: this.programIds.conditionalTokens,
2925
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
2926
+ token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
2927
+ systemProgram: anchor5__namespace.web3.SystemProgram.programId
2928
+ }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
2929
+ const alt = opts?.lookupTable ?? await this.buildAltForCondition(condition, payer, collateralMint);
2930
+ return this._buildUnsignedVtx([...hookInitIxs, redeemIx], alt, payer);
2931
+ }
2932
+ // ─── batchMergeWithFee ────────────────────────────────────────────────────────
2933
+ /**
2934
+ * Build a VersionedTransaction for batchMergeWithFee (pre-resolution merge with fee).
2935
+ * Each pair: YES order + NO order with equal amounts for the same user.
2936
+ * Only yes_signer receives net USDS (mirrors EVM _matchMergeOrder).
2937
+ *
2938
+ * Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
2939
+ */
2940
+ async buildBatchMergeWithFeeTx(orderPairs, condition, operator, payer, opts) {
2941
+ if (orderPairs.length === 0) throw new InvalidParamError("At least 1 order pair required");
2942
+ const collateralMint = this.networkConfig.defaultCollateral.mint;
2943
+ const cfg = await this.fetchConfig();
2944
+ if (!cfg) throw new InvalidParamError("CLOB config not found on-chain");
2945
+ const clobConfig = this.configPda();
2946
+ const [yesMint] = PDA.yesMint(condition, this.programIds);
2947
+ const [noMint] = PDA.noMint(condition, this.programIds);
2948
+ const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
2949
+ const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
2950
+ const [yesExtraMeta] = PDA.extraAccountMetaList(yesMint, this.programIds);
2951
+ const [noExtraMeta] = PDA.extraAccountMetaList(noMint, this.programIds);
2952
+ const [hookConfig] = PDA.hookConfig(this.programIds);
2953
+ const [clobYesPosition] = PDA.position(condition, 1, clobConfig, this.programIds);
2954
+ const [clobNoPosition] = PDA.position(condition, 0, clobConfig, this.programIds);
2955
+ const clobYesAta = splToken.getAssociatedTokenAddressSync(yesMint, clobConfig, true, splToken.TOKEN_2022_PROGRAM_ID);
2956
+ const clobNoAta = splToken.getAssociatedTokenAddressSync(noMint, clobConfig, true, splToken.TOKEN_2022_PROGRAM_ID);
2957
+ const userAccounts = [];
2958
+ for (const { yes, no } of orderPairs) {
2959
+ const [yesRecord] = PDA.redeemFeeOrderRecord(yes.order.user, yes.order.nonce, this.programIds);
2960
+ const [noRecord] = PDA.redeemFeeOrderRecord(no.order.user, no.order.nonce, this.programIds);
2961
+ const userYesAta = splToken.getAssociatedTokenAddressSync(yesMint, yes.order.user, false, splToken.TOKEN_2022_PROGRAM_ID);
2962
+ const userNoAta = splToken.getAssociatedTokenAddressSync(noMint, no.order.user, false, splToken.TOKEN_2022_PROGRAM_ID);
2963
+ const [userYesPos] = PDA.position(condition, 1, yes.order.user, this.programIds);
2964
+ const [userNoPos] = PDA.position(condition, 0, no.order.user, this.programIds);
2965
+ const yesCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, yes.order.user);
2966
+ userAccounts.push(
2967
+ { pubkey: yesRecord, isSigner: false, isWritable: true },
2968
+ { pubkey: noRecord, isSigner: false, isWritable: true },
2969
+ { pubkey: yes.order.user, isSigner: false, isWritable: false },
2970
+ { pubkey: no.order.user, isSigner: false, isWritable: false },
2971
+ { pubkey: userYesAta, isSigner: false, isWritable: true },
2972
+ { pubkey: userNoAta, isSigner: false, isWritable: true },
2973
+ { pubkey: userYesPos, isSigner: false, isWritable: true },
2974
+ { pubkey: userNoPos, isSigner: false, isWritable: true },
2975
+ { pubkey: yesCollateral, isSigner: false, isWritable: true }
2976
+ );
2977
+ }
2978
+ const hookAccounts = [
2979
+ { pubkey: yesExtraMeta, isSigner: false, isWritable: false },
2980
+ { pubkey: noExtraMeta, isSigner: false, isWritable: false },
2981
+ { pubkey: hookConfig, isSigner: false, isWritable: false },
2982
+ { pubkey: this.programIds.hook, isSigner: false, isWritable: false }
2983
+ ];
2984
+ let feeAccounts = [];
2985
+ if (this.programIds.feeManagement && this.feeConfigOwner) {
2986
+ const companyAddr = await this.companyAddress();
2987
+ const refVault = await this.referralVault();
2988
+ if (companyAddr && refVault) {
2989
+ const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2990
+ const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2991
+ if (feeOverrideExists) {
2992
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2993
+ feeAccounts = [
2994
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2995
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2996
+ { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2997
+ { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2998
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
2999
+ { pubkey: refVault, isSigner: false, isWritable: true }
3000
+ ];
3001
+ }
3002
+ }
3003
+ }
3004
+ await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
3005
+ const hookInitIxs = [];
3006
+ if (this.hookClient) {
3007
+ for (const mint of [yesMint, noMint]) {
3008
+ const ix = await this.hookClient.buildInitHookIxIfNeeded(mint, payer);
3009
+ if (ix) hookInitIxs.push(ix);
3010
+ }
3011
+ }
3012
+ const mergeIx = await this.program.methods.batchMergeWithFee(orderPairs.length).accounts({
3013
+ operator,
3014
+ payer,
3015
+ clobConfig,
3016
+ condition,
3017
+ collateralVault,
3018
+ vaultTokenAccount,
3019
+ feeRecipient: cfg.feeRecipient,
3020
+ yesMint,
3021
+ noMint,
3022
+ clobYesAta,
3023
+ clobNoAta,
3024
+ clobYesPosition,
3025
+ clobNoPosition,
3026
+ conditionalTokensProgram: this.programIds.conditionalTokens,
3027
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
3028
+ token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
3029
+ systemProgram: anchor5__namespace.web3.SystemProgram.programId
3030
+ }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
3031
+ const alt = opts?.lookupTable ?? await this.buildAltForCondition(condition, payer, collateralMint);
3032
+ return this._buildUnsignedVtx([...hookInitIxs, mergeIx], alt, payer);
3033
+ }
2752
3034
  /**
2753
3035
  * Build ALT for batchCollectRedeemEarly — includes per-user accounts so all
2754
3036
  * remaining_accounts fit as 1-byte ALT indices instead of 32-byte inline addresses.
@@ -3304,6 +3586,17 @@ var MarketOracleClient = class {
3304
3586
  return null;
3305
3587
  }
3306
3588
  }
3589
+ /**
3590
+ * Derive marketOracleVault from presaleAddress and return its USDS balance.
3591
+ * presaleAddress is used as the questionId seed in the question PDA.
3592
+ */
3593
+ async getOracleVaultBalance(presaleAddress, qmConfigPda, collateralMint) {
3594
+ const [questionPda] = PDA.question(qmConfigPda, presaleAddress.toBytes(), this.programIds);
3595
+ const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
3596
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, marketOraclePda, true);
3597
+ const bal = await this.program.provider.connection.getTokenAccountBalance(vault);
3598
+ return bal.value.uiAmount ?? 0;
3599
+ }
3307
3600
  async fetchUserClaimRecord(marketOraclePda, user) {
3308
3601
  try {
3309
3602
  const pda = this.userClaimRecordPda(marketOraclePda, user);
@@ -9752,70 +10045,372 @@ var clob_exchange_default = {
9752
10045
  ]
9753
10046
  },
9754
10047
  {
9755
- name: "cancel_order",
10048
+ name: "batch_merge_with_fee",
9756
10049
  docs: [
9757
- "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
10050
+ "Batch merge YES+NO tokens before resolution. Returns net USDS to yes_signer, keeps fee.",
10051
+ "Mirrors EVM _matchMergeOrder flow."
9758
10052
  ],
9759
10053
  discriminator: [
9760
- 95,
9761
- 129,
9762
- 237,
9763
- 240,
9764
- 8,
9765
- 49,
9766
- 223,
9767
- 132
10054
+ 56,
10055
+ 127,
10056
+ 113,
10057
+ 232,
10058
+ 208,
10059
+ 177,
10060
+ 157,
10061
+ 230
9768
10062
  ],
9769
10063
  accounts: [
9770
10064
  {
9771
- name: "maker",
9772
- docs: [
9773
- "Must be the order maker/signer"
9774
- ],
10065
+ name: "operator",
9775
10066
  signer: true
9776
10067
  },
9777
10068
  {
9778
- name: "order_record",
10069
+ name: "payer",
10070
+ writable: true,
10071
+ signer: true
10072
+ },
10073
+ {
10074
+ name: "clob_config",
9779
10075
  writable: true,
9780
10076
  pda: {
9781
10077
  seeds: [
9782
10078
  {
9783
10079
  kind: "const",
9784
10080
  value: [
10081
+ 99,
10082
+ 108,
9785
10083
  111,
9786
- 114,
9787
- 100,
9788
- 101,
9789
- 114,
10084
+ 98,
9790
10085
  95,
9791
- 114,
9792
- 101,
9793
10086
  99,
9794
10087
  111,
9795
- 114,
9796
- 100
10088
+ 110,
10089
+ 102,
10090
+ 105,
10091
+ 103
9797
10092
  ]
9798
- },
9799
- {
9800
- kind: "account",
9801
- path: "maker"
9802
- },
9803
- {
9804
- kind: "arg",
9805
- path: "nonce"
9806
10093
  }
9807
10094
  ]
9808
10095
  }
9809
10096
  },
9810
10097
  {
9811
- name: "system_program",
9812
- address: "11111111111111111111111111111111"
9813
- }
9814
- ],
9815
- args: [
10098
+ name: "condition",
10099
+ writable: true
10100
+ },
9816
10101
  {
9817
- name: "nonce",
9818
- type: "u64"
10102
+ name: "collateral_vault",
10103
+ writable: true,
10104
+ pda: {
10105
+ seeds: [
10106
+ {
10107
+ kind: "const",
10108
+ value: [
10109
+ 99,
10110
+ 111,
10111
+ 108,
10112
+ 108,
10113
+ 97,
10114
+ 116,
10115
+ 101,
10116
+ 114,
10117
+ 97,
10118
+ 108,
10119
+ 95,
10120
+ 118,
10121
+ 97,
10122
+ 117,
10123
+ 108,
10124
+ 116
10125
+ ]
10126
+ },
10127
+ {
10128
+ kind: "account",
10129
+ path: "condition.collateral_mint",
10130
+ account: "Condition"
10131
+ }
10132
+ ],
10133
+ program: {
10134
+ kind: "account",
10135
+ path: "conditional_tokens_program"
10136
+ }
10137
+ }
10138
+ },
10139
+ {
10140
+ name: "vault_token_account",
10141
+ writable: true
10142
+ },
10143
+ {
10144
+ name: "fee_recipient",
10145
+ docs: [
10146
+ "CLOB USDS ATA \u2014 receives USDS from merge, distributes to users + fee."
10147
+ ],
10148
+ writable: true
10149
+ },
10150
+ {
10151
+ name: "yes_mint",
10152
+ writable: true
10153
+ },
10154
+ {
10155
+ name: "no_mint",
10156
+ writable: true
10157
+ },
10158
+ {
10159
+ name: "clob_yes_ata",
10160
+ writable: true
10161
+ },
10162
+ {
10163
+ name: "clob_no_ata",
10164
+ writable: true
10165
+ },
10166
+ {
10167
+ name: "clob_yes_position",
10168
+ writable: true
10169
+ },
10170
+ {
10171
+ name: "clob_no_position",
10172
+ writable: true
10173
+ },
10174
+ {
10175
+ name: "conditional_tokens_program",
10176
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
10177
+ },
10178
+ {
10179
+ name: "token_program",
10180
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
10181
+ },
10182
+ {
10183
+ name: "token_2022_program",
10184
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
10185
+ },
10186
+ {
10187
+ name: "system_program",
10188
+ address: "11111111111111111111111111111111"
10189
+ }
10190
+ ],
10191
+ args: [
10192
+ {
10193
+ name: "order_count",
10194
+ type: "u8"
10195
+ }
10196
+ ]
10197
+ },
10198
+ {
10199
+ name: "batch_redeem_with_fee",
10200
+ docs: [
10201
+ "Batch redeem YES+NO tokens after resolution. Returns net USDS to users, keeps fee.",
10202
+ "Mirrors EVM _matchRedeemOrder flow."
10203
+ ],
10204
+ discriminator: [
10205
+ 240,
10206
+ 238,
10207
+ 168,
10208
+ 110,
10209
+ 84,
10210
+ 41,
10211
+ 165,
10212
+ 2
10213
+ ],
10214
+ accounts: [
10215
+ {
10216
+ name: "operator",
10217
+ signer: true
10218
+ },
10219
+ {
10220
+ name: "payer",
10221
+ writable: true,
10222
+ signer: true
10223
+ },
10224
+ {
10225
+ name: "clob_config",
10226
+ writable: true,
10227
+ pda: {
10228
+ seeds: [
10229
+ {
10230
+ kind: "const",
10231
+ value: [
10232
+ 99,
10233
+ 108,
10234
+ 111,
10235
+ 98,
10236
+ 95,
10237
+ 99,
10238
+ 111,
10239
+ 110,
10240
+ 102,
10241
+ 105,
10242
+ 103
10243
+ ]
10244
+ }
10245
+ ]
10246
+ }
10247
+ },
10248
+ {
10249
+ name: "condition",
10250
+ writable: true
10251
+ },
10252
+ {
10253
+ name: "collateral_vault",
10254
+ writable: true,
10255
+ pda: {
10256
+ seeds: [
10257
+ {
10258
+ kind: "const",
10259
+ value: [
10260
+ 99,
10261
+ 111,
10262
+ 108,
10263
+ 108,
10264
+ 97,
10265
+ 116,
10266
+ 101,
10267
+ 114,
10268
+ 97,
10269
+ 108,
10270
+ 95,
10271
+ 118,
10272
+ 97,
10273
+ 117,
10274
+ 108,
10275
+ 116
10276
+ ]
10277
+ },
10278
+ {
10279
+ kind: "account",
10280
+ path: "condition.collateral_mint",
10281
+ account: "Condition"
10282
+ }
10283
+ ],
10284
+ program: {
10285
+ kind: "account",
10286
+ path: "conditional_tokens_program"
10287
+ }
10288
+ }
10289
+ },
10290
+ {
10291
+ name: "vault_token_account",
10292
+ writable: true
10293
+ },
10294
+ {
10295
+ name: "fee_recipient",
10296
+ docs: [
10297
+ "CLOB USDS ATA \u2014 receives USDS from redeem, distributes to users + fee."
10298
+ ],
10299
+ writable: true
10300
+ },
10301
+ {
10302
+ name: "yes_mint",
10303
+ writable: true
10304
+ },
10305
+ {
10306
+ name: "no_mint",
10307
+ writable: true
10308
+ },
10309
+ {
10310
+ name: "clob_yes_ata",
10311
+ writable: true
10312
+ },
10313
+ {
10314
+ name: "clob_no_ata",
10315
+ writable: true
10316
+ },
10317
+ {
10318
+ name: "clob_yes_position",
10319
+ writable: true
10320
+ },
10321
+ {
10322
+ name: "clob_no_position",
10323
+ writable: true
10324
+ },
10325
+ {
10326
+ name: "conditional_tokens_program",
10327
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
10328
+ },
10329
+ {
10330
+ name: "token_program",
10331
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
10332
+ },
10333
+ {
10334
+ name: "token_2022_program",
10335
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
10336
+ },
10337
+ {
10338
+ name: "system_program",
10339
+ address: "11111111111111111111111111111111"
10340
+ }
10341
+ ],
10342
+ args: [
10343
+ {
10344
+ name: "order_count",
10345
+ type: "u8"
10346
+ }
10347
+ ]
10348
+ },
10349
+ {
10350
+ name: "cancel_order",
10351
+ docs: [
10352
+ "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
10353
+ ],
10354
+ discriminator: [
10355
+ 95,
10356
+ 129,
10357
+ 237,
10358
+ 240,
10359
+ 8,
10360
+ 49,
10361
+ 223,
10362
+ 132
10363
+ ],
10364
+ accounts: [
10365
+ {
10366
+ name: "maker",
10367
+ docs: [
10368
+ "Must be the order maker/signer"
10369
+ ],
10370
+ signer: true
10371
+ },
10372
+ {
10373
+ name: "order_record",
10374
+ writable: true,
10375
+ pda: {
10376
+ seeds: [
10377
+ {
10378
+ kind: "const",
10379
+ value: [
10380
+ 111,
10381
+ 114,
10382
+ 100,
10383
+ 101,
10384
+ 114,
10385
+ 95,
10386
+ 114,
10387
+ 101,
10388
+ 99,
10389
+ 111,
10390
+ 114,
10391
+ 100
10392
+ ]
10393
+ },
10394
+ {
10395
+ kind: "account",
10396
+ path: "maker"
10397
+ },
10398
+ {
10399
+ kind: "arg",
10400
+ path: "nonce"
10401
+ }
10402
+ ]
10403
+ }
10404
+ },
10405
+ {
10406
+ name: "system_program",
10407
+ address: "11111111111111111111111111111111"
10408
+ }
10409
+ ],
10410
+ args: [
10411
+ {
10412
+ name: "nonce",
10413
+ type: "u64"
9819
10414
  }
9820
10415
  ]
9821
10416
  },
@@ -10911,6 +11506,107 @@ var clob_exchange_default = {
10911
11506
  }
10912
11507
  ]
10913
11508
  },
11509
+ {
11510
+ name: "register_redeem_fee_order",
11511
+ docs: [
11512
+ "Register a signed RedeemFeeOrder on-chain (Ed25519 verify + PDA creation).",
11513
+ "Prerequisite for batch_redeem_with_fee and batch_merge_with_fee."
11514
+ ],
11515
+ discriminator: [
11516
+ 129,
11517
+ 167,
11518
+ 199,
11519
+ 14,
11520
+ 217,
11521
+ 12,
11522
+ 76,
11523
+ 162
11524
+ ],
11525
+ accounts: [
11526
+ {
11527
+ name: "payer",
11528
+ writable: true,
11529
+ signer: true
11530
+ },
11531
+ {
11532
+ name: "clob_config",
11533
+ pda: {
11534
+ seeds: [
11535
+ {
11536
+ kind: "const",
11537
+ value: [
11538
+ 99,
11539
+ 108,
11540
+ 111,
11541
+ 98,
11542
+ 95,
11543
+ 99,
11544
+ 111,
11545
+ 110,
11546
+ 102,
11547
+ 105,
11548
+ 103
11549
+ ]
11550
+ }
11551
+ ]
11552
+ }
11553
+ },
11554
+ {
11555
+ name: "ix_sysvar",
11556
+ address: "Sysvar1nstructions1111111111111111111111111"
11557
+ },
11558
+ {
11559
+ name: "order_signer"
11560
+ },
11561
+ {
11562
+ name: "redeem_fee_order_record",
11563
+ writable: true,
11564
+ pda: {
11565
+ seeds: [
11566
+ {
11567
+ kind: "const",
11568
+ value: [
11569
+ 114,
11570
+ 101,
11571
+ 100,
11572
+ 101,
11573
+ 101,
11574
+ 109,
11575
+ 95,
11576
+ 102,
11577
+ 101,
11578
+ 101,
11579
+ 95,
11580
+ 111,
11581
+ 114,
11582
+ 100,
11583
+ 101,
11584
+ 114
11585
+ ]
11586
+ },
11587
+ {
11588
+ kind: "account",
11589
+ path: "order_signer"
11590
+ },
11591
+ {
11592
+ kind: "arg",
11593
+ path: "nonce"
11594
+ }
11595
+ ]
11596
+ }
11597
+ },
11598
+ {
11599
+ name: "system_program",
11600
+ address: "11111111111111111111111111111111"
11601
+ }
11602
+ ],
11603
+ args: [
11604
+ {
11605
+ name: "nonce",
11606
+ type: "u64"
11607
+ }
11608
+ ]
11609
+ },
10914
11610
  {
10915
11611
  name: "reinit_clob",
10916
11612
  discriminator: [
@@ -11101,6 +11797,19 @@ var clob_exchange_default = {
11101
11797
  3
11102
11798
  ]
11103
11799
  },
11800
+ {
11801
+ name: "RedeemFeeOrderRecord",
11802
+ discriminator: [
11803
+ 88,
11804
+ 3,
11805
+ 122,
11806
+ 192,
11807
+ 131,
11808
+ 243,
11809
+ 143,
11810
+ 146
11811
+ ]
11812
+ },
11104
11813
  {
11105
11814
  name: "SignedOrderRecord",
11106
11815
  discriminator: [
@@ -11576,6 +12285,57 @@ var clob_exchange_default = {
11576
12285
  ]
11577
12286
  }
11578
12287
  },
12288
+ {
12289
+ name: "RedeemFeeOrderRecord",
12290
+ docs: [
12291
+ "On-chain record of a signed RedeemFeeOrder.",
12292
+ "Created by `register_redeem_fee_order` after Ed25519 verification.",
12293
+ "Read and marked collected by `batch_redeem_with_fee` / `batch_merge_with_fee`.",
12294
+ "",
12295
+ 'PDA seeds: [b"redeem_fee_order", user, nonce_le_bytes]'
12296
+ ],
12297
+ type: {
12298
+ kind: "struct",
12299
+ fields: [
12300
+ {
12301
+ name: "user",
12302
+ type: "pubkey"
12303
+ },
12304
+ {
12305
+ name: "condition",
12306
+ type: "pubkey"
12307
+ },
12308
+ {
12309
+ name: "token_mint",
12310
+ type: "pubkey"
12311
+ },
12312
+ {
12313
+ name: "amount",
12314
+ type: "u64"
12315
+ },
12316
+ {
12317
+ name: "taker_amount",
12318
+ type: "u64"
12319
+ },
12320
+ {
12321
+ name: "nonce",
12322
+ type: "u64"
12323
+ },
12324
+ {
12325
+ name: "expiry",
12326
+ type: "i64"
12327
+ },
12328
+ {
12329
+ name: "is_collected",
12330
+ type: "bool"
12331
+ },
12332
+ {
12333
+ name: "bump",
12334
+ type: "u8"
12335
+ }
12336
+ ]
12337
+ }
12338
+ },
11579
12339
  {
11580
12340
  name: "SignedOrderRecord",
11581
12341
  docs: [
@@ -18176,6 +18936,7 @@ exports.buildApproveAllOutcomeTokensTx = buildApproveAllOutcomeTokensTx;
18176
18936
  exports.buildApproveCollateralTx = buildApproveCollateralTx;
18177
18937
  exports.buildBatchedCollectFeeEd25519Instruction = buildBatchedCollectFeeEd25519Instruction;
18178
18938
  exports.buildBatchedEd25519Instruction = buildBatchedEd25519Instruction;
18939
+ exports.buildBatchedRedeemFeeEd25519Instruction = buildBatchedRedeemFeeEd25519Instruction;
18179
18940
  exports.buildCreateUserAtasTx = buildCreateUserAtasTx;
18180
18941
  exports.buildOrder = buildOrder;
18181
18942
  exports.buildOrderFromPrice = buildOrderFromPrice;
@@ -18187,6 +18948,7 @@ exports.getOrderSignBytes = getOrderSignBytes;
18187
18948
  exports.orderAmountsFromPrice = orderAmountsFromPrice;
18188
18949
  exports.serializeCollectFeeOrderToBytes = serializeCollectFeeOrderToBytes;
18189
18950
  exports.serializeOrderToBytes = serializeOrderToBytes;
18951
+ exports.serializeRedeemFeeOrderToBytes = serializeRedeemFeeOrderToBytes;
18190
18952
  exports.serializeSignedOrder = serializeSignedOrder;
18191
18953
  exports.signOrder = signOrder;
18192
18954
  exports.signOrderWithKeypair = signOrderWithKeypair;