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

Feature update get fees #24

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@

### 1.0.7 (2023-07-05)

- cleaned package structure
- cleaned package structure

### 1.0.8 (2023-11-30)

- Updated the getFees() method for gas estimation and added its test.
- Changed the License to MIT.
6 changes: 3 additions & 3 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getsafle/vault-optimism-controller",
"version": "1.0.7",
"version": "1.0.8",
"description": "optimism controller for safle vault",
"engines": {
"node": ">= 10"
Expand Down Expand Up @@ -28,7 +28,7 @@
"keyring"
],
"author": "",
"license": "ISC",
"license": "MIT",
"bugs": {
"url": "https://github.com/getsafle/vault-optimism-controller/issues"
},
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,13 @@ class KeyringController extends EventEmitter {
}

async getFees(optimismTx, web3) {
const { from, to, value, data, gasLimit } = optimismTx
const estimate = gasLimit ? gasLimit : await web3.eth.estimateGas({ to, from, value, data })
const { from, to, value, data } = optimismTx
const gasLimit = await web3.eth.estimateGas({ from, to, value, data });
const gasPrice = await web3.eth.getGasPrice();
return { transactionFees: estimate * gasPrice }
return {
gasLimit: gasLimit,
gasPrice: parseInt(gasPrice)
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ describe('Initialize wallet ', () => {
console.log(" get balance ", balance, accounts)
})

it("Get fees for a optimism tx", async () => {
const accounts = await optimismKeyring.getAccounts()
const web3 = new Web3(TESTNET.URL);
const tx = {
from:accounts[0],
to:'0x641BB2596D8c0b32471260712566BF933a2f1a8e',
value:0,
data:"0x00"
}
const getEstimate = await optimismKeyring.getFees(tx, web3)
console.log(" get gas estimate ", getEstimate)

})
it("sign Transaction ", async () => {

const accounts = await optimismKeyring.getAccounts()
Expand Down
Loading