Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ad95d22
feat: logging on atomic arb contract
kinrezC Feb 23, 2024
0a0a6de
fix: logData function in atomic:
kinrezC Feb 23, 2024
728ce2b
testing arbiter bug
kinrezC Feb 23, 2024
a6e8653
rename events
kinrezC Feb 23, 2024
c4f271a
rename event
kinrezC Feb 23, 2024
55c15f6
fix
kinrezC Feb 23, 2024
5c4779d
event changes
kinrezC Feb 23, 2024
87e630b
hacking matts computer
kinrezC Mar 4, 2024
785ab60
add dy/dx given S helpers
kinrezC Mar 4, 2024
a6c7c29
fix lower bound in bisection
kinrezC Mar 4, 2024
7baddb5
testing new bounds
kinrezC Mar 4, 2024
a814f89
set lower back to 1000 wei
kinrezC Mar 4, 2024
81aed61
set lower back to 1 wei
kinrezC Mar 4, 2024
71c0ce2
adjusted fee logic for lognormal
kinrezC Mar 5, 2024
ef7fe5c
add console logs
kinrezC Mar 5, 2024
419a18a
testing rx gt L
kinrezC Mar 5, 2024
16fa4f9
testing rx gt L
kinrezC Mar 5, 2024
6fd4147
logging things
kinrezC Mar 5, 2024
7a056a1
wip
kinrezC Mar 5, 2024
86fa5e8
wip
kinrezC Mar 5, 2024
cfa0d62
wip
kinrezC Mar 5, 2024
c16cdf9
log invariant
kinrezC Mar 5, 2024
a612df5
use rx as next liquidity lower bound
kinrezC Mar 5, 2024
d3adce9
use rx as next liquidity lower bound
kinrezC Mar 5, 2024
6fe6b3b
debugging
kinrezC Mar 5, 2024
087ed9f
wip
kinrezC Mar 5, 2024
1ed6e4f
check computed invariant
kinrezC Mar 5, 2024
208133d
wip
kinrezC Mar 5, 2024
23b972a
fix lower bound for next liquidity
kinrezC Mar 5, 2024
03b0fc9
conditionally use min fallback in computeNextLiquiditY
kinrezC Mar 5, 2024
17f404f
log computed dy
kinrezC Mar 5, 2024
a1e7150
update dx and dy logic
kinrezC Mar 5, 2024
7815568
log next x and current x
kinrezC Mar 5, 2024
536536b
update next rx bounds
kinrezC Mar 5, 2024
ecae212
fix lower bound for next rx
kinrezC Mar 5, 2024
961ca17
more logS
kinrezC Mar 5, 2024
5e0a7da
refactor fee calculations
kinrezC Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LogNormal/LogNormalSolver.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-latersolver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, I didn't mean to do that

pragma solidity ^0.8.13;

import "./LogNormalExtendedLib.sol";
Expand Down
74 changes: 66 additions & 8 deletions src/test/helpers/AtomicV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ import "solmate/utils/FixedPointMathLib.sol";
import "src/lib/BisectionLib.sol";
import "forge-std/console2.sol";

struct LogNormalParams {
uint256 strike;
uint256 sigma;
uint256 tau;
uint256 swapFee;
address controller;
}

interface LiquidExchange {
function swap(address token, uint256 amount) external;
function price() external returns (uint256);
}

