import { ethers } from 'ethers'; import AA0xGasless from '../index'; import {erc721_abi} from "./ERC721_ABI" import {erc20_abi} from "./ERC20_ABI" import { ClientOptions, TelegramClientOptions } from '../types'; import AA0xGaslessTG from '../AA0xGaslessTG'; require('dotenv').config(); const getChainName = async (chainId: number) => { switch (chainId) { case 137: return "polygon"; case 5: return "goerli"; case 80001: return "mumbai"; case 421613: return "arbitrum-goerli"; case 11155111: return "sepolia"; case 420: return "optimism-goerli"; case 59140: return "linea-testnet"; case 84531: return "base-goerli" case 534353: return "scroll-alpha-testnet" default: return null; } }; interface testERC721Obj { [key: number]: string; 80001: string; 421613: string; 5: string; } const testERC721:testERC721Obj = { 80001: "0x58295cDc01393955C6A4697ab1C6e54A08202939", 421613: "0xA95BF21f4Ca098ee22948F4fFB4229cFa272Cd5a", 5: "0x36602D6Ff67DBdfA258A1Fbc0f589A91b0059276", 250: "0xA4ED9640Bcdc3cA97eE93dd14596A8da4eFfCDa6", 1284: "0x28470A8D2d62d60C138a3ED3e57aBa1289ff050f" } describe('AA0xGasless SDK', () => { let provider:any; let wallet: any; const options: ClientOptions = { privateKey: process.env.PRIVATE_KEY, // chainId: 421613, //arb goerli // rpcUrl: process.env.ARB_GOERLI_RPC, // chainId: 5, // rpcUrl: process.env.GOERLI_RPC, chainId: 80001, rpcUrl: process.env.MUMBAI_RPC, // chainId: 250, // rpcUrl: process.env.FANTOM_RPC, // chainId: 1284, // rpcUrl: process.env.MOONBEAM_RPC, isSponsoredTrx: true } beforeEach(() => { //@ts-ignore wallet = new ethers.Wallet(process.env.PRIVATE_KEY); provider = new ethers.providers.JsonRpcProvider(options.rpcUrl); }) it.skip('create account successfully', async () => { const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); //@ts-ignore const address = await sdk.init(provider,options); console.log("address", address); console.log(ethers.utils.hashMessage("hello world")); console.log("wallet", wallet.address) const signature = await wallet.signMessage("hello world"); console.log("sig",signature); }, 80000); it('send transaction gasless', async () => { // Arrange const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); // options.bundlerEndpoint = "http://51.21.1.40:14337/5" // options.bundlerEndpoint="https://api.pimlico.io/v1/mumbai/rpc?apikey=6ba6f689-d06d-4c66-b501-c8b531f2ef89" options.bundlerEndpoint="https://bundler.0xgasless.com/80001" options.paymaster = '0xGasless'; options.paymasterEndpoint = "http://localhost:3000/v1/80001/rpc?apiKey=0xGS-f946752b56dea20e9309297e35dd3ac8ec2cad02a5aa48b7dad2d364e74b89c3" options.paymasterId = "0x4d7ea53a8bf9cbc32d3df125bd31dfa3f3d6f08063ae933f636be61e660f76e7"; options.erc20token = "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97" const address = await sdk.init(provider,options); console.log("smart account address", address); const contractAddress = testERC721[options.chainId]; const abi = erc721_abi const erc721Contract = new ethers.Contract(contractAddress, abi); const trx = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const contractAddress2 = "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97"; const abi2= erc20_abi; const erc20Contract = new ethers.Contract(contractAddress2, abi2); const trx2 = { target: contractAddress2 as `0x${string}`, data: erc20Contract.interface.encodeFunctionData("approve", ["0x4b1D3D2bbbf209F5994c385032C8f4e949348ADA", "100000000"]) as `0x${string}` } const userOpHash = await sdk.sendUserOp(trx); console.log("userOpHash",userOpHash); // expect(userOpHash.userOpHash).toHaveLength(66) }, 80000); it.skip('send transaction gasless by providing bundler endpoint', async () => { const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); const chain = await getChainName(options.chainId); //ETHERSPOT options.bundlerEndpoint = `https://arbitrumgoerli-bundler.etherspot.io/` //Voltaire // options.bundlerEndpoint = `https://goerli.voltaire.candidewallet.com/rpc` const address = await sdk.init(provider,options); console.log("smart account address", address); //arb goerli // const contractAddress = "0xA95BF21f4Ca098ee22948F4fFB4229cFa272Cd5a"; const contractAddress = testERC721[options.chainId];//"0x58295cDc01393955C6A4697ab1C6e54A08202939"; const abi = erc721_abi const erc721Contract = new ethers.Contract(contractAddress, abi); const trx = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const userOpHash = await sdk.sendUserOp(trx); console.log("userOpHash",userOpHash); expect(userOpHash.userOpHash).toHaveLength(66) }, 80000) it.skip('send transaction gasless by providing paymaster endpoint', async () => { const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); const chain = await getChainName(options.chainId); // PIMLICO PAYMASTER // options.paymaster='PIMLICO'; // options.paymasterEndpoint=`https://api.pimlico.io/v1/${chain}/rpc?apikey=${process.env.PIMLICO_PM_API_KEY}` //STACKUP PAYMASTER ARB GOERLI options.paymasterEndpoint = "https://api.stackup.sh/v1/paymaster/f207eaba85a875cc344d0ddae82430a56bf8ff04472c621f8d36e1c194f2f81b" options.paymaster = 'STACKUP'; const address = await sdk.init(provider,options); console.log("smart account address", address); const contractAddress = "0xA95BF21f4Ca098ee22948F4fFB4229cFa272Cd5a"; const abi = erc721_abi const erc721Contract = new ethers.Contract(contractAddress, abi); const trx = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const userOpHash = await sdk.sendUserOp(trx); console.log("userOpHash",userOpHash); expect(userOpHash.userOpHash).toHaveLength(66) }, 80000); it.skip('send bactch transaction gasless ERC20', async () => { // Arrange const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); const address = await sdk.init(provider,options); console.log("smart account address", address); const contractAddress = "0x6EFC3817b0536Ca6fA75f58F42F148cfccBe9f92"; const abi = erc20_abi; const erc20Contract = new ethers.Contract(contractAddress, abi); const trx1 = { target: contractAddress as `0x${string}`, data: erc20Contract.interface.encodeFunctionData("mint", ["1000000"]) as `0x${string}` } const trx2 = { target: contractAddress as `0x${string}`, data: erc20Contract.interface.encodeFunctionData("approve", ["0x9fD431b7703f94289Ba02034631dcC302717805B", "1000000"]) as `0x${string}` } const userOpHash = await sdk.sendUserOpsBatch([trx1, trx2]); console.log("userOpHash",userOpHash); expect(userOpHash.userOpHash).toHaveLength(66) }, 80000); it.skip('send bactch transaction gasless ERC721', async () => { // Arrange const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); const address = await sdk.init(provider,options); console.log("smart account address", address); const contractAddress = "0xA95BF21f4Ca098ee22948F4fFB4229cFa272Cd5a"; const abi = erc721_abi const erc721Contract = new ethers.Contract(contractAddress, abi); const trx1 = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const trx2 = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const userOpHash = await sdk.sendUserOpsBatch([trx1,trx2]); console.log("userOpHash",userOpHash); expect(userOpHash.userOpHash).toHaveLength(66) }, 80000); it.skip('add funds to entry point from EOA on behalf of AA', async () => { // Arrange const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); const address = await sdk.init(provider,options); console.log("smart account address", address); const trxReceipt = await sdk.addFundsToEntryPoint("10000000000000"); console.log("trxReceipt",trxReceipt); // expect(userOpHash.userOpHash).toHaveLength(66) }, 80000); it.skip('withdraw funds from entry point to EOA', async () => { // Arrange const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); const address = await sdk.init(provider,options); console.log("smart account address", address); const toAddress = "0x9fD431b7703f94289Ba02034631dcC302717805B" const trxReceipt = await sdk.withdrawFundsFromEntryPoint(toAddress,"100"); console.log("trxReceipt",trxReceipt); // expect(userOpHash.userOpHash).toHaveLength(66) }, 80000); const tgOptions: TelegramClientOptions = { telegramUserId: "6732034940", walletAddress: "0x78695de2c38aca313c7acb26c2d28dc959809a52", chainId: 421613, //arb goerli rpcUrl: process.env.ARB_GOERLI_RPC, isSponsoredTrx: true } it.skip('prepare userop for gasless tx using telegram module', async () => { const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGaslessTG(apiKey); const address = await sdk.init(provider,tgOptions); console.log("smart account address", address); const contractAddress = "0xA95BF21f4Ca098ee22948F4fFB4229cFa272Cd5a"; const abi = erc721_abi const erc721Contract = new ethers.Contract(contractAddress, abi); const trx = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const data = await sdk.prepareUserOp(trx); const requestId = data.requestId; const otpSent = data.otpSent; console.log("prepareUserOp",requestId,otpSent); expect(otpSent).toEqual("success") }, 80000); it.skip('send requesId and OTP for sending gasless tx using telegram module', async () => { const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGaslessTG(apiKey); const address = await sdk.init(provider,tgOptions); //get it from above test case const requestId = "6542b332b8d49b84bb57b4be"; const otp = "132003"; const resHash = await sdk.sendUserOp(requestId, otp); console.log("resHash",resHash); expect(resHash.userOpHash).toHaveLength(66); }, 80000); it.skip('prepare userop for gasless batch txs using telegram module', async () => { const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGaslessTG(apiKey); const address = await sdk.init(provider,tgOptions); console.log("smart account address", address); const contractAddress = "0xA95BF21f4Ca098ee22948F4fFB4229cFa272Cd5a"; const abi = erc721_abi const erc721Contract = new ethers.Contract(contractAddress, abi); const trx1 = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const trx2 = { target: contractAddress as `0x${string}`, data: erc721Contract.interface.encodeFunctionData("safeMint", ["0x9fD431b7703f94289Ba02034631dcC302717805B"]) as `0x${string}` } const data = await sdk.prepareUserOpBatch([trx1,trx2]); const requestId = data.requestId; const otpSent = data.otpSent; console.log("prepareUserOp",requestId,otpSent); expect(otpSent).toEqual("success") }, 80000); it.skip('get userop receipt by userophash', async () => { const apiKey = process.env.API_KEY || ""; const sdk = new AA0xGasless(apiKey); const address = await sdk.init(provider,options); const userOpHash = "0x574b64726c1fa87bd3c8b2316d4cf8c6ef7878cdf385f0d768ba54437fd8c320"; const chainId = 421613 const receipt = await sdk.getTrxReceiptByUserOpHash(userOpHash ,chainId ); console.log("receipt",receipt.transactionHash); }, 80000); });