Created
February 4, 2023 01:54
-
-
Save floatbeta/9a7e93664e3071547545d60df49d8246 to your computer and use it in GitHub Desktop.
This smart contract allows users to farm a fungible token on MoltenChain during a specific period.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Fungible Token Farming Smart Contract for MoltenChain | |
-- Define the name and symbol of the fungible token | |
local tokenName = "Your Token" | |
local tokenSymbol = "YURT" | |
-- Define the total supply of the fungible token | |
local totalSupply = 100000000 | |
-- Define the farming rate, in this case, 1 token per block | |
local farmingRate = 1 | |
-- Define the farming start and end block | |
local farmingStartBlock = 1 | |
local farmingEndBlock = 1000000 | |
-- Create a mapping to store the balance of each address | |
local balances = {} | |
-- Create a function to initialize the smart contract | |
function init() | |
-- Set the total supply of the token to the address of the contract | |
balances[msg.sender] = totalSupply | |
end | |
-- Create a function to farm the fungible token | |
function farm() | |
-- Check if the current block height is within the farming period | |
if block.height >= farmingStartBlock and block.height <= farmingEndBlock then | |
-- Check if the msg.sender has enough space in their balance to receive the farming rate | |
if balances[msg.sender] + farmingRate <= 2^256-1 then | |
-- Add the farming rate to the msg.sender's balance | |
balances[msg.sender] = balances[msg.sender] + farmingRate | |
else | |
-- If the msg.sender's balance is full, send an error message | |
error("The address's balance is full. Cannot farm more tokens.") | |
end | |
else | |
-- If the current block height is not within the farming period, send an error message | |
error("Farming period has ended.") | |
end | |
end | |
-- Create a function to transfer the fungible token | |
function transfer(to, value) | |
-- Check if the msg.sender has enough balance to transfer | |
if balances[msg.sender] >= value then | |
-- Check if the recipient's balance will not overflow | |
if balances[to] + value <= 2^256-1 then | |
-- Subtract the value from the msg.sender's balance | |
balances[msg.sender] = balances[msg.sender] - value | |
-- Add the value to the recipient's balance | |
balances[to] = balances[to] + value | |
else | |
-- If the recipient's balance will overflow, send an error message | |
error("Recipient's balance will overflow. Cannot transfer tokens.") | |
end | |
else | |
-- If the msg.sender does not have enough balance, send an error message | |
error("The address does not have enough balance to transfer.") | |
end | |
end | |
-- Create a function to check the balance of an address | |
function balanceOf(address) | |
-- Return the balance of the specified address | |
return balances[address] | |
end | |
-- Create a function to check the name of the token | |
function name() | |
-- Return the name of the token | |
return tokenName | |
end | |
-- Create a function to check the symbol of the token | |
function symbol() | |
-- Return the symbol of the token | |
return tokenSymbol | |
end | |
-- Create a function to check the total supply of the token | |
function totalSupply() | |
-- Return the total supply of the token | |
return totalSupply | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment