Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Created January 15, 2024 09:30
Show Gist options
  • Save z0r0z/821b1d4cb40be14298930ed1c495753f to your computer and use it in GitHub Desktop.
Save z0r0z/821b1d4cb40be14298930ed1c495753f to your computer and use it in GitHub Desktop.
Dollars-to-donuts exchange. Demo: Circle <> Tether. Smol Swap Lego.
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
/// @notice Dollars-to-donuts exchange.
/// Put in one thing for another thing.
contract CTX {
IERC20 constant C = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); // Circle dollars.
IERC20 constant T = IERC20(0xdAC17F958D2ee523a2206206994597C13D831ec7); // Tether dollars.
uint256 constant F = 1; // Fee is just a lil bit. Placeholder. Someone should do the math.
/// @dev So, we just assume same price. One in. One out.
function swap(bool cForT, uint256 amount) public payable {
unchecked {
// Pull in some tokens. We check whether it is C or T.
if (cForT) {
C.transferFrom(msg.sender, address(this), amount);
T.transfer(msg.sender, amount - F);
} else {
T.transferFrom(msg.sender, address(this), amount);
C.transfer(msg.sender, amount - F);
}
}
}
/// @dev Enter the pool with your amount, or exit fees.
function lp(bool enter, uint256 amount) public payable {
unchecked {
if (enter) {
C.transferFrom(msg.sender, address(this), amount);
T.transferFrom(msg.sender, address(this), amount);
} else {/*Do the withdrawal stuff.*/}
}
}
}
/// @dev Fungible token transfer interface.
interface IERC20 {
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment