Skip to content

Commit 5c19ade

Browse files
committed
chore: merge conflicts
2 parents 7df9551 + d7487b1 commit 5c19ade

File tree

26 files changed

+317
-79
lines changed

26 files changed

+317
-79
lines changed

packages/exceptions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@injectivelabs/exceptions",
33
"description": "List of exceptions that can be reused throughout Injective's projects.",
4-
"version": "1.14.43-beta.0",
4+
"version": "1.14.43-beta.1",
55
"sideEffects": false,
66
"license": "Apache-2.0",
77
"type": "module",

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export enum ChainErrorModule {
2121
Wasm = 'chain-wasm',
2222
WasmX = 'chain-wasmx',
2323
Tendermint = 'chain-tendermint',
24-
Permissions = 'chain-permissions'
24+
Permissions = 'chain-permissions',
2525
}
2626

2727
export enum IndexerErrorModule {
@@ -35,6 +35,7 @@ export enum IndexerErrorModule {
3535
Mito = 'indexer-mito',
3636
Dmm = 'dmm',
3737
OLP = 'olp',
38+
Referral = 'referral',
3839
Oracle = 'indexer-oracle',
3940
Portfolio = 'indexer-portfolio',
4041
Spot = 'indexer-spot',
@@ -45,7 +46,7 @@ export enum IndexerErrorModule {
4546
ChronosMarkets = 'indexer-chronos-markets',
4647
Campaign = 'indexer-campaign',
4748
Web3Gw = 'web3-gateway',
48-
Abacus = 'abacus'
49+
Abacus = 'abacus',
4950
}
5051

5152
export enum WalletErrorActionModule {

packages/networks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@injectivelabs/networks",
33
"description": "Endpoints, networks, etc. Can be reused throughout Injective's projects.",
4-
"version": "1.14.43-beta.0",
4+
"version": "1.14.43-beta.1",
55
"sideEffects": false,
66
"type": "module",
77
"license": "Apache-2.0",

packages/networks/src/endpoints.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const endpointsMainnetSentry: NetworkEndpoints = {
1010
cacheGrpc: 'https://sentry.chain.grpc-web.injective.network',
1111
cacheRest: 'https://staging.gateway.grpc-web.injective.network',
1212
web3gw: 'https://sentry.exchange.grpc-web.injective.network',
13+
chart: 'https://sentry.exchange.grpc-web.injective.network',
1314
}
1415

1516
export const endpointsMainnet: NetworkEndpoints = {
@@ -26,6 +27,7 @@ export const endpointsStaging: NetworkEndpoints = {
2627
cacheGrpc: 'https://staging.grpc.injective.network',
2728
cacheRest: 'https://staging.gateway.grpc-web.injective.network',
2829
web3gw: 'https://staging.api.injective.network',
30+
chart: 'https://k8s.mainnet.staging.chart.grpc-web.injective.network',
2931
}
3032

3133
export const endpointsInternal: NetworkEndpoints = {
@@ -38,6 +40,7 @@ export const endpointsInternal: NetworkEndpoints = {
3840
cacheGrpc: 'https://products.chain.grpc-web.injective.network',
3941
cacheRest: 'https://staging.gateway.grpc-web.injective.network',
4042
web3gw: 'https://products.web3-gateway.injective.network',
43+
chart: 'https://products.exchange.grpc-web.injective.network',
4144
}
4245

4346
export const endpointsTestnetSentry: NetworkEndpoints = {
@@ -159,6 +162,7 @@ export const endpointsMainnetLB: NetworkEndpoints = {
159162
cacheGrpc: 'https://k8s.global.mainnet.chain.grpc-web.injective.network',
160163
cacheRest: 'https://k8s.global.mainnet.exchange.grpc-web.injective.network',
161164
web3gw: 'https://k8s.global.mainnet.exchange.grpc-web.injective.network',
165+
chart: 'https://k8s.global.mainnet.chart.grpc-web.injective.network',
162166
}
163167

164168
/**

packages/networks/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type NetworkEndpoints = {
2929
chronos?: string // Chronos Service
3030
web3gw?: string // Web3Gateway Service
3131
explorer?: string // Explorer Service
32+
chart?: string // Chart Service
3233
}
3334

3435
export type UrlEndpoints = NetworkEndpoints /** Deprecated */

packages/sdk-ts/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@injectivelabs/sdk-ts",
33
"description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.",
4-
"version": "1.14.44-beta.0",
4+
"version": "1.14.44-beta.2",
55
"sideEffects": false,
66
"license": "Apache-2.0",
77
"author": {
@@ -124,16 +124,16 @@
124124
"@ethersproject/bytes": "^5.8.0",
125125
"@injectivelabs/abacus-proto-ts": "1.14.0",
126126
"@injectivelabs/core-proto-ts": "1.14.2",
127-
"@injectivelabs/exceptions": "^1.14.43-beta.0",
127+
"@injectivelabs/exceptions": "^1.14.43-beta.1",
128128
"@injectivelabs/grpc-web": "^0.0.1",
129129
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
130130
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
131131
"@injectivelabs/indexer-proto-ts": "1.13.9",
132132
"@injectivelabs/mito-proto-ts": "1.13.2",
133-
"@injectivelabs/networks": "^1.14.43-beta.0",
133+
"@injectivelabs/networks": "^1.14.43-beta.1",
134134
"@injectivelabs/olp-proto-ts": "1.13.4",
135135
"@injectivelabs/ts-types": "^1.14.43-beta.0",
136-
"@injectivelabs/utils": "^1.14.43-beta.0",
136+
"@injectivelabs/utils": "^1.14.43-beta.2",
137137
"@metamask/eth-sig-util": "^4.0.0",
138138
"@noble/curves": "^1.8.1",
139139
"@noble/hashes": "^1.7.1",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { mockFactory } from '@injectivelabs/utils/test-utils'
2+
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
3+
import { IndexerGrpcReferralTransformer } from '../transformers/index.js'
4+
import { IndexerGrpcReferralApi } from './IndexerGrpcReferralApi.js'
5+
6+
const injectiveAddress = mockFactory.injectiveAddress
7+
const endpoints = getNetworkEndpoints(Network.MainnetSentry)
8+
const indexerGrpcReferralApi = new IndexerGrpcReferralApi(endpoints.indexer)
9+
10+
describe('IndexerGrpcReferralApi', () => {
11+
test('fetchReferrerDetails', async () => {
12+
try {
13+
const response = await indexerGrpcReferralApi.fetchReferrerDetails(
14+
injectiveAddress,
15+
)
16+
17+
expect(response).toBeDefined()
18+
expect(response).toEqual(
19+
expect.objectContaining<
20+
ReturnType<
21+
typeof IndexerGrpcReferralTransformer.referrerDetailsResponseToReferrerDetails
22+
>
23+
>(response),
24+
)
25+
} catch (e) {
26+
console.error(
27+
'IndexerGrpcReferralApi.fetchReferrerDetails => ' + (e as any).message,
28+
)
29+
}
30+
})
31+
32+
test('fetchInviteeDetails', async () => {
33+
try {
34+
const response = await indexerGrpcReferralApi.fetchInviteeDetails(
35+
injectiveAddress,
36+
)
37+
38+
expect(response).toBeDefined()
39+
expect(response).toEqual(
40+
expect.objectContaining<
41+
ReturnType<
42+
typeof IndexerGrpcReferralTransformer.inviteeDetailsResponseToInviteeDetails
43+
>
44+
>(response),
45+
)
46+
} catch (e) {
47+
console.error(
48+
'IndexerGrpcReferralApi.fetchInviteeDetails => ' + (e as any).message,
49+
)
50+
}
51+
})
52+
53+
test('fetchReferrerByCode', async () => {
54+
try {
55+
const response = await indexerGrpcReferralApi.fetchReferrerByCode(
56+
injectiveAddress,
57+
)
58+
59+
expect(response).toBeDefined()
60+
expect(response).toEqual(
61+
expect.objectContaining<
62+
ReturnType<
63+
typeof IndexerGrpcReferralTransformer.referrerByCodeResponseToReferrerByCode
64+
>
65+
>(response),
66+
)
67+
} catch (e) {
68+
console.error(
69+
'IndexerGrpcReferralApi.fetchReferrerByCode => ' + (e as any).message,
70+
)
71+
}
72+
})
73+
})
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import {
2+
UnspecifiedErrorCode,
3+
GrpcUnaryRequestException,
4+
} from '@injectivelabs/exceptions'
5+
import { InjectiveReferralRpc } from '@injectivelabs/indexer-proto-ts'
6+
import BaseGrpcConsumer from '../../base/BaseIndexerGrpcConsumer.js'
7+
import { IndexerGrpcReferralTransformer } from '../transformers/index.js'
8+
import { IndexerModule } from '../types/index.js'
9+
10+
/**
11+
* @category Indexer Grpc API
12+
*/
13+
export class IndexerGrpcReferralApi extends BaseGrpcConsumer {
14+
protected module: string = IndexerModule.Referral
15+
16+
protected client: InjectiveReferralRpc.InjectiveReferralRPCClientImpl
17+
18+
constructor(endpoint: string) {
19+
super(endpoint)
20+
21+
this.client = new InjectiveReferralRpc.InjectiveReferralRPCClientImpl(
22+
this.getGrpcWebImpl(endpoint),
23+
)
24+
}
25+
26+
async fetchReferrerDetails(address: string) {
27+
const request = InjectiveReferralRpc.GetReferrerDetailsRequest.create()
28+
request.referrerAddress = address
29+
30+
try {
31+
const response =
32+
await this.retry<InjectiveReferralRpc.GetReferrerDetailsResponse>(() =>
33+
this.client.GetReferrerDetails(request),
34+
)
35+
36+
return IndexerGrpcReferralTransformer.referrerDetailsResponseToReferrerDetails(
37+
address,
38+
response,
39+
)
40+
} catch (e: unknown) {
41+
if (e instanceof InjectiveReferralRpc.GrpcWebError) {
42+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
43+
code: e.code,
44+
context: 'Referral',
45+
contextModule: this.module,
46+
})
47+
}
48+
49+
throw new GrpcUnaryRequestException(e as Error, {
50+
code: UnspecifiedErrorCode,
51+
context: 'Referral',
52+
contextModule: this.module,
53+
})
54+
}
55+
}
56+
57+
async fetchInviteeDetails(address: string) {
58+
const request = InjectiveReferralRpc.GetInviteeDetailsRequest.create()
59+
request.inviteeAddress = address
60+
61+
try {
62+
const response =
63+
await this.retry<InjectiveReferralRpc.GetInviteeDetailsResponse>(() =>
64+
this.client.GetInviteeDetails(request),
65+
)
66+
67+
return IndexerGrpcReferralTransformer.inviteeDetailsResponseToInviteeDetails(
68+
response,
69+
)
70+
} catch (e: unknown) {
71+
if (e instanceof InjectiveReferralRpc.GrpcWebError) {
72+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
73+
code: e.code,
74+
context: 'Referral',
75+
contextModule: this.module,
76+
})
77+
}
78+
79+
throw new GrpcUnaryRequestException(e as Error, {
80+
code: UnspecifiedErrorCode,
81+
context: 'Referral',
82+
contextModule: this.module,
83+
})
84+
}
85+
}
86+
87+
async fetchReferrerByCode(address: string) {
88+
const request = InjectiveReferralRpc.GetReferrerByCodeRequest.create()
89+
request.referralCode = address
90+
91+
try {
92+
const response =
93+
await this.retry<InjectiveReferralRpc.GetReferrerByCodeResponse>(() =>
94+
this.client.GetReferrerByCode(request),
95+
)
96+
97+
return IndexerGrpcReferralTransformer.referrerByCodeResponseToReferrerByCode(
98+
response,
99+
)
100+
} catch (e: unknown) {
101+
if (e instanceof InjectiveReferralRpc.GrpcWebError) {
102+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
103+
code: e.code,
104+
context: 'Referral',
105+
contextModule: this.module,
106+
})
107+
}
108+
109+
throw new GrpcUnaryRequestException(e as Error, {
110+
code: UnspecifiedErrorCode,
111+
context: 'Referral',
112+
contextModule: this.module,
113+
})
114+
}
115+
}
116+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ export { IndexerGrpcMitoApi } from './IndexerGrpcMitoApi.js'
22
export { IndexerGrpcMetaApi } from './IndexerGrpcMetaApi.js'
33
export { IndexerGrpcSpotApi } from './IndexerGrpcSpotApi.js'
44
export { IndexerGrpcOracleApi } from './IndexerGrpcOracleApi.js'
5+
export { IndexerGrpcWeb3GwApi } from './IndexerGrpcWeb3GwApi.js'
56
export { IndexerGrpcAccountApi } from './IndexerGrpcAccountApi.js'
67
export { IndexerGrpcAuctionApi } from './IndexerGrpcAuctionApi.js'
78
export { IndexerGrpcTradingApi } from './IndexerGrpcTradingApi.js'
89
export { IndexerGrpcExplorerApi } from './IndexerGrpcExplorerApi.js'
910
export { IndexerGrpcCampaignApi } from './IndexerGrpcCampaignApi.js'
1011
export { IndexerGrpcArchiverApi } from './IndexerGrpcArchiverApi.js'
12+
export { IndexerGrpcReferralApi } from './IndexerGrpcReferralApi.js'
1113
export { IndexerGrpcDerivativesApi } from './IndexerGrpcDerivativesApi.js'
1214
export { IndexerGrpcTransactionApi } from './IndexerGrpcTransactionApi.js'
13-
export { IndexerGrpcWeb3GwApi } from './IndexerGrpcWeb3GwApi.js'
1415
export { IndexerGrpcAccountPortfolioApi } from './IndexerGrpcPortfolioApi.js'
1516
export { IndexerGrpcInsuranceFundApi } from './IndexerGrpcInsuranceFundApi.js'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { BigNumberInBase } from '@injectivelabs/utils'
2+
import { InjectiveReferralRpc } from '@injectivelabs/indexer-proto-ts'
3+
import { ReferralDetails } from '../types/index.js'
4+
5+
export class IndexerGrpcReferralTransformer {
6+
static referrerDetailsResponseToReferrerDetails(
7+
address: string,
8+
response: InjectiveReferralRpc.GetReferrerDetailsResponse,
9+
): ReferralDetails {
10+
return {
11+
referrerAddress: address,
12+
invitees: response.invitees,
13+
referrerCode: response.referrerCode,
14+
totalCommission: new BigNumberInBase(response.totalCommission),
15+
totalTradingVolume: new BigNumberInBase(response.totalTradingVolume),
16+
}
17+
}
18+
19+
static inviteeDetailsResponseToInviteeDetails(
20+
response: InjectiveReferralRpc.GetInviteeDetailsResponse,
21+
): InjectiveReferralRpc.GetInviteeDetailsResponse {
22+
return response
23+
}
24+
25+
static referrerByCodeResponseToReferrerByCode(
26+
response: InjectiveReferralRpc.GetReferrerByCodeResponse,
27+
): boolean {
28+
return !response?.referrerAddress
29+
}
30+
}

0 commit comments

Comments
 (0)