Skip to content

Commit

Permalink
Merge pull request #592 from tokencard/remove-proxy-Admin
Browse files Browse the repository at this point in the history
Use UpgradeabilityProxy
  • Loading branch information
i-stam committed Jul 8, 2020
2 parents 16ce726 + b5c9757 commit f7ccd57
Show file tree
Hide file tree
Showing 27 changed files with 394 additions and 1,056 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract_sources=(
'mocks/walletMock'
'externals/ens/PublicResolver'
'externals/ens/ENSRegistry'
'externals/upgradeability/AdminUpgradeabilityProxy'
'externals/upgradeability/UpgradeabilityProxy'
)

for c in "${contract_sources[@]}"
Expand Down Expand Up @@ -72,7 +72,7 @@ contracts=(
"mocks/walletMock/WalletMock mocks/walletMock.go WalletMock mocks"
"externals/ens/ENSRegistry/ENSRegistry externals/ens/ENSRegistry.go ENSRegistry ens"
"externals/ens/PublicResolver/PublicResolver externals/ens/PublicResolver.go PublicResolver ens"
"externals/upgradeability/AdminUpgradeabilityProxy/AdminUpgradeabilityProxy externals/upgradeability/AdminUpgradeabilityProxy.go AdminUpgradeabilityProxy upgradeability"
"externals/upgradeability/UpgradeabilityProxy/UpgradeabilityProxy externals/upgradeability/UpgradeabilityProxy.go UpgradeabilityProxy upgradeability"
)

for c in "${contracts[@]}"
Expand Down
24 changes: 0 additions & 24 deletions contracts/externals/upgradeability/AdminUpgradeabilityProxy.sol

This file was deleted.

This file was deleted.

