Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Sep 14, 2023
1 parent aec0dc0 commit 5eeb106
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 311 deletions.
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -18,7 +18,7 @@ PoolTogether V5 uses the CGDA liquidator to sell yield for POOL tokens and contr

## LiquidationPair

The LiquidationPair sells one token for another using a periodic continuous gradual dutch auction. The pair does not hold liquidity, but rather prices liquidity held by a ILiquidationSource. The Liquidation Source makes liquidity available to the pair, which facilitates swaps.
The LiquidationPair sells one token for another using a periodic continuous gradual dutch auction. The pair does not hold liquidity, but rather prices liquidity held by a ILiquidationSource. The Liquidation Source makes liquidity available to the pair, which facilitates swaps.

A continuous gradual dutch auction is an algorithm that:

Expand All @@ -30,7 +30,7 @@ What you get, in a sense, is that a CGDA auction will drop the price until purch

For more information read the origina Paradigm article on [Gradual Dutch Auctions](https://www.paradigm.xyz/2022/04/gda).

The LiquidationPair is *periodic*, in the sense that it runs a sequence of CGDAs. At the start of each auction period, the LiquidationPair will adjust the target price and emissions rate so that the available liquidity can be sold as efficiently as possible.
The LiquidationPair is _periodic_, in the sense that it runs a sequence of CGDAs. At the start of each auction period, the LiquidationPair will adjust the target price and emissions rate so that the available liquidity can be sold as efficiently as possible.

<strong>Have questions or want the latest news?</strong>
<br/>Join the PoolTogether Discord or follow us on Twitter:
Expand All @@ -54,7 +54,6 @@ Install dependencies:
npm i
```


## Derivations

### Price Function
Expand Down Expand Up @@ -94,4 +93,3 @@ $$ p = \frac{k}{l}\cdot\frac{\left(e^{\frac{lq}{r}}-1\right)}{e^{lt}} $$
$$ l\cdot p\cdot e^{lt} = k\cdot\left(e^{\frac{lq}{r}}-1\right) $$

$$ \frac{l\cdot p\cdot e^{lt}}{(e^{\frac{lq}{r}}-1)} = k $$

1 change: 0 additions & 1 deletion src/LiquidationPairFactory.sol
Expand Up @@ -8,7 +8,6 @@ import { ILiquidationSource, LiquidationPair, SD59x18 } from "./LiquidationPair.
/// @author G9 Software Inc.
/// @notice Factory contract for deploying LiquidationPair contracts.
contract LiquidationPairFactory {

/* ============ Events ============ */

/// @notice Emitted when a new LiquidationPair is created
Expand Down
21 changes: 17 additions & 4 deletions src/LiquidationRouter.sol
Expand Up @@ -57,7 +57,7 @@ contract LiquidationRouter is IFlashSwapCallback {
/// @notice Constructs a new LiquidationRouter
/// @param liquidationPairFactory_ The factory that pairs will be verified to have been created by
constructor(LiquidationPairFactory liquidationPairFactory_) {
if(address(liquidationPairFactory_) == address(0)) {
if (address(liquidationPairFactory_) == address(0)) {
revert UndefinedLiquidationPairFactory();
}
_liquidationPairFactory = liquidationPairFactory_;
Expand Down Expand Up @@ -85,11 +85,24 @@ contract LiquidationRouter is IFlashSwapCallback {
revert SwapExpired(_deadline);
}

uint256 amountIn = _liquidationPair.swapExactAmountOut(address(this), _amountOut, _amountInMax, abi.encode(msg.sender));
uint256 amountIn = _liquidationPair.swapExactAmountOut(
address(this),
_amountOut,
_amountInMax,
abi.encode(msg.sender)
);

IERC20(_liquidationPair.tokenOut()).safeTransfer(_receiver, _amountOut);

emit SwappedExactAmountOut(_liquidationPair, msg.sender, _receiver, _amountOut, _amountInMax, amountIn, _deadline);
emit SwappedExactAmountOut(
_liquidationPair,
msg.sender,
_receiver,
_amountOut,
_amountInMax,
amountIn,
_deadline
);

return amountIn;
}
Expand All @@ -100,7 +113,7 @@ contract LiquidationRouter is IFlashSwapCallback {
uint256 _amountIn,
uint256,
bytes calldata _flashSwapData
) external onlyTrustedLiquidationPair(LiquidationPair(msg.sender)) onlySelf(_sender) override {
) external override onlyTrustedLiquidationPair(LiquidationPair(msg.sender)) onlySelf(_sender) {
address _originalSender = abi.decode(_flashSwapData, (address));
IERC20(LiquidationPair(msg.sender).tokenIn()).safeTransferFrom(
_originalSender,
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/ContinuousGDA.sol
Expand Up @@ -55,7 +55,9 @@ library ContinuousGDA {
SD59x18 _price
) internal pure returns (SD59x18) {
SD59x18 topE = _decayConstant.mul(_targetFirstSaleTime).safeExp();
SD59x18 denominator = (_decayConstant.mul(_purchaseAmount).div(_emissionRate)).safeExp().sub(ONE);
SD59x18 denominator = (_decayConstant.mul(_purchaseAmount).div(_emissionRate)).safeExp().sub(
ONE
);
SD59x18 result = topE.div(denominator);
SD59x18 multiplier = _decayConstant.mul(_price);
return result.mul(multiplier);
Expand Down
14 changes: 6 additions & 8 deletions src/libraries/SafeSD59x18.sol
Expand Up @@ -4,12 +4,10 @@ pragma solidity 0.8.19;
import { SD59x18, wrap } from "prb-math/SD59x18.sol";

library SafeSD59x18 {

function safeExp(SD59x18 x) internal pure returns (SD59x18) {
if (x.unwrap() < -41.45e18) {
return wrap(0);
}
return x.exp();
function safeExp(SD59x18 x) internal pure returns (SD59x18) {
if (x.unwrap() < -41.45e18) {
return wrap(0);
}

}
return x.exp();
}
}
3 changes: 0 additions & 3 deletions test/LiquidationPairFactory.t.sol
Expand Up @@ -56,8 +56,6 @@ contract LiquidationPairFactoryTest is Test {
/* ============ createPair ============ */

function testCreatePair() public {


vm.expectEmit(false, false, false, true);
emit PairCreated(
LiquidationPair(0x0000000000000000000000000000000000000000),
Expand Down Expand Up @@ -114,5 +112,4 @@ contract LiquidationPairFactoryTest is Test {
abi.encode(amount)
);
}

}

0 comments on commit 5eeb106

Please sign in to comment.