@0xobelisk/client 0.0.9 → 0.1.1
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.d.ts +2 -1
- package/dist/index.js +337 -292
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +345 -303
- package/dist/index.mjs.map +1 -1
- package/dist/libs/suiAccountManager/index.d.ts +1 -1
- package/dist/libs/suiAccountManager/keypair.d.ts +1 -1
- package/dist/libs/suiContractFactory/index.d.ts +0 -1
- package/dist/libs/suiInteractor/defaultConfig.d.ts +10 -0
- package/dist/libs/suiInteractor/index.d.ts +2 -0
- package/dist/libs/suiInteractor/suiInteractor.d.ts +204 -0
- package/dist/libs/suiInteractor/util.d.ts +1 -0
- package/dist/libs/suiModel/index.d.ts +2 -0
- package/dist/libs/suiModel/suiOwnedObject.d.ts +24 -0
- package/dist/libs/suiModel/suiSharedObject.d.ts +12 -0
- package/dist/libs/suiTxBuilder/index.d.ts +2 -2
- package/dist/libs/suiTxBuilder/util.d.ts +8 -8
- package/dist/metadata/index.d.ts +1 -1
- package/dist/obelisk.d.ts +122 -337
- package/dist/types/index.d.ts +48 -6
- package/package.json +3 -3
- package/src/index.ts +2 -1
- package/src/libs/suiAccountManager/index.ts +1 -1
- package/src/libs/suiAccountManager/keypair.ts +2 -2
- package/src/libs/suiContractFactory/index.ts +0 -1
- package/src/libs/{suiRpcProvider/defaultChainConfigs.ts → suiInteractor/defaultConfig.ts} +4 -2
- package/src/libs/suiInteractor/index.ts +2 -0
- package/src/libs/suiInteractor/suiInteractor.ts +269 -0
- package/src/libs/suiInteractor/util.ts +2 -0
- package/src/libs/suiModel/index.ts +2 -0
- package/src/libs/suiModel/suiOwnedObject.ts +62 -0
- package/src/libs/suiModel/suiSharedObject.ts +33 -0
- package/src/libs/suiTxBuilder/index.ts +1 -1
- package/src/libs/suiTxBuilder/util.ts +1 -1
- package/src/metadata/index.ts +7 -7
- package/src/obelisk.ts +38 -130
- package/src/types/index.ts +92 -10
- package/src/libs/suiAccountManager/types.ts +0 -10
- package/src/libs/suiRpcProvider/faucet.ts +0 -57
- package/src/libs/suiRpcProvider/index.ts +0 -150
- package/src/libs/suiRpcProvider/types.ts +0 -17
- package/src/libs/suiTxBuilder/types.ts +0 -32
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
export type { DerivePathParams } from '../libs/suiAccountManager/types';
|
|
1
|
+
import { Infer } from 'superstruct';
|
|
2
|
+
import { DisplayFieldsResponse, ObjectCallArg, ObjectContentFields, SharedObjectRef, SuiObjectRef, TransactionArgument, TransactionBlock, SuiTransactionBlockResponse, DevInspectResults, SuiMoveNormalizedModules } from '@mysten/sui.js';
|
|
4
3
|
import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
|
|
5
|
-
export type
|
|
6
|
-
|
|
4
|
+
export type ObeliskObjectData = {
|
|
5
|
+
objectId: string;
|
|
6
|
+
objectType: string;
|
|
7
|
+
objectVersion: number;
|
|
8
|
+
objectDisplay: DisplayFieldsResponse;
|
|
9
|
+
objectFields: ObjectContentFields;
|
|
10
|
+
};
|
|
7
11
|
export type ObeliskParams = {
|
|
8
12
|
mnemonics?: string;
|
|
9
13
|
secretKey?: string;
|
|
10
|
-
|
|
14
|
+
fullnodeUrls?: string[];
|
|
11
15
|
faucetUrl?: string;
|
|
12
16
|
networkType?: NetworkType;
|
|
13
17
|
packageId?: string;
|
|
@@ -70,3 +74,41 @@ export type MapMoudleFuncTx = Record<string, MapMessageTx>;
|
|
|
70
74
|
export type MapMoudleFuncQuery = Record<string, MapMessageQuery>;
|
|
71
75
|
export type MapMoudleFuncTest = Record<string, Record<string, string>>;
|
|
72
76
|
export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
|
|
77
|
+
export type AccountMangerParams = {
|
|
78
|
+
mnemonics?: string;
|
|
79
|
+
secretKey?: string;
|
|
80
|
+
};
|
|
81
|
+
export type DerivePathParams = {
|
|
82
|
+
accountIndex?: number;
|
|
83
|
+
isExternal?: boolean;
|
|
84
|
+
addressIndex?: number;
|
|
85
|
+
};
|
|
86
|
+
export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
87
|
+
export type FaucetNetworkType = 'testnet' | 'devnet' | 'localnet';
|
|
88
|
+
export type SuiKitParams = {
|
|
89
|
+
mnemonics?: string;
|
|
90
|
+
secretKey?: string;
|
|
91
|
+
fullnodeUrls?: string[];
|
|
92
|
+
faucetUrl?: string;
|
|
93
|
+
networkType?: NetworkType;
|
|
94
|
+
};
|
|
95
|
+
export type ObjectData = {
|
|
96
|
+
objectId: string;
|
|
97
|
+
objectType: string;
|
|
98
|
+
objectVersion: number;
|
|
99
|
+
objectDigest: string;
|
|
100
|
+
initialSharedVersion?: number;
|
|
101
|
+
objectDisplay: DisplayFieldsResponse;
|
|
102
|
+
objectFields: ObjectContentFields;
|
|
103
|
+
};
|
|
104
|
+
export type SuiTxArg = Infer<typeof TransactionArgument> | Infer<typeof ObjectCallArg> | string | number | bigint | boolean;
|
|
105
|
+
export type SuiObjectArg = SharedObjectRef | Infer<typeof SuiObjectRef> | string | Infer<typeof ObjectCallArg> | Infer<typeof TransactionArgument>;
|
|
106
|
+
export type SuiVecTxArg = {
|
|
107
|
+
value: SuiTxArg[];
|
|
108
|
+
vecType: SuiInputTypes;
|
|
109
|
+
} | SuiTxArg[];
|
|
110
|
+
/**
|
|
111
|
+
* These are the basics types that can be used in the SUI
|
|
112
|
+
*/
|
|
113
|
+
export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256';
|
|
114
|
+
export type SuiInputTypes = 'object' | SuiBasicTypes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xobelisk/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Tookit for interacting with move eps framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@mysten/bcs": "^0.7.3",
|
|
61
|
-
"@mysten/sui.js": "^0.
|
|
61
|
+
"@mysten/sui.js": "^0.41.0",
|
|
62
62
|
"@obelisk/common": "link:../common",
|
|
63
63
|
"@scure/bip39": "^1.2.1",
|
|
64
64
|
"assert": "^2.0.0",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"ts-retry-promise": "^0.7.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@mysten/sui.js": "^0.
|
|
74
|
+
"@mysten/sui.js": "^0.41.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@commitlint/cli": "^17.6.6",
|
package/src/index.ts
CHANGED
|
@@ -3,10 +3,11 @@ export {
|
|
|
3
3
|
SUI_CLOCK_OBJECT_ID,
|
|
4
4
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
5
5
|
} from '@mysten/sui.js';
|
|
6
|
+
export { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
7
|
+
export { fromB64, toB64 } from '@mysten/sui.js';
|
|
6
8
|
export { Obelisk } from './obelisk';
|
|
7
9
|
export { SuiAccountManager } from './libs/suiAccountManager';
|
|
8
10
|
export { SuiTxBlock } from './libs/suiTxBuilder';
|
|
9
|
-
export { SuiRpcProvider } from './libs/suiRpcProvider';
|
|
10
11
|
export { SuiContractFactory } from './libs/suiContractFactory';
|
|
11
12
|
export { getMetadata } from './metadata';
|
|
12
13
|
export type * from './types';
|
|
@@ -2,7 +2,7 @@ import { Ed25519Keypair } from '@mysten/sui.js';
|
|
|
2
2
|
import { getKeyPair } from './keypair';
|
|
3
3
|
import { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';
|
|
4
4
|
import { generateMnemonic } from './crypto';
|
|
5
|
-
import type { AccountMangerParams, DerivePathParams } from '
|
|
5
|
+
import type { AccountMangerParams, DerivePathParams } from 'src/types';
|
|
6
6
|
|
|
7
7
|
export class SuiAccountManager {
|
|
8
8
|
private mnemonics: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Ed25519Keypair } from '@mysten/sui.js';
|
|
2
|
-
import type { DerivePathParams } from '
|
|
1
|
+
import { Ed25519Keypair, fromB64 } from '@mysten/sui.js';
|
|
2
|
+
import type { DerivePathParams } from 'src/types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @description Get ed25519 derive path for SUI
|
|
@@ -5,14 +5,16 @@ import {
|
|
|
5
5
|
mainnetConnection,
|
|
6
6
|
} from '@mysten/sui.js';
|
|
7
7
|
import type { Connection } from '@mysten/sui.js';
|
|
8
|
-
import type { NetworkType } from '
|
|
8
|
+
import type { NetworkType } from 'src/types';
|
|
9
|
+
export const defaultGasBudget = 10 ** 8; // 0.1 SUI, should be enough for most of the transactions
|
|
10
|
+
export const defaultGasPrice = 1000; // 1000 MIST
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* @description Get the default fullnode url and faucet url for the given network type
|
|
12
14
|
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
|
|
13
15
|
* @returns { fullNode: string, websocket: string, faucet?: string }
|
|
14
16
|
*/
|
|
15
|
-
export const
|
|
17
|
+
export const getDefaultConnection = (
|
|
16
18
|
networkType: NetworkType = 'devnet'
|
|
17
19
|
): Connection => {
|
|
18
20
|
switch (networkType) {
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SuiTransactionBlockResponse,
|
|
3
|
+
SuiTransactionBlockResponseOptions,
|
|
4
|
+
JsonRpcProvider,
|
|
5
|
+
Connection,
|
|
6
|
+
getObjectDisplay,
|
|
7
|
+
getObjectFields,
|
|
8
|
+
getObjectId,
|
|
9
|
+
getObjectType,
|
|
10
|
+
getObjectVersion,
|
|
11
|
+
getSharedObjectInitialVersion,
|
|
12
|
+
DynamicFieldName,
|
|
13
|
+
SuiAddress
|
|
14
|
+
} from '@mysten/sui.js';
|
|
15
|
+
import { requestSuiFromFaucetV0, getFaucetHost } from '@mysten/sui.js/faucet';
|
|
16
|
+
import { SuiClient, getFullnodeUrl, GetBalanceParams } from '@mysten/sui.js/client';
|
|
17
|
+
import { FaucetNetworkType, NetworkType, ObjectData } from 'src/types';
|
|
18
|
+
import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
|
|
19
|
+
import { delay } from './util';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `SuiTransactionSender` is used to send transaction with a given gas coin.
|
|
23
|
+
* It always uses the gas coin to pay for the gas,
|
|
24
|
+
* and update the gas coin after the transaction.
|
|
25
|
+
*/
|
|
26
|
+
export class SuiInteractor {
|
|
27
|
+
public readonly providers: JsonRpcProvider[];
|
|
28
|
+
public currentProvider: JsonRpcProvider;
|
|
29
|
+
public network?: NetworkType;
|
|
30
|
+
|
|
31
|
+
constructor(fullNodeUrls: string[], network?: NetworkType) {
|
|
32
|
+
if (fullNodeUrls.length === 0)
|
|
33
|
+
throw new Error('fullNodeUrls must not be empty');
|
|
34
|
+
this.providers = fullNodeUrls.map(
|
|
35
|
+
(url) => new JsonRpcProvider(new Connection({ fullnode: url }))
|
|
36
|
+
);
|
|
37
|
+
this.currentProvider = this.providers[0];
|
|
38
|
+
this.network = network;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
switchToNextProvider() {
|
|
42
|
+
const currentProviderIdx = this.providers.indexOf(this.currentProvider);
|
|
43
|
+
this.currentProvider =
|
|
44
|
+
this.providers[(currentProviderIdx + 1) % this.providers.length];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async sendTx(
|
|
48
|
+
transactionBlock: Uint8Array | string,
|
|
49
|
+
signature: string | string[]
|
|
50
|
+
): Promise<SuiTransactionBlockResponse> {
|
|
51
|
+
const txResOptions: SuiTransactionBlockResponseOptions = {
|
|
52
|
+
showEvents: true,
|
|
53
|
+
showEffects: true,
|
|
54
|
+
showObjectChanges: true,
|
|
55
|
+
showBalanceChanges: true,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// const currentProviderIdx = this.providers.indexOf(this.currentProvider);
|
|
59
|
+
// const providers = [
|
|
60
|
+
// ...this.providers.slice(currentProviderIdx, this.providers.length),
|
|
61
|
+
// ...this.providers.slice(0, currentProviderIdx),
|
|
62
|
+
// ]
|
|
63
|
+
|
|
64
|
+
for (const provider of this.providers) {
|
|
65
|
+
try {
|
|
66
|
+
const res = await provider.executeTransactionBlock({
|
|
67
|
+
transactionBlock,
|
|
68
|
+
signature,
|
|
69
|
+
options: txResOptions,
|
|
70
|
+
});
|
|
71
|
+
return res;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.warn(
|
|
74
|
+
`Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`
|
|
75
|
+
);
|
|
76
|
+
await delay(2000);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw new Error('Failed to send transaction with all fullnodes');
|
|
80
|
+
}
|
|
81
|
+
async getObjects(ids: string[]) {
|
|
82
|
+
const options = {
|
|
83
|
+
showContent: true,
|
|
84
|
+
showDisplay: true,
|
|
85
|
+
showType: true,
|
|
86
|
+
showOwner: true,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// const currentProviderIdx = this.providers.indexOf(this.currentProvider);
|
|
90
|
+
// const providers = [
|
|
91
|
+
// ...this.providers.slice(currentProviderIdx, this.providers.length),
|
|
92
|
+
// ...this.providers.slice(0, currentProviderIdx),
|
|
93
|
+
// ]
|
|
94
|
+
|
|
95
|
+
for (const provider of this.providers) {
|
|
96
|
+
try {
|
|
97
|
+
const objects = await provider.multiGetObjects({ ids, options });
|
|
98
|
+
const parsedObjects = objects.map((object) => {
|
|
99
|
+
const objectId = getObjectId(object);
|
|
100
|
+
const objectType = getObjectType(object);
|
|
101
|
+
const objectVersion = getObjectVersion(object);
|
|
102
|
+
const objectDigest = object.data ? object.data.digest : undefined;
|
|
103
|
+
const initialSharedVersion = getSharedObjectInitialVersion(object);
|
|
104
|
+
const objectFields = getObjectFields(object);
|
|
105
|
+
const objectDisplay = getObjectDisplay(object);
|
|
106
|
+
return {
|
|
107
|
+
objectId,
|
|
108
|
+
objectType,
|
|
109
|
+
objectVersion,
|
|
110
|
+
objectDigest,
|
|
111
|
+
objectFields,
|
|
112
|
+
objectDisplay,
|
|
113
|
+
initialSharedVersion,
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
return parsedObjects as ObjectData[];
|
|
117
|
+
} catch (err) {
|
|
118
|
+
await delay(2000);
|
|
119
|
+
console.warn(
|
|
120
|
+
`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
throw new Error('Failed to get objects with all fullnodes');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async getObject(id: string) {
|
|
128
|
+
const objects = await this.getObjects([id]);
|
|
129
|
+
return objects[0];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
async getDynamicFieldObject(parentId: string, name: string | DynamicFieldName) {
|
|
134
|
+
for (const provider of this.providers) {
|
|
135
|
+
try {
|
|
136
|
+
return provider.getDynamicFieldObject({ parentId, name })
|
|
137
|
+
} catch (err) {
|
|
138
|
+
await delay(2000);
|
|
139
|
+
console.warn(
|
|
140
|
+
`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
throw new Error('Failed to get objects with all fullnodes');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async getDynamicFields(parentId: string, cursor?: string, limit?: number) {
|
|
148
|
+
for (const provider of this.providers) {
|
|
149
|
+
try {
|
|
150
|
+
return provider.getDynamicFields({ parentId, cursor, limit })
|
|
151
|
+
} catch (err) {
|
|
152
|
+
await delay(2000);
|
|
153
|
+
console.warn(
|
|
154
|
+
`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
throw new Error('Failed to get objects with all fullnodes');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async getOwnedObjects(owner: SuiAddress, cursor?: string, limit?: number) {
|
|
162
|
+
for (const provider of this.providers) {
|
|
163
|
+
try {
|
|
164
|
+
return await provider.getOwnedObjects({ owner, cursor, limit });
|
|
165
|
+
} catch (err) {
|
|
166
|
+
await delay(2000);
|
|
167
|
+
console.warn(
|
|
168
|
+
`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
throw new Error('Failed to get objects with all fullnodes');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
async getNormalizedMoveModulesByPackage(packageId: string) {
|
|
177
|
+
for (const provider of this.providers) {
|
|
178
|
+
try {
|
|
179
|
+
return provider.getNormalizedMoveModulesByPackage({package: packageId});
|
|
180
|
+
|
|
181
|
+
} catch (err) {
|
|
182
|
+
await delay(2000);
|
|
183
|
+
console.warn(
|
|
184
|
+
`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
throw new Error('Failed to get objects with all fullnodes');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @description Update objects in a batch
|
|
193
|
+
* @param suiObjects
|
|
194
|
+
*/
|
|
195
|
+
async updateObjects(suiObjects: (SuiOwnedObject | SuiSharedObject)[]) {
|
|
196
|
+
const objectIds = suiObjects.map((obj) => obj.objectId);
|
|
197
|
+
const objects = await this.getObjects(objectIds);
|
|
198
|
+
for (const object of objects) {
|
|
199
|
+
const suiObject = suiObjects.find(
|
|
200
|
+
(obj) => obj.objectId === object.objectId
|
|
201
|
+
);
|
|
202
|
+
if (suiObject instanceof SuiSharedObject) {
|
|
203
|
+
suiObject.initialSharedVersion = object.initialSharedVersion;
|
|
204
|
+
} else if (suiObject instanceof SuiOwnedObject) {
|
|
205
|
+
suiObject.version = object.objectVersion;
|
|
206
|
+
suiObject.digest = object.objectDigest;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @description Select coins that add up to the given amount.
|
|
213
|
+
* @param addr the address of the owner
|
|
214
|
+
* @param amount the amount that is needed for the coin
|
|
215
|
+
* @param coinType the coin type, default is '0x2::SUI::SUI'
|
|
216
|
+
*/
|
|
217
|
+
async selectCoins(
|
|
218
|
+
addr: string,
|
|
219
|
+
amount: number,
|
|
220
|
+
coinType: string = '0x2::SUI::SUI'
|
|
221
|
+
) {
|
|
222
|
+
const selectedCoins: {
|
|
223
|
+
objectId: string;
|
|
224
|
+
digest: string;
|
|
225
|
+
version: string;
|
|
226
|
+
}[] = [];
|
|
227
|
+
let totalAmount = 0;
|
|
228
|
+
let hasNext = true,
|
|
229
|
+
nextCursor: string | null = null;
|
|
230
|
+
while (hasNext && totalAmount < amount) {
|
|
231
|
+
const coins = await this.currentProvider.getCoins({
|
|
232
|
+
owner: addr,
|
|
233
|
+
coinType: coinType,
|
|
234
|
+
cursor: nextCursor,
|
|
235
|
+
});
|
|
236
|
+
// Sort the coins by balance in descending order
|
|
237
|
+
coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
|
|
238
|
+
for (const coinData of coins.data) {
|
|
239
|
+
selectedCoins.push({
|
|
240
|
+
objectId: coinData.coinObjectId,
|
|
241
|
+
digest: coinData.digest,
|
|
242
|
+
version: coinData.version,
|
|
243
|
+
});
|
|
244
|
+
totalAmount = totalAmount + parseInt(coinData.balance);
|
|
245
|
+
if (totalAmount >= amount) {
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
nextCursor = coins.nextCursor;
|
|
251
|
+
hasNext = coins.hasNextPage;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (!selectedCoins.length) {
|
|
255
|
+
throw new Error('No valid coins found for the transaction.');
|
|
256
|
+
}
|
|
257
|
+
return selectedCoins;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async requestFaucet(address: SuiAddress, network: FaucetNetworkType) {
|
|
261
|
+
await requestSuiFromFaucetV0({
|
|
262
|
+
host: getFaucetHost(network),
|
|
263
|
+
recipient: address,
|
|
264
|
+
});
|
|
265
|
+
// let params = {
|
|
266
|
+
// owner: address
|
|
267
|
+
// } as GetBalanceParams;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Infer } from 'superstruct';
|
|
2
|
+
import {
|
|
3
|
+
getObjectChanges,
|
|
4
|
+
SuiTransactionBlockResponse,
|
|
5
|
+
ObjectCallArg,
|
|
6
|
+
ObjectId,
|
|
7
|
+
} from '@mysten/sui.js';
|
|
8
|
+
|
|
9
|
+
export class SuiOwnedObject {
|
|
10
|
+
public readonly objectId: string;
|
|
11
|
+
public version?: number | string;
|
|
12
|
+
public digest?: string;
|
|
13
|
+
|
|
14
|
+
constructor(param: { objectId: string; version?: string; digest?: string }) {
|
|
15
|
+
this.objectId = param.objectId;
|
|
16
|
+
this.version = param.version;
|
|
17
|
+
this.digest = param.digest;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check if the object is fully initialized.
|
|
22
|
+
* So that when it's used as an input, it won't be necessary to fetch from fullnode again.
|
|
23
|
+
* Which can save time when sending transactions.
|
|
24
|
+
*/
|
|
25
|
+
isFullObject(): boolean {
|
|
26
|
+
return !!this.version && !!this.digest;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {
|
|
30
|
+
if (!this.version || !this.digest) {
|
|
31
|
+
return this.objectId;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
Object: {
|
|
35
|
+
ImmOrOwned: {
|
|
36
|
+
objectId: this.objectId,
|
|
37
|
+
version: this.version,
|
|
38
|
+
digest: this.digest,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Update object version & digest based on the transaction response.
|
|
46
|
+
* @param txResponse
|
|
47
|
+
*/
|
|
48
|
+
updateFromTxResponse(txResponse: SuiTransactionBlockResponse) {
|
|
49
|
+
const changes = getObjectChanges(txResponse);
|
|
50
|
+
if (!changes) {
|
|
51
|
+
throw new Error('Bad transaction response!');
|
|
52
|
+
}
|
|
53
|
+
for (const change of changes) {
|
|
54
|
+
if (change.type === 'mutated' && change.objectId === this.objectId) {
|
|
55
|
+
this.digest = change.digest;
|
|
56
|
+
this.version = change.version;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw new Error('Could not find object in transaction response!');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Infer } from 'superstruct';
|
|
2
|
+
import { ObjectCallArg, ObjectId } from '@mysten/sui.js';
|
|
3
|
+
|
|
4
|
+
export class SuiSharedObject {
|
|
5
|
+
public readonly objectId: string;
|
|
6
|
+
public initialSharedVersion?: number | string;
|
|
7
|
+
|
|
8
|
+
constructor(param: {
|
|
9
|
+
objectId: string;
|
|
10
|
+
initialSharedVersion?: number;
|
|
11
|
+
mutable?: boolean;
|
|
12
|
+
}) {
|
|
13
|
+
this.objectId = param.objectId;
|
|
14
|
+
this.initialSharedVersion = param.initialSharedVersion;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
asCallArg(
|
|
18
|
+
mutable: boolean = false
|
|
19
|
+
): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {
|
|
20
|
+
if (!this.initialSharedVersion) {
|
|
21
|
+
return this.objectId;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
Object: {
|
|
25
|
+
Shared: {
|
|
26
|
+
objectId: this.objectId,
|
|
27
|
+
initialSharedVersion: this.initialSharedVersion,
|
|
28
|
+
mutable,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ObjectCallArg,
|
|
11
11
|
} from '@mysten/sui.js';
|
|
12
12
|
import { convertArgs } from './util';
|
|
13
|
-
import type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from '
|
|
13
|
+
import type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from 'src/types';
|
|
14
14
|
|
|
15
15
|
export class SuiTxBlock {
|
|
16
16
|
public txBlock: TransactionBlock;
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
TransactionArgument,
|
|
4
4
|
TransactionBlock,
|
|
5
5
|
} from '@mysten/sui.js';
|
|
6
|
-
import { SuiTxArg, SuiInputTypes } from '
|
|
6
|
+
import { SuiTxArg, SuiInputTypes } from 'src/types';
|
|
7
7
|
|
|
8
8
|
export const getDefaultSuiInputType = (value: any): SuiInputTypes => {
|
|
9
9
|
if (typeof value === 'string' && value.startsWith('0x')) {
|
package/src/metadata/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { SuiMoveNormalizedModules } from '@mysten/sui.js';
|
|
2
|
-
import {
|
|
3
|
-
import { NetworkType } from '../libs/suiRpcProvider/types';
|
|
2
|
+
import { SuiInteractor, getDefaultConnection } from '../libs/suiInteractor';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
const rpcProvider = new SuiRpcProvider({
|
|
7
|
-
networkType,
|
|
8
|
-
});
|
|
4
|
+
import { NetworkType } from 'src/types';
|
|
9
5
|
|
|
6
|
+
export async function getMetadata(networkType: NetworkType, packageId: string) {
|
|
7
|
+
// Init the rpc provider
|
|
8
|
+
const fullnodeUrls = [getDefaultConnection(networkType).fullnode];
|
|
9
|
+
const suiInteractor = new SuiInteractor(fullnodeUrls);
|
|
10
10
|
if (packageId !== undefined) {
|
|
11
|
-
const jsonData = await
|
|
11
|
+
const jsonData = await suiInteractor.getNormalizedMoveModulesByPackage(packageId);
|
|
12
12
|
|
|
13
13
|
return jsonData as SuiMoveNormalizedModules;
|
|
14
14
|
} else {
|