Skip to content

Commit

Permalink
Freeze native asset on pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
abam-iksde committed Apr 17, 2023
1 parent 1a9ce45 commit c91e8bf
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/contracts-watr/contracts/TokenControllerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ contract TokenControllerV3 {
* @dev pause all pausable actions on TrueCurrency, mints/burn/transfer/approve
*/
function pauseToken() external virtual onlyOwner {
token.pauseNative();
IOwnedUpgradeabilityProxy(address(token)).upgradeTo(pausedImplementation);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/contracts-watr/contracts/TrueCurrency.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ abstract contract TrueCurrency is BurnableTokenWithBounds {
canBurn[account] = _canBurn;
}

function pauseNative() external override onlyOwner {
_freezeAsset();
}

/**
* @dev Check if neither account is blacklisted before performing transfer
* If transfer recipient is a redemption address, burns tokens
Expand Down
8 changes: 8 additions & 0 deletions packages/contracts-watr/contracts/common/XC20Wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,12 @@ abstract contract XC20Wrapper is IERC20, ClaimableOwnable, Context {
function _thaw(address account) internal {
IMintableXC20(nativeToken).thaw(account);
}

function _freezeAsset() internal {
IMintableXC20(nativeToken).freezeAsset();
}

function _thawAsset() internal {
IMintableXC20(nativeToken).thawAsset();
}
}
8 changes: 6 additions & 2 deletions packages/contracts-watr/contracts/interface/IMintableXC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ pragma solidity 0.6.10;
import {IERC20Plus} from "./IERC20Plus.sol";

interface IMintableXC20 is IERC20Plus {
function freeze(address account) external;
function freeze(address account) external returns (bool);

function thaw(address account) external;
function thaw(address account) external returns (bool);

function freezeAsset() external returns (bool);

function thawAsset() external returns (bool);
}
2 changes: 2 additions & 0 deletions packages/contracts-watr/contracts/interface/ITrueCurrency.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ interface ITrueCurrency {
function reclaimToken(IERC20 token, address _to) external;

function setBlacklisted(address account, bool isBlacklisted) external;

function pauseNative() external;
}
17 changes: 15 additions & 2 deletions packages/contracts-watr/contracts/mocks/MockXC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ contract MockXC20 {
uint8 public decimals;

mapping(address => bool) public frozen;
bool public assetFrozen;

constructor(uint8 _decimals) public {
decimals = _decimals;
Expand All @@ -27,11 +28,23 @@ contract MockXC20 {
return true;
}

function freeze(address account) public {
function freeze(address account) public returns (bool) {
frozen[account] = true;
return true;
}

function thaw(address account) public {
function thaw(address account) public returns (bool) {
frozen[account] = false;
return true;
}

function freezeAsset() public returns (bool) {
assetFrozen = true;
return true;
}

function thawAsset() public returns (bool) {
assetFrozen = false;
return true;
}
}
12 changes: 9 additions & 3 deletions packages/contracts-watr/test/TokenController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
MockTrueCurrency,
ForceEther,
ForceEther__factory,
MockXC20__factory, TokenControllerV3__factory, TokenControllerV3,
MockXC20__factory, TokenControllerV3__factory, TokenControllerV3, MockXC20,
} from 'contracts'
import { trueUSDDecimals } from 'utils'

Expand All @@ -35,6 +35,7 @@ describe('TokenController', () => {
let ratifier2: Wallet
let ratifier3: Wallet

let mockXC20: MockXC20
let token: MockTrueCurrency
let tokenImplementation: MockTrueCurrency
let tokenProxy: OwnedUpgradeabilityProxy
Expand All @@ -59,9 +60,9 @@ describe('TokenController', () => {
tokenImplementation = await new MockTrueCurrency__factory(owner).deploy()
await tokenProxy.upgradeTo(tokenImplementation.address)

const xc20 = await new MockXC20__factory(owner).deploy(trueUSDDecimals)
mockXC20 = await new MockXC20__factory(owner).deploy(trueUSDDecimals)
token = new MockTrueCurrency__factory(owner).attach(tokenProxy.address)
await token.initialize(xc20.address)
await token.initialize(mockXC20.address)

await token.transferOwnership(controller.address)
await controller.initialize(pausedImplementationAddress)
Expand Down Expand Up @@ -525,6 +526,11 @@ describe('TokenController', () => {
await expect(controller.connect(mintKey).pauseToken())
.to.be.reverted
})

it('pauseToken calls freezeAsset on native asset', async () => {
await controller.pauseToken()
expect(await mockXC20.assetFrozen()).to.be.true
})
})

describe('fall back function', function () {
Expand Down

0 comments on commit c91e8bf

Please sign in to comment.