bcnmy / biconomy-client-sdk

Biconomy SDK is a plug & play toolkit for dApps to build transaction legos that enable a highly customised one-click experience for their users
MIT License
76 stars 78 forks source link

Provider returned Incorrect Fee values #139

Closed talhamalik883 closed 1 year ago

talhamalik883 commented 1 year ago

In client-sdk provider.getFeeData() function is called to populate maxFeePerGas and maxPriorityFeePerGas for any userOp created in client-sdk. The fee values returned by getFeeData are either null or low as compared to on chain network fee. This can be sorted by switching from provider to an external api that send's accurate data. Following are the requirements for external endpoint for fetching fee values.

Url: BASE_URL/gas-prices/chainid
Type: GET
params: chainid

Response

{
code: 200,
message: 'SUCCESS',
data: {
gasPrice: 10,
maxFeePerGas: 12,
maxPriorityFeePerGas: 2
}
}
tomarsachin2271 commented 1 year ago

Instead of adding a new end point on bundler, we can use the same bundler end point and pass the request parameters in form of JSON RPC Request

Url: Bundler URL Type: GET Params:

{
    "method": "eth_getUserOpGasPrices",
    "params": ["<Chain_ID_Value"],
    "jsonrpc": "2.0",
    "id": 1
}

Success Response

{
    "jsonrpc": "2.0",
    "id": 1,
        "result" : {
            "maxFeePerGas": "0x987239",
            "maxPriorityFeePerGas": "0x86bac3"
        }
}

Error Response

{
    "jsonrpc": "2.0",
    "id": 1,
        "error" : {
            "code": <Integer value>,
            "message" : "String error message",
            "data": {}. // Any data related to error
        }
}
talhamalik883 commented 1 year ago

Instead of adding a new end point on bundler, we can use the same bundler end point and pass the request parameters in form of JSON RPC Request

Url: Bundler URL Type: GET Params:

{
  "method": "eth_getUserOpGasPrices",
  "params": ["<Chain_ID_Value"],
  "jsonrpc": "2.0",
  "id": 1
}

Success Response

{
  "jsonrpc": "2.0",
  "id": 1,
        "result" : {
            "maxFeePerGas": "0x987239",
            "maxPriorityFeePerGas": "0x86bac3"
        }
}

Error Response

{
  "jsonrpc": "2.0",
  "id": 1,
        "error" : {
            "code": <Integer value>,
            "message" : "String error message",
            "data": {}. // Any data related to error
        }
}

yeah that sounds good. Can we add gasPrice another attribute also in response ? Some chains do not support type 2 transaction so we will just use gasPrice in that case.

tomarsachin2271 commented 1 year ago

For those who don't support type 2, value of maxFeePerGas and maxPriorityFeePerGas value will be same in this case. This is mentioned in the ERC-4337 as well, as UserOp doesn't have gasPrice field.

tomarsachin2271 commented 1 year ago

You can check how EntryPoint handles this case here https://github.com/eth-infinitism/account-abstraction/blob/develop/contracts/core/EntryPoint.sol#L593

talhamalik883 commented 1 year ago

field

using gasPrice meant that i will assign gasPrice to maxFee and maxPriorityFee for chains that don't support type 2.

      const { maxFeePerGas,  maxPriorityFeePerGas, gasPrice } = await this.provider.getGasPrices()
        userOp.maxFeePerGas = maxFeePerGas ?? gasPrice
        userOp.maxPriorityFeePerGas = maxPriorityFeePerGas ?? gasPrice
    }
livingrockrises commented 1 year ago

https://github.com/bcnmy/biconomy-client-sdk/pull/143

github-actions[bot] commented 1 year ago

This issue has been inactive for 30 days. It will be closed due to inactivity. If this issue is still relevant, please comment to keep it open. Alternatively, you can create a new issue with updated information.