Skip to content

Commit

Permalink
Merge pull request #13 from etherspot/Added_Mantle_Network
Browse files Browse the repository at this point in the history
Mantle Support
  • Loading branch information
vignesha22 authored Jul 21, 2023
2 parents 38a0fa5 + 87ed9ea commit e042c19
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 99 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Changelog
## [1.1.0] - 2023-07-14
### New
- Added Mantle Mainnet config as supported networks
### Breaking Changes
- Changed the wallet factory address so the smart wallet address will generate a new address. Whoever wishes to access the old wallet should use version 1.0.3 to connect to the old smart wallet
- Renamed sign method to estimate and get the return object as UserOps without signature
- Now signing the UserOps is moved into send method so provider would be requested to sign only while calling send method
- getUserOpsReceipt returns the whole object with UserOpsReceipt with transaction Receipt as compared to previously returned transaction hash
- getUserOpsReceipt only returns if the transaction is included into the block on-chain and would give results only for 15k blocks from the latest block number

## [1.0.3] - 2023-07-10
### Fixed
- Fuse and ArbitrumGoerli bundler url and native transfer funds example
Expand Down
18 changes: 12 additions & 6 deletions examples/02-transfer-funds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';

dotenv.config();

Expand Down Expand Up @@ -30,18 +31,23 @@ async function main() {

console.log('balances: ', balance);

// sign transactions added to the batch
const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
// estimate transactions added to the batch and get the fee data for the UserOp
const op = await primeSdk.estimate();
console.log(`Estimate UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the UserOp and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}

main()
Expand Down
20 changes: 13 additions & 7 deletions examples/03-transfer-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { PrimeSdk } 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';

dotenv.config();

// add/change these values
const recipient: string = '0xD129dB5e418e389c3F7D3ae0B8771B3f76799A52'; // recipient wallet address
const recipient: string = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value: string = '0.1'; // transfer value
const tokenAddress: string = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB';

Expand Down Expand Up @@ -38,18 +39,23 @@ async function main() {
let userOpsBatch = await primeSdk.addUserOpsToBatch({to: tokenAddress, data: transactionData});
console.log('transactions: ', userOpsBatch);

// sign transactions added to the batch
const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
// estimate transactions added to the batch and get the fee data for the UserOp
const op = await primeSdk.estimate();
console.log(`Estimate UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the UserOp and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}

main()
Expand Down
16 changes: 11 additions & 5 deletions examples/04-transfer-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';

dotenv.config();

Expand Down Expand Up @@ -34,17 +35,22 @@ async function main() {
console.log('transactions: ', userOpsBatch);

// sign transactions added to the batch
const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
const op = await primeSdk.estimate();
console.log(`Estimated UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the userOps and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}

main()
Expand Down
16 changes: 11 additions & 5 deletions examples/scripts/commands/NFTTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from "ethers";
import config from "../../config.json";
import { PrimeSdk } from "../../../src";
import { printOp } from "../../../src/sdk/common/OperationUtils";
import { sleep } from "../../../src/sdk/common";

export default async function main(
tknid: number,
Expand Down Expand Up @@ -31,15 +32,20 @@ export default async function main(
await primeSdk.addUserOpsToBatch({to: tokenAddress, data: erc721Data});
console.log(`Added transaction to batch`);

const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
const op = await primeSdk.estimate();
console.log(`Estimated UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the userOp and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}
16 changes: 11 additions & 5 deletions examples/scripts/commands/batchErc20Transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ERC20_ABI } from '../../../src/sdk/helpers/abi/ERC20_ABI';
import config from "../../config.json";
import { PrimeSdk } from '../../../src';
import { printOp } from "../../../src/sdk/common/OperationUtils";
import { sleep } from "../../../src/sdk/common";

// This example requires several layers of calls:
// EntryPoint
Expand Down Expand Up @@ -52,15 +53,20 @@ export default async function main(
await primeSdk.addUserOpsToBatch({to: dest[i], data: data[i]})
}

const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
const op = await primeSdk.estimate();
console.log(`Estimated UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the userop and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}
16 changes: 11 additions & 5 deletions examples/scripts/commands/erc20Approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ERC20_ABI } from '../../../src/sdk/helpers/abi/ERC20_ABI';
import config from "../../config.json";
import { PrimeSdk } from "../../../src";
import { printOp } from "../../../src/sdk/common/OperationUtils";
import { sleep } from "../../../src/sdk/common";

export default async function main(
tkn: string,
Expand All @@ -30,15 +31,20 @@ export default async function main(
await primeSdk.addUserOpsToBatch({to: erc20.address, data: approveData});
console.log(`Added transaction to batch`);

const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
const op = await primeSdk.estimate();
console.log(`Estimated UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the userOp and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}
16 changes: 11 additions & 5 deletions examples/scripts/commands/erc20Transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ERC20_ABI } from '../../../src/sdk/helpers/abi/ERC20_ABI';
import config from "../../config.json";
import { PrimeSdk } from "../../../src";
import { printOp } from "../../../src/sdk/common/OperationUtils";
import { sleep } from "../../../src/sdk/common";

