Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions examples/simple/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
import { Network } from '../../src/resources/graphql'
import { Defined } from '@definedfi/sdk'
import { Network } from "../../src/resources/graphql";
import { Defined } from "@definedfi/sdk";

const sdk = new Defined(process.env.DEFINED_API_KEY || "")
const sdk = new Defined(process.env.DEFINED_API_KEY || "");

sdk.send<{ getNetworks: Network[] }>(`query GetNetworks { getNetworks { id name } }`, {}).then(res => {
console.log("Networks: ", res.getNetworks)
})
sdk.queries.price({ inputs: [{ address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", networkId: 56 }]}).then(console.log)
sdk.queries.pairEvents({ query: { address: "0xd99c7f6c65857ac913a8f880a4cb84032ab2fc5b", networkId: 56 } }).then(console.log)
sdk.queries.sparklines({ input: { ids: ["0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c:56"] } }).then(console.log)
sdk.queries.token({ input: { address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", networkId: 56 } }).then(console.log)
sdk.queries.symbol({ symbol: "0xd99c7f6c65857ac913a8f880a4cb84032ab2fc5b:56" }).then(console.log)
sdk
.send<{ getNetworks: Network[] }>(
`query GetNetworks { getNetworks { id name } }`,
{}
)
.then((res) => {
console.log("Networks: ", res.getNetworks);
});
sdk.queries
.price({
inputs: [
{ address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", networkId: 56 },
],
})
.then(console.log);
sdk.queries
.pairEvents({
query: {
address: "0xd99c7f6c65857ac913a8f880a4cb84032ab2fc5b",
networkId: 56,
},
})
.then(console.log);
sdk.queries
.sparklines({
input: { ids: ["0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c:56"] },
})
.then(console.log);
sdk.queries
.token({
input: {
address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
networkId: 56,
},
})
.then(console.log);
sdk.queries
.symbol({ symbol: "0xd99c7f6c65857ac913a8f880a4cb84032ab2fc5b:56" })
.then(console.log);
sdk.queries.networks().then(console.log);
2 changes: 2 additions & 0 deletions src/sdk/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FilterTokensDocument,
FilterTokensQueryVariables,
GetBarsDocument,
GetNetworksDocument,
GetSparklinesDocument,
GetSparklinesQueryVariables,
GetSymbolDocument,
Expand Down Expand Up @@ -40,4 +41,5 @@ export class Query {
this.sdk.query(FilterExchangesDocument, vars);
symbol = async (vars: GetSymbolQueryVariables) =>
this.sdk.query(GetSymbolDocument, vars);
networks = async () => this.sdk.query(GetNetworksDocument);
}
5 changes: 5 additions & 0 deletions src/sdk/generated/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const documents = {
"query FilterExchanges($filters: ExchangeFilters, $phrase: String, $rankings: [ExchangeRanking], $limit: Int, $offset: Int) {\n filterExchanges(\n filters: $filters\n rankings: $rankings\n limit: $limit\n phrase: $phrase\n offset: $offset\n ) {\n results {\n exchange {\n address\n iconUrl\n name\n tradeUrl\n }\n dailyActiveUsers\n monthlyActiveUsers\n txnCount1\n volumeNBT12\n volumeUSD24\n }\n }\n}": types.FilterExchangesDocument,
"query FilterTokens($filters: TokenFilters, $phrase: String, $tokens: [String], $rankings: [TokenRanking], $limit: Int, $offset: Int) {\n filterTokens(\n filters: $filters\n phrase: $phrase\n tokens: $tokens\n rankings: $rankings\n limit: $limit\n offset: $offset\n ) {\n results {\n buyCount1\n buyCount4\n buyCount12\n buyCount24\n change1\n change4\n change12\n change24\n createdAt\n high1\n high4\n high12\n high24\n lastTransaction\n liquidity\n low1\n low4\n low12\n low24\n marketCap\n priceUSD\n quoteToken\n sellCount1\n sellCount4\n sellCount12\n sellCount24\n txnCount1\n txnCount4\n txnCount12\n txnCount24\n uniqueBuys1\n uniqueBuys4\n uniqueBuys12\n uniqueBuys24\n uniqueSells1\n uniqueSells4\n uniqueSells12\n uniqueSells24\n uniqueTransactions1\n uniqueTransactions4\n uniqueTransactions12\n uniqueTransactions24\n volume1\n volume4\n volume12\n volume24\n pair {\n token0\n token1\n pooled {\n token0\n token1\n }\n }\n token {\n address\n decimals\n name\n networkId\n symbol\n info {\n imageSmallUrl\n circulatingSupply\n totalSupply\n }\n }\n }\n }\n}": types.FilterTokensDocument,
"query GetBars($symbol: String!, $from: Int!, $to: Int!, $resolution: String!, $currencyCode: String, $quoteToken: QuoteToken) {\n getBars(\n symbol: $symbol\n from: $from\n to: $to\n resolution: $resolution\n currencyCode: $currencyCode\n quoteToken: $quoteToken\n ) {\n o\n h\n l\n c\n volume\n }\n}": types.GetBarsDocument,
"query GetNetworks {\n getNetworks {\n id\n name\n }\n}": types.GetNetworksDocument,
"query PairEvents($query: EventsQueryInput!) {\n pairEvents: getTokenEvents(query: $query) {\n cursor\n items {\n address\n baseTokenPrice\n blockHash\n blockNumber\n eventDisplayType\n eventType\n id\n liquidityToken\n maker\n networkId\n quoteToken\n token0PoolValueUsd\n token0SwapValueUsd\n timestamp\n token0ValueBase\n token1PoolValueUsd\n token1SwapValueUsd\n token1ValueBase\n transactionHash\n transactionIndex\n logIndex\n }\n }\n}": types.PairEventsDocument,
"query GetTokenPrice($inputs: [GetPriceInput]) {\n getTokenPrices(inputs: $inputs) {\n address\n networkId\n priceUsd\n }\n}": types.GetTokenPriceDocument,
"query GetSparklines($input: TokenSparklineInput!) {\n tokenSparklines(input: $input) {\n attribute\n id\n sparkline {\n timestamp\n value\n }\n }\n}": types.GetSparklinesDocument,
Expand Down Expand Up @@ -53,6 +54,10 @@ export function graphql(source: "query FilterTokens($filters: TokenFilters, $phr
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query GetBars($symbol: String!, $from: Int!, $to: Int!, $resolution: String!, $currencyCode: String, $quoteToken: QuoteToken) {\n getBars(\n symbol: $symbol\n from: $from\n to: $to\n resolution: $resolution\n currencyCode: $currencyCode\n quoteToken: $quoteToken\n ) {\n o\n h\n l\n c\n volume\n }\n}"): (typeof documents)["query GetBars($symbol: String!, $from: Int!, $to: Int!, $resolution: String!, $currencyCode: String, $quoteToken: QuoteToken) {\n getBars(\n symbol: $symbol\n from: $from\n to: $to\n resolution: $resolution\n currencyCode: $currencyCode\n quoteToken: $quoteToken\n ) {\n o\n h\n l\n c\n volume\n }\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query GetNetworks {\n getNetworks {\n id\n name\n }\n}"): (typeof documents)["query GetNetworks {\n getNetworks {\n id\n name\n }\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading