-
Notifications
You must be signed in to change notification settings - Fork 16
feat: Implemented Djed Tefnut smart contracts with ETH backing #41
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
cd77db8
4241283
8b32a4a
b012dac
bf0d013
4820fd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,208 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: AEL | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| pragma solidity ^0.8.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {Coin} from "./Coin.sol"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {IOracleShu} from "./IOracleShu.sol"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| contract DjedTefnut is ReentrancyGuard { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| IOracleShu public oracle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Coin public stableCoin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Coin public reserveCoin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Treasury Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| address public immutable TREASURY; // address of the treasury | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable TREASURY_FEE; // fixed treasury fee (no decay) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public treasuryRevenue = 0; // holds how much has already been paid to the treasury // Mutable state variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Djed Parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable FEE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable THRESHOLD_SUPPLY_SC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable RC_MIN_PRICE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable RC_INITIAL_PRICE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable TX_LIMIT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Scaling factors: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable SCALING_FACTOR; // used to represent a decimal number `d` as the uint number `d * SCALING_FACTOR` | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable SC_DECIMAL_SCALING_FACTOR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 public immutable RC_DECIMAL_SCALING_FACTOR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| event BoughtStableCoins(address indexed buyer, address indexed receiver, uint256 amountSc, uint256 amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| event SoldStableCoins(address indexed seller, address indexed receiver, uint256 amountSc, uint256 amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| event BoughtReserveCoins(address indexed buyer, address indexed receiver, uint256 amountRc, uint256 amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| event SoldReserveCoins(address indexed seller, address indexed receiver, uint256 amountRc, uint256 amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| address oracleAddress, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 scalingFactor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| address treasury, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 treasuryFee, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 fee, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 thresholdSupplySc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 rcMinPrice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 rcInitialPrice, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 txLimit | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) payable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stableCoin = new Coin("StableCoin", "SC"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| reserveCoin = new Coin("ReserveCoin", "RC"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| SC_DECIMAL_SCALING_FACTOR = 10 ** stableCoin.decimals(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| RC_DECIMAL_SCALING_FACTOR = 10 ** reserveCoin.decimals(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| SCALING_FACTOR = scalingFactor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| TREASURY = treasury; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| TREASURY_FEE = treasuryFee; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| FEE = fee; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| THRESHOLD_SUPPLY_SC = thresholdSupplySc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| RC_MIN_PRICE = rcMinPrice; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| RC_INITIAL_PRICE = rcInitialPrice; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| TX_LIMIT = txLimit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| oracle = IOracleShu(oracleAddress); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| oracle.acceptTermsOfService(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Reserve, Liabilities, Equity (in weis) and Reserve Ratio | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| function R(uint256 currentPaymentAmount) public view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return address(this).balance - currentPaymentAmount; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function L(uint256 _scPrice) internal view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (stableCoin.totalSupply() * _scPrice) / SC_DECIMAL_SCALING_FACTOR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function L() external view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return L(scMaxPrice(0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function E(uint256 _scPrice, uint256 currentPaymentAmount) internal view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return R(currentPaymentAmount) - L(_scPrice); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function E(uint256 currentPaymentAmount) external view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return E(scMaxPrice(currentPaymentAmount), currentPaymentAmount); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Ratio functions kept for informational purposes only (no longer restrict transactions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| function ratio() external view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 liabilities = L(scMaxPrice(0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (liabilities == 0) return type(uint256).max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return SCALING_FACTOR * R(0) / liabilities; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // # Public Trading Functions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // scMaxPrice | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| function buyStableCoins(address receiver, uint256 feeUi, address ui) external payable nonReentrant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| oracle.updateOracleValues(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 scP = scMaxPrice(msg.value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 amountBc = deductFees(msg.value, feeUi, ui); // side-effect: increases `treasuryRevenue` and pays UI and treasury | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 amountSc = (amountBc * SC_DECIMAL_SCALING_FACTOR) / scP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(amountSc <= TX_LIMIT || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "buySC: tx limit exceeded"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(amountSc > 0, "buySC: receiving zero SCs"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stableCoin.mint(receiver, amountSc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Reserve ratio check removed in Tefnut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| emit BoughtStableCoins(msg.sender, receiver, amountSc, msg.value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
104
to
114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add slippage protection for user safety. The -function buyStableCoins(address receiver, uint256 feeUi, address ui) external payable nonReentrant {
+function buyStableCoins(address receiver, uint256 feeUi, address ui, uint256 minAmountSc) external payable nonReentrant {
oracle.updateOracleValues();
uint256 scP = scMaxPrice(msg.value);
uint256 amountBc = deductFees(msg.value, feeUi, ui);
uint256 amountSc = (amountBc * SC_DECIMAL_SCALING_FACTOR) / scP;
+ require(amountSc >= minAmountSc, "buySC: slippage exceeded");
require(amountSc <= TX_LIMIT || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "buySC: tx limit exceeded");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function sellStableCoins(uint256 amountSc, address receiver, uint256 feeUi, address ui) external nonReentrant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| oracle.updateOracleValues(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(stableCoin.balanceOf(msg.sender) >= amountSc, "sellSC: insufficient SC balance"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(amountSc <= TX_LIMIT || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "sellSC: tx limit exceeded"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 scP = scMinPrice(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 value = (amountSc * scP) / SC_DECIMAL_SCALING_FACTOR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 amountBc = deductFees(value, feeUi, ui); // side-effect: increases `treasuryRevenue` and pays UI and treasury | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(amountBc > 0, "sellSC: receiving zero BCs"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stableCoin.burn(msg.sender, amountSc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transferEth(receiver, amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| emit SoldStableCoins(msg.sender, receiver, amountSc, amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
116
to
127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add slippage protection and consider transfer failure handling. Similar to Add a minimum received amount parameter: -function sellStableCoins(uint256 amountSc, address receiver, uint256 feeUi, address ui) external nonReentrant {
+function sellStableCoins(uint256 amountSc, address receiver, uint256 feeUi, address ui, uint256 minAmountBc) external nonReentrant {
oracle.updateOracleValues();
require(stableCoin.balanceOf(msg.sender) >= amountSc, "sellSC: insufficient SC balance");
require(amountSc <= TX_LIMIT || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "sellSC: tx limit exceeded");
uint256 scP = scMinPrice(0);
uint256 value = (amountSc * scP) / SC_DECIMAL_SCALING_FACTOR;
uint256 amountBc = deductFees(value, feeUi, ui);
+ require(amountBc >= minAmountBc, "sellSC: slippage exceeded");
require(amountBc > 0, "sellSC: receiving zero BCs");📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function buyReserveCoins(address receiver, uint256 feeUi, address ui) external payable nonReentrant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| oracle.updateOracleValues(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 scP = scMinPrice(msg.value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 rcBp = rcBuyingPrice(scP, msg.value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 amountBc = deductFees(msg.value, feeUi, ui); // side-effect: increases `treasuryRevenue` and pays UI and treasury | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(amountBc <= (TX_LIMIT * scP) / SC_DECIMAL_SCALING_FACTOR || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "buyRC: tx limit exceeded"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 amountRc = (amountBc * RC_DECIMAL_SCALING_FACTOR) / rcBp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(amountRc > 0, "buyRC: receiving zero RCs"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| reserveCoin.mint(receiver, amountRc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Reserve ratio check removed in Tefnut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| emit BoughtReserveCoins(msg.sender, receiver, amountRc, msg.value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function sellReserveCoins(uint256 amountRc, address receiver, uint256 feeUi, address ui) external nonReentrant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| oracle.updateOracleValues(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(reserveCoin.balanceOf(msg.sender) >= amountRc, "sellRC: insufficient RC balance"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 scP = scMaxPrice(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 value = (amountRc * rcTargetPrice(scP, 0)) / RC_DECIMAL_SCALING_FACTOR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(value <= (TX_LIMIT * scP) / SC_DECIMAL_SCALING_FACTOR || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "sellRC: tx limit exceeded"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 amountBc = deductFees(value, feeUi, ui); // side-effect: increases `treasuryRevenue` and pays UI and treasury | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(amountBc > 0, "sellRC: receiving zero BCs"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| reserveCoin.burn(msg.sender, amountRc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transferEth(receiver, amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Reserve ratio check removed in Tefnut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| emit SoldReserveCoins(msg.sender, receiver, amountRc, amountBc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
142
to
154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add slippage protection and fix TX_LIMIT inconsistency. The TX_LIMIT check on line 139 uses -function sellReserveCoins(uint256 amountRc, address receiver, uint256 feeUi, address ui) external nonReentrant {
+function sellReserveCoins(uint256 amountRc, address receiver, uint256 feeUi, address ui, uint256 minAmountBc) external nonReentrant {
oracle.updateOracleValues();
require(reserveCoin.balanceOf(msg.sender) >= amountRc, "sellRC: insufficient RC balance");
uint256 scP = scMaxPrice(0);
uint256 value = (amountRc * rcTargetPrice(scP, 0)) / RC_DECIMAL_SCALING_FACTOR;
- require(value <= (TX_LIMIT * scP) / SC_DECIMAL_SCALING_FACTOR || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "sellRC: tx limit exceeded");
uint256 amountBc = deductFees(value, feeUi, ui);
+ require(amountBc <= (TX_LIMIT * scP) / SC_DECIMAL_SCALING_FACTOR || stableCoin.totalSupply() < THRESHOLD_SUPPLY_SC, "sellRC: tx limit exceeded");
+ require(amountBc >= minAmountBc, "sellRC: slippage exceeded");
require(amountBc > 0, "sellRC: receiving zero BCs");🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // sellBothCoins function removed in Tefnut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // # Auxiliary Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function deductFees(uint256 value, uint256 feeUi, address ui) internal returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 f = (value * FEE) / SCALING_FACTOR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 fUi = (value * feeUi) / SCALING_FACTOR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 fT = (value * TREASURY_FEE) / SCALING_FACTOR; // Fixed treasury fee (no decay) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| treasuryRevenue += fT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transferEth(TREASURY, fT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transferEth(ui, fUi); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // transferEth(address(this), f); // this happens implicitly, and thus `f` is effectively transferred to the reserve. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return value - f - fUi - fT; // amountBc | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
160
to
170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate fees and protect against DoS via malicious UI address. The function has several concerns:
function deductFees(uint256 value, uint256 feeUi, address ui) internal returns (uint256) {
+ require(feeUi + FEE + TREASURY_FEE <= SCALING_FACTOR, "Total fees exceed 100%");
uint256 f = (value * FEE) / SCALING_FACTOR;
uint256 fUi = (value * feeUi) / SCALING_FACTOR;
uint256 fT = (value * TREASURY_FEE) / SCALING_FACTOR;
treasuryRevenue += fT;
- transferEth(TREASURY, fT);
- transferEth(ui, fUi);
+ if (fT > 0) {
+ transferEth(TREASURY, fT);
+ }
+ if (fUi > 0 && ui != address(0)) {
+ transferEth(ui, fUi);
+ }
// transferEth(address(this), f); // this happens implicitly, and thus `f` is effectively transferred to the reserve.
return value - f - fUi - fT; // amountBc
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // isRatioAboveMin and isRatioBelowMax functions removed in Tefnut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // # Price Functions: return the price in weis for 1 whole coin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function scPrice(uint256 currentPaymentAmount, uint256 scTargetPrice) private view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 supplySc = stableCoin.totalSupply(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return supplySc == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? scTargetPrice | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| : Math.min(scTargetPrice, (R(currentPaymentAmount) * SC_DECIMAL_SCALING_FACTOR) / supplySc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function scMaxPrice(uint256 currentPaymentAmount) public view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (uint256 scTargetPrice,) = oracle.readMaxPrice(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return scPrice(currentPaymentAmount, scTargetPrice); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function scMinPrice(uint256 currentPaymentAmount) public view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (uint256 scTargetPrice,) = oracle.readMinPrice(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return scPrice(currentPaymentAmount, scTargetPrice); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function rcTargetPrice(uint256 currentPaymentAmount) external view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return rcTargetPrice(scMaxPrice(currentPaymentAmount), currentPaymentAmount); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function rcTargetPrice(uint256 _scPrice, uint256 currentPaymentAmount) internal view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint256 supplyRc = reserveCoin.totalSupply(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(supplyRc != 0, "RC supply is zero"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (E(_scPrice, currentPaymentAmount) * RC_DECIMAL_SCALING_FACTOR) / supplyRc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function rcBuyingPrice(uint256 currentPaymentAmount) external view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return rcBuyingPrice(scMaxPrice(currentPaymentAmount), currentPaymentAmount); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function rcBuyingPrice(uint256 _scPrice, uint256 currentPaymentAmount) internal view returns (uint256) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return reserveCoin.totalSupply() == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? RC_INITIAL_PRICE | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| : Math.max(rcTargetPrice(_scPrice, currentPaymentAmount), RC_MIN_PRICE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| function transferEth(address receiver, uint256 amount) internal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (bool success,) = payable(receiver).call{value: amount}(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| require(success, "Transfer failed."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
negimox marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPDX identifier
AELmay be invalid for tooling/verificationIf
AELisn’t a recognized SPDX license identifier in your pipeline/tooling, you’ll get warnings or verification friction. Consider switching to a standard SPDX id (orUNLICENSED) consistent with the repo’s licensing.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isnt this incorrect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
💡 Result:
Do you mean a specific license abbreviated “AEL”? If so, what does AEL stand for (full license name or a link)? I can then look up the correct SPDX identifier.
🌐 Web query:
💡 Result:
The official SPDX license identifiers are published on the SPDX License List page and in the SPDX license-list-data repository (machine-readable JSON/XML). Use the licenses page for the human-readable table and the GitHub repo (licenses.json / exceptions.json) for authoritative identifiers you can consume programmatically. Current references:
If you want the full JSON file of identifiers, download licenses.json from the license-list-data repo. [2]
Sources
[1] SPDX: SPDX License List — https://spdx.org/licenses/
[2] spdx/license-list-data — https://github.com/spdx/license-list-data
🏁 Script executed:
Length of output: 0
@negimox, I've checked the official SPDX license list (version 3.27.0), and "AEL" is not a recognized standard SPDX license identifier. So CodeRabbit's warning is technically accurate from a standards perspective.
However, if "AEL" is a custom or proprietary license identifier specific to your project (such as "All Emcompassing License" or similar), then using it may be intentional. Could you clarify:
If it's a custom identifier and intentional, you can safely ignore the warning. If you meant to use a standard SPDX identifier, I can help you find the appropriate one. Alternatively, if the code is proprietary/closed-source, you might want to use
UNLICENSEDinstead.