import * as t from "io-ts"; import * as Knex from "knex"; import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed"; import { ReportingState, DisputeTokensRowWithTokenState, UIDisputeTokens, UIDisputeTokenInfo } from "../../types"; import { reshapeDisputeTokensRowToUIDisputeTokenInfo } from "./database"; export const DisputeTokenState = t.keyof({ ALL: null, UNCLAIMED: null, UNFINALIZED: null, }); export const DisputeTokensParams = t.type({ universe: t.string, account: t.string, stakeTokenState: t.union([DisputeTokenState, t.null, t.undefined]), }); export async function getDisputeTokens(db: Knex, augur: {}, params: t.TypeOf<typeof DisputeTokensParams>) { const query: Knex.QueryBuilder = db.select(["payouts.*", "disputes.crowdsourcerId as disputeToken", "balances.balance", "market_state.reportingState"]).from("disputes"); query.join("markets", "markets.marketId", "crowdsourcers.marketId"); query.leftJoin("market_state", "markets.marketStateId", "market_state.marketStateId"); query.leftJoin("blocks", "markets.creationBlockNumber", "blocks.blockNumber"); query.join("crowdsourcers", "crowdsourcers.crowdsourcerId", "disputes.crowdsourcerId"); query.join("payouts", "payouts.payoutId", "crowdsourcers.payoutId"); query.join("balances", "crowdsourcers.crowdsourcerId", "balances.token"); query.where("universe", params.universe).where("disputes.reporter", params.account).where("balances.balance", ">", 0).where("balances.owner", params.account); if (params.stakeTokenState == null || params.stakeTokenState === "ALL") { // currently, do nothing, leaving this in case we want to flavor how we group or present response } else if (params.stakeTokenState === "UNFINALIZED") { query.whereNot("market_state.reportingState", ReportingState.FINALIZED);
jsonrpc: string; method: string; params: any; } export interface JsonRpcResponse { id: string|number|null; jsonrpc: string; result: any; } export const OutcomeParam = t.keyof({ 0: null, 1: null, 2: null, 3: null, 4: null, 5: null, 6: null, 7: null, }); export const SortLimitParams = t.partial({ sortBy: t.union([t.string, t.null, t.undefined]), isSortDescending: t.union([t.boolean, t.null, t.undefined]), limit: t.union([t.number, t.null, t.undefined]), offset: t.union([t.number, t.null, t.undefined]), }); export interface SortLimit { sortBy: string|null|undefined; isSortDescending: boolean|null|undefined;
import * as t from "io-ts"; import * as Knex from "knex"; import * as _ from "lodash"; import { BigNumber } from "bignumber.js"; import { Address } from "../../types"; import { ZERO } from "../../constants"; export const OrderType = t.keyof({ buy: null, sell: null, }); export const BetterWorseOrdersParams = t.type({ marketId: t.string, outcome: t.number, orderType: OrderType, price: t.string, }); export interface BetterWorseResult { betterOrderId: Address|null; worseOrderId: Address|null; } interface OrderRow { orderId: string|null; price: BigNumber; } export async function getBetterWorseOrders(db: Knex, augur: {}, params: t.TypeOf<typeof BetterWorseOrdersParams>): Promise<BetterWorseResult> { const ordersQuery = db("orders").select("orderId", "price").where({ orderState: "OPEN", ..._.pick(params, ["marketId", "outcome", "orderType"])});