Skip to content

Commit

Permalink
add category to protocol config
Browse files Browse the repository at this point in the history
  • Loading branch information
Manh Cao committed Nov 20, 2024
1 parent 0a1885e commit d7dbdf7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
16 changes: 16 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"id": "avalon-finance",
"name": "Avalon Finance",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -46,6 +47,7 @@
"id": "beefy",
"name": "Beefy",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [],
"yt": [],
Expand Down Expand Up @@ -178,6 +180,7 @@
"id": "cega",
"name": "Cega",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [],
"yt": [
Expand All @@ -196,6 +199,7 @@
"id": "contango",
"name": "Contango",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -262,6 +266,7 @@
"id": "euler",
"name": "Euler",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand All @@ -280,6 +285,7 @@
"id": "form",
"name": "Form",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand All @@ -298,6 +304,7 @@
"id": "index-coop",
"name": "Index Coop",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -328,6 +335,7 @@
"id": "marginly",
"name": "Marginly",
"icon": "marginly-logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -358,6 +366,7 @@
"id": "morpho",
"name": "Morpho",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -418,6 +427,7 @@
"id": "origami",
"name": "Origami",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand All @@ -436,6 +446,7 @@
"id": "pichi",
"name": "Pichi",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -486,6 +497,7 @@
"id": "silo",
"name": "Silo",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -546,6 +558,7 @@
"id": "timeswap",
"name": "Timeswap",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -582,6 +595,7 @@
"id": "venus",
"name": "Venus Protocol",
"icon": "venus.png",
"category": "others",
"metadata": {
"pt": [
{
Expand All @@ -600,6 +614,7 @@
"id": "yearn",
"name": "yearn",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down Expand Up @@ -804,6 +819,7 @@
"id": "zerolend",
"name": "ZeroLend",
"icon": "logo.png",
"category": "others",
"metadata": {
"pt": [
{
Expand Down
7 changes: 7 additions & 0 deletions const.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const DEFAULT_PROTOCOL_CATEGORY = 'others';
const PROTOCOL_CATEGORIES = ['money market', 'vault', 'liquid locker'];

module.exports = {
DEFAULT_PROTOCOL_CATEGORY,
PROTOCOL_CATEGORIES,
}
31 changes: 24 additions & 7 deletions merge-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const yaml = require("js-yaml");
const {DEFAULT_PROTOCOL_CATEGORY} = require("./const");

async function run() {
const protocolsPath = path.join(__dirname, 'protocols');
Expand Down Expand Up @@ -51,19 +52,35 @@ async function run() {
}

function formatProtocolConfig(config) {
const {metadata} = config;
const {id, name, icon, category, metadata} = config;
const {pt, yt, lp} = metadata;
lowercaseAddressOfMetadata(pt);
lowercaseAddressOfMetadata(yt);
lowercaseAddressOfMetadata(lp);

return config;
return {
id,
name,
icon,
category: category ?? DEFAULT_PROTOCOL_CATEGORY,
metadata: {
pt: formatMetadataAssets(pt),
yt: formatMetadataAssets(yt),
lp: formatMetadataAssets(lp),
},
};
}

function lowercaseAddressOfMetadata(assets) {
function formatMetadataAssets(assets) {
const result = [];
for (const asset of (assets ?? [])) {
asset.address = asset.address.toLowerCase();
const {chainId, address, integrationUrl, description} = asset;
result.push({
chainId,
address: address.toLowerCase(),
integrationUrl,
description,
})
}

return result;
}

function createMD5(filePath) {
Expand Down
16 changes: 14 additions & 2 deletions validate-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const {PROTOCOL_CATEGORIES} = require("./const");

const LIMIT_ICON_KB_SIZE = 20;
const BUFFER_LIMIT_ICON_KB_SIZE = LIMIT_ICON_KB_SIZE + 1;
Expand All @@ -15,6 +16,16 @@ function isKebabCase(str) {
return kebabCaseRegex.test(str);
}

function validateCategory(protocol, category) {
if (category === undefined) {
return;
}

if (!mustBeNonEmptyString(category) || !PROTOCOL_CATEGORIES.includes(category)) {
throw new Error(`protocol ${protocol}: invalid field 'category', category must be one of the values (${PROTOCOL_CATEGORIES.join(', ')}) or left unset`);
}
}

async function main() {
const CHANGED_PROTOCOLS = process.env.CHANGED_PROTOCOLS;
const GET_ASSET_LIST_URL = process.env.GET_ASSET_LIST_URL;
Expand Down Expand Up @@ -81,12 +92,14 @@ function validateConfig(protocol, assetMap) {
throw new Error(`protocol ${protocol}: config is not an object`);
}

const {name, icon, metadata} = protocolConfig;
const {name, icon, metadata, category} = protocolConfig;

if (!mustBeNonEmptyString(name)) {
throw new Error(`protocol ${protocol}: invalid field 'name'`);
}

validateCategory(protocol, category);

if (!mustBeNonEmptyString(icon)) {
throw new Error(`protocol ${protocol}: invalid field 'icon'`);
}
Expand All @@ -113,7 +126,6 @@ function validateConfig(protocol, assetMap) {
throw new Error(`protocol ${protocol}: icon size must be less than ${LIMIT_ICON_KB_SIZE}KB file`);
}


const {pt, yt, lp} = metadata;
checkMetadataField(pt, protocol, 'pt', ptMap);
checkMetadataField(yt, protocol, 'yt', ytMap);
Expand Down

0 comments on commit d7dbdf7

Please sign in to comment.