@layerzerolabs/common-suimove 0.2.6 → 0.2.8
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/.turbo/turbo-build.log +61 -49
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +1 -1
- package/dist/FYKWCR42.cjs +288 -0
- package/dist/FYKWCR42.cjs.map +1 -0
- package/dist/OM6KLLNA.cjs +29 -0
- package/dist/OM6KLLNA.cjs.map +1 -0
- package/dist/POB5KB3F.js +273 -0
- package/dist/POB5KB3F.js.map +1 -0
- package/dist/{OQ5C7BFY.js → VABOX5FT.js} +4 -5
- package/dist/VABOX5FT.js.map +1 -0
- package/dist/VUOMXK5T.js +6 -0
- package/dist/VUOMXK5T.js.map +1 -0
- package/dist/X6DCT36B.js +25 -0
- package/dist/X6DCT36B.js.map +1 -0
- package/dist/YJF4D23A.cjs +8 -0
- package/dist/YJF4D23A.cjs.map +1 -0
- package/dist/{AHFVRB2R.cjs → ZW4CIJT7.cjs} +5 -7
- package/dist/ZW4CIJT7.cjs.map +1 -0
- package/dist/error.cjs +4 -3
- package/dist/error.js +2 -1
- package/dist/index.cjs +60 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/multiSigTransaction.cjs +21 -0
- package/dist/multiSigTransaction.cjs.map +1 -0
- package/dist/multiSigTransaction.d.ts +87 -0
- package/dist/multiSigTransaction.d.ts.map +1 -0
- package/dist/multiSigTransaction.js +4 -0
- package/dist/multiSigTransaction.js.map +1 -0
- package/dist/provider.d.ts +8 -4
- package/dist/provider.d.ts.map +1 -1
- package/dist/transaction.d.ts +49 -8
- package/dist/transaction.d.ts.map +1 -1
- package/dist/types.d.ts +18 -14
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.cjs +47 -6
- package/dist/utils.d.ts +73 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -2
- package/package.json +8 -5
- package/src/index.ts +1 -0
- package/src/multiSigTransaction.ts +39 -0
- package/src/provider.ts +29 -1
- package/src/transaction.ts +61 -9
- package/src/types.ts +57 -14
- package/src/utils.ts +404 -2
- package/dist/AHFVRB2R.cjs.map +0 -1
- package/dist/CHPRFEFD.js +0 -69
- package/dist/CHPRFEFD.js.map +0 -1
- package/dist/EAFPTVEK.cjs +0 -74
- package/dist/EAFPTVEK.cjs.map +0 -1
- package/dist/OQ5C7BFY.js.map +0 -1
package/src/provider.ts
CHANGED
|
@@ -5,6 +5,16 @@ import type {
|
|
|
5
5
|
SuiMoveDevInspectResult,
|
|
6
6
|
SuiMoveEvent,
|
|
7
7
|
SuiMoveEventCursor,
|
|
8
|
+
SuiMoveGetAllCoinsParams,
|
|
9
|
+
SuiMoveGetAllCoinsResponse,
|
|
10
|
+
SuiMoveGetObjectParams,
|
|
11
|
+
SuiMoveGetOwnedObjectsParams,
|
|
12
|
+
SuiMoveGetOwnedObjectsResponse,
|
|
13
|
+
SuiMoveGetTransactionBlockParams,
|
|
14
|
+
SuiMoveObjectResponse,
|
|
15
|
+
SuiMovePaginatedTransactionResponse,
|
|
16
|
+
SuiMoveQueryTransactionBlocksParams,
|
|
17
|
+
SuiMoveSystemStateSummary,
|
|
8
18
|
SuiMoveTransactionBlockResponse,
|
|
9
19
|
} from './types';
|
|
10
20
|
|
|
@@ -23,9 +33,17 @@ export interface SuiMoveProvider {
|
|
|
23
33
|
cursor?: SuiMoveEventCursor;
|
|
24
34
|
}): Promise<SuiMoveEvent[]>;
|
|
25
35
|
|
|
36
|
+
queryTransactionBlocks(
|
|
37
|
+
args: SuiMoveQueryTransactionBlocksParams,
|
|
38
|
+
): Promise<SuiMovePaginatedTransactionResponse>;
|
|
39
|
+
|
|
40
|
+
getChainIdentifier(): Promise<string>;
|
|
41
|
+
|
|
26
42
|
getCheckpoint(args: { id: string }): Promise<SuiMoveCheckpoint>;
|
|
27
43
|
|
|
28
|
-
getSuiMoveTransactionBlock(
|
|
44
|
+
getSuiMoveTransactionBlock(
|
|
45
|
+
args: SuiMoveGetTransactionBlockParams,
|
|
46
|
+
): Promise<SuiMoveTransactionBlockResponse>;
|
|
29
47
|
|
|
30
48
|
getLatestCheckpointSequenceNumber(): Promise<string>;
|
|
31
49
|
|
|
@@ -42,4 +60,14 @@ export interface SuiMoveProvider {
|
|
|
42
60
|
transactionBlock: SuiMoveTransaction;
|
|
43
61
|
sender: string;
|
|
44
62
|
}): Promise<SuiMoveDevInspectResult>;
|
|
63
|
+
|
|
64
|
+
getSuiMoveObject(args: SuiMoveGetObjectParams): Promise<SuiMoveObjectResponse>;
|
|
65
|
+
|
|
66
|
+
getAllSuiMoveCoins(args: SuiMoveGetAllCoinsParams): Promise<SuiMoveGetAllCoinsResponse>;
|
|
67
|
+
|
|
68
|
+
getSuiMoveOwnedObject(
|
|
69
|
+
args: SuiMoveGetOwnedObjectsParams,
|
|
70
|
+
): Promise<SuiMoveGetOwnedObjectsResponse>;
|
|
71
|
+
|
|
72
|
+
getSuiMoveSystemStateSummary(): Promise<SuiMoveSystemStateSummary>;
|
|
45
73
|
}
|
package/src/transaction.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
TransactionArgument as IotaTransactionArgument,
|
|
3
|
-
TransactionObjectArgument as IotaTransactionObjectArgument,
|
|
4
3
|
TransactionResult as IotaTransactionResult,
|
|
5
4
|
} from '@iota/iota-sdk/transactions';
|
|
6
5
|
import type { Transaction as IotaTransaction } from '@iota/iota-sdk/transactions';
|
|
7
6
|
import type {
|
|
8
7
|
TransactionArgument as SuiTransactionArgument,
|
|
9
|
-
TransactionObjectArgument as SuiTransactionObjectArgument,
|
|
10
8
|
TransactionResult as SuiTransactionResult,
|
|
11
9
|
} from '@mysten/sui/transactions';
|
|
12
10
|
import type { Transaction as SuiTransaction } from '@mysten/sui/transactions';
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
import type { SuiMoveProvider } from './provider';
|
|
15
13
|
|
|
16
14
|
export type SuiMoveArgument = SuiTransactionArgument | IotaTransactionArgument;
|
|
17
15
|
|
|
@@ -19,13 +17,46 @@ export type SuiMoveTransactionResult = SuiTransactionResult | IotaTransactionRes
|
|
|
19
17
|
|
|
20
18
|
export type SuiMoveClock = SuiTransaction['object']['clock'] | IotaTransaction['object']['clock'];
|
|
21
19
|
|
|
20
|
+
// Extract types from SuiTransaction.getData() return type
|
|
21
|
+
export type SuiMoveTransactionData =
|
|
22
|
+
| ReturnType<SuiTransaction['getData']>
|
|
23
|
+
| ReturnType<IotaTransaction['getData']>;
|
|
24
|
+
export type SuiMoveTransactionInput = SuiMoveTransactionData['inputs'][number];
|
|
25
|
+
|
|
26
|
+
// Extract command types - filter out the undefined case
|
|
27
|
+
export type SuiMoveCommand = SuiMoveTransactionData['commands'][number];
|
|
28
|
+
export type SuiMoveCall = Extract<SuiMoveCommand, { $kind: 'MoveCall' }>['MoveCall'];
|
|
29
|
+
export type SuiMoveCallArgument = SuiMoveCall['arguments'][number];
|
|
30
|
+
|
|
31
|
+
export type SuiMoveGas = SuiTransaction['gas'] | IotaTransaction['gas'];
|
|
32
|
+
|
|
22
33
|
export interface SuiMoveTransaction {
|
|
34
|
+
gas: SuiMoveGas;
|
|
35
|
+
|
|
23
36
|
getNew(): SuiMoveTransaction;
|
|
24
37
|
|
|
25
|
-
from(tx: SuiMoveTransaction): SuiMoveTransaction;
|
|
38
|
+
from(tx: SuiMoveTransaction | string): SuiMoveTransaction;
|
|
26
39
|
|
|
27
40
|
setSender(sender: string): void;
|
|
28
41
|
|
|
42
|
+
suiMoveObjectRef(args: {
|
|
43
|
+
objectId: string;
|
|
44
|
+
digest: string;
|
|
45
|
+
version: string | number;
|
|
46
|
+
}): SuiMoveArgument;
|
|
47
|
+
|
|
48
|
+
suiMoveSharedObjectRef(args: {
|
|
49
|
+
objectId: string;
|
|
50
|
+
initialSharedVersion: string | number;
|
|
51
|
+
mutable: boolean;
|
|
52
|
+
}): SuiMoveArgument;
|
|
53
|
+
|
|
54
|
+
suiMoveReceivingRef(args: {
|
|
55
|
+
objectId: string;
|
|
56
|
+
digest: string;
|
|
57
|
+
version: string | number;
|
|
58
|
+
}): SuiMoveArgument;
|
|
59
|
+
|
|
29
60
|
suiMoveCall(args: {
|
|
30
61
|
target: string;
|
|
31
62
|
arguments: SuiMoveArgument[];
|
|
@@ -38,20 +69,41 @@ export interface SuiMoveTransaction {
|
|
|
38
69
|
}): SuiMoveTransactionResult;
|
|
39
70
|
|
|
40
71
|
suiMoveTransferObjects(
|
|
41
|
-
objects:
|
|
72
|
+
objects: (SuiMoveArgument | string)[],
|
|
42
73
|
target: string | SuiMoveArgument,
|
|
43
74
|
): SuiMoveTransactionResult;
|
|
44
75
|
|
|
45
76
|
suiMakeMoveVec(args: {
|
|
46
|
-
type: string;
|
|
47
|
-
elements:
|
|
77
|
+
type: string | undefined;
|
|
78
|
+
elements: SuiMoveArgument[];
|
|
48
79
|
}): SuiMoveTransactionResult;
|
|
49
80
|
|
|
50
81
|
toJSON(): Promise<string>;
|
|
51
82
|
|
|
52
|
-
getData():
|
|
83
|
+
getData(): SuiMoveTransactionData;
|
|
84
|
+
|
|
85
|
+
getDigest(args: { client: SuiMoveProvider }): Promise<string>;
|
|
86
|
+
|
|
87
|
+
suiMoveSplitCoins(args: {
|
|
88
|
+
coin?: SuiMoveArgument;
|
|
89
|
+
amounts: SuiMoveArgument[];
|
|
90
|
+
}): SuiMoveTransactionResult;
|
|
91
|
+
|
|
92
|
+
upgrade(args: {
|
|
93
|
+
modules: number[][] | string[];
|
|
94
|
+
dependencies: string[];
|
|
95
|
+
package: string;
|
|
96
|
+
ticket: string | SuiMoveArgument;
|
|
97
|
+
}): SuiMoveTransactionResult;
|
|
98
|
+
|
|
99
|
+
mergeCoins(
|
|
100
|
+
destination: string | SuiMoveArgument,
|
|
101
|
+
sources: (string | SuiMoveArgument)[],
|
|
102
|
+
): SuiMoveTransactionResult;
|
|
103
|
+
|
|
104
|
+
buildSuiMove(args: { client: SuiMoveProvider }): Promise<Uint8Array>;
|
|
53
105
|
|
|
54
|
-
|
|
106
|
+
setExpiration(args: { Epoch: string }): void;
|
|
55
107
|
|
|
56
108
|
asObject(args: { objectId: string | SuiMoveArgument }): SuiMoveArgument;
|
|
57
109
|
|
package/src/types.ts
CHANGED
|
@@ -2,17 +2,37 @@ import type { bcs as iotaBcs, BcsType as IotaBcsType } from '@iota/iota-sdk/bcs'
|
|
|
2
2
|
import type {
|
|
3
3
|
DevInspectResults as IotaDevInspectResults,
|
|
4
4
|
IotaExecutionResult,
|
|
5
|
+
IotaObjectData,
|
|
6
|
+
IotaObjectResponse,
|
|
7
|
+
IotaTransactionBlockResponse,
|
|
8
|
+
LatestIotaSystemStateSummary,
|
|
9
|
+
PaginatedObjectsResponse as IotaPaginatedObjectsResponse,
|
|
10
|
+
PaginatedTransactionResponse as IotaPaginatedTransactionResponse,
|
|
11
|
+
QueryTransactionBlocksParams as IotaQueryTransactionBlocksParams,
|
|
5
12
|
} from '@iota/iota-sdk/client';
|
|
6
13
|
import type { bcs as suiBcs, BcsType as SuiBcsType } from '@mysten/sui/bcs';
|
|
7
14
|
import type {
|
|
15
|
+
Checkpoint,
|
|
8
16
|
DevInspectResults as SuiDevInspectResults,
|
|
17
|
+
GetAllCoinsParams,
|
|
18
|
+
GetObjectParams,
|
|
19
|
+
GetOwnedObjectsParams,
|
|
20
|
+
GetTransactionBlockParams,
|
|
21
|
+
PaginatedCoins,
|
|
22
|
+
PaginatedObjectsResponse as SuiPaginatedObjectsResponse,
|
|
23
|
+
PaginatedTransactionResponse as SuiPaginatedTransactionResponse,
|
|
24
|
+
QueryTransactionBlocksParams as SuiQueryTransactionBlocksParams,
|
|
9
25
|
SuiExecutionResult,
|
|
26
|
+
SuiObjectData,
|
|
27
|
+
SuiObjectResponse,
|
|
28
|
+
SuiSystemStateSummary,
|
|
29
|
+
SuiTransactionBlockResponse,
|
|
10
30
|
} from '@mysten/sui/client';
|
|
11
31
|
|
|
12
32
|
export type SuiMoveBcsType<T, U> = SuiBcsType<T, U> | IotaBcsType<T, U>;
|
|
13
33
|
|
|
14
34
|
export type SuiTypes =
|
|
15
|
-
| typeof suiBcs.
|
|
35
|
+
| typeof suiBcs.U256
|
|
16
36
|
| typeof suiBcs.U64
|
|
17
37
|
| typeof suiBcs.U32
|
|
18
38
|
| typeof suiBcs.U16
|
|
@@ -28,7 +48,7 @@ export type SuiTypes =
|
|
|
28
48
|
>;
|
|
29
49
|
|
|
30
50
|
export type IotaTypes =
|
|
31
|
-
| typeof iotaBcs.
|
|
51
|
+
| typeof iotaBcs.U256
|
|
32
52
|
| typeof iotaBcs.U64
|
|
33
53
|
| typeof iotaBcs.U32
|
|
34
54
|
| typeof iotaBcs.U16
|
|
@@ -46,7 +66,7 @@ export type IotaTypes =
|
|
|
46
66
|
export type SuiMoveTypes = SuiTypes | IotaTypes;
|
|
47
67
|
|
|
48
68
|
export interface SuiMoveBcs {
|
|
49
|
-
u256: typeof suiBcs.
|
|
69
|
+
u256: typeof suiBcs.U256 | typeof iotaBcs.U256;
|
|
50
70
|
u128: typeof suiBcs.U128 | typeof iotaBcs.U128;
|
|
51
71
|
u64: typeof suiBcs.U64 | typeof iotaBcs.U64;
|
|
52
72
|
u32: typeof suiBcs.U32 | typeof iotaBcs.U32;
|
|
@@ -83,17 +103,6 @@ export interface SuiMoveEvent {
|
|
|
83
103
|
blockDigest?: string;
|
|
84
104
|
}
|
|
85
105
|
|
|
86
|
-
export interface SuiMoveCheckpoint {
|
|
87
|
-
digest: string;
|
|
88
|
-
sequenceNumber: string;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface SuiMoveTransactionBlockResponse {
|
|
92
|
-
digest: string;
|
|
93
|
-
events: SuiMoveEvent[];
|
|
94
|
-
checkpoint?: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
106
|
export interface SuiMoveCoinBalance {
|
|
98
107
|
coinType: string;
|
|
99
108
|
totalBalance: string;
|
|
@@ -104,6 +113,40 @@ export interface SuiMoveViewResult {
|
|
|
104
113
|
type: string;
|
|
105
114
|
}
|
|
106
115
|
|
|
116
|
+
export type SuiMoveCheckpoint = Checkpoint;
|
|
117
|
+
|
|
118
|
+
export type SuiMoveGetTransactionBlockParams = GetTransactionBlockParams;
|
|
119
|
+
|
|
120
|
+
export type SuiMoveTransactionBlockResponse =
|
|
121
|
+
| SuiTransactionBlockResponse
|
|
122
|
+
| IotaTransactionBlockResponse;
|
|
123
|
+
|
|
124
|
+
export type SuiMoveGetAllCoinsParams = GetAllCoinsParams;
|
|
125
|
+
|
|
126
|
+
export type SuiMoveGetAllCoinsResponse = PaginatedCoins;
|
|
127
|
+
|
|
128
|
+
export type SuiMoveGetObjectParams = GetObjectParams;
|
|
129
|
+
|
|
130
|
+
export type SuiMoveObjectResponse = SuiObjectResponse | IotaObjectResponse;
|
|
131
|
+
|
|
132
|
+
export type SuiMoveGetOwnedObjectsParams = GetOwnedObjectsParams;
|
|
133
|
+
|
|
134
|
+
export type SuiMoveGetOwnedObjectsResponse =
|
|
135
|
+
| SuiPaginatedObjectsResponse
|
|
136
|
+
| IotaPaginatedObjectsResponse;
|
|
137
|
+
|
|
107
138
|
export type SuiMoveDevInspectResult = SuiDevInspectResults | IotaDevInspectResults;
|
|
108
139
|
|
|
109
140
|
export type SuiMoveExecutionResult = SuiExecutionResult | IotaExecutionResult;
|
|
141
|
+
|
|
142
|
+
export type SuiMoveObjectData = SuiObjectData | IotaObjectData;
|
|
143
|
+
|
|
144
|
+
export type SuiMoveSystemStateSummary = SuiSystemStateSummary | LatestIotaSystemStateSummary;
|
|
145
|
+
|
|
146
|
+
export type SuiMoveQueryTransactionBlocksParams =
|
|
147
|
+
| SuiQueryTransactionBlocksParams
|
|
148
|
+
| IotaQueryTransactionBlocksParams;
|
|
149
|
+
|
|
150
|
+
export type SuiMovePaginatedTransactionResponse =
|
|
151
|
+
| SuiPaginatedTransactionResponse
|
|
152
|
+
| IotaPaginatedTransactionResponse;
|
package/src/utils.ts
CHANGED
|
@@ -1,12 +1,185 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeIotaAddress } from '@iota/iota-sdk/utils';
|
|
2
|
+
import type {
|
|
3
|
+
CoinStruct,
|
|
4
|
+
GetObjectParams,
|
|
5
|
+
GetTransactionBlockParams,
|
|
6
|
+
SuiObjectChange,
|
|
7
|
+
SuiObjectDataOptions,
|
|
8
|
+
SuiTransactionBlockResponseOptions,
|
|
9
|
+
} from '@mysten/sui/client';
|
|
10
|
+
import { fromBase64, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';
|
|
11
|
+
|
|
12
|
+
import { ChainName } from '@layerzerolabs/layerzero-definitions';
|
|
13
|
+
import type {
|
|
14
|
+
AllRequired,
|
|
15
|
+
MaybePartial,
|
|
16
|
+
Prettify,
|
|
17
|
+
RemoveNever,
|
|
18
|
+
} from '@layerzerolabs/typescript-utils';
|
|
2
19
|
|
|
3
20
|
import { SuiMoveAbortError, SuiMoveUnclassifiedError } from './error';
|
|
4
21
|
import type { SuiMoveProvider } from './provider';
|
|
5
22
|
import type { SuiMoveTransaction } from './transaction';
|
|
6
|
-
import type {
|
|
23
|
+
import type {
|
|
24
|
+
SuiMoveEvent,
|
|
25
|
+
SuiMoveExecutionResult,
|
|
26
|
+
SuiMoveObjectResponse,
|
|
27
|
+
SuiMoveTransactionBlockResponse,
|
|
28
|
+
SuiMoveViewResult,
|
|
29
|
+
} from './types';
|
|
7
30
|
|
|
8
31
|
const MOCK_SENDER = '0x1234567890123456789012345678901234567890123456789012345678901234';
|
|
9
32
|
|
|
33
|
+
export interface MatchQuery {
|
|
34
|
+
type: string;
|
|
35
|
+
check: 'includes' | 'startsWith' | 'endsWith' | 'equals' | 'regex';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type FullObjectOptions = AllRequired<SuiObjectDataOptions>;
|
|
39
|
+
type FullBlockResponseOptions = AllRequired<SuiTransactionBlockResponseOptions>;
|
|
40
|
+
|
|
41
|
+
type ObjectChangeTypes = SuiObjectChange['type'];
|
|
42
|
+
type ObjectChangeTypesOptions = {
|
|
43
|
+
[K in ObjectChangeTypes as `show${Capitalize<K>}`]?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type ObjectChangeTypeResults<Options extends ObjectChangeTypesOptions> = Prettify<
|
|
47
|
+
RemoveNever<{
|
|
48
|
+
[K in ObjectChangeTypes]: `show${Capitalize<K>}` extends keyof Options
|
|
49
|
+
? Options[`show${Capitalize<K>}`] extends true
|
|
50
|
+
? Extract<SuiObjectChange, { type: K }>[]
|
|
51
|
+
: never
|
|
52
|
+
: never;
|
|
53
|
+
}>
|
|
54
|
+
>;
|
|
55
|
+
|
|
56
|
+
const objectOptionKeys: (keyof FullObjectOptions)[] = [
|
|
57
|
+
'showBcs',
|
|
58
|
+
'showContent',
|
|
59
|
+
'showType',
|
|
60
|
+
'showDisplay',
|
|
61
|
+
'showOwner',
|
|
62
|
+
'showPreviousTransaction',
|
|
63
|
+
'showStorageRebate',
|
|
64
|
+
] as const;
|
|
65
|
+
|
|
66
|
+
const blockResponseOptionsKeys: (keyof FullBlockResponseOptions)[] = [
|
|
67
|
+
'showBalanceChanges',
|
|
68
|
+
'showEffects',
|
|
69
|
+
'showEvents',
|
|
70
|
+
'showObjectChanges',
|
|
71
|
+
'showRawEffects',
|
|
72
|
+
] as const;
|
|
73
|
+
|
|
74
|
+
type OptionsValidated<
|
|
75
|
+
FullOptions extends Record<string, any>,
|
|
76
|
+
CurrentOptions extends Record<string, any>,
|
|
77
|
+
Data extends Record<string, any>,
|
|
78
|
+
> = Prettify<
|
|
79
|
+
RemoveNever<{
|
|
80
|
+
[key in keyof AllRequired<Data>]: key extends string
|
|
81
|
+
? `show${Capitalize<key>}` extends keyof FullOptions
|
|
82
|
+
? CurrentOptions[`show${Capitalize<key>}`] extends true
|
|
83
|
+
? NonNullable<Data[key]>
|
|
84
|
+
: never
|
|
85
|
+
: Data[key]
|
|
86
|
+
: never;
|
|
87
|
+
}>
|
|
88
|
+
>;
|
|
89
|
+
|
|
90
|
+
const validateOptions = <
|
|
91
|
+
FullOptions extends Record<string, any>,
|
|
92
|
+
Options extends Record<string, any>,
|
|
93
|
+
Data extends Record<string, any>,
|
|
94
|
+
>(
|
|
95
|
+
data: Data,
|
|
96
|
+
fullOptionKeys: string[],
|
|
97
|
+
options?: Options,
|
|
98
|
+
): OptionsValidated<FullOptions, Options, Data> => {
|
|
99
|
+
// check inclusion of all options
|
|
100
|
+
fullOptionKeys.forEach((option) => {
|
|
101
|
+
// Remove 'show' prefix and convert first letter to lowercase for camelCase
|
|
102
|
+
const fieldName = option.slice('show'.length);
|
|
103
|
+
const field = fieldName.charAt(0).toLowerCase() + fieldName.slice(1);
|
|
104
|
+
if (options?.[option] && !data[field]) {
|
|
105
|
+
throw new Error(`Missing required field ${field} on data object ${data}`);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// check validity of inclusions:
|
|
110
|
+
return Object.fromEntries(
|
|
111
|
+
Object.entries(data).map(([key, value]) => {
|
|
112
|
+
for (const option of fullOptionKeys) {
|
|
113
|
+
// Convert option to expected field name
|
|
114
|
+
const fieldName = option.slice('show'.length);
|
|
115
|
+
const expectedField = fieldName.charAt(0).toLowerCase() + fieldName.slice(1);
|
|
116
|
+
if (expectedField === key && options?.[option] && !value) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Failed fetching data for option ${option} on object ${data.objectId}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return [key, value];
|
|
123
|
+
}),
|
|
124
|
+
) as OptionsValidated<FullObjectOptions, Options, Data>;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const checkInclusion = (objectType: string, query: MatchQuery) => {
|
|
128
|
+
const check = query.check;
|
|
129
|
+
const type = query.type;
|
|
130
|
+
switch (check) {
|
|
131
|
+
case 'includes':
|
|
132
|
+
return objectType.includes(type);
|
|
133
|
+
case 'startsWith':
|
|
134
|
+
return objectType.startsWith(type);
|
|
135
|
+
case 'endsWith':
|
|
136
|
+
return objectType.endsWith(type);
|
|
137
|
+
case 'equals':
|
|
138
|
+
return objectType === type;
|
|
139
|
+
case 'regex':
|
|
140
|
+
return new RegExp(type).test(objectType);
|
|
141
|
+
default:
|
|
142
|
+
throw new Error(`Unknown check type: ${check}`);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const filterObjectChanges = <Options extends ObjectChangeTypesOptions>(
|
|
147
|
+
objectChanges: SuiObjectChange[],
|
|
148
|
+
query: MatchQuery | 'all',
|
|
149
|
+
options?: Options,
|
|
150
|
+
): ObjectChangeTypeResults<Options> => {
|
|
151
|
+
const result = {} as ObjectChangeTypeResults<Options>;
|
|
152
|
+
type key = keyof ObjectChangeTypeResults<Options>;
|
|
153
|
+
const capitalize = (s: string) => s.slice(0, 1).toUpperCase() + s.slice(1);
|
|
154
|
+
|
|
155
|
+
for (const objectChange of objectChanges) {
|
|
156
|
+
// Published has packageId
|
|
157
|
+
if (objectChange.type === 'published') {
|
|
158
|
+
if (
|
|
159
|
+
options?.showPublished &&
|
|
160
|
+
(query === 'all' || checkInclusion(objectChange.packageId, query))
|
|
161
|
+
) {
|
|
162
|
+
// FIXME: maybe we can remove these as? not sure though
|
|
163
|
+
result['published' as key] ??= [] as any;
|
|
164
|
+
result['published' as key].push(objectChange as any);
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
// Everyone else has objectType
|
|
168
|
+
const show = `show${capitalize(objectChange.type)}` as keyof Options;
|
|
169
|
+
if (
|
|
170
|
+
options?.[show] &&
|
|
171
|
+
(query === 'all' || checkInclusion(objectChange.objectType, query))
|
|
172
|
+
) {
|
|
173
|
+
// FIXME: maybe we can remove these as? not sure though
|
|
174
|
+
result[objectChange.type as key] ??= [] as any;
|
|
175
|
+
result[objectChange.type as key].push(objectChange as any);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return result;
|
|
181
|
+
};
|
|
182
|
+
|
|
10
183
|
/**
|
|
11
184
|
* Converts raw Sui move events to SuiMoveEvent format
|
|
12
185
|
*/
|
|
@@ -84,3 +257,232 @@ export async function suiMoveView(
|
|
|
84
257
|
]);
|
|
85
258
|
return results[0];
|
|
86
259
|
}
|
|
260
|
+
|
|
261
|
+
export async function suiMoveViewParsed<T>({
|
|
262
|
+
client,
|
|
263
|
+
tx,
|
|
264
|
+
parser,
|
|
265
|
+
}: {
|
|
266
|
+
client: SuiMoveProvider;
|
|
267
|
+
tx: SuiMoveTransaction;
|
|
268
|
+
parser: (result: { value: Uint8Array }[]) => T;
|
|
269
|
+
}): Promise<T> {
|
|
270
|
+
const results = await suiMoveViewMultiResult(client, tx, [
|
|
271
|
+
tx.getData().commands.length - 1, // last command
|
|
272
|
+
]);
|
|
273
|
+
return parser(results[0]);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Returns the defining package ID for a given object type. This is the package
|
|
278
|
+
* that defined the object's Move type at the time the object was created.
|
|
279
|
+
*
|
|
280
|
+
* @param objectType The object type, e.g. 0xc6b8aab4e0124a27071228cb4c2b422344cb13574a9641ed0d9177c7111ed7::my_coin::MY_COIN
|
|
281
|
+
* @returns The defining package ID, e.g. 0xc6b8aab4e0124a27071228cb4c2b422344cb13574a9641ed0d9177c7111ed7
|
|
282
|
+
*/
|
|
283
|
+
export function getDefiningPackageIdFromObjectType(
|
|
284
|
+
chainName: ChainName,
|
|
285
|
+
objectType: string,
|
|
286
|
+
): string {
|
|
287
|
+
const address = parseStructTag(objectType).address;
|
|
288
|
+
return normalizeSuiMoveAddress(address, chainName);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export async function getSuiMoveObjectValidated<const Options extends SuiObjectDataOptions>(
|
|
292
|
+
args: Omit<GetObjectParams, 'options'> & { options?: Options; client: SuiMoveProvider },
|
|
293
|
+
): Promise<
|
|
294
|
+
OptionsValidated<FullObjectOptions, Options, NonNullable<SuiMoveObjectResponse['data']>>
|
|
295
|
+
> {
|
|
296
|
+
const object = await args.client.getSuiMoveObject(args);
|
|
297
|
+
if (object.error) {
|
|
298
|
+
throw new Error(`Failed to get object ${args.id}`, { cause: object.error });
|
|
299
|
+
} else if (!object.data) {
|
|
300
|
+
throw new Error(`Object not found: ${args.id}`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return validateOptions<FullObjectOptions, Options, NonNullable<SuiMoveObjectResponse['data']>>(
|
|
304
|
+
object.data,
|
|
305
|
+
objectOptionKeys,
|
|
306
|
+
args.options,
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export async function getSuiMoveTransactionBlockValidated<
|
|
311
|
+
const Options extends SuiTransactionBlockResponseOptions,
|
|
312
|
+
>(
|
|
313
|
+
args: Omit<GetTransactionBlockParams, 'options'> & {
|
|
314
|
+
options?: Options;
|
|
315
|
+
client: SuiMoveProvider;
|
|
316
|
+
},
|
|
317
|
+
): Promise<OptionsValidated<FullBlockResponseOptions, Options, SuiMoveTransactionBlockResponse>> {
|
|
318
|
+
const txBlock = await args.client.getSuiMoveTransactionBlock(args);
|
|
319
|
+
if (txBlock.errors?.length) {
|
|
320
|
+
throw new Error(`Couldn't fetch transaction block due to errors: ${txBlock.errors}`);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return validateOptions<FullBlockResponseOptions, Options, SuiMoveTransactionBlockResponse>(
|
|
324
|
+
txBlock,
|
|
325
|
+
blockResponseOptionsKeys,
|
|
326
|
+
args.options,
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Fetches all owned coins that have the specified package id
|
|
332
|
+
* @param chainName chainName to denormalize the addresses
|
|
333
|
+
* @param normalizedCoinPackageId Coin package id to search for
|
|
334
|
+
* @param normalizedWalletAddress Wallet address to search for coins on
|
|
335
|
+
* @returns Array of all found coin objects, sorted by balance
|
|
336
|
+
*/
|
|
337
|
+
export async function searchForCoinTypeInWallet(
|
|
338
|
+
chainName: ChainName,
|
|
339
|
+
coinPackageId: string,
|
|
340
|
+
walletAddress: string,
|
|
341
|
+
client: SuiMoveProvider,
|
|
342
|
+
): Promise<CoinStruct[]> {
|
|
343
|
+
let cursor: string | undefined | null = undefined;
|
|
344
|
+
let hasNextPage = true;
|
|
345
|
+
let coinObjects = [] as CoinStruct[];
|
|
346
|
+
|
|
347
|
+
while (hasNextPage) {
|
|
348
|
+
const coins = await client.getAllSuiMoveCoins({
|
|
349
|
+
owner: walletAddress,
|
|
350
|
+
limit: 50,
|
|
351
|
+
cursor,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// Sui has its own normalization for addresses that we need to use to compare addresses
|
|
355
|
+
const normalizedCoinPackageId = normalizeSuiMoveAddress(coinPackageId, chainName);
|
|
356
|
+
|
|
357
|
+
const matchedCoins = coins.data.filter((coin) => {
|
|
358
|
+
const coinType = coin.coinType;
|
|
359
|
+
const definingPackageId = getDefiningPackageIdFromObjectType(chainName, coinType);
|
|
360
|
+
return definingPackageId === normalizedCoinPackageId;
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
coinObjects = coinObjects.concat(matchedCoins);
|
|
364
|
+
cursor = coins.nextCursor;
|
|
365
|
+
hasNextPage = coins.hasNextPage;
|
|
366
|
+
}
|
|
367
|
+
return coinObjects.sort((a, b) => Number(BigInt(b.balance) - BigInt(a.balance)));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export async function getSuiMoveOwnedObjectsByType<
|
|
371
|
+
T extends Record<string, MatchQuery>,
|
|
372
|
+
Options extends SuiObjectDataOptions,
|
|
373
|
+
AllowPartial extends boolean = false,
|
|
374
|
+
>({
|
|
375
|
+
walletAddress,
|
|
376
|
+
typeInclusions,
|
|
377
|
+
options,
|
|
378
|
+
client,
|
|
379
|
+
}: {
|
|
380
|
+
walletAddress: string;
|
|
381
|
+
typeInclusions: T;
|
|
382
|
+
options?: Omit<Options, 'showType'> & { allowPartial?: AllowPartial };
|
|
383
|
+
client: SuiMoveProvider;
|
|
384
|
+
}): Promise<
|
|
385
|
+
Record<
|
|
386
|
+
keyof T,
|
|
387
|
+
MaybePartial<
|
|
388
|
+
OptionsValidated<
|
|
389
|
+
FullObjectOptions,
|
|
390
|
+
Options & { showType: true },
|
|
391
|
+
NonNullable<SuiMoveObjectResponse['data']>
|
|
392
|
+
>[],
|
|
393
|
+
AllowPartial
|
|
394
|
+
>
|
|
395
|
+
>
|
|
396
|
+
> {
|
|
397
|
+
let cursor: string | undefined | null = undefined;
|
|
398
|
+
let hasNextPage = true;
|
|
399
|
+
const result = {} as Record<
|
|
400
|
+
keyof T,
|
|
401
|
+
OptionsValidated<
|
|
402
|
+
FullObjectOptions,
|
|
403
|
+
Options & { showType: true },
|
|
404
|
+
NonNullable<SuiMoveObjectResponse['data']>
|
|
405
|
+
>[]
|
|
406
|
+
>;
|
|
407
|
+
const typeInclusionsArray = Object.entries(typeInclusions);
|
|
408
|
+
|
|
409
|
+
while (hasNextPage) {
|
|
410
|
+
const objects = await client.getSuiMoveOwnedObject({
|
|
411
|
+
owner: walletAddress,
|
|
412
|
+
options: {
|
|
413
|
+
...options,
|
|
414
|
+
showType: true,
|
|
415
|
+
},
|
|
416
|
+
cursor,
|
|
417
|
+
limit: 50,
|
|
418
|
+
});
|
|
419
|
+
for (const object of objects.data) {
|
|
420
|
+
if (!object.data) continue;
|
|
421
|
+
const objectType = object.data.type;
|
|
422
|
+
if (!objectType) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
for (const [key, query] of typeInclusionsArray) {
|
|
426
|
+
if (checkInclusion(objectType, query)) {
|
|
427
|
+
const validated = validateOptions<
|
|
428
|
+
FullObjectOptions,
|
|
429
|
+
Options,
|
|
430
|
+
NonNullable<SuiMoveObjectResponse['data']>
|
|
431
|
+
>(object.data, objectOptionKeys, options as Options | undefined);
|
|
432
|
+
result[key as keyof T] ??= [];
|
|
433
|
+
result[key as keyof T].push(validated);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
cursor = objects.nextCursor;
|
|
438
|
+
hasNextPage = objects.hasNextPage;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!options?.allowPartial && Object.keys(result).length !== typeInclusionsArray.length) {
|
|
442
|
+
const difference = new Set(typeInclusionsArray.map(([k]) => k));
|
|
443
|
+
Object.keys(result).forEach((key) => difference.delete(key));
|
|
444
|
+
throw new Error(`Couldnt find all objects, missing: ${[...difference]}`);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return result;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export async function getSuiMovePackagePublishObjectChanges<
|
|
451
|
+
Queries extends Record<string, MatchQuery | 'all'>,
|
|
452
|
+
ChangeOptions extends ObjectChangeTypesOptions,
|
|
453
|
+
>({
|
|
454
|
+
packageId,
|
|
455
|
+
queries,
|
|
456
|
+
options,
|
|
457
|
+
client,
|
|
458
|
+
}: {
|
|
459
|
+
packageId: string;
|
|
460
|
+
queries: Queries;
|
|
461
|
+
client: SuiMoveProvider;
|
|
462
|
+
options?: ChangeOptions;
|
|
463
|
+
}): Promise<Record<keyof Queries, ObjectChangeTypeResults<ChangeOptions>>> {
|
|
464
|
+
const pkgObject = await getSuiMoveObjectValidated({
|
|
465
|
+
id: packageId,
|
|
466
|
+
client,
|
|
467
|
+
options: { showPreviousTransaction: true },
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
const txBlock = await getSuiMoveTransactionBlockValidated({
|
|
471
|
+
digest: pkgObject.previousTransaction,
|
|
472
|
+
options: { showObjectChanges: true },
|
|
473
|
+
client,
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
return Object.fromEntries(
|
|
477
|
+
Object.entries(queries).map(([k, query]) => {
|
|
478
|
+
return [k, filterObjectChanges(txBlock.objectChanges, query, options)];
|
|
479
|
+
}),
|
|
480
|
+
) as Record<keyof Queries, ObjectChangeTypeResults<ChangeOptions>>;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export const normalizeSuiMoveAddress = (address: string, chainName: ChainName) => {
|
|
484
|
+
if (chainName === ChainName.IOTAL1) {
|
|
485
|
+
return normalizeIotaAddress(address);
|
|
486
|
+
}
|
|
487
|
+
return normalizeSuiAddress(address);
|
|
488
|
+
};
|
package/dist/AHFVRB2R.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts"],"names":["SuiMoveAbortError","Error","abortCode","rawMsg","SuiMoveUnclassifiedError"],"mappings":";;;;;;AAAO,IAAMA,iBAAAA,GAAN,cAAgCC,KAAAA,CAAAA;EAAvC;;;AACaC,EAAAA,SAAAA;AACT,EAAA,WAAA,CAAYA,WAAmBC,MAAAA,EAAgB;AAC3C,IAAA,KAAA,CAAM,CAAA,sBAAA,EAAyBD,SAAAA,CAAAA,qBAAAA,EAAiCC,MAAAA,CAAAA,CAAQ,CAAA;AACxE,IAAA,IAAA,CAAKD,SAAAA,GAAYA,SAAAA;AACrB,EAAA;AACJ;AAEO,IAAME,wBAAAA,GAAN,cAAuCH,KAAAA,CAAAA;EAR9C;;;AAQqD","file":"AHFVRB2R.cjs","sourcesContent":["export class SuiMoveAbortError extends Error {\n readonly abortCode: number;\n constructor(abortCode: number, rawMsg: string) {\n super(`Move abort with code: ${abortCode}. Raw error message: ${rawMsg}`);\n this.abortCode = abortCode;\n }\n}\n\nexport class SuiMoveUnclassifiedError extends Error {}\n"]}
|