Skip to main content

ERC4626DebtToken

Git Source

Inherits: ERC4626, ERC20DebtBase

Functions​

constructor​

constructor(ERC20BaseConfig memory config, address _asset) ERC4626(IERC20(_asset)) ERC20DebtBase(config);

ownerMint​

function ownerMint(
address sender,
address to,
uint256 assets,
uint256 shares
) public virtual override(ERC20Base, IAmmalgamERC20) onlyOwner;

ownerBurn​

function ownerBurn(
address sender,
address onBehalfOf,
uint256 assets,
uint256 shares
) public virtual override(IAmmalgamERC20) onlyOwner;

ammalgamBorrowCallV1​

We use the callback to transfer debt to the caller and transfer borrowed assets to the receiver. This contract never has assets or shares unless they were sent to it by the pair within the context of this function getting called. Calling this function directly will not do anything because there are no assets or shares to transfer.

Shares and assets need testing.

function ammalgamBorrowCallV1(
address sender,
uint256 assetsX,
uint256 assetsY,
uint256 sharesX,
uint256 sharesY,
bytes calldata data
) public virtual;

Parameters

NameTypeDescription
senderaddress
assetsXuint256assets amount of tokenX sent to this contract
assetsYuint256assets amount of tokenY sent to this contract
sharesXuint256shares amount of tokenX sent to this contract
sharesYuint256shares amount of tokenY sent to this contract
databytesencoded data containing the caller and receiver addresses

previewDeposit​

Preview the amount of shares that will be minted for a given amount of assets the user is borrowing, including the initial lending fee.

function previewDeposit(
uint256 assets
) public view override returns (uint256);

Parameters

NameTypeDescription
assetsuint256The amount of assets user is borrowing.

Returns

NameTypeDescription
<none>uint256The amount of shares that will be minted, including the initial lending fee.

previewMint​

Preview the amount of assets required to mint a given amount of shares, including the initial lending fee.

function previewMint(
uint256 shares
) public view override returns (uint256);

Parameters

NameTypeDescription
sharesuint256The amount of shares to mint.

Returns

NameTypeDescription
<none>uint256The amount of assets required to mint the given amount of shares, including the initial lending fee.

_deposit​

ERC4626 facade for IAmmalgamPair-borrow. both deposit and mint calls _deposit This is called when the user is borrowing

function _deposit(address caller, address receiver, uint256 assets, uint256) internal virtual override;

_withdraw​

ERC4626 facade for IAmmalgamPair-repay. both withdraw and redeem calls _withdraw This is called when the user is repaying their debt

function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256
) internal virtual override;

approve​

function approve(address spender, uint256 amount) public override(ERC20, ERC20DebtBase, IERC20) returns (bool);

allowance​

function allowance(
address owner,
address spender
) public view override(ERC20, ERC20DebtBase, IERC20) returns (uint256);

decimals​

function decimals() public view override(ERC20Base, ERC4626, IERC20Metadata) returns (uint8);

totalAssets​

function totalAssets() public view override returns (uint256);

totalSupply​

function totalSupply() public view override(ERC20, IERC20) returns (uint256);

transfer​

function transfer(address recipient, uint256 amount) public override(ERC20, IERC20, ERC20DebtBase) returns (bool);

transferFrom​

function transferFrom(
address sender,
address recipient,
uint256 amount
) public override(ERC20, IERC20, ERC20DebtBase) returns (bool);

_update​

function _update(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Base);

_spendAllowance​

function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual override(ERC20DebtBase, ERC20);

balanceOf​

function balanceOf(
address account
) public view override(ERC20Base, IERC20, ERC20) returns (uint256);

_convertToShares​

function _convertToShares(uint256 assets, Math.Rounding rounding) internal view override returns (uint256);

_convertToAssets​

function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view override returns (uint256);

Errors​

ReceiverIsNotOwner​

for the ERC4626 applied to a debt token, a withdraw reduces debt, thus the receiver of value is the owner. We require these arguments to be equal to ensure the caller understands this design.

error ReceiverIsNotOwner();