---
# System prepended metadata

title: Reward calculation

---

# Reward APR Calculation Logic
## Transactional Calculation

### Lend

1. Reward per second short:
$$ \text{Reward per second}_{\text{short}} = \frac{\text{reward per second in \$}}{\text{total short at that given time}} $$

2. Updated reward per second short:
$$ \text{Updated Reward per second}_{\text{short}} = \frac{\text{reward per second in \$}}{\text{total short at that given time} + \text{expected short}} $$

3. Reward APR:
$$ \text{reward apr}_{\text{short}} = \frac{\text{Updated Reward per second}_{\text{short}} \times \text{short} \times 31556926}{\text{total token amount user is lending in \$}} $$

### Borrow

#### Case Long 0

1. Reward per second long 0:
$$ \text{Reward per second}_{\text{long}0} = \frac{\text{reward per second in \$}}{\text{total long 0 at that given time}} $$

2. Updated reward per second long 0:
$$ \text{Updated Reward per second}_{\text{long}0} = \frac{\text{reward per second in \$}}{\text{total long 0 at that given time} + \text{expected long 0}} $$

3. Reward APR:
$$ \text{reward apr}_{\text{long}0} = \frac{\text{Updated Reward per second}_{\text{long}0} \times \text{expected long}0 \times 31556926}{\text{total token amount user is borrowing in \$}} $$

#### Case Long 1

1. Reward per second long 1:
$$ \text{Reward per second}_{\text{long}1} = \frac{\text{reward per second in \$}}{\text{total long 1 at that given time}} $$

2. Updated reward per second long 1:
$$ \text{Updated Reward per second}_{\text{expected long}1} = \frac{\text{reward per second in \$}}{\text{total long 1 at that given time} + \text{expected long 1}} $$

3. Reward APR:
$$ \text{reward apr}_{\text{long}1} = \frac{\text{Updated Reward per second}_{\text{long}1} \times \text{long}1 \times 31556926}{\text{total token amount user is borrowing in \$}} $$

### Liquidity

1. Reward per second liquidity:
$$ \text{Reward per second}_{\text{liquidity}} = \frac{\text{reward per second in \$}}{\text{total liquidity at that given time}} $$

2. Updated reward per second liquidity:
$$ \text{Updated Reward per second}_{\text{liquidity}} = \frac{\text{reward per second in \$}}{\text{total liquidity at that given time} + \text{expected liquidity}} $$

3. Reward APR:
$$ \text{reward apr}_{\text{liquidity}} = \frac{\text{Updated Reward per second}_{\text{liquidity}} \times \text{expected liquidity amount} \times 31556926}{\text{total token amount user is providing as liquidity in \$}} $$




Comments

total_reward_amount * remaining_duration / (duration * (duration + 1) / 2)

$$ \text{total_reward_amount} = \frac{(\text{duration})(\text{largest_reward_per_second})}{2} $$
$$ \frac{\text{largest_reward_per_second}}{\text{duration}} = \frac{\text{reward_per_second}}{\text{remaining_duration}} $$


$$ \text{total_reward_amount} = \frac{(\text{duration})(\text{reward_per_second})(\text{duration})}{2(\text{remaining_duration})} $$

$$ \text{reward_per_second}=\frac{2(\text{total_reward_amount})(\text{remaining_duration})}{(\text{duration})^2} $$


# MARGINAL REWARD APR

# Lending

$$ \text{solidity_sqrt_interest_rate} = \sqrt{\frac{z}{x+y}} $$

$$ \text{reward_per_second_short} = \frac{\text{reward_per_second}}{\text{short_in_reward}} $$

## Case 1 $\text{solidity_strike} >= 2^{128}$

### Case 1.1 User lends x' token0 (disregard when reward parameter isToken0 is false)

token0 $x'=x$

short per token0 $\frac{x+zd}{x}$

