Skip to content

Commit

Permalink
Merge branch 'cosmos:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0n00gler authored Jun 3, 2024
2 parents 246ad8b + 080fa73 commit a681556
Show file tree
Hide file tree
Showing 267 changed files with 10,123 additions and 1,159 deletions.
151 changes: 114 additions & 37 deletions .github/workflows/utility/sync_images.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,19 @@ function getLinkedImages(){
let chains = chain_reg.getChains();
chains.forEach((chainName) => {
let images = chain_reg.getFileProperty(chainName, "chain", "images");
if(images) {
let replacementImage;
images?.forEach((image) => {
if (!image?.image_sync) {
return;
}
replacementImage = getLinkedImage(image.image_sync.chain_name, image.image_sync.base_denom);
if(replacementImage){
image.png = replacementImage?.png;
image.svg = replacementImage?.svg;
image.theme = replacementImage?.theme;
}
});
chain_reg.setFileProperty(chainName, "chain", "images", images);
}
if (!images) { return; }
images?.forEach((image) => {
if (!image?.image_sync) {
return;
}
let replacementImage = getLinkedImage(image.image_sync.chain_name, image.image_sync.base_denom);
if (replacementImage) {
image.png = replacementImage?.png;
image.svg = replacementImage?.svg;
image.theme = replacementImage?.theme;
}
});
chain_reg.setFileProperty(chainName, "chain", "images", images);
});

// get list of assets, iterate each asset
Expand All @@ -240,60 +238,62 @@ function getLinkedImages(){
let assets = chain_reg.getAssetPointers();
assets.forEach((assetPointer) => {
let images = chain_reg.getAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "images");
if(images) {
images?.forEach((image) => {
let replacementImage;
if (!image?.image_sync) {
return;
}
replacementImage = getLinkedImage(image.image_sync.chain_name, image.image_sync.base_denom);
if(replacementImage){
image.png = replacementImage.png;
image.svg = replacementImage.svg;
image.theme = replacementImage.theme;
}
});
chain_reg.setAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "images", images);
}
if (!images) { return; }
images?.forEach((image) => {
if (!image?.image_sync) {
return;
}
let replacementImage = getLinkedImage(image.image_sync.chain_name, image.image_sync.base_denom);
if (replacementImage) {
image.png = replacementImage.png;
image.svg = replacementImage.svg;
image.theme = replacementImage.theme;
}
});
chain_reg.setAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "images", images);
});

}

