Skip to content

Commit

Permalink
fix: change query to reflect data onchain
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedpatla committed Nov 11, 2024
1 parent 5977ce3 commit be9476b
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 44 deletions.
40 changes: 23 additions & 17 deletions src/contracts/services/moneyMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))
: [],
});

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -646,17 +652,17 @@ async function queryMoneyMarketPublicLogs({
* NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY
*/
function batchQueryMoneyMarketPublicLogs$({
queryRouterContractAddress,
queryRouterCodeHash,
queryPublicLogsContractAddress,
queryPublicLogsCodeHash,
lcdEndpoint,
chainId,
moneyMarketContracts,
batchSize,
minBlockHeightValidationOptions,
blockHeight,
}: {
queryRouterContractAddress: string,
queryRouterCodeHash?: string,
queryPublicLogsContractAddress: string,
queryPublicLogsCodeHash?: string,
lcdEndpoint?: string,
chainId?: string,
moneyMarketContracts: ContractAndPagination[],
Expand All @@ -671,16 +677,16 @@ function batchQueryMoneyMarketPublicLogs$({
codeHash: contract.codeHash,
},
queryMsg: {
public_events: {
get_public_logs: {
pagination: contract.pageSize && contract.page
? { page_size: contract.pageSize, page: contract.page } : undefined,
},
},
}));

return batchQuery$({
contractAddress: queryRouterContractAddress,
codeHash: queryRouterCodeHash,
contractAddress: queryPublicLogsContractAddress,
codeHash: queryPublicLogsCodeHash,
lcdEndpoint,
chainId,
queries,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/services/moneymarket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
83 changes: 78 additions & 5 deletions src/test/mocks/moneymarket/publiclogs/queryMoneyMarketParsed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
Expand Down
119 changes: 98 additions & 21 deletions src/test/mocks/moneymarket/publiclogs/queryMoneyMarketResponse.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit be9476b

Please sign in to comment.