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

feat: gas abstraction #201

Open
wants to merge 4 commits into
base: chain-abstraction
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions docs/walletkit/android/gas-abstraction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Gas Abstraction (experimental)

WalletKit provides a toolkit for wallet developers to integrate verifying paymaster gas abstraction into their wallets.

`GasAbstractionClient` is instantiated with some basic RPC URL and API key information. This client is long-lived and should be reused between transactions as it will reuse network connections for improved latency.

When receiving a transaction request, send the transaction to the `prepare_gas_abstraction(txn)` method. This will do some thinking and will prepare a set of operations and return a couple of hashes to be signed.

The operations are:

1. Deploying the 7702 account and delegating to it, if needed
2. Sending a sponsored UserOperation for the initial transaction.

The user will then approve signatures for these operations and the wallet will then call `execute_transaction(txn, signatures)` with the same initial transaction and the signatures.

The function will send the transactions and return status information of them to you.

The below is an example psudo-Rust code of the usage of `GasAbstractionClient`:

```rust
async fn main() {
let eoa = LocalSigner::random();
let client = GasAbstractionClient::new(...);
let txn = Transaction { to: vitalik.eth, amount: 1 ETH };

let PreparedGasAbstraction {
hashes_to_sign,
fields
} = client.prepare_gas_abstraction(txn).await?;

ask_user_for_approval(fields).await?;

let signatures = hashes_to_sign.iter().map(|hash| account.sign(hash)).collect();

let receipt = client.execute_transaction(txn, Params {
signatures
}).await?;

display_success(receipt)
}
```

```rust
impl GasAbstractionClient {
/// Just provide a project ID
async fn new(project_id: String) -> Self;

/// Or you can make chain-specific clients if you want to do it manually
async fn new(chain_id: Caip10, rpc_url: Url, bundler_url: Url, paymaster_url: Url) -> Self;

// Prepare and send gas-abstracted transactions
async fn bool prepare_gas_abstraction(Transaction transaction) -> PreparedGasAbstraction;
async fn bool execute_transaction(Transaction transaction, params: Params) -> B256;

// Signature creation
async fn ..... COPY signature creation functions from current SDK

// == Future APIs ==
async fn send_user_operation(?) - ?;
async fn create_smart_session(?) -> ?;
}

enum PreparedGasAbstraction {
hashes_to_sign: Vec<B256>,
fees: GasAbstractionFees, // similar to RouteUiFields -> fee and other UI info for user display
}

enum Params {
/// EOA signatures by the transaction's sender of `hashes_to_sign`
signatures: Vec<Signature>,
}
```
76 changes: 76 additions & 0 deletions docs/walletkit/features/gas-abstraction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import Wrapper from '../../components/Home/Wrapper'

import androidLogo from '../../../static/assets/home/androidLogo.png'
import iosLogo from '../../../static/assets/home/iosLogo.png'
import rnLogo from '../../../static/assets/home/rnLogo.png'
import flutterLogo from '../../../static/assets/home/flutterLogo.png'
import csharpLogo from '../../../static/assets/home/csharpLogo.png'
import javascriptLogo from '../../../static/assets/home/javascriptLogo.png'

# Gas Abstraction for EOAs (experimental)

Gas Abstraction enables existing EOA accounts to execute transactions without needing to have special tokens to pay for the transaction gas; for example ETH on Ethereum. This solution provides wallet developers with a toolkit to integrate gas abstraction using WalletKit.

## How it works

When your wallet receives a `wallet_sendTransaction` request, the wallet will automatically sponsor the transaction for the user using the Reown paymaster. Native gas tokens are not needed.

This works by upgrading the EOA to a smart account that supports verifying paymasters and sending a sponsored User Operation. Specifically, a 7579 modular Safe smart account is deployed and delegated to in a 7702 transaction. The smart account has the same address as the EOA, and the EOA is the only signer on the account.

## Get Started

<Wrapper
type="large"
fit={false}
items={[
{
name: 'Android',
type: 'android',
description: 'Get started with WalletKit in Android.',
icon: androidLogo,
href: '../android/gas-abstraction'
},
// {
// name: 'iOS',
// type: 'ios',
// description: 'Get started with WalletKit in iOS.',
// icon: iosLogo,
// href: '../ios/gas-abstraction',
// isWhite: true
// },
// {
// name: 'React Native',
// type: 'react-native',
// description: 'Get started with WalletKit in React Native.',
// icon: rnLogo,
// href: '../react-native/gas-abstraction'
// }
]}
/>

## FAQ

### What are the available networks for Gas Abstraction?

Gas Abstraction is available on any network where 4337 bundlers and paymasters are available.

Click [here](/) to see what networks the Reown paymaster supports for seamless operation.

### What types of paymasters are supported?

Only verifying paymasters are currently supported (by default the Reown paymaster). ERC-20 paymasters are not yet supported.

### What are the limitations?

- Accounts that already have 7702 delegations will be rejected and are not supported.
- Because delegation cannot be removed (only changed), the account will need to indefinitely support EIP-1271 signature creation & validation. This is because apps assume if an account has code, that it is a smart account and it will use EIP-1271 to validate the signature.

### What apps does this support?

Any app that supports smart contract accounts. Specifically, EIP-1271 must now be used for signing.

### Are more smart account features available or just gas abstraction?

In the future more features will be supported such as:
- Sending user operations directly instead of transactions
- Smart sessions
5 changes: 5 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ module.exports = {
label: 'Chain Abstraction',
id: 'walletkit/features/chain-abstraction'
},
{
type: 'doc',
label: 'Gas Abstraction (experimental)',
id: 'walletkit/features/gas-abstraction'
},
{ type: 'doc', label: 'Notifications', id: 'walletkit/features/notifications' },
{ type: 'doc', label: 'Verify', id: 'walletkit/features/verify' }
]
Expand Down