Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/backend/src/database/schemas/purchase.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class Purchase {
assetName?: string;
industry?: string;
riskTier?: string;
type?: 'PURCHASE' | 'DEPOSIT'; // Track if this is a purchase or deposit
};

// Timestamps (automatically added by Mongoose with timestamps: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsString, IsNotEmpty, IsNumberString, IsOptional } from 'class-validator';
import { IsString, IsNotEmpty, IsNumberString, IsOptional, Matches } from 'class-validator';

export class NotifyPurchaseDto {
@IsString()
Expand All @@ -9,9 +9,9 @@ export class NotifyPurchaseDto {
@IsNotEmpty()
assetId!: string;

@IsNumberString()
@Matches(/^-?\d+$/, { message: 'amount must be a valid number string (can be negative)' })
@IsNotEmpty()
amount!: string; // Token amount purchased (in wei)
amount!: string; // Token amount purchased (in wei) - can be negative

@IsOptional()
@IsNumberString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export class PurchaseTrackerService {
assetName: `${asset.metadata?.invoiceNumber} - ${asset.metadata?.buyerName}`,
industry: asset.metadata?.industry,
riskTier: asset.metadata?.riskTier,
type: 'PURCHASE', // Mark as purchase

},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ export class SolvencyController {
throw new BadRequestException('Position does not belong to authenticated user');
}

// Auto-detect token type based on Asset collection
const tokenType = await this.positionService.determineTokenType(positionData.collateralToken);
// Use token type directly from blockchain (0 = RWA, 1 = PRIVATE_ASSET)
const tokenType = positionData.tokenType === 0 ? 'RWA' : 'PRIVATE_ASSET';

// Sync database record (update if exists, create if not)
const position = await this.positionService.syncPosition(
positionId,
positionData.user,
positionData.collateralToken,
tokenType,
tokenType as any,
positionData.collateralAmount.toString(),
positionData.tokenValueUSD.toString(),
dto.txHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export class SolvencyBlockchainService {
usdcBorrowed: bigint;
tokenValueUSD: bigint;
createdAt: bigint;
liquidatedAt: bigint;
creditLineId: bigint;
active: boolean;
tokenType: number;
}> {
Expand All @@ -169,15 +171,28 @@ export class SolvencyBlockchainService {
args: [BigInt(positionId)],
}) as any;

this.logger.log(`Position user retrieved for ID ${position[0]}`);
this.logger.log(`Position collateral token: ${position[1]}`);
this.logger.log(`Position collateral amount: ${position[2]}`);
this.logger.log(`Position USDC borrowed: ${position[3]}`);
this.logger.log(`Position token value USD: ${position[4]}`);
this.logger.log(`Position created at: ${position[5]}`);
this.logger.log(`Position liquidated at: ${position[6]}`);
this.logger.log(`Position credit line ID: ${position[7]}`);
this.logger.log(`Position active: ${position[8]}`);
this.logger.log(`Position token type: ${position[9]}`);

return {
user: position[0],
collateralToken: position[1],
collateralAmount: position[2],
usdcBorrowed: position[3],
tokenValueUSD: position[4],
createdAt: position[5],
active: position[6],
tokenType: position[7],
liquidatedAt: position[6],
creditLineId: position[7],
active: position[8],
tokenType: position[9],
};
}

Expand Down