export default async function main(
tkn: string,
Expand Down Expand Up @@ -32,15 +33,20 @@ export default async function main(
await primeSdk.addUserOpsToBatch({to: erc20.address, data: transferData});
console.log(`Added transaction to batch`);

const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
const op = await primeSdk.estimate();
console.log(`Estimated UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the UserOp and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}
16 changes: 11 additions & 5 deletions examples/scripts/commands/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from "ethers";
import config from "../../config.json";
import { PrimeSdk } from "../../../src";
import { printOp } from "../../../src/sdk/common/OperationUtils";
import { sleep } from "../../../src/sdk/common";


export default async function main(t: string, amt: string) {
Expand All @@ -18,15 +19,20 @@ export default async function main(t: string, amt: string) {
await primeSdk.addUserOpsToBatch({to: target, value});
console.log(`Added transaction to batch`);

const op = await primeSdk.sign();
console.log(`Signed UserOp: ${await printOp(op)}`);
const op = await primeSdk.estimate();
console.log(`Estimated UserOp: ${await printOp(op)}`);

// sending to the bundler...
// sign the userOp and sending to the bundler...
const uoHash = await primeSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
const txHash = await primeSdk.getUserOpReceipt(uoHash);
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`);
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.0.3",
"version": "1.1.0",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
20 changes: 12 additions & 8 deletions src/sdk/base/BaseAccountAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,7 @@ export abstract class BaseAccountAPI {
}
const provider = this.services.walletService.getWalletProvider();
const callGasLimit =
parseNumber(detailsForUserOp.gasLimit) ??
(await provider.estimateGas({
from: this.entryPointAddress,
to: this.getAccountAddress(),
data: callData,
}));
parseNumber(detailsForUserOp.gasLimit) ?? BigNumber.from(35000)

return {
callData,
Expand Down Expand Up @@ -448,7 +443,17 @@ export abstract class BaseAccountAPI {
let { maxFeePerGas, maxPriorityFeePerGas } = info;
if (maxFeePerGas == null || maxPriorityFeePerGas == null) {
const provider = this.services.walletService.getWalletProvider();
const feeData = await provider.getFeeData();
let feeData: any = {};
try {
feeData = await provider.getFeeData();
} catch (err) {
console.warn(
"getGas: eth_maxPriorityFeePerGas failed, falling back to legacy gas price."
);
const gas = await provider.getGasPrice();

feeData = { maxFeePerGas: gas, maxPriorityFeePerGas: gas };
}
if (maxFeePerGas == null) {
maxFeePerGas = feeData.maxFeePerGas ?? undefined;
}
Expand All @@ -466,7 +471,6 @@ export abstract class BaseAccountAPI {
verificationGasLimit,
maxFeePerGas,
maxPriorityFeePerGas,
chainId: 80001,
};


Expand Down
5 changes: 5 additions & 0 deletions src/sdk/base/HttpRpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class HttpRpcClient {
]);
}

async getUserOpsReceipt(uoHash: string): Promise<any> {
const response = await this.userOpJsonRpcProvider.send('eth_getUserOperationReceipt', [uoHash]);
return response;
}

private async printUserOperation(
method: string,
[userOp1, entryPointAddress]: [UserOperationStruct, string],
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export enum HeaderNames {
ProjectKey = 'x-project-key',
ProjectMetadata = 'x-project-metadata',
}

export const bufferPercent:number = 13; // Buffer in percent
Loading

0 comments on commit e042c19

Please sign in to comment.