Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions packages/exceptions/src/exceptions/types/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const IndexerErrorModule = {
Dmm: 'dmm',
OLP: 'olp',
Abacus: 'abacus',
RFQ: 'indexer-rfq',
Meta: 'indexer-meta',
Mito: 'indexer-mito',
Referral: 'referral',
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
"@injectivelabs/grpc-web": "^0.0.1",
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
"@injectivelabs/indexer-proto-ts-v2": "1.17.6",
"@injectivelabs/indexer-proto-ts-v2": "1.17.7-alpha.4",
"@injectivelabs/mito-proto-ts-v2": "1.17.3",
"@injectivelabs/networks": "workspace:*",
"@injectivelabs/olp-proto-ts-v2": "1.17.6",
Expand All @@ -348,7 +348,8 @@
"http-status-codes": "catalog:",
"rxjs": "7.8.2",
"snakecase-keys": "^5.4.1",
"viem": "catalog:"
"viem": "catalog:",
"ws": "^8.18.0"
},
"publishConfig": {
"access": "public"
Expand Down
86 changes: 86 additions & 0 deletions packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcRfqApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
import { IndexerGrpcRFQApi } from './IndexerGrpcRfqApi.js'
import type { IndexerGrpcRfqTransformer } from '../transformers/index.js'

const endpoints = getNetworkEndpoints(Network.Mainnet)
const indexerGrpcRfqApi = new IndexerGrpcRFQApi(endpoints.indexer)

describe('IndexerGrpcRFQApi', () => {
test('submitRequest', async () => {
try {
const response = await indexerGrpcRfqApi.submitRequest({
direction: 'LONG',
status: 'PENDING',
rfqId: BigInt(1717000000),
height: BigInt(1717000000),
expiry: BigInt(1717000000),
margin: '1000000000000000000',
updatedAt: BigInt(1717000000),
createdAt: BigInt(1717000000),
quantity: '1000000000000000000',
worstPrice: '1000000000000000000',
transactionTime: BigInt(1717000000),
marketId: 'inj1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqe2hm49',
requestAddress: 'inj1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqe2hm49',
})

expect(response).toBeDefined()
expect(response).toEqual(
expect.objectContaining<{ status: string }>(response),
)
} catch (e) {
console.error('IndexerGrpcRFQApi.submitRequest => ' + (e as any).message)
}
})

test('submitQuote', async () => {
try {
const response = await indexerGrpcRfqApi.submitRequest({
direction: 'LONG',
status: 'PENDING',
rfqId: BigInt(1717000000),
height: BigInt(1717000000),
expiry: BigInt(1717000000),
margin: '1000000000000000000',
updatedAt: BigInt(1717000000),
createdAt: BigInt(1717000000),
quantity: '1000000000000000000',
worstPrice: '1000000000000000000',
transactionTime: BigInt(1717000000),
marketId: 'inj1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqe2hm49',
requestAddress: 'inj1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqe2hm49',
})

expect(response).toBeDefined()
expect(response).toEqual(
expect.objectContaining<{ status: string }>(response),
)
} catch (e) {
console.error('IndexerGrpcRFQApi.submitQuote => ' + (e as any).message)
}
})
test('fetchSettlements', async () => {
try {
const response = await indexerGrpcRfqApi.fetchSettlements({
addresses: ['inj1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqe2hm49'],
pagination: {
skip: 0,
limit: 10,
},
})

expect(response).toBeDefined()
expect(response).toEqual(
expect.objectContaining<
ReturnType<
typeof IndexerGrpcRfqTransformer.listSettlementsResponseToSettlements
>
>(response),
)
} catch (e) {
console.error(
'IndexerGrpcRFQApi.fetchSettlements => ' + (e as any).message,
)
}
})
})
264 changes: 264 additions & 0 deletions packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcRfqApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
import * as InjectiveRFQExchangeRpcPb from '@injectivelabs/indexer-proto-ts-v2/generated/injective_rfqrpc_pb'
import { InjectiveRFQRPCClient } from '@injectivelabs/indexer-proto-ts-v2/generated/injective_rfqrpc_pb.client'
import { IndexerModule } from '../types/index.js'
import { IndexerGrpcRfqTransformer } from '../transformers/index.js'
import BaseIndexerGrpcConsumer from '../../base/BaseIndexerGrpcConsumer.js'
import type { PaginationOption } from '../../../types/index.js'

/**
* @category Indexer Grpc API
*/
export class IndexerGrpcRFQApi extends BaseIndexerGrpcConsumer {
protected module: string = IndexerModule.RFQ

private get client() {
return this.initClient(InjectiveRFQRPCClient)
}

async submitRequest({
rfqId,
margin,
expiry,
status,
height,
marketId,
quantity,
direction,
createdAt,
updatedAt,
worstPrice,
requestAddress,
transactionTime,
}: {
rfqId?: bigint
margin: string
expiry?: bigint
status?: string
height?: bigint
marketId: string
quantity: string
direction: string
worstPrice: string
createdAt?: bigint
updatedAt?: bigint
requestAddress?: string
transactionTime?: bigint
}) {
const request = InjectiveRFQExchangeRpcPb.RFQRequestType.create()

if (rfqId !== undefined) {
request.rfqId = rfqId
}

if (marketId) {
request.marketId = marketId
}

if (direction) {
request.direction = direction
}

if (margin) {
request.margin = margin
}

if (quantity) {
request.quantity = quantity
}

if (worstPrice) {
request.worstPrice = worstPrice
}

if (requestAddress) {
request.requestAddress = requestAddress
}

if (expiry) {
request.expiry = expiry
}

if (status) {
request.status = status
}

if (createdAt) {
request.createdAt = createdAt
}

if (updatedAt) {
request.updatedAt = updatedAt
}

if (transactionTime) {
request.transactionTime = transactionTime
}

if (height) {
request.height = height
}

const requestMessage = InjectiveRFQExchangeRpcPb.RequestRequest.create()
requestMessage.request = request

const response = await this.executeGrpcCall<
InjectiveRFQExchangeRpcPb.RequestRequest,
InjectiveRFQExchangeRpcPb.RequestResponse
>(requestMessage, this.client.request.bind(this.client))

return { status: response.status }
}

async submitQuote({
rfqId,
price,
maker,
taker,
margin,
expiry,
status,
height,
chainId,
marketId,
quantity,
signature,
createdAt,
updatedAt,
eventTime,
takerDirection,
contractAddress,
transactionTime,
}: {
rfqId?: bigint
price: string
maker: string
taker: string
margin: string
expiry?: bigint
status?: string
height?: bigint
chainId: string
marketId: string
quantity: string
signature: string
createdAt?: bigint
updatedAt?: bigint
eventTime?: bigint
takerDirection: string
contractAddress: string
transactionTime?: bigint
}): Promise<{ status: string }> {
const request = InjectiveRFQExchangeRpcPb.RFQQuoteType.create()

if (chainId) {
request.chainId = chainId
}

if (contractAddress) {
request.contractAddress = contractAddress
}

if (marketId) {
request.marketId = marketId
}

if (rfqId !== undefined) {
request.rfqId = rfqId
}

if (takerDirection) {
request.takerDirection = takerDirection
}

if (margin) {
request.margin = margin
}

if (quantity) {
request.quantity = quantity
}

if (price) {
request.price = price
}

if (expiry) {
request.expiry = expiry
}

if (maker) {
request.maker = maker
}

if (taker) {
request.taker = taker
}

if (signature) {
request.signature = signature
}

if (status) {
request.status = status
}

if (createdAt) {
request.createdAt = createdAt
}

if (updatedAt) {
request.updatedAt = updatedAt
}

if (height) {
request.height = height
}

if (eventTime) {
request.eventTime = eventTime
}

if (transactionTime) {
request.transactionTime = transactionTime
}

const quoteMessage = InjectiveRFQExchangeRpcPb.QuoteRequest.create()
quoteMessage.quote = request

const response = await this.executeGrpcCall<
InjectiveRFQExchangeRpcPb.QuoteRequest,
InjectiveRFQExchangeRpcPb.QuoteResponse
>(quoteMessage, this.client.quote.bind(this.client))

return { status: response.status }
}

async fetchSettlements(params?: {
addresses?: string[]
pagination?: PaginationOption
}) {
const { addresses, pagination } = params || {}
const request = InjectiveRFQExchangeRpcPb.ListSettlementRequest.create()

if (addresses && addresses.length > 0) {
request.addresses = addresses
}

if (pagination?.skip) {
request.skip = BigInt(pagination.skip)
}

if (pagination?.limit) {
request.limit = BigInt(pagination.limit)
}

const response = await this.executeGrpcCall<
InjectiveRFQExchangeRpcPb.ListSettlementRequest,
InjectiveRFQExchangeRpcPb.ListSettlementResponse
>(request, this.client.listSettlement.bind(this.client))

return IndexerGrpcRfqTransformer.listSettlementsResponseToSettlements(
response,
)
}
}
1 change: 1 addition & 0 deletions packages/sdk-ts/src/client/indexer/grpc/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { IndexerGrpcRFQApi } from './IndexerGrpcRfqApi.js'
export { IndexerGrpcMitoApi } from './IndexerGrpcMitoApi.js'
export { IndexerGrpcMetaApi } from './IndexerGrpcMetaApi.js'
export { IndexerGrpcSpotApi } from './IndexerGrpcSpotApi.js'
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-ts/src/client/indexer/grpc_stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './stream/streamHelpers.js'
export { default as StreamManager } from './stream/StreamManager.js'

// V2 Streams (Event-based, for StreamManagerV2)
export * from './streamV2/IndexerGrpcRfqStreamV2.js'
export * from './streamV2/IndexerGrpcSpotStreamV2.js'
export * from './streamV2/IndexerGrpcMitoStreamV2.js'
export * from './streamV2/IndexerGrpcOracleStreamV2.js'
Expand Down
Loading