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

feat: add RPC calls and checks #485

Merged
merged 9 commits into from
Dec 12, 2024

Conversation

rossgalloway
Copy link
Collaborator

@rossgalloway rossgalloway commented Nov 20, 2024

This supersedes #479

Implemented RPC contract reads into the site using the Viem Ethereum library. There are 2 features currently working.

1. Verifying Contract Addresses

All the V3 contract addresses shown on the V3 addresses page are now checked against from their respective registry smart contracts.

There is a single constants file with ENS names and addresses where addresses should be kept updated. A new github workflow is part of this PR, which runs a script to check the constants file against on-chain addresses every night at midnight. If the check fails, a new issue is posted to the repo issues board and a component on the addresses page gives a warning.

On initial site load:

  • Protocol Address Provider and Role Manager are resolved from their ENS names and checked against the constants file.
  • Protocol Periphery Addresses are queried from the Protocol Address Provider that was just resolved. They are checked against the constants file and their ENS names (if they have them).
  • Release Registry Addresses are queried from the Release Registry that is retrieved from the Protocol Address Provider. They are checked against the constants file and their ENS names (if they have them).
  • The most recent Vault Original is queried from the Vault Factory that was just pulled from the Release Registry. It is checked against the constants file.
  • Yearn Specific Contract addresses are pulled from the RoleManager. They are checked against the constants file and their ENS names (if they have them).

These contract addresses and the checks are then served as context to the app.

On initial Address page load:

The checks are consumed by an <AddressCheck> component that reads the checks from the context and posts a message about whether the checks passed or failed. If they failed then the failed check information is posted to the console.

Where addresses are needed, <ContractAddress> components consume static address data from the constants file and display a link with the Address as the text and the hyperlink to the etherscan page. It takes the following argument:

  • contractName which is the path to the data you want to read from the constants file.

The component is used like this:

<ContractAddress contractName = {['topLevel', 'protocolAddressProvider']} />

The shape of the data object is:

type ContractAddresses = {
  topLevel: TopLevelAddresses
  protocolPeriphery: ProtocolPeripheryAddresses
  releaseRegistry: ReleaseDataMap
  yearnV3: YearnAddresses
  yfiTokenContracts: YfiTokenContracts
  veYfiContracts: VeYfiContracts
}

type TopLevelAddresses = {
  v3ProtocolAddressProvider: `0x${string}`
  v3ReleaseRegistry: `0x${string}`
  v3RoleManager: `0x${string}`
}

type ProtocolPeripheryAddresses = {
  router: `0x${string}` | undefined
  aprOracle: `0x${string}` | undefined
  commonReportTrigger: `0x${string}` | undefined
  roleManagerFactory: `0x${string}` | undefined
}

type ReleaseDataMap = {
  latestRelease: string
  [releaseNumber: string]: ReleaseData | string
}
// contains array of:
type ReleaseData = {
  vaultOriginal: string
  factory: string
  tokenizedStrategy: string
}

type YearnAddresses = {
  yearnBrain: `0x${string}` | undefined
  yearnDaddy: `0x${string}` | undefined
  yearnAccountant: `0x${string}` | undefined
  yearnDebtAllocator: `0x${string}` | undefined
  yearnRegistry: `0x${string}` | undefined
}

2. Make arbitrary contract call reads in docs

You can make RPC calls to read contract data from on-chain sources from within the docs. You can add the information for all the read calls you want within the front-matter of a markdown document. Front-matter is metadata that docusaurus reads when serving pages.

To make a blockchain call you need to structure your data in the following format at the top of the markdown file:

---
rpcCalls:

  - name: 'dYFI Redemption' <-- descriptive name of contract to be called for use in component
    chain: '1' <--chainID
    address: '0x7dC3A74F0684fc026f9163C6D5c3C99fda2cf60a' <--the contract address
    abiName: 'dyfiRedemptionABI' <--name of exported ABI object from src/ethereum/ABIs
    methods:  
      - 'discount' <-- name of call (if no arguments needed)
      - 'get_latest_price'
      - name: 'eth_required' <-- name of call (if arguments are needed)
        args: ['1000000000000000000'] <--comma separated arguments of call as an array (square brackets)

  - name: 'YFI token'
    chain: '1'
    address: '0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e'
    abiName: 'yfiTokenABI'
    methods:
      - totalSupply
      - symbol
