Skip to content

Commit

Permalink
feat:subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
bl0up committed Apr 26, 2024
1 parent db0667b commit 3f9a4f1
Show file tree
Hide file tree
Showing 10 changed files with 1,276 additions and 160 deletions.
429 changes: 429 additions & 0 deletions subgraph/datasources/diamond.gql.json

Large diffs are not rendered by default.

624 changes: 624 additions & 0 deletions subgraph/datasources/diamond.ts

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions subgraph/datasources/diamond.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
- kind: ethereum/contract
name: {id}
network: {chain}
source:
address: "{address}"
abi: BondFacet
startBlock: {startBlock}
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
entities:
- BondFacet
abis:
- name: BondFacet
file: {root}/abi/BondFacet.json
eventHandlers:
- event: BondInitialized(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256)
handler: handleBondInitialized
- event: BondParametersEdited(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256)
handler: handleBondParametersEdited
- event: CouponsComputed(uint256,uint256[],uint256[],uint256[],uint256[],uint256[])
handler: handleCouponsComputed
- event: BondIssued(uint256,uint256,uint256)
handler: handleBondIssued
- event: BondsWithdrawn(string,uint256,address,uint256)
handler: handleBondsWithdrawn
- event: BalloonRateSet(uint256,uint256,uint256)
handler: handleBalloonRateSet
- event: GracePeriodSet(uint256,uint256)
handler: handleGracePeriodSet
- event: CapitalAmortizationFreePeriodSet(uint256,uint256)
handler: handleCapitalAmortizationFreePeriodSet
- event: InvestorsCountChanged(uint256,uint256)
handler: handleInvestorsCountChanged
- event: CampaignStartAndEndDateSet(uint256,uint256,uint256)
handler: handleCampaignStartAndEndDateSet
- event: CampaignPaused(uint256)
handler: handleCampaignPaused
- event: CampaignUnpaused(uint256)
handler: handleCampaignUnpaused
- event: MinAndMaxAmountSet(uint256,uint256,uint256,uint256)
handler: handleMinAndMaxAmountSet
- event: IssueDateSet(uint256,uint256)
handler: handleIssueDateSet
- event: BondTransferred(string,uint256,address,address,uint256)
handler: handleBondTransferred
- event: ReservedAmountChanged(uint256,uint256)
handler: handleReservedAmountChanged
- event: CouponStatusChanged(uint256,uint256)
handler: handleCouponStatusChanged
file: {file}
Empty file added subgraph/fetch/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions subgraph/fetch/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Address, Bytes } from '@graphprotocol/graph-ts';
import { Account } from '../../generated/schema';

export function fetchAccount(address: Address): Account {
const account = new Account(Bytes.fromHexString(address.toHex()));
account.save();
return account;
}
137 changes: 137 additions & 0 deletions subgraph/fetch/diamond.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts';
import { Bond, BondFacet, CouponList, Holder, Transfer } from '../../generated/schema';
import { fetchAccount } from './account';

export function fetchBondFacet(address: Address, facetOffset: string): BondFacet {
const account = fetchAccount(address);
const contractId = account.id.toHex().concat('/').concat(facetOffset);
//let contract = BondFacet.load(account.id.toHex());
let contract = BondFacet.load(contractId);

if (contract == null) {
//contract = new BondFacet(account.id.toHex());
contract = new BondFacet(contractId);
account.asBondFacet = contractId;
//account.asBondFacet = contract.id;
//contract.asAccount = account.id.toHex();

contract.save();
account.save();
}

return contract as BondFacet;
}

export function fetchCouponList(contract: BondFacet, bondId: string): CouponList {
let couponList = CouponList.load(bondId);
if (couponList == null) {
couponList = new CouponList(bondId);
couponList.contract = contract.id;
couponList.remainingCapital = [];
couponList.capitalRepayment = [];
couponList.grossInterestRate = [];
couponList.netInterestRate = [];
couponList.grossInterest = [];
couponList.netInterest = [];
couponList.stepUp = [];
couponList.stepDown = [];
couponList.fee = [];
couponList.capitalAndInterest = [];
couponList.couponDate = [];
couponList.newCouponDate = [];
couponList.feeAmount = [];
couponList.status = [];
couponList.totalToBeRepaid = BigDecimal.fromString('0');
couponList.totalAmountRepaid = BigDecimal.fromString('0');
couponList.capitalRepaid = BigDecimal.fromString('0');
couponList.interestRepaid = BigDecimal.fromString('0');
couponList.interestTotal = BigDecimal.fromString('0');
couponList.save();
}
return couponList as CouponList;
}

