8000
Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Ethers refactor - #100

Open
kanaagawa wants to merge 15 commits into
aragon:masterfrom
kanaagawa:ethers-refactor
Open

Ethers refactor#100
kanaagawa wants to merge 15 commits into
aragon:masterfrom
kanaagawa:ethers-refactor

Conversation

@kanaagawa
@kanaagawa kanaagawa commented Jun 4, 2020
Copy link
Copy Markdown

This PR refactor radspec logic to use ethers.js library instead of several packages of web3 and bn.js.

The changes are structure in four commits:

  1. Update dependencies and documentation.
  2. Refactor the logic under src.
  3. Update tests.
  4. Include the latest changes from master.

Note we are using the latest ethers beta version, the documentation site might be helpful to better understand part of the logic. In specific how the Provider, Interface, and Fragments objects work:

@codecov-commenter
codecov-commenter commented Jun 4, 2020
Copy link
Copy Markdown

Codecov Report

Merging #100 (424f238) into master (0147640) will decrease coverage by 1.28%.
The diff coverage is 89.91%.

@@            Coverage Diff             @@
##           master     #100      +/-   ##
==========================================
- Coverage   92.38%   91.11%   -1.28%     
==========================================
  Files          35       35              
  Lines         788      754      -34     
==========================================
- Hits          728      687      -41     
- Misses         60       67       +7     
Impacted Files Coverage Δ
examples/basic/index.js 0.00% <ø> (ø)
examples/contract-calls/index.js 0.00% <ø> (ø)
examples/user-helpers/index.js 0.00% <0.00%> (ø)
src/helpers/lib/token.js 100.00% <ø> (ø)
src/helpers/tokenAmount.js 89.28% <75.00%> (-10.72%) ⬇️
src/evaluator/index.js 92.21% <88.09%> (-0.56%) ⬇️
src/helpers/radspec.js 92.15% <91.17%> (-7.85%) ⬇️
src/defaults.js 100.00% <100.00%> (ø)
src/helpers/HelperManager.js 100.00% <100.00%> (ø)
src/helpers/formatPct.js 100.00% <100.00%> (ø)
... and 5 more

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment thread .github/workflows/ci.yml
Comment thread src/helpers/fromHex.js
@sohkai sohkai left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking pretty good ❤️!

My main concern is just with the method registry, and that's something we can work on later!

Comment thread .github/workflows/ci.yml
Comment thread README.md Outdated
Comment thread docs/API.md Outdated
Comment thread docs/API.md Outdated
Comment thread examples/user-helpers/index.js Outdated
Comment thread src/evaluator/index.js

const decodeData = ethersInterface.decodeFunctionResult(node.callee, data)

return new TypedValue(returnType, decodeData[selectedReturnValueIndex])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not opposed to the above and being low-level, but I wonder if creating an ethers contract wouldn't be simpler? Effectively we've created an ABI for the interface, and so it seems like something that could just go into the contract object.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

After trying to use the ethers Contract object I found that in this particular case working with the Interface object was easier because we need to select a specific return value element.

Comment thread src/helpers/lib/methodRegistry.js Outdated
Comment thread src/helpers/radspec.js Outdated
Comment thread src/helpers/radspec.js Outdated
Comment thread src/index.js Outdated
Comment thread src/helpers/radspec.js
* @return {Promise<radspec/evaluator/TypedValue>}
*/
async (addr, data) => {
async (addr, data, registryAddress) => {
@kanaagawa kanaagawa Jun 11, 2020
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

What do you think of this optional registry address to set up the Method Registry?

Comment thread src/helpers/radspec.js
} else {
} catch {
// Try fetching 4bytes API
const { results } = await ethers.utils.fetchJson(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If we can't resolve the signature with the on-chain registry we try fetching the 4bytes API. Otherwise, we finally default to an unknown function.

Comment thread test/examples/examples.js Outdated
source: 'Perform action: `@radspec(addr, data)`',
bindings: {
addr: address(),
data: bytes('0x0b30a8d7') // getLocators(address,uint256), from 4bytes api
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Test random signature from 4bytes API.

Comment thread src/helpers/radspec.js
const { name } = parse(result)
return {
type: 'string',
value: name // TODO: should we decode and print the arguments as well?
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I wonder what you think about this TODO 🤔

@kanaagawa
kanaagawa requested a review from sohkai June 11, 2020 04:56
@kanaagawa
kanaagawa commented Jun 11, 2020
Copy link
Copy Markdown
Author

I spent quite some time trying to migrate the transformTime helper to dayjs but I had some troubles to been able to replicate the behavior of this function.

I saw this issue that discuss a possible solution. But then I further look into the documentation and it seems humanize might not be the right way to convert between units. The way suggested is to use RelativeTime like: https://day.js.org/docs/en/display/from

@kanaagawa
Copy link
Copy Markdown
Author

We finally decide to stick with date-fns for now.

@kanaagawa
Copy link
Copy Markdown
Author

UPDATE: Add a timeout to request 4bytes API. An example of it using Aragon Connect, the request takes about 1 minute: https://stackblitz.com/edit/aragon-connect-uprtcl

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0