Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSoju2 authored Jan 22, 2024
2 parents 58b57fd + 11be70c commit 2753edb
Show file tree
Hide file tree
Showing 15 changed files with 872 additions and 650 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/validate-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ jobs:

## for local act testing
# - run: npm install -g yarn

- run: yarn install

- name: Validate PR
run: yarn validate-PR


run: yarn validate-PR >> $GITHUB_STEP_SUMMARY
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@solana/web3.js": "^1.73.2",
"@types/minimist": "^1.2.5",
"csv-writer": "^1.6.0",
"minimist": "^1.2.8",
"node-downloader-helper": "^2.1.6",
"node-fetch": "^2.6.6"
},
"devDependencies": {
"@types/node": "^18.13.0",
"@types/node-fetch": "^2.6.2",
"csv-parse": "^5.3.5",
"csv-parse": "^5.5.3",
"typescript": "^4.9.5"
}
}
20 changes: 10 additions & 10 deletions pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Validate [{Token Symbol}](https://solscan.io/token/{mint_address})
# Validate [SSHIB](https://solscan.io/token/6VHL2vMKgrF1YQFSv29Rs1pj9VCRK29bD11NtDqerqHA)

## Attestations (Please provide links):
- Tweet from your Twitter Account attesting the Mint address, tagging [@JupiterExchange](https://twitter.com/JupiterExchange) and showing community support: https://twitter.com/{your_account}/status/{your_tweet_id}
- Coingecko/ CMC URL (If available): https://www.coingecko.com/en/coins/{id}
- Tweet from your Twitter Account attesting the Mint address, tagging [@JupiterExchange](https://twitter.com/JupiterExchange) and showing community support: https://x.com/shibonsolana/status/1741126315565261245?s=46
- Coingecko/ CMC URL (If available): https://www.coingecko.com/en/coins/solana-shib / https://coinmarketcap.com/currencies/solana-shib/

## Validation (Please check off boxes):
- [ ] The metadata provided in the PR matches what is on-chain (Mandatory)
- [ ] Does not duplicate the symbol of another token on Jupiter's strict list (If not, review will be delayed)
- [ ] Is Listed on Coingecko / CMC (Optional, but helpful for reviewers)
- [x] The metadata provided in the PR matches what is on-chain (Mandatory)
- [x] Does not duplicate the symbol of another token on Jupiter's strict list (If not, review will be delayed)
- [x] Is Listed on Coingecko / CMC (Optional, but helpful for reviewers)

## Acknowledgement (Please check off boxes)
- [ ] My change matches the format in the file (no spaces between fields).
- [ ] My token is already live and trading on Jupiter.
- [ ] !!! I read the README section on Community-Driven Validation and understand this PR will be only be reviewed when there is community support on Twitter.
- [ ] Please make sure your pull request title has your token name. If it just says "Main", or "Validate", it will automatically be closed. PRs containing broken attestation or solscan links will also be closed.
- [x] My change matches the format in the file (no spaces between fields).
- [x] My token is already live and trading on Jupiter.
- [x] !!! I read the README section on Community-Driven Validation and understand this PR will be only be reviewed when there is community support on Twitter.
- [x] Please make sure your pull request title has your token name. If it just says "Main", or "Validate", it will automatically be closed. PRs containing broken attestation or solscan links will also be closed.
13 changes: 13 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { validateValidatedTokensCsv } from "./logic";
import minimist from "minimist";
// CLI entrypoint which accepts an argument
(async () => {
try {
const argv = minimist(process.argv.slice(2));
const returnCode = await validateValidatedTokensCsv(argv._[0]);
process.exit(returnCode);
}
catch (error: any) {
console.log(error.message)
}
})();
91 changes: 91 additions & 0 deletions src/logic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import { canOnlyAddOneToken, detectDuplicateSymbol, detectDuplicateMints as detectDuplicateMints, validMintAddress, noEditsToPreviousLinesAllowed } from "./utils/validate";
import { ValidatedTokensData } from "./types/types";
import { indexToLineNumber } from "./utils/validate";
import { parse } from "csv-parse/sync";
import fs from "fs";

export async function validateValidatedTokensCsv(filename: string): Promise<number> {
const [records, recordsRaw] = parseCsv(filename);

const recordsPreviousRaw = await gitPreviousVersion("validated-tokens.csv");
fs.writeFileSync(".validated-tokens-0.csv", recordsPreviousRaw);
const [recordsPrevious, _] = parseCsv(".validated-tokens-0.csv")

let duplicateSymbols;
let duplicateMints;
let attemptsToAddMultipleTokens;
let invalidMintAddresses;
let notCommunityValidated;
let noEditsAllowed;

duplicateSymbols = detectDuplicateSymbol(recordsPrevious, records);
duplicateMints = detectDuplicateMints(records);
attemptsToAddMultipleTokens = canOnlyAddOneToken(recordsPrevious, records)
invalidMintAddresses = validMintAddress(records);
noEditsAllowed = noEditsToPreviousLinesAllowed(recordsPrevious, records);
// notCommunityValidated = validCommunityValidated(records);

console.log("No More Duplicate Symbols:", duplicateSymbols);
console.log("Duplicate Mints:", duplicateMints);
console.log("Attempts to Add Multiple Tokens:", attemptsToAddMultipleTokens);
console.log("Invalid Mint Addresses:", invalidMintAddresses);
console.log("Not Community Validated:", notCommunityValidated);
console.log("Edits to Existing Tokens:", noEditsAllowed);
return (duplicateSymbols + duplicateMints + attemptsToAddMultipleTokens + invalidMintAddresses + noEditsAllowed)
}

// Get previous version of validated-tokens.csv from last commit
async function gitPreviousVersion(path: string): Promise<any> {
let prevVersion = "";
let gitCmdError = "";

try {
await exec("git", ["show", `origin/main:${path}`], {
listeners: {
stdout: (data: Buffer) => {
prevVersion += data.toString();
},
stderr: (data: Buffer) => {
gitCmdError += data.toString();
},
},
silent: true
});
} catch (error: any) {
core.setFailed(error.message);
}

if (gitCmdError) {
core.setFailed(gitCmdError);
}
return prevVersion;
}

function parseCsv(filename: string): [ValidatedTokensData[], string] {
const recordsRaw = fs.readFileSync(filename, "utf8")
const r = parse(recordsRaw, {
columns: true,
skip_empty_lines: true,
});
const records = csvToRecords(r);
return [records, recordsRaw];
}

function csvToRecords(r: any): ValidatedTokensData[] {
const records: ValidatedTokensData[] = [];
r.forEach((record: any, i: number) => {
const rec: ValidatedTokensData = {
Name: record.Name,
Symbol: record.Symbol,
Mint: record.Mint,
Decimals: record.Decimals,
LogoURI: record.LogoURI,
"Community Validated": JSON.parse(record["Community Validated"]),
Line: indexToLineNumber(i)
};
records.push(rec);
});
return records;
}
60 changes: 8 additions & 52 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import { parseGitPatch } from "./utils/parse";
import { validateGitPatch } from "./utils/validate";
import { getValidated } from "./utils/get-jup-strict";
import { ValidatedSet, ValidationError } from "./types/types";

// Validates diff between validated-tokens.csv in the branch vs origin/main
async function getDiffAndValidate(): Promise<void> {

let gitDiff = "";
let gitDiffError = "";

import { validateValidatedTokensCsv } from "./logic";
// Github Actions entrypoint
(async () => {
try {
await exec("git", ["diff", "origin/main", "validated-tokens.csv"], {
listeners: {
stdout: (data: Buffer) => {
gitDiff += data.toString();
},
stderr: (data: Buffer) => {
gitDiffError += data.toString();
},
},
});
} catch (error: any) {
core.setFailed(error.message);
}

if (gitDiffError) {
core.setFailed(gitDiffError);
const returnCode = await validateValidatedTokensCsv("validated-tokens.csv");
process.exit(returnCode);
}

// core.debug(`Git diff: ${gitDiff}`)

// Get Jup tokens that are in the strict list to check for duplicates.
let validatedSet: ValidatedSet;
try {
validatedSet = await getValidated();

const errors: ValidationError[][] = []

parseGitPatch(gitDiff).forEach((patch) => {
const patchErrors = validateGitPatch(patch, validatedSet);
if (patchErrors && patchErrors.length > 0) {
errors.push(patchErrors);
}
});

if (errors.length > 0) {
core.setFailed(errors.join(","));
}
} catch (error: any) {
catch (error: any) {
core.setFailed(error.message);
console.log(error.message)
}
}

getDiffAndValidate();
})();
Loading

0 comments on commit 2753edb

Please sign in to comment.