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

Staging #255

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ array_relationships:
name: proposals
schema: public
insert_permissions:
- role: anonymous
permission:
check: {}
columns:
- cond_finalize_token_mint_acct
- cond_revert_token_mint_acct
- cond_vault_acct
- nonce
- settlement_authority
- status
- underlying_mint_acct
- underlying_token_acct
- role: user
permission:
check: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,34 @@ select_permissions:
- content
filter: {}
comment: ""
- role: user
permission:
columns:
- proposal_id
- base_cond_vault_acct
- description
- fail_market_acct
- pass_market_acct
- proposal_acct
- proposer_acct
- quote_cond_vault_acct
- slug
- title
- categories
- content
filter: {}
comment: ""
- role: proposer
permission:
columns:
- proposal_id
- base_cond_vault_acct
- description
- fail_market_acct
- pass_market_acct
- proposal_acct
- proposer_acct
- quote_cond_vault_acct
- slug
- title
- categories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ insert_permissions:
- updated_at
- initial_slot
- end_slot
- description_url
- pass_threshold_bps
- duration_in_slots
- min_base_futarchic_liquidity
- min_quote_futarchic_liquidity
- twap_initial_observation
- twap_max_observation_change_per_update
comment: ""
select_permissions:
- role: anonymous
Expand Down Expand Up @@ -124,6 +131,12 @@ select_permissions:
- quote_vault
- status
- autocrat_version
- duration_in_slots
- pass_threshold_bps
- twap_initial_observation
- twap_max_observation_change_per_update
- min_quote_futarchic_liquidity
- min_base_futarchic_liquidity
- completed_at
- created_at
- ended_at
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 10 additions & 1 deletion packages/indexer/src/builders/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,16 @@ export class SwapBuilder {
} catch (e: any) {
logger.errorWithChatBotAlert(
"swap peristable general error",
e.message ? e.message : e
e.message
? {
message: e.message,
stack: e.stack,
name: e.name,
cause: e.cause,
fileName: e.fileName,
lineNumber: e.lineNumber,
}
: e
);
return Err({ type: SwapPersistableError.GeneralError });
}
Expand Down
66 changes: 42 additions & 24 deletions packages/indexer/src/indexers/autocrat/autocrat-proposal-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
.add(new BN(dbDao.slotsPerProposal?.toString()))
.toString()
),
durationInSlots: dbDao.slotsPerProposal,
minBaseFutarchicLiquidity: dbDao.minBaseFutarchicLiquidity,
minQuoteFutarchicLiquidity: dbDao.minQuoteFutarchicLiquidity,
passThresholdBps: dbDao.passThresholdBps,
Expand Down Expand Up @@ -213,20 +214,21 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
)
)[0];

const endSlot: BN = onChainProposal.account.slotEnqueued
.add(new BN(dbDao.slotsPerProposal?.valueOf()))
const endSlot: BN = onChainProposal.account.slotEnqueued.add(
new BN(dbDao.slotsPerProposal?.valueOf())
);

const slotDifference = onChainProposal.account.slotEnqueued
.add(new BN(dbDao.slotsPerProposal?.valueOf()))
.sub(new BN(currentSlot));

const lowHoursEstimate = Math.floor(
(slotDifference.toNumber() * 400) / 1000 / 60 / 60
);

