Pool
Deployed at: terra1z5j60wct88yz62ylqa4t8p8239cwx9kjlghkg2
config.rs
config.rsStores all relevant contract parameters.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Config {
pub this: CanonicalAddr,
pub owner: CanonicalAddr,
pub beneficiary: CanonicalAddr,
pub moneymarket: CanonicalAddr,
pub atoken: CanonicalAddr,
pub stable_denom: String,
pub dp_token: CanonicalAddr,
}this: the address of this pool contract.
owner: the owner address of this pool contract.
beneficiary: the address of which all interest collected from principal deposits are sent to. could be a single address, or a contract address that oversees additional distribution logic.
moneymarket: the address of the Anchor money market contract to accept deposits.
atoken: the address of the aUST token contract.
stable_denom: base Terra stablecoin denomination of this pool to be deposited to Anchor, i.e. uusd.
dp_token: the address of the DP token contract minted by this pool.
contract.rs
contract.rsDefines logic entry points for InitMsg, HandleMsg and QueryMsg calls.
Initializes a new pool contract. Updates data storage as defined with config.rs, and initializes a new DP token contract linked to this pool contract.
Defines HandleMsg endpoints. Calls the following functions per HandleMsg:
Receive(msg): callsreceive(deps, env, msg)defined underhandler_exec.rs.Deposit {}: callsdeposit(deps, env)defined underhandler_exec.rs.ClaimReward {}: callsclaim_reward(deps, env)defined underhandler_exec.rs.[INTERNAL]
RegisterDPToken {}: callsregister_dp_token(deps, env)defined underhandler_exec.rs.
Defines QueryMsg endpoints. Calls the following functions per QueryMsg:
DepositAmountOf { owner }: callsdeposit_amount(deps, owner)defined underhandler_query.rs; returns the current DP token balance of the sender of this message.TotalDepositAmount {}: callstotal_deposit_amount(deps)defined underhandler_query.rs; returns the total DP token balanced linked to this pool contract.Config {}: callsconfig(deps)defined underhandler/query.rs; returns the following:beneficiary: returns the current beneficiary address set for this pool contract.moneymarket: returns the Anchor money market contract set for this pool contract to call fordeposit_stableandredeem_stablemessages. For further information regarding logic of the Anchor money market, please refer to Anchor Protocol's official documentation.stable_denom: returns the current Terra stablecoin denomination that the underlying Anchor money market contract accepts.anchor_token: returns the aToken contract address that the underlying Anchor money market contract returns on deposits.dp_token: returns the DP token contract address minted by this pool contract on new deposits.
GetClaimableReward {}: callsclaimable_reward(deps)defined underhandler_query.rs; returns all claimable UST rewards for all UST deposits held by this pool.
handler/core.rs
handler/core.rsDefines core contract execution logic. Functions are as follows:
receive: defines a CW-20 token contract receive hook, which is executed when a Pylon DP token is sent to this Pylon pool.deposit: deposits UST to this Pylon pool, deposits them to Anchor, and mints Pylon DP tokens back to the depositor.redeem: consecutively called on a CW-20receivecall. Burns received DP tokens, retrieves equivalent amounts of UST from Anchor, and returns principal UST deposits excluding any interest generated.claim_reward: claims any remaining interest remaining in the pool, and sends them over to the beneficiary address. Interest is calculated as(total_aust_amount * exchange_rate) - (total_dp_balance)register_dp_token: registers a DP token contract controlled by this Pylon deposit pool for new DP token mints/burns on deposits/redemptions.
If a CW-20 transfer to this contract includes a Redeem {} Cw20HookMsg:
checks if the sender of this
HookMsgis the registered DP token address (i.e. not any other token contract address being sent to this pool) - returnunauthorized()error if not, else continueif passed, call
redeem(deps, _env, cw20_msg.sender, cw20_msg.amount)
If a Redeem {} message is not included with this function call, return an invalid_request error.
Sending native Terra stablecoins (UST) with this MsgExecuteContract call:
Check how much deposits have been made to this pool contract for
stable_denom.If there are no deposits, return a
generic_err.
Issue a
HandleResponseissuing the following messages:call
deposit_stablefrom the Anchor money market contract fordeposit_amountunits ofstable_denom(e.g. 100 UST). aUST will be returned from the Anchor money market contract to this pool contract.issue another
MsgExecuteContractcall that mintsdeposit_amountunits of Pylon DP tokens for this particular pool to the caller.
When a Redeem {} Cw20HookMsg is called:
Query the current
epoch_statefrom the Anchor money market.Calculate how much aUST needs to be redeemed back to UST to maintain principle:
dp_token_balance / epoch_state.exchange_rateCalculate how much Terra tax is charged during redemptions. As tax is charged for every Terra stablecoin
MsgSends on the Terra blockchain,deduct_taxshould be called twice, as there are two cases when Terra tax is charged for UST transfers during redemptions:when UST is transferred from the Anchor money market to this Pylon pool contract
when UST is transferred from this Pylon pool contract to the user's wallet
Issue a
HandleResponsecontaining the following messages:burn
amountunits of DP tokens for this Pylon pool.redeem
market_redeem_amountaUST (calculated asdp_token_balance / epoch_state.exchange_rate) forpool_redeem_amountUST.MsgSendspool_redeem_amountback to the caller of this contract
On a ClaimReward {} HandleMsg call:
calculate how much aUST should be redeemed:
(total_aust_amount * exchange_rate) - (total_dp_balance)apply a virtual exchange rate queryable from the Pylon Exchange Rate contract. This effectively re-calculates how much UST should be claimed excluding MINE token buybacks, which is sent to the Collector contract.
calculates how much UST should be redeemed for:
market_redeem_amount: amount of aUST for redemptions before Terra blockchain tax for bothbeneficiaryandcollector. returnsUint256.beneficiary_redeem_amount: amount of aUST for redemptions after Terra blockchain tax forbeneficiary. returns aCoinobject.collector_redeem_amount: amount of aUST for redemptions after Terra blockchain tax forcollector, sent to the Collector contract for buybacks. returns aCoinobject.
Issue a
HandleResponsethat includes the following messages:update virtual exchange rate
redeem
market_redeem_amountaUST from Anchorsend
beneficiary_redeem_amountto beneficiary accountsend
collector_redeem_amountto Collector contract
Last updated
Was this helpful?