rain-sdk-v2 2.1.6 → 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 +2 -1
- package/dist/Rain.js +11 -5
- package/dist/config/environments.js +1 -1
- package/package.json +2 -2
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
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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 *
|
|
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
|
}
|
|
@@ -28,7 +28,7 @@ export const ENV_CONFIG = {
|
|
|
28
28
|
oracle_fixed_fee_per_option: 1000000000000000000n, // $1 in 18 decimals
|
|
29
29
|
},
|
|
30
30
|
usdr: {
|
|
31
|
-
address: "
|
|
31
|
+
address: "0x2b67d5367175d8C0Ce3c755004565a60F1D08D4D",
|
|
32
32
|
symbol: "USDR",
|
|
33
33
|
decimals: 18,
|
|
34
34
|
oracle_fixed_fee_per_option: 1000000000000000000n, // $1 in 18 decimals
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rain-sdk-v2",
|
|
3
|
-
"version": "2.1.
|
|
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
|
+
}
|