@rainprotocolsdk/sdk 2.0.0 → 2.1.1
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 +54 -1
- package/dist/Rain.d.ts +2 -1
- package/dist/Rain.js +4 -0
- package/dist/abi/OracleAbi.d.ts +15 -0
- package/dist/abi/OracleAbi.js +20 -0
- package/dist/tx/ExtendTime/buildExtendTimeRawTx.d.ts +2 -0
- package/dist/tx/ExtendTime/buildExtendTimeRawTx.js +47 -0
- package/dist/tx/types.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ yarn add @rainprotocolsdk/sdk
|
|
|
30
30
|
```ts
|
|
31
31
|
import { Rain } from "@rainprotocolsdk/sdk";
|
|
32
32
|
|
|
33
|
-
const rain = new Rain(
|
|
33
|
+
const rain = new Rain();
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
### Constructor Parameters
|
|
@@ -825,6 +825,59 @@ const txs = await rain.buildCreateAppealTx({
|
|
|
825
825
|
|
|
826
826
|
---
|
|
827
827
|
|
|
828
|
+
## buildExtendTimeTx
|
|
829
|
+
|
|
830
|
+
Builds a **raw EVM transaction** to re-submit an appeal by extending the oracle voting timer on a disputed Rain market.
|
|
831
|
+
|
|
832
|
+
Internally calls `resolver()` on the market contract to resolve the oracle address, then fetches a signed epoch from the Rain backend, and encodes the `extendTime(epoch, signature)` call targeting the oracle contract.
|
|
833
|
+
|
|
834
|
+
This function **does not send the transaction** — it only prepares calldata.
|
|
835
|
+
|
|
836
|
+
### Method Signature
|
|
837
|
+
|
|
838
|
+
```ts
|
|
839
|
+
buildExtendTimeTx(params: ExtendTimeTxParams): Promise<RawTransaction>
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
### Parameters
|
|
843
|
+
|
|
844
|
+
```ts
|
|
845
|
+
interface ExtendTimeTxParams {
|
|
846
|
+
marketContractAddress: `0x${string}`; // TradeMarket contract address — resolver() is called on it
|
|
847
|
+
walletAddress: `0x${string}`; // Smart account address
|
|
848
|
+
accessToken: string; // JWT from Rain auth (login)
|
|
849
|
+
}
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
### Validations
|
|
853
|
+
|
|
854
|
+
| Field | Type | Required | Description |
|
|
855
|
+
| ----------------------- | ------------- | -------- | ---------------------------------------------------- |
|
|
856
|
+
| `marketContractAddress` | `0x${string}` | ✅ | Market contract — used to look up the oracle address |
|
|
857
|
+
| `walletAddress` | `0x${string}` | ✅ | Smart account address of the caller |
|
|
858
|
+
| `accessToken` | `string` | ✅ | JWT returned from `login()` |
|
|
859
|
+
|
|
860
|
+
### Return Type
|
|
861
|
+
|
|
862
|
+
```ts
|
|
863
|
+
interface RawTransaction {
|
|
864
|
+
to: `0x${string}`; // oracle contract address (resolved on-chain)
|
|
865
|
+
data: `0x${string}`;
|
|
866
|
+
}
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
### Example
|
|
870
|
+
|
|
871
|
+
```ts
|
|
872
|
+
const tx = await rain.buildExtendTimeTx({
|
|
873
|
+
marketContractAddress: "0xMarketContractAddress...",
|
|
874
|
+
walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
|
|
875
|
+
accessToken: "eyJhbGciOi...",
|
|
876
|
+
});
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
---
|
|
880
|
+
|
|
828
881
|
## RainAA Class (Account Abstraction)
|
|
829
882
|
|
|
830
883
|
`RainAA` is responsible for:
|
package/dist/Rain.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GetMarketByIdParams, GetMarketsParams, GetUserInvestmentsParams, Market, UserInvestment } from './markets/types.js';
|
|
2
|
-
import { ApproveTxParams, CancelAllOpenOrdersTxParams, CancelOrdersTxParams, ClaimTxParams, CloseMarketTxParams, CreateDisputeTxParams, CreateAppealTxParams, CreateMarketTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, LimitSellOptionTxParams, RawTransaction } from './tx/types.js';
|
|
2
|
+
import { ApproveTxParams, CancelAllOpenOrdersTxParams, CancelOrdersTxParams, ClaimTxParams, CloseMarketTxParams, CreateDisputeTxParams, CreateAppealTxParams, CreateMarketTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, ExtendTimeTxParams, LimitSellOptionTxParams, RawTransaction } from './tx/types.js';
|
|
3
3
|
import { RainCoreConfig, RainEnvironment } from './types.js';
|
|
4
4
|
import { LoginParams, LoginResult } from './auth/types.js';
|
|
5
5
|
export declare class Rain {
|
|
@@ -24,5 +24,6 @@ export declare class Rain {
|
|
|
24
24
|
buildCloseMarketTx(params: CloseMarketTxParams): Promise<RawTransaction[]>;
|
|
25
25
|
buildCreateDisputeTx(params: CreateDisputeTxParams): Promise<RawTransaction[]>;
|
|
26
26
|
buildCreateAppealTx(params: CreateAppealTxParams): Promise<RawTransaction[]>;
|
|
27
|
+
buildExtendTimeTx(params: ExtendTimeTxParams): Promise<RawTransaction>;
|
|
27
28
|
login(params: LoginParams): Promise<LoginResult>;
|
|
28
29
|
}
|
package/dist/Rain.js
CHANGED
|
@@ -10,6 +10,7 @@ import { buildApproveRawTx } from './tx/buildApprovalRawTx.js';
|
|
|
10
10
|
import { buildCreateMarketRawTx } from './tx/CreateMarket/buildCreateMarketRawTx.js';
|
|
11
11
|
import { ALLOWED_ENVIRONMENTS, ENV_CONFIG, getRandomRpc } from './config/environments.js';
|
|
12
12
|
import { buildClaimRawTx } from './tx/ClaimFunds/buildClaimFundsRawTx.js';
|
|
13
|
+
import { buildExtendTimeRawTx } from './tx/ExtendTime/buildExtendTimeRawTx.js';
|
|
13
14
|
import { loginUser } from './auth/login.js';
|
|
14
15
|
export class Rain {
|
|
15
16
|
environment;
|
|
@@ -76,6 +77,9 @@ export class Rain {
|
|
|
76
77
|
async buildCreateAppealTx(params) {
|
|
77
78
|
return buildCreateAppealRawTx({ ...params, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, usdtSymbol: this.usdtSymbol });
|
|
78
79
|
}
|
|
80
|
+
async buildExtendTimeTx(params) {
|
|
81
|
+
return buildExtendTimeRawTx({ ...params, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl });
|
|
82
|
+
}
|
|
79
83
|
async login(params) {
|
|
80
84
|
return loginUser({ ...params, apiUrl: this.apiUrl });
|
|
81
85
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const OracleAbi: readonly [{
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly internalType: "uint256";
|
|
4
|
+
readonly name: "newEndTime";
|
|
5
|
+
readonly type: "uint256";
|
|
6
|
+
}, {
|
|
7
|
+
readonly internalType: "bytes";
|
|
8
|
+
readonly name: "signature";
|
|
9
|
+
readonly type: "bytes";
|
|
10
|
+
}];
|
|
11
|
+
readonly name: "extendTime";
|
|
12
|
+
readonly outputs: readonly [];
|
|
13
|
+
readonly stateMutability: "nonpayable";
|
|
14
|
+
readonly type: "function";
|
|
15
|
+
}];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const OracleAbi = [
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "uint256",
|
|
6
|
+
"name": "newEndTime",
|
|
7
|
+
"type": "uint256"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"internalType": "bytes",
|
|
11
|
+
"name": "signature",
|
|
12
|
+
"type": "bytes"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"name": "extendTime",
|
|
16
|
+
"outputs": [],
|
|
17
|
+
"stateMutability": "nonpayable",
|
|
18
|
+
"type": "function"
|
|
19
|
+
}
|
|
20
|
+
];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { Contract, JsonRpcProvider } from "ethers";
|
|
3
|
+
import { OracleAbi } from "../../abi/OracleAbi.js";
|
|
4
|
+
import { TradePoolAbi } from "../../abi/TradeMarketsAbi.js";
|
|
5
|
+
async function getOracleAddress(marketContractAddress, rpcUrl) {
|
|
6
|
+
const provider = new JsonRpcProvider(rpcUrl);
|
|
7
|
+
const contract = new Contract(marketContractAddress, TradePoolAbi, provider);
|
|
8
|
+
const resolver = await contract.resolver();
|
|
9
|
+
return resolver;
|
|
10
|
+
}
|
|
11
|
+
async function fetchExtendTimeSignature(oracleContractAddress, walletAddress, accessToken, apiUrl) {
|
|
12
|
+
const res = await fetch(`${apiUrl}/pools/sign-oracles-extend-time?contractAddress=${oracleContractAddress}&walletAddress=${walletAddress}`, { headers: { Authorization: `Bearer ${accessToken}` } });
|
|
13
|
+
if (!res.ok)
|
|
14
|
+
throw new Error(`Failed to fetch extend time signature: ${res.status}`);
|
|
15
|
+
const json = await res.json();
|
|
16
|
+
const data = json?.data ?? json;
|
|
17
|
+
if (!data?.epoch || !data?.signature)
|
|
18
|
+
throw new Error("Invalid response from extend time signature endpoint");
|
|
19
|
+
return {
|
|
20
|
+
epoch: BigInt(data.epoch),
|
|
21
|
+
signature: data.signature,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export async function buildExtendTimeRawTx(params) {
|
|
25
|
+
const { marketContractAddress, walletAddress, accessToken, apiUrl, rpcUrl } = params;
|
|
26
|
+
if (!apiUrl)
|
|
27
|
+
throw new Error("Environment is not set properly, api url is missing");
|
|
28
|
+
if (!rpcUrl)
|
|
29
|
+
throw new Error("rpcUrl is required");
|
|
30
|
+
if (!marketContractAddress)
|
|
31
|
+
throw new Error("marketContractAddress is required");
|
|
32
|
+
if (!walletAddress)
|
|
33
|
+
throw new Error("walletAddress is required");
|
|
34
|
+
if (!accessToken)
|
|
35
|
+
throw new Error("accessToken is required");
|
|
36
|
+
const oracleContractAddress = await getOracleAddress(marketContractAddress, rpcUrl);
|
|
37
|
+
const { epoch, signature } = await fetchExtendTimeSignature(oracleContractAddress, walletAddress, accessToken, apiUrl);
|
|
38
|
+
return {
|
|
39
|
+
to: oracleContractAddress,
|
|
40
|
+
data: encodeFunctionData({
|
|
41
|
+
abi: OracleAbi,
|
|
42
|
+
functionName: "extendTime",
|
|
43
|
+
args: [epoch, signature],
|
|
44
|
+
}),
|
|
45
|
+
value: 0n,
|
|
46
|
+
};
|
|
47
|
+
}
|
package/dist/tx/types.d.ts
CHANGED
|
@@ -99,6 +99,13 @@ export interface CancelAllOpenOrdersTxParams {
|
|
|
99
99
|
accessToken: string;
|
|
100
100
|
apiUrl?: string;
|
|
101
101
|
}
|
|
102
|
+
export interface ExtendTimeTxParams {
|
|
103
|
+
marketContractAddress: `0x${string}`;
|
|
104
|
+
walletAddress: `0x${string}`;
|
|
105
|
+
accessToken: string;
|
|
106
|
+
apiUrl?: string;
|
|
107
|
+
rpcUrl?: string;
|
|
108
|
+
}
|
|
102
109
|
export interface GetUserOptionSharesParams {
|
|
103
110
|
options: [{
|
|
104
111
|
choiceIndex: number;
|