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

Ethers refactor #100

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Ethers refactor #100

wants to merge 15 commits into from

Conversation

0xGabi
Copy link

@0xGabi 0xGabi commented Jun 4, 2020

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
Copy link

codecov-commenter commented Jun 4, 2020

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

Copy link
Contributor

@sohkai sohkai left a comment

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!

.github/workflows/ci.yml Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
docs/API.md Outdated Show resolved Hide resolved
docs/API.md Outdated Show resolved Hide resolved
examples/user-helpers/index.js Outdated Show resolved Hide resolved

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

return new TypedValue(returnType, decodeData[selectedReturnValueIndex])
Copy link
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
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.

src/helpers/lib/methodRegistry.js Outdated Show resolved Hide resolved
src/helpers/radspec.js Outdated Show resolved Hide resolved
src/helpers/radspec.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
* @return {Promise<radspec/evaluator/TypedValue>}
*/
async (addr, data) => {
async (addr, data, registryAddress) => {
Copy link
Author

@0xGabi 0xGabi Jun 11, 2020

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?

} else {
} catch {
// Try fetching 4bytes API
const { results } = await ethers.utils.fetchJson(
Copy link
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.

source: 'Perform action: `@radspec(addr, data)`',
bindings: {
addr: address(),
data: bytes('0x0b30a8d7') // getLocators(address,uint256), from 4bytes api
Copy link
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.

: (await provider.getNetwork()).chainId
})
const result = await registry.lookup(methodId)
const { name } = parse(result)
return {
type: 'string',
value: name // TODO: should we decode and print the arguments as well?
Copy link
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 🤔

@0xGabi 0xGabi requested a review from sohkai June 11, 2020 04:56
@0xGabi
Copy link
Author

0xGabi commented Jun 11, 2020

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

@0xGabi
Copy link
Author

0xGabi commented Jul 7, 2020

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

@0xGabi
Copy link
Author

0xGabi commented Jul 20, 2020

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants