# TenderSwap Definitions
### Operations
- Deposit
- Withdraw
- WithdrawOther
- Swap
### Deposit
For input amount $a$ and and subpool index $i$
1. update assets $safe\_add(\sigma,sigma^{1,i},a)$
2. Update liabilities with amount $safe\_add(\sigma,sigma^{2,i},a)$
### Withdraw
If we consider the input negative, we can use the same definition as we used for deposit.
For input $a$
1. update assets $safe\_add(\sigma,sigma^{1,i},a)$
2. Update liabilities with amount $safe\_add(\sigma,sigma^{2,i},a)$
So both withdraw and deposit can be defined as the following function:
$update: \Sigma \times \mathbb{N} \times \mathbb{R} \rightarrow \Sigma, \\update(\sigma, i, v) = safe\_add(safe\_add(\sigma,sigma^{1,i},v),sigma^{2,i},v))$
### WithdrawOther
Similarly withdrawOther can be described with update, but given a function $S:\Sigma \times \mathbb{N} \times \mathbb{R}^+ \rightarrow \mathbb{R}^+$
$v'=S(\sigma,i, v)$
where $v'$ is the slippage adjusted amount,
1. let $input':=S(\sigma, i, input)$
2. $update(\sigma, i, input')$
So we can define
$withdraw\_other:\Sigma \times \mathbb{N} \times \mathbb{R}^+ \rightarrow \Sigma$
$withdraw\_other(\sigma,i,v)=update(\sigma,i,-S(\sigma,i,v))$
### Swap (helper)
$swap: \Sigma \times \mathbb{N} \times \mathbb{N} \times \mathbb{R}^+ \times \mathbb{R}^+ \rightarrow \Sigma$
$swap(\sigma, i, j, v, w) = update(update(\sigma,i,v), j, -w)$
where $i$ is the from and $j$ is the to indices of the subpools, and $v$ is the in amount and $w$ is the out amount.
### SwapWithSlippage
$swap\_with\_slippage: \Sigma \times \mathbb{N} \times \mathbb{N} \times \mathbb{R}^+ \times \mathbb{R}^+ \rightarrow \Sigma$
$swap\_with\_slippage(\sigma,i,j,v,w)=swap(\sigma,i,j,v,slippage(\sigma,i,j,v,w))$
## Helpers
### DeptRatio
Not used at the moment but will be needed when defining the slippage function.
$debt\_ratio: \Sigma \times \mathbb{N} \rightarrow \mathbb{R}^+$
$L_i = mat\_fet(\sigma, 2, i)$
$A_i = mat\_fet(\sigma, 1, i)$
$d_i=debt\_ratio(\sigma, i)=\frac{L_i}{A_i}$
### Slippage Function
The slippage function determines how much the assets in the **to** pool decrease (in practice that would mean how much the balance of the user incrase as well), based on the debt ratios of pool $i$ and $j$.
$slippage: \Sigma \times \mathbb{N} \times \mathbb{N} \times \mathbb{R}^+ \times \mathbb{R}^+ \rightarrow \mathbb{R^+}$
$slippage(\sigma,i,j,v,w)$