Skip to content

Commit

Permalink
feat: canary core proto-ts v1.13.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Feb 8, 2025
1 parent c3fdda6 commit fed16cb
Show file tree
Hide file tree
Showing 43 changed files with 1,588 additions and 1,096 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"@cosmjs/stargate": "^0.32.3",
"@ethersproject/bytes": "^5.7.0",
"@injectivelabs/abacus-proto-ts": "1.13.3",
"@injectivelabs/core-proto-ts": "1.13.5",
"@injectivelabs/core-proto-ts": "1.13.6",
"@injectivelabs/exceptions": "^1.14.40",
"@injectivelabs/grpc-web": "^0.0.1",
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
Expand Down
19 changes: 19 additions & 0 deletions packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuctionApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,23 @@ describe('ChainGrpcAuctionApi', () => {
)
}
})

test('fetchLastAuctionResult', async () => {
try {
const response = await chainGrpcAuctionApi.fetchLastAuctionResult()

expect(response).toBeDefined()
expect(response).toEqual(
expect.objectContaining<
ReturnType<
typeof ChainGrpcAuctionTransformer.LastAuctionResultResponseToLastAuctionResult
>
>(response),
)
} catch (e) {
console.error(
'ChainGrpcAuctionApi.fetchLastAuctionResult => ' + (e as any).message,
)
}
})
})
44 changes: 37 additions & 7 deletions packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuctionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ export class ChainGrpcAuctionApi extends BaseGrpcConsumer {
}
}

async fetchCurrentBasket() {
const request =
InjectiveAuctionV1Beta1Query.QueryCurrentAuctionBasketRequest.create()

try {
const response =
await this.retry<InjectiveAuctionV1Beta1Query.QueryCurrentAuctionBasketResponse>(
() => this.client.CurrentAuctionBasket(request, this.metadata),
)

return ChainGrpcAuctionTransformer.currentBasketResponseToCurrentBasket(
response,
)
} catch (e: unknown) {
if (e instanceof InjectiveAuctionV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
code: e.code,
context: 'CurrentAuctionBasket',
contextModule: this.module,
})
}

throw new GrpcUnaryRequestException(e as Error, {
code: UnspecifiedErrorCode,
context: 'CurrentAuctionBasket',
contextModule: this.module,
})
}
}

async fetchModuleState() {
const request =
InjectiveAuctionV1Beta1Query.QueryModuleStateRequest.create()
Expand Down Expand Up @@ -83,31 +113,31 @@ export class ChainGrpcAuctionApi extends BaseGrpcConsumer {
}
}

async fetchCurrentBasket() {
async fetchLastAuctionResult() {
const request =
InjectiveAuctionV1Beta1Query.QueryCurrentAuctionBasketRequest.create()
InjectiveAuctionV1Beta1Query.QueryLastAuctionResultRequest.create()

try {
const response =
await this.retry<InjectiveAuctionV1Beta1Query.QueryCurrentAuctionBasketResponse>(
() => this.client.CurrentAuctionBasket(request, this.metadata),
await this.retry<InjectiveAuctionV1Beta1Query.QueryLastAuctionResultResponse>(
() => this.client.LastAuctionResult(request, this.metadata),
)

return ChainGrpcAuctionTransformer.currentBasketResponseToCurrentBasket(
return ChainGrpcAuctionTransformer.LastAuctionResultResponseToLastAuctionResult(
response,
)
} catch (e: unknown) {
if (e instanceof InjectiveAuctionV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
code: e.code,
context: 'CurrentAuctionBasket',
context: 'LastAuctionResult',
contextModule: this.module,
})
}

throw new GrpcUnaryRequestException(e as Error, {
code: UnspecifiedErrorCode,
context: 'CurrentAuctionBasket',
context: 'LastAuctionResult',
contextModule: this.module,
})
}
Expand Down
19 changes: 9 additions & 10 deletions packages/sdk-ts/src/client/chain/grpc/ChainGrpcBankApi.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { CosmosBankV1Beta1Query } from '@injectivelabs/core-proto-ts'
import {
GrpcUnaryRequestException,
UnspecifiedErrorCode,
GrpcUnaryRequestException,
} from '@injectivelabs/exceptions'
import { CosmosBankV1Beta1Query } from '@injectivelabs/core-proto-ts'
import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
import { ChainModule } from '../types/index.js'
import { ChainGrpcBankTransformer } from '../transformers/index.js'
import { PaginationOption } from '../../../types/pagination.js'
import {
fetchAllWithPagination,
paginationRequestFromPagination,
} from '../../../utils/pagination.js'
import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
import { ChainGrpcBankTransformer } from '../transformers/index.js'
import { ChainGrpcCommonTransformer } from '../transformers/ChainGrpcCommonTransformer.js'
import { ChainModule } from '../types/index.js'
import { PaginationOption } from '../../../types/pagination.js'

const MAX_LIMIT_FOR_SUPPLY = 10000

Expand Down Expand Up @@ -180,7 +181,7 @@ export class ChainGrpcBankApi extends BaseGrpcConsumer {
this.client.SupplyOf(request, this.metadata),
)

return ChainGrpcBankTransformer.grpcCoinToCoin(response.amount!)
return ChainGrpcCommonTransformer.grpcCoinToCoin(response.amount!)
} catch (e: unknown) {
if (e instanceof CosmosBankV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
Expand Down Expand Up @@ -278,9 +279,7 @@ export class ChainGrpcBankApi extends BaseGrpcConsumer {
this.client.DenomOwners(request, this.metadata),
)

return ChainGrpcBankTransformer.denomOwnersResponseToDenomOwners(
response,
)
return ChainGrpcBankTransformer.denomOwnersResponseToDenomOwners(response)
} catch (e: unknown) {
if (e instanceof CosmosBankV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockFactory } from '@injectivelabs/test-utils'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { ChainGrpcExchangeApi } from './ChainGrpcExchangeApi.js'
import { mockFactory } from '@injectivelabs/test-utils'
import { ChainGrpcExchangeTransformer } from '../transformers/index.js'
import { InjectiveExchangeV1Beta1Query } from '@injectivelabs/core-proto-ts'

Expand Down Expand Up @@ -212,4 +212,44 @@ describe('ChainGrpcExchangeApi', () => {
)
}
})

test('fetchDenomDecimals', async () => {
try {
const response = await chainGrpcExchangeApi.fetchDenomDecimals()

expect(response).toBeDefined()
expect(response).toEqual(
expect.objectContaining<
ReturnType<
typeof ChainGrpcExchangeTransformer.denomDecimalsResponseToDenomDecimals
>
>(response),
)
} catch (e) {
console.error(
'chainGrpcExchangeApi.denomDecimalsResponseToDenomDecimals => ' +
(e as any).message,
)
}
})

test('fetchDenomMinNotionals', async () => {
try {
const response = await chainGrpcExchangeApi.fetchDenomMinNotionals()

expect(response).toBeDefined()
expect(response).toEqual(
expect.objectContaining<
ReturnType<
typeof ChainGrpcExchangeTransformer.denomMinNotionalsResponseToDenomMinNotionals
>
>(response),
)
} catch (e) {
console.error(
'chainGrpcExchangeApi.denomMinNotionalsResponseToDenomMinNotionals => ' +
(e as any).message,
)
}
})
})
124 changes: 122 additions & 2 deletions packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
GrpcUnaryRequestException,
UnspecifiedErrorCode,
GrpcUnaryRequestException,
} from '@injectivelabs/exceptions'
import { InjectiveExchangeV1Beta1Query } from '@injectivelabs/core-proto-ts'
import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
import { ChainModule } from '../types/index.js'
import { ChainGrpcExchangeTransformer } from '../transformers/index.js'
import { ChainModule } from '../types/index.js'

