@msafe/sui3-sdk 0.0.45 → 0.0.47-pre-8de330c.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/dist/index.cjs +1 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/backend/BackendImpl.ts +34 -14
- package/src/core/MSafeAccount.ts +27 -12
- package/src/globals/const.ts +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@msafe/sui3-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47-pre-8de330c.0",
|
|
4
4
|
"description": "SDK for MSafe SUI V3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@msafe/sui-wallet": "^0.0.41",
|
|
25
|
+
"@msafe/sui3-utils": "^3.1.55",
|
|
25
26
|
"axios": "^1.6.6",
|
|
26
27
|
"buffer": "^6.0.3"
|
|
27
28
|
},
|
|
@@ -39,7 +39,7 @@ 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
43
|
|
|
44
44
|
import { IBackend } from '@/backend/interface';
|
|
45
45
|
import { addPrefix } from '@/utils';
|
|
@@ -292,33 +292,53 @@ export class BackendImpl implements IBackend {
|
|
|
292
292
|
};
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
private async get<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<
|
|
295
|
+
private async get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {
|
|
296
296
|
const fullUrl = this.getFullUrl(url);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
throw
|
|
297
|
+
try {
|
|
298
|
+
return await axios.get<T, R, D>(fullUrl, config);
|
|
299
|
+
} catch (e) {
|
|
300
|
+
throw BackendError.fromError(e) ?? e;
|
|
301
301
|
}
|
|
302
|
-
return response;
|
|
303
302
|
}
|
|
304
303
|
|
|
305
|
-
private async post<T = any, D = any>(
|
|
304
|
+
private async post<T = any, R = AxiosResponse<T>, D = any>(
|
|
306
305
|
url: string,
|
|
307
306
|
data?: D,
|
|
308
307
|
config?: AxiosRequestConfig<D>,
|
|
309
|
-
): Promise<
|
|
308
|
+
): Promise<R> {
|
|
310
309
|
const fullUrl = this.getFullUrl(url);
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
310
|
+
try {
|
|
311
|
+
return await axios.post<T, R, D>(fullUrl, data, {
|
|
312
|
+
...config,
|
|
313
|
+
transformRequest: this.getTransformRequest(),
|
|
314
|
+
});
|
|
315
|
+
} catch (e) {
|
|
316
|
+
throw BackendError.fromError(e) ?? e;
|
|
315
317
|
}
|
|
316
|
-
return response;
|
|
317
318
|
}
|
|
318
319
|
|
|
319
320
|
private getFullUrl(url: string) {
|
|
320
321
|
return url.startsWith(this.apiURL) ? url : `${this.apiURL}${addPrefix(url, '/')}`;
|
|
321
322
|
}
|
|
323
|
+
|
|
324
|
+
private getTransformRequest() {
|
|
325
|
+
let transformRequests: AxiosRequestTransformer[] = [];
|
|
326
|
+
const { transformRequest } = axios.defaults;
|
|
327
|
+
|
|
328
|
+
if (!transformRequest) {
|
|
329
|
+
transformRequests = [];
|
|
330
|
+
} else if (transformRequest instanceof Array) {
|
|
331
|
+
transformRequests = transformRequest;
|
|
332
|
+
} else {
|
|
333
|
+
transformRequests = [transformRequest];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return [
|
|
337
|
+
(d: any) =>
|
|
338
|
+
JSON.parse(JSON.stringify(d, (_, value) => (typeof value === 'bigint' ? `${value.toString()}n` : value))),
|
|
339
|
+
...transformRequests,
|
|
340
|
+
];
|
|
341
|
+
}
|
|
322
342
|
}
|
|
323
343
|
|
|
324
344
|
export class BackendError extends Error {
|
package/src/core/MSafeAccount.ts
CHANGED
|
@@ -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:
|
|
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
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
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:
|
|
342
|
+
network: this.globals.config.network,
|
|
328
343
|
intentionData: intention.intention,
|
|
329
344
|
txType: intention.txType as TransactionType,
|
|
330
345
|
txSubType: intention.txSubType,
|
package/src/globals/const.ts
CHANGED
|
@@ -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
|
|
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
|
]);
|