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

feat: announcement banner on deposit withdraw screens #297

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 15 additions & 8 deletions .github/markets/pr_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Each json file under the [configs](../../configs) folder correspond to their res
|`wswth_contract` |`string` |false |wSWTH ERC-20 contract. |
|`market_banners` |`MarketBanner[]` |true |market banner configs. |
| `native_token_contracts_map` | `object` | false | Map of token denoms to their respective contract addresses on the native chain. | |
| `native_depositor_contracts_map` | `object` | false | Map of axelar connection ids to their respective native depositor contract addresses
| `native_depositor_contracts_map` | `object` | false | Map of axelar connection ids to their respective native depositor contract addresses
|`market_promo` |`MarketPromo` |false |Map of Objects that contains market promo parameters for each market |If the `market_promo` property is omitted, no promo will be shown. The key of each entry is the ids of the market with existing promo. |
|`spot_pool_config` |`SpotPoolConfig` |false |Object that contains the config parameters for the [Spot Pools](https://app.dem.exchange/pools/spot) page on Demex |
|`quick_select_tokens` |`QuickSelectToken[]` |true |List of quick select tokens for deposit and withdrawal forms. |
kylehoang92 marked this conversation as resolved.
Show resolved Hide resolved

|`disabled_transfer_banner_config` |`DisabledTransferBannerConfig` |false |Config parameters for displaying banner to inform users that transfers for the relevant tokens are disabled |
## TransferDisabledTokens Data Structure
|Field |Type |Required |Description |Notes |
|---|---|---|---|---|
Expand Down Expand Up @@ -96,19 +96,19 @@ Each json file under the [configs](../../configs) folder correspond to their res
|---|---|---|---|---|
|`perp_pool_id` |`string` |true |Perp pool id where the banner will be shown. |Perp pool id **MUST** match one of the existing perp pool ids from the PerpPool PoolInfoAll RPC call.<br /><br /> To view the values of PoolInfoAll RPC call, simply run `yarn get-perp-pool-ids [network]` on the command line. Sample for mainnet: `yarn get-perp-pool-ids mainnet` |
|`show_from` |`string` |false |The date and time when the perp pool 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 perp pool 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) |
|`title` |`string` |true |The title shown on the perp pool banner. |
|`show_until` |`string` |false |The date and time when the perp pool 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) |
|`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). |
|`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). |

## 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. |
|`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. |

## MarketPromo Data Structure
Expand Down Expand Up @@ -137,3 +137,10 @@ Each json file under the [configs](../../configs) folder correspond to their res
|---|---|---|---|---|
|`label_denom` |`string` |true |The default token will be show on UI deposit/withdrawal forms |
|`target_denom` |`string` |true |The default token will be use to transfer in deposit/withdrawal |

## TransferBanner Data Structure
Copy link
Collaborator

Choose a reason for hiding this comment

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

TransferBanner => DisabledTransferBannerConfig

|Field |Type |Required |Description |Notes |
|---|---|---|---|---|
|`unsupported_tokens` |`string[]` |false |List of tokens that are no longer supported | 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) |
|`temp_disabled_transfer_tokens` |`object` |false |List of tokens for which deposits and withdrawals have been temporarily disabled | The token denoms listed in this object **MUST** match the token denoms listed under the Carbon [Tokens API](https://api.carbon.network/carbon/coin/v1/tokens?pagination.limit=10000) |
|`temp_disabled_bridges` |`object` |false |List of bridges for which deposits and withdrawals have been temporarily disabled | 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`` |
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ More metadata will be added in the future if required by the Demex frontend. Ple
"baseDenom": "denom_3",
"chainRoutes": ["blockchain_5", "blockchain_6"],
"denomOnCarbon": "carbon_denom_1"
}],
}],
"demex_trading_league_config": {
"promoMarkets": [
"promo_market_1",
Expand All @@ -99,6 +99,21 @@ More metadata will be added in the future if required by the Demex frontend. Ple
],
"currentPrizeSymbol": "market_symbol",
"currentCompPerpPoolId": 1
},
"disabled_transfer_banner_config": {
"unsupported_tokens": ["denom_1", "denom_2"],
"temp_disabled_transfer_tokens": {
"denom_1": {
"start": "",
"end": ""
}
},
"temp_disabled_bridges": {
"bridge_address_1": {
"start": "",
"end": ""
}
}
}
}
```
51 changes: 49 additions & 2 deletions config.schema.json
kylehoang92 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@
},
"start": {
"type": "string",
"description": "The start time of perp pool promo",
"description": "The start time of the relevant program (in timestamp format)",
"pattern": "^\\d{4}(-\\d\\d(-\\d\\d(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?)?)?)?$"
},
"end": {
"type": "string",
"description": "The end time of perp pool promo",
"description": "The end time of the relevant program (in timestamp format)",
"pattern": "^\\d{4}(-\\d\\d(-\\d\\d(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?)?)?)?$"
},
"perpPoolDepositBoost": {
Expand Down Expand Up @@ -584,6 +584,53 @@
"items": {
"$ref": "#/$defs/quick_select_token"
}
},
"disabled_transfer_banner_config": {
"type": "object",
"description": "Config parameters for displaying banner to inform users that transfers for the relevant tokens are disabled",
"properties": {
"unsupported_tokens": {
"type": "array",
"description": "List of tokens are no longer supported",
"items": {
"type": "string"
}
},
"temp_disabled_transfer_tokens": {
"type": "object",
"description": "List of tokens for which deposits and withdrawals have been temporarily disabled",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"start": {
"$ref": "#/$defs/start"
},
"end": {
"$ref": "#/$defs/end"
}
}
}
}
},
"temp_disabled_bridges": {
"type": "object",
"description": "List of bridges for which deposits and withdrawals have been temporarily disabled",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"start": {
"$ref": "#/$defs/start"
},
"end": {
"$ref": "#/$defs/end"
}
}
}
}
sarah-thong marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
2 changes: 1 addition & 1 deletion configs/devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
{
"label_denom": "dai",
"target_denom" : "dai"
"target_denom" : "dai"
}
]
}
102 changes: 98 additions & 4 deletions scripts/check_configs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BlockchainUtils, CarbonSDK } from "carbon-js-sdk";
import { CarbonSDK } from "carbon-js-sdk";
import { PageRequest } from "carbon-js-sdk/lib/codec/cosmos/base/query/v1beta1/pagination";
import { BridgeMap } from "carbon-js-sdk/lib/util/blockchain";
import * as fs from "fs";
import Long from "long";

