Skip to content

Commit 08dfc49

Browse files
committed
feat: abacus abstractions
1 parent 6e81d06 commit 08dfc49

File tree

8 files changed

+162
-1
lines changed

8 files changed

+162
-1
lines changed

packages/exceptions/src/exceptions/types/modules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export enum IndexerErrorModule {
4444
ChronosSpot = 'indexer-chronos-spot',
4545
ChronosMarkets = 'indexer-chronos-markets',
4646
Campaign = 'indexer-campaign',
47-
Web3Gw = 'web3-gateway'
47+
Web3Gw = 'web3-gateway',
48+
Abacus = 'abacus'
4849
}
4950

5051
export enum WalletErrorActionModule {

packages/sdk-ts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
129129
"@injectivelabs/indexer-proto-ts": "1.13.3",
130130
"@injectivelabs/mito-proto-ts": "1.13.2",
131+
"@injectivelabs/abacus-proto-ts": "1.13.0",
131132
"@injectivelabs/networks": "^1.14.33",
132133
"@injectivelabs/olp-proto-ts": "1.13.1",
133134
"@injectivelabs/test-utils": "^1.14.34-beta.2",
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import {
2+
IndexerErrorModule,
3+
UnspecifiedErrorCode,
4+
GrpcUnaryRequestException,
5+
} from '@injectivelabs/exceptions'
6+
import { InjectiveAbacusRpc } from '@injectivelabs/abacus-proto-ts'
7+
import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
8+
import { AbacusGrpcTransformer } from './transformers/index.js'
9+
10+
export class AbacusGrpcApi extends BaseGrpcConsumer {
11+
protected module: string = IndexerErrorModule.Abacus
12+
13+
protected client: InjectiveAbacusRpc.PointsSvcClientImpl
14+
15+
constructor(endpoint: string) {
16+
super(endpoint)
17+
18+
this.client = new InjectiveAbacusRpc.PointsSvcClientImpl(
19+
this.getGrpcWebImpl(endpoint),
20+
)
21+
}
22+
23+
async fetchAccountLatestPoints(address: string) {
24+
const request = InjectiveAbacusRpc.PointsLatestForAccountRequest.create()
25+
26+
request.accountAddress = address
27+
28+
try {
29+
const response =
30+
await this.retry<InjectiveAbacusRpc.PointsLatestForAccountResponse>(
31+
() => this.client.PointsLatestForAccount(request),
32+
)
33+
34+
return AbacusGrpcTransformer.grpcPointsLatestToPointsLatest(response)
35+
} catch (e: unknown) {
36+
if (e instanceof InjectiveAbacusRpc.GrpcWebError) {
37+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
38+
code: e.code,
39+
context: 'PointsStatsLatestForAccount',
40+
contextModule: this.module,
41+
})
42+
}
43+
44+
throw new GrpcUnaryRequestException(e as Error, {
45+
code: UnspecifiedErrorCode,
46+
context: 'PointsStatsLatestForAccount',
47+
contextModule: this.module,
48+
})
49+
}
50+
}
51+
52+
async fetchAccountDailyPoints(address: string, daysLimit?: number) {
53+
const request =
54+
InjectiveAbacusRpc.PointsStatsDailyForAccountRequest.create()
55+
56+
request.accountAddress = address
57+
58+
if (daysLimit) {
59+
request.daysLimit = daysLimit
60+
}
61+
62+
try {
63+
const response =
64+
await this.retry<InjectiveAbacusRpc.PointsStatsDailyForAccountResponse>(
65+
() => this.client.PointsStatsDailyForAccount(request),
66+
)
67+
68+
return AbacusGrpcTransformer.grpcPointsStatsDailyToPointsStatsDaily(
69+
response,
70+
)
71+
} catch (e: unknown) {
72+
if (e instanceof InjectiveAbacusRpc.GrpcWebError) {
73+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
74+
code: e.code,
75+
context: 'PointsStatsDailyForAccount',
76+
contextModule: this.module,
77+
})
78+
}
79+
80+
throw new GrpcUnaryRequestException(e as Error, {
81+
code: UnspecifiedErrorCode,
82+
context: 'PointsStatsDailyForAccount',
83+
contextModule: this.module,
84+
})
85+
}
86+
}
87+
88+
async fetchAccountWeeklyPoints(address: string, weeksLimit?: number) {
89+
const request =
90+
InjectiveAbacusRpc.PointsStatsWeeklyForAccountRequest.create()
91+
92+
request.accountAddress = address
93+
94+
if (weeksLimit) {
95+
request.weeksLimit = weeksLimit
96+
}
97+
98+
try {
99+
const response =
100+
await this.retry<InjectiveAbacusRpc.PointsStatsWeeklyForAccountResponse>(
101+
() => this.client.PointsStatsWeeklyForAccount(request),
102+
)
103+
104+
return AbacusGrpcTransformer.grpcPointsStatsWeeklyToPointsStatsWeekly(
105+
response,
106+
)
107+
} catch (e: unknown) {
108+
if (e instanceof InjectiveAbacusRpc.GrpcWebError) {
109+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
110+
code: e.code,
111+
context: 'PointsStatsWeeklyForAccount',
112+
contextModule: this.module,
113+
})
114+
}
115+
116+
throw new GrpcUnaryRequestException(e as Error, {
117+
code: UnspecifiedErrorCode,
118+
context: 'PointsStatsWeeklyForAccount',
119+
contextModule: this.module,
120+
})
121+
}
122+
}
123+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { AbacusGrpcApi } from './AbacusGrpcApi.js'
2+
3+
export { AbacusGrpcApi }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { InjectiveAbacusRpc } from '@injectivelabs/abacus-proto-ts'
2+
3+
export class AbacusGrpcTransformer {
4+
static grpcPointsStatsDailyToPointsStatsDaily(
5+
response: InjectiveAbacusRpc.PointsStatsDailyForAccountResponse,
6+
) {
7+
return response.field
8+
}
9+
10+
static grpcPointsStatsWeeklyToPointsStatsWeekly(
11+
response: InjectiveAbacusRpc.PointsStatsWeeklyForAccountResponse,
12+
) {
13+
return response.field
14+
}
15+
16+
static grpcPointsLatestToPointsLatest(
17+
response: InjectiveAbacusRpc.PointsLatestForAccountResponse,
18+
) {
19+
return response
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './grpc/index.js'

packages/sdk-ts/src/client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './chain/index.js'
22
export * from './indexer/index.js'
33
export * from './wasm/index.js'
44
export * from './olp/index.js'
5+
export * from './abacus/index.js'

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,16 @@
21832183
resolved "https://registry.npmjs.org/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz#98c23c950a3d9b6c8f0daed06da6c3af06981340"
21842184
integrity sha512-H9XAx3hc0BQHY6l+IFSWHDySypcXsvsuLhgYLUGywmJ5pswRVQJUHpOsobnLYp2ZUaUlKiKDrgWWhosOwAEM8Q==
21852185

2186+
"@injectivelabs/[email protected]":
2187+
version "1.13.0"
2188+
resolved "https://registry.npmjs.org/@injectivelabs/abacus-proto-ts/-/abacus-proto-ts-1.13.0.tgz#cf5b0e683d9c51e01377f3137a2b8af65e798a13"
2189+
integrity sha512-yfMbTux7ljzDcmkKAZTHh3PuwjtlNfQ5PxFhEPO51gfQdRab0t3CqZ31rN+Q7LEaRMxZH/OxW2+ULLAUF07fsQ==
2190+
dependencies:
2191+
"@injectivelabs/grpc-web" "^0.0.1"
2192+
google-protobuf "^3.14.0"
2193+
protobufjs "^7.0.0"
2194+
rxjs "^7.4.0"
2195+
21862196
"@injectivelabs/[email protected]":
21872197
version "1.13.4"
21882198
resolved "https://registry.npmjs.org/@injectivelabs/core-proto-ts/-/core-proto-ts-1.13.4.tgz#c33568e471b8031ed66b1b954ac752f965e7f2bf"

0 commit comments

Comments
 (0)