Skip to content

Commit

Permalink
Add token address support to oracle commands. (#8010)
Browse files Browse the repository at this point in the history
* Add token address support to oracle commands.

* Update documentation.
  • Loading branch information
pedro-clabs authored and tkporter committed Jul 8, 2021
1 parent d153b15 commit 7e270c2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 45 deletions.
10 changes: 1 addition & 9 deletions packages/cli/src/commands/oracle/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CeloContract } from '@celo/contractkit'
import { stableTokenContractArray } from '@celo/contractkit/lib/base'
import { BaseCommand } from '../../base'
import { failWith } from '../../utils/cli'

Expand All @@ -15,7 +14,6 @@ export default class List extends BaseCommand {
name: 'token',
required: true,
description: 'Token to list the oracles for',
options: stableTokenContractArray,
default: CeloContract.StableToken,
},
]
Expand All @@ -26,13 +24,7 @@ export default class List extends BaseCommand {
const res = this.parse(List)
const sortedOracles = await this.kit.contracts.getSortedOracles()

try {
await this.kit.registry.addressFor(res.args.token)
} catch {
failWith(`The ${res.args.token} contract was not deployed yet`)
}

const oracles = await sortedOracles.getOracles(res.args.token)
const oracles = await sortedOracles.getOracles(res.args.token).catch((e) => failWith(e))
console.log(oracles)
}
}
13 changes: 2 additions & 11 deletions packages/cli/src/commands/oracle/remove-expired-reports.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { CeloContract } from '@celo/contractkit'
import { stableTokenContractArray } from '@celo/contractkit/lib/base'
import { BaseCommand } from '../../base'
import { displaySendTx, failWith } from '../../utils/cli'
import { Flags } from '../../utils/command'

export default class RemoveExpiredReports extends BaseCommand {
static description =
'Remove expired oracle reports for a specified token (currently just Celo Dollar, aka "StableToken")'
static description = 'Remove expired oracle reports for a specified token'

static args = [
{
name: 'token',
required: true,
default: CeloContract.StableToken,
description: 'Token to remove expired reports for',
options: stableTokenContractArray,
},
]
static flags = {
Expand All @@ -34,13 +31,7 @@ export default class RemoveExpiredReports extends BaseCommand {
async run() {
const res = this.parse(RemoveExpiredReports)

try {
await this.kit.registry.addressFor(res.args.token)
} catch {
failWith(`The ${res.args.token} contract was not deployed yet`)
}

const sortedOracles = await this.kit.contracts.getSortedOracles()
const sortedOracles = await this.kit.contracts.getSortedOracles().catch((e) => failWith(e))
const txo = await sortedOracles.removeExpiredReports(res.args.token)
await displaySendTx('removeExpiredReports', txo)
}
Expand Down
13 changes: 2 additions & 11 deletions packages/cli/src/commands/oracle/report.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { CeloContract } from '@celo/contractkit'
import { stableTokenContractArray } from '@celo/contractkit/lib/base'
import { flags } from '@oclif/command'
import BigNumber from 'bignumber.js'
import { BaseCommand } from '../../base'
import { displaySendTx, failWith } from '../../utils/cli'
import { Flags } from '../../utils/command'

export default class ReportPrice extends BaseCommand {
static description =
'Report the price of CELO in a specified token (currently just Celo Dollar, aka "StableToken")'
static description = 'Report the price of CELO in a specified token'

static args = [
{
name: 'token',
required: true,
default: CeloContract.StableToken,
description: 'Token to report on',
options: stableTokenContractArray,
},
]
static flags = {
Expand All @@ -39,15 +36,9 @@ export default class ReportPrice extends BaseCommand {
const sortedOracles = await this.kit.contracts.getSortedOracles()
const value = new BigNumber(res.flags.value)

try {
await this.kit.registry.addressFor(res.args.token)
} catch {
failWith(`The ${res.args.token} contract was not deployed yet`)
}

await displaySendTx(
'sortedOracles.report',
await sortedOracles.report(res.args.token, value, res.flags.from)
await sortedOracles.report(res.args.token, value, res.flags.from).catch((e) => failWith(e))
)
this.log(`Reported oracle value: ${value.toString()} ${res.args.token} == 1 CELO`)
}
Expand Down
10 changes: 1 addition & 9 deletions packages/cli/src/commands/oracle/reports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CeloContract } from '@celo/contractkit'
import { stableTokenContractArray } from '@celo/contractkit/lib/base'
import { cli } from 'cli-ux'
import { BaseCommand } from '../../base'
import { failWith } from '../../utils/cli'
Expand All @@ -17,7 +16,6 @@ export default class Reports extends BaseCommand {
name: 'token',
required: true,
description: 'Token to list the reports for',
options: stableTokenContractArray,
default: CeloContract.StableToken,
},
]
Expand All @@ -28,13 +26,7 @@ export default class Reports extends BaseCommand {
const res = this.parse(Reports)
const sortedOracles = await this.kit.contracts.getSortedOracles()

try {
await this.kit.registry.addressFor(res.args.token)
} catch {
failWith(`The ${res.args.token} contract was not deployed yet`)
}

const reports = await sortedOracles.getReports(res.args.token)
const reports = await sortedOracles.getReports(res.args.token).catch((e) => failWith(e))
cli.table(
reports,
{
Expand Down
8 changes: 4 additions & 4 deletions packages/docs/command-line-interface/oracle.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sdk/contractkit/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export enum CeloContract {
}

export type StableTokenContract = CeloContract.StableToken | CeloContract.StableTokenEUR
export const stableTokenContractArray = [CeloContract.StableToken, CeloContract.StableTokenEUR]

export type ExchangeContract = CeloContract.Exchange | CeloContract.ExchangeEUR

Expand Down

0 comments on commit 7e270c2

Please sign in to comment.