diff --git a/src/services/green-bean.service.ts b/src/services/green-bean.service.ts index 97d1688..d4e7cf1 100644 --- a/src/services/green-bean.service.ts +++ b/src/services/green-bean.service.ts @@ -22,6 +22,13 @@ export class GreenBeanService { return data[0]; } + async getAzukis({ canClaim }: Prisma.AzukiSelect) { + return this.prisma.azuki.findMany({ + where: { canClaim }, + orderBy: { tokenId: 'asc' }, + }); + } + async createAzuki({ tokenId, canClaim, diff --git a/src/standalone/scripts/asdf.ts b/src/standalone/scripts/asdf.ts deleted file mode 100644 index 49fee7b..0000000 --- a/src/standalone/scripts/asdf.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { decodeFunctionData } from 'viem'; -import { greenBeanAbi } from '../../abis/green-bean-abi'; - -const bytedata = - '0x6ba4c138000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000dd6'; -const value = decodeFunctionData({ - abi: greenBeanAbi, - data: bytedata, -}); -console.log(value); diff --git a/src/standalone/scripts/green-bean-checks.ts b/src/standalone/scripts/backfill/green-bean-checks.ts similarity index 81% rename from src/standalone/scripts/green-bean-checks.ts rename to src/standalone/scripts/backfill/green-bean-checks.ts index 9332c56..b9fced7 100644 --- a/src/standalone/scripts/green-bean-checks.ts +++ b/src/standalone/scripts/backfill/green-bean-checks.ts @@ -1,6 +1,6 @@ import { NestFactory } from '@nestjs/core'; -import { AppModule } from '../../app.module'; -import { GreenBeanService } from '../../services/green-bean.service'; +import { AppModule } from '../../../app.module'; +import { GreenBeanService } from '../../../services/green-bean.service'; // Initialize the db with canClaim statuses for all Azukis async function bootstrap() { diff --git a/src/standalone/scripts/store-past-claimed-green-beans.ts b/src/standalone/scripts/backfill/store-past-claimed-green-beans.ts similarity index 89% rename from src/standalone/scripts/store-past-claimed-green-beans.ts rename to src/standalone/scripts/backfill/store-past-claimed-green-beans.ts index 33aab16..3ebe4de 100644 --- a/src/standalone/scripts/store-past-claimed-green-beans.ts +++ b/src/standalone/scripts/backfill/store-past-claimed-green-beans.ts @@ -1,11 +1,11 @@ import { NestFactory } from '@nestjs/core'; import { decodeFunctionData } from 'viem'; import * as dayjs from 'dayjs'; -import { AppModule } from '../../app.module'; -import { GREEN_BEAN_ADDRESS } from '../../constants'; -import { client } from '../../utils/client'; -import { greenBeanAbi } from '../../abis/green-bean-abi'; -import { GreenBeanService } from '../../services/green-bean.service'; +import { AppModule } from '../../../app.module'; +import { GREEN_BEAN_ADDRESS } from '../../../constants'; +import { client } from '../../../utils/client'; +import { greenBeanAbi } from '../../../abis/green-bean-abi'; +import { GreenBeanService } from '../../../services/green-bean.service'; // store the thumbnail images for all Azukis async function bootstrap() { diff --git a/src/standalone/scripts/store-thumbnail-images.ts b/src/standalone/scripts/backfill/store-thumbnail-images.ts similarity index 74% rename from src/standalone/scripts/store-thumbnail-images.ts rename to src/standalone/scripts/backfill/store-thumbnail-images.ts index 21a1e9e..b9917a8 100644 --- a/src/standalone/scripts/store-thumbnail-images.ts +++ b/src/standalone/scripts/backfill/store-thumbnail-images.ts @@ -1,9 +1,9 @@ import { NestFactory } from '@nestjs/core'; import { NftTokenType } from 'alchemy-sdk'; -import { AppModule } from '../../app.module'; -import { GreenBeanService } from '../../services/green-bean.service'; -import { alchemy } from '../../utils/alchemy'; -import { AZUKI_CONTRACT_ADDRESS } from '../../constants'; +import { AppModule } from '../../../app.module'; +import { GreenBeanService } from '../../../services/green-bean.service'; +import { alchemy } from '../../../utils/alchemy'; +import { AZUKI_CONTRACT_ADDRESS } from '../../../constants'; // store the thumbnail images for all Azukis async function bootstrap() { diff --git a/src/standalone/scripts/schedule/check-can-claim-azukis.ts b/src/standalone/scripts/schedule/check-can-claim-azukis.ts new file mode 100644 index 0000000..5a26638 --- /dev/null +++ b/src/standalone/scripts/schedule/check-can-claim-azukis.ts @@ -0,0 +1,29 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from '../../../app.module'; +import { GreenBeanService } from '../../../services/green-bean.service'; + +// The intention for this script is to be run on a schedule, to check if there are any azukis that have claimed their green beans via a smart contract +async function bootstrap() { + const app = await NestFactory.createApplicationContext(AppModule); + const greenBeanService = app.get(GreenBeanService); + + const canClaimAzukis = await greenBeanService.getAzukis({ canClaim: true }); + await app.close(); + + for (let i = 0; i < canClaimAzukis.length; i++) { + const azuki = canClaimAzukis[i]; + + const canClaimStatus = await greenBeanService.checkGreenBean(azuki.tokenId); + console.log(`${i}: ${azuki.tokenId} - ${canClaimStatus}`); + + if (!canClaimStatus) { + await greenBeanService.updateAzuki({ + tokenId: azuki.tokenId, + canClaim: false, + }); + console.log(`Updated ${azuki.tokenId} with canClaim: false`); + } + } +} + +bootstrap();