rain-sdk-v2 2.0.3 → 2.0.4
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/README.md +3 -2
- package/dist/Rain.d.ts +3 -1
- package/dist/Rain.js +9 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -167,8 +167,9 @@ const txsRain = await rain.buildCreateMarketTx({
|
|
|
167
167
|
baseToken: config.tokens.rain.address, // RAIN token
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
-
// Approval
|
|
171
|
-
//
|
|
170
|
+
// Approval for USDT: liquidity + (oracleFixedFeePerOption * numberOfOptions)
|
|
171
|
+
// Approval for RAIN: liquidity + (numberOfOptions * 20% of liquidity)
|
|
172
|
+
// e.g. 1000 RAIN with 5 options → 1000 + (5 * 200) = 2000 RAIN approval
|
|
172
173
|
```
|
|
173
174
|
|
|
174
175
|
| Parameter | Type | Description |
|
package/dist/Rain.d.ts
CHANGED
|
@@ -15,9 +15,11 @@ 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}
|
|
18
|
+
getCreateMarketFees(tokenAddress: `0x${string}`, inputAmountWei: bigint): Promise<{
|
|
19
19
|
oracleFeePerOption: bigint;
|
|
20
20
|
liquidityFeeBps: bigint;
|
|
21
|
+
useBufferApproval: boolean;
|
|
22
|
+
perOptionBuffer: bigint;
|
|
21
23
|
}>;
|
|
22
24
|
buildCreateMarketTx(params: CreateMarketTxParams): Promise<RawTransaction[]>;
|
|
23
25
|
buildEnterOptionTx(params: EnterOptionTxParams & {
|
package/dist/Rain.js
CHANGED
|
@@ -40,7 +40,6 @@ const factoryViewAbi = parseAbi([
|
|
|
40
40
|
'function liquidityFee() view returns (uint256)',
|
|
41
41
|
'function baseToken() view returns (address)',
|
|
42
42
|
]);
|
|
43
|
-
const erc20DecimalsAbi = parseAbi(['function decimals() view returns (uint8)']);
|
|
44
43
|
export class Rain {
|
|
45
44
|
environment;
|
|
46
45
|
marketFactory;
|
|
@@ -78,7 +77,7 @@ export class Rain {
|
|
|
78
77
|
buildApprovalTx(params) {
|
|
79
78
|
return buildApproveRawTx(params);
|
|
80
79
|
}
|
|
81
|
-
async getCreateMarketFees(tokenAddress) {
|
|
80
|
+
async getCreateMarketFees(tokenAddress, inputAmountWei) {
|
|
82
81
|
const pc = createPublicClient({ chain: arbitrum, transport: http(this.rpcUrl) });
|
|
83
82
|
const [oracleFeeRaw, liquidityFeeBps, factoryBaseToken] = await Promise.all([
|
|
84
83
|
pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'oracleFixedFee' }),
|
|
@@ -86,27 +85,19 @@ export class Rain {
|
|
|
86
85
|
pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'baseToken' }),
|
|
87
86
|
]);
|
|
88
87
|
if (tokenAddress.toLowerCase() === factoryBaseToken.toLowerCase()) {
|
|
89
|
-
return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps };
|
|
88
|
+
return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps, useBufferApproval: false, perOptionBuffer: 0n };
|
|
90
89
|
}
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
const priceResponse = await whitelistedTokensApi.getTokenPrice(tokenAddress, { apiUrl: this.apiUrl });
|
|
95
|
-
const tokenPriceUsd = priceResponse.data?.currentprice;
|
|
96
|
-
if (!tokenPriceUsd || tokenPriceUsd <= 0) {
|
|
97
|
-
throw new Error(`Could not fetch price for token ${tokenAddress}`);
|
|
98
|
-
}
|
|
99
|
-
// oracleFeeRaw is in factory base token (USDT) = $value in base token decimals
|
|
100
|
-
// Convert to USD value, then to token amount: feeUsd / tokenPrice * 10^tokenDecimals
|
|
101
|
-
const feeUsd = Number(oracleFeeRaw) / (10 ** baseTokenDecimals);
|
|
102
|
-
const feeInToken = feeUsd / tokenPriceUsd;
|
|
103
|
-
const oracleFeePerOption = BigInt(Math.ceil(feeInToken * (10 ** tokenDecimals)));
|
|
104
|
-
return { oracleFeePerOption, liquidityFeeBps: liquidityFeeBps };
|
|
90
|
+
// For non-base tokens (e.g. RAIN): approval = initialLiquidity + (numberOfOptions * 20% of initialLiquidity)
|
|
91
|
+
const perOptionBuffer = inputAmountWei * 20n / 100n;
|
|
92
|
+
return { oracleFeePerOption: 0n, liquidityFeeBps: liquidityFeeBps, useBufferApproval: true, perOptionBuffer };
|
|
105
93
|
}
|
|
106
94
|
async buildCreateMarketTx(params) {
|
|
107
95
|
const tokenConfig = this.getTokenConfig(params.baseToken);
|
|
108
96
|
const tokenDecimals = params.tokenDecimals ?? tokenConfig?.decimals ?? 6;
|
|
109
|
-
const { oracleFeePerOption, liquidityFeeBps } = await this.getCreateMarketFees(params.baseToken);
|
|
97
|
+
const { oracleFeePerOption, liquidityFeeBps, useBufferApproval, perOptionBuffer } = await this.getCreateMarketFees(params.baseToken, params.inputAmountWei);
|
|
98
|
+
if (useBufferApproval) {
|
|
99
|
+
return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption: perOptionBuffer });
|
|
100
|
+
}
|
|
110
101
|
const liquidityFeeAmount = params.inputAmountWei * liquidityFeeBps / 10000n;
|
|
111
102
|
const totalOracleFee = oracleFeePerOption * BigInt(params.no_of_options) + liquidityFeeAmount;
|
|
112
103
|
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 });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rain-sdk-v2",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
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",
|