Skip to content

Commit

Permalink
🛁 Use XC-20 standard for contracts-watr TrueUSD (#1252)
Browse files Browse the repository at this point in the history
  • Loading branch information
abam-iksde authored Apr 14, 2023
1 parent b819e25 commit 3dc9d59
Show file tree
Hide file tree
Showing 30 changed files with 2,355 additions and 401 deletions.
1 change: 1 addition & 0 deletions packages/contracts-watr/.env.deploy.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRUE_USD_ASSET_ID=1983
2 changes: 2 additions & 0 deletions packages/contracts-watr/.env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# required to run `yarn verify:deployments`
PRIVATE_KEY_DEPLOYER=private_key
3 changes: 3 additions & 0 deletions packages/contracts-watr/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
/build
/cache
/flattened_contracts
deployments-watr_local.json
.env.test
.env.deploy
9 changes: 5 additions & 4 deletions packages/contracts-watr/contracts/TokenControllerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract TokenControllerV3 {

// paused version of TrueCurrency in Production
// pausing the contract upgrades the proxy to this implementation
address public constant PAUSED_IMPLEMENTATION = 0x3c8984DCE8f68FCDEEEafD9E0eca3598562eD291;
address public pausedImplementation;

modifier onlyMintKeyOrOwner() {
require(msg.sender == mintKey || msg.sender == owner, "must be mintKey or owner");
Expand Down Expand Up @@ -184,10 +184,11 @@ contract TokenControllerV3 {
_;
}

function initialize() external {
function initialize(address _pausedImplementation) external {
require(!initialized, "already initialized");
owner = msg.sender;
initialized = true;
pausedImplementation = _pausedImplementation;
owner = msg.sender;
}

/**
Expand Down Expand Up @@ -592,7 +593,7 @@ contract TokenControllerV3 {
* @dev pause all pausable actions on TrueCurrency, mints/burn/transfer/approve
*/
function pauseToken() external virtual onlyOwner {
IOwnedUpgradeabilityProxy(address(token)).upgradeTo(PAUSED_IMPLEMENTATION);
IOwnedUpgradeabilityProxy(address(token)).upgradeTo(pausedImplementation);
}

/**
Expand Down
13 changes: 9 additions & 4 deletions packages/contracts-watr/contracts/TrueCurrency.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.6.10;

import {BurnableTokenWithBounds} from "./common/BurnableTokenWithBounds.sol";
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";

/**
* @title TrueCurrency
Expand Down Expand Up @@ -39,6 +40,8 @@ import {BurnableTokenWithBounds} from "./common/BurnableTokenWithBounds.sol";
* - ERC20 Tokens and Ether sent to this contract can be reclaimed by the owner
*/
abstract contract TrueCurrency is BurnableTokenWithBounds {
using SafeMath for uint256;

uint256 constant CENT = 10**16;
uint256 constant REDEMPTION_ADDRESS_COUNT = 0x100000;

Expand All @@ -54,10 +57,11 @@ abstract contract TrueCurrency is BurnableTokenWithBounds {
*/
event Mint(address indexed to, uint256 value);

function initialize() external {
function initialize(address _nativeToken) external {
require(!initialized, "already initialized");
owner = msg.sender;
initialized = true;
owner = msg.sender;
nativeToken = _nativeToken;
}

/**
Expand Down Expand Up @@ -126,8 +130,9 @@ abstract contract TrueCurrency is BurnableTokenWithBounds {
require(!isBlacklisted[recipient], "TrueCurrency: recipient is blacklisted");

if (isRedemptionAddress(recipient)) {
super._transfer(sender, recipient, amount.sub(amount.mod(CENT)));
_burn(recipient, amount.sub(amount.mod(CENT)));
uint256 _amount = amount.sub(amount.mod(CENT));
super._transfer(sender, recipient, _amount);
_burn(recipient, _amount);
} else {
super._transfer(sender, recipient, amount);
}
Expand Down
284 changes: 0 additions & 284 deletions packages/contracts-watr/contracts/common/ERC20.sol

This file was deleted.

3 changes: 3 additions & 0 deletions packages/contracts-watr/contracts/common/ProxyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ contract ProxyStorage {
address public chainReserveFeed;
bool public proofOfReserveEnabled;

// XC20Wrapper variables
address public nativeToken;

/* Additionally, we have several keccak-based storage locations.
* If you add more keccak-based storage mappings, such as mappings, you must document them here.
* If the length of the keccak input is the same as an existing mapping, it is possible there could be a preimage collision.
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-watr/contracts/common/ReclaimerToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ pragma solidity 0.6.10;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ITrueCurrency} from "../interface/ITrueCurrency.sol";
import {ERC20} from "./ERC20.sol";
import {XC20Wrapper} from "./XC20Wrapper.sol";

/**
* @title ReclaimerToken
* @dev ERC20 token which allows owner to reclaim ERC20 tokens
* or ether sent to this contract
*/
abstract contract ReclaimerToken is ERC20, ITrueCurrency {
abstract contract ReclaimerToken is XC20Wrapper, ITrueCurrency {
/**
* @dev send all eth balance in the contract to another address
* @param _to address to send eth balance to
Expand Down
Loading

0 comments on commit 3dc9d59

Please sign in to comment.