Skip to content

Commit

Permalink
add Transfer event to mints and burns. add requires to btoken math fo…
Browse files Browse the repository at this point in the history
…r insufficient balance
  • Loading branch information
mikemcdonald committed Nov 11, 2019
1 parent d70a735 commit 16f15f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 0 additions & 4 deletions contracts/BConst.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ contract BConst is BBronze
uint256 constant MAX_IN_RATIO = BONE / 2;
uint256 constant MAX_OUT_RATIO = (BONE / 3) + 1 wei;


string constant ERR_ADD_OVERFLOW = "ERR_ADD_OVERFLOW";
string constant ERR_SUB_UNDERFLOW = "ERR_SUB_UNDERFLOW";
string constant ERR_MUL_OVERFLOW = "ERR_MUL_OVERFLOW";
Expand Down Expand Up @@ -69,9 +68,6 @@ contract BConst is BBronze
string constant ERR_NOT_FACTORY = "ERR_NOT_FACTORY";

string constant ERR_SWAP_NOT_PUBLIC = "ERR_SWAP_NOT_PUBLIC"; // trying to swap
string constant ERR_JOIN_NOT_PUBLIC = "ERR_JOIN_NOT_PUBLIC"; // trying to join
string constant ERR_EXIT_NOT_PUBLIC = "ERR_EXIT_NOT_PUBLIC"; // trying to exit (never thrown in bronze)
string constant ERR_EXIT_ALWAYS_PUBLIC = "ERR_EXIT_ALWAYS_PUBLIC"; // trying to setPublicExit(false) in bronze

string constant ERR_REENTRY = "ERR_REENTRY";
string constant ERR_ERC20_FALSE = "ERR_ERC20_FALSE";
Expand Down
7 changes: 6 additions & 1 deletion contracts/BToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,31 @@ contract BTokenBase is BNum

event Mint(uint amt);
event Burn(uint amt);
event Transfer(address indexed src, address indexed dst, uint amt);
event Move(address indexed src, address indexed dst, uint amt);

function sub(uint a, uint b) internal pure returns (uint) {
require(a >= b, "ERR_BTOKEN_UNDERFLOW"); // TODO report 'insufficient balance' if that's the case
require(a >= b, "ERR_BTOKEN_UNDERFLOW");
return a - b;
}

function _mint(uint amt) internal {
_balance[address(this)] = badd(_balance[address(this)], amt);
_totalSupply = badd(_totalSupply, amt);
emit Mint(amt);
emit Transfer(address(0), address(this), amt);
}

function _burn(uint amt) internal {
require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL");
_balance[address(this)] = sub(_balance[address(this)], amt);
_totalSupply = sub(_totalSupply, amt);
emit Burn(amt);
emit Transfer(address(this), address(0), amt);
}

function _move(address src, address dst, uint amt) internal {
require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL");
_balance[src] = sub(_balance[src], amt);
_balance[dst] = badd(_balance[dst], amt);
emit Move(src, dst, amt);
Expand Down
2 changes: 1 addition & 1 deletion test/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ contract('BPool', async (accounts) => {
});

it('Fails binding weights and balances outside MIX MAX', async () => {
await assertThrow(pool.bind(WETH, toWei('51'), toWei('1')), 'ERR_BTOKEN_UNDERFLOW'); // TODO change error to insufficient balance
await assertThrow(pool.bind(WETH, toWei('51'), toWei('1')), 'ERR_INSUFFICIENT_BAL');
await assertThrow(pool.bind(MKR, toWei('0.0000001'), toWei('1')), 'ERR_MIN_BALANCE');
await assertThrow(pool.bind(MKR, toWei('10000000000000000'), toWei('1')), 'ERR_MAX_BALANCE');
await assertThrow(pool.bind(DAI, toWei('1000'), toWei('0.99')), 'ERR_MIN_WEIGHT');
Expand Down

0 comments on commit 16f15f6

Please sign in to comment.