diff --git a/schema.gql b/schema.gql index b36c9ab72..2529f0127 100644 --- a/schema.gql +++ b/schema.gql @@ -352,12 +352,6 @@ input BuySftActionArgs { quantity: String } -input BuyTicketsArgs { - collectionIdentifier: String! - price: String! - ticketsNumber: Int! -} - type Campaign { availableNfts: Int! campaignId: ID! @@ -426,10 +420,6 @@ input ChildFilter { values: [String!]! } -input ClaimTicketsArgs { - collectionIdentifier: String! -} - input ClearReportCollectionInput { collectionIdentifier: String! } @@ -971,8 +961,6 @@ type Mutation { burnQuantity(input: HandleQuantityArgs!): TransactionNode! buyRandomNft(input: BuyRandomNftActionArgs!): TransactionNode! buySft(input: BuySftActionArgs!): TransactionNode! - buyTickets(input: BuyTicketsArgs!): TransactionNode! - claimTicket(input: ClaimTicketsArgs!): TransactionNode! clearCollectionScamInfo(collection: String!): Boolean! clearNftScamInfo(identifier: String!): Boolean! clearReportCollection(input: ClearReportCollectionInput!): Boolean! @@ -1240,36 +1228,6 @@ type PriceRange { minBid: Price! } -type PrimarySale { - collectionIdentifier: ID - frozen: Boolean - maxUnitsPerWallet: Int! - paymentToken: String! - price: String - saleTime: PrimarySaleTime! - status: PrimarySaleStatusEnum! -} - -input PrimarySaleFilter { - collectionName: String! -} - -enum PrimarySaleStatusEnum { - BetweenPeriod - ClaimPeriod - EndedPeriod - NonePeriod - NotStarted - SalePeriod -} - -type PrimarySaleTime { - endClaim: Int - endSale: Int! - startClaim: Int - startSale: Int! -} - enum Privacy { private public @@ -1308,17 +1266,13 @@ type Query { featuredCollections(filters: FeaturedCollectionsFilter, pagination: ConnectionArgs): CollectionResponse! featuredNfts(pagination: ConnectionArgs): AssetsResponse! generalAnalytics(input: AnalyticsInput): GeneralAnalyticsModel! - hasClaimedTickets(collectionIdentifier: String!): Boolean! - isWhitelisted: WhitelistedInfo! marketplaces(filters: MarketplaceFilters, pagination: ConnectionArgs): MarketplacesResponse! myClaimableAuctions(filters: MyClaimableAuctionsFilters, pagination: ConnectionArgs): AuctionResponse! - myTickets(collectionIdentifier: String!): [TicketInfo!]! notifications(filters: NotificationsFilters, pagination: ConnectionArgs): NotificationsResponse! offers(filters: OffersFilters, pagination: ConnectionArgs): OffersResponse! orders(filters: FiltersExpression, pagination: ConnectionArgs, sorting: [Sorting!]): OrdersResponse! owners(filters: OwnersFilters!, pagination: ConnectionArgs): OwnerResponse! priceRange(filters: TokenFilter): PriceRange! - primarySale(filters: PrimarySaleFilter!): PrimarySale! search(filters: SearchFilter!): SearchResponse! tags(filters: TagsFilter!, pagination: ConnectionArgs): TagsResponse! trendingAssets: [Asset!]! @@ -1448,12 +1402,6 @@ type TagsResponse { pageInfo: TagPageInfo } -type TicketInfo { - buyer: String! - ticketNumber: Int! - winningNonce: String! -} - type Tier { availableNfts: Int! campaignId: ID! @@ -1592,9 +1540,4 @@ input WhitelistMarketplaceArgs { input WhitelistMinterArgs { address: String! adminAddress: String! -} - -type WhitelistedInfo { - isWhitelisted: Boolean! - message: String } \ No newline at end of file diff --git a/src/abis/primary-sales-sc.abi.json b/src/abis/primary-sales-sc.abi.json deleted file mode 100644 index 8b4536ea6..000000000 --- a/src/abis/primary-sales-sc.abi.json +++ /dev/null @@ -1,768 +0,0 @@ -{ - "buildInfo": { - "rustc": { - "version": "1.66.0-nightly", - "commitHash": "a24a020e6d926dffe6b472fc647978f92269504e", - "commitDate": "2022-10-18", - "channel": "Nightly", - "short": "rustc 1.66.0-nightly (a24a020e6 2022-10-18)" - }, - "contractCrate": { - "name": "primary-sales-sc", - "version": "0.0.0", - "git_version": "6a13673" - }, - "framework": { - "name": "elrond-wasm", - "version": "0.33.1" - } - }, - "name": "Sales", - "constructor": { - "inputs": [ - { - "name": "payment_token", - "type": "EgldOrEsdtTokenIdentifier" - } - ], - "outputs": [] - }, - "endpoints": [ - { - "name": "add_nfts", - "mutability": "mutable", - "payableInTokens": ["*"], - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "frozen", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "bool" - } - ] - }, - { - "name": "admin", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "Address" - } - ] - }, - { - "name": "worker", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "Address" - } - ] - }, - { - "name": "manager", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "Address" - } - ] - }, - { - "name": "valid_nft_collections", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "variadic", - "multi_result": true - } - ] - }, - { - "name": "price", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "BigUint" - } - ] - }, - { - "name": "max_units_per_wallet", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "u32" - } - ] - }, - { - "name": "max_nfts", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "u32" - } - ] - }, - { - "name": "num_total_nfts", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "u32" - } - ] - }, - { - "name": "sc_nft_creator", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "Address" - } - ] - }, - { - "name": "payment_token", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "EgldOrEsdtTokenIdentifier" - } - ] - }, - { - "name": "buyer_users", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "variadic
", - "multi_result": true - } - ] - }, - { - "name": "ticket_queues_info", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "index", - "type": "u32" - } - ], - "outputs": [ - { - "type": "variadic", - "multi_result": true - } - ] - }, - { - "name": "timestamps", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "Timestamps" - } - ] - }, - { - "name": "current_token", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "TokenIdentifier" - } - ] - }, - { - "name": "funds_wallet", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "Address" - } - ] - }, - { - "name": "withdraw_wallet", - "mutability": "readonly", - "inputs": [], - "outputs": [ - { - "type": "Address" - } - ] - }, - { - "name": "claimers", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "variadic
", - "multi_result": true - } - ] - }, - { - "name": "all_tickets", - "mutability": "readonly", - "inputs": [ - { - "name": "caller", - "type": "Address" - }, - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "List" - } - ] - }, - { - "name": "payback", - "mutability": "readonly", - "inputs": [ - { - "name": "caller", - "type": "Address" - }, - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "BigUint" - } - ] - }, - { - "name": "freeze", - "mutability": "mutable", - "inputs": [], - "outputs": [] - }, - { - "name": "unfreeze", - "onlyOwner": true, - "mutability": "mutable", - "inputs": [], - "outputs": [] - }, - { - "name": "set_admin", - "onlyOwner": true, - "mutability": "mutable", - "inputs": [ - { - "name": "address", - "type": "Address" - } - ], - "outputs": [] - }, - { - "name": "set_worker", - "onlyOwner": true, - "mutability": "mutable", - "inputs": [ - { - "name": "address", - "type": "Address" - } - ], - "outputs": [] - }, - { - "name": "set_manager", - "onlyOwner": true, - "mutability": "mutable", - "inputs": [ - { - "name": "address", - "type": "Address" - } - ], - "outputs": [] - }, - { - "name": "set_sc_nft_creator", - "mutability": "mutable", - "inputs": [ - { - "name": "new_address", - "type": "Address" - } - ], - "outputs": [] - }, - { - "name": "set_sc_whitelist", - "mutability": "mutable", - "inputs": [ - { - "name": "new_address", - "type": "Address" - } - ], - "outputs": [] - }, - { - "name": "add_valid_nft_collection", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "remove_valid_nft_collection", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "set_price", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "amount", - "type": "BigUint" - } - ], - "outputs": [] - }, - { - "name": "set_max_units_per_wallet", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "max", - "type": "u32" - } - ], - "outputs": [] - }, - { - "name": "set_max_nfts", - "mutability": "mutable", - "inputs": [ - { - "name": "max", - "type": "u32" - } - ], - "outputs": [] - }, - { - "name": "configure_collection_for_sale", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "price", - "type": "BigUint" - }, - { - "name": "max_units_per_wallet", - "type": "u32" - } - ], - "outputs": [] - }, - { - "name": "set_funds_wallet", - "mutability": "mutable", - "inputs": [ - { - "name": "wallet_address", - "type": "Address" - } - ], - "outputs": [] - }, - { - "name": "set_withdraw_wallet", - "mutability": "mutable", - "inputs": [ - { - "name": "wallet_address", - "type": "Address" - } - ], - "outputs": [] - }, - { - "name": "set_current_token", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "buy_tickets", - "mutability": "mutable", - "payableInTokens": ["*"], - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "num", - "type": "u32" - } - ], - "outputs": [] - }, - { - "name": "buyers", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "variadic>", - "multi_result": true - } - ] - }, - { - "name": "my_tickets", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "user_address", - "type": "Address" - } - ], - "outputs": [ - { - "type": "variadic", - "multi_result": true - } - ] - }, - { - "name": "withdraw_funds", - "mutability": "mutable", - "inputs": [], - "outputs": [] - }, - { - "name": "withdraw_nfts", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "fair_distribution", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "available_nonces", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "u32" - } - ] - }, - { - "name": "claim", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "airdrop_unclaimed", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [] - }, - { - "name": "set_sale_timestamps", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "start_sale", - "type": "u64" - }, - { - "name": "end_sale", - "type": "u64" - }, - { - "name": "start_claim", - "type": "u64" - }, - { - "name": "end_claim", - "type": "u64" - } - ], - "outputs": [] - }, - { - "name": "set_sale_start", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "start_sale", - "type": "u64" - } - ], - "outputs": [] - }, - { - "name": "set_sale_end", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "end_sale", - "type": "u64" - } - ], - "outputs": [] - }, - { - "name": "set_claim_start", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "start_claim", - "type": "u64" - } - ], - "outputs": [] - }, - { - "name": "set_claim_end", - "mutability": "mutable", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - }, - { - "name": "end_claim", - "type": "u64" - } - ], - "outputs": [] - }, - { - "name": "status", - "mutability": "readonly", - "inputs": [ - { - "name": "nft_collection", - "type": "TokenIdentifier" - } - ], - "outputs": [ - { - "type": "Status" - } - ] - } - ], - "events": [], - "hasCallback": false, - "types": { - "Status": { - "type": "enum", - "variants": [ - { - "name": "ClaimPeriod", - "discriminant": 0 - }, - { - "name": "SalePeriod", - "discriminant": 1 - }, - { - "name": "NonePeriod", - "discriminant": 2 - } - ] - }, - "TicketInfo": { - "type": "struct", - "fields": [ - { - "name": "buyer", - "type": "Address" - }, - { - "name": "ticket_number", - "type": "u32" - }, - { - "name": "winner_nonce", - "type": "u64" - }, - { - "name": "price", - "type": "BigUint" - } - ] - }, - "Timestamps": { - "type": "struct", - "fields": [ - { - "name": "start_sale", - "type": "u64" - }, - { - "name": "end_sale", - "type": "u64" - }, - { - "name": "start_claim", - "type": "u64" - }, - { - "name": "end_claim", - "type": "u64" - } - ] - } - } -} diff --git a/src/app.module.ts b/src/app.module.ts index 86a275f7a..029b3054a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -31,7 +31,6 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { MarketplacesModuleGraph } from './modules/marketplaces/marketplaces.module'; import { ArtistsModuleGraph } from './modules/artists/artists.module'; import { ExploreStatsModuleGraph } from './modules/explore-stats/explore-stats.module'; -import { PrimarySaleModuleGraph } from './modules/primary-sale-sc/primary-sale.module'; import { ScamModule } from './modules/scam/scam.module'; import { ComplexityPlugin } from './modules/common/complexity.plugin'; import { BlacklistedCollectionsModule } from './modules/blacklist/blacklisted-collections.module'; @@ -96,7 +95,6 @@ import { MintersModuleGraph } from './modules/minters/minters.module'; MarketplacesModuleGraph, ArtistsModuleGraph, ExploreStatsModuleGraph, - PrimarySaleModuleGraph, TimescaleDbModule, MintersModuleGraph, ], diff --git a/src/modules/primary-sale-sc/models/BuyTicketArgs.ts b/src/modules/primary-sale-sc/models/BuyTicketArgs.ts deleted file mode 100644 index c3532759f..000000000 --- a/src/modules/primary-sale-sc/models/BuyTicketArgs.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Field, InputType, Int } from '@nestjs/graphql'; -import { Matches } from 'class-validator'; -import { COLLECTION_IDENTIFIER_ERROR, COLLECTION_IDENTIFIER_RGX, NUMERIC_ERROR, NUMERIC_RGX } from 'src/utils/constants'; - -@InputType() -export class BuyTicketsArgs { - @Field(() => String) - @Matches(RegExp(COLLECTION_IDENTIFIER_RGX), { - message: COLLECTION_IDENTIFIER_ERROR, - }) - collectionIdentifier: string; - @Field(() => Int) - ticketsNumber: number; - - @Field(() => String) - @Matches(RegExp(NUMERIC_RGX), { message: `Price ${NUMERIC_ERROR}` }) - price: string; -} diff --git a/src/modules/primary-sale-sc/models/ClaimTicketArgs.ts b/src/modules/primary-sale-sc/models/ClaimTicketArgs.ts deleted file mode 100644 index 36cfb04da..000000000 --- a/src/modules/primary-sale-sc/models/ClaimTicketArgs.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Field, InputType } from '@nestjs/graphql'; -import { Matches, MaxLength, MinLength } from 'class-validator'; -import { COLLECTION_IDENTIFIER_RGX, COLLECTION_IDENTIFIER_ERROR } from 'src/utils/constants'; - -@InputType() -export class ClaimTicketsArgs { - @Field(() => String) - @Matches(RegExp(COLLECTION_IDENTIFIER_RGX), { - message: COLLECTION_IDENTIFIER_ERROR, - }) - collectionIdentifier: string; -} diff --git a/src/modules/primary-sale-sc/models/Primary-sale.Filter.ts b/src/modules/primary-sale-sc/models/Primary-sale.Filter.ts deleted file mode 100644 index cf7d49d5d..000000000 --- a/src/modules/primary-sale-sc/models/Primary-sale.Filter.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Field, InputType } from '@nestjs/graphql'; -import { Matches } from 'class-validator'; -import { COLLECTION_IDENTIFIER_ERROR, COLLECTION_IDENTIFIER_RGX } from 'src/utils/constants'; - -@InputType() -export class PrimarySaleFilter { - @Field(() => String) - @Matches(RegExp(COLLECTION_IDENTIFIER_RGX), { - message: COLLECTION_IDENTIFIER_ERROR, - }) - collectionName: string; - - constructor(init?: Partial) { - Object.assign(this, init); - } -} diff --git a/src/modules/primary-sale-sc/models/PrimarySale.dto.ts b/src/modules/primary-sale-sc/models/PrimarySale.dto.ts deleted file mode 100644 index c8f2b6094..000000000 --- a/src/modules/primary-sale-sc/models/PrimarySale.dto.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Field, ID, Int, ObjectType, registerEnumType } from '@nestjs/graphql'; -import { PrimarySaleTime } from './PrimarySaleTime'; - -@ObjectType() -export class PrimarySale { - @Field(() => ID, { nullable: true }) - collectionIdentifier: string; - @Field(() => PrimarySaleStatusEnum) - status: PrimarySaleStatusEnum; - @Field({ nullable: true }) - frozen: boolean; - @Field(() => String, { nullable: true }) - price: string; - @Field() - paymentToken: string; - @Field(() => Int) - maxUnitsPerWallet: number; - @Field(() => PrimarySaleTime) - saleTime: PrimarySaleTime; - - constructor(init?: Partial) { - Object.assign(this, init); - } -} - -export enum PrimarySaleStatusEnum { - ClaimPeriod = 'ClaimPeriod', - SalePeriod = 'SalePeriod', - EndedPeriod = 'EndedPeriod', - BetweenPeriod = 'BetweenPeriod', - NotStarted = 'NotStarted', - NonePeriod = 'NonePeriod', -} -registerEnumType(PrimarySaleStatusEnum, { - name: 'PrimarySaleStatusEnum', -}); diff --git a/src/modules/primary-sale-sc/models/PrimarySaleTime.ts b/src/modules/primary-sale-sc/models/PrimarySaleTime.ts deleted file mode 100644 index 90ccd0955..000000000 --- a/src/modules/primary-sale-sc/models/PrimarySaleTime.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Field, ID, Int, ObjectType } from '@nestjs/graphql'; -import { PrimarySaleTimeAbi } from './PrimarySaleTimestamp.abi'; - -@ObjectType() -export class PrimarySaleTime { - @Field(() => Int) - startSale: number; - @Field(() => Int) - endSale: number; - @Field(() => Int, { nullable: true }) - startClaim: number; - @Field(() => Int, { nullable: true }) - endClaim: number; - - constructor(init?: Partial) { - Object.assign(this, init); - } - - static fromAbi(abi: PrimarySaleTimeAbi): PrimarySaleTime | undefined { - return abi - ? new PrimarySaleTime({ - startSale: parseInt(abi.start_sale.valueOf().toString()), - endSale: parseInt(abi.end_sale.valueOf().toString()), - startClaim: parseInt(abi.start_claim.valueOf().toString()), - endClaim: parseInt(abi.end_claim.valueOf().toString()), - }) - : undefined; - } -} diff --git a/src/modules/primary-sale-sc/models/PrimarySaleTimestamp.abi.ts b/src/modules/primary-sale-sc/models/PrimarySaleTimestamp.abi.ts deleted file mode 100644 index 71ba30dd2..000000000 --- a/src/modules/primary-sale-sc/models/PrimarySaleTimestamp.abi.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { AddressType, BigUIntValue, U32Type, U64Type } from '@multiversx/sdk-core'; - -export interface PrimarySaleTimeAbi { - start_sale: U64Type; - end_sale: U64Type; - start_claim: U64Type; - end_claim: U64Type; -} - -export interface TicketInfoAbi { - buyer: AddressType; - ticket_number: U32Type; - winner_nonce: U64Type; - price: BigUIntValue; -} diff --git a/src/modules/primary-sale-sc/models/TicketInfo.ts b/src/modules/primary-sale-sc/models/TicketInfo.ts deleted file mode 100644 index b02017440..000000000 --- a/src/modules/primary-sale-sc/models/TicketInfo.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Field, Int, ObjectType } from '@nestjs/graphql'; -import { TicketInfoAbi } from './PrimarySaleTimestamp.abi'; - -@ObjectType() -export class TicketInfo { - @Field(() => String) - buyer: string; - @Field(() => Int) - ticketNumber: number; - @Field(() => String) - winningNonce: string; - - constructor(init?: Partial) { - Object.assign(this, init); - } - - static fromAbi(abi: TicketInfoAbi): TicketInfo | undefined { - return abi - ? new TicketInfo({ - buyer: abi.buyer.valueOf().toString(), - ticketNumber: parseInt(abi.ticket_number.valueOf().toString()), - winningNonce: abi.winner_nonce.valueOf().toString(), - }) - : undefined; - } -} - -@ObjectType() -export class WhitelistedInfo { - @Field(() => Boolean) - isWhitelisted: boolean; - @Field(() => String, { nullable: true }) - message: string; - - constructor(init?: Partial) { - Object.assign(this, init); - } -} diff --git a/src/modules/primary-sale-sc/models/index.ts b/src/modules/primary-sale-sc/models/index.ts deleted file mode 100644 index 12e50930b..000000000 --- a/src/modules/primary-sale-sc/models/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './BuyTicketArgs'; -export * from './ClaimTicketArgs'; diff --git a/src/modules/primary-sale-sc/primary-sale.module.ts b/src/modules/primary-sale-sc/primary-sale.module.ts deleted file mode 100644 index e7851e46f..000000000 --- a/src/modules/primary-sale-sc/primary-sale.module.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { forwardRef, Module } from '@nestjs/common'; -import { PrimarySaleResolver } from './primary-sale.resolver'; -import { MxCommunicationModule } from 'src/common/services/mx-communication/mx-communication.module'; -import { PrimarySaleService } from './primary-sale.service'; -import { CommonModule } from 'src/common.module'; -import { AuthModule } from '../auth/auth.module'; - -@Module({ - providers: [PrimarySaleService, PrimarySaleResolver], - imports: [forwardRef(() => MxCommunicationModule), forwardRef(() => CommonModule), forwardRef(() => AuthModule)], - exports: [PrimarySaleService], -}) -export class PrimarySaleModuleGraph {} diff --git a/src/modules/primary-sale-sc/primary-sale.resolver.ts b/src/modules/primary-sale-sc/primary-sale.resolver.ts deleted file mode 100644 index 36a256d1a..000000000 --- a/src/modules/primary-sale-sc/primary-sale.resolver.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { Resolver, Args, Mutation, Query, ResolveField, Parent, Int } from '@nestjs/graphql'; -import { BaseResolver } from '../common/base.resolver'; -import { BuyTicketsArgs, ClaimTicketsArgs } from './models'; -import { PrimarySaleService } from './primary-sale.service'; -import { UseGuards } from '@nestjs/common'; -import { TransactionNode } from '../common/transaction'; -import { PrimarySale } from './models/PrimarySale.dto'; -import { PrimarySaleFilter } from './models/Primary-sale.Filter'; -import { PrimarySaleTime } from './models/PrimarySaleTime'; -import { TicketInfo, WhitelistedInfo } from './models/TicketInfo'; -import { UserAuthResult } from '../auth/userAuthResult'; -import { JwtOrNativeAuthGuard } from '../auth/jwt.or.native.auth-guard'; -import { AuthUser } from '../auth/authUser'; - -@Resolver(() => PrimarySale) -export class PrimarySaleResolver extends BaseResolver(PrimarySale) { - constructor(private primarySaleService: PrimarySaleService) { - super(); - } - - @Query(() => PrimarySale) - async primarySale( - @Args({ name: 'filters', type: () => PrimarySaleFilter }) - filters: PrimarySaleFilter, - ): Promise { - return await this.primarySaleService.getStatus(filters.collectionName); - } - - @Query(() => [TicketInfo]) - @UseGuards(JwtOrNativeAuthGuard) - async myTickets( - @Args({ name: 'collectionIdentifier', type: () => String }) - collectionIdentifier: string, - @AuthUser() user: UserAuthResult, - ): Promise { - return await this.primarySaleService.getMyTickets(collectionIdentifier, user.address); - } - - @Query(() => Boolean) - @UseGuards(JwtOrNativeAuthGuard) - async hasClaimedTickets( - @Args({ name: 'collectionIdentifier', type: () => String }) - collectionIdentifier: string, - @AuthUser() user: UserAuthResult, - ): Promise { - return await this.primarySaleService.hasClaimedTickets(collectionIdentifier, user.address); - } - - @Query(() => WhitelistedInfo) - @UseGuards(JwtOrNativeAuthGuard) - async isWhitelisted(@AuthUser() user: UserAuthResult): Promise<{ isWhitelisted: boolean; message?: string }> { - return await this.primarySaleService.isWhitelisted(user.address); - } - - @ResolveField('price', () => String) - async price(@Parent() sale: PrimarySale) { - const { collectionIdentifier } = sale; - const pricePerTicket = await this.primarySaleService.getPricePerTicket(collectionIdentifier); - return pricePerTicket || 0; - } - - @ResolveField(() => Int) - async maxUnitsPerWallet(@Parent() sale: PrimarySale) { - const { collectionIdentifier } = sale; - - const maxNftsPerWallet = await this.primarySaleService.getMaxNftPerWallet(collectionIdentifier); - return maxNftsPerWallet || 0; - } - - @ResolveField(() => String) - async paymentToken(@Parent() sale: PrimarySale) { - return process.env.HOLORIDE_PAYMENT_TOKEN; - } - - @ResolveField(() => PrimarySaleTime) - async saleTime(@Parent() sale: PrimarySale) { - const { collectionIdentifier } = sale; - return await this.primarySaleService.getTimestamps(collectionIdentifier); - } - - @Mutation(() => TransactionNode) - @UseGuards(JwtOrNativeAuthGuard) - async buyTickets( - @Args('input', { type: () => BuyTicketsArgs }) - input: BuyTicketsArgs, - @AuthUser() user: UserAuthResult, - ): Promise { - return await this.primarySaleService.buyTicket(user.address, input); - } - - @Mutation(() => TransactionNode) - @UseGuards(JwtOrNativeAuthGuard) - async claimTicket( - @Args('input', { type: () => ClaimTicketsArgs }) - input: ClaimTicketsArgs, - @AuthUser() user: UserAuthResult, - ): Promise { - return await this.primarySaleService.claim(user.address, input); - } -} diff --git a/src/modules/primary-sale-sc/primary-sale.service.ts b/src/modules/primary-sale-sc/primary-sale.service.ts deleted file mode 100644 index d7e953b8a..000000000 --- a/src/modules/primary-sale-sc/primary-sale.service.ts +++ /dev/null @@ -1,286 +0,0 @@ -import { Injectable, Logger } from '@nestjs/common'; -import '../../utils/extensions'; -import BigNumber from 'bignumber.js'; -import { - Address, - AddressValue, - BytesValue, - ContractFunction, - Interaction, - ResultsParser, - TokenIdentifierValue, - TokenTransfer, - U32Value, -} from '@multiversx/sdk-core'; -import { mxConfig, gas } from '../../config'; -import { TransactionNode } from '../common/transaction'; -import { BuyTicketsArgs, ClaimTicketsArgs } from './models'; -import { MxProxyService, getSmartContract } from 'src/common'; -import { PrimarySaleTimeAbi, TicketInfoAbi } from './models/PrimarySaleTimestamp.abi'; -import { generateCacheKeyFromParams } from 'src/utils/generate-cache-key'; -import { PrimarySale, PrimarySaleStatusEnum } from './models/PrimarySale.dto'; -import { PrimarySaleTime } from './models/PrimarySaleTime'; -import { TicketInfo } from './models/TicketInfo'; -import { DateUtils } from 'src/utils/date-utils'; -import { Constants } from '@multiversx/sdk-nestjs-common'; -import { RedisCacheService } from '@multiversx/sdk-nestjs-cache'; -import { ContractLoader } from '../auctions/contractLoader'; - -@Injectable() -export class PrimarySaleService { - private contract = new ContractLoader('./src/abis/primary-sales-sc.abi.json'); - private readonly parser: ResultsParser; - - constructor(private mxProxyService: MxProxyService, private redisCacheService: RedisCacheService, private logger: Logger) { - this.parser = new ResultsParser(); - } - - async getStatus(collectionIdentifier: string): Promise { - try { - const saleTime = await this.getTimestamps(collectionIdentifier); - return await this.getStatusMap(collectionIdentifier, saleTime); - } catch (err) { - this.logger.error('An error occurred while getting the status.', { - path: this.getStatus.name, - collectionIdentifier, - exception: err, - }); - } - } - - async getStatusMap(collectionIdentifier: string, saleTime: PrimarySaleTime): Promise { - if (saleTime.startSale > DateUtils.getCurrentTimestamp()) { - return new PrimarySale({ - status: PrimarySaleStatusEnum.NotStarted, - collectionIdentifier: collectionIdentifier, - }); - } - if (saleTime.startSale <= DateUtils.getCurrentTimestamp() && saleTime.endSale > DateUtils.getCurrentTimestamp()) { - return new PrimarySale({ - status: PrimarySaleStatusEnum.SalePeriod, - collectionIdentifier: collectionIdentifier, - }); - } - - if (saleTime.endSale <= DateUtils.getCurrentTimestamp() && saleTime.startClaim > DateUtils.getCurrentTimestamp()) { - return new PrimarySale({ - status: PrimarySaleStatusEnum.BetweenPeriod, - collectionIdentifier: collectionIdentifier, - }); - } - if (saleTime.startClaim <= DateUtils.getCurrentTimestamp() && saleTime.endClaim > DateUtils.getCurrentTimestamp()) { - return new PrimarySale({ - status: PrimarySaleStatusEnum.ClaimPeriod, - collectionIdentifier: collectionIdentifier, - }); - } - if (saleTime.endClaim <= DateUtils.getCurrentTimestamp()) { - return new PrimarySale({ - status: PrimarySaleStatusEnum.EndedPeriod, - collectionIdentifier: collectionIdentifier, - }); - } - return new PrimarySale({ - status: PrimarySaleStatusEnum.NonePeriod, - collectionIdentifier: collectionIdentifier, - }); - } - - async getPricePerTicket(collectionIdentifier: string): Promise { - try { - const cacheKey = generateCacheKeyFromParams('primarySaleCollectionPrice', collectionIdentifier); - return await this.redisCacheService.getOrSet( - cacheKey, - () => this.getPricePerTicketMap(collectionIdentifier), - 5 * Constants.oneSecond(), - ); - } catch (err) { - this.logger.error('An error occurred while getting price per ticket.', { - path: this.getPricePerTicket.name, - collectionIdentifier, - exception: err, - }); - } - } - - async getPricePerTicketMap(collectionIdentifier: string): Promise { - const contract = await this.contract.getContract(process.env.HOLORIDE_PRIMARY_SC); - let price = contract.methodsExplicit.price([BytesValue.fromUTF8(collectionIdentifier)]); - - const response = await this.getFirstQueryResult(price); - return response.firstValue.valueOf(); - } - - async getMaxNftPerWallet(collectionIdentifier: string): Promise { - try { - const cacheKey = generateCacheKeyFromParams('primarySaleMaxNftWallet', collectionIdentifier); - return await this.redisCacheService.getOrSet( - cacheKey, - () => this.getMaxNftPerWalletMap(collectionIdentifier), - 5 * Constants.oneSecond(), - ); - } catch (err) { - this.logger.error('An error occurred while getting the max nfts per wallet.', { - path: this.getMaxNftPerWallet.name, - collectionIdentifier, - exception: err, - }); - } - } - - async getMaxNftPerWalletMap(collectionIdentifier: string): Promise { - const contract = await this.contract.getContract(process.env.HOLORIDE_PRIMARY_SC); - let maxNftPerWalletInteraction = ( - contract.methodsExplicit.max_units_per_wallet([BytesValue.fromUTF8(collectionIdentifier)]) - ); - - const response = await this.getFirstQueryResult(maxNftPerWalletInteraction); - return response.firstValue.valueOf().toFixed(); - } - - async getTimestamps(collectionIdentifier: string): Promise { - try { - const cacheKey = generateCacheKeyFromParams('primarySaleTimestamp', collectionIdentifier); - return await this.redisCacheService.getOrSet(cacheKey, () => this.getTimestampsMap(collectionIdentifier), 5 * Constants.oneSecond()); - } catch (err) { - this.logger.error('An error occurred while getting timestamp.', { - path: this.getTimestampsMap.name, - collectionIdentifier, - exception: err, - }); - } - } - - async getMyTickets(collectionIdentifier: string, address: string): Promise { - try { - const cacheKey = generateCacheKeyFromParams('myTickets', address, collectionIdentifier); - return await this.redisCacheService.getOrSet( - cacheKey, - () => this.getMyTicketsMap(collectionIdentifier, address), - 5 * Constants.oneSecond(), - ); - } catch (err) { - this.logger.error('An error occurred while getting timestamp.', { - path: this.getMyTickets.name, - collectionIdentifier, - exception: err, - }); - } - } - - async getClaimStatus(collectionIdentifier: string, address: string): Promise<[boolean, number]> { - const contract = await this.contract.getContract(process.env.HOLORIDE_PRIMARY_SC); - let myTicketsInteraction = contract.methodsExplicit.claimers([new TokenIdentifierValue(collectionIdentifier)]); - - const response = await this.getFirstQueryResult(myTicketsInteraction); - const addresses: Address[] = response?.firstValue?.valueOf(); - const claimmers = addresses.map((x) => x.bech32()); - if (claimmers.includes(address)) { - return [true, Constants.oneHour()]; - } - return [false, Constants.oneSecond()]; - } - - async getMyTicketsMap(collectionIdentifier: string, address: string): Promise { - const contract = await this.contract.getContract(process.env.HOLORIDE_PRIMARY_SC); - let myTicketsInteraction = ( - contract.methodsExplicit.all_tickets([new AddressValue(new Address(address)), new TokenIdentifierValue(collectionIdentifier)]) - ); - - const response = await this.getFirstQueryResult(myTicketsInteraction); - const myTickets: TicketInfoAbi[] = response?.firstValue?.valueOf(); - return myTickets?.map((t) => TicketInfo.fromAbi(t)); - } - - async isWhitelisted(address: string): Promise<{ isWhitelisted: boolean; message?: string }> { - try { - const cacheKey = generateCacheKeyFromParams('isWhitelisted', address); - return await this.redisCacheService.getOrSet(cacheKey, () => this.isWhitelistedMap(address), 5 * Constants.oneSecond()); - } catch (err) { - this.logger.error('An error occurred while getting is whitelisted.', { - path: this.isWhitelisted.name, - exception: err, - }); - } - } - - async hasClaimedTickets(collectionIdentifier: string, address: string): Promise { - try { - const cacheKey = generateCacheKeyFromParams('hasClaimedTickets', address, collectionIdentifier); - const cachedValue = await this.redisCacheService.get(cacheKey); - if (cachedValue) { - return cachedValue; - } - const [value, ttl] = await this.getClaimStatus(collectionIdentifier, address); - await this.redisCacheService.set(cacheKey, value, ttl); - return value; - } catch (err) { - this.logger.error('An error occurred while getting has claimed status.', { - path: this.hasClaimedTickets.name, - exception: err, - }); - } - } - - async isWhitelistedMap(address: string): Promise<{ isWhitelisted: boolean; message?: string }> { - const contract = getSmartContract(process.env.HOLORIDE_WHITELIST_SC); - const func = new ContractFunction('in_whitelist'); - const args = [new AddressValue(new Address(address))]; - const query = new Interaction(contract, func, args).withQuerent(new Address(address)).buildQuery(); - - const queryResponse = await this.mxProxyService.getService().queryContract(query); - - const value = - queryResponse?.returnData && queryResponse.returnData.length > 0 - ? new Boolean(queryResponse.returnData[0].base64ToHex()).valueOf() - : false; - if (value === false) { - return { - isWhitelisted: false, - message: process.env.HOLORIDE_WHITELIST_MSG, - }; - } - return { - isWhitelisted: true, - }; - } - - async getTimestampsMap(collectionIdentifier: string): Promise { - const contract = await this.contract.getContract(process.env.HOLORIDE_PRIMARY_SC); - let price = contract.methodsExplicit.timestamps([BytesValue.fromUTF8(collectionIdentifier)]); - - const response = await this.getFirstQueryResult(price); - const saleTime: PrimarySaleTimeAbi = response?.firstValue?.valueOf(); - return PrimarySaleTime.fromAbi(saleTime); - } - - async buyTicket(ownerAddress: string, request: BuyTicketsArgs): Promise { - const contract = await this.contract.getContract(process.env.HOLORIDE_PRIMARY_SC); - - return contract.methodsExplicit - .buy_tickets([BytesValue.fromUTF8(request.collectionIdentifier), new U32Value(new BigNumber(request.ticketsNumber))]) - .withSingleESDTTransfer(TokenTransfer.fungibleFromBigInteger(process.env.HOLORIDE_PAYMENT_TOKEN, new BigNumber(request.price))) - .withChainID(mxConfig.chainID) - .withGasLimit(gas.buyTickets) - .withSender(Address.fromString(ownerAddress)) - .buildTransaction() - .toPlainObject(); - } - - async claim(ownerAddress: string, request: ClaimTicketsArgs): Promise { - const contract = await this.contract.getContract(process.env.HOLORIDE_PRIMARY_SC); - return contract.methodsExplicit - .claim([new TokenIdentifierValue(request.collectionIdentifier)]) - .withChainID(mxConfig.chainID) - .withGasLimit(gas.withdraw) - .withSender(Address.fromString(ownerAddress)) - .buildTransaction() - .toPlainObject(); - } - - private async getFirstQueryResult(interaction: Interaction) { - let queryResponse = await this.mxProxyService.getService().queryContract(interaction.buildQuery()); - let result = this.parser.parseQueryResponse(queryResponse, interaction.getEndpoint()); - return result; - } -}