-
-
Save astronaut7/a8031cc1ba86d76169de828931aa82c1 to your computer and use it in GitHub Desktop.
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
interface IERC20 { | |
function transferFrom(address from, address to, uint256 amount) external returns (bool); | |
function transfer(address to, uint256 amount) external returns (bool); | |
function balanceOf(address account) external view returns (uint256); | |
} | |
interface IERC20Mintable { | |
function mint(address for, uint256 amount) | |
function burn(address from, uint256 amount) | |
} | |
contract DepositFacility { | |
address public asset; | |
address public claim; | |
IERC20 private acceptedAsset; | |
IERC20Mintable private claimReceipt; | |
event AssetDeposited(address indexed depositor, uint256 amount); | |
event AssetWithdrawn(address indexed depositor, uint256 amount); | |
constructor(address _asset, address _claim) { | |
asset = _asset; | |
claim = _claim; | |
IERC20 acceptedAsset = IERC20(asset); | |
IERC20 claimRecepit = IERC20(claim); | |
} | |
function deposit(uint256 amount) external { | |
uint256 assetBalance = acceptedAsset.balanceOf(msg.sender); | |
require(assetBalance >= amount, "Insufficient balance"); | |
bool transferSuccess = acceptedAsset.transfer(address(this), amount); | |
require(transferSuccess, "Transfer failed"); | |
bool claimIssued = claimReceipt.mint(msg.sender, amount); | |
require(claimIssued, "Deposit refused"); | |
emit AssetDeposited(msg.sender, amount); | |
} | |
function withdraw(uint256 amount) external { | |
uint256 claimBalance = claimReceipt.balanceOf(msg.sender); | |
require(claimBalance >= amount, "Insufficient balance"); | |
bool redemptionSuccess = claimReceipt.burn(address(this), amount); | |
require(redemptionSuccess, "Withdrawal refused"); | |
bool withdrawalIssued = acceptedAsset.transfer(msg.sender, amount); | |
require(withdrawalIssued, "Withdrawal failed"); | |
emit AssetWithdrawn(msg.sender, amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment