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 market banners config #248

Merged
merged 4 commits into from
Nov 1, 2024
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
12 changes: 11 additions & 1 deletion .github/markets/pr_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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). |
|`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.<br /><br /> 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.<br /><br /> This field **MUST** follow the valid ISO 8601 format <br /> 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.<br /><br /> This field **MUST** follow the valid ISO 8601 format <br /> 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. |
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
44 changes: 42 additions & 2 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -389,4 +429,4 @@
}
}
}
}
}
11 changes: 10 additions & 1 deletion configs/devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
3 changes: 2 additions & 1 deletion configs/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,6 @@
}
]
},
"wswth_contract": "0x0e59f6Cf81B5Fae9F7a5912062Fe53909e7221C2"
"wswth_contract": "0x0e59f6Cf81B5Fae9F7a5912062Fe53909e7221C2",
"market_banners": []
}
11 changes: 10 additions & 1 deletion configs/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 33 additions & 1 deletion scripts/check_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -100,6 +101,14 @@ interface PerpPoolConfig {
banners: PerpPoolBanner[]
}

interface MarketBanner {
market_id: string;
show_from?: string;
show_until?: string;
content: string;
hideable?: boolean;
}
sarah-thong marked this conversation as resolved.
Show resolved Hide resolved

type OutcomeMap = { [key in CarbonSDK.Network]: boolean }; // true = success, false = failure

const outcomeMap: OutcomeMap = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -596,6 +624,10 @@ async function main() {
}
}

if(jsonData.market_banners && !isValidMarketBanners(jsonData.market_banners, network, marketIds)) {
outcomeMap[network] = false;
}
sarah-thong marked this conversation as resolved.
Show resolved Hide resolved

// external chain channels check
const isExternalChannelsValid = isValidExternalChainChannels(jsonData.external_chain_channels, ibcBridgeNames, network);
if (!isExternalChannelsValid) outcomeMap[network] = false;
Expand Down
33 changes: 33 additions & 0 deletions scripts/get_market_ids.ts
Original file line number Diff line number Diff line change
@@ -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));
Loading