Skip to content

Commit

Permalink
add Claim and Payout models with corresponding types and event proces…
Browse files Browse the repository at this point in the history
…sing
  • Loading branch information
doerfli committed Nov 21, 2024
1 parent 1422ce3 commit 7a29f11
Show file tree
Hide file tree
Showing 8 changed files with 609 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "ts-node-dev src/main.ts",
"build": " tsc --project tsconfig.json",
"postinstall": "$npm_execpath run typechainGif",
"typechainGif": "D=./node_modules/@etherisc/gif-next/artifacts/contracts/ && typechain --target ethers-v6 --out-dir src/generated/contracts/gif $D/product/IRiskService.sol/IRiskService.json $D/product/IApplicationService.sol/IApplicationService.json $D/product/IPolicyService.sol/IPolicyService.json $D/pool/IPoolService.sol/IPoolService.json $D/pool/IBundleService.sol/IBundleService.json $D/oracle/IOracleService.sol/IOracleService.json $D/registry/ChainNft.sol/ChainNft.json $D/registry/IRegistry.sol/IRegistry.json $D/instance/IInstance.sol/IInstance.json $D/instance/IInstanceService.sol/IInstanceService.json $D/instance/InstanceReader.sol/InstanceReader.json $D/instance/module/IPolicy.sol/IPolicy.json $D/instance/module/IRisk.sol/IRisk.json $D/shared/IComponentService.sol/IComponentService.json"
"typechainGif": "D=./node_modules/@etherisc/gif-next/artifacts/contracts/ && typechain --target ethers-v6 --out-dir src/generated/contracts/gif $D/product/IRiskService.sol/IRiskService.json $D/product/IApplicationService.sol/IApplicationService.json $D/product/IPolicyService.sol/IPolicyService.json $D/pool/IPoolService.sol/IPoolService.json $D/pool/IBundleService.sol/IBundleService.json $D/oracle/IOracleService.sol/IOracleService.json $D/registry/ChainNft.sol/ChainNft.json $D/registry/IRegistry.sol/IRegistry.json $D/instance/IInstance.sol/IInstance.json $D/instance/IInstanceService.sol/IInstanceService.json $D/instance/InstanceReader.sol/InstanceReader.json $D/instance/module/IPolicy.sol/IPolicy.json $D/instance/module/IRisk.sol/IRisk.json $D/shared/IComponentService.sol/IComponentService.json $D/product/IClaimService.sol/IClaimService.json"
},
"author": "",
"license": "Apache-2.0",
Expand Down
17 changes: 0 additions & 17 deletions prisma/migrations/20241119154054_init/migration.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,61 @@ CREATE TABLE "Component" (

CONSTRAINT "Component_pkey" PRIMARY KEY ("nftId")
);

-- CreateTable
CREATE TABLE "Risk" (
"productNftId" BIGINT NOT NULL,
"riskId" TEXT NOT NULL,
"locked" BOOLEAN NOT NULL DEFAULT false,
"closed" BOOLEAN NOT NULL DEFAULT false,
"created_blockNumber" INTEGER NOT NULL,
"created_timestamp" BIGINT NOT NULL,
"created_txHash" TEXT NOT NULL,
"created_from" TEXT NOT NULL,
"modified_blockNumber" INTEGER NOT NULL,
"modified_timestamp" BIGINT NOT NULL,
"modified_txHash" TEXT NOT NULL,
"modified_from" TEXT NOT NULL,

CONSTRAINT "Risk_pkey" PRIMARY KEY ("productNftId","riskId")
);

-- CreateTable
CREATE TABLE "Claim" (
"policyNftId" BIGINT NOT NULL,
"claimId" BIGINT NOT NULL,
"claimAmount" BIGINT NOT NULL,
"confirmedAmount" BIGINT NOT NULL,
"state" INTEGER NOT NULL,
"created_blockNumber" INTEGER NOT NULL,
"created_timestamp" BIGINT NOT NULL,
"created_txHash" TEXT NOT NULL,
"created_from" TEXT NOT NULL,
"modified_blockNumber" INTEGER NOT NULL,
"modified_timestamp" BIGINT NOT NULL,
"modified_txHash" TEXT NOT NULL,
"modified_from" TEXT NOT NULL,

CONSTRAINT "Claim_pkey" PRIMARY KEY ("policyNftId","claimId")
);

-- CreateTable
CREATE TABLE "Payout" (
"policyNftId" BIGINT NOT NULL,
"payoutId" BIGINT NOT NULL,
"claimId" BIGINT NOT NULL,
"beneficiary" TEXT NOT NULL,
"payoutAmount" BIGINT NOT NULL,
"paidAmount" BIGINT NOT NULL,
"cancelled" BOOLEAN NOT NULL,
"created_blockNumber" INTEGER NOT NULL,
"created_timestamp" BIGINT NOT NULL,
"created_txHash" TEXT NOT NULL,
"created_from" TEXT NOT NULL,
"modified_blockNumber" INTEGER NOT NULL,
"modified_timestamp" BIGINT NOT NULL,
"modified_txHash" TEXT NOT NULL,
"modified_from" TEXT NOT NULL,

CONSTRAINT "Payout_pkey" PRIMARY KEY ("policyNftId","payoutId")
);
40 changes: 39 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,42 @@ model Risk {
// compound primary key
@@id([productNftId, riskId])
}
}

