-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { | ||
MOCK_ATTESTER_ADDRESS, | ||
RHINESTONE_ATTESTER_ADDRESS | ||
} from "@rhinestone/module-sdk/module" | ||
import type { Address } from "viem" | ||
import type { PublicClient } from "viem" | ||
import { k1ValidatorFactoryAddress } from "../../constants" | ||
|
||
/** | ||
* Get the counterfactual address of a signer | ||
* | ||
* @param publicClient - The public client to use for the read contract | ||
* @param signerAddress - The address of the signer | ||
* @param index - The index of the account | ||
* @param isTestnet - Whether the network is testnet | ||
* @param attesters - The attesters to use | ||
* @param threshold - The threshold of the attesters | ||
* @param factoryAddress - The factory address to use | ||
* @returns The counterfactual address | ||
* | ||
* @example | ||
* ```ts | ||
* const counterFactualAddress = await getCounterFactualAddress(publicClient, signerAddress) | ||
* ``` | ||
*/ | ||
export const getCounterFactualAddress = async ( | ||
publicClient: PublicClient, | ||
signerAddress: Address, | ||
isTestnet = false, | ||
index = 0n, | ||
attesters = [RHINESTONE_ATTESTER_ADDRESS], | ||
threshold = 1, | ||
factoryAddress = k1ValidatorFactoryAddress | ||
) => { | ||
if (isTestnet) { | ||
attesters.push(MOCK_ATTESTER_ADDRESS) | ||
} | ||
|
||
return 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, attesters, threshold] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters