Skip to content

Commit 9a3a4b3

Browse files
authored
Add STABLECOIN_PAYOUT_FIXED_FEE_CENTS to stablecoinFundingAmount (dubinc#3716)
1 parent a7f402e commit 9a3a4b3

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
2-
import { MIN_WITHDRAWAL_AMOUNT_CENTS } from "@/lib/constants/payouts";
2+
import {
3+
MIN_WITHDRAWAL_AMOUNT_CENTS,
4+
STABLECOIN_PAYOUT_FIXED_FEE_CENTS,
5+
} from "@/lib/constants/payouts";
36
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
47
import { fundFinancialAccount } from "@/lib/stripe/fund-financial-account";
58
import { prisma } from "@dub/prisma";
@@ -66,8 +69,9 @@ export async function POST(req: Request) {
6669
`;
6770

6871
// Fund the total stablecoin payout amount for this invoice
69-
const { _sum } = await prisma.payout.aggregate({
72+
const { _sum, _count } = await prisma.payout.aggregate({
7073
_sum: { amount: true },
74+
_count: { id: true },
7175
where: {
7276
invoiceId: invoice.id,
7377
method: "stablecoin",
@@ -81,7 +85,10 @@ export async function POST(req: Request) {
8185
});
8286

8387
let skipStablecoinPayouts = false;
84-
const stablecoinFundingAmount = _sum.amount ?? 0;
88+
// we need to add the STABLECOIN_PAYOUT_FIXED_FEE_CENTS for each payout to the total funding amount
89+
// to make sure that `createStablecoinPayout` later has enough funds to cover Stripe's fees
90+
const stablecoinFundingAmount =
91+
(_sum.amount ?? 0) + _count.id * STABLECOIN_PAYOUT_FIXED_FEE_CENTS;
8592

8693
// Send money to Financial Account to handle stablecoin payouts
8794
if (stablecoinFundingAmount > 0) {

apps/web/lib/constants/payouts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const ELIGIBLE_PAYOUTS_MAX_PAGE_SIZE = 500;
1010
export const CUTOFF_PERIOD_MAX_PAYOUTS = 1000;
1111

1212
export const STABLECOIN_PAYOUT_FEE_RATE = 0.005; // 0.5%
13+
export const STABLECOIN_PAYOUT_FIXED_FEE_CENTS = 50; // $0.50
1314
export const FAST_ACH_FEE_CENTS = 2500; // $25
1415
export const PAYOUT_FAILURE_FEE_CENTS = 1000; // 10 USD
1516
export const FOREX_MARKUP_RATE = 0.005; // 0.5%

0 commit comments

Comments
 (0)