Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ MONGO_DB_NAME=dev_task_db
NFT_MINTER_KEY=1234567890123456789012345678901234
NFT_MINTER_ADDRESS=0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef
RECIPIENT_LIST_URL=https://example.com/location/of/json_file.json
LIT_NETWORK=cayenne
LIT_NETWORK=datil-test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.1
v20.11.1
20 changes: 9 additions & 11 deletions bin/validateJSONRecipients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@ import { recipientDetailSchema, SUPPORTED_LIT_NETWORKS } from 'lit-task-auto-top
// eslint-disable-next-line import/no-extraneous-dependencies
import { z } from 'zod';

import cayenneRecipientList from '../worker/recipient_list_cayenne.json' assert { type: 'json' };
import datilTestRecipientList from '../worker/recipient_list_datil-test.json' assert { type: 'json' };
import datilRecipientList from '../worker/recipient_list_datil.json' assert { type: 'json' };
import habaneroRecipientList from '../worker/recipient_list_habanero.json' assert { type: 'json' };
import manzanoRecipientList from '../worker/recipient_list_manzano.json' assert { type: 'json' };
import rawDatilTestRecipientList from '../worker/recipient_list_datil-test.json' assert { type: 'json' };
import rawDatilRecipientList from '../worker/recipient_list_datil.json' assert { type: 'json' };

const networks = SUPPORTED_LIT_NETWORKS.options;
const recipientListSchema = z.array(recipientDetailSchema);

const datilTestRecipientList = recipientListSchema.parse(rawDatilTestRecipientList);
const datilRecipientList = recipientListSchema.parse(rawDatilRecipientList);

// Ensures we are validating the shape of a recipient list for every network that we support
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const recipientListsMap: Record<
z.infer<typeof SUPPORTED_LIT_NETWORKS>,
z.infer<typeof recipientDetailSchema>[]
> = {
cayenne: cayenneRecipientList,
datil: datilRecipientList,
'datil-test': datilTestRecipientList,
habanero: habaneroRecipientList,
manzano: manzanoRecipientList,
};

// Also check at runtime, just in case.
const networks = SUPPORTED_LIT_NETWORKS.options;
networks.forEach((network: z.infer<typeof SUPPORTED_LIT_NETWORKS>) => {
const list = recipientListsMap[network];

if (!list) {
throw new Error(`Missing recipient list at 'worker/recipient_list_${network}'`);
}

z.array(recipientDetailSchema).parse(list);
});
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "Scheduled tasks for LIT Protocol",
"homepage": "https://github.com/LIT-protocol/lit-scheduled-tasks",
"engines": {
"node": "^18.19.1",
"pnpm": "8.15.5"
"node": "^20.11.0",
"pnpm": "10.7.0"
},
"type": "module",
"scripts": {
Expand All @@ -21,13 +21,13 @@
"ci_validate": "node ./dist/bin/validateJSONRecipients.js",
"validate": "pnpm build && node ./dist/bin/validateJSONRecipients.js"
},
"packageManager": "pnpm@8.15.5",
"packageManager": "pnpm@10.7.0",
"keywords": [],
"author": "Daryl Collins <daryl@darylcollins.com>",
"license": "ISC",
"devDependencies": {
"@dotenvx/dotenvx": "^0.26.0",
"@tsconfig/node18": "^18.2.2",
"@tsconfig/node20": "^20.1.5",
"@types/chai": "^4.3.14",
"@types/lodash": "^4.17.0",
"@types/mocha": "^10.0.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-task-auto-top-up/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NFT_MINTER_KEY=1234567890123456789012345678901234
NFT_MINTER_ADDRESS=0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef
RECIPIENT_LIST_URL=https://example.com/location/of/json_file.json
LIT_NETWORK=cayenne
LIT_NETWORK=datil-test
2 changes: 1 addition & 1 deletion packages/lit-task-auto-top-up/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@date-fns/tz": "^1.1.2",
"@hokify/agenda": "^6.3.0",
"@lit-protocol/contracts-sdk": "^6.4.0",
"@lit-protocol/contracts-sdk": "^7.2.0",
"awaity": "^1.0.0",
"bs58": "^5.0.0",
"consola": "^3.2.3",
Expand Down
3 changes: 3 additions & 0 deletions packages/lit-task-auto-top-up/src/Classes/TaskHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { addDays, isSameDay } from 'date-fns';
import VError from 'verror';

import { mintCapacityCreditNFT } from '../actions/mintCapacityCreditNFT';
import { pruneExpiredCapacityTokenNFT } from '../actions/pruneExpiredCapacityTokenNFT';
import { transferCapacityTokenNFT } from '../actions/transferCapacityTokenNFT';
import { toErrorWithMessage } from '../errors';
import { getLitContractsInstance } from '../singletons/getLitContracts';
Expand Down Expand Up @@ -38,6 +39,8 @@ export class TaskHandler {
today: TZDate.tz('UTC'),
});

