Skip to content

Commit

Permalink
Merge pull request #43 from neutral-protocol/readme-update
Browse files Browse the repository at this point in the history
Readme update and events in permissioned functions
  • Loading branch information
0xmichalis authored Feb 9, 2024
2 parents 1dfdf83 + 4ba0e29 commit 3a93bcc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,28 @@ Remember, the goal is to maintain a balanced pool composition and discourage mon

## How to Use

1. Deploy the contract on a Polygon network.
2. Call `feeSetup` function to set up the fee distribution among recipients.
3. Call `calculateDepositFees` function to calculate the deposit fees for a given amount.
4. Call `calculateRedemptionFee` function to calculate the redemption fees for a given amount.
1. Deploy the contract:

forge create --via-ir \
--rpc-url <rpc-url> \
--private-key <private-key> \
FeeCalculator

Optionally, if you want to verify the contract at the same time:

forge create --via-ir \
--rpc-url <rpc-url> \
--private-key <private-key> \
--etherscan-api-key <etherscan-key> \
--verify \
FeeCalculator


2. Call `feeSetup()` to set up the fee distribution among recipients.

Now callers should be able to estimate fees for a pool by calling the following functions:
- Call `calculateDepositFees()` to calculate the deposit fees for a given amount.
- Call `calculateRedemptionFees()` to calculate the redemption fees for a given amount.

## Requirements

Expand Down
17 changes: 17 additions & 0 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ contract FeeCalculator is IFeeCalculator, Ownable {
address[] private _recipients;
uint256[] private _shares;

event DepositFeeScaleUpdated(int256 depositFeeScale);
event DepositFeeRatioUpdated(int256 depositFeeRatioScale);
event SingleAssetDepositRelativeFeeUpdated(int256 singleAssetDepositRelativeFee);
event RedemptionFeeScaleUpdated(int256 redemptionFeeScale);
event RedemptionFeeShift(int256 redemptionFeeShift);
event SingleAssetRedemptionRelativeFeeUpdated(int256 singleAssetRedemptionRelativeFee);
event DustAssetRedemptionRelativeFeeUpdated(int256 dustAssetRedemptionRelativeFee);
event FeeSetup(address[] recipients, uint256[] shares);

constructor() Ownable() {}

/// @notice Sets the deposit fee scale.
Expand All @@ -47,6 +56,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
SD59x18 depositFeeScaleSD = sd(_depositFeeScale);
require(depositFeeScaleSD >= zero && depositFeeScaleSD <= one, "Deposit fee scale must be between 0 and 1");
depositFeeScale = depositFeeScaleSD;
emit DepositFeeScaleUpdated(_depositFeeScale);
}

/// @notice Sets the deposit fee ratio scale.
Expand All @@ -56,6 +66,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
SD59x18 depositFeeRatioScaleSD = sd(_depositFeeRatioScale);
require(depositFeeRatioScaleSD >= zero, "Deposit fee ratio scale must be above 0");
depositFeeRatioScale = depositFeeRatioScaleSD;
emit DepositFeeRatioUpdated(_depositFeeRatioScale);
}

/// @notice Sets the single asset deposit relative fee.
Expand All @@ -68,6 +79,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
"Single asset deposit relative fee must be between 0 and 1"
);
singleAssetDepositRelativeFee = singleAssetDepositRelativeFeeSD;
emit SingleAssetDepositRelativeFeeUpdated(_singleAssetDepositRelativeFee);
}

/// @notice Sets the redemption fee scale.
Expand All @@ -79,6 +91,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
redemptionFeeScaleSD >= zero && redemptionFeeScaleSD <= one, "Redemption fee scale must be between 0 and 1"
);
redemptionFeeScale = redemptionFeeScaleSD;
emit RedemptionFeeScaleUpdated(_redemptionFeeScale);
}

/// @notice Sets the redemption fee shift.
Expand All @@ -90,6 +103,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
redemptionFeeShiftSD >= zero && redemptionFeeShiftSD <= one, "Redemption fee shift must be between 0 and 1"
);
redemptionFeeShift = redemptionFeeShiftSD;
emit RedemptionFeeShift(_redemptionFeeShift);
}

/// @notice Sets the single asset redemption relative fee.
Expand All @@ -102,6 +116,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
"Single asset redemption relative fee must be between 0 and 1"
);
singleAssetRedemptionRelativeFee = singleAssetRedemptionRelativeFeeSD;
emit SingleAssetRedemptionRelativeFeeUpdated(_singleAssetRedemptionRelativeFee);
}

/// @notice Sets the dust asset redemption relative fee.
Expand All @@ -114,6 +129,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
"Dust asset redemption relative fee must be between 0 and 1"
);
dustAssetRedemptionRelativeFee = dustAssetRedemptionRelativeFeeSD;
emit DustAssetRedemptionRelativeFeeUpdated(_dustAssetRedemptionRelativeFee);
}

/// @notice Sets up the fee distribution among recipients.
Expand All @@ -131,6 +147,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {

_recipients = recipients;
_shares = shares;
emit FeeSetup(recipients, shares);
}

/// @notice Calculates the deposit fee for a given amount.
Expand Down

0 comments on commit 3a93bcc

Please sign in to comment.