Skip to content

Commit

Permalink
Merge branch 'main' into tron-tusd-contracts
Browse files Browse the repository at this point in the history
* main:
  🎦 Fix: add CI test (#2)
  πŸŠβ€β™‚οΈ Freeze Watr native token on blacklisting (trusttoken#1256)
  πŸ› Use XC-20 standard for `contracts-watr` TrueUSD (trusttoken#1252)
  🌊 Setup `contracts-watr` deployment (trusttoken#1251)
  ⬇️ Lower amount in `Pool Curve integration` test (trusttoken#1255)
  • Loading branch information
qiwihui committed Aug 9, 2023
2 parents 716fce8 + c2aee5e commit f734afd
Show file tree
Hide file tree
Showing 38 changed files with 2,668 additions and 377 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Lint and Test
on:
push:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
build:
name: Build
runs-on: ubuntu-latest
container: python:3.10.5
steps:
- name: checkout
uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Install yarn
run: npm install -g yarn
- name: Pull submodules
run: git submodule init && git submodule update
- name: Install dependencies
run: |
yarn install --frozen-lockfile
pip3 install -U pip setuptools virtualenv
pip3 install -r requirements-dev.txt
- name: Build
run: |
yarn build
yarn typecheck
yarn workspace @trusttoken-smart-contracts/contracts-por build
- name: lint
if: success() || failure()
run: yarn lint
- name: lint por
if: success() || failure()
run: yarn workspace @trusttoken-smart-contracts/contracts-por lint
- name: test por
if: success() || failure()
run: yarn workspace @trusttoken-smart-contracts/contracts-por test
- name: test-others
if: success() || failure()
run: |
yarn test:proxy
yarn test:registry
yarn test:true-currencies
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
25 changes: 23 additions & 2 deletions packages/contracts-watr/contracts/TokenControllerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {IRegistry} from "./interface/IRegistry.sol";
import {IOwnedUpgradeabilityProxy} from "./interface/IOwnedUpgradeabilityProxy.sol";
import {ITrueCurrency} from "./interface/ITrueCurrency.sol";
import {IProofOfReserveToken} from "./interface/IProofOfReserveToken.sol";
import {IClaimableOwnable} from "./interface/IClaimableOwnable.sol";

/** @title TokenController
* @dev This contract allows us to split ownership of the TrueCurrency contract
Expand Down Expand Up @@ -84,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 @@ -183,6 +184,13 @@ contract TokenControllerV3 {
_;
}

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

/**
* @dev Modifier throws if called by any account other than proofOfReserveEnabler or owner.
*/
Expand All @@ -209,6 +217,19 @@ contract TokenControllerV3 {
pendingOwner = address(0);
}

/*
========================================
token ownership
========================================
*/
function transferTrueCurrencyOwnership(address _newOwner) external onlyOwner {
IClaimableOwnable(address(token)).transferOwnership(_newOwner);
}

function claimTrueCurrencyOwnership() public onlyOwner {
IClaimableOwnable(address(token)).claimOwnership();
}

/*
========================================
proxy functions
Expand Down Expand Up @@ -572,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
27 changes: 25 additions & 2 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,6 +57,13 @@ abstract contract TrueCurrency is BurnableTokenWithBounds {
*/
event Mint(address indexed to, uint256 value);

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

/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
Expand Down Expand Up @@ -86,6 +96,7 @@ abstract contract TrueCurrency is BurnableTokenWithBounds {
*/
function setBlacklisted(address account, bool _isBlacklisted) external override onlyOwner {
require(uint256(account) >= REDEMPTION_ADDRESS_COUNT, "TrueCurrency: blacklisting of redemption address is not allowed");
_setBlacklistedXC20(account, _isBlacklisted);
isBlacklisted[account] = _isBlacklisted;
emit Blacklisted(account, _isBlacklisted);
}
Expand Down Expand Up @@ -120,8 +131,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 Expand Up @@ -168,4 +180,15 @@ abstract contract TrueCurrency is BurnableTokenWithBounds {
function isRedemptionAddress(address account) internal pure returns (bool) {
return uint256(account) < REDEMPTION_ADDRESS_COUNT && account != address(0);
}

function _setBlacklistedXC20(address account, bool _isBlacklisted) internal {
if (isBlacklisted[account] == _isBlacklisted) {
return;
}
if (_isBlacklisted) {
_freeze(account);
} else {
_thaw(account);
}
}
}
7 changes: 4 additions & 3 deletions packages/contracts-watr/contracts/common/ClaimableOwnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
pragma solidity 0.6.10;

import {ProxyStorage} from "./ProxyStorage.sol";
import {IClaimableOwnable} from "../interface/IClaimableOwnable.sol";

/**
* @title ClamableOwnable
* @dev The ClamableOwnable contract is a copy of Claimable Contract by Zeppelin.
* and provides basic authorization control functions. Inherits storage layout of
* ProxyStorage.
*/
contract ClaimableOwnable is ProxyStorage {
contract ClaimableOwnable is ProxyStorage, IClaimableOwnable {
/**
* @dev emitted when ownership is transferred
* @param previousOwner previous owner of this contract
Expand Down Expand Up @@ -46,14 +47,14 @@ contract ClaimableOwnable is ProxyStorage {
* @dev Allows the current owner to set the pendingOwner address.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) external onlyOwner {
function transferOwnership(address newOwner) external override onlyOwner {
pendingOwner = newOwner;
}

/**
* @dev Allows the pendingOwner address to finalize the transfer.
*/
function claimOwnership() external onlyPendingOwner {
function claimOwnership() external override onlyPendingOwner {
emit OwnershipTransferred(owner, pendingOwner);
owner = pendingOwner;
pendingOwner = address(0);
Expand Down
Loading

0 comments on commit f734afd

Please sign in to comment.