Developers
Search…
Minting and Redeeming Junior Tranche tokens (ERC-20)
Please refer to the SmartYield.sol repo for code references made on this page.

Overview

SMART Yield relies on minting and burning ERC-20 tokens to keep track of users' claims on the junior tranche of a given originator.
Upon depositing, the user receives a commensurate number of fungible tokens that reflects the exchange value between one such token and the underlying stablecoin.
1
event BuyTokens(address indexed buyer, uint256 underlyingIn, uint256 tokensOut, uint256 fee);
Copied!
SMART Yield junior tranche tokens all have a common format indicating that they are a BarnBridge product built on top of an existing platform (e.g., bb_cUSDC for USDC deposits into Compound Finance).
Upon redemption, the user burns the ERC-20 tokens in exchange for a proportional subset of the junior tranche, minus a possible redemption fee (i.e., the "forfeits" variable below) depending on what the weighted average maturity date of the senior tranche is.
1
event SellTokens(address indexed seller, uint256 tokensIn, uint256 underlyingOut, uint256 forfeits);
Copied!

How to Mint jTokens

Deposits into the junior tranches of all SMART Yield junior tranches assess a nominal fee on the principal.
1
uint256 fee = MathUtils.fractionOf(underlyingAmount_, IController(controller).FEE_BUY_JUNIOR_TOKEN());
Copied!
The junior tranche deposit fee is currently set to 0.5%, or 50 basis points, of the principal. This fee is then directed to the address set as "feesOwner" in IController.sol. In practice, this is the DAO's treasury address, which also allows for governance votes to adjust the fee size.
With the fee assessed, the appropriate number of jTokens for their deposit sum can be determined.
1
uint256 getsTokens = (underlyingAmount_.sub(fee)).mul(EXP_SCALE).div(price());
Copied!
The primary price of a given jToken is determined by the price() function.
1
function price()
2
public override
3
returns (uint256)
4
{
5
uint256 ts = totalSupply();
6
// (ts == 0) ? EXP_SCALE : (underlyingJuniors() * EXP_SCALE) / ts
7
return (ts == 0) ? EXP_SCALE : underlyingJuniors().mul(EXP_SCALE).div(ts);
8
}
Copied!
Assuming that checks are passed (i.e., the contract is not paused and the getsTokens variable is within range), the user is then able to exchange their stablecoins for jTokens. (See: IProvider.sol)
1
address buyer = msg.sender;
2
​
3
IProvider(pool)._takeUnderlying(buyer, underlyingAmount_);
4
IProvider(pool)._depositProvider(underlyingAmount_, fee);
5
_mint(buyer, getsTokens);
6
​
7
emit BuyTokens(buyer, underlyingAmount_, getsTokens, fee);
Copied!

The forfeits Variable

The junior tranche of any given SMART Yield pool is earning yield in part to cover the fixed yields of the senior tranche. In order to ensure that there remains enough capital in the system to cover what is owed to senior tranche tokens, the forfeits variable keeps track of the obligation for a given subset of the junior tranche.
forfeits is calculated within the sellTokens function upon a user's attempt to redeem their jTokens.
First, the debtShare variable is calculated to determine what percentage of the outstanding junior tranche token supply a potential sale amount represents.
1
uint256 debtShare = tokenAmount_.mul(EXP_SCALE).div(totalSupply());
Copied!
With the user's debt share determined, SMART Yield is then able to assess the proportionally correct value for forfeits which then gets subtracted from the value of the user's jTokens within the toPay variable.
1
uint256 forfeits = abondDebt().mul(debtShare).div(EXP_SCALE);
2
uint256 toPay = tokenAmount_.mul(price()).div(EXP_SCALE).sub(forfeits);
Copied!
The abond variable contains the necessary rate of payment by the junior tranche to the senior tranche at that given point in time; abondDebt() calls the difference between what yield is owed to outstanding senior tranche bonds and how much yield has been generated thus far.

Redeeming jTokens: Instant vs. Two-Step

Users are able to redeem their jTokens in one of two ways: either immediately, and be obligated to pay their respective forfeits sum, or via a slower two-step redemption process.

Instant Redemption

Single-step redemption allows the user to claim their principal and earned yield immediately, but potentially at the expense of forfeiting a portion necessary for covering senior tranche obligations. (See: IProvider.sol)
1
address seller = msg.sender;
2
​
3
_burn(seller, tokenAmount_);
4
IProvider(pool)._withdrawProvider(toPay, 0);
5
IProvider(pool)._sendUnderlying(seller, toPay);
6
​
7
emit SellTokens(seller, tokenAmount_, toPay, forfeits);
Copied!
There is no redemption fee charged on the junior tranche.

Two-Step Redemption

Two-step redemption allows the user to avoid forfeiting capital, but requires them to wait until the weighted average maturity date for the senior tranche at the time of initiating the process. This process involves the exchange of jTokens for a junior tranche ERC-721 bond, akin to the senior tranche token process.
When the user elects to redeem via this method, their maturity date is determined as the day following the aforementioned senior tranche, or ABOND, date.
1
uint256 maturesAt = abond.maturesAt.div(EXP_SCALE).add(1);
Copied!
Upon maturity of the jToken bond, the user is then able to redeem the original sum of jTokens they had by burning the associated ERC-721.
1
address payTo = IBond(juniorBond).ownerOf(jBondId_);
2
​
3
uint256 payAmnt = jBondsAt.price.mul(jb.tokens).div(EXP_SCALE);
4
​
5
_burnJuniorBond(jBondId_);
6
IProvider(pool)._withdrawProvider(payAmnt, 0);
7
IProvider(pool)._sendUnderlying(payTo, payAmnt);
8
underlyingLiquidatedJuniors = underlyingLiquidatedJuniors.sub(payAmnt);
9
​
10
emit RedeemJuniorBond(payTo, jBondId_, payAmnt);
Copied!
Last modified 6mo ago