Created
February 24, 2024 19:41
-
-
Save Mexidense/ad8497a7083637574aa020f13add2289 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.24+commit.e11b9ed9.js&optimize=false&runs=200&gist=
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.24; | |
contract JamToken { | |
string public name = "Jam Token"; | |
string public symbol = "JAM"; | |
uint256 public totalSupply = 1000000000000000000000000; | |
uint public decimals = 18; | |
event Transfer( | |
address indexed _from, | |
address indexed _to, | |
uint256 _value | |
); | |
event Approve( | |
address indexed _owner, | |
address indexed _spender, | |
uint256 value | |
); | |
mapping(address => uint256) public balanceOf; | |
mapping(address => mapping(address => uint)) public allowance; | |
constructor() { | |
balanceOf[msg.sender] = totalSupply; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
require(balanceOf[msg.sender] >= _value, "Insufficient amounts of tokens to transfer"); | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
allowance[msg.sender][_spender] += _value; | |
emit Approve(msg.sender, _spender, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
require(_value <= balanceOf[_from], "Insufficient amounts of tokens from origin address"); | |
require(_value <= allowance[_from][_to], "Not allowed sending this amount de tokens between origin & destination address"); | |
balanceOf[_from] -= _value; | |
balanceOf[_to] += _value; | |
allowance[_from][msg.sender] -= _value; | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
} |
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.24; | |
contract StellartToken { | |
string public name = "Stellart Token"; | |
string public symbol = "STE"; | |
uint256 public totalSupply = 1000000000000000000000000; | |
uint public decimals = 18; | |
event Transfer( | |
address indexed _from, | |
address indexed _to, | |
uint256 _value | |
); | |
event Approve( | |
address indexed _owner, | |
address indexed _spender, | |
uint256 value | |
); | |
mapping(address => uint256) public balanceOf; | |
mapping(address => mapping(address => uint)) public allowance; | |
constructor() { | |
balanceOf[msg.sender] = totalSupply; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
require(balanceOf[msg.sender] >= _value, "Insufficient amounts of tokens to transfer"); | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
allowance[msg.sender][_spender] += _value; | |
emit Approve(msg.sender, _spender, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
require(_value <= balanceOf[_from], "Insufficient amounts of tokens from origin address"); | |
require(_value <= allowance[_from][_to], "Not allowed sending this amount de tokens between origin & destination address"); | |
balanceOf[_from] -= _value; | |
balanceOf[_to] += _value; | |
allowance[_from][msg.sender] -= _value; | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
} |
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.24; | |
import "./JamToken.sol"; | |
import "./StellartToken.sol"; | |
// Owner: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 | |
// User: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 | |
contract TokenFarm { | |
string public name = "Stellar Token Farm"; | |
address public owner; | |
JamToken public jamToken; | |
StellartToken public stellartToken; | |
address[] public stakers; | |
mapping(address => uint) public stakingBalance; | |
mapping(address => bool) public hasStaked; | |
mapping(address => bool) public isStaking; | |
constructor(StellartToken _stellartToken, JamToken _jamToken) { | |
stellartToken = _stellartToken; | |
jamToken = _jamToken; | |
owner = msg.sender; | |
} | |
function stakeTokens(uint _amount) public { | |
require(_amount > 0, "Amount could not be zero"); | |
jamToken.transferFrom(msg.sender, address(this), _amount); | |
stakingBalance[msg.sender] += _amount; | |
if(!hasStaked[msg.sender]) { | |
stakers.push(msg.sender); | |
} | |
isStaking[msg.sender] = true; | |
hasStaked[msg.sender] = true; | |
} | |
function unstakeTokens() public { | |
uint balance = stakingBalance[msg.sender]; | |
require(balance > 0, "Staking balance must be greater than zero"); | |
jamToken.transfer(msg.sender, balance); | |
stakingBalance[msg.sender] = 0; | |
isStaking[msg.sender] = false; | |
} | |
function issueTokens() public { | |
require(msg.sender == owner, "Only owner must issue tokens"); | |
for (uint i=0; i<stakers.length; i++) { | |
address recipient = stakers[i]; | |
uint balance = stakingBalance[recipient]; | |
if (balance > 0) { | |
stellartToken.transfer(recipient, balance); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment