Smart Contract Wallet - Zerodev
Polynomial core contracts supports Account Abstracted (AA) Wallets based on ERC 4337. Currently we uses Zerodev as our primary AA provider and this docs will be containing configurations and examples of using zerodev Smart contract wallets for trade in Polynomial perps.
It is not mandatory to use AA wallets to trade on polynomial. But txs from AA wallet will be sponsored. You can save gas fees by using AA wallets rather than directly interacting with your EOA.
Bundler and Paymaster config
bundlerAPI: 'https://polynomial-mainnet.g.alchemy.com/v2/nUkjX-R-WfZwctQu_TLm0xQ7KI8TVXaD',
paymasterAPI: 'https://polynomial-mainnet.g.alchemy.com/v2/nUkjX-R-WfZwctQu_TLm0xQ7KI8TVXaD',
policy: '14119bab-6c62-4fed-8fe7-27ad5fcc5754'
Sample Code Snippets
AA client Setup (Typescript)
Uses Wagmi , Viem and zerodev sdk
import { getWalletClient } from '@wagmi/core';
import { signerToEcdsaValidator, getKernelAddressFromECDSA } from '@zerodev/ecdsa-validator';
import {createPublicClient} from 'viem';
import {
addressToEmptyAccount,
createKernelAccount,
createKernelAccountClient
} from '@zerodev/sdk';
const client = await getWalletClient(wagmiConfig);
const publicClient = createPublicClient({
transport: http(getZeroDevBundlerRPC(chain.id, true, ZERODEV_PROVIDER)),
chain: chain
});
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
signer: client,
entryPoint,
kernelVersion: KERNEL_V3_1
});
const account = await createKernelAccount(publicClient, {
plugins: {
sudo: ecdsaValidator
},
entryPoint,
index: 8008n,
kernelVersion: "0.3.1"
});
const aaClient = createKernelAccountClient({
account,
chain,
pollingInterval: 500,
bundlerTransport: http(getZeroDevBundlerRPC(chain.id, false, ZERODEV_PROVIDER)),
paymaster: {
getPaymasterData(userOperation) {
return sponsorUserOperationPolynomial({
userOperation,
entryPoint,
chain
});
}
},
userOperation: {
estimateFeesPerGas() {
return {
maxFeePerGas: 0n,
maxPriorityFeePerGas: 0n
};
}
}
});
SponsorUserOperation function
Transaction Execution through Zerodev
Last updated
Was this helpful?