This repository was archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 357
(Feature) [xDai] - Use parametrized network values #1437
Merged
fernandomg
merged 8 commits into
feature/#1353-xDai-compatibility
from
feature/#1416-paremeterize-network-selection
Oct 8, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa70dd3
use parametrized network values for wallet connection
fernandomg 29d3b2c
use mainnet contract address as a fallback if network is not defined …
fernandomg 32f353c
comment the reasons of using MAINNET network address
fernandomg a79bf16
replace `getExplorerLink` with the config-based `getExplorerInfo` fun…
fernandomg 10193e6
use config based rpc address
fernandomg a7be1fe
fix explorer domain extraction
fernandomg e7794f0
Revert "use config based rpc address"
dc83b5b
Remove buildSafeCreationTxUrl from config index to avoid circular dep…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| import { AbiItem } from 'web3-utils' | ||
| import contract from 'truffle-contract' | ||
| import Web3 from 'web3' | ||
| import ProxyFactorySol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafeProxyFactory.json' | ||
| import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json' | ||
| import SafeProxy from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafeProxy.json' | ||
| import { ensureOnce } from 'src/utils/singleton' | ||
| import ProxyFactorySol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafeProxyFactory.json' | ||
| import memoize from 'lodash.memoize' | ||
| import { getWeb3, getNetworkIdFrom } from 'src/logic/wallets/getWeb3' | ||
| import { calculateGasOf, calculateGasPrice } from 'src/logic/wallets/ethTransactions' | ||
| import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses' | ||
|
|
||
| import { ETHEREUM_NETWORK } from 'src/config/networks/network.d' | ||
| import { isProxyCode } from 'src/logic/contracts/historicProxyCode' | ||
| import { GnosisSafeProxyFactory } from 'src/types/contracts/GnosisSafeProxyFactory.d'; | ||
| import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses' | ||
| import { calculateGasOf, calculateGasPrice } from 'src/logic/wallets/ethTransactions' | ||
| import { getWeb3, getNetworkIdFrom } from 'src/logic/wallets/getWeb3' | ||
| import { GnosisSafe } from 'src/types/contracts/GnosisSafe.d' | ||
| import { GnosisSafeProxyFactory } from 'src/types/contracts/GnosisSafeProxyFactory.d' | ||
| import Web3 from 'web3' | ||
| import { AbiItem } from 'web3-utils' | ||
|
|
||
| export const SENTINEL_ADDRESS = '0x0000000000000000000000000000000000000001' | ||
| export const MULTI_SEND_ADDRESS = '0x8d29be29923b68abfdd21e541b9374737b49cdad' | ||
|
|
@@ -20,24 +20,39 @@ export const DEFAULT_FALLBACK_HANDLER_ADDRESS = '0xd5D82B6aDDc9027B22dCA772Aa68D | |
| export const SAFE_MASTER_COPY_ADDRESS_V10 = '0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A' | ||
|
|
||
|
|
||
| let proxyFactoryMaster | ||
| let safeMaster | ||
|
|
||
| const createGnosisSafeContract = (web3: Web3) => { | ||
| const gnosisSafe = contract(GnosisSafeSol) | ||
| gnosisSafe.setProvider(web3.currentProvider) | ||
|
|
||
| return gnosisSafe | ||
| let proxyFactoryMaster: GnosisSafeProxyFactory | ||
| let safeMaster: GnosisSafe | ||
|
|
||
| /** | ||
| * Creates a Contract instance of the GnosisSafe contract | ||
| * @param {Web3} web3 | ||
| * @param {ETHEREUM_NETWORK} networkId | ||
| */ | ||
| const createGnosisSafeContract = (web3: Web3, networkId: ETHEREUM_NETWORK) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be typed to return
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the returned type is inferred in this case, shall we add it anyway? I truly don't remember.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you are right, I think it's not needed |
||
| const networks = GnosisSafeSol.networks | ||
| // TODO: this may not be the most scalable approach, | ||
| // but up until v1.2.0 the address is the same for all the networks. | ||
| // So, if we can't find the network in the Contract artifact, we fallback to MAINNET. | ||
| const contractAddress = networks[networkId]?.address ?? networks[ETHEREUM_NETWORK.MAINNET].address | ||
dasanra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new web3.eth.Contract(GnosisSafeSol.abi as AbiItem[], contractAddress) as unknown as GnosisSafe | ||
| } | ||
|
|
||
| const createProxyFactoryContract = (web3: Web3, networkId: number): GnosisSafeProxyFactory => { | ||
| const contractAddress = ProxyFactorySol.networks[networkId].address | ||
| const proxyFactory = new web3.eth.Contract(ProxyFactorySol.abi as AbiItem[], contractAddress) as unknown as GnosisSafeProxyFactory | ||
|
|
||
| return proxyFactory | ||
| /** | ||
| * Creates a Contract instance of the GnosisSafeProxyFactory contract | ||
| * @param {Web3} web3 | ||
| * @param {ETHEREUM_NETWORK} networkId | ||
| */ | ||
| const createProxyFactoryContract = (web3: Web3, networkId: ETHEREUM_NETWORK): GnosisSafeProxyFactory => { | ||
| const networks = ProxyFactorySol.networks | ||
| // TODO: this may not be the most scalable approach, | ||
| // but up until v1.2.0 the address is the same for all the networks. | ||
| // So, if we can't find the network in the Contract artifact, we fallback to MAINNET. | ||
| const contractAddress = networks[networkId]?.address ?? networks[ETHEREUM_NETWORK.MAINNET].address | ||
| return new web3.eth.Contract(ProxyFactorySol.abi as AbiItem[], contractAddress) as unknown as GnosisSafeProxyFactory | ||
| } | ||
|
|
||
| export const getGnosisSafeContract = memoize(createGnosisSafeContract) | ||
|
|
||
| const getCreateProxyFactoryContract = memoize(createProxyFactoryContract) | ||
|
|
||
| const instantiateMasterCopies = async () => { | ||
|
|
@@ -47,25 +62,11 @@ const instantiateMasterCopies = async () => { | |
| // Create ProxyFactory Master Copy | ||
| proxyFactoryMaster = getCreateProxyFactoryContract(web3, networkId) | ||
|
|
||
| // Initialize Safe master copy | ||
| const GnosisSafe = getGnosisSafeContract(web3) | ||
| safeMaster = await GnosisSafe.deployed() | ||
| } | ||
|
|
||
| // ONLY USED IN TEST ENVIRONMENT | ||
| const createMasterCopies = async () => { | ||
| const web3 = getWeb3() | ||
| const accounts = await web3.eth.getAccounts() | ||
| const userAccount = accounts[0] | ||
|
|
||
| const ProxyFactory = getCreateProxyFactoryContract(web3, 4441) | ||
| proxyFactoryMaster = await ProxyFactory.deploy({ data: GnosisSafeSol.bytecode }).send({ from: userAccount, gas: 5000000 }) | ||
|
|
||
| const GnosisSafe = getGnosisSafeContract(web3) | ||
| safeMaster = await GnosisSafe.new({ from: userAccount, gas: '7000000' }) | ||
| // Create Safe Master copy | ||
| safeMaster = getGnosisSafeContract(web3, networkId) | ||
| } | ||
|
|
||
| export const initContracts = process.env.NODE_ENV === 'test' ? ensureOnce(createMasterCopies) : instantiateMasterCopies | ||
| export const initContracts = instantiateMasterCopies | ||
|
|
||
| export const getSafeMasterContract = async () => { | ||
| await initContracts() | ||
|
|
@@ -74,25 +75,25 @@ export const getSafeMasterContract = async () => { | |
| } | ||
|
|
||
| export const getSafeDeploymentTransaction = (safeAccounts, numConfirmations) => { | ||
| const gnosisSafeData = safeMaster.contract.methods | ||
| const gnosisSafeData = safeMaster.methods | ||
| .setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS) | ||
| .encodeABI() | ||
|
|
||
| return proxyFactoryMaster.methods.createProxy(safeMaster.address, gnosisSafeData) | ||
| return proxyFactoryMaster.methods.createProxy(safeMaster.options.address, gnosisSafeData) | ||
| } | ||
|
|
||
| export const estimateGasForDeployingSafe = async ( | ||
| safeAccounts, | ||
| numConfirmations, | ||
| userAccount, | ||
| ) => { | ||
| const gnosisSafeData = await safeMaster.contract.methods | ||
| const gnosisSafeData = await safeMaster.methods | ||
| .setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS) | ||
| .encodeABI() | ||
| const proxyFactoryData = proxyFactoryMaster.methods | ||
| .createProxy(safeMaster.address, gnosisSafeData) | ||
| .createProxy(safeMaster.options.address, gnosisSafeData) | ||
| .encodeABI() | ||
| const gas = await calculateGasOf(proxyFactoryData, userAccount, proxyFactoryMaster.address) | ||
| const gas = await calculateGasOf(proxyFactoryData, userAccount, proxyFactoryMaster.options.address) | ||
| const gasPrice = await calculateGasPrice() | ||
|
|
||
| return gas * parseInt(gasPrice, 10) | ||
|
|
||
This file contains hidden or 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 hidden or 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,10 @@ | ||
| import { getTxServiceUrl, getSafeCreationTxUri } from 'src/config' | ||
| import { checksumAddress } from 'src/utils/checksumAddress' | ||
|
|
||
| export const buildSafeCreationTxUrl = (safeAddress: string): string => { | ||
| const host = getTxServiceUrl() | ||
| const address = checksumAddress(safeAddress) | ||
| const base = getSafeCreationTxUri(address) | ||
|
|
||
| return `${host}${base}` | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.