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

Plugin-based Celo fee currency PoC #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shazarre
Copy link
Collaborator

Aim of this PR is to show how support for fee currencies could be achieved using existing plugin architecture.

To test it I used the following script that existed in a directory adjacent to directory to which ethers has been cloned to. I ran it using bun.

It requires dotenv to work and PRIVATE_KEY specified in .env file although can be modified to work without it.

It works with alfajores network only for now.

It also requires the sender to have sufficient funds to a) transfer CELO b) pay for the fee currency. Both can be acquired using the faucet.

import "dotenv/config";
import { JsonRpcProvider, Wallet } from "../ethers.js/src.ts";
import { CeloCustomData } from "../ethers.js/src.ts/chain/celo.ts";

const provider = new JsonRpcProvider("https://alfajores-forno.celo-testnet.org");
const signer = new Wallet(process.env.PRIVATE_KEY as string, provider);

let tx;

// Try to send a CELO CIP-64 transaction
tx = await signer.sendTransaction({
    to: signer.address,
    value: 1n,
    customData: {
        feeCurrency: "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1"
    } as CeloCustomData
});
  
// should be true
console.log(tx.type === 123);

// Try to send an EIP-1559 transaction
tx = await signer.sendTransaction({
    to: signer.address,
    value: 1n,
});
  
// should be true
console.log(tx.type === 2);

When everything works correctly the script should output:

$ bun goal.ts

true
true

@shazarre shazarre self-assigned this Feb 23, 2024
/**
* Custom chain specific data.
*/
customData?: any;
Copy link
Member

@aaronmgdr aaronmgdr Feb 23, 2024

Choose a reason for hiding this comment

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

you could make this a generic like

type TransactionLike<A = string, CD = any> {
customData: CD
...
}

then type CeloTranactionLike = TransactionLike<string, {feeCurrency: string}>

@sirpy
Copy link

sirpy commented Feb 25, 2024

I suggest to also test it with the Contract object, in ethers5 it wasn't enough to change the signer transaction
ie create a contract with a signer and try to execute a contract method passing feecurrency in the extra options

@shazarre
Copy link
Collaborator Author

@sirpy thanks for the suggestion!

using:

const sendResult = await contract.<method-name>.send({
  ...
  customData: {
    feeCurrency: <fee-currency-address>
  } as CeloCustomData
})

and then veryfing the type with:

console.log((await sendResult.getTransaction())?.type == 123);

outputs:

true

on the branch, so seems like it is covered without any additional changes ✅ I just reused the same signer while instantiating the contract instance.

Is that what your suggestion was about or some other use case?

@sirpy
Copy link

sirpy commented Feb 26, 2024 via email

@shazarre shazarre changed the title Celo fee currency POC Plugin-based Celo fee currency PoC Feb 29, 2024
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