@rainprotocolsdk/sdk 1.0.0 → 1.0.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 ADDED
@@ -0,0 +1,191 @@
1
+ # Rain SDK Documentation
2
+
3
+ ## Overview
4
+
5
+ Rain SDK is designed as a **clean, modular, and extensible TypeScript SDK** for interacting with Rain markets and preparing on-chain transactions.
6
+
7
+ The SDK is intentionally split into two layers:
8
+
9
+ * **Rain** → Stateless, public-facing utilities (data fetching, raw transaction builders)
10
+ * **RainAA** → Stateful Account Abstraction layer (smart accounts)
11
+
12
+ ---
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @rainprotocolsdk/sdk
18
+ ```
19
+
20
+ or
21
+
22
+ ```bash
23
+ yarn add @rainprotocolsdk/sdk
24
+ ```
25
+
26
+ ---
27
+
28
+ ### Initialization
29
+
30
+ ```ts
31
+ import { Rain } from "@rainprotocolsdk/sdk";
32
+
33
+ const rain = new Rain();
34
+ ```
35
+
36
+ > The constructor is intentionally empty to allow future configuration without breaking changes.
37
+
38
+ ---
39
+
40
+ ## getPublicMarkets
41
+
42
+ Fetches public market data from the Rain backend.
43
+
44
+ ### Method Signature
45
+
46
+ ```ts
47
+ getPublicMarkets(params: GetMarketsParams): Promise<Market[]>;
48
+ ```
49
+
50
+ ### Parameters
51
+
52
+ ```ts
53
+ interface GetMarketsParams {
54
+ limit: number;
55
+ offset: number;
56
+ sortBy?: "totalVolume" | "createdAt" | "liquidity";
57
+ status?: "Live" | "Resolved" | "Closed";
58
+ }
59
+ ```
60
+
61
+ ### Example
62
+
63
+ ```ts
64
+ const markets = await rain.getPublicMarkets({
65
+ limit?: 12,
66
+ offset?: 1,
67
+ sortBy?: "totalVolume",
68
+ status?: "Live",
69
+ });
70
+ ```
71
+
72
+ ---
73
+
74
+ ## buildBuyOptionRawTx
75
+
76
+ Builds a **raw EVM transaction** for entering a market option.
77
+
78
+ This function **does not send the transaction** — it only prepares calldata.
79
+
80
+ ### Method Signature
81
+
82
+ ```ts
83
+ buildBuyOptionRawTx(params: EnterOptionTxParams): RawTransaction;
84
+ ```
85
+
86
+ ### Parameters
87
+
88
+ ```ts
89
+ interface EnterOptionTxParams {
90
+ address: `0x${string}`; // Trademarket contract address
91
+ selectedOption: number; // Option index
92
+ buyInWei: bigint; // Amount in wei
93
+ }
94
+ ```
95
+
96
+ ### Return Type
97
+
98
+ ```ts
99
+ interface RawTransaction {
100
+ to: `0x${string}`;
101
+ data: `0x${string}`;
102
+ }
103
+ ```
104
+
105
+ ### Example
106
+
107
+ ```ts
108
+ const rawTx = rain.buildBuyOptionRawTx({
109
+ address: `0x${string}`,
110
+ selectedOption: 1,
111
+ buyInWei: 1000000000000000000n,
112
+ });
113
+ ```
114
+ ---
115
+
116
+ ## buildApprovalTx
117
+
118
+ ```
119
+ Builds a raw ERC20 approval transaction if needed.
120
+
121
+ This function prepares an unsigned approve(spender, amount) transaction and does not execute it.
122
+
123
+ If amount is not provided, a default large allowance is approved.
124
+ ```
125
+
126
+ ### Return Type
127
+
128
+ ```ts
129
+ interface RawTransaction {
130
+ to: `0x${string}`;
131
+ data: `0x${string}`;
132
+ }
133
+ ```
134
+
135
+ ### Example
136
+
137
+ ```ts
138
+ const approvalTx = rain.buildApprovalTx({
139
+ tokenAddress: `0x${string}`, // Approval token address
140
+ spender: `0x${string}`, // Market contract address
141
+ amount?: 1000000000000000000n // optional parameter
142
+ });
143
+ ```
144
+
145
+ ---
146
+
147
+ ## RainAA Class (Account Abstraction)
148
+
149
+ `RainAA` is responsible for:
150
+
151
+ * Smart account creation
152
+ * Session management (coming soon)
153
+ * Gas-sponsored execution (coming soon)
154
+ * Transaction submission (coming soon)
155
+
156
+ > `RainAA` consumes raw transactions generated by `Rain`.
157
+
158
+ ### Conceptual Flow
159
+
160
+ ```ts
161
+ Rain (WHAT to do)
162
+
163
+ Raw Transaction
164
+
165
+ RainAA (HOW to execute)
166
+ ```
167
+
168
+ ## Versioning Policy
169
+
170
+ Rain SDK follows **Semantic Versioning**:
171
+
172
+ * **Patch** (`1.0.x`) → Bug fixes
173
+ * **Minor** (`1.x.0`) → New features, backward compatible
174
+ * **Major** (`x.0.0`) → Breaking API changes
175
+
176
+ ---
177
+
178
+ ## Recommended Usage Pattern
179
+
180
+ ```ts
181
+ // 1. Read data / build tx
182
+ const rain = new Rain();
183
+ const rawTx = rain.buildBuyOptionRawTx(...);
184
+
185
+ // 2. Execute via your provider
186
+ await yourprovider.sendTransaction(rawTx);
187
+ ```
188
+
189
+ ---
190
+
191
+ **Rain SDK** is built to scale with both products and protocols.
package/dist/Rain.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { GetMarketsParams, Market } from './markets/types';
2
- import { EnterOptionTxParams, RawTransaction } from './tx/types';
2
+ import { ApproveTxParams, EnterOptionTxParams, RawTransaction } from './tx/types';
3
3
  export declare class Rain {
4
4
  getPublicMarkets(params: GetMarketsParams): Promise<Market[]>;
5
+ buildApprovalTx(params: ApproveTxParams): RawTransaction | Error;
5
6
  buildBuyOptionRawTx(params: EnterOptionTxParams): RawTransaction;
6
7
  }
package/dist/Rain.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { getMarkets } from './markets/getMarkets';
2
2
  import { buildEnterOptionRawTx } from './tx/buildRawTransactions';
3
+ import { buildApproveRawTx } from './tx/buildApprovalRawTx';
3
4
  export class Rain {
4
5
  async getPublicMarkets(params) {
5
6
  return getMarkets(params);
6
7
  }
8
+ buildApprovalTx(params) {
9
+ return buildApproveRawTx(params);
10
+ }
7
11
  buildBuyOptionRawTx(params) {
8
12
  return buildEnterOptionRawTx(params);
9
13
  }
@@ -1,5 +1,5 @@
1
1
  import { RainConfig } from './types';
2
- export declare class Rain {
2
+ export declare class RainAA {
3
3
  private config;
4
4
  private _client;
5
5
  private _address;
@@ -2,7 +2,7 @@ import { custom, createWalletClient } from 'viem';
2
2
  import { WalletClientSigner } from '@alchemy/aa-core';
3
3
  import { alchemy } from "@account-kit/infra";
4
4
  import { createSmartWalletClient } from "@account-kit/wallet-client";
5
- export class Rain {
5
+ export class RainAA {
6
6
  config;
7
7
  _client = null;
8
8
  _address = null;
@@ -15,7 +15,6 @@ export class Rain {
15
15
  throw new Error('paymasterPolicyId is required');
16
16
  if (!config.chain)
17
17
  throw new Error('chain is required');
18
- console.log('Rain SDK initialized with config:', config);
19
18
  this.config = config;
20
19
  }
21
20
  /**