agentcoinorg / AutoTx

A personal assistant for planning and executing on-chain transactions.
MIT License
97 stars 17 forks source link

Biconomy Smart Account Integration (CLI) #71

Open dOrgJelli opened 6 months ago

dOrgJelli commented 6 months ago

In this first integration we will focus on the CLI. The user must specify an EOA private key they want to use as the root address in control of the smart account. The environment variables will be modified to reflect the following: SAFE_SMART_ACCOUNT_ADDRESS & SMART_ACCOUNT_OWNER_PK. The user must specify one of these to use AutoTx.

Once the user private key is set, when AutoTx is run, it will detect if there is an existing smart account created for this address (localstorage). If one does not exist, it will walk the user through smart account deployment on the desired chain:

AutoTx: It appears you do not have a smart account deployed on this chain. Let's get that deployed for you...
AutoTx: Your smart account is 0xABC, please send at least ${amount} ${native_asset} to this address on ${chain} to initialize the account and get started making transactions.
...waiting...
...user sends funds...
AutoTx: Your smart account has been funded, we're ready to begin generating transactions.

Now that the smart accounts exists, AutoTx will continue to execute using the smart account's address as the user's address. Upon creating transaction bundles, we must format them accordingly for the bundler to be able to execute. NOTE: we'll need to a an environment variable for the bundler. This is something we can add on the user's behalf to be used by default.

Since the Biconomy SDK is only available in JS/TS, simplest approach would be to run a "smart account service" in a docker container that allows us to interface with the SDK for things like deployment, bundle creation, and bundle submission.

References: https://www.biconomy.io/smart-accounts https://www.biconomy.io/post/modular-session-keys https://github.com/bcnmy/biconomy-client-sdk/tree/main https://github.com/bcnmy/sdk-examples/blob/master/scripts/index.ts

nerfZael commented 6 months ago

Been looking into AA a lot lately, so I'd love to tackle this as soon as it's a priority

livingrockrises commented 3 months ago

can you share example of CLI integration please?

Also below maybe relevant on Discord integration issue but.. "You need to add AutoTx's address as a delegate or signer to your Safe. This allows AutoTx to propose transactions. Address: 0xa14C92946b37BFd4b2d55aCFAE43EF77ECb189e0" - from my discord interaction

Would we need this in this case? Why do make AutoTx delegate? just so it appears on safe dashboard for user to sign with main signer/s of the safe?

livingrockrises commented 3 months ago

Once the user private key is set, when AutoTx is run, it will detect if there is an existing smart account created for this address

this can be done by getting counterfactual SA address for an EOA, with or without biconomy SDK (using ECDSA module address and SA factory address)

livingrockrises commented 3 months ago

please check here for preparing and sending tx using a bundler. can share individual internal steps from the sdk and help them translate to smart account service.

https://github.com/bcnmy/sdk-examples/blob/master/scripts/gasless/mintNFT.ts#L36

imo AutoTx would just prepare the calldata (tx object or array of tx objects) and ask the EOA signer to sign userop hash.

also, smart account V2 repo is this one. https://github.com/bcnmy/scw-contracts/tree/develop we can give you deployed addresses from the docs