Skip to content

Commit

Permalink
chore: use loadConfig instead of loadSuiConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Aug 1, 2024
1 parent 6b3d1c4 commit 4964688
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 35 deletions.
14 changes: 13 additions & 1 deletion common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ const {
const { normalizeBech32 } = require('@cosmjs/encoding');

function loadConfig(env) {
return require(`${__dirname}/../axelar-chains-config/info/${env}.json`);
const config = require(`${__dirname}/../axelar-chains-config/info/${env}.json`);

if (!config.sui) {
config.sui = {
networkType: env === 'local' ? 'localnet' : env,
name: 'Sui',
contracts: {
AxelarGateway: {},
},
};
}

return config;
}

function saveConfig(config, env) {
Expand Down
5 changes: 2 additions & 3 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ const { Transaction } = require('@mysten/sui/transactions');
const {
utils: { arrayify },
} = ethers;
const { saveConfig, printInfo, validateParameters, writeJSON, getDomainSeparator } = require('../common');
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 {
loadSuiConfig,
getSigners,
deployPackage,
getObjectIdsByObjectTypes,
Expand Down Expand Up @@ -249,7 +248,7 @@ async function upgrade(keypair, client, supportedPackage, policy, config, chain,
}

async function mainProcessor(args, options, processor) {
const config = loadSuiConfig(options.env);
const config = loadConfig(options.env);
const [keypair, client] = getWallet(config.sui, options);
await printWalletInfo(keypair, client, config.sui, options);
await processor(keypair, client, ...args, config, config.sui, options);
Expand Down
4 changes: 2 additions & 2 deletions sui/deploy-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { saveConfig, prompt, printInfo } = require('../common/utils');
const { Command } = require('commander');
const { loadSuiConfig, deployPackage, getBcsBytesByObjectId } = require('./utils');
const { deployPackage, getBcsBytesByObjectId } = require('./utils');
const { singletonStruct } = require('./types-utils');
const { Transaction } = require('@mysten/sui/transactions');
const { addBaseOptions } = require('./cli-utils');
Expand Down Expand Up @@ -54,7 +54,7 @@ async function processCommand(config, chain, options) {
}

async function mainProcessor(options, processor) {
const config = loadSuiConfig(options.env);
const config = loadConfig(options.env);

Check failure on line 57 in sui/deploy-test.js

View workflow job for this annotation

GitHub Actions / lint

'loadConfig' is not defined

await processor(config, config.sui, options);
saveConfig(config, options.env);
Expand Down
5 changes: 3 additions & 2 deletions sui/gas-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ 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 { loadSuiConfig, getBcsBytesByObjectId } = require('./utils');
const { getBcsBytesByObjectId } = require('./utils');
const { ethers } = require('hardhat');
const { getFormattedAmount } = require('./amount-utils');
const {
Expand Down Expand Up @@ -160,7 +161,7 @@ async function processCommand(command, chain, args, options) {
}

async function mainProcessor(options, args, processor, command) {
const config = loadSuiConfig(options.env);
const config = loadConfig(options.env);
await processor(command, config.sui, args, options);
saveConfig(config, options.env);
}
Expand Down
4 changes: 2 additions & 2 deletions sui/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ 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 { loadSuiConfig } = require('./utils');
const { getSigners } = require('./deploy-gateway');
const secp256k1 = require('secp256k1');

Expand Down Expand Up @@ -218,7 +218,7 @@ async function rotateSigners(keypair, client, config, chain, args, options) {
}

async function mainProcessor(processor, args, options) {
const config = loadSuiConfig(options.env);
const config = loadConfig(options.env);

const [keypair, client] = getWallet(config.sui, options);
await printWalletInfo(keypair, client, config.sui, options);
Expand Down
5 changes: 3 additions & 2 deletions sui/gmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const { saveConfig, printInfo } = require('../common/utils');
const { Command } = require('commander');
const { Transaction } = require('@mysten/sui/transactions');
const { bcs } = require('@mysten/sui/bcs');
const { loadSuiConfig, getBcsBytesByObjectId } = require('./utils');
const { getBcsBytesByObjectId } = require('./utils');
const { loadConfig } = require('../common/utils');
const { ethers } = require('hardhat');
const {
utils: { arrayify },
Expand Down Expand Up @@ -165,7 +166,7 @@ async function processCommand(command, chain, args, options) {
}

async function mainProcessor(command, options, args, processor) {
const config = loadSuiConfig(options.env);
const config = loadConfig(options.env);
await processor(command, config.sui, args, options);
saveConfig(config, options.env);
}
Expand Down
4 changes: 2 additions & 2 deletions sui/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { fromB64 } = require('@mysten/bcs');
const { addBaseOptions } = require('./cli-utils');
const { getWallet, getMultisig, signTransactionBlockBytes, broadcastSignature } = require('./sign-utils');
const { getSignedTx, storeSignedTx } = require('../evm/sign-utils');
const { loadSuiConfig } = require('./utils');
const { loadConfig } = require('../common/utils');
const { printInfo, validateParameters } = require('../common/utils');

async function signTx(keypair, client, options) {
Expand Down Expand Up @@ -143,7 +143,7 @@ async function processCommand(chain, options) {
}

async function mainProcessor(options, processor) {
const config = loadSuiConfig(options.env);
const config = loadConfig(options.env);
await processor(config.sui, options);
}

Expand Down
4 changes: 2 additions & 2 deletions sui/transfer-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Command, Option } = require('commander');
const { printInfo, validateParameters } = require('../common/utils');
const { addExtendedOptions } = require('./cli-utils');
const { getWallet, printWalletInfo } = require('./sign-utils');
const { loadSuiConfig } = require('./utils');
const { loadConfig } = require('../common/utils');

async function processCommand(chain, options) {
const [keypair, client] = getWallet(chain, options);
Expand Down Expand Up @@ -54,7 +54,7 @@ async function processCommand(chain, options) {
}

async function mainProcessor(options, processor) {
const config = loadSuiConfig(options.env);
const config = loadConfig(options.env);
await processor(config.sui, options);
}

Expand Down
20 changes: 1 addition & 19 deletions sui/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, loadConfig, printError } = require('../common/utils');
const { printInfo, printError } = require('../common/utils');
const {
BigNumber,
utils: { arrayify, hexlify, toUtf8Bytes, keccak256 },
Expand Down Expand Up @@ -52,23 +52,6 @@ const getBcsBytesByObjectId = async (client, objectId) => {
return fromB64(response.data.bcs.bcsBytes);
};

const loadSuiConfig = (env) => {
const config = loadConfig(env);
const suiEnv = env === 'local' ? 'localnet' : env;

if (!config.sui) {
config.sui = {
networkType: suiEnv,
name: 'Sui',
contracts: {
AxelarGateway: {},
},
};
}

return config;
};

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

Expand Down Expand Up @@ -155,7 +138,6 @@ module.exports = {
suiClockAddress,
getAmplifierSigners,
getBcsBytesByObjectId,
loadSuiConfig,
deployPackage,
findPublishedObject,
readMovePackageName,
Expand Down

0 comments on commit 4964688

Please sign in to comment.