Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
solidoracle committed Oct 7, 2024
1 parent 63e32b1 commit ec51958
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 1,056 deletions.
8 changes: 5 additions & 3 deletions bulla-contracts/src/functions/BullaFactoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import {
} from "../../generated/schema";
import {
Deposit,
DepositMadeWithAttachment,
InvoiceFunded,
InvoiceImpaired,
InvoiceKickbackAmountSent,
InvoicePaid,
InvoiceUnfactored,
SharesRedeemedWithAttachment,
Withdraw
} from "../../generated/BullaFactoring/BullaFactoring";
} from "../../generated/BullaFactoringv2/BullaFactoringv2";
import { InvoiceUnfactored as InvoiceUnfactoredV1 } from "../../generated/BullaFactoring/BullaFactoring";

export const getInvoiceFundedEventId = (underlyingClaimId: BigInt, event: ethereum.Event): string =>
"InvoiceFunded-" + underlyingClaimId.toString() + "-" + event.transaction.hash.toHexString() + "-" + event.logIndex.toString();
Expand All @@ -42,6 +41,9 @@ export const createInvoicePaidEvent = (underlyingTokenId: BigInt, event: Invoice
export const getInvoiceUnfactoredEventId = (underlyingClaimId: BigInt, event: ethereum.Event): string =>
"InvoiceUnfactored-" + underlyingClaimId.toString() + "-" + event.transaction.hash.toHexString() + "-" + event.logIndex.toString();

export const createInvoiceUnfactoredEventv1 = (underlyingTokenId: BigInt, event: InvoiceUnfactoredV1): InvoiceUnfactoredEvent =>
new InvoiceUnfactoredEvent(getInvoiceUnfactoredEventId(underlyingTokenId, event));

export const createInvoiceUnfactoredEvent = (underlyingTokenId: BigInt, event: InvoiceUnfactored): InvoiceUnfactoredEvent =>
new InvoiceUnfactoredEvent(getInvoiceUnfactoredEventId(underlyingTokenId, event));

Expand Down
64 changes: 0 additions & 64 deletions bulla-contracts/src/functions/BullaFactoringv2.ts

This file was deleted.

22 changes: 2 additions & 20 deletions bulla-contracts/src/functions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ import {
PoolPnl,
PnlHistoryEntry
} from "../../generated/schema";
import { BullaFactoring as BullaFactoringv1 } from "../../generated/BullaFactoring/BullaFactoring";
import {
BullaFactoring__getFundInfoResultValue0Struct,
BullaFactoring as BullaFactoringv1,
BullaFactoringv2,
DepositMadeWithAttachmentAttachmentStruct,
SharesRedeemedWithAttachmentAttachmentStruct
} from "../../generated/BullaFactoring/BullaFactoring";
import {
BullaFactoringv2,
BullaFactoringv2__getFundInfoResultValue0Struct,
DepositMadeWithAttachmentAttachmentStruct as DepositMadeWithAttachmentAttachmentStructV2,
SharesRedeemedWithAttachmentAttachmentStruct as SharesRedeemedWithAttachmentAttachmentStructV2
} from "../../generated/BullaFactoringv2/BullaFactoringv2";
import { BigInt } from "@graphprotocol/graph-ts";

Expand Down Expand Up @@ -92,18 +86,6 @@ export const getIPFSHash_redeemWithAttachment = (attachment: SharesRedeemedWithA
return ipfsHash;
};

export const getIPFSHash_depositWithAttachment_v2 = (attachment: DepositMadeWithAttachmentAttachmentStructV2): string | null => {
if (attachment.hash.equals(Bytes.fromHexString(EMPTY_BYTES32))) return null;
const ipfsHash = multihashStructToBase58(attachment.hash, attachment.size, attachment.hashFunction);
return ipfsHash;
};

export const getIPFSHash_redeemWithAttachment_v2 = (attachment: SharesRedeemedWithAttachmentAttachmentStructV2): string | null => {
if (attachment.hash.equals(Bytes.fromHexString(EMPTY_BYTES32))) return null;
const ipfsHash = multihashStructToBase58(attachment.hash, attachment.size, attachment.hashFunction);
return ipfsHash;
};

export const getOrCreateUser = (address: Address): User => {
let user = User.load(address.toHexString());
if (!user) {
Expand Down
40 changes: 38 additions & 2 deletions bulla-contracts/src/mappings/BullaFactoring.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { log } from "matchstick-as";
import {
Deposit,
DepositMadeWithAttachment,
Expand All @@ -10,7 +9,8 @@ import {
InvoiceUnfactored,
SharesRedeemedWithAttachment,
Withdraw
} from "../../generated/BullaFactoring/BullaFactoring";
} from "../../generated/BullaFactoringv2/BullaFactoringv2";
import { InvoiceUnfactored as InvoiceUnfactoredV1 } from "../../generated/BullaFactoring/BullaFactoring";
import { getClaim } from "../functions/BullaClaimERC721";
import {
createDepositMadeEvent,
Expand All @@ -19,6 +19,7 @@ import {
createInvoiceKickbackAmountSentEvent,
createInvoicePaidEvent,
createInvoiceUnfactoredEvent,
createInvoiceUnfactoredEventv1,
createSharesRedeemedEvent,
getDepositMadeEventId,
getSharesRedeemedEventId
Expand Down Expand Up @@ -157,6 +158,41 @@ export function handleInvoiceUnfactored(event: InvoiceUnfactored): void {
const latestPrice = getLatestPrice(event, "v1");
const historical_factoring_statistics = getOrCreateHistoricalFactoringStatistics(event, "v1");

InvoiceUnfactoredEvent.eventName = "InvoiceUnfactored";
InvoiceUnfactoredEvent.blockNumber = event.block.number;
InvoiceUnfactoredEvent.transactionHash = event.transaction.hash;
InvoiceUnfactoredEvent.logIndex = event.logIndex;
InvoiceUnfactoredEvent.totalRefundAmount = ev.totalRefundOrPaymentAmount;
InvoiceUnfactoredEvent.interestToCharge = ev.interestToCharge;
InvoiceUnfactoredEvent.timestamp = event.block.timestamp;
InvoiceUnfactoredEvent.poolAddress = event.address;
InvoiceUnfactoredEvent.priceAfterTransaction = latestPrice;
InvoiceUnfactoredEvent.claim = underlyingClaim.id;

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

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

export function handleInvoiceUnfactoredV1(event: InvoiceUnfactoredV1): void {
const ev = event.params;
const originatingClaimId = ev.invoiceId;

const underlyingClaim = getClaim(originatingClaimId.toString());
const InvoiceUnfactoredEvent = createInvoiceUnfactoredEventv1(originatingClaimId, event);

InvoiceUnfactoredEvent.invoiceId = underlyingClaim.id;
InvoiceUnfactoredEvent.originalCreditor = ev.originalCreditor;
const original_creditor = getOrCreateUser(ev.originalCreditor);
const price_per_share = getOrCreatePricePerShare(event, "v1");
const latestPrice = getLatestPrice(event, "v1");
const historical_factoring_statistics = getOrCreateHistoricalFactoringStatistics(event, "v1");

InvoiceUnfactoredEvent.eventName = "InvoiceUnfactored";
InvoiceUnfactoredEvent.blockNumber = event.block.number;
InvoiceUnfactoredEvent.transactionHash = event.transaction.hash;
Expand Down
Loading

0 comments on commit ec51958

Please sign in to comment.