riskmarket-sdk 1.0.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.

Potentially problematic release.


This version of riskmarket-sdk might be problematic. Click here for more details.

@@ -0,0 +1,160 @@
1
+ /**
2
+ * Example Contract ABI
3
+ * Replace this with your actual contract ABI
4
+ */
5
+ export declare const ExampleContractABI: readonly [{
6
+ readonly inputs: readonly [{
7
+ readonly internalType: "address";
8
+ readonly name: "tokenIn";
9
+ readonly type: "address";
10
+ }, {
11
+ readonly internalType: "address";
12
+ readonly name: "tokenOut";
13
+ readonly type: "address";
14
+ }, {
15
+ readonly internalType: "uint256";
16
+ readonly name: "amountIn";
17
+ readonly type: "uint256";
18
+ }, {
19
+ readonly internalType: "uint256";
20
+ readonly name: "minAmountOut";
21
+ readonly type: "uint256";
22
+ }, {
23
+ readonly internalType: "address";
24
+ readonly name: "recipient";
25
+ readonly type: "address";
26
+ }, {
27
+ readonly internalType: "uint256";
28
+ readonly name: "deadline";
29
+ readonly type: "uint256";
30
+ }];
31
+ readonly name: "swap";
32
+ readonly outputs: readonly [{
33
+ readonly internalType: "uint256";
34
+ readonly name: "amountOut";
35
+ readonly type: "uint256";
36
+ }];
37
+ readonly stateMutability: "nonpayable";
38
+ readonly type: "function";
39
+ }, {
40
+ readonly inputs: readonly [{
41
+ readonly internalType: "address";
42
+ readonly name: "token";
43
+ readonly type: "address";
44
+ }, {
45
+ readonly internalType: "uint256";
46
+ readonly name: "amount";
47
+ readonly type: "uint256";
48
+ }, {
49
+ readonly internalType: "address";
50
+ readonly name: "recipient";
51
+ readonly type: "address";
52
+ }];
53
+ readonly name: "deposit";
54
+ readonly outputs: readonly [];
55
+ readonly stateMutability: "nonpayable";
56
+ readonly type: "function";
57
+ }, {
58
+ readonly inputs: readonly [{
59
+ readonly internalType: "address";
60
+ readonly name: "token";
61
+ readonly type: "address";
62
+ }, {
63
+ readonly internalType: "uint256";
64
+ readonly name: "amount";
65
+ readonly type: "uint256";
66
+ }];
67
+ readonly name: "withdraw";
68
+ readonly outputs: readonly [];
69
+ readonly stateMutability: "nonpayable";
70
+ readonly type: "function";
71
+ }, {
72
+ readonly inputs: readonly [{
73
+ readonly internalType: "address";
74
+ readonly name: "user";
75
+ readonly type: "address";
76
+ }, {
77
+ readonly internalType: "address";
78
+ readonly name: "token";
79
+ readonly type: "address";
80
+ }];
81
+ readonly name: "getUserBalance";
82
+ readonly outputs: readonly [{
83
+ readonly internalType: "uint256";
84
+ readonly name: "balance";
85
+ readonly type: "uint256";
86
+ }];
87
+ readonly stateMutability: "view";
88
+ readonly type: "function";
89
+ }, {
90
+ readonly anonymous: false;
91
+ readonly inputs: readonly [{
92
+ readonly indexed: true;
93
+ readonly internalType: "address";
94
+ readonly name: "user";
95
+ readonly type: "address";
96
+ }, {
97
+ readonly indexed: false;
98
+ readonly internalType: "address";
99
+ readonly name: "tokenIn";
100
+ readonly type: "address";
101
+ }, {
102
+ readonly indexed: false;
103
+ readonly internalType: "address";
104
+ readonly name: "tokenOut";
105
+ readonly type: "address";
106
+ }, {
107
+ readonly indexed: false;
108
+ readonly internalType: "uint256";
109
+ readonly name: "amountIn";
110
+ readonly type: "uint256";
111
+ }, {
112
+ readonly indexed: false;
113
+ readonly internalType: "uint256";
114
+ readonly name: "amountOut";
115
+ readonly type: "uint256";
116
+ }];
117
+ readonly name: "Swap";
118
+ readonly type: "event";
119
+ }, {
120
+ readonly anonymous: false;
121
+ readonly inputs: readonly [{
122
+ readonly indexed: true;
123
+ readonly internalType: "address";
124
+ readonly name: "user";
125
+ readonly type: "address";
126
+ }, {
127
+ readonly indexed: false;
128
+ readonly internalType: "address";
129
+ readonly name: "token";
130
+ readonly type: "address";
131
+ }, {
132
+ readonly indexed: false;
133
+ readonly internalType: "uint256";
134
+ readonly name: "amount";
135
+ readonly type: "uint256";
136
+ }];
137
+ readonly name: "Deposit";
138
+ readonly type: "event";
139
+ }, {
140
+ readonly anonymous: false;
141
+ readonly inputs: readonly [{
142
+ readonly indexed: true;
143
+ readonly internalType: "address";
144
+ readonly name: "user";
145
+ readonly type: "address";
146
+ }, {
147
+ readonly indexed: false;
148
+ readonly internalType: "address";
149
+ readonly name: "token";
150
+ readonly type: "address";
151
+ }, {
152
+ readonly indexed: false;
153
+ readonly internalType: "uint256";
154
+ readonly name: "amount";
155
+ readonly type: "uint256";
156
+ }];
157
+ readonly name: "Withdraw";
158
+ readonly type: "event";
159
+ }];
160
+ //# sourceMappingURL=ExampleABI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExampleABI.d.ts","sourceRoot":"","sources":["../../src/abi/ExampleABI.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6FrB,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Example Contract ABI
3
+ * Replace this with your actual contract ABI
4
+ */
5
+ export const ExampleContractABI = [
6
+ // Swap function
7
+ {
8
+ "inputs": [
9
+ { "internalType": "address", "name": "tokenIn", "type": "address" },
10
+ { "internalType": "address", "name": "tokenOut", "type": "address" },
11
+ { "internalType": "uint256", "name": "amountIn", "type": "uint256" },
12
+ { "internalType": "uint256", "name": "minAmountOut", "type": "uint256" },
13
+ { "internalType": "address", "name": "recipient", "type": "address" },
14
+ { "internalType": "uint256", "name": "deadline", "type": "uint256" }
15
+ ],
16
+ "name": "swap",
17
+ "outputs": [
18
+ { "internalType": "uint256", "name": "amountOut", "type": "uint256" }
19
+ ],
20
+ "stateMutability": "nonpayable",
21
+ "type": "function"
22
+ },
23
+ // Deposit function
24
+ {
25
+ "inputs": [
26
+ { "internalType": "address", "name": "token", "type": "address" },
27
+ { "internalType": "uint256", "name": "amount", "type": "uint256" },
28
+ { "internalType": "address", "name": "recipient", "type": "address" }
29
+ ],
30
+ "name": "deposit",
31
+ "outputs": [],
32
+ "stateMutability": "nonpayable",
33
+ "type": "function"
34
+ },
35
+ // Withdraw function
36
+ {
37
+ "inputs": [
38
+ { "internalType": "address", "name": "token", "type": "address" },
39
+ { "internalType": "uint256", "name": "amount", "type": "uint256" }
40
+ ],
41
+ "name": "withdraw",
42
+ "outputs": [],
43
+ "stateMutability": "nonpayable",
44
+ "type": "function"
45
+ },
46
+ // Get user balance function (view)
47
+ {
48
+ "inputs": [
49
+ { "internalType": "address", "name": "user", "type": "address" },
50
+ { "internalType": "address", "name": "token", "type": "address" }
51
+ ],
52
+ "name": "getUserBalance",
53
+ "outputs": [
54
+ { "internalType": "uint256", "name": "balance", "type": "uint256" }
55
+ ],
56
+ "stateMutability": "view",
57
+ "type": "function"
58
+ },
59
+ // Events
60
+ {
61
+ "anonymous": false,
62
+ "inputs": [
63
+ { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
64
+ { "indexed": false, "internalType": "address", "name": "tokenIn", "type": "address" },
65
+ { "indexed": false, "internalType": "address", "name": "tokenOut", "type": "address" },
66
+ { "indexed": false, "internalType": "uint256", "name": "amountIn", "type": "uint256" },
67
+ { "indexed": false, "internalType": "uint256", "name": "amountOut", "type": "uint256" }
68
+ ],
69
+ "name": "Swap",
70
+ "type": "event"
71
+ },
72
+ {
73
+ "anonymous": false,
74
+ "inputs": [
75
+ { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
76
+ { "indexed": false, "internalType": "address", "name": "token", "type": "address" },
77
+ { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
78
+ ],
79
+ "name": "Deposit",
80
+ "type": "event"
81
+ },
82
+ {
83
+ "anonymous": false,
84
+ "inputs": [
85
+ { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
86
+ { "indexed": false, "internalType": "address", "name": "token", "type": "address" },
87
+ { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
88
+ ],
89
+ "name": "Withdraw",
90
+ "type": "event"
91
+ }
92
+ ];
@@ -0,0 +1,106 @@
1
+ import { AxiosInstance } from "axios";
2
+ /**
3
+ * APIClient class for interacting with backend APIs
4
+ */
5
+ export declare class APIClient {
6
+ private client;
7
+ private apiKey?;
8
+ private baseURL;
9
+ /**
10
+ * Initialize API client
11
+ * @param baseURL - Base URL for API endpoints
12
+ * @param apiKey - Optional API key for authentication
13
+ */
14
+ constructor(baseURL: string, apiKey?: string);
15
+ /**
16
+ * Handle API errors
17
+ * @private
18
+ */
19
+ private handleAPIError;
20
+ /**
21
+ * Example method - Replace with your actual API calls
22
+ *
23
+ * Template for a GET request:
24
+ *
25
+ * async getYourData(id: string): Promise<YourDataType> {
26
+ * try {
27
+ * const response = await this.client.get<APIResponse<YourDataType>>(
28
+ * `/your-endpoint/${id}`
29
+ * );
30
+ *
31
+ * if (!response.data.success) {
32
+ * throw new SDKError(
33
+ * response.data.error || 'Failed to fetch data',
34
+ * ErrorType.API_ERROR
35
+ * );
36
+ * }
37
+ *
38
+ * return response.data.data;
39
+ * } catch (error) {
40
+ * if (error instanceof SDKError) throw error;
41
+ * throw new SDKError(
42
+ * `Failed to fetch data: ${error}`,
43
+ * ErrorType.API_ERROR
44
+ * );
45
+ * }
46
+ * }
47
+ *
48
+ * Template for a POST request:
49
+ *
50
+ * async createYourData(data: YourInputType): Promise<YourDataType> {
51
+ * try {
52
+ * const response = await this.client.post<APIResponse<YourDataType>>(
53
+ * '/your-endpoint',
54
+ * data
55
+ * );
56
+ *
57
+ * if (!response.data.success) {
58
+ * throw new SDKError(
59
+ * response.data.error || 'Failed to create data',
60
+ * ErrorType.API_ERROR
61
+ * );
62
+ * }
63
+ *
64
+ * return response.data.data;
65
+ * } catch (error) {
66
+ * if (error instanceof SDKError) throw error;
67
+ * throw new SDKError(
68
+ * `Failed to create data: ${error}`,
69
+ * ErrorType.API_ERROR
70
+ * );
71
+ * }
72
+ * }
73
+ */
74
+ /**
75
+ * Generic GET request
76
+ * @param endpoint - API endpoint (relative to baseURL)
77
+ * @param params - Query parameters
78
+ */
79
+ get<T>(endpoint: string, params?: Record<string, any>): Promise<T>;
80
+ /**
81
+ * Generic POST request
82
+ * @param endpoint - API endpoint (relative to baseURL)
83
+ * @param data - Request body data
84
+ */
85
+ post<T>(endpoint: string, data: any): Promise<T>;
86
+ /**
87
+ * Generic PUT request
88
+ * @param endpoint - API endpoint (relative to baseURL)
89
+ * @param data - Request body data
90
+ */
91
+ put<T>(endpoint: string, data: any): Promise<T>;
92
+ /**
93
+ * Generic DELETE request
94
+ * @param endpoint - API endpoint (relative to baseURL)
95
+ */
96
+ delete<T>(endpoint: string): Promise<T>;
97
+ /**
98
+ * Get the base URL
99
+ */
100
+ getBaseURL(): string;
101
+ /**
102
+ * Get the axios instance for advanced usage
103
+ */
104
+ getClient(): AxiosInstance;
105
+ }
106
+ //# sourceMappingURL=APIClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"APIClient.d.ts","sourceRoot":"","sources":["../../src/api/APIClient.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAc,MAAM,OAAO,CAAC;AAGzD;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IAExB;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAsB5C;;;OAGG;IACH,OAAO,CAAC,cAAc;IA0BtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IAMH;;;;OAIG;IACG,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAoBxE;;;;OAIG;IACG,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAkBtD;;;;OAIG;IACG,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAkBrD;;;OAGG;IACG,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAqB7C;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,SAAS,IAAI,aAAa;CAG3B"}
@@ -0,0 +1,201 @@
1
+ import axios from "axios";
2
+ import { SDKError, ErrorType } from "../types";
3
+ /**
4
+ * APIClient class for interacting with backend APIs
5
+ */
6
+ export class APIClient {
7
+ /**
8
+ * Initialize API client
9
+ * @param baseURL - Base URL for API endpoints
10
+ * @param apiKey - Optional API key for authentication
11
+ */
12
+ constructor(baseURL, apiKey) {
13
+ this.baseURL = baseURL;
14
+ this.apiKey = apiKey;
15
+ this.client = axios.create({
16
+ baseURL,
17
+ timeout: 30000,
18
+ headers: {
19
+ "Content-Type": "application/json",
20
+ ...(apiKey && { Authorization: `Bearer ${apiKey}` }),
21
+ },
22
+ });
23
+ // Add response interceptor for error handling
24
+ this.client.interceptors.response.use((response) => response, (error) => {
25
+ throw this.handleAPIError(error);
26
+ });
27
+ }
28
+ /**
29
+ * Handle API errors
30
+ * @private
31
+ */
32
+ handleAPIError(error) {
33
+ if (error.response) {
34
+ // Server responded with error status
35
+ const message = error.response.data?.message || error.message;
36
+ return new SDKError(`API Error: ${message}`, ErrorType.API_ERROR, {
37
+ status: error.response.status,
38
+ data: error.response.data,
39
+ });
40
+ }
41
+ else if (error.request) {
42
+ // Request was made but no response
43
+ return new SDKError("No response from server", ErrorType.NETWORK_ERROR, {
44
+ originalError: error,
45
+ });
46
+ }
47
+ else {
48
+ // Something else happened
49
+ return new SDKError(`Request failed: ${error.message}`, ErrorType.API_ERROR);
50
+ }
51
+ }
52
+ // ============================================
53
+ // ADD YOUR API METHODS HERE
54
+ // ============================================
55
+ /**
56
+ * Example method - Replace with your actual API calls
57
+ *
58
+ * Template for a GET request:
59
+ *
60
+ * async getYourData(id: string): Promise<YourDataType> {
61
+ * try {
62
+ * const response = await this.client.get<APIResponse<YourDataType>>(
63
+ * `/your-endpoint/${id}`
64
+ * );
65
+ *
66
+ * if (!response.data.success) {
67
+ * throw new SDKError(
68
+ * response.data.error || 'Failed to fetch data',
69
+ * ErrorType.API_ERROR
70
+ * );
71
+ * }
72
+ *
73
+ * return response.data.data;
74
+ * } catch (error) {
75
+ * if (error instanceof SDKError) throw error;
76
+ * throw new SDKError(
77
+ * `Failed to fetch data: ${error}`,
78
+ * ErrorType.API_ERROR
79
+ * );
80
+ * }
81
+ * }
82
+ *
83
+ * Template for a POST request:
84
+ *
85
+ * async createYourData(data: YourInputType): Promise<YourDataType> {
86
+ * try {
87
+ * const response = await this.client.post<APIResponse<YourDataType>>(
88
+ * '/your-endpoint',
89
+ * data
90
+ * );
91
+ *
92
+ * if (!response.data.success) {
93
+ * throw new SDKError(
94
+ * response.data.error || 'Failed to create data',
95
+ * ErrorType.API_ERROR
96
+ * );
97
+ * }
98
+ *
99
+ * return response.data.data;
100
+ * } catch (error) {
101
+ * if (error instanceof SDKError) throw error;
102
+ * throw new SDKError(
103
+ * `Failed to create data: ${error}`,
104
+ * ErrorType.API_ERROR
105
+ * );
106
+ * }
107
+ * }
108
+ */
109
+ // ============================================
110
+ // GENERIC REQUEST METHODS (Keep these - they're useful!)
111
+ // ============================================
112
+ /**
113
+ * Generic GET request
114
+ * @param endpoint - API endpoint (relative to baseURL)
115
+ * @param params - Query parameters
116
+ */
117
+ async get(endpoint, params) {
118
+ try {
119
+ const response = await this.client.get(endpoint, {
120
+ params,
121
+ });
122
+ if (!response.data.success) {
123
+ throw new SDKError(response.data.error || "Request failed", ErrorType.API_ERROR);
124
+ }
125
+ return response.data.data;
126
+ }
127
+ catch (error) {
128
+ if (error instanceof SDKError)
129
+ throw error;
130
+ throw new SDKError(`GET request failed: ${error}`, ErrorType.API_ERROR);
131
+ }
132
+ }
133
+ /**
134
+ * Generic POST request
135
+ * @param endpoint - API endpoint (relative to baseURL)
136
+ * @param data - Request body data
137
+ */
138
+ async post(endpoint, data) {
139
+ try {
140
+ const response = await this.client.post(endpoint, data);
141
+ if (!response.data.success) {
142
+ throw new SDKError(response.data.error || "Request failed", ErrorType.API_ERROR);
143
+ }
144
+ return response.data.data;
145
+ }
146
+ catch (error) {
147
+ if (error instanceof SDKError)
148
+ throw error;
149
+ throw new SDKError(`POST request failed: ${error}`, ErrorType.API_ERROR);
150
+ }
151
+ }
152
+ /**
153
+ * Generic PUT request
154
+ * @param endpoint - API endpoint (relative to baseURL)
155
+ * @param data - Request body data
156
+ */
157
+ async put(endpoint, data) {
158
+ try {
159
+ const response = await this.client.put(endpoint, data);
160
+ if (!response.data.success) {
161
+ throw new SDKError(response.data.error || "Request failed", ErrorType.API_ERROR);
162
+ }
163
+ return response.data.data;
164
+ }
165
+ catch (error) {
166
+ if (error instanceof SDKError)
167
+ throw error;
168
+ throw new SDKError(`PUT request failed: ${error}`, ErrorType.API_ERROR);
169
+ }
170
+ }
171
+ /**
172
+ * Generic DELETE request
173
+ * @param endpoint - API endpoint (relative to baseURL)
174
+ */
175
+ async delete(endpoint) {
176
+ try {
177
+ const response = await this.client.delete(endpoint);
178
+ if (!response.data.success) {
179
+ throw new SDKError(response.data.error || "Request failed", ErrorType.API_ERROR);
180
+ }
181
+ return response.data.data;
182
+ }
183
+ catch (error) {
184
+ if (error instanceof SDKError)
185
+ throw error;
186
+ throw new SDKError(`DELETE request failed: ${error}`, ErrorType.API_ERROR);
187
+ }
188
+ }
189
+ /**
190
+ * Get the base URL
191
+ */
192
+ getBaseURL() {
193
+ return this.baseURL;
194
+ }
195
+ /**
196
+ * Get the axios instance for advanced usage
197
+ */
198
+ getClient() {
199
+ return this.client;
200
+ }
201
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Main entry point for the Protocol SDK
3
+ * @packageDocumentation
4
+ */
5
+ export { ProtocolSDK } from './ProtocolSDK';
6
+ export { APIClient } from './api/APIClient';
7
+ export { TransactionBuilder } from './transactions/TransactionBuilder';
8
+ export { Utils } from './utils/helpers';
9
+ export type { SDKConfig, MarketData, UserBalance, Transaction, APIResponse, TransactionResponse, } from './types';
10
+ export { SDKError, ErrorType } from './types';
11
+ export { NETWORKS, API_ENDPOINTS, CONTRACT_METHODS, TOKEN_DECIMALS, GAS_LIMITS, DEFAULT_DEADLINE_MINUTES, MAX_UINT256, ZERO_ADDRESS, } from './utils/constants';
12
+ export { ProtocolSDK as default } from './ProtocolSDK';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,YAAY,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAG9C,OAAO,EACL,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,wBAAwB,EACxB,WAAW,EACX,YAAY,GACb,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC"}