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

chore: release v4.6.1 #578

Merged
merged 3 commits into from
Sep 17, 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
25 changes: 25 additions & 0 deletions .github/workflows/test-playground.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: test-playground
on:
workflow_dispatch:
push:
branches:
- test/*
jobs:
test-playground:
name: test-playground
permissions: write-all
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v3

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Run the tests
run: bun run test:ci -t=Playground
env:
E2E_PRIVATE_KEY_ONE: ${{ secrets.E2E_PRIVATE_KEY_ONE }}
TESTING: true
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @biconomy/account

## 4.6.2

### Patch Changes

- Temporary removal of DAN

## 4.6.1

### Patch Changes

- Taiko testnet fix

## 4.5.5

### Patch Changes
Expand All @@ -13,6 +25,7 @@
- Distributed Session Keys

## 4.5.3

## 4.6.0

### Minor Changes
Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sideEffects": false,
"name": "@biconomy/account",
"author": "Biconomy",
"version": "4.6.0",
"version": "4.6.2",
"description": "SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.",
"keywords": [
"erc-7579",
Expand Down Expand Up @@ -120,7 +120,6 @@
"commit-msg": "npx --no -- commitlint --edit ${1}"
},
"dependencies": {
"@silencelaboratories/walletprovider-sdk": "^0.1.0",
"merkletreejs": "^0.4.0"
}
}
6 changes: 4 additions & 2 deletions src/account/BaseSmartContractAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export enum DeploymentState {

export abstract class BaseSmartContractAccount<
TSigner extends SmartAccountSigner = SmartAccountSigner
> implements ISmartContractAccount<TSigner>
{
> implements ISmartContractAccount<TSigner> {
protected factoryAddress: Address

protected deploymentState: DeploymentState = DeploymentState.UNDEFINED
Expand Down Expand Up @@ -209,6 +208,7 @@ export abstract class BaseSmartContractAccount<
}

async getInitCode(): Promise<Hex> {

if (this.deploymentState === DeploymentState.DEPLOYED) {
return "0x"
}
Expand All @@ -228,12 +228,14 @@ export abstract class BaseSmartContractAccount<
}

async getAddress(): Promise<Address> {

if (!this.accountAddress) {
const initCode = await this._getAccountInitCode()
Logger.log("[BaseSmartContractAccount](getAddress) initCode: ", initCode)
try {
await this.entryPoint.simulate.getSenderAddress([initCode])
} catch (err: any) {

Logger.log(
"[BaseSmartContractAccount](getAddress) getSenderAddress err: ",
err
Expand Down
110 changes: 69 additions & 41 deletions src/account/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type GetContractReturnType,
type Hex,
type PublicClient,
type WalletClient,
concat,
concatHex,
createPublicClient,
Expand All @@ -21,6 +22,7 @@ import {
toBytes,
toHex,
} from "viem";
import { taikoHekla } from "viem/chains";
import type { IBundler } from "../bundler/IBundler.js";
import {
Bundler,
Expand All @@ -35,7 +37,6 @@ import {
type SessionType,
createECDSAOwnershipValidationModule,
getBatchSessionTxParams,
getDanSessionTxParams,
getSingleSessionTxParams
} from "../modules"
import type { ISessionStorage } from "../modules/interfaces/ISessionStorage.js"
Expand Down Expand Up @@ -75,6 +76,7 @@ import {
MAGIC_BYTES,
NATIVE_TOKEN_ALIAS,
PROXY_CREATION_CODE,
TAIKO_FACTORY_ADDRESS,
} from "./utils/Constants.js";
import type {
BalancePayload,
Expand Down Expand Up @@ -146,23 +148,31 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
private constructor(
readonly biconomySmartAccountConfig: BiconomySmartAccountV2ConfigConstructorProps,
) {

const chain = biconomySmartAccountConfig.viemChain ??
biconomySmartAccountConfig.customChain ??
getChain(biconomySmartAccountConfig.chainId)

const rpcClient = biconomySmartAccountConfig.rpcUrl ||
getChain(biconomySmartAccountConfig.chainId).rpcUrls.default.http[0]

const defaultedFactoryAddress = chain?.id === taikoHekla.id ? TAIKO_FACTORY_ADDRESS :
biconomySmartAccountConfig.factoryAddress ??
DEFAULT_BICONOMY_FACTORY_ADDRESS;

const isDefaultFactory = [DEFAULT_BICONOMY_FACTORY_ADDRESS, TAIKO_FACTORY_ADDRESS].some(address => addressEquals(defaultedFactoryAddress, address));

super({
...biconomySmartAccountConfig,
chain:
biconomySmartAccountConfig.viemChain ??
biconomySmartAccountConfig.customChain ??
getChain(biconomySmartAccountConfig.chainId),
rpcClient:
biconomySmartAccountConfig.rpcUrl ||
getChain(biconomySmartAccountConfig.chainId).rpcUrls.default.http[0],
chain,
rpcClient,
entryPointAddress:
(biconomySmartAccountConfig.entryPointAddress as Hex) ??
DEFAULT_ENTRYPOINT_ADDRESS,
accountAddress:
(biconomySmartAccountConfig.accountAddress as Hex) ?? undefined,
factoryAddress:
biconomySmartAccountConfig.factoryAddress ??
DEFAULT_BICONOMY_FACTORY_ADDRESS,
defaultedFactoryAddress,
});

this.sessionData = biconomySmartAccountConfig.sessionData
Expand Down Expand Up @@ -194,10 +204,12 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {

this.bundler = biconomySmartAccountConfig.bundler;


const defaultFallbackHandlerAddress =
this.factoryAddress === DEFAULT_BICONOMY_FACTORY_ADDRESS
isDefaultFactory
? DEFAULT_FALLBACK_HANDLER_ADDRESS
: biconomySmartAccountConfig.defaultFallbackHandler;

if (!defaultFallbackHandlerAddress) {
throw new Error("Default Fallback Handler address is not provided");
}
Expand All @@ -212,14 +224,8 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
biconomySmartAccountConfig.activeValidationModule!;

this.provider = createPublicClient({
chain:
biconomySmartAccountConfig.viemChain ??
biconomySmartAccountConfig.customChain ??
getChain(biconomySmartAccountConfig.chainId),
transport: http(
biconomySmartAccountConfig.rpcUrl ||
getChain(biconomySmartAccountConfig.chainId).rpcUrls.default.http[0]
)
chain,
transport: http(rpcClient)
})

this.scanForUpgradedAccountsFromV1 =
Expand Down Expand Up @@ -705,10 +711,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
}
}

const counterFactualAddressV2 = await this.getCounterFactualAddressV2({
validationModule,
index,
});
const counterFactualAddressV2 = await this.getCounterFactualAddressV2({ validationModule, index });
return counterFactualAddressV2;
}

Expand All @@ -720,13 +723,31 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
const index = params?.index ?? this.index;

try {

const owner = validationModule.getAddress()
const moduleSetupData = (await validationModule.getInitData()) as Hex

if (this.chainId === taikoHekla.id) {

const factoryContract = getContract({
address: TAIKO_FACTORY_ADDRESS,
abi: BiconomyFactoryAbi,
client: { public: this.provider, wallet: this.getSigner() as unknown as WalletClient }
})

const smartAccountAddressFromContracts =
await factoryContract.read.getAddressForCounterFactualAccount([owner, moduleSetupData, BigInt(index)])

return smartAccountAddressFromContracts
}

const initCalldata = encodeFunctionData({
abi: BiconomyAccountAbi,
functionName: "init",
args: [
this.defaultFallbackHandlerAddress,
validationModule.getAddress() as Hex,
(await validationModule.getInitData()) as Hex,
owner,
moduleSetupData,
],
});

Expand Down Expand Up @@ -845,15 +866,15 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* Return the value to put into the "initCode" field, if the account is not yet deployed.
* This value holds the "factory" address, followed by this account's information
*/
async getAccountInitCode(): Promise<Hex> {
public override async getAccountInitCode(): Promise<Hex> {

this.isDefaultValidationModuleDefined();

if (await this.isAccountDeployed()) return "0x";

return concatHex([
this.factoryAddress as Hex,
(await this.getFactoryData()) ?? "0x",
]);
const factoryData = await this.getFactoryData() as Hex;

return concatHex([this.factoryAddress, factoryData]);
}

/**
Expand Down Expand Up @@ -1317,6 +1338,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
userOp: Partial<UserOperationStruct>,
stateOverrideSet?: StateOverrideSet,
): Promise<Partial<UserOperationStruct>> {

if (!this.bundler) throw new Error("Bundler is not provided");
const requiredFields: UserOperationKey[] = [
"sender",
Expand All @@ -1336,12 +1358,17 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
maxFeePerGas,
maxPriorityFeePerGas,
} = await this.bundler.estimateUserOpGas(userOp, stateOverrideSet);



// if neither user sent gas fee nor the bundler, estimate gas from provider
if (
!userOp.maxFeePerGas &&
!userOp.maxPriorityFeePerGas &&
(!maxFeePerGas || !maxPriorityFeePerGas)
) {


const feeData = await this.provider.estimateFeesPerGas();
if (feeData.maxFeePerGas?.toString()) {
finalUserOp.maxFeePerGas = `0x${feeData.maxFeePerGas.toString(
Expand Down Expand Up @@ -1609,11 +1636,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
if (!defaultedChain) throw new Error("Chain is not provided")

if (this.sessionType === "DISTRIBUTED_KEY") {
return getDanSessionTxParams(
defaultedConditionalSession,
defaultedChain,
correspondingIndex
)
// return getDanSessionTxParams(
// defaultedConditionalSession,
// defaultedChain,
// correspondingIndex
// )
}
if (this.sessionType === "BATCHED") {
return getBatchSessionTxParams(
Expand Down Expand Up @@ -1694,6 +1721,8 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
dummySignatureFetchPromise,
]);

const sender = await this.getAccountAddress() as Hex

if (transactions.length === 0) {
throw new Error("Transactions array cannot be empty");
}
Expand All @@ -1708,7 +1737,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
}

let userOp: Partial<UserOperationStruct> = {
sender: (await this.getAccountAddress()) as Hex,
sender,
nonce: toHex(nonceFromFetch),
initCode,
callData,
Expand Down Expand Up @@ -2115,14 +2144,13 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {

this.isDefaultValidationModuleDefined();

const defaultValidationModuleAddress = this.defaultValidationModule.getAddress();
const defaultValidationInitData = await this.defaultValidationModule.getInitData();

return encodeFunctionData({
abi: BiconomyFactoryAbi,
functionName: "deployCounterFactualAccount",
args: [
this.defaultValidationModule.getAddress() as Hex,
(await this.defaultValidationModule.getInitData()) as Hex,
BigInt(this.index),
],
args: [defaultValidationModuleAddress, defaultValidationInitData, BigInt(this.index)],
});
}

Expand Down
7 changes: 1 addition & 6 deletions src/account/utils/Constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Hex } from "viem"
import type {
BiconomyFactories,
BiconomyFactoriesByVersion,
BiconomyImplementations,
BiconomyImplementationsByVersion,
EntryPointAddresses,
Expand All @@ -22,6 +21,7 @@ export const ENTRYPOINT_ADDRESSES: EntryPointAddresses = {
}

// will always be latest factory address
export const TAIKO_FACTORY_ADDRESS = "0x000008B3078bA5ed444FFf7658F76385F6004e7A"; //https://biconomyworkspace.slack.com/archives/C061BSA9279/p1721234773541039
export const DEFAULT_BICONOMY_FACTORY_ADDRESS =
"0x000000a56Aaca3e9a4C479ea6b6CD0DbcB6634F5"
export const DEFAULT_FALLBACK_HANDLER_ADDRESS =
Expand All @@ -47,11 +47,6 @@ export const ENTRYPOINT_ADDRESSES_BY_VERSION: EntryPointAddressesByVersion = {
V0_0_6: "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"
}

export const BICONOMY_FACTORY_ADDRESSES_BY_VERSION: BiconomyFactoriesByVersion =
Object.fromEntries(
Object.entries(BICONOMY_FACTORY_ADDRESSES).map(([k, v]) => [v, k])
)

export const BICONOMY_IMPLEMENTATION_ADDRESSES_BY_VERSION: BiconomyImplementationsByVersion =
Object.fromEntries(
Object.entries(BICONOMY_IMPLEMENTATION_ADDRESSES).map(([k, v]) => [v, k])
Expand Down
Loading
Loading