rain-sdk-v2 2.1.7 → 2.1.8

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/Rain.d.ts CHANGED
@@ -21,7 +21,8 @@ export declare class Rain {
21
21
  buildApprovalTx(params: ApproveTxParams): RawTransaction;
22
22
  getCreateMarketFees(tokenAddress: `0x${string}`, inputAmountWei: bigint): Promise<{
23
23
  oracleFeePerOption: bigint;
24
- liquidityFeeBps: bigint;
24
+ liquidityFee: bigint;
25
+ feeMagnification: bigint;
25
26
  useBufferApproval: boolean;
26
27
  perOptionBuffer: bigint;
27
28
  }>;
package/dist/Rain.js CHANGED
@@ -51,6 +51,12 @@ const factoryViewAbi = parseAbi([
51
51
  'function liquidityFee() view returns (uint256)',
52
52
  'function baseToken() view returns (address)',
53
53
  ]);
54
+ // Scale of the factory's liquidityFee(). Matches the market contracts'
55
+ // FEE_MAGNIFICATION constant (verified on-chain = 1000 on dev and production
56
+ // markets; the factory itself does not expose it). liquidityFee() = 12 means
57
+ // a 1.2% fee — the unit is per-mille, NOT basis points: dividing by 10000
58
+ // computes every fee 10x too small.
59
+ const FEE_MAGNIFICATION = 1000n;
54
60
  export class Rain {
55
61
  environment;
56
62
  marketFactory;
@@ -90,26 +96,26 @@ export class Rain {
90
96
  }
91
97
  async getCreateMarketFees(tokenAddress, inputAmountWei) {
92
98
  const pc = createPublicClient({ chain: arbitrum, transport: http(this.rpcUrl) });
93
- const [oracleFeeRaw, liquidityFeeBps, factoryBaseToken] = await Promise.all([
99
+ const [oracleFeeRaw, liquidityFee, factoryBaseToken] = await Promise.all([
94
100
  pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'oracleFixedFee' }),
95
101
  pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'liquidityFee' }),
96
102
  pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'baseToken' }),
97
103
  ]);
98
104
  if (tokenAddress.toLowerCase() === factoryBaseToken.toLowerCase()) {
99
- return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps, useBufferApproval: false, perOptionBuffer: 0n };
105
+ return { oracleFeePerOption: oracleFeeRaw, liquidityFee: liquidityFee, feeMagnification: FEE_MAGNIFICATION, useBufferApproval: false, perOptionBuffer: 0n };
100
106
  }
101
107
  // For non-base tokens (e.g. RAIN): approval = initialLiquidity + (numberOfOptions * 20% of initialLiquidity)
102
108
  const perOptionBuffer = inputAmountWei * 20n / 100n;
103
- return { oracleFeePerOption: 0n, liquidityFeeBps: liquidityFeeBps, useBufferApproval: true, perOptionBuffer };
109
+ return { oracleFeePerOption: 0n, liquidityFee: liquidityFee, feeMagnification: FEE_MAGNIFICATION, useBufferApproval: true, perOptionBuffer };
104
110
  }
105
111
  async buildCreateMarketTx(params) {
106
112
  const tokenConfig = this.getTokenConfig(params.baseToken);
107
113
  const tokenDecimals = params.tokenDecimals ?? tokenConfig?.decimals ?? 6;
108
- const { oracleFeePerOption, liquidityFeeBps, useBufferApproval, perOptionBuffer } = await this.getCreateMarketFees(params.baseToken, params.inputAmountWei);
114
+ const { oracleFeePerOption, liquidityFee, feeMagnification, useBufferApproval, perOptionBuffer } = await this.getCreateMarketFees(params.baseToken, params.inputAmountWei);
109
115
  if (useBufferApproval) {
110
116
  return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption: perOptionBuffer });
111
117
  }
112
- const liquidityFeeAmount = params.inputAmountWei * liquidityFeeBps / 10000n;
118
+ const liquidityFeeAmount = params.inputAmountWei * liquidityFee / feeMagnification;
113
119
  const totalOracleFee = oracleFeePerOption * BigInt(params.no_of_options) + liquidityFeeAmount;
114
120
  return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption: totalOracleFee / BigInt(params.no_of_options) + 1n });
115
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rain-sdk-v2",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "type": "module",
5
5
  "description": "Rain SDK V2 — TypeScript SDK for Rain prediction markets on Arbitrum. Market creation, trading, liquidity, order book, split/merge, dispute, and smart account support.",
6
6
  "main": "dist/index.js",
@@ -63,4 +63,4 @@
63
63
  "typescript": "^5.9.3",
64
64
  "viem": "^2.48.8"
65
65
  }
66
- }
66
+ }