Skip to content

Commit

Permalink
test ci :( and changes, still bugged with token schema
Browse files Browse the repository at this point in the history
  • Loading branch information
rinchan01 committed Nov 26, 2024
1 parent dcbe940 commit a2c85b8
Show file tree
Hide file tree
Showing 15 changed files with 2,439 additions and 101 deletions.
8 changes: 4 additions & 4 deletions internal/checkTVL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function verifyTVL() {
for (const file of files) {
const filePath = path.join(tokenDir, file);
const tokenData = <TokenMetadata>load(fs.readFileSync(filePath, "utf8"));
const tokenId = file.substring(0, file.length - 5);
const tokenId = file.split('.')[0];
const newVerified = await checkTVL(v1Pools, v2Pools, tokenId);

if (newVerified === tokenData.verified) {
Expand Down Expand Up @@ -74,9 +74,9 @@ async function checkTVL(v1Pools: SDK.PoolV1.State[], v2Pools: SDK.PoolV2.State[]

const poolV2 = v2Pools.find((pool) => pool.assetA === SDK.Asset.toString(SDK.ADA) && pool.assetB === tokenId);

const reserveV2 = (poolV2?.reserveA ?? 0n) * 2n;
if (maxTVL < reserveV2) {
maxTVL = reserveV2;
const tvlV2 = (poolV2?.reserveA ?? 0n) * 2n;
if (maxTVL < tvlV2) {
maxTVL = tvlV2;
}

return maxTVL >= MINIMUM_TVL;
Expand Down
10 changes: 4 additions & 6 deletions internal/validateTokenFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import * as fs from "node:fs";
import { load } from "js-yaml";
import { execSync } from "node:child_process";

import { DEFAULT_TOKEN_DIR } from "@/types";
import { DEFAULT_TOKEN_DIR, FILE_REGEX } from "@/const";
import type { TokenMetadata } from "@/types";
import { tokenSchema } from "@/token-schema";

const ajv = new Ajv();
const __dirname = import.meta.dirname;
const TOKEN_DIR = path.join(__dirname, `../src/${DEFAULT_TOKEN_DIR}`);
const FILE_REGEX = /^.*[\\/]/;

async function validateTokenFiles(files: string[]) {
for (const file of files) {
if (!file.includes('src/tokens')) {
if (!file.includes("src/tokens")) {
continue;
}
const fileName = file.replace(FILE_REGEX, "");
Expand All @@ -34,10 +33,9 @@ async function validateTokenFiles(files: string[]) {

function getChangedFiles(extension = "") {
const extensionFilter = extension ? `-- '***.${extension}'` : "";
const command = `git diff HEAD^ HEAD --name-only ${extensionFilter}`;
const command = `git diff --name-only @{u}...HEAD ${extensionFilter}`;
const diff = execSync(command.toString());

return diff.toString().split("\n").filter(Boolean);
}

validateTokenFiles(getChangedFiles('yaml'));
validateTokenFiles(getChangedFiles("yaml"));
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ const config = {
// watchman: true,
};

module.exports = config;
export default config;
1 change: 0 additions & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
require("jest-fetch-mock").enableMocks();
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"type": "module",
"scripts": {
"build": "rimraf build && rollup -c rollup.config.js",
"test": "npx tsx ./internal/validateTokenFiles.ts",
"test": "jest && npx tsx ./internal/validateTokenFiles.ts",
"lint": "biome check --no-errors-on-unmatched --fix ."
},
"files": ["build"],
"files": [
"build"
],
"exports": {
".": {
"types": "./build/index.d.ts",
Expand All @@ -27,8 +29,10 @@
"@biomejs/biome": "1.9.4",
"@minswap/sdk": "^0.3.4",
"@total-typescript/ts-reset": "^0.6.1",
"@types/jest": "^29.5.14",
"@types/js-yaml": "^4.0.9",
"@types/node": "^22.9.1",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
"rollup": "^2.79.2",
"rollup-plugin-copy": "^3.5.0",
Expand All @@ -39,6 +43,8 @@
"dependencies": {
"@blockfrost/blockfrost-js": "^5.7.0",
"ajv": "^8.17.1",
"js-yaml": "^4.1.0"
"ajv-formats": "^3.0.1",
"js-yaml": "^4.1.0",
"ts-jest": "^29.2.5"
}
}
Loading

0 comments on commit a2c85b8

Please sign in to comment.