Created
July 24, 2024 13:42
-
-
Save markin-io/520ac15e8f08a8783dd6d6a93c21b97e to your computer and use it in GitHub Desktop.
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.0; | |
| // Interface for ERC20 tokens | |
| interface IERC20 { | |
| function balanceOf(address account) external view returns (uint256); | |
| } | |
| contract CapitalCommitment { | |
| // Mapping from user address to token address to commitment amount | |
| mapping(address => mapping(address => uint256)) public commitments; | |
| // Supported tokens | |
| address[] public supportedTokens; | |
| // Events | |
| event Committed(address indexed user, address indexed token, uint256 amount); | |
| // Errors | |
| error TokenNotSupported(); | |
| error InsufficientBalance(); | |
| // Add supported tokens (e.g., USDC, USDT, DAI, ETH, wBTC) | |
| constructor(address[] memory _supportedTokens) { | |
| supportedTokens = _supportedTokens; | |
| } | |
| // Function to check if a token is supported | |
| function isSupportedToken(address token) public view returns (bool) { | |
| for (uint256 i = 0; i < supportedTokens.length; i++) { | |
| if (supportedTokens[i] == token) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| // Function to commit capital | |
| function commit(address token, uint256 amount) external { | |
| if (!isSupportedToken(token)) revert TokenNotSupported(); | |
| // Check the user's balance | |
| IERC20 tokenContract = IERC20(token); | |
| uint256 userBalance = tokenContract.balanceOf(msg.sender); | |
| if (userBalance < amount) revert InsufficientBalance(); | |
| // Record the commitment | |
| commitments[msg.sender][token] = amount; | |
| // Emit an event | |
| emit Committed(msg.sender, token, amount); | |
| } | |
| // Function to get a user's commitment for a specific token | |
| function getCommitment(address user, address token) external view returns (uint256) { | |
| return commitments[user][token]; | |
| } | |
| // Function to get all supported tokens | |
| function getSupportedTokens() external view returns (address[] memory) { | |
| return supportedTokens; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment