@easysui/sdk 1.1.0 → 1.2.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.d.mts +21 -12
- package/dist/index.d.ts +21 -12
- package/dist/index.js +67 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -2,12 +2,13 @@ import path from 'path';
|
|
|
2
2
|
import * as fs3 from 'fs';
|
|
3
3
|
import fs3__default from 'fs';
|
|
4
4
|
import dotenv from 'dotenv';
|
|
5
|
-
import { getJsonRpcFullnodeUrl
|
|
5
|
+
import { getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';
|
|
6
6
|
import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
|
|
7
7
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
8
8
|
import { Secp256k1Keypair } from '@mysten/sui/keypairs/secp256k1';
|
|
9
9
|
import { Secp256r1Keypair } from '@mysten/sui/keypairs/secp256r1';
|
|
10
10
|
import { SUI_CLOCK_OBJECT_ID, fromHex, fromBase64, toBase64, normalizeStructTag, deriveObjectID, toHex } from '@mysten/sui/utils';
|
|
11
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
11
12
|
import { Transaction, coinWithBalance } from '@mysten/sui/transactions';
|
|
12
13
|
import { bcs } from '@mysten/sui/bcs';
|
|
13
14
|
import { spawn } from 'child_process';
|
|
@@ -1635,16 +1636,11 @@ var MoveType = /* @__PURE__ */ ((MoveType2) => {
|
|
|
1635
1636
|
MoveType2[MoveType2["vec_u64"] = 14] = "vec_u64";
|
|
1636
1637
|
return MoveType2;
|
|
1637
1638
|
})(MoveType || {});
|
|
1638
|
-
var txOptions = {
|
|
1639
|
-
showEffects: true,
|
|
1640
|
-
showObjectChanges: true,
|
|
1641
|
-
showBalanceChanges: true
|
|
1642
|
-
};
|
|
1643
1639
|
var SuiClient = class _SuiClient {
|
|
1644
1640
|
static instance = null;
|
|
1645
1641
|
client;
|
|
1646
1642
|
constructor() {
|
|
1647
|
-
this.client = new
|
|
1643
|
+
this.client = new SuiGrpcClient({ baseUrl: Config.vars.RPC, network: Config.vars.NETWORK });
|
|
1648
1644
|
}
|
|
1649
1645
|
static getInstance() {
|
|
1650
1646
|
if (!_SuiClient.instance) {
|
|
@@ -1656,20 +1652,31 @@ var SuiClient = class _SuiClient {
|
|
|
1656
1652
|
return this.getInstance().client;
|
|
1657
1653
|
}
|
|
1658
1654
|
static async waitForTransaction(ptb, resp) {
|
|
1659
|
-
await _SuiClient.client.waitForTransaction({ digest: resp.digest });
|
|
1660
|
-
if (resp.
|
|
1655
|
+
await _SuiClient.client.core.waitForTransaction({ digest: resp.digest });
|
|
1656
|
+
if (!resp.status.success) {
|
|
1661
1657
|
throw new Error(JSON.stringify(resp));
|
|
1662
1658
|
}
|
|
1663
1659
|
analyze_cost(ptb, resp);
|
|
1664
1660
|
return resp;
|
|
1665
1661
|
}
|
|
1666
1662
|
static async signAndExecute(ptb, signer) {
|
|
1667
|
-
const
|
|
1663
|
+
const result = await _SuiClient.client.core.signAndExecuteTransaction({
|
|
1668
1664
|
transaction: ptb,
|
|
1669
1665
|
signer,
|
|
1670
|
-
|
|
1666
|
+
include: {
|
|
1667
|
+
effects: true,
|
|
1668
|
+
events: true,
|
|
1669
|
+
balanceChanges: true,
|
|
1670
|
+
objectTypes: true,
|
|
1671
|
+
transaction: true,
|
|
1672
|
+
bcs: true
|
|
1673
|
+
}
|
|
1671
1674
|
});
|
|
1672
|
-
|
|
1675
|
+
const tx = result.Transaction ?? result.FailedTransaction;
|
|
1676
|
+
if (!tx) {
|
|
1677
|
+
throw new Error("Transaction failed with no response");
|
|
1678
|
+
}
|
|
1679
|
+
return _SuiClient.waitForTransaction(ptb, tx);
|
|
1673
1680
|
}
|
|
1674
1681
|
static toMoveArg(ptb, value, type3) {
|
|
1675
1682
|
if (typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -1760,11 +1767,14 @@ var SuiClient = class _SuiClient {
|
|
|
1760
1767
|
gasOwnerSignature = await this.getSignature(gasOwnerSignature, transactionBlock);
|
|
1761
1768
|
signature.push(gasOwnerSignature);
|
|
1762
1769
|
}
|
|
1763
|
-
const
|
|
1764
|
-
|
|
1765
|
-
signature
|
|
1766
|
-
options: txOptions
|
|
1770
|
+
const result = await _SuiClient.client.core.executeTransaction({
|
|
1771
|
+
transaction: transactionBlock,
|
|
1772
|
+
signatures: signature
|
|
1767
1773
|
});
|
|
1774
|
+
const resp = result.Transaction ?? result.FailedTransaction;
|
|
1775
|
+
if (!resp) {
|
|
1776
|
+
throw new Error("Transaction execution failed with no response");
|
|
1777
|
+
}
|
|
1768
1778
|
const ptb = Transaction.from(toBase64(transactionBlock));
|
|
1769
1779
|
return _SuiClient.waitForTransaction(ptb, resp);
|
|
1770
1780
|
}
|
|
@@ -1786,14 +1796,20 @@ var SuiClient = class _SuiClient {
|
|
|
1786
1796
|
return await _SuiClient.signAndExecute(tx, from);
|
|
1787
1797
|
}
|
|
1788
1798
|
static async devInspect(ptb, sender) {
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1799
|
+
ptb.setSender(sender);
|
|
1800
|
+
return await _SuiClient.client.core.simulateTransaction({
|
|
1801
|
+
transaction: ptb,
|
|
1802
|
+
checksEnabled: false,
|
|
1803
|
+
include: { commandResults: true }
|
|
1792
1804
|
});
|
|
1793
1805
|
}
|
|
1794
1806
|
static async devInspectRaw(ptb, sender) {
|
|
1795
1807
|
const result = await this.devInspect(ptb, sender);
|
|
1796
|
-
|
|
1808
|
+
const commandResult = result.commandResults?.[0];
|
|
1809
|
+
if (!commandResult || !commandResult.returnValues?.[0]) {
|
|
1810
|
+
return void 0;
|
|
1811
|
+
}
|
|
1812
|
+
return commandResult.returnValues[0];
|
|
1797
1813
|
}
|
|
1798
1814
|
static async devInspectBool(ptb, sender) {
|
|
1799
1815
|
const result = await this.devInspectRaw(ptb, sender);
|
|
@@ -1819,24 +1835,25 @@ var SuiClient = class _SuiClient {
|
|
|
1819
1835
|
return bcs.string().parse(new Uint8Array(value));
|
|
1820
1836
|
}
|
|
1821
1837
|
static async getObject(id) {
|
|
1822
|
-
return _SuiClient.client.getObject({
|
|
1823
|
-
id,
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1838
|
+
return _SuiClient.client.core.getObject({
|
|
1839
|
+
objectId: id,
|
|
1840
|
+
include: {
|
|
1841
|
+
content: true,
|
|
1842
|
+
type: true,
|
|
1843
|
+
display: true,
|
|
1844
|
+
bcs: true
|
|
1829
1845
|
}
|
|
1830
1846
|
});
|
|
1831
1847
|
}
|
|
1832
1848
|
static async getObjectsByType(owner, type3) {
|
|
1833
|
-
const res = await _SuiClient.client.
|
|
1849
|
+
const res = await _SuiClient.client.core.listOwnedObjects({
|
|
1834
1850
|
owner,
|
|
1835
|
-
|
|
1836
|
-
|
|
1851
|
+
type: type3,
|
|
1852
|
+
include: {
|
|
1853
|
+
content: true
|
|
1837
1854
|
}
|
|
1838
1855
|
});
|
|
1839
|
-
return res.
|
|
1856
|
+
return res.objects.map((o) => o.objectId).filter((o) => o);
|
|
1840
1857
|
}
|
|
1841
1858
|
};
|
|
1842
1859
|
|
|
@@ -16236,24 +16253,27 @@ var Coin = class {
|
|
|
16236
16253
|
throw new Error("`coinType` getter must be implemented !");
|
|
16237
16254
|
}
|
|
16238
16255
|
static async getBalance(owner) {
|
|
16239
|
-
const result = await SuiClient.client.
|
|
16240
|
-
owner
|
|
16241
|
-
coinType: this.coinType
|
|
16256
|
+
const result = await SuiClient.client.core.listBalances({
|
|
16257
|
+
owner
|
|
16242
16258
|
});
|
|
16243
|
-
|
|
16259
|
+
const balance = result.balances.find((b) => b.coinType === this.coinType);
|
|
16260
|
+
return BigInt(balance?.balance || 0);
|
|
16244
16261
|
}
|
|
16245
|
-
static
|
|
16246
|
-
|
|
16247
|
-
const tx = new Transaction();
|
|
16248
|
-
const coinSplit = coinWithBalance({
|
|
16262
|
+
static coinWithBalance(balance) {
|
|
16263
|
+
return coinWithBalance({
|
|
16249
16264
|
balance,
|
|
16250
16265
|
useGasCoin: false,
|
|
16251
16266
|
type: this.coinType
|
|
16252
16267
|
});
|
|
16268
|
+
}
|
|
16269
|
+
static async getCoin(owner, amount) {
|
|
16270
|
+
const balance = amount || await this.getBalance(owner.toSuiAddress());
|
|
16271
|
+
const tx = new Transaction();
|
|
16272
|
+
const coinSplit = this.coinWithBalance(balance);
|
|
16253
16273
|
tx.transferObjects([coinSplit], owner.toSuiAddress());
|
|
16254
16274
|
const result = await SuiClient.signAndExecute(tx, owner);
|
|
16255
|
-
const coin = result.
|
|
16256
|
-
(o) => o.
|
|
16275
|
+
const coin = result.effects?.changedObjects?.find(
|
|
16276
|
+
(o) => o.idOperation === "Created"
|
|
16257
16277
|
);
|
|
16258
16278
|
return coin?.objectId;
|
|
16259
16279
|
}
|
|
@@ -16282,9 +16302,8 @@ var Coin = class {
|
|
|
16282
16302
|
});
|
|
16283
16303
|
}
|
|
16284
16304
|
static async send(amount, from, to) {
|
|
16285
|
-
const coin = await this.getCoin(from, amount);
|
|
16286
16305
|
const ptb = new Transaction();
|
|
16287
|
-
ptb.transferObjects([
|
|
16306
|
+
ptb.transferObjects([this.coinWithBalance(amount)], to);
|
|
16288
16307
|
await SuiClient.signAndExecute(ptb, from);
|
|
16289
16308
|
}
|
|
16290
16309
|
static async assertBalance(wallet, amount) {
|
|
@@ -16535,12 +16554,14 @@ function sleep(ms) {
|
|
|
16535
16554
|
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
16536
16555
|
}
|
|
16537
16556
|
async function waitForNextEpoch(timeoutMs = 5 * 60 * 1e3, pollIntervalMs = 2e3) {
|
|
16538
|
-
const
|
|
16557
|
+
const startEpochData = await SuiClient.client.core.getCurrentSystemState();
|
|
16558
|
+
const startEpoch = BigInt(startEpochData.systemState.epoch);
|
|
16539
16559
|
const startTime = Date.now();
|
|
16540
16560
|
while (true) {
|
|
16541
|
-
const
|
|
16542
|
-
|
|
16543
|
-
|
|
16561
|
+
const currentEpochData = await SuiClient.client.core.getCurrentSystemState();
|
|
16562
|
+
const currentEpoch = BigInt(currentEpochData.systemState.epoch);
|
|
16563
|
+
if (currentEpoch > startEpoch) {
|
|
16564
|
+
return currentEpoch.toString();
|
|
16544
16565
|
}
|
|
16545
16566
|
if (Date.now() - startTime > timeoutMs) {
|
|
16546
16567
|
throw new Error("Timeout waiting for next epoch.");
|