Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@scallop-io/sui-kit

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scallop-io/sui-kit - npm Package Compare versions

Comparing version 0.35.3 to 0.36.0

dist/libs/suiAccountManager/crypto.d.ts

185

./dist/index.js

@@ -34,12 +34,16 @@ "use strict";

// src/lib/sui-kit.ts
// src/suiKit.ts
var import_sui9 = require("@mysten/sui.js");
// src/lib/sui-account-manager/sui-account-manager.ts
// src/libs/suiAccountManager/index.ts
var import_sui3 = require("@mysten/sui.js");
// src/lib/sui-account-manager/keypair.ts
// src/libs/suiAccountManager/keypair.ts
var import_sui = require("@mysten/sui.js");
var getDerivePathForSUI = (derivePathParams = {}) => {
const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;
const {
accountIndex = 0,
isExternal = false,
addressIndex = 0
} = derivePathParams;
return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;

@@ -52,11 +56,11 @@ };

// src/lib/sui-account-manager/util.ts
// src/libs/suiAccountManager/util.ts
var import_sui2 = require("@mysten/sui.js");
var isHex = (str) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);
var isBase64 = (str) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);
function fromHEX(hexStr) {
var fromHEX = (hexStr) => {
if (!hexStr) {
throw new Error("cannot parse empty string to Uint8Array");
}
let intArr = hexStr.replace("0x", "").match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16));
const intArr = hexStr.replace("0x", "").match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16));
if (!intArr || intArr.length === 0) {

@@ -66,3 +70,3 @@ throw new Error(`Unable to parse HEX: ${hexStr}`);

return Uint8Array.from(intArr);
}
};
var hexOrBase64ToUint8Array = (str) => {

@@ -90,3 +94,3 @@ if (isHex(str)) {

// src/lib/sui-account-manager/crypto.ts
// src/libs/suiAccountManager/crypto.ts
var import_bip39 = require("@scure/bip39");

@@ -99,3 +103,3 @@ var import_english = require("@scure/bip39/wordlists/english.js");

// src/lib/sui-account-manager/sui-account-manager.ts
// src/libs/suiAccountManager/index.ts
var SuiAccountManager = class {

@@ -154,6 +158,6 @@ /**

// src/lib/sui-rpc-provider/sui-rpc-provider.ts
// src/libs/suiRpcProvider/index.ts
var import_sui6 = require("@mysten/sui.js");
// src/lib/sui-rpc-provider/faucet.ts
// src/libs/suiRpcProvider/faucet.ts
var import_sui4 = require("@mysten/sui.js");

@@ -173,3 +177,3 @@ var import_ts_retry_promise = require("ts-retry-promise");

"content-type": "application/json",
"origin": "chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil",
origin: "chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil",
cookie: '_ga=GA1.1.2092533979.1664032306; sui_io_cookie={"level":["necessary","analytics"],"revision":0,"data":null,"rfc_cookie":false}; _ga_YKP53WJMB0=GS1.1.1680531285.31.0.1680531334.11.0.0; _ga_0GW4F97GFL=GS1.1.1680826187.125.0.1680826187.60.0.0; __cf_bm=6rPjXUwuzUPy4yDlZuXgDj0v7xLPpUd5z0CFGCoN_YI-1680867579-0-AZMhU7/mKUUbUlOa27LmfW6eIFkBkXsPKqYgWjpjWpj2XzDckgUsRu/pxSRGfvXCspn3w7Df+uO1MR/b+XikJU0=; _cfuvid=zjwCXMmu19KBIVo_L9Qbq4TqFXJpophG3.EvFTxqdf4-1680867579342-0-604800000',

@@ -184,10 +188,13 @@ "sec-ch-ua": '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',

};
const resp = await (0, import_ts_retry_promise.retry)(() => provider.requestSuiFromFaucet(address, headers), {
backoff: "EXPONENTIAL",
// overall timeout in 60 seconds
timeout: 1e3 * 60,
// skip retry if we hit the rate-limit error
retryIf: (error) => !(error instanceof import_sui4.FaucetRateLimitError),
logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`)
});
const resp = await (0, import_ts_retry_promise.retry)(
() => provider.requestSuiFromFaucet(address, headers),
{
backoff: "EXPONENTIAL",
// overall timeout in 60 seconds
timeout: 1e3 * 60,
// skip retry if we hit the rate-limit error
retryIf: (error) => !(error instanceof import_sui4.FaucetRateLimitError),
logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`)
}
);
(0, import_sui4.assert)(resp, import_sui4.FaucetResponse, "Request faucet failed\n");

@@ -197,3 +204,3 @@ console.log("Request faucet success\n");

// src/lib/sui-rpc-provider/default-chain-configs.ts
// src/libs/suiRpcProvider/defaultChainConfigs.ts
var import_sui5 = require("@mysten/sui.js");

@@ -215,3 +222,3 @@ var getDefaultNetworkParams = (networkType = "devnet") => {

// src/lib/sui-rpc-provider/sui-rpc-provider.ts
// src/libs/suiRpcProvider/index.ts
var SuiRpcProvider = class {

@@ -224,4 +231,10 @@ /**

*/
constructor({ fullnodeUrl, faucetUrl, networkType } = {}) {
const defaultNetworkParams = getDefaultNetworkParams(networkType || "devnet");
constructor({
fullnodeUrl,
faucetUrl,
networkType
} = {}) {
const defaultNetworkParams = getDefaultNetworkParams(
networkType || "devnet"
);
this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullnode;

@@ -254,3 +267,9 @@ this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;

const objectDisplay = (0, import_sui6.getObjectDisplay)(object);
return { objectId, objectType, objectVersion, objectFields, objectDisplay };
return {
objectId,
objectType,
objectVersion,
objectFields,
objectDisplay
};
});

@@ -267,5 +286,5 @@ return parsedObjects;

const coins = await this.provider.getCoins({ owner: addr, coinType });
let selectedCoins = [];
const selectedCoins = [];
let totalAmount = 0;
const coinsData = coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
for (const coinData of coins.data) {

@@ -289,6 +308,6 @@ selectedCoins.push({

// src/lib/sui-tx-builder/sui-tx-block.ts
// src/libs/suiTxBuilder/index.ts
var import_sui8 = require("@mysten/sui.js");
// src/lib/sui-tx-builder/util.ts
// src/libs/suiTxBuilder/util.ts
var import_sui7 = require("@mysten/sui.js");

@@ -340,3 +359,3 @@ var getDefaultSuiInputType = (value) => {

// src/lib/sui-tx-builder/sui-tx-block.ts
// src/libs/suiTxBuilder/index.ts
var SuiTxBlock = class {

@@ -409,3 +428,6 @@ constructor(transaction) {

const coinObject = convertArgs(this.txBlock, [coin])[0];
const res = tx.splitCoins(coinObject, amounts.map((m) => tx.pure(m)));
const res = tx.splitCoins(
coinObject,
amounts.map((m) => tx.pure(m))
);
return amounts.map((_, i) => res[i]);

@@ -437,3 +459,5 @@ }

if (match === null)
throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");
throw new Error(
"Invalid target format. Expected `${string}::${string}::${string}`"
);
const convertedArgs = convertArgs(this.txBlock, args);

@@ -450,6 +474,11 @@ const tx = this.txBlock;

if (recipients.length !== amounts.length) {
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
throw new Error(
"transferSuiToMany: recipients.length !== amounts.length"
);
}
const tx = this.txBlock;
const coins = tx.splitCoins(tx.gas, amounts.map((amount) => tx.pure(amount)));
const coins = tx.splitCoins(
tx.gas,
amounts.map((amount) => tx.pure(amount))
);
recipients.forEach((recipient, index) => {

@@ -475,3 +504,6 @@ tx.transferObjects([coins[index]], tx.pure(recipient));

const tx = this.txBlock;
return tx.splitCoins(tx.gas, amounts.map((m) => tx.pure(m)));
return tx.splitCoins(
tx.gas,
amounts.map((m) => tx.pure(m))
);
}

@@ -485,3 +517,6 @@ splitMultiCoins(coins, amounts) {

}
const splitedCoins = tx.splitCoins(mergedCoin, amounts.map((m) => tx.pure(m)));
const splitedCoins = tx.splitCoins(
mergedCoin,
amounts.map((m) => tx.pure(m))
);
return { splitedCoins, mergedCoin };

@@ -491,6 +526,11 @@ }

if (recipients.length !== amounts.length) {
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
throw new Error(
"transferSuiToMany: recipients.length !== amounts.length"
);
}
const tx = this.txBlock;
const { splitedCoins, mergedCoin } = this.splitMultiCoins(inputCoins, amounts);
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
inputCoins,
amounts
);
recipients.forEach((recipient, index) => {

@@ -510,3 +550,7 @@ tx.transferObjects([splitedCoins[index]], tx.pure(recipient));

target: "0x3::sui_system::request_add_stake",
arguments: [tx.object(import_sui8.SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)]
arguments: [
tx.object(import_sui8.SUI_SYSTEM_STATE_OBJECT_ID),
stakeCoin,
tx.pure(validatorAddr)
]
});

@@ -517,3 +561,3 @@ return tx;

// src/lib/sui-kit.ts
// src/suiKit.ts
var SuiKit = class {

@@ -532,5 +576,15 @@ /**

*/
constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl } = {}) {
constructor({
mnemonics,
secretKey,
networkType,
fullnodeUrl,
faucetUrl
} = {}) {
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
this.rpcProvider = new SuiRpcProvider({ fullnodeUrl, faucetUrl, networkType });
this.rpcProvider = new SuiRpcProvider({
fullnodeUrl,
faucetUrl,
networkType
});
}

@@ -590,7 +644,10 @@ /**

const signer = this.getSigner(derivePathParams);
return signer.signAndExecuteTransactionBlock({ transactionBlock: tx, options: {
showEffects: true,
showEvents: true,
showObjectChanges: true
} });
return signer.signAndExecuteTransactionBlock({
transactionBlock: tx,
options: {
showEffects: true,
showEvents: true,
showObjectChanges: true
}
});
}

@@ -630,8 +687,22 @@ /**

const totalAmount = amounts.reduce((a, b) => a + b, 0);
const coins = await this.rpcProvider.selectCoins(owner, totalAmount, coinType);
tx.transferCoinToMany(coins.map((c) => c.objectId), owner, recipients, amounts);
const coins = await this.rpcProvider.selectCoins(
owner,
totalAmount,
coinType
);
tx.transferCoinToMany(
coins.map((c) => c.objectId),
owner,
recipients,
amounts
);
return this.signAndSendTxn(tx, derivePathParams);
}
async transferCoin(recipient, amount, coinType, derivePathParams) {
return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams);
return this.transferCoinToMany(
[recipient],
[amount],
coinType,
derivePathParams
);
}

@@ -644,3 +715,8 @@ async transferObjects(objects, recipient, derivePathParams) {

async moveCall(callParams) {
const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;
const {
target,
arguments: args = [],
typeArguments = [],
derivePathParams
} = callParams;
const tx = new SuiTxBlock();

@@ -681,3 +757,6 @@ tx.moveCall(target, args, typeArguments);

tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;
return this.rpcProvider.provider.devInspectTransactionBlock({ transactionBlock: tx, sender: this.getAddress(derivePathParams) });
return this.rpcProvider.provider.devInspectTransactionBlock({
transactionBlock: tx,
sender: this.getAddress(derivePathParams)
});
}

@@ -684,0 +763,0 @@ };

@@ -1,9 +0,6 @@

export { TransactionBlock, SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js';
export { SuiKit } from './lib/sui-kit';
export type { SuiKitParams } from './lib/sui-kit';
export { SuiAccountManager } from './lib/sui-account-manager';
export type { DerivePathParams } from './lib/sui-account-manager';
export { SuiTxBlock } from './lib/sui-tx-builder';
export type { SuiTxArg, SuiObjectArg } from './lib/sui-tx-builder';
export { SuiRpcProvider } from './lib/sui-rpc-provider';
export type { NetworkType } from './lib/sui-rpc-provider';
export { TransactionBlock, SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID, } from '@mysten/sui.js';
export { SuiKit } from './suiKit';
export { SuiAccountManager } from './libs/suiAccountManager';
export { SuiTxBlock } from './libs/suiTxBuilder';
export { SuiRpcProvider } from './libs/suiRpcProvider';
export type * from './types';

@@ -34,12 +34,16 @@ "use strict";

// src/lib/sui-kit.ts
// src/suiKit.ts
var import_sui9 = require("@mysten/sui.js");
// src/lib/sui-account-manager/sui-account-manager.ts
// src/libs/suiAccountManager/index.ts
var import_sui3 = require("@mysten/sui.js");
// src/lib/sui-account-manager/keypair.ts
// src/libs/suiAccountManager/keypair.ts
var import_sui = require("@mysten/sui.js");
var getDerivePathForSUI = (derivePathParams = {}) => {
const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;
const {
accountIndex = 0,
isExternal = false,
addressIndex = 0
} = derivePathParams;
return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;

@@ -52,11 +56,11 @@ };

// src/lib/sui-account-manager/util.ts
// src/libs/suiAccountManager/util.ts
var import_sui2 = require("@mysten/sui.js");
var isHex = (str) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);
var isBase64 = (str) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);
function fromHEX(hexStr) {
var fromHEX = (hexStr) => {
if (!hexStr) {
throw new Error("cannot parse empty string to Uint8Array");
}
let intArr = hexStr.replace("0x", "").match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16));
const intArr = hexStr.replace("0x", "").match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16));
if (!intArr || intArr.length === 0) {

@@ -66,3 +70,3 @@ throw new Error(`Unable to parse HEX: ${hexStr}`);

return Uint8Array.from(intArr);
}
};
var hexOrBase64ToUint8Array = (str) => {

@@ -90,3 +94,3 @@ if (isHex(str)) {

// src/lib/sui-account-manager/crypto.ts
// src/libs/suiAccountManager/crypto.ts
var import_bip39 = require("@scure/bip39");

@@ -99,3 +103,3 @@ var import_english = require("@scure/bip39/wordlists/english.js");

// src/lib/sui-account-manager/sui-account-manager.ts
// src/libs/suiAccountManager/index.ts
var SuiAccountManager = class {

@@ -154,6 +158,6 @@ /**

// src/lib/sui-rpc-provider/sui-rpc-provider.ts
// src/libs/suiRpcProvider/index.ts
var import_sui6 = require("@mysten/sui.js");
// src/lib/sui-rpc-provider/faucet.ts
// src/libs/suiRpcProvider/faucet.ts
var import_sui4 = require("@mysten/sui.js");

@@ -173,3 +177,3 @@ var import_ts_retry_promise = require("ts-retry-promise");

"content-type": "application/json",
"origin": "chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil",
origin: "chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil",
cookie: '_ga=GA1.1.2092533979.1664032306; sui_io_cookie={"level":["necessary","analytics"],"revision":0,"data":null,"rfc_cookie":false}; _ga_YKP53WJMB0=GS1.1.1680531285.31.0.1680531334.11.0.0; _ga_0GW4F97GFL=GS1.1.1680826187.125.0.1680826187.60.0.0; __cf_bm=6rPjXUwuzUPy4yDlZuXgDj0v7xLPpUd5z0CFGCoN_YI-1680867579-0-AZMhU7/mKUUbUlOa27LmfW6eIFkBkXsPKqYgWjpjWpj2XzDckgUsRu/pxSRGfvXCspn3w7Df+uO1MR/b+XikJU0=; _cfuvid=zjwCXMmu19KBIVo_L9Qbq4TqFXJpophG3.EvFTxqdf4-1680867579342-0-604800000',

@@ -184,10 +188,13 @@ "sec-ch-ua": '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',

};
const resp = await (0, import_ts_retry_promise.retry)(() => provider.requestSuiFromFaucet(address, headers), {
backoff: "EXPONENTIAL",
// overall timeout in 60 seconds
timeout: 1e3 * 60,
// skip retry if we hit the rate-limit error
retryIf: (error) => !(error instanceof import_sui4.FaucetRateLimitError),
logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`)
});
const resp = await (0, import_ts_retry_promise.retry)(
() => provider.requestSuiFromFaucet(address, headers),
{
backoff: "EXPONENTIAL",
// overall timeout in 60 seconds
timeout: 1e3 * 60,
// skip retry if we hit the rate-limit error
retryIf: (error) => !(error instanceof import_sui4.FaucetRateLimitError),
logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`)
}
);
(0, import_sui4.assert)(resp, import_sui4.FaucetResponse, "Request faucet failed\n");

@@ -197,3 +204,3 @@ console.log("Request faucet success\n");

// src/lib/sui-rpc-provider/default-chain-configs.ts
// src/libs/suiRpcProvider/defaultChainConfigs.ts
var import_sui5 = require("@mysten/sui.js");

@@ -215,3 +222,3 @@ var getDefaultNetworkParams = (networkType = "devnet") => {

// src/lib/sui-rpc-provider/sui-rpc-provider.ts
// src/libs/suiRpcProvider/index.ts
var SuiRpcProvider = class {

@@ -224,4 +231,10 @@ /**

*/
constructor({ fullnodeUrl, faucetUrl, networkType } = {}) {
const defaultNetworkParams = getDefaultNetworkParams(networkType || "devnet");
constructor({
fullnodeUrl,
faucetUrl,
networkType
} = {}) {
const defaultNetworkParams = getDefaultNetworkParams(
networkType || "devnet"
);
this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullnode;

@@ -254,3 +267,9 @@ this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;

const objectDisplay = (0, import_sui6.getObjectDisplay)(object);
return { objectId, objectType, objectVersion, objectFields, objectDisplay };
return {
objectId,
objectType,
objectVersion,
objectFields,
objectDisplay
};
});

@@ -267,5 +286,5 @@ return parsedObjects;

const coins = await this.provider.getCoins({ owner: addr, coinType });
let selectedCoins = [];
const selectedCoins = [];
let totalAmount = 0;
const coinsData = coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance));
for (const coinData of coins.data) {

@@ -289,6 +308,6 @@ selectedCoins.push({

// src/lib/sui-tx-builder/sui-tx-block.ts
// src/libs/suiTxBuilder/index.ts
var import_sui8 = require("@mysten/sui.js");
// src/lib/sui-tx-builder/util.ts
// src/libs/suiTxBuilder/util.ts
var import_sui7 = require("@mysten/sui.js");

@@ -340,3 +359,3 @@ var getDefaultSuiInputType = (value) => {

// src/lib/sui-tx-builder/sui-tx-block.ts
// src/libs/suiTxBuilder/index.ts
var SuiTxBlock = class {

@@ -409,3 +428,6 @@ constructor(transaction) {

const coinObject = convertArgs(this.txBlock, [coin])[0];
const res = tx.splitCoins(coinObject, amounts.map((m) => tx.pure(m)));
const res = tx.splitCoins(
coinObject,
amounts.map((m) => tx.pure(m))
);
return amounts.map((_, i) => res[i]);

@@ -437,3 +459,5 @@ }

if (match === null)
throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");
throw new Error(
"Invalid target format. Expected `${string}::${string}::${string}`"
);
const convertedArgs = convertArgs(this.txBlock, args);

@@ -450,6 +474,11 @@ const tx = this.txBlock;

if (recipients.length !== amounts.length) {
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
throw new Error(
"transferSuiToMany: recipients.length !== amounts.length"
);
}
const tx = this.txBlock;
const coins = tx.splitCoins(tx.gas, amounts.map((amount) => tx.pure(amount)));
const coins = tx.splitCoins(
tx.gas,
amounts.map((amount) => tx.pure(amount))
);
recipients.forEach((recipient, index) => {

@@ -475,3 +504,6 @@ tx.transferObjects([coins[index]], tx.pure(recipient));

const tx = this.txBlock;
return tx.splitCoins(tx.gas, amounts.map((m) => tx.pure(m)));
return tx.splitCoins(
tx.gas,
amounts.map((m) => tx.pure(m))
);
}

@@ -485,3 +517,6 @@ splitMultiCoins(coins, amounts) {

}
const splitedCoins = tx.splitCoins(mergedCoin, amounts.map((m) => tx.pure(m)));
const splitedCoins = tx.splitCoins(
mergedCoin,
amounts.map((m) => tx.pure(m))
);
return { splitedCoins, mergedCoin };

@@ -491,6 +526,11 @@ }

if (recipients.length !== amounts.length) {
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
throw new Error(
"transferSuiToMany: recipients.length !== amounts.length"
);
}
const tx = this.txBlock;
const { splitedCoins, mergedCoin } = this.splitMultiCoins(inputCoins, amounts);
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
inputCoins,
amounts
);
recipients.forEach((recipient, index) => {

@@ -510,3 +550,7 @@ tx.transferObjects([splitedCoins[index]], tx.pure(recipient));

target: "0x3::sui_system::request_add_stake",
arguments: [tx.object(import_sui8.SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)]
arguments: [
tx.object(import_sui8.SUI_SYSTEM_STATE_OBJECT_ID),
stakeCoin,
tx.pure(validatorAddr)
]
});

@@ -517,3 +561,3 @@ return tx;

// src/lib/sui-kit.ts
// src/suiKit.ts
var SuiKit = class {

@@ -532,5 +576,15 @@ /**

*/
constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl } = {}) {
constructor({
mnemonics,
secretKey,
networkType,
fullnodeUrl,
faucetUrl
} = {}) {
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
this.rpcProvider = new SuiRpcProvider({ fullnodeUrl, faucetUrl, networkType });
this.rpcProvider = new SuiRpcProvider({
fullnodeUrl,
faucetUrl,
networkType
});
}

@@ -590,7 +644,10 @@ /**

const signer = this.getSigner(derivePathParams);
return signer.signAndExecuteTransactionBlock({ transactionBlock: tx, options: {
showEffects: true,
showEvents: true,
showObjectChanges: true
} });
return signer.signAndExecuteTransactionBlock({
transactionBlock: tx,
options: {
showEffects: true,
showEvents: true,
showObjectChanges: true
}
});
}

@@ -630,8 +687,22 @@ /**

const totalAmount = amounts.reduce((a, b) => a + b, 0);
const coins = await this.rpcProvider.selectCoins(owner, totalAmount, coinType);
tx.transferCoinToMany(coins.map((c) => c.objectId), owner, recipients, amounts);
const coins = await this.rpcProvider.selectCoins(
owner,
totalAmount,
coinType
);
tx.transferCoinToMany(
coins.map((c) => c.objectId),
owner,
recipients,
amounts
);
return this.signAndSendTxn(tx, derivePathParams);
}
async transferCoin(recipient, amount, coinType, derivePathParams) {
return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams);
return this.transferCoinToMany(
[recipient],
[amount],
coinType,
derivePathParams
);
}

@@ -644,3 +715,8 @@ async transferObjects(objects, recipient, derivePathParams) {

async moveCall(callParams) {
const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;
const {
target,
arguments: args = [],
typeArguments = [],
derivePathParams
} = callParams;
const tx = new SuiTxBlock();

@@ -681,3 +757,6 @@ tx.moveCall(target, args, typeArguments);

tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;
return this.rpcProvider.provider.devInspectTransactionBlock({ transactionBlock: tx, sender: this.getAddress(derivePathParams) });
return this.rpcProvider.provider.devInspectTransactionBlock({
transactionBlock: tx,
sender: this.getAddress(derivePathParams)
});
}

@@ -684,0 +763,0 @@ };

{
"name": "@scallop-io/sui-kit",
"version": "0.35.3",
"version": "0.36.0",
"description": "Tookit for interacting with SUI network",

@@ -40,3 +40,3 @@ "keywords": [

"dependencies": {
"@mysten/sui.js": "^0.35.1",
"@mysten/sui.js": "^0.36.0",
"@scure/bip39": "^1.2.0",

@@ -53,10 +53,84 @@ "assert": "^2.0.0",

"devDependencies": {
"@types/node": "^20.2.1",
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.6.5",
"@commitlint/prompt-cli": "^17.6.5",
"@types/node": "^20.3.1",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@types/tmp": "^0.2.3",
"dotenv": "^16.0.3",
"dotenv": "^16.3.1",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"tsconfig-paths": "^4.2.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"tsup": "^6.7.0",
"typescript": "^5.0.4"
"tsup": "^7.0.0",
"typedoc": "^0.24.8",
"typescript": "^5.0.4",
"vitest": "^0.32.2"
},
"lint-staged": {
"**/*.ts": [
"pnpm run format:fix",
"pnpm run lint:fix"
],
"**/*.json|md": [
"pnpm run format:fix"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"prettier": {
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"useTabs": false,
"quoteProps": "as-needed",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
},
"eslintConfig": {
"root": true,
"env": {
"browser": true,
"node": true,
"es2022": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:prettier/recommended"
],
"plugins": [
"@typescript-eslint",
"prettier"
],
"parser": "@typescript-eslint/parser",
"rules": {
"prettier/prettier": "warn",
"@typescript-eslint/no-explicit-any": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
}
},
"scripts": {

@@ -69,4 +143,12 @@ "clean": "rm -rf tsconfig.tsbuildinfo ./dist",

"watch:types": "tsc --watch",
"watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup"
"watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup",
"test": "pnpm test:typecheck && pnpm test:unit",
"test:typecheck": "tsc -p ./test",
"test:unit": "vitest run --test-timeout=60000",
"test:watch": "vitest",
"format:fix": "prettier --ignore-path 'dist/* docs/*' --write '**/*.{ts,json,md}'",
"lint:fix": "eslint . --ignore-pattern dist --ext .ts --fix",
"commit": "commit",
"doc": "typedoc --out docs src/index.ts"
}
}
# Tookit for interacting with SUI network
[中文文档](./README_cn.md)
[中文文档](./document/README_cn.md)
## Features
- [x] Transfer SUI, Custom Coin and objects.
- [x] Move call
- [x] Programmable transaction
- [x] Query on-chain data
- [x] Query on-chain data
- [x] HD wallet multi-accounts
- [x] Publish & upgrade Move packages

@@ -19,3 +19,2 @@ ## Pre-requisites

## How to use

@@ -35,3 +34,2 @@

// 12 or 24 words mnemonics

@@ -41,7 +39,5 @@ const mnemonics = '<Mnemonics>';

// It will create a HD wallet with a random mnemonics
// It will create a HD wallet with a random mnemonics
const suiKit3 = new SuiKit();
// Override options

@@ -55,12 +51,11 @@ const suiKit = new SuiKit({

// the faucet url, default is the preconfig faucet url for the given network type
faucetUrl: '<SUI faucet url>'
faucetUrl: '<SUI faucet url>',
});
```
### Transfer
### Transfer
You can use SuiKit to transfer SUI, custom coins, and any objects.
```typescript
const recipient1 = '0x123'; // repace with real address

@@ -78,3 +73,7 @@ const recipient2 = '0x456'; // repace with real address

// Transfer custom coin to multiple recipients
await suiKit.transferCoinToMany([recipient1, recipient2], [1000, 2000], coinType);
await suiKit.transferCoinToMany(
[recipient1, recipient2],
[1000, 2000],
coinType
);

@@ -87,2 +86,3 @@ // Transfer objects

### Stake SUI
You can use SuiKit to stake SUI.

@@ -102,2 +102,3 @@

### Move call
You can use SuiKit to call move functions.

@@ -111,7 +112,8 @@

});
console.log(res)
console.log(res);
```
How to pass arguments?
How to pass arguments?
Suppose you have a move function like this:
```move

@@ -129,8 +131,14 @@ public entry fun test_args(

```
You can pass the arguments like this:
```typescript
const addr1 = '0x656b875c9c072a465048fc10643470a39ba331727719df46c004973fcfb53c95';
const addr2 = '0x10651e50cdbb4944a8fd77665d5af27f8abde6eb76a12b97444809ae4ddb1aad';
const coin1 = '0xd4a01b597b87986b04b65e04049499b445c0ee901fe8ba310b1cf29feaa86876';
const coin2 = '0x4d4a01b597b87986b04b65e04049499b445c0ee901fe8ba310b1cf29feaa8687';
const addr1 =
'0x656b875c9c072a465048fc10643470a39ba331727719df46c004973fcfb53c95';
const addr2 =
'0x10651e50cdbb4944a8fd77665d5af27f8abde6eb76a12b97444809ae4ddb1aad';
const coin1 =
'0xd4a01b597b87986b04b65e04049499b445c0ee901fe8ba310b1cf29feaa86876';
const coin2 =
'0x4d4a01b597b87986b04b65e04049499b445c0ee901fe8ba310b1cf29feaa8687';
suiKit.moveCall({

@@ -140,5 +148,5 @@ target: `${pkgId}::module::test_args`,

// pass vector<address>, need to specify the vecType as 'address'
{value: [addr1, addr2], vecType: 'address'},
{ value: [addr1, addr2], vecType: 'address' },
// pass vector<u8>, need to specify the vecType as 'u8'
{value: [10, 20], vecType: 'u8'},
{ value: [10, 20], vecType: 'u8' },
// pass vector<u64>, default vecType for number array is 'u64', so no need to specify

@@ -150,6 +158,8 @@ [34324, 234234],

[coin1, coin2],
]
],
});
```
All the supported types are:
- address

@@ -166,2 +176,3 @@ - u8

### Programmable transaction
With programmable transaction, you can send a transaction with multiple actions.

@@ -171,45 +182,43 @@ The following is an example using flashloan to make arbitrage.

```typescript
import { SuiKit, SuiTxBlock } from "@scallop-io/sui-kit";
import * as process from "process";
import * as dotenv from "dotenv";
import { SuiKit, SuiTxBlock } from '@scallop-io/sui-kit';
import * as process from 'process';
import * as dotenv from 'dotenv';
dotenv.config();
const treasuryA = '0xe5042357d2c2bb928f37e4d12eac594e6d02327d565e801eaf9aca4c7340c28c';
const treasuryB = '0xdd2f53171b8c886fad20e0bfecf1d4eede9d6c75762f169a9f3c3022e5ce7293';
const dexPool = '0x8a13859a8d930f3238ddd31180a5f0914e5b8dbaa31e18387066b61a563fedf9';
const treasuryA =
'0xe5042357d2c2bb928f37e4d12eac594e6d02327d565e801eaf9aca4c7340c28c';
const treasuryB =
'0xdd2f53171b8c886fad20e0bfecf1d4eede9d6c75762f169a9f3c3022e5ce7293';
const dexPool =
'0x8a13859a8d930f3238ddd31180a5f0914e5b8dbaa31e18387066b61a563fedf9';
const pkgId = '0x3c316b6af0586343ce8e6b4be890305a1f83b7e196366f6435b22b6e3fc8e3d9';
const pkgId =
'0x3c316b6af0586343ce8e6b4be890305a1f83b7e196366f6435b22b6e3fc8e3d9';
(async() => {
(async () => {
const mnemonics = process.env.MNEMONICS;
const suiKit = new SuiKit({ mnemonics });
const sender = suiKit.currentAddress();
const tx = new SuiTxBlock();
// 1. Make a flash loan for coinB
const[coinB, loan] = tx.moveCall(
`${pkgId}::custom_coin_b::flash_loan`,
[treasuryB, 10 ** 9],
);
const [coinB, loan] = tx.moveCall(`${pkgId}::custom_coin_b::flash_loan`, [
treasuryB,
10 ** 9,
]);
// 2. Swap from coinB to coinA, ratio is 1:1
const coinA = tx.moveCall(
`${pkgId}::dex::swap_a`,
[dexPool, coinB],
);
const coinA = tx.moveCall(`${pkgId}::dex::swap_a`, [dexPool, coinB]);
// 3. Swap from coinA back to coinB, ratio is 1:2
const coinB2 = tx.moveCall(
`${pkgId}::dex::swap_b`,
[dexPool, coinA]
);
const coinB2 = tx.moveCall(`${pkgId}::dex::swap_b`, [dexPool, coinA]);
// 4. Repay flash loan
const [paybackCoinB] = tx.splitCoins(coinB2, [10 ** 9]);
tx.moveCall(
`${pkgId}::custom_coin_b::payback_loan`,
[treasuryB, paybackCoinB, loan],
);
tx.moveCall(`${pkgId}::custom_coin_b::payback_loan`, [
treasuryB,
paybackCoinB,
loan,
]);
// 4. Transfer profits to sender
tx.transferObjects([coinB2], sender);
// 5. Execute transaction

@@ -219,3 +228,2 @@ const res = await suiKit.signAndSendTxn(tx);

})();
```

@@ -236,74 +244,41 @@

const displayAccounts = async (suiKit: SuiKit, accountIndex: number) => {
const coinType = '0x2::sui::SUI'
const addr = suiKit.getAddress({accountIndex})
const balance = (await suiKit.getBalance(coinType, {accountIndex})).totalBalance
console.log(`Account ${accountIndex}: ${addr} has ${balance} SUI`)
}
const coinType = '0x2::sui::SUI';
const addr = suiKit.getAddress({ accountIndex });
const balance = (await suiKit.getBalance(coinType, { accountIndex }))
.totalBalance;
console.log(`Account ${accountIndex}: ${addr} has ${balance} SUI`);
};
// log the first 10 accounts
const numAccounts = 10
const numAccounts = 10;
for (let i = 0; i < numAccounts; i++) {
await displayAccounts(suiKit, i)
await displayAccounts(suiKit, i);
}
}
async function internalTransferSui(suiKit: SuiKit, fromAccountIndex: number, toAccountIndex: number, amount: number) {
const toAddr = suiKit.getAddress({accountIndex: toAccountIndex })
console.log(`Transfer ${amount} SUI from account ${fromAccountIndex} to account ${toAccountIndex}`)
return await suiKit.transferSui(toAddr, amount, {accountIndex: fromAccountIndex})
async function internalTransferSui(
suiKit: SuiKit,
fromAccountIndex: number,
toAccountIndex: number,
amount: number
) {
const toAddr = suiKit.getAddress({ accountIndex: toAccountIndex });
console.log(
`Transfer ${amount} SUI from account ${fromAccountIndex} to account ${toAccountIndex}`
);
return await suiKit.transferSui(toAddr, amount, {
accountIndex: fromAccountIndex,
});
}
const mnemonics = process.env.MNEMONICS;
const suiKit = new SuiKit({ mnemonics })
checkAccounts(suiKit).then(() => {})
const suiKit = new SuiKit({ mnemonics });
checkAccounts(suiKit).then(() => {});
// transfer 1000 SUI from account 0 to account 1
internalTransferSui(suiKit, 0, 1, 1000).then(() => {})
internalTransferSui(suiKit, 0, 1, 1000).then(() => {});
```
### Publish & upgrade Move package
We have a standalone npm package to help you publish and upgrade Move package with typescript.
1. Install the package
```bash
npm install @scallop-io/sui-package-kit
```
We have a standalone npm package to help you publish and upgrade Move package based on sui-kit.
2. Install SUI cli
Please refer to the official documentation: [How to install SUI cli](https://docs.sui.io/devnet/build/install)
```typescript
/**
* This is an example of using SuiKit to publish a move package
*/
import { SuiKit } from "@scallop-io/sui-kit";
import { SuiPackagePublisher } from "@scallop-dao/sui-package-kit";
(async() => {
const mnemonics = '<Your mnemonics>';
const suiKit = new SuiKit({ mnemonics, networkType: 'devnet' });
const packagePath = path.join(__dirname, './sample_move/package_a');
const publisher = new SuiPackagePublisher();
const result = await publisher.publishPackage(packagePath, suiKit.getSigner());
console.log('packageId: ' + result.packageId);
})();
```
```typescript
/**
* This is an example of using SuiKit to upgrade a move package
*/
import { SuiKit } from "@scallop-io/sui-kit";
import { SuiPackagePublisher } from "@scallop-dao/sui-package-kit";
(async() => {
const mnemonics = '<Your mnemonics>';
const suiKit = new SuiKit({ mnemonics, networkType: 'devnet' });
const upgradeCapId = '<Package upgrade cap id>';
// Rember to set the 'published-at' in the package manifest
const packagePath = path.join(__dirname, './sample_move/package_a_upgrade');
const publisher = new SuiPackagePublisher();
const result = await publisher.upgradePackage(packagePath, upgradeCapId, { skipFetchLatestGitDeps: true });
console.log(result);
})();
```
Please refer to the repository: [sui-package-kit](https://docs.sui.io/devnet/build/install)

@@ -1,10 +0,10 @@

export { TransactionBlock, SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js'
export { SuiKit } from './lib/sui-kit'
export type { SuiKitParams } from './lib/sui-kit'
export { SuiAccountManager } from './lib/sui-account-manager'
export type { DerivePathParams } from './lib/sui-account-manager'
export { SuiTxBlock } from './lib/sui-tx-builder'
export type { SuiTxArg, SuiObjectArg } from './lib/sui-tx-builder'
export { SuiRpcProvider } from './lib/sui-rpc-provider'
export type { NetworkType } from './lib/sui-rpc-provider'
export {
TransactionBlock,
SUI_CLOCK_OBJECT_ID,
SUI_SYSTEM_STATE_OBJECT_ID,
} from '@mysten/sui.js';
export { SuiKit } from './suiKit';
export { SuiAccountManager } from './libs/suiAccountManager';
export { SuiTxBlock } from './libs/suiTxBuilder';
export { SuiRpcProvider } from './libs/suiRpcProvider';
export type * from './types';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc