TellerWithMultiAssetSupport

Git Source

Inherits: Auth, BeforeTransferHook, ReentrancyGuard

State Variables

NATIVE

Native address used to tell the contract to handle native asset deposits.

address internal constant NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

MAX_SHARE_LOCK_PERIOD

The maximum possible share lock period.

uint256 internal constant MAX_SHARE_LOCK_PERIOD = 3 days;

isSupported

Mapping ERC20s to an isSupported bool.

mapping(ERC20 => bool) public isSupported;

depositNonce

The deposit nonce used to map to a deposit hash.

uint96 public depositNonce = 1;

shareLockPeriod

After deposits, shares are locked to the msg.sender's address for shareLockPeriod.

During this time all transfers from msg.sender will revert, and deposits are refundable.

uint64 public shareLockPeriod;

isPaused

Used to pause calls to deposit and depositWithPermit.

bool public isPaused;

publicDepositHistory

Maps deposit nonce to keccak256(address receiver, address depositAsset, uint256 depositAmount, uint256 shareAmount, uint256 timestamp, uint256 shareLockPeriod).

mapping(uint256 => bytes32) public publicDepositHistory;

shareUnlockTime

Maps user address to the time their shares will be unlocked.

mapping(address => uint256) public shareUnlockTime;

vault

The BoringVault this contract is working with.

BoringVault public immutable vault;

accountant

The AccountantWithRateProviders this contract is working with.

AccountantWithRateProviders public immutable accountant;

ONE_SHARE

One share of the BoringVault.

uint256 internal immutable ONE_SHARE;

Functions

constructor

constructor(address _owner, address _vault, address _accountant) Auth(_owner, Authority(address(0)));

pause

Pause this contract, which prevents future calls to deposit and depositWithPermit.

Callable by MULTISIG_ROLE.

function pause() external requiresAuth;

unpause

Unpause this contract, which allows future calls to deposit and depositWithPermit.

Callable by MULTISIG_ROLE.

function unpause() external requiresAuth;

addAsset

Adds this asset as a deposit asset.

The accountant must also support pricing this asset, else the deposit call will revert.

Callable by OWNER_ROLE.

function addAsset(ERC20 asset) external requiresAuth;

removeAsset

Removes this asset as a deposit asset.

Callable by OWNER_ROLE.

function removeAsset(ERC20 asset) external requiresAuth;

setShareLockPeriod

Sets the share lock period.

This not only locks shares to the user address, but also serves as the pending deposit period, where deposits can be reverted.

If a new shorter share lock period is set, users with pending share locks could make a new deposit to receive 1 wei shares, and have their shares unlock sooner than their original deposit allows. This state would allow for the user deposit to be refunded, but only if they have not transferred their shares out of there wallet. This is an accepted limitation, and should be known when decreasing the share lock period.

Callable by OWNER_ROLE.

function setShareLockPeriod(uint64 _shareLockPeriod) external requiresAuth;

beforeTransfer

Implement beforeTransfer hook to check if shares are locked.

function beforeTransfer(address from) public view;

refundDeposit

Allows DEPOSIT_REFUNDER_ROLE to revert a pending deposit.

Once a deposit share lock period has passed, it can no longer be reverted.

It is possible the admin does not setup the BoringVault to call the transfer hook, but this contract can still be saving share lock state. In the event this happens deposits are still refundable if the user has not transferred their shares. But there is no guarantee that the user has not transferred their shares.

Callable by STRATEGIST_MULTISIG_ROLE.

function refundDeposit(
    uint256 nonce,
    address receiver,
    address depositAsset,
    uint256 depositAmount,
    uint256 shareAmount,
    uint256 depositTimestamp,
    uint256 shareLockUpPeriodAtTimeOfDeposit
)
    external
    requiresAuth;

deposit

Allows users to deposit into the BoringVault, if this contract is not paused.

Publicly callable.