await pruneExpiredCapacityTokenNFT({ recipientDetail });

if (noUsableTokensTomorrow) {
const capacityTokenIdStr = await mintCapacityCreditNFT({ recipientDetail });
await transferCapacityTokenNFT({ capacityTokenIdStr, recipientAddress });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { toErrorWithMessage } from '../errors';
import { getConfig } from '../singletons/getConfig';
import { getLitContractsInstance } from '../singletons/getLitContracts';
import { RecipientDetail } from '../types/types';

export async function pruneExpiredCapacityTokenNFT({
recipientDetail,
}: {
recipientDetail: RecipientDetail;
}) {
const litContracts = await getLitContractsInstance();
const { logger } = getConfig();

const { recipientAddress } = recipientDetail;

try {
logger.log('Pruning expired capacity token NFTs for', recipientDetail);

const { actualTokensBurned, txHash } =
await litContracts.rateLimitNftContractUtils.write.pruneExpired(recipientAddress);

logger.log('Pruned capacity token NFTs for', recipientAddress, { actualTokensBurned, txHash });
} catch (e) {
const err = toErrorWithMessage(e);

logger.error('Failed to prune capacity tokens', err.toString(), 'for', recipientAddress, '...');
}
}
2 changes: 1 addition & 1 deletion packages/lit-task-auto-top-up/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const DEFAULT_RECIPIENT_LIST_URL =
'https://raw.githubusercontent.com/LIT-Protocol/lit-scheduled-tasks/main/worker/recipient_list_habanero.json';
'https://raw.githubusercontent.com/LIT-Protocol/lit-scheduled-tasks/main/worker/recipient_list_datil.json';
export const taskName = 'top-up capacity credits';
10 changes: 2 additions & 8 deletions packages/lit-task-auto-top-up/src/types/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ export const requiredConfigSchema = {
NFT_MINTER_KEY: z.string().min(32),
};

export const SUPPORTED_LIT_NETWORKS = z.enum([
'cayenne', // Playground for testing refactors/critical changes
'manzano',
'habanero',
'datil',
'datil-test',
]);
export const SUPPORTED_LIT_NETWORKS = z.enum(['datil', 'datil-test']);
export const optionalConfigSchema = {
LIT_NETWORK: SUPPORTED_LIT_NETWORKS.default('cayenne'),
LIT_NETWORK: SUPPORTED_LIT_NETWORKS.default('datil'),
RECIPIENT_LIST_URL: z.string().default(DEFAULT_RECIPIENT_LIST_URL),
};
export const envConfigSchema = z.intersection(
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-task-auto-top-up/tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EnvConfig } from '../src/types/types';

const NFT_MINTER_ADDRESS = '123456789012345678901234567890123';
const NFT_MINTER_KEY = '123456789012345678901234567890123';
const LIT_NETWORK = 'manzano';
const LIT_NETWORK = 'datil';
const RECIPIENT_LIST_URL = 'https://example.com/json/file.json';

export const COMPLETE_CONFIG: EnvConfig = {
Expand Down
1 change: 1 addition & 0 deletions packages/lit-task-auto-top-up/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"include": ["src/**/*", "tests/**/*"],
"compilerOptions": {
"composite": true,
"target": "es2020",
"module": "esnext",
"lib": ["es2020"],
Expand Down
1 change: 1 addition & 0 deletions packages/lit-task-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"include": ["src/**/*", "tests/**/*"],
"compilerOptions": {
"composite": true,
"target": "es2020",
"module": "esnext",
"lib": ["es2020"],
Expand Down
Loading
Loading