Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: viem migration #34

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1c34e81
feat: viem migration
kanthgithub Aug 19, 2024
79b90d3
fix: version and changeLog updates
kanthgithub Aug 19, 2024
255af32
fix: network constants correction
kanthgithub Aug 19, 2024
603ebcf
fix: missing config files addes for packaging
kanthgithub Aug 19, 2024
3deb792
fix: XDC mainnet config added
kanthgithub Aug 23, 2024
64823c4
fix: resolve merge conflict in changeLog and package dependencies
kanthgithub Aug 23, 2024
2ac5fd2
fix: package versioning fix
kanthgithub Aug 23, 2024
9994d42
Merge branch 'master' into feature/viem-migration
kanthgithub Aug 23, 2024
4988d5f
feat: refactor SessionKeyValidator sdk - viem version with master
kanthgithub Sep 9, 2024
5a84629
feat: refactor SessionKeyValidator sdk - viem version with master
kanthgithub Sep 9, 2024
09a26c8
feat: refactor SessionKeyValidator sdk - viem version with master
kanthgithub Sep 9, 2024
0119a2c
fix: SessionkeyValidatorSDK initialisation and example changes
kanthgithub Sep 10, 2024
b807ee8
fix: resolve conflicts with master
kanthgithub Sep 10, 2024
09dfb50
Merge branch 'master' into feature/viem-migration
kanthgithub Sep 10, 2024
3687b68
fix: delete obselte example scripts
kanthgithub Sep 10, 2024
cc5f880
fix: token validity check for EnableSessionKey
kanthgithub Sep 19, 2024
aee8ac3
fix: refactor token validity function on the chain and apply for enab…
kanthgithub Sep 19, 2024
a4d331b
fix: validate token address call during sessionKey generation and rot…
kanthgithub Sep 19, 2024
a1f4ddd
feat: ValidatorAddress checks in getNonce
kanthgithub Sep 20, 2024
2588023
fix: ValidatorAddress Validation during getNonce
kanthgithub Sep 21, 2024
6302892
feat: PRO-2716 SDK initialisation normalisation for viem similar to e…
kanthgithub Sep 29, 2024
3e6f53e
fix: SDK initialisation should take privateKey passed as initialisati…
kanthgithub Sep 30, 2024
1370ad1
Merge branch 'master' into feature/viem-migration
kanthgithub Oct 3, 2024
2455562
feat: Add node options to test command
sarthakprp Oct 3, 2024
f10710c
fix: export node options as global
sarthakprp Oct 3, 2024
ba341e5
fix: global options
sarthakprp Oct 3, 2024
c801593
feat: examples usage updates and organise imports in sdk
kanthgithub Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASSWORD
environment:
NODE_OPTIONS: "--max-old-space-size=4096"
steps:
- checkout
- run:
Expand Down Expand Up @@ -42,6 +44,8 @@ jobs:
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASSWORD
environment:
NODE_OPTIONS: "--max-old-space-size=4096"
steps:
- checkout
- when:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
### Breaking Changes
- Fix for `deleteSessionKey` API request failure

## [2.0.3] - 2024-08-23
### Breaking Changes
- Migrate from ethers to viem library

## [2.0.2] - 2024-08-21
### New
- Updated XDC Mainnet factory address
Expand Down
41 changes: 26 additions & 15 deletions examples/05-add-guardians.ts → examples/basics/add-guardians.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { ethers } from 'ethers';
import { EtherspotBundler, ModularSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import { printOp } from '../../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
import { sleep } from '../../src/sdk/common';
import { encodeFunctionData, parseAbi } from 'viem';
import { generateModularSDKInstance } from '../helpers/sdk-helper';

dotenv.config();

// tsx examples/basics/add-guardians.ts
async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

// initializating sdk...
const modularSdk = new ModularSdk(
{ privateKey: process.env.WALLET_PRIVATE_KEY },
{ chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) },
);

console.log('address: ', modularSdk.state.EOAAddress);
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get address of EtherspotWallet
const address: string = await modularSdk.getCounterFactualAddress();
Expand All @@ -29,12 +27,25 @@ async function main() {

console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);

const addGuardianInterface = new ethers.utils.Interface(['function addGuardian(address _newGuardian)']);

const addGuardianData1 = addGuardianInterface.encodeFunctionData('addGuardian', [guardianAddresses[0]]);
const addGuardianData2 = addGuardianInterface.encodeFunctionData('addGuardian', [guardianAddresses[1]]);
const addGuardianData3 = addGuardianInterface.encodeFunctionData('addGuardian', [guardianAddresses[2]]);
const addGuardianInterface = ['function addGuardian(address _newGuardian)'];

