Skip to content

Commit

Permalink
update description for exchange commands to be via mento instead of s…
Browse files Browse the repository at this point in the history
…tability mechanism
  • Loading branch information
aaronmgdr committed Feb 5, 2024
1 parent f46ddd1 commit 47c87ae
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/src/commands/exchange/celo.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -79,17 +79,17 @@ 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(
'Warning: the expected amount to receive is less than the minimum amount to receive. Are you sure you want to continue?',
false
)
if (!check) {
consoleLogger('Cancelled')
return
ux.info('Cancelled')
ux.exit(0)
}
}

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/exchange/dollars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/exchange/euros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/exchange/gold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/exchange/reals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 10 additions & 15 deletions packages/cli/src/commands/exchange/show.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/exchange/stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 47c87ae

Please sign in to comment.