diff --git a/README.md b/README.md index c33732c..1202171 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package-lock.json b/package-lock.json index 7049938..b095192 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@sushiswap/sushi-data", - "version": "1.0.6", + "version": "1.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2238,9 +2238,8 @@ "dev": true }, "graph-results-pager": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/graph-results-pager/-/graph-results-pager-1.0.3.tgz", - "integrity": "sha512-Dxh58jIlkhiK+siS0B45eGBc8dk1rukaJOGqLMgrst7bIYpJ52zxhHht6FhxX5JbVyXzmbXqecztr659ir0C6Q==", + "version": "git+https://github.com/LufyCZ/graph-results-pager.git#9b230f05b8d79aeedc9e167ac5a1fea33e04d51f", + "from": "git+https://github.com/LufyCZ/graph-results-pager.git", "requires": { "node-fetch": "2.6.1" }, diff --git a/package.json b/package.json index 6aae736..03ee392 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@sushiswap/sushi-data", "license": "MIT", - "version": "1.0.6", + "version": "1.0.7", "author": "SushiSwap", "main": "index", "scripts": { @@ -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", diff --git a/queries/exchange/factory.js b/queries/exchange/factory.js index 4c7923f..8445533 100644 --- a/queries/exchange/factory.js +++ b/queries/exchange/factory.js @@ -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), diff --git a/queries/exchange/pair.js b/queries/exchange/pair.js index fc74000..19832f5 100644 --- a/queries/exchange/pair.js +++ b/queries/exchange/pair.js @@ -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), @@ -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 }); @@ -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 @@ -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) { diff --git a/queries/exchange/token.js b/queries/exchange/token.js index 471edb9..a5aca19 100644 --- a/queries/exchange/token.js +++ b/queries/exchange/token.js @@ -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()} }`))} }` @@ -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), @@ -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 @@ -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) { @@ -311,4 +310,4 @@ const tokens = { txCount: Number(result.txCount) })); } -}; \ No newline at end of file +}; diff --git a/queries/lockup.js b/queries/lockup.js index 40338c1..4e4c36a 100644 --- a/queries/lockup.js +++ b/queries/lockup.js @@ -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), diff --git a/queries/maker.js b/queries/maker.js index 156e985..fcb1da6 100644 --- a/queries/maker.js +++ b/queries/maker.js @@ -30,8 +30,6 @@ module.exports = { query: { entity: 'servings', selection: { - orderBy: 'block', - orderDirection: 'desc', where: { block_gte: minBlock || undefined, block_lte: maxBlock || undefined, @@ -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 }, diff --git a/queries/masterchef.js b/queries/masterchef.js index 7a0fd06..fcf1360 100644 --- a/queries/masterchef.js +++ b/queries/masterchef.js @@ -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 @@ -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}); @@ -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), @@ -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) })); } }; diff --git a/queries/timelock.js b/queries/timelock.js index 7a5f1e8..b5ede4c 100644 --- a/queries/timelock.js +++ b/queries/timelock.js @@ -10,8 +10,6 @@ module.exports = { query: { entity: 'timelocks', selection: { - orderBy: 'createdBlock', - orderDirection: 'desc', where: { isCanceled: false, isExecuted: false, @@ -33,8 +31,6 @@ module.exports = { query: { entity: 'timelocks', selection: { - orderBy: 'createdBlock', - orderDirection: 'desc', where: { isCanceled: true, createdBlock_gte: minBlock || (minTimestamp ? await timestampToBlock(minTimestamp) : undefined), @@ -55,8 +51,6 @@ module.exports = { query: { entity: 'timelocks', selection: { - orderBy: 'createdBlock', - orderDirection: 'desc', where: { isExecuted: true, createdBlock_gte: minBlock || (minTimestamp ? await timestampToBlock(minTimestamp) : undefined), @@ -77,8 +71,6 @@ module.exports = { query: { entity: 'timelocks', selection: { - orderBy: 'createdBlock', - orderDirection: 'desc', where: { createdBlock_gte: minBlock || (minTimestamp ? await timestampToBlock(minTimestamp) : undefined), createdBlock_lte: maxBlock || (maxTimestamp ? await timestampToBlock(maxTimestamp) : undefined), @@ -109,22 +101,24 @@ const queuedTxs = { ], callback(results) { - return results.map(({ id, description, value, eta, functionName, data, targetAddress, createdBlock, createdTs, expiresTs, createdTx }) => ({ - txHash: id, - description: description, - value: Number(value), - etaTs: Number(eta * 1000), - etaDate: new Date(eta * 1000), - functionName: functionName, - data: data, - targetAddress: targetAddress, - createdBlock: Number(createdBlock), - createdTs: Number(createdTs * 1000), - createdDate: new Date(createdTs * 1000), - expiresTs: Number(expiresTs * 1000), - expiresDate: new Date(expiresTs * 1000), - createdTx: createdTx, - })); + return results + .map(({ id, description, value, eta, functionName, data, targetAddress, createdBlock, createdTs, expiresTs, createdTx }) => ({ + txHash: id, + description: description, + value: Number(value), + etaTs: Number(eta * 1000), + etaDate: new Date(eta * 1000), + functionName: functionName, + data: data, + targetAddress: targetAddress, + createdBlock: Number(createdBlock), + createdTs: Number(createdTs * 1000), + createdDate: new Date(createdTs * 1000), + expiresTs: Number(expiresTs * 1000), + expiresDate: new Date(expiresTs * 1000), + createdTx: createdTx, + })) + .sort((a, b) => b.createdBlock - a.createdBlock); } }; @@ -147,26 +141,28 @@ const canceledTxs = { ], callback(results) { - return results.map(({ id, description, value, eta, functionName, data, targetAddress, createdBlock, createdTs, expiresTs, canceledBlock, canceledTs, createdTx, canceledTx }) => ({ - txHash: id, - description: description, - value: Number(value), - etaTs: Number(eta * 1000), - etaDate: new Date(eta * 1000), - functionName: functionName, - data: data, - targetAddress: targetAddress, - createdBlock: Number(createdBlock), - createdTs: Number(createdTs * 1000), - createdDate: new Date(createdTs * 1000), - expiresTs: Number(expiresTs * 1000), - expiresDate: new Date(expiresTs * 1000), - canceledBlock: canceledTx ? Number(canceledBlock) : null, - canceledTs: canceledTx ? Number(canceledTs * 1000) : null, - canceledDate: canceledTx ? new Date(canceledTs * 1000) : null, - createdTx: createdTx, - canceledTx: canceledTx, - })); + return results + .map(({ id, description, value, eta, functionName, data, targetAddress, createdBlock, createdTs, expiresTs, canceledBlock, canceledTs, createdTx, canceledTx }) => ({ + txHash: id, + description: description, + value: Number(value), + etaTs: Number(eta * 1000), + etaDate: new Date(eta * 1000), + functionName: functionName, + data: data, + targetAddress: targetAddress, + createdBlock: Number(createdBlock), + createdTs: Number(createdTs * 1000), + createdDate: new Date(createdTs * 1000), + expiresTs: Number(expiresTs * 1000), + expiresDate: new Date(expiresTs * 1000), + canceledBlock: canceledTx ? Number(canceledBlock) : null, + canceledTs: canceledTx ? Number(canceledTs * 1000) : null, + canceledDate: canceledTx ? new Date(canceledTs * 1000) : null, + createdTx: createdTx, + canceledTx: canceledTx, + })) + .sort((a, b) => b.createdBlock - a.createdBlock); } }; @@ -189,26 +185,28 @@ const executedTxs = { ], callback(results) { - return results.map(({ id, description, value, eta, functionName, data, targetAddress, createdBlock, createdTs, expiresTs, executedBlock, executedTs, createdTx, executedTx }) => ({ - txHash: id, - description: description, - value: Number(value), - etaTs: Number(eta * 1000), - etaDate: new Date(eta * 1000), - functionName: functionName, - data: data, - targetAddress: targetAddress, - createdBlock: Number(createdBlock), - createdTs: Number(createdTs * 1000), - createdDate: new Date(createdTs * 1000), - expiresTs: Number(expiresTs * 1000), - expiresDate: new Date(expiresTs * 1000), - executedBlock: executedTx ? Number(executedBlock) : null, - executedTs: executedTx ? Number(executedTs * 1000) : null, - executedDate: executedTx ? new Date(executedTs * 1000) : null, - createdTx: createdTx, - executedTx: executedTx - })); + return results + .map(({ id, description, value, eta, functionName, data, targetAddress, createdBlock, createdTs, expiresTs, executedBlock, executedTs, createdTx, executedTx }) => ({ + txHash: id, + description: description, + value: Number(value), + etaTs: Number(eta * 1000), + etaDate: new Date(eta * 1000), + functionName: functionName, + data: data, + targetAddress: targetAddress, + createdBlock: Number(createdBlock), + createdTs: Number(createdTs * 1000), + createdDate: new Date(createdTs * 1000), + expiresTs: Number(expiresTs * 1000), + expiresDate: new Date(expiresTs * 1000), + executedBlock: executedTx ? Number(executedBlock) : null, + executedTs: executedTx ? Number(executedTs * 1000) : null, + executedDate: executedTx ? new Date(executedTs * 1000) : null, + createdTx: createdTx, + executedTx: executedTx + })) + .sort((a, b) => b.createdBlock - a.createdBlock);; } }; @@ -236,30 +234,32 @@ const allTxs = { ], callback(results) { - return results.map(({ id, description, value, eta, functionName, data, targetAddress, isCanceled, isExecuted, createdBlock, createdTs, expiresTs, canceledBlock, canceledTs, executedBlock, executedTs, createdTx, canceledTx, executedTx }) => ({ - txHash: id, - description: description, - value: Number(value), - etaTs: Number(eta * 1000), - etaDate: new Date(eta * 1000), - functionName: functionName, - data: data, - targetAddress: targetAddress, - isCanceled: isCanceled, - isExecuted: isExecuted, - createdBlock: Number(createdBlock), - createdTs: Number(createdTs * 1000), - createdDate: new Date(createdTs * 1000), - expiresTs: Number(expiresTs * 1000), - expiresDate: new Date(expiresTs * 1000), - canceledBlock: canceledTx ? Number(canceledBlock) : null, - canceledTs: canceledTx ? Number(canceledTs * 1000) : null, - canceledDate: canceledTx ? new Date(canceledTs * 1000) : null, - executedTs: executedTx ? Number(executedTs * 1000) : null, - executedDate: executedTx ? new Date(executedTs * 1000) : null, - createdTx: createdTx, - canceledTx: canceledTx, - executedTx: executedTx - })); + return results + .map(({ id, description, value, eta, functionName, data, targetAddress, isCanceled, isExecuted, createdBlock, createdTs, expiresTs, canceledBlock, canceledTs, executedBlock, executedTs, createdTx, canceledTx, executedTx }) => ({ + txHash: id, + description: description, + value: Number(value), + etaTs: Number(eta * 1000), + etaDate: new Date(eta * 1000), + functionName: functionName, + data: data, + targetAddress: targetAddress, + isCanceled: isCanceled, + isExecuted: isExecuted, + createdBlock: Number(createdBlock), + createdTs: Number(createdTs * 1000), + createdDate: new Date(createdTs * 1000), + expiresTs: Number(expiresTs * 1000), + expiresDate: new Date(expiresTs * 1000), + canceledBlock: canceledTx ? Number(canceledBlock) : null, + canceledTs: canceledTx ? Number(canceledTs * 1000) : null, + canceledDate: canceledTx ? new Date(canceledTs * 1000) : null, + executedTs: executedTx ? Number(executedTs * 1000) : null, + executedDate: executedTx ? new Date(executedTs * 1000) : null, + createdTx: createdTx, + canceledTx: canceledTx, + executedTx: executedTx + })) + .sort((a, b) => b.createdBlock - a.createdBlock); } }; diff --git a/typings/lockup.d.ts b/typings/lockup.d.ts index 558132b..cab317a 100755 --- a/typings/lockup.d.ts +++ b/typings/lockup.d.ts @@ -2,11 +2,11 @@ type User = { id: string, address: string, amount: number, - rewardDebt: number, + rewardDebt: bigint, pool: { id: string, balance: number, - accSushiPerShare: number + accSushiPerShare: bigint }, sushiAtLockup: number, sushiHarvestedSinceLockup: number, diff --git a/typings/masterchef.d.ts b/typings/masterchef.d.ts index d471434..9123fd8 100755 --- a/typings/masterchef.d.ts +++ b/typings/masterchef.d.ts @@ -28,7 +28,7 @@ type Pool = { pair: string, allocPoint: number, lastRewardBlock: number, - accSushiPerShare: number, + accSushiPerShare: bigint, userCount: number, slpBalance: number, slpAge: number, @@ -79,22 +79,20 @@ export function stakedValue({ block, timestamp, token_address }: { type User = { id: string, address: string, + poolId: number, pool: { id: string, pair: string, balance: number, - accSushiPerShare: number, + accSushiPerShare: bigint, lastRewardBlock: number - }, + } | undefined, amount: number, - rewardDebt: number, + rewardDebt: bigint, entryUSD: number, exitUSD: number, - sushiAtLockup: number, sushiHarvested: number, sushiHarvestedUSD: number, - sushiHarvestedSinceLockup: number, - sushiHarvestedSinceLockupUSD: number } export function user({ block, timestamp, user_address }: { @@ -103,6 +101,11 @@ export function user({ block, timestamp, user_address }: { user_address: string; }): Promise; +export function users({ block, timestamp }?: { + block?: number; + timestamp?: number; +}): Promise; + export function apys({ block, timestamp}?: { diff --git a/typings/utils.d.ts b/typings/utils.d.ts index f4a7e2e..1f02777 100644 --- a/typings/utils.d.ts +++ b/typings/utils.d.ts @@ -1,10 +1,10 @@ -export function timestampToBlock(timestmap: number): Promise; +export function timestampToBlock(timestmap: number): Promise; -export function timestampsToBlocks(timestamps: number[]): Promise; +export function timestampsToBlocks(timestamps: number[]): Promise; -export function blockToTimestamp(block: number): Promise; +export function blockToTimestamp(block: number): Promise; export function getAverageBlockTime({ block, timestamp }?: { block?: number; timestamp?: number; -}): Promise; \ No newline at end of file +}): Promise; \ No newline at end of file diff --git a/utils.js b/utils.js index c2bf637..8e466ff 100644 --- a/utils.js +++ b/utils.js @@ -85,24 +85,26 @@ async function getAverageBlockTime({block = undefined, timestamp = undefined} = } }) - const averageBlockTime = blocks.reduce( - (previousValue, currentValue, currentIndex) => { - if (previousValue.timestamp) { - const difference = previousValue.timestamp - currentValue.timestamp; - - previousValue.difference = previousValue.difference + difference; - } + const averageBlockTime = blocks + .sort((a, b) => Number(b.timestamp) - Number(a.timestamp)) + .reduce( + (previousValue, currentValue, currentIndex) => { + if (previousValue.timestamp) { + const difference = previousValue.timestamp - currentValue.timestamp; + + previousValue.difference = previousValue.difference + difference; + } - previousValue.timestamp = currentValue.timestamp; + previousValue.timestamp = currentValue.timestamp; - if (currentIndex === blocks.length - 1) { - return previousValue.difference / blocks.length; - } + if (currentIndex === blocks.length - 1) { + return previousValue.difference / blocks.length; + } - return previousValue; - }, - { timestamp: null, difference: 0 } - ); + return previousValue; + }, + { timestamp: null, difference: 0 } + ); return averageBlockTime; }