const addGuardianData1 =
encodeFunctionData({
functionName: 'addGuardian',
abi: parseAbi(addGuardianInterface),
args: [guardianAddresses[0]],
});
const addGuardianData2 =
encodeFunctionData({
functionName: 'addGuardian',
abi: parseAbi(addGuardianInterface),
args: [guardianAddresses[1]],
});
const addGuardianData3 = encodeFunctionData({
functionName: 'addGuardian',
abi: parseAbi(addGuardianInterface),
args: [guardianAddresses[2]],
});
// clear the transaction batch
await modularSdk.clearUserOpsFromBatch();

Expand Down
19 changes: 8 additions & 11 deletions examples/07-callGasLimit.ts → examples/basics/callGasLimit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ethers } from 'ethers';
import { EtherspotBundler, ModularSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import { printOp } from '../../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
import { sleep } from '../../src/sdk/common';
import { parseEther } from 'viem';
import { generateModularSDKInstance } from '../helpers/sdk-helper';

dotenv.config();

Expand All @@ -12,12 +12,9 @@ const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxM

async function main() {
// initializating sdk...
const modularSdk = new ModularSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID),
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

console.log('address: ', modularSdk.state.EOAAddress)
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get address of EtherspotWallet...
const address: string = await modularSdk.getCounterFactualAddress();
Expand All @@ -27,7 +24,7 @@ async function main() {
await modularSdk.clearUserOpsFromBatch();

// add transactions to the batch
const transactionBatch = await modularSdk.addUserOpsToBatch({ to: recipient, value: ethers.utils.parseEther(value) });
const transactionBatch = await modularSdk.addUserOpsToBatch({ to: recipient, value: parseEther(value) });
console.log('transactions: ', transactionBatch);

// get balance of the account address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { BigNumber, ethers, providers } from 'ethers';
import { EtherspotBundler, ModularSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import { printOp } from '../../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
import { sleep } from '../../src/sdk/common';
import { getPublicClient } from '../../src/sdk/common/utils/viem-utils';
import { Hex, http, parseEther, PublicClient } from 'viem';
import { generateModularSDKInstance } from '../helpers/sdk-helper';
import { BigNumber } from '../../src/sdk/types/bignumber';

dotenv.config();

Expand All @@ -11,20 +13,26 @@ const value = '0.000001'; // transfer value
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
const provider = new providers.JsonRpcProvider(process.env.RPC_PROVIDER_URL);
// initializating sdk...
const modularSdk = new ModularSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID),
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})
// initializating sdk for index 0...
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

console.log('address: ', modularSdk.state.EOAAddress)
const publicClient = getPublicClient({
chainId: Number(process.env.CHAIN_ID),
transport: http(bundlerApiKey)
}) as PublicClient;

// get address of EtherspotWallet...
const address: string = await modularSdk.getCounterFactualAddress();
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);

if ((await provider.getCode(address)).length <= 2) {
// get code
const code = await publicClient.getCode({
address: address as Hex
});

if (code.length <= 2) {
console.log("Account must be created first");
return;
}
Expand All @@ -33,7 +41,7 @@ async function main() {
await modularSdk.clearUserOpsFromBatch();

// add transactions to the batch
const transactionBatch = await modularSdk.addUserOpsToBatch({to: recipient, value: ethers.utils.parseEther(value)});
const transactionBatch = await modularSdk.addUserOpsToBatch({to: recipient, value: parseEther(value)});
console.log('transactions: ', transactionBatch);

// get balance of the account address
Expand Down
10 changes: 6 additions & 4 deletions examples/01-get-address.ts → examples/basics/get-address.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ethers } from 'ethers';
import { EtherspotBundler, ModularSdk } from '../src';
import * as dotenv from 'dotenv';
import { generateModularSDKInstance } from '../helpers/sdk-helper';

dotenv.config();

// npx ts-node examples/01-get-address.ts
// tsx examples/basics/get-address.ts
async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
const customBundlerUrl = '';

// initializating sdk...
const modularSdk = new ModularSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey, customBundlerUrl) }) // Testnets dont need apiKey on bundlerProvider
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get EtherspotWallet address...
const address: string = await modularSdk.getCounterFactualAddress();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { EtherspotBundler, ModularSdk } from '../src';
import * as dotenv from 'dotenv';
import { generateModularSDKInstance } from '../helpers/sdk-helper';

dotenv.config();


// tsx examples/basics/get-counterfactual-address.ts
async function main() {
const etherspotBundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
// initializating sdk...
const modularSdk = new ModularSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID),
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), etherspotBundlerApiKey)
})
// initializating sdk for index 0...
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), etherspotBundlerApiKey);

