Skip to content

Commit

Permalink
Brian/apy rescue fix (#270)
Browse files Browse the repository at this point in the history
Fix shares math for APYRescue
  • Loading branch information
bweick committed May 2, 2023
1 parent 0e1c22f commit 63d6cf5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/product/APYRescue.sol
Expand Up @@ -69,7 +69,7 @@ contract APYRescue is Ownable {
// Must approve _amount to this contract to be transferred
apyToken.transferFrom(msg.sender, address(this), _amount);

shares[msg.sender] += shares[msg.sender].add(_amount);
shares[msg.sender] = shares[msg.sender].add(_amount);
totalShares = totalShares.add(_amount);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@setprotocol/set-protocol-v2",
"version": "0.11.2",
"version": "0.11.3",
"description": "",
"main": "dist",
"files": [
Expand Down
20 changes: 18 additions & 2 deletions test/product/apyRescue.spec.ts
Expand Up @@ -90,8 +90,8 @@ describe("APYRescue", () => {
await setup.usdc.connect(owner.wallet).approve(issuanceModule.address, usdc(150));
await issuanceModule.connect(owner.wallet).issue(apyToken.address, ether(1.5), owner.address);

subjectAmount = ether(1);
await apyToken.approve(apyRescue.address, subjectAmount);
subjectAmount = ether(.5);
await apyToken.approve(apyRescue.address, ether(1));

subjectCaller = owner;
});
Expand Down Expand Up @@ -120,6 +120,22 @@ describe("APYRescue", () => {
expect(postBalance).to.eq(preBalance.add(subjectAmount));
});

describe("when multiple deposits are performed", async () => {
beforeEach(async () => {
await subject();
});

it("should have the correct amount of shares", async () => {
const preBalance = await apyRescue.shares(owner.address);

await subject();

const postBalance = await apyRescue.shares(owner.address);

expect(postBalance).to.eq(preBalance.add(subjectAmount));
});
});

describe("when the rescue has already been performed", async () => {
beforeEach(async () => {
await apyRescue.connect(subjectCaller.wallet).deposit(subjectAmount);
Expand Down

0 comments on commit 63d6cf5

Please sign in to comment.