$$ \frac{zd}{x} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_short})(\text{short_per_token0})(\text{year})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{short_in_reward}})(\frac{x+zd}{x})(\text{year})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)(\text{year})}{(\text{token0_dollar_spot_price_per_smallest_unit})(\text{short_in_reward})(2^{288})} $$

### Case 1.2 User lends y' token1 (disregard when reward parameter isToken0 is true)

token1 $\frac{y'(2^{128})}{\text{solidity_strike}}=y$

short per token1 $\frac{y+zd}{y'}=\frac{(y+zd)(2^{128})}{y(\text{solidity_strike})}$

$$ \frac{zd}{y} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_short})(\text{short_per_token1})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{short_in_reward}})(\frac{(y+zd)(2^{128})}{y(\text{solidity_strike})})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)}{(\text{token1_dollar_spot_price_per_smallest_unit})(\text{short_in_reward})(\text{solidity_strike})(2^{160})}$$


## Case 2 $\text{solidity_strike} < 2^{128}$

### Case 2.1 User lends x' token0 (disregard when reward parameter isToken0 is false)

token0 $\frac{x'(\text{solidity_strike})}{2^{128}}=x$

short per token0 $\frac{x+zd}{x'}=\frac{(x+zd)(\text{solidity_strike})}{x(2^{128})}$

$$ \frac{zd}{x} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_short})(\text{short_per_token0})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)(\text{solidity_strike})}{(\text{token0_dollar_spot_price_per_smallest_unit})(\text{short_in_reward})(2^{416})}$$

### Case 2.2 User lends y' token1 (disregard when reward parameter isToken0 is true)

token1 $y'=y$

short per token1 $\frac{y+zd}{y}$

$$ \frac{zd}{y} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_short})(\text{short_per_token1})(\text{year})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{short_in_reward}})(\frac{y+zd}{y})(\text{year})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)(\text{year})}{(\text{token1_dollar_spot_price_per_smallest_unit})(\text{short_in_reward})(2^{288})}$$

### Reverse

$$ \text{short_in_reward} = \frac{(\text{reward_per_second})(1+d(\text{sqrt_interest_rate})^2)(\text{year})}{(\text{token1_dollar_spot_price_per_smallest_unit})(\text{reward_apr})(2^{288})}$$


# Borrowing

$$ \text{solidity_sqrt_interest_rate} = \sqrt{\frac{z}{x+y}} $$

if isLong0 is true
$$ \text{reward_per_second_long0} = \frac{\text{reward_per_second}}{\text{long0}} $$

if isLong0 is false
$$ \text{reward_per_second_long1} = \frac{\text{reward_per_second}}{\text{long1}} $$

when reward parameter isToken0 is true, then isLong0 is false.
when reward parameter isToken0 is false, then isLong0 is true.

## Case 1 $\text{solidity_strike} >= 2^{128}$

### Case 1.1 isToken0 is true and isLong0 is false. Borrower borrows x' token0 (Disregard if reward parameter isToken0 is false)

token0 $x'=x$

long1 per token0 $\frac{(x+zd)(\text{solidity_strike})}{x(2^{128})}$

$$ \frac{zd}{x} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_long1})(\text{long1_per_token0})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$


$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{long1_in_reward}})(\frac{(x+zd)(\text{solidity_strike})}{x(2^{128})})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)(\text{solidity_strike})}{(\text{token0_dollar_spot_price_per_smallest_unit})(\text{long1_in_reward})(2^{416})} $$

### Case 1.2 isToken0 is false and isLong0 is true. Borrower borrows y' token1 (Disregard if reward parameter isToken0 is true)

token1 $\frac{y'(2^{128})}{\text{solidity_strike}}=y$

long0 per token1 $\frac{(y+zd)}{y'}=\frac{(y+zd)(2^{128})}{y(\text{solidity_strike})}$

$$ \frac{zd}{y} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_long0})(\text{long0_per_token1})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{long0_in_reward}})(\frac{(y+zd)(2^{128})}{y(\text{solidity_strike})})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)}{(\text{token1_dollar_spot_price_per_smallest_unit})(\text{long0_in_reward})(\text{solidity_strike})(2^{160})}$$

