From 4f58598b16381b1c9c5f18dfccc1afda27a517bc Mon Sep 17 00:00:00 2001 From: luizstacio Date: Sun, 29 Sep 2024 23:59:17 -0300 Subject: [PATCH 01/10] fix: add @fuels/kms-account to release latest --- .github/workflows/release-npm-latest.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release-npm-latest.yaml b/.github/workflows/release-npm-latest.yaml index 1c0ea1c..64f3c90 100644 --- a/.github/workflows/release-npm-latest.yaml +++ b/.github/workflows/release-npm-latest.yaml @@ -35,6 +35,7 @@ jobs: npm dist-tag add @fuels/changeset@${{ env.BUILD_VERSION }} latest npm dist-tag add @fuels/eslint-plugin@${{ env.BUILD_VERSION }} latest npm dist-tag add @fuels/jest@${{ env.BUILD_VERSION }} latest + npm dist-tag add @fuels/kms-account@${{ env.BUILD_VERSION }} latest npm dist-tag add @fuels/local-storage@${{ env.BUILD_VERSION }} latest npm dist-tag add @fuels/prettier-config@${{ env.BUILD_VERSION }} latest npm dist-tag add @fuels/react-xstore@${{ env.BUILD_VERSION }} latest From 9f121015675b3d738af048061ab4299067f1712e Mon Sep 17 00:00:00 2001 From: luizstacio Date: Sun, 6 Oct 2024 02:14:38 -0300 Subject: [PATCH 02/10] wip: add proxy-cli --- .github/workflows/release-npm-latest.yaml | 2 + packages/proxy-actions/package.json | 30 +++++++ .../proxy-actions/src/actions/getBalance.ts | 12 +++ .../proxy-actions/src/actions/getOwnership.ts | 39 +++++++++ .../src/actions/setimplementation.ts | 40 ++++++++++ .../src/actions/transferOwnership.ts | 63 +++++++++++++++ .../proxy-actions/src/actions/transferSelf.ts | 12 +++ packages/proxy-actions/src/index.ts | 80 +++++++++++++++++++ .../proxy-actions/src/utils/createAccount.ts | 16 ++++ packages/proxy-actions/src/utils/index.ts | 3 + packages/proxy-actions/src/utils/log.ts | 6 ++ .../proxy-actions/src/utils/requireEnv.ts | 10 +++ packages/proxy-actions/tsconfig.json | 11 +++ packages/proxy-actions/tsup.config.ts | 11 +++ pnpm-lock.yaml | 76 ++++++++++++++++++ 15 files changed, 411 insertions(+) create mode 100644 packages/proxy-actions/package.json create mode 100644 packages/proxy-actions/src/actions/getBalance.ts create mode 100644 packages/proxy-actions/src/actions/getOwnership.ts create mode 100644 packages/proxy-actions/src/actions/setimplementation.ts create mode 100644 packages/proxy-actions/src/actions/transferOwnership.ts create mode 100644 packages/proxy-actions/src/actions/transferSelf.ts create mode 100644 packages/proxy-actions/src/index.ts create mode 100644 packages/proxy-actions/src/utils/createAccount.ts create mode 100644 packages/proxy-actions/src/utils/index.ts create mode 100644 packages/proxy-actions/src/utils/log.ts create mode 100644 packages/proxy-actions/src/utils/requireEnv.ts create mode 100644 packages/proxy-actions/tsconfig.json create mode 100644 packages/proxy-actions/tsup.config.ts diff --git a/.github/workflows/release-npm-latest.yaml b/.github/workflows/release-npm-latest.yaml index 64f3c90..d911cfe 100644 --- a/.github/workflows/release-npm-latest.yaml +++ b/.github/workflows/release-npm-latest.yaml @@ -41,3 +41,5 @@ jobs: npm dist-tag add @fuels/react-xstore@${{ env.BUILD_VERSION }} latest npm dist-tag add @fuels/ts-config@${{ env.BUILD_VERSION }} latest npm dist-tag add @fuels/tsup-config@${{ env.BUILD_VERSION }} latest + npm dist-tag add @fuels/proxy-cli@${{ env.BUILD_VERSION }} latest + diff --git a/packages/proxy-actions/package.json b/packages/proxy-actions/package.json new file mode 100644 index 0000000..511a158 --- /dev/null +++ b/packages/proxy-actions/package.json @@ -0,0 +1,30 @@ +{ + "name": "@fuels/proxy-cli", + "version": "0.24.0", + "description": "A cli tool to execute action on a proxy contract", + "license": "APACHE-2.0", + "bin": { + "fuels-proxy": "./dist/index.js" + }, + "files": [ + "./dist" + ], + "scripts": { + "build": "tsup", + "dev": "ts-node ./src/index.ts", + "scripts": "node ./dist/index.js" + }, + "peerDependencies": { + "fuels": "0.94.4" + }, + "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^5.1.6" + }, + "dependencies": { + "@fuel-bridge/fungible-token": "^0.6.0", + "@fuels/kms-account": "0.24.1", + "@types/node": "^18.11.9", + "commander": "^12.1.0" + } +} diff --git a/packages/proxy-actions/src/actions/getBalance.ts b/packages/proxy-actions/src/actions/getBalance.ts new file mode 100644 index 0000000..238c09f --- /dev/null +++ b/packages/proxy-actions/src/actions/getBalance.ts @@ -0,0 +1,12 @@ +import type { Account } from "fuels"; + +type GetBalanceParams = { + account: Account; +} + +export async function getBalance({ account }: GetBalanceParams) { + const balance = await account.getBalance(); + console.log(`${account.address}: ${balance.format({ + precision: 9, + })}`); +} diff --git a/packages/proxy-actions/src/actions/getOwnership.ts b/packages/proxy-actions/src/actions/getOwnership.ts new file mode 100644 index 0000000..acbcc1c --- /dev/null +++ b/packages/proxy-actions/src/actions/getOwnership.ts @@ -0,0 +1,39 @@ +/** + * This is a stand-alone script that upgrades the bridge + */ +import { Proxy } from '@fuel-bridge/fungible-token'; +import type { Account} from 'fuels'; + +import { debug } from '../utils'; + +type GetOwnershipParams = { + account: Account; + proxyAddress: string; +} + +export const getOwnership = async ({ account, proxyAddress }: GetOwnershipParams) => { + const proxy = new Proxy(proxyAddress, account); + + console.log(`Proxy(${proxyAddress}) get ownership script initiated`); + console.log('\t> Balance: ', (await account.getBalance()).format({ + precision: 9 + })); + + debug('Detecting if the bridge is a proxy...'); + const owner: string | null = await proxy.functions + ._proxy_owner() + .get() + .then((result) => { + debug('Proxy._proxy.owner() succeeded, assuming proxy'); + return result.value.Initialized.Address.bits; + }) + .catch((e) => { + console.error(e); + debug(`Proxy._proxy_owner() failed with error: `); + debug(`${JSON.stringify(e, undefined, 2)}`); + return null; + }); + + console.log('\t> Owner: ', owner); +}; + diff --git a/packages/proxy-actions/src/actions/setimplementation.ts b/packages/proxy-actions/src/actions/setimplementation.ts new file mode 100644 index 0000000..6fbb6a2 --- /dev/null +++ b/packages/proxy-actions/src/actions/setimplementation.ts @@ -0,0 +1,40 @@ +import { Proxy } from "@fuel-bridge/fungible-token"; +import { Address, type Account } from "fuels"; + +type SetImplementationParams = { + account: Account; + proxyAddress: string; + implementationAddress: string; +}; + +export async function setImplementation({ account, proxyAddress, implementationAddress }: SetImplementationParams) { + const proxy = new Proxy(proxyAddress, account); + + console.log(`Proxy(${proxyAddress}) set implementation script initiated`); + console.log('\t> Owner address: ', account.address.toB256()); + console.log('\t> Balance: ', (await account.getBalance()).format({ + precision: 9 + })); + + const { id: contract_id } = await account.provider.getContract(implementationAddress); + if (!contract_id) { + console.log(`\t> Implementation ${implementationAddress} not found`); + return; + } + + const { value: currentTarget } = await proxy.functions.proxy_target().get(); + if (currentTarget.bits === implementationAddress) { + console.log(`\t> Implementation ${implementationAddress} is already live in the proxy`); + return; + } + + console.log('\t> New implementation at ', implementationAddress); + const contractId = Address.fromB256(implementationAddress); + const contractIdentityInput = { bits: contractId.toB256() }; + const tx = await proxy.functions + .set_proxy_target(contractIdentityInput) + .call(); + + console.log('\t> Transaction ID: ', tx.transactionId); + await tx.waitForResult(); +} \ No newline at end of file diff --git a/packages/proxy-actions/src/actions/transferOwnership.ts b/packages/proxy-actions/src/actions/transferOwnership.ts new file mode 100644 index 0000000..08d8380 --- /dev/null +++ b/packages/proxy-actions/src/actions/transferOwnership.ts @@ -0,0 +1,63 @@ +/** + * This is a stand-alone script that upgrades the bridge + */ +import { Proxy } from '@fuel-bridge/fungible-token'; +import type { Account} from 'fuels'; +import { Address } from 'fuels'; + +import { debug } from '../utils'; + +type TransferOwnershipParams = { + account: Account; + newOwner: string; + proxyAddress: string; +} + +export const transferOwnership = async ({ account, newOwner, proxyAddress }: TransferOwnershipParams) => { + const proxy = new Proxy(proxyAddress, account); + + console.log(`Proxy(${proxyAddress}) transfer ownership script initiated`); + console.log('\t> Owner address: ', account.address.toB256()); + console.log('\t> Balance: ', (await account.getBalance()).format({ + precision: 9 + })); + + debug('Detecting if contract is a proxy...'); + const owner: string | null = await proxy.functions + ._proxy_owner() + .get() + .then((result) => { + debug('Proxy._proxy.owner() succeeded, assuming proxy'); + return result.value.Initialized.Address.bits; + }) + .catch((e) => { + debug(`Proxy._proxy_owner() failed with error: `); + debug(`${JSON.stringify(e, undefined, 2)}`); + return null; + }); + + if (owner === null) { + console.log('Could not fetch the proxy owner, is it a proxy?'); + return; + } + + if ( + owner.replace('0x', '').toLowerCase() !== + account.address.toB256().replace('0x', '').toLowerCase() + ) { + console.log(`\t> Owner mismatch, contract owned by ${owner}`); + return; + } + + // New owner should be a valid b256 address + const address = Address.fromB256(newOwner); + const addressInput = { bits: address.toB256() }; + const addressIdentityInput = { Address: addressInput }; + const tx = await proxy.functions + ._proxy_change_owner(addressIdentityInput) + .call(); + + console.log('\t> Transaction ID: ', tx.transactionId); + await tx.waitForResult(); +}; + diff --git a/packages/proxy-actions/src/actions/transferSelf.ts b/packages/proxy-actions/src/actions/transferSelf.ts new file mode 100644 index 0000000..76c1706 --- /dev/null +++ b/packages/proxy-actions/src/actions/transferSelf.ts @@ -0,0 +1,12 @@ +import { bn, type Account } from "fuels"; + +type GetBalanceParams = { + account: Account; +} + +export async function transferSelf({ account }: GetBalanceParams) { + console.log(`\t> Account initiate a transfer of 0.0000001 to itself`); + const transfer = await account.transfer(account.address, bn.parseUnits('0.0000001')); + await transfer.waitForResult(); + console.log(`\t> Transfer transaction ID: ${transfer.id}`); +} diff --git a/packages/proxy-actions/src/index.ts b/packages/proxy-actions/src/index.ts new file mode 100644 index 0000000..59d5950 --- /dev/null +++ b/packages/proxy-actions/src/index.ts @@ -0,0 +1,80 @@ +import { Option, program } from 'commander'; + +import { getBalance } from './actions/getBalance'; +import { getOwnership } from './actions/getOwnership'; +import { setImplementation } from './actions/setimplementation'; +import { transferOwnership } from './actions/transferOwnership'; +import { transferSelf } from './actions/transferSelf'; +import { createAccount } from './utils'; + +const optionProvider = new Option('--providerUrl ', 'Provider URL is required!').env('PROVIDER_URL').makeOptionMandatory(); +const optionAccountKey = new Option('-a, --account ', 'Account address is required!').env('ACCOUNT_KEY').makeOptionMandatory(); + +program + .name('Proxy scripts') + .description('Scripts for interacting with the proxy contract'); + +program + .command('balance') + .addOption(optionProvider) + .addOption(optionAccountKey) + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await getBalance({ account }); + }); + +program + .command('setImplementation') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') + .requiredOption('--implementationAddress ', 'Implementation address is required!') + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await setImplementation({ + account, + proxyAddress: options.proxyAddress, + implementationAddress: options.implementationAddress + }); + }); + +program + .command('getOwnership') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await getOwnership({ + account, + proxyAddress: options.proxyAddress, + }); + }); + +program + .command('transferOwnership') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') + .requiredOption('--newOwner ', 'New owner address is required!') + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await transferOwnership({ + account, + proxyAddress: options.proxyAddress, + newOwner: options.newOwner + }); + }); + +program + .command('transferSelf') + .addOption(optionProvider) + .addOption(optionAccountKey) + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await transferSelf({ account }); + }); + +program + .parse() + .showSuggestionAfterError(); diff --git a/packages/proxy-actions/src/utils/createAccount.ts b/packages/proxy-actions/src/utils/createAccount.ts new file mode 100644 index 0000000..d09f9d7 --- /dev/null +++ b/packages/proxy-actions/src/utils/createAccount.ts @@ -0,0 +1,16 @@ +import { KMSAccount } from "@fuels/kms-account"; +import { Provider, Wallet } from "fuels"; + +export async function createAccount(key: string, providerUrl: string) { + if (!key || !providerUrl) { + throw new Error('Account key and provider URL are required!'); + } + const provider = await Provider.create(providerUrl); + const isKMS = key.startsWith('arn:'); + + if (isKMS) { + return KMSAccount.create(key, {}, provider); + } + + return Wallet.fromPrivateKey(key, provider); +} \ No newline at end of file diff --git a/packages/proxy-actions/src/utils/index.ts b/packages/proxy-actions/src/utils/index.ts new file mode 100644 index 0000000..a68ff5c --- /dev/null +++ b/packages/proxy-actions/src/utils/index.ts @@ -0,0 +1,3 @@ +export * from './createAccount'; +export * from './log'; +export * from './requireEnv'; diff --git a/packages/proxy-actions/src/utils/log.ts b/packages/proxy-actions/src/utils/log.ts new file mode 100644 index 0000000..f3c7ae7 --- /dev/null +++ b/packages/proxy-actions/src/utils/log.ts @@ -0,0 +1,6 @@ + +export function debug(...args: any) { + if (process.env.DEBUG) { + console.log(...args); + } + } \ No newline at end of file diff --git a/packages/proxy-actions/src/utils/requireEnv.ts b/packages/proxy-actions/src/utils/requireEnv.ts new file mode 100644 index 0000000..19d394f --- /dev/null +++ b/packages/proxy-actions/src/utils/requireEnv.ts @@ -0,0 +1,10 @@ +export function requireEnv(keys: T[]): { [K in T]: string } { + const env = keys.reduce((ret, key) => { + if (!process.env[key]) { + throw new Error(`Environment variable ${key} is required`); + } + ret[key] = process.env[key]!; + return ret; + }, {} as { [K in T]: string }); + return env; +} diff --git a/packages/proxy-actions/tsconfig.json b/packages/proxy-actions/tsconfig.json new file mode 100644 index 0000000..566a8fd --- /dev/null +++ b/packages/proxy-actions/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES2021", + "module": "commonjs", + "esModuleInterop": true, + "outDir": "dist", + "resolveJsonModule": true, + "lib": ["ES2021"] + }, + "include": ["./src/**/*.ts"] +} diff --git a/packages/proxy-actions/tsup.config.ts b/packages/proxy-actions/tsup.config.ts new file mode 100644 index 0000000..26b6962 --- /dev/null +++ b/packages/proxy-actions/tsup.config.ts @@ -0,0 +1,11 @@ +export default { + sourcemap: true, // Useful for debugging CLI + shims: true, // Helps with Node.js environments + dts: false, // Typically not needed for CLI binaries + format: ['cjs', 'esm'], // Provide CommonJS and ESM support for wider compatibility + minify: true, // Usually, you want to minify the CLI for performance + entry: ['./src/index.ts'], // Entry point remains the same unless specified otherwise + target: 'node14', // Target a specific Node.js version for CLI + outDir: 'dist', // Specify output directory for clarity + clean: true, // Clean the output directory before building +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c14b77..011e1d3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -284,6 +284,31 @@ importers: specifier: ^3.0.3 version: 3.0.3 + packages/proxy-actions: + dependencies: + '@fuel-bridge/fungible-token': + specifier: ^0.6.0 + version: 0.6.0 + '@fuels/kms-account': + specifier: 0.24.1 + version: 0.24.1(fuels@0.94.8) + '@types/node': + specifier: ^18.11.9 + version: 18.19.54 + commander: + specifier: ^12.1.0 + version: 12.1.0 + fuels: + specifier: 0.94.4 + version: 0.94.8 + devDependencies: + ts-node: + specifier: ^10.9.1 + version: 10.9.1(@swc/core@1.3.82)(@types/node@18.19.54)(typescript@5.4.2) + typescript: + specifier: ^5.1.6 + version: 5.4.2 + packages/react-xstore: dependencies: '@fuels/local-storage': @@ -1337,6 +1362,9 @@ packages: resolution: {integrity: sha512-ZSjtmelB7IJfWD2Fvb7+Z+ChTIKWq6kjda95fLcQKNS5aheVHn4IkfgRQE3sIIzTcSLwLcLZUD9UBt+V7+h+Pw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + '@fuel-bridge/fungible-token@0.6.0': + resolution: {integrity: sha512-ScOWLPXrM4KBJHdj/BpOmfSpiQlSLd+6NICSgxT4/FzgZMmLMXu9OwhfrF3l+OgM2CA2W+R4SAliisMTspB06Q==} + '@fuel-ts/abi-coder@0.94.8': resolution: {integrity: sha512-tyqDHfGyHyEOrH+CjgoMLuoBHBmHJgcsqdR6jGWw4gvvctvo8j0GIk2H9HBc4t9mK5+IGCCnURSvUvAdh5S8bQ==} engines: {node: ^18.20.3 || ^20.0.0 || ^22.0.0} @@ -1403,6 +1431,11 @@ packages: engines: {node: ^18.20.3 || ^20.0.0 || ^22.0.0} hasBin: true + '@fuels/kms-account@0.24.1': + resolution: {integrity: sha512-lcm4CrZfg3KJ7TpDH2oZye7QrWPCnvf5YwN0VbBU3o6UkeuJndJYZgUC01G8PntzV4CiTl1ys62pEHFb7XTOUg==} + peerDependencies: + fuels: '>=0.94.8' + '@fuels/vm-asm@0.57.1': resolution: {integrity: sha512-+TSJSfamSaHrG4j274NEDW0ndZXLEXfNq5TvgjA4HN4JTnGudm41pFM7+Xgrfi0AxkpxJCaZLBTycGj6SZNmBw==} @@ -2073,6 +2106,9 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} + '@types/node@18.19.54': + resolution: {integrity: sha512-+BRgt0G5gYjTvdLac9sIeE0iZcJxi4Jc4PV5EUzqi+88jmQLr+fRZdv2tCTV7IHKSGxM6SaLoOXQWWUiLUItMw==} + '@types/node@20.5.9': resolution: {integrity: sha512-PcGNd//40kHAS3sTlzKB9C9XL4K0sTup8nbG5lC14kzEteTNuAFh9u5nA0o5TWnSG2r/JNPRXFVcHJIIeRlmqQ==} @@ -5224,6 +5260,9 @@ packages: unbox-primitive@1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} + undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + universalify@0.1.2: resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} engines: {node: '>= 4.0.0'} @@ -6642,6 +6681,8 @@ snapshots: '@eslint/js@8.48.0': {} + '@fuel-bridge/fungible-token@0.6.0': {} + '@fuel-ts/abi-coder@0.94.8': dependencies: '@fuel-ts/crypto': 0.94.8 @@ -6800,6 +6841,15 @@ snapshots: chalk: 4.1.2 cli-table: 0.3.11 + '@fuels/kms-account@0.24.1(fuels@0.94.8)': + dependencies: + '@aws-sdk/client-kms': 3.658.1 + '@noble/curves': 1.6.0 + asn1js: 3.0.5 + fuels: 0.94.8 + transitivePeerDependencies: + - aws-crt + '@fuels/vm-asm@0.57.1': {} '@graphql-typed-document-node/core@3.2.0(graphql@16.9.0)': @@ -7690,6 +7740,10 @@ snapshots: '@types/node@12.20.55': {} + '@types/node@18.19.54': + dependencies: + undici-types: 5.26.5 + '@types/node@20.5.9': {} '@types/normalize-package-data@2.4.1': {} @@ -11363,6 +11417,26 @@ snapshots: ts-interface-checker@0.1.13: {} + ts-node@10.9.1(@swc/core@1.3.82)(@types/node@18.19.54)(typescript@5.4.2): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.9 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 18.19.54 + acorn: 8.9.0 + acorn-walk: 8.2.0 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.4.2 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + optionalDependencies: + '@swc/core': 1.3.82 + ts-node@10.9.1(@swc/core@1.3.82)(@types/node@20.5.9)(typescript@5.4.2): dependencies: '@cspotcode/source-map-support': 0.8.1 @@ -11535,6 +11609,8 @@ snapshots: has-symbols: 1.0.3 which-boxed-primitive: 1.0.2 + undici-types@5.26.5: {} + universalify@0.1.2: {} universalify@0.2.0: {} From ddebf43ad2d5e9672960e90864aa9f36336788b2 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Sun, 6 Oct 2024 05:48:50 -0300 Subject: [PATCH 03/10] feat: make getImplementation --- .../proxy-actions/src/actions/getBalance.ts | 2 +- .../src/actions/getImplementation.ts | 21 +++++++++++++++++++ packages/proxy-actions/src/index.ts | 16 +++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 packages/proxy-actions/src/actions/getImplementation.ts diff --git a/packages/proxy-actions/src/actions/getBalance.ts b/packages/proxy-actions/src/actions/getBalance.ts index 238c09f..80a97cb 100644 --- a/packages/proxy-actions/src/actions/getBalance.ts +++ b/packages/proxy-actions/src/actions/getBalance.ts @@ -6,7 +6,7 @@ type GetBalanceParams = { export async function getBalance({ account }: GetBalanceParams) { const balance = await account.getBalance(); - console.log(`${account.address}: ${balance.format({ + console.log(`${account.address.toB256()}: ${balance.format({ precision: 9, })}`); } diff --git a/packages/proxy-actions/src/actions/getImplementation.ts b/packages/proxy-actions/src/actions/getImplementation.ts new file mode 100644 index 0000000..e4848c4 --- /dev/null +++ b/packages/proxy-actions/src/actions/getImplementation.ts @@ -0,0 +1,21 @@ +import { Proxy } from "@fuel-bridge/fungible-token"; +import { type Account } from "fuels"; + +type GetImplementationParams = { + account: Account; + proxyAddress: string; +}; + +export async function getImplementation({ account, proxyAddress }: GetImplementationParams) { + const proxy = new Proxy(proxyAddress, account); + + console.log(`Proxy(${proxyAddress}) get implementation script initiated`); + console.log('\t> Account address: ', account.address.toB256()); + console.log('\t> Balance: ', (await account.getBalance()).format({ + precision: 9 + })); + + const { value: currentTarget } = await proxy.functions.proxy_target().get(); + + console.log(`\t> Implementation: ${currentTarget.bits}`); +} \ No newline at end of file diff --git a/packages/proxy-actions/src/index.ts b/packages/proxy-actions/src/index.ts index 59d5950..a35494b 100644 --- a/packages/proxy-actions/src/index.ts +++ b/packages/proxy-actions/src/index.ts @@ -2,10 +2,11 @@ import { Option, program } from 'commander'; import { getBalance } from './actions/getBalance'; import { getOwnership } from './actions/getOwnership'; -import { setImplementation } from './actions/setimplementation'; +import { setImplementation } from './actions/setImplementation'; import { transferOwnership } from './actions/transferOwnership'; import { transferSelf } from './actions/transferSelf'; import { createAccount } from './utils'; +import { getImplementation } from './actions/getImplementation'; const optionProvider = new Option('--providerUrl ', 'Provider URL is required!').env('PROVIDER_URL').makeOptionMandatory(); const optionAccountKey = new Option('-a, --account ', 'Account address is required!').env('ACCOUNT_KEY').makeOptionMandatory(); @@ -38,6 +39,19 @@ program }); }); +program + .command('getImplementation') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await getImplementation({ + account, + proxyAddress: options.proxyAddress, + }); + }); + program .command('getOwnership') .addOption(optionProvider) From f81572ffe8bffe926a4537737f6c03a057dd67a0 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Sun, 6 Oct 2024 05:54:14 -0300 Subject: [PATCH 04/10] chore --- packages/proxy-actions/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proxy-actions/src/index.ts b/packages/proxy-actions/src/index.ts index a35494b..af35bca 100644 --- a/packages/proxy-actions/src/index.ts +++ b/packages/proxy-actions/src/index.ts @@ -1,12 +1,12 @@ import { Option, program } from 'commander'; import { getBalance } from './actions/getBalance'; +import { getImplementation } from './actions/getImplementation'; import { getOwnership } from './actions/getOwnership'; import { setImplementation } from './actions/setImplementation'; import { transferOwnership } from './actions/transferOwnership'; import { transferSelf } from './actions/transferSelf'; import { createAccount } from './utils'; -import { getImplementation } from './actions/getImplementation'; const optionProvider = new Option('--providerUrl ', 'Provider URL is required!').env('PROVIDER_URL').makeOptionMandatory(); const optionAccountKey = new Option('-a, --account ', 'Account address is required!').env('ACCOUNT_KEY').makeOptionMandatory(); From bf5ddf1cb0b0bf5e39a5bd58b15392d6806b4b9c Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Sun, 6 Oct 2024 05:54:51 -0300 Subject: [PATCH 05/10] chore --- .changeset/fluffy-taxis-leave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fluffy-taxis-leave.md diff --git a/.changeset/fluffy-taxis-leave.md b/.changeset/fluffy-taxis-leave.md new file mode 100644 index 0000000..34d125d --- /dev/null +++ b/.changeset/fluffy-taxis-leave.md @@ -0,0 +1,5 @@ +--- +'@fuels/proxy-cli': minor +--- + +Create CLI to interact with proxy contrat From 3a8ec4d759e6bb12513088e91b3fe2cb94ca67dc Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Sun, 6 Oct 2024 06:14:42 -0300 Subject: [PATCH 06/10] chore --- packages/proxy-actions/src/utils/log.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proxy-actions/src/utils/log.ts b/packages/proxy-actions/src/utils/log.ts index f3c7ae7..c52c7b2 100644 --- a/packages/proxy-actions/src/utils/log.ts +++ b/packages/proxy-actions/src/utils/log.ts @@ -1,4 +1,4 @@ - +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function debug(...args: any) { if (process.env.DEBUG) { console.log(...args); From 59d2395c5dbc2cb0af69f99526975bdbc82142f8 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Sun, 6 Oct 2024 06:22:25 -0300 Subject: [PATCH 07/10] chore: test lint --- packages/proxy-actions/src/index.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/proxy-actions/src/index.ts b/packages/proxy-actions/src/index.ts index af35bca..7bf031f 100644 --- a/packages/proxy-actions/src/index.ts +++ b/packages/proxy-actions/src/index.ts @@ -1,7 +1,7 @@ import { Option, program } from 'commander'; import { getBalance } from './actions/getBalance'; -import { getImplementation } from './actions/getImplementation'; +// import { getImplementation } from './actions/getImplementation'; import { getOwnership } from './actions/getOwnership'; import { setImplementation } from './actions/setImplementation'; import { transferOwnership } from './actions/transferOwnership'; @@ -39,18 +39,18 @@ program }); }); -program - .command('getImplementation') - .addOption(optionProvider) - .addOption(optionAccountKey) - .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') - .action(async (options) => { - const account = await createAccount(options.account, options.providerUrl); - await getImplementation({ - account, - proxyAddress: options.proxyAddress, - }); - }); +// program +// .command('getImplementation') +// .addOption(optionProvider) +// .addOption(optionAccountKey) +// .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') +// .action(async (options) => { +// const account = await createAccount(options.account, options.providerUrl); +// await getImplementation({ +// account, +// proxyAddress: options.proxyAddress, +// }); +// }); program .command('getOwnership') From 382862e38e52b13fe8d05e1c981197cd9b11b6b6 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Sun, 6 Oct 2024 06:23:59 -0300 Subject: [PATCH 08/10] chore --- packages/proxy-actions/src/index.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/proxy-actions/src/index.ts b/packages/proxy-actions/src/index.ts index 7bf031f..af35bca 100644 --- a/packages/proxy-actions/src/index.ts +++ b/packages/proxy-actions/src/index.ts @@ -1,7 +1,7 @@ import { Option, program } from 'commander'; import { getBalance } from './actions/getBalance'; -// import { getImplementation } from './actions/getImplementation'; +import { getImplementation } from './actions/getImplementation'; import { getOwnership } from './actions/getOwnership'; import { setImplementation } from './actions/setImplementation'; import { transferOwnership } from './actions/transferOwnership'; @@ -39,18 +39,18 @@ program }); }); -// program -// .command('getImplementation') -// .addOption(optionProvider) -// .addOption(optionAccountKey) -// .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') -// .action(async (options) => { -// const account = await createAccount(options.account, options.providerUrl); -// await getImplementation({ -// account, -// proxyAddress: options.proxyAddress, -// }); -// }); +program + .command('getImplementation') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await getImplementation({ + account, + proxyAddress: options.proxyAddress, + }); + }); program .command('getOwnership') From 9f4af1570e4f75b7216531d11dc94ccddd15c6ee Mon Sep 17 00:00:00 2001 From: Luiz Gomes <8636507+LuizAsFight@users.noreply.github.com> Date: Sun, 6 Oct 2024 06:26:21 -0300 Subject: [PATCH 09/10] Rename setimplementation.ts to setImplementation.ts --- .../src/actions/{setimplementation.ts => setImplementation.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/proxy-actions/src/actions/{setimplementation.ts => setImplementation.ts} (99%) diff --git a/packages/proxy-actions/src/actions/setimplementation.ts b/packages/proxy-actions/src/actions/setImplementation.ts similarity index 99% rename from packages/proxy-actions/src/actions/setimplementation.ts rename to packages/proxy-actions/src/actions/setImplementation.ts index 6fbb6a2..df3d284 100644 --- a/packages/proxy-actions/src/actions/setimplementation.ts +++ b/packages/proxy-actions/src/actions/setImplementation.ts @@ -37,4 +37,4 @@ export async function setImplementation({ account, proxyAddress, implementationA console.log('\t> Transaction ID: ', tx.transactionId); await tx.waitForResult(); -} \ No newline at end of file +} From a84aa97048565775059d8b802cb1eca309ca6b45 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Sun, 6 Oct 2024 06:27:49 -0300 Subject: [PATCH 10/10] chore: prettier --- .../proxy-actions/src/actions/getBalance.ts | 16 +- .../src/actions/getImplementation.ts | 34 ++-- .../proxy-actions/src/actions/getOwnership.ts | 23 +-- .../src/actions/setImplementation.ts | 71 ++++---- .../src/actions/transferOwnership.ts | 26 +-- .../proxy-actions/src/actions/transferSelf.ts | 17 +- packages/proxy-actions/src/index.ts | 153 ++++++++++-------- .../proxy-actions/src/utils/createAccount.ts | 24 +-- packages/proxy-actions/src/utils/log.ts | 8 +- .../proxy-actions/src/utils/requireEnv.ts | 17 +- 10 files changed, 224 insertions(+), 165 deletions(-) diff --git a/packages/proxy-actions/src/actions/getBalance.ts b/packages/proxy-actions/src/actions/getBalance.ts index 80a97cb..bea1852 100644 --- a/packages/proxy-actions/src/actions/getBalance.ts +++ b/packages/proxy-actions/src/actions/getBalance.ts @@ -1,12 +1,14 @@ -import type { Account } from "fuels"; +import type { Account } from 'fuels'; type GetBalanceParams = { - account: Account; -} + account: Account; +}; export async function getBalance({ account }: GetBalanceParams) { - const balance = await account.getBalance(); - console.log(`${account.address.toB256()}: ${balance.format({ - precision: 9, - })}`); + const balance = await account.getBalance(); + console.log( + `${account.address.toB256()}: ${balance.format({ + precision: 9, + })}`, + ); } diff --git a/packages/proxy-actions/src/actions/getImplementation.ts b/packages/proxy-actions/src/actions/getImplementation.ts index e4848c4..c099668 100644 --- a/packages/proxy-actions/src/actions/getImplementation.ts +++ b/packages/proxy-actions/src/actions/getImplementation.ts @@ -1,21 +1,27 @@ -import { Proxy } from "@fuel-bridge/fungible-token"; -import { type Account } from "fuels"; +import { Proxy } from '@fuel-bridge/fungible-token'; +import { type Account } from 'fuels'; type GetImplementationParams = { - account: Account; - proxyAddress: string; + account: Account; + proxyAddress: string; }; -export async function getImplementation({ account, proxyAddress }: GetImplementationParams) { - const proxy = new Proxy(proxyAddress, account); +export async function getImplementation({ + account, + proxyAddress, +}: GetImplementationParams) { + const proxy = new Proxy(proxyAddress, account); - console.log(`Proxy(${proxyAddress}) get implementation script initiated`); - console.log('\t> Account address: ', account.address.toB256()); - console.log('\t> Balance: ', (await account.getBalance()).format({ - precision: 9 - })); + console.log(`Proxy(${proxyAddress}) get implementation script initiated`); + console.log('\t> Account address: ', account.address.toB256()); + console.log( + '\t> Balance: ', + (await account.getBalance()).format({ + precision: 9, + }), + ); - const { value: currentTarget } = await proxy.functions.proxy_target().get(); + const { value: currentTarget } = await proxy.functions.proxy_target().get(); - console.log(`\t> Implementation: ${currentTarget.bits}`); -} \ No newline at end of file + console.log(`\t> Implementation: ${currentTarget.bits}`); +} diff --git a/packages/proxy-actions/src/actions/getOwnership.ts b/packages/proxy-actions/src/actions/getOwnership.ts index acbcc1c..396fcad 100644 --- a/packages/proxy-actions/src/actions/getOwnership.ts +++ b/packages/proxy-actions/src/actions/getOwnership.ts @@ -2,22 +2,28 @@ * This is a stand-alone script that upgrades the bridge */ import { Proxy } from '@fuel-bridge/fungible-token'; -import type { Account} from 'fuels'; +import type { Account } from 'fuels'; import { debug } from '../utils'; type GetOwnershipParams = { - account: Account; - proxyAddress: string; -} + account: Account; + proxyAddress: string; +}; -export const getOwnership = async ({ account, proxyAddress }: GetOwnershipParams) => { +export const getOwnership = async ({ + account, + proxyAddress, +}: GetOwnershipParams) => { const proxy = new Proxy(proxyAddress, account); console.log(`Proxy(${proxyAddress}) get ownership script initiated`); - console.log('\t> Balance: ', (await account.getBalance()).format({ - precision: 9 - })); + console.log( + '\t> Balance: ', + (await account.getBalance()).format({ + precision: 9, + }), + ); debug('Detecting if the bridge is a proxy...'); const owner: string | null = await proxy.functions @@ -36,4 +42,3 @@ export const getOwnership = async ({ account, proxyAddress }: GetOwnershipParams console.log('\t> Owner: ', owner); }; - diff --git a/packages/proxy-actions/src/actions/setImplementation.ts b/packages/proxy-actions/src/actions/setImplementation.ts index df3d284..3ffb893 100644 --- a/packages/proxy-actions/src/actions/setImplementation.ts +++ b/packages/proxy-actions/src/actions/setImplementation.ts @@ -1,40 +1,51 @@ -import { Proxy } from "@fuel-bridge/fungible-token"; -import { Address, type Account } from "fuels"; +import { Proxy } from '@fuel-bridge/fungible-token'; +import { Address, type Account } from 'fuels'; type SetImplementationParams = { - account: Account; - proxyAddress: string; - implementationAddress: string; + account: Account; + proxyAddress: string; + implementationAddress: string; }; -export async function setImplementation({ account, proxyAddress, implementationAddress }: SetImplementationParams) { - const proxy = new Proxy(proxyAddress, account); +export async function setImplementation({ + account, + proxyAddress, + implementationAddress, +}: SetImplementationParams) { + const proxy = new Proxy(proxyAddress, account); - console.log(`Proxy(${proxyAddress}) set implementation script initiated`); - console.log('\t> Owner address: ', account.address.toB256()); - console.log('\t> Balance: ', (await account.getBalance()).format({ - precision: 9 - })); + console.log(`Proxy(${proxyAddress}) set implementation script initiated`); + console.log('\t> Owner address: ', account.address.toB256()); + console.log( + '\t> Balance: ', + (await account.getBalance()).format({ + precision: 9, + }), + ); - const { id: contract_id } = await account.provider.getContract(implementationAddress); - if (!contract_id) { - console.log(`\t> Implementation ${implementationAddress} not found`); - return; - } + const { id: contract_id } = await account.provider.getContract( + implementationAddress, + ); + if (!contract_id) { + console.log(`\t> Implementation ${implementationAddress} not found`); + return; + } - const { value: currentTarget } = await proxy.functions.proxy_target().get(); - if (currentTarget.bits === implementationAddress) { - console.log(`\t> Implementation ${implementationAddress} is already live in the proxy`); - return; - } + const { value: currentTarget } = await proxy.functions.proxy_target().get(); + if (currentTarget.bits === implementationAddress) { + console.log( + `\t> Implementation ${implementationAddress} is already live in the proxy`, + ); + return; + } - console.log('\t> New implementation at ', implementationAddress); - const contractId = Address.fromB256(implementationAddress); - const contractIdentityInput = { bits: contractId.toB256() }; - const tx = await proxy.functions - .set_proxy_target(contractIdentityInput) - .call(); + console.log('\t> New implementation at ', implementationAddress); + const contractId = Address.fromB256(implementationAddress); + const contractIdentityInput = { bits: contractId.toB256() }; + const tx = await proxy.functions + .set_proxy_target(contractIdentityInput) + .call(); - console.log('\t> Transaction ID: ', tx.transactionId); - await tx.waitForResult(); + console.log('\t> Transaction ID: ', tx.transactionId); + await tx.waitForResult(); } diff --git a/packages/proxy-actions/src/actions/transferOwnership.ts b/packages/proxy-actions/src/actions/transferOwnership.ts index 08d8380..ac3b742 100644 --- a/packages/proxy-actions/src/actions/transferOwnership.ts +++ b/packages/proxy-actions/src/actions/transferOwnership.ts @@ -2,25 +2,32 @@ * This is a stand-alone script that upgrades the bridge */ import { Proxy } from '@fuel-bridge/fungible-token'; -import type { Account} from 'fuels'; +import type { Account } from 'fuels'; import { Address } from 'fuels'; import { debug } from '../utils'; type TransferOwnershipParams = { - account: Account; - newOwner: string; - proxyAddress: string; -} + account: Account; + newOwner: string; + proxyAddress: string; +}; -export const transferOwnership = async ({ account, newOwner, proxyAddress }: TransferOwnershipParams) => { +export const transferOwnership = async ({ + account, + newOwner, + proxyAddress, +}: TransferOwnershipParams) => { const proxy = new Proxy(proxyAddress, account); console.log(`Proxy(${proxyAddress}) transfer ownership script initiated`); console.log('\t> Owner address: ', account.address.toB256()); - console.log('\t> Balance: ', (await account.getBalance()).format({ - precision: 9 - })); + console.log( + '\t> Balance: ', + (await account.getBalance()).format({ + precision: 9, + }), + ); debug('Detecting if contract is a proxy...'); const owner: string | null = await proxy.functions @@ -60,4 +67,3 @@ export const transferOwnership = async ({ account, newOwner, proxyAddress }: Tra console.log('\t> Transaction ID: ', tx.transactionId); await tx.waitForResult(); }; - diff --git a/packages/proxy-actions/src/actions/transferSelf.ts b/packages/proxy-actions/src/actions/transferSelf.ts index 76c1706..96e5f63 100644 --- a/packages/proxy-actions/src/actions/transferSelf.ts +++ b/packages/proxy-actions/src/actions/transferSelf.ts @@ -1,12 +1,15 @@ -import { bn, type Account } from "fuels"; +import { bn, type Account } from 'fuels'; type GetBalanceParams = { - account: Account; -} + account: Account; +}; export async function transferSelf({ account }: GetBalanceParams) { - console.log(`\t> Account initiate a transfer of 0.0000001 to itself`); - const transfer = await account.transfer(account.address, bn.parseUnits('0.0000001')); - await transfer.waitForResult(); - console.log(`\t> Transfer transaction ID: ${transfer.id}`); + console.log(`\t> Account initiate a transfer of 0.0000001 to itself`); + const transfer = await account.transfer( + account.address, + bn.parseUnits('0.0000001'), + ); + await transfer.waitForResult(); + console.log(`\t> Transfer transaction ID: ${transfer.id}`); } diff --git a/packages/proxy-actions/src/index.ts b/packages/proxy-actions/src/index.ts index af35bca..1614e4a 100644 --- a/packages/proxy-actions/src/index.ts +++ b/packages/proxy-actions/src/index.ts @@ -8,87 +8,110 @@ import { transferOwnership } from './actions/transferOwnership'; import { transferSelf } from './actions/transferSelf'; import { createAccount } from './utils'; -const optionProvider = new Option('--providerUrl ', 'Provider URL is required!').env('PROVIDER_URL').makeOptionMandatory(); -const optionAccountKey = new Option('-a, --account ', 'Account address is required!').env('ACCOUNT_KEY').makeOptionMandatory(); +const optionProvider = new Option( + '--providerUrl ', + 'Provider URL is required!', +) + .env('PROVIDER_URL') + .makeOptionMandatory(); +const optionAccountKey = new Option( + '-a, --account ', + 'Account address is required!', +) + .env('ACCOUNT_KEY') + .makeOptionMandatory(); program - .name('Proxy scripts') - .description('Scripts for interacting with the proxy contract'); + .name('Proxy scripts') + .description('Scripts for interacting with the proxy contract'); program - .command('balance') - .addOption(optionProvider) - .addOption(optionAccountKey) - .action(async (options) => { - const account = await createAccount(options.account, options.providerUrl); - await getBalance({ account }); - }); + .command('balance') + .addOption(optionProvider) + .addOption(optionAccountKey) + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await getBalance({ account }); + }); program - .command('setImplementation') - .addOption(optionProvider) - .addOption(optionAccountKey) - .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') - .requiredOption('--implementationAddress ', 'Implementation address is required!') - .action(async (options) => { - const account = await createAccount(options.account, options.providerUrl); - await setImplementation({ - account, - proxyAddress: options.proxyAddress, - implementationAddress: options.implementationAddress - }); + .command('setImplementation') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption( + '-p, --proxyAddress ', + 'Proxy address is required!', + ) + .requiredOption( + '--implementationAddress ', + 'Implementation address is required!', + ) + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await setImplementation({ + account, + proxyAddress: options.proxyAddress, + implementationAddress: options.implementationAddress, }); + }); program - .command('getImplementation') - .addOption(optionProvider) - .addOption(optionAccountKey) - .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') - .action(async (options) => { - const account = await createAccount(options.account, options.providerUrl); - await getImplementation({ - account, - proxyAddress: options.proxyAddress, - }); + .command('getImplementation') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption( + '-p, --proxyAddress ', + 'Proxy address is required!', + ) + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await getImplementation({ + account, + proxyAddress: options.proxyAddress, }); + }); program - .command('getOwnership') - .addOption(optionProvider) - .addOption(optionAccountKey) - .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') - .action(async (options) => { - const account = await createAccount(options.account, options.providerUrl); - await getOwnership({ - account, - proxyAddress: options.proxyAddress, - }); + .command('getOwnership') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption( + '-p, --proxyAddress ', + 'Proxy address is required!', + ) + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await getOwnership({ + account, + proxyAddress: options.proxyAddress, }); + }); program - .command('transferOwnership') - .addOption(optionProvider) - .addOption(optionAccountKey) - .requiredOption('-p, --proxyAddress ', 'Proxy address is required!') - .requiredOption('--newOwner ', 'New owner address is required!') - .action(async (options) => { - const account = await createAccount(options.account, options.providerUrl); - await transferOwnership({ - account, - proxyAddress: options.proxyAddress, - newOwner: options.newOwner - }); + .command('transferOwnership') + .addOption(optionProvider) + .addOption(optionAccountKey) + .requiredOption( + '-p, --proxyAddress ', + 'Proxy address is required!', + ) + .requiredOption('--newOwner ', 'New owner address is required!') + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await transferOwnership({ + account, + proxyAddress: options.proxyAddress, + newOwner: options.newOwner, }); + }); program - .command('transferSelf') - .addOption(optionProvider) - .addOption(optionAccountKey) - .action(async (options) => { - const account = await createAccount(options.account, options.providerUrl); - await transferSelf({ account }); - }); + .command('transferSelf') + .addOption(optionProvider) + .addOption(optionAccountKey) + .action(async (options) => { + const account = await createAccount(options.account, options.providerUrl); + await transferSelf({ account }); + }); -program - .parse() - .showSuggestionAfterError(); +program.parse().showSuggestionAfterError(); diff --git a/packages/proxy-actions/src/utils/createAccount.ts b/packages/proxy-actions/src/utils/createAccount.ts index d09f9d7..d1c0184 100644 --- a/packages/proxy-actions/src/utils/createAccount.ts +++ b/packages/proxy-actions/src/utils/createAccount.ts @@ -1,16 +1,16 @@ -import { KMSAccount } from "@fuels/kms-account"; -import { Provider, Wallet } from "fuels"; +import { KMSAccount } from '@fuels/kms-account'; +import { Provider, Wallet } from 'fuels'; export async function createAccount(key: string, providerUrl: string) { - if (!key || !providerUrl) { - throw new Error('Account key and provider URL are required!'); - } - const provider = await Provider.create(providerUrl); - const isKMS = key.startsWith('arn:'); + if (!key || !providerUrl) { + throw new Error('Account key and provider URL are required!'); + } + const provider = await Provider.create(providerUrl); + const isKMS = key.startsWith('arn:'); - if (isKMS) { - return KMSAccount.create(key, {}, provider); - } + if (isKMS) { + return KMSAccount.create(key, {}, provider); + } - return Wallet.fromPrivateKey(key, provider); -} \ No newline at end of file + return Wallet.fromPrivateKey(key, provider); +} diff --git a/packages/proxy-actions/src/utils/log.ts b/packages/proxy-actions/src/utils/log.ts index c52c7b2..83fdbb6 100644 --- a/packages/proxy-actions/src/utils/log.ts +++ b/packages/proxy-actions/src/utils/log.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function debug(...args: any) { - if (process.env.DEBUG) { - console.log(...args); - } - } \ No newline at end of file + if (process.env.DEBUG) { + console.log(...args); + } +} diff --git a/packages/proxy-actions/src/utils/requireEnv.ts b/packages/proxy-actions/src/utils/requireEnv.ts index 19d394f..e5dd9b9 100644 --- a/packages/proxy-actions/src/utils/requireEnv.ts +++ b/packages/proxy-actions/src/utils/requireEnv.ts @@ -1,10 +1,13 @@ export function requireEnv(keys: T[]): { [K in T]: string } { - const env = keys.reduce((ret, key) => { - if (!process.env[key]) { - throw new Error(`Environment variable ${key} is required`); - } - ret[key] = process.env[key]!; - return ret; - }, {} as { [K in T]: string }); + const env = keys.reduce( + (ret, key) => { + if (!process.env[key]) { + throw new Error(`Environment variable ${key} is required`); + } + ret[key] = process.env[key]!; + return ret; + }, + {} as { [K in T]: string }, + ); return env; }