Skip to content
Closed
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
2 changes: 1 addition & 1 deletion packages/sdk-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
"@injectivelabs/mito-proto-ts-v2": "1.17.3",
"@injectivelabs/networks": "workspace:*",
"@injectivelabs/olp-proto-ts-v2": "1.17.6",
"@injectivelabs/tc-abacus-proto-ts-v2": "1.18.2",
"@injectivelabs/tc-abacus-proto-ts-v2": "1.18.4",
"@injectivelabs/ts-types": "workspace:*",
"@injectivelabs/utils": "workspace:*",
"@noble/curves": "catalog:",
Expand Down
44 changes: 44 additions & 0 deletions packages/sdk-ts/src/client/tcAbacus/grpc/TcAbacusGrpcApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,48 @@ export class TcAbacusGrpcApi extends BaseGrpcConsumer {
response,
)
}

async fetchReferrerEligibility(address: string) {
const request = TcAbacusPb.GetReferrerElegibilityRequest.create({
address,
})

const response = await this.executeGrpcCall<
TcAbacusPb.GetReferrerElegibilityRequest,
TcAbacusPb.GetReferrerElegibilityResponse
>(request, this.client.getReferrerElegibility.bind(this.client))

return TcAbacusGrpcTransformer.grpcReferrerEligibilityToReferrerEligibility(
response,
)
}

async createReferrerCode(address: string, code: string) {
const request = TcAbacusPb.CreateReferrerCodeRequest.create({
code,
address,
})

await this.executeGrpcCall<
TcAbacusPb.CreateReferrerCodeRequest,
TcAbacusPb.CreateReferrerCodeResponse
>(request, this.client.createReferrerCode.bind(this.client))
}

async fetchReferrerCodes(address: string, cursor?: string, limit?: number) {
const request = TcAbacusPb.ListReferrerCodesRequest.create({
limit,
cursor,
address,
})

const response = await this.executeGrpcCall<
TcAbacusPb.ListReferrerCodesRequest,
TcAbacusPb.ListReferrerCodesResponse
>(request, this.client.listReferrerCodes.bind(this.client))

return TcAbacusGrpcTransformer.grpcListReferrerCodesToListReferrerCodes(
response,
)
}
}
36 changes: 36 additions & 0 deletions packages/sdk-ts/src/client/tcAbacus/grpc/transformers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as TcAbacusPb from '@injectivelabs/tc-abacus-proto-ts-v2/generated/injective_tc_abacus_rpc_pb'
import type {
Referrer,
ReferrerCode,
SnapshotPoints,
ReferrerInvitee,
HealthCheckResponse,
Expand All @@ -9,6 +10,8 @@ import type {
AccountPointsResponse,
ListReferrersResponse,
AccountInviteesResponse,
ListReferrerCodesResponse,
ReferrerEligibilityResponse,
} from '../../types/index.js'

export class TcAbacusGrpcTransformer {
Expand All @@ -18,6 +21,7 @@ export class TcAbacusGrpcTransformer {
return {
epochEnd: response.epochEnd,
epochPoints: response.epochPoints,
epochPointsDistributedAt: response.epochPointsDistributedAt,
}
}

Expand Down Expand Up @@ -114,4 +118,36 @@ export class TcAbacusGrpcTransformer {
),
}
}

static grpcReferrerEligibilityToReferrerEligibility(
response: TcAbacusPb.GetReferrerElegibilityResponse,
): ReferrerEligibilityResponse {
return {
volume: response.volume,
isEligible: response.isEligible,
volumeThreshold: response.volumeThreshold,
}
}

static grpcReferrerCodeToReferrerCode(
code: TcAbacusPb.ReferrerCode,
): ReferrerCode {
return {
cap: code.cap,
code: code.code,
invitees: code.invitees,
createdAt: code.createdAt,
}
}

static grpcListReferrerCodesToListReferrerCodes(
response: TcAbacusPb.ListReferrerCodesResponse,
): ListReferrerCodesResponse {
return {
nextCursor: response.nextCursor,
codes: response.codes.map((code) =>
TcAbacusGrpcTransformer.grpcReferrerCodeToReferrerCode(code),
),
}
}
}
19 changes: 19 additions & 0 deletions packages/sdk-ts/src/client/tcAbacus/types/tcAbacus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface CurrentEpochResponse {
epochEnd: string
epochPoints: string
epochPointsDistributedAt: string
}

export interface HealthCheckResponse {
Expand Down Expand Up @@ -60,3 +61,21 @@ export interface AccountInviteesResponse {
nextCursor?: string
invitees: ReferrerInvitee[]
}

export interface ReferrerEligibilityResponse {
volume: string
isEligible: boolean
volumeThreshold: string
}

export interface ReferrerCode {
code: string
cap?: number
invitees: string[]
createdAt: string
}

export interface ListReferrerCodesResponse {
nextCursor?: string
codes: ReferrerCode[]
}
1 change: 1 addition & 0 deletions packages/utils/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig({
outDir: 'dist',
external: [
// External workspace dependencies
'bignumber.js',
'@injectivelabs/exceptions',
'@injectivelabs/networks',
'@injectivelabs/ts-types',
Expand Down
Loading