safe-global / safe-apps-sdk

Client-side SDKs to create third-party Safe Apps
https://safe.global
MIT License
249 stars 116 forks source link

Research: Can/which SDK packages can support batch transactions with minimal development #245

Open Graeme-Code opened 2 years ago

Graeme-Code commented 2 years ago

Background:

1inch has introduced batch transactions for their Safe App. The experience is glorious. To my knowledge, it is the only "Dapp as a Safe App" that does this. We know from looking at data that most common transactions come from Defi protocols:

Problem:

1inch did the integration via the javascript SDK, it comes with more flexibility than say the web3 modules or onboard.js packages but requires more understanding and work to intergrate.

What can we do?

The purpose of this ticket is to answer the following questions:

What should the research unlock?

If we know that it is possible to facilitate batch transactions via existing web3 wallet libraries, then we can push it as a default standard. If it can't be done, then we need to incentivize and encourage dapp developers through promotion and placement in the Safe Apps UI.

mmv08 commented 2 years ago

The biggest obstacle for broader batch transactions support is that only smart contract wallets support them. So it's tough to make a one-stop solution that would use batch transactions for SC wallets and fall back to regular transactions for an EOA wallet. dApp developers need to implement conditional logic for sending txs 1-by-1 or as a batch depending on a wallet.

The only possible way to batch transactions with a Safe is to use the safe-apps-sdk package. It works fine for apps explicitly tailored for the Safe, but not for existing dApps because most of the dapps work with eth providers following EIP-1193. Our solutions (bnc-onboard, safe-apps-provider) that compile with the standard don't allow batching.

I think the best way to go with is a solution as wallet-agnostic as possible. I believe that SC wallets will eventually overtake EOAs and that there will be some standards for batching transactions in the future, and our solution can serve as a base.

My proposed solution is to support Argent's wc_multicall RPC method in the safe-apps-provider package and WalletConnect Safe App. It has the same method signature for Gnosis' multisend, so it's trivial to implement. And by doing that, the two most popular smart contract wallets will share the same method for batching transactions.

cc @rmeissner @sche

sche commented 2 years ago

Thanks @mikheevm I have added a problem statement here https://github.com/gnosis/safe-pm/issues/1

mmv08 commented 2 years ago

My proposed solution is to support Argent's wc_multicall RPC method in the safe-apps-provider package and WalletConnect Safe App. It has the same method signature for Gnosis' multisend, so it's trivial to implement. And by doing that, the two most popular smart contract wallets will share the same method for batching transactions.

cc @rmeissner @sche

It turns out that argent's multicall is not an RPC method, it's a fake ABI that is then mapped to a different method on a smart contract on the app side:

Personally, not a big fan of this approach. I've asked them if they're interested in collaborating in a shared RPC method.

mmv08 commented 2 years ago

I shared a proposal doc in this issue for team review

mmv08 commented 2 years ago

I would appreciate your feedback on the second round of wallet_batchTransaction RPC proposal, this time it is EOA “compatible”, and the transaction types are exactly the same as in eth_sendTransaction. https://hackmd.io/HFHohGDbRSGgUFI2rk22bA?view

mmv08 commented 2 years ago

Update: Argent team said they would be happy to support this too.

dasanra commented 2 years ago

@clemoon