Skip to content

Commit

Permalink
Merge pull request #337 from metaDAOproject/feat/sync-staging
Browse files Browse the repository at this point in the history
feat: sync up the hasura-meta-data
  • Loading branch information
R-K-H authored Dec 15, 2024
2 parents 9b7365c + 420e4bb commit 5cd562b
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 74 deletions.
1 change: 1 addition & 0 deletions packages/hasura/metadata/databases/databases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,4 @@
returns: website_stats
root_field_name: website_stats
tables: "!include futarchy/tables/tables.yaml"
functions: "!include futarchy/functions/functions.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- "!include public_reid_play.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function:
name: reid_play
schema: public
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ array_relationships:
remote_table:
name: prices_5m
schema: public
- name: proposals
using:
foreign_key_constraint_on:
column: fail_market_acct
table:
name: proposals
schema: public
- name: proposalsByPassMarketAcct
using:
foreign_key_constraint_on:
column: pass_market_acct
table:
name: proposals
schema: public
- name: takes
using:
foreign_key_constraint_on:
Expand All @@ -128,22 +142,24 @@ select_permissions:
permission:
columns:
- active_slot
- base_lot_size
- inactive_slot
- quote_lot_size
- quote_tick_size
- asks_token_acct
- base_amount
- base_lot_size
- base_maker_fee
- base_mint_acct
- base_taker_fee
- bids_token_acct
- create_tx_sig
- created_at
- inactive_slot
- market_acct
- market_type
- proposal_acct
- quote_mint_acct
- base_maker_fee
- base_taker_fee
- quote_amount
- quote_lot_size
- quote_maker_fee
- quote_mint_acct
- quote_taker_fee
- created_at
- quote_tick_size
filter: {}
comment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table:
name: proposal_bars_4h
schema: public
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ object_relationships:
- name: dao
using:
foreign_key_constraint_on: dao_acct
- name: fail_market
- name: details
using:
manual_configuration:
column_mapping:
fail_market_acct: market_acct
proposal_acct: proposal_acct
insertion_order: null
remote_table:
name: markets
name: proposal_details
schema: public
- name: fail_market
using:
foreign_key_constraint_on: fail_market_acct
- name: pass_market
using:
manual_configuration:
column_mapping:
pass_market_acct: market_acct
insertion_order: null
remote_table:
name: markets
schema: public
foreign_key_constraint_on: pass_market_acct
array_relationships:
- name: comments
using:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table:
name: reid_data
schema: public
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ array_relationships:
table:
name: v0_4_metric_decisions
schema: public
- name: market
using:
manual_configuration:
column_mapping:
amm_addr: market_acct
insertion_order: null
remote_table:
name: markets
schema: public
select_permissions:
- role: anonymous
permission:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
- "!include public_program_system.yaml"
- "!include public_programs.yaml"
- "!include public_proposal_bars.yaml"
- "!include public_proposal_bars_4h.yaml"
- "!include public_proposal_details.yaml"
- "!include public_proposal_total_trade_volume.yaml"
- "!include public_proposals.yaml"
- "!include public_reactions.yaml"
- "!include public_reid_data.yaml"
- "!include public_sessions.yaml"
- "!include public_signature_accounts.yaml"
- "!include public_signatures.yaml"
Expand Down
34 changes: 0 additions & 34 deletions packages/hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,3 @@
updated_at
}
}
- name: MyQuery
query: |
query MyQuery {
proposals(where: {proposal_acct:{_eq:"hEoj5ca54sU14MD3QqmKp734h7EgiuoPqyeWkBTUDr1"}}) {
pass_market {
market_acct
prices(limit: 1, order_by: {updated_slot:desc}) {
price
quote_amount
base_amount
}
}
fail_market {
market_acct
prices(limit: 1, order_by: {updated_slot:desc}) {
price
quote_amount
base_amount
}
}
}
}
- name: MyQuery2
query: |
query MyQuery {
proposal_bars(where: {proposal_acct:{_eq:"hEoj5ca54sU14MD3QqmKp734h7EgiuoPqyeWkBTUDr1"}}, order_by: [{bar_start_time:desc}], limit: 1) {
pass_price
fail_price
pass_base_amount
pass_quote_amount
fail_base_amount
fail_quote_amount
}
}
18 changes: 0 additions & 18 deletions packages/hasura/metadata/rest_endpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@
- GET
name: fetchLatestFourProposals
url: fetchlatestfourproposals
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: MyQuery
methods:
- GET
name: MyQuery
url: myquery
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: MyQuery2
methods:
- GET
name: MyQuery2
url: myquery2
- comment: ""
definition:
query:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
twapMaxObservationChangePerUpdate:
dbDao.twapMaxObservationChangePerUpdate ?? null,
};
// NOTE: We insert the markets first so that we can update the proposal with the market accounts
await insertAssociatedAccountsDataForProposal(proposal, currentTime);

await usingDb((db) =>
db
Expand All @@ -217,7 +219,10 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
.onConflictDoNothing()
.execute()
);
await insertAssociatedAccountsDataForProposal(proposal, currentTime);

// NOTE: We update the markets with the proposal after the proposal is inserted
await updateMarketsWithProposal(proposal);

});

logger.log("inserted proposals");
Expand Down Expand Up @@ -391,7 +396,6 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
await calculateUserPerformance(onChainProposal);
}

// check if markets are there, if they aren't insert them
// Check if markets are there, if they aren't, insert them
const passAmm = onChainProposal.account.passAmm;
const failAmm = onChainProposal.account.failAmm;
Expand Down Expand Up @@ -445,6 +449,27 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {

};

async function updateMarketsWithProposal(
proposal: ProposalAccountWithKey,
) {
if(!proposal.account.passAmm || !proposal.account.failAmm) return Err({ type: AutocratDaoIndexerError.MissingParamError });

await usingDb((db) =>
db
.update(schema.markets)
.set({
proposalAcct: proposal.publicKey.toString(),
})
.where(
or(
eq(schema.markets.marketAcct, passMarket.marketAcct),
eq(schema.markets.marketAcct, failMarket.marketAcct)
)
)
.execute()
);
}


async function insertAssociatedAccountsDataForProposal(
proposal: ProposalAccountWithKey,
Expand Down Expand Up @@ -633,7 +658,6 @@ async function insertAssociatedAccountsDataForProposal(

let passMarket: MarketRecord = {
marketAcct: proposal.account.passAmm.toString(),
proposalAcct: proposal.publicKey.toString(),
marketType: MarketType.FUTARCHY_AMM,
createTxSig: "",
baseMintAcct: storedBaseVault.conditionalOnFinalizeTokenMint.toString(),
Expand All @@ -659,7 +683,6 @@ async function insertAssociatedAccountsDataForProposal(

let failMarket: MarketRecord = {
marketAcct: proposal.account.failAmm.toString(),
proposalAcct: proposal.publicKey.toString(),
marketType: MarketType.FUTARCHY_AMM,
createTxSig: "",
baseMintAcct: storedBaseVault.conditionalOnRevertTokenMint.toString(),
Expand Down

0 comments on commit 5cd562b

Please sign in to comment.