Ethereum Wrapper Contract
Anchor's Ethereum wrapper contract is a client-specifically generated smart contract on the Ethereum blockchain to handle wrapped UST deposits to Anchor Protocol. Both depositing wrapped UST and redeeming wrapped aUST is processed with an init - finish architecture. It is important to note that additional processing time (separate from time required for Ethereum tx confirmation) is needed in order for init requests, until which finish requests will result in failure.
Additionally, wrapper contracts can only process requests in series, allowing an additional request to be made only after the finish operation for the previous request was successfully executed.
Anchor Ethereum wrapper contracts have two execution modes: standard and custodied. Standard mode functions return aUST back to msg.sender, in which they can be potentially utilized with other Ethereum DeFi applications. Custodied mode functions do not return aUST back to msg.sender, but only holds aUST under the contract account. As there can be only one custody contract per authorized account, redeeming custodied aUST back to UST can be done at any time as long as the sender is authorized.
Events
InitDeposit
InitDepositEmitted when wrapped UST is requested for deposit to Anchor via initDepositStable.
event InitDeposit(address indexed sender, uint256 amount, bytes32 to);FinishDeposit
FinishDepositEmitted when wrapped aUST is claimed from Anchor via finishDepositStable.
event FinishDeposit(address indexed sender);InitRedeem
InitRedeemEmitted when wrapped aUST is requested for redemption to Anchor via initRedeemStable.
event InitRedeem(address indexed sender, uint256 amount, bytes32 to);FinishRedeem
FinishRedeemEmitted when wrapped UST is claimed from Anchor via finishRedeemStable.
EmergencyWithdrawActivated
EmergencyWithdrawActivatedEmitted when emergencyWithdraw is activated for withdrawing ERC-20 tokens from the contract.
Functions
initDepositStable
initDepositStableAccepts new wrapped UST deposits.
Prerequisite: must have called approve() for an allowance of at least amount for the wrapped UST contract, ActionFlag is set to false
Accepts: amount - how much UST to deposit
Updates: ActionFlag to true
Emits: InitDeposit
finishDepositStable
finishDepositStableClaims resulting wrapped aUST after deposit.
Prerequisite: aUST balance of account-specific endpoint contract must be greater than 0, ActionFlag is set to true
Updates: sets ActionFlag to false, transfers all aUST balances from contract address to tx.origin
Emits: FinishDeposit
Prerequisite: aUST balance of account-specific endpoint contract must be greater than 0, ActionFlag is set to true
Updates: sets ActionFlag to false
Emits: FinishDeposit
Prerequisite: aUST balance of account-specific endpoint contract must be greater than 0, ActionFlag is set to true
Checks: _isCustodyEnabled. If this value is set to true, delegatecalls finishDepositStableCustody. Otherwise, delegatecalls finishDepositStable.
Emits: FinishDeposit
initRedeemStable
initRedeemStableAccepts wrapped aUST for redemption back to wrapped UST.
Prerequisite: must have called approve() for an allowance of at least amount for the wrapped aUST contract, ActionFlag is set to false
Accepts: amount - how much aUST to redeem back to UST
Updates: ActionFlag to trueIMPORTANT: aUST redemptions may fail if UST buffer is low on the Terra side Anchor money market → be sure to check account contract balances & initRedeemStable() success parameters.
Emits: InitRedemption
Prerequisite: ActionFlag is set to false
Accepts: amount - how much aUST to redeem back to UST. If this value is set to 0, all balances held within the contract are redeemed back to UST. Otherwise, amount aUST held under the contract account is redeemed back to UST (assuming that contract aUST balances is equal to or larger than amount).
Updates: ActionFlag to trueIMPORTANT: aUST redemptions may fail if UST buffer is low on the Terra side Anchor money market → be sure to check account contract balances & initRedeemStable() success parameters.
Emits: InitRedemption
Prerequisite: ActionFlag is set to false
Accepts: amount - how much aUST to redeem back to UST. If this value is set to 0, all balances held within the contract; _isCustodyEnabled - an indicator to which mode amount should be passed as a parameter to.
Checks: _isCustodyEnabled. If this value is set to true, delegatecalls initRedeemStableCustody. Otherwise, delegatecalls initRedeemStable.
Emits: InitRedemption
finishRedeemStable
finishRedeemStableClaims resulting wrapped UST after withdrawal.
Prerequisite: UST balance of account-specific endpoint contract must be greater than 0, ActionFlag is set to true
Updates: sets ActionFlag to false, transfers all UST balances from contract address to tx.origin
Emits: FinishRedemption
reportFailure
reportFailureReports any failures in-between init operations to allow the AnchorEth bot to return any funds, and reset ActionFlag back to false. Only callable by contract owner.
Prerequisite: UST balance of account-specific endpoint contract must be 0, ActionFlag is set to true
Updates: sets RedemptionFlag to false
emergencyWithdraw
emergencyWithdrawWithdraws all balances of any ERC-20 token from the contract address. Only callable by contract owner.
Prerequisite: ERC-20 token balances of token contract _tokenAddress at contract address must be greater than 0
Updates: transfers all ERC-20 token balances of token contract _tokenAddress back to msg.sender
Last updated
Was this helpful?