From e5d44b6a86c7612358f067cf54e82dfe8e77ff8f Mon Sep 17 00:00:00 2001 From: Kornii Date: Thu, 11 Jul 2024 09:50:32 +0100 Subject: [PATCH 1/2] TW-1464 Prepare backend for new native ads (#165) (#166) * TW-1464 Prepare backend for new native ads * TW-1464 Update API documentation * TW-1464 Enable adding native ads in replace-only mode Co-authored-by: Inokentii Mazhara --- src/advertising/external-ads.ts | 8 +++++- src/routers/slise-ad-rules/ad-places.ts | 36 ++++++++++++++++++++++++- src/utils/schemas.ts | 8 +++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/advertising/external-ads.ts b/src/advertising/external-ads.ts index a735339..16328b9 100644 --- a/src/advertising/external-ads.ts +++ b/src/advertising/external-ads.ts @@ -99,6 +99,7 @@ export interface AdPlacesRule extends ExtVersionConstraints { }; stylesOverrides?: AdStylesOverrides[]; shouldHideOriginal?: boolean; + isNative?: boolean; } export interface PermanentAdPlacesRule extends ExtVersionConstraints { @@ -117,9 +118,14 @@ export interface PermanentAdPlacesRule extends ExtVersionConstraints { insertBeforeSelector?: string; insertAfterSelector?: string; insertionsCount?: number; - shouldUseDivWrapper: boolean; + shouldUseDivWrapper?: boolean; + wrapperType?: string; + colsBefore?: number; + colspan?: number; + colsAfter?: number; elementStyle?: Record; divWrapperStyle?: Record; + wrapperStyle?: Record; elementToMeasureSelector?: string; stylesOverrides?: AdStylesOverrides[]; shouldHideOriginal?: boolean; diff --git a/src/routers/slise-ad-rules/ad-places.ts b/src/routers/slise-ad-rules/ad-places.ts index 169fd29..40058d1 100644 --- a/src/routers/slise-ad-rules/ad-places.ts +++ b/src/routers/slise-ad-rules/ad-places.ts @@ -108,6 +108,10 @@ const transformAdPlacesDictionary = (rules: Rec * type: boolean * description: Whether original ads banners should be hidden but not removed * default: false + * isNative: + * type: boolean + * description: Whether the ad is native + * default: false * example: * urlRegexes: * - '^https://goerli\.etherscan\.io/?$' @@ -158,7 +162,6 @@ const transformAdPlacesDictionary = (rules: Rec * - urlRegexes * - adSelector * - parentSelector - * - shouldUseDivWrapper * properties: * urlRegexes: * type: array @@ -233,6 +236,32 @@ const transformAdPlacesDictionary = (rules: Rec * shouldUseDivWrapper: * type: boolean * description: Whether the ads banner should be wrapped in a div + * wrapperType: + * type: string + * enum: + * - div + * - tbody + * colsBefore: + * type: number + * integer: true + * min: 0 + * description: > + * If `wrapperType` is `tbody`, this property describes how many table columns should be inserted before + * the new ads banner. + * colspan: + * type: number + * integer: true + * min: 1 + * description: > + * If `wrapperType` is `tbody`, this property describes how many table columns should be spanned by the + * new ads banner. + * colsAfter: + * type: number + * integer: true + * min: 0 + * description: > + * If `wrapperType` is `tbody`, this property describes how many table columns should be inserted after + * the new ads banner. * elementStyle: * type: object * description: Style of the new ad banner @@ -243,6 +272,11 @@ const transformAdPlacesDictionary = (rules: Rec * description: Style of the div wrapper * additionalProperties: * type: string + * wrapperStyle: + * type: object + * description: Style of the new ad banner's wrapper + * additionalProperties: + * type: string * elementToMeasureSelector: * type: string * description: A selector of the element which should be measured to define banner size diff --git a/src/utils/schemas.ts b/src/utils/schemas.ts index d624f45..1ffb518 100644 --- a/src/utils/schemas.ts +++ b/src/utils/schemas.ts @@ -124,6 +124,7 @@ const adPlacesRulesSchema = arraySchema() .required(), stylesOverrides: arraySchema().of(adStylesOverridesSchema.clone().required()), shouldHideOriginal: booleanSchema(), + isNative: booleanSchema(), extVersion: versionRangeSchema.clone().required() }) .required() @@ -158,9 +159,14 @@ const permanentAdPlacesRulesSchema = arraySchema() insertBeforeSelector: cssSelectorSchema, insertAfterSelector: cssSelectorSchema, insertionsCount: numberSchema().integer().min(1), - shouldUseDivWrapper: booleanSchema().required(), + shouldUseDivWrapper: booleanSchema(), + wrapperType: stringSchema().oneOf(['div', 'tbody']), + colsBefore: numberSchema().integer().min(0), + colspan: numberSchema().integer().min(1), + colsAfter: numberSchema().integer().min(0), elementStyle: styleSchema, divWrapperStyle: styleSchema, + wrapperStyle: styleSchema, elementToMeasureSelector: cssSelectorSchema, stylesOverrides: arraySchema().of(adStylesOverridesSchema.clone().required()), shouldHideOriginal: booleanSchema(), From e95969e9fafcba957e1a73dfd8d1011030415148 Mon Sep 17 00:00:00 2001 From: Kornii Date: Tue, 17 Sep 2024 09:33:10 +0100 Subject: [PATCH 2/2] TW-1537 Add TKEY stats endpoint (#173) (#175) * TW-1537 Add TKEY stats endpoint * TW-1537 Fix linter errors * TW-1537 Fetch incentives, developer rewards and investment fund dynamically --- src/index.ts | 5 +++++ src/tkey-stats.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/tkey-stats.ts diff --git a/src/index.ts b/src/index.ts index 66a1771..35f8f26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,7 @@ import { getPlatforms } from './notifications/utils/get-platforms.util'; import { redisClient } from './redis'; import { evmRouter } from './routers/evm'; import { adRulesRouter } from './routers/slise-ad-rules'; +import { getTkeyStats } from './tkey-stats'; import { getABData } from './utils/ab-test'; import { cancelAliceBobOrder } from './utils/alice-bob/cancel-alice-bob-order'; import { createAliceBobOrder } from './utils/alice-bob/create-alice-bob-order'; @@ -105,6 +106,10 @@ app.get('/api/top-coins', (_req, res) => { res.status(200).send(coinGeckoTokens); }); +app.get('/api/tkey', async (_req, res) => { + res.send(await getTkeyStats()); +}); + app.get('/api/notifications', async (_req, res) => { try { const { platform, startFromTime } = _req.query; diff --git a/src/tkey-stats.ts b/src/tkey-stats.ts new file mode 100644 index 0000000..bbcc38c --- /dev/null +++ b/src/tkey-stats.ts @@ -0,0 +1,52 @@ +import axios from 'axios'; +import memoizee from 'memoizee'; + +const BURN_ADDRESS = 'tz1burnburnburnburnburnburnburjAYjjX'; +const INCENTIVES_ADDRESS = 'tz1Ntpk55Q6AVJHVrCs1uN4HyTTxBbVMFZcb'; +const INVESTMENT_ADDRESS = 'tz1imUX3aTc4HX6KygaQUe8e1sQqYvGs6eCF'; +const DEVELOPER_REWARDS_ADDRESS = 'tz1bxHEHAtKubVy44vBDFVEZ1iqYPYdJVS9U'; +const CONTRACT = 'KT1VaEsVNiBoA56eToEK6n6BcPgh1tdx9eXi'; +const DECIMALS = 18n; +const TOTAL_SUPPLY = 14_000_000_000_000_000_000_000_000n; +const TOTAL_SUPPLY_WITH_DECIMALS = TOTAL_SUPPLY / 10n ** DECIMALS; + +const getTkeyBalance = memoizee( + async (holder: string) => { + const response = await axios.get( + `https://api.tzkt.io/v1/tokens/balances?account=${holder}&token.contract=${CONTRACT}` + ); + + return BigInt(response.data[0].balance) / 10n ** DECIMALS; + }, + { + maxAge: 1000 * 60 * 60 // 1 hour + } +); + +const getBurnedTokens = () => getTkeyBalance(BURN_ADDRESS); +const getInvestmentFund = () => getTkeyBalance(INVESTMENT_ADDRESS); +const getIncentivesFund = () => getTkeyBalance(INCENTIVES_ADDRESS); +const getDeveloperRewardsFund = () => getTkeyBalance(DEVELOPER_REWARDS_ADDRESS); + +export const getTkeyStats = memoizee( + async () => { + const burned = await getBurnedTokens(); + const incentives = await getIncentivesFund(); + const investment = await getInvestmentFund(); + const developerRewards = await getDeveloperRewardsFund(); + + const circulating = TOTAL_SUPPLY_WITH_DECIMALS - incentives - developerRewards - investment - burned; + + return { + incentivesFund: incentives.toString(), + investmentFund: investment.toString(), + developerRewardsFund: developerRewards.toString(), + totalSupply: TOTAL_SUPPLY_WITH_DECIMALS.toString(), + circulating: circulating.toString(), + burned: burned.toString() + }; + }, + { + maxAge: 1000 * 60 * 60 // 1 hour + } +); diff --git a/tsconfig.json b/tsconfig.json index 87d512f..aa0ae21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { /* Basic Options */ - "target": "ES2019", + "target": "ES2020", "module": "commonjs", "lib": ["esnext"], "allowJs": true,