Skip to content

Commit

Permalink
Development to main (#984)
Browse files Browse the repository at this point in the history
* SERVICES1086 rebuild marketplace data/state endpoint, service and functions (part 1)

* SERVICES-1085 extract confusing logic in a separete function; renaming; remove comment

* SERVICES-1085 code splitting, renamings & improvements

* SERVICES-1085 rename param

* SERVICES-1085 add marketplace reindex process event logic

* SERVICES-1085 fix batch slice function; code improvements for get event category function

* SERVICES-1085 remove console log

* SERVICES-1085 extract total bought tokens in a separate function

* SERVICES-1085 split reindex marketplace data code

* SERVICES-1085 use handlers and summary classes for rebuilding marketplace state

* SERVICES-1085 fix marketplace elastic query time range filter

* SERVICES-1085 create MarketplaceReindexState class with common methods and remove common handlers

* SERVICES-1085 add handlers for XOXNO specfic events

* set default paymentNonce if not already set

* SERVICES-1085 ignore not used marketplace events for better performance\

* undo default paymentNonce

* SERVICES-1085 marketplace events summaries

* SERVICES-1085 update marketplace event summaries and add DeadRare updatePrice topics

* SERVICES-1085 marketplace events summary service

* SERVICES-1085 fix marketplace reindex summaries and handle krogan acceptOffer

* SERVICES-1085 marketplace reindex state handlers

* SERVICES-1085 remove confusing method

* SERVICES-1085 remove confusing method

* SERVICES-1085 extract create new order from event summary logic into a separate method

* SERVICES-1085 improve createOrder from summary function

* SERVICES-1085 renamings

* SERVICES-1085 renamings

* SERVICES-1085 update marketplace reindex state service

* SERVICES-1085 process event even if no payment token found

* SERVICES-1085 xoxno user deposit

* SERVICES-1085 fix elrondnftswap offerId type

* SERVICES-1085 reindex marketplace state before & after time range

* SERVICES-1085 reindex marketplace state logs & fixes

* SERVICES-1085 renaming

* SERVICES-1085 fix duplicate bid for internal marketplace

* SERVICES-1085 try-catch and better logging

* SERVICES-1085 fix xoxno no startTime

* SERVICES-1085 fix xoxno no startTime

* SERVICES-1085 fix endAuction with no winning order

* SERVICES-1085 fix case when undefined beforeTimestamp

* SERVICES-1085 save auction tags

* SERVICES-1085 admin endpoints fire and forget

* SERVICES-1085 fix internal auction timestamp topic

* SERVICES-1085 marketplace reindex events locker & logs

* SERVICES-1085 handle multiple internal marketplaces with same address case

* fix admin resolver catch

* SERVICES-1085 exclude collection filtering when unique marketplace address

* SERVICES-1085 fix case when timestamp not spported by DB

* Add plugins module

* Update scam cronjob

* Update scam service

* Add none scam info

* Update workflow

* Update cronjob time

* Remode delete by pattern where not needed

* Fix scam report

* Remove unused code

* trigger cache invalidation

* Change delete to update

* Remove delete by pattern for asset history

* Remove delete by pattern from cache invalidation

* Clear to none nft scam info

* Update scam update cache invalidation

* Add null check

* Add collections with no volum

* Fix trending order by

* Fix trending return

* Fix order trending

* Move blacklist filter before order

* Update filter collection

* Remove clear by pattern in auctions

* Add Scam Collection setting

* Add cache invalidation

* Remove scam info from api

* clean up code

* Upgrade testing packages

* Remove data api calls

* Update mapping

* Refactor Token model

* Add historical price retrieve

* Add elrond tools back

* Add create nft with multiple files

* Extract duplicated code

* Fix typo

* Decrease caching time

* Decrease caching time

* Add ici handling

* Update key

* Update key

* Fix Scam Mapping

* Fix bug for event processing

* Add tickets type on collections

* Add page consts and remove extra pagination

* Remove extra line

* Add isTicket field on asset

* Update redis handler for is ticket

* Add debuging logging

* Fix tickets assets return

* Remove logging

* Update length check

* Update collection length checking

* Fix undefined error

* Allow nullable for role address

---------

Co-authored-by: johnykes <[email protected]>
Co-authored-by: johnykes <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2023
1 parent 1a1d9a1 commit b9e9309
Show file tree
Hide file tree
Showing 127 changed files with 4,506 additions and 1,448 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npm run build --if-present
- run: npm ci
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,4 @@ build.yaml

# PEM file(s)
*.pem
/src/plugins
998 changes: 361 additions & 637 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"description": "Nest TypeScript starter repository",
"license": "MIT",
"scripts": {
"init": "run-script-os",
"init:nix": "rimraf src/plugins && mkdir src/plugins && cp src/plugins.template/plugin.module.ts.template src/plugins/plugin.module.ts",
"prebuild": "rimraf dist",
"build": "nest build && npm run copy-pem",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
Expand Down Expand Up @@ -90,11 +92,11 @@
"devDependencies": {
"@nestjs/cli": "9.2.0",
"@nestjs/schematics": "9.0.4",
"@nestjs/testing": "9.1.4",
"@nestjs/testing": "9.3.12",
"@types/express": "^4.17.11",
"@types/graphql-relay": "^0.6.0",
"@types/jest": "^27.4.1",
"@types/node": "^14.14.36",
"@types/jest": "29.5.0",
"@types/node": "^14.14.42",
"@types/passport-local": "^1.0.33",
"@types/supertest": "^2.0.12",
"@types/tiny-async-pool": "^1.0.0",
Expand All @@ -103,7 +105,7 @@
"eslint": "8.28.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "3.4.1",
"jest": "29.4.2",
"jest": "29.5.0",
"prettier": "^2.2.1",
"supertest": "6.3.3",
"ts-jest": "29.0.5",
Expand Down
21 changes: 20 additions & 1 deletion schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Asset {
identifier: String!
isLiked(byAddress: String!): Boolean
isNsfw: Boolean
isTicket: Boolean
isWhitelistedStorage: Boolean!
likesCount: Int
lowestAuction(filters: MarketplaceFilters): Auction
Expand Down Expand Up @@ -115,12 +116,15 @@ type Asset {

enum AssetActionEnum {
Added
Bid
Bought
ClosedAuction
Created
EndedAuction
PriceUpdated
Received
StartedAuction
Updated
}

type AssetEdge {
Expand Down Expand Up @@ -181,6 +185,7 @@ input AssetsFilter {
"""This will work only with an owner address"""
collections: [String!]
creatorAddress: String
customFilters: CustomFiltersEnum
identifier: String
identifiers: [String!]
likedByAddress: String
Expand Down Expand Up @@ -508,7 +513,7 @@ type CollectionResponse {
}

type CollectionRole {
address: String!
address: String
canAddQuantity: Boolean
canAddUri: Boolean
canBurn: Boolean
Expand Down Expand Up @@ -623,6 +628,10 @@ input CurrentPaymentTokensFilters {
marketplaceKey: String
}

enum CustomFiltersEnum {
Tickets
}

type ExploreCollectionsStats {
activeLast30DaysCount: Int!
allCollectionsCount: Int!
Expand All @@ -645,6 +654,7 @@ type ExploreStats {
enum FeaturedCollectionTypeEnum {
Featured
Hero
Tickets
}

input FeaturedCollectionsArgs {
Expand Down Expand Up @@ -768,6 +778,12 @@ type MarketplacePageInfo {
startCursor: String
}

input MarketplaceReindexDataArgs {
afterTimestamp: Float
beforeTimestamp: Float
marketplaceAddress: String!
}

enum MarketplaceTypeEnum {
External
Internal
Expand Down Expand Up @@ -838,13 +854,15 @@ type Mutation {
clearReportNft(input: ClearReportInput!): Boolean!
createAuction(input: CreateAuctionArgs!): TransactionNode!
createNft(file: Upload!, input: CreateNftArgs!): TransactionNode!
createNftWithMultipleFiles(files: [Upload!]!, input: CreateNftArgs!): TransactionNode!
endAuction(auctionId: Int!): TransactionNode!
flagCollection(input: FlagCollectionInput!): Boolean!
flagNft(input: FlagNftInput!): Boolean!
indexTrandingCollections(forTheLastHours: Float!): Boolean!
issueCampaign(input: IssueCampaignArgs!): TransactionNode!
issueNftCollection(input: IssueCollectionArgs!): TransactionNode!
issueSftCollection(input: IssueCollectionArgs!): TransactionNode!
reindexMarketplaceData(input: MarketplaceReindexDataArgs!): Boolean!
reindexMarketplaceEvents(input: MarketplaceEventsIndexingArgs!): Boolean!
removeBlacklistedCollection(collection: String!): Boolean!
removeFeaturedCollection(input: FeaturedCollectionsArgs!): Boolean!
Expand Down Expand Up @@ -1201,6 +1219,7 @@ type ScamInfo {
}

enum ScamInfoTypeEnum {
none
potentialScam
scam
}
Expand Down
68 changes: 67 additions & 1 deletion src/common/persistence/persistence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class PersistenceService {
private readonly auctionsRepository: AuctionsRepository,
private readonly marketplaceEventsRepository: MarketplaceEventsRepository,
private readonly offersRepository: OffersRepository,
) {}
) { }

private async execute<T>(key: string, action: Promise<T>): Promise<T> {
const profiler = new PerformanceProfiler();
Expand Down Expand Up @@ -338,6 +338,13 @@ export class PersistenceService {
);
}

async getFeaturedCollectionsByIdentifiers(collections: string[]): Promise<FeaturedCollectionEntity[]> {
return await this.execute(
this.getFeaturedCollections.name,
this.featuredCollectionsRepository.getFeaturedCollectionsByIdentifiers(collections),
);
}

async addFeaturedCollection(
collection: string,
type: FeaturedCollectionTypeEnum,
Expand Down Expand Up @@ -729,6 +736,13 @@ export class PersistenceService {
);
}

async saveBulkOrders(orders: OrderEntity[]) {
return await this.execute(
this.saveBulkOrders.name,
this.ordersRepository.saveBulkOrders(orders),
);
}

async updateOrderWithStatus(order: OrderEntity, status: OrderStatusEnum) {
return await this.execute(
this.updateOrderWithStatus.name,
Expand Down Expand Up @@ -878,6 +892,18 @@ export class PersistenceService {
this.auctionsRepository.getBulkAuctions(auctionsIds),
);
}
async getBulkAuctionsByAuctionIdsAndMarketplace(
auctionsIds: number[],
marketplaceKey: string,
): Promise<AuctionEntity[]> {
return await this.execute(
this.getBulkAuctionsByAuctionIdsAndMarketplace.name,
this.auctionsRepository.getBulkAuctionsByAuctionIdsAndMarketplace(
auctionsIds,
marketplaceKey,
),
);
}

async getAuctionByMarketplace(
id: number,
Expand Down Expand Up @@ -918,6 +944,19 @@ export class PersistenceService {
);
}

async getBulkAuctionsByIdentifierAndMarketplace(
identifiers: string[],
marletplaceKey: string,
): Promise<any[]> {
return await this.execute(
this.getBulkAuctionsByIdentifierAndMarketplace.name,
this.auctionsRepository.getBulkAuctionsByIdentifiersAndMarketplace(
identifiers,
marletplaceKey,
),
);
}

async getAvailableTokensForIdentifiers(identifiers: string[]): Promise<any> {
return await this.execute(
this.getAvailableTokensForIdentifiers.name,
Expand Down Expand Up @@ -978,6 +1017,13 @@ export class PersistenceService {
);
}

async saveBulkAuctions(auctions: AuctionEntity[]): Promise<void> {
return await this.execute(
this.saveBulkAuctions.name,
this.auctionsRepository.saveBulkAuctions(auctions),
);
}

async rollbackAuctionAndOrdersByHash(blockHash: string): Promise<any> {
return await this.execute(
this.rollbackAuctionAndOrdersByHash.name,
Expand Down Expand Up @@ -1078,6 +1124,13 @@ export class PersistenceService {
);
}

async saveBulkOffers(offers: OfferEntity[]): Promise<void> {
return await this.execute(
this.saveBulkOffers.name,
this.offersRepository.saveBulkOffers(offers),
);
}

async getOffersThatReachedDeadline(): Promise<OfferEntity[]> {
return await this.execute(
this.getOffersThatReachedDeadline.name,
Expand All @@ -1092,6 +1145,19 @@ export class PersistenceService {
);
}

async getBulkOffersByOfferIdsAndMarketplace(
offerIds: number[],
marketplaceKey: string,
): Promise<OfferEntity[]> {
return await this.execute(
this.getBulkOffersByOfferIdsAndMarketplace.name,
this.offersRepository.getBulkOffersByOfferIdsAndMarketplace(
offerIds,
marketplaceKey,
),
);
}

async getMostLikedAssetsIdentifiers(
offset?: number,
limit?: number,
Expand Down
7 changes: 7 additions & 0 deletions src/common/pluggins/plugin.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Asset } from 'src/modules/assets/models/Asset.dto';

@Injectable()
export class PluginService {
async computeScamInfo(_nft: Asset[]): Promise<void> {}
}
12 changes: 11 additions & 1 deletion src/common/services/caching/entities/cache.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export class CacheInfo {
ttl: 10 * Constants.oneMinute(),
};

static CexTokens: CacheInfo = {
key: 'cexTokens',
ttl: 10 * Constants.oneMinute(),
};

static xExchangeTokens: CacheInfo = {
key: 'xExchangeTokens',
ttl: 10 * Constants.oneMinute(),
};

static AllTokens: CacheInfo = {
key: 'allTokens',
ttl: Constants.oneMinute(),
Expand Down Expand Up @@ -156,7 +166,7 @@ export class CacheInfo {

static AssetHistory: CacheInfo = {
key: 'assetHistory',
ttl: Constants.oneDay(),
ttl: 5 * Constants.oneMinute(),
};

static CollectionTypes: CacheInfo = {
Expand Down
1 change: 0 additions & 1 deletion src/common/services/mx-communication/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './mx-api.service';
export * from './mx-stats.service';
export * from './mx-communication.module';
export * from './mx-tools.service';
export * from './mx-elastic.service';
export * from './mx-identity.service';
export * from './mx-proxy.service';
Expand Down
19 changes: 19 additions & 0 deletions src/common/services/mx-communication/models/account.info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ScamInfo } from 'src/modules/assets/models/ScamInfo.dto';

export class AccountInfo {
address: string = '';
nonce: number = 0;
balance: string = '';
username: string = '';
code: string = '';
codeHash: string | undefined;
rootHash: string = '';
codeMetadata: string = '';
developerReward: string = '';
ownerAddress: string = '';
scamInfo: ScamInfo | undefined = undefined;

constructor(init?: Partial<AccountInfo>) {
Object.assign(this, init);
}
}
23 changes: 23 additions & 0 deletions src/common/services/mx-communication/models/api-token.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export class ApiToken {
identifier: string;
ticker: string;
name: string;
price: string;
decimals: number;

constructor(init?: Partial<ApiToken>) {
Object.assign(this, init);
}
}

export class DexToken {
id: string;
symbol: string;
name: string;
price: string;
decimals: number;

constructor(init?: Partial<DexToken>) {
Object.assign(this, init);
}
}
1 change: 1 addition & 0 deletions src/common/services/mx-communication/models/nft.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Nft {
nonce: number;
royalties: string;
timestamp: number;
url: string;
uris: string[];
tags: string[];
metadata: NftMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface ScamInfoApi {
}

export enum ScamInfoTypeApiEnum {
none = 'none',
scam = 'scam',
potentialScam = 'potentialScam',
}
Loading

0 comments on commit b9e9309

Please sign in to comment.