Skip to content

Commit

Permalink
type magic
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed May 22, 2024
1 parent 47eb42b commit f278fd7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
26 changes: 11 additions & 15 deletions examples/4337-gas-metering/gelato/gelato.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from 'dotenv'
import { Address, Hash, PublicClient, createPublicClient, http, zeroAddress } from 'viem'
import { Address, Hash, PublicClient, createPublicClient, http, zeroAddress, type Transport } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { baseSepolia, sepolia } from 'viem/chains'
import { getAccountAddress, getGelatoAccountInitCode, getGelatoCallData, prepareForGelatoTx } from '../utils/safe'
Expand Down Expand Up @@ -50,23 +50,19 @@ if (!privateKey) {
throw new Error('Please populate .env file with demo Private Key. Recommended to not use your personal private key.')
}

// Check if the network is supported.
if (chain != 'sepolia' && chain != 'base-sepolia') {
throw new Error('Current code only support limited networks. Please make required changes if you want to use custom network.')
}

const signer = privateKeyToAccount(privateKey as Hash)
console.log('Signer Extracted from Private Key.')

let publicClient: PublicClient
if (chain == 'sepolia') {
publicClient = createPublicClient({
transport: http(rpcURL),
chain: sepolia,
})
} else if (chain == 'base-sepolia') {
publicClient = createPublicClient({
transport: http(rpcURL),
chain: baseSepolia,
}) as PublicClient
} else {
throw new Error('Current code only support limited networks. Please make required changes if you want to use custom network.')
}
const viemChain = chain === 'sepolia' ? sepolia : baseSepolia
const publicClient = createPublicClient({
transport: http(rpcURL),
chain: viemChain,
})

// Creating the Account Init Code.
let requestData = await getGelatoAccountInitCode({
Expand Down
2 changes: 1 addition & 1 deletion examples/4337-gas-metering/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"outDir": "./dist" /* Redirect output structure to the directory. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */
},
"exclude": ["node_modules"]
"include": ["./alchemy/**/*", "./gelato/**/*", "./pimlico/**/*", "./utils/**/*"]
}
9 changes: 5 additions & 4 deletions examples/4337-gas-metering/utils/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { InternalTx, encodeMultiSend } from './multisend'
import { generateApproveCallData, generateTransferCallData, getERC20Balance, getERC20Decimals, mintERC20Token } from './erc20'
import { setTimeout } from 'timers/promises'
import { baseSepolia, sepolia } from 'viem/chains'
import { generateMintingCallData } from './erc721'
import { transferETH } from './nativeTransfer'
import {
Expand Down Expand Up @@ -48,7 +49,7 @@ export const getGelatoCallData = async ({
}: {
safe: Address
owner: PrivateKeyAccount
publicClient: PublicClient<Transport<"http">, Chain>
publicClient: PublicClient<Transport<"http">, typeof sepolia | typeof baseSepolia>
txType: string
erc20TokenAddress: Address
erc721TokenAddress: Address
Expand Down Expand Up @@ -187,7 +188,7 @@ const getGelatoInitializerCode = async ({
erc721TokenAddress,
}: {
owner: Address
client: PublicClient
client: PublicClient<Transport<"http">, typeof sepolia | typeof baseSepolia>
txType: string
safeModuleSetupAddress: Address
safe4337ModuleAddress: Address
Expand Down Expand Up @@ -252,7 +253,7 @@ export const prepareForGelatoTx = async ({
}: {
signer: PrivateKeyAccount
chain: string
publicClient: PublicClient
publicClient: PublicClient<Transport<"http">, typeof sepolia | typeof baseSepolia>
txType: string
senderAddress: Address
erc20TokenAddress: Address
Expand Down Expand Up @@ -354,7 +355,7 @@ export const getGelatoAccountInitCode = async ({
erc721TokenAddress,
}: {
owner: Address
client: PublicClient
client: PublicClient<Transport<"http">, typeof sepolia | typeof baseSepolia>
txType: string
safeModuleSetupAddress: Address
safe4337ModuleAddress: Address
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f278fd7

Please sign in to comment.