Skip to content

Commit 10b8712

Browse files
authored
Merge pull request #17 from NEAR-DevHub/improvements
Optimisation and fallbacks
2 parents e80843d + a16c630 commit 10b8712

File tree

19 files changed

+662
-759
lines changed

19 files changed

+662
-759
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Twice Weekly Production API Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
- cron: "0 9 * * 1" # Every Monday at 09:00 UTC
12+
- cron: "0 9 * * 4" # Every Thursday at 09:00 UTC
13+
workflow_dispatch: # Allow manual trigger from GitHub UI
14+
15+
jobs:
16+
production-test:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Use Node.js
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: "18"
27+
28+
- name: Install dependencies
29+
run: yarn install --frozen-lockfile
30+
31+
- name: Run Production Tests
32+
run: npm test test/production.test.ts
33+
34+
- name: Report Success
35+
if: success()
36+
run: echo "Production test suite completed."
37+
38+
- name: Report Failure
39+
if: failure()
40+
run: echo "Production test suite failed!"

README.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,6 @@ By default, the server will run on `http://127.0.0.1:3000` (or as specified by t
110110

111111
## API Endpoints
112112

113-
### Get Token Metadata
114-
115-
- **Endpoint:** `GET /api/token-metadata`
116-
- **Query Parameters:**
117-
- `token` (string, required): The token ID for which to retrieve metadata.
118-
- **Response:** JSON object containing metadata for the token.
119-
- **Example:**
120-
121-
```http
122-
GET /api/token-metadata?token=near
123-
```
124-
125-
---
126-
127113
### Whitelist Tokens
128114

129115
- **Endpoint:** `GET /api/whitelist-tokens`
@@ -201,19 +187,6 @@ By default, the server will run on `http://127.0.0.1:3000` (or as specified by t
201187

202188
---
203189

204-
### Clear Token Balance History
205-
206-
- **Endpoint:** `DELETE /api/clear-token-balance-history`
207-
- **Description:** Removes all `TokenBalanceHistory` records from the database.
208-
- **Response:** JSON message confirming deletion.
209-
- **Example:**
210-
211-
```http
212-
DELETE /api/clear-token-balance-history
213-
```
214-
215-
---
216-
217190
### Transactions Transfer History
218191

219192
- **Endpoint:** `GET /api/transactions-transfer-history`
@@ -230,12 +203,13 @@ By default, the server will run on `http://127.0.0.1:3000` (or as specified by t
230203

231204
## Caching & Rate Limiting
232205

233-
- **Caching:**
206+
- **Caching:**
207+
234208
- The API uses [NodeCache](https://www.npmjs.com/package/node-cache) to store short-term responses (e.g., NEAR prices and token balance histories) to reduce external API calls and recomputation.
235209
- RPC calls (in `src/utils/fetch-from-rpc.ts`) also cache responses and skip endpoints temporarily on rate-limited (HTTP 429) responses.
236210

237-
- **Rate Limiting:**
238-
- All `/api/*` endpoints are limited to 180 requests per 30 seconds per IP (or forwarded IP when available).
211+
- **Rate Limiting:**
212+
- All `/api/*` endpoints are limited to 180 requests per 30 seconds per IP (or forwarded IP when available).
239213
- This helps protect against abuse and ensures service stability.
240214

241215
---
@@ -257,4 +231,4 @@ This project is licensed under the MIT License. See [LICENSE](LICENSE) for more
257231

258232
---
259233

260-
*For additional questions or contributions, please open an issue or submit a PR on GitHub.*
234+
_For additional questions or contributions, please open an issue or submit a PR on GitHub._

prisma/migrations/20250131194148_init/migration.sql

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

prisma/migrations/20250205121547_rpc_requests/migration.sql

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

prisma/migrations/20250205124152_token_history_per_period/migration.sql

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

prisma/migrations/20250205125343_remove_unique_requesthash/migration.sql

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

prisma/migrations/20250205130002_account_block_existence/migration.sql

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

prisma/migrations/migration_lock.toml

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

prisma/schema.prisma

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ model TokenBalanceHistory {
1717
id String @id @default(uuid())
1818
account_id String
1919
token_id String
20-
period String @default("1Y")
21-
balance_history Json
20+
period String // e.g., "1Y", "1M", "1W", etc.
21+
balance_history Json // Array of { timestamp, date, balance }
22+
fromBlock Int // oldest block in the history
23+
toBlock Int // latest block stored for this period
2224
timestamp DateTime @default(now())
2325
24-
@@index([account_id, token_id, period, timestamp])
26+
@@index([account_id, token_id, period])
27+
@@unique([account_id, token_id, period], name: "account_id_token_id_period")
2528
}
2629

30+
2731
model RpcRequest {
2832
id String @id @default(uuid())
2933
requestHash String
@@ -60,3 +64,9 @@ model AccountBlockExistence {
6064
@@unique([accountId, blockHeight])
6165
@@index([accountId, blockHeight])
6266
}
67+
68+
model TransferHistory {
69+
cacheKey String @id
70+
data Json
71+
timestamp DateTime @default(now())
72+
}

script/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ interface EndpointResponse {
2323
}
2424

2525
const endpoints = [
26-
// '/api/token-metadata',
2726
// '/api/whitelist-tokens', I made some changes to whitelist-tokens so they differ
2827
"/api/swap",
2928
"/api/near-price",

0 commit comments

Comments
 (0)