Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Remove Token Counts #177

Merged
merged 6 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions contracts/ERC20Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,15 @@ import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
contract ERC20Safe {
using SafeMath for uint256;

// ERC20 contract => amount of tokens owned by Safe
mapping(address => uint256) public _balances;

// ERC20 contract => amount of tokens burned by Safe
mapping(address => uint256) public _burnedTokens;

/**
@notice Used to transfer tokens into the safe to fund proposals.
@param tokenAddress Address of ERC20 to transfer.
@param owner Address of current token owner.
@param amount Amount of tokens to transfer.
@notice Increments balance for {tokenAddress}.
*/
function fundERC20(address tokenAddress, address owner, uint256 amount) public {
IERC20 erc20 = IERC20(tokenAddress);
_safeTransferFrom(erc20, owner, address(this), amount);

_balances[tokenAddress] = _balances[tokenAddress].add(amount);
}

/**
Expand All @@ -39,57 +30,44 @@ contract ERC20Safe {
@param owner Address of current token owner.
@param recipient Address to transfer tokens to.
@param amount Amount of tokens to transfer.
@notice Increments balance for {tokenAddress}.
*/
function lockERC20(address tokenAddress, address owner, address recipient, uint256 amount) internal {
IERC20 erc20 = IERC20(tokenAddress);
_safeTransferFrom(erc20, owner, recipient, amount);

_balances[tokenAddress] = _balances[tokenAddress].add(amount);
}

/**
@notice Transfers custody of token to recipient.
@param tokenAddress Address of ERC20 to transfer.
@param recipient Address to transfer tokens to.
@param amount Amount of tokens to transfer.
@notice Decrements balance for {tokenAddress}.
*/
function releaseERC20(address tokenAddress, address recipient, uint256 amount) internal {
IERC20 erc20 = IERC20(tokenAddress);
_safeTransfer(erc20, recipient, amount);

_balances[tokenAddress] = _balances[tokenAddress].sub(amount);
}

/**
@notice Used to create new ERC20s.
@param tokenAddress Address of ERC20 to transfer.
@param recipient Address to mint token to.
@param amount Amount of token to mint.
@notice Increments balance for {tokenAddress}.
*/
function mintERC20(address tokenAddress, address recipient, uint256 amount) internal {
ERC20PresetMinterPauser erc20 = ERC20PresetMinterPauser(tokenAddress);
erc20.mint(recipient, amount);

if (address(this) == recipient) {
_balances[tokenAddress] = _balances[tokenAddress].add(amount);
}
}

/**
@notice Used to burn ERC20s.
@param tokenAddress Address of ERC20 to burn.
@param owner Current owner of tokens.
@param amount Amount of tokens to burn.
@notice Increments {_burnedTokens} balance for {tokenAddress}.
*/
function burnERC20(address tokenAddress, address owner, uint256 amount) internal {
ERC20Burnable erc20 = ERC20Burnable(tokenAddress);
erc20.burnFrom(owner, amount);

_burnedTokens[tokenAddress] = _burnedTokens[tokenAddress].add(amount);
}

/**
Expand Down
22 changes: 0 additions & 22 deletions contracts/ERC721Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,15 @@ import "./ERC721MinterBurnerPauser.sol";
contract ERC721Safe {
using SafeMath for uint256;

// ERC721 contract => amount of tokens owned by Safe
mapping(address => uint256) public _balances;

// ERC721 contract => amount of tokens burned by Safe
mapping(address => uint256) public _burnedTokens;

/**
@notice Used to transfer tokens into the safe to fund proposals.
@param tokenAddress Address of ERC721 to transfer.
@param owner Address of current token owner.
@param tokenID ID of token to transfer.
@notice Increments balance for {tokenAddress}.
*/
function fundERC721(address tokenAddress, address owner, uint tokenID) public {
IERC721 erc721 = IERC721(tokenAddress);
erc721.transferFrom(owner, address(this), tokenID);

_balances[tokenAddress] = _balances[tokenAddress].add(1);
}

/**
Expand All @@ -38,13 +29,11 @@ contract ERC721Safe {
@param owner Address of current token owner.
@param recipient Address to transfer token to.
@param tokenID ID of token to transfer.
@notice Increments balance for {tokenAddress}.
*/
function lockERC721(address tokenAddress, address owner, address recipient, uint tokenID) internal {
IERC721 erc721 = IERC721(tokenAddress);
erc721.transferFrom(owner, recipient, tokenID);

_balances[tokenAddress] = _balances[tokenAddress].add(1);
}

/**
Expand All @@ -53,13 +42,10 @@ contract ERC721Safe {
@param owner Address of current token owner.
@param recipient Address to transfer token to.
@param tokenID ID of token to transfer.
@notice Decrements balance for {tokenAddress}.
*/
function releaseERC721(address tokenAddress, address owner, address recipient, uint256 tokenID) internal {
IERC721 erc721 = IERC721(tokenAddress);
erc721.transferFrom(owner, recipient, tokenID);

_balances[tokenAddress] = _balances[tokenAddress].sub(1);
}

/**
Expand All @@ -68,28 +54,20 @@ contract ERC721Safe {
@param recipient Address to mint token to.
@param tokenID ID of token to mint.
@param data Optional data to send along with mint call.
@notice Increments balance for {tokenAddress}.
*/
function mintERC721(address tokenAddress, address recipient, uint256 tokenID, bytes memory data) internal {
ERC721MinterBurnerPauser erc721 = ERC721MinterBurnerPauser(tokenAddress);
erc721.mint(recipient, tokenID, string(data));

if (address(this) == recipient) {
_balances[tokenAddress] = _balances[tokenAddress].add(1);
}
}

/**
@notice Used to burn ERC721s.
@param tokenAddress Address of ERC721 to burn.
@param tokenID ID of token to burn.
@notice Increments {_burnedTokens} balance for {tokenAddress}.
*/
function burnERC721(address tokenAddress, uint256 tokenID) internal {
ERC721MinterBurnerPauser erc721 = ERC721MinterBurnerPauser(tokenAddress);
erc721.burn(tokenID);

_burnedTokens[tokenAddress] = _burnedTokens[tokenAddress].add(1);
}

}
35 changes: 0 additions & 35 deletions test/handlers/erc20/depositBurn.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,4 @@ contract('ERC20Handler - [Deposit Burn ERC20]', async (accounts) => {
assert.isTrue(isBurnable, "Contract wasn't successfully marked burnable");
}
});

