Verified contractPartial
FastBridgeVault
Address0xadb10d2d5a95e58ddb1a0744a0d2d7b55db7843d
- Balance
0 ETH
- Transactions
14
- Compiler
vyper 0.4.3
- Same code
2 more contracts
Details
- Compiler
- vyper 0.4.3+commit.bff19ea2
- Language
- vyper
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 23,792,373
- Creation transaction
- 0xf4c626b879…7ceb0aac0c
contracts/FastBridgeVault.vy
# pragma version 0.4.3
"""
@title FastBridgeVault
@notice Vault with crvUSD for FastBridge
@license MIT
@author curve.fi
@custom:version 0.0.1
@custom:security [email protected]
"""
version: public(constant(String[8])) = "0.0.1"
from ethereum.ercs import IERC20
from snekmate.auth import access_control
initializes: access_control
exports: (
access_control.hasRole,
access_control.getRoleAdmin,
access_control.DEFAULT_ADMIN_ROLE,
access_control.grantRole,
access_control.revokeRole,
access_control.renounceRole,
access_control.set_role_admin
)
interface IMinter: # ControllerFactory
def rug_debt_ceiling(_to: address): nonpayable
def debt_ceiling(of: address) -> uint256: view
def debt_ceiling_residual(of: address) -> uint256: view
event Minted:
receiver: indexed(address)
amount: uint256
event RugScheduled:
status: bool
event SetFee:
fee: uint256
event SetFeeReceiver:
fee_receiver: address
event SetKilled:
actor: indexed(address)
killed: bool
event Recovered:
token: indexed(IERC20)
receiver: address
amount: uint256
struct RecoverInput:
coin: IERC20
amount: uint256
MINTER_ROLE: public(constant(bytes32)) = keccak256("MINTER")
KILLER_ROLE: public(constant(bytes32)) = keccak256("KILLER")
CRVUSD: public(constant(IERC20)) = IERC20(0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E)
MINTER: public(constant(IMinter)) = IMinter(0xC9332fdCB1C491Dcc683bAe86Fe3cb70360738BC)
balanceOf: public(HashMap[address, uint256])
fee: public(uint256) # 10^18 precision
fee_receiver: public(address)
rug_scheduled: public(bool)
is_killed: public(HashMap[address, bool])
@deploy
def __init__(_ownership: address, _emergency: address, _minters: DynArray[address, 4]):
"""
@param _ownership Address of owner admin
@param _emergency Address of emergency(kill operations) admin
@param _minters Addresses of contracts able to mint tokens from vault
"""
access_control.__init__()
for minter: address in _minters:
assert minter != empty(address), "Bad minter"
access_control._grant_role(MINTER_ROLE, minter)
assert _ownership != empty(address), "Bad owner"
assert _emergency != empty(address), "Bad emergency"
access_control._revoke_role(access_control.DEFAULT_ADMIN_ROLE, msg.sender)
access_control._grant_role(access_control.DEFAULT_ADMIN_ROLE, _ownership)
access_control._grant_role(KILLER_ROLE, _emergency)
# Allow ControllerFactory to rug debt ceiling and burn coins
assert extcall CRVUSD.approve(MINTER.address, max_value(uint256), default_return_value=True)
# initially no fee
self.fee_receiver = 0xa2Bcd1a4Efbd04B63cd03f5aFf2561106ebCCE00 # FeeCollector
log SetFeeReceiver(fee_receiver=0xa2Bcd1a4Efbd04B63cd03f5aFf2561106ebCCE00)
@view
def _need_to_rug() -> bool:
"""
@notice Check if there was a cut in debt ceiling
"""
return staticcall MINTER.debt_ceiling_residual(self) > staticcall MINTER.debt_ceiling(self)
@internal
def _get_balance() -> uint256:
"""
@notice Get balance of crvUSD after rugging debt ceiling
@return Amount of crvUSD available to mint
"""
if self.rug_scheduled:
extcall MINTER.rug_debt_ceiling(self)
if not self._need_to_rug():
self.rug_scheduled = False
log RugScheduled(status=False)
else:
return 0
return staticcall CRVUSD.balanceOf(self)
@external
def schedule_rug() -> bool:
"""
@notice Schedule rugging debt ceiling if necessary. Callable by anyone
@return Boolean whether need to rug or not
"""
rug_scheduled: bool = self._need_to_rug()
self.rug_scheduled = rug_scheduled
log RugScheduled(status=rug_scheduled)
return rug_scheduled
@external
@nonreentrant
def mint(_receiver: address, _amount: uint256) -> uint256:
"""
@notice Receive bridged crvUSD
@param _receiver Receiver of crvUSD
@param _amount Amount of crvUSD to mint (0 if not minter)
@return Amount of crvUSD minted to receiver
"""
assert not (self.is_killed[empty(address)] or self.is_killed[msg.sender])
amount: uint256 = self.balanceOf[_receiver]
if access_control.hasRole[MINTER_ROLE][msg.sender]:
amount += _amount
# Apply fee
fee: uint256 = _amount * self.fee // 10 ** 18
fee_receiver: address = self.fee_receiver
if _receiver != fee_receiver:
self.balanceOf[fee_receiver] += fee
amount -= fee
available: uint256 = min(self._get_balance(), amount)
if available != 0:
assert extcall CRVUSD.transfer(_receiver, available, default_return_value=True)
self.balanceOf[_receiver] = amount - available
log Minted(receiver=_receiver, amount=available)
return available
@external
def set_killed(_status: bool, _who: address=empty(address)):
"""
@notice Emergency method to kill minter
@param _status Boolean whether to stop minter from working
@param _who Minter to kill/unkill, empty address to kill all receiving
"""
access_control._check_role(KILLER_ROLE, msg.sender)
self.is_killed[_who] = _status
log SetKilled(actor=_who, killed=_status)
@external
def set_fee(_new_fee: uint256):
"""
@notice Set fee on bridge transactions
@param _new_fee Fee with 10^18 precision
"""
access_control._check_role(access_control.DEFAULT_ADMIN_ROLE, msg.sender)
assert _new_fee <= 10 ** 18
self.fee = _new_fee
log SetFee(fee=_new_fee)
@external
def set_fee_receiver(_new_fee_receiver: address):
"""
@notice Set new fee receiver
@param _new_fee_receiver Fee receiver address
"""
access_control._check_role(access_control.DEFAULT_ADMIN_ROLE, msg.sender)
assert _new_fee_receiver != empty(address)
self.fee_receiver = _new_fee_receiver
log SetFeeReceiver(fee_receiver=_new_fee_receiver)
@external
def recover(_recovers: DynArray[RecoverInput, 32], _receiver: address):
"""
@notice Recover ERC20 tokens from this contract. Needed in case of minter malfunction.
@dev Callable only by owner
@param _recovers (Token, amount) to recover
@param _receiver Receiver of coins
"""
access_control._check_role(access_control.DEFAULT_ADMIN_ROLE, msg.sender)
for input: RecoverInput in _recovers:
amount: uint256 = input.amount
if amount == max_value(uint256):
amount = staticcall input.coin.balanceOf(self)
extcall input.coin.transfer(_receiver, amount, default_return_value=True) # do not need safe transfer
log Recovered(token=input.coin, receiver=_receiver, amount=amount)
.venv/lib/python3.12/site-packages/snekmate/auth/access_control.vy
# pragma version ~=0.4.3
# pragma nonreentrancy off
"""
@title Multi-Role-Based Access Control Functions
@custom:contract-name access_control
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions can be used to implement role-based access
control mechanisms. Roles are referred to by their `bytes32`
identifier. These should be exposed in the external API and
be unique. The best way to achieve this is by using `public`
`constant` hash digests:
```vy
MY_ROLE: public(constant(bytes32)) = keccak256("MY_ROLE");
```
Roles can be used to represent a set of permissions. To restrict
access to a function call, use the `external` function `hasRole`
or the `internal` function `_check_role` (to avoid any NatSpec
parsing error, no `@` character is added to the visibility decorator
`@external` in the following examples; please add them accordingly):
```vy
from ethereum.ercs import IERC165
implements: IERC165
from snekmate.auth.interfaces import IAccessControl
implements: IAccessControl
from snekmate.auth import access_control
initializes: access_control
exports: access_control.__interface__
...
external
def foo():
assert access_control.hasRole[MY_ROLE][msg.sender], "access_control: account is missing role"
...
OR
external
def foo():
access_control._check_role(MY_ROLE, msg.sender)
...
```
Roles can be granted and revoked dynamically via the `grantRole`
and `revokeRole` functions. Each role has an associated admin role,
and only accounts that have a role's admin role can call `grantRole`
and `revokeRole`. Also, by default, the admin role for all roles is
`DEFAULT_ADMIN_ROLE`, which means that only accounts with this role
will be able to grant or revoke other roles. More complex role
relationships can be created by using `set_role_admin`.
WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin! It has
permission to grant and revoke this role. Extra precautions should be
taken to secure accounts that have been granted it.
The implementation is inspired by OpenZeppelin's implementation here:
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol.
"""
# @dev We import and implement the `IERC165` interface,
# which is a built-in interface of the Vyper compiler.
from ethereum.ercs import IERC165
implements: IERC165
# @dev We import and implement the `IAccessControl`
# interface, which is written using standard Vyper
# syntax.
from .interfaces import IAccessControl
implements: IAccessControl
# @dev The default 32-byte admin role.
# @notice If you declare a variable as `public`,
# Vyper automatically generates an `external`
# getter function for the variable.
DEFAULT_ADMIN_ROLE: public(constant(bytes32)) = empty(bytes32)
# @dev Stores the ERC-165 interface identifier for each
# imported interface. The ERC-165 interface identifier
# is defined as the XOR of all function selectors in the
# interface.
_SUPPORTED_INTERFACES: constant(bytes4[2]) = [
0x01FFC9A7, # The ERC-165 identifier for ERC-165.
0x7965DB0B, # The ERC-165 identifier for `IAccessControl`.
]
# @dev Returns `True` if `account` has been granted `role`.
hasRole: public(HashMap[bytes32, HashMap[address, bool]])
# @dev Returns the admin role that controls `role`.
getRoleAdmin: public(HashMap[bytes32, bytes32])
@deploy
@payable
def __init__():
"""
@dev To omit the opcodes for checking the `msg.value`
in the creation-time EVM bytecode, the constructor
is declared as `payable`.
@notice The `DEFAULT_ADMIN_ROLE` role will be assigned
to the `msg.sender`.
"""
self._grant_role(DEFAULT_ADMIN_ROLE, msg.sender)
@external
@view
def supportsInterface(interface_id: bytes4) -> bool:
"""
@dev Returns `True` if this contract implements the
interface defined by `interface_id`.
@param interface_id The 4-byte interface identifier.
@return bool The verification whether the contract
implements the interface or not.
"""
return interface_id in _SUPPORTED_INTERFACES
@external
def grantRole(role: bytes32, account: address):
"""
@dev Grants `role` to `account`.
@notice If `account` had not been already
granted `role`, emits a `RoleGranted`
event. Note that the caller must have
`role`'s admin role.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
self._check_role(self.getRoleAdmin[role], msg.sender)
self._grant_role(role, account)
@external
def revokeRole(role: bytes32, account: address):
"""
@dev Revokes `role` from `account`.
@notice If `account` had been granted `role`,
emits a `RoleRevoked` event. Note that
the caller must have `role`'s admin role.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
self._check_role(self.getRoleAdmin[role], msg.sender)
self._revoke_role(role, account)
@external
def renounceRole(role: bytes32, account: address):
"""
@dev Revokes `role` from the calling account.
@notice Roles are often managed via `grantRole`
and `revokeRole`. This function's purpose
is to provide a mechanism for accounts to
lose their privileges if they are compromised
(such as when a trusted device is misplaced).
If the calling account had been granted `role`,
emits a `RoleRevoked` event. Note that the
caller must be `account`.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
assert account == msg.sender, "access_control: can only renounce roles for itself"
self._revoke_role(role, account)
@external
def set_role_admin(role: bytes32, admin_role: bytes32):
"""
@dev Sets `admin_role` as `role`'s admin role.
@notice Note that the caller must have `role`'s
admin role.
@param role The 32-byte role definition.
@param admin_role The new 32-byte admin role definition.
"""
self._check_role(self.getRoleAdmin[role], msg.sender)
self._set_role_admin(role, admin_role)
@internal
@view
def _check_role(role: bytes32, account: address):
"""
@dev Reverts with a standard message if `account`
is missing `role`.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
assert self.hasRole[role][account], "access_control: account is missing role"
@internal
def _set_role_admin(role: bytes32, admin_role: bytes32):
"""
@dev Sets `admin_role` as `role`'s admin role.
@notice This is an `internal` function without
access restriction.
@param role The 32-byte role definition.
@param admin_role The new 32-byte admin role definition.
"""
previous_admin_role: bytes32 = self.getRoleAdmin[role]
self.getRoleAdmin[role] = admin_role
log IAccessControl.RoleAdminChanged(role=role, previousAdminRole=previous_admin_role, newAdminRole=admin_role)
@internal
def _grant_role(role: bytes32, account: address):
"""
@dev Grants `role` to `account`.
@notice This is an `internal` function without
access restriction.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
if not self.hasRole[role][account]:
self.hasRole[role][account] = True
log IAccessControl.RoleGranted(role=role, account=account, sender=msg.sender)
@internal
def _revoke_role(role: bytes32, account: address):
"""
@dev Revokes `role` from `account`.
@notice This is an `internal` function without
access restriction.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
if self.hasRole[role][account]:
self.hasRole[role][account] = False
log IAccessControl.RoleRevoked(role=role, account=account, sender=msg.sender)
.venv/lib/python3.12/site-packages/snekmate/auth/interfaces/IAccessControl.vyi
# pragma version ~=0.4.3
"""
@title `access_control` Interface Definition
@custom:contract-name IAccessControl
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice The interface definition of `access_control`
to support the ERC-165 detection. In order
to ensure consistency and interoperability,
we follow OpenZeppelin's definition here:
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/IAccessControl.sol.
On how to use interfaces in Vyper, please visit:
https://vyper.readthedocs.io/en/latest/interfaces.html#interfaces.
"""
# @dev Emitted when `newAdminRole` is set as
# `role`'s admin role, replacing `previousAdminRole`.
# Note that `DEFAULT_ADMIN_ROLE` is the starting
# admin for all roles, despite `RoleAdminChanged`
# not being emitted signaling this.
event RoleAdminChanged:
role: indexed(bytes32)
previousAdminRole: indexed(bytes32)
newAdminRole: indexed(bytes32)
# @dev Emitted when `account` is granted `role`.
# Note that `sender` is the account (an admin
# role bearer) that originated the contract call.
event RoleGranted:
role: indexed(bytes32)
account: indexed(address)
sender: indexed(address)
# @dev Emitted when `account` is revoked `role`.
# Note that `sender` is the account that originated
# the contract call:
# - if using `revokeRole`, it is the admin role
# bearer,
# - if using `renounceRole`, it is the role bearer
# (i.e. `account`).
event RoleRevoked:
role: indexed(bytes32)
account: indexed(address)
sender: indexed(address)
@external
@view
def hasRole(role: bytes32, account: address) -> bool:
"""
@dev Returns `True` if `account` has been
granted `role`.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
@return bool The verification whether the role
`role` has been granted to `account` or not.
"""
...
@external
@view
def getRoleAdmin(role: bytes32) -> bytes32:
"""
@dev Returns the admin role that controls
`role`.
@notice See `grantRole` and `revokeRole`.
To change a role's admin, use
{access_control-set_role_admin}.
@param role The 32-byte role definition.
@return bytes32 The 32-byte admin role
that controls `role`.
"""
...
@external
def grantRole(role: bytes32, account: address):
"""
@dev Grants `role` to `account`.
@notice If `account` had not been already
granted `role`, emits a `RoleGranted`
event. Note that the caller must have
`role`'s admin role.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
...
@external
def revokeRole(role: bytes32, account: address):
"""
@dev Revokes `role` from `account`.
@notice If `account` had been granted `role`,
emits a `RoleRevoked` event. Note that
the caller must have `role`'s admin role.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
...
@external
def renounceRole(role: bytes32, account: address):
"""
@dev Revokes `role` from the calling account.
@notice Roles are often managed via `grantRole`
and `revokeRole`. This function's purpose
is to provide a mechanism for accounts to
lose their privileges if they are compromised
(such as when a trusted device is misplaced).
If the calling account had been granted `role`,
emits a `RoleRevoked` event. Note that the
caller must be `account`.
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
...
Compiler settingsShow
{
"search_paths": [
".venv/lib/python3.12/site-packages",
"."
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.