0xFableOrg / 0xFable

A fully on-chain trading card game. There will be elves, wizards & shit. Drama and broken friendships also.
https://twitter.com/0xFableGame
BSD 3-Clause Clear License
103 stars 35 forks source link

Account abstraction #110

Open eerkaijun opened 6 months ago

eerkaijun commented 6 months ago

Context (Problem, Motivation, Solution)

https://github.com/0xFableOrg/0xFable/issues/31 and https://github.com/0xFableOrg/0xFable/issues/32 (Issue 31 is dependent on issue 32 as account abstraction toolings cannot work on Anvil node)

Describe Your Changes

  1. Use rollop to be the dev node rather than Anvil. Include Makefile commands to start rollop node and account abstraction toolings.
  2. Integrate permissionlessjs to deal with smart contract account
  3. Users can opt to use a burner account which generates a private key and store on browser. The private key is then used as the signer of the smart contract account. Transactions are sponsored by the paymaster. (So the notion of "accounts" are abstracted away from end users)

Checklist

Testing

If you didn't write tests, explain how you made sure the code was correct and working as intended.

eerkaijun commented 6 months ago

Just opening this as a draft PR - there are still a bunch of things to be done. Will be easier to collaborate and might need some help too.

Currently main thing to figure out is how to connect smartAccountClient (defined here) to wagmi config. I think the idea is make it into a connector, though there are some typing incompatibility issues.

Once that is figured out and tested, a bunch of other things to be done are:

norswap commented 6 months ago

In the BurnerConnector, the wallet client is set here: https://github.com/0xFableOrg/0xFable/blob/master/packages/webapp/src/wagmi/BurnerConnector.ts#L63-L67

So you could assign the client there for that connector.

Connectors are set here: https://github.com/0xFableOrg/0xFable/blob/account-abstraction/packages/webapp/src/chain.ts#L78-L79

getDefaultConnectors in ConnectKit: https://github.com/family/connectkit/blob/35aeecd0cf12ef265beba724ae9b01fdc34b19b6/packages/connectkit/src/defaultConnectors.ts, populates them with a bunch of connectors defined in wagmi itself.

Here's the one used for Metamask: https://github.com/wevm/wagmi/blob/1.x/packages/connectors/src/injected.ts#L167-L181

The one from Coinbase Wallet is identical, but does not inherit InjectedConnector: https://github.com/wevm/wagmi/blob/1.x/packages/connectors/src/injected.ts#L167-L181 (the other ones, WalletConnect, Safe, ... seem similar, though maybe there's some slight subtlety I missed).

I think the move might be to monkey patch those to replace their getWalletClient function to return the original when not using account abstraction, and the AA one otherwise.