Skip to content

Commit

Permalink
Merge pull request #18 from bcnmy/modular-sa-v2-playground
Browse files Browse the repository at this point in the history
Modular sa v2 playground
  • Loading branch information
livingrockrises committed Sep 22, 2023
2 parents b4e8751 + 9b5849d commit 16c0f73
Show file tree
Hide file tree
Showing 20 changed files with 598 additions and 107 deletions.
6 changes: 3 additions & 3 deletions backend-node/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"privateKey": "<PRIVATE_KEY>",
"accountIndex": 0,
"chainId": 80001,
"rpcUrl": "https://rpc.ankr.com/polygon_mumbai",
"bundlerUrl": "https://bundler.biconomy.io/api/v2/80001/cJPK7B3ru.dd7f7861-190d-45ic-af80-6877f74b8f44",
"biconomyPaymasterUrl": "https://paymaster.biconomy.io/api/v1/80001/<YOUR_PAYMASTER_API_KEY_FROM_DASHBOARD>",
"rpcUrl": "https://polygon-testnet.public.blastapi.io",
"bundlerUrl": "https://bundler.biconomy.io/api/v2/80001/A5CBjLqSc.0dcbc53e-anPe-44c7-b22d-21071345f76a",
"biconomyPaymasterUrl": "https://paymaster.biconomy.io/api/v1/80001/tf47vamuW.3c55594d-14f8-4451-b5dd-39f46abe272a",
"preferredToken": "",
"tokenList": []
}
11 changes: 6 additions & 5 deletions backend-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"keywords": [],
"license": "ISC",
"dependencies": {
"@biconomy/account": "^3.0.0",
"@biconomy/bundler": "^3.0.0",
"@biconomy/common": "^3.0.0",
"@biconomy/core-types": "^3.0.0",
"@biconomy/paymaster": "^3.0.0",
"@biconomy/account": "^3.1.0",
"@biconomy/bundler": "^3.1.0",
"@biconomy/common": "^3.1.0",
"@biconomy/core-types": "^3.1.0",
"@biconomy/modules": "^3.1.0",
"@biconomy/paymaster": "^3.1.0",
"chalk": "^4.1.2",
"ethers": "^5.7.2",
"inquirer": "^8.0.0",
Expand Down
4 changes: 2 additions & 2 deletions backend-node/scripts/address.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chalk from "chalk";
const chalk = require('chalk')
import { createBiconomyAccountInstance } from "./helperFunctions";
import config from "../config.json";

export async function getAddress() {
const biconomySmartAccount = await createBiconomyAccountInstance();
const scwAddress = await biconomySmartAccount.getSmartAccountAddress(config.accountIndex);
const scwAddress = await biconomySmartAccount.getAccountAddress();
console.log(chalk.green(`SmartAccount address: ${scwAddress}`));
}
24 changes: 16 additions & 8 deletions backend-node/scripts/erc20/batchMintNFT.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ethers } from "ethers";
import chalk from "chalk";
const chalk = require('chalk')
import inquirer from "inquirer";
import {
BiconomySmartAccount,
BiconomySmartAccountV2,
DEFAULT_ENTRYPOINT_ADDRESS,
} from "@biconomy/account";
import { Bundler } from "@biconomy/bundler";
Expand All @@ -14,6 +14,7 @@ import {
SponsorUserOperationDto,
} from "@biconomy/paymaster";
import config from "../../config.json";
import { DEFAULT_ECDSA_OWNERSHIP_MODULE, DEFAULT_MULTICHAIN_MODULE, ECDSAOwnershipValidationModule, MultiChainValidationModule } from "@biconomy/modules";

export const batchMintNftPayERC20 = async () => {
// ------------------------STEP 1: Initialise Biconomy Smart Account SDK--------------------------------//
Expand All @@ -37,6 +38,11 @@ export const batchMintNftPayERC20 = async () => {
paymasterUrl: config.biconomyPaymasterUrl
});