---
  • Each element in rpcCalls creates an object that is exported from the front-matter.
  • Each object can contain calls to different functions in the same contract if you add them into the methods field.
    • If the method doesn't require args (the function doesn't require any input) then you only need to list the name. This is the name you see on etherscan, without the number.
    • If the method does require an argument then you need to add it with a name parameter and an args parameter, with the values for the arguments separated by commas and in square brackets.

When adding a new contract to call, you need to add the ABI to "src/ethereum/ABIs". Create a new typescript file with the name of your ABI. The convention is to name it in camelCase and end it with ABI (i.e. yfiTokenABI.ts). Then paste the ABI into the file (you can copy it from etherscan. It is in the contract->code section.). You need to export it and add as const at the end.

// src/ethereum/ABIs/yourContractABI.ts
export const yourContractABI = [
    {
    // abi data here
    }
] as const

You then need to export this element from the index.ts file in the same directory. Add a line exporting your ABI as shown below.

export * from './yourContractABI'

To display the data from the calls, use the component. It takes the following arguments:

  • contractName which reads the name field in the rpcCall defined in the front-matter
  • methodName which reads from the methods in the rpcCall defined in the front-matter
  • decimals which is an optional argument to format your output to display with human readable decimals. It should be wrapped in curly brackets {}.
The current redemption discount is: <ContractData contractName='dYFI Redemption' methodName='discount' decimals={18} />

Copy link

vercel bot commented Nov 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
yearn-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 12, 2024 8:44pm

