celo-org / celo-monorepo

Official repository for core projects comprising the Celo platform
https://celo.org
Apache License 2.0
687 stars 362 forks source link

Add an adapted token to FeeCurrencyDirectory (e.g. USDC) #10994

Open arthurgousset opened 2 months ago

arthurgousset commented 2 months ago

Currently, the Anvil devchain only has cUSD as fee currency. Add an adapted token as fee currency (e.g. USDC) so the devchain can be used to test 6 decimal (adapted) fee currencies, and 18 decimal ("normal") fee currencies. This is a request that will help the DevTooling team use the devchain on CI to test SDKs and CLI.

For example, DevTooling could use it here:

it('fetches fee currency information', async () => {
    const wrapper = await kit.contracts.getFeeCurrencyWhitelist()

    expect(await wrapper.getFeeCurrencyInformation()).toMatchInlineSnapshot(`
      [
        {
          "adaptedToken": undefined,
          "address": "0x5315e44798395d4a952530d131249fE00f554565",
          "name": "Celo Dollar",
          "symbol": "cUSD",
        },
        {
          "adaptedToken": undefined,
          "address": "0x965D352283a3C8A016b9BBbC9bf6306665d495E7",
          "name": "Celo Brazilian Real",
          "symbol": "cREAL",
        },
        {
          "adaptedToken": undefined,
          "address": "0xdD66C23e07b4D6925b6089b5Fe6fc9E62941aFE8",
          "name": "Celo Euro",
          "symbol": "cEUR",
        },
      ]
    `)
  })

Source: FeeCurrencyWhitelistWrapper.test.ts

shazarre commented 1 month ago

Currently there are 3 tokens deployed in foundry migrations (none of them being adapted):

Would be cool if we could customise the symbols as well apart from adding an adapted token to the list, so we could have more meaningful tests.

arthurgousset commented 1 month ago

@shazarre and I spoke today. Quick TLDR for future reference:

  1. we will add an adapted token to the FeeCurrencyDirectory. It will be an instance of StableToken.sol with 6 digits.
  2. sepately, consumers of the devchain (e.g. the CLI and SDK test suites) can freely modify symbols and FeeCurrencyDirectory settings by impersonating the Governance contract (or whichever address is the owner of the contract). For example, using anvil_impersonateAccount to "Send transactions impersonating an externally owned account or contract."
arthurgousset commented 1 month ago

@martinvol and I spoke today.

We decided not to use an instance of StableToken.sol, because it's an old version of the contract (the new versions live in the mento repository mento-protocol/mento-core > contracts/StableToken.sol).

That means I'll:

  1. implement a demo ERC20 (ExampleFeeCurrency.sol) with debitGasFees, creditGasFees, and decimals functions (taking inspiration from FeeCurrencyAdapter.t.sol). It'll live in packages/protocol/contracts-0.8/stability/.
  2. refactor FeeCurrencyAdapter.t.sol to use ExampleFeeCurrency.sol
  3. deploy ExampleFeeCurrency.sol with an adapter (FeeCurrencyAdapter.sol), and register it in the FeeCurrencyDirectory in the Anvil migrations (Migration.s.sol).
arthurgousset commented 4 weeks ago

I'm working on this here:

This is more challenging than I expected. I think this might take me another 2-3 dev days to implement and test, before I can put this up for review.

arthurgousset commented 3 weeks ago

Pausing work on this issue to prioritise this: