Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crosschain volume query #570

Merged
merged 4 commits into from
Jan 16, 2025
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
8 changes: 7 additions & 1 deletion examples/query_insights.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PositionViewOptions } from "../lib/insights";
import * as BIP39 from "bip39";
import { CarbonSDK } from "./_sdk";
import dayjs from "dayjs";

(async () => {
const mnemonics = process.env.MNEMONICS ?? BIP39.generateMnemonic();
const sdk = await CarbonSDK.instance({
network: CarbonSDK.Network.DevNet,
network: CarbonSDK.Network.MainNet,
config: {
tmRpcUrl: process.env.TRPC_ENDPOINT,
},
Expand Down Expand Up @@ -118,4 +119,9 @@ import { CarbonSDK } from "./_sdk";
const fundingHistoryGraphData = await sdk.insights.FundingHistoryGraphData({ market: 'cmkt/117' })
console.log("fundingHistoryGraphData", fundingHistoryGraphData)

// Crosschain Volumes Data
const twoWeeksAgoUnix = dayjs().subtract(2, 'weeks').unix().toString()
const crosschainVolumesData = await sdk.insights.CrosschainVolumes({ from: twoWeeksAgoUnix })
console.log("crosschainVolumesData", crosschainVolumesData)

})().catch(console.error).finally(() => process.exit(0));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carbon-js-sdk",
"version": "0.11.39",
"version": "0.11.40-beta.1",
"description": "TypeScript SDK for Carbon blockchain",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
8 changes: 7 additions & 1 deletion src/clients/InsightsQueryClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NetworkConfig } from "@carbon-sdk/constant";
import { Insights } from "@carbon-sdk/index";
import { ConnectedWalletParams, ConnectedWalletResponse, InsightsQueryResponse } from "@carbon-sdk/insights";
import { ConnectedWalletParams, ConnectedWalletResponse, CrossChainVolume, InsightsQueryResponse } from "@carbon-sdk/insights";
import { APIUtils } from "@carbon-sdk/util";
import BigNumber from "bignumber.js";
import dayjs from "dayjs";
Expand Down Expand Up @@ -621,6 +621,12 @@ class InsightsQueryClient {
const response = await request.get();
return response.data as Insights.InsightsQueryResponse<Insights.QueryGetAlliancesRewardsResponse>;
}

async CrosschainVolumes(req: Insights.QueryCrosschainVolumeRequest = {}): Promise<Insights.InsightsQueryResponse<CrossChainVolume[]>> {
const request = this.apiManager.path("crosschain/volume", {}, req)
const response = await request.get()
return response.data as Insights.InsightsQueryResponse<CrossChainVolume[]>
}
andrewsoon marked this conversation as resolved.
Show resolved Hide resolved
}

export default InsightsQueryClient;
3 changes: 3 additions & 0 deletions src/insights/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export const InsightsEndpoints = {
"alliances/stake": "/alliances/stake",
"alliances/rewards": "/alliances/rewards",

// Crosschain api
"crosschain/volume": "/crosschain/volume",

"reward/epoch": "/reward/epoch/:epoch/:unixStart",
"reward/leaderboard": "/reward/:unixStart/:unixEnd/leaderboard",
};
Expand Down
12 changes: 12 additions & 0 deletions src/insights/crosschain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { QueryByTimeRequest } from "./common";


export interface QueryCrosschainVolumeRequest extends QueryByTimeRequest { }

export interface CrossChainVolume {
absoluteVolume: string
netVolume: string
inflow: string
outflow: string
denom: string
}
1 change: 1 addition & 0 deletions src/insights/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./balance";
export * from "./common";
export * from "./crosschain";
export * from "./node";
export * from "./pool";
export * from "./position";
Expand Down