-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move orderbook fetching to src folder and expose it (#619)
@anxolin suggested to reuse the fetch orderbook logic in the dex-price-estimator. In order to do this we need to move this logic into `/src` and expose it on `index.js` and `index.d.ts`. ### Test Plan local price estimation script still works, and `yalc publish` allows using this method in dex-price-estimator
- Loading branch information
Showing
11 changed files
with
79 additions
and
58 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
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
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
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
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
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
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
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,53 @@ | ||
const { decodeOrdersBN } = require("./encoding") | ||
|
||
/** | ||
* Returns an iterator yielding an item for each page of order in the orderbook that is currently being collected. | ||
* @param {BatchExchangeViewer} contract to query from | ||
* @param {number} pageSize the number of items to fetch per page | ||
*/ | ||
const getOpenOrdersPaginated = async function* (contract, pageSize) { | ||
let nextPageUser = "0x0000000000000000000000000000000000000000" | ||
let nextPageUserOffset = 0 | ||
let lastPageSize = pageSize | ||
|
||
while (lastPageSize == pageSize) { | ||
const page = await contract.methods.getOpenOrderBookPaginated([], nextPageUser, nextPageUserOffset, pageSize).call() | ||
const elements = decodeOrdersBN(page.elements) | ||
yield elements | ||
|
||
//Update page info | ||
lastPageSize = elements.length | ||
nextPageUser = page.nextPageUser | ||
nextPageUserOffset = page.nextPageUserOffset | ||
} | ||
} | ||
|
||
/** | ||
* Returns all orders in the orderbook. | ||
* @param {BatchExchange} contract to query from | ||
* @param {number} pageSize the number of items to fetch per page | ||
*/ | ||
const getOrdersPaginated = async (contract, pageSize) => { | ||
let orders = [] | ||
let currentUser = "0x0000000000000000000000000000000000000000" | ||
let currentOffSet = 0 | ||
let lastPageSize = pageSize | ||
while (lastPageSize == pageSize) { | ||
const page = decodeOrdersBN(await contract.methods.getEncodedUsersPaginated(currentUser, currentOffSet, pageSize).call()) | ||
orders = orders.concat(page) | ||
for (const index in page) { | ||
if (page[index].user != currentUser) { | ||
currentUser = page[index].user | ||
currentOffSet = 0 | ||
} | ||
currentOffSet += 1 | ||
} | ||
lastPageSize = page.length | ||
} | ||
return orders | ||
} | ||
|
||
module.exports = { | ||
getOpenOrdersPaginated, | ||
getOrdersPaginated, | ||
} |
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
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
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 |
---|---|---|
|
@@ -8882,7 +8882,7 @@ [email protected]: | |
web3-core-requestmanager "1.2.2" | ||
web3-utils "1.2.2" | ||
|
||
[email protected]: | ||
[email protected], web3-core@^1.2.6: | ||
version "1.2.6" | ||
resolved "https://registry.yarnpkg.com/web3-core/-/web3-core-1.2.6.tgz#bb42a1d7ae49a7258460f0d95ddb00906f59ef92" | ||
integrity sha512-y/QNBFtr5cIR8vxebnotbjWJpOnO8LDYEAzZjeRRUJh2ijmhjoYk7dSNx9ExgC0UCfNFRoNCa9dGRu/GAxwRlw== | ||
|