Description:
Decentralized Finance (DeFi) protocol contract providing Swap, Factory functionality.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Vyper",
"sources": {
"src/periphery/interfaces/IExchange.vyi": {
"content": "# @version 0.4.1
# ============================================================================================
# View functions
# ============================================================================================
@external
@view
def BORROW_TOKEN() -> address:
...
@external
@view
def COLLATERAL_TOKEN() -> address:
...
@external
@view
def price() -> uint256:
...
# ============================================================================================
# Mutative functions
# ============================================================================================
@external
def swap(amount: uint256, receiver: address = msg.sender) -> uint256:
...",
"sha256sum": "041e04a8201d46cb1aba81dd5d42ed01edf0d0a10c181f10d9833c2e545ee530"
},
"src/periphery/interfaces/ICurveTwocryptoPool.vyi": {
"content": "# @version 0.4.1
@external
@view
def price_oracle() -> uint256:
...
@external
@view
def coins(i: uint256) -> address:
...
@external
def exchange(
i: uint256,
j: uint256,
dx: uint256,
min_dy: uint256,
receiver: address = msg.sender
) -> uint256:
...",
"sha256sum": "be986a072ed12476b904853a3753637bfde5f4a741c70c3dfa603ff0a596413f"
},
"src/periphery/tbtc.vy": {
"content": "# @version 0.4.1
"""
@title tBTC --> crvUSD
@license MIT
@author Flex
@notice Swaps tBTC for crvUSD
"""
from ethereum.ercs import IERC20
from ethereum.ercs import IERC4626
from interfaces import IExchange
from interfaces import ICurveTwocryptoPool as ICurvePool
# ============================================================================================
# Interfaces
# ============================================================================================
implements: IExchange
# ============================================================================================
# Constants
# ============================================================================================
# Token addresses
_CRVUSD: constant(IERC20) = IERC20(0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E)
_TBTC: constant(IERC20) = IERC20(0x18084fbA666a33d37592fA2633fD49a74DD93a88)
# Curve pool
_CURVE_POOL_TBTC_INDEX: constant(uint256) = 1
_CURVE_POOL_CRVUSD_INDEX: constant(uint256) = 0
_CURVE_POOL: constant(ICurvePool) = ICurvePool(0xf1F435B05D255a5dBdE37333C0f61DA6F69c6127) # YB tBTC
# ============================================================================================
# Constructor
# ============================================================================================
@deploy
def __init__():
"""
@notice Initialize the contract
"""
assert staticcall _CURVE_POOL.coins(_CURVE_POOL_TBTC_INDEX) == _TBTC.address, "!COLLATERAL_TOKEN"
assert staticcall _CURVE_POOL.coins(_CURVE_POOL_CRVUSD_INDEX) == _CRVUSD.address, "!BORROW_TOKEN"
extcall _TBTC.approve(_CURVE_POOL.address, max_value(uint256), default_return_value=True)
# ============================================================================================
# View functions
# ============================================================================================
@external
@view
def BORROW_TOKEN() -> address:
"""
@notice Returns the address of the borrow token
@return Address of the borrow token
"""
return _CRVUSD.address
@external
@view
def COLLATERAL_TOKEN() -> address:
"""
@notice Returns the address of the collateral token
@return Address of the collateral token
"""
return _TBTC.address
@external
@view
def price() -> uint256:
"""
@notice Returns the price of the collateral token in terms of the borrow token
@dev Price is in 1e18 format
@return Price of the collateral token in terms of borrow token
"""
return staticcall _CURVE_POOL.price_oracle()
# ============================================================================================
# Mutative functions
# ============================================================================================
@external
def swap(amount: uint256, receiver: address = msg.sender) -> uint256:
"""
@notice Swap from the collateral token to the borrow token
@dev Caller should add slippage protection
@param amount Amount of collateral tokens to swap
@return Amount of borrow tokens received
"""
# Do nothing on zero amount
if amount == 0:
return 0
# Pull tBTC from the caller
extcall _TBTC.transferFrom(msg.sender, self, amount, default_return_value=True)
# tBTC --> crvUSD
amount_out: uint256 = extcall _CURVE_POOL.exchange(
_CURVE_POOL_TBTC_INDEX,
_CURVE_POOL_CRVUSD_INDEX,
amount,
0, # min_dy
receiver # receiver
)
return amount_out",
"sha256sum": "98d48a3c402031e037ff5114a51e005ca28063ac9caaa96e322b5a98d80a89e4"
}
},
"settings": {
"outputSelection": {
"src/periphery/tbtc.vy": [
"evm.bytecode",
"evm.deployedBytecode",
"abi"
]
},
"search_paths": [
"."
]
},
"compiler_version": "v0.4.1+commit.8a93dd27",
"integrity": "276a740983eb918411475cf9bb7ada6a24c0a8d3e1cd2faca6fda0b39eaa27bb"
}}
Submitted on: 2025-10-25 20:37:22
Comments
Log in to comment.
No comments yet.