-
Notifications
You must be signed in to change notification settings - Fork 3
SDK upgrade with the ModularEtherspotWalletFactory contracts (on all chains) with latest IHook #65
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
Changes from all commits
0fa69d5
b73ff31
5219a88
1d89ed1
c3d6b03
1d82f1e
5c20e25
8c48d01
aa2afe1
96ee7a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { printOp } from '../../src/sdk/common/OperationUtils'; | ||
import * as dotenv from 'dotenv'; | ||
import { MODULE_TYPE, sleep } from '../../src/sdk/common'; | ||
import { encodeAbiParameters, encodeFunctionData, Hex, parseAbi } from 'viem'; | ||
import { generateModularSDKInstance } from '../helpers/sdk-helper'; | ||
import { getHookMultiPlexerInitData } from '../pulse/utils'; | ||
import { accountAbi } from '../../src/sdk/common/abis'; | ||
|
||
dotenv.config(); | ||
|
||
const bundlerApiKey = 'etherspot_public_key'; | ||
const CHAIN_ID = '1'; | ||
const HOOK_MULTIPLEXER_ADDRESS = '0xDcA918dd23456d321282DF9507F6C09A50522136'; | ||
|
||
// tsx examples/modules/install-hook.ts | ||
async function main() { | ||
// Init SDK | ||
const modularSdk = generateModularSDKInstance( | ||
process.env.WALLET_PRIVATE_KEY as string, | ||
Number(CHAIN_ID), | ||
bundlerApiKey, | ||
); | ||
|
||
// Get counterfactual of ModularEtherspotWallet... | ||
const address: Hex = (await modularSdk.getCounterFactualAddress()) as Hex; | ||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`); | ||
// Get native balance | ||
const balance = await modularSdk.getNativeBalance(); | ||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet native balance: ${balance}`); | ||
// Clear existing UserOps from batch | ||
await modularSdk.clearUserOpsFromBatch(); | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
INSTALL HOOK MULTIPLEXER WITH CREDIBLE ACCOUNT MODULE - AS HOOK | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
//Get HookMultiPlexer init data with CredibleAccountHook as global subhook | ||
let hmpInitData = getHookMultiPlexerInitData([]); | ||
const hmpInstallCalldata = encodeFunctionData({ | ||
abi: parseAbi(accountAbi), | ||
functionName: 'installModule', | ||
args: [BigInt(MODULE_TYPE.HOOK), HOOK_MULTIPLEXER_ADDRESS, hmpInitData], | ||
}); | ||
// // Add UserOp to batch | ||
await modularSdk.addUserOpsToBatch({ to: address, data: hmpInstallCalldata }); | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
ESTIMATE/SEND USER OP | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
// Estimate UserOp | ||
const op = await modularSdk.estimate(); | ||
console.log(`Estimate UserOp: ${await printOp(op)}`); | ||
// Send UserOp | ||
const uoHash = await modularSdk.send(op); | ||
console.log(`UserOpHash: ${uoHash}`); | ||
// Await transaction hash | ||
console.log('Waiting for transaction...'); | ||
let userOpsReceipt = null; | ||
const timeout = Date.now() + 1200000; // 1 minute timeout | ||
while (userOpsReceipt == null && Date.now() < timeout) { | ||
await sleep(2); | ||
userOpsReceipt = await modularSdk.getUserOpReceipt(uoHash); | ||
} | ||
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as dotenv from 'dotenv'; | ||
import { MODULE_TYPE } from '../../src/sdk/common'; | ||
import { generateModularSDKInstance } from '../helpers/sdk-helper'; | ||
|
||
dotenv.config(); | ||
|
||
// tsx examples/modules/is-module-installed.ts | ||
async function main() { | ||
const bundlerApiKey = 'etherspot_public_key'; | ||
|
||
console.log(`inside is-module-installed script:`); | ||
|
||
// initializating sdk for index 0... | ||
const modularSdk = generateModularSDKInstance( | ||
process.env.WALLET_PRIVATE_KEY, | ||
Number(process.env.CHAIN_ID), | ||
bundlerApiKey | ||
);// Testnets dont need apiKey on bundlerProvider | ||
|
||
// get address of EtherspotWallet | ||
const address: string = await modularSdk.getCounterFactualAddress(); | ||
|
||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`); | ||
|
||
const isModuleInstalled = await modularSdk.isModuleInstalled(MODULE_TYPE.VALIDATOR, '0xFE14F6d4e407850b24D160B9ACfBb042D32BE492'); | ||
console.log(`isModuleInstalled: ${isModuleInstalled}`); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -76,6 +76,18 @@ export class EtherspotWalletAPI extends BaseAccountAPI { | |||||||||||||||||||||||||||||||||||||||||||
return response as boolean; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
async isModuleInitialised(moduleTypeId: MODULE_TYPE, module: string, initData = '0x'): Promise<boolean> { | ||||||||||||||||||||||||||||||||||||||||||||
const accountAddress = await this.getAccountAddress(); | ||||||||||||||||||||||||||||||||||||||||||||
if (!accountAddress) throw new Error('Account address not found'); | ||||||||||||||||||||||||||||||||||||||||||||
const response = await this.publicClient.readContract({ | ||||||||||||||||||||||||||||||||||||||||||||
address: accountAddress as Hex, | ||||||||||||||||||||||||||||||||||||||||||||
abi: parseAbi(accountAbi), | ||||||||||||||||||||||||||||||||||||||||||||
functionName: 'isModuleInstalled', | ||||||||||||||||||||||||||||||||||||||||||||
args: [moduleTypeId, module, initData] | ||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||
return response as boolean; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+79
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainClarify the purpose of This new method appears to be an exact duplicate of the existing Options to resolve:
async isModuleInitialised(moduleTypeId: MODULE_TYPE, module: string, initData = '0x'): Promise<boolean> {
const accountAddress = await this.getAccountAddress();
if (!accountAddress) throw new Error('Account address not found');
const response = await this.publicClient.readContract({
address: accountAddress as Hex,
abi: parseAbi(accountAbi),
- functionName: 'isModuleInstalled',
+ functionName: 'isModuleInitialised', // or the correct function name
args: [moduleTypeId, module, initData]
});
return response as boolean;
}
+ /**
+ * Alias for isModuleInstalled for backward compatibility
+ */
async isModuleInitialised(moduleTypeId: MODULE_TYPE, module: string, initData = '0x'): Promise<boolean> {
- const accountAddress = await this.getAccountAddress();
- if (!accountAddress) throw new Error('Account address not found');
- const response = await this.publicClient.readContract({
- address: accountAddress as Hex,
- abi: parseAbi(accountAbi),
- functionName: 'isModuleInstalled',
- args: [moduleTypeId, module, initData]
- });
- return response as boolean;
+ return this.isModuleInstalled(moduleTypeId, module, initData);
} Check if the contract has a separate 🏁 Script executed: #!/bin/bash
# Description: Check if the account ABI contains isModuleInitialised function
# Expected: Should show if this function exists in the contract
echo "=== Checking for isModuleInitialised in account ABI ==="
rg -A 5 -B 5 "isModuleInitialised" src/sdk/common/abis.ts
echo "=== Checking usage of this new method ==="
rg "isModuleInitialised" --type ts -A 3 -B 3 Length of output: 896 Clarify the purpose of The account ABI ( • If you meant to call a different on‐chain function, update the + /**
+ * Alias for isModuleInstalled (kept for backward compatibility).
+ */
async isModuleInitialised(
moduleTypeId: MODULE_TYPE,
module: string,
initData = '0x'
): Promise<boolean> {
- const accountAddress = await this.getAccountAddress();
- if (!accountAddress) throw new Error('Account address not found');
- const response = await this.publicClient.readContract({
- address: accountAddress as Hex,
- abi: parseAbi(accountAbi),
- functionName: 'isModuleInstalled',
- args: [moduleTypeId, module, initData]
- });
- return response as boolean;
+ return this.isModuleInstalled(moduleTypeId, module, initData);
} Please choose one of these resolutions so the code’s intent matches its implementation. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
async installModule(moduleTypeId: MODULE_TYPE, module: string, initData = '0x'): Promise<string> { | ||||||||||||||||||||||||||||||||||||||||||||
const accountAddress = await this.getAccountAddress(); | ||||||||||||||||||||||||||||||||||||||||||||
if (!accountAddress) throw new Error('Account address not found'); | ||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the filename and comment inconsistency.
There's a mismatch between the filename (
is-module-initialised.ts
) and the comment (is-module-installed
). The script actually callsisModuleInstalled
, so the filename should reflect what it's actually doing.Apply this diff to fix the comment:
Or consider renaming the file to
is-module-installed.ts
if that better reflects the intended functionality.📝 Committable suggestion
🤖 Prompt for AI Agents