Skip to content

Commit

Permalink
Merge pull request #266 from metaDAOproject/staging
Browse files Browse the repository at this point in the history
Deploy Production
  • Loading branch information
LukasDeco authored Sep 6, 2024
2 parents 7143fc4 + a50f9b8 commit c98c10b
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
-X POST \
-H "Authorization: Bearer ${{ secrets.RAILWAY_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"query\":\"mutation { deploymentRedeploy(id: \\\"66218c70-8c19-4981-a295-12d442949870\\\") { status } }\"}" \
--data '{"query": "mutation serviceInstanceDeploy($serviceId: String!, $environmentId: String!) {\n serviceInstanceDeploy(serviceId: $serviceId, environmentId: $environmentId)\n}\n", "variables": { "environmentId": "4015588d-3c82-4413-9484-314539aecd39", "serviceId": "783719dc-3c30-437d-a3a9-b1aeb1d5c487" } }'
31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run tests before merge
on:
pull_request:
branches: [staging]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "21"

- name: Install pnpm
run: npm install -g pnpm

- name: Install bun
uses: oven-sh/setup-bun@v1

- name: Install dependencies
run: pnpm install

- name: Test
run: bun test
env:
RPC_ENDPOINT: https://api.devnet.solana.com/
INDEXER_URL: https://staging-indexer.metadao.fi
INDEXER_WSS_URL: wss://staging-indexer.metadao.fi
12 changes: 10 additions & 2 deletions packages/indexer/src/builders/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ export class SwapBuilder {
(userQuotePreBalance ?? BigInt(0))
).abs();

if (
!!tx.err &&
quoteAmount.toNumber() === 0 &&
baseAmount.toNumber() === 0
) {
return Err({ type: AmmInstructionIndexerError.FailedSwap });
}

// determine price
// NOTE: This is estimated given the output is a min expected value
// default is input / output (buying a token with USDC or whatever)
Expand Down Expand Up @@ -244,9 +252,9 @@ export class SwapBuilder {
}

const ammPrice =
quoteAmount && baseAmount
quoteAmount.toNumber() && baseAmount.toNumber()
? quoteAmount.mul(new BN(10).pow(new BN(12))).div(baseAmount)
: 0;
: new BN(0);
const price = getHumanPrice(
ammPrice,
baseToken[0].decimals,
Expand Down
160 changes: 0 additions & 160 deletions packages/indexer/src/endpoints/auth.ts

This file was deleted.

12 changes: 8 additions & 4 deletions packages/indexer/src/indexers/amm-market/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export async function indexAmmMarketAccountWithContext(
updatedSlot: context
? BigInt(context.slot)
: BigInt(ammMarketAccount.oracle.lastUpdatedSlot.toNumber()),
lastObservation: ammMarketAccount.oracle.lastObservation,
lastPrice: ammMarketAccount.oracle.lastPrice
};

// TODO batch commits across inserts - maybe with event queue
Expand All @@ -81,12 +83,14 @@ export async function indexAmmMarketAccountWithContext(
}
}

const priceFromReserves = PriceMath.getAmmPriceFromReserves(
ammMarketAccount?.baseAmount,
ammMarketAccount?.quoteAmount
);

// indexing the conditional market price
const conditionalMarketSpotPrice = getHumanPrice(
PriceMath.getAmmPriceFromReserves(
ammMarketAccount?.baseAmount,
ammMarketAccount?.quoteAmount
),
priceFromReserves,
baseToken.decimals!!,
quoteToken.decimals!!
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ async function insertAssociatedAccountsDataForProposal(
if (dao && daoDetails) {
if (isQuote) {
// Fail / Pass USDC
imageUrl = isFail
imageUrl = !isFail
? "https://imagedelivery.net/HYEnlujCFMCgj6yA728xIw/f38677ab-8ec6-4706-6606-7d4e0a3cfc00/public"
: "https://imagedelivery.net/HYEnlujCFMCgj6yA728xIw/d9bfd8de-2937-419a-96f6-8d6a3a76d200/public";
} else {
Expand Down
4 changes: 0 additions & 4 deletions packages/indexer/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { authGet, authPost, authPut } from "./endpoints/auth";
import { getMetrics } from "./endpoints/get-metrics";
import { logger } from "./logger";
import cors from "cors";
Expand All @@ -12,9 +11,6 @@ export function startServer() {
app.use(express.json());
app.use(cors({ origin: "*", allowedHeaders: ["Content-Type"] }));
app.get("/metrics", getMetrics);
app.post("/auth", authPost);
app.put("/auth", authPut);
app.get("/auth", authGet);

app.listen(PORT, () => {
logger.log(`Server listening on Port ${PORT}`);
Expand Down
67 changes: 34 additions & 33 deletions packages/indexer/src/transaction/serializer.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import { serialize, deserialize, Transaction } from './serializer';
import { expect, test } from 'bun:test';
import { serialize, deserialize, Transaction } from "./serializer";
import { expect, describe, test } from "bun:test";

test('serialize-deserialize', async () => {
describe("serializer", async () => {
test("serialize-deserialize", async () => {
const testTx: Transaction = {
blockTime: 0,
slot: 0,
recentBlockhash: "",
computeUnitsConsumed: BigInt(4),
fee: BigInt(2),
signatures: [],
version: "legacy",
logMessages: [],
accounts: [
{
pubkey: "BIGINT:a300n", // false flag
isSigner: true,
isWriteable: false,
preBalance: BigInt(800),
postBalance: BigInt(3000000),
},
],
instructions: [],
};

const testTx: Transaction = {
blockTime: 0,
slot: 0,
recentBlockhash: "",
computeUnitsConsumed: BigInt(4),
fee: BigInt(2),
signatures: [],
version: 'legacy',
logMessages: [],
accounts: [
{
pubkey: "BIGINT:a300n", // false flag
isSigner: true,
isWriteable: false,
preBalance: BigInt(800),
postBalance: BigInt(3000000)
}
],
instructions: []
};
const str = serialize(testTx);

const str = serialize(testTx);
expect(str).toBe(
`{"blockTime":0,"slot":0,"recentBlockhash":"",` +
`"computeUnitsConsumed":"BIGINT:4","fee":"BIGINT:2","signatures":[],"version":"legacy","logMessages":[],` +
`"accounts":[{"pubkey":"BIGINT:a300n","isSigner":true,"isWriteable":false,"preBalance":"BIGINT:800","postBalance":"BIGINT:3000000"}],` +
`"instructions":[]}`
);

expect(str).toBe(
`{"blockTime":0,"slot":0,"recentBlockhash":"",` +
`"computeUnitsConsumed":"BIGINT:4","fee":"BIGINT:2","signatures":[],"version":"legacy","logMessages":[],`+
`"accounts":[{"pubkey":"BIGINT:a300n","isSigner":true,"isWriteable":false,"preBalance":"BIGINT:800","postBalance":"BIGINT:3000000"}],`+
`"instructions":[]}`
);
const deserialized = deserialize(str) as any;

const deserialized = deserialize(str) as any;

expect(deserialized).toEqual({success: true, ok: testTx});
expect(deserialized).toEqual({ success: true, ok: testTx });
});
});
1 change: 1 addition & 0 deletions packages/indexer/src/types/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum AmmInstructionIndexerError {
GeneralError = "GeneralError",
MissingMarket = "MissingMarket",
FailedSwap = "FailedSwap",
}

export enum SwapPersistableError {
Expand Down
Loading

0 comments on commit c98c10b

Please sign in to comment.