Skip to content

Commit

Permalink
Allow guardian to redeem instantly without fees (#2380)
Browse files Browse the repository at this point in the history
* Allow guardian to redeem instantly without fees

* Fix fork-test script

* Fix tests

* Governor can redeem without fee as well

* Update comment

* Fix broke test on Base
  • Loading branch information
shahthepro authored Feb 5, 2025
1 parent 1d4a532 commit 1b78421
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
7 changes: 4 additions & 3 deletions contracts/contracts/vault/OETHVaultCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ contract OETHVaultCore is VaultCore {
}

// Amount excluding fees
uint256 amountMinusFee = _calculateRedeemOutputs(_amount)[
wethAssetIndex
];
// No fee for the strategist or the governor, makes it easier to do operations
uint256 amountMinusFee = (msg.sender == strategistAddr || isGovernor())
? _amount
: _calculateRedeemOutputs(_amount)[wethAssetIndex];

require(
amountMinusFee >= _minimumUnitAmount,
Expand Down
6 changes: 5 additions & 1 deletion contracts/fork-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ main()

# Run specific files when a param is given
if [[ ! -z "$1" ]]; then
params+="--testfiles $@"
if [[ $is_coverage == "true" ]]; then
params+="--testfiles $@"
else
params+="$@"
fi
fi

# Add trace flag if enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe("ForkTest: Aerodrome AMO Strategy (Base)", async function () {
it("Should have the correct initial state", async function () {
// correct pool weth share interval
expect(await aerodromeAmoStrategy.allowedWethShareStart()).to.equal(
oethUnits("0.05")
oethUnits("0.010000001")
);

expect(await aerodromeAmoStrategy.allowedWethShareEnd()).to.equal(
Expand Down
47 changes: 47 additions & 0 deletions contracts/test/vault/oeth-vault.mainnet.fork-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,53 @@ describe("ForkTest: OETH Vault", function () {
});
});

it("should allow strategist to redeem without fee", async () => {
const { oethVault, strategist, weth, oeth } = fixture;

const amount = oethUnits("10");

await weth.connect(strategist).approve(oethVault.address, amount);

// Mint 1:1
await oethVault.connect(strategist).mint(weth.address, amount, amount);

const oethBalanceBefore = await oeth.balanceOf(strategist.address);
const wethBalanceBefore = await weth.balanceOf(strategist.address);

// Redeem 1:1 instantly
await oethVault.connect(strategist).redeem(amount, amount);

const oethBalanceAfter = await oeth.balanceOf(strategist.address);
const wethBalanceAfter = await weth.balanceOf(strategist.address);

expect(oethBalanceAfter).to.equal(oethBalanceBefore.sub(amount));
expect(wethBalanceAfter).to.equal(wethBalanceBefore.add(amount));
});

it("should enforce fee on other users for instant redeem", async () => {
const { oethVault, josh, weth, oeth } = fixture;

const amount = oethUnits("10");
const expectedWETH = amount.mul("9990").div("10000");

await weth.connect(josh).approve(oethVault.address, amount);

// Mint 1:1
await oethVault.connect(josh).mint(weth.address, amount, amount);

const oethBalanceBefore = await oeth.balanceOf(josh.address);
const wethBalanceBefore = await weth.balanceOf(josh.address);

// Redeem 1:1 instantly
await oethVault.connect(josh).redeem(amount, expectedWETH);

const oethBalanceAfter = await oeth.balanceOf(josh.address);
const wethBalanceAfter = await weth.balanceOf(josh.address);

expect(oethBalanceAfter).to.equal(oethBalanceBefore.sub(amount));
expect(wethBalanceAfter).to.equal(wethBalanceBefore.add(expectedWETH));
});

it("should partially redeem 10 OETH", async () => {
const { domen, oeth, oethVault, weth } = fixture;

Expand Down

0 comments on commit 1b78421

Please sign in to comment.