// SPDX-License-Identifier: ---DG----
pragma solidity =0.8.23;
import "./ERC20.sol";
interface ILightDGToken {
function transfer(
address _recipient,
uint256 _amount
)
external
returns (bool);
function transferFrom(
address _sender,
address _recipient,
uint256 _amount
)
external
returns (bool);
}
contract BAGCOIN is ERC20 {
ILightDGToken immutable public lightDG;
uint256 constant public RATIO = 8;
constructor(
string memory _tokenName,
string memory _tokenSymbol,
address _lightDGTokenAddress
)
ERC20(
_tokenName,
_tokenSymbol
)
{
lightDG = ILightDGToken(
_lightDGTokenAddress
);
}
function getBAGTokens(
uint256 _lightDGAmountToDeposit
)
external
{
lightDG.transferFrom(
msg.sender,
address(this),
_lightDGAmountToDeposit
);
_mint(
msg.sender,
_lightDGAmountToDeposit * RATIO
);
}
function returnBAGTokens(
uint256 _lightDGAmountToReceive
)
external
{
_burn(
msg.sender,
_lightDGAmountToReceive * RATIO
);
lightDG.transfer(
msg.sender,
_lightDGAmountToReceive
);
}
}
// SPDX-License-Identifier: -- DG --
pragma solidity =0.8.23;
contract ERC20 {
string public name;
string public symbol;
uint8 public decimals;
address internal constant ZERO_ADDY = address(0x0);
uint256 internal constant UINT256_MAX = type(uint256).max;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
mapping(address => uint256) public nonces;
bytes32 public immutable 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 _name,
string memory _symbol
) {
name = _name;
symbol = _symbol;
decimals = 18;
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 _mint(
address _to,
uint256 _value
)
internal
{
totalSupply =
totalSupply + _value;
unchecked {
balanceOf[_to] =
balanceOf[_to] + _value;
}
emit Transfer(
ZERO_ADDY,
_to,
_value
);
}
function _burn(
address _from,
uint256 _value
)
internal
{
unchecked {
totalSupply =
totalSupply - _value;
}
balanceOf[_from] =
balanceOf[_from] - _value;
emit Transfer(
_from,
ZERO_ADDY,
_value
);
}
function _approve(
address _owner,
address _spender,
uint256 _value
)
private
{
allowance[_owner][_spender] = _value;
emit Approval(
_owner,
_spender,
_value
);
}
function _transfer(
address _from,
address _to,
uint256 _value
)
private
{
balanceOf[_from] =
balanceOf[_from] - _value;
unchecked {
balanceOf[_to] =
balanceOf[_to] + _value;
}
emit Transfer(
_from,
_to,
_value
);
}
function approve(
address _spender,
uint256 _value
)
external
returns (bool)
{
_approve(
msg.sender,
_spender,
_value
);
return true;
}
function transfer(
address _to,
uint256 _value
)
external
returns (bool)
{
_transfer(
msg.sender,
_to,
_value
);
return true;
}
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
if (allowance[_from][msg.sender] != UINT256_MAX) {
allowance[_from][msg.sender] -= _value;
}
_transfer(
_from,
_to,
_value
);
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
)
)
)
);
if (uint256(_s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
revert("Token: INVALID_SIGNATURE");
}
address recoveredAddress = ecrecover(
digest,
_v,
_r,
_s
);
require(
recoveredAddress != ZERO_ADDY &&
recoveredAddress == _owner,
"ERC20: INVALID_SIGNATURE"
);
_approve(
_owner,
_spender,
_value
);
}
}
{
"compilationTarget": {
"BAGCOIN.sol": "BAGCOIN"
},
"evmVersion": "shanghai",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"_tokenName","type":"string"},{"internalType":"string","name":"_tokenSymbol","type":"string"},{"internalType":"address","name":"_lightDGTokenAddress","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":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lightDGAmountToDeposit","type":"uint256"}],"name":"getBAGTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lightDG","outputs":[{"internalType":"contract ILightDGToken","name":"","type":"address"}],"stateMutability":"view","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":[{"internalType":"uint256","name":"_lightDGAmountToReceive","type":"uint256"}],"name":"returnBAGTokens","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":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]