feat: support credit transfers and precious metal valuations

This commit is contained in:
陈煜 committed 2026-10-03 21:10:26 +08:00
1 parent 425b45c91a
commit 518aea1e59
39 files changed
+1572 -77

No files matched your search

+10 -3
View File
@@ -1,15 +1,22 @@
import Decimal from 'decimal.js';
import { BadRequestException } from '@nestjs/common';
export type Movement = 'transfer' | 'borrow' | 'lend' | 'collect' | 'repay';
export function movementDeltas(operation: Movement, amount: string, received: string, fee: string) {
export function movementDeltas(
operation: Movement,
amount: string,
received: string,
fee: string,
sourceSide = 'asset',
targetSide = 'asset',
) {
const incoming = operation === 'borrow' || operation === 'collect';
const principal = new Decimal(amount),
charge = new Decimal(fee),
debt = new Decimal(received);
if (operation === 'transfer')
return {
source: principal.plus(charge).neg(),
target: debt,
source: principal.plus(charge).mul(sourceSide === 'liability' ? 1 : -1),
target: debt.mul(targetSide === 'liability' ? -1 : 1),
sourceReason: 'transfer_out',
targetReason: 'transfer_in',
};