## Case 2 $\text{solidity_strike} < 2^{128}$

### Case 2.1 isToken0 is true and isLong0 is false. Borrower borrows x' token0 (Disregard if reward parameter isToken0 is false)

token0 $\frac{x'(\text{solidity_strike})}{2^{128}}=x$

long1 per token0 $\frac{(x+zd)}{x'}=\frac{(x+zd)(\text{solidity_strike})}{x(2^{128})}$

$$ \frac{zd}{x} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_long1})(\text{long1_per_token0})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)(\text{solidity_strike})}{(\text{token0_dollar_spot_price_per_smallest_unit})(\text{long1_in_reward})(2^{416})}$$

### Case 2.2 isToken0 is false and isLong0 is true. Borrower borrows y' token1 (Disregard if reward parameter isToken0 is true)

token1 $y'=y$ (token1)

long1 per token1 = $\frac{y+zd}{y}$ (long1/token1)


long0 per token1 $\frac{(y+zd)(2^{128})}{y(\text{solidity_strike})}$ (long0/token1)

$$ \frac{zd}{y} = \frac{d(\text{sqrt_interest_rate})^2}{2^{288}}$$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_long0})(\text{long0_per_token1})(\text{year})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{long0_in_reward}})(\frac{(y+zd)(2^{128})}{y(\text{solidity_strike})})(\text{year})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(2^{288}+d(\text{sqrt_interest_rate})^2)(\text{year})}{(\text{token1_dollar_spot_price_per_smallest_unit})(\text{long0_in_reward})(\text{solidity_strike})(2^{160})}$$

y=100 USDC
zd = 10 USDC
y+zd = 110 USDC
(y+zd) / y = 1.1
0.6 USDC/ARB
1.833 ARB/USDC long0 per token1

spot price $ / USDC

reward per second long0 $ / (second * ARB)

year second

($ / (second * ARB))*(ARB/USDC)*second*(USDC/$)




## Assumptions
- Base all calculations on debt and not principals
- Lenders looked okay even though we used the short position
- Borrow reward apr is off by the cdp factor

borrow $\Delta y$
long0 received is $\frac{(\Delta y+d\Delta z)(2^{128})}{\text{solidity_strike}}$
$$\text{new_reward_per_second_long0} = \frac{\text{reward_per_second}(year)}{\text{long0_in_reward} + \frac{(\Delta y+d\Delta z)(2^{128})}{\text{solidity_strike}}} $$

$$ \text{transaction_reward_APR} = \frac{\text{new_reward_per_second_long0}(\frac{(\Delta y+d\Delta z)(2^{128})}{\text{solidity_strike}})(year)}{\Delta y} $$


# Add Liquidity

## Case 1 $\text{solidity_strike}>=2^{128}$

$$ \text{solidity_sqrt_interest_rate} = \sqrt{\frac{z}{x+y}} $$

$$ \text{solidity_liquidity} = L = \sqrt{(z)(x+y)} $$

### Case 1.1 LP adds token0 (disregard if reward parameter isToken0 is false)

token0 $x'=x$

liquidity per token0 $\frac{L}{x}$

$$ \frac{L}{x}=\frac{\text{solidity_sqrt_interest_rate}}{2^{96}} $$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_liquidity})(\text{liquidity_per_token0})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{liquidity_in_reward}})(\frac{L}{x})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(\text{sqrt_interest_rate})}{(\text{token0_dollar_spot_price_per_smallest_unit})(\text{liquidity_in_reward})(2^{96})} $$

### Case 1.2 LP adds token1 (disregard if reward parameter isToken0 is true)

