@scallop-io/sui-kit 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,8 +53,8 @@ const suiKit = new SuiKit({
53
53
  You can use SuiKit to transfer SUI, custom coins, and any objects.
54
54
 
55
55
  ```typescript
56
- const recipient1 = '0x123'; // repace with real address
57
- const recipient2 = '0x456'; // repace with real address
56
+ const recipient1 = '0x123'; // replace with real address
57
+ const recipient2 = '0x456'; // replace with real address
58
58
 
59
59
  // transfer SUI to single recipient
60
60
  await suiKit.transferSui(recipient1, 1000);
@@ -204,7 +204,7 @@ const pkgId =
204
204
  paybackCoinB,
205
205
  loan,
206
206
  ]);
207
- // 4. Transfer profits to sender
207
+ // 5. Transfer profits to sender
208
208
  tx.transferObjects([coinB2], sender);
209
209
 
210
210
  // 5. Execute transaction
@@ -265,6 +265,10 @@ internalTransferSui(suiKit, 0, 1, 1000).then(() => {});
265
265
 
266
266
  We have a standalone npm package to help you publish and upgrade Move package based on sui-kit.
267
267
 
268
- Please refer to the repository: [sui-package-kit](https://docs.sui.io/devnet/build/install)
268
+ Please refer to the repository: [sui-package-kit](https://github.com/scallop-io/sui-package-kit)
269
+
270
+ ## Migration Guide
271
+
272
+ If you're upgrading from v1.x to v2.0.0, please refer to the [Migration Guide](./document/migration-guide-v2.md).
269
273
 
270
274
  [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/scallop-io/sui-kit)
package/dist/index.cjs CHANGED
@@ -10,10 +10,10 @@ var cryptography = require('@mysten/sui/cryptography');
10
10
  var grpc = require('@mysten/sui/grpc');
11
11
  var multisig = require('@mysten/sui/multisig');
12
12
 
13
- var Y=(r={})=>{let{accountIndex:t=0,isExternal:e=!1,addressIndex:i=0}=r;return `m/44'/784'/${t}'/${e?1:0}'/${i}'`},b=(r,t={})=>{let e=Y(t);return ed25519.Ed25519Keypair.deriveKeypair(r,e)};var X=r=>/^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(r),H=r=>/^[a-zA-Z0-9+/]+={0,2}$/g.test(r),B=r=>{if(X(r))return bcs.fromHex(r);if(H(r))return bcs.fromBase64(r);throw new Error("The string is not a valid hex or base64 string.")},O=32,L=64,w=r=>{if(r.length===L)return r.slice(0,O);if(r.length===O+1&&r[0]===0)return r.slice(1);if(r.length===O)return r;throw new Error("invalid secret key")};var I=(r=24)=>bip39.generateMnemonic(english.wordlist,r===12?128:256);var S=class{mnemonics;secretKey;currentKeyPair;currentAddress;constructor({mnemonics:t,secretKey:e}={}){this.mnemonics=t||"",this.secretKey=e||"",!this.mnemonics&&!this.secretKey&&(this.mnemonics=I(24)),this.currentKeyPair=this.secretKey?this.parseSecretKey(this.secretKey):b(this.mnemonics),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress();}parseSecretKey(t){if(t.startsWith(cryptography.SUI_PRIVATE_KEY_PREFIX)){let{secretKey:e}=cryptography.decodeSuiPrivateKey(t);return ed25519.Ed25519Keypair.fromSecretKey(w(e))}return ed25519.Ed25519Keypair.fromSecretKey(w(B(t)))}getKeyPair(t){return !t||!this.mnemonics?this.currentKeyPair:b(this.mnemonics,t)}getAddress(t){return !t||!this.mnemonics?this.currentAddress:b(this.mnemonics,t).getPublicKey().toSuiAddress()}switchAccount(t){this.mnemonics&&(this.currentKeyPair=b(this.mnemonics,t),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress());}};var ct=["u8","u16","u32","u64","u128","u256","bool","address"];function ut(r){if(!ct.includes(r))throw new Error(`Invalid SimpleBcsType: ${r}`);return {$kind:r}}var lt=r=>{if(typeof r=="string"&&utils.isValidSuiObjectId(r))return "object";if(typeof r=="number"||typeof r=="bigint")return "u64";if(typeof r=="boolean")return "bool"};function U(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="string"&&!utils.isValidSuiAddress(r)&&!isNaN(Number(r))}function ht(r){return typeof r=="object"&&"vecType"in r&&"value"in r?!0:!!Array.isArray(r)}function dt(r){return typeof r=="object"&&"digest"in r&&"version"in r&&"objectId"in r}function mt(r){return typeof r=="object"&&"objectId"in r&&"initialSharedVersion"in r&&"mutable"in r}function E(r,t,e){if(t.length===0)throw new Error("Transaction builder error: Empty array is not allowed");let i=lt(t[0]),n=/^vector<(.+)>$/,s=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;if(e=e||i,e==="object"){let o=t.map(a=>typeof a=="string"&&utils.isValidSuiObjectId(a)?r.object(utils.normalizeSuiObjectId(a)):d(r,a));return r.makeMoveVec({elements:o})}else if(typeof e=="string"&&!n.test(e)&&!s.test(e)){let o=ut(e),a=transactions.getPureBcsSchema(o);if(!a)throw new Error(`Unknown type: ${e}`);return r.pure(bcs.bcs.vector(a).serialize(t))}else {let o=t.map(a=>d(r,a));return r.makeMoveVec({elements:o,type:e})}}function y(r,t){return t.map(e=>e instanceof bcs.SerializedBcs||bcs.isSerializedBcs(e)?r.pure(e):ht(e)?"vecType"in e?E(r,e.value,e.vecType):E(r,e):U(e)?p(r,[e])[0]:d(r,e))}function g(r,t){return typeof t=="string"&&utils.isValidSuiAddress(t)?r.pure.address(utils.normalizeSuiAddress(t)):y(r,[t])[0]}function d(r,t){if(typeof t=="string")return r.object(t);if(dt(t))return r.objectRef(t);if(mt(t))return r.sharedObjectRef(t);if("Object"in t){if("ImmOrOwnedObject"in t.Object)return r.object(transactions.Inputs.ObjectRef(t.Object.ImmOrOwnedObject));if("SharedObject"in t.Object)return r.object(transactions.Inputs.SharedObjectRef(t.Object.SharedObject));throw new Error("Invalid argument type")}if(typeof t=="function"||"GasCoin"in t||"Input"in t||"Result"in t||"NestedResult"in t)return t;throw new Error("Invalid argument type")}function p(r,t){return t.map(e=>U(e)?r.pure.u64(e):y(r,[e])[0])}var V=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var u=class{txBlock;constructor(t){this.txBlock=t?transactions.Transaction.from(t):new transactions.Transaction;}get gas(){return this.txBlock.gas}getData(){return this.txBlock.getData()}address(t){return this.txBlock.pure.address(t)}get pure(){return this.txBlock.pure}object(t){return this.txBlock.object(t)}objectRef(t){return this.txBlock.objectRef(t)}sharedObjectRef(t){return this.txBlock.sharedObjectRef(t)}setSender(t){return this.txBlock.setSender(t)}setSenderIfNotSet(t){return this.txBlock.setSenderIfNotSet(t)}setExpiration(t){return this.txBlock.setExpiration(t)}setGasPrice(t){return this.txBlock.setGasPrice(t)}setGasBudget(t){return this.txBlock.setGasBudget(t)}setGasOwner(t){return this.txBlock.setGasOwner(t)}setGasPayment(t){return this.txBlock.setGasPayment(t)}serialize(){return this.txBlock.serialize()}toJSON(){return this.txBlock.toJSON()}sign(t){return this.txBlock.sign(t)}build(t={}){return this.txBlock.build(t)}getDigest(t={}){return this.txBlock.getDigest(t)}add(...t){return this.txBlock.add(...t)}publish({modules:t,dependencies:e}){return this.txBlock.publish({modules:t,dependencies:e})}upgrade(...t){return this.txBlock.upgrade(...t)}makeMoveVec(...t){return this.txBlock.makeMoveVec(...t)}transferObjects(t,e){return this.txBlock.transferObjects(t.map(i=>d(this.txBlock,i)),g(this.txBlock,e))}splitCoins(t,e){let i=this.txBlock.splitCoins(d(this.txBlock,t),p(this.txBlock,e));return e.map((n,s)=>i[s])}mergeCoins(t,e){let i=d(this.txBlock,t),n=e.map(s=>d(this.txBlock,s));return this.txBlock.mergeCoins(i,n)}moveCall(t,e=[],i=[]){let n=/(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;if(t.match(n)===null)throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");let o=y(this.txBlock,e);return this.txBlock.moveCall({target:t,arguments:o,typeArguments:i})}transferSuiToMany(t,e){if(t.length!==e.length)throw new Error("transferSuiToMany: recipients.length !== amounts.length");let i=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,e));return t.map(s=>g(this.txBlock,s)).forEach((s,o)=>{this.txBlock.transferObjects([i[o]],s);}),this}transferSui(t,e){return this.transferSuiToMany([t],[e])}takeAmountFromCoins(t,e){let{splitedCoins:i,mergedCoin:n}=this.splitMultiCoins(t,p(this.txBlock,[e]));return [i,n]}splitSUIFromGas(t){return this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,t))}splitMultiCoins(t,e){if(t.length===0)throw new Error("takeAmountFromCoins: coins array is empty");let i=V(t.slice(1),511),n=d(this.txBlock,t[0]);for(let o of i){let a=o.map(m=>d(this.txBlock,m));this.txBlock.mergeCoins(n,a);}return {splitedCoins:this.txBlock.splitCoins(n,p(this.txBlock,e)),mergedCoin:n}}transferCoinToMany(t,e,i,n){if(i.length!==n.length)throw new Error("transferCoinToMany: recipients.length !== amounts.length");let s=t.map(c=>d(this.txBlock,c)),{splitedCoins:o,mergedCoin:a}=this.splitMultiCoins(s,p(this.txBlock,n));return i.map(c=>g(this.txBlock,c)).forEach((c,h)=>{this.txBlock.transferObjects([o[h]],c);}),this.txBlock.transferObjects([a],g(this.txBlock,e)),this}transferCoin(t,e,i,n){return this.transferCoinToMany(t,e,[i],[n])}stakeSui(t,e){let[i]=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,[t]));return this.txBlock.moveCall({target:"0x3::sui_system::request_add_stake",arguments:y(this.txBlock,[this.txBlock.object(utils.SUI_SYSTEM_STATE_OBJECT_ID),i,g(this.txBlock,e)])})}};var A=class{objectId;version;digest;constructor(t){this.objectId=t.objectId,this.version=t.version,this.digest=t.digest;}isFullObject(){return !!this.version&&!!this.digest}asCallArg(){return !this.version||!this.digest?this.objectId:{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{objectId:this.objectId,version:this.version,digest:this.digest}}}}updateFromTxResponse(t){let e=t.Transaction??t.FailedTransaction;if(!e)throw new Error("Bad transaction response!");let i=e.effects;if(!i)throw new Error("Transaction response has no effects!");for(let n of i.changedObjects)if(n.objectId===this.objectId&&n.outputDigest){this.digest=n.outputDigest,this.version=n.outputVersion??void 0;return}throw new Error("Could not find object in transaction response!")}};var x=class{objectId;initialSharedVersion;constructor(t){this.objectId=t.objectId,this.initialSharedVersion=t.initialSharedVersion;}asCallArg(t=!1){return this.initialSharedVersion?{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{objectId:this.objectId,initialSharedVersion:this.initialSharedVersion,mutable:t}}}:this.objectId}};var P=r=>new Promise(t=>setTimeout(t,r)),$=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var _=50;function k(r,t){return {baseUrl:r,network:t}}function T(r){switch(r){case"mainnet":return "https://fullnode.mainnet.sui.io:443";case"testnet":return "https://fullnode.testnet.sui.io:443";case"devnet":return "https://fullnode.devnet.sui.io:443";case"localnet":return "http://127.0.0.1:9000";default:throw new Error(`Unknown network: ${r}`)}}var f=class{clients=[];currentClient;fullNodes=[];network;constructor(t){this.network="mainnet","fullnodeUrls"in t&&t.fullnodeUrls?(this.network=t.network??"mainnet",this.fullNodes=t.fullnodeUrls,this.clients=this.fullNodes.map(e=>new grpc.SuiGrpcClient(k(e,this.network)))):"suiClients"in t&&t.suiClients?this.clients=t.suiClients:(this.fullNodes=[T(this.network)],this.clients=[new grpc.SuiGrpcClient(k(this.fullNodes[0],this.network))]),this.currentClient=this.clients[0];}switchToNextClient(){let t=this.clients.indexOf(this.currentClient);this.currentClient=this.clients[(t+1)%this.clients.length];}switchFullNodes(t,e){if(t.length===0)throw new Error("fullNodes cannot be empty");this.fullNodes=t,e&&(this.network=e),this.clients=t.map(i=>new grpc.SuiGrpcClient(k(i,this.network))),this.currentClient=this.clients[0];}get currentFullNode(){if(this.fullNodes.length===0)throw new Error("No full nodes available");let t=this.clients.indexOf(this.currentClient);if(t===-1)throw new Error("Current client not found");return this.fullNodes[t]}async sendTx(t,e){let i=typeof t=="string"?Uint8Array.from(Buffer.from(t,"base64")):t,n=Array.isArray(e)?e:[e];for(let s in this.clients)try{return await this.clients[s].core.executeTransaction({transaction:i,signatures:n,include:{balanceChanges:!0,effects:!0,events:!0,objectTypes:!0}})}catch(o){console.warn(`Failed to send transaction with fullnode ${this.fullNodes[s]}: ${o}`),await P(2e3);}throw new Error("Failed to send transaction with all fullnodes")}async dryRunTx(t){for(let e in this.clients)try{return await this.clients[e].core.simulateTransaction({transaction:t,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}catch(i){console.warn(`Failed to dry run transaction with fullnode ${this.fullNodes[e]}: ${i}`),await P(2e3);}throw new Error("Failed to dry run transaction with all fullnodes")}async getObjects(t,e){let i=e?.include??{content:!0,json:!0},n=$(t,Math.max(e?.batchSize??_,_)),s=[],o=null;for(let a of n){for(let m in this.clients)try{let h=(await this.clients[m].core.getObjects({objectIds:a,include:i})).objects.map(l=>l instanceof Error?null:l).filter(l=>l!==null);s.push(...h),o=null;break}catch(c){o=c instanceof Error?c:new Error(String(c)),await P(e?.switchClientDelay??2e3),console.warn(`Failed to get objects with fullnode ${this.fullNodes[m]}: ${c}`);}if(o)throw new Error(`Failed to get objects with all fullnodes: ${o}`)}return s}async getObject(t,e){return (await this.getObjects([t],e))[0]}async updateObjects(t){let e=t.map(n=>n.objectId),i=await this.getObjects(e);for(let n of i){let s=t.find(o=>o.objectId===n?.objectId);if(s instanceof x){let o=n.owner;o&&typeof o=="object"&&"Shared"in o?s.initialSharedVersion=o.Shared.initialSharedVersion:s.initialSharedVersion=void 0;}else s instanceof A&&(s.version=n?.version,s.digest=n?.digest);}}async selectCoins(t,e,i="0x2::SUI::SUI"){let n=[],s=0,o=!0,a=null;for(;o&&s<e;){let{objects:m,hasNextPage:c,cursor:h}=await this.currentClient.core.listCoins({owner:t,coinType:i,cursor:a});m.sort((l,W)=>parseInt(W.balance)-parseInt(l.balance));for(let l of m)if(n.push({objectId:l.objectId,digest:l.digest,version:l.version,balance:l.balance}),s=s+parseInt(l.balance),s>=e)break;a=h,o=c;}if(!n.length)throw new Error("No valid coins found for the transaction.");return n}};var v=class{accountManager;suiInteractor;constructor(t){let{mnemonics:e,secretKey:i,networkType:n}=t;this.accountManager=new S({mnemonics:e,secretKey:i});let s=n??"mainnet",o;"fullnodeUrls"in t?o={fullnodeUrls:t.fullnodeUrls,network:s}:"suiClients"in t?o={suiClients:t.suiClients}:o={fullnodeUrls:[T(s)],network:s},this.suiInteractor=new f(o);}createTxBlock(){let t=new u;return t.setSender(this.accountManager.currentAddress),t}getKeypair(t){return this.accountManager.getKeyPair(t)}switchAccount(t){this.accountManager.switchAccount(t);}getAddress(t){return this.accountManager.getAddress(t)}get currentAddress(){return this.accountManager.currentAddress}async getBalance(t,e){let i=this.accountManager.getAddress(e),{balance:n}=await this.suiInteractor.currentClient.core.getBalance({owner:i,coinType:t});return n}get client(){return this.suiInteractor.currentClient}async getObjects(t,e){return this.suiInteractor.getObjects(t,e)}async updateObjects(t){return this.suiInteractor.updateObjects(t)}async signTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return await this.getKeypair(e).signTransaction(n)}async signAndSendTxn(t,e){let{bytes:i,signature:n}=await this.signTxn(t,e);return this.suiInteractor.sendTx(i,n)}async dryRunTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.dryRunTx(n)}async transferSui(t,e,i=!0,n){let s=new u;return s.transferSui(t,e),i?await this.signAndSendTxn(s,n):s}async transferSuiToMany(t,e,i=!0,n){let s=new u;return s.transferSuiToMany(t,e),i?await this.signAndSendTxn(s,n):s}async transferCoinToMany(t,e,i,n=!0,s){let o=new u,a=this.accountManager.getAddress(s),m=e.reduce((c,h)=>c+h,0);if(utils.normalizeStructTag(i)===utils.normalizeStructTag(utils.SUI_TYPE_ARG))o.transferSuiToMany(t,e);else {let c=await this.suiInteractor.selectCoins(a,m,i);o.transferCoinToMany(c.map(h=>"objectId"in h?o.objectRef(h):h),a,t,e);}return n?await this.signAndSendTxn(o,s):o}async transferCoin(t,e,i,n=!0,s){return this.transferCoinToMany([t],[e],i,n,s)}async transferObjects(t,e,i=!0,n){let s=new u;return s.transferObjects(t,e),i?await this.signAndSendTxn(s,n):s}async moveCall(t){let{target:e,arguments:i=[],typeArguments:n=[],derivePathParams:s}=t,o=new u;return o.moveCall(e,i,n),this.signAndSendTxn(o,s)}async selectCoinsWithAmount(t,e,i){return i=i||this.accountManager.currentAddress,await this.suiInteractor.selectCoins(i,t,e)}async stakeSui(t,e,i=!0,n){let s=new u;return s.stakeSui(t,e),i?await this.signAndSendTxn(s,n):s}async inspectTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.currentClient.core.simulateTransaction({transaction:n,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}};function G(r){let t=bcs.fromBase64(r);if(t.length!==32&&t.length!==33)throw "invalid pubkey length";return t=t.length===33?t.slice(1):t,new ed25519.Ed25519PublicKey(t)}var j=class r{pksWeightPairs;threshold;multiSigPublicKey;constructor(t,e){this.pksWeightPairs=t,this.threshold=e,this.multiSigPublicKey=multisig.MultiSigPublicKey.fromPublicKeys({threshold:this.threshold,publicKeys:this.pksWeightPairs});}static fromRawEd25519PublicKeys(t,e,i){let n=t.map((s,o)=>({publicKey:G(s),weight:e[o]}));return new r(n,i)}multiSigAddress(){return this.multiSigPublicKey.toSuiAddress()}combinePartialSigs(t){return this.multiSigPublicKey.combinePartialSignatures(t)}};
13
+ var Y=(r={})=>{let{accountIndex:t=0,isExternal:e=!1,addressIndex:i=0}=r;return `m/44'/784'/${t}'/${e?1:0}'/${i}'`},S=(r,t={})=>{let e=Y(t);return ed25519.Ed25519Keypair.deriveKeypair(r,e)};var X=r=>/^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(r),H=r=>/^[a-zA-Z0-9+/]+={0,2}$/g.test(r),B=r=>{if(X(r))return bcs.fromHex(r);if(H(r))return bcs.fromBase64(r);throw new Error("The string is not a valid hex or base64 string.")},O=32,L=64,w=r=>{if(r.length===L)return r.slice(0,O);if(r.length===O+1&&r[0]===0)return r.slice(1);if(r.length===O)return r;throw new Error("invalid secret key")};var I=(r=24)=>bip39.generateMnemonic(english.wordlist,r===12?128:256);var b=class{mnemonics;secretKey;currentKeyPair;currentAddress;constructor({mnemonics:t,secretKey:e}={}){this.mnemonics=t||"",this.secretKey=e||"",!this.mnemonics&&!this.secretKey&&(this.mnemonics=I(24)),this.currentKeyPair=this.secretKey?this.parseSecretKey(this.secretKey):S(this.mnemonics),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress();}parseSecretKey(t){if(t.startsWith(cryptography.SUI_PRIVATE_KEY_PREFIX)){let{secretKey:e}=cryptography.decodeSuiPrivateKey(t);return ed25519.Ed25519Keypair.fromSecretKey(w(e))}return ed25519.Ed25519Keypair.fromSecretKey(w(B(t)))}getKeyPair(t){return !t||!this.mnemonics?this.currentKeyPair:S(this.mnemonics,t)}getAddress(t){return !t||!this.mnemonics?this.currentAddress:S(this.mnemonics,t).getPublicKey().toSuiAddress()}switchAccount(t){this.mnemonics&&(this.currentKeyPair=S(this.mnemonics,t),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress());}};var ct=["u8","u16","u32","u64","u128","u256","bool","address"];function ut(r){if(!ct.includes(r))throw new Error(`Invalid SimpleBcsType: ${r}`);return {$kind:r}}var lt=r=>{if(typeof r=="string"&&utils.isValidSuiObjectId(r))return "object";if(typeof r=="number"||typeof r=="bigint")return "u64";if(typeof r=="boolean")return "bool"};function U(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="string"&&!utils.isValidSuiAddress(r)&&!isNaN(Number(r))}function ht(r){return r!==null&&typeof r=="object"&&"vecType"in r&&"value"in r?!0:!!Array.isArray(r)}function dt(r){return typeof r=="object"&&"digest"in r&&"version"in r&&"objectId"in r}function mt(r){return typeof r=="object"&&"objectId"in r&&"initialSharedVersion"in r&&"mutable"in r}function E(r,t,e){if(t.length===0)throw new Error("Transaction builder error: Empty array is not allowed");let i=lt(t[0]),n=/^vector<(.+)>$/,s=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;if(e=e||i,e==="object"){let o=t.map(a=>typeof a=="string"&&utils.isValidSuiObjectId(a)?r.object(utils.normalizeSuiObjectId(a)):d(r,a));return r.makeMoveVec({elements:o})}else if(typeof e=="string"&&!n.test(e)&&!s.test(e)){let o=ut(e),a=transactions.getPureBcsSchema(o);if(!a)throw new Error(`Unknown type: ${e}`);return r.pure(bcs.bcs.vector(a).serialize(t))}else {let o=t.map(a=>d(r,a));return r.makeMoveVec({elements:o,type:e})}}function y(r,t){return t.map(e=>e instanceof bcs.SerializedBcs||bcs.isSerializedBcs(e)?r.pure(e):ht(e)?"vecType"in e?E(r,e.value,e.vecType):E(r,e):U(e)?p(r,[e])[0]:d(r,e))}function g(r,t){return typeof t=="string"&&utils.isValidSuiAddress(t)?r.pure.address(utils.normalizeSuiAddress(t)):y(r,[t])[0]}function d(r,t){if(typeof t=="string")return r.object(t);if(dt(t))return r.objectRef(t);if(mt(t))return r.sharedObjectRef(t);if("Object"in t){if("ImmOrOwnedObject"in t.Object)return r.object(transactions.Inputs.ObjectRef(t.Object.ImmOrOwnedObject));if("SharedObject"in t.Object)return r.object(transactions.Inputs.SharedObjectRef(t.Object.SharedObject));throw new Error("Invalid argument type")}if(typeof t=="function"||"GasCoin"in t||"Input"in t||"Result"in t||"NestedResult"in t)return t;throw new Error("Invalid argument type")}function p(r,t){return t.map(e=>U(e)?r.pure.u64(e):y(r,[e])[0])}var V=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var u=class{txBlock;constructor(t){this.txBlock=t?transactions.Transaction.from(t):new transactions.Transaction;}get gas(){return this.txBlock.gas}getData(){return this.txBlock.getData()}address(t){return this.txBlock.pure.address(t)}get pure(){return this.txBlock.pure}object(t){return this.txBlock.object(t)}objectRef(t){return this.txBlock.objectRef(t)}sharedObjectRef(t){return this.txBlock.sharedObjectRef(t)}setSender(t){return this.txBlock.setSender(t)}setSenderIfNotSet(t){return this.txBlock.setSenderIfNotSet(t)}setExpiration(t){return this.txBlock.setExpiration(t)}setGasPrice(t){return this.txBlock.setGasPrice(t)}setGasBudget(t){return this.txBlock.setGasBudget(t)}setGasOwner(t){return this.txBlock.setGasOwner(t)}setGasPayment(t){return this.txBlock.setGasPayment(t)}serialize(){return this.txBlock.serialize()}toJSON(){return this.txBlock.toJSON()}sign(t){return this.txBlock.sign(t)}build(t={}){return this.txBlock.build(t)}getDigest(t={}){return this.txBlock.getDigest(t)}add(...t){return this.txBlock.add(...t)}publish({modules:t,dependencies:e}){return this.txBlock.publish({modules:t,dependencies:e})}upgrade(...t){return this.txBlock.upgrade(...t)}makeMoveVec(...t){return this.txBlock.makeMoveVec(...t)}transferObjects(t,e){return this.txBlock.transferObjects(t.map(i=>d(this.txBlock,i)),g(this.txBlock,e))}splitCoins(t,e){let i=this.txBlock.splitCoins(d(this.txBlock,t),p(this.txBlock,e));return e.map((n,s)=>i[s])}mergeCoins(t,e){let i=d(this.txBlock,t),n=e.map(s=>d(this.txBlock,s));return this.txBlock.mergeCoins(i,n)}moveCall(t,e=[],i=[]){let n=/(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;if(t.match(n)===null)throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");let o=y(this.txBlock,e);return this.txBlock.moveCall({target:t,arguments:o,typeArguments:i})}transferSuiToMany(t,e){if(t.length!==e.length)throw new Error("transferSuiToMany: recipients.length !== amounts.length");let i=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,e));return t.map(s=>g(this.txBlock,s)).forEach((s,o)=>{this.txBlock.transferObjects([i[o]],s);}),this}transferSui(t,e){return this.transferSuiToMany([t],[e])}takeAmountFromCoins(t,e){let{splitedCoins:i,mergedCoin:n}=this.splitMultiCoins(t,p(this.txBlock,[e]));return [i,n]}splitSUIFromGas(t){return this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,t))}splitMultiCoins(t,e){if(t.length===0)throw new Error("takeAmountFromCoins: coins array is empty");let i=V(t.slice(1),511),n=d(this.txBlock,t[0]);for(let o of i){let a=o.map(m=>d(this.txBlock,m));this.txBlock.mergeCoins(n,a);}return {splitedCoins:this.txBlock.splitCoins(n,p(this.txBlock,e)),mergedCoin:n}}transferCoinToMany(t,e,i,n){if(i.length!==n.length)throw new Error("transferCoinToMany: recipients.length !== amounts.length");let s=t.map(c=>d(this.txBlock,c)),{splitedCoins:o,mergedCoin:a}=this.splitMultiCoins(s,p(this.txBlock,n));return i.map(c=>g(this.txBlock,c)).forEach((c,h)=>{this.txBlock.transferObjects([o[h]],c);}),this.txBlock.transferObjects([a],g(this.txBlock,e)),this}transferCoin(t,e,i,n){return this.transferCoinToMany(t,e,[i],[n])}stakeSui(t,e){let[i]=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,[t]));return this.txBlock.moveCall({target:"0x3::sui_system::request_add_stake",arguments:y(this.txBlock,[this.txBlock.object(utils.SUI_SYSTEM_STATE_OBJECT_ID),i,g(this.txBlock,e)])})}};var A=class{objectId;version;digest;constructor(t){this.objectId=t.objectId,this.version=t.version,this.digest=t.digest;}isFullObject(){return !!this.version&&!!this.digest}asCallArg(){return !this.version||!this.digest?this.objectId:{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{objectId:this.objectId,version:this.version,digest:this.digest}}}}updateFromTxResponse(t){let e=t.Transaction??t.FailedTransaction;if(!e)throw new Error("Bad transaction response!");let i=e.effects;if(!i)throw new Error("Transaction response has no effects!");for(let n of i.changedObjects)if(n.objectId===this.objectId&&n.outputDigest){this.digest=n.outputDigest,this.version=n.outputVersion??void 0;return}throw new Error("Could not find object in transaction response!")}};var x=class{objectId;initialSharedVersion;constructor(t){this.objectId=t.objectId,this.initialSharedVersion=t.initialSharedVersion;}asCallArg(t=!1){return this.initialSharedVersion?{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{objectId:this.objectId,initialSharedVersion:this.initialSharedVersion,mutable:t}}}:this.objectId}};var P=r=>new Promise(t=>setTimeout(t,r)),$=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var _=50;function k(r,t){return {baseUrl:r,network:t}}function T(r){switch(r){case"mainnet":return "https://fullnode.mainnet.sui.io:443";case"testnet":return "https://fullnode.testnet.sui.io:443";case"devnet":return "https://fullnode.devnet.sui.io:443";case"localnet":return "http://127.0.0.1:9000";default:throw new Error(`Unknown network: ${r}`)}}var f=class{clients=[];currentClient;fullNodes=[];network;constructor(t){this.network="mainnet","fullnodeUrls"in t&&t.fullnodeUrls?(this.network=t.network??"mainnet",this.fullNodes=t.fullnodeUrls,this.clients=this.fullNodes.map(e=>new grpc.SuiGrpcClient(k(e,this.network)))):"suiClients"in t&&t.suiClients?this.clients=t.suiClients:(this.fullNodes=[T(this.network)],this.clients=[new grpc.SuiGrpcClient(k(this.fullNodes[0],this.network))]),this.currentClient=this.clients[0];}switchToNextClient(){let t=this.clients.indexOf(this.currentClient);this.currentClient=this.clients[(t+1)%this.clients.length];}switchFullNodes(t,e){if(t.length===0)throw new Error("fullNodes cannot be empty");this.fullNodes=t,e&&(this.network=e),this.clients=t.map(i=>new grpc.SuiGrpcClient(k(i,this.network))),this.currentClient=this.clients[0];}get currentFullNode(){if(this.fullNodes.length===0)throw new Error("No full nodes available");let t=this.clients.indexOf(this.currentClient);if(t===-1)throw new Error("Current client not found");return this.fullNodes[t]}async sendTx(t,e){let i=typeof t=="string"?Uint8Array.from(Buffer.from(t,"base64")):t,n=Array.isArray(e)?e:[e];for(let s in this.clients)try{return await this.clients[s].core.executeTransaction({transaction:i,signatures:n,include:{balanceChanges:!0,effects:!0,events:!0,objectTypes:!0}})}catch(o){console.warn(`Failed to send transaction with fullnode ${this.fullNodes[s]}: ${o}`),await P(2e3);}throw new Error("Failed to send transaction with all fullnodes")}async dryRunTx(t){for(let e in this.clients)try{return await this.clients[e].core.simulateTransaction({transaction:t,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}catch(i){console.warn(`Failed to dry run transaction with fullnode ${this.fullNodes[e]}: ${i}`),await P(2e3);}throw new Error("Failed to dry run transaction with all fullnodes")}async getObjects(t,e){let i=e?.include??{content:!0,json:!0},n=$(t,Math.max(e?.batchSize??_,_)),s=[],o=null;for(let a of n){for(let m in this.clients)try{let h=(await this.clients[m].core.getObjects({objectIds:a,include:i})).objects.map(l=>l instanceof Error?null:l).filter(l=>l!==null);s.push(...h),o=null;break}catch(c){o=c instanceof Error?c:new Error(String(c)),await P(e?.switchClientDelay??2e3),console.warn(`Failed to get objects with fullnode ${this.fullNodes[m]}: ${c}`);}if(o)throw new Error(`Failed to get objects with all fullnodes: ${o}`)}return s}async getObject(t,e){return (await this.getObjects([t],e))[0]}async updateObjects(t){let e=t.map(n=>n.objectId),i=await this.getObjects(e);for(let n of i){let s=t.find(o=>o.objectId===n?.objectId);if(s instanceof x){let o=n.owner;o&&typeof o=="object"&&"Shared"in o?s.initialSharedVersion=o.Shared.initialSharedVersion:s.initialSharedVersion=void 0;}else s instanceof A&&(s.version=n?.version,s.digest=n?.digest);}}async selectCoins(t,e,i="0x2::SUI::SUI"){let n=[],s=0,o=!0,a=null;for(;o&&s<e;){let{objects:m,hasNextPage:c,cursor:h}=await this.currentClient.core.listCoins({owner:t,coinType:i,cursor:a});m.sort((l,W)=>parseInt(W.balance)-parseInt(l.balance));for(let l of m)if(n.push({objectId:l.objectId,digest:l.digest,version:l.version,balance:l.balance}),s=s+parseInt(l.balance),s>=e)break;a=h,o=c;}if(!n.length)throw new Error("No valid coins found for the transaction.");return n}};var v=class{accountManager;suiInteractor;constructor(t){let{mnemonics:e,secretKey:i,networkType:n}=t;this.accountManager=new b({mnemonics:e,secretKey:i});let s=n??"mainnet",o;"fullnodeUrls"in t?o={fullnodeUrls:t.fullnodeUrls,network:s}:"suiClients"in t?o={suiClients:t.suiClients}:o={fullnodeUrls:[T(s)],network:s},this.suiInteractor=new f(o);}createTxBlock(){let t=new u;return t.setSender(this.accountManager.currentAddress),t}getKeypair(t){return this.accountManager.getKeyPair(t)}switchAccount(t){this.accountManager.switchAccount(t);}getAddress(t){return this.accountManager.getAddress(t)}get currentAddress(){return this.accountManager.currentAddress}async getBalance(t,e){let i=this.accountManager.getAddress(e),{balance:n}=await this.suiInteractor.currentClient.core.getBalance({owner:i,coinType:t});return n}get client(){return this.suiInteractor.currentClient}async getObjects(t,e){return this.suiInteractor.getObjects(t,e)}async updateObjects(t){return this.suiInteractor.updateObjects(t)}async signTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return await this.getKeypair(e).signTransaction(n)}async signAndSendTxn(t,e){let{bytes:i,signature:n}=await this.signTxn(t,e);return this.suiInteractor.sendTx(i,n)}async dryRunTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.dryRunTx(n)}async transferSui(t,e,i=!0,n){let s=new u;return s.transferSui(t,e),i?await this.signAndSendTxn(s,n):s}async transferSuiToMany(t,e,i=!0,n){let s=new u;return s.transferSuiToMany(t,e),i?await this.signAndSendTxn(s,n):s}async transferCoinToMany(t,e,i,n=!0,s){let o=new u,a=this.accountManager.getAddress(s),m=e.reduce((c,h)=>c+h,0);if(utils.normalizeStructTag(i)===utils.normalizeStructTag(utils.SUI_TYPE_ARG))o.transferSuiToMany(t,e);else {let c=await this.suiInteractor.selectCoins(a,m,i);o.transferCoinToMany(c.map(h=>"objectId"in h?o.objectRef(h):h),a,t,e);}return n?await this.signAndSendTxn(o,s):o}async transferCoin(t,e,i,n=!0,s){return this.transferCoinToMany([t],[e],i,n,s)}async transferObjects(t,e,i=!0,n){let s=new u;return s.transferObjects(t,e),i?await this.signAndSendTxn(s,n):s}async moveCall(t){let{target:e,arguments:i=[],typeArguments:n=[],derivePathParams:s}=t,o=new u;return o.moveCall(e,i,n),this.signAndSendTxn(o,s)}async selectCoinsWithAmount(t,e,i){return i=i||this.accountManager.currentAddress,await this.suiInteractor.selectCoins(i,t,e)}async stakeSui(t,e,i=!0,n){let s=new u;return s.stakeSui(t,e),i?await this.signAndSendTxn(s,n):s}async inspectTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.currentClient.core.simulateTransaction({transaction:n,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}};function G(r){let t=bcs.fromBase64(r);if(t.length!==32&&t.length!==33)throw "invalid pubkey length";return t=t.length===33?t.slice(1):t,new ed25519.Ed25519PublicKey(t)}var j=class r{pksWeightPairs;threshold;multiSigPublicKey;constructor(t,e){this.pksWeightPairs=t,this.threshold=e,this.multiSigPublicKey=multisig.MultiSigPublicKey.fromPublicKeys({threshold:this.threshold,publicKeys:this.pksWeightPairs});}static fromRawEd25519PublicKeys(t,e,i){let n=t.map((s,o)=>({publicKey:G(s),weight:e[o]}));return new r(n,i)}multiSigAddress(){return this.multiSigPublicKey.toSuiAddress()}combinePartialSigs(t){return this.multiSigPublicKey.combinePartialSignatures(t)}};
14
14
 
15
15
  exports.MultiSigClient = j;
16
- exports.SuiAccountManager = S;
16
+ exports.SuiAccountManager = b;
17
17
  exports.SuiInteractor = f;
18
18
  exports.SuiKit = v;
19
19
  exports.SuiTxBlock = u;
package/dist/index.d.cts CHANGED
@@ -368,7 +368,7 @@ declare class SuiTxBlock {
368
368
  * @param args the arguments of the move call, such as `['0x1', '0x2']`
369
369
  * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`
370
370
  */
371
- moveCall(target: string, args?: (SuiTxArg | SuiVecTxArg)[], typeArgs?: string[]): _mysten_sui_transactions.TransactionResult;
371
+ moveCall(target: string, args?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[], typeArgs?: string[]): _mysten_sui_transactions.TransactionResult;
372
372
  transferSuiToMany(recipients: SuiAddressArg[], amounts: SuiAmountsArg[]): this;
373
373
  transferSui(address: SuiAddressArg, amount: SuiAmountsArg): this;
374
374
  takeAmountFromCoins(coins: SuiObjectArg[], amount: SuiAmountsArg): _mysten_sui_transactions.TransactionObjectArgument[];
@@ -695,7 +695,7 @@ declare class SuiKit {
695
695
  transferObjects<S extends boolean>(objects: SuiObjectArg[], recipient: string, sign?: S, derivePathParams?: DerivePathParams): Promise<SuiKitReturnType<S>>;
696
696
  moveCall(callParams: {
697
697
  target: string;
698
- arguments?: (SuiTxArg | SuiVecTxArg)[];
698
+ arguments?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[];
699
699
  typeArguments?: string[];
700
700
  derivePathParams?: DerivePathParams;
701
701
  }): Promise<SuiTransactionBlockResponse>;
package/dist/index.d.ts CHANGED
@@ -368,7 +368,7 @@ declare class SuiTxBlock {
368
368
  * @param args the arguments of the move call, such as `['0x1', '0x2']`
369
369
  * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`
370
370
  */
371
- moveCall(target: string, args?: (SuiTxArg | SuiVecTxArg)[], typeArgs?: string[]): _mysten_sui_transactions.TransactionResult;
371
+ moveCall(target: string, args?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[], typeArgs?: string[]): _mysten_sui_transactions.TransactionResult;
372
372
  transferSuiToMany(recipients: SuiAddressArg[], amounts: SuiAmountsArg[]): this;
373
373
  transferSui(address: SuiAddressArg, amount: SuiAmountsArg): this;
374
374
  takeAmountFromCoins(coins: SuiObjectArg[], amount: SuiAmountsArg): _mysten_sui_transactions.TransactionObjectArgument[];
@@ -695,7 +695,7 @@ declare class SuiKit {
695
695
  transferObjects<S extends boolean>(objects: SuiObjectArg[], recipient: string, sign?: S, derivePathParams?: DerivePathParams): Promise<SuiKitReturnType<S>>;
696
696
  moveCall(callParams: {
697
697
  target: string;
698
- arguments?: (SuiTxArg | SuiVecTxArg)[];
698
+ arguments?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[];
699
699
  typeArguments?: string[];
700
700
  derivePathParams?: DerivePathParams;
701
701
  }): Promise<SuiTransactionBlockResponse>;
package/dist/index.js CHANGED
@@ -10,6 +10,6 @@ import { SUI_PRIVATE_KEY_PREFIX, decodeSuiPrivateKey } from '@mysten/sui/cryptog
10
10
  import { SuiGrpcClient } from '@mysten/sui/grpc';
11
11
  import { MultiSigPublicKey } from '@mysten/sui/multisig';
12
12
 
13
- var Y=(r={})=>{let{accountIndex:t=0,isExternal:e=!1,addressIndex:i=0}=r;return `m/44'/784'/${t}'/${e?1:0}'/${i}'`},b=(r,t={})=>{let e=Y(t);return Ed25519Keypair.deriveKeypair(r,e)};var X=r=>/^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(r),H=r=>/^[a-zA-Z0-9+/]+={0,2}$/g.test(r),B=r=>{if(X(r))return fromHex(r);if(H(r))return fromBase64(r);throw new Error("The string is not a valid hex or base64 string.")},O=32,L=64,w=r=>{if(r.length===L)return r.slice(0,O);if(r.length===O+1&&r[0]===0)return r.slice(1);if(r.length===O)return r;throw new Error("invalid secret key")};var I=(r=24)=>generateMnemonic(wordlist,r===12?128:256);var S=class{mnemonics;secretKey;currentKeyPair;currentAddress;constructor({mnemonics:t,secretKey:e}={}){this.mnemonics=t||"",this.secretKey=e||"",!this.mnemonics&&!this.secretKey&&(this.mnemonics=I(24)),this.currentKeyPair=this.secretKey?this.parseSecretKey(this.secretKey):b(this.mnemonics),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress();}parseSecretKey(t){if(t.startsWith(SUI_PRIVATE_KEY_PREFIX)){let{secretKey:e}=decodeSuiPrivateKey(t);return Ed25519Keypair.fromSecretKey(w(e))}return Ed25519Keypair.fromSecretKey(w(B(t)))}getKeyPair(t){return !t||!this.mnemonics?this.currentKeyPair:b(this.mnemonics,t)}getAddress(t){return !t||!this.mnemonics?this.currentAddress:b(this.mnemonics,t).getPublicKey().toSuiAddress()}switchAccount(t){this.mnemonics&&(this.currentKeyPair=b(this.mnemonics,t),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress());}};var ct=["u8","u16","u32","u64","u128","u256","bool","address"];function ut(r){if(!ct.includes(r))throw new Error(`Invalid SimpleBcsType: ${r}`);return {$kind:r}}var lt=r=>{if(typeof r=="string"&&isValidSuiObjectId(r))return "object";if(typeof r=="number"||typeof r=="bigint")return "u64";if(typeof r=="boolean")return "bool"};function U(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="string"&&!isValidSuiAddress(r)&&!isNaN(Number(r))}function ht(r){return typeof r=="object"&&"vecType"in r&&"value"in r?!0:!!Array.isArray(r)}function dt(r){return typeof r=="object"&&"digest"in r&&"version"in r&&"objectId"in r}function mt(r){return typeof r=="object"&&"objectId"in r&&"initialSharedVersion"in r&&"mutable"in r}function E(r,t,e){if(t.length===0)throw new Error("Transaction builder error: Empty array is not allowed");let i=lt(t[0]),n=/^vector<(.+)>$/,s=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;if(e=e||i,e==="object"){let o=t.map(a=>typeof a=="string"&&isValidSuiObjectId(a)?r.object(normalizeSuiObjectId(a)):d(r,a));return r.makeMoveVec({elements:o})}else if(typeof e=="string"&&!n.test(e)&&!s.test(e)){let o=ut(e),a=getPureBcsSchema(o);if(!a)throw new Error(`Unknown type: ${e}`);return r.pure(bcs.vector(a).serialize(t))}else {let o=t.map(a=>d(r,a));return r.makeMoveVec({elements:o,type:e})}}function y(r,t){return t.map(e=>e instanceof SerializedBcs||isSerializedBcs(e)?r.pure(e):ht(e)?"vecType"in e?E(r,e.value,e.vecType):E(r,e):U(e)?p(r,[e])[0]:d(r,e))}function g(r,t){return typeof t=="string"&&isValidSuiAddress(t)?r.pure.address(normalizeSuiAddress(t)):y(r,[t])[0]}function d(r,t){if(typeof t=="string")return r.object(t);if(dt(t))return r.objectRef(t);if(mt(t))return r.sharedObjectRef(t);if("Object"in t){if("ImmOrOwnedObject"in t.Object)return r.object(Inputs.ObjectRef(t.Object.ImmOrOwnedObject));if("SharedObject"in t.Object)return r.object(Inputs.SharedObjectRef(t.Object.SharedObject));throw new Error("Invalid argument type")}if(typeof t=="function"||"GasCoin"in t||"Input"in t||"Result"in t||"NestedResult"in t)return t;throw new Error("Invalid argument type")}function p(r,t){return t.map(e=>U(e)?r.pure.u64(e):y(r,[e])[0])}var V=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var u=class{txBlock;constructor(t){this.txBlock=t?Transaction.from(t):new Transaction;}get gas(){return this.txBlock.gas}getData(){return this.txBlock.getData()}address(t){return this.txBlock.pure.address(t)}get pure(){return this.txBlock.pure}object(t){return this.txBlock.object(t)}objectRef(t){return this.txBlock.objectRef(t)}sharedObjectRef(t){return this.txBlock.sharedObjectRef(t)}setSender(t){return this.txBlock.setSender(t)}setSenderIfNotSet(t){return this.txBlock.setSenderIfNotSet(t)}setExpiration(t){return this.txBlock.setExpiration(t)}setGasPrice(t){return this.txBlock.setGasPrice(t)}setGasBudget(t){return this.txBlock.setGasBudget(t)}setGasOwner(t){return this.txBlock.setGasOwner(t)}setGasPayment(t){return this.txBlock.setGasPayment(t)}serialize(){return this.txBlock.serialize()}toJSON(){return this.txBlock.toJSON()}sign(t){return this.txBlock.sign(t)}build(t={}){return this.txBlock.build(t)}getDigest(t={}){return this.txBlock.getDigest(t)}add(...t){return this.txBlock.add(...t)}publish({modules:t,dependencies:e}){return this.txBlock.publish({modules:t,dependencies:e})}upgrade(...t){return this.txBlock.upgrade(...t)}makeMoveVec(...t){return this.txBlock.makeMoveVec(...t)}transferObjects(t,e){return this.txBlock.transferObjects(t.map(i=>d(this.txBlock,i)),g(this.txBlock,e))}splitCoins(t,e){let i=this.txBlock.splitCoins(d(this.txBlock,t),p(this.txBlock,e));return e.map((n,s)=>i[s])}mergeCoins(t,e){let i=d(this.txBlock,t),n=e.map(s=>d(this.txBlock,s));return this.txBlock.mergeCoins(i,n)}moveCall(t,e=[],i=[]){let n=/(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;if(t.match(n)===null)throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");let o=y(this.txBlock,e);return this.txBlock.moveCall({target:t,arguments:o,typeArguments:i})}transferSuiToMany(t,e){if(t.length!==e.length)throw new Error("transferSuiToMany: recipients.length !== amounts.length");let i=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,e));return t.map(s=>g(this.txBlock,s)).forEach((s,o)=>{this.txBlock.transferObjects([i[o]],s);}),this}transferSui(t,e){return this.transferSuiToMany([t],[e])}takeAmountFromCoins(t,e){let{splitedCoins:i,mergedCoin:n}=this.splitMultiCoins(t,p(this.txBlock,[e]));return [i,n]}splitSUIFromGas(t){return this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,t))}splitMultiCoins(t,e){if(t.length===0)throw new Error("takeAmountFromCoins: coins array is empty");let i=V(t.slice(1),511),n=d(this.txBlock,t[0]);for(let o of i){let a=o.map(m=>d(this.txBlock,m));this.txBlock.mergeCoins(n,a);}return {splitedCoins:this.txBlock.splitCoins(n,p(this.txBlock,e)),mergedCoin:n}}transferCoinToMany(t,e,i,n){if(i.length!==n.length)throw new Error("transferCoinToMany: recipients.length !== amounts.length");let s=t.map(c=>d(this.txBlock,c)),{splitedCoins:o,mergedCoin:a}=this.splitMultiCoins(s,p(this.txBlock,n));return i.map(c=>g(this.txBlock,c)).forEach((c,h)=>{this.txBlock.transferObjects([o[h]],c);}),this.txBlock.transferObjects([a],g(this.txBlock,e)),this}transferCoin(t,e,i,n){return this.transferCoinToMany(t,e,[i],[n])}stakeSui(t,e){let[i]=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,[t]));return this.txBlock.moveCall({target:"0x3::sui_system::request_add_stake",arguments:y(this.txBlock,[this.txBlock.object(SUI_SYSTEM_STATE_OBJECT_ID),i,g(this.txBlock,e)])})}};var A=class{objectId;version;digest;constructor(t){this.objectId=t.objectId,this.version=t.version,this.digest=t.digest;}isFullObject(){return !!this.version&&!!this.digest}asCallArg(){return !this.version||!this.digest?this.objectId:{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{objectId:this.objectId,version:this.version,digest:this.digest}}}}updateFromTxResponse(t){let e=t.Transaction??t.FailedTransaction;if(!e)throw new Error("Bad transaction response!");let i=e.effects;if(!i)throw new Error("Transaction response has no effects!");for(let n of i.changedObjects)if(n.objectId===this.objectId&&n.outputDigest){this.digest=n.outputDigest,this.version=n.outputVersion??void 0;return}throw new Error("Could not find object in transaction response!")}};var x=class{objectId;initialSharedVersion;constructor(t){this.objectId=t.objectId,this.initialSharedVersion=t.initialSharedVersion;}asCallArg(t=!1){return this.initialSharedVersion?{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{objectId:this.objectId,initialSharedVersion:this.initialSharedVersion,mutable:t}}}:this.objectId}};var P=r=>new Promise(t=>setTimeout(t,r)),$=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var _=50;function k(r,t){return {baseUrl:r,network:t}}function T(r){switch(r){case"mainnet":return "https://fullnode.mainnet.sui.io:443";case"testnet":return "https://fullnode.testnet.sui.io:443";case"devnet":return "https://fullnode.devnet.sui.io:443";case"localnet":return "http://127.0.0.1:9000";default:throw new Error(`Unknown network: ${r}`)}}var f=class{clients=[];currentClient;fullNodes=[];network;constructor(t){this.network="mainnet","fullnodeUrls"in t&&t.fullnodeUrls?(this.network=t.network??"mainnet",this.fullNodes=t.fullnodeUrls,this.clients=this.fullNodes.map(e=>new SuiGrpcClient(k(e,this.network)))):"suiClients"in t&&t.suiClients?this.clients=t.suiClients:(this.fullNodes=[T(this.network)],this.clients=[new SuiGrpcClient(k(this.fullNodes[0],this.network))]),this.currentClient=this.clients[0];}switchToNextClient(){let t=this.clients.indexOf(this.currentClient);this.currentClient=this.clients[(t+1)%this.clients.length];}switchFullNodes(t,e){if(t.length===0)throw new Error("fullNodes cannot be empty");this.fullNodes=t,e&&(this.network=e),this.clients=t.map(i=>new SuiGrpcClient(k(i,this.network))),this.currentClient=this.clients[0];}get currentFullNode(){if(this.fullNodes.length===0)throw new Error("No full nodes available");let t=this.clients.indexOf(this.currentClient);if(t===-1)throw new Error("Current client not found");return this.fullNodes[t]}async sendTx(t,e){let i=typeof t=="string"?Uint8Array.from(Buffer.from(t,"base64")):t,n=Array.isArray(e)?e:[e];for(let s in this.clients)try{return await this.clients[s].core.executeTransaction({transaction:i,signatures:n,include:{balanceChanges:!0,effects:!0,events:!0,objectTypes:!0}})}catch(o){console.warn(`Failed to send transaction with fullnode ${this.fullNodes[s]}: ${o}`),await P(2e3);}throw new Error("Failed to send transaction with all fullnodes")}async dryRunTx(t){for(let e in this.clients)try{return await this.clients[e].core.simulateTransaction({transaction:t,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}catch(i){console.warn(`Failed to dry run transaction with fullnode ${this.fullNodes[e]}: ${i}`),await P(2e3);}throw new Error("Failed to dry run transaction with all fullnodes")}async getObjects(t,e){let i=e?.include??{content:!0,json:!0},n=$(t,Math.max(e?.batchSize??_,_)),s=[],o=null;for(let a of n){for(let m in this.clients)try{let h=(await this.clients[m].core.getObjects({objectIds:a,include:i})).objects.map(l=>l instanceof Error?null:l).filter(l=>l!==null);s.push(...h),o=null;break}catch(c){o=c instanceof Error?c:new Error(String(c)),await P(e?.switchClientDelay??2e3),console.warn(`Failed to get objects with fullnode ${this.fullNodes[m]}: ${c}`);}if(o)throw new Error(`Failed to get objects with all fullnodes: ${o}`)}return s}async getObject(t,e){return (await this.getObjects([t],e))[0]}async updateObjects(t){let e=t.map(n=>n.objectId),i=await this.getObjects(e);for(let n of i){let s=t.find(o=>o.objectId===n?.objectId);if(s instanceof x){let o=n.owner;o&&typeof o=="object"&&"Shared"in o?s.initialSharedVersion=o.Shared.initialSharedVersion:s.initialSharedVersion=void 0;}else s instanceof A&&(s.version=n?.version,s.digest=n?.digest);}}async selectCoins(t,e,i="0x2::SUI::SUI"){let n=[],s=0,o=!0,a=null;for(;o&&s<e;){let{objects:m,hasNextPage:c,cursor:h}=await this.currentClient.core.listCoins({owner:t,coinType:i,cursor:a});m.sort((l,W)=>parseInt(W.balance)-parseInt(l.balance));for(let l of m)if(n.push({objectId:l.objectId,digest:l.digest,version:l.version,balance:l.balance}),s=s+parseInt(l.balance),s>=e)break;a=h,o=c;}if(!n.length)throw new Error("No valid coins found for the transaction.");return n}};var v=class{accountManager;suiInteractor;constructor(t){let{mnemonics:e,secretKey:i,networkType:n}=t;this.accountManager=new S({mnemonics:e,secretKey:i});let s=n??"mainnet",o;"fullnodeUrls"in t?o={fullnodeUrls:t.fullnodeUrls,network:s}:"suiClients"in t?o={suiClients:t.suiClients}:o={fullnodeUrls:[T(s)],network:s},this.suiInteractor=new f(o);}createTxBlock(){let t=new u;return t.setSender(this.accountManager.currentAddress),t}getKeypair(t){return this.accountManager.getKeyPair(t)}switchAccount(t){this.accountManager.switchAccount(t);}getAddress(t){return this.accountManager.getAddress(t)}get currentAddress(){return this.accountManager.currentAddress}async getBalance(t,e){let i=this.accountManager.getAddress(e),{balance:n}=await this.suiInteractor.currentClient.core.getBalance({owner:i,coinType:t});return n}get client(){return this.suiInteractor.currentClient}async getObjects(t,e){return this.suiInteractor.getObjects(t,e)}async updateObjects(t){return this.suiInteractor.updateObjects(t)}async signTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return await this.getKeypair(e).signTransaction(n)}async signAndSendTxn(t,e){let{bytes:i,signature:n}=await this.signTxn(t,e);return this.suiInteractor.sendTx(i,n)}async dryRunTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.dryRunTx(n)}async transferSui(t,e,i=!0,n){let s=new u;return s.transferSui(t,e),i?await this.signAndSendTxn(s,n):s}async transferSuiToMany(t,e,i=!0,n){let s=new u;return s.transferSuiToMany(t,e),i?await this.signAndSendTxn(s,n):s}async transferCoinToMany(t,e,i,n=!0,s){let o=new u,a=this.accountManager.getAddress(s),m=e.reduce((c,h)=>c+h,0);if(normalizeStructTag(i)===normalizeStructTag(SUI_TYPE_ARG))o.transferSuiToMany(t,e);else {let c=await this.suiInteractor.selectCoins(a,m,i);o.transferCoinToMany(c.map(h=>"objectId"in h?o.objectRef(h):h),a,t,e);}return n?await this.signAndSendTxn(o,s):o}async transferCoin(t,e,i,n=!0,s){return this.transferCoinToMany([t],[e],i,n,s)}async transferObjects(t,e,i=!0,n){let s=new u;return s.transferObjects(t,e),i?await this.signAndSendTxn(s,n):s}async moveCall(t){let{target:e,arguments:i=[],typeArguments:n=[],derivePathParams:s}=t,o=new u;return o.moveCall(e,i,n),this.signAndSendTxn(o,s)}async selectCoinsWithAmount(t,e,i){return i=i||this.accountManager.currentAddress,await this.suiInteractor.selectCoins(i,t,e)}async stakeSui(t,e,i=!0,n){let s=new u;return s.stakeSui(t,e),i?await this.signAndSendTxn(s,n):s}async inspectTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.currentClient.core.simulateTransaction({transaction:n,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}};function G(r){let t=fromBase64(r);if(t.length!==32&&t.length!==33)throw "invalid pubkey length";return t=t.length===33?t.slice(1):t,new Ed25519PublicKey(t)}var j=class r{pksWeightPairs;threshold;multiSigPublicKey;constructor(t,e){this.pksWeightPairs=t,this.threshold=e,this.multiSigPublicKey=MultiSigPublicKey.fromPublicKeys({threshold:this.threshold,publicKeys:this.pksWeightPairs});}static fromRawEd25519PublicKeys(t,e,i){let n=t.map((s,o)=>({publicKey:G(s),weight:e[o]}));return new r(n,i)}multiSigAddress(){return this.multiSigPublicKey.toSuiAddress()}combinePartialSigs(t){return this.multiSigPublicKey.combinePartialSignatures(t)}};
13
+ var Y=(r={})=>{let{accountIndex:t=0,isExternal:e=!1,addressIndex:i=0}=r;return `m/44'/784'/${t}'/${e?1:0}'/${i}'`},S=(r,t={})=>{let e=Y(t);return Ed25519Keypair.deriveKeypair(r,e)};var X=r=>/^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(r),H=r=>/^[a-zA-Z0-9+/]+={0,2}$/g.test(r),B=r=>{if(X(r))return fromHex(r);if(H(r))return fromBase64(r);throw new Error("The string is not a valid hex or base64 string.")},O=32,L=64,w=r=>{if(r.length===L)return r.slice(0,O);if(r.length===O+1&&r[0]===0)return r.slice(1);if(r.length===O)return r;throw new Error("invalid secret key")};var I=(r=24)=>generateMnemonic(wordlist,r===12?128:256);var b=class{mnemonics;secretKey;currentKeyPair;currentAddress;constructor({mnemonics:t,secretKey:e}={}){this.mnemonics=t||"",this.secretKey=e||"",!this.mnemonics&&!this.secretKey&&(this.mnemonics=I(24)),this.currentKeyPair=this.secretKey?this.parseSecretKey(this.secretKey):S(this.mnemonics),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress();}parseSecretKey(t){if(t.startsWith(SUI_PRIVATE_KEY_PREFIX)){let{secretKey:e}=decodeSuiPrivateKey(t);return Ed25519Keypair.fromSecretKey(w(e))}return Ed25519Keypair.fromSecretKey(w(B(t)))}getKeyPair(t){return !t||!this.mnemonics?this.currentKeyPair:S(this.mnemonics,t)}getAddress(t){return !t||!this.mnemonics?this.currentAddress:S(this.mnemonics,t).getPublicKey().toSuiAddress()}switchAccount(t){this.mnemonics&&(this.currentKeyPair=S(this.mnemonics,t),this.currentAddress=this.currentKeyPair.getPublicKey().toSuiAddress());}};var ct=["u8","u16","u32","u64","u128","u256","bool","address"];function ut(r){if(!ct.includes(r))throw new Error(`Invalid SimpleBcsType: ${r}`);return {$kind:r}}var lt=r=>{if(typeof r=="string"&&isValidSuiObjectId(r))return "object";if(typeof r=="number"||typeof r=="bigint")return "u64";if(typeof r=="boolean")return "bool"};function U(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="string"&&!isValidSuiAddress(r)&&!isNaN(Number(r))}function ht(r){return r!==null&&typeof r=="object"&&"vecType"in r&&"value"in r?!0:!!Array.isArray(r)}function dt(r){return typeof r=="object"&&"digest"in r&&"version"in r&&"objectId"in r}function mt(r){return typeof r=="object"&&"objectId"in r&&"initialSharedVersion"in r&&"mutable"in r}function E(r,t,e){if(t.length===0)throw new Error("Transaction builder error: Empty array is not allowed");let i=lt(t[0]),n=/^vector<(.+)>$/,s=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;if(e=e||i,e==="object"){let o=t.map(a=>typeof a=="string"&&isValidSuiObjectId(a)?r.object(normalizeSuiObjectId(a)):d(r,a));return r.makeMoveVec({elements:o})}else if(typeof e=="string"&&!n.test(e)&&!s.test(e)){let o=ut(e),a=getPureBcsSchema(o);if(!a)throw new Error(`Unknown type: ${e}`);return r.pure(bcs.vector(a).serialize(t))}else {let o=t.map(a=>d(r,a));return r.makeMoveVec({elements:o,type:e})}}function y(r,t){return t.map(e=>e instanceof SerializedBcs||isSerializedBcs(e)?r.pure(e):ht(e)?"vecType"in e?E(r,e.value,e.vecType):E(r,e):U(e)?p(r,[e])[0]:d(r,e))}function g(r,t){return typeof t=="string"&&isValidSuiAddress(t)?r.pure.address(normalizeSuiAddress(t)):y(r,[t])[0]}function d(r,t){if(typeof t=="string")return r.object(t);if(dt(t))return r.objectRef(t);if(mt(t))return r.sharedObjectRef(t);if("Object"in t){if("ImmOrOwnedObject"in t.Object)return r.object(Inputs.ObjectRef(t.Object.ImmOrOwnedObject));if("SharedObject"in t.Object)return r.object(Inputs.SharedObjectRef(t.Object.SharedObject));throw new Error("Invalid argument type")}if(typeof t=="function"||"GasCoin"in t||"Input"in t||"Result"in t||"NestedResult"in t)return t;throw new Error("Invalid argument type")}function p(r,t){return t.map(e=>U(e)?r.pure.u64(e):y(r,[e])[0])}var V=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var u=class{txBlock;constructor(t){this.txBlock=t?Transaction.from(t):new Transaction;}get gas(){return this.txBlock.gas}getData(){return this.txBlock.getData()}address(t){return this.txBlock.pure.address(t)}get pure(){return this.txBlock.pure}object(t){return this.txBlock.object(t)}objectRef(t){return this.txBlock.objectRef(t)}sharedObjectRef(t){return this.txBlock.sharedObjectRef(t)}setSender(t){return this.txBlock.setSender(t)}setSenderIfNotSet(t){return this.txBlock.setSenderIfNotSet(t)}setExpiration(t){return this.txBlock.setExpiration(t)}setGasPrice(t){return this.txBlock.setGasPrice(t)}setGasBudget(t){return this.txBlock.setGasBudget(t)}setGasOwner(t){return this.txBlock.setGasOwner(t)}setGasPayment(t){return this.txBlock.setGasPayment(t)}serialize(){return this.txBlock.serialize()}toJSON(){return this.txBlock.toJSON()}sign(t){return this.txBlock.sign(t)}build(t={}){return this.txBlock.build(t)}getDigest(t={}){return this.txBlock.getDigest(t)}add(...t){return this.txBlock.add(...t)}publish({modules:t,dependencies:e}){return this.txBlock.publish({modules:t,dependencies:e})}upgrade(...t){return this.txBlock.upgrade(...t)}makeMoveVec(...t){return this.txBlock.makeMoveVec(...t)}transferObjects(t,e){return this.txBlock.transferObjects(t.map(i=>d(this.txBlock,i)),g(this.txBlock,e))}splitCoins(t,e){let i=this.txBlock.splitCoins(d(this.txBlock,t),p(this.txBlock,e));return e.map((n,s)=>i[s])}mergeCoins(t,e){let i=d(this.txBlock,t),n=e.map(s=>d(this.txBlock,s));return this.txBlock.mergeCoins(i,n)}moveCall(t,e=[],i=[]){let n=/(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;if(t.match(n)===null)throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");let o=y(this.txBlock,e);return this.txBlock.moveCall({target:t,arguments:o,typeArguments:i})}transferSuiToMany(t,e){if(t.length!==e.length)throw new Error("transferSuiToMany: recipients.length !== amounts.length");let i=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,e));return t.map(s=>g(this.txBlock,s)).forEach((s,o)=>{this.txBlock.transferObjects([i[o]],s);}),this}transferSui(t,e){return this.transferSuiToMany([t],[e])}takeAmountFromCoins(t,e){let{splitedCoins:i,mergedCoin:n}=this.splitMultiCoins(t,p(this.txBlock,[e]));return [i,n]}splitSUIFromGas(t){return this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,t))}splitMultiCoins(t,e){if(t.length===0)throw new Error("takeAmountFromCoins: coins array is empty");let i=V(t.slice(1),511),n=d(this.txBlock,t[0]);for(let o of i){let a=o.map(m=>d(this.txBlock,m));this.txBlock.mergeCoins(n,a);}return {splitedCoins:this.txBlock.splitCoins(n,p(this.txBlock,e)),mergedCoin:n}}transferCoinToMany(t,e,i,n){if(i.length!==n.length)throw new Error("transferCoinToMany: recipients.length !== amounts.length");let s=t.map(c=>d(this.txBlock,c)),{splitedCoins:o,mergedCoin:a}=this.splitMultiCoins(s,p(this.txBlock,n));return i.map(c=>g(this.txBlock,c)).forEach((c,h)=>{this.txBlock.transferObjects([o[h]],c);}),this.txBlock.transferObjects([a],g(this.txBlock,e)),this}transferCoin(t,e,i,n){return this.transferCoinToMany(t,e,[i],[n])}stakeSui(t,e){let[i]=this.txBlock.splitCoins(this.txBlock.gas,p(this.txBlock,[t]));return this.txBlock.moveCall({target:"0x3::sui_system::request_add_stake",arguments:y(this.txBlock,[this.txBlock.object(SUI_SYSTEM_STATE_OBJECT_ID),i,g(this.txBlock,e)])})}};var A=class{objectId;version;digest;constructor(t){this.objectId=t.objectId,this.version=t.version,this.digest=t.digest;}isFullObject(){return !!this.version&&!!this.digest}asCallArg(){return !this.version||!this.digest?this.objectId:{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{objectId:this.objectId,version:this.version,digest:this.digest}}}}updateFromTxResponse(t){let e=t.Transaction??t.FailedTransaction;if(!e)throw new Error("Bad transaction response!");let i=e.effects;if(!i)throw new Error("Transaction response has no effects!");for(let n of i.changedObjects)if(n.objectId===this.objectId&&n.outputDigest){this.digest=n.outputDigest,this.version=n.outputVersion??void 0;return}throw new Error("Could not find object in transaction response!")}};var x=class{objectId;initialSharedVersion;constructor(t){this.objectId=t.objectId,this.initialSharedVersion=t.initialSharedVersion;}asCallArg(t=!1){return this.initialSharedVersion?{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{objectId:this.objectId,initialSharedVersion:this.initialSharedVersion,mutable:t}}}:this.objectId}};var P=r=>new Promise(t=>setTimeout(t,r)),$=(r,t)=>{let e=[];for(let i=0;i<r.length;i+=t)e.push(r.slice(i,i+t));return e};var _=50;function k(r,t){return {baseUrl:r,network:t}}function T(r){switch(r){case"mainnet":return "https://fullnode.mainnet.sui.io:443";case"testnet":return "https://fullnode.testnet.sui.io:443";case"devnet":return "https://fullnode.devnet.sui.io:443";case"localnet":return "http://127.0.0.1:9000";default:throw new Error(`Unknown network: ${r}`)}}var f=class{clients=[];currentClient;fullNodes=[];network;constructor(t){this.network="mainnet","fullnodeUrls"in t&&t.fullnodeUrls?(this.network=t.network??"mainnet",this.fullNodes=t.fullnodeUrls,this.clients=this.fullNodes.map(e=>new SuiGrpcClient(k(e,this.network)))):"suiClients"in t&&t.suiClients?this.clients=t.suiClients:(this.fullNodes=[T(this.network)],this.clients=[new SuiGrpcClient(k(this.fullNodes[0],this.network))]),this.currentClient=this.clients[0];}switchToNextClient(){let t=this.clients.indexOf(this.currentClient);this.currentClient=this.clients[(t+1)%this.clients.length];}switchFullNodes(t,e){if(t.length===0)throw new Error("fullNodes cannot be empty");this.fullNodes=t,e&&(this.network=e),this.clients=t.map(i=>new SuiGrpcClient(k(i,this.network))),this.currentClient=this.clients[0];}get currentFullNode(){if(this.fullNodes.length===0)throw new Error("No full nodes available");let t=this.clients.indexOf(this.currentClient);if(t===-1)throw new Error("Current client not found");return this.fullNodes[t]}async sendTx(t,e){let i=typeof t=="string"?Uint8Array.from(Buffer.from(t,"base64")):t,n=Array.isArray(e)?e:[e];for(let s in this.clients)try{return await this.clients[s].core.executeTransaction({transaction:i,signatures:n,include:{balanceChanges:!0,effects:!0,events:!0,objectTypes:!0}})}catch(o){console.warn(`Failed to send transaction with fullnode ${this.fullNodes[s]}: ${o}`),await P(2e3);}throw new Error("Failed to send transaction with all fullnodes")}async dryRunTx(t){for(let e in this.clients)try{return await this.clients[e].core.simulateTransaction({transaction:t,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}catch(i){console.warn(`Failed to dry run transaction with fullnode ${this.fullNodes[e]}: ${i}`),await P(2e3);}throw new Error("Failed to dry run transaction with all fullnodes")}async getObjects(t,e){let i=e?.include??{content:!0,json:!0},n=$(t,Math.max(e?.batchSize??_,_)),s=[],o=null;for(let a of n){for(let m in this.clients)try{let h=(await this.clients[m].core.getObjects({objectIds:a,include:i})).objects.map(l=>l instanceof Error?null:l).filter(l=>l!==null);s.push(...h),o=null;break}catch(c){o=c instanceof Error?c:new Error(String(c)),await P(e?.switchClientDelay??2e3),console.warn(`Failed to get objects with fullnode ${this.fullNodes[m]}: ${c}`);}if(o)throw new Error(`Failed to get objects with all fullnodes: ${o}`)}return s}async getObject(t,e){return (await this.getObjects([t],e))[0]}async updateObjects(t){let e=t.map(n=>n.objectId),i=await this.getObjects(e);for(let n of i){let s=t.find(o=>o.objectId===n?.objectId);if(s instanceof x){let o=n.owner;o&&typeof o=="object"&&"Shared"in o?s.initialSharedVersion=o.Shared.initialSharedVersion:s.initialSharedVersion=void 0;}else s instanceof A&&(s.version=n?.version,s.digest=n?.digest);}}async selectCoins(t,e,i="0x2::SUI::SUI"){let n=[],s=0,o=!0,a=null;for(;o&&s<e;){let{objects:m,hasNextPage:c,cursor:h}=await this.currentClient.core.listCoins({owner:t,coinType:i,cursor:a});m.sort((l,W)=>parseInt(W.balance)-parseInt(l.balance));for(let l of m)if(n.push({objectId:l.objectId,digest:l.digest,version:l.version,balance:l.balance}),s=s+parseInt(l.balance),s>=e)break;a=h,o=c;}if(!n.length)throw new Error("No valid coins found for the transaction.");return n}};var v=class{accountManager;suiInteractor;constructor(t){let{mnemonics:e,secretKey:i,networkType:n}=t;this.accountManager=new b({mnemonics:e,secretKey:i});let s=n??"mainnet",o;"fullnodeUrls"in t?o={fullnodeUrls:t.fullnodeUrls,network:s}:"suiClients"in t?o={suiClients:t.suiClients}:o={fullnodeUrls:[T(s)],network:s},this.suiInteractor=new f(o);}createTxBlock(){let t=new u;return t.setSender(this.accountManager.currentAddress),t}getKeypair(t){return this.accountManager.getKeyPair(t)}switchAccount(t){this.accountManager.switchAccount(t);}getAddress(t){return this.accountManager.getAddress(t)}get currentAddress(){return this.accountManager.currentAddress}async getBalance(t,e){let i=this.accountManager.getAddress(e),{balance:n}=await this.suiInteractor.currentClient.core.getBalance({owner:i,coinType:t});return n}get client(){return this.suiInteractor.currentClient}async getObjects(t,e){return this.suiInteractor.getObjects(t,e)}async updateObjects(t){return this.suiInteractor.updateObjects(t)}async signTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return await this.getKeypair(e).signTransaction(n)}async signAndSendTxn(t,e){let{bytes:i,signature:n}=await this.signTxn(t,e);return this.suiInteractor.sendTx(i,n)}async dryRunTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.dryRunTx(n)}async transferSui(t,e,i=!0,n){let s=new u;return s.transferSui(t,e),i?await this.signAndSendTxn(s,n):s}async transferSuiToMany(t,e,i=!0,n){let s=new u;return s.transferSuiToMany(t,e),i?await this.signAndSendTxn(s,n):s}async transferCoinToMany(t,e,i,n=!0,s){let o=new u,a=this.accountManager.getAddress(s),m=e.reduce((c,h)=>c+h,0);if(normalizeStructTag(i)===normalizeStructTag(SUI_TYPE_ARG))o.transferSuiToMany(t,e);else {let c=await this.suiInteractor.selectCoins(a,m,i);o.transferCoinToMany(c.map(h=>"objectId"in h?o.objectRef(h):h),a,t,e);}return n?await this.signAndSendTxn(o,s):o}async transferCoin(t,e,i,n=!0,s){return this.transferCoinToMany([t],[e],i,n,s)}async transferObjects(t,e,i=!0,n){let s=new u;return s.transferObjects(t,e),i?await this.signAndSendTxn(s,n):s}async moveCall(t){let{target:e,arguments:i=[],typeArguments:n=[],derivePathParams:s}=t,o=new u;return o.moveCall(e,i,n),this.signAndSendTxn(o,s)}async selectCoinsWithAmount(t,e,i){return i=i||this.accountManager.currentAddress,await this.suiInteractor.selectCoins(i,t,e)}async stakeSui(t,e,i=!0,n){let s=new u;return s.stakeSui(t,e),i?await this.signAndSendTxn(s,n):s}async inspectTxn(t,e){t instanceof u&&t.setSender(this.getAddress(e));let i=t instanceof u?t.txBlock:t,n=i instanceof Uint8Array?i:await i.build({client:this.client});return this.suiInteractor.currentClient.core.simulateTransaction({transaction:n,include:{effects:!0,events:!0,balanceChanges:!0,commandResults:!0}})}};function G(r){let t=fromBase64(r);if(t.length!==32&&t.length!==33)throw "invalid pubkey length";return t=t.length===33?t.slice(1):t,new Ed25519PublicKey(t)}var j=class r{pksWeightPairs;threshold;multiSigPublicKey;constructor(t,e){this.pksWeightPairs=t,this.threshold=e,this.multiSigPublicKey=MultiSigPublicKey.fromPublicKeys({threshold:this.threshold,publicKeys:this.pksWeightPairs});}static fromRawEd25519PublicKeys(t,e,i){let n=t.map((s,o)=>({publicKey:G(s),weight:e[o]}));return new r(n,i)}multiSigAddress(){return this.multiSigPublicKey.toSuiAddress()}combinePartialSigs(t){return this.multiSigPublicKey.combinePartialSignatures(t)}};
14
14
 
15
- export { j as MultiSigClient, S as SuiAccountManager, f as SuiInteractor, v as SuiKit, u as SuiTxBlock, T as getFullnodeUrl };
15
+ export { j as MultiSigClient, b as SuiAccountManager, f as SuiInteractor, v as SuiKit, u as SuiTxBlock, T as getFullnodeUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-kit",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Toolkit for interacting with SUI network",
5
5
  "keywords": [
6
6
  "sui",
@@ -166,7 +166,7 @@ export class SuiTxBlock {
166
166
  */
167
167
  moveCall(
168
168
  target: string,
169
- args: (SuiTxArg | SuiVecTxArg)[] = [],
169
+ args: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[] = [],
170
170
  typeArgs: string[] = []
171
171
  ) {
172
172
  // a regex for pattern `${string}::${string}::${string}`
@@ -87,8 +87,15 @@ function isAmountArg(arg: any): arg is bigint | number | string {
87
87
  * @param arg The argument to check.
88
88
  * @returns boolean.
89
89
  */
90
- function isMoveVecArg(arg: SuiTxArg | SuiVecTxArg): arg is SuiVecTxArg {
91
- if (typeof arg === 'object' && 'vecType' in arg && 'value' in arg) {
90
+ function isMoveVecArg(
91
+ arg: SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg
92
+ ): arg is SuiVecTxArg {
93
+ if (
94
+ arg !== null &&
95
+ typeof arg === 'object' &&
96
+ 'vecType' in arg &&
97
+ 'value' in arg
98
+ ) {
92
99
  return true;
93
100
  } else if (Array.isArray(arg)) {
94
101
  return true;
@@ -191,7 +198,7 @@ export function makeVecParam(
191
198
  */
192
199
  export function convertArgs(
193
200
  txBlock: Transaction,
194
- args: (SuiTxArg | SuiVecTxArg)[]
201
+ args: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[]
195
202
  ): TransactionArgument[] {
196
203
  return args.map((arg) => {
197
204
  if (arg instanceof SerializedBcs || isSerializedBcs(arg)) {
@@ -206,11 +213,10 @@ export function convertArgs(
206
213
  }
207
214
 
208
215
  if (isAmountArg(arg)) {
209
- return convertAmounts(txBlock, [arg])[0];
216
+ return convertAmounts(txBlock, [arg as unknown as SuiAmountsArg])[0];
210
217
  }
211
218
 
212
- // Cast to SuiObjectArg - at this point it should be an object type
213
- return convertObjArg(txBlock, arg as unknown as SuiObjectArg);
219
+ return convertObjArg(txBlock, arg as SuiObjectArg);
214
220
  });
215
221
  }
216
222
 
package/src/suiKit.ts CHANGED
@@ -18,6 +18,7 @@ import type {
18
18
  SuiVecTxArg,
19
19
  SuiKitReturnType,
20
20
  SuiObjectArg,
21
+ SuiAmountsArg,
21
22
  SuiTransactionBlockResponse,
22
23
  } from './types/index.js';
23
24
  import { normalizeStructTag, SUI_TYPE_ARG } from '@mysten/sui/utils';
@@ -351,7 +352,7 @@ export class SuiKit {
351
352
 
352
353
  async moveCall(callParams: {
353
354
  target: string;
354
- arguments?: (SuiTxArg | SuiVecTxArg)[];
355
+ arguments?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[];
355
356
  typeArguments?: string[];
356
357
  derivePathParams?: DerivePathParams;
357
358
  }) {