Skip to content

Commit

Permalink
Merge pull request #16 from etherspot/skandha_getGasPrice
Browse files Browse the repository at this point in the history
skandha_getGasPrice Endpoint
  • Loading branch information
vignesha22 authored Jul 27, 2023
2 parents e042c19 + 5b4c2ea commit 04cfede
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [1.1.1] - 2023-07-27
### New
- Added skandha_getGasPrice from the bundler if the bundler url is skandha bundler url

## [1.1.0] - 2023-07-14
### New
- Added Mantle Mainnet config as supported networks
Expand Down
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.1.0",
"version": "1.1.1",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
19 changes: 19 additions & 0 deletions src/sdk/base/HttpRpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { resolveProperties } from 'ethers/lib/utils';
import { UserOperationStruct } from '../contracts/src/aa-4337/core/BaseAccount';
import Debug from 'debug';
import { deepHexlify } from '../common/ERC4337Utils';
import { Gas } from '../common';

const debug = Debug('aa.rpc');

Expand Down Expand Up @@ -58,6 +59,24 @@ export class HttpRpcClient {
]);
}

async getSkandhaGasPrice(): Promise<Gas> {
try {
const { maxFeePerGas, maxPriorityFeePerGas } = await this.userOpJsonRpcProvider.send('skandha_getGasPrice', []);
return { maxFeePerGas, maxPriorityFeePerGas };
} catch (err) {
console.warn(
"getGas: skandha_getGasPrice failed, falling back to legacy gas price."
);
const gas = await this.userOpJsonRpcProvider.getGasPrice();
return { maxFeePerGas: gas, maxPriorityFeePerGas: gas };
}
}

async getBundlerVersion(): Promise<string> {
const version = await this.userOpJsonRpcProvider.send('web3_clientVersion', []);
return version;
}

async getUserOpsReceipt(uoHash: string): Promise<any> {
const response = await this.userOpJsonRpcProvider.send('eth_getUserOperationReceipt', [uoHash]);
return response;
Expand Down
12 changes: 9 additions & 3 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export class PrimeSdk {

private etherspotWallet: EtherspotWalletAPI;
private bundler: HttpRpcClient;
private chainId: number;

private userOpsBatch: BatchUserOpsRequest = {to: [], data: [], value: []};
private userOpsBatch: BatchUserOpsRequest = { to: [], data: [], value: [] };

constructor(walletProvider: WalletProviderLike, optionsLike: SdkOptions) {

Expand All @@ -36,6 +37,8 @@ export class PrimeSdk {
rpcProviderUrl,
} = optionsLike;

this.chainId = chainId;

if (!optionsLike.bundlerRpcUrl) {
const networkConfig = getNetworkConfig(chainId);
optionsLike.bundlerRpcUrl = networkConfig.bundler;
Expand Down Expand Up @@ -122,7 +125,7 @@ export class PrimeSdk {
async estimate(gasDetails?: TransactionGasInfoForUserOp) {
const gas = await this.getGasFee();

if (this.userOpsBatch.to.length < 1){
if (this.userOpsBatch.to.length < 1) {
throw new Error("cannot sign empty transaction batch");
}

Expand All @@ -139,7 +142,7 @@ export class PrimeSdk {
});

const bundlerGasEstimate = await this.bundler.getVerificationGasInfo(partialtx);

if (bundlerGasEstimate.preVerificationGas) {
partialtx.preVerificationGas = BigNumber.from(bundlerGasEstimate.preVerificationGas);
partialtx.verificationGasLimit = BigNumber.from(bundlerGasEstimate.verificationGas);
Expand All @@ -151,6 +154,9 @@ export class PrimeSdk {
}

async getGasFee() {
const version = await this.bundler.getBundlerVersion();
if (version.includes('skandha'))
return this.bundler.getSkandhaGasPrice();
return getGasFee(this.etherspotWallet.provider as providers.JsonRpcProvider);
}

Expand Down

0 comments on commit 04cfede

Please sign in to comment.