Skip to content

Commit

Permalink
Merge pull request #54 from pimlicolabs/feat/get-required-prefund
Browse files Browse the repository at this point in the history
define api key in env variables
  • Loading branch information
plusminushalf authored Dec 15, 2023
2 parents 3d8fd61 + 92afce7 commit da162e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion test/userOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const buildUserOp = async (
): Promise<UserOperation> => {
await new Promise((resolve) => {
setTimeout(() => {
// wait for prev user op to be added to make sure ew get correct nonce
// wait for prev user op to be added to make sure we get correct nonce
resolve(0)
}, 1000)
})
Expand Down
54 changes: 24 additions & 30 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
Hex,
createPublicClient,
createWalletClient,
defineChain,
encodeFunctionData
} from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { goerli, polygonMumbai } from "viem/chains"
import * as allChains from "viem/chains"

export const getFactoryAddress = () => {
Expand All @@ -46,7 +46,21 @@ export const getTestingChain = () => {
}

// Otherwise, use fallback to goerli
return goerli
return defineChain({
id: 1337,
network: "goerli",
name: "Goerli",
nativeCurrency: { name: "Goerli Ether", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: {
http: ["http://0.0.0.0:3000"]
},
public: {
http: ["http://0.0.0.0:3000"]
}
},
testnet: true
})
}

export const getSignerToSimpleSmartAccount = async () => {
Expand Down Expand Up @@ -104,19 +118,14 @@ export const getSmartAccountClient = async ({
account,
sponsorUserOperation
}: SponsorUserOperationMiddleware & { account?: SmartAccount } = {}) => {
if (!process.env.PIMLICO_API_KEY)
throw new Error("PIMLICO_API_KEY environment variable not set")
if (!process.env.PIMLICO_BUNDLER_RPC_HOST)
throw new Error("PIMLICO_BUNDLER_RPC_HOST environment variable not set")
const pimlicoApiKey = process.env.PIMLICO_API_KEY
if (!process.env.BUNDLER_RPC_HOST)
throw new Error("BUNDLER_RPC_HOST environment variable not set")
const chain = getTestingChain()

return createSmartAccountClient({
account: account ?? (await getSignerToSimpleSmartAccount()),
chain,
transport: http(
`${process.env.PIMLICO_BUNDLER_RPC_HOST}?apikey=${pimlicoApiKey}`
),
transport: http(`${process.env.BUNDLER_RPC_HOST}`),
sponsorUserOperation
})
}
Expand Down Expand Up @@ -152,36 +161,26 @@ export const getPublicClient = async () => {
}

export const getBundlerClient = () => {
if (!process.env.PIMLICO_API_KEY)
throw new Error("PIMLICO_API_KEY environment variable not set")
if (!process.env.PIMLICO_BUNDLER_RPC_HOST)
throw new Error("PIMLICO_BUNDLER_RPC_HOST environment variable not set")
const pimlicoApiKey = process.env.PIMLICO_API_KEY
if (!process.env.BUNDLER_RPC_HOST)
throw new Error("BUNDLER_RPC_HOST environment variable not set")

const chain = getTestingChain()

return createBundlerClient({
chain: chain,
transport: http(
`${process.env.PIMLICO_BUNDLER_RPC_HOST}?apikey=${pimlicoApiKey}`
)
transport: http(`${process.env.BUNDLER_RPC_HOST}`)
})
}

export const getPimlicoBundlerClient = () => {
if (!process.env.PIMLICO_BUNDLER_RPC_HOST)
throw new Error("PIMLICO_BUNDLER_RPC_HOST environment variable not set")
if (!process.env.PIMLICO_API_KEY)
throw new Error("PIMLICO_API_KEY environment variable not set")
const pimlicoApiKey = process.env.PIMLICO_API_KEY

const chain = getTestingChain()

return createPimlicoBundlerClient({
chain: chain,
transport: http(
`${process.env.PIMLICO_BUNDLER_RPC_HOST}?apikey=${pimlicoApiKey}`
)
transport: http(`${process.env.PIMLICO_BUNDLER_RPC_HOST}`)
})
}

Expand All @@ -190,17 +189,12 @@ export const getPimlicoPaymasterClient = () => {
throw new Error(
"PIMLICO_PAYMASTER_RPC_HOST environment variable not set"
)
if (!process.env.PIMLICO_API_KEY)
throw new Error("PIMLICO_API_KEY environment variable not set")
const pimlicoApiKey = process.env.PIMLICO_API_KEY

const chain = getTestingChain()

return createPimlicoPaymasterClient({
chain: chain,
transport: http(
`${process.env.PIMLICO_PAYMASTER_RPC_HOST}?apikey=${pimlicoApiKey}`
)
transport: http(`${process.env.PIMLICO_PAYMASTER_RPC_HOST}`)
})
}

Expand Down

0 comments on commit da162e2

Please sign in to comment.