Skip to content

Commit

Permalink
Merge pull request #21 from LufyCZ/main
Browse files Browse the repository at this point in the history
v1.0.7
  • Loading branch information
jiro-ono authored Feb 28, 2021
2 parents e9abaeb + b69903b commit c094ef1
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 215 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@ The below all return a Promise that resolves with the requested results.
29. `masterchef.info({¹})` Gets MasterChef contract info.
30. `masterchef.pool({¹, pool_id, pool_address})` Gets pool info, either by pool id or by pool address.
31. `masterchef.pools({¹})` Gets pool info for all pools in MasterChef.
32. `masterchef.user({¹, user_address})` Gets all pools user has stake in.
33. `masterchef.apys({¹})` Gets pool info for all pools in MasterChef including APYs.
34. `masterchef.apys24h({¹})` Gets 24h pool info for all pools in MasterChef including APYs.
35. `exchange.stakedValue({¹, token_address})` Get pricing info for MasterChef pool.
36. `bar.info({¹})` Gets SushiBar contract info.
37. `bar.user({¹, user_address})` Gets SushiBar data for specified user.
38. `maker.info({¹})` Gets SushiMaker contract info.
39. `maker.servings({²})` Gets past servings to the bar.
40. `maker.servers({¹})` Gets servers that have served Sushi to the bar.
41. `maker.pendingServings({¹})` Gets data on the servings ready to be served to the bar.
42. `timelock.queuedTxs({²})` Gets queued Timelock transactions.
43. `timelock.canceledTxs({²})` Gets canceled Timelock transactions.
44. `timelock.executedTxs({²})` Gets executed Timelock transactions.
45. `timelock.allTxs({²})` Gets all Timelock transactions.
46. `lockup.user({¹, user_address})` Gets lockup data for specified user.
32. `masterchef.user({¹, user_address})` Gets user's data for all of the user's pools.
33. `masterchef.users({¹})` Gets all users and data for all of the users' pools.
34. `masterchef.apys({¹})` Gets pool info for all pools in MasterChef including APYs.
35. `masterchef.apys24h({¹})` Gets 24h pool info for all pools in MasterChef including APYs.
36. `exchange.stakedValue({¹, token_address})` Get pricing info for MasterChef pool.
37. `bar.info({¹})` Gets SushiBar contract info.
38. `bar.user({¹, user_address})` Gets SushiBar data for specified user.
39. `maker.info({¹})` Gets SushiMaker contract info.
40. `maker.servings({²})` Gets past servings to the bar.
41. `maker.servers({¹})` Gets servers that have served Sushi to the bar.
42. `maker.pendingServings({¹})` Gets data on the servings ready to be served to the bar.
43. `timelock.queuedTxs({²})` Gets queued Timelock transactions.
44. `timelock.canceledTxs({²})` Gets canceled Timelock transactions.
45. `timelock.executedTxs({²})` Gets executed Timelock transactions.
46. `timelock.allTxs({²})` Gets all Timelock transactions.
47. `lockup.user({¹, user_address})` Gets lockup data for specified user.

