From e3569f384aa3f929f704815e3e6a28a343290b7f Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:19:24 +0400 Subject: [PATCH] session key comments --- src/components/Modules/CreateSession.tsx | 2 +- ....tsx => CreateSessionsWithBatchRouter.tsx} | 0 ...sfer.tsx => ERC20TransferUsingSession.tsx} | 47 ++++++++++--------- ...outerTransfer.tsx => UseSessionsBatch.tsx} | 0 src/components/TabsBody.tsx | 6 +-- 5 files changed, 30 insertions(+), 25 deletions(-) rename src/components/Modules/{CreateBatchRouter.tsx => CreateSessionsWithBatchRouter.tsx} (100%) rename src/components/Modules/{ERC20Transfer.tsx => ERC20TransferUsingSession.tsx} (61%) rename src/components/Modules/{ERC20RouterTransfer.tsx => UseSessionsBatch.tsx} (100%) diff --git a/src/components/Modules/CreateSession.tsx b/src/components/Modules/CreateSession.tsx index aec4aa0..3fbc349 100644 --- a/src/components/Modules/CreateSession.tsx +++ b/src/components/Modules/CreateSession.tsx @@ -69,7 +69,7 @@ const CreateSession: React.FC = () => { // If you have session key-pair on the client side you can keep using those without making part of any storage window.localStorage.setItem("sessionPKey", sessionSigner.privateKey); - // Create an instanbce of Session Key Manager module from modules package + // Create an instance of Session Key Manager module from modules package // This module is responsible for below tasks/helpers: // a. Maintain session leaf storage in defined storage client (Biconomy by default using browser local storage which works for front-end apps) // b. Generate dummy signature for userOp estimations diff --git a/src/components/Modules/CreateBatchRouter.tsx b/src/components/Modules/CreateSessionsWithBatchRouter.tsx similarity index 100% rename from src/components/Modules/CreateBatchRouter.tsx rename to src/components/Modules/CreateSessionsWithBatchRouter.tsx diff --git a/src/components/Modules/ERC20Transfer.tsx b/src/components/Modules/ERC20TransferUsingSession.tsx similarity index 61% rename from src/components/Modules/ERC20Transfer.tsx rename to src/components/Modules/ERC20TransferUsingSession.tsx index a7656fd..a5e178b 100644 --- a/src/components/Modules/ERC20Transfer.tsx +++ b/src/components/Modules/ERC20TransferUsingSession.tsx @@ -12,6 +12,7 @@ import { showErrorMessage, } from "../../utils"; import { DEFAULT_SESSION_KEY_MANAGER_MODULE } from "@biconomy/modules"; +import { ERC20_SESSION_VALIDATION_MODULE } from "../../utils/chainConfig"; const ERC20Transfer: React.FC = () => { const classes = useStyles(); @@ -27,8 +28,8 @@ const ERC20Transfer: React.FC = () => { try { setLoading(true); let biconomySmartAccount = smartAccount; - const managerModuleAddr = DEFAULT_SESSION_KEY_MANAGER_MODULE; - const erc20ModuleAddr = "0x000000D50C68705bd6897B2d17c7de32FB519fDA"; + const sessionKeyManagerModuleAddr = DEFAULT_SESSION_KEY_MANAGER_MODULE; + const erc20SessionValidationModuleAddr = ERC20_SESSION_VALIDATION_MODULE; // get session key from local storage const sessionKeyPrivKey = window.localStorage.getItem("sessionPKey"); @@ -40,15 +41,17 @@ const ERC20Transfer: React.FC = () => { const sessionSigner = new ethers.Wallet(sessionKeyPrivKey); console.log("sessionSigner", sessionSigner); - // generate sessionModule - const sessionModule = await SessionKeyManagerModule.create({ - moduleAddress: managerModuleAddr, + // generate sessionManagerModule + const sessionManagerModule = await SessionKeyManagerModule.create({ + moduleAddress: sessionKeyManagerModuleAddr, smartAccountAddress: scwAddress, }); - // set active module to sessionModule + // set active module to sessionManagerModule + // This time we will make use of enabled session hence transaction needs to via go through session manager module + // Hence it is set as runtime active module biconomySmartAccount = - biconomySmartAccount.setActiveValidationModule(sessionModule); + biconomySmartAccount.setActiveValidationModule(sessionManagerModule); const tokenContract = new ethers.Contract( config.usdc.address, @@ -64,36 +67,38 @@ const ERC20Transfer: React.FC = () => { } const { data } = await tokenContract.populateTransaction.transfer( - "0x42138576848E839827585A3539305774D36B9602", // receiver address + "0x42138576848E839827585A3539305774D36B9602", // receiver address // Has to be the same receiver for which session permissions are set ethers.utils.parseUnits("5".toString(), decimals) ); - // TODO // get these from config // generate tx data to erc20 transfer + // NOTE: It can only be used for single transaction and not part of batch calldata + // If you want to make use of batch calldata then you need to use the session router module const tx1 = { - to: "0xdA5289fCAAF71d52a80A254da614a192b693e977", //erc20 token address + to: config.usdc.address, //erc20 token address data: data, value: "0", }; // build user op + // with calldata to transfer ERC20 tokens let userOp = await biconomySmartAccount.buildUserOp([tx1], { - overrides: { - // signature: "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000456b395c4e107e0302553b90d1ef4a32e9000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000db3d753a1da5a6074a9f74f39a0a779d3300000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000080000000000000000000000000bfe121a6dcf92c49f6c2ebd4f306ba0ba0ab6f1c000000000000000000000000da5289fcaaf71d52a80a254da614a192b693e97700000000000000000000000042138576848e839827585a3539305774d36b96020000000000000000000000000000000000000000000000000000000002faf08000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041feefc797ef9e9d8a6a41266a85ddf5f85c8f2a3d2654b10b415d348b150dabe82d34002240162ed7f6b7ffbc40162b10e62c3e35175975e43659654697caebfe1c00000000000000000000000000000000000000000000000000000000000000" - // callGasLimit: 2000000, // only if undeployed account - // verificationGasLimit: 700000 - }, - skipBundlerGasEstimation: false, + skipBundlerGasEstimation: false, // can skip this if paymasterServiceData is being provided for sponsorship mode + // These are required (as query params in session storage) to be able to find the leaf and generate proof for the dummy signature (which is in turn used for estimating gas values) params: { sessionSigner: sessionSigner, - sessionValidationModule: erc20ModuleAddr, + sessionValidationModule: erc20SessionValidationModuleAddr, }, }); - // send user op - const userOpResponse = await biconomySmartAccount.sendUserOp(userOp, { + // send user operation + const userOpResponse = await biconomySmartAccount.sendUserOp(userOp, + // below params are required for passing on this information to session key manager module to create padded signature + { sessionSigner: sessionSigner, - sessionValidationModule: erc20ModuleAddr, + sessionValidationModule: erc20SessionValidationModuleAddr, + // optionally can also provide simulationType + simulationType: 'validation_and_execution' }); console.log("userOpHash", userOpResponse); @@ -117,7 +122,7 @@ const ERC20Transfer: React.FC = () => {
- This is an example gasless transaction to transfer ERC20 tokens. + This is an example to transfer ERC20 tokens makin use of enabled session.