Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[contractkit] SortedOraclesWrapper + tests #1405

Merged
merged 18 commits into from
Oct 23, 2019

Conversation

yerdua
Copy link
Contributor

@yerdua yerdua commented Oct 18, 2019

Description

This adds a wrapper for the SortedOracles contract. In some cases it derives arguments that the caller shouldn't have to figure out, but are required by the contract. It also includes helper functions for StableToken.

The work here was started in the still-WIP #1394 as some foundational pieces. For ease of reviewing, I've broken this out.

Tested

Tests are included in this PR.

Other changes

In order to make the tests run and to make it possible for CLabs to run a single oracle to report on the cUSD/cGLD exchange rate, I modified the StableToken migration to change how oracles are added before ownership is transferred to Governance. Rather than taking the address of the first miner, read the accounts from migrationsConfig and allow it to be overridden with migration overrides. For now, it's just an empty array except during contractkit tests. In #1394, a new account type will be added.

Related issues

@codecov
Copy link

codecov bot commented Oct 21, 2019

Codecov Report

Merging #1405 into master will increase coverage by 1.78%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1405      +/-   ##
==========================================
+ Coverage   65.87%   67.66%   +1.78%     
==========================================
  Files         271      269       -2     
  Lines        8061     8043      -18     
  Branches      490      558      +68     
==========================================
+ Hits         5310     5442     +132     
+ Misses       2639     2488     -151     
- Partials      112      113       +1
Flag Coverage Δ
#mobile 67.66% <ø> (+1.78%) ⬆️
Impacted Files Coverage Δ
packages/mobile/src/firebase/firebase.ts 20.28% <0%> (-21.94%) ⬇️
packages/mobile/src/firebase/notifications.ts 40.54% <0%> (-5.18%) ⬇️
packages/mobile/src/redux/store.ts 96% <0%> (-4%) ⬇️
.../src/paymentRequest/PaymentRequestConfirmation.tsx 70.68% <0%> (-3.32%) ⬇️
packages/mobile/src/home/WalletHome.tsx 89.15% <0%> (-0.85%) ⬇️
packages/mobile/src/firebase/actions.ts 100% <0%> (ø) ⬆️
packages/mobile/src/redux/reducers.ts 100% <0%> (ø) ⬆️
packages/mobile/src/identity/reducer.ts 41.66% <0%> (ø) ⬆️
packages/mobile/src/sentry/saga.ts
packages/mobile/src/sentry/actions.ts
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73c1d69...ff148d0. Read the comment docs.

@mcortesi mcortesi assigned yerdua and unassigned mcortesi Oct 21, 2019
@yerdua yerdua assigned mcortesi and unassigned yerdua Oct 21, 2019
@yerdua yerdua requested a review from mcortesi October 21, 2019 16:08
Comment on lines +88 to +89
numerator: number,
denominator: number,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcortesi numerator and denominator aren't very intuitive, as you pointed out in getRates. Do you think it's worth changing these as well? I can see leaving them as-is to match the contract signature. But I could also see changing them to something like amountToken, amountGold. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an issue about changing fraction to fixidity. #1365 Which is something to be done in a later PR.

Copy link
Contributor

@mcortesi mcortesi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

async numRates(token: CeloToken): Promise<BigNumber> {
const tokenAddress = await this.kit.registry.addressFor(token)
const response = await this.contract.methods.numRates(tokenAddress).call()
return toBigNumber(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably we don't need a big number here, a plain js number would suffice

@mcortesi mcortesi assigned yerdua and unassigned mcortesi Oct 22, 2019
const sortedOracles: SortedOraclesInstance = await getDeployedProxiedContract<
SortedOraclesInstance
>('SortedOracles', artifacts)

await sortedOracles.addOracle(stableToken.address, minerAddress)
for (const oracle of config.stableToken.priceOracleAccounts) {
console.log(`Adding ${oracle} as an Oracle for StableToken`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: it's generally preferred to choose a log level when logging. i.e. console.debug or console.info instead of console.log
I guess we don't have lint checks here or it would have caught that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every migration file that has logging uses console.log. I'm happy to change all instances of those, but it makes me wonder if there's a reason for it.

@yerdua yerdua added the automerge Have PR merge automatically when checks pass label Oct 23, 2019
@celo-ci-bot-user celo-ci-bot-user merged commit 6258848 into master Oct 23, 2019
@celo-ci-bot-user celo-ci-bot-user deleted the yerdua/sorted-oracles-wrapper-contractkit branch October 23, 2019 17:17
aaronmgdr added a commit that referenced this pull request Oct 24, 2019
* master:
  [Wallet] Wallet can switch between hosted and local node (#1419)
  [Wallet] Prevent error from Avatar when name is missing (#1454)
  [Wallet] Show splash screen until JS is ready on iOS (#1453)
  Use new segment api keys used by both iOS and Android (#1452)
  [Wallet] Don't log all props, which includes i18n (#1445)
  [Helm] Updated the helm package to deploy the upgraded blockscout version (#1129)
  Tiny copy change (#1429)
  [contractkit] SortedOraclesWrapper + tests (#1405)
  [wallet] Refactor leftover thunk to sagas (#1388)
  [Wallet] Fix repeated QR code scanning and related navigation issues (#1439)
  [Wallet] Show the currency values with correct rounding. (#1435)
  [Wallet] Fix firebase initialization error on iOS after reinstalling the app (#1423)
  [Wallet] Use exit on iOS since we can't restart like Android (#1424)
  [Wallet] Update local currency styles and layout (#1325)
  Reset pincode cache if unlock fails (#1430)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass contractkit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create ContractWrapper for SortedOracles
4 participants