@rossgalloway rossgalloway merged commit 19afa83 into yearn:master Dec 12, 2024
4 of 5 checks passed
@rossgalloway rossgalloway deleted the worktree-add-rpc-calls branch December 12, 2024 20:45
rossgalloway added a commit to rossgalloway/yearn-devdocs that referenced this pull request Jan 21, 2025
commit 9945280
Author: rossgalloway <[email protected]>
Date:   Tue Jan 21 09:59:16 2025 -0500

    Feat: wallet integration guide (yearn#499)

    * feat: wallet and portfolio tracker integration doc

    * fix: grammar

    * fix: update kong APY types.

    * fix: missing vaults and incorrect links

    * fix: add ens

    * fix: add info on APY/APR

commit d2cd23b
Author: Ross <[email protected]>
Date:   Thu Jan 16 09:29:39 2025 -0500

    fix: conflict

commit 086f888
Author: rossgalloway <[email protected]>
Date:   Mon Dec 30 15:30:31 2024 -0500

    chore: update address checks data (yearn#498)

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    ---------

    Co-authored-by: rossgalloway <[email protected]>

commit 3301db6
Author: rossgalloway <[email protected]>
Date:   Wed Dec 18 12:39:49 2024 -0500

    Chore: clean up actions (yearn#497)

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * chore: clean up old actions

    ---------

    Co-authored-by: rossgalloway <[email protected]>

commit 8ced3cc
Author: rossgalloway <[email protected]>
Date:   Mon Dec 16 11:27:20 2024 -0500

    Fix: AddressCheck action (yearn#495)

    * Update data from daily check

    * fix: addressCheck action

    ---------

    Co-authored-by: rossgalloway <[email protected]>

commit 670cdb0
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 17:38:34 2024 -0500

    add guardian information (yearn#494)

    * add guardian information

    * edit phrasing

    * update phrasing again

commit f8b2d03
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 15:46:19 2024 -0500

    Chore: add new veyfi gauges (yearn#490)

    * Add new gauges

    * update chart title and formatting

commit 19afa83
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 15:45:49 2024 -0500

    add RPC calls and checks (yearn#485)

    * add RPC calls and checks

    * add script and license, fix imports

    * clean up react functions.

    * update workflow

    * update workflow

    * update workflow

    * remove automatic address checking on load.

commit a210351
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 13:53:15 2024 -0500

    Feat: Add new FAQ to guides section (yearn#482)

    * update env

    * add FAQ
    * new faq page
    * update sidebar
    * add logic to open details tab when linked to a contained heading.

    * minor grammar fixes

    * minor grammarly fixes

    ---------

    Co-authored-by: Marco Guaspari Worms <[email protected]>

commit 715ca1b
Author: cuiyourong <[email protected]>
Date:   Wed Dec 11 23:59:30 2024 +0800

    chore: remove redundant words in comment (yearn#491)

    Signed-off-by: cuiyourong <[email protected]>

commit 2c5e245
Author: Skylar Ray <[email protected]>
Date:   Wed Dec 4 21:18:51 2024 +0200

    Update ygift.md (yearn#487)

    Co-authored-by: rossgalloway <[email protected]>

commit 3d529ee
Author: Danil <[email protected]>
Date:   Wed Dec 4 20:18:34 2024 +0100

    Update interfaces.md (yearn#488)

    Co-authored-by: rossgalloway <[email protected]>

commit a80e8bf
Author: rossgalloway <[email protected]>
Date:   Wed Dec 4 14:14:48 2024 -0500

    update yETH addresses (yearn#489)
@rossgalloway rossgalloway changed the title add RPC calls and checks feat: add RPC calls and checks Jan 23, 2025
rossgalloway added a commit to rossgalloway/yearn-devdocs that referenced this pull request Feb 12, 2025
* first pass at yPools updates

* fix typo

* grammar fix to yeth-overview.md

* fix grammar in ypools-overview.md

* fix grammar in ypools-overview.md

* update LSD to LST

* working on it

* add specs

* feat: misc updates

* Squashed commit of the following:

commit 9945280
Author: rossgalloway <[email protected]>
Date:   Tue Jan 21 09:59:16 2025 -0500

    Feat: wallet integration guide (yearn#499)

    * feat: wallet and portfolio tracker integration doc

    * fix: grammar

    * fix: update kong APY types.

    * fix: missing vaults and incorrect links

    * fix: add ens

    * fix: add info on APY/APR

commit d2cd23b
Author: Ross <[email protected]>
Date:   Thu Jan 16 09:29:39 2025 -0500

    fix: conflict

commit 086f888
Author: rossgalloway <[email protected]>
Date:   Mon Dec 30 15:30:31 2024 -0500

    chore: update address checks data (yearn#498)

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    ---------

    Co-authored-by: rossgalloway <[email protected]>

commit 3301db6
Author: rossgalloway <[email protected]>
Date:   Wed Dec 18 12:39:49 2024 -0500

    Chore: clean up actions (yearn#497)

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * Update data from daily check

    * chore: clean up old actions

    ---------

    Co-authored-by: rossgalloway <[email protected]>

commit 8ced3cc
Author: rossgalloway <[email protected]>
Date:   Mon Dec 16 11:27:20 2024 -0500

    Fix: AddressCheck action (yearn#495)

    * Update data from daily check

    * fix: addressCheck action

    ---------

    Co-authored-by: rossgalloway <[email protected]>

commit 670cdb0
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 17:38:34 2024 -0500

    add guardian information (yearn#494)

    * add guardian information

    * edit phrasing

    * update phrasing again

commit f8b2d03
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 15:46:19 2024 -0500

    Chore: add new veyfi gauges (yearn#490)

    * Add new gauges

    * update chart title and formatting

commit 19afa83
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 15:45:49 2024 -0500

    add RPC calls and checks (yearn#485)

    * add RPC calls and checks

    * add script and license, fix imports

    * clean up react functions.

    * update workflow

    * update workflow

    * update workflow

    * remove automatic address checking on load.

commit a210351
Author: rossgalloway <[email protected]>
Date:   Thu Dec 12 13:53:15 2024 -0500

    Feat: Add new FAQ to guides section (yearn#482)

    * update env

    * add FAQ
    * new faq page
    * update sidebar
    * add logic to open details tab when linked to a contained heading.

    * minor grammar fixes

    * minor grammarly fixes

    ---------

    Co-authored-by: Marco Guaspari Worms <[email protected]>

commit 715ca1b
Author: cuiyourong <[email protected]>
Date:   Wed Dec 11 23:59:30 2024 +0800

    chore: remove redundant words in comment (yearn#491)

    Signed-off-by: cuiyourong <[email protected]>

commit 2c5e245
Author: Skylar Ray <[email protected]>
Date:   Wed Dec 4 21:18:51 2024 +0200

    Update ygift.md (yearn#487)

    Co-authored-by: rossgalloway <[email protected]>

commit 3d529ee
Author: Danil <[email protected]>
Date:   Wed Dec 4 20:18:34 2024 +0100

    Update interfaces.md (yearn#488)

    Co-authored-by: rossgalloway <[email protected]>

commit a80e8bf
Author: rossgalloway <[email protected]>
Date:   Wed Dec 4 14:14:48 2024 -0500

    update yETH addresses (yearn#489)

* fix: picked wrong merge conflict choice

* updates

* fix: yaml formatting

* feat: add new abi encoder widget

* Revert "Merge remote-tracking branch 'origin/feat--update-and-re-org-yETH' into pr/rossgalloway/33"

This reverts commit 7f5fc6b, reversing
changes made to 9fecf30.
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.

2 participants