@scallop-io/sui-kit 0.38.0 → 0.38.2

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/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Tookit for interacting with SUI network
2
2
 
3
- [中文文档](./document/README_cn.md)
4
-
5
3
  ## Features
6
4
 
7
5
  - [x] Transfer SUI, Custom Coin and objects.
@@ -43,7 +41,8 @@ const suiKit = new SuiKit({
43
41
  // 'testnet' | 'mainnet' | 'devnet', default is 'devnet'
44
42
  networkType: 'testnet',
45
43
  // the fullnode url, default is the preconfig fullnode url for the given network type
46
- fullnodeUrl: '<SUI fullnode>',
44
+ // It will rotate the fullnode when the current fullnode is not available
45
+ fullnodeUrls: '[<SUI fullnode1>, <SUI fullnode2>]',
47
46
  // the faucet url, default is the preconfig faucet url for the given network type
48
47
  faucetUrl: '<SUI faucet url>',
49
48
  });
package/dist/index.js CHANGED
@@ -468,12 +468,17 @@ var SuiSharedObject = class {
468
468
  }
469
469
  };
470
470
 
471
+ // src/libs/suiInteractor/util.ts
472
+ var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
473
+
471
474
  // src/libs/suiInteractor/suiInteractor.ts
472
475
  var SuiInteractor = class {
473
476
  constructor(fullNodeUrls) {
474
477
  if (fullNodeUrls.length === 0)
475
478
  throw new Error("fullNodeUrls must not be empty");
476
- this.providers = fullNodeUrls.map((url) => new import_sui7.JsonRpcProvider(new import_sui7.Connection({ fullnode: url })));
479
+ this.providers = fullNodeUrls.map(
480
+ (url) => new import_sui7.JsonRpcProvider(new import_sui7.Connection({ fullnode: url }))
481
+ );
477
482
  this.currentProvider = this.providers[0];
478
483
  }
479
484
  switchToNextProvider() {
@@ -487,37 +492,33 @@ var SuiInteractor = class {
487
492
  showObjectChanges: true,
488
493
  showBalanceChanges: true
489
494
  };
490
- const currentProviderIdx = this.providers.indexOf(this.currentProvider);
491
- const providers = [
492
- ...this.providers.slice(currentProviderIdx, this.providers.length),
493
- ...this.providers.slice(0, currentProviderIdx)
494
- ];
495
- for (const provider of providers) {
495
+ for (const provider of this.providers) {
496
496
  try {
497
- const res = await this.currentProvider.executeTransactionBlock({
497
+ const res = await provider.executeTransactionBlock({
498
498
  transactionBlock,
499
499
  signature,
500
500
  options: txResOptions
501
501
  });
502
- this.currentProvider = provider;
503
502
  return res;
504
503
  } catch (err) {
505
- console.warn(`Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`);
504
+ console.warn(
505
+ `Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`
506
+ );
507
+ await delay(2e3);
506
508
  }
507
509
  }
508
510
  throw new Error("Failed to send transaction with all fullnodes");
509
511
  }
510
512
  async getObjects(ids) {
511
- const options = { showContent: true, showDisplay: true, showType: true, showOwner: true };
512
- const currentProviderIdx = this.providers.indexOf(this.currentProvider);
513
- const providers = [
514
- ...this.providers.slice(currentProviderIdx, this.providers.length),
515
- ...this.providers.slice(0, currentProviderIdx)
516
- ];
517
- for (const provider of providers) {
513
+ const options = {
514
+ showContent: true,
515
+ showDisplay: true,
516
+ showType: true,
517
+ showOwner: true
518
+ };
519
+ for (const provider of this.providers) {
518
520
  try {
519
- const objects = await this.currentProvider.multiGetObjects({ ids, options });
520
- this.currentProvider = provider;
521
+ const objects = await provider.multiGetObjects({ ids, options });
521
522
  const parsedObjects = objects.map((object) => {
522
523
  const objectId = (0, import_sui7.getObjectId)(object);
523
524
  const objectType = (0, import_sui7.getObjectType)(object);
@@ -538,7 +539,10 @@ var SuiInteractor = class {
538
539
  });
539
540
  return parsedObjects;
540
541
  } catch (err) {
541
- console.warn(`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`);
542
+ await delay(2e3);
543
+ console.warn(
544
+ `Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
545
+ );
542
546
  }
543
547
  }
544
548
  throw new Error("Failed to get objects with all fullnodes");
@@ -555,7 +559,9 @@ var SuiInteractor = class {
555
559
  const objectIds = suiObjects.map((obj) => obj.objectId);
556
560
  const objects = await this.getObjects(objectIds);
557
561
  for (const object of objects) {
558
- const suiObject = suiObjects.find((obj) => obj.objectId === object.objectId);
562
+ const suiObject = suiObjects.find(
563
+ (obj) => obj.objectId === object.objectId
564
+ );
559
565
  if (suiObject instanceof SuiSharedObject) {
560
566
  suiObject.initialSharedVersion = object.initialSharedVersion;
561
567
  } else if (suiObject instanceof SuiOwnedObject) {
@@ -571,20 +577,29 @@ var SuiInteractor = class {
571
577
  * @param coinType the coin type, default is '0x2::SUI::SUI'
572
578
  */
573
579
  async selectCoins(addr, amount, coinType = "0x2::SUI::SUI") {
574
- const coins = await this.currentProvider.getCoins({ owner: addr, coinType });
575
580
  const selectedCoins = [];
576
581
  let totalAmount = 0;
577
- coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
578
- for (const coinData of coins.data) {
579
- selectedCoins.push({
580
- objectId: coinData.coinObjectId,
581
- digest: coinData.digest,
582
- version: coinData.version
582
+ let hasNext = true, nextCursor = null;
583
+ while (hasNext && totalAmount < amount) {
584
+ const coins = await this.currentProvider.getCoins({
585
+ owner: addr,
586
+ coinType,
587
+ cursor: nextCursor
583
588
  });
584
- totalAmount = totalAmount + parseInt(coinData.balance);
585
- if (totalAmount >= amount) {
586
- break;
589
+ coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
590
+ for (const coinData of coins.data) {
591
+ selectedCoins.push({
592
+ objectId: coinData.coinObjectId,
593
+ digest: coinData.digest,
594
+ version: coinData.version
595
+ });
596
+ totalAmount = totalAmount + parseInt(coinData.balance);
597
+ if (totalAmount >= amount) {
598
+ break;
599
+ }
587
600
  }
601
+ nextCursor = coins.nextCursor;
602
+ hasNext = coins.hasNextPage;
588
603
  }
589
604
  if (!selectedCoins.length) {
590
605
  throw new Error("No valid coins found for the transaction.");
@@ -684,7 +699,10 @@ var SuiKit = class {
684
699
  return signer.signTransactionBlock({ transactionBlock: tx });
685
700
  }
686
701
  async signAndSendTxn(tx, derivePathParams) {
687
- const { transactionBlockBytes, signature } = await this.signTxn(tx, derivePathParams);
702
+ const { transactionBlockBytes, signature } = await this.signTxn(
703
+ tx,
704
+ derivePathParams
705
+ );
688
706
  return this.suiInteractor.sendTx(transactionBlockBytes, signature);
689
707
  }
690
708
  /**
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/suiKit.ts","../src/libs/suiAccountManager/index.ts","../src/libs/suiAccountManager/keypair.ts","../src/libs/suiAccountManager/util.ts","../src/libs/suiAccountManager/crypto.ts","../src/libs/suiTxBuilder/index.ts","../src/libs/suiTxBuilder/util.ts","../src/libs/suiInteractor/suiInteractor.ts","../src/libs/suiModel/suiOwnedObject.ts","../src/libs/suiModel/suiSharedObject.ts","../src/libs/suiInteractor/defaultConfig.ts"],"sourcesContent":["export {\n TransactionBlock,\n SUI_CLOCK_OBJECT_ID,\n SUI_SYSTEM_STATE_OBJECT_ID,\n} from '@mysten/sui.js';\nexport { SuiKit } from './suiKit';\nexport { SuiAccountManager } from './libs/suiAccountManager';\nexport { SuiTxBlock } from './libs/suiTxBuilder';\nexport type * from './types';\n","/**\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n */\nimport {\n RawSigner,\n TransactionBlock,\n DevInspectResults,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js';\nimport { SuiAccountManager } from './libs/suiAccountManager';\nimport { SuiTxBlock } from './libs/suiTxBuilder';\nimport { SuiInteractor, getDefaultConnection } from './libs/suiInteractor';\nimport { SuiSharedObject, SuiOwnedObject } from './libs/suiModel';\nimport { SuiKitParams, DerivePathParams, SuiTxArg, SuiVecTxArg } from './types';\n\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n public accountManager: SuiAccountManager;\n public suiInteractor: SuiInteractor;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n */\n constructor({\n mnemonics,\n secretKey,\n networkType,\n fullnodeUrls,\n }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n fullnodeUrls = fullnodeUrls || [getDefaultConnection(networkType).fullnode];\n this.suiInteractor = new SuiInteractor(fullnodeUrls);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.suiInteractor.currentProvider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() {\n return this.accountManager.currentAddress;\n }\n\n provider() {\n return this.suiInteractor.currentProvider;\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.suiInteractor.currentProvider.getBalance({ owner, coinType });\n }\n\n async getObjects(objectIds: string[]) {\n return this.suiInteractor.getObjects(objectIds);\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiSharedObject | SuiOwnedObject)[]) {\n return this.suiInteractor.updateObjects(suiObjects);\n }\n\n async signTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<SuiTransactionBlockResponse> {\n const { transactionBlockBytes, signature } = await this.signTxn(tx, derivePathParams);\n return this.suiInteractor.sendTx(transactionBlockBytes, signature);\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(\n recipient: string,\n amount: number,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(\n recipients: string[],\n amounts: number[],\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(\n recipients: string[],\n amounts: number[],\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.suiInteractor.selectCoins(\n owner,\n totalAmount,\n coinType\n );\n tx.transferCoinToMany(\n coins.map((c) => c.objectId),\n owner,\n recipients,\n amounts\n );\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async transferCoin(\n recipient: string,\n amount: number,\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n return this.transferCoinToMany(\n [recipient],\n [amount],\n coinType,\n derivePathParams\n );\n }\n\n async transferObjects(\n objects: string[],\n recipient: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async moveCall(callParams: {\n target: string;\n arguments?: (SuiTxArg | SuiVecTxArg)[];\n typeArguments?: string[];\n derivePathParams?: DerivePathParams;\n }) {\n const {\n target,\n arguments: args = [],\n typeArguments = [],\n derivePathParams,\n } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(\n amount: number,\n coinType: string,\n owner?: string\n ) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.suiInteractor.selectCoins(owner, amount, coinType);\n return coins.map((c) => c.objectId);\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(\n amount: number,\n validatorAddr: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.suiInteractor.currentProvider.devInspectTransactionBlock({\n transactionBlock: tx,\n sender: this.getAddress(derivePathParams),\n });\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport { getKeyPair } from './keypair';\nimport { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';\nimport { generateMnemonic } from './crypto';\nimport type { AccountMangerParams, DerivePathParams } from 'src/types';\n\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || '';\n this.secretKey = secretKey || '';\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24);\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams)\n .getPublicKey()\n .toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport type { DerivePathParams } from 'src/types';\n\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (\n derivePathParams: DerivePathParams = {}\n) => {\n const {\n accountIndex = 0,\n isExternal = false,\n addressIndex = 0,\n } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n};\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (\n mnemonics: string,\n derivePathParams: DerivePathParams = {}\n) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n};\n","import { fromB64 } from '@mysten/sui.js';\n\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) =>\n /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport const fromHEX = (hexStr: string): Uint8Array => {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array');\n }\n const intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)\n ?.map((byte) => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n};\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str);\n } else if (isBase64(str)) {\n return fromB64(str);\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n};\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n};\n","import { generateMnemonic as genMnemonic } from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english';\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256;\n return genMnemonic(wordlist, strength);\n};\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n TransactionExpiration,\n SuiObjectRef,\n SharedObjectRef,\n JsonRpcProvider,\n TransactionType,\n Transactions,\n ObjectCallArg,\n} from '@mysten/sui.js';\nimport { convertArgs } from './util';\nimport type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from 'src/types';\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor(transaction?: TransactionBlock) {\n this.txBlock = new TransactionBlock(transaction);\n }\n\n //======== override methods of TransactionBlock ============\n\n address(value: string) {\n return this.txBlock.pure(value, 'address');\n }\n pure(value: unknown, type?: string) {\n return this.txBlock.pure(value, type);\n }\n object(value: string | ObjectCallArg) {\n return this.txBlock.object(value);\n }\n objectRef(ref: SuiObjectRef) {\n return this.txBlock.objectRef(ref);\n }\n sharedObjectRef(ref: SharedObjectRef) {\n return this.txBlock.sharedObjectRef(ref);\n }\n setSender(sender: string) {\n return this.txBlock.setSender(sender);\n }\n setSenderIfNotSet(sender: string) {\n return this.txBlock.setSenderIfNotSet(sender);\n }\n setExpiration(expiration?: TransactionExpiration) {\n return this.txBlock.setExpiration(expiration);\n }\n setGasPrice(price: number | bigint) {\n return this.txBlock.setGasPrice(price);\n }\n setGasBudget(budget: number | bigint) {\n return this.txBlock.setGasBudget(budget);\n }\n setGasOwner(owner: string) {\n return this.txBlock.setGasOwner(owner);\n }\n setGasPayment(payments: SuiObjectRef[]) {\n return this.txBlock.setGasPayment(payments);\n }\n\n add(transaction: TransactionType) {\n return this.txBlock.add(transaction);\n }\n serialize() {\n return this.txBlock.serialize();\n }\n build(\n params: {\n provider?: JsonRpcProvider;\n onlyTransactionKind?: boolean;\n } = {}\n ) {\n return this.txBlock.build(params);\n }\n getDigest({ provider }: { provider?: JsonRpcProvider } = {}) {\n return this.txBlock.getDigest({ provider });\n }\n\n get gas() {\n return this.txBlock.gas;\n }\n get blockData() {\n return this.txBlock.blockData;\n }\n\n transferObjects(objects: SuiObjectArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(convertArgs(this.txBlock, objects), tx.pure(recipient));\n return this;\n }\n splitCoins(coin: SuiObjectArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = convertArgs(this.txBlock, [coin])[0];\n const res = tx.splitCoins(\n coinObject,\n amounts.map((m) => tx.pure(m))\n );\n return amounts.map((_, i) => res[i]);\n }\n mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {\n const destinationObject = convertArgs(this.txBlock, [destination])[0];\n const sourceObjects = convertArgs(this.txBlock, sources);\n return this.txBlock.mergeCoins(destinationObject, sourceObjects);\n }\n publish(...args: Parameters<(typeof Transactions)['Publish']>) {\n return this.txBlock.publish(...args);\n }\n upgrade(...args: Parameters<(typeof Transactions)['Upgrade']>) {\n return this.txBlock.upgrade(...args);\n }\n makeMoveVec(...args: Parameters<(typeof Transactions)['MakeMoveVec']>) {\n return this.txBlock.makeMoveVec(...args);\n }\n\n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(\n target: string,\n args: (SuiTxArg | SuiVecTxArg)[] = [],\n typeArgs: string[] = []\n ) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex =\n /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null)\n throw new Error(\n 'Invalid target format. Expected `${string}::${string}::${string}`'\n );\n const convertedArgs = convertArgs(this.txBlock, args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n //======== enhance methods ============\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n\n const tx = this.txBlock;\n const coins = tx.splitCoins(\n tx.gas,\n amounts.map((amount) => tx.pure(amount))\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n takeAmountFromCoins(coins: SuiObjectArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(\n tx.gas,\n amounts.map((m) => tx.pure(m))\n );\n }\n\n splitMultiCoins(coins: SuiObjectArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(\n mergedCoin,\n amounts.map((m) => tx.pure(m))\n );\n return { splitedCoins, mergedCoin };\n }\n\n transferCoinToMany(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipients: string[],\n amounts: number[]\n ) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(\n inputCoins,\n amounts\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender));\n return this;\n }\n\n transferCoin(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipient: string,\n amount: number\n ) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [\n tx.object(SUI_SYSTEM_STATE_OBJECT_ID),\n stakeCoin,\n tx.pure(validatorAddr),\n ],\n });\n return tx;\n }\n}\n","import {\n normalizeSuiObjectId,\n TransactionArgument,\n TransactionBlock,\n} from '@mysten/sui.js';\nimport { SuiTxArg, SuiInputTypes } from 'src/types';\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object';\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64';\n } else if (typeof value === 'boolean') {\n return 'bool';\n } else {\n return 'object';\n }\n};\n\n/**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\nexport function makeVecParam(\n txBlock: TransactionBlock,\n args: SuiTxArg[],\n type?: SuiInputTypes\n) {\n if (args.length === 0)\n throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0]);\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map((arg) =>\n typeof arg === 'string'\n ? txBlock.object(normalizeSuiObjectId(arg))\n : (arg as any)\n );\n return txBlock.makeMoveVec({ objects });\n } else {\n const vecType = type || defaultSuiType;\n return txBlock.pure(args, `vector<${vecType}>`);\n }\n}\n\nexport function isMoveVecArg(arg: any) {\n const isFullMoveVecArg =\n arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n}\n\nexport function convertArgs(\n txBlock: TransactionBlock,\n args: any[]\n): TransactionArgument[] {\n return args.map((arg) => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return txBlock.object(normalizeSuiObjectId(arg));\n } else if (isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? makeVecParam(txBlock, arg.value, vecType)\n : makeVecParam(txBlock, arg);\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return txBlock.pure(arg);\n } else {\n // We do nothing, because it's most likely already a move value\n return arg;\n }\n });\n}\n","import {\n SuiTransactionBlockResponse,\n SuiTransactionBlockResponseOptions,\n JsonRpcProvider,\n Connection,\n getObjectDisplay,\n getObjectFields,\n getObjectId,\n getObjectType,\n getObjectVersion,\n getSharedObjectInitialVersion\n} from '@mysten/sui.js';\nimport { ObjectData } from \"src/types\";\nimport { SuiOwnedObject, SuiSharedObject } from \"../suiModel\";\n\n/**\n * `SuiTransactionSender` is used to send transaction with a given gas coin.\n * It always uses the gas coin to pay for the gas,\n * and update the gas coin after the transaction.\n */\nexport class SuiInteractor {\n public readonly providers: JsonRpcProvider[];\n public currentProvider: JsonRpcProvider;\n constructor(fullNodeUrls: string[]) {\n if (fullNodeUrls.length === 0) throw new Error('fullNodeUrls must not be empty');\n this.providers = fullNodeUrls.map(url => new JsonRpcProvider(new Connection({ fullnode: url })));\n this.currentProvider = this.providers[0];\n }\n\n switchToNextProvider() {\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n this.currentProvider = this.providers[(currentProviderIdx + 1) % this.providers.length];\n }\n\n async sendTx(\n transactionBlock: Uint8Array | string,\n signature: string | string[],\n ): Promise<SuiTransactionBlockResponse> {\n\n const txResOptions: SuiTransactionBlockResponseOptions = {\n showEvents: true,\n showEffects: true,\n showObjectChanges: true,\n showBalanceChanges: true,\n }\n\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n const providers = [\n ...this.providers.slice(currentProviderIdx, this.providers.length),\n ...this.providers.slice(0, currentProviderIdx),\n ]\n\n for (const provider of providers) {\n try {\n const res = await this.currentProvider.executeTransactionBlock({\n transactionBlock,\n signature,\n options: txResOptions\n });\n this.currentProvider = provider;\n return res;\n } catch (err) {\n console.warn(`Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`);\n }\n }\n throw new Error('Failed to send transaction with all fullnodes');\n }\n async getObjects(ids: string[]) {\n const options = { showContent: true, showDisplay: true, showType: true, showOwner: true };\n\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n const providers = [\n ...this.providers.slice(currentProviderIdx, this.providers.length),\n ...this.providers.slice(0, currentProviderIdx),\n ]\n\n for (const provider of providers) {\n try {\n const objects = await this.currentProvider.multiGetObjects({ ids, options });\n this.currentProvider = provider;\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectDigest = object.data ? object.data.digest : undefined;\n const initialSharedVersion = getSharedObjectInitialVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return {\n objectId,\n objectType,\n objectVersion,\n objectDigest,\n objectFields,\n objectDisplay,\n initialSharedVersion,\n };\n });\n return parsedObjects as ObjectData[];\n } catch (err) {\n console.warn(`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`);\n }\n }\n throw new Error('Failed to get objects with all fullnodes');\n }\n\n async getObject(id: string) {\n const objects = await this.getObjects([id]);\n return objects[0];\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiOwnedObject | SuiSharedObject)[]) {\n const objectIds = suiObjects.map((obj) => obj.objectId);\n const objects = await this.getObjects(objectIds);\n for(const object of objects) {\n const suiObject = suiObjects.find((obj) => obj.objectId === object.objectId);\n if(suiObject instanceof SuiSharedObject) {\n suiObject.initialSharedVersion = object.initialSharedVersion;\n } else if (suiObject instanceof SuiOwnedObject) {\n suiObject.version = object.objectVersion;\n suiObject.digest = object.objectDigest;\n }\n }\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(\n addr: string,\n amount: number,\n coinType: string = '0x2::SUI::SUI'\n ) {\n const coins = await this.currentProvider.getCoins({ owner: addr, coinType });\n const selectedCoins: {\n objectId: string;\n digest: string;\n version: string;\n }[] = [];\n let totalAmount = 0;\n // Sort the coins by balance in descending order\n coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));\n for (const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import { Infer } from 'superstruct';\nimport {\n getObjectChanges,\n SuiTransactionBlockResponse,\n ObjectCallArg,\n ObjectId,\n Inputs\n} from '@mysten/sui.js';\n\nexport class SuiOwnedObject {\n public readonly objectId: string;\n public version?: number | string;\n public digest?: string;\n\n constructor(param: {objectId: string, version?: string, digest?: string}) {\n this.objectId = param.objectId;\n this.version = param.version;\n this.digest = param.digest;\n }\n\n /**\n * Check if the object is fully initialized.\n * So that when it's used as an input, it won't be necessary to fetch from fullnode again.\n * Which can save time when sending transactions.\n */\n isFullObject(): boolean {\n return !!this.version && !!this.digest;\n }\n\n asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.version || !this.digest) {\n return this.objectId;\n }\n return {\n Object: {\n ImmOrOwned: {\n objectId: this.objectId,\n version: this.version,\n digest: this.digest,\n }\n }\n }\n }\n\n /**\n * Update object version & digest based on the transaction response.\n * @param txResponse\n */\n updateFromTxResponse(txResponse: SuiTransactionBlockResponse) {\n const changes = getObjectChanges(txResponse);\n if (!changes) {\n throw new Error('Bad transaction response!');\n }\n for (const change of changes) {\n if (change.type === 'mutated' && change.objectId === this.objectId) {\n this.digest = change.digest;\n this.version = change.version;\n return;\n }\n }\n throw new Error('Could not find object in transaction response!');\n }\n}\n","import { Infer } from 'superstruct';\nimport {\n ObjectCallArg,\n ObjectId,\n} from '@mysten/sui.js';\n\nexport class SuiSharedObject {\n public readonly objectId: string;\n public initialSharedVersion?: number | string;\n\n constructor(param: {objectId: string, initialSharedVersion?: number, mutable?: boolean}) {\n this.objectId = param.objectId;\n this.initialSharedVersion = param.initialSharedVersion;\n }\n\n asCallArg(mutable: boolean = false): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.initialSharedVersion) {\n return this.objectId;\n }\n return {\n Object: {\n Shared: {\n objectId: this.objectId,\n initialSharedVersion: this.initialSharedVersion,\n mutable,\n }\n }\n }\n }\n}\n","import {\n localnetConnection,\n devnetConnection,\n testnetConnection,\n mainnetConnection,\n} from '@mysten/sui.js';\nimport type { Connection } from '@mysten/sui.js';\nimport type { NetworkType } from 'src/types';\nexport const defaultGasBudget = 10 ** 8; // 0.1 SUI, should be enough for most of the transactions\nexport const defaultGasPrice = 1000; // 1000 MIST\n\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @returns { fullNode: string, websocket: string, faucet?: string }\n */\nexport const getDefaultConnection = (\n networkType: NetworkType = 'devnet'\n): Connection => {\n switch (networkType) {\n case 'localnet':\n return localnetConnection;\n case 'devnet':\n return devnetConnection;\n case 'testnet':\n return testnetConnection;\n case 'mainnet':\n return mainnetConnection;\n default:\n return devnetConnection;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,eAIO;;;ACDP,IA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U;AAC7C,WAAO,KAAK,cAAc,gBAAgB,2BAA2B;AAAA,MACnE,kBAAkB;AAAA,MAClB,QAAQ,KAAK,WAAW,gBAAgB;AAAA,IAC1C,CAAC;AAAA,EACH;AACF;","names":["import_sui","import_sui","import_sui","import_sui","genMnemonic","import_sui","import_sui","import_sui","import_sui","import_sui"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/suiKit.ts","../src/libs/suiAccountManager/index.ts","../src/libs/suiAccountManager/keypair.ts","../src/libs/suiAccountManager/util.ts","../src/libs/suiAccountManager/crypto.ts","../src/libs/suiTxBuilder/index.ts","../src/libs/suiTxBuilder/util.ts","../src/libs/suiInteractor/suiInteractor.ts","../src/libs/suiModel/suiOwnedObject.ts","../src/libs/suiModel/suiSharedObject.ts","../src/libs/suiInteractor/util.ts","../src/libs/suiInteractor/defaultConfig.ts"],"sourcesContent":["export {\n TransactionBlock,\n SUI_CLOCK_OBJECT_ID,\n SUI_SYSTEM_STATE_OBJECT_ID,\n} from '@mysten/sui.js';\nexport { SuiKit } from './suiKit';\nexport { SuiAccountManager } from './libs/suiAccountManager';\nexport { SuiTxBlock } from './libs/suiTxBuilder';\nexport type * from './types';\n","/**\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n */\nimport {\n RawSigner,\n TransactionBlock,\n DevInspectResults,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js';\nimport { SuiAccountManager } from './libs/suiAccountManager';\nimport { SuiTxBlock } from './libs/suiTxBuilder';\nimport { SuiInteractor, getDefaultConnection } from './libs/suiInteractor';\nimport { SuiSharedObject, SuiOwnedObject } from './libs/suiModel';\nimport { SuiKitParams, DerivePathParams, SuiTxArg, SuiVecTxArg } from './types';\n\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n public accountManager: SuiAccountManager;\n public suiInteractor: SuiInteractor;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n */\n constructor({\n mnemonics,\n secretKey,\n networkType,\n fullnodeUrls,\n }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n fullnodeUrls = fullnodeUrls || [getDefaultConnection(networkType).fullnode];\n this.suiInteractor = new SuiInteractor(fullnodeUrls);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.suiInteractor.currentProvider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() {\n return this.accountManager.currentAddress;\n }\n\n provider() {\n return this.suiInteractor.currentProvider;\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.suiInteractor.currentProvider.getBalance({ owner, coinType });\n }\n\n async getObjects(objectIds: string[]) {\n return this.suiInteractor.getObjects(objectIds);\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiSharedObject | SuiOwnedObject)[]) {\n return this.suiInteractor.updateObjects(suiObjects);\n }\n\n async signTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<SuiTransactionBlockResponse> {\n const { transactionBlockBytes, signature } = await this.signTxn(\n tx,\n derivePathParams\n );\n return this.suiInteractor.sendTx(transactionBlockBytes, signature);\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(\n recipient: string,\n amount: number,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(\n recipients: string[],\n amounts: number[],\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(\n recipients: string[],\n amounts: number[],\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.suiInteractor.selectCoins(\n owner,\n totalAmount,\n coinType\n );\n tx.transferCoinToMany(\n coins.map((c) => c.objectId),\n owner,\n recipients,\n amounts\n );\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async transferCoin(\n recipient: string,\n amount: number,\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n return this.transferCoinToMany(\n [recipient],\n [amount],\n coinType,\n derivePathParams\n );\n }\n\n async transferObjects(\n objects: string[],\n recipient: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async moveCall(callParams: {\n target: string;\n arguments?: (SuiTxArg | SuiVecTxArg)[];\n typeArguments?: string[];\n derivePathParams?: DerivePathParams;\n }) {\n const {\n target,\n arguments: args = [],\n typeArguments = [],\n derivePathParams,\n } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(\n amount: number,\n coinType: string,\n owner?: string\n ) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.suiInteractor.selectCoins(owner, amount, coinType);\n return coins.map((c) => c.objectId);\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(\n amount: number,\n validatorAddr: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.suiInteractor.currentProvider.devInspectTransactionBlock({\n transactionBlock: tx,\n sender: this.getAddress(derivePathParams),\n });\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport { getKeyPair } from './keypair';\nimport { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';\nimport { generateMnemonic } from './crypto';\nimport type { AccountMangerParams, DerivePathParams } from 'src/types';\n\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || '';\n this.secretKey = secretKey || '';\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24);\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams)\n .getPublicKey()\n .toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport type { DerivePathParams } from 'src/types';\n\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (\n derivePathParams: DerivePathParams = {}\n) => {\n const {\n accountIndex = 0,\n isExternal = false,\n addressIndex = 0,\n } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n};\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (\n mnemonics: string,\n derivePathParams: DerivePathParams = {}\n) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n};\n","import { fromB64 } from '@mysten/sui.js';\n\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) =>\n /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport const fromHEX = (hexStr: string): Uint8Array => {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array');\n }\n const intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)\n ?.map((byte) => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n};\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str);\n } else if (isBase64(str)) {\n return fromB64(str);\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n};\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n};\n","import { generateMnemonic as genMnemonic } from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english';\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256;\n return genMnemonic(wordlist, strength);\n};\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n TransactionExpiration,\n SuiObjectRef,\n SharedObjectRef,\n JsonRpcProvider,\n TransactionType,\n Transactions,\n ObjectCallArg,\n} from '@mysten/sui.js';\nimport { convertArgs } from './util';\nimport type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from 'src/types';\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor(transaction?: TransactionBlock) {\n this.txBlock = new TransactionBlock(transaction);\n }\n\n //======== override methods of TransactionBlock ============\n\n address(value: string) {\n return this.txBlock.pure(value, 'address');\n }\n pure(value: unknown, type?: string) {\n return this.txBlock.pure(value, type);\n }\n object(value: string | ObjectCallArg) {\n return this.txBlock.object(value);\n }\n objectRef(ref: SuiObjectRef) {\n return this.txBlock.objectRef(ref);\n }\n sharedObjectRef(ref: SharedObjectRef) {\n return this.txBlock.sharedObjectRef(ref);\n }\n setSender(sender: string) {\n return this.txBlock.setSender(sender);\n }\n setSenderIfNotSet(sender: string) {\n return this.txBlock.setSenderIfNotSet(sender);\n }\n setExpiration(expiration?: TransactionExpiration) {\n return this.txBlock.setExpiration(expiration);\n }\n setGasPrice(price: number | bigint) {\n return this.txBlock.setGasPrice(price);\n }\n setGasBudget(budget: number | bigint) {\n return this.txBlock.setGasBudget(budget);\n }\n setGasOwner(owner: string) {\n return this.txBlock.setGasOwner(owner);\n }\n setGasPayment(payments: SuiObjectRef[]) {\n return this.txBlock.setGasPayment(payments);\n }\n\n add(transaction: TransactionType) {\n return this.txBlock.add(transaction);\n }\n serialize() {\n return this.txBlock.serialize();\n }\n build(\n params: {\n provider?: JsonRpcProvider;\n onlyTransactionKind?: boolean;\n } = {}\n ) {\n return this.txBlock.build(params);\n }\n getDigest({ provider }: { provider?: JsonRpcProvider } = {}) {\n return this.txBlock.getDigest({ provider });\n }\n\n get gas() {\n return this.txBlock.gas;\n }\n get blockData() {\n return this.txBlock.blockData;\n }\n\n transferObjects(objects: SuiObjectArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(convertArgs(this.txBlock, objects), tx.pure(recipient));\n return this;\n }\n splitCoins(coin: SuiObjectArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = convertArgs(this.txBlock, [coin])[0];\n const res = tx.splitCoins(\n coinObject,\n amounts.map((m) => tx.pure(m))\n );\n return amounts.map((_, i) => res[i]);\n }\n mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {\n const destinationObject = convertArgs(this.txBlock, [destination])[0];\n const sourceObjects = convertArgs(this.txBlock, sources);\n return this.txBlock.mergeCoins(destinationObject, sourceObjects);\n }\n publish(...args: Parameters<(typeof Transactions)['Publish']>) {\n return this.txBlock.publish(...args);\n }\n upgrade(...args: Parameters<(typeof Transactions)['Upgrade']>) {\n return this.txBlock.upgrade(...args);\n }\n makeMoveVec(...args: Parameters<(typeof Transactions)['MakeMoveVec']>) {\n return this.txBlock.makeMoveVec(...args);\n }\n\n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(\n target: string,\n args: (SuiTxArg | SuiVecTxArg)[] = [],\n typeArgs: string[] = []\n ) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex =\n /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null)\n throw new Error(\n 'Invalid target format. Expected `${string}::${string}::${string}`'\n );\n const convertedArgs = convertArgs(this.txBlock, args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n //======== enhance methods ============\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n\n const tx = this.txBlock;\n const coins = tx.splitCoins(\n tx.gas,\n amounts.map((amount) => tx.pure(amount))\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n takeAmountFromCoins(coins: SuiObjectArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(\n tx.gas,\n amounts.map((m) => tx.pure(m))\n );\n }\n\n splitMultiCoins(coins: SuiObjectArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(\n mergedCoin,\n amounts.map((m) => tx.pure(m))\n );\n return { splitedCoins, mergedCoin };\n }\n\n transferCoinToMany(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipients: string[],\n amounts: number[]\n ) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(\n inputCoins,\n amounts\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender));\n return this;\n }\n\n transferCoin(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipient: string,\n amount: number\n ) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [\n tx.object(SUI_SYSTEM_STATE_OBJECT_ID),\n stakeCoin,\n tx.pure(validatorAddr),\n ],\n });\n return tx;\n }\n}\n","import {\n normalizeSuiObjectId,\n TransactionArgument,\n TransactionBlock,\n} from '@mysten/sui.js';\nimport { SuiTxArg, SuiInputTypes } from 'src/types';\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object';\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64';\n } else if (typeof value === 'boolean') {\n return 'bool';\n } else {\n return 'object';\n }\n};\n\n/**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\nexport function makeVecParam(\n txBlock: TransactionBlock,\n args: SuiTxArg[],\n type?: SuiInputTypes\n) {\n if (args.length === 0)\n throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0]);\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map((arg) =>\n typeof arg === 'string'\n ? txBlock.object(normalizeSuiObjectId(arg))\n : (arg as any)\n );\n return txBlock.makeMoveVec({ objects });\n } else {\n const vecType = type || defaultSuiType;\n return txBlock.pure(args, `vector<${vecType}>`);\n }\n}\n\nexport function isMoveVecArg(arg: any) {\n const isFullMoveVecArg =\n arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n}\n\nexport function convertArgs(\n txBlock: TransactionBlock,\n args: any[]\n): TransactionArgument[] {\n return args.map((arg) => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return txBlock.object(normalizeSuiObjectId(arg));\n } else if (isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? makeVecParam(txBlock, arg.value, vecType)\n : makeVecParam(txBlock, arg);\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return txBlock.pure(arg);\n } else {\n // We do nothing, because it's most likely already a move value\n return arg;\n }\n });\n}\n","import {\n SuiTransactionBlockResponse,\n SuiTransactionBlockResponseOptions,\n JsonRpcProvider,\n Connection,\n getObjectDisplay,\n getObjectFields,\n getObjectId,\n getObjectType,\n getObjectVersion,\n getSharedObjectInitialVersion,\n} from '@mysten/sui.js';\nimport { ObjectData } from 'src/types';\nimport { SuiOwnedObject, SuiSharedObject } from '../suiModel';\nimport { delay } from './util';\n\n/**\n * `SuiTransactionSender` is used to send transaction with a given gas coin.\n * It always uses the gas coin to pay for the gas,\n * and update the gas coin after the transaction.\n */\nexport class SuiInteractor {\n public readonly providers: JsonRpcProvider[];\n public currentProvider: JsonRpcProvider;\n constructor(fullNodeUrls: string[]) {\n if (fullNodeUrls.length === 0)\n throw new Error('fullNodeUrls must not be empty');\n this.providers = fullNodeUrls.map(\n (url) => new JsonRpcProvider(new Connection({ fullnode: url }))\n );\n this.currentProvider = this.providers[0];\n }\n\n switchToNextProvider() {\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n this.currentProvider =\n this.providers[(currentProviderIdx + 1) % this.providers.length];\n }\n\n async sendTx(\n transactionBlock: Uint8Array | string,\n signature: string | string[]\n ): Promise<SuiTransactionBlockResponse> {\n const txResOptions: SuiTransactionBlockResponseOptions = {\n showEvents: true,\n showEffects: true,\n showObjectChanges: true,\n showBalanceChanges: true,\n };\n\n // const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n // const providers = [\n // ...this.providers.slice(currentProviderIdx, this.providers.length),\n // ...this.providers.slice(0, currentProviderIdx),\n // ]\n\n for (const provider of this.providers) {\n try {\n const res = await provider.executeTransactionBlock({\n transactionBlock,\n signature,\n options: txResOptions,\n });\n return res;\n } catch (err) {\n console.warn(\n `Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`\n );\n await delay(2000);\n }\n }\n throw new Error('Failed to send transaction with all fullnodes');\n }\n async getObjects(ids: string[]) {\n const options = {\n showContent: true,\n showDisplay: true,\n showType: true,\n showOwner: true,\n };\n\n // const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n // const providers = [\n // ...this.providers.slice(currentProviderIdx, this.providers.length),\n // ...this.providers.slice(0, currentProviderIdx),\n // ]\n\n for (const provider of this.providers) {\n try {\n const objects = await provider.multiGetObjects({ ids, options });\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectDigest = object.data ? object.data.digest : undefined;\n const initialSharedVersion = getSharedObjectInitialVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return {\n objectId,\n objectType,\n objectVersion,\n objectDigest,\n objectFields,\n objectDisplay,\n initialSharedVersion,\n };\n });\n return parsedObjects as ObjectData[];\n } catch (err) {\n await delay(2000);\n console.warn(\n `Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`\n );\n }\n }\n throw new Error('Failed to get objects with all fullnodes');\n }\n\n async getObject(id: string) {\n const objects = await this.getObjects([id]);\n return objects[0];\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiOwnedObject | SuiSharedObject)[]) {\n const objectIds = suiObjects.map((obj) => obj.objectId);\n const objects = await this.getObjects(objectIds);\n for (const object of objects) {\n const suiObject = suiObjects.find(\n (obj) => obj.objectId === object.objectId\n );\n if (suiObject instanceof SuiSharedObject) {\n suiObject.initialSharedVersion = object.initialSharedVersion;\n } else if (suiObject instanceof SuiOwnedObject) {\n suiObject.version = object.objectVersion;\n suiObject.digest = object.objectDigest;\n }\n }\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(\n addr: string,\n amount: number,\n coinType: string = '0x2::SUI::SUI'\n ) {\n const selectedCoins: {\n objectId: string;\n digest: string;\n version: string;\n }[] = [];\n let totalAmount = 0;\n let hasNext = true,\n nextCursor: string | null = null;\n while (hasNext && totalAmount < amount) {\n const coins = await this.currentProvider.getCoins({\n owner: addr,\n coinType: coinType,\n cursor: nextCursor,\n });\n // Sort the coins by balance in descending order\n coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));\n for (const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n nextCursor = coins.nextCursor;\n hasNext = coins.hasNextPage;\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import { Infer } from 'superstruct';\nimport {\n getObjectChanges,\n SuiTransactionBlockResponse,\n ObjectCallArg,\n ObjectId,\n} from '@mysten/sui.js';\n\nexport class SuiOwnedObject {\n public readonly objectId: string;\n public version?: number | string;\n public digest?: string;\n\n constructor(param: { objectId: string; version?: string; digest?: string }) {\n this.objectId = param.objectId;\n this.version = param.version;\n this.digest = param.digest;\n }\n\n /**\n * Check if the object is fully initialized.\n * So that when it's used as an input, it won't be necessary to fetch from fullnode again.\n * Which can save time when sending transactions.\n */\n isFullObject(): boolean {\n return !!this.version && !!this.digest;\n }\n\n asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.version || !this.digest) {\n return this.objectId;\n }\n return {\n Object: {\n ImmOrOwned: {\n objectId: this.objectId,\n version: this.version,\n digest: this.digest,\n },\n },\n };\n }\n\n /**\n * Update object version & digest based on the transaction response.\n * @param txResponse\n */\n updateFromTxResponse(txResponse: SuiTransactionBlockResponse) {\n const changes = getObjectChanges(txResponse);\n if (!changes) {\n throw new Error('Bad transaction response!');\n }\n for (const change of changes) {\n if (change.type === 'mutated' && change.objectId === this.objectId) {\n this.digest = change.digest;\n this.version = change.version;\n return;\n }\n }\n throw new Error('Could not find object in transaction response!');\n }\n}\n","import { Infer } from 'superstruct';\nimport { ObjectCallArg, ObjectId } from '@mysten/sui.js';\n\nexport class SuiSharedObject {\n public readonly objectId: string;\n public initialSharedVersion?: number | string;\n\n constructor(param: {\n objectId: string;\n initialSharedVersion?: number;\n mutable?: boolean;\n }) {\n this.objectId = param.objectId;\n this.initialSharedVersion = param.initialSharedVersion;\n }\n\n asCallArg(\n mutable: boolean = false\n ): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.initialSharedVersion) {\n return this.objectId;\n }\n return {\n Object: {\n Shared: {\n objectId: this.objectId,\n initialSharedVersion: this.initialSharedVersion,\n mutable,\n },\n },\n };\n }\n}\n","export const delay = (ms: number) =>\n new Promise((resolve) => setTimeout(resolve, ms));\n","import {\n localnetConnection,\n devnetConnection,\n testnetConnection,\n mainnetConnection,\n} from '@mysten/sui.js';\nimport type { Connection } from '@mysten/sui.js';\nimport type { NetworkType } from 'src/types';\nexport const defaultGasBudget = 10 ** 8; // 0.1 SUI, should be enough for most of the transactions\nexport const defaultGasPrice = 1000; // 1000 MIST\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @returns { fullNode: string, websocket: string, faucet?: string }\n */\nexport const getDefaultConnection = (\n networkType: NetworkType = 'devnet'\n): Connection => {\n switch (networkType) {\n case 'localnet':\n return localnetConnection;\n case 'devnet':\n return devnetConnection;\n case 'testnet':\n return testnetConnection;\n case 'mainnet':\n return mainnetConnection;\n default:\n return devnetConnection;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,eAIO;;;ACDP,IAAAC,cAKO;;;ACRP,IAAAC,cAA+B;;;ACA/B,iBAA+B;AAOxB,IAAM,sBAAsB,CACjC,mBAAqC,CAAC,MACnC;AACH,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,aAAa;AAAA,IACb,eAAe;AAAA,EACjB,IAAI;AACJ,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CACxB,WACA,mBAAqC,CAAC,MACnC;AACH,QAAM,aAAa,oBAAoB,gBAAgB;AACvD,SAAO,0BAAe,cAAc,WAAW,UAAU;AAC3D;;;ACrCA,IAAAC,cAAwB;AAMjB,IAAM,QAAQ,CAAC,QACpB,kCAAkC,KAAK,GAAG;AAOrC,IAAM,WAAW,CAAC,QAAgB,0BAA0B,KAAK,GAAG;AAMpE,IAAM,UAAU,CAAC,WAA+B;AACrD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,QAAM,SAAS,OACZ,QAAQ,MAAM,EAAE,EAChB,MAAM,SAAS,GACd,IAAI,CAAC,SAAS,SAAS,MAAM,EAAE,CAAC;AAEpC,MAAI,CAAC,UAAU,OAAO,WAAW,GAAG;AAClC,UAAM,IAAI,MAAM,wBAAwB,QAAQ;AAAA,EAClD;AACA,SAAO,WAAW,KAAK,MAAM;AAC/B;AAKO,IAAM,0BAA0B,CAAC,QAA4B;AAClE,MAAI,MAAM,GAAG,GAAG;AACd,WAAO,QAAQ,GAAG;AAAA,EACpB,WAAW,SAAS,GAAG,GAAG;AACxB,eAAO,qBAAQ,GAAG;AAA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a;AACjC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WACJ,IACA,kBAC4B;AAC5B,SAAK,cAAc,aAAa,GAAG,UAAU;AAC7C,WAAO,KAAK,cAAc,gBAAgB,2BAA2B;AAAA,MACnE,kBAAkB;AAAA,MAClB,QAAQ,KAAK,WAAW,gBAAgB;AAAA,IAC1C,CAAC;AAAA,EACH;AACF;","names":["import_sui","import_sui","import_sui","import_sui","genMnemonic","import_sui","import_sui","import_sui","import_sui","import_sui"]}
package/dist/index.mjs CHANGED
@@ -461,12 +461,17 @@ var SuiSharedObject = class {
461
461
  }
462
462
  };
463
463
 
464
+ // src/libs/suiInteractor/util.ts
465
+ var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
466
+
464
467
  // src/libs/suiInteractor/suiInteractor.ts
465
468
  var SuiInteractor = class {
466
469
  constructor(fullNodeUrls) {
467
470
  if (fullNodeUrls.length === 0)
468
471
  throw new Error("fullNodeUrls must not be empty");
469
- this.providers = fullNodeUrls.map((url) => new JsonRpcProvider2(new Connection({ fullnode: url })));
472
+ this.providers = fullNodeUrls.map(
473
+ (url) => new JsonRpcProvider2(new Connection({ fullnode: url }))
474
+ );
470
475
  this.currentProvider = this.providers[0];
471
476
  }
472
477
  switchToNextProvider() {
@@ -480,37 +485,33 @@ var SuiInteractor = class {
480
485
  showObjectChanges: true,
481
486
  showBalanceChanges: true
482
487
  };
483
- const currentProviderIdx = this.providers.indexOf(this.currentProvider);
484
- const providers = [
485
- ...this.providers.slice(currentProviderIdx, this.providers.length),
486
- ...this.providers.slice(0, currentProviderIdx)
487
- ];
488
- for (const provider of providers) {
488
+ for (const provider of this.providers) {
489
489
  try {
490
- const res = await this.currentProvider.executeTransactionBlock({
490
+ const res = await provider.executeTransactionBlock({
491
491
  transactionBlock,
492
492
  signature,
493
493
  options: txResOptions
494
494
  });
495
- this.currentProvider = provider;
496
495
  return res;
497
496
  } catch (err) {
498
- console.warn(`Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`);
497
+ console.warn(
498
+ `Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`
499
+ );
500
+ await delay(2e3);
499
501
  }
500
502
  }
501
503
  throw new Error("Failed to send transaction with all fullnodes");
502
504
  }
503
505
  async getObjects(ids) {
504
- const options = { showContent: true, showDisplay: true, showType: true, showOwner: true };
505
- const currentProviderIdx = this.providers.indexOf(this.currentProvider);
506
- const providers = [
507
- ...this.providers.slice(currentProviderIdx, this.providers.length),
508
- ...this.providers.slice(0, currentProviderIdx)
509
- ];
510
- for (const provider of providers) {
506
+ const options = {
507
+ showContent: true,
508
+ showDisplay: true,
509
+ showType: true,
510
+ showOwner: true
511
+ };
512
+ for (const provider of this.providers) {
511
513
  try {
512
- const objects = await this.currentProvider.multiGetObjects({ ids, options });
513
- this.currentProvider = provider;
514
+ const objects = await provider.multiGetObjects({ ids, options });
514
515
  const parsedObjects = objects.map((object) => {
515
516
  const objectId = getObjectId(object);
516
517
  const objectType = getObjectType(object);
@@ -531,7 +532,10 @@ var SuiInteractor = class {
531
532
  });
532
533
  return parsedObjects;
533
534
  } catch (err) {
534
- console.warn(`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`);
535
+ await delay(2e3);
536
+ console.warn(
537
+ `Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
538
+ );
535
539
  }
536
540
  }
537
541
  throw new Error("Failed to get objects with all fullnodes");
@@ -548,7 +552,9 @@ var SuiInteractor = class {
548
552
  const objectIds = suiObjects.map((obj) => obj.objectId);
549
553
  const objects = await this.getObjects(objectIds);
550
554
  for (const object of objects) {
551
- const suiObject = suiObjects.find((obj) => obj.objectId === object.objectId);
555
+ const suiObject = suiObjects.find(
556
+ (obj) => obj.objectId === object.objectId
557
+ );
552
558
  if (suiObject instanceof SuiSharedObject) {
553
559
  suiObject.initialSharedVersion = object.initialSharedVersion;
554
560
  } else if (suiObject instanceof SuiOwnedObject) {
@@ -564,20 +570,29 @@ var SuiInteractor = class {
564
570
  * @param coinType the coin type, default is '0x2::SUI::SUI'
565
571
  */
566
572
  async selectCoins(addr, amount, coinType = "0x2::SUI::SUI") {
567
- const coins = await this.currentProvider.getCoins({ owner: addr, coinType });
568
573
  const selectedCoins = [];
569
574
  let totalAmount = 0;
570
- coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
571
- for (const coinData of coins.data) {
572
- selectedCoins.push({
573
- objectId: coinData.coinObjectId,
574
- digest: coinData.digest,
575
- version: coinData.version
575
+ let hasNext = true, nextCursor = null;
576
+ while (hasNext && totalAmount < amount) {
577
+ const coins = await this.currentProvider.getCoins({
578
+ owner: addr,
579
+ coinType,
580
+ cursor: nextCursor
576
581
  });
577
- totalAmount = totalAmount + parseInt(coinData.balance);
578
- if (totalAmount >= amount) {
579
- break;
582
+ coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
583
+ for (const coinData of coins.data) {
584
+ selectedCoins.push({
585
+ objectId: coinData.coinObjectId,
586
+ digest: coinData.digest,
587
+ version: coinData.version
588
+ });
589
+ totalAmount = totalAmount + parseInt(coinData.balance);
590
+ if (totalAmount >= amount) {
591
+ break;
592
+ }
580
593
  }
594
+ nextCursor = coins.nextCursor;
595
+ hasNext = coins.hasNextPage;
581
596
  }
582
597
  if (!selectedCoins.length) {
583
598
  throw new Error("No valid coins found for the transaction.");
@@ -682,7 +697,10 @@ var SuiKit = class {
682
697
  return signer.signTransactionBlock({ transactionBlock: tx });
683
698
  }
684
699
  async signAndSendTxn(tx, derivePathParams) {
685
- const { transactionBlockBytes, signature } = await this.signTxn(tx, derivePathParams);
700
+ const { transactionBlockBytes, signature } = await this.signTxn(
701
+ tx,
702
+ derivePathParams
703
+ );
686
704
  return this.suiInteractor.sendTx(transactionBlockBytes, signature);
687
705
  }
688
706
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/suiKit.ts","../src/libs/suiAccountManager/index.ts","../src/libs/suiAccountManager/keypair.ts","../src/libs/suiAccountManager/util.ts","../src/libs/suiAccountManager/crypto.ts","../src/libs/suiTxBuilder/index.ts","../src/libs/suiTxBuilder/util.ts","../src/libs/suiInteractor/suiInteractor.ts","../src/libs/suiModel/suiOwnedObject.ts","../src/libs/suiModel/suiSharedObject.ts","../src/libs/suiInteractor/defaultConfig.ts"],"sourcesContent":["export {\n TransactionBlock,\n SUI_CLOCK_OBJECT_ID,\n SUI_SYSTEM_STATE_OBJECT_ID,\n} from '@mysten/sui.js';\nexport { SuiKit } from './suiKit';\nexport { SuiAccountManager } from './libs/suiAccountManager';\nexport { SuiTxBlock } from './libs/suiTxBuilder';\nexport type * from './types';\n","/**\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n */\nimport {\n RawSigner,\n TransactionBlock,\n DevInspectResults,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js';\nimport { SuiAccountManager } from './libs/suiAccountManager';\nimport { SuiTxBlock } from './libs/suiTxBuilder';\nimport { SuiInteractor, getDefaultConnection } from './libs/suiInteractor';\nimport { SuiSharedObject, SuiOwnedObject } from './libs/suiModel';\nimport { SuiKitParams, DerivePathParams, SuiTxArg, SuiVecTxArg } from './types';\n\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n public accountManager: SuiAccountManager;\n public suiInteractor: SuiInteractor;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n */\n constructor({\n mnemonics,\n secretKey,\n networkType,\n fullnodeUrls,\n }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n fullnodeUrls = fullnodeUrls || [getDefaultConnection(networkType).fullnode];\n this.suiInteractor = new SuiInteractor(fullnodeUrls);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.suiInteractor.currentProvider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() {\n return this.accountManager.currentAddress;\n }\n\n provider() {\n return this.suiInteractor.currentProvider;\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.suiInteractor.currentProvider.getBalance({ owner, coinType });\n }\n\n async getObjects(objectIds: string[]) {\n return this.suiInteractor.getObjects(objectIds);\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiSharedObject | SuiOwnedObject)[]) {\n return this.suiInteractor.updateObjects(suiObjects);\n }\n\n async signTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<SuiTransactionBlockResponse> {\n const { transactionBlockBytes, signature } = await this.signTxn(tx, derivePathParams);\n return this.suiInteractor.sendTx(transactionBlockBytes, signature);\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(\n recipient: string,\n amount: number,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(\n recipients: string[],\n amounts: number[],\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(\n recipients: string[],\n amounts: number[],\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.suiInteractor.selectCoins(\n owner,\n totalAmount,\n coinType\n );\n tx.transferCoinToMany(\n coins.map((c) => c.objectId),\n owner,\n recipients,\n amounts\n );\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async transferCoin(\n recipient: string,\n amount: number,\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n return this.transferCoinToMany(\n [recipient],\n [amount],\n coinType,\n derivePathParams\n );\n }\n\n async transferObjects(\n objects: string[],\n recipient: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async moveCall(callParams: {\n target: string;\n arguments?: (SuiTxArg | SuiVecTxArg)[];\n typeArguments?: string[];\n derivePathParams?: DerivePathParams;\n }) {\n const {\n target,\n arguments: args = [],\n typeArguments = [],\n derivePathParams,\n } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(\n amount: number,\n coinType: string,\n owner?: string\n ) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.suiInteractor.selectCoins(owner, amount, coinType);\n return coins.map((c) => c.objectId);\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(\n amount: number,\n validatorAddr: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.suiInteractor.currentProvider.devInspectTransactionBlock({\n transactionBlock: tx,\n sender: this.getAddress(derivePathParams),\n });\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport { getKeyPair } from './keypair';\nimport { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';\nimport { generateMnemonic } from './crypto';\nimport type { AccountMangerParams, DerivePathParams } from 'src/types';\n\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || '';\n this.secretKey = secretKey || '';\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24);\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams)\n .getPublicKey()\n .toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport type { DerivePathParams } from 'src/types';\n\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (\n derivePathParams: DerivePathParams = {}\n) => {\n const {\n accountIndex = 0,\n isExternal = false,\n addressIndex = 0,\n } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n};\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (\n mnemonics: string,\n derivePathParams: DerivePathParams = {}\n) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n};\n","import { fromB64 } from '@mysten/sui.js';\n\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) =>\n /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport const fromHEX = (hexStr: string): Uint8Array => {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array');\n }\n const intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)\n ?.map((byte) => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n};\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str);\n } else if (isBase64(str)) {\n return fromB64(str);\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n};\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n};\n","import { generateMnemonic as genMnemonic } from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english';\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256;\n return genMnemonic(wordlist, strength);\n};\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n TransactionExpiration,\n SuiObjectRef,\n SharedObjectRef,\n JsonRpcProvider,\n TransactionType,\n Transactions,\n ObjectCallArg,\n} from '@mysten/sui.js';\nimport { convertArgs } from './util';\nimport type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from 'src/types';\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor(transaction?: TransactionBlock) {\n this.txBlock = new TransactionBlock(transaction);\n }\n\n //======== override methods of TransactionBlock ============\n\n address(value: string) {\n return this.txBlock.pure(value, 'address');\n }\n pure(value: unknown, type?: string) {\n return this.txBlock.pure(value, type);\n }\n object(value: string | ObjectCallArg) {\n return this.txBlock.object(value);\n }\n objectRef(ref: SuiObjectRef) {\n return this.txBlock.objectRef(ref);\n }\n sharedObjectRef(ref: SharedObjectRef) {\n return this.txBlock.sharedObjectRef(ref);\n }\n setSender(sender: string) {\n return this.txBlock.setSender(sender);\n }\n setSenderIfNotSet(sender: string) {\n return this.txBlock.setSenderIfNotSet(sender);\n }\n setExpiration(expiration?: TransactionExpiration) {\n return this.txBlock.setExpiration(expiration);\n }\n setGasPrice(price: number | bigint) {\n return this.txBlock.setGasPrice(price);\n }\n setGasBudget(budget: number | bigint) {\n return this.txBlock.setGasBudget(budget);\n }\n setGasOwner(owner: string) {\n return this.txBlock.setGasOwner(owner);\n }\n setGasPayment(payments: SuiObjectRef[]) {\n return this.txBlock.setGasPayment(payments);\n }\n\n add(transaction: TransactionType) {\n return this.txBlock.add(transaction);\n }\n serialize() {\n return this.txBlock.serialize();\n }\n build(\n params: {\n provider?: JsonRpcProvider;\n onlyTransactionKind?: boolean;\n } = {}\n ) {\n return this.txBlock.build(params);\n }\n getDigest({ provider }: { provider?: JsonRpcProvider } = {}) {\n return this.txBlock.getDigest({ provider });\n }\n\n get gas() {\n return this.txBlock.gas;\n }\n get blockData() {\n return this.txBlock.blockData;\n }\n\n transferObjects(objects: SuiObjectArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(convertArgs(this.txBlock, objects), tx.pure(recipient));\n return this;\n }\n splitCoins(coin: SuiObjectArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = convertArgs(this.txBlock, [coin])[0];\n const res = tx.splitCoins(\n coinObject,\n amounts.map((m) => tx.pure(m))\n );\n return amounts.map((_, i) => res[i]);\n }\n mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {\n const destinationObject = convertArgs(this.txBlock, [destination])[0];\n const sourceObjects = convertArgs(this.txBlock, sources);\n return this.txBlock.mergeCoins(destinationObject, sourceObjects);\n }\n publish(...args: Parameters<(typeof Transactions)['Publish']>) {\n return this.txBlock.publish(...args);\n }\n upgrade(...args: Parameters<(typeof Transactions)['Upgrade']>) {\n return this.txBlock.upgrade(...args);\n }\n makeMoveVec(...args: Parameters<(typeof Transactions)['MakeMoveVec']>) {\n return this.txBlock.makeMoveVec(...args);\n }\n\n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(\n target: string,\n args: (SuiTxArg | SuiVecTxArg)[] = [],\n typeArgs: string[] = []\n ) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex =\n /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null)\n throw new Error(\n 'Invalid target format. Expected `${string}::${string}::${string}`'\n );\n const convertedArgs = convertArgs(this.txBlock, args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n //======== enhance methods ============\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n\n const tx = this.txBlock;\n const coins = tx.splitCoins(\n tx.gas,\n amounts.map((amount) => tx.pure(amount))\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n takeAmountFromCoins(coins: SuiObjectArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(\n tx.gas,\n amounts.map((m) => tx.pure(m))\n );\n }\n\n splitMultiCoins(coins: SuiObjectArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(\n mergedCoin,\n amounts.map((m) => tx.pure(m))\n );\n return { splitedCoins, mergedCoin };\n }\n\n transferCoinToMany(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipients: string[],\n amounts: number[]\n ) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(\n inputCoins,\n amounts\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender));\n return this;\n }\n\n transferCoin(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipient: string,\n amount: number\n ) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [\n tx.object(SUI_SYSTEM_STATE_OBJECT_ID),\n stakeCoin,\n tx.pure(validatorAddr),\n ],\n });\n return tx;\n }\n}\n","import {\n normalizeSuiObjectId,\n TransactionArgument,\n TransactionBlock,\n} from '@mysten/sui.js';\nimport { SuiTxArg, SuiInputTypes } from 'src/types';\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object';\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64';\n } else if (typeof value === 'boolean') {\n return 'bool';\n } else {\n return 'object';\n }\n};\n\n/**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\nexport function makeVecParam(\n txBlock: TransactionBlock,\n args: SuiTxArg[],\n type?: SuiInputTypes\n) {\n if (args.length === 0)\n throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0]);\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map((arg) =>\n typeof arg === 'string'\n ? txBlock.object(normalizeSuiObjectId(arg))\n : (arg as any)\n );\n return txBlock.makeMoveVec({ objects });\n } else {\n const vecType = type || defaultSuiType;\n return txBlock.pure(args, `vector<${vecType}>`);\n }\n}\n\nexport function isMoveVecArg(arg: any) {\n const isFullMoveVecArg =\n arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n}\n\nexport function convertArgs(\n txBlock: TransactionBlock,\n args: any[]\n): TransactionArgument[] {\n return args.map((arg) => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return txBlock.object(normalizeSuiObjectId(arg));\n } else if (isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? makeVecParam(txBlock, arg.value, vecType)\n : makeVecParam(txBlock, arg);\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return txBlock.pure(arg);\n } else {\n // We do nothing, because it's most likely already a move value\n return arg;\n }\n });\n}\n","import {\n SuiTransactionBlockResponse,\n SuiTransactionBlockResponseOptions,\n JsonRpcProvider,\n Connection,\n getObjectDisplay,\n getObjectFields,\n getObjectId,\n getObjectType,\n getObjectVersion,\n getSharedObjectInitialVersion\n} from '@mysten/sui.js';\nimport { ObjectData } from \"src/types\";\nimport { SuiOwnedObject, SuiSharedObject } from \"../suiModel\";\n\n/**\n * `SuiTransactionSender` is used to send transaction with a given gas coin.\n * It always uses the gas coin to pay for the gas,\n * and update the gas coin after the transaction.\n */\nexport class SuiInteractor {\n public readonly providers: JsonRpcProvider[];\n public currentProvider: JsonRpcProvider;\n constructor(fullNodeUrls: string[]) {\n if (fullNodeUrls.length === 0) throw new Error('fullNodeUrls must not be empty');\n this.providers = fullNodeUrls.map(url => new JsonRpcProvider(new Connection({ fullnode: url })));\n this.currentProvider = this.providers[0];\n }\n\n switchToNextProvider() {\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n this.currentProvider = this.providers[(currentProviderIdx + 1) % this.providers.length];\n }\n\n async sendTx(\n transactionBlock: Uint8Array | string,\n signature: string | string[],\n ): Promise<SuiTransactionBlockResponse> {\n\n const txResOptions: SuiTransactionBlockResponseOptions = {\n showEvents: true,\n showEffects: true,\n showObjectChanges: true,\n showBalanceChanges: true,\n }\n\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n const providers = [\n ...this.providers.slice(currentProviderIdx, this.providers.length),\n ...this.providers.slice(0, currentProviderIdx),\n ]\n\n for (const provider of providers) {\n try {\n const res = await this.currentProvider.executeTransactionBlock({\n transactionBlock,\n signature,\n options: txResOptions\n });\n this.currentProvider = provider;\n return res;\n } catch (err) {\n console.warn(`Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`);\n }\n }\n throw new Error('Failed to send transaction with all fullnodes');\n }\n async getObjects(ids: string[]) {\n const options = { showContent: true, showDisplay: true, showType: true, showOwner: true };\n\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n const providers = [\n ...this.providers.slice(currentProviderIdx, this.providers.length),\n ...this.providers.slice(0, currentProviderIdx),\n ]\n\n for (const provider of providers) {\n try {\n const objects = await this.currentProvider.multiGetObjects({ ids, options });\n this.currentProvider = provider;\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectDigest = object.data ? object.data.digest : undefined;\n const initialSharedVersion = getSharedObjectInitialVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return {\n objectId,\n objectType,\n objectVersion,\n objectDigest,\n objectFields,\n objectDisplay,\n initialSharedVersion,\n };\n });\n return parsedObjects as ObjectData[];\n } catch (err) {\n console.warn(`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`);\n }\n }\n throw new Error('Failed to get objects with all fullnodes');\n }\n\n async getObject(id: string) {\n const objects = await this.getObjects([id]);\n return objects[0];\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiOwnedObject | SuiSharedObject)[]) {\n const objectIds = suiObjects.map((obj) => obj.objectId);\n const objects = await this.getObjects(objectIds);\n for(const object of objects) {\n const suiObject = suiObjects.find((obj) => obj.objectId === object.objectId);\n if(suiObject instanceof SuiSharedObject) {\n suiObject.initialSharedVersion = object.initialSharedVersion;\n } else if (suiObject instanceof SuiOwnedObject) {\n suiObject.version = object.objectVersion;\n suiObject.digest = object.objectDigest;\n }\n }\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(\n addr: string,\n amount: number,\n coinType: string = '0x2::SUI::SUI'\n ) {\n const coins = await this.currentProvider.getCoins({ owner: addr, coinType });\n const selectedCoins: {\n objectId: string;\n digest: string;\n version: string;\n }[] = [];\n let totalAmount = 0;\n // Sort the coins by balance in descending order\n coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));\n for (const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import { Infer } from 'superstruct';\nimport {\n getObjectChanges,\n SuiTransactionBlockResponse,\n ObjectCallArg,\n ObjectId,\n Inputs\n} from '@mysten/sui.js';\n\nexport class SuiOwnedObject {\n public readonly objectId: string;\n public version?: number | string;\n public digest?: string;\n\n constructor(param: {objectId: string, version?: string, digest?: string}) {\n this.objectId = param.objectId;\n this.version = param.version;\n this.digest = param.digest;\n }\n\n /**\n * Check if the object is fully initialized.\n * So that when it's used as an input, it won't be necessary to fetch from fullnode again.\n * Which can save time when sending transactions.\n */\n isFullObject(): boolean {\n return !!this.version && !!this.digest;\n }\n\n asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.version || !this.digest) {\n return this.objectId;\n }\n return {\n Object: {\n ImmOrOwned: {\n objectId: this.objectId,\n version: this.version,\n digest: this.digest,\n }\n }\n }\n }\n\n /**\n * Update object version & digest based on the transaction response.\n * @param txResponse\n */\n updateFromTxResponse(txResponse: SuiTransactionBlockResponse) {\n const changes = getObjectChanges(txResponse);\n if (!changes) {\n throw new Error('Bad transaction response!');\n }\n for (const change of changes) {\n if (change.type === 'mutated' && change.objectId === this.objectId) {\n this.digest = change.digest;\n this.version = change.version;\n return;\n }\n }\n throw new Error('Could not find object in transaction response!');\n }\n}\n","import { Infer } from 'superstruct';\nimport {\n ObjectCallArg,\n ObjectId,\n} from '@mysten/sui.js';\n\nexport class SuiSharedObject {\n public readonly objectId: string;\n public initialSharedVersion?: number | string;\n\n constructor(param: {objectId: string, initialSharedVersion?: number, mutable?: boolean}) {\n this.objectId = param.objectId;\n this.initialSharedVersion = param.initialSharedVersion;\n }\n\n asCallArg(mutable: boolean = false): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.initialSharedVersion) {\n return this.objectId;\n }\n return {\n Object: {\n Shared: {\n objectId: this.objectId,\n initialSharedVersion: this.initialSharedVersion,\n mutable,\n }\n }\n }\n }\n}\n","import {\n localnetConnection,\n devnetConnection,\n testnetConnection,\n mainnetConnection,\n} from '@mysten/sui.js';\nimport type { Connection } from '@mysten/sui.js';\nimport type { NetworkType } from 'src/types';\nexport const defaultGasBudget = 10 ** 8; // 0.1 SUI, should be enough for most of the transactions\nexport const defaultGasPrice = 1000; // 1000 MIST\n\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @returns { fullNode: string, websocket: string, faucet?: string }\n */\nexport const getDefaultConnection = (\n networkType: NetworkType = 'devnet'\n): Connection => {\n switch (networkType) {\n case 'localnet':\n return localnetConnection;\n case 'devnet':\n return devnetConnection;\n case 'testnet':\n return testnetConnection;\n case 'mainnet':\n return mainnetConnection;\n default:\n return devnetConnection;\n }\n};\n"],"mappings":";AAAA;AAAA,EACE,oBAAAA;AAAA,EACA;AAAA,EACA,8BAAAC;AAAA,OACK;;;ACDP;AAAA,EACE;AAAA,OAIK;;;ACRP,SAAS,kBAAAC,uBAAsB;;;ACA/B,SAAS,sBAAsB;AAOxB,IAAM,sBAAsB,CACjC,mBAAqC,CAAC,MACnC;AACH,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,aAAa;AAAA,IACb,eAAe;AAAA,EACjB,IAAI;AACJ,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CACxB,WACA,mBAAqC,CAAC,MACn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W,gBAAgB;AAAA,IAC1C,CAAC;AAAA,EACH;AACF;","names":["TransactionBlock","SUI_SYSTEM_STATE_OBJECT_ID","Ed25519Keypair","Ed25519Keypair","TransactionBlock","TransactionBlock","JsonRpcProvider","JsonRpcProvider"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/suiKit.ts","../src/libs/suiAccountManager/index.ts","../src/libs/suiAccountManager/keypair.ts","../src/libs/suiAccountManager/util.ts","../src/libs/suiAccountManager/crypto.ts","../src/libs/suiTxBuilder/index.ts","../src/libs/suiTxBuilder/util.ts","../src/libs/suiInteractor/suiInteractor.ts","../src/libs/suiModel/suiOwnedObject.ts","../src/libs/suiModel/suiSharedObject.ts","../src/libs/suiInteractor/util.ts","../src/libs/suiInteractor/defaultConfig.ts"],"sourcesContent":["export {\n TransactionBlock,\n SUI_CLOCK_OBJECT_ID,\n SUI_SYSTEM_STATE_OBJECT_ID,\n} from '@mysten/sui.js';\nexport { SuiKit } from './suiKit';\nexport { SuiAccountManager } from './libs/suiAccountManager';\nexport { SuiTxBlock } from './libs/suiTxBuilder';\nexport type * from './types';\n","/**\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n */\nimport {\n RawSigner,\n TransactionBlock,\n DevInspectResults,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js';\nimport { SuiAccountManager } from './libs/suiAccountManager';\nimport { SuiTxBlock } from './libs/suiTxBuilder';\nimport { SuiInteractor, getDefaultConnection } from './libs/suiInteractor';\nimport { SuiSharedObject, SuiOwnedObject } from './libs/suiModel';\nimport { SuiKitParams, DerivePathParams, SuiTxArg, SuiVecTxArg } from './types';\n\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n public accountManager: SuiAccountManager;\n public suiInteractor: SuiInteractor;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n */\n constructor({\n mnemonics,\n secretKey,\n networkType,\n fullnodeUrls,\n }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n fullnodeUrls = fullnodeUrls || [getDefaultConnection(networkType).fullnode];\n this.suiInteractor = new SuiInteractor(fullnodeUrls);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.suiInteractor.currentProvider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() {\n return this.accountManager.currentAddress;\n }\n\n provider() {\n return this.suiInteractor.currentProvider;\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.suiInteractor.currentProvider.getBalance({ owner, coinType });\n }\n\n async getObjects(objectIds: string[]) {\n return this.suiInteractor.getObjects(objectIds);\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiSharedObject | SuiOwnedObject)[]) {\n return this.suiInteractor.updateObjects(suiObjects);\n }\n\n async signTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<SuiTransactionBlockResponse> {\n const { transactionBlockBytes, signature } = await this.signTxn(\n tx,\n derivePathParams\n );\n return this.suiInteractor.sendTx(transactionBlockBytes, signature);\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(\n recipient: string,\n amount: number,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(\n recipients: string[],\n amounts: number[],\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(\n recipients: string[],\n amounts: number[],\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.suiInteractor.selectCoins(\n owner,\n totalAmount,\n coinType\n );\n tx.transferCoinToMany(\n coins.map((c) => c.objectId),\n owner,\n recipients,\n amounts\n );\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async transferCoin(\n recipient: string,\n amount: number,\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n return this.transferCoinToMany(\n [recipient],\n [amount],\n coinType,\n derivePathParams\n );\n }\n\n async transferObjects(\n objects: string[],\n recipient: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async moveCall(callParams: {\n target: string;\n arguments?: (SuiTxArg | SuiVecTxArg)[];\n typeArguments?: string[];\n derivePathParams?: DerivePathParams;\n }) {\n const {\n target,\n arguments: args = [],\n typeArguments = [],\n derivePathParams,\n } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(\n amount: number,\n coinType: string,\n owner?: string\n ) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.suiInteractor.selectCoins(owner, amount, coinType);\n return coins.map((c) => c.objectId);\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(\n amount: number,\n validatorAddr: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.suiInteractor.currentProvider.devInspectTransactionBlock({\n transactionBlock: tx,\n sender: this.getAddress(derivePathParams),\n });\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport { getKeyPair } from './keypair';\nimport { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';\nimport { generateMnemonic } from './crypto';\nimport type { AccountMangerParams, DerivePathParams } from 'src/types';\n\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || '';\n this.secretKey = secretKey || '';\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24);\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams)\n .getPublicKey()\n .toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport type { DerivePathParams } from 'src/types';\n\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (\n derivePathParams: DerivePathParams = {}\n) => {\n const {\n accountIndex = 0,\n isExternal = false,\n addressIndex = 0,\n } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n};\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (\n mnemonics: string,\n derivePathParams: DerivePathParams = {}\n) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n};\n","import { fromB64 } from '@mysten/sui.js';\n\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) =>\n /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport const fromHEX = (hexStr: string): Uint8Array => {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array');\n }\n const intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)\n ?.map((byte) => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n};\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str);\n } else if (isBase64(str)) {\n return fromB64(str);\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n};\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n};\n","import { generateMnemonic as genMnemonic } from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english';\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256;\n return genMnemonic(wordlist, strength);\n};\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n TransactionExpiration,\n SuiObjectRef,\n SharedObjectRef,\n JsonRpcProvider,\n TransactionType,\n Transactions,\n ObjectCallArg,\n} from '@mysten/sui.js';\nimport { convertArgs } from './util';\nimport type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from 'src/types';\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor(transaction?: TransactionBlock) {\n this.txBlock = new TransactionBlock(transaction);\n }\n\n //======== override methods of TransactionBlock ============\n\n address(value: string) {\n return this.txBlock.pure(value, 'address');\n }\n pure(value: unknown, type?: string) {\n return this.txBlock.pure(value, type);\n }\n object(value: string | ObjectCallArg) {\n return this.txBlock.object(value);\n }\n objectRef(ref: SuiObjectRef) {\n return this.txBlock.objectRef(ref);\n }\n sharedObjectRef(ref: SharedObjectRef) {\n return this.txBlock.sharedObjectRef(ref);\n }\n setSender(sender: string) {\n return this.txBlock.setSender(sender);\n }\n setSenderIfNotSet(sender: string) {\n return this.txBlock.setSenderIfNotSet(sender);\n }\n setExpiration(expiration?: TransactionExpiration) {\n return this.txBlock.setExpiration(expiration);\n }\n setGasPrice(price: number | bigint) {\n return this.txBlock.setGasPrice(price);\n }\n setGasBudget(budget: number | bigint) {\n return this.txBlock.setGasBudget(budget);\n }\n setGasOwner(owner: string) {\n return this.txBlock.setGasOwner(owner);\n }\n setGasPayment(payments: SuiObjectRef[]) {\n return this.txBlock.setGasPayment(payments);\n }\n\n add(transaction: TransactionType) {\n return this.txBlock.add(transaction);\n }\n serialize() {\n return this.txBlock.serialize();\n }\n build(\n params: {\n provider?: JsonRpcProvider;\n onlyTransactionKind?: boolean;\n } = {}\n ) {\n return this.txBlock.build(params);\n }\n getDigest({ provider }: { provider?: JsonRpcProvider } = {}) {\n return this.txBlock.getDigest({ provider });\n }\n\n get gas() {\n return this.txBlock.gas;\n }\n get blockData() {\n return this.txBlock.blockData;\n }\n\n transferObjects(objects: SuiObjectArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(convertArgs(this.txBlock, objects), tx.pure(recipient));\n return this;\n }\n splitCoins(coin: SuiObjectArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = convertArgs(this.txBlock, [coin])[0];\n const res = tx.splitCoins(\n coinObject,\n amounts.map((m) => tx.pure(m))\n );\n return amounts.map((_, i) => res[i]);\n }\n mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {\n const destinationObject = convertArgs(this.txBlock, [destination])[0];\n const sourceObjects = convertArgs(this.txBlock, sources);\n return this.txBlock.mergeCoins(destinationObject, sourceObjects);\n }\n publish(...args: Parameters<(typeof Transactions)['Publish']>) {\n return this.txBlock.publish(...args);\n }\n upgrade(...args: Parameters<(typeof Transactions)['Upgrade']>) {\n return this.txBlock.upgrade(...args);\n }\n makeMoveVec(...args: Parameters<(typeof Transactions)['MakeMoveVec']>) {\n return this.txBlock.makeMoveVec(...args);\n }\n\n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(\n target: string,\n args: (SuiTxArg | SuiVecTxArg)[] = [],\n typeArgs: string[] = []\n ) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex =\n /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null)\n throw new Error(\n 'Invalid target format. Expected `${string}::${string}::${string}`'\n );\n const convertedArgs = convertArgs(this.txBlock, args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n //======== enhance methods ============\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n\n const tx = this.txBlock;\n const coins = tx.splitCoins(\n tx.gas,\n amounts.map((amount) => tx.pure(amount))\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n takeAmountFromCoins(coins: SuiObjectArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(\n tx.gas,\n amounts.map((m) => tx.pure(m))\n );\n }\n\n splitMultiCoins(coins: SuiObjectArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(\n mergedCoin,\n amounts.map((m) => tx.pure(m))\n );\n return { splitedCoins, mergedCoin };\n }\n\n transferCoinToMany(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipients: string[],\n amounts: number[]\n ) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(\n inputCoins,\n amounts\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender));\n return this;\n }\n\n transferCoin(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipient: string,\n amount: number\n ) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [\n tx.object(SUI_SYSTEM_STATE_OBJECT_ID),\n stakeCoin,\n tx.pure(validatorAddr),\n ],\n });\n return tx;\n }\n}\n","import {\n normalizeSuiObjectId,\n TransactionArgument,\n TransactionBlock,\n} from '@mysten/sui.js';\nimport { SuiTxArg, SuiInputTypes } from 'src/types';\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object';\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64';\n } else if (typeof value === 'boolean') {\n return 'bool';\n } else {\n return 'object';\n }\n};\n\n/**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\nexport function makeVecParam(\n txBlock: TransactionBlock,\n args: SuiTxArg[],\n type?: SuiInputTypes\n) {\n if (args.length === 0)\n throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0]);\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map((arg) =>\n typeof arg === 'string'\n ? txBlock.object(normalizeSuiObjectId(arg))\n : (arg as any)\n );\n return txBlock.makeMoveVec({ objects });\n } else {\n const vecType = type || defaultSuiType;\n return txBlock.pure(args, `vector<${vecType}>`);\n }\n}\n\nexport function isMoveVecArg(arg: any) {\n const isFullMoveVecArg =\n arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n}\n\nexport function convertArgs(\n txBlock: TransactionBlock,\n args: any[]\n): TransactionArgument[] {\n return args.map((arg) => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return txBlock.object(normalizeSuiObjectId(arg));\n } else if (isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? makeVecParam(txBlock, arg.value, vecType)\n : makeVecParam(txBlock, arg);\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return txBlock.pure(arg);\n } else {\n // We do nothing, because it's most likely already a move value\n return arg;\n }\n });\n}\n","import {\n SuiTransactionBlockResponse,\n SuiTransactionBlockResponseOptions,\n JsonRpcProvider,\n Connection,\n getObjectDisplay,\n getObjectFields,\n getObjectId,\n getObjectType,\n getObjectVersion,\n getSharedObjectInitialVersion,\n} from '@mysten/sui.js';\nimport { ObjectData } from 'src/types';\nimport { SuiOwnedObject, SuiSharedObject } from '../suiModel';\nimport { delay } from './util';\n\n/**\n * `SuiTransactionSender` is used to send transaction with a given gas coin.\n * It always uses the gas coin to pay for the gas,\n * and update the gas coin after the transaction.\n */\nexport class SuiInteractor {\n public readonly providers: JsonRpcProvider[];\n public currentProvider: JsonRpcProvider;\n constructor(fullNodeUrls: string[]) {\n if (fullNodeUrls.length === 0)\n throw new Error('fullNodeUrls must not be empty');\n this.providers = fullNodeUrls.map(\n (url) => new JsonRpcProvider(new Connection({ fullnode: url }))\n );\n this.currentProvider = this.providers[0];\n }\n\n switchToNextProvider() {\n const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n this.currentProvider =\n this.providers[(currentProviderIdx + 1) % this.providers.length];\n }\n\n async sendTx(\n transactionBlock: Uint8Array | string,\n signature: string | string[]\n ): Promise<SuiTransactionBlockResponse> {\n const txResOptions: SuiTransactionBlockResponseOptions = {\n showEvents: true,\n showEffects: true,\n showObjectChanges: true,\n showBalanceChanges: true,\n };\n\n // const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n // const providers = [\n // ...this.providers.slice(currentProviderIdx, this.providers.length),\n // ...this.providers.slice(0, currentProviderIdx),\n // ]\n\n for (const provider of this.providers) {\n try {\n const res = await provider.executeTransactionBlock({\n transactionBlock,\n signature,\n options: txResOptions,\n });\n return res;\n } catch (err) {\n console.warn(\n `Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`\n );\n await delay(2000);\n }\n }\n throw new Error('Failed to send transaction with all fullnodes');\n }\n async getObjects(ids: string[]) {\n const options = {\n showContent: true,\n showDisplay: true,\n showType: true,\n showOwner: true,\n };\n\n // const currentProviderIdx = this.providers.indexOf(this.currentProvider);\n // const providers = [\n // ...this.providers.slice(currentProviderIdx, this.providers.length),\n // ...this.providers.slice(0, currentProviderIdx),\n // ]\n\n for (const provider of this.providers) {\n try {\n const objects = await provider.multiGetObjects({ ids, options });\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectDigest = object.data ? object.data.digest : undefined;\n const initialSharedVersion = getSharedObjectInitialVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return {\n objectId,\n objectType,\n objectVersion,\n objectDigest,\n objectFields,\n objectDisplay,\n initialSharedVersion,\n };\n });\n return parsedObjects as ObjectData[];\n } catch (err) {\n await delay(2000);\n console.warn(\n `Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`\n );\n }\n }\n throw new Error('Failed to get objects with all fullnodes');\n }\n\n async getObject(id: string) {\n const objects = await this.getObjects([id]);\n return objects[0];\n }\n\n /**\n * @description Update objects in a batch\n * @param suiObjects\n */\n async updateObjects(suiObjects: (SuiOwnedObject | SuiSharedObject)[]) {\n const objectIds = suiObjects.map((obj) => obj.objectId);\n const objects = await this.getObjects(objectIds);\n for (const object of objects) {\n const suiObject = suiObjects.find(\n (obj) => obj.objectId === object.objectId\n );\n if (suiObject instanceof SuiSharedObject) {\n suiObject.initialSharedVersion = object.initialSharedVersion;\n } else if (suiObject instanceof SuiOwnedObject) {\n suiObject.version = object.objectVersion;\n suiObject.digest = object.objectDigest;\n }\n }\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(\n addr: string,\n amount: number,\n coinType: string = '0x2::SUI::SUI'\n ) {\n const selectedCoins: {\n objectId: string;\n digest: string;\n version: string;\n }[] = [];\n let totalAmount = 0;\n let hasNext = true,\n nextCursor: string | null = null;\n while (hasNext && totalAmount < amount) {\n const coins = await this.currentProvider.getCoins({\n owner: addr,\n coinType: coinType,\n cursor: nextCursor,\n });\n // Sort the coins by balance in descending order\n coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));\n for (const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n nextCursor = coins.nextCursor;\n hasNext = coins.hasNextPage;\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import { Infer } from 'superstruct';\nimport {\n getObjectChanges,\n SuiTransactionBlockResponse,\n ObjectCallArg,\n ObjectId,\n} from '@mysten/sui.js';\n\nexport class SuiOwnedObject {\n public readonly objectId: string;\n public version?: number | string;\n public digest?: string;\n\n constructor(param: { objectId: string; version?: string; digest?: string }) {\n this.objectId = param.objectId;\n this.version = param.version;\n this.digest = param.digest;\n }\n\n /**\n * Check if the object is fully initialized.\n * So that when it's used as an input, it won't be necessary to fetch from fullnode again.\n * Which can save time when sending transactions.\n */\n isFullObject(): boolean {\n return !!this.version && !!this.digest;\n }\n\n asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.version || !this.digest) {\n return this.objectId;\n }\n return {\n Object: {\n ImmOrOwned: {\n objectId: this.objectId,\n version: this.version,\n digest: this.digest,\n },\n },\n };\n }\n\n /**\n * Update object version & digest based on the transaction response.\n * @param txResponse\n */\n updateFromTxResponse(txResponse: SuiTransactionBlockResponse) {\n const changes = getObjectChanges(txResponse);\n if (!changes) {\n throw new Error('Bad transaction response!');\n }\n for (const change of changes) {\n if (change.type === 'mutated' && change.objectId === this.objectId) {\n this.digest = change.digest;\n this.version = change.version;\n return;\n }\n }\n throw new Error('Could not find object in transaction response!');\n }\n}\n","import { Infer } from 'superstruct';\nimport { ObjectCallArg, ObjectId } from '@mysten/sui.js';\n\nexport class SuiSharedObject {\n public readonly objectId: string;\n public initialSharedVersion?: number | string;\n\n constructor(param: {\n objectId: string;\n initialSharedVersion?: number;\n mutable?: boolean;\n }) {\n this.objectId = param.objectId;\n this.initialSharedVersion = param.initialSharedVersion;\n }\n\n asCallArg(\n mutable: boolean = false\n ): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {\n if (!this.initialSharedVersion) {\n return this.objectId;\n }\n return {\n Object: {\n Shared: {\n objectId: this.objectId,\n initialSharedVersion: this.initialSharedVersion,\n mutable,\n },\n },\n };\n }\n}\n","export const delay = (ms: number) =>\n new Promise((resolve) => setTimeout(resolve, ms));\n","import {\n localnetConnection,\n devnetConnection,\n testnetConnection,\n mainnetConnection,\n} from '@mysten/sui.js';\nimport type { Connection } from '@mysten/sui.js';\nimport type { NetworkType } from 'src/types';\nexport const defaultGasBudget = 10 ** 8; // 0.1 SUI, should be enough for most of the transactions\nexport const defaultGasPrice = 1000; // 1000 MIST\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @returns { fullNode: string, websocket: string, faucet?: string }\n */\nexport const getDefaultConnection = (\n networkType: NetworkType = 'devnet'\n): Connection => {\n switch (networkType) {\n case 'localnet':\n return localnetConnection;\n case 'devnet':\n return devnetConnection;\n case 'testnet':\n return testnetConnection;\n case 'mainnet':\n return mainnetConnection;\n default:\n return devnetConnection;\n }\n};\n"],"mappings":";AAAA;AAAA,EACE,oBAAAA;AAAA,EACA;AAAA,EACA,8BAAAC;AAAA,OACK;;;ACDP;AAAA,EACE;AAAA,OAIK;;;ACRP,SAAS,kBAAAC,uBAAsB;;;ACA/B,SAAS,sBAAsB;AAOxB,IAAM,sBAAsB,CACjC,mBAAqC,CAAC,MACnC;AACH,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,aAAa;AAAA,IACb,eAAe;AAAA,EACjB,IAAI;AACJ,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CACxB,WACA,mBAAqC,CAAC,MACnC;AACH,QAAM,aAAa,oBAAoB,gBAAgB;AACvD,SAAO,eAAe,cAAc,WAAW,UAAU;AAC3D;;;ACrCA,SAAS,eAAe;AAMjB,IAAM,QAAQ,CAAC,QACpB,kCAAkC,KAAK,GAAG;AAOrC,IAAM,WAAW,CAAC,QAAgB,0BAA0B,KAAK,GAAG;AAMpE,IAAM,UAAU,CAAC,WAA+B;AACrD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,QAAM,SAAS,OACZ,QAAQ,MAAM,EAAE,EAChB,MAAM,SAAS,GACd,IAAI,CAAC,SAAS,SAAS,MAAM,EAAE,CAAC;AAEpC,MAAI,CAAC,UAAU,OAAO,WAAW,GAAG;AAClC,UAAM,IAAI,MAAM,wBAAwB,QAAQ;AAAA,EAClD;AACA,SAAO,WAAW,KAAK,MAAM;AAC/B;AAKO,IAAM,0BAA0B,CAAC,QAA4B;AAClE,MAAI,MAAM,GAAG,GAAG;AACd,WAAO,QAAQ,GAAG;AAAA,EACpB,WAAW,SAAS,GAAG,GAAG;AACxB,WAAO,QAAQ,GAAG;AAAA,EACpB,OAAO;AACL,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AACF;AAEA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AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SACJ,QACA,eACA,kBACA;AACA,UAAM,KAAK,IAAI,WAAW;AAC1B,OAAG,SAAS,QAAQ,aAAa;AACjC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WACJ,IACA,kBAC4B;AAC5B,SAAK,cAAc,aAAa,GAAG,UAAU;AAC7C,WAAO,KAAK,cAAc,gBAAgB,2BAA2B;AAAA,MACnE,kBAAkB;AAAA,MAClB,QAAQ,KAAK,WAAW,gBAAgB;AAAA,IAC1C,CAAC;AAAA,EACH;AACF;","names":["TransactionBlock","SUI_SYSTEM_STATE_OBJECT_ID","Ed25519Keypair","Ed25519Keypair","TransactionBlock","TransactionBlock","JsonRpcProvider","JsonRpcProvider"]}
@@ -1,6 +1,6 @@
1
1
  import { SuiTransactionBlockResponse, JsonRpcProvider } from '@mysten/sui.js';
2
- import { ObjectData } from "src/types";
3
- import { SuiOwnedObject, SuiSharedObject } from "../suiModel";
2
+ import { ObjectData } from 'src/types';
3
+ import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
4
4
  /**
5
5
  * `SuiTransactionSender` is used to send transaction with a given gas coin.
6
6
  * It always uses the gas coin to pay for the gas,
@@ -0,0 +1 @@
1
+ export declare const delay: (ms: number) => Promise<unknown>;
@@ -1,5 +1,5 @@
1
1
  import { Infer } from 'superstruct';
2
- import { DisplayFieldsResponse, ObjectCallArg, ObjectContentFields, SharedObjectRef, SuiObjectRef, TransactionArgument } from "@mysten/sui.js";
2
+ import { DisplayFieldsResponse, ObjectCallArg, ObjectContentFields, SharedObjectRef, SuiObjectRef, TransactionArgument } from '@mysten/sui.js';
3
3
  export type AccountMangerParams = {
4
4
  mnemonics?: string;
5
5
  secretKey?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-kit",
3
- "version": "0.38.0",
3
+ "version": "0.38.2",
4
4
  "description": "Tookit for interacting with SUI network",
5
5
  "keywords": [
6
6
  "sui",
@@ -47,26 +47,26 @@
47
47
  "@mysten/sui.js": "^0.37.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@commitlint/cli": "^17.6.6",
51
- "@commitlint/config-conventional": "^17.6.6",
52
- "@commitlint/prompt-cli": "^17.6.6",
53
- "@types/node": "^20.3.2",
50
+ "@commitlint/cli": "^17.6.7",
51
+ "@commitlint/config-conventional": "^17.6.7",
52
+ "@commitlint/prompt-cli": "^17.6.7",
53
+ "@types/node": "^20.4.5",
54
54
  "@types/tmp": "^0.2.3",
55
- "@typescript-eslint/eslint-plugin": "^5.60.1",
56
- "@typescript-eslint/parser": "^5.60.1",
55
+ "@typescript-eslint/eslint-plugin": "^6.2.1",
56
+ "@typescript-eslint/parser": "^6.2.1",
57
57
  "dotenv": "^16.3.1",
58
- "eslint": "^8.43.0",
59
- "eslint-config-prettier": "^8.8.0",
60
- "eslint-plugin-prettier": "^4.2.1",
58
+ "eslint": "^8.46.0",
59
+ "eslint-config-prettier": "^8.9.0",
60
+ "eslint-plugin-prettier": "^5.0.0",
61
61
  "husky": "^8.0.3",
62
62
  "lint-staged": "^13.2.3",
63
- "prettier": "^2.8.8",
63
+ "prettier": "^3.0.0",
64
64
  "ts-node": "^10.9.1",
65
65
  "tsconfig-paths": "^4.2.0",
66
66
  "tsup": "^7.1.0",
67
67
  "typedoc": "^0.24.8",
68
- "typescript": "^5.0.4",
69
- "vitest": "^0.32.2"
68
+ "typescript": "^5.1.6",
69
+ "vitest": "^0.33.0"
70
70
  },
71
71
  "lint-staged": {
72
72
  "**/*.ts": [
@@ -9,7 +9,6 @@ import type { NetworkType } from 'src/types';
9
9
  export const defaultGasBudget = 10 ** 8; // 0.1 SUI, should be enough for most of the transactions
10
10
  export const defaultGasPrice = 1000; // 1000 MIST
11
11
 
12
-
13
12
  /**
14
13
  * @description Get the default fullnode url and faucet url for the given network type
15
14
  * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
@@ -1,2 +1,2 @@
1
1
  export { SuiInteractor } from './suiInteractor';
2
- export { getDefaultConnection } from'./defaultConfig';
2
+ export { getDefaultConnection } from './defaultConfig';
@@ -8,10 +8,11 @@ import {
8
8
  getObjectId,
9
9
  getObjectType,
10
10
  getObjectVersion,
11
- getSharedObjectInitialVersion
11
+ getSharedObjectInitialVersion,
12
12
  } from '@mysten/sui.js';
13
- import { ObjectData } from "src/types";
14
- import { SuiOwnedObject, SuiSharedObject } from "../suiModel";
13
+ import { ObjectData } from 'src/types';
14
+ import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
15
+ import { delay } from './util';
15
16
 
16
17
  /**
17
18
  * `SuiTransactionSender` is used to send transaction with a given gas coin.
@@ -22,62 +23,71 @@ export class SuiInteractor {
22
23
  public readonly providers: JsonRpcProvider[];
23
24
  public currentProvider: JsonRpcProvider;
24
25
  constructor(fullNodeUrls: string[]) {
25
- if (fullNodeUrls.length === 0) throw new Error('fullNodeUrls must not be empty');
26
- this.providers = fullNodeUrls.map(url => new JsonRpcProvider(new Connection({ fullnode: url })));
26
+ if (fullNodeUrls.length === 0)
27
+ throw new Error('fullNodeUrls must not be empty');
28
+ this.providers = fullNodeUrls.map(
29
+ (url) => new JsonRpcProvider(new Connection({ fullnode: url }))
30
+ );
27
31
  this.currentProvider = this.providers[0];
28
32
  }
29
33
 
30
34
  switchToNextProvider() {
31
35
  const currentProviderIdx = this.providers.indexOf(this.currentProvider);
32
- this.currentProvider = this.providers[(currentProviderIdx + 1) % this.providers.length];
36
+ this.currentProvider =
37
+ this.providers[(currentProviderIdx + 1) % this.providers.length];
33
38
  }
34
39
 
35
40
  async sendTx(
36
41
  transactionBlock: Uint8Array | string,
37
- signature: string | string[],
42
+ signature: string | string[]
38
43
  ): Promise<SuiTransactionBlockResponse> {
39
-
40
44
  const txResOptions: SuiTransactionBlockResponseOptions = {
41
45
  showEvents: true,
42
46
  showEffects: true,
43
47
  showObjectChanges: true,
44
48
  showBalanceChanges: true,
45
- }
49
+ };
46
50
 
47
- const currentProviderIdx = this.providers.indexOf(this.currentProvider);
48
- const providers = [
49
- ...this.providers.slice(currentProviderIdx, this.providers.length),
50
- ...this.providers.slice(0, currentProviderIdx),
51
- ]
51
+ // const currentProviderIdx = this.providers.indexOf(this.currentProvider);
52
+ // const providers = [
53
+ // ...this.providers.slice(currentProviderIdx, this.providers.length),
54
+ // ...this.providers.slice(0, currentProviderIdx),
55
+ // ]
52
56
 
53
- for (const provider of providers) {
57
+ for (const provider of this.providers) {
54
58
  try {
55
- const res = await this.currentProvider.executeTransactionBlock({
59
+ const res = await provider.executeTransactionBlock({
56
60
  transactionBlock,
57
61
  signature,
58
- options: txResOptions
62
+ options: txResOptions,
59
63
  });
60
- this.currentProvider = provider;
61
64
  return res;
62
65
  } catch (err) {
63
- console.warn(`Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`);
66
+ console.warn(
67
+ `Failed to send transaction with fullnode ${provider.connection.fullnode}: ${err}`
68
+ );
69
+ await delay(2000);
64
70
  }
65
71
  }
66
72
  throw new Error('Failed to send transaction with all fullnodes');
67
73
  }
68
74
  async getObjects(ids: string[]) {
69
- const options = { showContent: true, showDisplay: true, showType: true, showOwner: true };
75
+ const options = {
76
+ showContent: true,
77
+ showDisplay: true,
78
+ showType: true,
79
+ showOwner: true,
80
+ };
70
81
 
71
- const currentProviderIdx = this.providers.indexOf(this.currentProvider);
72
- const providers = [
73
- ...this.providers.slice(currentProviderIdx, this.providers.length),
74
- ...this.providers.slice(0, currentProviderIdx),
75
- ]
82
+ // const currentProviderIdx = this.providers.indexOf(this.currentProvider);
83
+ // const providers = [
84
+ // ...this.providers.slice(currentProviderIdx, this.providers.length),
85
+ // ...this.providers.slice(0, currentProviderIdx),
86
+ // ]
76
87
 
77
- for (const provider of providers) {
88
+ for (const provider of this.providers) {
78
89
  try {
79
- const objects = await this.currentProvider.multiGetObjects({ ids, options });
80
- this.currentProvider = provider;
90
+ const objects = await provider.multiGetObjects({ ids, options });
81
91
  const parsedObjects = objects.map((object) => {
82
92
  const objectId = getObjectId(object);
83
93
  const objectType = getObjectType(object);
@@ -98,7 +108,10 @@ export class SuiInteractor {
98
108
  });
99
109
  return parsedObjects as ObjectData[];
100
110
  } catch (err) {
101
- console.warn(`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`);
111
+ await delay(2000);
112
+ console.warn(
113
+ `Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
114
+ );
102
115
  }
103
116
  }
104
117
  throw new Error('Failed to get objects with all fullnodes');
@@ -116,9 +129,11 @@ export class SuiInteractor {
116
129
  async updateObjects(suiObjects: (SuiOwnedObject | SuiSharedObject)[]) {
117
130
  const objectIds = suiObjects.map((obj) => obj.objectId);
118
131
  const objects = await this.getObjects(objectIds);
119
- for(const object of objects) {
120
- const suiObject = suiObjects.find((obj) => obj.objectId === object.objectId);
121
- if(suiObject instanceof SuiSharedObject) {
132
+ for (const object of objects) {
133
+ const suiObject = suiObjects.find(
134
+ (obj) => obj.objectId === object.objectId
135
+ );
136
+ if (suiObject instanceof SuiSharedObject) {
122
137
  suiObject.initialSharedVersion = object.initialSharedVersion;
123
138
  } else if (suiObject instanceof SuiOwnedObject) {
124
139
  suiObject.version = object.objectVersion;
@@ -138,25 +153,36 @@ export class SuiInteractor {
138
153
  amount: number,
139
154
  coinType: string = '0x2::SUI::SUI'
140
155
  ) {
141
- const coins = await this.currentProvider.getCoins({ owner: addr, coinType });
142
156
  const selectedCoins: {
143
157
  objectId: string;
144
158
  digest: string;
145
159
  version: string;
146
160
  }[] = [];
147
161
  let totalAmount = 0;
148
- // Sort the coins by balance in descending order
149
- coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
150
- for (const coinData of coins.data) {
151
- selectedCoins.push({
152
- objectId: coinData.coinObjectId,
153
- digest: coinData.digest,
154
- version: coinData.version,
162
+ let hasNext = true,
163
+ nextCursor: string | null = null;
164
+ while (hasNext && totalAmount < amount) {
165
+ const coins = await this.currentProvider.getCoins({
166
+ owner: addr,
167
+ coinType: coinType,
168
+ cursor: nextCursor,
155
169
  });
156
- totalAmount = totalAmount + parseInt(coinData.balance);
157
- if (totalAmount >= amount) {
158
- break;
170
+ // Sort the coins by balance in descending order
171
+ coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
172
+ for (const coinData of coins.data) {
173
+ selectedCoins.push({
174
+ objectId: coinData.coinObjectId,
175
+ digest: coinData.digest,
176
+ version: coinData.version,
177
+ });
178
+ totalAmount = totalAmount + parseInt(coinData.balance);
179
+ if (totalAmount >= amount) {
180
+ break;
181
+ }
159
182
  }
183
+
184
+ nextCursor = coins.nextCursor;
185
+ hasNext = coins.hasNextPage;
160
186
  }
161
187
 
162
188
  if (!selectedCoins.length) {
@@ -0,0 +1,2 @@
1
+ export const delay = (ms: number) =>
2
+ new Promise((resolve) => setTimeout(resolve, ms));
@@ -1,2 +1,2 @@
1
- export { SuiOwnedObject } from './suiOwnedObject'
2
- export { SuiSharedObject } from './suiSharedObject'
1
+ export { SuiOwnedObject } from './suiOwnedObject';
2
+ export { SuiSharedObject } from './suiSharedObject';
@@ -4,7 +4,6 @@ import {
4
4
  SuiTransactionBlockResponse,
5
5
  ObjectCallArg,
6
6
  ObjectId,
7
- Inputs
8
7
  } from '@mysten/sui.js';
9
8
 
10
9
  export class SuiOwnedObject {
@@ -12,7 +11,7 @@ export class SuiOwnedObject {
12
11
  public version?: number | string;
13
12
  public digest?: string;
14
13
 
15
- constructor(param: {objectId: string, version?: string, digest?: string}) {
14
+ constructor(param: { objectId: string; version?: string; digest?: string }) {
16
15
  this.objectId = param.objectId;
17
16
  this.version = param.version;
18
17
  this.digest = param.digest;
@@ -27,7 +26,7 @@ export class SuiOwnedObject {
27
26
  return !!this.version && !!this.digest;
28
27
  }
29
28
 
30
- asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {
29
+ asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {
31
30
  if (!this.version || !this.digest) {
32
31
  return this.objectId;
33
32
  }
@@ -37,9 +36,9 @@ export class SuiOwnedObject {
37
36
  objectId: this.objectId,
38
37
  version: this.version,
39
38
  digest: this.digest,
40
- }
41
- }
42
- }
39
+ },
40
+ },
41
+ };
43
42
  }
44
43
 
45
44
  /**
@@ -1,19 +1,22 @@
1
1
  import { Infer } from 'superstruct';
2
- import {
3
- ObjectCallArg,
4
- ObjectId,
5
- } from '@mysten/sui.js';
2
+ import { ObjectCallArg, ObjectId } from '@mysten/sui.js';
6
3
 
7
4
  export class SuiSharedObject {
8
5
  public readonly objectId: string;
9
6
  public initialSharedVersion?: number | string;
10
7
 
11
- constructor(param: {objectId: string, initialSharedVersion?: number, mutable?: boolean}) {
8
+ constructor(param: {
9
+ objectId: string;
10
+ initialSharedVersion?: number;
11
+ mutable?: boolean;
12
+ }) {
12
13
  this.objectId = param.objectId;
13
14
  this.initialSharedVersion = param.initialSharedVersion;
14
15
  }
15
16
 
16
- asCallArg(mutable: boolean = false): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {
17
+ asCallArg(
18
+ mutable: boolean = false
19
+ ): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {
17
20
  if (!this.initialSharedVersion) {
18
21
  return this.objectId;
19
22
  }
@@ -23,8 +26,8 @@ export class SuiSharedObject {
23
26
  objectId: this.objectId,
24
27
  initialSharedVersion: this.initialSharedVersion,
25
28
  mutable,
26
- }
27
- }
28
- }
29
+ },
30
+ },
31
+ };
29
32
  }
30
33
  }
package/src/suiKit.ts CHANGED
@@ -109,7 +109,10 @@ export class SuiKit {
109
109
  tx: Uint8Array | TransactionBlock | SuiTxBlock,
110
110
  derivePathParams?: DerivePathParams
111
111
  ): Promise<SuiTransactionBlockResponse> {
112
- const { transactionBlockBytes, signature } = await this.signTxn(tx, derivePathParams);
112
+ const { transactionBlockBytes, signature } = await this.signTxn(
113
+ tx,
114
+ derivePathParams
115
+ );
113
116
  return this.suiInteractor.sendTx(transactionBlockBytes, signature);
114
117
  }
115
118
 
@@ -1,11 +1,12 @@
1
1
  import { Infer } from 'superstruct';
2
2
  import {
3
- DisplayFieldsResponse, ObjectCallArg,
3
+ DisplayFieldsResponse,
4
+ ObjectCallArg,
4
5
  ObjectContentFields,
5
6
  SharedObjectRef,
6
7
  SuiObjectRef,
7
- TransactionArgument
8
- } from "@mysten/sui.js";
8
+ TransactionArgument,
9
+ } from '@mysten/sui.js';
9
10
 
10
11
  export type AccountMangerParams = {
11
12
  mnemonics?: string;