16 changes: 8 additions & 8 deletions contracts/externals/upgradeability/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ pragma solidity ^0.5.0;
* returned by the abstract _implementation() internal function.
*/
contract Proxy {

event Received(address _from, uint256 _amount);

/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
function () payable external {
_fallback();
if (msg.data.length == 0) {
emit Received(msg.sender, msg.value);
return;
}
_delegate(_implementation());
}

/**
Expand Down Expand Up @@ -48,11 +55,4 @@ contract Proxy {
}
}

/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_delegate(_implementation());
}
}
4 changes: 2 additions & 2 deletions contracts/oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ contract Oracle is ENSResolvable, usingOraclize, Transferrable, Base64, Date, Co
// Require that the proof is valid.
if (valid) {
// Parse the JSON result to get the rate in wei.
uint256 parsedRate = _parseIntScientificWei(parseRate(_result));
uint256 parsedRate = _parseIntScientificWei(_parseRate(_result));
// Set the update time of the token rate.
uint256 parsedLastUpdate = timestamp;
// Remove query from the list.
Expand All @@ -149,7 +149,7 @@ contract Oracle is ENSResolvable, usingOraclize, Transferrable, Base64, Date, Co

/// @notice Extracts JSON rate value from the response object.
/// @param _json body of the JSON response from the CryptoCompare API.
function parseRate(string memory _json) internal pure returns (string memory) {
function _parseRate(string memory _json) internal pure returns (string memory) {
uint256 jsonLen = abi.encodePacked(_json).length;
//{"ETH":}.length = 8, assuming a (maximum of) 18 digit prevision
require(jsonLen > 8 && jsonLen <= 28, "misformatted input");
Expand Down
20 changes: 7 additions & 13 deletions contracts/wallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,11 @@ contract Wallet is ENSResolvable, AddressWhitelist, SpendLimit, GasTopUpLimit, L
event ExecutedTransaction(address _destination, uint256 _value, bytes _data, bytes _returndata);
event IncreasedRelayNonce(address _sender, uint256 _currentNonce);
event LoadedTokenCard(address _asset, uint256 _amount);
event Received(address _from, uint256 _amount);
event ToppedUpGas(address _sender, address _owner, uint256 _amount);
event Transferred(address _to, address _asset, uint256 _amount);
event UpdatedAvailableLimit(); // This is here because our tests don't inherit events from a library

string public constant WALLET_VERSION = "3.2.0";
string public constant WALLET_VERSION = "3.3.1";

// keccak256("isValidSignature(bytes,bytes)") = 20c13b0bc670c284a9f19cdf7a533ca249404190f8dc132aac33e733b965269e
bytes4 private constant _EIP_1271 = 0x20c13b0b;
Expand Down Expand Up @@ -575,17 +574,6 @@ contract Wallet is ENSResolvable, AddressWhitelist, SpendLimit, GasTopUpLimit, L
_;
}

/// @dev Ether can be deposited from any source, so this contract must be payable by anyone.
function() external payable {
emit Received(msg.sender, msg.value);
}

/// @dev This returns the balance of the contract for any ERC20 token or ETH.
/// @param _asset is the address of an ERC20 token or 0x0 for ETH.
function getBalance(address _asset) external view returns (uint256) {
return _balance(_asset);
}

/// @dev This is a bulk transfer convenience function, used to migrate contracts.
/// @notice If any of the transfers fail, this will revert.
/// @param _to is the recipient's address, can't be the zero (0x0) address: transfer() will revert.
Expand Down Expand Up @@ -629,6 +617,12 @@ contract Wallet is ENSResolvable, AddressWhitelist, SpendLimit, GasTopUpLimit, L
emit ExecutedRelayedTransaction(_data, returndata);
}

/// @dev This returns the balance of the contract for any ERC20 token or ETH.
/// @param _asset is the address of an ERC20 token or 0x0 for ETH.
function getBalance(address _asset) external view returns (uint256) {
return _balance(_asset);
}

/// @dev This allows the user to cancel a transaction that was unexpectedly delayed by the relayer
function increaseRelayNonce() external onlyOwner {
_increaseRelayNonce();
Expand Down
12 changes: 2 additions & 10 deletions contracts/walletCache.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
pragma solidity 0.5.17;

import "./wallet.sol";
import "./externals/upgradeability/AdminUpgradeabilityProxy.sol";
import "./externals/upgradeability/UpgradeabilityProxy.sol";
import "./internals/ensResolvable.sol";
import "./internals/controllable.sol";

Expand All @@ -33,7 +33,6 @@ interface IWalletCache {
//// @title Wallet cache with wallet pre-caching functionality.
contract WalletCache is ENSResolvable, Controllable {
event CachedWallet(address payable _wallet);
event setNewWalletImplementation(address _newWalletImplementation);

/***** Constants *****/
// Default values for mainnet ENS
Expand Down Expand Up @@ -95,13 +94,6 @@ contract WalletCache is ENSResolvable, Controllable {
return cachedWallets.length;
}

/// @notice Sets a new wallet implementation.
function setNewWalletImplementaton(address _newWalletImplementation) external onlyAdmin {
require(_newWalletImplementation != address(0) && _newWalletImplementation != walletImplementation, "invalid implementation");
walletImplementation = _newWalletImplementation;
emit setNewWalletImplementation(_newWalletImplementation);
}

/// @notice This public method allows only the wallet deployer to pop pre-cached wallets or create a new one in case there aren't any
function walletCachePop() external onlyWalletDeployer returns (address payable) {
if (cachedWallets.length < 1) {
Expand All @@ -117,7 +109,7 @@ contract WalletCache is ENSResolvable, Controllable {
/// @notice This public method allows anyone to pre-cache wallets
function cacheWallet() public {
address walletDeployerAddress = _ensResolve(walletDeployerNode);
address payable wallet = address(new AdminUpgradeabilityProxy(walletImplementation, walletDeployerAddress, ""));
address payable wallet = address(new UpgradeabilityProxy(walletImplementation, ""));
Wallet(wallet).initializeWallet(
address(uint160(walletDeployerAddress)), // the address(uint160()) cast is done as the Wallet owner (1st argument) needs to be payable
true,
Expand Down
4 changes: 0 additions & 4 deletions contracts/walletDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ contract WalletDeployer is ENSResolvable, Controllable {

deployedWallets[_owner] = wallet;

// We have το change the owner of the proxy before transfring ownership of the wallet.
BaseAdminUpgradeabilityProxy(wallet).changeAdmin(_owner);
// This sets the 'transferable' boolean to false, i.e. no more change of ownership.
Wallet(wallet).transferOwnership(_owner, false);
}
Expand Down Expand Up @@ -100,8 +98,6 @@ contract WalletDeployer is ENSResolvable, Controllable {
Wallet(wallet).setWhitelist(_whitelistedAddresses);
}

// Change admin before transferring owenrship.
BaseAdminUpgradeabilityProxy(wallet).changeAdmin(_owner);
// Change ownership and set transferable to false so ownership cannot be transferred again.
Wallet(wallet).transferOwnership(_owner, false);

Expand Down
Loading

0 comments on commit f7ccd57

Please sign in to comment.