@rainprotocolsdk/sdk 1.1.0 → 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/README.md +88 -0
- package/dist/Rain.d.ts +8 -1
- package/dist/Rain.js +24 -1
- package/dist/abi/CreateMarketAbi.d.ts +1144 -0
- package/dist/abi/CreateMarketAbi.js +1478 -0
- package/dist/config/environments.d.ts +18 -0
- package/dist/config/environments.js +18 -0
- package/dist/constants/contractmethods.d.ts +1 -0
- package/dist/constants/contractmethods.js +1 -0
- package/dist/markets/getMarkets.js +4 -2
- package/dist/markets/types.d.ts +1 -0
- package/dist/tx/CreateMarket/buildCreateMarketRawTx.d.ts +2 -0
- package/dist/tx/CreateMarket/buildCreateMarketRawTx.js +36 -0
- package/dist/tx/CreateMarket/createMarketValidation.d.ts +2 -0
- package/dist/tx/CreateMarket/createMarketValidation.js +34 -0
- package/dist/tx/CreateMarket/helpers.d.ts +1 -0
- package/dist/tx/CreateMarket/helpers.js +11 -0
- package/dist/tx/types.d.ts +15 -0
- package/dist/types.d.ts +4 -0
- package/package.json +3 -2
- package/dist/config/api.d.ts +0 -1
- package/dist/config/api.js +0 -1
package/README.md
CHANGED
|
@@ -102,6 +102,94 @@ const approvalTx = rain.buildApprovalTx({
|
|
|
102
102
|
|
|
103
103
|
---
|
|
104
104
|
|
|
105
|
+
## buildCreateMarketTx
|
|
106
|
+
|
|
107
|
+
Builds a **raw EVM transaction** for creating a market in rain protocol.
|
|
108
|
+
|
|
109
|
+
This function **does not send the transaction** — it only prepares calldata.
|
|
110
|
+
|
|
111
|
+
### Method Signature
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
buildCreateMarketTx(params: CreateMarketTxParams): RawTransaction;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Parameters
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
interface CreateMarketTxParams {
|
|
121
|
+
isPublic: boolean;
|
|
122
|
+
isPublicPoolResolverAi: boolean;
|
|
123
|
+
creator: `0x${string}`;
|
|
124
|
+
startTime: number | bigint; // Unix timestamp (seconds)
|
|
125
|
+
endTime: number | bigint; // Must be > startTime
|
|
126
|
+
options: number; // Number of options (> 0)
|
|
127
|
+
ipfsUrl: string; // IPFS CID
|
|
128
|
+
inputAmountWei: bigint; // Initial liquidity (token wei)
|
|
129
|
+
barValues: (number)[]; // Token Distribution values in options in %
|
|
130
|
+
baseToken: `0x${string}`; // ERC20 token address
|
|
131
|
+
tokenDecimals?: number; // Optional (default: 6)
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Validations
|
|
136
|
+
|
|
137
|
+
| Field | Type | Required | Description |
|
|
138
|
+
| ------------------------ | ------------------ | -------- | -------------------------------- |
|
|
139
|
+
| `isPublic` | `boolean` | ✅ | Whether market is public |
|
|
140
|
+
| `isPublicPoolResolverAi` | `boolean` | ✅ | AI resolver flag |
|
|
141
|
+
| `creator` | `0x${string}` | ✅ | Market creator address |
|
|
142
|
+
| `startTime` | `number \| bigint` | ✅ | Market start timestamp |
|
|
143
|
+
| `endTime` | `number \| bigint` | ✅ | Must be greater than `startTime` |
|
|
144
|
+
| `options` | `number` | ✅ | Number of market options (> 2) |
|
|
145
|
+
| `ipfsUrl` | `string` | ✅ | IPFS CID containing metadata |
|
|
146
|
+
| `inputAmountWei` | `bigint` | ✅ | Initial liquidity amount |
|
|
147
|
+
| `barValues` | `array` | ✅ | Cannot be empty |
|
|
148
|
+
| `baseToken` | `0x${string}` | ✅ | ERC20 base token address |
|
|
149
|
+
| `tokenDecimals` | `number` | ❌ | Defaults to `6` |
|
|
150
|
+
|
|
151
|
+
### Minimum Liquidity Rule
|
|
152
|
+
|
|
153
|
+
# inputAmountWei >= 10 tokens
|
|
154
|
+
|
|
155
|
+
### Return Type
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
interface RawTransaction {
|
|
159
|
+
to: `0x${string}`;
|
|
160
|
+
data: `0x${string}`;
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Example
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
rain.buildCreateMarketTx({
|
|
168
|
+
isPublic: true,
|
|
169
|
+
isPublicPoolResolverAi: false,
|
|
170
|
+
creator: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
|
|
171
|
+
startTime: 1770836400,
|
|
172
|
+
endTime: 1770922800,
|
|
173
|
+
options: 3,
|
|
174
|
+
ipfsUrl: "QmUdu2eLEQ2qFtNeVVLfVQDBCoc4DT5752enxDitLGmVec",
|
|
175
|
+
inputAmountWei: 100000000n,
|
|
176
|
+
barValues: [48, 40, 1],
|
|
177
|
+
baseToken: "0xCa4f77A38d8552Dd1D5E44e890173921B67725F4"
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Recommended Execution Pattern
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
// 1. Build raw transaction
|
|
185
|
+
const rawTx = rain.buildCreateMarketTx({...});
|
|
186
|
+
|
|
187
|
+
// 2. Execute using your provider
|
|
188
|
+
await yourProvider.sendTransaction(rawTx);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
105
193
|
## buildBuyOptionRawTx
|
|
106
194
|
|
|
107
195
|
Builds a **raw EVM transaction** for entering a market option.
|
package/dist/Rain.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { GetMarketsParams, Market } from './markets/types.js';
|
|
2
|
-
import { ApproveTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, RawTransaction } from './tx/types.js';
|
|
2
|
+
import { ApproveTxParams, CreateMarketTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, RawTransaction } from './tx/types.js';
|
|
3
|
+
import { RainCoreConfig, RainEnvironment } from './types.js';
|
|
3
4
|
export declare class Rain {
|
|
5
|
+
readonly environment: RainEnvironment;
|
|
6
|
+
private readonly marketFactory;
|
|
7
|
+
private readonly apiUrl;
|
|
8
|
+
private readonly distute_initial_timer;
|
|
9
|
+
constructor(config?: RainCoreConfig);
|
|
4
10
|
getPublicMarkets(params: GetMarketsParams): Promise<Market[]>;
|
|
5
11
|
buildApprovalTx(params: ApproveTxParams): RawTransaction | Error;
|
|
6
12
|
buildBuyOptionRawTx(params: EnterOptionTxParams): RawTransaction;
|
|
7
13
|
buildLimitBuyOptionTx(params: EnterLimitOptionTxParams): RawTransaction;
|
|
14
|
+
buildCreateMarketTx(params: CreateMarketTxParams): RawTransaction;
|
|
8
15
|
}
|
package/dist/Rain.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { getMarkets } from './markets/getMarkets.js';
|
|
2
2
|
import { buildEnterOptionRawTx, buildLimitBuyOrderRawTx } from './tx/buildRawTransactions.js';
|
|
3
3
|
import { buildApproveRawTx } from './tx/buildApprovalRawTx.js';
|
|
4
|
+
import { buildCreateMarketRawTx } from './tx/CreateMarket/buildCreateMarketRawTx.js';
|
|
5
|
+
import { ALLOWED_ENVIRONMENTS, ENV_CONFIG } from './config/environments.js';
|
|
4
6
|
export class Rain {
|
|
7
|
+
environment;
|
|
8
|
+
marketFactory;
|
|
9
|
+
apiUrl;
|
|
10
|
+
distute_initial_timer;
|
|
11
|
+
constructor(config = {}) {
|
|
12
|
+
const { environment = "development" } = config;
|
|
13
|
+
function isValidEnvironment(env) {
|
|
14
|
+
return ALLOWED_ENVIRONMENTS.includes(env);
|
|
15
|
+
}
|
|
16
|
+
if (!isValidEnvironment(environment)) {
|
|
17
|
+
throw new Error(`Invalid environment "${environment}". Allowed values: ${ALLOWED_ENVIRONMENTS.join(", ")}`);
|
|
18
|
+
}
|
|
19
|
+
this.environment = environment;
|
|
20
|
+
const envConfig = ENV_CONFIG[this.environment];
|
|
21
|
+
this.marketFactory = envConfig.market_factory_address;
|
|
22
|
+
this.apiUrl = envConfig.apiUrl;
|
|
23
|
+
this.distute_initial_timer = envConfig.dispute_initial_timer;
|
|
24
|
+
}
|
|
5
25
|
async getPublicMarkets(params) {
|
|
6
|
-
return getMarkets(params);
|
|
26
|
+
return getMarkets({ ...params, apiUrl: this.apiUrl });
|
|
7
27
|
}
|
|
8
28
|
buildApprovalTx(params) {
|
|
9
29
|
return buildApproveRawTx(params);
|
|
@@ -14,4 +34,7 @@ export class Rain {
|
|
|
14
34
|
buildLimitBuyOptionTx(params) {
|
|
15
35
|
return buildLimitBuyOrderRawTx(params);
|
|
16
36
|
}
|
|
37
|
+
buildCreateMarketTx(params) {
|
|
38
|
+
return buildCreateMarketRawTx({ ...params, factoryContractAddress: this.marketFactory, disputeTimer: this.distute_initial_timer });
|
|
39
|
+
}
|
|
17
40
|
}
|