-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
578 additions
and
665 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
import { GraphQLClient } from '../helpers/graphql'; | ||
import { | ||
TotalSupplyResponse, | ||
TotalStakedCoinsResponse, | ||
ActiveValidatorsResponse, | ||
} from '../types/bigDipper'; | ||
import { TotalSupplyResponse, TotalStakedCoinsResponse, ActiveValidatorsResponse } from '../types/bigDipper'; | ||
|
||
export class BigDipperApi { | ||
constructor(public readonly graphql_client: GraphQLClient) {} | ||
constructor(public readonly graphql_client: GraphQLClient) {} | ||
|
||
async getTotalSupply(): Promise<number> { | ||
let query = `query TotalSupply { | ||
async getTotalSupply(): Promise<number> { | ||
let query = `query TotalSupply { | ||
supply { | ||
coins | ||
} | ||
}`; | ||
|
||
let resp = await this.graphql_client.query<{ | ||
data: TotalSupplyResponse; | ||
}>(query); | ||
let resp = await this.graphql_client.query<{ | ||
data: TotalSupplyResponse; | ||
}>(query); | ||
|
||
return Number( | ||
resp.data.supply[0].coins.find((coin) => coin.denom === 'ncheq') | ||
?.amount || '0' | ||
); | ||
} | ||
return Number(resp.data.supply[0].coins.find((coin) => coin.denom === 'ncheq')?.amount || '0'); | ||
} | ||
|
||
getTotalStakedCoins = async (): Promise<string> => { | ||
let query = `query StakingInfo{ | ||
getTotalStakedCoins = async (): Promise<string> => { | ||
let query = `query StakingInfo{ | ||
staking_pool { | ||
bonded_tokens | ||
} | ||
}`; | ||
|
||
const resp = await this.graphql_client.query<{ | ||
data: TotalStakedCoinsResponse; | ||
}>(query); | ||
return resp.data.staking_pool[0].bonded_tokens; | ||
}; | ||
const resp = await this.graphql_client.query<{ | ||
data: TotalStakedCoinsResponse; | ||
}>(query); | ||
return resp.data.staking_pool[0].bonded_tokens; | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import { MarketMonitorData } from '../types/marketMonitor'; | ||
export class MarketMonitorApi { | ||
constructor(public readonly base_market_monitor_api_url: string) {} | ||
constructor(public readonly base_market_monitor_api_url: string) {} | ||
|
||
async getMarketMonitoringData(): Promise<MarketMonitorData> { | ||
const requestOptions = { | ||
method: 'GET', | ||
}; | ||
const response = await fetch( | ||
`${this.base_market_monitor_api_url}`, | ||
requestOptions | ||
); | ||
return (await response.json()) as MarketMonitorData; | ||
} | ||
async getMarketMonitoringData(): Promise<MarketMonitorData> { | ||
const requestOptions = { | ||
method: 'GET', | ||
}; | ||
const response = await fetch(`${this.base_market_monitor_api_url}`, requestOptions); | ||
return (await response.json()) as MarketMonitorData; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,79 +1,56 @@ | ||
import { | ||
Account, | ||
Coin, | ||
DelegationsResponse, | ||
UnbondingResponse, | ||
RewardsResponse | ||
} from '../types/node'; | ||
import { Account, Coin, DelegationsResponse, UnbondingResponse, RewardsResponse } from '../types/node'; | ||
|
||
export class NodeApi { | ||
constructor(public readonly base_rest_api_url: string) {} | ||
|
||
async getAccountInfo(address: string): Promise<Account> { | ||
let resp = await fetch( | ||
`${this.base_rest_api_url}/cosmos/auth/v1beta1/accounts/${address}` | ||
); | ||
let respJson = (await resp.json()) as { account: Account }; | ||
|
||
return respJson.account; | ||
} | ||
|
||
async getAvailableBalance(address: string): Promise<Coin[]> { | ||
let resp = await fetch( | ||
`${this.base_rest_api_url}/cosmos/bank/v1beta1/balances/${address}` | ||
); | ||
let respJson = (await resp.json()) as { balances: Coin[] }; | ||
|
||
return respJson.balances; | ||
} | ||
|
||
async distributionGetRewards(address: string): Promise<number> { | ||
let resp = await fetch( | ||
`${this.base_rest_api_url}/cosmos/distribution/v1beta1/delegators/${address}/rewards` | ||
); | ||
let respJson = (await resp.json()) as RewardsResponse; | ||
|
||
return Number(respJson?.total?.[0]?.amount ?? '0'); | ||
} | ||
|
||
async getAllDelegations( | ||
address: string, | ||
offset: number, | ||
should_count_total: boolean, | ||
limit?: number | ||
) { | ||
// order of query params: count_total -> offset -> limit | ||
const pagination_count_total = should_count_total | ||
? 'pagination.count_total=true' | ||
: 'pagination.count_total=false'; | ||
const pagination_limit = `pagination.limit=${ | ||
limit ? limit : REST_API_PAGINATION_LIMIT | ||
}`; | ||
const pagination_offset = `pagination.offset=${offset}`; | ||
// NOTE: be cautious of newlines or spaces. Might make the request URL malformed | ||
const resp = await fetch( | ||
`${this.base_rest_api_url}/cosmos/staking/v1beta1/delegations/${address}?${pagination_count_total}&${pagination_limit}&${pagination_offset}` | ||
); | ||
|
||
return (await resp.json()) as DelegationsResponse; | ||
} | ||
|
||
async getAllUnbondingDelegations( | ||
address: string, | ||
offset: number, | ||
should_count_total: boolean | ||
) { | ||
// order of query params: count_total -> offset -> limit | ||
const pagination_count_total = should_count_total | ||
? 'pagination.count_total=true' | ||
: 'pagination.count_total=false'; | ||
const pagination_limit = `pagination.limit=${REST_API_PAGINATION_LIMIT}`; | ||
const pagination_offset = `pagination.offset=${offset}`; | ||
// NOTE: be cautious of new lines or spaces. Might make the request URL malformed | ||
const resp = await fetch( | ||
`${this.base_rest_api_url}/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations?${pagination_count_total}&${pagination_limit}&${pagination_offset}` | ||
); | ||
|
||
return (await resp.json()) as UnbondingResponse; | ||
} | ||
constructor(public readonly base_rest_api_url: string) {} | ||
|
||
async getAccountInfo(address: string): Promise<Account> { | ||
let resp = await fetch(`${this.base_rest_api_url}/cosmos/auth/v1beta1/accounts/${address}`); | ||
let respJson = (await resp.json()) as { account: Account }; | ||
|
||
return respJson.account; | ||
} | ||
|
||
async getAvailableBalance(address: string): Promise<Coin[]> { | ||
let resp = await fetch(`${this.base_rest_api_url}/cosmos/bank/v1beta1/balances/${address}`); | ||
let respJson = (await resp.json()) as { balances: Coin[] }; | ||
|
||
return respJson.balances; | ||
} | ||
|
||
async distributionGetRewards(address: string): Promise<number> { | ||
let resp = await fetch(`${this.base_rest_api_url}/cosmos/distribution/v1beta1/delegators/${address}/rewards`); | ||
let respJson = (await resp.json()) as RewardsResponse; | ||
|
||
return Number(respJson?.total?.[0]?.amount ?? '0'); | ||
} | ||
|
||
async getAllDelegations(address: string, offset: number, should_count_total: boolean, limit?: number) { | ||
// order of query params: count_total -> offset -> limit | ||
const pagination_count_total = should_count_total | ||
? 'pagination.count_total=true' | ||
: 'pagination.count_total=false'; | ||
const pagination_limit = `pagination.limit=${limit ? limit : REST_API_PAGINATION_LIMIT}`; | ||
const pagination_offset = `pagination.offset=${offset}`; | ||
// NOTE: be cautious of newlines or spaces. Might make the request URL malformed | ||
const resp = await fetch( | ||
`${this.base_rest_api_url}/cosmos/staking/v1beta1/delegations/${address}?${pagination_count_total}&${pagination_limit}&${pagination_offset}` | ||
); | ||
|
||
return (await resp.json()) as DelegationsResponse; | ||
} | ||
|
||
async getAllUnbondingDelegations(address: string, offset: number, should_count_total: boolean) { | ||
// order of query params: count_total -> offset -> limit | ||
const pagination_count_total = should_count_total | ||
? 'pagination.count_total=true' | ||
: 'pagination.count_total=false'; | ||
const pagination_limit = `pagination.limit=${REST_API_PAGINATION_LIMIT}`; | ||
const pagination_offset = `pagination.offset=${offset}`; | ||
// NOTE: be cautious of new lines or spaces. Might make the request URL malformed | ||
const resp = await fetch( | ||
`${this.base_rest_api_url}/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations?${pagination_count_total}&${pagination_limit}&${pagination_offset}` | ||
); | ||
|
||
return (await resp.json()) as UnbondingResponse; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
declare global { | ||
const TOKEN_EXPONENT: number; | ||
const REST_API: string; | ||
const REST_API_PAGINATION_LIMIT: number; | ||
const GRAPHQL_API: string; | ||
const CIRCULATING_SUPPLY_WATCHLIST: KVNamespace; | ||
const CIRCULATING_SUPPLY_GROUPS: number; | ||
const MARKET_MONITORING_API: string; | ||
const WEBHOOK_URL: string; | ||
const TOKEN_EXPONENT: number; | ||
const REST_API: string; | ||
const REST_API_PAGINATION_LIMIT: number; | ||
const GRAPHQL_API: string; | ||
const CIRCULATING_SUPPLY_WATCHLIST: KVNamespace; | ||
const CIRCULATING_SUPPLY_GROUPS: number; | ||
const MARKET_MONITORING_API: string; | ||
const WEBHOOK_URL: string; | ||
} | ||
|
||
export {}; |
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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { MarketMonitorApi } from "../api/marketMonitorApi"; | ||
import { MarketMonitorApi } from '../api/marketMonitorApi'; | ||
|
||
export async function fetchPrices() { | ||
let market_monitor_api = new MarketMonitorApi( | ||
`${MARKET_MONITORING_API}` | ||
); | ||
return await market_monitor_api.getMarketMonitoringData(); | ||
let market_monitor_api = new MarketMonitorApi(`${MARKET_MONITORING_API}`); | ||
return await market_monitor_api.getMarketMonitoringData(); | ||
} | ||
export async function handler(request: Request): Promise<Response> { | ||
const payload = await fetchPrices(); | ||
return new Response(JSON.stringify(payload, null, 2), { | ||
headers: { | ||
"content-type": "application/json;charset=UTF-8", | ||
}, | ||
}); | ||
const payload = await fetchPrices(); | ||
return new Response(JSON.stringify(payload, null, 2), { | ||
headers: { | ||
'content-type': 'application/json;charset=UTF-8', | ||
}, | ||
}); | ||
} |
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
Oops, something went wrong.