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