Skip to content

Commit

Permalink
Merge pull request #85 from clober-dex/feat/sync-block
Browse files Browse the repository at this point in the history
feat: add `getSubgraphBlockNumber` function
  • Loading branch information
graykode authored Jul 29, 2024
2 parents 5c2124a + dc11d70 commit 98d1e87
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clober/v2-sdk",
"version": "0.0.57",
"version": "0.0.58",
"description": "🛠 An SDK for building applications on top of Clober V2",
"files": [
"dist"
Expand Down
41 changes: 41 additions & 0 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getMarketId } from './utils/market'
import { CONTRACT_ADDRESSES } from './constants/addresses'
import { invertTick, toPrice } from './utils/tick'
import { MAX_TICK, MIN_TICK } from './constants/tick'
import { Subgraph } from './constants/subgraph'

/**
* Get contract addresses by chain id
Expand All @@ -36,6 +37,46 @@ export const getContractAddresses = ({ chainId }: { chainId: CHAIN_IDS }) => {
return CONTRACT_ADDRESSES[chainId]
}

/**
* Get subgraph block number by chain id
* @param chainId - chain id from {@link CHAIN_IDS}
* @returns Contract addresses
*
* @example
* import { getContractAddresses } from '@clober/v2-sdk'
*
* const blockNumber = await getSubgraphBlockNumber({
* chainId: 421614,
* })
*/
export const getSubgraphBlockNumber = async ({
chainId,
}: {
chainId: CHAIN_IDS
}) => {
const {
data: {
_meta: {
block: { number },
},
},
} = await Subgraph.get<{
data: {
_meta: {
block: {
number: number
}
}
}
}>(
chainId,
'getLatestBlockNumber',
'query getLatestBlockNumber { _meta { block { number } } }',
{},
)
return number
}

/**
* Get market information by chain id and token addresses
* @param chainId - chain id from {@link CHAIN_IDS}
Expand Down

0 comments on commit 98d1e87

Please sign in to comment.