token1 $\frac{y'(2^{128})}{\text{solidity_strike}}=y$

liquidity per token1 $\frac{L}{y'}=\frac{L(2^{128})}{y(\text{solidity_strike})}$

$$ \frac{L}{y}=\frac{\text{solidity_sqrt_interest_rate}}{2^{96}} $$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_liquidity})(\text{liquidity_per_token1})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\frac{\text{reward_per_second}}{\text{liquidity_in_reward}})(\frac{L(2^{128})}{y(\text{solidity_strike})})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(\text{sqrt_interest_rate})(2^{32})}{(\text{token1_dollar_spot_price_per_smallest_unit})(\text{liquidity_in_reward})(\text{solidity_strike})} $$

## Case 2 $\text{solidity_strike} < 2^{128}$

### Case 2.1 LP adds token0 (disregard if reward parameter isToken0 is false)

token0 $\frac{x'(\text{solidity_strike})}{2^{128}}=x$

liquidity per token0 $\frac{L}{x'}=\frac{L(\text{solidity_strike})}{x(2^{128})}$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_liquidity})(\text{liquidity_per_token0})}{\text{token0_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(\text{sqrt_interest_rate})(\text{solidity_strike})}{(\text{token0_dollar_spot_price_per_smallest_unit})(\text{liquidity_in_reward})(2^{224})} $$


### Case 2.2 LP adds token1 (disregard if reward parameter isToken0 is true)

token1 $y'=y$

liquidity per token1 $\frac{L}{y}$

$$ \text{reward_apr}= \frac{(\text{reward_per_second_liquidity})(\text{liquidity_per_token1})(\text{year})}{\text{token1_dollar_spot_price_per_smallest_unit}}$$

$$ \text{reward_apr} = \frac{(\text{reward_per_second})(\text{sqrt_interest_rate})(\text{year})}{(\text{token1_dollar_spot_price_per_smallest_unit})(\text{liquidity_in_reward})(2^{96})} $$


# Alternative

## Lend

Given Short tokens to token0 return


$$ \text{token0_return} = \frac{short}{K \geq 1 ? 1 : K} $$


$$ \text{reward_APR} = \text{reward_per_second_short} \times \text{year} \times \frac{short}{\text{token0_return}(\text{token0_spot})}$$

$$ \text{reward_APR} = \frac{\text{reward_per_second_short} \times \text{year} \times (K \geq 1 ? 1 : K)}{\text{token0_spot}}$$


Given Short tokens to token1 return

$$ \text{token1_return} = \text{short} \times (K \geq 1 ? K : 1)$$

$$ \text{reward_APR} = \text{reward_per_second_short} \times \text{year} \times \frac{short}{\text{token1_return}(\text{token1_spot})}$$

$$ \text{reward_APR} = \frac{\text{reward_per_second_short} \times \text{year}}{(K \geq 1 ? 1 : K)(\text{token1_spot})}$$


## Borrow

Given Long1 to token0

$$\text{token0_debt}= \frac{\text{long1}}{K}$$

$$ \text{reward_APR} = \text{reward_per_second_long1} \times \text{year} \times \frac{long1}{\text{token0_debt}(\text{token0_spot})} $$

$$ \text{reward_APR} = \frac{\text{reward_per_second_long1} \times \text{year} \times K}{\text{token0_spot}}$$


Given Long0 to token1

$$\text{token1_debt} = \text{long0} \times K$$

$$ \text{reward_APR} = \text{reward_per_second_long0} \times \text{year} \times \frac{long0}{\text{token1_debt}(\text{token1_spot})}$$

$$ \text{reward_APR} = \frac{\text{reward_per_second_long0} \times \text{year}}{\text{token0_spot}(K)}$$

Illustrative example
- Reward per year is 100 USD
- Alice borrows 500 USD has a position 500 Long ARB
- Bob borrows 500 USD has a position of 1000 Long ARB
- Alice will get 25 USD per year => APR of 5%
- Bob will get 75 USD per year => APR of 15%
- Assuming interest of 10%
- From the formula above we get the Marginal APR to be 9.1%
