Skip to content

Commit

Permalink
Merge pull request #27 from getsafle/dev
Browse files Browse the repository at this point in the history
Merging dev code to test
  • Loading branch information
sshubhamagg authored Dec 4, 2023
2 parents c9d4ec6 + 28480cf commit 76dfa76
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 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 gasFee() method for type 1 transactions and added its test.
- Changed 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-arbitrum-controller",
"version": "1.0.7",
"version": "1.0.8",
"description": "arbitrum 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-arbitrum-controller/issues"
},
Expand Down
20 changes: 16 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,22 @@ class KeyringController extends EventEmitter {
}

async getFees(arbitrumTx, web3) {
const { from, to, value, data, gasLimit } = arbitrumTx
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, manualLimit } = arbitrumTx
const gasLimit = manualLimit ? manualLimit : await web3.eth.estimateGas({ to, from, 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}
}
}

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 arbitrum tx", async () => {
const accounts = await arbitrumKeyring.getAccounts()
const web3 = new Web3(TESTNET.URL);
const tx = {
from: accounts[0],
to: '0x641BB2596D8c0b32471260712566BF933a2f1a8e',
value: 0,
data: "0x00"
}
const getEstimate = await arbitrumKeyring.getFees(tx, web3)
console.log(" get gas estimate ", getEstimate)
})

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

const accounts = await arbitrumKeyring.getAccounts()
Expand Down

0 comments on commit 76dfa76

Please sign in to comment.