Skip to content

Commit

Permalink
chore: fix getAddress (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler authored Dec 5, 2024
1 parent d1cb310 commit f1157cb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @biconomy/sdk

## 0.0.13

### Patch Changes

- Fix getAddress()

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/sdk",
"version": "0.0.12",
"version": "0.0.13",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
Expand Down
58 changes: 53 additions & 5 deletions src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,13 @@ export const toNexusAccount = async (
args: [signerAddress, index, [], 0]
})

let _accountAddress: Address | undefined = parameters.accountAddress

/**
* @description Gets the init code for the account
* @returns The init code as a hexadecimal string
*/
const getInitCode = () => concatHex([factoryAddress, factoryData])

let _accountAddress: Address | undefined = parameters.accountAddress
/**
* @description Gets the counterfactual address of the account
* @returns The counterfactual address
Expand All @@ -233,12 +232,61 @@ export const toNexusAccount = async (
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
} catch (e: any) {
if (e?.cause?.data?.errorName === "SenderAddressResult") {
_accountAddress = e?.cause.data.args[0] as Address
if (!addressEquals(_accountAddress, zeroAddress)) {
return _accountAddress
const accountAddressFromError = e?.cause.data.args[0] as Address
if (!addressEquals(accountAddressFromError, zeroAddress)) {
_accountAddress = accountAddressFromError
return accountAddressFromError
}
}
}

const addressFromFactory = (await publicClient.readContract({
address: factoryAddress,
abi: [
{
inputs: [
{
internalType: "address",
name: "eoaOwner",
type: "address"
},
{
internalType: "uint256",
name: "index",
type: "uint256"
},
{
internalType: "address[]",
name: "attesters",
type: "address[]"
},
{
internalType: "uint8",
name: "threshold",
type: "uint8"
}
],
name: "computeAccountAddress",
outputs: [
{
internalType: "address payable",
name: "expectedAddress",
type: "address"
}
],
stateMutability: "view",
type: "function"
}
],
functionName: "computeAccountAddress",
args: [signerAddress, index, [], 0]
})) as Address

if (!addressEquals(addressFromFactory, zeroAddress)) {
_accountAddress = addressFromFactory
return addressFromFactory
}

throw new Error("Failed to get counterfactual account address")
}

Expand Down

0 comments on commit f1157cb

Please sign in to comment.