diff --git a/packages/cli/package.json b/packages/cli/package.json index 87476dab5..514c6c7af 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -132,7 +132,7 @@ "description": "Participate in and view the state of Validator Elections" }, "exchange": { - "description": "Exchange Celo Dollars and CELO via the stability mechanism" + "description": "Exchange Celo Dollars and CELO via Mento" }, "governance": { "description": "Interact with on-chain governance proposals and hotfixes" diff --git a/packages/cli/src/commands/exchange/celo.ts b/packages/cli/src/commands/exchange/celo.ts index 6943aa457..75850a9ef 100644 --- a/packages/cli/src/commands/exchange/celo.ts +++ b/packages/cli/src/commands/exchange/celo.ts @@ -1,6 +1,6 @@ import { StableToken } from '@celo/contractkit' import { stableTokenInfos } from '@celo/contractkit/lib/celo-tokens' -import { Flags } from '@oclif/core' +import { Flags, ux } from '@oclif/core' import BigNumber from 'bignumber.js' import { BaseCommand } from '../../base' import { newCheckBuilder } from '../../utils/checks' @@ -9,14 +9,13 @@ import { CustomFlags } from '../../utils/command' import { checkNotDangerousExchange } from '../../utils/exchange' import { enumEntriesDupWithLowercase } from '../../utils/helpers' import { getMentoBroker } from '../../utils/mento-broker-adaptor' -import { consoleLogger } from '@celo/base' const depeggedPricePercentage = 20 const stableTokenOptions = enumEntriesDupWithLowercase(Object.entries(StableToken)) export default class ExchangeCelo extends BaseCommand { static description = - 'Exchange CELO for StableTokens via the stability mechanism. (Note: this is the equivalent of the old exchange:gold)' + 'Exchange CELO for StableTokens via Mento. (Note: this is the equivalent of the old exchange:gold)' static flags = { ...BaseCommand.flags, @@ -64,12 +63,13 @@ export default class ExchangeCelo extends BaseCommand { return expectedAmountOut } - consoleLogger(`Fetching Quote`) + ux.action.start(`Fetching Quote`) const expectedAmountToReceive = await getQuote( celoToken.address, stableTokenAddress, sellAmount.toFixed() ) + ux.action.stop() if (minBuyAmount.toNumber() === 0) { const check = await checkNotDangerousExchange( kit, @@ -79,8 +79,8 @@ export default class ExchangeCelo extends BaseCommand { stableTokenInfos[stableToken] ) if (!check) { - console.log('Cancelled') - return + ux.info('Cancelled') + ux.exit(0) } } else if (expectedAmountToReceive.lt(minBuyAmount.toString())) { const check = await binaryPrompt( @@ -88,8 +88,8 @@ export default class ExchangeCelo extends BaseCommand { false ) if (!check) { - consoleLogger('Cancelled') - return + ux.info('Cancelled') + ux.exit(0) } } @@ -98,7 +98,7 @@ export default class ExchangeCelo extends BaseCommand { celoToken.increaseAllowance(brokerAddress, sellAmount.toFixed()) ) - consoleLogger('Swapping', sellAmount.toFixed(), 'for at least', expectedAmountToReceive) + ux.log('Swapping', sellAmount.toFixed(), 'for at least', expectedAmountToReceive.toString()) const tx = await mento.swapIn( celoToken.address, stableTokenAddress, diff --git a/packages/cli/src/commands/exchange/dollars.ts b/packages/cli/src/commands/exchange/dollars.ts index 0b31d6343..c8d43f440 100644 --- a/packages/cli/src/commands/exchange/dollars.ts +++ b/packages/cli/src/commands/exchange/dollars.ts @@ -2,7 +2,7 @@ import { StableToken } from '@celo/contractkit' import ExchangeStableBase from '../../exchange-stable-base' import { CustomFlags } from '../../utils/command' export default class ExchangeDollars extends ExchangeStableBase { - static description = 'Exchange Celo Dollars for CELO via the stability mechanism' + static description = 'Exchange Celo Dollars for CELO via Mento' static flags = { ...ExchangeStableBase.flags, diff --git a/packages/cli/src/commands/exchange/euros.ts b/packages/cli/src/commands/exchange/euros.ts index 48c122fc9..5c89e247d 100644 --- a/packages/cli/src/commands/exchange/euros.ts +++ b/packages/cli/src/commands/exchange/euros.ts @@ -2,7 +2,7 @@ import { StableToken } from '@celo/contractkit' import ExchangeStableBase from '../../exchange-stable-base' import { CustomFlags } from '../../utils/command' export default class ExchangeEuros extends ExchangeStableBase { - static description = 'Exchange Celo Euros for CELO via the stability mechanism' + static description = 'Exchange Celo Euros for CELO via Mento' static flags = { ...ExchangeStableBase.flags, diff --git a/packages/cli/src/commands/exchange/gold.ts b/packages/cli/src/commands/exchange/gold.ts index 8dc2923bd..a512c785a 100644 --- a/packages/cli/src/commands/exchange/gold.ts +++ b/packages/cli/src/commands/exchange/gold.ts @@ -2,7 +2,7 @@ import ExchangeCelo from './celo' export default class ExchangeGold extends ExchangeCelo { static description = - 'Exchange CELO for StableTokens via the stability mechanism. *DEPRECATION WARNING* Use the "exchange:celo" command instead' + 'Exchange CELO for StableTokens via Mento. *DEPRECATION WARNING* Use the "exchange:celo" command instead' static flags = { ...ExchangeCelo.flags, diff --git a/packages/cli/src/commands/exchange/reals.ts b/packages/cli/src/commands/exchange/reals.ts index 2474cd30a..ae815064f 100644 --- a/packages/cli/src/commands/exchange/reals.ts +++ b/packages/cli/src/commands/exchange/reals.ts @@ -2,7 +2,7 @@ import { StableToken } from '@celo/contractkit' import ExchangeStableBase from '../../exchange-stable-base' import { CustomFlags } from '../../utils/command' export default class ExchangeEuros extends ExchangeStableBase { - static description = 'Exchange Celo Brazilian Real (cREAL) for CELO via the stability mechanism' + static description = 'Exchange Celo Brazilian Real (cREAL) for CELO via Mento' static flags = { ...ExchangeStableBase.flags, diff --git a/packages/cli/src/commands/exchange/show.ts b/packages/cli/src/commands/exchange/show.ts index c983815a9..01d447e42 100644 --- a/packages/cli/src/commands/exchange/show.ts +++ b/packages/cli/src/commands/exchange/show.ts @@ -1,7 +1,7 @@ -import { StableTokenInfo } from '@celo/contractkit/lib/celo-tokens' import { Flags, ux } from '@oclif/core' import { BaseCommand } from '../../base' +import { getExchangeRates } from '../../utils/mento-broker-adaptor' export default class ExchangeShow extends BaseCommand { static description = 'Show the current exchange rates offered by the Exchange' @@ -23,21 +23,16 @@ export default class ExchangeShow extends BaseCommand { const { flags: parsedFlags } = await this.parse(ExchangeShow) ux.action.start('Fetching exchange rates...') - const exchangeAmounts = await kit.celoTokens.forStableCeloToken( - async (info: StableTokenInfo) => { - const exchange = await kit.contracts.getContract(info.exchangeContract) - return { - buy: await exchange.getBuyTokenAmount(parsedFlags.amount as string, true), - sell: await exchange.getBuyTokenAmount(parsedFlags.amount as string, false), - } - } - ) + const exchangeAmounts = await getExchangeRates(kit.connection, parsedFlags.amount as string) ux.action.stop() - Object.entries(exchangeAmounts).forEach((element) => { - this.log(`CELO/${element[0]}:`) - this.log(`${parsedFlags.amount} CELO => ${element[1]!.buy} ${element[0]}`) - this.log(`${parsedFlags.amount} ${element[0]} => ${element[1]!.sell} CELO`) - }) + exchangeAmounts + .filter((element) => element !== undefined) + .forEach((element) => { + this.log(`CELO/${element?.symbol}:`) + this.log(`${parsedFlags.amount} CELO => ${element?.buy} ${element?.symbol}`) + this.log(`${parsedFlags.amount} ${element?.symbol} => ${element?.sell} CELO`) + }) + ux.exit(0) } } diff --git a/packages/cli/src/commands/exchange/stable.ts b/packages/cli/src/commands/exchange/stable.ts index 12f44034e..d2f631e2d 100644 --- a/packages/cli/src/commands/exchange/stable.ts +++ b/packages/cli/src/commands/exchange/stable.ts @@ -5,7 +5,7 @@ import { enumEntriesDupWithLowercase } from '../../utils/helpers' const stableTokenOptions = enumEntriesDupWithLowercase(Object.entries(StableToken)) export default class ExchangeStable extends ExchangeStableBase { - static description = 'Exchange Stable Token for CELO via the stability mechanism' + static description = 'Exchange Stable Token for CELO via Mento' static flags = { ...ExchangeStableBase.flags,