Skip to content

Commit

Permalink
Close invalidators on unissue
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbogle committed Sep 12, 2022
1 parent 6c1f603 commit 55148f9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ node_modules
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
!.yarn/versions

.env.local
41 changes: 40 additions & 1 deletion src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export const withUnissueToken = async (
wallet.publicKey
);

return transaction.add(
transaction.add(
tokenManager.instruction.unissue(
connection,
wallet,
Expand All @@ -435,6 +435,45 @@ export const withUnissueToken = async (
issuerTokenAccountId
)
);

const [[useInvalidatorId], [timeInvalidatorId]] = await Promise.all([
useInvalidator.pda.findUseInvalidatorAddress(tokenManagerId),
timeInvalidator.pda.findTimeInvalidatorAddress(tokenManagerId),
]);

const [useInvalidatorData, timeInvalidatorData] = await Promise.all([
tryGetAccount(() =>
useInvalidator.accounts.getUseInvalidator(connection, useInvalidatorId)
),
tryGetAccount(() =>
timeInvalidator.accounts.getTimeInvalidator(connection, timeInvalidatorId)
),
]);

if (timeInvalidatorData) {
transaction.add(
timeInvalidator.instruction.close(
connection,
wallet,
timeInvalidatorId,
tokenManagerId,
timeInvalidatorData.parsed.collector
)
);
}
if (useInvalidatorData) {
transaction.add(
useInvalidator.instruction.close(
connection,
wallet,
useInvalidatorId,
tokenManagerId,
useInvalidatorData.parsed.collector
)
);
}

return transaction;
};

export const withInvalidate = async (
Expand Down

0 comments on commit 55148f9

Please sign in to comment.