Skip to content

Commit

Permalink
Enable gas estimation and paymaster of user-op builder service for up…
Browse files Browse the repository at this point in the history
…dated smart-session module (#705)

* add getDummySignature impl

* chore:run prettier

* update @biconomy/permission-context-builder deps

* use chain specific module address

* add base-sepolia to supported chains data

* chores: run prettier

* update @rhinestone/module-kit deps

* use SMART_SESSION_ADDRESS from module-sdk

* impl ContextBuilderUtil using module-sdk

* enable safeSmartAccount on sepolia and baseSepolia

* added smart-session support on base-sepolia

* attest and install modules in single userOp

* chores: run prettier

* update co-signer handling and url

* chores: move constants to single source

* return smartAccount on allowed chains

* display smartAccount on requested chains only

* chores:run prettier
  • Loading branch information
KannuSingh authored Sep 18, 2024
1 parent c062f18 commit 49eaccd
Show file tree
Hide file tree
Showing 24 changed files with 1,140 additions and 615 deletions.
5 changes: 2 additions & 3 deletions advanced/wallets/react-wallet-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"prettier:write": "prettier --write '**/*.{js,ts,jsx,tsx}'"
},
"dependencies": {
"@biconomy/permission-context-builder": "^1.0.9",
"@cosmjs/amino": "0.32.3",
"@cosmjs/encoding": "0.32.3",
"@cosmjs/proto-signing": "0.32.3",
Expand All @@ -29,7 +28,7 @@
"@nextui-org/react": "1.0.8-beta.5",
"@polkadot/keyring": "^10.1.2",
"@polkadot/types": "^9.3.3",
"@rhinestone/module-sdk": "0.1.2",
"@rhinestone/module-sdk": "0.1.16",
"@solana/web3.js": "1.89.2",
"@taquito/signer": "^15.1.0",
"@taquito/taquito": "^15.1.0",
Expand Down Expand Up @@ -71,4 +70,4 @@
"prettier": "2.6.2",
"typescript": "5.2.2"
}
}
}
4 changes: 2 additions & 2 deletions advanced/wallets/react-wallet-v2/src/consts/smartAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { KernelSmartAccountLib } from '@/lib/smart-accounts/KernelSmartAccountLib'
import { SafeSmartAccountLib } from '@/lib/smart-accounts/SafeSmartAccountLib'
import { getAddress } from 'viem'
import { goerli, polygonMumbai, sepolia } from 'viem/chains'
import { baseSepolia, goerli, polygonMumbai, sepolia } from 'viem/chains'

// Types
export const allowedChains = [sepolia, polygonMumbai, goerli]
export const allowedChains = [sepolia, polygonMumbai, goerli, baseSepolia]
// build chains so I can access them by id
export const chains = allowedChains.reduce((acc, chain) => {
acc[chain.id] = chain
Expand Down
9 changes: 9 additions & 0 deletions advanced/wallets/react-wallet-v2/src/data/EIP155Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ export const EIP155_TEST_CHAINS: Record<string, EIP155Chain> = {
namespace: 'eip155',
smartAccountEnabled: true
},
'eip155:84532': {
chainId: 84532,
name: 'Base Sepolia',
logo: '/chain-logos/eip155-1.png',
rgb: '99, 125, 234',
rpc: 'https://sepolia.base.org',
namespace: 'eip155',
smartAccountEnabled: true
},
'eip155:43113': {
chainId: 43113,
name: 'Avalanche Fuji',
Expand Down
76 changes: 76 additions & 0 deletions advanced/wallets/react-wallet-v2/src/data/EIP7715Data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
import { Address } from 'viem'

/**
* EIP7715Method
*/
export const EIP7715_METHOD = {
WALLET_GRANT_PERMISSIONS: 'wallet_grantPermissions'
}

// `data` is not necessary for this signer type as the wallet is both the signer and grantor of these permissions
export type WalletSigner = {
type: 'wallet'
data: {}
}

// A signer representing a single key.
// `id` is a did:key identifier and can therefore represent both Secp256k1 or Secp256r1 keys, among other key types.
export type KeySigner = {
type: 'key'
data: {
id: string
}
}

// A signer representing a multisig signer.
// Each element of `ids` is a did:key identifier just like the `key` signer.
export type MultiKeySigner = {
type: 'keys'
data: {
ids: string[]
address?: Address
}
}

// An account that can be granted with permissions as in ERC-7710.
export type AccountSigner = {
type: 'account'
data: {
id: `0x${string}`
}
}

export enum SignerType {
EOA,
PASSKEY
}

export type Signer = {
type: SignerType
data: string
}

export type Permission = {
type: PermissionType
policies: Policy[]
required: boolean
data: any
}
export type Policy = {
type: PolicyType
data: any
}
export type PermissionType =
| 'native-token-transfer'
| 'erc20-token-transfer'
| 'erc721-token-transfer'
| 'erc1155-token-transfer'
| {
custom: any
}
export type PolicyType =
| 'gas-limit'
| 'call-limit'
| 'rate-limit'
| 'spent-limit'
| 'value-limit'
| 'time-frame'
| 'uni-action'
| 'simpler-signer'
| {
custom: any
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { smartSessionAddress } from '@biconomy/permission-context-builder'
import { ModuleType } from '@rhinestone/module-sdk'
//Note: ES6 syntax dont work for this package
const {
SMART_SESSIONS_ADDRESS,
MULTI_FACTOR_VALIDATOR_ADDRESS,
OWNABLE_VALIDATOR_ADDRESS,
WEBAUTHN_VALIDATOR_ADDRESS,
Expand Down Expand Up @@ -31,7 +31,7 @@ export const supportedModules: Module[] = [
name: 'Permission Validator',
type: 'validator',
url: '/permission-validator',
moduleAddress: smartSessionAddress,
moduleAddress: SMART_SESSIONS_ADDRESS,
description: `The Permission Validator module is a module that allows DApp to request permissions from a wallet in order to execute transactions on users's behalf that is scoped with permissions`,
moduleData: '0x'
},
Expand Down
23 changes: 22 additions & 1 deletion advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EIP155Chain } from '@/data/EIP155Data'
import SettingsStore from '@/store/SettingsStore'
import {
createOrRestoreBiconomySmartAccount,
Expand Down Expand Up @@ -51,8 +52,28 @@ export default function useSmartAccounts() {
return accounts
}

const getAvailableSmartAccountsOnNamespaceChains = (chains: string[] | undefined) => {
if (!smartAccountEnabled || chains === undefined) {
return []
}
const accounts = []
for (const [key, lib] of Object.entries(smartAccountWallets)) {
accounts.push({
address: key.split(':')[1],
type: lib.type,
chain: lib.chain
})
}

const filteredAccounts = accounts.filter(account =>
chains.some(chain => chain && parseInt(chain.split(':')[1]) === account.chain.id)
)
return filteredAccounts
}

return {
initializeSmartAccounts,
getAvailableSmartAccounts
getAvailableSmartAccounts,
getAvailableSmartAccountsOnNamespaceChains
}
}
Loading

0 comments on commit 49eaccd

Please sign in to comment.