diff --git a/.github/markets/pr_template.md b/.github/markets/pr_template.md index 3e120b5..d7a8a3a 100644 --- a/.github/markets/pr_template.md +++ b/.github/markets/pr_template.md @@ -22,6 +22,7 @@ Each json file under the [configs](../../configs) folder correspond to their res |`demex_trading_league_config` |`DemexTradingLeagueConfig` |false |Object that contains the parameters for the current trading league. | |`perp_pools` |`PerpPoolConfig` |false |Object that contains the configs for Perp Pools | |`wswth_contract` |`string` |false |wSWTH ERC-20 contract. | +|`market_banners` |`MarketBanner[]` |true |market banner configs. | ## Maintenance Data Structure |Field |Type |Required |Description |Notes | @@ -85,4 +86,13 @@ Each json file under the [configs](../../configs) folder correspond to their res |`title` |`string` |true |The title shown on the perp pool banner. | |`removed_markets` |`string` |false |The message describing markets being removed, shown below the perp-pool banner title. | e.g. "BTCETH Perp will be removed on 6 Mar, 09:00AM UTC". If the field is omitted, no message describing markets being removed will be shown. | |`added_markets` |`string` |false |The message describing markets being added, shown below the markets being removed (if any). | e.g. "ATOM Perp & SOL Perp will be added on 8 Mar, 12:00AM UTC". If the field is omitted, no message describing markets being added will be shown. | -|`subtext` |`string` |false |The subtext shown on the perp pool banner (below the removed and added market descriptions). | \ No newline at end of file +|`subtext` |`string` |false |The subtext shown on the perp pool banner (below the removed and added market descriptions). | + +## MarketBanner +|Field |Type |Required |Description |Notes | +|---|---|---|---|---| +|`market_id` |`string` |true |Market id where the banner will be shown. |Market id **MUST** match one of the existing market ids from the Market MarketAll RPC call.

To view the values of MarketAll RPC call, simply run `yarn get-market-ids [network]` on the command line. Sample for mainnet: `yarn get-market-ids mainnet` | +|`show_from` |`string` |false |The date and time when the market banner is scheduled to begin displaying. |If not provided, the banner will be shown immediately.

This field **MUST** follow the valid ISO 8601 format
e.g. *2024-01-23T09:00+00:00* (23 Jan 2024, 9am UTC) | +|`show_until` |`string` |false |The date and time when the market banner is scheduled to stop displaying. |If not provided, the banner will continue to display indefinitely.

