MKF High level
Explain the MKF Solidity code
Master Key Finance / Portal
MKF High Level
Explains the MKF Solidity code
Master Key Finance / Portal
1. Inheritance
β Ownable: This gives the contract an owner who can control certain functions.
β ReentrancyGuard: Protects against reentrancy attacks, a type of vulnerability in smart contracts.
2. Purpose This contract appears to be a marketplace for trading tokens. It allows users to:
β List tokens for sale
β Buy listings
β Claim rewards
3. Key Variables and Mappings
β MSFY: An instance of an ERC20 token (likely the platform's native token).
β BUSD: An instance of the Binance USD (BUSD) stablecoin.
β dataFeed: An instance of a Chainlink price feed, used to get the price of BNB.
β subscriptionService: An interface to a subscription service (likely for accessing features on the platform).
β token: An instance of the MasterKeyToken contract (likely the token used for rewards).
β listings: A mapping that stores information about listings (token pairs, amounts, rewards, etc.).
β tokens: A mapping that stores information about whitelisted tokens (address, name, symbol, decimals, tax rate, etc.).
β rewards: A mapping that stores information about user rewards (wallet address, rewards debt, listing IDs, etc.).
β tokenIds: An array that stores the IDs of whitelisted tokens.
β BBB: An address (likely a "Big Buyer Bonus" address).
β feeCollector: An address that collects fees.
β totalListings: A counter for the total number of listings.
β totalTokensWhitelisted: A counter for the total number of whitelisted tokens.
β dailyBountyMAX: The maximum daily bounty reward.
β listingRewardTimeframe: The timeframe for earning rewards on a listing.
β BNBListingFee: The fee for creating a listing, denominated in BNB.
β pricingEnabled: A flag indicating whether BNB fees are enabled.
β authorizedContract: The address of an authorized contract (likely the subscription service).
4. Events
β ListingCreated: Emitted when a new listing is created.
β ListingRemoved: Emitted when a listing is removed.
β ListingBought: Emitted when a listing is bought.
β TokenAdded: Emitted when a new token is added to the whitelist.
β TokenRemoved: Emitted when a token is removed from the whitelist.
β AddedPlatformAddress: Emitted when a new platform address is added.
β RemovedPlatformAddress: Emitted when a platform address is removed.
β TaxTransfered: Emitted when tax is transferred to the fee collector.
β NewUserRegistered: Emitted when a new user is registered.
5. Modifiers
β onlyPlatform: Ensures that only platform addresses can call the function.
β onlyOwnerOrPlatform: Ensures that only the owner or a platform address can call the function.
β onlyAuthorizedContract: Ensures that only the owner or the authorized contract can call the function.
β BNBFeeEnabled: Ensures that the BNB fee is paid if pricing is enabled.
6. Functions
β updateSubscriptionServiceAddress: Updates the address of the subscription service.
β triggerRefillSubscription: Triggers a refill of a subscription using rewards.
β getBNBPrice: Gets the current price of BNB from the Chainlink price feed.
β setBNBFeeEnabled: Enables or disables BNB fees.
β setBNBListingFee: Sets the BNB fee for creating a listing.
β setMSFYAddress: Sets the address of the MSFY token.
β setListingRewardTimeframe: Sets the timeframe for earning rewards on a listing.
β setBBBAddress: Sets the address of the "Big Buyer Bonus" address.
β setFeeCollectorAddress: Sets the address of the fee collector.
β setTaxRate: Sets the tax rate for a specific token.
β addWhitelistToken: Adds a new token to the whitelist.
β removeWhitelistToken: Removes a token from the whitelist.
β userRegister: Registers a new user.
β setrewardsDebt: Sets the rewards debt for a user (for testing purposes).
β createListing: Creates a new listing.
β buyListing: Buys a listing.
β removeListing: Removes a listing.
β getListingBounty: Calculates the bounty and reward for a listing.
β convertDecimals: Converts an amount from one token's decimals to another's.
β getDecimals: Gets the decimals of a token.
β convertDecimal: Converts an amount from one decimal to another.
β emergencyWithdrawNative: Allows the owner or platform to withdraw native tokens.
β emergencyWithdrawERC20: Allows the owner or platform to withdraw ERC20 tokens.
β addPlatformAddress: Adds a new platform address.
β removePlatformAddress: Removes a platform address.
β claimReward: Allows users to claim their rewards.
β monthly: Performs monthly tasks, such as transferring tax to the fee collector.
7. Key Functionality
β Listing Creation: Users can create listings by providing the token pair, amounts, and a bounty/reward amount.
β Listing Purchase: Users can buy listings by paying the required amount of the "to" token and receiving the "from" token.
β Rewards: Rewards are earned based on the time a listing is active.
β Tax: A tax rate can be set for each token, and the tax is collected by the fee collector.
β Subscription Service: The contract interacts with a subscription service, allowing users to refill their subscriptions using rewards.
8. Important Notes
β Security: The contract uses the ReentrancyGuard modifier to protect against reentrancy attacks.
β Ownership: The contract uses the Ownable modifier to give an owner control over certain functions.
β Platform Addresses: The contract allows platform addresses to have special privileges.
β BNB Fees: The contract allows for BNB fees to be charged for creating listings.
β Chainlink Price Feed: The contract uses a Chainlink price feed to get the current price of BNB.
Overall, this contract appears to be a complex marketplace for trading tokens, with features such as rewards, tax collection, and integration with a subscription service.
Last updated