-
Notifications
You must be signed in to change notification settings - Fork 204
feat/rfq #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat/rfq #615
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
10bc944
chore: add indexer rfq to protoV2
ThomasRalee f568ea6
feat: rfq
ThomasRalee cbd300f
chore: rfq updates
Frederick-88 4b25e10
chore: abstract websocket usage for scalability on rfq updates
Frederick-88 3d4d418
chore: updates as per rfq contract updates
Frederick-88 bddf73c
chore: debugging
Frederick-88 10c6284
chore: deprecate unused rfq grpc endpoints
Frederick-88 00d3c48
chore: rfq updates to sync with indexer and contract changes
Frederick-88 1709759
Merge branch 'dev' & resolve conflict
Frederick-88 7941b59
chore: updates as per PR review/feedbacks
Frederick-88 37ae922
chore: updates as per PR review/feedbacks
Frederick-88 7284f29
chore: updates as per PR feedbacks
Frederick-88 8792459
fix: minor
Frederick-88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcRfqApi.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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({ | ||
Frederick-88 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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
264
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcRfqApi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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, | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.