Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/blockchain/mint-ticket.processor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BlockchainTxType, WalletCreationStatus } from '@prisma/client';
import type { Job } from 'bullmq';
import { MintTicketProcessor } from './mint-ticket.processor';
import { FEE_TYPE_USDC } from './onchain-fees';
import { MINT_TICKET_JOB, MintTicketJobData } from './mint-queue.service';

// getChain is env-driven; stub the USDC + Diamond addresses.
Expand Down Expand Up @@ -83,8 +84,12 @@ describe('MintTicketProcessor', () => {

await m.proc.process(job());

// Authoritative on-chain fee read for the USDC feeType (5).
expect(m.getAllFees).toHaveBeenCalledWith('BASE-SEPOLIA', 7n, 5);
// Authoritative on-chain fee read for the crypto settlement feeType.
expect(m.getAllFees).toHaveBeenCalledWith(
'BASE-SEPOLIA',
7n,
FEE_TYPE_USDC,
);
// Approve the Diamond to pull exactly totalFee from the buyer wallet.
expect(m.approveErc20).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -98,7 +103,7 @@ describe('MintTicketProcessor', () => {
expect(m.executeContract).toHaveBeenCalledWith(
expect.objectContaining({
method: 'mintTicket',
args: [7n, 5, '0xBUYER'],
args: [7n, FEE_TYPE_USDC, '0xBUYER'],
walletId: 'cw-buyer',
txType: BlockchainTxType.MINT,
existingBlockchainTransactionId: 'bt-1',
Expand Down
17 changes: 15 additions & 2 deletions src/blockchain/onchain-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ export const FEE_TYPE_BY_NAME: Record<string, number> = {
LSK: 10,
};

/** On-chain FeeType code for USDC — HostIT's crypto settlement token. */
export const FEE_TYPE_USDC = FEE_TYPE_BY_NAME.USDC;
/**
* ⚠️ TEMPORARY TESTNET WORKAROUND — revert after the Diamond is redeployed.
*
* The deployed Base Sepolia Diamond has the real USDC token address
* registered under the **USDT (4)** slot; `FeeType.USDC (5)` is UNSET, so
* `mintTicket(…, USDC, …)` reverts `TokenAddressZero()`. Until a redeploy
* maps USDC (5) → 0x036CbD5…, we route crypto settlement (publish fee +
* approve + mintTicket) through the USDT slot, which resolves to the USDC
* token on-chain. Flip `SETTLEMENT_FEE_TYPE_NAME` back to `'USDC'` once the
* contract is fixed. Tracked in epic #96.
*/
export const SETTLEMENT_FEE_TYPE_NAME = 'USDT';

/** On-chain FeeType code used for crypto (USDC) settlement. */
export const FEE_TYPE_USDC = FEE_TYPE_BY_NAME[SETTLEMENT_FEE_TYPE_NAME];

/** USDC is 6-decimal everywhere Circle issues it. */
export const USDC_DECIMALS = 6;
Expand Down
14 changes: 9 additions & 5 deletions src/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
Prisma,
} from '@prisma/client';
import * as crypto from 'crypto';
import { computeUsdcFees } from '../blockchain/onchain-fees';
import {
computeUsdcFees,
SETTLEMENT_FEE_TYPE_NAME,
} from '../blockchain/onchain-fees';

@Injectable()
export class EventsService {
Expand Down Expand Up @@ -536,10 +539,11 @@ export class EventsService {
symbol: `${eventSymbol}-${tt.name.replace(/\s+/g, '').slice(0, 4).toUpperCase()}`,
uri: `https://api.hostit.ng/events/${event.slug}/${tt.id}/metadata`,
},
// Crypto checkout settles in USDC via `mintTicket`. Free events
// ignore fees on-chain (createTicket skips setTicketFees when
// isFree), so the converted value is harmless there.
feeTypes: ['USDC'],
// Crypto checkout settles in USDC via `mintTicket`. The on-chain fee
// slot is `SETTLEMENT_FEE_TYPE_NAME` (temporarily USDT — see
// onchain-fees.ts). Free events ignore fees on-chain (createTicket
// skips setTicketFees when isFree), so the value is harmless there.
feeTypes: [SETTLEMENT_FEE_TYPE_NAME],
prices: [computeUsdcFees(tt.price, usdcNgnRate).ticketFee],
}));

Expand Down
Loading