Skip to content

Commit

Permalink
chore(cli): adds TODOs re fee currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgousset committed Feb 26, 2024
1 parent fea1ddd commit 0769487
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
13 changes: 12 additions & 1 deletion packages/cli/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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()) {
Expand All @@ -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
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/transfer/celo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/transfer-stable-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
11 changes: 10 additions & 1 deletion packages/cli/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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')
}
Expand Down

0 comments on commit 0769487

Please sign in to comment.