Verified contractPartialMIT
FASPforFrontEndInterface
Address0xe1853c5dc7e26affedade24c7d7d0f0f489d0a43
- Balance
0 ETH
- Transactions
34
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- No
- EVM version
- cancun
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 22,378,819
- Creation transaction
- 0x548689be34…51d2cac073
FASPforFrontEndInterface.sol
// SPDX-License-Identifier: MIT
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(
address owner,
address spender
) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https:
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
}
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
contract ShareProfitsListener {
function _realizeProfitsTokenListOfShareSubject(
address player,
address sharesSubject
) internal virtual {}
}
pragma solidity >=0.8.2 <0.9.0;
contract FriendtechSharesV1 is Ownable, ShareProfitsListener {
address public protocolFeeDestination;
uint256 public protocolFeePercent;
uint256 public subjectFeePercent;
uint256 public denominatorOfPrice = 16000;
IERC20 public paymentToken;
constructor(address _paymentToken) {
require(_paymentToken != address(0), "Invalid token address");
paymentToken = IERC20(_paymentToken);
}
event Trade(
address trader,
address subject,
bool isBuy,
uint256 shareAmount,
uint256 ethAmount,
uint256 protocolEthAmount,
uint256 subjectEthAmount,
uint256 supply
);
mapping(address => mapping(address => uint256)) public sharesBalance;
mapping(address => uint256) public sharesSupply;
function setFeeDestination(address _feeDestination) external onlyOwner {
protocolFeeDestination = _feeDestination;
}
function setProtocolFeePercent(uint256 _feePercent) external onlyOwner {
protocolFeePercent = _feePercent;
}
function setSubjectFeePercent(uint256 _feePercent) external onlyOwner {
subjectFeePercent = _feePercent;
}
function setDenominatorOfPrice(
uint256 newDenominatorOfPrice
) external onlyOwner {
denominatorOfPrice = newDenominatorOfPrice;
}
function getPrice(
uint256 supply,
uint256 amount
) public view returns (uint256) {
uint256 sum1 = supply == 0
? 0
: ((supply - 1) * (supply) * (2 * (supply - 1) + 1)) / 6;
uint256 sum2 = supply == 0 && amount == 1
? 0
: ((supply - 1 + amount) *
(supply + amount) *
(2 * (supply - 1 + amount) + 1)) / 6;
uint256 summation = sum2 - sum1;
return (summation * 1 ether) / denominatorOfPrice;
}
function getBuyPrice(
address sharesSubject,
uint256 amount
) public view returns (uint256) {
return getPrice(sharesSupply[sharesSubject], amount);
}
function getSellPrice(
address sharesSubject,
uint256 amount
) public view returns (uint256) {
return getPrice(sharesSupply[sharesSubject] - amount, amount);
}
function getBuyPriceAfterFee(
address sharesSubject,
uint256 amount
) public view returns (uint256) {
uint256 price = getBuyPrice(sharesSubject, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 subjectFee = (price * subjectFeePercent) / 1 ether;
return price + protocolFee + subjectFee;
}
function getSellPriceAfterFee(
address sharesSubject,
uint256 amount
) public view returns (uint256) {
uint256 price = getSellPrice(sharesSubject, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 subjectFee = (price * subjectFeePercent) / 1 ether;
return price - protocolFee - subjectFee;
}
function buyShares(address sharesSubject, uint256 amount) public {
uint256 supply = sharesSupply[sharesSubject];
require(
supply > 0 || sharesSubject == msg.sender,
"Only the shares' subject can buy the first share"
);
uint256 price = getPrice(supply, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 subjectFee = (price * subjectFeePercent) / 1 ether;
uint256 totalCost = price + protocolFee + subjectFee;
require(
paymentToken.allowance(msg.sender, address(this)) >= totalCost,
"Insufficient allowance"
);
require(
paymentToken.balanceOf(msg.sender) >= totalCost,
"Insufficient balance"
);
require(
paymentToken.transferFrom(msg.sender, address(this), totalCost),
"Token transfer failed"
);
_realizeProfitsTokenListOfShareSubject(msg.sender, sharesSubject);
sharesBalance[sharesSubject][msg.sender] =
sharesBalance[sharesSubject][msg.sender] +
amount;
sharesSupply[sharesSubject] = supply + amount;
require(
paymentToken.transfer(protocolFeeDestination, protocolFee),
"Protocol fee transfer failed"
);
require(
paymentToken.transfer(sharesSubject, subjectFee),
"Subject fee transfer failed"
);
emit Trade(
msg.sender,
sharesSubject,
true,
amount,
price,
protocolFee,
subjectFee,
supply + amount
);
}
function sellShares(address sharesSubject, uint256 amount) public {
uint256 supply = sharesSupply[sharesSubject];
require(supply > amount, "Cannot sell the last share");
uint256 price = getPrice(supply - amount, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 subjectFee = (price * subjectFeePercent) / 1 ether;
uint256 userReceiveAmount = price - protocolFee - subjectFee;
require(
sharesBalance[sharesSubject][msg.sender] >= amount,
"Insufficient shares"
);
_realizeProfitsTokenListOfShareSubject(msg.sender, sharesSubject);
sharesBalance[sharesSubject][msg.sender] =
sharesBalance[sharesSubject][msg.sender] -
amount;
sharesSupply[sharesSubject] = supply - amount;
require(
paymentToken.transfer(msg.sender, userReceiveAmount),
"Transfer to seller failed"
);
require(
paymentToken.transfer(protocolFeeDestination, protocolFee),
"Protocol fee transfer failed"
);
require(
paymentToken.transfer(sharesSubject, subjectFee),
"Subject fee transfer failed"
);
emit Trade(
msg.sender,
sharesSubject,
false,
amount,
price,
protocolFee,
subjectFee,
supply - amount
);
}
}
contract FriendTechAsShareProfitsV2 is FriendtechSharesV1 {
constructor(address _acpToken) FriendtechSharesV1(_acpToken) {
}
event profitsTokenListUpdated(
address indexed operatorAddress,
address[] newProfitsTokenList
);
mapping(address => mapping(address => uint256)) playerToProfitsSubjectToRealizedAmount;
mapping(address => mapping(address => uint256)) sharesSubjectToProfitsSubjectToBeaconHeight;
mapping(address => mapping(address => mapping(address => uint256))) playerToSharesSubjectToProfitsSubjectToRealizedHeight;
address[] autoRealizeProfitsTokenList;
function updateAutoRealizeProfitsTokenList(
address[] calldata newAutoRealizeProfitsTokenList
) external onlyOwner {
autoRealizeProfitsTokenList = newAutoRealizeProfitsTokenList;
emit profitsTokenListUpdated(msg.sender, autoRealizeProfitsTokenList);
}
function injectProfits(
address profitsSubject,
address[] calldata sharesSubjects,
uint256[] calldata profitsAmounts
) external {
uint256 _totalProfits = 0;
require(
sharesSubjects.length == profitsAmounts.length,
"FASP: Unequal length"
);
for (uint256 i = 0; i < sharesSubjects.length; i++) {
sharesSubjectToProfitsSubjectToBeaconHeight[sharesSubjects[i]][
profitsSubject
] += profitsAmounts[i] / sharesSupply[sharesSubjects[i]];
_totalProfits += profitsAmounts[i];
}
IERC20 profitsToken = IERC20(profitsSubject);
profitsToken.transferFrom(msg.sender, address(this), _totalProfits);
}
function _realizeProfitsTokenListOfShareSubject(
address player,
address sharesSubject
) internal override {
for (uint256 i = 0; i < autoRealizeProfitsTokenList.length; i++) {
realizeProfits(
player,
sharesSubject,
autoRealizeProfitsTokenList[i]
);
}
}
function realizeProfits(
address player,
address sharesSubject,
address profitsSubject
) internal {
uint256 unrealizedProfits = getUnrealizedProfitsOf(
player,
sharesSubject,
profitsSubject
);
playerToSharesSubjectToProfitsSubjectToRealizedHeight[player][
sharesSubject
][profitsSubject] = sharesSubjectToProfitsSubjectToBeaconHeight[
sharesSubject
][profitsSubject];
playerToProfitsSubjectToRealizedAmount[player][
profitsSubject
] += unrealizedProfits;
}
function getUnrealizedProfitsOf(
address player,
address sharesSubject,
address profitsSubject
) public view returns (uint256 unrealizedProfits) {
uint256 dHeight = sharesSubjectToProfitsSubjectToBeaconHeight[
sharesSubject
][profitsSubject] -
playerToSharesSubjectToProfitsSubjectToRealizedHeight[player][
sharesSubject
][profitsSubject];
unrealizedProfits = dHeight * sharesBalance[sharesSubject][player];
}
function getProfitsTokenList() public view returns (address[] memory) {
return autoRealizeProfitsTokenList;
}
function getMarketCapitalOf(
address sharesSubject
) public view returns (uint256 marketCapital) {
marketCapital =
sharesSupply[sharesSubject] *
getPrice(sharesSupply[sharesSubject], 1);
}
function getBatchMarketCapitalOf(
address[] calldata sharesSubjects
)
external
view
returns (uint256[] memory marketCapitals, uint256 totalMarketCapital)
{
uint256[] memory cache = new uint256[](sharesSubjects.length);
for (uint256 i = 0; i < sharesSubjects.length; i++) {
cache[i] = getMarketCapitalOf(sharesSubjects[i]);
totalMarketCapital += cache[i];
}
marketCapitals = cache;
}
function getUnclaimedProfitsOf(
address player,
address sharesSubject,
address profitsSubject
) external view returns (uint256 unclaimedProfits) {
uint256 unrealizedProfits = getUnrealizedProfitsOf(
player,
sharesSubject,
profitsSubject
);
uint256 realizedProfits = playerToProfitsSubjectToRealizedAmount[
player
][profitsSubject];
unclaimedProfits = unrealizedProfits + realizedProfits;
}
function claimProfits(
address player,
address sharesSubject,
address profitsSubject
) external {
realizeProfits(player, sharesSubject, profitsSubject);
uint256 realizedProfits = playerToProfitsSubjectToRealizedAmount[
player
][profitsSubject];
playerToProfitsSubjectToRealizedAmount[player][profitsSubject] = 0;
IERC20(profitsSubject).transfer(player, realizedProfits);
}
}
contract FASPforFrontEndInterface is FriendTechAsShareProfitsV2 {
constructor(address _acpToken) FriendTechAsShareProfitsV2(_acpToken) {
}
function getMainPageList(
address[] calldata sharesSubjects
)
external
view
returns (uint256[] memory marketCapitals, uint256[] memory priceList)
{
uint256[] memory cacheA = new uint256[](sharesSubjects.length);
uint256[] memory cacheB = new uint256[](sharesSubjects.length);
for (uint256 i = 0; i < sharesSubjects.length; i++) {
cacheA[i] = getMarketCapitalOf(sharesSubjects[i]);
cacheB[i] = getPrice(sharesSupply[sharesSubjects[i]], 1);
}
marketCapitals = cacheA;
priceList = cacheB;
}
}
//Aven@AOF 2025-4-30 0xe1853C5DC7E26afFeDADE24C7d7D0F0f489d0a43Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "cancun",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.