suidouble 2.5.0 → 2.16.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/.claude/settings.local.json +7 -0
- package/README.md +222 -131
- package/index.js +0 -2
- package/lib/SuiCliCommands.js +18 -25
- package/lib/SuiCoin.js +79 -137
- package/lib/SuiCoins.js +41 -29
- package/lib/SuiCommonMethods.js +40 -3
- package/lib/SuiEvent.js +54 -6
- package/lib/SuiInBrowser.js +143 -15
- package/lib/SuiInBrowserAdapter.js +164 -37
- package/lib/SuiLocalTestValidator.js +76 -14
- package/lib/SuiMaster.js +335 -139
- package/lib/SuiMemoryObjectStorage.js +66 -73
- package/lib/SuiObject.js +128 -153
- package/lib/SuiPackage.js +292 -187
- package/lib/SuiPackageModule.js +176 -221
- package/lib/SuiPaginatedResponse.js +288 -25
- package/lib/SuiPseudoRandomAddress.js +29 -2
- package/lib/SuiTransaction.js +115 -70
- package/lib/SuiUtils.js +179 -127
- package/package.json +29 -13
- package/test/build_modules.test.js +41 -0
- package/test/coins.test.js +17 -16
- package/test/custom_transaction.test.js +167 -0
- package/test/event_listeners.test.js +171 -0
- package/test/failed_transaction.test.js +184 -0
- package/test/name_service.test.js +28 -0
- package/test/owned_objects.test.js +148 -0
- package/test/rpc.test.js +3 -6
- package/test/sui_in_browser.test.js +2 -2
- package/test/sui_master_basic.test.js +4 -5
- package/test/sui_master_onlocal.test.js +84 -22
- package/test/sui_object_properties.test.js +85 -0
- package/tsconfig.json +15 -0
- package/types/index.d.ts +15 -0
- package/types/lib/SuiCliCommands.d.ts +6 -0
- package/types/lib/SuiCoin.d.ts +183 -0
- package/types/lib/SuiCoins.d.ts +93 -0
- package/types/lib/SuiCommonMethods.d.ts +37 -0
- package/types/lib/SuiEvent.d.ts +95 -0
- package/types/lib/SuiInBrowser.d.ts +189 -0
- package/types/lib/SuiInBrowserAdapter.d.ts +167 -0
- package/types/lib/SuiLocalTestValidator.d.ts +92 -0
- package/types/lib/SuiMaster.d.ts +333 -0
- package/types/lib/SuiMemoryObjectStorage.d.ts +96 -0
- package/types/lib/SuiObject.d.ts +135 -0
- package/types/lib/SuiPackage.d.ts +233 -0
- package/types/lib/SuiPackageModule.d.ts +139 -0
- package/types/lib/SuiPaginatedResponse.d.ts +148 -0
- package/types/lib/SuiPseudoRandomAddress.d.ts +33 -0
- package/types/lib/SuiTransaction.d.ts +92 -0
- package/types/lib/SuiUtils.d.ts +152 -0
- package/types/lib/data/icons.d.ts +12 -0
- package/lib/SuiTestScenario.js +0 -169
- package/test/sui_test_scenario.test.js +0 -61
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import t from 'tap';
|
|
4
|
+
import { SuiMaster, SuiLocalTestValidator } from '../index.js';
|
|
5
|
+
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
const { test } = t;
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
let suiLocalTestValidator = null;
|
|
14
|
+
let suiMaster = null;
|
|
15
|
+
let contract = null;
|
|
16
|
+
|
|
17
|
+
test('spawn local test node', async t => {
|
|
18
|
+
suiLocalTestValidator = await SuiLocalTestValidator.launch({ testFallbackEnabled: true });
|
|
19
|
+
t.ok(suiLocalTestValidator.active);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('setup — init, fund, publish', async t => {
|
|
23
|
+
suiMaster = new SuiMaster({ client: suiLocalTestValidator, as: 'somebody', debug: false });
|
|
24
|
+
await suiMaster.initialize();
|
|
25
|
+
|
|
26
|
+
await suiMaster.requestSuiFromFaucet();
|
|
27
|
+
|
|
28
|
+
contract = suiMaster.addPackage({
|
|
29
|
+
path: path.join(__dirname, './test_move_contracts/suidouble_chat/'),
|
|
30
|
+
});
|
|
31
|
+
await contract.build();
|
|
32
|
+
await contract.publish();
|
|
33
|
+
t.ok(contract.address, 'contract published');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('localProperties — stores arbitrary data without touching the chain', async t => {
|
|
37
|
+
const chatShop = suiMaster.objectStorage.findMostRecentByTypeName('ChatShop');
|
|
38
|
+
t.ok(chatShop, 'ChatShop found in objectStorage');
|
|
39
|
+
|
|
40
|
+
// initial state — empty object
|
|
41
|
+
t.type(chatShop.localProperties, 'object', 'localProperties is an object');
|
|
42
|
+
t.notOk(chatShop.localProperties.myKey, 'myKey not set initially');
|
|
43
|
+
|
|
44
|
+
// write
|
|
45
|
+
chatShop.localProperties.myKey = 'hello';
|
|
46
|
+
chatShop.localProperties.count = 42;
|
|
47
|
+
|
|
48
|
+
// read back from the same instance
|
|
49
|
+
t.equal(chatShop.localProperties.myKey, 'hello', 'myKey persists on the instance');
|
|
50
|
+
t.equal(chatShop.localProperties.count, 42, 'count persists on the instance');
|
|
51
|
+
|
|
52
|
+
// does NOT affect the object on chain — the object's fields are unrelated
|
|
53
|
+
t.notOk(chatShop.fields.myKey, 'myKey is not in on-chain fields');
|
|
54
|
+
|
|
55
|
+
// clear
|
|
56
|
+
delete chatShop.localProperties.myKey;
|
|
57
|
+
t.notOk(chatShop.localProperties.myKey, 'myKey removed after delete');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('isImmutable — published package object is immutable', async t => {
|
|
61
|
+
// packages are always frozen / immutable on Sui after publishing
|
|
62
|
+
const packageObj = await suiMaster.getObject(contract.address);
|
|
63
|
+
t.ok(packageObj, 'package object fetched');
|
|
64
|
+
t.ok(packageObj.isImmutable, 'package object isImmutable is true');
|
|
65
|
+
t.notOk(packageObj.isShared, 'package object isShared is false');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('display — fetchFields populates display property', async t => {
|
|
69
|
+
const chatShop = suiMaster.objectStorage.findMostRecentByTypeName('ChatShop');
|
|
70
|
+
t.ok(chatShop, 'ChatShop found');
|
|
71
|
+
|
|
72
|
+
await chatShop.fetchFields();
|
|
73
|
+
|
|
74
|
+
// display is always an object — {} when no Display template, otherwise keyed values
|
|
75
|
+
t.type(chatShop.display, 'object', 'display is an object after fetchFields');
|
|
76
|
+
|
|
77
|
+
// suidouble_chat has no Display template so we expect an empty map —
|
|
78
|
+
// but the field must exist and not throw
|
|
79
|
+
t.doesNotThrow(() => { void chatShop.display; }, 'accessing display does not throw');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('stops local test node', async t => {
|
|
83
|
+
await SuiLocalTestValidator.stop().catch(() => {});
|
|
84
|
+
t.pass('stopped');
|
|
85
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"emitDeclarationOnly": true,
|
|
6
|
+
"declarationDir": "./types",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"target": "ES2020",
|
|
10
|
+
"strict": false,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"checkJs": false
|
|
13
|
+
},
|
|
14
|
+
"include": ["index.js", "lib/*.js"]
|
|
15
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import SuiMaster from './lib/SuiMaster.js';
|
|
2
|
+
import SuiObject from './lib/SuiObject.js';
|
|
3
|
+
import SuiInBrowser from './lib/SuiInBrowser.js';
|
|
4
|
+
import SuiLocalTestValidator from './lib/SuiLocalTestValidator.js';
|
|
5
|
+
export const MIST_PER_SUI: bigint;
|
|
6
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
7
|
+
import { TransactionCommands as Commands } from '@mysten/sui/transactions';
|
|
8
|
+
import SuiUtils from './lib/SuiUtils.js';
|
|
9
|
+
export const txInput: typeof SuiUtils.txInput;
|
|
10
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
11
|
+
import SuiMemoryObjectStorage from './lib/SuiMemoryObjectStorage.js';
|
|
12
|
+
import SuiCoin from './lib/SuiCoin.js';
|
|
13
|
+
import SuiCoins from './lib/SuiCoins.js';
|
|
14
|
+
import SuiPaginatedResponse from './lib/SuiPaginatedResponse.js';
|
|
15
|
+
export { SuiMaster, SuiObject, SuiInBrowser, SuiLocalTestValidator, Transaction, Commands, SuiUtils, bcs, SuiMemoryObjectStorage, SuiCoin, SuiCoins, SuiPaginatedResponse };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export default class SuiCliCommands {
|
|
2
|
+
static isPortThere(port: any): Promise<any>;
|
|
3
|
+
static spawn(command: any, params?: any[], envVars?: {}): Promise<any>;
|
|
4
|
+
static exec(command: any): Promise<any>;
|
|
5
|
+
static getModulesNamesFromPackagePath(path: any): Promise<any>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("@mysten/sui/transactions").TransactionObjectArgument} TransactionObjectArgument
|
|
3
|
+
*
|
|
4
|
+
* @import { SuiClientTypes } from "@mysten/sui/client"
|
|
5
|
+
*
|
|
6
|
+
* @typedef CoinMeta
|
|
7
|
+
* @type {object}
|
|
8
|
+
* @property {number} decimals - Number of decimal places the coin uses.
|
|
9
|
+
* @property {string} description - Description of the token
|
|
10
|
+
* @property {string} iconUrl - URL for the token logo
|
|
11
|
+
* @property {string} name - Name for the token
|
|
12
|
+
* @property {string} symbol - Symbol for the token
|
|
13
|
+
* @property {string} [id] - Meta id
|
|
14
|
+
* @property {string} [type] - Coin type string
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @typedef {SuiClientTypes.Balance & { coin: SuiCoin, totalBalance: bigint }} SuidoubleCoinBalance
|
|
18
|
+
* @typedef {import("./SuiMaster.js").default} SuiMaster
|
|
19
|
+
* @typedef {import("./SuiCoins.js").default} SuiCoins
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Handle for a single coin type (e.g. `0x2::sui::SUI`). Caches metadata, formats amounts
|
|
23
|
+
* via decimals, and builds `Coin<T>` arguments for transactions.
|
|
24
|
+
*/
|
|
25
|
+
export default class SuiCoin {
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if the object looks like a usable CoinMeta (has positive `decimals`, `name`, `symbol`).
|
|
28
|
+
* @param {CoinMeta} meta
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
static isValidMetadata(meta: CoinMeta): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* SuiCoin constructor
|
|
34
|
+
* @param {Object} params - Initialization parameters
|
|
35
|
+
* @param {string} params.coinType - sui object type for a coin, without Coin<...>, only the inside type
|
|
36
|
+
* @param {SuiCoins} params.suiCoins - instance of SuiCoins
|
|
37
|
+
*/
|
|
38
|
+
constructor(params: {
|
|
39
|
+
coinType: string;
|
|
40
|
+
suiCoins: SuiCoins;
|
|
41
|
+
});
|
|
42
|
+
_coinType: string;
|
|
43
|
+
_suiCoins: import("./SuiCoins.js").default;
|
|
44
|
+
_exists: boolean;
|
|
45
|
+
_metadata: CoinMeta | SuiClientTypes.CoinMetadata;
|
|
46
|
+
/**
|
|
47
|
+
* Normalize amount based on .decimals. Pass a string with a dot ('5.22', '0.0005') to convert it to units
|
|
48
|
+
* always use a dot, event for '1.0' or '100.0'.
|
|
49
|
+
* @param {String|Number|BigInt} amount
|
|
50
|
+
* @returns {BigInt}
|
|
51
|
+
*/
|
|
52
|
+
normalizeAmount(amount: string | number | bigint): bigint;
|
|
53
|
+
/**
|
|
54
|
+
* Normalize amount based on .decimals. Pass a string with a dot ('5.22', '0.0005') to convert it to units. No worries about loading metadata first.
|
|
55
|
+
* @param {String|Number|bigint} amount
|
|
56
|
+
* @returns {Promise.<bigint>}
|
|
57
|
+
*/
|
|
58
|
+
lazyNormalizeAmount(amount: string | number | bigint): Promise<bigint>;
|
|
59
|
+
/**
|
|
60
|
+
* Get readable representation of a raw amount (bigint-native, NOT a pre-formatted "1.99" string),
|
|
61
|
+
* based on coin decimals metadata (requires metadata to be loaded or set).
|
|
62
|
+
*
|
|
63
|
+
* @param {bigint|number|string} amount - raw amount in the coin's base units
|
|
64
|
+
* @param {Object} [options] - format options
|
|
65
|
+
* @param {boolean} [options.withAbbr] - append K/M/B/T for large amounts (Suiet-style)
|
|
66
|
+
* @param {boolean|string} [options.separateThousands] - separate thousands by `,` (true) or by a custom delimiter
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
amountToString(amount: bigint | number | string, options?: {
|
|
70
|
+
withAbbr?: boolean;
|
|
71
|
+
separateThousands?: boolean | string;
|
|
72
|
+
}): string;
|
|
73
|
+
/**
|
|
74
|
+
* Format large amounts.
|
|
75
|
+
*
|
|
76
|
+
* thanks @bruceeewong and @suiet
|
|
77
|
+
*
|
|
78
|
+
* @param {bigint} amount
|
|
79
|
+
* @param {bigint} measureUnit - divisor for the unit (1_000n for K, 1_000_000n for M, …)
|
|
80
|
+
* @param {string} abbrSymbol - suffix to append (K, M, B, T)
|
|
81
|
+
* @param {boolean|string} [separateThousands=false] - separate thousands by `,` (true) or by a custom delimiter
|
|
82
|
+
* @returns {string}
|
|
83
|
+
*/
|
|
84
|
+
formatWithAbbr(amount: bigint, measureUnit: bigint, abbrSymbol: string, separateThousands?: boolean | string): string;
|
|
85
|
+
/**
|
|
86
|
+
* @type {SuiMaster}
|
|
87
|
+
*/
|
|
88
|
+
get suiMaster(): SuiMaster;
|
|
89
|
+
/** @returns {string} coin type string, always prefixed with `0x` */
|
|
90
|
+
get coinType(): string;
|
|
91
|
+
/**
|
|
92
|
+
* Move type for the Coin object of this coin type
|
|
93
|
+
*
|
|
94
|
+
* @type {string}
|
|
95
|
+
*/
|
|
96
|
+
get coinObjectType(): string;
|
|
97
|
+
/** @returns {number | undefined} decimals from loaded metadata, or `undefined` if not yet loaded */
|
|
98
|
+
get decimals(): number | undefined;
|
|
99
|
+
/** @returns {?CoinMeta} loaded coin metadata, or null if not loaded */
|
|
100
|
+
get metadata(): CoinMeta | null;
|
|
101
|
+
/** @returns {?string} coin symbol from metadata, or null if metadata isn't loaded */
|
|
102
|
+
get symbol(): string | null;
|
|
103
|
+
/** @returns {?string} coin name from metadata, or null if metadata isn't loaded */
|
|
104
|
+
get name(): string | null;
|
|
105
|
+
/**
|
|
106
|
+
* True if this coin's type is the normalized SUI type (`0x2::sui::SUI` expanded to 64 hex chars).
|
|
107
|
+
* @returns {boolean}
|
|
108
|
+
*/
|
|
109
|
+
isSUI(): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* set predefined coin metadata so it will not be fetched from RPC
|
|
112
|
+
* @param {CoinMeta} meta
|
|
113
|
+
*
|
|
114
|
+
* @returns {boolean} if processed ok
|
|
115
|
+
*/
|
|
116
|
+
setMetadata(meta: CoinMeta): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Load coin metadata from the blockchain. Concurrent callers share the same in-flight request.
|
|
119
|
+
* As a good pattern, prefer hard-coded / cached metadata set via `suiMaster.suiCoins.setCoinMetas(...)`.
|
|
120
|
+
*
|
|
121
|
+
* @returns {Promise<?CoinMeta>} resolved metadata, or `null` if the coin type has none on chain
|
|
122
|
+
*/
|
|
123
|
+
getMetadata(): Promise<CoinMeta | null>;
|
|
124
|
+
__getMetadataResolver: (value: any) => void;
|
|
125
|
+
__getMetadataPromise: Promise<any>;
|
|
126
|
+
/**
|
|
127
|
+
* Get coin balance of the wallet
|
|
128
|
+
* @param {string} owner
|
|
129
|
+
*
|
|
130
|
+
* @returns {Promise.<bigint>}
|
|
131
|
+
*/
|
|
132
|
+
getBalance(owner: string): Promise<bigint>;
|
|
133
|
+
/**
|
|
134
|
+
* Return a TransactionObjectArgument with a Coin of the requested amount, ready to use in moveCall.
|
|
135
|
+
* Delegates to the v2 SDK's `tx.coinWithBalance` intent, which at build time fetches all owned
|
|
136
|
+
* coins of this type, merges them (including zero-balance dust), and splits off the requested amount.
|
|
137
|
+
*
|
|
138
|
+
* @param {Transaction} txb - Native SUI SDK Transaction
|
|
139
|
+
* @param {string} _owner - unused; kept for signature compatibility. The resolver picks coins owned by the tx sender.
|
|
140
|
+
* @param {BigInt|string} amount - amount of coin. BigInt or string normalized via Coin decimals ("0.05" → 0.05 SUI)
|
|
141
|
+
* @returns {Promise.<TransactionObjectArgument>}
|
|
142
|
+
*/
|
|
143
|
+
coinOfAmountToTxCoin(txb: Transaction, _owner: string, amount: bigint | string): Promise<TransactionObjectArgument>;
|
|
144
|
+
}
|
|
145
|
+
export type TransactionObjectArgument = import("@mysten/sui/transactions").TransactionObjectArgument;
|
|
146
|
+
export type CoinMeta = {
|
|
147
|
+
/**
|
|
148
|
+
* - Number of decimal places the coin uses.
|
|
149
|
+
*/
|
|
150
|
+
decimals: number;
|
|
151
|
+
/**
|
|
152
|
+
* - Description of the token
|
|
153
|
+
*/
|
|
154
|
+
description: string;
|
|
155
|
+
/**
|
|
156
|
+
* - URL for the token logo
|
|
157
|
+
*/
|
|
158
|
+
iconUrl: string;
|
|
159
|
+
/**
|
|
160
|
+
* - Name for the token
|
|
161
|
+
*/
|
|
162
|
+
name: string;
|
|
163
|
+
/**
|
|
164
|
+
* - Symbol for the token
|
|
165
|
+
*/
|
|
166
|
+
symbol: string;
|
|
167
|
+
/**
|
|
168
|
+
* - Meta id
|
|
169
|
+
*/
|
|
170
|
+
id?: string;
|
|
171
|
+
/**
|
|
172
|
+
* - Coin type string
|
|
173
|
+
*/
|
|
174
|
+
type?: string;
|
|
175
|
+
};
|
|
176
|
+
export type SuidoubleCoinBalance = SuiClientTypes.Balance & {
|
|
177
|
+
coin: SuiCoin;
|
|
178
|
+
totalBalance: bigint;
|
|
179
|
+
};
|
|
180
|
+
export type SuiMaster = import("./SuiMaster.js").default;
|
|
181
|
+
export type SuiCoins = import("./SuiCoins.js").default;
|
|
182
|
+
import type { SuiClientTypes } from "@mysten/sui/client";
|
|
183
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("./SuiCoin.js").CoinMeta} CoinMeta
|
|
3
|
+
* @typedef {import("./SuiCoin.js").SuidoubleCoinBalance} SuidoubleCoinBalance
|
|
4
|
+
* @typedef {import("./SuiMaster.js").default} SuiMaster
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Common class to work with Coins and Coin objects. Expected to have single instance per SuiMaster instance
|
|
8
|
+
* @class
|
|
9
|
+
* @constructor
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export default class SuiCoins extends SuiCommonMethods {
|
|
13
|
+
/**
|
|
14
|
+
* Fetch the mainnet coin metadata bundle from `coinmeta.polymedia.app` and cache the promise so
|
|
15
|
+
* concurrent callers share a single request. Failures are swallowed and resolve to an empty array.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Promise<Array.<CoinMeta>>} list of CoinMeta records, or an empty array on failure
|
|
18
|
+
*/
|
|
19
|
+
static prefetchMainnetCoinMetas(): Promise<Array<CoinMeta>>;
|
|
20
|
+
static _singleInstances: {};
|
|
21
|
+
/**
|
|
22
|
+
* Return singleton instance of the SuiCoins object for the specific chain
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} params - parameters
|
|
25
|
+
* @param {SuiMaster} params.suiMaster - instance of SuiMaster
|
|
26
|
+
* @returns {SuiCoins}
|
|
27
|
+
*/
|
|
28
|
+
static getSingleton(params: {
|
|
29
|
+
suiMaster: SuiMaster;
|
|
30
|
+
}): SuiCoins;
|
|
31
|
+
/**
|
|
32
|
+
* SuiCoins constructor
|
|
33
|
+
* @param {Object} params - Initialization parameters
|
|
34
|
+
* @param {SuiMaster} params.suiMaster - instance of SuiMaster
|
|
35
|
+
* @param {boolean} [params.debug]
|
|
36
|
+
*/
|
|
37
|
+
constructor(params: {
|
|
38
|
+
suiMaster: SuiMaster;
|
|
39
|
+
debug?: boolean;
|
|
40
|
+
});
|
|
41
|
+
/** @type {SuiMaster} */
|
|
42
|
+
_suiMaster: SuiMaster;
|
|
43
|
+
/** @type {Object.<string, SuiCoin>} */
|
|
44
|
+
_coins: {
|
|
45
|
+
[x: string]: SuiCoin;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* @type {SuiMaster}
|
|
49
|
+
*/
|
|
50
|
+
get suiMaster(): SuiMaster;
|
|
51
|
+
/** @returns {Object.<string, SuiCoin>} map of coinType → SuiCoin instance */
|
|
52
|
+
get coins(): {
|
|
53
|
+
[x: string]: SuiCoin;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Set predefined coin metas so they will not need to be fetched from RPC.
|
|
57
|
+
*
|
|
58
|
+
* @param {Object.<string, CoinMeta> | Array.<CoinMeta>} coinMetas - keyed map by coin type, or an array of CoinMeta with `type` field
|
|
59
|
+
* @returns {number} count of processed items
|
|
60
|
+
*/
|
|
61
|
+
setCoinMetas(coinMetas: {
|
|
62
|
+
[x: string]: CoinMeta;
|
|
63
|
+
} | Array<CoinMeta>): number;
|
|
64
|
+
/**
|
|
65
|
+
* Get all CoinBalance[] for the specific address or connected address.
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} [params]
|
|
68
|
+
* @param {?string} [params.owner] - owner address; if omitted, uses the connected SuiMaster address
|
|
69
|
+
* @returns {Promise<Array<SuidoubleCoinBalance>>}
|
|
70
|
+
*/
|
|
71
|
+
getAllBalances(params?: {
|
|
72
|
+
owner?: string | null;
|
|
73
|
+
}): Promise<Array<SuidoubleCoinBalance>>;
|
|
74
|
+
/**
|
|
75
|
+
* normalize coinType string to sui's coin type. As extra, may take 'sui' or 'SUI' as the type and return type for it
|
|
76
|
+
* @param {string} coinType
|
|
77
|
+
* @returns {string} normalized coin type
|
|
78
|
+
*/
|
|
79
|
+
normalizeCoinType(coinType: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Return instance of SuiCoin of specific type. The result is cached per normalized coin type,
|
|
82
|
+
* so repeated calls with equivalent inputs return the same instance.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} coinType - MoveType, or 'SUI' as helper
|
|
85
|
+
* @returns {SuiCoin}
|
|
86
|
+
*/
|
|
87
|
+
get(coinType: string): SuiCoin;
|
|
88
|
+
}
|
|
89
|
+
export type CoinMeta = import("./SuiCoin.js").CoinMeta;
|
|
90
|
+
export type SuidoubleCoinBalance = import("./SuiCoin.js").SuidoubleCoinBalance;
|
|
91
|
+
export type SuiMaster = import("./SuiMaster.js").default;
|
|
92
|
+
import SuiCommonMethods from './SuiCommonMethods.js';
|
|
93
|
+
import SuiCoin from './SuiCoin.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for suidouble domain objects. Extends `EventTarget` so subclasses can emit
|
|
3
|
+
* events via `this.emit(...)` and consumers can subscribe via `addEventListener(...)`.
|
|
4
|
+
* Also provides a debug-gated `log(...)` helper.
|
|
5
|
+
*/
|
|
6
|
+
export default class SuiCommonMethods extends EventTarget {
|
|
7
|
+
/**
|
|
8
|
+
* @param {Object} [params]
|
|
9
|
+
* @param {boolean} [params.debug] - enable debug logging via `log(...)`
|
|
10
|
+
*/
|
|
11
|
+
constructor(params?: {
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
});
|
|
14
|
+
_debug: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Debug logger. No-op unless the instance was constructed with `debug: true`.
|
|
17
|
+
* Prefixes messages with the owning SuiMaster's instance number (if available) and the class name.
|
|
18
|
+
* @param {...any} args
|
|
19
|
+
*/
|
|
20
|
+
log(...args: any[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Dispatch an event to registered `addEventListener` subscribers.
|
|
23
|
+
*
|
|
24
|
+
* If `data` is a `SuiEvent` (has `isSuiEvent === true`) and `forceCustom` is falsy, it is dispatched
|
|
25
|
+
* directly so its own `.type` (the Move event name) is used — this lets consumers
|
|
26
|
+
* `addEventListener('ChatShopCreated', …)` without wrapping. Otherwise dispatches a `CustomEvent`
|
|
27
|
+
* of type `eventType` with `data` placed on the event's `detail` field.
|
|
28
|
+
*
|
|
29
|
+
* Any dispatch errors are caught and logged to `console.error` so a buggy listener can't abort the
|
|
30
|
+
* surrounding flow.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} eventType - event name when wrapping in a CustomEvent (ignored for direct SuiEvent dispatch)
|
|
33
|
+
* @param {*} data - payload; SuiEvent is dispatched directly, anything else is wrapped
|
|
34
|
+
* @param {boolean} [forceCustom=false] - if true, always wrap in a CustomEvent even for SuiEvent payloads
|
|
35
|
+
*/
|
|
36
|
+
emit(eventType: string, data: any, forceCustom?: boolean): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("./SuiMaster.js").default} SuiMaster
|
|
3
|
+
*
|
|
4
|
+
* @typedef SuiEventData
|
|
5
|
+
* @type {object}
|
|
6
|
+
* @property {string} [type] - Fully-qualified Move type of the event, e.g. `<pkg>::<module>::<EventName>`
|
|
7
|
+
* @property {Object} [parsedJson] - JSON representation of the event's Move struct contents
|
|
8
|
+
* @property {string|number} [timestampMs] - Timestamp (ms since epoch) of the checkpoint the event's tx was finalized in
|
|
9
|
+
* @property {string} [sender] - SuiAddress of the sender of the emitting transaction
|
|
10
|
+
* @property {string} [transactionDigest] - Digest of the emitting transaction
|
|
11
|
+
* @property {string|number} [sequenceNumber] - Event position within its transaction
|
|
12
|
+
* @property {string|Uint8Array} [bcs] - BCS bytes (base64 string from GraphQL, Uint8Array from gRPC)
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Wrapper over a Sui event. Extends the native `Event` so it can be dispatched through
|
|
16
|
+
* `EventTarget`-style listeners; also exposes the common Sui event fields directly.
|
|
17
|
+
*/
|
|
18
|
+
export default class SuiEvent extends Event {
|
|
19
|
+
/**
|
|
20
|
+
* @param {Object} params - Initialization parameters
|
|
21
|
+
* @param {SuiMaster} params.suiMaster - instance of SuiMaster
|
|
22
|
+
* @param {SuiEventData} [params.data] - raw event data
|
|
23
|
+
* @param {boolean} [params.debug] - enable debug logging
|
|
24
|
+
*/
|
|
25
|
+
constructor(params: {
|
|
26
|
+
suiMaster: SuiMaster;
|
|
27
|
+
data?: SuiEventData;
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
});
|
|
30
|
+
_debug: boolean;
|
|
31
|
+
/** @type {SuiMaster} */
|
|
32
|
+
_suiMaster: SuiMaster;
|
|
33
|
+
/** @type {SuiEventData} */
|
|
34
|
+
_data: SuiEventData;
|
|
35
|
+
detail: this;
|
|
36
|
+
/**
|
|
37
|
+
* Debug logger. No-op unless the instance was constructed with `debug: true`.
|
|
38
|
+
* Prefixes messages with the SuiMaster instance number and the class name.
|
|
39
|
+
* @param {...any} args
|
|
40
|
+
*/
|
|
41
|
+
log(...args: any[]): void;
|
|
42
|
+
/** Brand property for duck-typing. @returns {true} */
|
|
43
|
+
get isSuiEvent(): true;
|
|
44
|
+
/**
|
|
45
|
+
* In-module type name — last segment of `package::module::Name<...>`, without package/module prefix or `<T..>` suffix.
|
|
46
|
+
* @returns {?string}
|
|
47
|
+
*/
|
|
48
|
+
get typeName(): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Raw event data as received from the client.
|
|
51
|
+
* @returns {SuiEventData}
|
|
52
|
+
*/
|
|
53
|
+
get data(): SuiEventData;
|
|
54
|
+
/**
|
|
55
|
+
* JSON representation of the event's Move struct contents.
|
|
56
|
+
* @returns {?Object}
|
|
57
|
+
*/
|
|
58
|
+
get parsedJson(): any | null;
|
|
59
|
+
/**
|
|
60
|
+
* Timestamp (milliseconds since epoch) of the checkpoint the emitting transaction was finalized in.
|
|
61
|
+
* @returns {?number}
|
|
62
|
+
*/
|
|
63
|
+
get timestampMs(): number | null;
|
|
64
|
+
}
|
|
65
|
+
export type SuiMaster = import("./SuiMaster.js").default;
|
|
66
|
+
export type SuiEventData = {
|
|
67
|
+
/**
|
|
68
|
+
* - Fully-qualified Move type of the event, e.g. `<pkg>::<module>::<EventName>`
|
|
69
|
+
*/
|
|
70
|
+
type?: string;
|
|
71
|
+
/**
|
|
72
|
+
* - JSON representation of the event's Move struct contents
|
|
73
|
+
*/
|
|
74
|
+
parsedJson?: any;
|
|
75
|
+
/**
|
|
76
|
+
* - Timestamp (ms since epoch) of the checkpoint the event's tx was finalized in
|
|
77
|
+
*/
|
|
78
|
+
timestampMs?: string | number;
|
|
79
|
+
/**
|
|
80
|
+
* - SuiAddress of the sender of the emitting transaction
|
|
81
|
+
*/
|
|
82
|
+
sender?: string;
|
|
83
|
+
/**
|
|
84
|
+
* - Digest of the emitting transaction
|
|
85
|
+
*/
|
|
86
|
+
transactionDigest?: string;
|
|
87
|
+
/**
|
|
88
|
+
* - Event position within its transaction
|
|
89
|
+
*/
|
|
90
|
+
sequenceNumber?: string | number;
|
|
91
|
+
/**
|
|
92
|
+
* - BCS bytes (base64 string from GraphQL, Uint8Array from gRPC)
|
|
93
|
+
*/
|
|
94
|
+
bcs?: string | Uint8Array;
|
|
95
|
+
};
|