Skip to content

Commit

Permalink
Add denom traces and validation (#169)
Browse files Browse the repository at this point in the history
* feat: add denom traces and validation

* update python version

* update python version

* fix: fix milkyway assetlist
  • Loading branch information
ALPAC-4 authored Jul 23, 2024
1 parent 93a3c8f commit ff16e97
Show file tree
Hide file tree
Showing 16 changed files with 1,021 additions and 25 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/utility/validate_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import hashlib
from os import getcwd

rootdir = getcwd()
Expand Down Expand Up @@ -49,6 +50,9 @@ def checkChains():
validateRawGithubContent(asset["logo_URIs"]["png"])
if "svg" in asset["logo_URIs"]:
validateRawGithubContent(asset["logo_URIs"]["svg"])

if "base" in asset and "traces" in asset:
validateTraces(asset["traces"], asset["base"])
else:
raise Exception("'assets' array doesn't contain any tokens")
else:
Expand Down Expand Up @@ -86,3 +90,48 @@ def validateRawGithubContent(uri: str):
if not os.path.exists(path):
raise Exception("file(" + path + ") doesn't exists")

# check trace
def validateTraces(traces, denom: str):
denomBefore = None
for trace in traces:
baseDenom = trace["counterparty"]["base_denom"]
if denomBefore != None and baseDenom != denomBefore:
raise Exception("mislink denom traces")
denomBefore = validateTrace(trace)

if denomBefore != None and denomBefore != denom:
print(denomBefore, denom)
raise Exception("denom is not match with denom traces")


# check trace and return estimate denom
def validateTrace(trace) -> str | None:
if trace["type"] == "op":
baseDenom = trace["counterparty"]["base_denom"]
bridgeId = int(trace["chain"]["bridge_id"])
array = bytearray(bridgeId.to_bytes(8, byteorder='big'))
array.extend(bytearray(baseDenom, 'utf-8'))
sha3_256 = hashlib.sha3_256()
sha3_256.update(array)
hash = sha3_256.digest().hex()
return 'l2/' + hash
if trace["type"] == "ibc":
# check counterparty
baseDenom = trace["counterparty"]["base_denom"]
path = trace["chain"]["path"]
pathBefore = '/'.join(path.split('/')[2:])
print(pathBefore, baseDenom)
if getIBCDenom(pathBefore) != baseDenom:
raise Exception("counterparty's base denom is not match with current path")
return getIBCDenom(path)
return None


def getIBCDenom(path: str) -> str :
if len(path.split('transfer/')) == 1:
return path

sha256 = hashlib.sha256()
sha256.update(bytes(path, 'utf-8'))
hash = sha256.digest().hex().upper()
return 'ibc/' + hash
2 changes: 1 addition & 1 deletion .github/workflows/validate_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.9
python-version: 3.11.6

- name: Install Python dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion _packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia-registry-types",
"version": "0.0.19",
"version": "0.0.20",
"description": "The package provides TypeScript type definitions and Zod integration for initia-registry.",
"types": "./dist/types/index.d.ts",
"exports": {
Expand Down
21 changes: 20 additions & 1 deletion _packages/types/src/types/AssetList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface Asset {
/**
* The origin of the asset, starting with the index, and capturing all transitions in form and location.
*/
traces?: (IbcTransition | IbcCw20Transition | NonIbcTransition)[];
traces?: (IbcTransition | IbcCw20Transition | NonIbcTransition | OpTransition)[];
/**
* [OPTIONAL] IBC Channel between src and dst between chain
*/
Expand Down Expand Up @@ -181,6 +181,25 @@ export interface NonIbcTransition {
*/
provider: string;
}
export interface OpTransition {
type: "op";
counterparty: {
/**
* The name of the counterparty chain. (must match exactly the chain name used in the Chain Registry)
*/
chain_name: string;
/**
* The base unit of the asset on its source platform. E.g., when describing ATOM from Cosmos Hub, specify 'uatom', NOT 'atom' nor 'ATOM'; base units are unique per platform.
*/
base_denom: string;
};
chain: {
/**
* The identifier of the OPinit bridge used to transfer assets between L1 and L2.
*/
bridge_id: string;
};
}
/**
* The (primary) key used to identify an object within the Chain Registry.
*/
Expand Down
28 changes: 28 additions & 0 deletions _packages/types/src/zods/AssetList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,34 @@ export const AssetListSchema = z
),
})
.strict(),
z
.object({
type: z.literal("op"),
counterparty: z
.object({
chain_name: z
.string()
.describe(
"The name of the counterparty chain. (must match exactly the chain name used in the Chain Registry)"
),
base_denom: z
.string()
.describe(
"The base unit of the asset on its source platform. E.g., when describing ATOM from Cosmos Hub, specify 'uatom', NOT 'atom' nor 'ATOM'; base units are unique per platform."
),
})
.strict(),
chain: z
.object({
bridge_id: z
.string()
.describe(
"The identifier of the OPinit bridge used to transfer assets between L1 and L2."
),
})
.strict(),
})
.strict(),
])
)
.describe(
Expand Down
40 changes: 40 additions & 0 deletions assetlist.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
},
{
"$ref": "#/$defs/non_ibc_transition"
},
{
"$ref": "#/$defs/op_transition"
}
]
},
Expand Down Expand Up @@ -319,6 +322,43 @@
},
"additionalProperties": false
},
"op_transition": {
"type": "object",
"required": ["type", "counterparty", "chain"],
"properties": {
"type": {
"type": "string",
"enum": ["op"]
},
"counterparty": {
"type": "object",
"required": ["chain_name", "base_denom"],
"properties": {
"chain_name": {
"type": "string",
"description": "The name of the counterparty chain. (must match exactly the chain name used in the Chain Registry)"
},
"base_denom": {
"type": "string",
"description": "The base unit of the asset on its source platform. E.g., when describing ATOM from Cosmos Hub, specify 'uatom', NOT 'atom' nor 'ATOM'; base units are unique per platform."
}
},
"additionalProperties": false
},
"chain": {
"type": "object",
"required": ["bridge_id"],
"properties": {
"bridge_id": {
"type": "string",
"description": "The identifier of the OPinit bridge used to transfer assets between L1 and L2."
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
"non_ibc_transition": {
"type": "object",
"required": ["type", "counterparty", "provider"],
Expand Down
110 changes: 108 additions & 2 deletions testnets/blackwing/assetlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
"name": "Initia Native Token",
"symbol": "INIT",
"coingecko_id": "",
"traces": [
{
"type": "op",
"counterparty": {
"base_denom": "uinit",
"chain_name": "initia"
},
"chain": {
"bridge_id": "8"
}
}
],
"images": [
{
"png": "https://raw.githubusercontent.com/initia-labs/initia-registry/main/testnets/blackwing/images/INIT.png",
Expand Down Expand Up @@ -47,6 +59,20 @@
"name": "Fake ETH Token",
"symbol": "ETH",
"coingecko_id": "",
"traces": [
{
"type": "ibc",
"counterparty": {
"chain_name": "initia",
"base_denom": "ueth",
"channel_id": "channel-13"
},
"chain": {
"channel_id": "channel-0",
"path": "transfer/channel-0/ueth"
}
}
],
"images": [
{
"png": "https://raw.githubusercontent.com/initia-labs/initia-registry/main/testnets/initia/images/ETH.png",
Expand Down Expand Up @@ -75,6 +101,20 @@
"name": "USDC",
"symbol": "USDC",
"coingecko_id": "",
"traces": [
{
"type": "ibc",
"counterparty": {
"chain_name": "initia",
"base_denom": "uusdc",
"channel_id": "channel-13"
},
"chain": {
"channel_id": "channel-0",
"path": "transfer/channel-0/uusdc"
}
}
],
"images": [
{
"png": "https://raw.githubusercontent.com/initia-labs/initia-registry/main/testnets/minimove/images/USDC.png",
Expand Down Expand Up @@ -103,6 +143,20 @@
"name": "Fake TIA Token",
"symbol": "TIA",
"coingecko_id": "",
"traces": [
{
"type": "ibc",
"counterparty": {
"chain_name": "initia",
"base_denom": "utia",
"channel_id": "channel-13"
},
"chain": {
"channel_id": "channel-0",
"path": "transfer/channel-0/utia"
}
}
],
"images": [
{
"png": "https://raw.githubusercontent.com/initia-labs/initia-registry/main/testnets/initia/images/TIA.png",
Expand All @@ -118,19 +172,45 @@
"description": "The native token of Tucana",
"denom_units": [
{
"denom": "ibc/3762BA3774945931505989900A95A73915BD8DD7C50AF32893D00EAE27976561",
"denom": "ibc/F04D40D5C3F283DD816EFA276B11D4804A2ECAB45F654D7355C0209760CCD051",
"exponent": 0
},
{
"denom": "TUC",
"exponent": 6
}
],
"base": "ibc/3762BA3774945931505989900A95A73915BD8DD7C50AF32893D00EAE27976561",
"base": "ibc/F04D40D5C3F283DD816EFA276B11D4804A2ECAB45F654D7355C0209760CCD051",
"display": "TUC",
"name": "Tucana Native Token",
"symbol": "TUC",
"coingecko_id": "",
"traces": [
{
"type": "ibc",
"counterparty": {
"chain_name": "tucana",
"base_denom": "utuc",
"channel_id": "channel-0"
},
"chain": {
"channel_id": "channel-25",
"path": "transfer/channel-25/utuc"
}
},
{
"type": "ibc",
"counterparty": {
"chain_name": "initia",
"base_denom": "ibc/276C63284D960E3E4D76AEFC9A8BA338BAD24E30530C7C95E7EFC4D250D4E23D",
"channel_id": "channel-13"
},
"chain": {
"channel_id": "channel-0",
"path": "transfer/channel-0/transfer/channel-25/utuc"
}
}
],
"images": [
{
"png": "https://raw.githubusercontent.com/initia-labs/initia-registry/main/testnets/tucana/images/TUCANA.png",
Expand Down Expand Up @@ -159,6 +239,32 @@
"name": "MilkyWay IBC milkINIT",
"symbol": "milkINIT",
"coingecko_id": "",
"traces": [
{
"type": "ibc",
"counterparty": {
"chain_name": "milkyway",
"base_denom": "milkuinit",
"channel_id": "channel-0"
},
"chain": {
"channel_id": "channel-310",
"path": "transfer/channel-310/milkuinit"
}
},
{
"type": "ibc",
"counterparty": {
"chain_name": "initia",
"base_denom": "ibc/26939E676F967B14E319631A9A42233148BBC7F7CEFDCBD347447AF0AE37B1AD",
"channel_id": "channel-13"
},
"chain": {
"channel_id": "channel-0",
"path": "transfer/channel-0/transfer/channel-310/milkuinit"
}
}
],
"images": [
{
"png": "https://raw.githubusercontent.com/initia-labs/initia-registry/main/testnets/milkyway/images/milkINIT.png",
Expand Down
Loading

0 comments on commit ff16e97

Please sign in to comment.