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

Enable gas estimation and paymaster of user-op builder service for updated smart-session module #705

Merged
merged 19 commits into from
Sep 18, 2024
Merged
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
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 @@ -83,6 +83,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