rain-sdk-v2 2.0.7 → 2.0.9
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 +34 -0
- package/dist/Rain.d.ts +2 -0
- package/dist/Rain.js +4 -0
- package/dist/abi/OracleAbi.d.ts +14 -0
- package/dist/abi/OracleAbi.js +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/tx/CreateMarket/createMarketValidation.js +2 -2
- package/dist/tx/buildExtendTimeRawTx.d.ts +10 -0
- package/dist/tx/buildExtendTimeRawTx.js +37 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -459,6 +459,35 @@ const tx = await rain.buildCalculateWinnerTx({
|
|
|
459
459
|
|
|
460
460
|
---
|
|
461
461
|
|
|
462
|
+
#### `buildExtendTimeTx(params: ExtendTimeTxParams): Promise<RawTransaction>`
|
|
463
|
+
|
|
464
|
+
Extend the resolution time of a market option. Requires a signature from the oracle backend (obtained via `signOraclesExtendTime` API). Reads `optionResolver(option)` from the market and calls `extendTime(newEndTime, signature)` on that resolver contract.
|
|
465
|
+
|
|
466
|
+
```typescript
|
|
467
|
+
// 1. Get the signature from the API
|
|
468
|
+
const signResult = await rain.signOraclesExtendTime(
|
|
469
|
+
{ contractAddress: '0x...', walletAddress: '0x...' },
|
|
470
|
+
accessToken
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
// 2. Build the extend time transaction
|
|
474
|
+
const tx = await rain.buildExtendTimeTx({
|
|
475
|
+
marketContractAddress: '0x...',
|
|
476
|
+
option: 1n,
|
|
477
|
+
newEndTime: BigInt(Math.floor(Date.now() / 1000) + 86400), // extend by 1 day
|
|
478
|
+
signature: signResult.signature, // from API
|
|
479
|
+
});
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
| Param | Type | Description |
|
|
483
|
+
|---|---|---|
|
|
484
|
+
| `marketContractAddress` | `0x${string}` | Market contract address |
|
|
485
|
+
| `option` | `bigint` | Option index (1-based) |
|
|
486
|
+
| `newEndTime` | `bigint` | New end time as unix timestamp (seconds) |
|
|
487
|
+
| `signature` | `0x${string}` | Backend signature from `signOraclesExtendTime` |
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
462
491
|
### Claiming
|
|
463
492
|
|
|
464
493
|
#### `buildClaimTx(params: ClaimTxParams): RawTransaction`
|
|
@@ -804,6 +833,11 @@ If disputed:
|
|
|
804
833
|
6c. Appeal (buildOpenDisputeTx again)
|
|
805
834
|
```
|
|
806
835
|
|
|
836
|
+
If extending time:
|
|
837
|
+
```
|
|
838
|
+
5b. Extend Time (signOraclesExtendTime API → buildExtendTimeTx)
|
|
839
|
+
```
|
|
840
|
+
|
|
807
841
|
---
|
|
808
842
|
|
|
809
843
|
## REST API Methods
|
package/dist/Rain.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApproveTxParams, CreateMarketTxParams, EnterOptionTxParams, SellOptionTxParams, AddLiquidityTxParams, RemoveLiquidityTxParams, SplitTxParams, MergeTxParams, ClosePoolAITxParams, ClosePoolManualTxParams, ChooseWinnerTxParams, PlaceBuyOrderTxParams, PlaceSellOrderTxParams, OpenDisputeTxParams, ClaimTxParams, CancelBuyOrdersTxParams, CancelSellOrdersTxParams, RawTransaction } from './tx/types.js';
|
|
2
2
|
import { CalculateWinnerTxParams } from './tx/buildCalculateWinnerRawTx.js';
|
|
3
|
+
import { ExtendTimeTxParams } from './tx/buildExtendTimeRawTx.js';
|
|
3
4
|
import { RainCoreConfig, RainEnvironment } from './types.js';
|
|
4
5
|
import { LoginParams, LoginResult } from './auth/types.js';
|
|
5
6
|
import { EntrySharesResult } from './markets/getEntryShares.js';
|
|
@@ -80,6 +81,7 @@ export declare class Rain {
|
|
|
80
81
|
buildPlaceSellOrderTx(params: PlaceSellOrderTxParams): RawTransaction;
|
|
81
82
|
buildOpenDisputeTx(params: OpenDisputeTxParams): Promise<RawTransaction[]>;
|
|
82
83
|
buildCalculateWinnerTx(params: CalculateWinnerTxParams): Promise<RawTransaction>;
|
|
84
|
+
buildExtendTimeTx(params: ExtendTimeTxParams): Promise<RawTransaction>;
|
|
83
85
|
buildClaimTx(params: ClaimTxParams): RawTransaction;
|
|
84
86
|
buildCancelBuyOrdersTx(params: CancelBuyOrdersTxParams): RawTransaction;
|
|
85
87
|
buildCancelSellOrdersTx(params: CancelSellOrdersTxParams): RawTransaction;
|
package/dist/Rain.js
CHANGED
|
@@ -12,6 +12,7 @@ import { buildOpenDisputeRawTx } from './tx/buildOpenDisputeRawTx.js';
|
|
|
12
12
|
import { buildClaimRawTx } from './tx/buildClaimRawTx.js';
|
|
13
13
|
import { buildCancelBuyOrdersRawTx, buildCancelSellOrdersRawTx } from './tx/buildCancelOrdersRawTx.js';
|
|
14
14
|
import { buildCalculateWinnerRawTx } from './tx/buildCalculateWinnerRawTx.js';
|
|
15
|
+
import { buildExtendTimeRawTx } from './tx/buildExtendTimeRawTx.js';
|
|
15
16
|
import { getUserActiveBuyOrders, getUserActiveSellOrders, getFirstBuyOrderPrice, getFirstSellOrderPrice, getBuyOrdersAtPrice, getSellOrdersAtPrice, checkOrderExists } from './markets/getOrderInfo.js';
|
|
16
17
|
import { ALLOWED_ENVIRONMENTS, ENV_CONFIG, getRandomRpc } from './config/environments.js';
|
|
17
18
|
import { loginUser } from './auth/login.js';
|
|
@@ -165,6 +166,9 @@ export class Rain {
|
|
|
165
166
|
async buildCalculateWinnerTx(params) {
|
|
166
167
|
return buildCalculateWinnerRawTx({ ...params, rpcUrl: this.rpcUrl });
|
|
167
168
|
}
|
|
169
|
+
async buildExtendTimeTx(params) {
|
|
170
|
+
return buildExtendTimeRawTx({ ...params, rpcUrl: this.rpcUrl });
|
|
171
|
+
}
|
|
168
172
|
buildClaimTx(params) {
|
|
169
173
|
return buildClaimRawTx(params);
|
|
170
174
|
}
|
package/dist/abi/OracleAbi.d.ts
CHANGED
|
@@ -8,4 +8,18 @@ export declare const OracleAbi: readonly [{
|
|
|
8
8
|
}];
|
|
9
9
|
readonly stateMutability: "nonpayable";
|
|
10
10
|
readonly type: "function";
|
|
11
|
+
}, {
|
|
12
|
+
readonly inputs: readonly [{
|
|
13
|
+
readonly internalType: "uint256";
|
|
14
|
+
readonly name: "newEndTime";
|
|
15
|
+
readonly type: "uint256";
|
|
16
|
+
}, {
|
|
17
|
+
readonly internalType: "bytes";
|
|
18
|
+
readonly name: "signature";
|
|
19
|
+
readonly type: "bytes";
|
|
20
|
+
}];
|
|
21
|
+
readonly name: "extendTime";
|
|
22
|
+
readonly outputs: readonly [];
|
|
23
|
+
readonly stateMutability: "nonpayable";
|
|
24
|
+
readonly type: "function";
|
|
11
25
|
}];
|
package/dist/abi/OracleAbi.js
CHANGED
|
@@ -11,5 +11,23 @@ export const OracleAbi = [
|
|
|
11
11
|
],
|
|
12
12
|
"stateMutability": "nonpayable",
|
|
13
13
|
"type": "function"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"inputs": [
|
|
17
|
+
{
|
|
18
|
+
"internalType": "uint256",
|
|
19
|
+
"name": "newEndTime",
|
|
20
|
+
"type": "uint256"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"internalType": "bytes",
|
|
24
|
+
"name": "signature",
|
|
25
|
+
"type": "bytes"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"name": "extendTime",
|
|
29
|
+
"outputs": [],
|
|
30
|
+
"stateMutability": "nonpayable",
|
|
31
|
+
"type": "function"
|
|
14
32
|
}
|
|
15
33
|
];
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export { TradingModel, OptionSide } from './tx/types.js';
|
|
|
5
5
|
export type { CreateMarketTxParams, EnterOptionTxParams, AddLiquidityTxParams, RemoveLiquidityTxParams, SplitTxParams, MergeTxParams, ClosePoolAITxParams, ClosePoolManualTxParams, ChooseWinnerTxParams, PlaceBuyOrderTxParams, PlaceSellOrderTxParams, OpenDisputeTxParams, ClaimTxParams, CancelBuyOrdersTxParams, CancelSellOrdersTxParams, RawTransaction, ApproveTxParams } from './tx/types.js';
|
|
6
6
|
export type { LoginParams, LoginResult } from './auth/types.js';
|
|
7
7
|
export { signLoginMessage } from './auth/signMessage.js';
|
|
8
|
+
export type { ExtendTimeTxParams } from './tx/buildExtendTimeRawTx.js';
|
|
9
|
+
export type { CalculateWinnerTxParams } from './tx/buildCalculateWinnerRawTx.js';
|
|
8
10
|
export type { TokenConfig } from './config/environments.js';
|
|
9
11
|
export * from './api/index.js';
|
|
10
12
|
export { RainSocket } from './socket/RainSocket.js';
|
|
@@ -17,8 +17,8 @@ export function validateCreateMarketParams(params) {
|
|
|
17
17
|
if (marketOptions.some(opt => !opt?.toString().trim())) {
|
|
18
18
|
throw new Error("options cannot contain empty values");
|
|
19
19
|
}
|
|
20
|
-
if (!Array.isArray(marketTags) || marketTags.length < 1 || marketTags.length >
|
|
21
|
-
throw new Error("tags must be between 1 and
|
|
20
|
+
if (!Array.isArray(marketTags) || marketTags.length < 1 || marketTags.length > 15) {
|
|
21
|
+
throw new Error("tags must be between 1 and 15");
|
|
22
22
|
}
|
|
23
23
|
if (marketTags.some(tag => !tag?.toString().trim())) {
|
|
24
24
|
throw new Error("tags cannot contain empty values");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RawTransaction } from "./types.js";
|
|
2
|
+
export interface ExtendTimeTxParams {
|
|
3
|
+
marketContractAddress: `0x${string}`;
|
|
4
|
+
option: bigint;
|
|
5
|
+
newEndTime: bigint;
|
|
6
|
+
signature: `0x${string}`;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildExtendTimeRawTx(params: ExtendTimeTxParams & {
|
|
9
|
+
rpcUrl: string;
|
|
10
|
+
}): Promise<RawTransaction>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { encodeFunctionData, createPublicClient, http, parseAbi } from "viem";
|
|
2
|
+
import { arbitrum } from "viem/chains";
|
|
3
|
+
import { OracleAbi } from "../abi/OracleAbi.js";
|
|
4
|
+
const optionResolverAbi = parseAbi(['function optionResolver(uint256 option) view returns (address)']);
|
|
5
|
+
export async function buildExtendTimeRawTx(params) {
|
|
6
|
+
const { marketContractAddress, option, newEndTime, signature, rpcUrl } = params;
|
|
7
|
+
if (!marketContractAddress)
|
|
8
|
+
throw new Error("marketContractAddress is required");
|
|
9
|
+
if (option === undefined || option === null)
|
|
10
|
+
throw new Error("option is required");
|
|
11
|
+
if (!newEndTime)
|
|
12
|
+
throw new Error("newEndTime is required");
|
|
13
|
+
if (!signature)
|
|
14
|
+
throw new Error("signature is required");
|
|
15
|
+
const client = createPublicClient({
|
|
16
|
+
chain: arbitrum,
|
|
17
|
+
transport: http(rpcUrl),
|
|
18
|
+
});
|
|
19
|
+
const resolverAddress = await client.readContract({
|
|
20
|
+
address: marketContractAddress,
|
|
21
|
+
abi: optionResolverAbi,
|
|
22
|
+
functionName: 'optionResolver',
|
|
23
|
+
args: [option],
|
|
24
|
+
});
|
|
25
|
+
if (!resolverAddress || resolverAddress === '0x0000000000000000000000000000000000000000') {
|
|
26
|
+
throw new Error("No resolver set for this option");
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
to: resolverAddress,
|
|
30
|
+
data: encodeFunctionData({
|
|
31
|
+
abi: OracleAbi,
|
|
32
|
+
functionName: 'extendTime',
|
|
33
|
+
args: [newEndTime, signature],
|
|
34
|
+
}),
|
|
35
|
+
value: 0n,
|
|
36
|
+
};
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rain-sdk-v2",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
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",
|