Skip to content

Commit

Permalink
setup factoringEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
solidoracle committed Apr 25, 2024
1 parent dc65803 commit 307f597
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions bulla-contracts/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ type User @entity {
instantPayments: [InstantPayment!]!
financeEvents: [IEventLog!]!
frendLendEvents: [IEventLog!]!
factoringEvents: [IEventLog!]!
}

type BullaManager @entity {
Expand Down
1 change: 1 addition & 0 deletions bulla-contracts/src/functions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const getOrCreateUser = (address: Address): User => {
user.instantPayments = [];
user.financeEvents = [];
user.frendLendEvents = [];
user.factoringEvents = [];
user.save();
}

Expand Down
34 changes: 33 additions & 1 deletion bulla-contracts/src/mappings/BullaFactoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
createSharesRedeemedEvent,
createSharesRedeemedWithAttachmentEvent
} from "../functions/BullaFactoring";
import { getIPFSHash_depositWithAttachment, getIPFSHash_redeemWithAttachment } from "../functions/common";
import { getIPFSHash_depositWithAttachment, getIPFSHash_redeemWithAttachment, getOrCreateUser } from "../functions/common";

export function handleInvoiceFunded(event: InvoiceFunded): void {
const ev = event.params;
Expand All @@ -29,14 +29,18 @@ export function handleInvoiceFunded(event: InvoiceFunded): void {
InvoiceFundedEvent.invoiceId = underlyingClaim.id;
InvoiceFundedEvent.fundedAmount = ev.fundedAmount;
InvoiceFundedEvent.originalCreditor = ev.originalCreditor;
const original_creditor = getOrCreateUser(ev.originalCreditor);

InvoiceFundedEvent.eventName = "InvoiceFunded";
InvoiceFundedEvent.blockNumber = event.block.number;
InvoiceFundedEvent.transactionHash = event.transaction.hash;
InvoiceFundedEvent.logIndex = event.logIndex;
InvoiceFundedEvent.timestamp = event.block.timestamp;

original_creditor.factoringEvents = original_creditor.factoringEvents ? original_creditor.factoringEvents.concat([InvoiceFundedEvent.id]) : [InvoiceFundedEvent.id];

InvoiceFundedEvent.save();
original_creditor.save();
}

export function handleInvoiceKickbackAmountSent(event: InvoiceKickbackAmountSent): void {
Expand All @@ -49,14 +53,20 @@ export function handleInvoiceKickbackAmountSent(event: InvoiceKickbackAmountSent
InvoiceKickbackAmountSentEvent.invoiceId = underlyingClaim.id;
InvoiceKickbackAmountSentEvent.kickbackAmount = ev.kickbackAmount;
InvoiceKickbackAmountSentEvent.originalCreditor = ev.originalCreditor;
const original_creditor = getOrCreateUser(ev.originalCreditor);

InvoiceKickbackAmountSentEvent.eventName = "InvoiceKickbackAmountSent";
InvoiceKickbackAmountSentEvent.blockNumber = event.block.number;
InvoiceKickbackAmountSentEvent.transactionHash = event.transaction.hash;
InvoiceKickbackAmountSentEvent.logIndex = event.logIndex;
InvoiceKickbackAmountSentEvent.timestamp = event.block.timestamp;

original_creditor.factoringEvents = original_creditor.factoringEvents
? original_creditor.factoringEvents.concat([InvoiceKickbackAmountSentEvent.id])
: [InvoiceKickbackAmountSentEvent.id];

InvoiceKickbackAmountSentEvent.save();
original_creditor.save();
}

export function handleInvoiceUnfactored(event: InvoiceUnfactored): void {
Expand All @@ -68,14 +78,20 @@ export function handleInvoiceUnfactored(event: InvoiceUnfactored): void {

InvoiceUnfactoredEvent.invoiceId = underlyingClaim.id;
InvoiceUnfactoredEvent.originalCreditor = ev.originalCreditor;
const original_creditor = getOrCreateUser(ev.originalCreditor);

InvoiceUnfactoredEvent.eventName = "InvoiceUnfactored";
InvoiceUnfactoredEvent.blockNumber = event.block.number;
InvoiceUnfactoredEvent.transactionHash = event.transaction.hash;
InvoiceUnfactoredEvent.logIndex = event.logIndex;
InvoiceUnfactoredEvent.timestamp = event.block.timestamp;

original_creditor.factoringEvents = original_creditor.factoringEvents
? original_creditor.factoringEvents.concat([InvoiceUnfactoredEvent.id])
: [InvoiceUnfactoredEvent.id];

InvoiceUnfactoredEvent.save();
original_creditor.save();
}

export function handleDepositMade(event: DepositMade): void {
Expand All @@ -87,14 +103,18 @@ export function handleDepositMade(event: DepositMade): void {
DepositMadeEvent.depositor = ev.depositor;
DepositMadeEvent.assets = ev.assets;
DepositMadeEvent.sharesIssued = ev.sharesIssued;
const investor = getOrCreateUser(ev.depositor);

DepositMadeEvent.eventName = "DepositMade";
DepositMadeEvent.blockNumber = event.block.number;
DepositMadeEvent.transactionHash = event.transaction.hash;
DepositMadeEvent.logIndex = event.logIndex;
DepositMadeEvent.timestamp = event.block.timestamp;

investor.factoringEvents = investor.factoringEvents ? investor.factoringEvents.concat([DepositMadeEvent.id]) : [DepositMadeEvent.id];

DepositMadeEvent.save();
investor.save();
}

export function handleDepositMadeWithAttachment(event: DepositMadeWithAttachment): void {
Expand All @@ -107,14 +127,18 @@ export function handleDepositMadeWithAttachment(event: DepositMadeWithAttachment
DepositMadeWithAttachmentEvent.assets = ev.assets;
DepositMadeWithAttachmentEvent.sharesIssued = ev.shares;
DepositMadeWithAttachmentEvent.ipfsHash = getIPFSHash_depositWithAttachment(ev.attachment);
const investor = getOrCreateUser(ev.depositor);

DepositMadeWithAttachmentEvent.eventName = "DepositMadeWithAttachment";
DepositMadeWithAttachmentEvent.blockNumber = event.block.number;
DepositMadeWithAttachmentEvent.transactionHash = event.transaction.hash;
DepositMadeWithAttachmentEvent.logIndex = event.logIndex;
DepositMadeWithAttachmentEvent.timestamp = event.block.timestamp;

investor.factoringEvents = investor.factoringEvents ? investor.factoringEvents.concat([DepositMadeWithAttachmentEvent.id]) : [DepositMadeWithAttachmentEvent.id];

DepositMadeWithAttachmentEvent.save();
investor.save();
}

export function handleSharesRedeemed(event: SharesRedeemed): void {
Expand All @@ -126,14 +150,18 @@ export function handleSharesRedeemed(event: SharesRedeemed): void {
SharesRedeemedEvent.redeemer = ev.redeemer;
SharesRedeemedEvent.assets = ev.assets;
SharesRedeemedEvent.shares = ev.shares;
const investor = getOrCreateUser(ev.redeemer);

SharesRedeemedEvent.eventName = "SharesRedeemed";
SharesRedeemedEvent.blockNumber = event.block.number;
SharesRedeemedEvent.transactionHash = event.transaction.hash;
SharesRedeemedEvent.logIndex = event.logIndex;
SharesRedeemedEvent.timestamp = event.block.timestamp;

investor.factoringEvents = investor.factoringEvents ? investor.factoringEvents.concat([SharesRedeemedEvent.id]) : [SharesRedeemedEvent.id];

SharesRedeemedEvent.save();
investor.save();
}

export function handleSharesRedeemedWithAttachment(event: SharesRedeemedWithAttachment): void {
Expand All @@ -146,12 +174,16 @@ export function handleSharesRedeemedWithAttachment(event: SharesRedeemedWithAtta
SharesRedeemedWithAttachmentEvent.assets = ev.assets;
SharesRedeemedWithAttachmentEvent.shares = ev.shares;
SharesRedeemedWithAttachmentEvent.ipfsHash = getIPFSHash_redeemWithAttachment(ev.attachment);
const investor = getOrCreateUser(ev.redeemer);

SharesRedeemedWithAttachmentEvent.eventName = "SharesRedeemedWithAttachment";
SharesRedeemedWithAttachmentEvent.blockNumber = event.block.number;
SharesRedeemedWithAttachmentEvent.transactionHash = event.transaction.hash;
SharesRedeemedWithAttachmentEvent.logIndex = event.logIndex;
SharesRedeemedWithAttachmentEvent.timestamp = event.block.timestamp;

investor.factoringEvents = investor.factoringEvents ? investor.factoringEvents.concat([SharesRedeemedWithAttachmentEvent.id]) : [SharesRedeemedWithAttachmentEvent.id];

SharesRedeemedWithAttachmentEvent.save();
investor.save();
}

0 comments on commit 307f597

Please sign in to comment.