-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tx-construction): throw when deregistering reward accounts with …
…rewards without drep
- Loading branch information
1 parent
51b6667
commit c594937
Showing
6 changed files
with
194 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/tx-construction/src/tx-builder/ensureNoDeRegistrationsWithRewardsLocked.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DeRegistrationsWithRewardsLocked } from './types'; | ||
import { hasCorrectVoteDelegation } from './hasCorrectVoteDelegation'; | ||
import type { RewardAccountWithPoolId } from '../types'; | ||
|
||
export const ensureNoDeRegistrationsWithRewardsLocked = (rewardAccountsToBeDeRegistered: RewardAccountWithPoolId[]) => { | ||
const rewardAccountsWithLockedRewards = rewardAccountsToBeDeRegistered.filter( | ||
(rewardAccountWithPoolId) => | ||
rewardAccountWithPoolId.rewardBalance > 0n && !hasCorrectVoteDelegation(rewardAccountWithPoolId) | ||
); | ||
|
||
if (rewardAccountsWithLockedRewards.length > 0) { | ||
throw new DeRegistrationsWithRewardsLocked(rewardAccountsWithLockedRewards); | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
packages/tx-construction/src/tx-builder/hasCorrectVoteDelegation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Cardano } from '@cardano-sdk/core'; | ||
import { RewardAccountWithPoolId } from '../types'; | ||
|
||
export const hasCorrectVoteDelegation = ({ | ||
dRepDelegatee | ||
}: Pick<RewardAccountWithPoolId, 'dRepDelegatee'>): boolean => { | ||
const drep = dRepDelegatee?.delegateRepresentative; | ||
return !!drep && (!Cardano.isDrepInfo(drep) || drep.active); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters