Skip to content
Open
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
20 changes: 20 additions & 0 deletions contracts/UpsideProtocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./UpsideMetaCoin.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract UpsideProtocol is Ownable {
using SafeERC20 for IERC20Metadata;
Expand Down Expand Up @@ -46,6 +47,7 @@ contract UpsideProtocol is Ownable {
uint256 public withdrawLiquidityTimerStartTime;
uint256 public claimableProtocolFees; // @dev This is always in liquidity tokens
FeeInfo public feeInfo;
uint256 public minSellAmount;

// @dev stores data on which addresses are whitelisted to transfer MetaCoins (per meta coin)
mapping(address metaCoinAddress => mapping(address walletAddress => bool isWhitelisted))
Expand Down Expand Up @@ -210,13 +212,30 @@ contract UpsideProtocol is Ownable {

if (_isBuy) {
// @dev On buy, the dynamic time fee is used
uint256 minBuyAmount = 10000 / swapFeeBp;
require(
_tokenAmount >= minBuyAmount,
string.concat(
"Insufficient input: please swap at least ",
Strings.toString(minBuyAmount),
" tokens"
)
);
fee = (_tokenAmount * swapFeeBp) / 10000;
tokenAmountAfterFee = _tokenAmount - fee;

claimableProtocolFees += fee;
feeToProtocol = fee;
} else {
// @dev On sell, a static percentage bp is used (impl could be significantly improved to save gas)
require(
_tokenAmount >= minSellAmount,
string.concat(
"Insufficient input: please swap at least ",
Strings.toString(minSellAmount),
" tokens"
)
);
fee = (_tokenAmount * feeInfo.swapFeeSellBp) / 10000;
tokenAmountAfterFee = _tokenAmount - fee;

Expand Down Expand Up @@ -349,6 +368,7 @@ contract UpsideProtocol is Ownable {
}

feeInfo = _newFeeInfo;
minSellAmount = 10000 / feeInfo.swapFeeSellBp;
emit FeeInfoSet(_newFeeInfo);
}

Expand Down