Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/arb loop math #40

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions box-contracts/src/G3M.sol
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ contract G3M is IG3M {
}

/// @inheritdoc IG3M
function getInvariant() external view returns (UD60x18) {
return computeInvariant(reserveX, weightX(), reserveY, weightY());
function getInvariant() external view returns (uint) {
return convert(computeInvariant(reserveX, weightX(), reserveY, weightY()));
}

function reserveXWithoutPrecision() external view returns (uint256) {
Expand Down
2 changes: 1 addition & 1 deletion box-contracts/src/IG3M.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ interface IG3M {
function getSpotPrice() external view returns (uint256);

/// @notice Computes the invariant of the pool.
function getInvariant() external view returns (UD60x18);
function getInvariant() external view returns (uint);

/// @notice Address of token X.
function tokenX() external view returns (address);
Expand Down
14 changes: 4 additions & 10 deletions simulation/src/agents/arbitrageur/g3m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ impl Strategy for G3M<RevmMiddleware> {
info!("weight_x: {}", weight_x);
let weight_y = I256::from_raw(self.weight_y().call().await?);
info!("weight_y: {}", weight_y);
let reserve_x = I256::from_raw(self.reserve_x().call().await?);
let reserve_x = I256::from_raw(self.reserve_x_without_precision().call().await?);
info!("reserve_x: {}", reserve_x);
let reserve_y = I256::from_raw(self.reserve_y().call().await?);
let reserve_y = I256::from_raw(self.reserve_y_without_precision().call().await?);
info!("reserve_y: {}", reserve_y);
let invariant = I256::from_raw(self.get_invariant().call().await?);
info!("invariant: {}", invariant);
Expand All @@ -31,9 +31,6 @@ impl Strategy for G3M<RevmMiddleware> {
let delta_x = invariant * math.pow(inside, weight_y).call().await? / iwad - reserve_x;
info!("delta_x: {}", delta_x);

let gamma = iwad - (I256::from_raw(self.swap_fee().await?)) * I256::from(10u128.pow(14));
info!("gamma: {}", gamma);
let delta_x = delta_x * gamma / iwad;
Ok(delta_x.into_raw())
}

Expand All @@ -46,9 +43,9 @@ impl Strategy for G3M<RevmMiddleware> {
info!("weight_x: {}", weight_x);
let weight_y = I256::from_raw(self.weight_y().call().await?);
info!("weight_y: {}", weight_y);
let reserve_x = I256::from_raw(self.reserve_x().call().await?);
let reserve_x = I256::from_raw(self.reserve_x_without_precision().call().await?);
info!("reserve_x: {}", reserve_x);
let reserve_y = I256::from_raw(self.reserve_y().call().await?);
let reserve_y = I256::from_raw(self.reserve_y_without_precision().call().await?);
info!("reserve_y: {}", reserve_y);
let invariant = I256::from_raw(self.get_invariant().call().await?);
info!("invariant: {}", invariant);
Expand All @@ -62,9 +59,6 @@ impl Strategy for G3M<RevmMiddleware> {
info!("inside: {}", inside);
let delta_y = invariant * math.pow(inside, weight_x).call().await? / iwad - reserve_y;
info!("delta_y: {}", delta_y);
let gamma = iwad - (I256::from_raw(self.swap_fee().await?)) * I256::from(10u128.pow(14));
info!("gamma: {}", gamma);
let delta_y = delta_y * gamma / iwad;

Ok(delta_y.into_raw())
}
Expand Down