Skip to content

Commit

Permalink
Merge pull request #66 from bcnmy/Modular_SDK_Update
Browse files Browse the repository at this point in the history
Modular sdk update
  • Loading branch information
tomarsachin2271 authored Sep 20, 2023
2 parents 5f8fd1c + 49a0327 commit 09745ca
Show file tree
Hide file tree
Showing 60 changed files with 5,830 additions and 302 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern
static website generator.

### Installation
### Installation

```
$ npm install
Expand Down
59 changes: 42 additions & 17 deletions docs/Biconomy AA Stack/Account/accountmethods.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ sidebar_position: 4
# Smart Account Methods
``` typescript
export interface IBiconomySmartAccount extends ISmartAccount {
init(initilizationData?: InitilizationData): Promise<this>
initializeAccountAtIndex(accountIndex: number): void
getExecuteCallData(to: string, value: BigNumberish, data: BytesLike): string
getExecuteBatchCallData(
to: Array<string>,
value: Array<BigNumberish>,
data: Array<BytesLike>
): string
buildUserOp(transactions: Transaction[], overrides?: Overrides): Promise<Partial<UserOperation>>
getAllTokenBalances(balancesDto: BalancesDto): Promise<BalancesResponse>
getTotalBalanceInUsd(balancesDto: BalancesDto): Promise<UsdBalanceResponse>
getSmartAccountsByOwner(
smartAccountByOwnerDto: SmartAccountByOwnerDto
): Promise<SmartAccountsResponse>
getTransactionsByAddress(chainId: number, address: string): Promise<SCWTransactionResponse[]>
getTransactionByHash(txHash: string): Promise<SCWTransactionResponse>
getAllSupportedChains(): Promise<SupportedChainsResponse>
init(_initilizationData?: InitilizationData): Promise<this>;
initializeAccountAtIndex(_accountIndex: number): void;
getExecuteCallData(_to: string, _value: BigNumberish, _data: BytesLike): string;
getExecuteBatchCallData(_to: Array<string>, _value: Array<BigNumberish>, _data: Array<BytesLike>): string;
buildUserOp(_transactions: Transaction[], _overrides?: Overrides): Promise<Partial<UserOperation>>;
getAllTokenBalances(_balancesDto: BalancesDto): Promise<BalancesResponse>;
getTotalBalanceInUsd(_balancesDto: BalancesDto): Promise<UsdBalanceResponse>;
getSmartAccountsByOwner(_smartAccountByOwnerDto: SmartAccountByOwnerDto): Promise<SmartAccountsResponse>;
getTransactionsByAddress(_chainId: number, _address: string): Promise<SCWTransactionResponse[]>;
getTransactionByHash(_txHash: string): Promise<SCWTransactionResponse>;
getAllSupportedChains(): Promise<SupportedChainsResponse>;
attachSigner(_signer: Signer): Promise<void>;
}
```
# IBiconomySmartAccount Interface
Expand All @@ -40,6 +35,7 @@ The `IBiconomySmartAccount` interface extends the `ISmartAccount` interface and
| getTransactionsByAddress | chainId: number, address: string | Retrieves the transactions associated with the specified `address` on the given `chainId`. Returns a Promise that resolves to an array of `SCWTransactionResponse` objects containing information about the transactions. |
| getTransactionByHash | txHash: string | Retrieves the transaction details for the specified transaction hash (`txHash`). Returns a Promise that resolves to a `SCWTransactionResponse` object containing information about the transaction. |
| getAllSupportedChains | N/A | Retrieves information about all supported chains. Returns a Promise that resolves to the `SupportedChainsResponse` containing the list of supported chains. |
| attachSigner | Ethers Signer | Attaach ethers signer object |



Expand All @@ -65,3 +61,32 @@ export interface ISmartAccount {
| sendSignedUserOp | userOperation: UserOperation | Sends the pre-signed `UserOperation` to the Biconomy network for execution. Returns a Promise that resolves to a `UserOpResponse` containing the response from the network. |


# IBaseSmartAccount

```typescript