Expand Down Expand Up @@ -34,6 +35,7 @@ interface ConfigJSON {
market_banners?: MarketBanner[];
market_promo?: {[marketId: string]: MarketPromo};
spot_pool_config?: SpotPoolConfig;
disabled_transfer_banner_config?: DisabledTransferBannerConfig;
announcement_banner: AnnouncementBanner;
quick_select_deposit_options?: QuickSelectToken[];
}
Expand Down Expand Up @@ -134,6 +136,22 @@ interface SpotPoolConfig {
show_apr_tooltip: boolean;
}

interface DisabledTransferBannerConfig {
unsupported_tokens?: [],
temp_disabled_transfer_tokens?: {
[denom: string]: {
start?: string,
end?: string
}
},
temp_disabled_bridges?: {
[bridgeAddress: string]: {
start?: string,
end?: string
}
}
}
kylehoang92 marked this conversation as resolved.
Show resolved Hide resolved

interface AnnouncementBanner {
show_from?: string;
show_until?: string;
Expand Down Expand Up @@ -216,7 +234,7 @@ function joinEntriesIntoStr(entriesArr: string[]): string {
: entriesArr[0];
}

// check list of markets to ensure that it does not have blacklisted markets
// check list of markets to ensure that it does not have blacklisted markets
function checkBlacklistedMarkets(marketData: string[], blacklistedMarkets: string[]): InvalidEntry {
let overlappingMarkets: string[] = [];
marketData.forEach(market => {
Expand Down Expand Up @@ -449,6 +467,67 @@ function isValidMarketPromo(marketPromo: {[marketId: string]: MarketPromo}, netw
return true;
}

function isValidDisabledTransferBannerConfig(transferBanner: DisabledTransferBannerConfig, denoms: string[], bridges: string[], network: CarbonSDK.Network): boolean {
const { unsupported_tokens = [], temp_disabled_transfer_tokens = {}, temp_disabled_bridges = {} } = transferBanner;

if (unsupported_tokens.length > 0) {
const validUnsupportedTokensOutcome = checkValidEntries(unsupported_tokens, denoms);

if (validUnsupportedTokensOutcome.status && isErrorOutcome(validUnsupportedTokensOutcome)) {
const invalidUnsupportedTokensStr = joinEntriesIntoStr(validUnsupportedTokensOutcome.entry!);
console.error(`[ERROR] disabled_transfer_banner_config.unsupported_tokens of ${network}.json has the following invalid token denoms: ${invalidUnsupportedTokensStr}. Please make sure to input only valid token denoms.`);
return false
}
}

const disabledTokenKeys = Object.keys(temp_disabled_transfer_tokens)
if (disabledTokenKeys.length > 0) {
const validDisabledTknsOutcome = checkValidEntries(disabledTokenKeys, denoms);

if (validDisabledTknsOutcome.status && isErrorOutcome(validDisabledTknsOutcome)) {
const invalidDissabedTokensStr = joinEntriesIntoStr(validDisabledTknsOutcome.entry!);
console.error(`[ERROR] disabled_transfer_banner_config.temp_disabled_transfer_tokens of ${network}.json has the following invalid token denoms: ${invalidDissabedTokensStr}. Please make sure to input only valid token denoms.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

invalidDissabedTokensStr => invalidDisabledTokensStr

return false
}

disabledTokenKeys.map((key) => {
const { start, end } = temp_disabled_transfer_tokens[key];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be .forEach(...) instead of .map(...) as you're not returning any array

if (end && start) {
const startTime = new Date(start);
const endTime = new Date(end);
if (endTime < startTime) {
console.error(`ERROR: ${network}.json has an invalid end time (${end}) as it is before start time (${start}) for token denom ${key}.`);
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, think this should be ERROR: disabled_transfer_banner_config.temp_disabled_transfer_tokens on ${network}.json has an invalid end time (${end}) for denom ${key} as it is before start time (${start}).

}
}
});
}

const disabledBridgeKeys = Object.keys(temp_disabled_bridges)
if (disabledBridgeKeys.length > 0) {
const validDisableBridgesOutcome = checkValidEntries(disabledBridgeKeys, bridges);
if (validDisableBridgesOutcome.status && isErrorOutcome(validDisableBridgesOutcome)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

validDisableBridgesOutcome => validDisabledBridgesOutcome

const invalidDissabedBridgesStr = joinEntriesIntoStr(validDisableBridgesOutcome.entry!);
console.error(`[ERROR] disabled_transfer_banner_config.temp_disabled_bridges of ${network}.json has the following invalid bridge addreses: ${invalidDissabedBridgesStr}. Please make sure to input only valid bridge addresses.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

invalidDissabedBridgesStr => invalidDisabledBridgesStr

return false
Copy link
Collaborator

Choose a reason for hiding this comment

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

addreses => addresses

}

disabledBridgeKeys.map((key) => {
const { start, end } = temp_disabled_bridges[key];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be .forEach(...) instead of .map(...) as you're not returning any array

if (start && end) {
const startTime = new Date(start);
const endTime = new Date(end);
if (endTime < startTime) {
console.error(`ERROR: ${network}.json has an invalid end time (${end}) as it is before start time (${start}) for bridge ${key}.`);
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think this should be ERROR: disabled_transfer_banner_config.temp_disabled_bridges on ${network}.json has an invalid end time (${end}) for bridge ${key} as it is before start time (${start}).

}
}
});
}

return true
}

function isValidQuickSelectTokens(quickSelectTokens: QuickSelectToken[], network: CarbonSDK.Network, denoms: string[]): boolean {
const duplicateQuickSelectTokens = checkDuplicateEntries(quickSelectTokens.map(token => token.label_denom));
const invalidQuickSelectTokens = checkValidEntries(quickSelectTokens.map(token => token.label_denom), denoms);
Expand Down Expand Up @@ -596,6 +675,16 @@ async function main() {
outcomeMap[network] = false;
}

// query all bridges
const bridgesMap: BridgeMap | undefined = sdk?.token?.bridges
let bridgesArr: string[] = []

if (bridgesMap && bridgesMap.ibc.length && bridgesMap.polynetwork.length) {
const polynetworkBridges = bridgesMap.polynetwork.map((bridge) => bridge.bridgeAddresses).flat()
const ibcBridges = bridgesMap.ibc.map((bridge) => bridge.bridgeAddresses).flat()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pls remember to check that !!bridge.enabled before mapping (maybe can use a .reduce(...) instead)

sarah-thong marked this conversation as resolved.
Show resolved Hide resolved
bridgesArr = polynetworkBridges.concat(ibcBridges)
Copy link
Collaborator

@sarah-thong sarah-thong Dec 27, 2024

Choose a reason for hiding this comment

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

IBC Bridges have no bridgeAddresses
image

Maybe you can use the IBC channel id instead (i.e. bridge.channels?.src_channel)

sarah-thong marked this conversation as resolved.
Show resolved Hide resolved
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't forget to include axelar bridge addresses as well

sarah-thong marked this conversation as resolved.
Show resolved Hide resolved

// transfer disabled tokens object check
const isTransferDisabledTokensValid = isValidTransferDisabledTokens(jsonData.transfer_disabled_tokens, tokens, network);
if (!isTransferDisabledTokensValid) outcomeMap[network] = false;
Expand Down Expand Up @@ -807,11 +896,11 @@ async function main() {
if(jsonData.market_promo && !isValidMarketPromo(jsonData.market_promo, network, marketIds)) {
outcomeMap[network] = false;
}

if(jsonData.announcement_banner && !isValidAnnouncementBanner(jsonData.announcement_banner, network)) {
outcomeMap[network] = false;
}

// check for spot pool config
if (jsonData.spot_pool_config) {
const spotPoolConfig = jsonData.spot_pool_config
Expand All @@ -835,6 +924,11 @@ async function main() {
if (!isDemexTradingLeagueConfigValid) outcomeMap[network] = false;
}

// transfer banner check
if (jsonData.disabled_transfer_banner_config && !isValidDisabledTransferBannerConfig(jsonData.disabled_transfer_banner_config, tokens, bridgesArr, network)) {
outcomeMap[network] = false;
}

// check for validate quick select tokens
if (jsonData.quick_select_deposit_options && !isValidQuickSelectTokens(jsonData.quick_select_deposit_options, network, tokens)) {
outcomeMap[network] = false;
Expand Down
Loading