@msafe/sui3-sdk 0.0.45 → 0.0.46

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msafe/sui3-sdk",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "description": "SDK for MSafe SUI V3",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -21,13 +21,16 @@
21
21
  "author": "MSafe <admin@m-safe.io>",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@msafe/sui-wallet": "^0.0.41",
24
+ "@msafe/sui-wallet": "^0.0.41-pre-e5d4812.0",
25
+ "@msafe/sui3-utils": "^3.1.55-pre-1d77150.0",
25
26
  "axios": "^1.6.6",
26
- "buffer": "^6.0.3"
27
+ "buffer": "^6.0.3",
28
+ "json-bigint": "^1.0.0"
27
29
  },
28
30
  "devDependencies": {
29
31
  "@mysten/sui.js": "^0.50.1",
30
32
  "@types/jest": "^29.5.8",
33
+ "@types/json-bigint": "^1.0.4",
31
34
  "@types/node": "^20.9.2",
32
35
  "@typescript-eslint/eslint-plugin": "^6.5.0",
33
36
  "@typescript-eslint/parser": "^6.5.0",
@@ -39,7 +39,8 @@ import {
39
39
  IGetDashboardResp,
40
40
  } from '@msafe/sui3-utils';
41
41
  import { SerializedSignature, PublicKey } from '@mysten/sui.js/cryptography';
42
- import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
42
+ import axios, { AxiosError, AxiosRequestConfig, AxiosRequestTransformer, AxiosResponse } from 'axios';
43
+ import * as JSONBig from 'json-bigint';
43
44
 
44
45
  import { IBackend } from '@/backend/interface';
45
46
  import { addPrefix } from '@/utils';
@@ -292,33 +293,49 @@ export class BackendImpl implements IBackend {
292
293
  };
293
294
  }
294
295
 
