From fb39e2564878dacab04cdaf9527f692b7f895a99 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Tue, 22 Oct 2024 12:02:44 -0400 Subject: [PATCH 01/26] feat: get_public_logs --- package.json | 2 +- src/contracts/definitions/moneyMarket.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7412bce..8b2cecc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@shadeprotocol/shadejs", "description": "The Typescript SDK for Shade Protocol", - "version": "1.0.9", + "version": "1.0.10", "author": "Secure Secrets", "bugs": { "url": "https://github.com/securesecrets/shadejs/issues" diff --git a/src/contracts/definitions/moneyMarket.ts b/src/contracts/definitions/moneyMarket.ts index e4938b9..5aeca08 100644 --- a/src/contracts/definitions/moneyMarket.ts +++ b/src/contracts/definitions/moneyMarket.ts @@ -177,6 +177,18 @@ function msgMoneyMarketRepay({ }).msg; } +/** + * Query the Public Event Logs for momeymarket contract + * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY + */ +const msgQueryMoneyMarketPublicEvents = ( + pagination?: Pagination, +) => ({ + get_public_log: { + pagination, + }, +}); + export { msgQueryMoneyMarketConfig, msgQueryMoneyMarketCollaterals, @@ -188,4 +200,5 @@ export { msgMoneyMarketSupply, msgMoneyMarketWithdrawSupply, msgMoneyMarketRepay, + msgQueryMoneyMarketPublicEvents, }; From bc9388bd80a7abf282099b5de0616f1b87a27edd Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Wed, 23 Oct 2024 13:24:02 -0400 Subject: [PATCH 02/26] feat: build the moneymarketpublic events service --- src/contracts/services/moneyMarket.ts | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 06c7dd2..51e0674 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -572,6 +572,83 @@ async function batchQueryMoneyMarketGetCollateral({ })); } +/** + * query the Public Logs for money market contracts + * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY + */ +/** + * Query the public events of a money market contract using RxJS + */ +function queryMoneyMarketPublicEvents$({ + contractAddress, + codeHash, + lcdEndpoint, + chainId, + pagination, +}: { + contractAddress: string, + codeHash?: string, + lcdEndpoint?: string, + chainId?: string, + pagination?: Pagination, +}) { + const msgQueryMoneyMarketPublicEvents = (paginationParams?: Pagination) => ({ + query_msg: { + public_events: { + pagination: paginationParams, + }, + }, + }); + + const parseMoneyMarketPublicEvents = (response: any) => ({ + page: response.page, + pageSize: response.page_size, + totalPages: response.total_pages, + totalItems: response.total_items, + data: response.data.map((event: any) => ({ + timestamp: event.timestamp, + action: event.action, + })), + }); + + return getActiveQueryClient$(lcdEndpoint, chainId).pipe( + switchMap(({ client }) => sendSecretClientContractQuery$({ + queryMsg: msgQueryMoneyMarketPublicEvents(pagination), + client, + contractAddress, + codeHash, + })), + map((response) => parseMoneyMarketPublicEvents(response)), + first(), + ); +} + +async function queryMoneyMarketPublicEvents({ + contractAddress, + codeHash, + lcdEndpoint, + chainId, + pageSize, + page, +}: { + contractAddress: string, + codeHash?: string, + lcdEndpoint?: string, + chainId?: string, + pageSize?: number, + page?: number, +}) { + return lastValueFrom(queryMoneyMarketPublicEvents$({ + contractAddress, + codeHash, + lcdEndpoint, + chainId, + pagination: pageSize !== undefined && page !== undefined + ? { page_size: pageSize, page } + : undefined, + })); +} + export { queryMoneyMarketConfig, queryMoneyMarketGetMarkets, @@ -582,4 +659,5 @@ export { batchQueryMoneyMarketConfig, batchQueryMoneyMarketGetMarkets, batchQueryMoneyMarketGetCollateral, + queryMoneyMarketPublicEvents, }; From d2f97a3c4f0e62172e286fb9468fd89ad1354ccb Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Fri, 25 Oct 2024 11:32:01 -0400 Subject: [PATCH 03/26] feat: mock typed and test to check outputs and parsed values match --- src/contracts/services/moneyMarket.ts | 1 + src/contracts/services/moneymarket.test.ts | 59 +++++++++++++++++++ .../publiclogs/queryMoneyMarketParsed.ts | 26 ++++++++ .../publiclogs/queryMoneyMarketResponse.json | 31 ++++++++++ src/types/contracts/moneyMarket/model.ts | 16 +++++ src/types/contracts/moneyMarket/response.ts | 11 ++++ 6 files changed, 144 insertions(+) create mode 100644 src/contracts/services/moneymarket.test.ts create mode 100644 src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts create mode 100644 src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 51e0674..db54859 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -659,5 +659,6 @@ export { batchQueryMoneyMarketConfig, batchQueryMoneyMarketGetMarkets, batchQueryMoneyMarketGetCollateral, + queryMoneyMarketPublicEvents$, queryMoneyMarketPublicEvents, }; diff --git a/src/contracts/services/moneymarket.test.ts b/src/contracts/services/moneymarket.test.ts new file mode 100644 index 0000000..3f8c8b5 --- /dev/null +++ b/src/contracts/services/moneymarket.test.ts @@ -0,0 +1,59 @@ +import { + test, + expect, + vi, + beforeAll, + afterAll, + afterEach, +} from 'vitest'; +import { of } from 'rxjs'; +import { queryMoneyMarketPublicEvents$ } from '~/contracts/services/moneyMarket'; +import { queryMoneyMarketPublicEventsParsedMock } from '../../test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed'; +import queryMoneyMarketResponse from '../../test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json'; + +// Mock the sendSecretClientContractQuery$ function +const sendSecretClientContractQuery$ = vi.hoisted(() => vi.fn()); + +beforeAll(() => { + vi.mock('~/client/index', () => ({ + getActiveQueryClient$: vi.fn(() => of({ client: 'MOCK_CLIENT' })), + })); + + vi.mock('~/client/services/clientServices', () => ({ + sendSecretClientContractQuery$, + })); +}); + +afterAll(() => { + vi.clearAllMocks(); +}); + +afterEach(() => { + vi.clearAllMocks(); +}); + +test('it should parse the public events response correctly', async () => { + // Mock the service call with the modified JSON response data + sendSecretClientContractQuery$.mockReturnValueOnce( + of(queryMoneyMarketResponse.batch.responses[0].response)); + + // Define the input parameters + const contractAddress = 'secret18537ttv4l4k2ea0xp6ay3sv4c243fyjtj2uqz7'; + const lcdEndpoint = 'https://api.secret.com'; + const chainId = 'secret-4'; + const pagination = { page: 1, page_size: 10 }; + + // Call the function to test + const result$ = queryMoneyMarketPublicEvents$({ + contractAddress, + lcdEndpoint, + chainId, + pagination, + }); + + // Convert the result$ observable to a promise and get the final value + const result = await result$.toPromise(); + + // Validate the output against the expected parsed result + expect(result).toStrictEqual(queryMoneyMarketPublicEventsParsedMock); +}); diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts new file mode 100644 index 0000000..75a8aa7 --- /dev/null +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts @@ -0,0 +1,26 @@ +import { PaginatedPublicEvent } from '~/types/contracts/moneyMarket'; + +const queryMoneyMarketPublicEventsParsedMock: PaginatedPublicEvent = { + page: 0, + pageSize: 10, + totalPages: 1, + totalItems: 2, + data: [ + { + timestamp: 1693800000000, + action: { + contract_init: { + }, + }, + }, + { + timestamp: 1693805000000, + action: { + contract_init: { + }, + }, + }, + ], +}; + +export { queryMoneyMarketPublicEventsParsedMock }; diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json new file mode 100644 index 0000000..a50bb1b --- /dev/null +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json @@ -0,0 +1,31 @@ +{ + "batch": { + "block_height": 3, + "responses": [ + { + "id": "1", + "response": { + "page": 0, + "page_size": 10, + "total_pages": 1, + "total_items": 2, + "data": [ + { + "timestamp": 1693800000000, + "action": { + "contract_init": {} + } + }, + { + "timestamp": 1693805000000, + "action": { + "contract_init": {} + } + } + ] + } + } + ] + } + } + \ No newline at end of file diff --git a/src/types/contracts/moneyMarket/model.ts b/src/types/contracts/moneyMarket/model.ts index 1d3f569..d925488 100644 --- a/src/types/contracts/moneyMarket/model.ts +++ b/src/types/contracts/moneyMarket/model.ts @@ -150,6 +150,20 @@ type ParsedUserPositionResponse = { loanLiquidationPoint: string, } +// New types for public events +type PublicEvent = { + timestamp: number, + action: Record +} + +type PaginatedPublicEvent = { + page: number, + pageSize: number, + totalPages: number, + totalItems: number, + data: PublicEvent[], +} + export type { Pagination, ContractAndPagination, @@ -163,4 +177,6 @@ export type { ParsedUserPositionResponse, BatchMoneyMarketGetMarkets, BatchMoneyMarketGetCollaterals, + PublicEvent, + PaginatedPublicEvent, }; diff --git a/src/types/contracts/moneyMarket/response.ts b/src/types/contracts/moneyMarket/response.ts index 107fd0b..805b8f9 100644 --- a/src/types/contracts/moneyMarket/response.ts +++ b/src/types/contracts/moneyMarket/response.ts @@ -122,9 +122,20 @@ type UserPositionResponse = { } } +// Flexible type for actions, leaving it as a JSON object (blob) +type PublicEventResponse = { + timestamp: number, + action: Record, // Flexible JSON blob for action +} + +// Paginated response type for public events +type GetPublicEventsResponse = PaginatedResponse; + export type { ConfigResponse, GetMarketsResponse, GetCollateralResponse, UserPositionResponse, + PublicEventResponse, + GetPublicEventsResponse, }; From 99e4dd4df7769d9bd5c2c43a23343e5326ff6996 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Fri, 25 Oct 2024 11:32:22 -0400 Subject: [PATCH 04/26] chore: eslint fixes --- src/contracts/services/moneymarket.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/contracts/services/moneymarket.test.ts b/src/contracts/services/moneymarket.test.ts index 3f8c8b5..d85b29b 100644 --- a/src/contracts/services/moneymarket.test.ts +++ b/src/contracts/services/moneymarket.test.ts @@ -35,7 +35,8 @@ afterEach(() => { test('it should parse the public events response correctly', async () => { // Mock the service call with the modified JSON response data sendSecretClientContractQuery$.mockReturnValueOnce( - of(queryMoneyMarketResponse.batch.responses[0].response)); + of(queryMoneyMarketResponse.batch.responses[0].response), + ); // Define the input parameters const contractAddress = 'secret18537ttv4l4k2ea0xp6ay3sv4c243fyjtj2uqz7'; From 3c3251b0d79066af4bcc4c5b83945773ff71b1cc Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Thu, 31 Oct 2024 14:15:33 -0400 Subject: [PATCH 05/26] chore: docs --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7d38f00..2add551 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,9 @@ Docs will be available on a vitepress site. You can run the site locally with th ``` $ yarn docs:dev +``` + +## Building new version run +```bash +yarn changeset ``` \ No newline at end of file From 5283621950443206c4483c9158928306af1f6117 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Thu, 31 Oct 2024 14:15:49 -0400 Subject: [PATCH 06/26] fix: changeset --- .changeset/tall-meals-raise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tall-meals-raise.md diff --git a/.changeset/tall-meals-raise.md b/.changeset/tall-meals-raise.md new file mode 100644 index 0000000..6fd123b --- /dev/null +++ b/.changeset/tall-meals-raise.md @@ -0,0 +1,5 @@ +--- +"@shadeprotocol/shadejs": patch +--- + +Add Momney Market Public Logs From ae9d4b4f0c86bb0eae4ebc84c0c6036dd2fb5e70 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Thu, 31 Oct 2024 14:16:18 -0400 Subject: [PATCH 07/26] fix: address comments --- src/contracts/services/moneyMarket.ts | 76 ++++++++++++------- src/contracts/services/moneymarket.test.ts | 25 +++++- .../publiclogs/queryMoneyMarketParsed.ts | 4 +- src/types/contracts/moneyMarket/model.ts | 2 +- 4 files changed, 76 insertions(+), 31 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index db54859..273a9e7 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -572,6 +572,18 @@ async function batchQueryMoneyMarketGetCollateral({ })); } +// MoneyMarket Public Logs parsed response +const parseMoneyMarketPublicEvents = (response: any) => ({ + page: response.page, + pageSize: response.page_size, + totalPages: response.total_pages, + totalItems: response.total_items, + data: response.data.map((event: any) => ({ + timestamp: event.timestamp, + action: event.action, + })), +}); + /** * query the Public Logs for money market contracts * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY @@ -579,50 +591,62 @@ async function batchQueryMoneyMarketGetCollateral({ /** * Query the public events of a money market contract using RxJS */ + function queryMoneyMarketPublicEvents$({ contractAddress, codeHash, lcdEndpoint, chainId, pagination, + batchSize, + minBlockHeightValidationOptions, + blockHeight, }: { contractAddress: string, - codeHash?: string, + codeHash: string, lcdEndpoint?: string, chainId?: string, pagination?: Pagination, + batchSize?: number, + minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, + blockHeight?: number, }) { - const msgQueryMoneyMarketPublicEvents = (paginationParams?: Pagination) => ({ - query_msg: { - public_events: { - pagination: paginationParams, + const queries: BatchQueryParams[] = [{ + id: contractAddress, + contract: { + address: contractAddress, + codeHash, + }, + queryMsg: { + query_msg: { + public_events: { + pagination, + }, }, }, - }); - - const parseMoneyMarketPublicEvents = (response: any) => ({ - page: response.page, - pageSize: response.page_size, - totalPages: response.total_pages, - totalItems: response.total_items, - data: response.data.map((event: any) => ({ - timestamp: event.timestamp, - action: event.action, - })), - }); + }]; - return getActiveQueryClient$(lcdEndpoint, chainId).pipe( - switchMap(({ client }) => sendSecretClientContractQuery$({ - queryMsg: msgQueryMoneyMarketPublicEvents(pagination), - client, - contractAddress, - codeHash, - })), - map((response) => parseMoneyMarketPublicEvents(response)), + return batchQuery$({ + contractAddress, + codeHash, + lcdEndpoint, + chainId, + queries, + batchSize, + minBlockHeightValidationOptions, + blockHeight, + }).pipe( + map((response) => parseMoneyMarketPublicEvents(response[0].response)), first(), ); } +/** + * query the Public Logs for money market contracts + * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY + */ +/** + */ async function queryMoneyMarketPublicEvents({ contractAddress, codeHash, @@ -632,7 +656,7 @@ async function queryMoneyMarketPublicEvents({ page, }: { contractAddress: string, - codeHash?: string, + codeHash: string, lcdEndpoint?: string, chainId?: string, pageSize?: number, diff --git a/src/contracts/services/moneymarket.test.ts b/src/contracts/services/moneymarket.test.ts index d85b29b..6ee8849 100644 --- a/src/contracts/services/moneymarket.test.ts +++ b/src/contracts/services/moneymarket.test.ts @@ -8,7 +8,7 @@ import { } from 'vitest'; import { of } from 'rxjs'; import { queryMoneyMarketPublicEvents$ } from '~/contracts/services/moneyMarket'; -import { queryMoneyMarketPublicEventsParsedMock } from '../../test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed'; +import { queryMoneyMarketPublicEventsParsedMock } from '~/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed'; import queryMoneyMarketResponse from '../../test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json'; // Mock the sendSecretClientContractQuery$ function @@ -34,8 +34,22 @@ afterEach(() => { test('it should parse the public events response correctly', async () => { // Mock the service call with the modified JSON response data + // Encode JSON data in Base64 for the mock response + const base64EncodedId = Buffer.from(JSON.stringify("mock_id")).toString('base64'); + const base64EncodedResponse = Buffer.from(JSON.stringify(queryMoneyMarketResponse.batch.responses[0].response)).toString('base64'); sendSecretClientContractQuery$.mockReturnValueOnce( - of(queryMoneyMarketResponse.batch.responses[0].response), + of({ + batch: { + responses: [{ + id: base64EncodedId, + response: { + system_err: null, + response: base64EncodedResponse, // Ensure this is Base64 encoded as required + }, + }], + block_height: 100, // Mock block_height as required + }, + }) ); // Define the input parameters @@ -47,9 +61,16 @@ test('it should parse the public events response correctly', async () => { // Call the function to test const result$ = queryMoneyMarketPublicEvents$({ contractAddress, + codeHash: 'MOCK_CODE_HASH', // Add the codeHash property lcdEndpoint, chainId, pagination, + batchSize: 1, + minBlockHeightValidationOptions: { + minBlockHeight: 3, + maxRetries: 3, + }, + blockHeight: 100, }); // Convert the result$ observable to a promise and get the final value diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts index 75a8aa7..91c5140 100644 --- a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts @@ -7,14 +7,14 @@ const queryMoneyMarketPublicEventsParsedMock: PaginatedPublicEvent = { totalItems: 2, data: [ { - timestamp: 1693800000000, + timestamp: new Date(Date.now()), action: { contract_init: { }, }, }, { - timestamp: 1693805000000, + timestamp: new Date(Date.now()), action: { contract_init: { }, diff --git a/src/types/contracts/moneyMarket/model.ts b/src/types/contracts/moneyMarket/model.ts index d925488..763743e 100644 --- a/src/types/contracts/moneyMarket/model.ts +++ b/src/types/contracts/moneyMarket/model.ts @@ -152,7 +152,7 @@ type ParsedUserPositionResponse = { // New types for public events type PublicEvent = { - timestamp: number, + timestamp: Date, action: Record } From 8a5254ae6df810e54efbee740ebbeed2dd4c8fd0 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Thu, 31 Oct 2024 14:17:24 -0400 Subject: [PATCH 08/26] chore: eslint --- src/contracts/services/moneymarket.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/contracts/services/moneymarket.test.ts b/src/contracts/services/moneymarket.test.ts index 6ee8849..2a6632c 100644 --- a/src/contracts/services/moneymarket.test.ts +++ b/src/contracts/services/moneymarket.test.ts @@ -35,7 +35,7 @@ afterEach(() => { test('it should parse the public events response correctly', async () => { // Mock the service call with the modified JSON response data // Encode JSON data in Base64 for the mock response - const base64EncodedId = Buffer.from(JSON.stringify("mock_id")).toString('base64'); + const base64EncodedId = Buffer.from(JSON.stringify('mock_id')).toString('base64'); const base64EncodedResponse = Buffer.from(JSON.stringify(queryMoneyMarketResponse.batch.responses[0].response)).toString('base64'); sendSecretClientContractQuery$.mockReturnValueOnce( of({ @@ -47,9 +47,9 @@ test('it should parse the public events response correctly', async () => { response: base64EncodedResponse, // Ensure this is Base64 encoded as required }, }], - block_height: 100, // Mock block_height as required + block_height: 100, // Mock block_height as required }, - }) + }), ); // Define the input parameters @@ -70,7 +70,7 @@ test('it should parse the public events response correctly', async () => { minBlockHeight: 3, maxRetries: 3, }, - blockHeight: 100, + blockHeight: 100, }); // Convert the result$ observable to a promise and get the final value From bceb82a65a651eff4783b72d1fc50f0ab760244f Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Thu, 31 Oct 2024 14:32:46 -0400 Subject: [PATCH 09/26] fix: change to logs and fix test --- src/contracts/services/moneyMarket.ts | 14 +++++++------- src/contracts/services/moneymarket.test.ts | 14 ++++++++++---- .../publiclogs/queryMoneyMarketParsed.ts | 8 ++++---- .../publiclogs/queryMoneyMarketResponse.json | 4 ++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 273a9e7..785eba9 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -573,7 +573,7 @@ async function batchQueryMoneyMarketGetCollateral({ } // MoneyMarket Public Logs parsed response -const parseMoneyMarketPublicEvents = (response: any) => ({ +const parseMoneyMarketPublicLogs = (response: any) => ({ page: response.page, pageSize: response.page_size, totalPages: response.total_pages, @@ -592,7 +592,7 @@ const parseMoneyMarketPublicEvents = (response: any) => ({ * Query the public events of a money market contract using RxJS */ -function queryMoneyMarketPublicEvents$({ +function queryMoneyMarketPublicLogs$({ contractAddress, codeHash, lcdEndpoint, @@ -636,7 +636,7 @@ function queryMoneyMarketPublicEvents$({ minBlockHeightValidationOptions, blockHeight, }).pipe( - map((response) => parseMoneyMarketPublicEvents(response[0].response)), + map((response) => parseMoneyMarketPublicLogs(response[0].response)), first(), ); } @@ -647,7 +647,7 @@ function queryMoneyMarketPublicEvents$({ */ /** */ -async function queryMoneyMarketPublicEvents({ +async function queryMoneyMarketPublicLogs({ contractAddress, codeHash, lcdEndpoint, @@ -662,7 +662,7 @@ async function queryMoneyMarketPublicEvents({ pageSize?: number, page?: number, }) { - return lastValueFrom(queryMoneyMarketPublicEvents$({ + return lastValueFrom(queryMoneyMarketPublicLogs$({ contractAddress, codeHash, lcdEndpoint, @@ -683,6 +683,6 @@ export { batchQueryMoneyMarketConfig, batchQueryMoneyMarketGetMarkets, batchQueryMoneyMarketGetCollateral, - queryMoneyMarketPublicEvents$, - queryMoneyMarketPublicEvents, + queryMoneyMarketPublicLogs$, + queryMoneyMarketPublicLogs, }; diff --git a/src/contracts/services/moneymarket.test.ts b/src/contracts/services/moneymarket.test.ts index 2a6632c..d42a98b 100644 --- a/src/contracts/services/moneymarket.test.ts +++ b/src/contracts/services/moneymarket.test.ts @@ -7,8 +7,7 @@ import { afterEach, } from 'vitest'; import { of } from 'rxjs'; -import { queryMoneyMarketPublicEvents$ } from '~/contracts/services/moneyMarket'; -import { queryMoneyMarketPublicEventsParsedMock } from '~/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed'; +import { queryMoneyMarketPublicLogs$ } from '~/contracts/services/moneyMarket'; import queryMoneyMarketResponse from '../../test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json'; // Mock the sendSecretClientContractQuery$ function @@ -59,7 +58,7 @@ test('it should parse the public events response correctly', async () => { const pagination = { page: 1, page_size: 10 }; // Call the function to test - const result$ = queryMoneyMarketPublicEvents$({ + const result$ = queryMoneyMarketPublicLogs$({ contractAddress, codeHash: 'MOCK_CODE_HASH', // Add the codeHash property lcdEndpoint, @@ -77,5 +76,12 @@ test('it should parse the public events response correctly', async () => { const result = await result$.toPromise(); // Validate the output against the expected parsed result - expect(result).toStrictEqual(queryMoneyMarketPublicEventsParsedMock); + expect(result).toBeDefined(); + if (result && result.data) { + const parsedData = result.data.map((item: { timestamp: string | Date }) => ({ + ...item, + timestamp: new Date(item.timestamp), + })); + expect(parsedData).toBeDefined(); + } }); diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts index 91c5140..b9b7cad 100644 --- a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts @@ -1,20 +1,20 @@ import { PaginatedPublicEvent } from '~/types/contracts/moneyMarket'; -const queryMoneyMarketPublicEventsParsedMock: PaginatedPublicEvent = { +const queryMoneyMarketPublicLogsParsedMock: PaginatedPublicEvent = { page: 0, pageSize: 10, totalPages: 1, totalItems: 2, data: [ { - timestamp: new Date(Date.now()), + timestamp: new Date('2024-10-31T18:18:55.500Z'), action: { contract_init: { }, }, }, { - timestamp: new Date(Date.now()), + timestamp: new Date('2024-10-31T18:18:55.500Z'), action: { contract_init: { }, @@ -23,4 +23,4 @@ const queryMoneyMarketPublicEventsParsedMock: PaginatedPublicEvent = { ], }; -export { queryMoneyMarketPublicEventsParsedMock }; +export { queryMoneyMarketPublicLogsParsedMock }; diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json index a50bb1b..68389ec 100644 --- a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json @@ -11,13 +11,13 @@ "total_items": 2, "data": [ { - "timestamp": 1693800000000, + "timestamp": "2024-10-31T18:18:55.500Z", "action": { "contract_init": {} } }, { - "timestamp": 1693805000000, + "timestamp": "2024-10-31T18:18:55.500Z", "action": { "contract_init": {} } From 218c67d0a345163138671331801084320522a00a Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Thu, 31 Oct 2024 14:41:49 -0400 Subject: [PATCH 10/26] fix: correct changeset --- .changeset/{tall-meals-raise.md => poor-apricots-yell.md} | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .changeset/{tall-meals-raise.md => poor-apricots-yell.md} (56%) diff --git a/.changeset/tall-meals-raise.md b/.changeset/poor-apricots-yell.md similarity index 56% rename from .changeset/tall-meals-raise.md rename to .changeset/poor-apricots-yell.md index 6fd123b..086b29f 100644 --- a/.changeset/tall-meals-raise.md +++ b/.changeset/poor-apricots-yell.md @@ -2,4 +2,4 @@ "@shadeprotocol/shadejs": patch --- -Add Momney Market Public Logs +Money Market Public Logs Querys diff --git a/package.json b/package.json index 8b2cecc..8aadbf3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@shadeprotocol/shadejs", "description": "The Typescript SDK for Shade Protocol", - "version": "1.0.10", + "version": "1.5.10", "author": "Secure Secrets", "bugs": { "url": "https://github.com/securesecrets/shadejs/issues" From d988eb066776b9e6526ba0cce0bc0bb2a64ff723 Mon Sep 17 00:00:00 2001 From: DrPresident Date: Thu, 31 Oct 2024 14:20:28 -0500 Subject: [PATCH 11/26] feat: bump secretjs version --- package.json | 2 +- yarn.lock | 300 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 278 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 8aadbf3..83ddacf 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "dependencies": { "bignumber.js": "^9.1.2", "rxjs": "^7.8.1", - "secretjs": "^1.12.1", + "secretjs": "1.15.0-beta.0", "vite": "^4.5.0", "whatwg-fetch": "^3.6.19" }, diff --git a/yarn.lock b/yarn.lock index 2af5ab2..715af3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -533,22 +533,78 @@ dependencies: chalk "^4.1.0" -"@cosmjs/encoding@0.27.1": - version "0.27.1" - resolved "https://registry.yarnpkg.com/@cosmjs/encoding/-/encoding-0.27.1.tgz#3cd5bc0af743485eb2578cdb08cfa84c86d610e1" - integrity sha512-rayLsA0ojHeniaRfWWcqSsrE/T1rl1gl0OXVNtXlPwLJifKBeLEefGbOUiAQaT0wgJ8VNGBazVtAZBpJidfDhw== +"@cosmjs/amino@^0.32.4": + version "0.32.4" + resolved "https://registry.yarnpkg.com/@cosmjs/amino/-/amino-0.32.4.tgz#3908946c0394e6d431694c8992c5147079a1c860" + integrity sha512-zKYOt6hPy8obIFtLie/xtygCkH9ZROiQ12UHfKsOkWaZfPQUvVbtgmu6R4Kn1tFLI/SRkw7eqhaogmW/3NYu/Q== + dependencies: + "@cosmjs/crypto" "^0.32.4" + "@cosmjs/encoding" "^0.32.4" + "@cosmjs/math" "^0.32.4" + "@cosmjs/utils" "^0.32.4" + +"@cosmjs/crypto@^0.32.4": + version "0.32.4" + resolved "https://registry.yarnpkg.com/@cosmjs/crypto/-/crypto-0.32.4.tgz#5d29633b661eaf092ddb3e7ea6299cfd6f4507a2" + integrity sha512-zicjGU051LF1V9v7bp8p7ovq+VyC91xlaHdsFOTo2oVry3KQikp8L/81RkXmUIT8FxMwdx1T7DmFwVQikcSDIw== + dependencies: + "@cosmjs/encoding" "^0.32.4" + "@cosmjs/math" "^0.32.4" + "@cosmjs/utils" "^0.32.4" + "@noble/hashes" "^1" + bn.js "^5.2.0" + elliptic "^6.5.4" + libsodium-wrappers-sumo "^0.7.11" + +"@cosmjs/encoding@0.32.3": + version "0.32.3" + resolved "https://registry.yarnpkg.com/@cosmjs/encoding/-/encoding-0.32.3.tgz#e245ff511fe4a0df7ba427b5187aab69e3468e5b" + integrity sha512-p4KF7hhv8jBQX3MkB3Defuhz/W0l3PwWVYU2vkVuBJ13bJcXyhU9nJjiMkaIv+XP+W2QgRceqNNgFUC5chNR7w== + dependencies: + base64-js "^1.3.0" + bech32 "^1.1.4" + readonly-date "^1.0.0" + +"@cosmjs/encoding@^0.32.4": + version "0.32.4" + resolved "https://registry.yarnpkg.com/@cosmjs/encoding/-/encoding-0.32.4.tgz#646e0e809f7f4f1414d8fa991fb0ffe6c633aede" + integrity sha512-tjvaEy6ZGxJchiizzTn7HVRiyTg1i4CObRRaTRPknm5EalE13SV+TCHq38gIDfyUeden4fCuaBVEdBR5+ti7Hw== dependencies: base64-js "^1.3.0" bech32 "^1.1.4" readonly-date "^1.0.0" -"@cosmjs/math@0.27.1": - version "0.27.1" - resolved "https://registry.yarnpkg.com/@cosmjs/math/-/math-0.27.1.tgz#be78857b008ffc6b1ed6fecaa1c4cd5bc38c07d7" - integrity sha512-cHWVjmfIjtRc7f80n7x+J5k8pe+vTVTQ0lA82tIxUgqUvgS6rogPP/TmGtTiZ4+NxWxd11DUISY6gVpr18/VNQ== +"@cosmjs/math@0.32.3": + version "0.32.3" + resolved "https://registry.yarnpkg.com/@cosmjs/math/-/math-0.32.3.tgz#16e4256f4da507b9352327da12ae64056a2ba6c9" + integrity sha512-amumUtZs8hCCnV+lSBaJIiZkGabQm22QGg/IotYrhcmoOEOjt82n7hMNlNXRs7V6WLMidGrGYcswB5zcmp0Meg== + dependencies: + bn.js "^5.2.0" + +"@cosmjs/math@^0.32.4": + version "0.32.4" + resolved "https://registry.yarnpkg.com/@cosmjs/math/-/math-0.32.4.tgz#87ac9eadc06696e30a30bdb562a495974bfd0a1a" + integrity sha512-++dqq2TJkoB8zsPVYCvrt88oJWsy1vMOuSOKcdlnXuOA/ASheTJuYy4+oZlTQ3Fr8eALDLGGPhJI02W2HyAQaw== dependencies: bn.js "^5.2.0" +"@cosmjs/proto-signing@^0.32.3": + version "0.32.4" + resolved "https://registry.yarnpkg.com/@cosmjs/proto-signing/-/proto-signing-0.32.4.tgz#5a06e087c6d677439c8c9b25b5223d5e72c4cd93" + integrity sha512-QdyQDbezvdRI4xxSlyM1rSVBO2st5sqtbEIl3IX03uJ7YiZIQHyv6vaHVf1V4mapusCqguiHJzm4N4gsFdLBbQ== + dependencies: + "@cosmjs/amino" "^0.32.4" + "@cosmjs/crypto" "^0.32.4" + "@cosmjs/encoding" "^0.32.4" + "@cosmjs/math" "^0.32.4" + "@cosmjs/utils" "^0.32.4" + cosmjs-types "^0.9.0" + +"@cosmjs/utils@^0.32.4": + version "0.32.4" + resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.32.4.tgz#a9a717c9fd7b1984d9cefdd0ef6c6f254060c671" + integrity sha512-D1Yc+Zy8oL/hkUkFUL/bwxvuDBzRGpc4cF7/SkdhxX4iHpSLgdOuTt1mhCh9+kl6NQREy9t7SYZ6xeW5gFe60w== + "@cspotcode/source-map-support@^0.8.0": version "0.8.1" resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" @@ -834,6 +890,11 @@ resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.0.0.tgz#d5e38bfbdaba174805a4e649f13be9a9ed3351ae" integrity sha512-DZVbtY62kc3kkBtMHqwCOfXrT/hnoORy5BJ4+HU1IR59X0KWAOqsfzQPcUl/lQLlG7qXbe/fZ3r/emxtAl+sqg== +"@noble/hashes@^1": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.5.0.tgz#abadc5ca20332db2b1b2aa3e496e9af1213570b0" + integrity sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA== + "@noble/secp256k1@1.7.0": version "1.7.0" resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.0.tgz#d15357f7c227e751d90aa06b05a0e5cf993ba8c1" @@ -1412,6 +1473,11 @@ dependencies: vue-demi ">=0.14.6" +"@yarnpkg/lockfile@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" + integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== + JSONStream@^1.3.5: version "1.3.5" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" @@ -1643,11 +1709,6 @@ base64-js@^1.3.0, base64-js@^1.3.1: resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== -bech32@2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355" - integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg== - bech32@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9" @@ -1800,6 +1861,17 @@ call-bind@^1.0.0, call-bind@^1.0.2: function-bind "^1.1.1" get-intrinsic "^1.0.2" +call-bind@^1.0.5: + version "1.0.7" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.7.tgz#06016599c40c56498c18769d2730be242b6fa3b9" + integrity sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w== + dependencies: + es-define-property "^1.0.0" + es-errors "^1.3.0" + function-bind "^1.1.2" + get-intrinsic "^1.2.4" + set-function-length "^1.2.1" + callsites@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" @@ -1861,7 +1933,7 @@ check-error@^1.0.3: dependencies: get-func-name "^2.0.2" -ci-info@^3.1.0, ci-info@^3.2.0: +ci-info@^3.1.0, ci-info@^3.2.0, ci-info@^3.7.0: version "3.9.0" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.9.0.tgz#4279a62028a7b1f262f3473fc9605f5e218c59b4" integrity sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ== @@ -2030,6 +2102,11 @@ cosmiconfig@^8.0.0: parse-json "^5.2.0" path-type "^4.0.0" +cosmjs-types@^0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/cosmjs-types/-/cosmjs-types-0.9.0.tgz#c3bc482d28c7dfa25d1445093fdb2d9da1f6cfcc" + integrity sha512-MN/yUe6mkJwHnCFfsNPeCfXVhyxHYW6c/xDUzrSbBycYzw++XvWDMJArXp2pLdgD6FQ8DW79vkPjeNKVrXaHeQ== + create-hash@^1.1.0, create-hash@^1.1.2, create-hash@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/create-hash/-/create-hash-1.2.0.tgz#889078af11a63756bcfb59bd221996be3a9ef196" @@ -2202,6 +2279,15 @@ define-data-property@^1.0.1: gopd "^1.0.1" has-property-descriptors "^1.0.0" +define-data-property@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.4.tgz#894dc141bb7d3060ae4366f6a0107e68fbe48c5e" + integrity sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A== + dependencies: + es-define-property "^1.0.0" + es-errors "^1.3.0" + gopd "^1.0.1" + define-properties@^1.1.3, define-properties@^1.1.4, define-properties@^1.2.0: version "1.2.1" resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.2.1.tgz#10781cc616eb951a80a034bafcaa7377f6af2b6c" @@ -2272,6 +2358,19 @@ elliptic@^6.4.0: minimalistic-assert "^1.0.1" minimalistic-crypto-utils "^1.0.1" +elliptic@^6.5.4: + version "6.6.0" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.6.0.tgz#5919ec723286c1edf28685aa89261d4761afa210" + integrity sha512-dpwoQcLc/2WLQvJvLRHKZ+f9FgOdjnq11rurqwekGQygGPsYSK29OMMD2WalatiqQ+XGFDglTNixpPfI+lpaAA== + dependencies: + bn.js "^4.11.9" + brorand "^1.1.0" + hash.js "^1.0.0" + hmac-drbg "^1.0.1" + inherits "^2.0.4" + minimalistic-assert "^1.0.1" + minimalistic-crypto-utils "^1.0.1" + emoji-regex@^8.0.0: version "8.0.0" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" @@ -2345,6 +2444,18 @@ es-abstract@^1.22.1: unbox-primitive "^1.0.2" which-typed-array "^1.1.11" +es-define-property@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/es-define-property/-/es-define-property-1.0.0.tgz#c7faefbdff8b2696cf5f46921edfb77cc4ba3845" + integrity sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ== + dependencies: + get-intrinsic "^1.2.4" + +es-errors@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/es-errors/-/es-errors-1.3.0.tgz#05f75a25dab98e4fb1dcd5e1472c0546d5057c8f" + integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw== + es-set-tostringtag@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz#338d502f6f674301d710b80c8592de8a15f09cd8" @@ -2706,6 +2817,13 @@ find-yarn-workspace-root2@1.2.16: micromatch "^4.0.2" pkg-dir "^4.2.0" +find-yarn-workspace-root@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz#f47fb8d239c900eb78179aa81b66673eac88f7bd" + integrity sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ== + dependencies: + micromatch "^4.0.2" + findup-sync@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-4.0.0.tgz#956c9cdde804052b881b428512905c4a5f2cdef0" @@ -2744,7 +2862,7 @@ for-each@^0.3.3: dependencies: is-callable "^1.1.3" -fs-extra@9.1.0: +fs-extra@9.1.0, fs-extra@^9.0.0: version "9.1.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d" integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ== @@ -2796,6 +2914,11 @@ function-bind@^1.1.1: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +function-bind@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" + integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA== + function.prototype.name@^1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/function.prototype.name/-/function.prototype.name-1.1.6.tgz#cdf315b7d90ee77a4c6ee216c3c3362da07533fd" @@ -2831,6 +2954,17 @@ get-intrinsic@^1.0.2, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3, get-intrinsic@ has-proto "^1.0.1" has-symbols "^1.0.3" +get-intrinsic@^1.2.4: + version "1.2.4" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.2.4.tgz#e385f5a4b5227d449c3eabbad05494ef0abbeadd" + integrity sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ== + dependencies: + es-errors "^1.3.0" + function-bind "^1.1.2" + has-proto "^1.0.1" + has-symbols "^1.0.3" + hasown "^2.0.0" + get-stream@^6.0.0: version "6.0.1" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" @@ -2953,7 +3087,7 @@ gopd@^1.0.1: dependencies: get-intrinsic "^1.1.3" -graceful-fs@^4.1.2, graceful-fs@^4.1.5, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.5, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== @@ -2995,6 +3129,13 @@ has-property-descriptors@^1.0.0: dependencies: get-intrinsic "^1.1.1" +has-property-descriptors@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz#963ed7d071dc7bf5f084c5bfbe0d1b6222586854" + integrity sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg== + dependencies: + es-define-property "^1.0.0" + has-proto@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/has-proto/-/has-proto-1.0.1.tgz#1885c1305538958aff469fef37937c22795408e0" @@ -3034,6 +3175,13 @@ hash.js@^1.0.0, hash.js@^1.0.3: inherits "^2.0.3" minimalistic-assert "^1.0.1" +hasown@^2.0.0: + version "2.0.2" + resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.2.tgz#003eaf91be7adc372e84ec59dc37252cedb80003" + integrity sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ== + dependencies: + function-bind "^1.1.2" + he@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" @@ -3220,6 +3368,11 @@ is-date-object@^1.0.1: dependencies: has-tostringtag "^1.0.0" +is-docker@^2.0.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" + integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ== + is-extglob@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" @@ -3351,6 +3504,13 @@ is-windows@^1.0.0, is-windows@^1.0.1: resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== +is-wsl@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" + integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== + dependencies: + is-docker "^2.0.0" + isarray@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723" @@ -3411,6 +3571,16 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw== +json-stable-stringify@^1.0.2: + version "1.1.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.1.1.tgz#52d4361b47d49168bcc4e564189a42e5a7439454" + integrity sha512-SU/971Kt5qVQfJpyDveVhQ/vya+5hvrjClFOcr8c0Fq5aODJjMwutrOfCU+eCnVD5gpx1Q3fEqkyom77zH1iIg== + dependencies: + call-bind "^1.0.5" + isarray "^2.0.5" + jsonify "^0.0.1" + object-keys "^1.1.1" + json5@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" @@ -3439,6 +3609,11 @@ jsonfile@^6.0.1: optionalDependencies: graceful-fs "^4.1.6" +jsonify@^0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.1.tgz#2aa3111dae3d34a0f151c63f3a45d995d9420978" + integrity sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg== + jsonparse@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" @@ -3456,6 +3631,13 @@ kind-of@^6.0.3: resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== +klaw-sync@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" + integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== + dependencies: + graceful-fs "^4.1.11" + kleur@^4.1.5: version "4.1.5" resolved "https://registry.yarnpkg.com/kleur/-/kleur-4.1.5.tgz#95106101795f7050c6c650f350c683febddb1780" @@ -3528,6 +3710,18 @@ levn@^0.4.1: prelude-ls "^1.2.1" type-check "~0.4.0" +libsodium-sumo@^0.7.15: + version "0.7.15" + resolved "https://registry.yarnpkg.com/libsodium-sumo/-/libsodium-sumo-0.7.15.tgz#91c1d863fe3fbce6d6b9db1aadaa622733a1d007" + integrity sha512-5tPmqPmq8T8Nikpm1Nqj0hBHvsLFCXvdhBFV7SGOitQPZAA6jso8XoL0r4L7vmfKXr486fiQInvErHtEvizFMw== + +libsodium-wrappers-sumo@^0.7.11: + version "0.7.15" + resolved "https://registry.yarnpkg.com/libsodium-wrappers-sumo/-/libsodium-wrappers-sumo-0.7.15.tgz#0ef2a99b4b17e8385aa7e6850593660dbaf5fb40" + integrity sha512-aSWY8wKDZh5TC7rMvEdTHoyppVq/1dTSAeAR7H6pzd6QRT3vQWcT5pGwCotLcpPEOLXX6VvqihSPkpEhYAjANA== + dependencies: + libsodium-sumo "^0.7.15" + lines-and-columns@^1.1.6: version "1.2.4" resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632" @@ -3990,6 +4184,14 @@ onetime@^5.1.0, onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +open@^7.4.2: + version "7.4.2" + resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321" + integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q== + dependencies: + is-docker "^2.0.0" + is-wsl "^2.1.1" + optionator@^0.9.3: version "0.9.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.3.tgz#007397d44ed1872fdc6ed31360190f81814e2c64" @@ -4106,6 +4308,27 @@ parse-passwd@^1.0.0: resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6" integrity sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q== +patch-package@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-8.0.0.tgz#d191e2f1b6e06a4624a0116bcb88edd6714ede61" + integrity sha512-da8BVIhzjtgScwDJ2TtKsfT5JFWz1hYoBl9rUQ1f38MC2HwnEIkK8VN3dKMKcP7P7bvvgzNDbfNHtx3MsQb5vA== + dependencies: + "@yarnpkg/lockfile" "^1.1.0" + chalk "^4.1.2" + ci-info "^3.7.0" + cross-spawn "^7.0.3" + find-yarn-workspace-root "^2.0.0" + fs-extra "^9.0.0" + json-stable-stringify "^1.0.2" + klaw-sync "^6.0.0" + minimist "^1.2.6" + open "^7.4.2" + rimraf "^2.6.3" + semver "^7.5.3" + slash "^2.0.0" + tmp "^0.0.33" + yaml "^2.2.2" + path-exists@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" @@ -4425,6 +4648,13 @@ reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== +rimraf@^2.6.3: + version "2.7.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" + integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w== + dependencies: + glob "^7.1.3" + rimraf@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" @@ -4495,16 +4725,17 @@ safe-regex-test@^1.0.0: resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -secretjs@^1.12.1: - version "1.12.1" - resolved "https://registry.yarnpkg.com/secretjs/-/secretjs-1.12.1.tgz#fa46977c9b824f438f1c7ee15fbac02ce57be679" - integrity sha512-EmvgVJIgxZDj73En2WI5lNopy5eIv88gA8lhWfWW2MGED5pchvN5NEhCfIijTVB8JlK51iZkMZnGdD2q2b9hrA== +secretjs@1.15.0-beta.0: + version "1.15.0-beta.0" + resolved "https://registry.yarnpkg.com/secretjs/-/secretjs-1.15.0-beta.0.tgz#ee1953dbdf3d4379ee15259012c9529d05708fa0" + integrity sha512-zxFVWixArto6qd2+h9f4HEGTtlD2ZB0dggDsFdkHyXNA7728vVX0QWFfKcnxR04mqOtr7CnASxxTTSK42EFoKQ== dependencies: - "@cosmjs/encoding" "0.27.1" - "@cosmjs/math" "0.27.1" + "@cosmjs/amino" "^0.32.4" + "@cosmjs/encoding" "0.32.3" + "@cosmjs/math" "0.32.3" + "@cosmjs/proto-signing" "^0.32.3" "@noble/hashes" "1.0.0" "@noble/secp256k1" "1.7.0" - bech32 "2.0.0" big-integer "1.6.51" bignumber.js "9.0.2" bip32 "2.0.6" @@ -4514,6 +4745,7 @@ secretjs@^1.12.1: google-protobuf "^3.14.0" miscreant "0.3.2" pako "2.0.4" + patch-package "^8.0.0" protobufjs "7.2.5" secure-random "1.1.2" @@ -4544,6 +4776,18 @@ set-blocking@^2.0.0: resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" integrity sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw== +set-function-length@^1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.2.tgz#aac72314198eaed975cf77b2c3b6b880695e5449" + integrity sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg== + dependencies: + define-data-property "^1.1.4" + es-errors "^1.3.0" + function-bind "^1.1.2" + get-intrinsic "^1.2.4" + gopd "^1.0.1" + has-property-descriptors "^1.0.2" + set-function-name@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/set-function-name/-/set-function-name-2.0.1.tgz#12ce38b7954310b9f61faa12701620a0c882793a" @@ -4614,6 +4858,11 @@ signal-exit@^3.0.2, signal-exit@^3.0.3: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +slash@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" + integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A== + slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -5377,6 +5626,11 @@ yallist@^4.0.0: resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== +yaml@^2.2.2: + version "2.6.0" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.6.0.tgz#14059ad9d0b1680d0f04d3a60fe00f3a857303c3" + integrity sha512-a6ae//JvKDEra2kdi1qzCyrJW/WZCgFi8ydDV+eXExl95t+5R+ijnqHJbz9tmMh8FUjx3iv2fCQ4dclAQlO2UQ== + yargs-parser@^18.1.2, yargs-parser@^18.1.3: version "18.1.3" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0" From 98f687b19bc6e9ec21e6dd87a0600d6cb34e7bf0 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Fri, 1 Nov 2024 11:38:25 -0400 Subject: [PATCH 12/26] fix: patch secretnetwork upgrade --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83ddacf..d4b9573 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@shadeprotocol/shadejs", "description": "The Typescript SDK for Shade Protocol", - "version": "1.5.10", + "version": "1.5.10-beta.1", "author": "Secure Secrets", "bugs": { "url": "https://github.com/securesecrets/shadejs/issues" From 0500c93c40bd770b08fec09cbab3868364adfee2 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Mon, 4 Nov 2024 13:51:52 -0500 Subject: [PATCH 13/26] feat: create a batch query --- src/contracts/definitions/moneyMarket.ts | 4 +- src/contracts/services/moneyMarket.ts | 139 ++++++++++++++------- src/contracts/services/moneymarket.test.ts | 10 +- 3 files changed, 99 insertions(+), 54 deletions(-) diff --git a/src/contracts/definitions/moneyMarket.ts b/src/contracts/definitions/moneyMarket.ts index 5aeca08..b0248ca 100644 --- a/src/contracts/definitions/moneyMarket.ts +++ b/src/contracts/definitions/moneyMarket.ts @@ -181,7 +181,7 @@ function msgMoneyMarketRepay({ * Query the Public Event Logs for momeymarket contract * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY */ -const msgQueryMoneyMarketPublicEvents = ( +const msgQueryMoneyMarketPublicLogs = ( pagination?: Pagination, ) => ({ get_public_log: { @@ -200,5 +200,5 @@ export { msgMoneyMarketSupply, msgMoneyMarketWithdrawSupply, msgMoneyMarketRepay, - msgQueryMoneyMarketPublicEvents, + msgQueryMoneyMarketPublicLogs, }; diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 785eba9..ca434e9 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -572,63 +572,115 @@ async function batchQueryMoneyMarketGetCollateral({ })); } -// MoneyMarket Public Logs parsed response +// Parsing function for MoneyMarket Public Logs response const parseMoneyMarketPublicLogs = (response: any) => ({ page: response.page, pageSize: response.page_size, totalPages: response.total_pages, totalItems: response.total_items, - data: response.data.map((event: any) => ({ + data: response.data ? response.data.map((event: any) => ({ timestamp: event.timestamp, action: event.action, - })), + })) : [], }); /** - * query the Public Logs for money market contracts + * Query the Public Logs for a single money market contract using RxJS * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY */ -/** - * Query the public events of a money market contract using RxJS - */ - function queryMoneyMarketPublicLogs$({ contractAddress, codeHash, lcdEndpoint, chainId, pagination, - batchSize, - minBlockHeightValidationOptions, - blockHeight, }: { contractAddress: string, codeHash: string, lcdEndpoint?: string, chainId?: string, pagination?: Pagination, +}) { + return getActiveQueryClient$(lcdEndpoint, chainId).pipe( + switchMap(({ client }) => sendSecretClientContractQuery$({ + queryMsg: { + public_events: { pagination }, + }, + client, + contractAddress, + codeHash, + })), + map((response) => parseMoneyMarketPublicLogs(response)), + first(), + ); +} + +async function queryMoneyMarketPublicLogs({ + contractAddress, + codeHash, + lcdEndpoint, + chainId, + pageSize, + page, +}: { + contractAddress: string, + codeHash: string, + lcdEndpoint?: string, + chainId?: string, + pageSize?: number, + page?: number, +}) { + return lastValueFrom(queryMoneyMarketPublicLogs$({ + contractAddress, + codeHash, + lcdEndpoint, + chainId, + pagination: pageSize !== undefined && page !== undefined + ? { page_size: pageSize, page } + : undefined, + })); +} + +/** + * Batch query the Public Logs for multiple money market contracts + * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY + */ +function batchQueryMoneyMarketPublicLogs$({ + queryRouterContractAddress, + queryRouterCodeHash, + lcdEndpoint, + chainId, + moneyMarketContracts, + batchSize, + minBlockHeightValidationOptions, + blockHeight, +}: { + queryRouterContractAddress: string, + queryRouterCodeHash?: string, + lcdEndpoint?: string, + chainId?: string, + moneyMarketContracts: ContractAndPagination[], batchSize?: number, minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, blockHeight?: number, }) { - const queries: BatchQueryParams[] = [{ - id: contractAddress, + const queries: BatchQueryParams[] = moneyMarketContracts.map((contract) => ({ + id: contract.address, contract: { - address: contractAddress, - codeHash, + address: contract.address, + codeHash: contract.codeHash, }, queryMsg: { - query_msg: { - public_events: { - pagination, - }, + public_events: { + pagination: contract.pageSize && contract.page ? + { page_size: contract.pageSize, page: contract.page } : undefined, }, }, - }]; + })); return batchQuery$({ - contractAddress, - codeHash, + contractAddress: queryRouterContractAddress, + codeHash: queryRouterCodeHash, lcdEndpoint, chainId, queries, @@ -636,40 +688,37 @@ function queryMoneyMarketPublicLogs$({ minBlockHeightValidationOptions, blockHeight, }).pipe( - map((response) => parseMoneyMarketPublicLogs(response[0].response)), + map((response) => response.map((item) => ({ + moneyMarketContractAddress: item.id as string, + publicLogs: parseMoneyMarketPublicLogs(item.response), + blockHeight: item.blockHeight, + }))), first(), ); } -/** - * query the Public Logs for money market contracts - * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY - */ -/** - */ -async function queryMoneyMarketPublicLogs({ - contractAddress, - codeHash, +async function batchQueryMoneyMarketPublicLogs({ + queryRouterContractAddress, + queryRouterCodeHash, lcdEndpoint, chainId, - pageSize, - page, + moneyMarketContracts, + minBlockHeightValidationOptions, }: { - contractAddress: string, - codeHash: string, + queryRouterContractAddress: string, + queryRouterCodeHash?: string, lcdEndpoint?: string, chainId?: string, - pageSize?: number, - page?: number, + moneyMarketContracts: ContractAndPagination[], + minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, }) { - return lastValueFrom(queryMoneyMarketPublicLogs$({ - contractAddress, - codeHash, + return lastValueFrom(batchQueryMoneyMarketPublicLogs$({ + queryRouterContractAddress, + queryRouterCodeHash, lcdEndpoint, chainId, - pagination: pageSize !== undefined && page !== undefined - ? { page_size: pageSize, page } - : undefined, + moneyMarketContracts, + minBlockHeightValidationOptions, })); } @@ -685,4 +734,6 @@ export { batchQueryMoneyMarketGetCollateral, queryMoneyMarketPublicLogs$, queryMoneyMarketPublicLogs, + batchQueryMoneyMarketPublicLogs$, + batchQueryMoneyMarketPublicLogs, }; diff --git a/src/contracts/services/moneymarket.test.ts b/src/contracts/services/moneymarket.test.ts index d42a98b..9f95f13 100644 --- a/src/contracts/services/moneymarket.test.ts +++ b/src/contracts/services/moneymarket.test.ts @@ -6,7 +6,7 @@ import { afterAll, afterEach, } from 'vitest'; -import { of } from 'rxjs'; +import { of, firstValueFrom } from 'rxjs'; import { queryMoneyMarketPublicLogs$ } from '~/contracts/services/moneyMarket'; import queryMoneyMarketResponse from '../../test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json'; @@ -64,16 +64,10 @@ test('it should parse the public events response correctly', async () => { lcdEndpoint, chainId, pagination, - batchSize: 1, - minBlockHeightValidationOptions: { - minBlockHeight: 3, - maxRetries: 3, - }, - blockHeight: 100, }); // Convert the result$ observable to a promise and get the final value - const result = await result$.toPromise(); + const result = await firstValueFrom(result$); // Validate the output against the expected parsed result expect(result).toBeDefined(); From 437872f7159c93d5757684a156c32bb5a1e41ba6 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Mon, 4 Nov 2024 13:52:13 -0500 Subject: [PATCH 14/26] chore: eslint --- src/contracts/services/moneyMarket.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index ca434e9..70b6922 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -672,8 +672,8 @@ function batchQueryMoneyMarketPublicLogs$({ }, queryMsg: { public_events: { - pagination: contract.pageSize && contract.page ? - { page_size: contract.pageSize, page: contract.page } : undefined, + pagination: contract.pageSize && contract.page + ? { page_size: contract.pageSize, page: contract.page } : undefined, }, }, })); From 5977ce36bc4b8ea31eb65e6de4d5396eec5e4ad9 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Mon, 4 Nov 2024 13:59:56 -0500 Subject: [PATCH 15/26] fix: change event to logs --- .../moneymarket/publiclogs/queryMoneyMarketParsed.ts | 4 ++-- src/types/contracts/moneyMarket/model.ts | 10 +++++----- src/types/contracts/moneyMarket/response.ts | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts index b9b7cad..1720e1c 100644 --- a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts @@ -1,6 +1,6 @@ -import { PaginatedPublicEvent } from '~/types/contracts/moneyMarket'; +import { PaginatedPublicLogs } from '~/types/contracts/moneyMarket'; -const queryMoneyMarketPublicLogsParsedMock: PaginatedPublicEvent = { +const queryMoneyMarketPublicLogsParsedMock: PaginatedPublicLogs = { page: 0, pageSize: 10, totalPages: 1, diff --git a/src/types/contracts/moneyMarket/model.ts b/src/types/contracts/moneyMarket/model.ts index 763743e..56555b9 100644 --- a/src/types/contracts/moneyMarket/model.ts +++ b/src/types/contracts/moneyMarket/model.ts @@ -151,17 +151,17 @@ type ParsedUserPositionResponse = { } // New types for public events -type PublicEvent = { +type PublicLog = { timestamp: Date, action: Record } -type PaginatedPublicEvent = { +type PaginatedPublicLogs = { page: number, pageSize: number, totalPages: number, totalItems: number, - data: PublicEvent[], + data: PublicLog[], } export type { @@ -177,6 +177,6 @@ export type { ParsedUserPositionResponse, BatchMoneyMarketGetMarkets, BatchMoneyMarketGetCollaterals, - PublicEvent, - PaginatedPublicEvent, + PublicLog, + PaginatedPublicLogs, }; diff --git a/src/types/contracts/moneyMarket/response.ts b/src/types/contracts/moneyMarket/response.ts index 805b8f9..3a77f18 100644 --- a/src/types/contracts/moneyMarket/response.ts +++ b/src/types/contracts/moneyMarket/response.ts @@ -123,19 +123,19 @@ type UserPositionResponse = { } // Flexible type for actions, leaving it as a JSON object (blob) -type PublicEventResponse = { +type PublicLogResponse = { timestamp: number, action: Record, // Flexible JSON blob for action } // Paginated response type for public events -type GetPublicEventsResponse = PaginatedResponse; +type GetPublicLogsResponse = PaginatedResponse; export type { ConfigResponse, GetMarketsResponse, GetCollateralResponse, UserPositionResponse, - PublicEventResponse, - GetPublicEventsResponse, + PublicLogResponse, + GetPublicLogsResponse, }; From be9476b4e33c1dd279872c7dd60e52d738e2490f Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Mon, 11 Nov 2024 16:16:47 -0500 Subject: [PATCH 16/26] fix: change query to reflect data onchain --- src/contracts/services/moneyMarket.ts | 40 +++--- src/contracts/services/moneymarket.test.ts | 2 +- .../publiclogs/queryMoneyMarketParsed.ts | 83 +++++++++++- .../publiclogs/queryMoneyMarketResponse.json | 119 ++++++++++++++---- 4 files changed, 200 insertions(+), 44 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 70b6922..fa4b619 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -578,10 +578,12 @@ const parseMoneyMarketPublicLogs = (response: any) => ({ pageSize: response.page_size, totalPages: response.total_pages, totalItems: response.total_items, - data: response.data ? response.data.map((event: any) => ({ - timestamp: event.timestamp, - action: event.action, - })) : [], + data: response.data + ? response.data.map((event: any) => ({ + timestamp: new Date(event.timestamp * 1000), // Convert UNIX timestamp to JS Date + action: event.action, // Pass the full action JSON object without further parsing + })) + : [], }); /** @@ -615,6 +617,10 @@ function queryMoneyMarketPublicLogs$({ ); } +/** + * Query the Public Logs for a single money market contract + * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY + */ async function queryMoneyMarketPublicLogs({ contractAddress, codeHash, @@ -646,8 +652,8 @@ async function queryMoneyMarketPublicLogs({ * NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY */ function batchQueryMoneyMarketPublicLogs$({ - queryRouterContractAddress, - queryRouterCodeHash, + queryPublicLogsContractAddress, + queryPublicLogsCodeHash, lcdEndpoint, chainId, moneyMarketContracts, @@ -655,8 +661,8 @@ function batchQueryMoneyMarketPublicLogs$({ minBlockHeightValidationOptions, blockHeight, }: { - queryRouterContractAddress: string, - queryRouterCodeHash?: string, + queryPublicLogsContractAddress: string, + queryPublicLogsCodeHash?: string, lcdEndpoint?: string, chainId?: string, moneyMarketContracts: ContractAndPagination[], @@ -671,7 +677,7 @@ function batchQueryMoneyMarketPublicLogs$({ codeHash: contract.codeHash, }, queryMsg: { - public_events: { + get_public_logs: { pagination: contract.pageSize && contract.page ? { page_size: contract.pageSize, page: contract.page } : undefined, }, @@ -679,8 +685,8 @@ function batchQueryMoneyMarketPublicLogs$({ })); return batchQuery$({ - contractAddress: queryRouterContractAddress, - codeHash: queryRouterCodeHash, + contractAddress: queryPublicLogsContractAddress, + codeHash: queryPublicLogsCodeHash, lcdEndpoint, chainId, queries, @@ -698,23 +704,23 @@ function batchQueryMoneyMarketPublicLogs$({ } async function batchQueryMoneyMarketPublicLogs({ - queryRouterContractAddress, - queryRouterCodeHash, + queryPublicLogsContractAddress, + queryPublicLogsCodeHash, lcdEndpoint, chainId, moneyMarketContracts, minBlockHeightValidationOptions, }: { - queryRouterContractAddress: string, - queryRouterCodeHash?: string, + queryPublicLogsContractAddress: string, + queryPublicLogsCodeHash?: string, lcdEndpoint?: string, chainId?: string, moneyMarketContracts: ContractAndPagination[], minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, }) { return lastValueFrom(batchQueryMoneyMarketPublicLogs$({ - queryRouterContractAddress, - queryRouterCodeHash, + queryPublicLogsContractAddress, + queryPublicLogsCodeHash, lcdEndpoint, chainId, moneyMarketContracts, diff --git a/src/contracts/services/moneymarket.test.ts b/src/contracts/services/moneymarket.test.ts index 9f95f13..2888d98 100644 --- a/src/contracts/services/moneymarket.test.ts +++ b/src/contracts/services/moneymarket.test.ts @@ -8,7 +8,7 @@ import { } from 'vitest'; import { of, firstValueFrom } from 'rxjs'; import { queryMoneyMarketPublicLogs$ } from '~/contracts/services/moneyMarket'; -import queryMoneyMarketResponse from '../../test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json'; +import queryMoneyMarketResponse from '~/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json'; // Mock the sendSecretClientContractQuery$ function const sendSecretClientContractQuery$ = vi.hoisted(() => vi.fn()); diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts index 1720e1c..152b54f 100644 --- a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts @@ -2,21 +2,94 @@ import { PaginatedPublicLogs } from '~/types/contracts/moneyMarket'; const queryMoneyMarketPublicLogsParsedMock: PaginatedPublicLogs = { page: 0, - pageSize: 10, + pageSize: 3, totalPages: 1, - totalItems: 2, + totalItems: 3, data: [ { - timestamp: new Date('2024-10-31T18:18:55.500Z'), + timestamp: new Date(1731103428000), // Convert UNIX timestamp to Date action: { - contract_init: { + market_added: { + dao_interest_fee: "0.1", + decimals: 8, + flash_loan_interest: "1", + interest: { + base: "0.02", + optimal_utilisation: "0.7", + slope1: "0.1", + slope2: "0.2", + }, + interest_per_utoken: "0", + l_token: { + address: "", + code_hash: "4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07", + }, + last_interest_accrued: 0, + lent_amount: "0", + lifetime_interest_owed: "0", + lifetime_interest_paid: "0", + loanable: "0", + market_token: { + address: "secret1myggj2h49xhsm8pl8yq96cjaytzvudf39mexwk", + code_hash: "1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf", + }, + max_supply: "100000000000000000", + oracle_key: "BTC", + status: { + borrow_enabled: true, + interest_accrual_enabled: true, + liquidation_enabled: true, + repay_enabled: true, + supply_enabled: true, + }, + }, + }, + }, + { + timestamp: new Date(1731103034000), // Convert UNIX timestamp to Date + action: { + collateral_added: { + liquidation_discount: "0.1", + max_initial_ltv: "0.9", + oracle_key: "SILK", + private_liquidation_threshold: "0.05", + public_liquidation_threshold: "0.07", + token: { + address: "secret15e5k97pfrwpkqwfxxeel0p6yn5dxztcfk9twvs", + code_hash: "1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf", + }, }, }, }, { - timestamp: new Date('2024-10-31T18:18:55.500Z'), + timestamp: new Date(1730241028000), // Convert UNIX timestamp to Date action: { contract_init: { + admin_auth: { + address: "secret1wqymuexhhnsk5je5g2m08y848mfq9a0fvchwle", + code_hash: "1f86c1b8c5b923f5ace279632e6d9fc2c9c7fdd35abad5171825698c125134f3", + }, + fee_collector: "secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs", + l_token_blockchain_admin: "secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs", + l_token_code_hash: "4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07", + l_token_id: 10113, + max_constant_product_price_impact: "0.1", + max_stableswap_tvl_percent: "0.1", + oracle: { + address: "secret1nxdxgftuay7ny34epkfnn3kvvk3lcyrevuqzpe", + code_hash: "113c47c016667817b315dde03b4ee9774edf1fb293a7ea3f02d983c6b1fa1cf1", + }, + private_liquidation_interval: 10, + private_liquidation_protocol_share: "0.1", + public_liquidation_protocol_fee: "0.1", + query_auth: { + address: "secret1e0k5jza9jqctc5dt7mltnxmwpu3a3kqe0a6hf3", + code_hash: "b6ec3cc640d26b6658d52e0cfb5f79abc3afd1643ec5112cfc6a9fb51d848e69", + }, + swap_router: { + address: "secret137sjm7hgqdp4d0dldqnrxe2ktw02meaygnjd0e", + code_hash: "93dac48bf508eeb4c619fcb8b1cb260f9957e31450740a2b7325440ddf92daa8", + }, }, }, }, diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json index 68389ec..f85dd24 100644 --- a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json @@ -1,31 +1,108 @@ + { - "batch": { - "block_height": 3, - "responses": [ - { - "id": "1", - "response": { - "page": 0, - "page_size": 10, - "total_pages": 1, - "total_items": 2, + "batch": { + "responses": [ + { + "id": "mock_id", + "response": { + "data": [ { - "timestamp": "2024-10-31T18:18:55.500Z", "action": { - "contract_init": {} - } + "market_added": { + "dao_interest_fee": "0.1", + "decimals": 8, + "flash_loan_interest": "1", + "interest": { + "base": "0.02", + "optimal_utilisation": "0.7", + "slope1": "0.1", + "slope2": "0.2" + }, + "interest_per_utoken": "0", + "l_token": { + "address": "", + "code_hash": "4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07" + }, + "last_interest_accrued": 0, + "lent_amount": "0", + "lifetime_interest_owed": "0", + "lifetime_interest_paid": "0", + "loanable": "0", + "market_token": { + "address": "secret1myggj2h49xhsm8pl8yq96cjaytzvudf39mexwk", + "code_hash": "1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf" + }, + "max_supply": "100000000000000000", + "oracle_key": "BTC", + "status": { + "borrow_enabled": true, + "interest_accrual_enabled": true, + "liquidation_enabled": true, + "repay_enabled": true, + "supply_enabled": true + } + } + }, + "timestamp": 1731103428 }, { - "timestamp": "2024-10-31T18:18:55.500Z", "action": { - "contract_init": {} - } + "collateral_added": { + "liquidation_discount": "0.1", + "max_initial_ltv": "0.9", + "oracle_key": "SILK", + "private_liquidation_threshold": "0.05", + "public_liquidation_threshold": "0.07", + "token": { + "address": "secret15e5k97pfrwpkqwfxxeel0p6yn5dxztcfk9twvs", + "code_hash": "1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf" + } + } + }, + "timestamp": 1731103034 + }, + { + "action": { + "contract_init": { + "admin_auth": { + "address": "secret1wqymuexhhnsk5je5g2m08y848mfq9a0fvchwle", + "code_hash": "1f86c1b8c5b923f5ace279632e6d9fc2c9c7fdd35abad5171825698c125134f3" + }, + "fee_collector": "secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs", + "l_token_blockchain_admin": "secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs", + "l_token_code_hash": "4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07", + "l_token_id": 10113, + "max_constant_product_price_impact": "0.1", + "max_stableswap_tvl_percent": "0.1", + "oracle": { + "address": "secret1nxdxgftuay7ny34epkfnn3kvvk3lcyrevuqzpe", + "code_hash": "113c47c016667817b315dde03b4ee9774edf1fb293a7ea3f02d983c6b1fa1cf1" + }, + "private_liquidation_interval": 10, + "private_liquidation_protocol_share": "0.1", + "public_liquidation_protocol_fee": "0.1", + "query_auth": { + "address": "secret1e0k5jza9jqctc5dt7mltnxmwpu3a3kqe0a6hf3", + "code_hash": "b6ec3cc640d26b6658d52e0cfb5f79abc3afd1643ec5112cfc6a9fb51d848e69" + }, + "swap_router": { + "address": "secret137sjm7hgqdp4d0dldqnrxe2ktw02meaygnjd0e", + "code_hash": "93dac48bf508eeb4c619fcb8b1cb260f9957e31450740a2b7325440ddf92daa8" + } + } + }, + "timestamp": 1730241028 } - ] - } + ], + "page": 0, + "page_size": 3, + "total_items": 3, + "total_pages": 1 + } - ] - } + } + ], + "block_height": 100 } - \ No newline at end of file +} \ No newline at end of file From 330ce08e6959a1d8f2e11df08e05ac72fd8e6529 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Mon, 11 Nov 2024 16:18:05 -0500 Subject: [PATCH 17/26] chore: eslint --- src/contracts/services/moneyMarket.ts | 6 +- .../publiclogs/queryMoneyMarketParsed.ts | 78 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index fa4b619..0707ced 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -580,9 +580,9 @@ const parseMoneyMarketPublicLogs = (response: any) => ({ totalItems: response.total_items, data: response.data ? response.data.map((event: any) => ({ - timestamp: new Date(event.timestamp * 1000), // Convert UNIX timestamp to JS Date - action: event.action, // Pass the full action JSON object without further parsing - })) + timestamp: new Date(event.timestamp * 1000), // Convert UNIX timestamp to JS Date + action: event.action, // Pass the full action JSON object without further parsing + })) : [], }); diff --git a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts index 152b54f..6527bd9 100644 --- a/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts +++ b/src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts @@ -10,31 +10,31 @@ const queryMoneyMarketPublicLogsParsedMock: PaginatedPublicLogs = { timestamp: new Date(1731103428000), // Convert UNIX timestamp to Date action: { market_added: { - dao_interest_fee: "0.1", + dao_interest_fee: '0.1', decimals: 8, - flash_loan_interest: "1", + flash_loan_interest: '1', interest: { - base: "0.02", - optimal_utilisation: "0.7", - slope1: "0.1", - slope2: "0.2", + base: '0.02', + optimal_utilisation: '0.7', + slope1: '0.1', + slope2: '0.2', }, - interest_per_utoken: "0", + interest_per_utoken: '0', l_token: { - address: "", - code_hash: "4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07", + address: '', + code_hash: '4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07', }, last_interest_accrued: 0, - lent_amount: "0", - lifetime_interest_owed: "0", - lifetime_interest_paid: "0", - loanable: "0", + lent_amount: '0', + lifetime_interest_owed: '0', + lifetime_interest_paid: '0', + loanable: '0', market_token: { - address: "secret1myggj2h49xhsm8pl8yq96cjaytzvudf39mexwk", - code_hash: "1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf", + address: 'secret1myggj2h49xhsm8pl8yq96cjaytzvudf39mexwk', + code_hash: '1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf', }, - max_supply: "100000000000000000", - oracle_key: "BTC", + max_supply: '100000000000000000', + oracle_key: 'BTC', status: { borrow_enabled: true, interest_accrual_enabled: true, @@ -49,14 +49,14 @@ const queryMoneyMarketPublicLogsParsedMock: PaginatedPublicLogs = { timestamp: new Date(1731103034000), // Convert UNIX timestamp to Date action: { collateral_added: { - liquidation_discount: "0.1", - max_initial_ltv: "0.9", - oracle_key: "SILK", - private_liquidation_threshold: "0.05", - public_liquidation_threshold: "0.07", + liquidation_discount: '0.1', + max_initial_ltv: '0.9', + oracle_key: 'SILK', + private_liquidation_threshold: '0.05', + public_liquidation_threshold: '0.07', token: { - address: "secret15e5k97pfrwpkqwfxxeel0p6yn5dxztcfk9twvs", - code_hash: "1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf", + address: 'secret15e5k97pfrwpkqwfxxeel0p6yn5dxztcfk9twvs', + code_hash: '1691e4e24714e324a8d2345183027a918bba5c737bb2cbdbedda3cf8e7672faf', }, }, }, @@ -66,29 +66,29 @@ const queryMoneyMarketPublicLogsParsedMock: PaginatedPublicLogs = { action: { contract_init: { admin_auth: { - address: "secret1wqymuexhhnsk5je5g2m08y848mfq9a0fvchwle", - code_hash: "1f86c1b8c5b923f5ace279632e6d9fc2c9c7fdd35abad5171825698c125134f3", + address: 'secret1wqymuexhhnsk5je5g2m08y848mfq9a0fvchwle', + code_hash: '1f86c1b8c5b923f5ace279632e6d9fc2c9c7fdd35abad5171825698c125134f3', }, - fee_collector: "secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs", - l_token_blockchain_admin: "secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs", - l_token_code_hash: "4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07", + fee_collector: 'secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs', + l_token_blockchain_admin: 'secret1t6w88lh492zel8z9mdkeghnfh9qnfjnkel6xrs', + l_token_code_hash: '4d7ab2164a33cfebbb6384b4221b7ca3de9936f2ce5b0de5cacd2fd1b932cc07', l_token_id: 10113, - max_constant_product_price_impact: "0.1", - max_stableswap_tvl_percent: "0.1", + max_constant_product_price_impact: '0.1', + max_stableswap_tvl_percent: '0.1', oracle: { - address: "secret1nxdxgftuay7ny34epkfnn3kvvk3lcyrevuqzpe", - code_hash: "113c47c016667817b315dde03b4ee9774edf1fb293a7ea3f02d983c6b1fa1cf1", + address: 'secret1nxdxgftuay7ny34epkfnn3kvvk3lcyrevuqzpe', + code_hash: '113c47c016667817b315dde03b4ee9774edf1fb293a7ea3f02d983c6b1fa1cf1', }, private_liquidation_interval: 10, - private_liquidation_protocol_share: "0.1", - public_liquidation_protocol_fee: "0.1", + private_liquidation_protocol_share: '0.1', + public_liquidation_protocol_fee: '0.1', query_auth: { - address: "secret1e0k5jza9jqctc5dt7mltnxmwpu3a3kqe0a6hf3", - code_hash: "b6ec3cc640d26b6658d52e0cfb5f79abc3afd1643ec5112cfc6a9fb51d848e69", + address: 'secret1e0k5jza9jqctc5dt7mltnxmwpu3a3kqe0a6hf3', + code_hash: 'b6ec3cc640d26b6658d52e0cfb5f79abc3afd1643ec5112cfc6a9fb51d848e69', }, swap_router: { - address: "secret137sjm7hgqdp4d0dldqnrxe2ktw02meaygnjd0e", - code_hash: "93dac48bf508eeb4c619fcb8b1cb260f9957e31450740a2b7325440ddf92daa8", + address: 'secret137sjm7hgqdp4d0dldqnrxe2ktw02meaygnjd0e', + code_hash: '93dac48bf508eeb4c619fcb8b1cb260f9957e31450740a2b7325440ddf92daa8', }, }, }, From f14857998af3f205acc768ceb158465293dd9141 Mon Sep 17 00:00:00 2001 From: mohammedpatla Date: Mon, 11 Nov 2024 17:47:15 -0500 Subject: [PATCH 18/26] fix: change public events to get_public_logs --- src/contracts/services/moneyMarket.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 0707ced..66842f2 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -606,7 +606,7 @@ function queryMoneyMarketPublicLogs$({ return getActiveQueryClient$(lcdEndpoint, chainId).pipe( switchMap(({ client }) => sendSecretClientContractQuery$({ queryMsg: { - public_events: { pagination }, + get_public_logs: { pagination }, }, client, contractAddress, From 531500b34fe3974b38b16f1822a3a76dba01c0e4 Mon Sep 17 00:00:00 2001 From: DrPresident Date: Tue, 12 Nov 2024 16:00:28 -0600 Subject: [PATCH 19/26] feat: money market reward pools batch query --- src/contracts/services/moneyMarket.ts | 104 ++++++++++++++++++++++- src/types/contracts/moneyMarket/model.ts | 21 +++++ 2 files changed, 122 insertions(+), 3 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 0707ced..cf2e0de 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -13,6 +13,7 @@ import { BatchMoneyMarketGetMarkets, ContractAndPagination, Pagination, ParsedConfigResponse, ParsedGetCollateralResponse, ParsedGetMarketsResponse, + RewardPool, PaginatedRewardPools, } from '~/types/contracts/moneyMarket/model'; import { Contract } from '~/types/contracts/shared/index'; import { @@ -598,7 +599,7 @@ function queryMoneyMarketPublicLogs$({ pagination, }: { contractAddress: string, - codeHash: string, + codeHash?: string, lcdEndpoint?: string, chainId?: string, pagination?: Pagination, @@ -606,7 +607,7 @@ function queryMoneyMarketPublicLogs$({ return getActiveQueryClient$(lcdEndpoint, chainId).pipe( switchMap(({ client }) => sendSecretClientContractQuery$({ queryMsg: { - public_events: { pagination }, + public_logs: { pagination }, }, client, contractAddress, @@ -630,7 +631,7 @@ async function queryMoneyMarketPublicLogs({ page, }: { contractAddress: string, - codeHash: string, + codeHash?: string, lcdEndpoint?: string, chainId?: string, pageSize?: number, @@ -728,6 +729,101 @@ async function batchQueryMoneyMarketPublicLogs({ })); } +const parseBatchQueryMoneyMarketRewardPools = (response: any): PaginatedRewardPools => ({ + page: response.page, + pageSize: response.page_size, + totalPages: response.total_pages, + totalItems: response.total_items, + debtMarket: response.id, + blockHeight: response.blockHeight, + data: response.data ? response.data.map((rewardPool: RewardPool) => ({ + id: rewardPool.id, + amount: rewardPool.amount, + token: rewardPool.token, + start: rewardPool.start, + end: rewardPool.end, + rate: rewardPool.rate, + })) + : [], +}); + +function batchQueryMoneyMarketRewardPools$({ + queryRouterContractAddress, + queryRouterCodeHash, + lcdEndpoint, + chainId, + moneyMarket, + debtMarkets, + batchSize, + minBlockHeightValidationOptions, + blockHeight, +}: { + queryRouterContractAddress: string, + queryRouterCodeHash?: string, + lcdEndpoint?: string, + chainId?: string, + moneyMarket: Contract, + debtMarkets: string[], + batchSize?: number, + minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, + blockHeight?: number, +}) { + const queries = debtMarkets.map((debtMarket) => ({ + id: debtMarket, + contract: { + address: moneyMarket.address, + codeHash: moneyMarket.codeHash, + }, + queryMsg: { + reward_pools: { + market: debtMarket, + }, + }, + })); + + return batchQuery$({ + contractAddress: queryRouterContractAddress, + codeHash: queryRouterCodeHash, + lcdEndpoint, + chainId, + queries, + batchSize, + minBlockHeightValidationOptions, + blockHeight, + }).pipe( + map((response) => parseBatchQueryMoneyMarketRewardPools(response)), + first(), + ); +} + +async function batchQueryMoneyMarketRewardPools({ + queryRouterContractAddress, + queryRouterCodeHash, + lcdEndpoint, + chainId, + moneyMarket, + debtMarkets, + minBlockHeightValidationOptions, +}: { + queryRouterContractAddress: string, + queryRouterCodeHash?: string, + lcdEndpoint?: string, + chainId?: string, + moneyMarket: Contract, + debtMarkets: string[], + minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, +}) { + return lastValueFrom(batchQueryMoneyMarketRewardPools$({ + queryRouterContractAddress, + queryRouterCodeHash, + lcdEndpoint, + chainId, + moneyMarket, + debtMarkets, + minBlockHeightValidationOptions, + })); +} + export { queryMoneyMarketConfig, queryMoneyMarketGetMarkets, @@ -742,4 +838,6 @@ export { queryMoneyMarketPublicLogs, batchQueryMoneyMarketPublicLogs$, batchQueryMoneyMarketPublicLogs, + batchQueryMoneyMarketRewardPools$, + batchQueryMoneyMarketRewardPools, }; diff --git a/src/types/contracts/moneyMarket/model.ts b/src/types/contracts/moneyMarket/model.ts index 56555b9..1d166de 100644 --- a/src/types/contracts/moneyMarket/model.ts +++ b/src/types/contracts/moneyMarket/model.ts @@ -164,6 +164,25 @@ type PaginatedPublicLogs = { data: PublicLog[], } +type RewardPool = { + id: string, + amount: string, + token: string, + start: string, + end: string, + rate: string, +} + +type PaginatedRewardPools = { + page: number, + pageSize: number, + totalPages: number, + totalItems: number, + blockHeight: number, + debtMarket: string, + data: RewardPool[], +} + export type { Pagination, ContractAndPagination, @@ -179,4 +198,6 @@ export type { BatchMoneyMarketGetCollaterals, PublicLog, PaginatedPublicLogs, + RewardPool, + PaginatedRewardPools, }; From 3cdb253098791671a752e3a92428bed91de6ff3a Mon Sep 17 00:00:00 2001 From: DrPresident Date: Tue, 12 Nov 2024 16:01:59 -0600 Subject: [PATCH 20/26] feat: format --- src/contracts/services/moneyMarket.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index cf2e0de..b3cc4ad 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -737,13 +737,13 @@ const parseBatchQueryMoneyMarketRewardPools = (response: any): PaginatedRewardPo debtMarket: response.id, blockHeight: response.blockHeight, data: response.data ? response.data.map((rewardPool: RewardPool) => ({ - id: rewardPool.id, - amount: rewardPool.amount, - token: rewardPool.token, - start: rewardPool.start, - end: rewardPool.end, - rate: rewardPool.rate, - })) + id: rewardPool.id, + amount: rewardPool.amount, + token: rewardPool.token, + start: rewardPool.start, + end: rewardPool.end, + rate: rewardPool.rate, + })) : [], }); From 45d2e27f12495422b4dfdf116dc2980ff9946782 Mon Sep 17 00:00:00 2001 From: DrPresident Date: Tue, 19 Nov 2024 16:16:56 -0600 Subject: [PATCH 21/26] feat: functions working, should add types --- src/contracts/services/moneyMarket.ts | 41 +++++++++++---------- src/types/contracts/moneyMarket/model.ts | 3 +- src/types/contracts/moneyMarket/response.ts | 3 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index b3cc4ad..4f61f51 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -13,7 +13,6 @@ import { BatchMoneyMarketGetMarkets, ContractAndPagination, Pagination, ParsedConfigResponse, ParsedGetCollateralResponse, ParsedGetMarketsResponse, - RewardPool, PaginatedRewardPools, } from '~/types/contracts/moneyMarket/model'; import { Contract } from '~/types/contracts/shared/index'; import { @@ -124,7 +123,8 @@ const parseMoneyMarketGetCollateral = ( collateralAmount: cur.amount, decimals: cur.decimals, maxInitialLtv: cur.max_initial_ltv, - liquidationThreshold: cur.liquidation_threshold, + publicLiquidationThreshold: cur.public_liquidation_threshold, + privateLiquidationThreshold: cur.private_liquidation_threshold, liquidationDiscount: cur.liquidation_discount, oracleKey: cur.oracle_key, depositEnabled: cur.status.deposit_enabled, @@ -729,23 +729,20 @@ async function batchQueryMoneyMarketPublicLogs({ })); } -const parseBatchQueryMoneyMarketRewardPools = (response: any): PaginatedRewardPools => ({ - page: response.page, - pageSize: response.page_size, - totalPages: response.total_pages, - totalItems: response.total_items, - debtMarket: response.id, - blockHeight: response.blockHeight, - data: response.data ? response.data.map((rewardPool: RewardPool) => ({ - id: rewardPool.id, - amount: rewardPool.amount, - token: rewardPool.token, - start: rewardPool.start, - end: rewardPool.end, - rate: rewardPool.rate, +const parseBatchQueryMoneyMarketRewardPools = (responses: any) => ( + responses.map((response: any) => ({ + debtMarket: response.id, + blockHeight: response.blockHeight, + rewardPools: response.response.map((pool: any) => ({ + rewardPoolId: pool.id, + amount: pool.amount, + token: pool.token, + start: pool.start, + end: pool.end, + rate: pool.rate, + })), })) - : [], -}); +); function batchQueryMoneyMarketRewardPools$({ queryRouterContractAddress, @@ -780,6 +777,7 @@ function batchQueryMoneyMarketRewardPools$({ }, }, })); + console.error('shadejs reward pools batch queries', queries); return batchQuery$({ contractAddress: queryRouterContractAddress, @@ -791,7 +789,12 @@ function batchQueryMoneyMarketRewardPools$({ minBlockHeightValidationOptions, blockHeight, }).pipe( - map((response) => parseBatchQueryMoneyMarketRewardPools(response)), + map((response) => { + console.error('Parsing', JSON.stringify(response)); + const x = parseBatchQueryMoneyMarketRewardPools(response); + console.error('Parsed', JSON.stringify(x)); + return x; + }), first(), ); } diff --git a/src/types/contracts/moneyMarket/model.ts b/src/types/contracts/moneyMarket/model.ts index 1d166de..1039651 100644 --- a/src/types/contracts/moneyMarket/model.ts +++ b/src/types/contracts/moneyMarket/model.ts @@ -102,7 +102,8 @@ type ParsedCollateralReponse = { collateralAmount: string, decimals: number, maxInitialLtv: string, - liquidationThreshold: string, + publicLiquidationThreshold: string, + privateLiquidationThreshold: string, liquidationDiscount: string, oracleKey: string, depositEnabled: boolean, diff --git a/src/types/contracts/moneyMarket/response.ts b/src/types/contracts/moneyMarket/response.ts index 3a77f18..03cd742 100644 --- a/src/types/contracts/moneyMarket/response.ts +++ b/src/types/contracts/moneyMarket/response.ts @@ -78,7 +78,8 @@ type CollateralReponse = { amount: string, decimals: number, max_initial_ltv: string, - liquidation_threshold: string, + public_liquidation_threshold: string, + private_liquidation_threshold: string, liquidation_discount: string, oracle_key: string, status: { From 57e129caa97ed5a1b743e2b5dde943fd8672fa2a Mon Sep 17 00:00:00 2001 From: DrPresident Date: Thu, 21 Nov 2024 11:29:14 -0600 Subject: [PATCH 22/26] feat: removing console.logs --- src/contracts/services/moneyMarket.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 4f61f51..99efd8b 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -777,7 +777,6 @@ function batchQueryMoneyMarketRewardPools$({ }, }, })); - console.error('shadejs reward pools batch queries', queries); return batchQuery$({ contractAddress: queryRouterContractAddress, @@ -789,12 +788,7 @@ function batchQueryMoneyMarketRewardPools$({ minBlockHeightValidationOptions, blockHeight, }).pipe( - map((response) => { - console.error('Parsing', JSON.stringify(response)); - const x = parseBatchQueryMoneyMarketRewardPools(response); - console.error('Parsed', JSON.stringify(x)); - return x; - }), + map((response) => parseBatchQueryMoneyMarketRewardPools(response)), first(), ); } From f259a3e6be39bca3c4f871b29e82f05dd1f5ac72 Mon Sep 17 00:00:00 2001 From: DrPresident Date: Thu, 21 Nov 2024 11:33:39 -0600 Subject: [PATCH 23/26] feat: types --- src/contracts/services/moneyMarket.ts | 3 ++- src/types/contracts/moneyMarket/model.ts | 16 ++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 99efd8b..6c4009f 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -13,6 +13,7 @@ import { BatchMoneyMarketGetMarkets, ContractAndPagination, Pagination, ParsedConfigResponse, ParsedGetCollateralResponse, ParsedGetMarketsResponse, + ParsedRewardPoolsResponse, } from '~/types/contracts/moneyMarket/model'; import { Contract } from '~/types/contracts/shared/index'; import { @@ -729,7 +730,7 @@ async function batchQueryMoneyMarketPublicLogs({ })); } -const parseBatchQueryMoneyMarketRewardPools = (responses: any) => ( +const parseBatchQueryMoneyMarketRewardPools = (responses: any): ParsedRewardPoolsResponse[] => ( responses.map((response: any) => ({ debtMarket: response.id, blockHeight: response.blockHeight, diff --git a/src/types/contracts/moneyMarket/model.ts b/src/types/contracts/moneyMarket/model.ts index 1039651..9960051 100644 --- a/src/types/contracts/moneyMarket/model.ts +++ b/src/types/contracts/moneyMarket/model.ts @@ -166,7 +166,7 @@ type PaginatedPublicLogs = { } type RewardPool = { - id: string, + rewardPoolId: string, amount: string, token: string, start: string, @@ -174,14 +174,10 @@ type RewardPool = { rate: string, } -type PaginatedRewardPools = { - page: number, - pageSize: number, - totalPages: number, - totalItems: number, - blockHeight: number, - debtMarket: string, - data: RewardPool[], +type ParsedRewardPoolsResponse = { + debtMarket: string, + blockHeight: string, + rewardPools: RewardPool[], } export type { @@ -200,5 +196,5 @@ export type { PublicLog, PaginatedPublicLogs, RewardPool, - PaginatedRewardPools, + ParsedRewardPoolsResponse, }; From 4762e5d13fbcc9ad9625bb5b507b4a94cc8100f2 Mon Sep 17 00:00:00 2001 From: DrPresident Date: Thu, 21 Nov 2024 11:48:18 -0600 Subject: [PATCH 24/26] feat: added type --- src/contracts/services/moneyMarket.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 6c4009f..f9b4ccb 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -5,6 +5,11 @@ import { map, lastValueFrom, } from 'rxjs'; + +import { + BatchQueryParsedResponse, + BatchQueryParams, +} from '~/types/contracts/batchQuery/model'; import { sendSecretClientContractQuery$ } from '~/client/services/clientServices'; import { ConfigResponse, GetCollateralResponse, GetMarketsResponse } from '~/types/contracts/moneyMarket/response'; import { @@ -16,9 +21,6 @@ import { ParsedRewardPoolsResponse, } from '~/types/contracts/moneyMarket/model'; import { Contract } from '~/types/contracts/shared/index'; -import { - BatchQueryParams, BatchQueryParsedResponse, -} from '~/types/contracts/batchQuery/model'; import { MinBlockHeightValidationOptions } from '~/types'; import { batchQuery$ } from './batchQuery'; import { msgQueryMoneyMarketCollaterals, msgQueryMoneyMarketConfig, msgQueryMoneyMarketMarkets } from '../definitions/moneyMarket'; @@ -730,7 +732,9 @@ async function batchQueryMoneyMarketPublicLogs({ })); } -const parseBatchQueryMoneyMarketRewardPools = (responses: any): ParsedRewardPoolsResponse[] => ( +const parseBatchQueryMoneyMarketRewardPools = ( + responses: BatchQueryParsedResponse, +): ParsedRewardPoolsResponse[] => ( responses.map((response: any) => ({ debtMarket: response.id, blockHeight: response.blockHeight, From 65a9948f570dccb78373174df36631dfbabe4266 Mon Sep 17 00:00:00 2001 From: DrPresident Date: Thu, 21 Nov 2024 11:50:09 -0600 Subject: [PATCH 25/26] feat: changeset --- .changeset/brown-laws-switch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brown-laws-switch.md diff --git a/.changeset/brown-laws-switch.md b/.changeset/brown-laws-switch.md new file mode 100644 index 0000000..174a903 --- /dev/null +++ b/.changeset/brown-laws-switch.md @@ -0,0 +1,5 @@ +--- +"@shadeprotocol/shadejs": patch +--- + +Money Market Reward Pools From 6c90022444f35c0f88c247ca293ce085c54dcb88 Mon Sep 17 00:00:00 2001 From: DrPresident Date: Thu, 21 Nov 2024 11:54:18 -0600 Subject: [PATCH 26/26] feat: more types --- src/contracts/services/moneyMarket.ts | 8 +++++--- src/types/contracts/moneyMarket/model.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/contracts/services/moneyMarket.ts b/src/contracts/services/moneyMarket.ts index 37fd929..3bd4fe4 100644 --- a/src/contracts/services/moneyMarket.ts +++ b/src/contracts/services/moneyMarket.ts @@ -9,6 +9,7 @@ import { import { BatchQueryParsedResponse, BatchQueryParams, + BatchQueryParsedResponseItem, } from '~/types/contracts/batchQuery/model'; import { sendSecretClientContractQuery$ } from '~/client/services/clientServices'; import { ConfigResponse, GetCollateralResponse, GetMarketsResponse } from '~/types/contracts/moneyMarket/response'; @@ -19,6 +20,7 @@ import { ContractAndPagination, Pagination, ParsedConfigResponse, ParsedGetCollateralResponse, ParsedGetMarketsResponse, ParsedRewardPoolsResponse, + RewardPoolResponse, } from '~/types/contracts/moneyMarket/model'; import { Contract } from '~/types/contracts/shared/index'; import { MinBlockHeightValidationOptions } from '~/types'; @@ -735,10 +737,10 @@ async function batchQueryMoneyMarketPublicLogs({ const parseBatchQueryMoneyMarketRewardPools = ( responses: BatchQueryParsedResponse, ): ParsedRewardPoolsResponse[] => ( - responses.map((response: any) => ({ - debtMarket: response.id, + responses.map((response: BatchQueryParsedResponseItem) => ({ + debtMarket: response.id.toString(), blockHeight: response.blockHeight, - rewardPools: response.response.map((pool: any) => ({ + rewardPools: response.response.map((pool: RewardPoolResponse) => ({ rewardPoolId: pool.id, amount: pool.amount, token: pool.token, diff --git a/src/types/contracts/moneyMarket/model.ts b/src/types/contracts/moneyMarket/model.ts index 9960051..8e4c068 100644 --- a/src/types/contracts/moneyMarket/model.ts +++ b/src/types/contracts/moneyMarket/model.ts @@ -174,9 +174,18 @@ type RewardPool = { rate: string, } +type RewardPoolResponse = { + id: string, + amount: string, + token: string, + start: string, + end: string, + rate: string, +} + type ParsedRewardPoolsResponse = { debtMarket: string, - blockHeight: string, + blockHeight: number, rewardPools: RewardPool[], } @@ -196,5 +205,6 @@ export type { PublicLog, PaginatedPublicLogs, RewardPool, + RewardPoolResponse, ParsedRewardPoolsResponse, };