Skip to content

Commit

Permalink
Marketplace tokens: configurable minimum volume threshold (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lezek123 authored Nov 7, 2024
1 parent 41bf490 commit 03d4e5c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ARCHIVE_GATEWAY_URL=${CUSTOM_ARCHIVE_GATEWAY_URL:-http://localhost:8888/graphql}
APP_NAME=Gleev
SUPPORT_NO_CATEGORY_VIDEOS=true
SUPPORT_NEW_CATEGORIES=true
CRT_MARKET_CAP_MIN_VOLUME_JOY=100
KILL_SWITCH_ON=false
# 10 seconds
VIDEO_VIEW_PER_USER_TIME_LIMIT=10
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# 4.1.0

## Misc
## Affected components:
- Migrations (`marketplace_tokens` view)
- GraphQL server (`tokensWithPriceChange` and `topSellingToken` queries, `setCrtMarketCapMinVolume` mutation)
- Config: `CRT_MARKET_CAP_MIN_VOLUME_JOY`
- Docker compose

## Changes
- `tokensWithPriceChange`, `marketplaceTokens` and `topSellingToken` queries now only take the currently active AMM sale into account when calculating values such as volume / liquidity / price change.
- `marketplaceTokens` query now takes into account a configurable `CRT_MARKET_CAP_MIN_VOLUME_JOY` value which allows specifying a volume threshold below which tokens are considered to have no market cap.
- added `minVolume` argument to `tokensWithPriceChange` query to allow filtering out tokens w/ negligible volume
- updated docker setup to support the latest docker version

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const { getViewDefinitions } = require('../viewDefinitions')

module.exports = class Views1730895049782 {
name = 'Views1730895049782'
module.exports = class Views1730976542053 {
name = 'Views1730976542053'

async up(db) {
// these two queries will be invoked and the cleaned up by the squid itself
Expand Down
11 changes: 9 additions & 2 deletions db/viewDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ function getViewDefinitions(db) {
${withPriceChange({ periodDays: 30, currentBlock: 'last_block' })}
SELECT
COALESCE(tws.total_liquidity, 0) as liquidity,
(ct.last_price * ct.total_supply) as market_cap,
CASE
WHEN tws.amm_volume >= COALESCE(
market_cap_min_volume_cfg.value::int8,
${parseInt(process.env.CRT_MARKET_CAP_MIN_VOLUME_JOY)}
) THEN (ct.last_price * ct.total_supply)
ELSE 0
END as market_cap,
c.cumulative_revenue,
c.id as channel_id,
COALESCE(tws.amm_volume, 0) as amm_volume,
Expand All @@ -142,7 +148,8 @@ function getViewDefinitions(db) {
LEFT JOIN token_channel tc ON tc.token_id = ct.id
LEFT JOIN channel c ON c.id = tc.channel_id
LEFT JOIN tokens_with_price_change twpc ON twpc.token_id = ct.id
LEFT JOIN tokens_with_stats tws ON tws.token_id = ct.id`,
LEFT JOIN tokens_with_stats tws ON tws.token_id = ct.id
LEFT JOIN "admin"."gateway_config" market_cap_min_volume_cfg ON market_cap_min_volume_cfg.id = 'CRT_MARKET_CAP_MIN_VOLUME_JOY'`,
}
}

Expand Down
1 change: 1 addition & 0 deletions schema/auth.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum OperatorPermission {
RESTORE_CONTENT
SET_PUBLIC_FEED_VIDEOS
SET_FEATURED_CRTS
SET_CRT_MARKETCAP_MIN_VOLUME
}

type User @entity @schema(name: "admin") {
Expand Down
12 changes: 11 additions & 1 deletion src/server-extension/resolvers/AdminResolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
AppActionSignatureInput,
AppRootDomain,
ChannelWeight,
CrtMarketCapMinVolume,
ExcludableContentType,
ExcludeContentArgs,
ExcludeContentResult,
Expand All @@ -51,6 +52,7 @@ import {
SetCategoryFeaturedVideosArgs,
SetCategoryFeaturedVideosResult,
SetChannelsWeightsArgs,
SetCrtMarketCapMinVolume,
SetFeaturedCrtsInput,
SetFeaturedCrtsResult,
SetFeaturedNftsInput,
Expand Down Expand Up @@ -232,6 +234,14 @@ export class AdminResolver {
return results
}

@UseMiddleware(OperatorOnly(OperatorPermission.SET_CRT_MARKETCAP_MIN_VOLUME))
@Mutation(() => CrtMarketCapMinVolume)
async setCrtMarketCapMinVolume(@Args() args: SetCrtMarketCapMinVolume) {
const em = await this.em()
await config.set(ConfigVariable.CrtMarketCapMinVolumeJoy, args.minVolumeJoy, em)
return { minVolumeJoy: await config.get(ConfigVariable.CrtMarketCapMinVolumeJoy, em) }
}

@UseMiddleware(OperatorOnly(OperatorPermission.SET_KILL_SWITCH))
@Mutation(() => KillSwitch)
async setKillSwitch(@Args() args: SetKillSwitchInput): Promise<KillSwitch> {
Expand Down Expand Up @@ -353,7 +363,7 @@ export class AdminResolver {
}
}

@UseMiddleware(OperatorOnly(OperatorPermission.SET_SUPPORTED_CATEGORIES))
@UseMiddleware(OperatorOnly(OperatorPermission.SET_CRT_MARKETCAP_MIN_VOLUME))
@Mutation(() => SetSupportedCategoriesResult)
async setSupportedCategories(
@Args()
Expand Down
12 changes: 12 additions & 0 deletions src/server-extension/resolvers/AdminResolver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ export class ChannelWeight {
isApplied!: boolean
}

@ArgsType()
export class SetCrtMarketCapMinVolume {
@Field(() => Int, { nullable: false })
minVolumeJoy!: number
}

@ObjectType()
export class CrtMarketCapMinVolume {
@Field(() => Int, { nullable: false })
minVolumeJoy!: number
}

@ArgsType()
export class SetKillSwitchInput {
@Field(() => Boolean, { nullable: false })
Expand Down
2 changes: 2 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { withHiddenEntities } from './sql'
export enum ConfigVariable {
SupportNoCategoryVideo = 'SUPPORT_NO_CATEGORY_VIDEOS',
SupportNewCategories = 'SUPPORT_NEW_CATEGORIES',
CrtMarketCapMinVolumeJoy = 'CRT_MARKET_CAP_MIN_VOLUME_JOY',
KillSwitch = 'KILL_SWITCH_ON',
VideoViewPerUserTimeLimit = 'VIDEO_VIEW_PER_USER_TIME_LIMIT',
VideoRelevanceViewsTick = 'VIDEO_RELEVANCE_VIEWS_TICK',
Expand Down Expand Up @@ -49,6 +50,7 @@ const jsonType = <T>() => ({
export const configVariables = {
[ConfigVariable.SupportNoCategoryVideo]: boolType,
[ConfigVariable.SupportNewCategories]: boolType,
[ConfigVariable.CrtMarketCapMinVolumeJoy]: intType,
[ConfigVariable.KillSwitch]: boolType,
[ConfigVariable.VideoViewPerUserTimeLimit]: intType,
[ConfigVariable.VideoRelevanceViewsTick]: intType,
Expand Down

0 comments on commit 03d4e5c

Please sign in to comment.