const ecdsaModule = await ECDSAOwnershipValidationModule.create({
signer: signer,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

// Biconomy smart account config
// Note that paymaster and bundler are optional. You can choose to create new instances of this later and make account API use
const biconomySmartAccountConfig = {
Expand All @@ -45,13 +51,16 @@ export const batchMintNftPayERC20 = async () => {
rpcUrl: config.rpcUrl,
paymaster: paymaster,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: ecdsaModule,
activeValidationModule: ecdsaModule
};

// create biconomy smart account instance
const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig);
const biconomySmartAccount = await BiconomySmartAccountV2.create(biconomySmartAccountConfig);

// passing accountIndex is optional, by default it will be 0. You may use different indexes for generating multiple counterfactual smart accounts for the same user
const biconomySmartAccount = await biconomyAccount.init( {accountIndex: config.accountIndex} );





Expand All @@ -65,9 +74,8 @@ export const batchMintNftPayERC20 = async () => {
"function safeMint(address _to)",
]);

// passing accountIndex is optional, by default it will be 0
// it should match with the index used to initialise the SDK Biconomy Smart Account instance
const scwAddress = await biconomySmartAccount.getSmartAccountAddress(config.accountIndex);

const scwAddress = await biconomySmartAccount.getAccountAddress();

// Here we are minting NFT to smart account address itself
const data = nftInterface.encodeFunctionData("safeMint", [scwAddress]);
Expand Down
22 changes: 15 additions & 7 deletions backend-node/scripts/erc20/erc20Transfer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ethers } from "ethers";
const { ERC20ABI } = require('../abi')
import chalk from "chalk";
const chalk = require('chalk')
import inquirer from "inquirer";
import {
BiconomySmartAccount,
BiconomySmartAccountV2,
DEFAULT_ENTRYPOINT_ADDRESS,
} from "@biconomy/account";
import { Bundler } from "@biconomy/bundler";
Expand All @@ -15,6 +15,7 @@ import {
SponsorUserOperationDto,
} from "@biconomy/paymaster";
import config from "../../config.json";
import { DEFAULT_ECDSA_OWNERSHIP_MODULE, DEFAULT_MULTICHAIN_MODULE, ECDSAOwnershipValidationModule, MultiChainValidationModule } from "@biconomy/modules";

export const erc20TransferPayERC20 = async (
recipientAddress: string,
Expand Down Expand Up @@ -42,6 +43,11 @@ export const erc20TransferPayERC20 = async (
paymasterUrl: config.biconomyPaymasterUrl
});

