Is it possible in Solidity to compare LastTransactionPrice with CurrentAsk & CurrentBid?
then Disable Buying/Selling if the price (Ask/Bid) is below LastTransactionPrice?
Thank you!
Is it possible in Solidity to compare LastTransactionPrice with CurrentAsk & CurrentBid?
then Disable Buying/Selling if the price (Ask/Bid) is below LastTransactionPrice?
Thank you!
You create 3 state variables for CurrentAsk, CurrentBid and LastTransactionPrice:
uint256 CurrentAsk private;
uint256 CurrentBid private;
uint256 LastTransactionPrice private;
then write to setters to mutate those two state variables:
// askPrice gets set by the seller
function setCurrentAsk(uint256 askPrice) public {
CurrentAsk=askPrice
}
// bidPrice gets set by the buyer
function setCurrentBid(uint256 bidPrice) public {
CurrentBid=bidPrice
}
You can write a require statement to add buying/selling function but in this way, people still can call setCurrentAsk and setCurrentBid functions and pay gas fees. To be more efficient, you add require statements to both functions.
function setCurrentAsk(uint256 askPrice) public {
require(askPrice>LastTransactionPrice,"ask higher amount")
CurrentAsk=askPrice
}
function setCurrentBid(uint256 bidPrice) public {
require(bidPrice > LastTransactionPrice, "ask higher amount")
CurrentBid=bidPrice
}
require statement will check the current condition and if does not return true, it will revert the function execution and solidity will show the error that you defined: "ask higher amount"