This field **MUST** follow the valid ISO 8601 format
e.g. *2024-01-23T09:00+00:00* (23 Jan 2024, 9am UTC) | +|`content` |`string` |true |The content shown on the market banner. | +|`hideable` |`boolean` |false |Indicates if user can hide the banner by clicking on the close button |If set to `false`, the close button will not be rendered on the banner, and user will not be able to dismiss the banner. | \ No newline at end of file diff --git a/README.md b/README.md index 5c0d065..840b05c 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Additionally, the JSON file for mainnet contains the following data to support o - config for the Demex Trading League competition - perp pool promotion parameters - typeform survey parameters +- market banner parameters for information banners to be displayed on the TradingView charts on Trade UI More metadata will be added in the future if required by the Demex frontend. Please see below the structure of the JSON file: diff --git a/config.schema.json b/config.schema.json index 3fde81f..eca36e9 100644 --- a/config.schema.json +++ b/config.schema.json @@ -221,6 +221,34 @@ "type": "string", "description": "ERC-20 contract for wrapped SWTH" }, + "market_banners": { + "type": "array", + "description": "List of banner information to be displayed over the TradingView chart for the required market", + "items": { + "type": "object", + "required": [ + "market_id", + "content" + ], + "properties": { + "market_id": { + "$ref": "#/$defs/market_id" + }, + "show_from": { + "$ref": "#/$defs/show_from" + }, + "show_until": { + "$ref": "#/$defs/show_until" + }, + "content": { + "$ref": "#/$defs/content" + }, + "hideable": { + "$ref": "#/$defs/hideable" + } + } + } + }, "$defs": { "prelaunch_market": { "type": "string", @@ -279,7 +307,7 @@ "type": "string", "description": "The message shown on the banner describing markets being added" }, - "subtext": { + "subtext": { "type": "string", "description": "The subtext shown on the banner" }, @@ -310,6 +338,18 @@ "description": "The end time of the tyepform survey", "pattern": "^\\d{4}(-\\d\\d(-\\d\\d(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?)?)?)?$" }, + "market_id": { + "type": "string", + "description": "Market id (type: string)" + }, + "hideable": { + "type": "boolean", + "description": "Whether the banner can be hidden by the user" + }, + "content": { + "type": "string", + "description": "The content shown on the banner, we can render hyperlink in the content eg: You can visit [here](url)" + }, "additional_ibc_token_info": { "type": "object", "description": "Information for token that (1) is not added on Carbon blockchain or (2) requires packet forwarding.", @@ -389,4 +429,4 @@ } } } -} +} \ No newline at end of file diff --git a/configs/devnet.json b/configs/devnet.json index 9fd6f97..99f2321 100644 --- a/configs/devnet.json +++ b/configs/devnet.json @@ -28,5 +28,14 @@ }, "cross_selling_source_tokens": [], "external_chain_channels": {}, - "additional_ibc_token_config": [] + "additional_ibc_token_config": [], + "market_banners": [ + { + "market_id": "swth_dai", + "show_from": "2024-09-30T08:00+00:00", + "show_until": "2024-10-30T08:00+00:00", + "content": "Hello World", + "hideable": true + } + ] } \ No newline at end of file diff --git a/configs/mainnet.json b/configs/mainnet.json index a68c48c..552215d 100644 --- a/configs/mainnet.json +++ b/configs/mainnet.json @@ -402,5 +402,6 @@ } ] }, - "wswth_contract": "0x0e59f6Cf81B5Fae9F7a5912062Fe53909e7221C2" + "wswth_contract": "0x0e59f6Cf81B5Fae9F7a5912062Fe53909e7221C2", + "market_banners": [] } diff --git a/configs/testnet.json b/configs/testnet.json index 44074d6..dcd40f9 100644 --- a/configs/testnet.json +++ b/configs/testnet.json @@ -39,5 +39,14 @@ }, "banners": [] }, - "wswth_contract": "0xb4A23b09eBBA7dbA01A7bF95EFd41b3600fF22F9" + "wswth_contract": "0xb4A23b09eBBA7dbA01A7bF95EFd41b3600fF22F9", + "market_banners": [ + { + "market_id": "cmkt/2", + "show_from": "2024-09-30T08:00+00:00", + "show_until": "2024-10-30T08:00+00:00", + "content": "Hello World", + "hideable": true + } + ] } diff --git a/package.json b/package.json index ae79c43..67d22c4 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "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", - "get-perp-pool-ids": "ts-node scripts/get_perp_pool_ids" + "get-perp-pool-ids": "ts-node scripts/get_perp_pool_ids", + "get-market-ids": "ts-node scripts/get_market_ids" }, "dependencies": { "@cosmjs/tendermint-rpc": "~0.31.3", diff --git a/scripts/check_configs.ts b/scripts/check_configs.ts index 2d1c507..12fba2e 100644 --- a/scripts/check_configs.ts +++ b/scripts/check_configs.ts @@ -28,7 +28,8 @@ interface ConfigJSON { additional_ibc_token_config: AdditionalIbcTokenConfigItem[]; demex_trading_league_config?: DemexTradingLeagueConfig; perp_pools: PerpPoolConfig; - wswth_contract?: string + wswth_contract?: string; + market_banners?: MarketBanner[]; } interface InvalidEntry { @@ -100,6 +101,14 @@ interface PerpPoolConfig { banners: PerpPoolBanner[] } +interface MarketBanner { + market_id: string; + show_from?: string; + show_until?: string; + content: string; + hideable?: boolean; +} + type OutcomeMap = { [key in CarbonSDK.Network]: boolean }; // true = success, false = failure const outcomeMap: OutcomeMap = { @@ -280,6 +289,25 @@ function isValidDemexTradingLeagueConfig( return true; } +function isValidMarketBanners(marketBanners: MarketBanner[], network: CarbonSDK.Network, marketIds: string[]): boolean { + const marketBannerIds = marketBanners.map((banner) => banner.market_id); + const hasInvalidMarketBannerIds = checkValidEntries(marketBannerIds, marketIds); + const hasDuplicateMarketBannerIds = checkDuplicateEntries(marketBannerIds); + + if (hasInvalidMarketBannerIds.status && hasInvalidMarketBannerIds.entry) { + let listOfInvalidIds: string = hasInvalidMarketBannerIds.entry.join(", "); + console.error(`ERROR: ${network}.json has the following invalid market ids under the market_banners field: ${listOfInvalidIds}`); + return false; + } + + if (hasDuplicateMarketBannerIds.status && hasDuplicateMarketBannerIds.entry) { + let listOfDuplicates: string = hasDuplicateMarketBannerIds.entry.join(", "); + console.error(`ERROR: ${network}.json has duplicated market banners for the following market ids: ${listOfDuplicates}. Please make sure to add only 1 market banner for each market id in ${network}.json`); + return false; + } + return true; +} + async function main() { for (const net of myArgs) { let network: CarbonSDK.Network; @@ -596,6 +624,10 @@ async function main() { } } + if(jsonData.market_banners && !isValidMarketBanners(jsonData.market_banners, network, marketIds)) { + outcomeMap[network] = false; + } + // external chain channels check const isExternalChannelsValid = isValidExternalChainChannels(jsonData.external_chain_channels, ibcBridgeNames, network); if (!isExternalChannelsValid) outcomeMap[network] = false; diff --git a/scripts/get_market_ids.ts b/scripts/get_market_ids.ts new file mode 100644 index 0000000..904e8ea --- /dev/null +++ b/scripts/get_market_ids.ts @@ -0,0 +1,33 @@ +import { CarbonSDK } from "carbon-js-sdk"; +import { PageRequest } from "carbon-js-sdk/lib/codec/cosmos/base/query/v1beta1/pagination"; +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 pools = await sdk.query.market.MarketAll({ + pagination: PageRequest.fromPartial({ + limit: new Long(10000), + }), + }) + const marketIds = pools.markets.map((m) => m.id.toString()) + + console.log(marketIds) +})().catch(console.error).finally(() => process.exit(0));