it('[sanity] ERC20HandlerInstance.address should have an allowance of depositAmount from depositerAddress', async () => {
const handlerAllowance = await ERC20MintableInstance1.allowance(depositerAddress, ERC20HandlerInstance.address);
assert.strictEqual(handlerAllowance.toNumber(), depositAmount);
});

it('depositAmount of ERC20MintableInstance1 tokens should have been burned', async () => {
await BridgeInstance.deposit(
chainID,
resourceID1,
depositData,
{ from: depositerAddress }
);

const handlerAllowance = await ERC20MintableInstance1.allowance(depositerAddress, ERC20HandlerInstance.address);
assert.strictEqual(handlerAllowance.toNumber(), 0);

const handlerBalance = await ERC20MintableInstance1.balanceOf(ERC20HandlerInstance.address);
assert.strictEqual(handlerBalance.toNumber(), 0);

const zeroAddressBalance = await ERC20MintableInstance1.balanceOf(Ethers.utils.hexZeroPad('0x0', 20));
assert.strictEqual(zeroAddressBalance.toNumber(), 0);
});

it('_burnedTokens for ERC20MintableInstance1.address should have been incremented by depositAmount', async () => {
await BridgeInstance.deposit(
chainID,
resourceID1,
depositData,
{ from: depositerAddress }
);

const numBurnedTokens = await ERC20HandlerInstance._burnedTokens.call(ERC20MintableInstance1.address);
assert.strictEqual(numBurnedTokens.toNumber(), depositAmount);
});
});