Skip to content

Instantly share code, notes, and snippets.

@astronaut7
Last active June 14, 2023 18:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
// 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