Skip to content

Commit

Permalink
feat: Send ETH from vault to user for testing flow
Browse files Browse the repository at this point in the history
  • Loading branch information
wryonik committed Oct 3, 2024
1 parent f7c4a39 commit a0a11f0
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions src/components/burnerWallet/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import "viem/window";
import {
ENTRYPOINT_ADDRESS_V07,
} from "permissionless";
import { ENTRYPOINT_ADDRESS_V07 } from "permissionless";
import {
createPimlicoBundlerClient,
// createPimlicoPaymasterClient,
} from "permissionless/clients/pimlico";
import {
Address,
createWalletClient,
encodeAbiParameters,
keccak256,
parseAbiParameters,
parseEther,
publicActions,
WalletClient,
} from "viem";
import { createPublicClient, http } from "viem";
import {

Check warning on line 18 in src/components/burnerWallet/deploy.ts

View workflow job for this annotation

GitHub Actions / eslint

`../../../contracts.base-sepolia.json` import should occur after import of `viem/ens`

Check warning on line 18 in src/components/burnerWallet/deploy.ts

View workflow job for this annotation

GitHub Actions / eslint

`../../../contracts.base-sepolia.json` import should occur after import of `viem/ens`
universalEmailRecoveryModule,
validatorsAddress,
} from "../../../contracts.base-sepolia.json";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";
import { normalize } from "viem/ens"; // For ENS name normalization

Check failure on line 24 in src/components/burnerWallet/deploy.ts

View workflow job for this annotation

GitHub Actions / eslint

'normalize' is defined but never used

Check failure on line 24 in src/components/burnerWallet/deploy.ts

View workflow job for this annotation

GitHub Actions / eslint

'normalize' is defined but never used

export const publicClient = createPublicClient({
transport: http("https://sepolia.base.org"),
});

export const pimlicoBundlerClient = createPimlicoBundlerClient({
transport: http(
`https://api.pimlico.io/v2/base-sepolia/rpc?apikey=${import.meta.env.VITE_PIMLICO_API_KEY}`,
`https://api.pimlico.io/v2/base-sepolia/rpc?apikey=${import.meta.env.VITE_PIMLICO_API_KEY}`
),
entryPoint: ENTRYPOINT_ADDRESS_V07,
});
Expand All @@ -45,7 +49,7 @@ export async function run(
client: WalletClient,
safeAccount: object,
smartAccountClient: object,
guardianAddr: string,
guardianAddr: string
) {
const ownableValidatorAddress = validatorsAddress;

Check failure on line 54 in src/components/burnerWallet/deploy.ts

View workflow job for this annotation

GitHub Actions / eslint

'ownableValidatorAddress' is assigned a value but never used

Check failure on line 54 in src/components/burnerWallet/deploy.ts

View workflow job for this annotation

GitHub Actions / eslint

'ownableValidatorAddress' is assigned a value but never used
// Universal Email Recovery Module with
Expand All @@ -61,13 +65,37 @@ export async function run(
}); // Cast the result to string[]
const [address] = addresses;

const PRIVATE_KEY = import.meta.env.VITE_VAULT_PRIVATE_KEY as Address;
const QUICKNODE_ENDPOINT =
`https://base-sepolia.g.alchemy.com/v2/${import.meta.env.VITE_ALCHEMY_API_KEY}` as string;

// In the below if block, we are sending ETHs to the user so that they can test the flow without spending their own ETHs
if (PRIVATE_KEY) {
// Convert the private key to an account object
const vaultAccount = privateKeyToAccount(PRIVATE_KEY);
// Create a wallet client with the specified account, chain, and HTTP transport
const walletClient = createWalletClient({
vaultAccount,
chain: baseSepolia,
transport: http(QUICKNODE_ENDPOINT),
}).extend(publicActions);

const ethAmount = parseEther("0.0004"); // Doing a bit extra to cover gas costs failure

// Send the transaction to the resolved ENS address
await walletClient.sendTransaction({
account: vaultAccount,
to: address,
value: ethAmount,
});
}

// generate hash
await client.sendTransaction({
to: safeAccount.address,
value: parseEther("0.0003"),
});


// txHash
await smartAccountClient.sendTransaction({
to: address,
Expand All @@ -81,7 +109,7 @@ export async function run(
const account: `0x${string}` = safeAccount.address as `0x${string}`;
const isInstalledContext = new Uint8Array([0]);
const functionSelector = keccak256(
new TextEncoder().encode("swapOwner(address,address,address)"),
new TextEncoder().encode("swapOwner(address,address,address)")
).slice(0, 10);
const guardians = [guardianAddr];
const guardianWeights = [1];
Expand All @@ -91,7 +119,7 @@ export async function run(

const callData = encodeAbiParameters(
parseAbiParameters(
"address, bytes, bytes4, address[], uint256[], uint256, uint256, uint256",
"address, bytes, bytes4, address[], uint256[], uint256, uint256, uint256"
),
[
account,
Expand All @@ -104,7 +132,7 @@ export async function run(
threshold.toString(),
delay.toString(),
expiry.toString(),
],
]
);

// acceptanceSubjectTemplates -> [["Accept", "guardian", "request", "for", "{ethAddr}"]]
Expand Down

0 comments on commit a0a11f0

Please sign in to comment.