const ecdsaModule = await ECDSAOwnershipValidationModule.create({
signer: signer,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

// Biconomy smart account config
// Note that paymaster and bundler are optional. You can choose to create new instances of this later and make account API use
const biconomySmartAccountConfig = {
Expand All @@ -50,13 +56,16 @@ export const erc20TransferPayERC20 = async (
rpcUrl: config.rpcUrl,
paymaster: paymaster,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: ecdsaModule,
activeValidationModule: ecdsaModule
};

// create biconomy smart account instance
const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig);
const biconomySmartAccount = await BiconomySmartAccountV2.create(biconomySmartAccountConfig);

// passing accountIndex is optional, by default it will be 0. You may use different indexes for generating multiple counterfactual smart accounts for the same user
const biconomySmartAccount = await biconomyAccount.init( {accountIndex: config.accountIndex} );





Expand Down Expand Up @@ -153,8 +162,7 @@ export const erc20TransferPayERC20 = async (
let paymasterServiceData = {
mode: PaymasterMode.ERC20, // - mandatory // now we know chosen fee token and requesting paymaster and data for it
feeTokenAddress: selectedFeeQuote.tokenAddress,
// optional params..
calculateGasLimits: true, // Always recommended and especially when using token paymaster
calculateGasLimits: true, // - optional by default false
};

try{
Expand Down
30 changes: 18 additions & 12 deletions backend-node/scripts/erc20/mintNFT.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ethers } from "ethers";
import chalk from "chalk";
const chalk = require('chalk')
import inquirer from "inquirer";
import {
BiconomySmartAccount,
DEFAULT_ENTRYPOINT_ADDRESS,
} from "@biconomy/account";
BiconomySmartAccountV2,
DEFAULT_ENTRYPOINT_ADDRESS,
} from "@biconomy/account";
import { Bundler } from "@biconomy/bundler";
import { BiconomyPaymaster } from "@biconomy/paymaster";
import {
Expand All @@ -14,6 +14,7 @@ import {
SponsorUserOperationDto,
} from "@biconomy/paymaster";
import config from "../../config.json";
import { ECDSAOwnershipValidationModule, MultiChainValidationModule, DEFAULT_ECDSA_OWNERSHIP_MODULE, DEFAULT_MULTICHAIN_MODULE, DEFAULT_SESSION_KEY_MANAGER_MODULE } from "@biconomy/modules";

export const mintNftPayERC20 = async () => {
// ------------------------STEP 1: Initialise Biconomy Smart Account SDK--------------------------------//
Expand All @@ -37,6 +38,11 @@ export const mintNftPayERC20 = async () => {
paymasterUrl: config.biconomyPaymasterUrl
});

const ecdsaModule = await ECDSAOwnershipValidationModule.create({
signer: signer,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

// Biconomy smart account config
// Note that paymaster and bundler are optional. You can choose to create new instances of this later and make account API use
const biconomySmartAccountConfig = {
Expand All @@ -45,29 +51,29 @@ export const mintNftPayERC20 = async () => {
rpcUrl: config.rpcUrl,
paymaster: paymaster,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: ecdsaModule,
activeValidationModule: ecdsaModule
};

// create biconomy smart account instance
const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig);
const biconomySmartAccount = await BiconomySmartAccountV2.create(biconomySmartAccountConfig);

// passing accountIndex is optional, by default it will be 0. You may use different indexes for generating multiple counterfactual smart accounts for the same user
const biconomySmartAccount = await biconomyAccount.init( {accountIndex: config.accountIndex} );






// ------------------------STEP 2: Build Partial User op from your user Transaction/s Request --------------------------------//



// generate mintNft data
const nftInterface = new ethers.utils.Interface([
"function safeMint(address _to)",
]);

// passing accountIndex is optional, by default it will be 0
// it should match with the index used to initialise the SDK Biconomy Smart Account instance
const scwAddress = await biconomySmartAccount.getSmartAccountAddress(config.accountIndex);

const scwAddress = await biconomySmartAccount.getAccountAddress();

// Here we are minting NFT to smart account address itself
const data = nftInterface.encodeFunctionData("safeMint", [scwAddress]);
Expand Down
23 changes: 15 additions & 8 deletions backend-node/scripts/erc20/nativeTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ethers } from "ethers";
import chalk from "chalk";
const chalk = require('chalk')
import inquirer from "inquirer";
import {
BiconomySmartAccount,
BiconomySmartAccountV2,
DEFAULT_ENTRYPOINT_ADDRESS,
} from "@biconomy/account";
import { Bundler } from "@biconomy/bundler";
Expand All @@ -14,6 +14,7 @@ import {
SponsorUserOperationDto,
} from "@biconomy/paymaster";
import config from "../../config.json";
import { DEFAULT_ECDSA_OWNERSHIP_MODULE, DEFAULT_MULTICHAIN_MODULE, ECDSAOwnershipValidationModule, MultiChainValidationModule } from "@biconomy/modules";

export const nativeTransferPayERC20 = async (
to: string,
Expand All @@ -40,6 +41,11 @@ export const nativeTransferPayERC20 = async (
paymasterUrl: config.biconomyPaymasterUrl
});

const ecdsaModule = await ECDSAOwnershipValidationModule.create({
signer: signer,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

// Biconomy smart account config
// Note that paymaster and bundler are optional. You can choose to create new instances of this later and make account API use
const biconomySmartAccountConfig = {
Expand All @@ -48,13 +54,15 @@ export const nativeTransferPayERC20 = async (
rpcUrl: config.rpcUrl,
paymaster: paymaster,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: ecdsaModule,
activeValidationModule: ecdsaModule
};

// create biconomy smart account instance
const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig);
const biconomySmartAccount = await BiconomySmartAccountV2.create(biconomySmartAccountConfig);

// passing accountIndex is optional, by default it will be 0. You may use different indexes for generating multiple counterfactual smart accounts for the same user
const biconomySmartAccount = await biconomyAccount.init( {accountIndex: config.accountIndex} );




Expand Down Expand Up @@ -141,8 +149,7 @@ export const nativeTransferPayERC20 = async (
let paymasterServiceData = {
mode: PaymasterMode.ERC20, // - mandatory // now we know chosen fee token and requesting paymaster and data for it
feeTokenAddress: selectedFeeQuote.tokenAddress,
// optional params..
calculateGasLimits: true, // Always recommended and especially when using token paymaster
calculateGasLimits: true, // - optional by default false
};

try{
Expand All @@ -169,7 +176,7 @@ export const nativeTransferPayERC20 = async (
paymasterAndDataWithLimits.verificationGasLimit;
finalUserOp.preVerificationGas =
paymasterAndDataWithLimits.preVerificationGas;
}
}
} catch (e) {
console.log("error received ", e);
}
Expand Down
Loading

0 comments on commit 16c0f73

Please sign in to comment.