+
+ {!!hasSession ? (
+
+ ) : (
+
+ )}
+
+
+ );
+};
+
+const useStyles = makeStyles(() => ({
+ main: {
+ margin: "auto",
+ padding: "10px 40px",
+ color: "#EEEEEE",
+ },
+ subTitle: {
+ color: "#FFB999",
+ fontSize: 36,
+ margin: 0,
+ },
+ h3Title: {
+ color: "#e6e6e6",
+ },
+ listHover: {
+ "&:hover": {
+ color: "#FF9551",
+ },
+ },
+}));
+
+export default CreateSession;
diff --git a/src/components/Modules/CreateSessionForCustomSVM.tsx b/src/components/Modules/CreateSessionForCustomSVM.tsx
deleted file mode 100644
index 883f730..0000000
--- a/src/components/Modules/CreateSessionForCustomSVM.tsx
+++ /dev/null
@@ -1,241 +0,0 @@
-import React, { useEffect, useState } from "react";
-import { makeStyles } from "@mui/styles";
-import { useAccount } from "wagmi";
-import {
- Hex,
- encodeAbiParameters,
- encodeFunctionData,
- getFunctionSelector,
- parseEther,
- slice,
-} from "viem";
-import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
-import { createSessionKeyManagerModule } from "@biconomy/account";
-import Button from "../Button";
-import { useSmartAccountContext } from "../../contexts/SmartAccountContext";
-import { CONTRACT_CALL_SESSION_VALIDATION_MODULE } from "../../utils/chainConfig";
-import { getActionForErrorMessage } from "../../utils/error-utils";
-import {
- configInfo as config,
- showErrorMessage,
- showSuccessMessage,
-} from "../../utils";
-import { managerModuleAddr } from "../../utils/constants";
-
-const CreateCustomSession: React.FC = () => {
- const classes = useStyles();
- const { address } = useAccount();
- const { scwAddress, smartAccount } = useSmartAccountContext();
- const [loading, setLoading] = useState(false);
- const [isSessionKeyModuleEnabled, setIsSessionKeyModuleEnabled] =
- useState(false);
-
- useEffect(() => {
- let checkSessionModuleEnabled = async () => {
- if (!scwAddress || !smartAccount || !address) {
- setIsSessionKeyModuleEnabled(false);
- return;
- }
- try {
- let biconomySmartAccount = smartAccount;
- const sessionKeyManagerModuleAddr = managerModuleAddr;
- // Checks if Session Key Manager module is enabled on the smart account.
- // Before using session keys this module must be enabled.
- // If not, createSession transaction will also enable this module along with storing session info on-chain.
- const isEnabled = await biconomySmartAccount.isModuleEnabled(
- sessionKeyManagerModuleAddr
- );
- console.log("isSessionKeyModuleEnabled", isEnabled);
- setIsSessionKeyModuleEnabled(isEnabled);
- return;
- } catch (err: any) {
- console.error(err);
- setLoading(false);
- setIsSessionKeyModuleEnabled(false);
- return;
- }
- };
- checkSessionModuleEnabled();
- }, [isSessionKeyModuleEnabled, scwAddress, smartAccount, address]);
-
- const createSession = async (enableSessionKeyModule: boolean) => {
- if (!scwAddress || !smartAccount || !address) {
- showErrorMessage("Please connect wallet first");
- return;
- }
- try {
- let biconomySmartAccount = smartAccount;
- const sessionKeyManagerModuleAddr = managerModuleAddr;
- const ccSessionValidationModuleAddr =
- CONTRACT_CALL_SESSION_VALIDATION_MODULE;
-
- // -----> setMerkle tree tx flow
- // create dapp side session key
- const sessionPKey = generatePrivateKey();
- const sessionSigner = privateKeyToAccount(sessionPKey);
- const sessionKeyEOA = sessionSigner.address;
- console.log("sessionKeyEOA", sessionKeyEOA);
-
- // Optional: JUST FOR DEMO: update local storage with session key
- // 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", sessionPKey);
-
- console.log("here it works ");
-
- // 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
- // c. Provides helpers to sign userOpHash with session key in the right format and generate proof for particular leaf
- const sessionManagerModule = await createSessionKeyManagerModule({
- moduleAddress: sessionKeyManagerModuleAddr,
- smartAccountAddress: scwAddress,
- });
-
- console.log("ever here? ");
-
- // Cretae session key data
- // Session key data is always corrsponding to the Session Validation Module being used
- // It always requires the public address of the session key
- // Rest of the details depends on the actual permissions
-
- const permission = [
- config.hyphenLP.address,
- slice(getFunctionSelector("addTokenLiquidity(address,uint256)"), 0, 4),
- ];
-
- const sessionKeyData = encodeAbiParameters(
- [
- { type: "address" },
- {
- type: "tuple",
- components: [{ type: "address" }, { type: "bytes4" }],
- },
- ],
- [sessionKeyEOA, [permission[0] as Hex, permission[1] as Hex]]
- );
-
- // Below helper gives you tx data to be used to make a call from Smart Account to enable session on-chain
- // This transaction needs a user signature and for gas sponsorship or ERC20 paymaster can be used.
- const sessionTxData = await sessionManagerModule.createSessionData([
- {
- validUntil: 0, // 0 value means extremes
- validAfter: 0, // 0 value means extremes
- sessionValidationModule: ccSessionValidationModuleAddr,
- sessionPublicKey: sessionKeyEOA,
- sessionKeyData: sessionKeyData,
- },
- // can optionally enable multiple leaves(sessions) altogether
- ]);
- console.log("sessionTxData", sessionTxData);
-
- // tx to set session key
- const tx2 = {
- to: sessionKeyManagerModuleAddr as Hex, // session manager module address
- value: BigInt(0),
- data: sessionTxData.data as Hex,
- };
-
- let transactionArray = [];
- if (enableSessionKeyModule) {
- // -----> enableModule session manager module
- const tx1 = await biconomySmartAccount.getEnableModuleData(
- sessionKeyManagerModuleAddr
- );
- transactionArray.push({
- to: tx1.to as Hex,
- value: BigInt(0),
- data: tx1.data as Hex,
- });
- }
- transactionArray.push(tx2);
-
- const approveCallData = encodeFunctionData({
- abi: config.usdc.abi,
- functionName: "approve",
- args: [config.hyphenLP.address, parseEther("100", "gwei")],
- });
- const tx3 = {
- to: config.usdc.address as Hex,
- value: BigInt(0),
- data: approveCallData,
- };
- transactionArray.push(tx3);
-
- // Building the user operation
- // If you're going to use sponsorship paymaster details can be provided at this step
- let userOpResponse = await smartAccount.sendTransaction(transactionArray);
- console.log("userOpHash", userOpResponse);
- const { transactionHash } = await userOpResponse.waitForTxHash();
- console.log("txHash", transactionHash);
- showSuccessMessage("Session Created Successfully", transactionHash);
- } catch (err: any) {
- console.error(err);
- setLoading(false);
- const errorAction = getActionForErrorMessage(err.message);
- showErrorMessage(
- errorAction || err.message || "Error in sending the transaction"
- );
- }
- };
-
- return (
-
-
- Use Cases {"->"} Session {"->"} Create Session
-
-
-
Create Session Flow
-
- {isSessionKeyModuleEnabled ? (
-
-
- Session Key Manager Module is already enabled ✅. Click on the
- button to create a new session.
-
-
- {
- createSession(false);
- }}
- />
-
- ) : (
-
-
- This is a single transaction to enable the sesion key manager module
- and make a session active on-chain using Contract call (ABI) session
- validation module.
-
-
- {
- createSession(true);
- }}
- />
-
- )}
-
- );
-};
-
-const useStyles = makeStyles(() => ({
- main: {
- padding: "10px 40px",
- color: "#EEEEEE",
- },
- subTitle: {
- color: "#FFB999",
- fontSize: 36,
- margin: 0,
- },
- h3Title: {
- color: "#e6e6e6",
- },
-}));
-
-export default CreateCustomSession;
diff --git a/src/components/Modules/ERC20TransferUsingSession.tsx b/src/components/Modules/ERC20TransferUsingSession.tsx
deleted file mode 100644
index 4ff04db..0000000
--- a/src/components/Modules/ERC20TransferUsingSession.tsx
+++ /dev/null
@@ -1,151 +0,0 @@
-import React, { useState } from "react";
-import { ethers } from "ethers";
-import { makeStyles } from "@mui/styles";
-
-import Button from "../Button";
-import { useSmartAccountContext } from "../../contexts/SmartAccountContext";
-import {
- configInfo as config,
- showSuccessMessage,
- showErrorMessage,
-} from "../../utils";
-import {
- DEFAULT_ERC20_MODULE,
- createSessionKeyManagerModule,
-} from "@biconomy/account";
-import { EthersSigner } from "@biconomy/account";
-import { useAccount } from "wagmi";
-import { managerModuleAddr } from "../../utils/constants";
-
-const ERC20Transfer: React.FC = () => {
- const classes = useStyles();
- const { smartAccount, scwAddress } = useSmartAccountContext();
- const { address } = useAccount();
- const [loading, setLoading] = useState(false);
-
- const erc20Transfer = async () => {
- if (!scwAddress || !smartAccount || !address) {
- showErrorMessage("Please connect wallet first");
- return;
- }
- try {
- setLoading(true);
- let biconomySmartAccount = smartAccount;
- const sessionKeyManagerModuleAddr = managerModuleAddr;
- const erc20SessionValidationModuleAddr = DEFAULT_ERC20_MODULE;
-
- // get session key from local storage
- const sessionKeyPrivKey = window.localStorage.getItem("sessionPKey");
-
- if (!sessionKeyPrivKey) {
- showErrorMessage("Session key not found");
- return;
- }
- const sessionSigner = new ethers.Wallet(sessionKeyPrivKey);
- console.log("sessionSigner", sessionSigner);
-
- const newSigner = new EthersSigner(sessionSigner, "ethers");
-
- // generate sessionManagerModule
- const sessionManagerModule = await createSessionKeyManagerModule({
- moduleAddress: sessionKeyManagerModuleAddr,
- smartAccountAddress: scwAddress,
- });
-
- // 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(sessionManagerModule);
-
- const tokenContract = new ethers.Contract(
- config.usdc.address,
- config.usdc.abi,
- sessionSigner
- );
- let decimals = 18;
-
- try {
- decimals = await tokenContract.decimals();
- } catch (error) {
- throw new Error("invalid token address supplied");
- }
-
- // @ts-ignore
- const { data } = await tokenContract.populateTransaction.transfer(
- "0x42138576848E839827585A3539305774D36B9602", // receiver address // Has to be the same receiver for which session permissions are set
- ethers.parseUnits("5".toString(), decimals)
- );
-
- // 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: config.usdc.address, //erc20 token address
- data: data,
- value: 0,
- };
-
- // send user operation
- const userOpResponse = await biconomySmartAccount.sendTransaction(
- tx1,
- // below params are required for passing on this information to session key manager module to create padded signature
- {
- params: {
- sessionSigner: newSigner,
- sessionValidationModule: erc20SessionValidationModuleAddr,
- },
- simulationType: "validation_and_execution",
- }
- );
-
- console.log("userOpHash", userOpResponse);
- const { transactionHash } = await userOpResponse.waitForTxHash();
- console.log("txHash", transactionHash);
- showSuccessMessage(`ERC20 Transfer ${transactionHash}`, transactionHash);
- setLoading(false);
- } catch (err: any) {
- console.error(err);
- setLoading(false);
- showErrorMessage(err.message || "Error in sending the transaction");
- }
- };
-
- return (
-
-
- Use Cases {"->"} Gasless {"->"} ERC20 Transfer
-
-
-
ERC20 Transfer via Session Key
-
-
- This is an example to transfer ERC20 tokens makin use of enabled
- session.
-
-
-
-
- );
-};
-
-const useStyles = makeStyles(() => ({
- main: {
- padding: "10px 40px",
- color: "#EEEEEE",
- },
- subTitle: {
- color: "#FFB999",
- fontSize: 36,
- margin: 0,
- },
- h3Title: {
- color: "#e6e6e6",
- },
-}));
-
-export default ERC20Transfer;
diff --git a/src/components/Modules/HyphenLpUsingSession.tsx b/src/components/Modules/HyphenLpUsingSession.tsx
deleted file mode 100644
index 40c1d44..0000000
--- a/src/components/Modules/HyphenLpUsingSession.tsx
+++ /dev/null
@@ -1,139 +0,0 @@
-import React, { useState } from "react";
-import { ethers } from "ethers";
-import { makeStyles } from "@mui/styles";
-
-import Button from "../Button";
-import { useSmartAccountContext } from "../../contexts/SmartAccountContext";
-import {
- configInfo as config,
- showSuccessMessage,
- showErrorMessage,
-} from "../../utils";
-import { createSessionKeyManagerModule } from "@biconomy/account";
-import { CONTRACT_CALL_SESSION_VALIDATION_MODULE } from "../../utils/chainConfig";
-import { EthersSigner } from "@biconomy/account";
-import { useAccount } from "wagmi";
-import { managerModuleAddr } from "../../utils/constants";
-import { parseUnits } from "viem";
-
-const HyphenLpUsingSession: React.FC = () => {
- const classes = useStyles();
- const { address } = useAccount();
- const { smartAccount, scwAddress } = useSmartAccountContext();
- const [loading, setLoading] = useState(false);
-
- const hyphenLpUsingSession = async () => {
- if (!scwAddress || !smartAccount || !address) {
- showErrorMessage("Please connect wallet first");
- return;
- }
- try {
- setLoading(true);
- let biconomySmartAccount = smartAccount;
- const sessionKeyManagerModuleAddr = managerModuleAddr;
- const ccSessionValidationModuleAddr =
- CONTRACT_CALL_SESSION_VALIDATION_MODULE;
-
- // get session key from local storage
- const sessionKeyPrivKey = window.localStorage.getItem("sessionPKey");
-
- if (!sessionKeyPrivKey) {
- showErrorMessage("Session key not found");
- return;
- }
- const sessionSigner = new ethers.Wallet(sessionKeyPrivKey);
- console.log("sessionSigner", sessionSigner);
-
- const newSigner = new EthersSigner(sessionSigner, "ethers");
-
- // generate sessionManagerModule
- const sessionManagerModule = await createSessionKeyManagerModule({
- moduleAddress: sessionKeyManagerModuleAddr,
- smartAccountAddress: scwAddress,
- });
-
- // 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(sessionManagerModule);
-
- const hyphenContract = new ethers.Contract(
- config.hyphenLP.address,
- config.hyphenLP.abi,
- sessionSigner
- );
-
- const addLiquidityData = hyphenContract.interface.encodeFunctionData(
- "addTokenLiquidity",
- [config.usdc.address, parseUnits("0.01", 6)]
- ); // 1 USDC (amoy USDC has 6 decimals)
- const tx1 = {
- to: config.hyphenLP.address,
- data: addLiquidityData,
- value: 0,
- };
-
- // build user op
- // with calldata to provide LP
- let userOpResponse = await biconomySmartAccount.sendTransaction(tx1, {
- params: {
- sessionSigner: newSigner,
- sessionValidationModule: ccSessionValidationModuleAddr,
- },
- simulationType: "validation_and_execution",
- });
-
- console.log("userOpHash", userOpResponse);
- const { transactionHash } = await userOpResponse.waitForTxHash();
- console.log("txHash", transactionHash);
- showSuccessMessage(`LP Deposit ${transactionHash}`, transactionHash);
- setLoading(false);
- } catch (err: any) {
- console.error(err);
- setLoading(false);
- showErrorMessage(err.message || "Error in sending the transaction");
- }
- };
-
- return (
-
-
- Use Cases {"->"} Gasless {"->"} Deposit into Hyphen Pool using session
- key
-
-
-
- Deposit into Hyphen Pool via Session Key
-
-
-
- This is an example to Deposit into Hyphen Pool making use of enabled
- session. Requires prior approval from smart account
-