Skip to content

Commit

Permalink
Merge pull request #67 from compolabs/feat/add-points-query
Browse files Browse the repository at this point in the history
feat: add points
  • Loading branch information
EchoDex authored Feb 6, 2025
2 parents b41afc8 + d0e11ca commit 6d706ff
Show file tree
Hide file tree
Showing 5 changed files with 70 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": "@compolabs/spark-orderbook-ts-sdk",
"version": "1.14.15",
"version": "1.14.16",
"type": "module",
"main": "./dist/index.сjs",
"module": "./dist/index.js",
Expand Down
4 changes: 4 additions & 0 deletions src/SparkOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
GetSortedLeaderboardQueryParams,
GetTradeEventQueryParams,
GetTradeOrderEventsParams,
GetUserPointQueryParams,
GetUserScoreSnapshotParams,
GraphClientConfig,
MarketInfo,
Expand Down Expand Up @@ -382,6 +383,9 @@ export class SparkOrderbook {
return this.activeSentioApi.getSortedLeaderboardPnl(params);
}

async getUserPoints(params: GetUserPointQueryParams) {
return this.activeSentioApi.getUserPoints(params);
}
/**
* @experimental
* Returns the current instance to allow method chaining.
Expand Down
10 changes: 10 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ export interface GetLeaderboardPnlQueryParams {
wallets: string[];
}

export interface GetUserPointQueryParams {
userAddress: string;
toTimestamp: number;
fromTimestamp: number;
}

export interface UserPointsResponse {
result: string;
}

export interface GetSortedLeaderboardPnlQueryParams {
side: string;
timeline: string;
Expand Down
46 changes: 46 additions & 0 deletions src/query/sentioQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
GetSortedLeaderboardPnlQueryParams,
GetSortedLeaderboardQueryParams,
GetTradeEventQueryParams,
GetUserPointQueryParams,
GetUserScoreSnapshotParams,
LeaderboardPnlResponse,
RowSnapshot,
RowTradeEvent,
SentioApiParams,
TraderVolumeResponse,
UserPointsResponse,
} from "src/interface";
import { Fetch } from "src/utils/Fetch";

Expand Down Expand Up @@ -311,6 +313,40 @@ export class SentioQuery extends Fetch {
headers,
);
}

async getUserPoints({
userAddress,
fromTimestamp,
toTimestamp,
}: GetTradeEventQueryParams): Promise<GetSentioResponse<UserPointsResponse>> {
const sqlQuery: sqlQueryParams = {
sqlQuery: {
sql: `SELECT (total_volume / latest_volume) * 400000 AS result FROM
(SELECT
SUM(te.volume) AS total_volume,
(SELECT volume
FROM TotalVolume_raw
ORDER BY timestamp DESC
LIMIT 1) AS latest_volume
FROM
TradeEvent te
WHERE
(te.seller = '${userAddress}'
OR te.buyer = '${userAddress}')
AND te.timestamp BETWEEN '${fromTimestamp}' AND '${toTimestamp}'
) AS aggregated_data;`,
size: 10,
},
};
const headers: Record<string, string> = {
"api-key": this.apiKey,
};
return await this.post<GetSentioResponse<UserPointsResponse>>(
sqlQuery,
"same-origin",
headers,
);
}
}

export const getUserScoreSnapshotQuery = async (
Expand Down Expand Up @@ -372,3 +408,13 @@ export const getSortedLeaderboardPnlQuery = async (
...params,
});
};

export const getUserPointsQuery = async (
params: GetUserPointQueryParams & SentioApiParams,
): Promise<GetSentioResponse<UserPointsResponse>> => {
const { url, apiKey } = params;
const sentioQuery = new SentioQuery({ url, apiKey });
return await sentioQuery.getUserPoints({
...params,
});
};
9 changes: 9 additions & 0 deletions src/sentioApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getSortedLeaderboardPnlQuery,
getSortedLeaderboardQuery,
getTradeEventQuery,
getUserPointsQuery,
getUserScoreSnapshotQuery,
} from "./query/sentioQuery";
import {
Expand All @@ -12,6 +13,7 @@ import {
GetSortedLeaderboardPnlQueryParams,
GetSortedLeaderboardQueryParams,
GetTradeEventQueryParams,
GetUserPointQueryParams,
GetUserScoreSnapshotParams,
SentioApiParams,
} from "./interface";
Expand Down Expand Up @@ -75,4 +77,11 @@ export class SentioApi {
apiKey: this.apiKey,
});
};
getUserPoints = (params: GetUserPointQueryParams) => {
return getUserPointsQuery({
...params,
url: this.url,
apiKey: this.apiKey,
});
};
}

0 comments on commit 6d706ff

Please sign in to comment.