From 076948710c1be43694838016040aee4db14cdff9 Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:40:32 -0300 Subject: [PATCH] chore(cli): adds TODOs re fee currencies --- packages/cli/src/base.ts | 13 ++++++++++++- packages/cli/src/commands/config/set.ts | 1 + packages/cli/src/commands/transfer/celo.test.ts | 4 ++-- packages/cli/src/transfer-stable-base.ts | 1 + packages/cli/src/utils/config.ts | 11 ++++++++++- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/base.ts b/packages/cli/src/base.ts index 5ed48a166..5d4324076 100644 --- a/packages/cli/src/base.ts +++ b/packages/cli/src/base.ts @@ -11,6 +11,12 @@ import net from 'net' import Web3 from 'web3' import { getGasCurrency, getNodeUrl } from './utils/config' import { enumEntriesDupWithLowercase, requireNodeIsSynced } from './utils/helpers' +/** + * TODO(Arthur): Probably need to change the `gasOption` defintion because we support arbitrary + * addresses, and not just strings in a list. + * + * Possibly change this check to make a feeCurrencyWhitelist contract call and assert inclusion. + */ export const gasOptions = { auto: 'auto', Auto: 'auto', @@ -46,6 +52,9 @@ export abstract class BaseCommand extends Command { } }, }), + /** + * TODO(Arthur): What does "defaults to 'auto' which uses whatever feeCurrency is available" mean? + */ gasCurrency: Flags.option({ options: Object.keys(gasOptions), description: @@ -201,6 +210,7 @@ export abstract class BaseCommand extends Command { kit.defaultAccount = res.flags.from } + // TODO(Arthur): Update this const gasCurrencyConfig = res.flags.gasCurrency ? (gasOptions as any)[res.flags.gasCurrency] : getGasCurrency(this.config.configDir) @@ -211,6 +221,7 @@ export abstract class BaseCommand extends Command { } if (Object.keys(StableToken).includes(gasCurrencyConfig)) { await setStableTokenGas(StableToken[gasCurrencyConfig as keyof typeof StableToken]) + // TODO(Arthur): Check if `gasOptions.auto` continues to make sense } else if (gasCurrencyConfig === gasOptions.auto && kit.defaultAccount) { const balances = await kit.getTotalBalance(kit.defaultAccount) if (balances.CELO!.isZero()) { @@ -220,7 +231,7 @@ export abstract class BaseCommand extends Command { const stableToken = stable[1] // has balance if ((balances as any)[stableName] && !(balances as any)[stableName].isZero()) { - await setStableTokenGas(stableToken) + await setStableTokenGas(stableToken) // TODO(Arthur): Update this break } } diff --git a/packages/cli/src/commands/config/set.ts b/packages/cli/src/commands/config/set.ts index 25217be10..ea07270a6 100644 --- a/packages/cli/src/commands/config/set.ts +++ b/packages/cli/src/commands/config/set.ts @@ -28,6 +28,7 @@ export default class Set extends BaseCommand { const res = await this.parse(Set) const curr = readConfig(this.config.configDir) const node = res.flags.node ?? curr.node + // TODO(Arthur): Update `gasCurrency` logic here const gasCurrency = res.flags.gasCurrency ? (gasOptions as any)[res.flags.gasCurrency as string] : curr.gasCurrency diff --git a/packages/cli/src/commands/transfer/celo.test.ts b/packages/cli/src/commands/transfer/celo.test.ts index 9731c79f4..5282cce60 100644 --- a/packages/cli/src/commands/transfer/celo.test.ts +++ b/packages/cli/src/commands/transfer/celo.test.ts @@ -32,7 +32,7 @@ testWithGanache('transfer:celo cmd', (web3: Web3) => { '--value', amountToTransfer, '--gasCurrency', - 'cusd', + 'cusd', // TODO(Arthur): Update this test to accept fee currency addresses ]) // RG cUSD balance should match the amount sent const receiverBalance = await kit.getTotalBalance(accounts[1]) @@ -48,7 +48,7 @@ testWithGanache('transfer:celo cmd', (web3: Web3) => { '--value', amountToTransfer, '--gasCurrency', - 'cusd', + 'cusd', // TODO(Arthur): Update this test to accept fee currency addresses ]) const balanceAfter = await kit.getTotalBalance(accounts[0]) expect(balanceBefore.CELO).toEqual(balanceAfter.CELO) diff --git a/packages/cli/src/transfer-stable-base.ts b/packages/cli/src/transfer-stable-base.ts index 7f1d7c126..ae42cad77 100644 --- a/packages/cli/src/transfer-stable-base.ts +++ b/packages/cli/src/transfer-stable-base.ts @@ -17,6 +17,7 @@ export abstract class TransferStableBase extends BaseCommand { comment: Flags.string({ description: 'Transfer comment' }), } + // TODO(Arthur): Reminder to check what to do here protected _stableCurrency: StableToken | null = null async run() { diff --git a/packages/cli/src/utils/config.ts b/packages/cli/src/utils/config.ts index da284cf73..098d8822e 100644 --- a/packages/cli/src/utils/config.ts +++ b/packages/cli/src/utils/config.ts @@ -4,7 +4,7 @@ import { gasOptions } from '../base' export interface CeloConfig { node: string - gasCurrency: string + gasCurrency: string // TODO(Arthur): Nit - Consider typing with hex addresses instead of arbitrary strings } export const defaultConfig: CeloConfig = { @@ -35,11 +35,20 @@ export function getNodeUrl(configDir: string): string { return readConfig(configDir).node } +// TODO(Arthur): Nit - Consider typing with hex addresses instead of arbitrary strings export function getGasCurrency(configDir: string): string { return readConfig(configDir).gasCurrency } export function writeConfig(configDir: string, configObj: CeloConfig) { + /** + * TODO(Arthur): Probably need to either + * 1. remove this check, because we support arbitrary addresses, and not just strings in a list, or + * 2. change this check to make a feeCurrencyWhitelist contract call and assert inclusion. + * If we use this option, we probably want to make the contract call where `gasOptions` if defined + * and pass it here. + */ + // if (!Object.keys(gasOptions).includes(configObj.gasCurrency)) { throw new Error('Invalid gas option') }