-
Notifications
You must be signed in to change notification settings - Fork 13
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
Introduce registry helper contracts to speed up pair discovery & bulk pair refresh #31
Conversation
struct PairState { | ||
uint reserve0; | ||
uint reserve1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reserve information for the pair state information we need for refresh()
address token0; | ||
address token1; | ||
PairState state; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial Pair information for initialization, address of pair, tokens, and the initial state
c831d0a
to
443dc45
Compare
443dc45
to
e6eea13
Compare
IUniswapV2Factory factory, | ||
address[] calldata tokenWhitelist, | ||
uint offset, | ||
uint limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed to introduce offset
and limit
so that the amount of work done per call is capped
otherwise, Forno complains about out of gas when trying to fetch info for > 200 pairs.
The safe limit I've found is to fetch in chunks of 100.
// allocate a buffer array with the upper bound of the number of pairs returned | ||
PairInfo[] memory buffer = new PairInfo[](limit); | ||
uint found = 0; | ||
for (uint i = offset; i < allPairsUpTo; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop through starting from the given offset
49a379c
to
8506928
Compare
I am going to take over this diff, since I need to integrate the registry helper into the dpeloyer too. |
Registry helper to speed up:
Example deployment of earlier draft of this contract, some naming changed, but functionality is the same:
Uniswap Helper https://explorer.celo.org/address/0x4d416fE42BA21C59fc853bd887B996D8C05A0e20/contracts
Balancer Helper https://explorer.celo.org/address/0xba2d6Ec829d1026B2E8ae93c06112A457918c44e/read-contract
These registry helpers are absolutely necessary to scaling the per-block pair refresh() to 2k+ pairs.
TODO: make it possible for a registry to bulk-refresh all of its pairs with the registry helper contract
Probably will create pair specific Snapshot from the on-chain fetched batch data, and use the current
restore(snapshot)
api to batch initialize / refresh the pairs