Skip to content

Commit

Permalink
10 percent flat fee for deposits and redemptions when there is a sing…
Browse files Browse the repository at this point in the history
…le asset in the pool or the pool is empty
  • Loading branch information
PawelTroka committed Nov 22, 2023
1 parent 3d233d1 commit e9e4fc4
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator {

SD59x18 private depositFeeScale = sd(0.18 * 1e18);
SD59x18 private depositFeeRatioScale = sd(0.99 * 1e18);
SD59x18 private singleAssetDepositRelativeFee = sd(0.1 * 1e18);

SD59x18 private redemptionFeeScale = sd(0.3 * 1e18);
SD59x18 private redemptionFeeShift = sd(0.1 * 1e18);//-log10(0+0.1)=1 -> 10^-1
SD59x18 private redemptionFeeConstant = redemptionFeeScale * (one + redemptionFeeShift).log10(); //0.0413926851582251=log10(1+0.1)
SD59x18 private singleAssetRedemptionRelativeFee = sd(0.1 * 1e18);

address[] private _recipients;
uint256[] private _shares;
Expand Down Expand Up @@ -55,6 +57,10 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator {
require(depositAmount > 0, "depositAmount must be > 0");

uint256 totalFee = getDepositFee(depositAmount, getTokenBalance(pool, tco2), getTotalSupply(pool));

require(totalFee <= depositAmount, "Fee must be lower or equal to deposit amount");
require(totalFee > 0, "Fee must be greater than 0");

return distributeFeeAmongShares(totalFee);
}

Expand Down Expand Up @@ -87,6 +93,9 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator {
require(depositAmount > 0, "depositAmount must be > 0");

uint256 totalFee = getRedemptionFee(depositAmount, getTokenBalance(pool, tco2), getTotalSupply(pool));

require(totalFee <= depositAmount, "Fee must be lower or equal to redemption amount");

return distributeFeeAmongShares(totalFee);
}

Expand Down Expand Up @@ -142,6 +151,13 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator {
require(total >= current);

SD59x18 amount_float = sd(int256(amount));

if(current==total)//single asset (or no assets) special case
{
uint256 fee = intoUint256(amount_float.mul(singleAssetDepositRelativeFee));
return fee;
}

SD59x18 ta = sd(int256(current));
SD59x18 tb = ta + amount_float;

Expand All @@ -153,10 +169,6 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator {
SD59x18 fee_float = depositFeeScale * (ta_log_a - tb_log_b);

uint256 fee = intoUint256(fee_float);

require(fee <= amount, "Fee must be lower or equal to deposit amount");
require(fee > 0, "Fee must be greater than 0");

return fee;
}

Expand All @@ -170,6 +182,13 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator {
require(amount <= current);

SD59x18 amount_float = sd(int256(amount));

if(current==total)//single asset (or no assets) special case
{
uint256 fee = intoUint256(amount_float.mul(singleAssetRedemptionRelativeFee));
return fee;
}

SD59x18 ta = sd(int256(current));
SD59x18 tb = ta - amount_float;

Expand All @@ -190,9 +209,6 @@ contract FeeCalculator is IDepositFeeCalculator, IRedemptionFeeCalculator {
}

uint256 fee = intoUint256(fee_float);

require(fee <= amount, "Fee must be lower or equal to redemption amount");

return fee;
}
}

0 comments on commit e9e4fc4

Please sign in to comment.