@msafe/sui3-sdk 0.0.44 → 0.0.45-pre-14ca25c.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msafe/sui3-sdk",
3
- "version": "0.0.44",
3
+ "version": "0.0.45-pre-14ca25c.0",
4
4
  "description": "SDK for MSafe SUI V3",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -22,12 +22,15 @@
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
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';
@@ -133,11 +133,12 @@ export class MSafeAccount {
133
133
 
134
134
  async simulateIntention(request: Omit<IProposeIntentionRequest, 'msafeAddress' | 'signature'>) {
135
135
  const appHelper = appHelpers.getAppHelper(request.application);
136
+ console.log('🚀 ~ MSafeAccount ~ simulateIntention ~ appHelper:', appHelper);
136
137
  if (!appHelper) {
137
138
  throw new Error(`Can't find app helper for application ${request.application}`);
138
139
  }
139
140
  const txb = await appHelper.build({
140
- network: 'sui:testnet',
141
+ network: this.globals.config.network,
141
142
  intentionData: request.intention,
142
143
  txType: request.txType,
143
144
  txSubType: request.txSubType,
@@ -167,19 +168,35 @@ export class MSafeAccount {
167
168
  }
168
169
 
169
170
  async proposeIntentionAndBuildVote(
170
- input: Omit<IProposeIntentionAndBuildAndVoteRequest, 'signature' | 'msafeAddress'>,
171
+ input: Omit<IProposeIntentionAndBuildAndVoteRequest, 'signature' | 'msafeAddress' | 'payload' | 'digest'>,
171
172
  ): 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,
173
+ const appHelper = appHelpers.getAppHelper(input.application);
174
+ if (!appHelper) {
175
+ throw new Error(`Can't find app helper for application ${input.application}`);
176
+ }
177
+
178
+ const txb = await appHelper.build({
179
+ network: this.globals.config.network,
180
+ intentionData: input.intention,
181
+ txType: input.txType,
182
+ txSubType: input.txSubType,
183
+ suiClient: this.globals.suiClient,
184
+ account: {
185
+ address: this.address,
186
+ },
179
187
  });
188
+ txb.setGasPrice(input.gasPrice);
189
+ txb.setGasBudget(input.gasBudget);
190
+ txb.setSender(this.address);
191
+ const payload = await txb.build({ client: this.globals.suiClient });
192
+ const digest = await txb.getDigest({ client: this.globals.suiClient });
193
+
194
+ const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
180
195
 
181
196
  return this.backend.proposeIntentionAndBuildVote({
182
197
  ...input,
198
+ payload: toHEX(payload),
199
+ digest,
183
200
  msafeAddress: this.address,
184
201
  signature: signature.signature,
185
202
  });
@@ -318,13 +335,12 @@ export class MSafeAccount {
318
335
 
319
336
  async simulateBuildTransaction(): Promise<SimulationResult> {
320
337
  const intention = await this.backend.getNextIntention({ msafeAddress: this.address });
321
- console.log('🚀 ~ MSafeAccount ~ simulateBuildTransaction ~ appHelper:', appHelpers.apps);
322
338
  const appHelper = appHelpers.getAppHelper(intention.application);
323
339
  if (!appHelper) {
324
340
  throw new Error(`Can't find app helper for application ${intention.application}`);
325
341
  }
326
342
  const txb = await appHelper.build({
327
- network: 'sui:testnet',
343
+ network: this.globals.config.network,
328
344
  intentionData: intention.intention,
329
345
  txType: intention.txType as TransactionType,
330
346
  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
  ]);