Skip to content

Commit

Permalink
added events
Browse files Browse the repository at this point in the history
  • Loading branch information
Aodhgan authored and PierrickGT committed Jul 7, 2021
1 parent a151fe4 commit 0d28569
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions contracts/SushiYieldSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ contract SushiYieldSource is IYieldSource {

mapping(address => uint256) public balances;

/// @notice Emitted when asset tokens are redeemed from the yield source
event RedeemedToken(
address indexed from,
uint256 shares,
uint256 amount
);

/// @notice Emitted when asset tokens are supplied to the yield source
event SuppliedTokenTo(
address indexed from,
uint256 shares,
uint256 amount,
address indexed to
);

constructor(ISushiBar _sushiBar, ISushi _sushiAddr) public {
sushiBar = _sushiBar;
sushiAddr = _sushiAddr;
Expand Down Expand Up @@ -57,6 +72,7 @@ contract SushiYieldSource is IYieldSource {
uint256 balanceDiff = afterBalance.sub(beforeBalance);

balances[to] = balances[to].add(balanceDiff);
emit SuppliedTokenTo(msg.sender, balanceDiff, amount, to);
}

/// @notice Redeems tokens from the yield source to the msg.sender, it burns yield bearing tokens and returns token to the sender.
Expand Down Expand Up @@ -87,6 +103,7 @@ contract SushiYieldSource is IYieldSource {

balances[msg.sender] = balances[msg.sender].sub(requiredSharesBalance);
sushi.transfer(msg.sender, sushiBalanceDiff);
emit RedeemedToken(msg.sender, requiredSharesBalance, amount);

return (sushiBalanceDiff);
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("SushiYieldSource", function () {

it("supplyTokenTo", async function () {
await sushi.connect(wallet).approve(yieldSource.address, amount);
await yieldSource.supplyTokenTo(amount, wallet.address);
expect(await yieldSource.supplyTokenTo(amount, wallet.address)).to.emit(yieldSource, "SuppliedTokenTo");
expect(await sushi.balanceOf(sushiBar.address)).to.eq(amount.mul(100));
expect(await yieldSource.callStatic.balanceOfToken(wallet.address)).to.eq(
amount
Expand All @@ -79,7 +79,7 @@ describe("SushiYieldSource", function () {
await yieldSource.supplyTokenTo(amount, wallet.address);

expect(await sushi.balanceOf(wallet.address)).to.eq(0);
await yieldSource.redeemToken(amount);
expect(await yieldSource.redeemToken(amount)).to.emit(yieldSource, "RedeemedToken");
expect(await sushi.balanceOf(wallet.address)).to.eq(amount);
});

Expand Down

0 comments on commit 0d28569

Please sign in to comment.