GithubHelp home page GithubHelp logo

vnavascues / direct-request-coordinator Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 2.0 2.22 MB

Chainlink Hackaton 2022 Fall

License: MIT License

Shell 0.52% JavaScript 0.07% Solidity 22.58% TypeScript 76.84%
chainlink chainlink-adapter chainlink-hackathon chainlink-price-feeds ethersjs solidity directrequest hardhat web3-dapp

direct-request-coordinator's People

Contributors

vnavascues avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

direct-request-coordinator's Issues

Consider moving paymentAfterFee logic into an external library

This way each node operator could use either an existing one (very generic) or a customised one.
This probably requires another approach with FeeType enum at DRCoordinator level, making it just an internal uint8 (with its external getter/setter).

Improve logs

  • Include filename in logger template (parentLogger -> child logger approach).
  • Make sure datetime is displayed as ISO 8061 (e.g. YYYY-MM-DDThh:mm:ssZ) instead of UNIX timestamp.

Address existing test suite

This task should be split into several-sub tasks:

  • Remove unnecessary tests (i.e. fallback ones once DRCoordinator inherits from Operator).
  • Evaluate which existing ones should be unit tests and convert them.
  • Consider adopting the approach of 1 assert per test.
  • Add missing ones
  • Run a fuzzer
  • Fix coverage

Improve contracts folder organisation

Something along these lines:

contracts/
    - chainlink/
    - drcoordinator/
    |    - v0.8/
    |    |    - consumers/
    |    |    - dev/
    |    |    - interfaces/
    |    |    - libraries/
    |    |    |    - external/
    |    |    |    - internal/
    |    |    - tests/

Consider improving DRCoordinator on-chain metadata

Few may be subject to gas costs and/or redundancy reading events. By topic:

  • LINK:
    • LINK in escrow (pending requests)
  • Spec:
    • Number of requests per Spec and/or last time it was requested
    • Whether the Spec has a dynamic result (a boolean in the Spec struct)

Make DRCoordinator.sol inherit from Operator.sol

Making DRCoordinator derive from Operator implies:

  • Extend parent contract with the genuine DRCoordinator logic (e.g. config, Spec management, LINK payment amount, subscription).
  • Implement drcoordinatorRequest(). Explore getting rid of validateFromLINK() and the necessity of LINK.transferAndCall() thanks to subscription support. Try to be consistent and still emit an OracleRequest event, which means gasLimit, minConfirmations and any other future on-demand param should be CBOR encoded in data. Alternatively consider using a specific event (i.e. event DRCoordinatorRequest(...) that may include a struct).
    • DRCoordinator could also support processing DRCoordinator requests via LINK.transferAndCall(), however it wouldn't be a priority. It would require though a bytes4 private constant DRCOORDINATOR_REQUEST_SELECTOR = this.drCoordinatorRequest.selector;, etc.
  • Rename fulfillData() as fulfillDRCoordinatorRequest() (aligned with fulfillOracleRequest() and fulfillOracleRequest2()), and finally have a strong reason to remove all the fulfill-via-fallback() implementation. Off-chain and on-chain fulfillment steps will be simplified. TOML spec won't need the double encoding used on the fulfillData() case, and will call fulfillDRCoordinatorRequest() on the ethabiencode task. On-chain implementation will very much be like fulfillOracleRequest2().
  • The relationship shifts from 1 DRCoordinator..N Operator to 1 DRCoordinator..1 Operator. Which means:
    • Spec struct does not need to store operator nor externalJobId. DRCoordinatorConsumer does not need to send Operator address, and DRCoordinator does not need to generate and check a Spec key. A Spec key is now externalJobId.
  • DRCoordinatorConsumer library (which should currently be an abstract contract) will be affected too. Sending a DRCoordinator request via LINK.transferAndCall() won't be needed on subscription model. But again, for flexibility reasons, it may be supported as well.

Advantages:

  • No hops/bouncing/middle-man.
  • A single "operator" contract to deploy, which supports standard oracle and operator requests as well.
  • Simpler TOML specs. DRCoordinator address will be set in contractAddress, and not in requesters (free to use/properly whitelist msg.sender(s)). And no need for double encoding.
  • Simpler JSON specs: operator is not needed.
  • Allegedly cheaper deployments, requests, requests fulfillment and CUD specs (less data stored on-chain).

Disadvantages:

  • I have to prove no LINK transfer is needed to initiate directrequest jobs (e.g. he CL node does validate that an OracleRequest event proceeded a LINK.transferAndCall()). Also testing other events than OracleRequest.
  • Without a LINK.transferAndCall() between the requester and the DRCoordinator (and even cheaper requests), it would be good to have a more thorough thought with regards to TOML spec payment and spamming protection. Just as an extreme example, in the most defensive scenario DRCoordinator could charge the whole MAX LINK payment and make a refund after fulfilling the request.

Specs whitelisting / access control

This issue relates to #12

After making DRCoordinator inherit from Operator (#6) the easiest & cheapest way of whitelisting callers per Spec will be via the TOML Spec requesters field.

Consider whether an on-chain whitelisting would be interesting:

  • A new property in the JSON Spec: configuration.requesters (an Array).

Events clean-up

For sure not all the indexed parameters are needed, nor all the parameters.
We'll only know after plug it into the monitoring system and observe for a while.

Add support for calculating the weiPerUnitLink via LINK / USD + TKN / USD

Calculate weiPerUnitLink via LINK / USD + TKN / USD on networks where the LINK / TKN price feed is not available yet. Consider enabling this mode at constructor level (and flag it). Make variable names generic, e.g. PRICE_FEED_1, PRICE_FEED_2 as the former will be used either as LINK_TKN_FEED or LINK_USD_FEED.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.