InjectiveExchangeV1Beta1Query

Expand Down Expand Up @@ -361,4 +361,124 @@ export class ChainGrpcExchangeApi extends BaseGrpcConsumer {
})
}
}

async fetchDenomDecimal(denom: string) {
const request =
InjectiveExchangeV1Beta1Query.QueryDenomDecimalRequest.create()

request.denom = denom

try {
const response =
await this.retry<InjectiveExchangeV1Beta1Query.QueryDenomDecimalResponse>(
() => this.client.DenomDecimal(request, this.metadata),
)

return response.decimal
} catch (e: any) {
if (e instanceof InjectiveExchangeV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
code: e.code,
context: 'DenomDecimal',
contextModule: this.module,
})
}

throw new GrpcUnaryRequestException(e as Error, {
code: UnspecifiedErrorCode,
context: 'DenomDecimal',
contextModule: ChainModule.Exchange,
})
}
}

async fetchDenomDecimals() {
const request =
InjectiveExchangeV1Beta1Query.QueryDenomDecimalsRequest.create()

try {
const response =
await this.retry<InjectiveExchangeV1Beta1Query.QueryDenomDecimalsResponse>(
() => this.client.DenomDecimals(request, this.metadata),
)

return ChainGrpcExchangeTransformer.denomDecimalsResponseToDenomDecimals(
response,
)
} catch (e: any) {
if (e instanceof InjectiveExchangeV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
code: e.code,
context: 'DenomDecimals',
contextModule: this.module,
})
}

throw new GrpcUnaryRequestException(e as Error, {
code: UnspecifiedErrorCode,
context: 'DenomDecimals',
contextModule: ChainModule.Exchange,
})
}
}

async fetchDenomMinNotional(denom: string) {
const request =
InjectiveExchangeV1Beta1Query.QueryDenomMinNotionalRequest.create()

request.denom = denom

try {
const response =
await this.retry<InjectiveExchangeV1Beta1Query.QueryDenomMinNotionalResponse>(
() => this.client.DenomMinNotional(request, this.metadata),
)

return response.amount
} catch (e: any) {
if (e instanceof InjectiveExchangeV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
code: e.code,
context: 'DenomMinNotional',
contextModule: this.module,
})
}

throw new GrpcUnaryRequestException(e as Error, {
code: UnspecifiedErrorCode,
context: 'DenomMinNotional',
contextModule: ChainModule.Exchange,
})
}
}

async fetchDenomMinNotionals() {
const request =
InjectiveExchangeV1Beta1Query.QueryDenomMinNotionalsRequest.create()

try {
const response =
await this.retry<InjectiveExchangeV1Beta1Query.QueryDenomMinNotionalsResponse>(
() => this.client.DenomMinNotionals(request, this.metadata),
)

return ChainGrpcExchangeTransformer.denomMinNotionalsResponseToDenomMinNotionals(
response,
)
} catch (e: any) {
if (e instanceof InjectiveExchangeV1Beta1Query.GrpcWebError) {
throw new GrpcUnaryRequestException(new Error(e.toString()), {
code: e.code,
context: 'DenomMinNotionals',
contextModule: this.module,
})
}

throw new GrpcUnaryRequestException(e as Error, {
code: UnspecifiedErrorCode,
context: 'DenomMinNotionals',
contextModule: ChainModule.Exchange,
})
}
}
}
Loading

0 comments on commit fed16cb

Please sign in to comment.