Skip to content

Commit

Permalink
Merge pull request #26 from getsafle/dev
Browse files Browse the repository at this point in the history
integrating dev code to test
  • Loading branch information
sshubhamagg authored Dec 4, 2023
2 parents dd99341 + 3281ec5 commit 8666134
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
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
21 changes: 17 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,24 @@ 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 gasPrice = await web3.eth.getGasPrice();
return { transactionFees: estimate * gasPrice }
const { from, to, value, data } = optimismTx
const gasLimit = await web3.eth.estimateGas({ from, to, value, data });
const gasPrice = parseInt(await web3.eth.getGasPrice());
const fees = {
"slow":{
"gasPrice": parseInt(gasPrice)
},
"standard":{
"gasPrice": gasPrice + parseInt(gasPrice * 0.05)
},
"fast":{
"gasPrice": gasPrice + parseInt(gasPrice * 0.1)
},
baseFee: 0
}
return { gasLimit: gasLimit, fees: fees}
}

}

const getBalance = async (address, web3) => {
Expand Down
16 changes: 13 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ describe('Initialize wallet ', () => {
console.log(" with manual gasLimit ", fees)

const privateKey = await optimismKeyring.exportAccount(accounts[0])
//console.log('privateKey=',privateKey)
const tx3 = await optimismKeyring.sign(TESTING_MESSAGE_1, privateKey, web3)
console.log("tx3 ", tx3)
})
Expand All @@ -109,6 +108,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 Expand Up @@ -136,8 +148,6 @@ describe('Initialize wallet ', () => {
const signedTX = await optimismKeyring.signTransaction(rawTx, privateKey)
console.log("signedTX ", signedTX)

// const sentTX = await optimismKeyring.sendTransaction(signedTX, web3)
//console.log("sentTX ", sentTX)
})

})

0 comments on commit 8666134

Please sign in to comment.