Skip to content

Commit

Permalink
feat(lit-task-auto-top-up): LIT-3897 - Implement pruning of expired c…
Browse files Browse the repository at this point in the history
…apacity token NFTs
  • Loading branch information
MaximusHaximus committed Sep 24, 2024
1 parent eb3ef37 commit 94dc062
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 36 deletions.
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 @@ -33,7 +33,7 @@
},
"dependencies": {
"@hokify/agenda": "^6.3.0",
"@lit-protocol/contracts-sdk": "^6.4.0",
"@lit-protocol/contracts-sdk": "^6.6.0",
"awaity": "^1.0.0",
"bs58": "^5.0.0",
"consola": "^3.2.3",
Expand Down
2 changes: 2 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 @@ -5,6 +5,7 @@ import date from 'date-and-time';
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 @@ -40,6 +41,7 @@ export class TaskHandler {
if (noUsableTokensTomorrow) {
const capacityTokenIdStr = await mintCapacityCreditNFT({ recipientDetail });
await transferCapacityTokenNFT({ capacityTokenIdStr, recipientAddress });
await pruneExpiredCapacityTokenNFT({ recipientDetail });

return { capacityTokenIdStr, result: TaskResultEnum.minted, ...recipientDetail };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { toErrorWithMessage } from '../errors';
import { PruneCapacityTokensFailure } from '../errors/PruneCapacityTokensFailure';
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);

// @ts-ignore FIXME: This contract method has not yet been published
await litContracts.rateLimitNftContract.write.pruneExpired(recipientAddress);
} catch (e) {
const err = toErrorWithMessage(e);

throw new PruneCapacityTokensFailure(
{
cause: err,
info: {
recipientAddress,
},
name: 'PruneCapacityTokensFailure',
},
'Failed to prune capacity tokens'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import VError from 'verror';

export class PruneCapacityTokensFailure extends VError {}
70 changes: 35 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 94dc062

Please sign in to comment.