This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from gnosis/development
Development to master
- Loading branch information
Showing
66 changed files
with
1,416 additions
and
854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ build_webpack/ | |
build_storybook/ | ||
.DS_Store | ||
build/ | ||
yarn-error.log | ||
yarn-error.log | ||
.env.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// @flow | ||
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json' | ||
import { type Transaction } from '~/routes/safe/store/models/transaction' | ||
import { getWeb3, getAccountFrom } from '~/logic/wallets/getWeb3' | ||
import { generateSignaturesFromTxConfirmations } from '~/routes/safe/store/actions/processTransaction' | ||
import { calculateGasOf, calculateGasPrice } from '~/logic/wallets/ethTransactions' | ||
import { ZERO_ADDRESS } from '~/logic/wallets/ethAddresses' | ||
import { CALL } from '.' | ||
|
||
export const estimateTxGasCosts = async ( | ||
safeAddress: string, | ||
to: string, | ||
data: string, | ||
tx?: Transaction, | ||
preApprovingOwner?: string, | ||
): Promise<number> => { | ||
try { | ||
const web3 = getWeb3() | ||
const from = await getAccountFrom(web3) | ||
const safeInstance = new web3.eth.Contract(GnosisSafeSol.abi, safeAddress) | ||
const nonce = await safeInstance.methods.nonce().call() | ||
const threshold = await safeInstance.methods.getThreshold().call() | ||
|
||
const isExecution = (tx && tx.confirmations.size === threshold) || !!preApprovingOwner || threshold === '1' | ||
|
||
let txData | ||
if (isExecution) { | ||
// https://gnosis-safe.readthedocs.io/en/latest/contracts/signatures.html#pre-validated-signatures | ||
const signatures = tx && tx.confirmations | ||
? generateSignaturesFromTxConfirmations(tx.confirmations, preApprovingOwner) | ||
: `0x000000000000000000000000${from.replace( | ||
'0x', | ||
'', | ||
)}000000000000000000000000000000000000000000000000000000000000000001` | ||
txData = await safeInstance.methods | ||
.execTransaction(to, tx ? tx.value : 0, data, CALL, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, signatures) | ||
.encodeABI() | ||
} else { | ||
const txHash = await safeInstance.methods | ||
.getTransactionHash(to, tx ? tx.value : 0, data, CALL, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, nonce) | ||
.call({ | ||
from, | ||
}) | ||
txData = await safeInstance.methods.approveHash(txHash).encodeABI() | ||
} | ||
|
||
const gas = await calculateGasOf(txData, from, safeAddress) | ||
const gasPrice = await calculateGasPrice() | ||
|
||
return gas * parseInt(gasPrice, 10) | ||
} catch (err) { | ||
console.error('Error while estimating transaction execution gas costs:') | ||
console.error(err) | ||
|
||
return 10000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// @flow | ||
// https://github.com/ethers-io/ethers.js/issues/527 | ||
|
||
export const ALTERNATIVE_TOKEN_ABI = [ | ||
{ | ||
constant: true, | ||
inputs: [], | ||
name: 'name', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'bytes32', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: true, | ||
inputs: [], | ||
name: 'symbol', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'bytes32', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: true, | ||
inputs: [], | ||
name: 'decimals', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'uint8', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.