// SPDX-License-Identifier: ---DG----
pragma solidity ^0.8.9;
import "./ERC20.sol";
interface IClassicDGToken {
function transfer(
address _recipient,
uint256 _amount
)
external
returns (bool);
function transferFrom(
address _sender,
address _recipient,
uint256 _amount
)
external
returns (bool);
}
contract DGLight is ERC20("Decentral Games", "DG") {
IClassicDGToken immutable public classicDG;
uint16 constant public RATIO = 1000;
constructor(
address _classicDGTokenAddress
) {
classicDG = IClassicDGToken(
_classicDGTokenAddress
);
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name())),
keccak256(bytes('1')),
block.chainid,
address(this)
)
);
}
function goLight(
uint256 _classicAmountToDeposit
)
external
{
classicDG.transferFrom(
msg.sender,
address(this),
_classicAmountToDeposit
);
_mint(
msg.sender,
_classicAmountToDeposit * RATIO
);
}
function goClassic(
uint256 _classicAmountToReceive
)
external
{
classicDG.transfer(
msg.sender,
_classicAmountToReceive
);
_burn(
msg.sender,
_classicAmountToReceive * RATIO
);
}
}
// SPDX-License-Identifier: ---DG----
pragma solidity ^0.8.9;
contract ERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
uint256 private _totalSupply;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => uint) public nonces;
bytes32 public DOMAIN_SEPARATOR;
bytes32 public constant PERMIT_TYPEHASH = keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);
event Transfer(
address indexed _from,
address indexed _to,
uint256 _value
);
event Approval(
address indexed _owner,
address indexed _spender,
uint256 _value
);
constructor(
string memory _entryname,
string memory _entrysymbol
) {
_name = _entryname;
_symbol = _entrysymbol;
_decimals = 18;
}
function name()
public
view
returns (string memory)
{
return _name;
}
function symbol()
public
view
returns (string memory)
{
return _symbol;
}
function decimals()
public
view
returns (uint8)
{
return _decimals;
}
function totalSupply()
public
view
returns (uint256)
{
return _totalSupply;
}
function balanceOf(
address _account
)
public
view
returns (uint256)
{
return _balances[_account];
}
function transfer(
address _recipient,
uint256 _amount
)
external
returns (bool)
{
_transfer(
msg.sender,
_recipient,
_amount
);
return true;
}
function allowance(
address _owner,
address _spender
)
external
view
returns (uint256)
{
return _allowances[_owner][_spender];
}
function approve(
address _spender,
uint256 _amount
)
external
returns (bool)
{
_approve(
msg.sender,
_spender,
_amount
);
return true;
}
function transferFrom(
address _sender,
address _recipient,
uint256 _amount
)
public
returns (bool)
{
_approve(
_sender,
msg.sender,
_allowances[_sender][msg.sender] - _amount
);
_transfer(
_sender,
_recipient,
_amount
);
return true;
}
function permit(
address _owner,
address _spender,
uint256 _value,
uint256 _deadline,
uint8 _v,
bytes32 _r,
bytes32 _s
)
external
{
require(
_deadline >= block.timestamp,
'ERC20: PERMIT_CALL_EXPIRED'
);
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR,
keccak256(
abi.encode(
PERMIT_TYPEHASH,
_owner,
_spender,
_value,
nonces[_owner]++,
_deadline
)
)
)
);
address recoveredAddress = ecrecover(
digest,
_v,
_r,
_s
);
require(
recoveredAddress != address(0) &&
recoveredAddress == _owner,
'INVALID_SIGNATURE'
);
_approve(
_owner,
_spender,
_value
);
}
function _transfer(
address _sender,
address _recipient,
uint256 _amount
)
internal
{
_balances[_sender] =
_balances[_sender] - _amount;
_balances[_recipient] =
_balances[_recipient] + _amount;
emit Transfer(
_sender,
_recipient,
_amount
);
}
function _mint(
address _account,
uint256 _amount
)
internal
{
_totalSupply =
_totalSupply + _amount;
unchecked {
_balances[_account] =
_balances[_account] + _amount;
}
emit Transfer(
address(0),
_account,
_amount
);
}
function _burn(
address _account,
uint256 _amount
)
internal
{
_balances[_account] =
_balances[_account] - _amount;
unchecked {
_totalSupply =
_totalSupply - _amount;
}
emit Transfer(
_account,
address(0),
_amount
);
}
function _approve(
address _owner,
address _spender,
uint256 _amount
)
internal
{
_allowances[_owner][_spender] = _amount;
emit Approval(
_owner,
_spender,
_amount
);
}
}
{
"compilationTarget": {
"DGLightToken.sol": "DGLight"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_classicDGTokenAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RATIO","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"classicDG","outputs":[{"internalType":"contract IClassicDGToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_classicAmountToReceive","type":"uint256"}],"name":"goClassic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_classicAmountToDeposit","type":"uint256"}],"name":"goLight","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"uint8","name":"_v","type":"uint8"},{"internalType":"bytes32","name":"_r","type":"bytes32"},{"internalType":"bytes32","name":"_s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_sender","type":"address"},{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]