function deposit(
    ERC20 depositAsset,
    uint256 depositAmount,
    uint256 minimumMint
)
    external
    requiresAuth
    nonReentrant
    returns (uint256 shares);

depositWithPermit

Allows users to deposit into BoringVault using permit.

Publicly callable.

function depositWithPermit(
    ERC20 depositAsset,
    uint256 depositAmount,
    uint256 minimumMint,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
)
    external
    requiresAuth
    nonReentrant
    returns (uint256 shares);

bulkDeposit

Allows on ramp role to deposit into this contract.

Does NOT support native deposits.

Callable by SOLVER_ROLE.

function bulkDeposit(
    ERC20 depositAsset,
    uint256 depositAmount,
    uint256 minimumMint,
    address to
)
    external
    requiresAuth
    nonReentrant
    returns (uint256 shares);

bulkWithdraw

Allows off ramp role to withdraw from this contract.

Callable by SOLVER_ROLE.

function bulkWithdraw(
    ERC20 withdrawAsset,
    uint256 shareAmount,
    uint256 minimumAssets,
    address to
)
    external
    requiresAuth
    returns (uint256 assetsOut);

_erc20Deposit

Implements a common ERC20 deposit into BoringVault.

function _erc20Deposit(
    ERC20 depositAsset,
    uint256 depositAmount,
    uint256 minimumMint,
    address to
)
    internal
    returns (uint256 shares);

_afterPublicDeposit

Handle share lock logic, and event.

function _afterPublicDeposit(
    address user,
    ERC20 depositAsset,
    uint256 depositAmount,
    uint256 shares,
    uint256 currentShareLockPeriod
)
    internal;

Events

Paused

event Paused();

Unpaused

event Unpaused();

AssetAdded

event AssetAdded(address indexed asset);

AssetRemoved

event AssetRemoved(address indexed asset);

Deposit

event Deposit(
    uint256 indexed nonce,
    address indexed receiver,
    address indexed depositAsset,
    uint256 depositAmount,
    uint256 shareAmount,
    uint256 depositTimestamp,
    uint256 shareLockPeriodAtTimeOfDeposit
);

BulkDeposit

event BulkDeposit(address indexed asset, uint256 depositAmount);

BulkWithdraw

event BulkWithdraw(address indexed asset, uint256 shareAmount);

DepositRefunded

event DepositRefunded(uint256 indexed nonce, bytes32 depositHash, address indexed user);

Errors

TellerWithMultiAssetSupport__ShareLockPeriodTooLong

error TellerWithMultiAssetSupport__ShareLockPeriodTooLong();

TellerWithMultiAssetSupport__SharesAreLocked

error TellerWithMultiAssetSupport__SharesAreLocked();

TellerWithMultiAssetSupport__SharesAreUnLocked

error TellerWithMultiAssetSupport__SharesAreUnLocked();

TellerWithMultiAssetSupport__BadDepositHash

error TellerWithMultiAssetSupport__BadDepositHash();

TellerWithMultiAssetSupport__AssetNotSupported

error TellerWithMultiAssetSupport__AssetNotSupported();

TellerWithMultiAssetSupport__ZeroAssets

error TellerWithMultiAssetSupport__ZeroAssets();

TellerWithMultiAssetSupport__MinimumMintNotMet

error TellerWithMultiAssetSupport__MinimumMintNotMet();

TellerWithMultiAssetSupport__MinimumAssetsNotMet

error TellerWithMultiAssetSupport__MinimumAssetsNotMet();

TellerWithMultiAssetSupport__PermitFailedAndAllowanceTooLow

error TellerWithMultiAssetSupport__PermitFailedAndAllowanceTooLow();

TellerWithMultiAssetSupport__ZeroShares

error TellerWithMultiAssetSupport__ZeroShares();

TellerWithMultiAssetSupport__Paused

error TellerWithMultiAssetSupport__Paused();