export interface INon4337Account {
estimateCreationGas(_initCode: string): Promise<BigNumberish>;
getNonce(): Promise<BigNumber>;
signMessage(_message: Bytes | string): Promise<string>;
getAccountAddress(_accountIndex?: number): Promise<string>;
}

export interface IBaseSmartAccount extends INon4337Account {
getVerificationGasLimit(_initCode: BytesLike): Promise<BigNumberish>;
getPreVerificationGas(_userOp: Partial<UserOperation>): Promise<BigNumberish>;
signUserOp(_userOp: UserOperation): Promise<UserOperation>;
signUserOpHash(_userOpHash: string): Promise<string>;
getUserOpHash(_userOp: Partial<UserOperation>): Promise<string>;
getAccountInitCode(): Promise<string>;
getDummySignature(): Promise<string>;
}

```

| Method | Parameters | Description |
|--------------------------|------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| estimateCreationGas | _initCode: string | Estimate gas for account creation |
| getNonce | n/a | Returns promise that resolves into big number for nonce |
| signMessage | _message: Bytes or String | Returns signature as promise that resolves to a string |
| getAccountAddress | accountIndex?: number | Returns address, optionally takes an index if not default address |
51 changes: 29 additions & 22 deletions docs/Biconomy AA Stack/Account/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ IBundler and IPaymaster are typings for Bundler and BiconomyPaymaster classes th
Let’s start with the initial configuration here

```typescript
const bundler: IBundler = new Bundler({
bundlerUrl: '', // you can get this value from biconomy dashboard.
const bundler: IBundler = new Bundler({
//https://dashboard.biconomy.io/ get bundler urls from your dashboard
bundlerUrl: "",
chainId: ChainId.POLYGON_MUMBAI,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
})

const paymaster: IPaymaster = new BiconomyPaymaster({
paymasterUrl: '' // you can get this value from biconomy dashboard.
//https://dashboard.biconomy.io/ get paymaster urls from your dashboard
paymasterUrl: ""
})
```

Expand All @@ -39,37 +41,42 @@ const bundler: IBundler = new Bundler({
Now with the paymaster and bundler instances configured let’s set up the rest of what we need for our Smart Account

```typescript
import { BiconomySmartAccount, BiconomySmartAccountConfig, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account"
import { BiconomySmartAccountV2, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account"
```

Update your import from the account package to also include `BiconomySmartAccount` and `BiconomySmartAccountConfig` and also import Wallet, providers, and ethers from the ethers package.
Update your import from the account package to also include `BiconomySmartAccountV2` and also import Wallet, providers, and ethers from the ethers package.

Now we need an object that will hold the configuration values for our Smart Account.

```typescript
const biconomySmartAccountConfig: BiconomySmartAccountConfig = {
signer: wallet.getSigner(),
chainId: ChainId.POLYGON_MUMBAI,
rpcUrl: '',
paymaster: paymaster, //you can skip paymaster instance if you are not interested in transaction sponsorship
bundler: bundler,
}
const biconomySmartAccountConfig = {
signer: {}, //ethers signer object
chainId: ChainId.POLYGON_MUMBAI, //or any chain of your choice
bundler: bundler, // instance of bundler
paymaster: paymaster, // instance of paymaster
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS, //entry point address for chain
defaultValidationModule: ownerShipModule, // either ECDSA or Multi chain to start
activeValidationModule: ownerShipModule // either ECDSA or Multi chain to start
}
```

| Key | Description |
| ------------- | ------------- |
| signer | This signer will be used for signing userOps for any transactions you build. You can supply your your EOA wallet signer|
| chainId | This represents the network your smart wallet transactions will be conducted on. Take a look following [Link](https://shorturl.at/arETU) for supported chain id's |
| rpcUrl | This represents the EVM node RPC URL you'll interact with, adjustable according to your needs. We recommend to use some private node url for efficient userOp building|
| paymaster | you can pass same paymaster instance that you have build in previous step. Alternatively, you can skip this if you are not interested in sponsoring transaction using paymaster|
| | Note: if you don't pass the paymaster instance, your smart account will need funds to pay for transaction fees.|
| bundler | You can pass same bundler instance that you have build in previous step. Alternatively, you can skip this if you are only interested in building userOP|
| signer | This signer will be used for signing userOps for any transactions you build. You can supply your EOA wallet as a signer|
| chainId | This represents the network your smart wallet transactions will be conducted on. Take a look at the [following](../../supportedchains/supportedchains.md) for supported chains |
| rpcUrl | This represents the EVM node RPC URL you'll interact with, adjustable according to your needs. We recommend using some private node url for efficient ```userOp``` building|
| paymaster | You can pass the same paymaster instance that you have built in the previous step. Alternatively, you can skip this if you are not interested in sponsoring transactions using Paymaster |
| | Note: if you don't pass the Paymaster instance, your Smart Contract Account will need funds to pay for transaction fees.|
| bundler | You can pass the same bundler instance that you have built in the previous step. Alternatively, you can skip this if you are only interested in building ```userOp```|
| entryPointAddress | Entry point address for chain, you can use the DEFAULT_ENTRYPOINT_ADDRESS here |
| defaultValidationModule | Validation module to initialize with this should be either ECDSA or Multi chain |
| activeValidationModule | Validation module to initialize with this should be either ECDSA or Multi chain and this can be changed later once you activate further modules |

Lets create a new instance of the account using the BiconomySmartAccount class and passing it the biconomySmartAccountConfig configuration, we created above. We then await the initialisation of the account and log out two values to out terminal: the owner of the account and the smart account address. The owner should be your signer and the smart account address will be a new address referring to the address of this wallet.

```typescript
const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig)
const biconomySmartAccount = await biconomyAccount.init()
console.log("owner: ", biconomySmartAccount.owner)
console.log("address: ", biconomySmartAccount.address)
let biconomySmartAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()
const address = await biconomySmartAccount.getSmartAccountAddress()
console.log("address", address)
``
82 changes: 42 additions & 40 deletions docs/Biconomy AA Stack/Account/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ The ```common``` package is needed by our accounts package as another dependency
| paymaster | You can pass the same paymaster instance that you have built in the previous step. Alternatively, you can skip this if you are not interested in sponsoring transactions using Paymaster |
| | Note: if you don't pass the Paymaster instance, your Smart Contract Account will need funds to pay for transaction fees.|
| bundler | You can pass the same bundler instance that you have built in the previous step. Alternatively, you can skip this if you are only interested in building ```userOp```|

| entryPointAddress | Entry point address for chain, you can use the DEFAULT_ENTRYPOINT_ADDRESS here |
| defaultValidationModule | Validation module to initialize with this should be either ECDSA or Multi chain |
| activeValidationModule | Validation module to initialize with this should be either ECDSA or Multi chain and this can be changed later once you activate further modules |

:::info
We are utilizing Ethers to pass the signer during initialization. However, it's worth mentioning that you have the flexibility to obtain the signer from various other SDKs. Some popular options include Web3.js, Wagmi React hooks, as well as authentication providers like Particle, Web3Auth, Magic, and many others.
Expand All @@ -59,46 +61,46 @@ We are utilizing Ethers to pass the signer during initialization. However, it's
```typescript
// This is how you create BiconomySmartAccount instance in your dapp's

import { BiconomySmartAccount, BiconomySmartAccountConfig } from "@biconomy/account"

// Note that paymaster and bundler are optional. You can choose to create new instances of this later and make account API use
const biconomySmartAccountConfig: BiconomySmartAccountConfig = {
signer: wallet.getSigner(),
chainId: ChainId.POLYGON_MAINNET,
rpcUrl: '',
// paymaster: paymaster, // check the README.md section of Paymaster package
// bundler: bundler, // check the README.md section of Bundler package
}

const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig)
import { BiconomySmartAccountV2, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account"
import { ECDSAOwnershipValidationModule, DEFAULT_ECDSA_OWNERSHIP_MODULE } from "@biconomy/modules";
import { ChainId } from "@biconomy/core-types"
import { IBundler, Bundler } from '@biconomy/bundler'
import { IPaymaster, BiconomyPaymaster } from '@biconomy/paymaster'

// create instance of bundler
const bundler: IBundler = new Bundler({
//https://dashboard.biconomy.io/ get bundler urls from your dashboard
bundlerUrl: "",
chainId: ChainId.POLYGON_MUMBAI,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
})


// create instance of paymaster
const paymaster: IPaymaster = new BiconomyPaymaster({
//https://dashboard.biconomy.io/ get paymaster urls from your dashboard
paymasterUrl: ""
})

// instance of ownership module - this can alternatively be the multi chain module
const ownerShipModule = new ECDSAOwnershipValidationModule({
signer: {}, // ethers signer object
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

const biconomySmartAccountConfig = {
signer: {}, //ethers signer object
chainId: ChainId.POLYGON_MUMBAI, //or any chain of your choice
bundler: bundler, // instance of bundler
paymaster: paymaster, // instance of paymaster
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS, //entry point address for chain
defaultValidationModule: ownerShipModule, // either ECDSA or Multi chain to start
activeValidationModule: ownerShipModule // either ECDSA or Multi chain to start
}

const biconomyAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
const biconomySmartAccount = await biconomyAccount.init()
const address = await biconomySmartAccount.getSmartAccountAddress()

// native token transfer
// you can create any sort of transaction following same structure
const transaction = {
to: '0x85B51B068bF0fefFEFD817882a14f6F5BDF7fF2E',
data: '0x',
value: ethers.utils.parseEther('0.1'),
}

// building partialUserOp
const partialUserOp = await biconomySmartAccount.buildUserOp([transaction])

// using the paymaster package one can populate paymasterAndData to partial userOp. by default it is '0x'


```

```typescript
const userOpResponse = await smartAccount.sendUserOp(partialUserOp)
const transactionDetails = await userOpResponse.wait()
console.log("transaction details below")
console.log(transactionDetails)
```
Finally, we send the ```userOp``` and save the value to a variable named ```userOpResponse``` and get the ```transactionDetails``` after calling ```userOpResponse.wait()```

```typescript
const transactionDetails = await userOpResponse.wait()
console.log("transaction details below")
console.log(transactionDetails)
```
8 changes: 8 additions & 0 deletions docs/Biconomy AA Stack/Modules/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Modules",
"position": 4,
"link": {
"type": "generated-index",
"description": "Learn more about Validation Modules available with the Biconomy SDK"
}
}
17 changes: 17 additions & 0 deletions docs/Biconomy AA Stack/Modules/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
sidebar_position: 1
---
# Description

With the upgrade to the Biconomy Smart Account V2 our smart accounts no longer store ownership information and no longer have a default algorithm for validating signatures. This allows for more easily building modules that contain arbitrary Validation logic before executing user operations.

Custom Validation algorithms are one of the the key features of Account Abstraction and open up the ability to provide better customized user experiences in your wallets and dApps.

Refer to the chart below for the modules currently available with the Biconomy SDK:

| Module | Description | Address |
| -------- | ----------- | ------------------- |
| ECDSA Ownership Module | This module relies on ECDSA. The EOA owners public key is needed to sign and verify a message. This can also be used as default and active validation modules. | 0x0000001c5b32F37F5beA87BDD5374eB2aC54eA8e |
| MultiChain Validation Module | This module is an extenstion of the ECDSA Module. In addition to the ECSA functionality this module allows for dispatching multiple userOps to different EVM chains. Can be used in place of ECDSA Module as default and active validation modules. | 0x000000824dc138db84FD9109fc154bdad332Aa8E |
| Session Key Manager Module | This module enables the use of sessions with session validation modules which can be deployed at different addresses. The validation modules themselves do not get implemented as modules but can be managed by this one. This can only be used as an active validation module. | 0x000000456b395c4e107e0302553B90D1eF4a32e9 |
| Batched Session Router Module | This module works with Session Ket Manager Module. Normally only one session key signed userOp could be executed, this module allows for multiple session operations. | 0x000008dA71757C0E1D83CE56c823e25Aa49bC058 |
Loading

0 comments on commit 09745ca

Please sign in to comment.