interface StrategyLike {
interface DfmmLike {
function swap(uint256 poolId, bytes calldata data) external;
}

interface SolverLike {
function simulateSwap(
uint256 poolId,
bool swapXIn,
Expand All @@ -31,8 +42,18 @@ interface StrategyLike {
external
view
returns (uint256, uint256, uint256);
function strategy() external view returns (address);
}

interface LogNormalStrategyLike {
function fetchPoolParams(uint256 poolId) external view returns (LogNormalParams memory);
}

interface StrategyLike {
function name() external view returns (string memory);
}


interface TokenLike {
function transferFrom(address, address, uint256) external;
function transfer(address, uint256) external;
Expand Down Expand Up @@ -69,6 +90,9 @@ contract AtomicV2 {
address public solver;
address public asset;
address public quote;
address public strategy;

string public strategyName;

/// @dev Since token x is transferred inside the arbitrage loop, this stores that value in the last arb loop.
uint256 public intermediateTokenXBalance;
Expand All @@ -90,16 +114,36 @@ contract AtomicV2 {
liquidExchange = liquidExchangeAddress;
asset = assetAddress;
quote = quoteAddress;
strategy = SolverLike(solver).strategy();
strategyName = StrategyLike(strategy).name();
}

bool public XTOY = true;
bool public YTOX = false;

error AttemptedProfit(int256 profit);
event LogDfmmData(uint256 price, uint256 timestamp, uint256 rx, uint256 ry, uint256 liq, uint256 strike, uint256 sigma, uint256 tau);
event LogLexData(uint256 price, uint256 timestamp, uint256 rx, uint256 ry);
event LogArbData(uint256 xBalance, uint256 yBalance, uint256 timestamp);

function lower_exchange_price(uint256 poolId, uint256 input) external {
uint256 price = StrategyLike(solver).internalPrice(poolId);
emit Price(price, block.timestamp);
uint256 price = SolverLike(solver).internalPrice(poolId);

if (keccak256(abi.encode(strategyName)) == keccak256(abi.encode("LogNormal"))) {
(uint256 rx, uint256 ry, uint256 L) = SolverLike(solver).getReservesAndLiquidity(poolId);
LogNormalParams memory params = LogNormalStrategyLike(solver).fetchPoolParams(poolId);
emit LogDfmmData(price, block.timestamp, rx, ry, L, params.strike, params.sigma, params.tau);
}

uint256 lexPrice = LiquidExchange(liquidExchange).price();
uint256 lexBalanceX = TokenLike(asset).balanceOf(liquidExchange);
uint256 lexBalanceY = TokenLike(quote).balanceOf(liquidExchange);
emit LogLexData(lexPrice, block.timestamp, lexBalanceX, lexBalanceY);

uint256 arbBalanceX = TokenLike(asset).balanceOf(msg.sender);
uint256 arbBalanceY = TokenLike(quote).balanceOf(msg.sender);
emit LogArbData(arbBalanceX, arbBalanceY, block.timestamp);

// Arbitrageur Y -> AtomicV2
_invoice(input);

Expand All @@ -114,8 +158,22 @@ contract AtomicV2 {
}

function raise_exchange_price(uint256 poolId, uint256 input) external {
uint256 price = StrategyLike(solver).internalPrice(poolId);
emit Price(price, block.timestamp);
uint256 price = SolverLike(solver).internalPrice(poolId);
if (keccak256(abi.encode(strategyName)) == keccak256(abi.encode("LogNormal"))) {
(uint256 rx, uint256 ry, uint256 L) = SolverLike(solver).getReservesAndLiquidity(poolId);
LogNormalParams memory params = LogNormalStrategyLike(solver).fetchPoolParams(poolId);
emit LogDfmmData(price, block.timestamp, rx, ry, L, params.strike, params.sigma, params.tau);
}

uint256 lexPrice = LiquidExchange(liquidExchange).price();
uint256 lexBalanceX = TokenLike(asset).balanceOf(liquidExchange);
uint256 lexBalanceY = TokenLike(quote).balanceOf(liquidExchange);
emit LogLexData(lexPrice, block.timestamp, lexBalanceX, lexBalanceY);

uint256 arbBalanceX = TokenLike(asset).balanceOf(msg.sender);
uint256 arbBalanceY = TokenLike(quote).balanceOf(msg.sender);
emit LogArbData(arbBalanceX, arbBalanceY, block.timestamp);

// Arbitrageur Y -> AtomicV2
_invoice(input);

Expand Down Expand Up @@ -194,7 +252,7 @@ contract AtomicV2 {
uint256 estimatedOut,
uint256 estimatedPrice,
bytes memory payload
) = StrategyLike(solver).simulateSwap(poolId, swapXIn, amountIn);
) = SolverLike(solver).simulateSwap(poolId, swapXIn, amountIn);

if (!valid) {
revert SimulatedSwapFailure(
Expand All @@ -203,7 +261,7 @@ contract AtomicV2 {
}

// Execute the swap.
try StrategyLike(exchange).swap(poolId, payload) {
try DfmmLike(exchange).swap(poolId, payload) {
// Swap succeeded, do nothing other than store the intermediary balance.
if (swapXIn) {
// If X -> Y
Expand Down Expand Up @@ -262,7 +320,7 @@ contract AtomicV2 {
bytes memory payload
)
{
return StrategyLike(solver).simulateSwap(poolId, swapXIn, amountIn);
return SolverLike(solver).simulateSwap(poolId, swapXIn, amountIn);
}

function cdf(int256 input) public pure returns (int256 output) {
Expand Down