// Our check to ensure we're actually updating the time correctly.
if(currentSlot <= endSlot.toNumber() && lowHoursEstimate <= 0){
console.error('Issue with slot update contact administrator')
if (currentSlot <= endSlot.toNumber() && lowHoursEstimate <= 0) {
console.error("Issue with slot update contact administrator");
}

const endedAt = new Date(currentTime.toUTCString());
Expand Down Expand Up @@ -662,14 +664,14 @@ async function calculateUserPerformance(

const { proposals, daos, quote_tokens, base_tokens } = proposal;

let proposalDaoAcct = daos?.daoAcct
let proposalDaoAcct = daos?.daoAcct;

if (!proposalDaoAcct) {
proposalDaoAcct = proposals.daoAcct
proposalDaoAcct = proposals.daoAcct;
}

if (!proposalDaoAcct) {
console.error('No daoAcct found')
console.error("No daoAcct found");
}

const allOrders = await usingDb((db) => {
Expand All @@ -692,7 +694,10 @@ async function calculateUserPerformance(
proposalFinalizedAt.getMinutes() - 2
);

const resolvingMarket = proposals.status === ProposalStatus.Passed ? proposals.passMarketAcct : proposals.failMarketAcct;
const resolvingMarket =
proposals.status === ProposalStatus.Passed
? proposals.passMarketAcct
: proposals.failMarketAcct;
// TODO: Get spot price at proposal finalization or even current spot price
// if the proposal is still active (this would be UNREALISED P&L)
// TODO: If this is 0 we really need to throw and error and alert someone, we shouldn't have missing spot data
Expand Down Expand Up @@ -754,19 +759,23 @@ async function calculateUserPerformance(
totals.volumeBought = totals.volumeBought + amount;
totals.buyOrderCount = totals.buyOrderCount + 1;
// If this is the resolving market then we want to keep a running tally for that for P&L
if(next.marketAcct === resolvingMarket){
totals.tokensBoughtResolvingMarket = totals.tokensBoughtResolvingMarket + size;
totals.volumeBoughtResolvingMarket = totals.volumeBoughtResolvingMarket + amount;
if (next.marketAcct === resolvingMarket) {
totals.tokensBoughtResolvingMarket =
totals.tokensBoughtResolvingMarket + size;
totals.volumeBoughtResolvingMarket =
totals.volumeBoughtResolvingMarket + amount;
}
// Sell Side
// Sell Side
} else if (next.side === "ASK") {
totals.tokensSold = totals.tokensSold + size;
totals.volumeSold = totals.volumeSold + amount;
totals.sellOrderCount = totals.sellOrderCount + 1;
// If this is the resolving market then we want to keep a running tally for that for P&L
if(next.marketAcct === resolvingMarket){
totals.tokensSoldResolvingMarket = totals.tokensSoldResolvingMarket + size;
totals.volumeSoldResolvingMarket = totals.volumeSoldResolvingMarket + amount;
if (next.marketAcct === resolvingMarket) {
totals.tokensSoldResolvingMarket =
totals.tokensSoldResolvingMarket + size;
totals.volumeSoldResolvingMarket =
totals.volumeSoldResolvingMarket + amount;
}
}

Expand All @@ -781,10 +790,13 @@ async function calculateUserPerformance(
const [actor, values] = k;

// NOTE: this gets us the delta, whereas we need to know the direction at the very end
const tradeSizeDelta = Math.abs(values.tokensBoughtResolvingMarket - values.tokensSoldResolvingMarket);
const tradeSizeDelta = Math.abs(
values.tokensBoughtResolvingMarket - values.tokensSoldResolvingMarket
);

// NOTE: Directionally orients our last leg
const needsSellToExit = values.tokensBoughtResolvingMarket > values.tokensSoldResolvingMarket; // boolean
const needsSellToExit =
values.tokensBoughtResolvingMarket > values.tokensSoldResolvingMarket; // boolean

// We need to complete the round trip / final leg
if (tradeSizeDelta !== 0) {
Expand All @@ -796,9 +808,11 @@ async function calculateUserPerformance(
// We've bought more than we've sold, therefore when we exit the position calulcation
// we need to count the remaining volume as a sell at spot price when conditional
// market is finalized.
values.volumeSoldResolvingMarket = values.volumeSoldResolvingMarket + lastLegNotional;
values.volumeSoldResolvingMarket =
values.volumeSoldResolvingMarket + lastLegNotional;
} else {
values.volumeBoughtResolvingMarket = values.volumeBoughtResolvingMarket + lastLegNotional;
values.volumeBoughtResolvingMarket =
values.volumeBoughtResolvingMarket + lastLegNotional;
}
}

Expand All @@ -810,9 +824,11 @@ async function calculateUserPerformance(
tokensSold: values.tokensSold.toString(),
volumeBought: values.volumeBought.toString(),
volumeSold: values.volumeSold.toString(),
tokensBoughtResolvingMarket: values.tokensBoughtResolvingMarket.toString(),
tokensBoughtResolvingMarket:
values.tokensBoughtResolvingMarket.toString(),
tokensSoldResolvingMarket: values.tokensSoldResolvingMarket.toString(),
volumeBoughtResolvingMarket: values.volumeBoughtResolvingMarket.toString(),
volumeBoughtResolvingMarket:
values.volumeBoughtResolvingMarket.toString(),
volumeSoldResolvingMarket: values.volumeSoldResolvingMarket.toString(),
buyOrdersCount: values.buyOrderCount as unknown as bigint,
sellOrdersCount: values.sellOrderCount as unknown as bigint,
Expand Down Expand Up @@ -849,9 +865,11 @@ async function calculateUserPerformance(
tokensSold: insert.tokensSold,
volumeBought: insert.volumeBought,
volumeSold: insert.volumeSold,
tokensBoughtResolvingMarket: insert.tokensBoughtResolvingMarket,
tokensBoughtResolvingMarket:
insert.tokensBoughtResolvingMarket,
tokensSoldResolvingMarket: insert.tokensSoldResolvingMarket,
volumeBoughtResolvingMarket: insert.volumeBoughtResolvingMarket,
volumeBoughtResolvingMarket:
insert.volumeBoughtResolvingMarket,
volumeSoldResolvingMarket: insert.volumeSoldResolvingMarket,
buyOrdersCount: insert.buyOrdersCount,
sellOrdersCount: insert.sellOrdersCount,
Expand Down
Loading
Loading