model Claim {
policyNftId BigInt
claimId BigInt
claimAmount BigInt
confirmedAmount BigInt
state Int
created_blockNumber Int
created_timestamp BigInt
created_txHash String
created_from String
modified_blockNumber Int
modified_timestamp BigInt
modified_txHash String
modified_from String
@@id([policyNftId, claimId])
}

model Payout {
policyNftId BigInt
payoutId BigInt
claimId BigInt
beneficiary String
payoutAmount BigInt
paidAmount BigInt
cancelled Boolean
created_blockNumber Int
created_timestamp BigInt
created_txHash String
created_from String
modified_blockNumber Int
modified_timestamp BigInt
modified_txHash String
modified_from String
@@id([policyNftId, payoutId])
}
48 changes: 46 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import ComponentProcessor from './component_processor';
import { Component } from './types/component';
import RiskProcessor from './risk_processor';
import { Risk } from './types/risk';
import { Claim } from './types/claim';
import { Payout } from './types/payout';

dotenv.config();

Expand Down Expand Up @@ -44,13 +46,15 @@ class Main {

public async main(): Promise<void> {
const gifEvents = await this.dune.getLatestResult(DUNE_QUERY_ID_GIF_EVENTS, 0);
const { nfts, instances, policies, components, risks } = await this.parseGifEvents(gifEvents);
const { nfts, instances, policies, components, risks, claims, payouts } = await this.parseGifEvents(gifEvents);

await this.nftProcessor.persistNfts(Array.from(nfts.values()));
await this.instanceProcessor.persistInstances(Array.from(instances.values()));
await this.policyProcessor.persistPolicies(Array.from(policies.values()));
await this.componentProcessor.persistComponents(Array.from(components.values()));
await this.riskProcessor.persistRisks(Array.from(risks.values()));
await this.policyProcessor.persistClaims(Array.from(claims.values()));
await this.policyProcessor.persistPayouts(Array.from(payouts.values()));

for (const nft of nfts.values()) {
logger.info(`NFT: ${nft.nftId} - ${ObjectType[nft.objectType]} - ${nft.objectAddress} - ${nft.owner}`);
Expand All @@ -60,9 +64,21 @@ class Main {
logger.info(`Instance: ${instance.nftId} - ${instance.instanceAddress}`);
}

for (const risk of risks.values()) {
logger.info(`Risk: ${risk.productNftId} - ${risk.riskId} - ${risk.locked} - ${risk.closed}`);
}

for (const policy of policies.values()) {
logger.info(`Policy: ${policy.nftId} - ${policy.riskId} - ${policy.sumInsuredAmount}`);
}

for (const claim of claims.values()) {
logger.info(`Claim: ${claim.policyNftId} ${claim.claimId} - ${claim.claimAmount}`);
}

for (const payout of payouts.values()) {
logger.info(`Payout: ${payout.policyNftId} ${payout.payoutId} - ${payout.payoutAmount}`);
}
}

async parseGifEvents(gifEvents: Array<DecodedLogEntry>)
Expand All @@ -72,13 +88,17 @@ class Main {
policies: Map<BigInt, Policy>,
components: Map<BigInt, Component>,
risks: Map<string, Risk>,
claims: Map<string, Claim>,
payouts: Map<string, Payout>,
}>
{
const nfts = new Map<BigInt, Nft>();
const instances = new Map<BigInt, Instance>();
const components = new Map<BigInt, Component>();
const risks = new Map<string, Risk>();
const policies = new Map<BigInt, Policy>();
const claims = new Map<string, Claim>();
const payouts = new Map<string, Payout>();

for (const event of gifEvents) {
// logger.debug(`Processing gif event ${event.tx_hash} - ${event.block_number} - ${event.event_name}`);
Expand Down Expand Up @@ -126,13 +146,37 @@ class Main {
case 'LogPolicyServicePolicyClosed':
await this.policyProcessor.processPolicyClosedEvent(event, policies);
break;
case 'LogClaimServiceClaimSubmitted':
await this.policyProcessor.processClaimSubmittedEvent(event, policies, claims);
break;
case 'LogClaimServiceClaimConfirmed':
await this.policyProcessor.processClaimConfirmedEvent(event, claims);
break;
case 'LogClaimServiceClaimDeclined':
await this.policyProcessor.processClaimDeclinedEvent(event, claims);
break;
case 'LogClaimServiceClaimRevoked':
await this.policyProcessor.processClaimRevokedEvent(event, claims);
break;
case 'LogClaimServiceClaimCancelled':
await this.policyProcessor.processClaimCancelledEvent(event, claims);
break;
case 'LogClaimServicePayoutCreated':
await this.policyProcessor.processPayoutCreatedEvent(event, policies, claims, payouts);
break;
case 'LogClaimServicePayoutProcessed':
await this.policyProcessor.processPayoutProcessedEvent(event, payouts);
break;
case 'LogClaimServicePayoutCancelled':
await this.policyProcessor.processPayoutCancelledEvent(event, payouts);
break;

default:
logger.info('Unhandeled event: ' + event.event_name);
}
}

return { nfts, instances, policies, components, risks };
return { nfts, instances, policies, components, risks, claims, payouts };
}
}

Expand Down
Loading

0 comments on commit 7a29f11

Please sign in to comment.