// get EtherspotWallet address...
const address: string = await modularSdk.getCounterFactualAddress();
Expand Down
23 changes: 23 additions & 0 deletions examples/basics/get-gas-fees.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as dotenv from 'dotenv';
import { generateModularSDKInstance } from '../helpers/sdk-helper';

dotenv.config();

// tsx examples/basics/get-gas-fees.ts
async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
const customBundlerUrl = '';

// initializating sdk...
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get EtherspotWallet address...
const gasFees: any = await modularSdk.getGasFee();
console.log(`gasFees is: ${JSON.stringify(gasFees)}`);
}

main()
.catch(console.error)
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { EtherspotBundler, ModularSdk } from '../src';
import * as dotenv from 'dotenv';
import { generateModularSDKInstance } from '../helpers/sdk-helper';

dotenv.config();

const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

// tsx examples/basics/get-multiple-accounts.ts
async function main() {
// initializating sdk for index 0...
const modularSdk = new ModularSdk(
{ privateKey: process.env.WALLET_PRIVATE_KEY },
{ chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) },
);
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get EtherspotWallet address for index 0...
const address: string = await modularSdk.getCounterFactualAddress();
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address for index 0: ${address}`);

// initializating sdk for index 1...
const modularSdk1 = new ModularSdk(
{ privateKey: process.env.WALLET_PRIVATE_KEY },
{ chainId: Number(process.env.CHAIN_ID), index: 1, bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) },
);
const modularSdk1 = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY,
Number(process.env.CHAIN_ID),
bundlerApiKey,
1
);// Testnets dont need apiKey on bundlerProvider

// get EtherspotWallet address for index 1...
const address1: string = await modularSdk1.getCounterFactualAddress();
Expand Down
23 changes: 23 additions & 0 deletions examples/basics/get-nonce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as dotenv from 'dotenv';
import { generateModularSDKInstance } from '../helpers/sdk-helper';

dotenv.config();

// tsx examples/basics/get-nonce.ts
async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
const customBundlerUrl = '';

// initializating sdk...
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get EtherspotWallet nonce...
const nonce = await modularSdk.getNonce();
console.log(`nonce is: ${nonce}`);
}

main()
.catch(console.error)
.finally(() => process.exit());
49 changes: 32 additions & 17 deletions examples/03-transfer-erc20.ts → examples/basics/transfer-erc20.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
import { ethers } from 'ethers';
import { EtherspotBundler, ModularSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import { ERC20_ABI } from '../src/sdk/helpers/abi/ERC20_ABI';
import { EtherspotBundler, ModularSdk } from '../../src';
import { printOp } from '../../src/sdk/common/OperationUtils';
import { ERC20_ABI } from '../../src/sdk/helpers/abi/ERC20_ABI';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
import { sleep } from '../../src/sdk/common';
import { getPublicClient, getViemAccount } from '../../src/sdk/common/utils/viem-utils';
import { encodeFunctionData, Hex, http, parseAbi, parseUnits } from 'viem';
import { generateModularSDKInstance } from '../helpers/sdk-helper';
import { erc20Abi } from '../../src/sdk/common/abis';

dotenv.config();

// add/change these values
const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '1'; // transfer value
const value = '0.1'; // transfer value
const tokenAddress = process.env.TOKEN_ADDRESS as string; // token address
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

// npx ts-node examples/03-transfer-erc20.ts
// tsx examples/basics/transfer-erc20.ts
async function main() {
// initializating sdk...
const modularSdk = new ModularSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) })

console.log('address: ', modularSdk.state.EOAAddress)
const bundlerProvider = new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey);
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get address of EtherspotWallet...
const address: string = await modularSdk.getCounterFactualAddress();
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);

const provider = new ethers.providers.JsonRpcProvider('https://polygon-amoy.drpc.org')
// get erc20 Contract Interface
const erc20Instance = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
const publicClient = getPublicClient({
chainId: Number(process.env.CHAIN_ID),
transport: http(bundlerProvider.url)
});

// get decimals from erc20 contract
const decimals = await erc20Instance.functions.decimals();


const decimals = await publicClient.readContract({
address: tokenAddress as Hex,
abi: parseAbi(erc20Abi),
functionName: 'decimals',
args: []
})

// get transferFrom encoded data
const transactionData = erc20Instance.interface.encodeFunctionData('transfer', [recipient, ethers.utils.parseUnits(value, decimals)])

const transactionData = encodeFunctionData({
functionName: 'transfer',
abi: parseAbi(ERC20_ABI),
args: [recipient, parseUnits(value, decimals as number)]
});

// clear the transaction batch
await modularSdk.clearUserOpsFromBatch();

Expand Down
Loading
Loading