export function fetchHolder(contract: BondFacet, account: Address, bondId: string): Holder {
const holderId = account.toString().concat('/').concat(bondId);
let holder = Holder.load(holderId);

if (holder == null) {
holder = new Holder(holderId);
holder.contract = contract.id;
holder.account = account;
holder.amount = BigInt.fromString('0');
holder.bondId = bondId;
holder.dateOfOwnership = BigInt.fromString('0');
holder.save();
}
return holder;
}

export function fetchTransfer(contract: BondFacet, transferId: string): Transfer {
//const transferId = bondId.concat('/').concat(from).concat('/').concat(to).concat('/').concat(timestamp);
let transfer = Transfer.load(transferId);
if (transfer == null) {
transfer = new Transfer(transferId);
transfer.bondTransferId = transferId;
transfer.contract = contract.id;
transfer.bondId = '';
transfer.transferDate = BigInt.fromString('0');
transfer.amount = BigInt.fromString('0');
transfer.save();
}
return transfer;
}

export function fetchBond(contract: BondFacet, bondId: string): Bond {
let bond = Bond.load(bondId);
if (bond == null) {
bond = new Bond(bondId);
bond.contract = contract.id;
bond.coupure = BigInt.fromString('0');
bond.grossInterestRate = BigDecimal.fromString('0');
bond.netReturn = BigDecimal.fromString('0');
bond.withholdingTaxRate = BigDecimal.fromString('0');
bond.periodicInterestRate = BigDecimal.fromString('0');
bond.holders = [];
bond.holdersAmount = [];
bond.reservationsByAddresses = [];
bond.reservedAmountByAddresses = [];
bond.reservedAmount = BigInt.fromString('0');
bond.periodicity = '';
bond.methodOfRepayment = '';
bond.duration = BigInt.fromString('0');
bond.gracePeriod = BigInt.fromString('0');
bond.balloonPercentage = BigDecimal.fromString('0');
bond.capitalAmortizationFreePeriod = BigInt.fromString('0');
bond.costEmittent = BigDecimal.fromString('0');
bond.investorsCount = BigInt.fromString('0');
bond.revocationsCount = BigInt.fromString('0');
bond.campaignStartDate = BigInt.fromString('0');
bond.campaignEndDate = BigInt.fromString('0');
bond.paused = false;
bond.maxSupply = BigDecimal.fromString('0');
bond.maxAmountPerInvestor = BigDecimal.fromString('0');
bond.campaignStartDate = BigInt.fromString('0');
bond.campaignEndDate = BigInt.fromString('0');
bond.maxAmount = BigInt.fromString('0');
bond.minAmount = BigInt.fromString('0');
bond.issueDate = BigInt.fromString('0');
bond.formOfFinancing = '';
bond.status = '';
bond.withdrawRef = '';
bond.cancelRef = '';
bond.terminated = false;
bond.isReplacementBond = false;
//bond.hashLockCancel =Bytes.fromHexString('');
//bond.hashLockWithdraw = Bytes.fromHexString('');

bond.withdrawStartTime = BigInt.fromString('0');
bond.withdrawEndTime = BigInt.fromString('0');
bond.cancelStartTime = BigInt.fromString('0');
bond.cancelEndTime = BigInt.fromString('0');
bond.issuedAmount = BigInt.fromString('0');
bond.totalAmountOfAssignedBonds = BigInt.fromString('0');
bond.save();
}
return bond as Bond;
}
19 changes: 19 additions & 0 deletions subgraph/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "solidity-token-diamond-bond",
"version": "7.0.0",
"description": "Solidity Token Diamond Bond",
"scripts": {},
"keywords": [
"solidity",
"subgraph"
],
"author": "SettleMint <[email protected]>",
"license": "MIT",
"dependencies": {
"@amxx/graphprotocol-utils": "1.1.0",
"@graphprotocol/graph-cli": "0.71.0",
"@graphprotocol/graph-ts": "0.35.1",
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/subgraphs": "0.1.8-5"
}
}
7 changes: 7 additions & 0 deletions subgraph/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@graphprotocol/graph-ts/types/tsconfig.base.json",
"include": [
"datasources",
"fetch"
]
}
33 changes: 0 additions & 33 deletions tasks/extract-selectors.ts

This file was deleted.

127 changes: 0 additions & 127 deletions test/Lock.ts

This file was deleted.

0 comments on commit 3f9a4f1

Please sign in to comment.