Skip to content

Commit

Permalink
Change harvest functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLienid committed Sep 7, 2023
1 parent 48e8307 commit b79a2eb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
19 changes: 10 additions & 9 deletions contracts/allocators/old-allocators/FraxSharesAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,21 @@ contract FraxSharesAllocator is Initializable, OwnableUpgradeable {
/* ======== POLICY FUNCTIONS ======== */

/**
* @notice harvest FXS rewards, will relock all veFXS for the maximum amount of time (4 years)
* @notice harvest FXS rewards
*/
function harvest() external {
uint256 amount = veFXSYieldDistributorV4.getYield();

if (amount > 0) {
totalAmountDeployed = totalAmountDeployed.add(amount);

fxs.safeApprove(address(veFXS), amount);
veFXS.increase_amount(amount);
if (_canExtendLock()) {
lockEnd = block.timestamp + MAX_TIME;
veFXS.increase_unlock_time(block.timestamp + MAX_TIME);
}
fxs.transfer(owner(), amount);

// Do not extend lock
// fxs.safeApprove(address(veFXS), amount);
// veFXS.increase_amount(amount);
// if (_canExtendLock()) {
// lockEnd = block.timestamp + MAX_TIME;
// veFXS.increase_unlock_time(block.timestamp + MAX_TIME);
// }
}
}

Expand Down
52 changes: 42 additions & 10 deletions test/allocators/FraxSharesAllocatorVotingV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe("FraxSharesAllocatorVotingV2", () => {
let proxyAdmin: any;
let proxy: any;
let allocator: FraxSharesAllocatorVoting;
let proxiedAllocator: any;

// tokens
let fxs: ERC20;
Expand Down Expand Up @@ -80,6 +81,9 @@ describe("FraxSharesAllocatorVotingV2", () => {
fxs.address,
"0xc6764e58b36e26b08Fd1d2AeD4538c02171fA872"
);

proxiedAllocator = await allocator.attach(proxy.address);
proxiedAllocator = proxiedAllocator.connect(owner);
});

beforeEach(async () => {
Expand All @@ -98,46 +102,74 @@ describe("FraxSharesAllocatorVotingV2", () => {
});

describe("deposit", () => {
before(async () => {
await proxyAdmin.connect(owner).upgrade(proxy.address, allocator.address);
});

it("should do nothing on deposit", async () => {
const fxsTreasuryBalanceBefore = await fxs.balanceOf(treasury.address);
const fxsAllocatorBalanceBefore = await fxs.balanceOf(allocator.address);
const fxsAllocatorBalanceBefore = await fxs.balanceOf(proxiedAllocator.address);

allocator.deposit(1);
proxiedAllocator.deposit(1);

const fxsTreasuryBalanceAfter = await fxs.balanceOf(treasury.address);
const fxsAllocatorBalanceAfter = await fxs.balanceOf(allocator.address);
const fxsAllocatorBalanceAfter = await fxs.balanceOf(proxiedAllocator.address);

expect(fxsTreasuryBalanceAfter).to.eq(fxsTreasuryBalanceBefore);
expect(fxsAllocatorBalanceAfter).to.eq(fxsAllocatorBalanceBefore);
});
});

describe("setTreasury", () => {
before(async () => {
await proxyAdmin.connect(owner).upgrade(proxy.address, allocator.address);
});

it("should do nothing on setTreasury", async () => {
const treasuryBefore = await allocator.treasury();
allocator.setTreasury(ZERO_ADDRESS);
const treasuryAfter = await allocator.treasury();
const treasuryBefore = await proxiedAllocator.treasury();
proxiedAllocator.setTreasury(ZERO_ADDRESS);
const treasuryAfter = await proxiedAllocator.treasury();

expect(treasuryBefore).to.eq(treasuryAfter);
});
});

describe("withdrawToken", () => {
before(async () => {
await proxyAdmin.connect(owner).upgrade(proxy.address, allocator.address);
});

it("should send tokens to owner on withdraw", async () => {
// transfer fxs in
await fxs.connect(fxsWallet).transfer(allocator.address, 1000);
await fxs.connect(fxsWallet).transfer(proxy.address, 1000);

const fxsBalanceBefore = await fxs.balanceOf(owner.address);
const fxsAllocatorBalanceBefore = await fxs.balanceOf(allocator.address);
const fxsAllocatorBalanceBefore = await fxs.balanceOf(proxy.address);

await allocator.withdrawToken(fxs.address, 1000);
await proxiedAllocator.withdrawToken(fxs.address, 1000);

const fxsBalanceAfter = await fxs.balanceOf(owner.address);
const fxsAllocatorBalanceAfter = await fxs.balanceOf(allocator.address);
const fxsAllocatorBalanceAfter = await fxs.balanceOf(proxy.address);

expect(fxsBalanceAfter).to.eq(fxsBalanceBefore.add(1000));
expect(fxsAllocatorBalanceAfter).to.eq(fxsAllocatorBalanceBefore.sub(1000));
});
});

describe("harvest", () => {
before(async () => {
await proxyAdmin.connect(owner).upgrade(proxy.address, allocator.address);
});

it("should get yield", async () => {
const fxsBalanceBefore = await fxs.balanceOf(owner.address);

await proxiedAllocator.harvest();

const fxsBalanceAfter = await fxs.balanceOf(owner.address);

expect(fxsBalanceAfter).to.be.gt(fxsBalanceBefore);
});
});
});
});

0 comments on commit b79a2eb

Please sign in to comment.