Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Exchange created with zero reserve #558

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/goodDollar/BancorExchangeProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ contract BancorExchangeProvider is IExchangeProvider, IBancorExchangeProvider, B
require(exchange.reserveRatio > 1, "Reserve ratio is too low");
require(exchange.reserveRatio <= MAX_WEIGHT, "Reserve ratio is too high");
require(exchange.exitContribution <= MAX_WEIGHT, "Exit contribution is too high");
require(exchange.reserveBalance > 0, "Reserve balance must be greater than 0");
}

/**
Expand Down
56 changes: 6 additions & 50 deletions test/unit/goodDollar/BancorExchangeProvider.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ contract BancorExchangeProviderTest_createExchange is BancorExchangeProviderTest
bancorExchangeProvider.createExchange(poolExchange1);
}

function test_createExchange_whenReserveBalanceIsZero_shouldRevert() public {
poolExchange1.reserveBalance = 0;
vm.expectRevert("Reserve balance must be greater than 0");
bancorExchangeProvider.createExchange(poolExchange1);
}

function test_createExchange_whenReserveAssetIsNotCollateral_shouldRevert() public {
vm.mockCall(
reserveAddress,
Expand Down Expand Up @@ -452,19 +458,6 @@ contract BancorExchangeProviderTest_getAmountIn is BancorExchangeProviderTest {
});
}

function test_getAmountIn_whenTokenInIsTokenAndReserveBalanceIsZero_shouldRevert() public {
poolExchange1.reserveBalance = 0;
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);

vm.expectRevert("ERR_INVALID_RESERVE_BALANCE");
bancorExchangeProvider.getAmountIn({
exchangeId: exchangeId,
tokenIn: address(token),
tokenOut: address(reserveToken),
amountOut: 1e18
});
}

function test_getAmountIn_whenTokenInIsTokenAndAmountOutLargerThanReserveBalance_shouldRevert() public {
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);
vm.expectRevert("ERR_INVALID_AMOUNT");
Expand Down Expand Up @@ -533,19 +526,6 @@ contract BancorExchangeProviderTest_getAmountIn is BancorExchangeProviderTest {
});
}

function test_getAmountIn_whenTokenInIsReserveAssetAndReserveBalanceIsZero_shouldRevert() public {
poolExchange1.reserveBalance = 0;
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);

vm.expectRevert("ERR_INVALID_RESERVE_BALANCE");
bancorExchangeProvider.getAmountIn({
exchangeId: exchangeId,
tokenIn: address(reserveToken),
tokenOut: address(token),
amountOut: 1e18
});
}

function test_getAmountIn_whenTokenInIsReserveAssetAndAmountOutIsZero_shouldReturnZero() public {
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);
uint256 amountIn = bancorExchangeProvider.getAmountIn({
Expand Down Expand Up @@ -998,18 +978,6 @@ contract BancorExchangeProviderTest_getAmountOut is BancorExchangeProviderTest {
});
}

function test_getAmountOut_whenTokenInIsReserveAssetAndReserveBalanceIsZero_shouldRevert() public {
poolExchange1.reserveBalance = 0;
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);
vm.expectRevert("ERR_INVALID_RESERVE_BALANCE");
bancorExchangeProvider.getAmountOut({
exchangeId: exchangeId,
tokenIn: address(reserveToken),
tokenOut: address(token),
amountIn: 1e18
});
}

function test_getAmountOut_whenTokenInIsReserveAssetAndAmountInIsZero_shouldReturnZero() public {
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);
uint256 amountOut = bancorExchangeProvider.getAmountOut({
Expand Down Expand Up @@ -1049,18 +1017,6 @@ contract BancorExchangeProviderTest_getAmountOut is BancorExchangeProviderTest {
});
}

function test_getAmountOut_whenTokenInIsTokenAndReserveBalanceIsZero_shouldRevert() public {
poolExchange1.reserveBalance = 0;
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);
vm.expectRevert("ERR_INVALID_RESERVE_BALANCE");
bancorExchangeProvider.getAmountOut({
exchangeId: exchangeId,
tokenIn: address(token),
tokenOut: address(reserveToken),
amountIn: 1e18
});
}

function test_getAmountOut_whenTokenInIsTokenAndAmountLargerSupply_shouldRevert() public {
bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1);
vm.expectRevert("ERR_INVALID_AMOUNT");
Expand Down
Loading