Skip to content

Commit

Permalink
Get the liquidity e2e tests working
Browse files Browse the repository at this point in the history
Have `postgrest` start after the `processor` in order to ensure the schema is uploaded correctly- aka after migrations are run

Bump the processor submodule
  • Loading branch information
matt committed Sep 26, 2024
1 parent 5d76c33 commit 4ede070
Show file tree
Hide file tree
Showing 25 changed files with 282 additions and 255 deletions.
2 changes: 1 addition & 1 deletion src/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:

postgrest:
depends_on:
postgres:
processor:
condition: 'service_healthy'
environment:
PGRST_DB_URI: 'postgres://emojicoin:emojicoin@postgres:5432/emojicoin'
Expand Down
2 changes: 1 addition & 1 deletion src/typescript/frontend/src/app/market/[market]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const EmojicoinPage = async (params: EmojicoinPageProps) => {
}
return res;
});
const state = await fetchMarketState({ marketEmojis: emojis });
const state = await fetchMarketState({ searchEmojis: emojis });

const geoblocked = await isUserGeoblocked(headers().get("x-real-ip"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,20 @@ export const CongratulationsToast = ({
<div className="flex flex-col text-center">
<span className="text-7xl p-[20px]">🎉</span>
<div className="flex flex-col text-center">
<span className="font-pixelar text-5xl uppercase">
Congratulations!
</span>
<span className="font-pixelar text-5xl uppercase">Congratulations!</span>
<span className="font-forma text-2xl uppercase text-ec-blue">
<span>{`You won ${amountString} APT.`}</span>
</span>
<div className="w-[100%] flex flex-row justify-center mb-[15px]">
<span className="text-dark-gray text-l uppercase">
View the transaction&nbsp;
</span>
<span className="text-dark-gray text-l uppercase">View the transaction&nbsp;</span>
<ExplorerLink
network={network?.name ?? APTOS_NETWORK}
value={transactionHash}
type="transaction"
>
<span className="text-dark-gray text-l uppercase underline">
here
</span>
<span className="text-dark-gray text-l uppercase underline">here</span>
</ExplorerLink>
<span className="text-dark-gray text-l uppercase">
.
</span>
<span className="text-dark-gray text-l uppercase">.</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const SwapButton = ({
toast.dark(
<>
<RewardsAnimation controls={controls} />
<CongratulationsToast transactionHash={res.response.hash} amount={rewardsEvent.data.octas_reward_amount} />
<CongratulationsToast
transactionHash={res.response.hash}
amount={rewardsEvent.data.octas_reward_amount}
/>
</>,
{
pauseOnFocusLoss: false,
Expand All @@ -80,7 +83,7 @@ export const SwapButton = ({
<Button disabled={disabled} onClick={handleClick} scale="lg">
{t("Swap")}
</Button>
<RewardsAnimation controls={controls} />
<RewardsAnimation controls={controls} />
</ButtonWithConnectWalletFallback>
</>
);
Expand Down
Empty file.
94 changes: 0 additions & 94 deletions src/typescript/frontend/src/lib/queries/sorting/market-data.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/typescript/sdk/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AccountAddress, APTOS_COIN, parseTypeTag } from "@aptos-labs/ts-sdk";
import Big from "big.js";
import { type ValueOf } from "./utils/utility-types";
import { type DatabaseDataTypes } from "./indexer-v2/types/json-types";
import { type DatabaseStructType } from "./indexer-v2/types/json-types";

export const VERCEL = process.env.VERCEL === "1";
if (!process.env.NEXT_PUBLIC_MODULE_ADDRESS || !process.env.NEXT_PUBLIC_REWARDS_MODULE_ADDRESS) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export enum Trigger {
Chat = "chat",
}

export const toPeriod = (s: DatabaseDataTypes["PeriodicStateMetadata"]["period"]) =>
export const toPeriod = (s: DatabaseStructType["PeriodicStateMetadata"]["period"]) =>
({
// From the database.
period_1m: Period.Period1M,
Expand All @@ -106,7 +106,7 @@ export const toPeriod = (s: DatabaseDataTypes["PeriodicStateMetadata"]["period"]
throw new Error(`Unknown period: ${s}`);
})();

export const toTrigger = (s: DatabaseDataTypes["GlobalStateEventData"]["trigger"]) =>
export const toTrigger = (s: DatabaseStructType["GlobalStateEventData"]["trigger"]) =>
({
// From the database.
package_publication: Trigger.PackagePublication,
Expand Down
1 change: 1 addition & 0 deletions src/typescript/sdk/src/indexer-v2/queries/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./home";
export * from "./market";
export * from "./pools";
export * from "./candlesticks";
9 changes: 4 additions & 5 deletions src/typescript/sdk/src/indexer-v2/queries/app/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "server-only";
import { type PostgrestBuilder } from "@supabase/postgrest-js";
import { LIMIT, ORDER_BY } from "../../../queries";
import { type AnyNumberString } from "../../../types";
import { type DatabaseType, TableName } from "../../types/json-types";
import { type DatabaseJsonType, TableName } from "../../types/json-types";
import { postgrest, toQueryArray } from "../client";
import { queryHelper, queryHelperSingle } from "../utils";
import {
Expand Down Expand Up @@ -63,14 +63,13 @@ const selectPeriodicEventsSince = ({
.range(offset, offset + limit - 1)
.limit(limit);

// prettier-ignore
const selectMarketState = ({ marketEmojis }: { marketEmojis: MarketSymbolEmojis }) =>
const selectMarketState = ({ searchEmojis }: { searchEmojis: MarketSymbolEmojis }) =>
postgrest
.from(TableName.MarketState)
.select("*")
.eq("symbol_emojis", toQueryArray(marketEmojis))
.eq("symbol_emojis", toQueryArray(searchEmojis))
.limit(1)
.single() as PostgrestBuilder<DatabaseType["market_state"]>;
.single() as PostgrestBuilder<DatabaseJsonType["market_state"]>;

export const fetchSwapEvents = queryHelper(selectSwapsByMarketID, toSwapEventModel);
export const fetchChatEvents = queryHelper(selectChatsByMarketID, toChatEventModel);
Expand Down
12 changes: 10 additions & 2 deletions src/typescript/sdk/src/indexer-v2/queries/app/pools.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { type AccountAddressInput, type Account } from "@aptos-labs/ts-sdk";
import { type PostgrestTransformBuilder } from "@supabase/postgrest-js";
import { LIMIT, ORDER_BY } from "../../../queries";
import { toAccountAddressString } from "../../../utils";
import { toUserPoolsRPCResponse } from "../../types";
import { postgrest } from "../client";
import { queryHelper } from "../utils";
import { sortByWithFallback } from "../query-params";
import { type MarketStateQueryArgs, SortMarketsBy } from "../../types/common";
import { type DatabaseRpc, type DatabaseJsonType } from "../../types/json-types";

const callUserPools = ({
provider,
Expand All @@ -24,7 +26,13 @@ const callUserPools = ({
query = query.range((page - 1) * limit, page * limit - 1);
}

return query;
return query as PostgrestTransformBuilder<
any,
any,
Array<DatabaseJsonType["user_pools"]>,
DatabaseRpc.UserPools,
DatabaseRpc.UserPools
>;
};

export const fetchUserLiquidityPools = queryHelper(callUserPools as any, toUserPoolsRPCResponse);
export const fetchUserLiquidityPools = queryHelper(callUserPools, toUserPoolsRPCResponse);
25 changes: 14 additions & 11 deletions src/typescript/sdk/src/indexer-v2/queries/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import "server-only";
import { PostgrestClient } from "@supabase/postgrest-js";
import { stringifyParsedBigInts } from "../json-bigint";
import { type TableName } from "../types/json-types";
import { EMOJICOIN_INDEXER_URL } from "../../server-env";
import { EMOJICOIN_INDEXER_URL, FETCH_DEBUG, FETCH_DEBUG_VERBOSE } from "../../server-env";

/**
* Fetch with BigInt support. This is necessary because the JSON returned by the indexer
* contains BigInts, which are not supported by the default fetch implementation.
*
* If you set the environment variable `FETCH_DEBUG=true`, it will log every response and URL to the
* console.
* To log all query URLs to the terminal, set the environment variable `FETCH_DEBUG=true`.
* Set `FETCH_DEBUG_VERBOSE=true` to see all query URLs *and* responses.
* Queries for the the latest success version from the `processor_status` table are not logged.
*/
const fetchPatch: typeof fetch = async (input, init) => {
const response = await fetch(input, init);
Expand All @@ -22,15 +23,17 @@ const fetchPatch: typeof fetch = async (input, init) => {
const text = await response.text();
const json = stringifyParsedBigInts(text);

if (process.env.FETCH_DEBUG === "true") {
/* eslint-disable-next-line no-console */
console.dir(
{
RESPONSE: json,
URL: response.url,
},
{ depth: null }
if (FETCH_DEBUG || FETCH_DEBUG_VERBOSE) {
const isWaitForEmojicoinIndexerQuery = response.url.endsWith(
"processor_status?select=last_success_version"
);
if (!isWaitForEmojicoinIndexerQuery) {
console.debug(response.url);
if (FETCH_DEBUG_VERBOSE) {
const stringified = JSON.stringify(json, null, 2);
console.debug(stringified);
}
}
}

return new Response(json, response);
Expand Down
8 changes: 5 additions & 3 deletions src/typescript/sdk/src/indexer-v2/queries/query-params.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SortMarketsBy } from "../types/common";
import { type DatabaseType } from "../types/json-types";
import { type DatabaseJsonType } from "../types/json-types";

/* eslint-disable-next-line import/no-unused-modules */
export const sortByToColumn = (sortBy: SortMarketsBy): keyof DatabaseType["market_state"] => {
export const sortByToColumn = (sortBy: SortMarketsBy): keyof DatabaseJsonType["market_state"] => {
switch (sortBy) {
case SortMarketsBy.AllTimeVolume:
return "cumulative_stats_quote_volume";
Expand All @@ -23,7 +23,9 @@ export const sortByToColumn = (sortBy: SortMarketsBy): keyof DatabaseType["marke
}
};

export const sortByWithFallback = (input?: string | null): keyof DatabaseType["market_state"] => {
export const sortByWithFallback = (
input?: string | null
): keyof DatabaseJsonType["market_state"] => {
const sortBy = input ?? SortMarketsBy.MarketCap;
try {
return sortByToColumn(sortBy as SortMarketsBy);
Expand Down
Loading

0 comments on commit 4ede070

Please sign in to comment.