Skip to content

Commit 5d01d69

Browse files
feat: Remove market monitoring API and update documentation for identity analytics [DEV-4788] (#271)
* chore: Update docs & remove MM API && fix ledgerDenom querying * fix linter error * Fix querying by ledgerOperationType * Update text --------- Co-authored-by: Ankur Banerjee <ankurdotb@users.noreply.github.com>
1 parent 15a2ec9 commit 5d01d69

8 files changed

Lines changed: 73 additions & 94 deletions

File tree

README.md

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,86 @@ Total account balance for specified account, in CHEQ.
120120

121121
The standard Cosmos SDK REST API for account balances returns JSON with the account balances along with its denomination, usually the lowest denomination. This is hard to parse in applications such as Google Sheets (e.g., to monitor the account balance by fetching a response from a REST API directly in Google Sheets). This API returns a plain number that can be directly plugged into such applications, without having to parse JSON.
122122

123-
### 🚨 Arbitrage
123+
### 📊 Identity Analytics
124124

125-
#### Endpoint
125+
#### Endpoints
126+
127+
##### Mainnet
128+
129+
* **DID Documents**: [`data-api.cheqd.io/analytics/mainnet/did`](https://data-api.cheqd.io/analytics/mainnet/did)
130+
* **DID-Linked Resources (DLRs)**: [`data-api.cheqd.io/analytics/mainnet/resource`](https://data-api.cheqd.io/analytics/mainnet/resource)
131+
* **DIDs and DLRs combined** (harder to paginate): [`data-api.cheqd.io/analytics/mainnet`](https://data-api.cheqd.io/analytics/mainnet)
132+
133+
##### Testnet
126134

127-
- Results filtered by threshold value: [`data-api.cheqd.io/arbitrage`](https://data-api.cheqd.io/arbitrage)
128-
- Unfiltered results: [`data-api.cheqd.io/arbitrage/all`](https://data-api.cheqd.io/arbitrage/all)
135+
* **DID Documents**: [`data-api.cheqd.io/analytics/testnet/did`](https://data-api.cheqd.io/analytics/testnet/did)
136+
* **DID-Linked Resources (DLRs)**: [`data-api.cheqd.io/analytics/testnet/resource`](https://data-api.cheqd.io/analytics/mainnet/resource)
137+
* **DIDs and DLRs combined** (harder to paginate): [`data-api.cheqd.io/analytics/testnet`](https://data-api.cheqd.io/analytics/mainnet)
129138

130139
#### Response
131140

132-
Returns current price of CHEQ token among different markets along with an evaluation of whether they are at risk of arbitrage opportunities.
141+
Returns the identity transactions data for the specified network in JSON format.
142+
By default, the endpoint returns the data for the **last 30 days**.
143+
144+
If `did` or `resource` is not specified, it will both DID and DLR analytics data, sorted by date in descending order.
145+
By default, the response is paginated with a limit of **100 results per page**. It's harder to paginate through responses on the combined endpoints, so where possible it is recommended to query DIDs and DLRs separately.
146+
147+
#### Optional Query Parameters
148+
149+
These optional query paramaters can be used to filter the results that are returned from the API.
150+
151+
* `startDate`: Start date for the analytics data. If you provide *just* this parameter, the *current* date will be considered the end date.
152+
* `endDate`: End date for the analytics data. If you provide *just* this parameter, the start date will be considered as 30 days prior to this date.
153+
* `operationType`: Operation type for the analytics data. It accepts the following values:
154+
* `createDid`
155+
* `updateDid`
156+
* `deactivateDid`
157+
* `createResource`
158+
* `ledgerOperationType`: Ledger operation type for the analytics data. (Only relevant if the underlying operation types on ledger go through a breaking change in version number and you want to filter by specific operation type. Otherwise, use above.)
159+
* `cheqd.did.v2.MsgCreateDid`
160+
* `cheqd.did.v2.MsgUpdateDid`
161+
* `cheqd.did.v2.MsgDeactivateDid`
162+
* `cheqd.resource.v2.MsgCreateResource`
163+
* `denom`: Friendly denomination used for paying fees, e.g. `CHEQ` or `USDC`. Note that by default the results are returned in **main denomination**, i.e., the on-ledger value in `ncheq` is convert to CHEQ.
164+
* `ledgerDenom`: Ledger denomination used for paying fees, e.g. `ncheq` or `ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4`.
165+
* `feePayer`: Fee payer address, e.g., `cheqd1...xx`.
166+
* `success` (boolean; default: `true`): Whether transaction was successful or not. By default, only successful transactions are returned. Allows for specifically fetching failed transaction details.
167+
* `page` (default: `1`): Page number for pagination.
168+
* `limit` (default: `100`): Number of results per page.
133169

134170
#### Rationale
135171

136-
The CHEQ token trades on multiple markets/exchanges (e.g., [Osmosis](https://app.osmosis.zone), [Gate.io](https://www.gate.io/trade/CHEQ_USDT), [BitMart](https://www.bitmart.com/trade/en?layout=basic&symbol=CHEQ_USDT), [LBank](https://www.lbank.info/exchange/cheq/usdt), [Uniswap](https://app.uniswap.org/#/swap?inputCurrency=0x70edf1c215d0ce69e7f16fd4e6276ba0d99d4de7&outputCurrency=0xdac17f958d2ee523a2206206994597c13d831ec7&chain=mainnet)). This is typically established as CHEQ along with another token pair or currency.
172+
The purpose of this API is to provide more granular data and help us to understand the usage of identity modules and how they are used by the community.
137173

138-
Fluctuations in the exchange rate between CHEQ and other tokens pairs can give rise to opportunities for arbitrage. Having a significant market arbitrage among different exchanges creates a [market inefficiencies](https://www.investopedia.com/terms/i/inefficientmarket.asp). Extreme market inefficiencies result [market failure](https://www.investopedia.com/terms/m/marketfailure.asp) and [deadweight loss](https://www.investopedia.com/terms/d/deadweightloss.asp).
174+
#### Example
139175

140-
Having monitoring capabilities for arbitrage gives opportunities for the cheqd community to rectify potential liquidity issues and aware of exchange rate movements.
141-
142-
#### Alerting via Zapier
176+
```bash
177+
curl -X GET "https://data-api.cheqd.io/analytics/mainnet?startDate=2024-01-01&endDate=2024-01-31&operationType=createDid&denom=CHEQ&&success=true&limit=1"
178+
```
143179

144-
To alert a significant market arbitrages for CHEQ listings on different exchanges, we pull latest markets data from the [CoinGecko API for cheqd's ticker page](https://www.coingecko.com/en/coins/cheqd-network) via our Market Monitoring API [Monitor Markets API](https://github.com/cheqd/market-monitoring). If an arbitrage threshold is exceeded, a webhook trigger is sent to [Zapier](https://zapier.com/) for alerting via different channels (such as Slack).
180+
Response:
181+
182+
```json
183+
{
184+
"items": [
185+
{
186+
"didId": "did:cheqd:mainnet:f1a32c8b-bd76-450d-b5c2-46b1b92db74d",
187+
"operationType": "createDid",
188+
"feePayer": "cheqd15yqrljq6h7u8et30hqrwwaz8f9m62jvztlpc9t",
189+
"amount": 50,
190+
"denom": "CHEQ",
191+
"blockHeight": "11709907",
192+
"transactionHash": "36EEBB3E4551CC9BB1A70FACB9775AB8DD12F5ABF931A60322558C03F91822B9",
193+
"createdAt": "2024-01-25T19:49:35.093Z",
194+
"success": true
195+
}
196+
],
197+
"totalCount": 7,
198+
"page": 1,
199+
"limit": 1,
200+
"totalPages": 7
201+
}
202+
```
145203

146204
## 🧑‍💻🛠 Developer Guide
147205

src/handlers/allArbitrageOpportunities.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/handlers/arbitrageOpportunities.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/handlers/webhookTriggers.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { updateCirculatingSupply } from '../helpers/circulating';
2-
import { filterArbitrageOpportunities } from './arbitrageOpportunities';
32
import { Network } from '../types/network';
43
import { syncNetworkData } from '../helpers/identity';
54

65
export async function webhookTriggers(env: Env) {
76
console.log('Triggering webhook...');
8-
await sendPriceDiscrepancies(env);
97

108
await updateCirculatingSupply(getHour(), env);
119
await syncIdentityData(env);
@@ -22,35 +20,6 @@ export async function syncIdentityData(env: Env) {
2220
}
2321
}
2422

25-
export async function sendPriceDiscrepancies(env: Env) {
26-
try {
27-
console.log('Sending price discrepancies...');
28-
29-
const arbitrageOpportunities = await filterArbitrageOpportunities(env);
30-
const hasArbitrageOpportunities = arbitrageOpportunities.length > 0;
31-
if (hasArbitrageOpportunities) {
32-
console.log('Arbitrage opportunities...');
33-
try {
34-
const init = {
35-
body: JSON.stringify({
36-
arbitrage_opportunities: arbitrageOpportunities,
37-
}),
38-
method: 'POST',
39-
headers: {
40-
'content-type': 'application/json;charset=UTF-8',
41-
},
42-
};
43-
44-
await fetch(env.WEBHOOK_URL, init);
45-
} catch (err: any) {
46-
console.log(err);
47-
}
48-
}
49-
} catch (e) {
50-
console.log('Error at: ', 'sendPriceDiscrepancies');
51-
}
52-
}
53-
5423
function getHour(): number {
5524
// This function only works when CIRCULATING_SUPPLY_GROUPS is set to 24
5625
let hour = Number(new Date().getHours() + 1); // getHours() returns 0-23

src/helpers/analytics.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DrizzleClient } from '../database/client';
1414
import { serializeBigInt } from './csv';
1515
import { Network } from '../types/network';
1616
import { validateDateRange } from './validate';
17-
17+
import { DenomType, OperationType } from '../types/bigDipper';
1818
export const DEFAULT_LIMIT = 100;
1919

2020
// Network-based table mapping
@@ -59,11 +59,11 @@ export function buildQueryConditions(
5959
}
6060

6161
if (params.ledgerOperationType !== null) {
62-
conditions.push(ilike(operationTypesTable.ledgerOperationType, params.ledgerOperationType));
62+
conditions.push(eq(operationTypesTable.ledgerOperationType, params.ledgerOperationType as OperationType));
6363
}
6464

6565
if (params.ledgerDenom !== null) {
66-
conditions.push(ilike(denomTable.ledgerDenom, params.ledgerDenom));
66+
conditions.push(eq(denomTable.ledgerDenom, params.ledgerDenom as DenomType));
6767
}
6868

6969
if (params.denom !== null) {

src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ import { handler as liquidBalanceHandler } from './handlers/liquidBalance';
66
import { handler as vestingBalanceHandler } from './handlers/vestingBalance';
77
import { handler as vestedBalanceHandler } from './handlers/vestedBalance';
88
import { handler as totalStakedCoinsHandler } from './handlers/totalStakedCoins';
9-
import { handler as allArbitrageOpportunitiesHandler } from './handlers/allArbitrageOpportunities';
10-
import { handler as arbitrageOpportunitiesHandler } from './handlers/arbitrageOpportunities';
119
import { webhookTriggers } from './handlers/webhookTriggers';
1210
import { registerAnalyticsRoutes } from './routes/analytics';
1311

1412
function registerRoutes(router: ReturnType<typeof Router>, env: Env, ctx: ExecutionContext) {
1513
router.get('/', (request) => totalSupplyHandler(request, env));
16-
router.get('/arbitrage', (request) => arbitrageOpportunitiesHandler(request, env));
17-
router.get('/arbitrage/all', (request) => allArbitrageOpportunitiesHandler(request, env));
1814
router.get('/balances/liquid/:address', (request) => liquidBalanceHandler(request, env));
1915
router.get('/balances/total/:address', (request) => totalBalanceHandler(request, env));
2016
router.get('/balances/vested/:address', (request) => vestedBalanceHandler(request, env));

src/worker-types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ declare global {
77
GRAPHQL_API: string;
88
TESTNET_GRAPHQL_API: string;
99
CIRCULATING_SUPPLY_GROUPS: string;
10-
MARKET_MONITORING_API: string;
1110
ENVIRONMENT: string;
1211
BIGDIPPER_URL: string;
1312
WEBHOOK_URL: string;

wrangler.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ TESTNET_GRAPHQL_API = "https://testnet-gql.cheqd.io/v1/graphql"
5353
# Number of groups circulating supply watchlist is split into
5454
CIRCULATING_SUPPLY_GROUPS = "24"
5555
# Market monitoring API endpoint
56-
MARKET_MONITORING_API = "https://market-monitoring.cheqd.net"
5756
ENVIRONMENT = "production"
5857

5958
# The necessary secrets are:
@@ -103,7 +102,7 @@ route = { pattern = "data-api-staging.cheqd.io/*", zone_id = "afe3b66243382f2714
103102

104103
# Map of environment variables to set when deploying the Worker
105104
# Not inherited. @default `{}`
106-
vars = { ENVIRONMENT = "staging", TOKEN_EXPONENT = 9, REST_API = "https://api.cheqd.net", REST_API_PAGINATION_LIMIT = "50", GRAPHQL_API = "https://explorer-gql.cheqd.io/v1/graphql", CIRCULATING_SUPPLY_GROUPS = "24", MARKET_MONITORING_API = "https://market-monitoring-staging.cheqd.net", TESTNET_GRAPHQL_API = "https://testnet-gql.cheqd.io/v1/graphql" }
105+
vars = { ENVIRONMENT = "staging", TOKEN_EXPONENT = 9, REST_API = "https://api.cheqd.net", REST_API_PAGINATION_LIMIT = "50", GRAPHQL_API = "https://explorer-gql.cheqd.io/v1/graphql", CIRCULATING_SUPPLY_GROUPS = "24", TESTNET_GRAPHQL_API = "https://testnet-gql.cheqd.io/v1/graphql" }
107106

108107
# The necessary secrets are:
109108
# - WEBHOOK_URL

0 commit comments

Comments
 (0)