Skip to content

Commit c6ddcea

Browse files
committed
feat: wip create asset activity
1 parent 6509314 commit c6ddcea

20 files changed

+404
-85
lines changed

api-schema.graphql

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ type AppConfig {
8484

8585
type Asset {
8686
account: String!
87+
activities: [PresetActivity!]!
8788
attributes: [[String!]!]!
8889
description: String!
8990
image: String!
90-
lists: [AssetActivityType!]!
9191
name: String!
9292
}
9393

@@ -99,7 +99,7 @@ type AssetActivity {
9999
pointsLabel: String!
100100
pointsTotal: Float!
101101
startDate: DateTime!
102-
type: AssetActivityType!
102+
type: PresetActivity!
103103
}
104104

105105
type AssetActivityEntry {
@@ -109,11 +109,6 @@ type AssetActivityEntry {
109109
url: String
110110
}
111111

112-
enum AssetActivityType {
113-
Payouts
114-
Points
115-
}
116-
117112
type Claim {
118113
account: String!
119114
amount: String!
@@ -316,6 +311,7 @@ type Mutation {
316311
adminUpdateUser(input: AdminUpdateUserInput!, userId: String!): User
317312
adminUpdateWallet(input: WalletAdminUpdateInput!, walletId: String!): Wallet
318313
anonVerifyIdentityChallenge(input: VerifyIdentityChallengeInput!): IdentityChallenge
314+
createAssetActivity(account: String!, type: PresetActivity!): AssetActivity
319315
login(input: LoginInput!): User
320316
logout: Boolean
321317
register(input: RegisterInput!): User
@@ -355,6 +351,7 @@ type PagingMeta {
355351
}
356352

357353
type Preset {
354+
activities: [PresetActivity!]
358355
color: String!
359356
config: JSON
360357
createdAt: DateTime
@@ -365,6 +362,11 @@ type Preset {
365362
updatedAt: DateTime
366363
}
367364

365+
enum PresetActivity {
366+
Payouts
367+
Points
368+
}
369+
368370
input PresetAdminCreateInput {
369371
description: String
370372
name: String!
@@ -464,7 +466,7 @@ type Query {
464466
appConfig: AppConfig!
465467
currencies: [Currency!]!
466468
getAsset(account: String!): Asset!
467-
getAssetActivity(account: String!, type: AssetActivityType!): AssetActivity!
469+
getAssetActivity(account: String!, type: PresetActivity!): AssetActivity
468470
me: User
469471
metadataAll(account: String!): JSON
470472
solanaGetBalance(account: String!): String

libs/api/asset/data-access/src/lib/api-asset.data-access.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Module } from '@nestjs/common'
22
import { ApiCoreDataAccessModule } from '@tokengator/api-core-data-access'
33
import { ApiMetadataDataAccessModule } from '@tokengator/api-metadata-data-access'
4+
import { ApiPresetDataAccessModule } from '@tokengator/api-preset-data-access'
45
import { ApiAssetService } from './api-asset.service'
56

67
@Module({
7-
imports: [ApiCoreDataAccessModule, ApiMetadataDataAccessModule],
8+
imports: [ApiCoreDataAccessModule, ApiMetadataDataAccessModule, ApiPresetDataAccessModule],
89
providers: [ApiAssetService],
910
exports: [ApiAssetService],
1011
})

libs/api/asset/data-access/src/lib/api-asset.service.ts

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,76 @@
11
import { Injectable } from '@nestjs/common'
2+
import { PublicKey } from '@solana/web3.js'
23
import { ApiMetadataService } from '@tokengator/api-metadata-data-access'
3-
import { AssetActivity, AssetActivityType } from './entity/asset-activity.entity'
4+
import { ApiPresetService, PresetActivity } from '@tokengator/api-preset-data-access'
5+
import { AssetActivity } from './entity/asset-activity.entity'
46
import { Asset } from './entity/asset.entity'
57

68
@Injectable()
79
export class ApiAssetService {
8-
constructor(private readonly metadata: ApiMetadataService) {}
10+
constructor(private readonly metadata: ApiMetadataService, private readonly preset: ApiPresetService) {}
911

10-
async getAsset(account: string): Promise<Asset> {
11-
const { json } = await this.metadata.getAll(account)
12+
async getAsset(account: string): Promise<Asset & { mint: PublicKey }> {
13+
const { json, accountMetadata } = await this.metadata.getAll(account)
1214

1315
if (!json) {
1416
throw new Error('Asset metadata not found')
1517
}
1618

19+
const mint = accountMetadata?.state.updateAuthority
20+
if (!mint) {
21+
throw new Error('Asset minter not found')
22+
}
23+
24+
const presetId = json.attributes.find((attr) => attr.trait_type === 'preset' && attr.value)?.value
25+
if (!presetId) {
26+
throw new Error('Asset preset not found')
27+
}
28+
29+
const preset = await this.preset.data.findOne(presetId)
30+
1731
return {
1832
account,
1933
name: json.name,
2034
description: json.description,
2135
image: json.image,
22-
lists: this.getLists('business-visa'),
36+
activities: preset.activities ?? [],
2337
attributes: json.attributes.map((attr) => [attr.trait_type, attr.value]),
38+
mint,
2439
}
2540
}
2641

27-
async getAssetActivity(account: string, type: AssetActivityType): Promise<AssetActivity> {
42+
async getAssetActivity(account: string, type: PresetActivity): Promise<AssetActivity | null> {
43+
const { accountMetadata } = await this.metadata.getAll(account)
44+
45+
const mint = accountMetadata?.state.updateAuthority
46+
if (!mint) {
47+
throw new Error('Asset minter not found')
48+
}
49+
50+
const activityPda = this.preset.minter.getActivityPda({
51+
mint: new PublicKey(mint),
52+
label: type.toLowerCase(),
53+
})
54+
55+
const activity = await this.preset.minter.getActivity({ account: activityPda })
56+
57+
if (typeof activity === 'boolean') {
58+
//
59+
// console.log('Creating activity...')
60+
// await this.createAssetActivity(account, type)
61+
// throw new Error('Activity not found')
62+
return null
63+
}
64+
// this.preset.minter.getCommunityPda()
65+
console.log(`Account, type: ${account}, ${type}`, activity)
66+
2867
const listAccount = `pda-${account}-${type}`
2968
const found = {
3069
label: `${type}`,
3170
startDate: new Date(),
3271
endDate: new Date().getTime() + 30 * 24 * 60 * 60 * 1000,
3372
entries:
34-
type === AssetActivityType.Payouts
73+
type === PresetActivity.Payouts
3574
? [
3675
{ timestamp: new Date(2024, 0, 1), message: 'Payout for December 2023', points: 100 },
3776
{ timestamp: new Date(2024, 1, 1), message: 'Payout for January 2024', points: 100 },
@@ -50,7 +89,7 @@ export class ApiAssetService {
5089
}
5190

5291
const pointsTotal = found.entries.reduce((acc, entry) => acc + (entry.points ?? 0), 0)
53-
const pointsLabel = type === AssetActivityType.Payouts ? 'USD' : 'Points'
92+
const pointsLabel = type === PresetActivity.Payouts ? 'USD' : 'Points'
5493

5594
return {
5695
account: listAccount,
@@ -64,11 +103,16 @@ export class ApiAssetService {
64103
}
65104
}
66105

67-
private getLists(preset: string): AssetActivityType[] {
68-
// TODO: Specify per preset what activity lists are available
69-
if (preset === 'business-visa') {
70-
return [AssetActivityType.Payouts, AssetActivityType.Points]
71-
}
72-
return [AssetActivityType.Points]
106+
async createAssetActivity(account: string, activity: PresetActivity) {
107+
const asset = await this.getAsset(account)
108+
const minter = await this.preset.minter.getMinter(asset.mint.toString())
109+
console.log('minter', minter)
110+
// const activity = await this.getAssetActivity(account, type)
111+
//
112+
// if (activity) {
113+
// return activity
114+
// }
115+
116+
return this.preset.minter.createActivity({ minter, asset: account, activity })
73117
}
74118
}

libs/api/asset/data-access/src/lib/entity/asset-activity.entity.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql'
2-
3-
export enum AssetActivityType {
4-
Payouts = 'Payouts',
5-
Points = 'Points',
6-
}
7-
8-
registerEnumType(AssetActivityType, { name: 'AssetActivityType' })
1+
import { Field, ObjectType } from '@nestjs/graphql'
2+
import { PresetActivity } from '@tokengator/api-preset-data-access'
93

104
@ObjectType()
115
export class AssetActivity {
126
@Field()
137
account!: string
14-
@Field(() => AssetActivityType)
15-
type!: AssetActivityType
8+
@Field(() => PresetActivity)
9+
type!: PresetActivity
1610
@Field()
1711
label!: string
1812
@Field()

libs/api/asset/data-access/src/lib/entity/asset.entity.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Field, ObjectType } from '@nestjs/graphql'
2-
import { AssetActivityType } from './asset-activity.entity'
2+
import { PresetActivity } from '@tokengator/api-preset-data-access'
33

44
@ObjectType()
55
export class Asset {
@@ -11,8 +11,8 @@ export class Asset {
1111
description!: string
1212
@Field()
1313
image!: string
14-
@Field(() => [AssetActivityType])
15-
lists!: AssetActivityType[]
14+
@Field(() => [PresetActivity])
15+
activities!: PresetActivity[]
1616
@Field(() => [[String]])
1717
attributes!: [string, string][]
1818
}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { UseGuards } from '@nestjs/common'
2-
import { Args, Query, Resolver } from '@nestjs/graphql'
3-
import { ApiAssetService, Asset, AssetActivity, AssetActivityType } from '@tokengator/api-asset-data-access'
2+
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'
3+
import { ApiAssetService, Asset, AssetActivity } from '@tokengator/api-asset-data-access'
44
import { ApiAuthGraphQLUserGuard } from '@tokengator/api-auth-data-access'
5+
import { PresetActivity } from '@tokengator/api-preset-data-access'
56

67
@Resolver(() => Asset)
78
@UseGuards(ApiAuthGraphQLUserGuard)
@@ -13,11 +14,19 @@ export class ApiAssetResolver {
1314
return this.service.getAsset(account)
1415
}
1516

16-
@Query(() => AssetActivity)
17+
@Query(() => AssetActivity, { nullable: true })
1718
getAssetActivity(
1819
@Args('account') account: string,
19-
@Args({ name: 'type', type: () => AssetActivityType }) type: AssetActivityType,
20+
@Args({ name: 'type', type: () => PresetActivity }) type: PresetActivity,
2021
) {
2122
return this.service.getAssetActivity(account, type)
2223
}
24+
25+
@Mutation(() => AssetActivity, { nullable: true })
26+
createAssetActivity(
27+
@Args('account') account: string,
28+
@Args({ name: 'type', type: () => PresetActivity }) type: PresetActivity,
29+
) {
30+
return this.service.createAssetActivity(account, type)
31+
}
2332
}

libs/api/preset/data-access/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ export * from './lib/api-preset.service'
33
export * from './lib/dto/preset-admin-create.input'
44
export * from './lib/dto/preset-admin-find-many.input'
55
export * from './lib/dto/preset-admin-update.input'
6+
export * from './lib/dto/preset-user-find-many.input'
67
export * from './lib/dto/preset-user-mint-from-minter'
78
export * from './lib/dto/preset-user-mint-from-preset'
8-
export * from './lib/dto/preset-user-find-many.input'
9+
export * from './lib/entity/preset-activity.enum'
910
export * from './lib/entity/preset.entity'
11+
export * from './lib/entity/token-gator-activity.entity'
1012
export * from './lib/entity/token-gator-minter-application-config.entity'
1113
export * from './lib/entity/token-gator-minter-config.entity'
1214
export * from './lib/entity/token-gator-minter-metadata-config.entity'

0 commit comments

Comments
 (0)