295
- private async get<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<T, D>> {
296
+ private async get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {
296
297
  const fullUrl = this.getFullUrl(url);
297
- const response = await axios.get<T, AxiosResponse<T, D>, D>(fullUrl, config);
298
- if (axios.isAxiosError(response)) {
299
- const error = BackendError.fromError(response);
300
- throw error ?? new Error(response.statusText);
298
+ try {
299
+ return await axios.get<T, R, D>(fullUrl, config);
300
+ } catch (e) {
301
+ throw BackendError.fromError(e) ?? e;
301
302
  }
302
- return response;
303
303
  }
304
304
 
305
- private async post<T = any, D = any>(
305
+ private async post<T = any, R = AxiosResponse<T>, D = any>(
306
306
  url: string,
307
307
  data?: D,
308
308
  config?: AxiosRequestConfig<D>,
309
- ): Promise<AxiosResponse<T, D>> {
309
+ ): Promise<R> {
310
310
  const fullUrl = this.getFullUrl(url);
311
- const response = await axios.post<T, AxiosResponse<T, D>, D>(fullUrl, data, config);
312
- if (axios.isAxiosError(response)) {
313
- const error = BackendError.fromError(response);
314
- throw error ?? new Error(response.statusText);
311
+ try {
312
+ return await axios.post<T, R, D>(fullUrl, data, {
313
+ ...config,
314
+ transformRequest: this.getTransformRequest(),
315
+ });
316
+ } catch (e) {
317
+ throw BackendError.fromError(e) ?? e;
315
318
  }
316
- return response;
317
319
  }
318
320
 
319
321
  private getFullUrl(url: string) {
320
322
  return url.startsWith(this.apiURL) ? url : `${this.apiURL}${addPrefix(url, '/')}`;
321
323
  }
324
+
325
+ private getTransformRequest() {
326
+ let transformRequests: AxiosRequestTransformer[] = [];
327
+ const { transformRequest } = axios.defaults;
328
+
329
+ if (!transformRequest) {
330
+ transformRequests = [];
331
+ } else if (transformRequest instanceof Array) {
332
+ transformRequests = transformRequest;
333
+ } else {
334
+ transformRequests = [transformRequest];
335
+ }
336
+
337
+ return [(d: any) => JSONBig.parse(JSONBig.stringify(d)), ...transformRequests];
338
+ }
322
339
  }
323
340
 
324
341
  export class BackendError extends Error {
@@ -19,7 +19,7 @@ import {
19
19
  import { SuiObjectData, SuiObjectResponse } from '@mysten/sui.js/client';
20
20
  import { SerializedSignature } from '@mysten/sui.js/cryptography';
21
21
  import { TransactionBlock } from '@mysten/sui.js/transactions';
22
- import { normalizeStructTag } from '@mysten/sui.js/utils';
22
+ import { normalizeStructTag, toHEX } from '@mysten/sui.js/utils';
23
23
 
24
24
  import { MSafeGlobals } from '@/globals/MSafeGlobals';
25
25
  import { Simulator } from '@/simulate/simulator';
@@ -137,7 +137,7 @@ export class MSafeAccount {
137
137
  throw new Error(`Can't find app helper for application ${request.application}`);
138
138
  }
139
139
  const txb = await appHelper.build({
140
- network: 'sui:testnet',
140
+ network: this.globals.config.network,
141
141
  intentionData: request.intention,
142
142
  txType: request.txType,
143
143
  txSubType: request.txSubType,
@@ -167,19 +167,35 @@ export class MSafeAccount {
167
167
  }
168
168
 
169
169
  async proposeIntentionAndBuildVote(
170
- input: Omit<IProposeIntentionAndBuildAndVoteRequest, 'signature' | 'msafeAddress'>,
170
+ input: Omit<IProposeIntentionAndBuildAndVoteRequest, 'signature' | 'msafeAddress' | 'payload' | 'digest'>,
171
171
  ): Promise<void> {
172
- const message = SigningMessageHelper.proposeIntentionMessage({
173
- msafeAddress: this.address,
174
- intention: input.intention,
175
- sn: input.sequenceNumber,
176
- });
177
- const signature = await this.wallet.signPersonalMessage({
178
- messageStr: message,
172
+ const appHelper = appHelpers.getAppHelper(input.application);
173
+ if (!appHelper) {
174
+ throw new Error(`Can't find app helper for application ${input.application}`);
175
+ }
176
+
177
+ const txb = await appHelper.build({
178
+ network: this.globals.config.network,
179
+ intentionData: input.intention,
180
+ txType: input.txType,
181
+ txSubType: input.txSubType,
182
+ suiClient: this.globals.suiClient,
183
+ account: {
184
+ address: this.address,
185
+ },
179
186
  });
187
+ txb.setGasPrice(input.gasPrice);
188
+ txb.setGasBudget(input.gasBudget);
189
+ txb.setSender(this.address);
190
+ const payload = await txb.build({ client: this.globals.suiClient });
191
+ const digest = await txb.getDigest({ client: this.globals.suiClient });
192
+
193
+ const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
180
194
 
181
195
  return this.backend.proposeIntentionAndBuildVote({
182
196
  ...input,
197
+ payload: toHEX(payload),
198
+ digest,
183
199
  msafeAddress: this.address,
184
200
  signature: signature.signature,
185
201
  });
@@ -318,13 +334,12 @@ export class MSafeAccount {
318
334
 
319
335
  async simulateBuildTransaction(): Promise<SimulationResult> {
320
336
  const intention = await this.backend.getNextIntention({ msafeAddress: this.address });
321
- console.log('🚀 ~ MSafeAccount ~ simulateBuildTransaction ~ appHelper:', appHelpers.apps);
322
337
  const appHelper = appHelpers.getAppHelper(intention.application);
323
338
  if (!appHelper) {
324
339
  throw new Error(`Can't find app helper for application ${intention.application}`);
325
340
  }
326
341
  const txb = await appHelper.build({
327
- network: 'sui:testnet',
342
+ network: this.globals.config.network,
328
343
  intentionData: intention.intention,
329
344
  txType: intention.txType as TransactionType,
330
345
  txSubType: intention.txSubType,
@@ -14,6 +14,7 @@ export interface MSafeConfig {
14
14
  url: string;
15
15
  };
16
16
  syncingURL: string;
17
+ network: 'sui:mainnet' | 'sui:testnet';
17
18
  }
18
19
 
19
20
  export interface MSafeConfigOptions {
@@ -25,8 +26,9 @@ export interface MSafeConfigOptions {
25
26
  };
26
27
  }
27
28
 
28
- export const TESTNET_RPC_URL = 'https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD';
29
- export const MAINNET_RPC_URL = 'https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7';
29
+ // export const TESTNET_RPC_URL = 'https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD';
30
+ export const TESTNET_RPC_URL = 'https://fullnode.testnet.sui.io';
31
+ export const MAINNET_RPC_URL = 'https://fullnode.mainnet.sui.io';
30
32
 
31
33
  export const LOCAL_API_URL = 'http://127.0.0.1:3000';
32
34
  export const LOCAL_SYNCING_URL = 'http://127.0.0.1:3001';
@@ -49,6 +51,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
49
51
  url: LOCAL_API_URL,
50
52
  },
51
53
  syncingURL: LOCAL_SYNCING_URL,
54
+ network: 'sui:testnet',
52
55
  },
53
56
  ],
54
57
  [
@@ -61,6 +64,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
61
64
  url: LOCAL_API_URL,
62
65
  },
63
66
  syncingURL: LOCAL_SYNCING_URL,
67
+ network: 'sui:testnet',
64
68
  },
65
69
  ],
66
70
  [
@@ -73,6 +77,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
73
77
  url: DEV_API_URL,
74
78
  },
75
79
  syncingURL: DEV_SYNCING_URL,
80
+ network: 'sui:testnet',
76
81
  },
77
82
  ],
78
83
  [
@@ -85,6 +90,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
85
90
  url: PREV_API_URL,
86
91
  },
87
92
  syncingURL: '',
93
+ network: 'sui:mainnet',
88
94
  },
89
95
  ],
90
96
  [
@@ -97,6 +103,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
97
103
  url: PROD_API_URL,
98
104
  },
99
105
  syncingURL: '',
106
+ network: 'sui:mainnet',
100
107
  },
101
108
  ],
102
109
  ]);