¹ `{block, timestamp}` Supports fetching at a specific block / UNIX timestamp.
² `{minBlock, maxBlock, minTimestamp, maxTimestamp}` Supports fetching in a specific timeframe.
Expand Down
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sushiswap/sushi-data",
"license": "MIT",
"version": "1.0.6",
"version": "1.0.7",
"author": "SushiSwap",
"main": "index",
"scripts": {
Expand All @@ -14,7 +14,7 @@
"commander": "6.1.0",
"csv-stringify": "5.3.3",
"date-fns": "^2.17.0",
"graph-results-pager": "~1.0.0",
"graph-results-pager": "https://github.com/LufyCZ/graph-results-pager",
"graphql": "14.5.8",
"graphql-request": "^3.4.0",
"isomorphic-ws": "^4.0.1",
Expand Down
3 changes: 1 addition & 2 deletions queries/exchange/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ module.exports = {
query: {
entity: 'dayDatas',
selection: {
orderBy: 'date',
orderDirection: 'asc',
orderDirection: 'desc',
where: {
date_gte: minTimestamp || (minBlock ? await blockToTimestamp(minBlock) : undefined),
date_lte: maxTimestamp || (maxBlock ? await blockToTimestamp(maxBlock) : undefined),
Expand Down
69 changes: 34 additions & 35 deletions queries/exchange/pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ module.exports = {
query: {
entity: 'pairDayDatas',
selection: {
orderBy: 'date',
orderDirection: 'asc',
orderDirection: 'desc',
where: {
pair: `\\"${pair_address.toLowerCase()}\\"`,
date_gte: minTimestamp || (minBlock ? await blockToTimestamp(minBlock) : undefined),
Expand All @@ -121,7 +120,7 @@ module.exports = {
pair(id: "${pair_address.toLowerCase()}") {
${pairs.properties.toString()}
}
}`;
}`

const client = new SubscriptionClient(graphWSEndpoints.exchange, { reconnect: true, }, ws,);
const observable = client.request({ query });
Expand Down Expand Up @@ -164,8 +163,6 @@ module.exports = {
query: {
entity: 'pairs',
selection: {
orderBy: 'reserveUSD',
orderDirection: 'desc',
block: block ? { number: block } : timestamp ? { number: await timestampToBlock(timestamp) } : undefined,
},
properties: pairs.properties
Expand Down Expand Up @@ -242,36 +239,38 @@ const pairs = {
],

callback(results) {
return results.map(result => ({
id: result.id,
token0: {
id: result.token0.id,
name: result.token0.name,
symbol: result.token0.symbol,
totalSupply: Number(result.token0.totalSupply),
derivedETH: Number(result.token0.derivedETH),
},
token1: {
id: result.token1.id,
name: result.token1.name,
symbol: result.token1.symbol,
totalSupply: Number(result.token1.totalSupply),
derivedETH: Number(result.token1.derivedETH),
},
reserve0: Number(result.reserve0),
reserve1: Number(result.reserve1),
totalSupply: Number(result.totalSupply),
reserveETH: Number(result.reserveETH),
reserveUSD: Number(result.reserveUSD),
trackedReserveETH: Number(result.trackedReserveETH),
token0Price: Number(result.token0Price),
token1Price: Number(result.token1Price),
volumeToken0: Number(result.volumeToken0),
volumeToken1: Number(result.volumeToken1),
volumeUSD: Number(result.volumeUSD),
untrackedVolumeUSD: Number(result.untrackedVolumeUSD),
txCount: Number(result.txCount),
}));
return results
.map(result => ({
id: result.id,
token0: {
id: result.token0.id,
name: result.token0.name,
symbol: result.token0.symbol,
totalSupply: Number(result.token0.totalSupply),
derivedETH: Number(result.token0.derivedETH),
},
token1: {
id: result.token1.id,
name: result.token1.name,
symbol: result.token1.symbol,
totalSupply: Number(result.token1.totalSupply),
derivedETH: Number(result.token1.derivedETH),
},
reserve0: Number(result.reserve0),
reserve1: Number(result.reserve1),
totalSupply: Number(result.totalSupply),
reserveETH: Number(result.reserveETH),
reserveUSD: Number(result.reserveUSD),
trackedReserveETH: Number(result.trackedReserveETH),
token0Price: Number(result.token0Price),
token1Price: Number(result.token1Price),
volumeToken0: Number(result.volumeToken0),
volumeToken1: Number(result.volumeToken1),
volumeUSD: Number(result.volumeUSD),
untrackedVolumeUSD: Number(result.untrackedVolumeUSD),
txCount: Number(result.txCount),
}))
.sort((a, b) => b.reserveUSD - a.reserveUSD);
},

callback24h(results, results24h, results48h, ethPriceUSD, ethPriceUSD24ago) {
Expand Down
37 changes: 18 additions & 19 deletions queries/exchange/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
const query = (
gql`{
${blocks.map((block, i) => (gql`
timestamp${timestamps[i]}: token(id: ${token_address.toLowerCase()}, block: {number: ${block}}) {
timestamp${timestamps[i]}: token(id: "${token_address.toLowerCase()}", block: {number: ${block}}) {
${tokens.properties.toString()}
}`))}
}`
Expand All @@ -98,8 +98,7 @@ module.exports = {
query: {
entity: 'tokenDayDatas',
selection: {
orderBy: 'date',
orderDirection: 'asc',
orderDirection: 'desc',
where: {
token: `\\"${token_address.toLowerCase()}\\"`,
date_gte: minTimestamp || (minBlock ? await blockToTimestamp(minBlock) : undefined),
Expand Down Expand Up @@ -145,8 +144,6 @@ module.exports = {
query: {
entity: 'tokens',
selection: {
orderBy: 'volumeUSD',
orderDirection: 'desc',
block: block ? { number: block } : timestamp ? { number: await timestampToBlock(timestamp) } : undefined,
},
properties: tokens.properties
Expand Down Expand Up @@ -217,19 +214,21 @@ const tokens = {
],

callback(results) {
return results.map(({ id, symbol, name, decimals, totalSupply, volume, volumeUSD, untrackedVolumeUSD, txCount, liquidity, derivedETH }) => ({
id: id,
symbol: symbol,
name: name,
decimals: Number(decimals),
totalSupply: Number(totalSupply),
volume: Number(volume),
volumeUSD: Number(volumeUSD),
untrackedVolumeUSD: Number(untrackedVolumeUSD),
txCount: Number(txCount),
liquidity: Number(liquidity),
derivedETH: Number(derivedETH)
}));
return results
.map(({ id, symbol, name, decimals, totalSupply, volume, volumeUSD, untrackedVolumeUSD, txCount, liquidity, derivedETH }) => ({
id: id,
symbol: symbol,
name: name,
decimals: Number(decimals),
totalSupply: Number(totalSupply),
volume: Number(volume),
volumeUSD: Number(volumeUSD),
untrackedVolumeUSD: Number(untrackedVolumeUSD),
txCount: Number(txCount),
liquidity: Number(liquidity),
derivedETH: Number(derivedETH)
}))
.sort((a, b) => b.volumeUSD - a.volumeUSD);
},

callback24h(results, results24h, results48h, ethPriceUSD, ethPriceUSD24ago) {
Expand Down Expand Up @@ -311,4 +310,4 @@ const tokens = {
txCount: Number(result.txCount)
}));
}
};
};
4 changes: 2 additions & 2 deletions queries/lockup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ const user = {
id: entry.id,
address: entry.address,
amount: Number(entry.amount),
rewardDebt: Number(entry.rewardDebt),
rewardDebt: BigInt(entry.rewardDebt),
pool: {
id: entry.pool.id,
balance: Number(entry.pool.balance),
accSushiPerShare: Number(entry.pool.accSushiPerShare)
accSushiPerShare: BigInt(accSushiPerShare)
},
sushiAtLockup: Number(entry.sushiAtLockup),
sushiHarvestedSinceLockup: Number(entry.sushiHarvestedSinceLockup),
Expand Down
6 changes: 0 additions & 6 deletions queries/maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ module.exports = {
query: {
entity: 'servings',
selection: {
orderBy: 'block',
orderDirection: 'desc',
where: {
block_gte: minBlock || undefined,
block_lte: maxBlock || undefined,
Expand All @@ -52,10 +50,6 @@ module.exports = {
api: graphAPIEndpoints.maker,
query: {
entity: 'servers',
selection: {
orderBy: 'sushiServed',
orderDirection: 'desc',
},
block: block ? { number: block } : timestamp ? { number: await timestampToBlock(timestamp) } : undefined,
properties: servers.properties
},
Expand Down
34 changes: 21 additions & 13 deletions queries/masterchef.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module.exports = {
query: {
entity: 'pools',
selection: {
orderBy: 'id',
block: block ? { number: block } : timestamp ? { number: await timestampToBlock(timestamp) } : undefined,
},
properties: pools.properties
Expand Down Expand Up @@ -107,6 +106,21 @@ module.exports = {
.catch(err => console.log(err));
},

async users({block = undefined, timestamp = undefined} = {}) {
return pageResults({
api: graphAPIEndpoints.masterchef,
query: {
entity: 'users',
selection: {
block: block ? { number: block } : timestamp ? { number: await timestampToBlock(timestamp) } : undefined,
},
properties: user.properties
}
})
.then(results => user.callback(results))
.catch(err => console.log(err));
},

async apys({block = undefined, timestamp = undefined} = {}) {
const masterchefList = await module.exports.pools({block, timestamp});
const exchangeList = await exchangePairs({block, timestamp});
Expand Down Expand Up @@ -216,7 +230,7 @@ const pools = {
pair: pair,
allocPoint: Number(allocPoint),
lastRewardBlock: Number(lastRewardBlock),
accSushiPerShare: accSushiPerShare / 1e18,
accSushiPerShare: BigInt(accSushiPerShare),
userCount: Number(userCount),
slpBalance: Number(slpBalance),
slpAge: Number(slpAge),
Expand Down Expand Up @@ -263,34 +277,28 @@ const user = {
'rewardDebt',
'entryUSD',
'exitUSD',
'sushiAtLockup',
'sushiHarvested',
'sushiHarvestedUSD',
'sushiHarvestedSinceLockup',
'sushiHarvestedSinceLockupUSD',
],

callback(results) {
console.log(results)
return results.map(entry => ({
id: entry.id,
address: entry.address,
pool: {
poolId: Number(entry.id.split("-")[0]),
pool: entry.pool ? {
id: entry.pool.id,
pair: entry.pool.pair,
balance: Number(entry.pool.balance),
accSushiPerShare: Number(entry.pool.accSushiPerShare),
accSushiPerShare: BigInt(accSushiPerShare),
lastRewardBlock: Number(entry.pool.lastRewardBlock)
},
} : undefined,
amount: Number(entry.amount),
rewardDebt: Number(entry.rewardDebt),
rewardDebt: BigInt(entry.rewardDebt),
entryUSD: Number(entry.entryUSD),
exitUSD: Number(entry.exitUSD),
sushiAtLockup: Number(entry.sushiAtLockup),
sushiHarvested: Number(entry.sushiHarvested),
sushiHarvestedUSD: Number(entry.sushiHarvestedUSD),
sushiHarvestedSinceLockup: Number(entry.sushiHarvestedSinceLockup),
sushiHarvestedSinceLockupUSD: Number(entry.sushiHarvestedSinceLockupUSD)
}));
}
};
Expand Down
Loading

0 comments on commit c094ef1

Please sign in to comment.