Skip to content

Commit

Permalink
add category to protocol config (#69)
Browse files Browse the repository at this point in the history
* add category to protocol config

* update readme

---------

Co-authored-by: Manh Cao <[email protected]>
Co-authored-by: Manh Cao <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent 0a1885e commit cb0214a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The YAML file includes details for multiple objects (PT, YT, LP), each correspon

- name: The name of the protocol.
- icon: The protocol’s logo (circular logo in PNG). The string on this field should be the same as the name of the logo file uploaded. Size limit for logo is 20KB.
- category: The protocol's category. It must belong to one of the following categories: `money market`, `vault` or `liquid locker`. If no category is specified, the protocol will automatically default to the `others` type.
- metadata: This section contains detailed information about the protocol's integration assets.

#### Asset fields
Expand All @@ -25,6 +26,7 @@ The YAML file includes details for multiple objects (PT, YT, LP), each correspon
```yaml
name: Protocol Name 2
icon: logo.png
category: 'vault'
metadata:
pt:
- chainId: 1
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 cb0214a

Please sign in to comment.