Skip to main content

AmmalgamPair

Git Source

Inherits: IAmmalgamPair, AmmalgamERC20Controller

State Variables

MINIMUM_LIQUIDITY

uint256 public constant MINIMUM_LIQUIDITY = 10 ** 3;

LTV

uint8 public constant override LTV = 75;

MAX_BORROW

uint8 public constant MAX_BORROW = 90;

ALLOWED_LIQUIDITY_LEVERAGE

uint8 public constant override ALLOWED_LIQUIDITY_LEVERAGE = 100;

BUFFER

uint8 public constant BUFFER = 95;

externalLiquidity

uint112 public override externalLiquidity = 0;

factory

address public immutable factory;

feeToSetter

address public immutable feeToSetter;

activeLiquidity

uint112 private activeLiquidity;

activeLiquidityScaler

uint256 private activeLiquidityScaler;

obs

GeometricBWAP.Observations private obs;

reserveX

uint112 private reserveX;

reserveY

uint112 private reserveY;

depositedX

uint112 private depositedX;

depositedY

uint112 private depositedY;

borrowedX

uint112 private borrowedX;

borrowedY

uint112 private borrowedY;

kLast

uint256 public kLast;

unlocked

uint256 private unlocked = 1;

missingX

uint112 public override missingX;

missingY

uint112 public override missingY;

Functions

lock

modifier lock();

onlyFeeToSetter

modifier onlyFeeToSetter();

constructor

constructor();

updateExternalLiquidity

function updateExternalLiquidity(uint112 externalLiquidity_) external override onlyFeeToSetter;

mint

function mint(address to) external lock returns (uint256 liquidity);

burn

function burn(address to) external lock returns (uint256 amountX, uint256 amountY);

swap

function swap(uint256 amountXOut, uint256 amountYOut, address to, bytes calldata data) external lock;

deposit

function deposit(address to) external lock;

withdraw

withdraw X and/or Y

function withdraw(address to) external lock;

borrow

function borrow(address to, uint256 amountX, uint256 amountY, bytes calldata data) external lock;

borrowLiquidity

function borrowLiquidity(
address to,
uint256 borrowAmountL,
bytes calldata data
) external lock returns (uint256, uint256);

repay

function repay(address onBehalfOf) public lock;

repayLiquidity

function repayLiquidity(address onBehalfOf)
public
lock
returns (uint256 amountX, uint256 amountY, uint256 repayAmountL);

depletionReserveAdjustmentWhenLiquidityIsAdded

Minting when assets depleted requires less of the depleted asset as we give extra credit to minter for bringing the scarce asset. We account for liquidity as if moving from the unmodified invariant prior to mint to the where it would move after the mint including the extra credited scarce asset. I continue to update the Desmos to help create test cases with easier numbers to reason about, The current version of desmos is linked below. The chart could use some clean up and reorganization to be clearer, will do in the future. https://www.desmos.com/calculator/etzuxkjeig

function depletionReserveAdjustmentWhenLiquidityIsAdded(
uint112 reserve_,
uint256 amount_,
uint256 missing_,
uint256 activeLiquidity_
) private pure returns (uint256);

depletionReserveAdjustmentWhenAssetIsAdded

When assets are depleted, a user can deposit the depleted asset and earn additional deposit credit for moving the swap curve from the adjusted amount due to assets being depleted to the original curve.

function depletionReserveAdjustmentWhenAssetIsAdded(
uint256 amount_,
uint256 reserve_,
uint256 missing_
) private pure returns (uint256 adjustReserves_);

skim

function skim(address to) external lock;

sync

function sync() external lock;

getReserves

function getReserves() public view returns (uint112 _reserveX, uint112 _reserveY, uint256 _blockLast);

updateMissingAssets

function updateMissingAssets() private;

_update

function _update(uint256 balanceX, uint256 balanceY, uint112 _reserveX, uint112 _reserveY) private;

_mintFee

function _mintFee(uint112 _reserveX, uint112 _reserveY) private returns (bool feeOn);

validateSolvency

function validateSolvency(TokenType tokenType, address toCheck, uint256 amount, uint256 balanceFrom) public view;

getNetAmounts

function getNetAmounts() private view returns (uint256 amountX, uint256 amountY);

configLongTermInterval

function configLongTermInterval(uint24 longTermIntervalConfig) external onlyFeeToSetter;

getObservations

function getObservations() external view override returns (GeometricBWAP.Observations memory);

getTickRange

function getTickRange() external view returns (int24, int24);

Errors

AmmalgamLocked

error AmmalgamLocked();

AmmalgamForbidden

error AmmalgamForbidden();

AmmalgamInsufficientLiquidityMinted

error AmmalgamInsufficientLiquidityMinted();

AmmalgamInsufficientLiquidityBurned

error AmmalgamInsufficientLiquidityBurned();

AmmalgamInsufficientOutputAmount

error AmmalgamInsufficientOutputAmount();

AmmalgamInsufficientInputAmount

error AmmalgamInsufficientInputAmount();

AmmalgamInsufficientLiquidity

error AmmalgamInsufficientLiquidity();

AmmalgamInvalidToAddress

error AmmalgamInvalidToAddress();

AmmalgamK

error AmmalgamK();

AmmalgamDepositOverflow

error AmmalgamDepositOverflow();

AmmalgamInsufficientRepayLiquidity

error AmmalgamInsufficientRepayLiquidity();

AmmalgamOverflow

error AmmalgamOverflow();