Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add network fees and transfer options config #39

Merged
merged 8 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/markets/pr_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Each json file under the [configs](../../configs) folder correspond to their res
|`blacklisted_pools` |`string[]` |true |The array of pool ids that are blacklisted. A pool can be blacklisted for a number of reasons, such as it being invalid/duplicate/wrongly-added/etc. |The pool ids listed here **MUST** match the pool ids listed under the Carbon [Liquidity Pool API](https://api.carbon.network/carbon/liquiditypool/v1/pools?pagination.limit=10000). |
|`blacklisted_tokens` |`string[]` |true |The array of token denoms that are blacklisted. A token can be blacklisted for a number of reasons, such as it being invalid/deprecated/etc. |The token denoms listed here **MUST** match the token denoms listed under the Carbon [Tokens API](https://api.carbon.network/carbon/coin/v1/tokens?pagination.limit=10000). |
|`ibc_tokens_total_supply` |`IBCTotalSuppply[]` |true |The array of IBC fee token denoms with their respective total supply on Coingecko. |Please refer to the [IBC total supply data structure](#ibc-total-supply-data-structure) for the data to include in each `IBCTotalSuppply` object |
|`transfer_options` |`object` |true |A collection of blockchain networks along with their associated priority numbers, used to establish their order in the transfer options list for deposit and withdrawal forms. |Blockchain network listed here **MUST** match the valid chainName of the bridges listed under BridgeAll RPC call.<br /><br /> To view the values of BridgeAll RPC call, simply run `yarn get-bridges [network]` on the command line. Sample for mainnet: `yarn get-bridges mainnet`|
|`network_fees` |`object` |true |List of token denoms along with their associated priority numbers, used to establish their default order in the network fees preference list. |Token denoms listed here **MUST** match the valid denoms listed under MinGasPriceAll RPC call.<br /><br /> To view the values of MinGasPriceAll RPC call, simply run `yarn get-min-gas-prices [network]` on the command line. Sample for mainnet: `yarn get-min-gas-prices mainnet`|

## IBC total supply Data Structure
|Field |Type |Required |Description |Notes |
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Currently, each JSON file contain the following data on its corresponding networ
- blacklisted pools
- blacklisted tokens
- total supply of IBC fee tokens on Mintscan
- default blockchain transfer option order in deposit/withdrawal forms dropdown
- default network token fee order

More metadata will be added in the future if required by the Demex frontend. Please see below the structure of the JSON file:

Expand Down Expand Up @@ -45,6 +47,18 @@ More metadata will be added in the future if required by the Demex frontend. Ple
}, {
denom: "ibc-token-denom-2",
amount: "1000000000",
}]
}],
"transfer_options": {
"chain_1": 0,
"chain_2": 1,
"chain_3": 2,
...
},
"network_fees": {
"token_denom_1": 0,
"token_denom_2": 1,
"token_denom_3": 2,
...
}
}
```
20 changes: 20 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@
"items": {
"$ref": "#/$defs/ibc_total_supply"
}
},
"transfer_options": {
"type": "object",
"description": "List of blockchain networks and their priority numbers, used to set their order in deposit and withdrawal forms transfer option dropdown",
"patternProperties": {
".*": {
"type": "integer"
}
},
"additionalProperties": false
},
"network_fees": {
"type": "object",
"description": "List of token denoms and their priority numbers, used to set their order in network fee preferences",
"patternProperties": {
".*": {
"type": "integer"
}
},
"additionalProperties": false
}
},
"$defs": {
Expand Down
8 changes: 7 additions & 1 deletion configs/devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
],
"blacklisted_pools": [],
"blacklisted_tokens": [],
"ibc_tokens_total_supply": []
"ibc_tokens_total_supply": [],
"transfer_options": {},
"network_fees": {
"swth": 0,
"usdc": 1,
"eth": 2
}
}
53 changes: 51 additions & 2 deletions configs/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,54 @@
"denom": "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518",
"amount": "600527806000000"
}
]
}
],
"transfer_options": {
"Cosmos Hub": 0,
"Osmosis": 1,
"Evmos": 2,
"Axelar": 3,
"Juno": 4,
"Stride": 5,
"Kujira": 6,
"Terra": 7,
"Comdex": 8,
"Stafihub": 9,
"Persistence Core": 10,
"Stargaze": 11,
"Canto": 12,
"Sommelier": 13,
"Ethereum": 14,
"Arbitrum": 15,
"Polygon": 16,
"OKC": 17,
"Binance Smart Chain": 18,
"Carbon": 19,
"Neo": 20,
"Neo3": 21,
"Zilliqa": 22
},
"network_fees": {
"swth": 0,
"cgt/1": 1,
"usc": 2,
"ibc/A4DB47A9D3CF9A068D454513891B526702455D3EF08FB9EB558C561F9DC2B701": 3,
"ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518": 4,
"ibc/2B58B8C147E8718EECCB3713271DF46DEE8A3A00A27242628604E31C2F370EF5": 5,
"ibc/662914D0C1CEBCB070C68F061D035E8B10A07C79AB286E7342C85F3BE74612C5": 6,
"ibc/3552CECB7BCE1891DB6070D37EC6E954C972B1400141308FCD85FD148BD06DE5": 7,
"ibc/92E974290AF9E2BC3AEEEC35305C8FD76AC5A22A74CF8D91270FDF5A1C41E861": 8,
"ibc/35E771B8682D828173F4B795F6C307780F96DC64D6F914FAE4CC9B4666F66364": 9,
"ibc/07FA7831E1920D0C87C9388F86B0108677F6ED0C9DE7E4063F05ED675192405C": 10,
"ibc/75249A18DEFBEFE55F83B1C70CAD234DF164F174C6BC51682EE92C2C81C18C93": 11,
"ibc/B7864B03E1B9FD4F049243E92ABD691586F682137037A9F3FCA5222815620B3C": 12,
"bnb.1.6.773edb": 13,
"usdc.1.6.53ff75": 14,
"busd.1.6.754a80": 15,
"eth.1.19.c3b805": 16,
"cglp.1.19.1698d3": 17,
"zil.1.18.1a4a06": 18,
"bneo.1.14.e2e5f6": 19,
"eth.1.2.942d87": 20,
"usdc.1.2.343151": 21
}
}
10 changes: 8 additions & 2 deletions configs/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
],
"blacklisted_pools": [],
"blacklisted_tokens": [],
"ibc_tokens_total_supply": []
}
"ibc_tokens_total_supply": [],
"transfer_options": {},
"network_fees": {
"swth": 0,
"usdc": 1,
"eth": 2
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heyyo, for this PR:

  1. You may need to add struct validation into config.schema.json like the rest of the fields.
    Can check out how it's done here

  2. Do update the README.md document with the fields that you added.

  3. Do update JSON Data Structure section under .github/markets/pr_template.md with the definitions of the 2 new fields.

  4. Under scripts/check_configs.ts, think it would be good to add code to validate the 2 new fields:

  • transfer_options
    • Whether or not the blockchain names (i.e. Cosmos Hub/Zilliqa) are valid bridges listed under BridgeAll RPC call
  • network_fees
    • Whether or not the denoms listed (i.e. swth/usdc) are valid denoms listed under MinGasPriceAll RPC call

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"validate": "pajv validate -s config.schema.json -d \"configs/*.json\" --verbose",
"check-configs": "ts-node scripts/check_configs",
"update-total-supply": "ts-node scripts/update_ibc_total_supply",
"upgrade-sdk": "yarn upgrade carbon-js-sdk@latest"
"upgrade-sdk": "yarn upgrade carbon-js-sdk@latest",
"get-bridges": "ts-node scripts/get_all_bridges",
"get-min-gas-prices": "ts-node scripts/get_all_network_fees"
},
"dependencies": {
"@cosmjs/tendermint-rpc": "^0.29.4",
Expand Down
66 changes: 58 additions & 8 deletions scripts/check_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ interface ConfigJSON {
blacklisted_pools: string[];
blacklisted_tokens: string[];
ibc_tokens_total_supply: TotalSupplyItem[]
transfer_options: {
[chainKey: string]: number
},
network_fees: {
[denom: string]: number
},
}

interface InvalidEntry {
Expand All @@ -41,7 +47,7 @@ const outcomeMap: OutcomeMap = {

// check for valid entries (match data to the api query)
function checkValidEntries(data: string[], query: string[]): InvalidEntry {
let invalidEntries : string[] = [];
let invalidEntries: string[] = [];
data.forEach(entry => {
if (!query.includes(entry)) {
invalidEntries.push(entry);
Expand Down Expand Up @@ -75,7 +81,7 @@ function checkDuplicateEntries(data: string[]): DuplicateEntry {

// check for featured markets to ensure that it does not have blacklisted markets
function checkBlacklistedMarkets(featuredMarkets: string[], blacklistedMarkets: string[]): InvalidEntry {
let overlappingMarkets : string[] = [];
let overlappingMarkets: string[] = [];
featuredMarkets.forEach(market => {
if (blacklistedMarkets.includes(market)) {
overlappingMarkets.push(market);
Expand All @@ -91,8 +97,8 @@ function checkBlacklistedMarkets(featuredMarkets: string[], blacklistedMarkets:

async function main() {
for (const net of myArgs) {
let network : CarbonSDK.Network;
switch(net.toLowerCase()) {
let network: CarbonSDK.Network;
switch (net.toLowerCase()) {
case "mainnet":
network = CarbonSDK.Network.MainNet;
break;
Expand Down Expand Up @@ -153,7 +159,7 @@ async function main() {
console.error(`ERROR: ${network}.json has the following duplicated market entries: ${listOfDuplicates}. Please make sure to only input each market once in ${network}`);
outcomeMap[network] = false;
}

const hasDuplicateBlacklistedMarkets = checkDuplicateEntries(jsonData.blacklisted_markets);
if (hasDuplicateBlacklistedMarkets.status && hasDuplicateBlacklistedMarkets.entry) {
let listOfDuplicates: string = hasDuplicateBlacklistedMarkets.entry.join(", ");
Expand All @@ -180,7 +186,7 @@ async function main() {
}
});
const pools: string[] = allPools.pools.map(pool => pool.pool?.id.toString() ?? "");

const hasInvalidPools = checkValidEntries(jsonData.blacklisted_pools, pools);
if (hasInvalidPools.status && hasInvalidPools.entry) {
let listOfInvalidPools: string = hasInvalidPools.entry.join(', ');
Expand Down Expand Up @@ -246,6 +252,50 @@ async function main() {
console.error(`ERROR: ${network}.json has the following duplicated fee token denom entries under ibc_tokens_total_supply field: ${listOfIbcFeeDuplicates}. Please make sure to input each fee token denom only once in ${network}`);
outcomeMap[network] = false;
}

// Checking transfer options
const transferOptionsArr = Object.keys(jsonData.transfer_options)
const bridgesQuery = await sdk.query.coin.BridgeAll({
pagination: {
key: new Uint8Array(),
limit: new Long(10000),
offset: Long.UZERO,
countTotal: true,
reverse: false,
},
})
const bridges = bridgesQuery.bridges
const validTransferOptionChains = bridges.map(bridge => bridge.chainName)
validTransferOptionChains.push('Carbon')

const hasInvalidChains = checkValidEntries(transferOptionsArr, validTransferOptionChains);
if (hasInvalidChains.status && hasInvalidChains.entry) {
let listOfInvalidChains: string = hasInvalidChains.entry.join(', ');
console.error(`ERROR: ${network}.json has the following chain name entries under transfer_options field: ${listOfInvalidChains}. Please make sure to only input valid chain names in ${network}`);
outcomeMap[network] = false;
}

// Checking network fees
const networkFeeDenomOptions = Object.keys(jsonData.network_fees)
const gasPricesQuery = await sdk.query.fee.MinGasPriceAll({
pagination: {
limit: new Long(10000),
offset: new Long(0),
key: new Uint8Array(),
countTotal: true,
reverse: false,
},
})

const minGasPrices = gasPricesQuery.minGasPrices
const validNetworkFeeDenoms = minGasPrices.map(gasPrice => gasPrice.denom)

const hasInvalidFeeDenoms = checkValidEntries(networkFeeDenomOptions, validNetworkFeeDenoms);
if (hasInvalidFeeDenoms.status && hasInvalidFeeDenoms.entry) {
let listOfInvalidFeeDenoms: string = hasInvalidFeeDenoms.entry.join(', ');
console.error(`ERROR: ${network}.json has the following network fee token denoms under network_fees field: ${listOfInvalidFeeDenoms}. Please make sure to only input valid network fee token denoms in ${network}`);
outcomeMap[network] = false;
}
}
}
const outcomeArr = Object.values(outcomeMap);
Expand All @@ -260,5 +310,5 @@ async function main() {
}

main()
.catch(console.error)
.finally(() => process.exit(0));
.catch(console.error)
.finally(() => process.exit(0));
35 changes: 35 additions & 0 deletions scripts/get_all_bridges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { CarbonSDK } from "carbon-js-sdk";
import Long from "long";
const myArgs = process.argv.slice(2);


(async () => {
const net = myArgs[0]
let network: CarbonSDK.Network;
switch (net.toLowerCase()) {
case "mainnet":
network = CarbonSDK.Network.MainNet;
break;
case "testnet":
network = CarbonSDK.Network.TestNet;
break;
case "devnet":
network = CarbonSDK.Network.DevNet;
break;
default:
console.log("ERROR: Invalid network keyed");
process.exit(1);
}

const sdk = await CarbonSDK.instance({ network });
const bridges = await sdk.query.coin.BridgeAll({
pagination: {
key: new Uint8Array(),
limit: new Long(10000),
offset: Long.UZERO,
countTotal: true,
reverse: false,
},
})
console.log(bridges)
})().catch(console.error).finally(() => process.exit(0));
42 changes: 42 additions & 0 deletions scripts/get_all_network_fees.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { CarbonSDK } from "carbon-js-sdk";
import Long from "long";
const myArgs = process.argv.slice(2);


(async () => {
const net = myArgs[0]
let network: CarbonSDK.Network;
if (!net || net === "") {
console.log("ERROR: No network keyed");
process.exit(1);
}

switch (net.toLowerCase()) {
case "mainnet":
network = CarbonSDK.Network.MainNet;
break;
case "testnet":
network = CarbonSDK.Network.TestNet;
break;
case "devnet":
network = CarbonSDK.Network.DevNet;
break;
default:
console.log("ERROR: Invalid network keyed");
process.exit(1);
}

const sdk = await CarbonSDK.instance({ network });
const feeQueryClient = sdk.query.fee
const gasPrices = await feeQueryClient.MinGasPriceAll({
pagination: {
limit: new Long(10000),
offset: new Long(0),
key: new Uint8Array(),
countTotal: true,
reverse: false,
},
})

console.log(gasPrices)
})().catch(console.error).finally(() => process.exit(0));