Skip to content

Commit

Permalink
chore: cleanup and refactor (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
npty authored Aug 19, 2024
1 parent f2d771b commit ca64dd9
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 122 deletions.
13 changes: 9 additions & 4 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ const {
utils: { arrayify },
} = ethers;
const { saveConfig, printInfo, validateParameters, writeJSON, getDomainSeparator, loadConfig } = require('../common');
const { addBaseOptions, addOptionsToCommands } = require('./cli-utils');
const { getWallet, printWalletInfo, broadcast } = require('./sign-utils');
const { bytes32Struct, signersStruct } = require('./types-utils');
const { upgradePackage, UPGRADE_POLICIES } = require('./deploy-utils');
const {
addBaseOptions,
addOptionsToCommands,
getWallet,
printWalletInfo,
broadcast,
bytes32Struct,
signersStruct,
upgradePackage,
UPGRADE_POLICIES,
getSigners,
deployPackage,
getObjectIdsByObjectTypes,
Expand Down
75 changes: 0 additions & 75 deletions sui/deploy-test.js

This file was deleted.

5 changes: 2 additions & 3 deletions sui/faucet.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const { addBaseOptions } = require('./cli-utils');
const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui/faucet');
const { getWallet, printWalletInfo } = require('./sign-utils');
const { Command } = require('commander');
const { saveConfig, loadConfig, printInfo } = require('../common/utils');
const { getWallet, printWalletInfo, addBaseOptions } = require('./utils');
const { Command } = require('commander');

async function processCommand(config, chain, options) {
const [keypair, client] = getWallet(chain, options);
Expand Down
20 changes: 12 additions & 8 deletions sui/gas-service.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
const { saveConfig, printInfo, printError } = require('../common/utils');
const { Command } = require('commander');
const { Transaction } = require('@mysten/sui/transactions');
const { bcs } = require('@mysten/sui/bcs');
const { loadConfig } = require('../common/utils');
const { gasServiceStruct } = require('./types-utils');
const { getBcsBytesByObjectId } = require('./utils');
const { ethers } = require('hardhat');
const { getFormattedAmount } = require('./amount-utils');
const {
utils: { arrayify },
} = ethers;

const { addOptionsToCommands, addBaseOptions, parseSuiUnitAmount } = require('./cli-utils');
const { getWallet, printWalletInfo, broadcast } = require('./sign-utils');
const { saveConfig, loadConfig, printInfo, printError } = require('../common/utils');
const {
getWallet,
printWalletInfo,
broadcast,
gasServiceStruct,
getBcsBytesByObjectId,
getFormattedAmount,
addOptionsToCommands,
addBaseOptions,
parseSuiUnitAmount,
} = require('./utils');

async function payGas(keypair, client, gasServiceConfig, args, options) {
const walletAddress = keypair.toSuiAddress();
Expand Down
20 changes: 14 additions & 6 deletions sui/gateway.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { saveConfig, printInfo } = require('../common/utils');
const { Command, Option } = require('commander');
const { Transaction } = require('@mysten/sui/transactions');
const { bcs } = require('@mysten/sui/bcs');
Expand All @@ -8,11 +7,20 @@ const {
constants: { HashZero },
} = ethers;

const { loadConfig } = require('../common/utils');
const { addBaseOptions } = require('./cli-utils');
const { getWallet, printWalletInfo, getRawPrivateKey, broadcast } = require('./sign-utils');
const { bytes32Struct, signersStruct, messageToSignStruct, messageStruct, proofStruct } = require('./types-utils');
const { getSigners } = require('./deploy-gateway');
const { saveConfig, printInfo, loadConfig } = require('../common/utils');
const {
bytes32Struct,
signersStruct,
messageToSignStruct,
messageStruct,
proofStruct,
addBaseOptions,
getSigners,
getWallet,
printWalletInfo,
getRawPrivateKey,
broadcast,
} = require('./utils');
const secp256k1 = require('secp256k1');

const COMMAND_TYPE_APPROVE_MESSAGES = 0;
Expand Down
3 changes: 1 addition & 2 deletions sui/generate-keypair.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const { addBaseOptions } = require('./cli-utils');
const { generateKeypair, getRawPrivateKey } = require('./sign-utils');
const { Command, Option } = require('commander');
const { addBaseOptions, generateKeypair, getRawPrivateKey } = require('./utils');
const { saveConfig, loadConfig, printInfo } = require('../common/utils');

const { ethers } = require('hardhat');
Expand Down
20 changes: 12 additions & 8 deletions sui/gmp.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
const { saveConfig, printInfo } = require('../common/utils');
const { Command } = require('commander');
const { Transaction } = require('@mysten/sui/transactions');
const { bcs } = require('@mysten/sui/bcs');
const { getBcsBytesByObjectId } = require('./utils');
const { loadConfig } = require('../common/utils');
const { saveConfig, printInfo } = require('../common/utils');
const {
loadConfig,
getBcsBytesByObjectId,
addBaseOptions,
addOptionsToCommands,
getUnitAmount,
getWallet,
printWalletInfo,
discoveryStruct,
broadcast,
} = require('./utils');
const { ethers } = require('hardhat');
const {
utils: { arrayify },
} = ethers;

const { addBaseOptions, addOptionsToCommands } = require('./cli-utils');
const { getUnitAmount } = require('./amount-utils.js');
const { getWallet, printWalletInfo, broadcast } = require('./sign-utils');
const { discoveryStruct } = require('./types-utils.js');

async function sendCommand(keypair, client, contracts, args, options) {
const [destinationChain, destinationAddress, feeAmount, payload] = args;
const params = options.params;
Expand Down
6 changes: 2 additions & 4 deletions sui/multisig.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const { Command, Option } = require('commander');
const { fromB64 } = require('@mysten/bcs');
const { addBaseOptions } = require('./cli-utils');
const { getWallet, getMultisig, signTransactionBlockBytes, broadcastSignature } = require('./sign-utils');
const { loadConfig, printInfo, validateParameters } = require('../common/utils');
const { getSignedTx, storeSignedTx } = require('../evm/sign-utils');
const { loadConfig } = require('../common/utils');
const { printInfo, validateParameters } = require('../common/utils');
const { addBaseOptions, getWallet, getMultisig, signTransactionBlockBytes, broadcastSignature } = require('./utils');

async function signTx(keypair, client, options) {
const txFileData = getSignedTx(options.txBlockPath);
Expand Down
12 changes: 9 additions & 3 deletions sui/operators.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const { Command, Option } = require('commander');
const { Transaction } = require('@mysten/sui/transactions');
const { printInfo, printError, loadConfig } = require('../common/utils');
const { addBaseOptions, addOptionsToCommands, parseSuiUnitAmount } = require('./cli-utils');
const { getWallet, printWalletInfo, broadcast } = require('./sign-utils');
const { findOwnedObjectId } = require('./utils');
const {
addBaseOptions,
addOptionsToCommands,
parseSuiUnitAmount,
getWallet,
printWalletInfo,
broadcast,
findOwnedObjectId,
} = require('./utils');

function operatorMoveCall(contractConfig, gasServiceConfig, operatorCapId, tx, moveCall) {
const operatorId = contractConfig.objects.Operators;
Expand Down
6 changes: 2 additions & 4 deletions sui/transfer-object.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { Transaction } = require('@mysten/sui/transactions');
const { Command, Option } = require('commander');
const { printInfo, validateParameters } = require('../common/utils');
const { addExtendedOptions } = require('./cli-utils');
const { getWallet, printWalletInfo } = require('./sign-utils');
const { loadConfig } = require('../common/utils');
const { loadConfig, printInfo, validateParameters } = require('../common/utils');
const { getWallet, printWalletInfo, addExtendedOptions } = require('./utils');

async function processCommand(chain, options) {
const [keypair, client] = getWallet(chain, options);
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions sui/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
...require('./amount-utils'),
...require('./sign-utils'),
...require('./types-utils'),
...require('./utils'),
...require('./upgrade-utils'),
...require('./cli-utils'),
};
2 changes: 1 addition & 1 deletion sui/sign-utils.js → sui/utils/sign-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { Secp256k1Keypair, Secp256k1PublicKey } = require('@mysten/sui/keypairs/s
const { Secp256r1Keypair, Secp256r1PublicKey } = require('@mysten/sui/keypairs/secp256r1');
const { SuiClient, getFullnodeUrl } = require('@mysten/sui/client');
const { fromB64, fromHEX } = require('@mysten/bcs');
const { printInfo } = require('../common/utils');
const { printInfo } = require('../../common/utils');
const { ethers } = require('hardhat');
const {
utils: { hexlify },
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sui/deploy-utils.js → sui/utils/upgrade-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { bcs } = require('@mysten/bcs');
const { fromB64 } = require('@mysten/bcs');
const { printInfo, validateParameters } = require('../common/utils');
const { printInfo, validateParameters } = require('../../common/utils');
const { getObjectIdsByObjectTypes, suiPackageAddress } = require('./utils');
const UPGRADE_POLICIES = {
code_upgrade: 'only_additive_upgrades',
Expand Down
9 changes: 6 additions & 3 deletions sui/utils.js → sui/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { ethers } = require('hardhat');
const toml = require('toml');
const { printInfo, printError } = require('../common/utils');
const { printInfo, printError } = require('../../common/utils');
const {
BigNumber,
utils: { arrayify, hexlify, toUtf8Bytes, keccak256 },
Expand Down Expand Up @@ -53,7 +53,7 @@ const getBcsBytesByObjectId = async (client, objectId) => {
};

const deployPackage = async (packageName, client, keypair, options = {}) => {
const compileDir = `${__dirname}/move`;
const compileDir = `${__dirname}/../move`;

copyMovePackage(packageName, null, compileDir);

Expand All @@ -74,7 +74,10 @@ const findPublishedObject = (published, packageDir, contractName) => {

const readMovePackageName = (moveDir) => {
try {
const moveToml = fs.readFileSync(`${__dirname}/../node_modules/@axelar-network/axelar-cgp-sui/move/${moveDir}/Move.toml`, 'utf8');
const moveToml = fs.readFileSync(
`${__dirname}/../../node_modules/@axelar-network/axelar-cgp-sui/move/${moveDir}/Move.toml`,
'utf8',
);

const { package: movePackage } = toml.parse(moveToml);

Expand Down

0 comments on commit ca64dd9

Please sign in to comment.