// finds the URL of the image being referenced--recursive incase the image being referenced references another image
function getLinkedImage(chain_name, base_denom){

let images;
if (base_denom) {
images = chain_reg.getAssetProperty(chain_name, base_denom, "images");
} else {
images = chain_reg.getFileProperty(chain_name, "chain", "images")
}
if(!images){return;}
if (!images) { return; }
let image = images[0];
if(image.image_sync){
if (image.image_sync) {
if (
base_denom == image.image_sync.base_denom &&
chain_name == image.image_sync.chain_name
) {
return;
return; //catches self-references
}
return getLinkedImage(image.image_sync.chain_name, image.image_sync.base_denom);
} else {
return image;
}
}

function overwriteLogoURIs(chain_name, base_denom){
function overwriteLogoURIs(){

// iterate chains
// iterate assets
// if images
// logo_URIs::png&&svg = images[0].png&&svg



let chains = chain_reg.getChains();
chains.forEach((chainName) => {
let logo_URIs = chain_reg.getFileProperty(chainName, "chain", "logo_URIs");
if (!logo_URIs) { return; }
let images = chain_reg.getFileProperty(chainName, "chain", "images");
let logo_URIs = {
logo_URIs = {
png: images?.[0]?.png,
svg: images?.[0]?.svg
}
Expand All @@ -306,8 +306,10 @@ function overwriteLogoURIs(chain_name, base_denom){

let assets = chain_reg.getAssetPointers();
assets.forEach((assetPointer) => {
let logo_URIs = chain_reg.getAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "logo_URIs");
if (!logo_URIs) { return; }
let images = chain_reg.getAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "images");
let logo_URIs = {
logo_URIs = {
png: images?.[0]?.png,
svg: images?.[0]?.svg
}
Expand All @@ -320,8 +322,83 @@ function overwriteLogoURIs(chain_name, base_denom){

}

function defineImageSync() {

let assets = chain_reg.getAssetPointers();
assets.forEach((assetPointer) => {

let traces = chain_reg.getAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "traces");
if (!traces) { return; }
let lastTrace = traces[traces.length - 1];
let originAssetPointer = {
chain_name: lastTrace.counterparty.chain_name,
base_denom: lastTrace.counterparty.base_denom
}

let images = chain_reg.getAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "images");

//find out of any of the images are synced with the origin
for (let i = 0; i < images.length; ++i) {
if (
images[i].image_sync?.chain_name === originAssetPointer.chain_name &&
images[i].image_sync?.base_denom === originAssetPointer.base_denom
) {
return;
}
}

//if there is one, then skip, otherwise,
//if there is none, the iterate each image, and
//look for any matches between the image and the origin image

let originImage = chain_reg.getAssetProperty(originAssetPointer.chain_name, originAssetPointer.base_denom, "images")?.[0];
if (!originImage) { return; }

let newImages = [];
let HAS_UPDATED = false;
images.forEach((image) => {
let newImage = {};

if (
(
(image.png === originImage.png && originImage.png) ||
(image.svg === originImage.svg && originImage.svg)
) &&
!image.image_sync
) {
newImage.image_sync = originAssetPointer;
if (originImage.png) {
newImage.png = originImage.png;
}
if (originImage.svg) {
newImage.svg = originImage.svg;
}
newImage.theme === originImage.theme;
HAS_UPDATED = true;
} else {
newImage = image;
}
newImages.push(newImage);
});

if (HAS_UPDATED) {
chain_reg.setAssetProperty(assetPointer.chain_name, assetPointer.base_denom, "images", newImages);
if (assetPointer.base_denom === "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7") {
console.log(assetPointer.chain_name);
console.log(assetPointer.base_denom);
console.log(images);
console.log(newImages);
}
HAS_UPDATED = false;
}

});

}

function main(){
createImagesArray();
defineImageSync();
getLinkedImages();
overwriteLogoURIs();
}
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/utility/validate_data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ function checkDenomUnits(asset) {

}

function checkTraceCounterpartyIsValid(chain_name, asset) {

if (!asset.base) { return; }
asset.traces?.forEach((trace) => {
let base = chain_reg.getAssetProperty(trace.counterparty.chain_name, trace.counterparty.base_denom, "base");
if (!base) {
throw new Error(`Trace of ${chain_name}, ${asset.base} makes invalid reference to ${trace.counterparty.chain_name}, ${trace.counterparty.base_denom}.`);
}
if (asset.base === trace.counterparty.base_denom && chain_name === trace.counterparty.chain_name) {
throw new Error(`Trace of ${chain_name}, ${asset.base} makes reference to self.`);
}
});

}

function checkImageSyncIsValid(chain_name, asset) {

if (!asset.base) { return; }
asset.images?.forEach((image) => {
if (!image.image_sync) { return; }
let base = chain_reg.getAssetProperty(image.image_sync.chain_name, image.image_sync.base_denom, "base");
if (!base) {
throw new Error(`Image Sync Pointer of ${chain_name}, ${asset.base} makes invalid reference to ${image.image_sync.chain_name}, ${image.image_sync.base_denom}.`);
}
if (asset.base === image.image_sync.base_denom && chain_name === image.image_sync.chain_name) {
throw new Error(`Image_sync of ${chain_name}, ${asset.base} makes reference to self.`);
}
});

}


export function validate_chain_files() {

Expand Down Expand Up @@ -146,6 +177,12 @@ export function validate_chain_files() {

//check denom units
checkDenomUnits(asset);

//check counterparty pointers of traces
checkTraceCounterpartyIsValid(chain_name, asset);

//check image_sync pointers of images
checkImageSyncIsValid(chain_name, asset);

});

Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

name: Validate ✅

jobs:
validate-schema:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4

- name: Setup Node.js 🌐
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install @chain-registry/cli 📜
run: |
npm install -g @chain-registry/cli@1.47.0
- name: Validate ✓
run: |
chain-registry validate --registryDir . --logLevel error
20 changes: 20 additions & 0 deletions .github/workflows/validate_versionsjson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on: [pull_request, workflow_dispatch]
name: PR workflow
jobs:
validate_chainjson:
name: Validate edited versions.json
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install JSON-Schema-Validator
run: npm install -g jsonschema

- name: Validate Versions.json schema
run: |
for file in $(find . -name 'versions.json' | grep -v '_template/'); do
if ! jsonschema -i "$file" ./versions.schema.json; then
exit 1
fi
done
38 changes: 2 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,41 +110,7 @@ A sample `chain.json` includes the following information.
"height": 0,
"next_version_name": "v4"
},
{
"name": "v4",
"tag": "v4.2.0",
"height": 1314500,
"proposal": 38,
"next_version_name": "v5"
},
{
"name": "v5",
"tag": "v6.4.1",
"height": 2383300,
"proposal": 95,
"next_version_name": "v7"
},
{
"name": "v7",
"tag": "v8.0.0",
"height": 3401000,
"proposal": 157,
"next_version_name": "v9"
},
{
"name": "v9",
"tag": "v10.0.1",
"height": 4707300,
"proposal": 252,
"next_version_name": "v11"
},
{
"name": "v11",
"tag": "v11.0.0",
"height": 5432450,
"proposal": 296,
"next_version_name": "v12"
},
...//version history can alternatively go into 'versions.json'
{
"name": "v12",
"tag": "v12.1.0",
Expand Down Expand Up @@ -260,7 +226,7 @@ Asset Lists are inspired by the [Token Lists](https://tokenlists.org/) project o

Asset lists are a similar mechanism to allow frontends and other UIs to fetch metadata associated with Cosmos SDK denoms, especially for assets sent over IBC.

This standard is a work in progress. You'll notice that the format of `assets` in the assetlist.json structure is a strict superset json representation of the [`banktypes.DenomMetadata`](https://docs.cosmos.network/master/architecture/adr-024-coin-metadata.html) from the Cosmos SDK. This is purposefully done so that this standard may eventually be migrated into a Cosmos SDK module in the future, so it can be easily maintained on chain instead of on Github.
This standard is a work in progress. You'll notice that the format of `assets` in the assetlist.json structure is a strict superset json representation of the [`banktypes.DenomMetadata`](https://docs.cosmos.network/main/build/architecture/adr-024-coin-metadata) from the Cosmos SDK. This is purposefully done so that this standard may eventually be migrated into a Cosmos SDK module in the future, so it can be easily maintained on chain instead of on Github.

The assetlist JSON Schema can be found [here](/assetlist.schema.json).

Expand Down
31 changes: 31 additions & 0 deletions _IBC/axelar-pryzm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "../ibc_data.schema.json",
"chain_1": {
"chain_name": "axelar",
"client_id": "07-tendermint-224",
"connection_id": "connection-209"
},
"chain_2": {
"chain_name": "pryzm",
"client_id": "07-tendermint-7",
"connection_id": "connection-7"
},
"channels": [
{
"chain_1": {
"channel_id": "channel-155",
"port_id": "transfer"
},
"chain_2": {
"channel_id": "channel-13",
"port_id": "transfer"
},
"ordering": "unordered",
"version": "ics20-1",
"tags": {
"status": "live",
"preferred": true
}
}
]
}
Loading

0 comments on commit a681556

Please sign in to comment.