rain-sdk-v2 1.0.11 → 1.2.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/Rain.d.ts +4 -0
- package/dist/Rain.js +27 -3
- package/dist/config/environments.js +2 -2
- package/package.json +1 -1
package/dist/Rain.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export declare class Rain {
|
|
|
15
15
|
*/
|
|
16
16
|
getTokenConfig(tokenAddress: `0x${string}`): import("./config/environments.js").TokenConfig | null;
|
|
17
17
|
buildApprovalTx(params: ApproveTxParams): RawTransaction;
|
|
18
|
+
getCreateMarketFees(tokenAddress: `0x${string}`): Promise<{
|
|
19
|
+
oracleFeePerOption: bigint;
|
|
20
|
+
liquidityFeeBps: bigint;
|
|
21
|
+
}>;
|
|
18
22
|
buildCreateMarketTx(params: CreateMarketTxParams): Promise<RawTransaction[]>;
|
|
19
23
|
buildEnterOptionTx(params: EnterOptionTxParams & {
|
|
20
24
|
walletAddress: `0x${string}`;
|
package/dist/Rain.js
CHANGED
|
@@ -32,6 +32,12 @@ import * as rainBurnApi from './api/rainBurn.js';
|
|
|
32
32
|
import * as disputeApi from './api/dispute.js';
|
|
33
33
|
import * as followApi from './api/follow.js';
|
|
34
34
|
const erc20AllowanceAbi = parseAbi(['function allowance(address owner, address spender) view returns (uint256)']);
|
|
35
|
+
const factoryViewAbi = parseAbi([
|
|
36
|
+
'function oracleFixedFee() view returns (uint256)',
|
|
37
|
+
'function liquidityFee() view returns (uint256)',
|
|
38
|
+
'function baseToken() view returns (address)',
|
|
39
|
+
]);
|
|
40
|
+
const erc20DecimalsAbi = parseAbi(['function decimals() view returns (uint8)']);
|
|
35
41
|
export class Rain {
|
|
36
42
|
environment;
|
|
37
43
|
marketFactory;
|
|
@@ -69,11 +75,29 @@ export class Rain {
|
|
|
69
75
|
buildApprovalTx(params) {
|
|
70
76
|
return buildApproveRawTx(params);
|
|
71
77
|
}
|
|
72
|
-
|
|
78
|
+
async getCreateMarketFees(tokenAddress) {
|
|
79
|
+
const pc = createPublicClient({ chain: arbitrum, transport: http(this.rpcUrl) });
|
|
80
|
+
const [oracleFeeRaw, liquidityFeeBps, factoryBaseToken] = await Promise.all([
|
|
81
|
+
pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'oracleFixedFee' }),
|
|
82
|
+
pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'liquidityFee' }),
|
|
83
|
+
pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'baseToken' }),
|
|
84
|
+
]);
|
|
85
|
+
if (tokenAddress.toLowerCase() === factoryBaseToken.toLowerCase()) {
|
|
86
|
+
return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps };
|
|
87
|
+
}
|
|
88
|
+
const baseTokenDecimals = await pc.readContract({ address: factoryBaseToken, abi: erc20DecimalsAbi, functionName: 'decimals' });
|
|
89
|
+
const tokenConfig = this.getTokenConfig(tokenAddress);
|
|
90
|
+
const tokenDecimals = BigInt(tokenConfig?.decimals ?? 18);
|
|
91
|
+
const oracleFeePerOption = oracleFeeRaw * (10n ** (tokenDecimals - BigInt(baseTokenDecimals)));
|
|
92
|
+
return { oracleFeePerOption, liquidityFeeBps: liquidityFeeBps };
|
|
93
|
+
}
|
|
94
|
+
async buildCreateMarketTx(params) {
|
|
73
95
|
const tokenConfig = this.getTokenConfig(params.baseToken);
|
|
74
|
-
const oracleFixedFeePerOption = tokenConfig?.oracle_fixed_fee_per_option ?? 1000000n;
|
|
75
96
|
const tokenDecimals = params.tokenDecimals ?? tokenConfig?.decimals ?? 6;
|
|
76
|
-
|
|
97
|
+
const { oracleFeePerOption, liquidityFeeBps } = await this.getCreateMarketFees(params.baseToken);
|
|
98
|
+
const liquidityFeeAmount = params.inputAmountWei * liquidityFeeBps / 10000n;
|
|
99
|
+
const totalOracleFee = oracleFeePerOption * BigInt(params.no_of_options) + liquidityFeeAmount;
|
|
100
|
+
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 });
|
|
77
101
|
}
|
|
78
102
|
async buildEnterOptionTx(params) {
|
|
79
103
|
return buildEnterOptionRawTx({ ...params, rpcUrl: this.rpcUrl });
|
|
@@ -22,7 +22,7 @@ export const ENV_CONFIG = {
|
|
|
22
22
|
oracle_fixed_fee_per_option: 1000000n, // $1 in 6 decimals
|
|
23
23
|
},
|
|
24
24
|
rain: {
|
|
25
|
-
address: "
|
|
25
|
+
address: "0x43976a124e6834b541840Ce741243dAD3dd538DA",
|
|
26
26
|
symbol: "RAIN",
|
|
27
27
|
decimals: 18,
|
|
28
28
|
oracle_fixed_fee_per_option: 1000000000000000000n, // $1 in 18 decimals
|
|
@@ -41,7 +41,7 @@ export const ENV_CONFIG = {
|
|
|
41
41
|
oracle_fixed_fee_per_option: 1000000n,
|
|
42
42
|
},
|
|
43
43
|
rain: {
|
|
44
|
-
address: "
|
|
44
|
+
address: "0x25118290e6A5f4139381D072181157035864099d",
|
|
45
45
|
symbol: "RAIN",
|
|
46
46
|
decimals: 18,
|
|
47
47
|
oracle_fixed_fee_per_option: 1000000000000000000n,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rain-sdk-v2",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|