Skip to content

Commit ed95198

Browse files
fixup! fix(core): withdrawal calculation in computeImplicitCoin
1 parent b8c1e95 commit ed95198

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/core/src/Cardano/util/computeImplicitCoin.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ const getTxDeposits = (
154154
};
155155
};
156156

157+
const getOwnWithdrawals = (withdrawals: Cardano.Withdrawal[], rewardAccounts: Address.RewardAccount[]) =>
158+
BigIntMath.sum(
159+
withdrawals
160+
.filter(({ stakeAddress }) => stakeAddressInRewardAccounts(stakeAddress, rewardAccounts))
161+
.map(({ quantity }) => quantity)
162+
);
163+
157164
/**
158165
* Computes the implicit coin from the given transaction.
159166
* If rewardAccounts is provided, it will only count the deposits from
@@ -174,7 +181,7 @@ export const computeImplicitCoin = (
174181
{
175182
certificates,
176183
proposalProcedures,
177-
withdrawals
184+
withdrawals = []
178185
}: Pick<Cardano.HydratedTxBody, 'certificates' | 'proposalProcedures' | 'withdrawals'>,
179186
rewardAccounts?: Address.RewardAccount[],
180187
dRepKeyHash?: Crypto.Ed25519KeyHashHex
@@ -187,11 +194,9 @@ export const computeImplicitCoin = (
187194
proposalProcedures
188195
);
189196

190-
const ownWithdrawals =
191-
rewardAccounts && withdrawals
192-
? withdrawals.filter((withdrawal) => stakeAddressInRewardAccounts(withdrawal.stakeAddress, rewardAccounts))
193-
: [];
194-
const withdrawalsTotal = BigIntMath.sum(ownWithdrawals.map(({ quantity }) => quantity)) || 0n;
197+
const hasRewardAccount = !!rewardAccounts?.length;
198+
const withdrawalsAll = BigIntMath.sum(withdrawals.map(({ quantity }) => quantity));
199+
const withdrawalsTotal = hasRewardAccount ? getOwnWithdrawals(withdrawals, rewardAccounts) : withdrawalsAll;
195200

196201
return {
197202
deposit,

0 commit comments

Comments
 (0)