Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get_public_logs #173

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fb39e25
feat: get_public_logs
mohammedpatla Oct 22, 2024
bc9388b
feat: build the moneymarketpublic events service
mohammedpatla Oct 23, 2024
d2f97a3
feat: mock typed and test to check outputs and parsed values match
mohammedpatla Oct 25, 2024
99e4dd4
chore: eslint fixes
mohammedpatla Oct 25, 2024
3c3251b
chore: docs
mohammedpatla Oct 31, 2024
5283621
fix: changeset
mohammedpatla Oct 31, 2024
ae9d4b4
fix: address comments
mohammedpatla Oct 31, 2024
8a5254a
chore: eslint
mohammedpatla Oct 31, 2024
bceb82a
fix: change to logs and fix test
mohammedpatla Oct 31, 2024
218c67d
fix: correct changeset
mohammedpatla Oct 31, 2024
d988eb0
feat: bump secretjs version
DrPresident Oct 31, 2024
98f687b
fix: patch secretnetwork upgrade
mohammedpatla Nov 1, 2024
0500c93
feat: create a batch query
mohammedpatla Nov 4, 2024
437872f
chore: eslint
mohammedpatla Nov 4, 2024
5977ce3
fix: change event to logs
mohammedpatla Nov 4, 2024
be9476b
fix: change query to reflect data onchain
mohammedpatla Nov 11, 2024
330ce08
chore: eslint
mohammedpatla Nov 11, 2024
f148579
fix: change public events to get_public_logs
mohammedpatla Nov 11, 2024
531500b
feat: money market reward pools batch query
DrPresident Nov 12, 2024
3cdb253
feat: format
DrPresident Nov 12, 2024
45d2e27
feat: functions working, should add types
DrPresident Nov 19, 2024
57e129c
feat: removing console.logs
DrPresident Nov 21, 2024
f259a3e
feat: types
DrPresident Nov 21, 2024
4762e5d
feat: added type
DrPresident Nov 21, 2024
a9b17c1
Merge branch 'moneymarket' into money-market-reward-pools
DrPresident Nov 21, 2024
65a9948
feat: changeset
DrPresident Nov 21, 2024
c69792f
Merge pull request #175 from securesecrets/money-market-reward-pools
AustinWoetzel Nov 21, 2024
57320fd
feat: fixed block height type
DrPresident Nov 21, 2024
951351c
Borrower rewards (#177)
DrPresident Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
mohammedpatla marked this conversation as resolved.
Show resolved Hide resolved
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not correct, the batch query requires the query router.

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
}
}