Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ikprk committed Jul 15, 2024
1 parent e13c03f commit c74b8d2
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 226 deletions.
15 changes: 15 additions & 0 deletions db/migrations/1721051247791-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = class Data1721051247791 {
name = 'Data1721051247791'

async up(db) {
await db.query(`CREATE TABLE "admin"."marketplace_token" ("liquidity" integer, "market_cap" numeric, "cumulative_revenue" numeric, "amm_volume" numeric, "price_change" numeric, "liquidity_change" numeric, "id" character varying NOT NULL, "status" character varying(6) NOT NULL, "avatar" jsonb, "total_supply" numeric NOT NULL, "is_featured" boolean NOT NULL, "symbol" text, "is_invite_only" boolean NOT NULL, "annual_creator_reward_permill" integer NOT NULL, "revenue_share_ratio_permill" integer NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL, "channel_id" text, "description" text, "whitelist_applicant_note" text, "whitelist_applicant_link" text, "accounts_num" integer NOT NULL, "number_of_revenue_share_activations" integer NOT NULL, "deissued" boolean NOT NULL, "current_amm_sale_id" text, "current_sale_id" text, "current_revenue_share_id" text, "number_of_vested_transfer_issued" integer NOT NULL, "last_price" numeric, CONSTRAINT "PK_d836a8c3d907b67099c140c4d84" PRIMARY KEY ("id"))`)
await db.query(`CREATE INDEX "IDX_1268fd020cf195b2e8d5d85093" ON "admin"."marketplace_token" ("symbol") `)
await db.query(`CREATE INDEX "IDX_b99bb1ecee77f23016f6ef687c" ON "admin"."marketplace_token" ("created_at") `)
}

async down(db) {
await db.query(`DROP TABLE "admin"."marketplace_token"`)
await db.query(`DROP INDEX "admin"."IDX_1268fd020cf195b2e8d5d85093"`)
await db.query(`DROP INDEX "admin"."IDX_b99bb1ecee77f23016f6ef687c"`)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

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

module.exports = class Views1719855101957 {
name = 'Views1719855101957'
module.exports = class Views1721051247895 {
name = 'Views1721051247895'

async up(db) {
// these two queries will be invoked and the cleaned up by the squid itself
// these two queries will be invoked and the cleaned up by the squid itself
// we only do this to be able to reference processor height in mappings
await db.query(`
CREATE SCHEMA squid_processor;
CREATE SCHEMA IF NOT EXISTS squid_processor;
`)
await db.query(`CREATE TABLE IF NOT EXISTS squid_processor.status (
id SERIAL PRIMARY KEY,
Expand Down
2 changes: 1 addition & 1 deletion schema/token.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type CreatorToken @entity {
lastPrice: BigInt
}

type MarketplaceToken @entity {
type MarketplaceToken @entity @schema(name: "admin") {
liquidity: Int
marketCap: BigInt
cumulativeRevenue: BigInt
Expand Down
5 changes: 2 additions & 3 deletions src/auth-server/handlers/registerUserInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UserInteractionCount } from '../../model'

import { InMemoryRateLimiter } from 'rolling-rate-limiter'

export const interactionLimiter = new InMemoryRateLimiter({
const interactionLimiter = new InMemoryRateLimiter({
interval: 1000 * 60 * 5, // 5 minutes
maxInInterval: 1,
})
Expand All @@ -28,7 +28,6 @@ export const registerUserInteraction: (
const { authContext: session } = res.locals
const { type, entityId } = req.body

console.log(session)
if (!session) {
throw new UnauthorizedError('Cannot register interactions for empty session')
}
Expand Down Expand Up @@ -58,7 +57,7 @@ export const registerUserInteraction: (
if (!dailyInteractionRow) {
await em.getRepository(UserInteractionCount).save({
id: `${Date.now()}-${entityId}-${type}`,
dayTimestamp: new Date(),
dayTimestamp: new Date(date.setHours(0, 0, 0, 0)),
count: 1,
type,
entityId,
Expand Down
3 changes: 1 addition & 2 deletions src/mappings/token/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ export async function processAmmActivatedEvent({
ammInitPrice: BigInt(intercept),
finalized: false,
})
token.lastPrice =
(amm.ammSlopeParameter * BigInt(token.totalSupply)) / BigInt(2) + amm.ammInitPrice
token.lastPrice = (amm.ammSlopeParameter * token.totalSupply) / BigInt(2) + amm.ammInitPrice
token.currentAmmSaleId = id

const eventEntity = overlay.getRepository(Event).new({
Expand Down
172 changes: 0 additions & 172 deletions src/model/MarketplaceToken.ts

This file was deleted.

26 changes: 15 additions & 11 deletions src/server-extension/resolvers/CreatorToken/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import {
GetShareDividendsResult,
GetShareDividensArgs,
MarketplaceTokensArgs,
CreatorToken as TokenReturnType,
MarketplaceTokensReturnType,
TopSellingTokensReturnType,
MarketplaceTableTokensArgs,
MarketplaceToken,
MarketplaceTokenCount,
MarketplaceTokensCountArgs,
} from './types'
Expand All @@ -26,6 +24,7 @@ import { parseAnyTree, parseSqlArguments } from '@subsquid/openreader/lib/opencr
import { extendClause } from '../../../utils/sql'
import { Context } from '../../check'
import { getCurrentBlockHeight } from '../../../utils/blockHeight'
import { MarketplaceToken, CreatorToken as TokenReturnType } from '../baseTypes'

export const BLOCKS_PER_DAY = 10 * 60 * 24 // 10 blocs per minute, 60 mins * 24 hours

Expand Down Expand Up @@ -80,13 +79,18 @@ export class TokenResolver {
const tokenFields = parseAnyTree(model, 'CreatorToken', info.schema, tokenSubTree)

const topTokensCtes = `
WITH tokens_volumes AS (
SELECT ac.token_id,
WITH tokens_volumes AS (
SELECT
ac.token_id,
SUM(tr.price_paid) as ammVolume
FROM amm_transaction tr
JOIN amm_curve ac ON ac.id = tr.amm_id
WHERE tr.created_in >= ${lastProcessedBlock - args.periodDays * BLOCKS_PER_DAY}
GROUP BY token_id
FROM
amm_transaction tr
JOIN
amm_curve ac ON ac.id = tr.amm_id
WHERE
tr.created_in >= ${lastProcessedBlock - args.periodDays * BLOCKS_PER_DAY}
GROUP BY
token_id
)
`

Expand Down Expand Up @@ -141,7 +145,7 @@ WITH tokens_volumes AS (

const result = await ctx.openreader.executeQuery(listQuery)

return result as TokenReturnType[]
return result as TopSellingTokensReturnType[]
}

@Query(() => [MarketplaceTokensReturnType])
Expand Down Expand Up @@ -325,12 +329,12 @@ END AS percentage_change
offset: args.offset,
})

const videoFields = parseAnyTree(model, 'MarketplaceToken', info.schema, tree)
const marketplaceTokensFields = parseAnyTree(model, 'MarketplaceToken', info.schema, tree)
const listQuery = new ListQuery(
model,
ctx.openreader.dialect,
'MarketplaceToken',
videoFields,
marketplaceTokensFields,
sqlArgs
)

Expand Down
29 changes: 6 additions & 23 deletions src/server-extension/resolvers/CreatorToken/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ArgsType, Field, Float, Int, ObjectType } from 'type-graphql'
import { GraphQLScalarType } from 'graphql'
import {
CreatorToken,
MarketplaceTokenOrderByInput,
MarketplaceTokenWhereInput,
TokenWhereInput,
} from '../baseTypes'

@ArgsType()
export class GetShareDividensArgs {
Expand Down Expand Up @@ -46,11 +51,6 @@ export class GetAccountTransferrableBalanceResult {
transferrableCrtAmount!: number
}

@ObjectType()
export class CreatorToken {
@Field(() => String, { nullable: false }) id!: string
}

@ObjectType()
export class MarketplaceTokensReturnType {
@Field(() => CreatorToken, { nullable: false }) creatorToken!: CreatorToken
Expand All @@ -63,10 +63,6 @@ export class TopSellingTokensReturnType {
@Field(() => String, { nullable: false }) ammVolume!: string
}

export const TokenWhereInput = new GraphQLScalarType({
name: 'CreatorTokenWhereInput',
})

@ArgsType()
export class MarketplaceTokensArgs {
@Field(() => TokenWhereInput, { nullable: true })
Expand All @@ -90,19 +86,6 @@ export class MarketplaceTokensArgs {
orderByPriceDesc: boolean | null
}

export const MarketplaceTokenWhereInput = new GraphQLScalarType({
name: 'MarketplaceTokenWhereInput',
})

export const MarketplaceTokenOrderByInput = new GraphQLScalarType({
name: 'id_ASC',
})

@ObjectType()
export class MarketplaceToken {
@Field(() => String, { nullable: false }) id!: string
}

@ObjectType()
export class MarketplaceTokenCount {
@Field(() => Int, { nullable: false }) count: number
Expand Down
Loading

0 comments on commit c74b8d2

Please sign in to comment.