TenderSwap
TenderSwap is a light-weight StableSwap implementation for two assets. See the Curve StableSwap paper for more details (https://curve.fi/files/stableswap-paper.pdf). that trade 1:1 with eachother (e.g. USD stablecoins or tenderToken derivatives vs their underlying assets). It supports Elastic Supply ERC20 tokens, which are tokens of which the balances can change as the total supply of the token 'rebases'.

Functions:

Events:

Functions

initialize

function initialize(
contract IERC20 _token0,
contract IERC20 _token1,
string lpTokenName,
string lpTokenSymbol,
uint256 _a,
uint256 _fee,
uint256 _adminFee,
contract LiquidityPoolToken lpTokenTargetAddress
) external returns (bool success)
Initializes this Swap contract with the given parameters. This will also clone a LPToken contract that represents users' LP positions. The owner of LPToken will be this contract - which means only this contract is allowed to mint/burn tokens.
Parameters:
Name
Type
Description
_token0
contract IERC20
First token in the pool
_token1
contract IERC20
Second token in the pool
lpTokenName
string
the long-form name of the token to be deployed
lpTokenSymbol
string
the short symbol for the token to be deployed
_a
uint256
the amplification coefficient * n * (n - 1). See the StableSwap paper for details
_fee
uint256
default swap fee to be initialized with
_adminFee
uint256
default adminFee to be initialized with
lpTokenTargetAddress
contract LiquidityPoolToken
the address of an existing LiquidityPoolToken contract to use as a target
Return Values:
Name
Type
Description
success
bool
true is successfully initialized

lpToken

function lpToken() external returns (contract LiquidityPoolToken lpTokenContract)
Returns the liquidity pool token contract.
Return Values:
Name
Type
Description
lpTokenContract
contract LiquidityPoolToken
Liquidity pool token contract.

getA

function getA() external returns (uint256 a)
Return A, the amplification coefficient * n * (n - 1)
Note: See the StableSwap paper for details
Return Values:
Name
Type
Description
a
uint256
the amplifaction coefficient

getAPrecise

function getAPrecise() external returns (uint256 aPrecise)
Return A in its raw precision form
Note: See the StableSwap paper for details
Return Values:
Name
Type
Description
aPrecise
uint256
A parameter in its raw precision form

getToken0

function getToken0() external returns (contract IERC20 token0)
Returns the contract address for token0
Note: EVM return type is IERC20
Return Values:
Name
Type
Description
token0
contract IERC20
contract address

getToken1

function getToken1() external returns (contract IERC20 token1)
Returns the contract address for token1
Note: EVM return type is IERC20
Return Values:
Name
Type
Description
token1
contract IERC20
contract address

getToken0Balance

function getToken0Balance() external returns (uint256 token0Balance)
Return current balance of token0 (tender) in the pool
Return Values:
Name
Type
Description
token0Balance
uint256
current balance of the pooled tendertoken

getToken1Balance

function getToken1Balance() external returns (uint256 token1Balance)
Return current balance of token1 (underlying) in the pool
Return Values:
Name
Type
Description
token1Balance
uint256
current balance of the pooled underlying token

getVirtualPrice

function getVirtualPrice() external returns (uint256 virtualPrice)
Get the override price, to help calculate profit
Return Values:
Name
Type
Description
virtualPrice
uint256
the override price, scaled to the POOL_PRECISION_DECIMALS

calculateSwap

function calculateSwap(
contract IERC20 _tokenFrom,
uint256 _dx
) external returns (uint256 tokensToReceive)
Calculate amount of tokens you receive on swap
Parameters:
Name
Type
Description
_tokenFrom
contract IERC20
the token the user wants to sell
_dx
uint256
the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee.
Return Values:
Name
Type
Description
tokensToReceive
uint256
amount of tokens the user will receive

calculateRemoveLiquidity

function calculateRemoveLiquidity(
uint256 amount
) external returns (uint256[2] tokensToReceive)
A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens
Parameters:
Name
Type
Description
amount
uint256
the amount of LP tokens that would be burned on withdrawal
Return Values:
Name
Type
Description
tokensToReceive
uint256[2]
array of token balances that the user will receive

calculateRemoveLiquidityOneToken

function calculateRemoveLiquidityOneToken(
uint256 tokenAmount,
contract IERC20 tokenReceive
) external returns (uint256 tokensToReceive)
Calculate the amount of underlying token available to withdraw when withdrawing via only single token
Parameters:
Name
Type
Description
tokenAmount
uint256
the amount of LP token to burn
tokenReceive
contract IERC20
the token to receive
Return Values:
Name
Type
Description
tokensToReceive
uint256
calculated amount of underlying token to be received. available to withdraw

calculateTokenAmount

function calculateTokenAmount(
uint256[] amounts,
bool deposit
) external returns (uint256 tokensToReceive)
A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running
Note: This shouldn't be used outside frontends for user estimates.
Parameters:
Name
Type
Description
amounts
uint256[]
an array of token amounts to deposit or withdrawal, corresponding to pool cardinality of [token0, token1]. The amount should be in each pooled token's native precision.
deposit
bool
whether this is a deposit or a withdrawal
Return Values:
Name
Type
Description
tokensToReceive
uint256
token amount the user will receive

swap

function swap(
contract IERC20 _tokenFrom,
uint256 _dx,
uint256 _minDy,
uint256 _deadline
) external returns (uint256 _dy)
Swap two tokens using this pool
Note: revert is token being sold is not in the pool.
Parameters:
Name
Type
Description
_tokenFrom
contract IERC20
the token the user wants to sell
_dx
uint256
the amount of tokens the user wants to swap from
_minDy
uint256
the min amount the user would like to receive, or revert
_deadline
uint256
latest timestamp to accept this transaction
Return Values:
Name
Type
Description
_dy
uint256
amount of tokens received

addLiquidity

function addLiquidity(
uint256[2] _amounts,
uint256 _minToMint,
uint256 _deadline
) external returns (uint256 lpMinted)
Add liquidity to the pool with the given amounts of tokens
Parameters:
Name
Type
Description
_amounts
uint256[2]
the amounts of each token to add, in their native precision according to the cardinality of the pool [token0, token1]
_minToMint
uint256
the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation
_deadline
uint256
latest timestamp to accept this transaction
Return Values:
Name
Type
Description
lpMinted
uint256
amount of LP token user minted and received

removeLiquidity

function removeLiquidity(
uint256 amount,
uint256[2] minAmounts,
uint256 deadline
) external returns (uint256[2] tokensReceived)
Burn LP tokens to remove liquidity from the pool.
Note: Liquidity can always be removed, even when the pool is paused.
Parameters:
Name
Type
Description
amount
uint256
the amount of LP tokens to burn
minAmounts
uint256[2]
the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation according to the cardinality of the pool [token0, token1]
deadline
uint256
latest timestamp to accept this transaction
Return Values:
Name
Type
Description
tokensReceived
uint256[2]
is the amounts of tokens user received

removeLiquidityOneToken

function removeLiquidityOneToken(
uint256 _tokenAmount,
contract IERC20 _tokenReceive,
uint256 _minAmount,
uint256 _deadline
) external returns (uint256 tokensReceived)
Remove liquidity from the pool all in one token.
Parameters:
Name
Type
Description
_tokenAmount
uint256
the amount of the token you want to receive
_tokenReceive
contract IERC20
the token you want to receive
_minAmount
uint256
the minimum amount to withdraw, otherwise revert
_deadline
uint256
latest timestamp to accept this transaction
Return Values:
Name
Type
Description
tokensReceived
uint256
amount of chosen token user received

removeLiquidityImbalance

function removeLiquidityImbalance(
uint256[2] _amounts,
uint256 _maxBurnAmount,
uint256 _deadline
) external returns (uint256 lpBurned)
Remove liquidity from the pool, weighted differently than the pool's current balances.
Parameters:
Name
Type
Description
_amounts
uint256[2]
how much of each token to withdraw
_maxBurnAmount
uint256
the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation.
_deadline
uint256
latest timestamp to accept this transaction
Return Values:
Name
Type
Description
lpBurned
uint256
amount of LP tokens burned

setAdminFee

function setAdminFee(
uint256 newAdminFee
) external
Update the admin fee. Admin fee takes portion of the swap fee.
Parameters:
Name
Type
Description
newAdminFee
uint256
new admin fee to be applied on future transactions

setSwapFee

function setSwapFee(
uint256 newSwapFee
) external
Update the swap fee to be applied on swaps
Parameters:
Name
Type
Description
newSwapFee
uint256
new swap fee to be applied on future transactions

rampA

function rampA(
uint256 futureA,
uint256 futureTime
) external
Start ramping up or down A parameter towards given futureA and futureTime Checks if the change is too rapid, and commits the new A value only when it falls under the limit range.
Parameters:
Name
Type
Description
futureA
uint256
the new A to ramp towards
futureTime
uint256
timestamp when the new A should be reached

stopRampA

function stopRampA() external
Stop ramping A immediately. Reverts if ramp A is already stopped.

transferOwnership

function transferOwnership(
address _newOwner
) external
Changes the owner of the contract
Parameters:
Name
Type
Description
_newOwner
address
address of the new owner

Events

Swap

event Swap(
)
Swap gets emitted when an accounts exchanges tokens.
No description
Parameters:
Name
Type
Description
buyer
address
address of the account initiating the swap
tokenSold
contract IERC20
address of the swapped token
amountSold
uint256
amount of tokens swapped
amountReceived
uint256
amount of tokens received in exchange

AddLiquidity

event AddLiquidity(
)
AddLiquidity gets emitted when liquidity is added to the pool.
No description
Parameters:
Name
Type
Description
provider
address
address of the account providing liquidity
tokenAmounts
uint256[2]
array of token amounts provided corresponding to pool cardinality of [token0, token1]
fees
uint256[2]
fees deducted for each of the tokens added corresponding to pool cardinality of [token0, token1]
invariant
uint256
pool invariant after adding liquidity
lpTokenSupply
uint256
the lpToken supply after minting

RemoveLiquidity

event RemoveLiquidity(
)
RemoveLiquidity gets emitted when liquidity for both tokens is removed from the pool.
No description
Parameters:
Name
Type
Description
provider
address
address of the account removing liquidity
tokenAmounts
uint256[2]
array of token amounts removed corresponding to pool cardinality of [token0, token1]
lpTokenSupply
uint256
total supply of liquidity pool token after removing liquidity

RemoveLiquidityOne

event RemoveLiquidityOne(
)
RemoveLiquidityOne gets emitted when single-sided liquidity is removed
No description
Parameters:
Name
Type
Description
provider
address
address of the account removing liquidity
lpTokenAmount
uint256
amount of liquidity pool tokens burnt
lpTokenSupply
uint256
total supply of liquidity pool token after removing liquidity
tokenReceived
contract IERC20
address of the token for which liquidity was removed
receivedAmount
uint256
amount of tokens received

RemoveLiquidityImbalance

event RemoveLiquidityImbalance(
)
RemoveLiquidityImbalance gets emitted when liquidity is removed weighted differently than the pool's current balances. with different weights than that of the pool.
No description
Parameters:
Name
Type
Description
provider
address
address of the the account removing liquidity imbalanced
tokenAmounts
uint256[2]
array of amounts of tokens being removed corresponding to pool cardinality of [token0, token1]
fees
uint256[2]
fees for each of the tokens removed corresponding to pool cardinality of [token0, token1]
invariant
uint256
pool invariant after removing liquidity
lpTokenSupply
uint256
total supply of liquidity pool token after removing liquidity

NewAdminFee

event NewAdminFee(
)
NewAdminFee gets emitted when the admin fee is updated.
No description
Parameters:
Name
Type
Description
newAdminFee
uint256
admin fee after update

NewSwapFee

event NewSwapFee(
)
NewSwapFee gets emitted when the swap fee is updated.
No description
Parameters:
Name
Type
Description
newSwapFee
uint256
swap fee after update

RampA

event RampA(
)
RampA gets emitted when A has started ramping up.
No description
Parameters:
Name
Type
Description
oldA
uint256
initial A value
newA
uint256
target value of A to ramp up to
initialTime
uint256
ramp start timestamp
futureTime
uint256
ramp end timestamp

StopRampA

event StopRampA(
)
StopRampA gets emitted when ramping A is stopped manually
No description
Parameters:
Name
Type
Description
currentA
uint256
current value of A
time
uint256
timestamp of when ramp is stopped
Copy link
On this page
Functions:
Events:
Functions
Events