From 87223ba93ab79f43ae6884282d30a420eb09c23c Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Tue, 1 Oct 2024 15:05:08 +0200 Subject: [PATCH] Remove support for reserve commands. (#339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description Penultimate step of sunsetting the reserve commands. https://forum.celo.org/t/sunset-of-reserve-commands/8454 ### Other changes n/a ### Tested n/a ### Related issues - Fixes https://github.com/celo-org/celo-blockchain-planning/issues/439 ### Backwards compatibility nope ### Documentation docs for commands removed --- ## PR-Codex overview This PR removes the support for `reserve:*` commands in the CLI as part of the deprecation process outlined in a forum discussion. ### Detailed summary - Deleted the following files: - `packages/cli/src/commands/reserve/status.ts` - `packages/cli/src/commands/reserve/transfergold.ts` - `packages/cli/src/commands/reserve/transfergold.test.ts` - Updated the `changeset/gold-pumas-fry.md` to reflect the major version change for `@celo/celocli` and document the removal of `reserve:*` commands. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .changeset/gold-pumas-fry.md | 5 + packages/cli/src/commands/reserve/status.ts | 28 ----- .../src/commands/reserve/transfergold.test.ts | 107 ------------------ .../cli/src/commands/reserve/transfergold.ts | 62 ---------- 4 files changed, 5 insertions(+), 197 deletions(-) create mode 100644 .changeset/gold-pumas-fry.md delete mode 100644 packages/cli/src/commands/reserve/status.ts delete mode 100644 packages/cli/src/commands/reserve/transfergold.test.ts delete mode 100644 packages/cli/src/commands/reserve/transfergold.ts diff --git a/.changeset/gold-pumas-fry.md b/.changeset/gold-pumas-fry.md new file mode 100644 index 000000000..c06ee3719 --- /dev/null +++ b/.changeset/gold-pumas-fry.md @@ -0,0 +1,5 @@ +--- +'@celo/celocli': major +--- + +Remove support for reserve:\* commands. As foretold by https://forum.celo.org/t/sunset-of-reserve-commands/8454 diff --git a/packages/cli/src/commands/reserve/status.ts b/packages/cli/src/commands/reserve/status.ts deleted file mode 100644 index d29d9ecda..000000000 --- a/packages/cli/src/commands/reserve/status.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { BaseCommand } from '../../base' -import { printValueMapRecursive } from '../../utils/cli' - -/** - * @deprecated https://forum.celo.org/t/sunset-of-reserve-commands/8454 - */ -export default class ReserveStatus extends BaseCommand { - static description = 'Shows information about reserve' - - static flags = { - ...BaseCommand.flags, - } - - static examples = ['status'] - - async run() { - const kit = await this.getKit() - const reserve = await kit.contracts.getReserve() - const data = { - 'Reserve address': reserve.address, - Spenders: await reserve.getSpenders(), - 'Other reserves': await reserve.getOtherReserveAddresses(), - Frozen: await reserve.frozenReserveGoldStartBalance(), - 'Gold balance': await reserve.getReserveGoldBalance(), - } - printValueMapRecursive(data) - } -} diff --git a/packages/cli/src/commands/reserve/transfergold.test.ts b/packages/cli/src/commands/reserve/transfergold.test.ts deleted file mode 100644 index 5e3c256ba..000000000 --- a/packages/cli/src/commands/reserve/transfergold.test.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { newReserve } from '@celo/abis/web3/mento/Reserve' -import { newMultiSig } from '@celo/abis/web3/MultiSig' -import { StrongAddress } from '@celo/base' -import { CeloContract, newKitFromWeb3 } from '@celo/contractkit' -import { GoldTokenWrapper } from '@celo/contractkit/lib/wrappers/GoldTokenWrapper' -import { - asCoreContractsOwner, - DEFAULT_OWNER_ADDRESS, - setBalance, - testWithAnvilL1, - withImpersonatedAccount, -} from '@celo/dev-utils/lib/anvil-test' -import BigNumber from 'bignumber.js' -import Web3 from 'web3' -import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils' -import TransferGold from './transfergold' - -process.env.NO_SYNCCHECK = 'true' - -testWithAnvilL1('reserve:transfergold cmd', (web3: Web3) => { - const transferAmt = new BigNumber(100000) - const kit = newKitFromWeb3(web3) - - let accounts: StrongAddress[] = [] - let otherReserveAddress: StrongAddress - let otherSpender: StrongAddress - let goldToken: GoldTokenWrapper - - beforeEach(async () => { - accounts = (await web3.eth.getAccounts()) as StrongAddress[] - goldToken = await kit.contracts.getGoldToken() - - otherReserveAddress = accounts[9] - otherSpender = accounts[7] - const multiSigAddress = await kit.registry.addressFor('ReserveSpenderMultiSig' as CeloContract) - const reserveSpenderMultiSig = await kit.contracts.getMultiSig(multiSigAddress) - const reserve = await kit.contracts.getReserve() - - const reserveContract = newReserve(web3, reserve.address) - const reserveSpenderMultiSigContract = newMultiSig(web3, reserveSpenderMultiSig.address) - - await withImpersonatedAccount( - web3, - multiSigAddress, - async () => { - await reserveSpenderMultiSig - .replaceOwner(DEFAULT_OWNER_ADDRESS, accounts[0]) - .sendAndWaitForReceipt({ from: multiSigAddress }) - await reserveSpenderMultiSigContract.methods - .addOwner(otherSpender) - .send({ from: multiSigAddress }) - await reserveSpenderMultiSigContract.methods - .changeRequirement(2) - .send({ from: multiSigAddress }) - }, - new BigNumber(web3.utils.toWei('1', 'ether')) - ) - - await asCoreContractsOwner(web3, async (ownerAdress: StrongAddress) => { - await reserveContract.methods.addSpender(multiSigAddress).send({ from: ownerAdress }) - await reserveContract.methods - .addOtherReserveAddress(otherReserveAddress) - .send({ from: ownerAdress }) - }) - - await setBalance(web3, reserve.address, new BigNumber(web3.utils.toWei('1', 'ether'))) - }) - test('transferGold fails if spender not passed in', async () => { - await expect( - testLocallyWithWeb3Node( - TransferGold, - ['--from', accounts[0], '--value', transferAmt.toString(10), '--to', otherReserveAddress], - web3 - ) - ).rejects.toThrow("Some checks didn't pass!") - }) - test('can transferGold with multisig option', async () => { - const initialBalance = await goldToken.balanceOf(otherReserveAddress) - await testLocallyWithWeb3Node( - TransferGold, - [ - '--from', - accounts[0], - '--value', - transferAmt.toString(10), - '--to', - otherReserveAddress, - '--useMultiSig', - ], - web3 - ) - await testLocallyWithWeb3Node( - TransferGold, - [ - '--from', - otherSpender, - '--value', - transferAmt.toString(10), - '--to', - otherReserveAddress, - '--useMultiSig', - ], - web3 - ) - expect(await goldToken.balanceOf(accounts[9])).toEqual(initialBalance.plus(transferAmt)) - }) -}) diff --git a/packages/cli/src/commands/reserve/transfergold.ts b/packages/cli/src/commands/reserve/transfergold.ts deleted file mode 100644 index e5b0a8552..000000000 --- a/packages/cli/src/commands/reserve/transfergold.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Flags } from '@oclif/core' -import { BaseCommand } from '../../base' -import { newCheckBuilder } from '../../utils/checks' -import { displaySendTx } from '../../utils/cli' -import { CustomFlags } from '../../utils/command' - -/** - @deprecated https://forum.celo.org/t/sunset-of-reserve-commands/8454 -*/ -export default class TransferGold extends BaseCommand { - static description = 'Transfers reserve celo to other reserve address' - - static flags = { - ...BaseCommand.flags, - value: Flags.string({ required: true, description: 'The unit amount of CELO' }), - to: CustomFlags.address({ required: true, description: 'Receiving address' }), - from: CustomFlags.address({ required: true, description: "Spender's address" }), - useMultiSig: Flags.boolean({ - description: 'True means the request will be sent through multisig.', - }), - } - - static examples = [ - 'transfergold --value 9000 --to 0x91c987bf62D25945dB517BDAa840A6c661374402 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631', - 'transfergold --value 9000 --to 0x91c987bf62D25945dB517BDAa840A6c661374402 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631 --useMultiSig', - ] - - async run() { - const kit = await this.getKit() - const res = await this.parse(TransferGold) - const value = res.flags.value - const to = res.flags.to - const account = res.flags.from - const useMultiSig = res.flags.useMultiSig - kit.defaultAccount = account - const reserve = await kit.contracts.getReserve() - const spenders = useMultiSig ? await reserve.getSpenders() : [] - // assumes that the multisig is the most recent spender in the spenders array - const multiSigAddress = spenders.length > 0 ? spenders[spenders.length - 1] : '' - const reserveSpenderMultiSig = useMultiSig - ? await kit.contracts.getMultiSig(multiSigAddress) - : undefined - const spender = useMultiSig ? multiSigAddress : account - - await newCheckBuilder(this) - .addCheck(`${spender} is a reserve spender`, async () => reserve.isSpender(spender)) - .addConditionalCheck(`${account} is a multisig signatory`, useMultiSig, async () => - reserveSpenderMultiSig !== undefined - ? reserveSpenderMultiSig.isOwner(account) - : new Promise(() => false) - ) - .addCheck(`${to} is another reserve address`, async () => reserve.isOtherReserveAddress(to)) - .runChecks() - - const reserveTx = await reserve.transferGold(to, value) - const tx = - reserveSpenderMultiSig === undefined - ? reserveTx - : await reserveSpenderMultiSig.submitOrConfirmTransaction(reserve.address, reserveTx.txo) - await displaySendTx('transferGoldTx', tx) - } -}