-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from 1inch/feature/Maverick2
Maverick2
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.23; | ||
|
||
interface Pool { | ||
struct TickState { | ||
uint128 reserveA; | ||
uint128 reserveB; | ||
uint128 totalSupply; | ||
uint32[4] binIdsByTick; | ||
} | ||
struct State { | ||
uint128 reserveA; | ||
uint128 reserveB; | ||
int64 lastTwaD8; | ||
int64 lastLogPriceD8; | ||
uint40 lastTimestamp; | ||
int32 activeTick; | ||
bool isLocked; | ||
uint32 binCounter; | ||
uint8 protocolFeeRatioD3; | ||
} | ||
|
||
function getTick(int32 tick) external view returns (TickState memory _tick); | ||
function getState() external view returns (State memory); | ||
} | ||
|
||
contract Maverick2TickHelper { | ||
struct Tick { | ||
uint128 reserveA; | ||
uint128 reserveB; | ||
} | ||
|
||
function get(Pool pool, int32 limit) public view returns(Pool.State memory state, Tick[] memory reserves) { | ||
state = pool.getState(); | ||
uint32 len = uint32(limit*2+1); | ||
reserves = new Tick[](len); | ||
for (uint32 i = 0; i < len; i++) { | ||
Pool.TickState memory tick = pool.getTick(state.activeTick-limit+int32(i)); | ||
reserves[i].reserveA = tick.reserveA; | ||
reserves[i].reserveB = tick.reserveB; | ||
} | ||
} | ||
} |