Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
20221026 Integrate progress until sprint 14 (#22)
Browse files Browse the repository at this point in the history
* 74 index loanentity data types (#86)

* feat: create loanService

* refactor: improved service getters

* feat: increase outstandingDebt on borrowings

* feat: basics for handle loan prices

* feat: save priced loans

* feat: activate loan when priced

* feat: handle writeoffs

* feat: handle loan closed and write offs

* fix: loan.repay() should increase totalRepaid

* fix: invest execution decimals and avoid empty transactions (#87)

* 82 add prices to all investortransaction types (#88)

* chore: update chain data

* feat: extend InvestorTransaction decoration and refactor

* feat: use rpc prices from trancheTokenPrices() when investor transactions are processed (#89)

* feat: improved loans and borrower transactions (#90)

* 63 convert outflows to dai (#91)

* feat: add currency value for redeem fields

* fix: currency conversion should support null prices

* 98 failing poolservicegettranchetokenprices causes period to be skipped for remaining pools (#99)

* ci: fix deployment version

* fix: handle missing price updates from RPC

* fix: throw errors on missing prices

* feat: aggregate total investments and repayments for epoches (#100)

* feat: index accounts and tranche balances (#101)

* docs: add deployment status badge

* Update README.md

docs: fix badge link to deployment workflow

* feat: tracking loans history with state snapshot (#102)

* 56 handle updates to pool information poolsupdated event (#106)

* chore: upgraded packages

* feat: track pool updates

* 103 totalinvested  and totalredeemed  are missing in poolsnapshot (#107)

* fix: add missing properties to snapshot

* deploy: update node and query versions

* fix: pool investment and redemptions totals

* feat: indexing missing values (#108)

* ci: updated deployment

* ci: upgraded packages

* feat: paginated getters for snapshots and models (#109)

* chore: upgrade packages

* 104 track currency balances for accounts (#111)

* feat: add data model for currency balances

* feat: track endowments withdrawals and deposits of currency

* feat: get initial balance on currency balance init

* ci: revert subql/node version

* 112 develop suitable unit testing approach (#117)

* test: fundamental approach

* test: poolHandlers testing

* test: run pools and tranche tests in CI

* test: include generation of entities

* ci: execute testing in correct order

* docs: updated data model diagram (#118)

* 115 extend kpis as from spreadsheet (#119)

* feat: aggregate loan writeoffs and total overdue

* feat: index additional data

* chore: remove unnecessary imports

* feat: parse and index loanSpecs

* fix: indexing of overdue amount

Co-authored-by: Timon <timon@embrio.tech>
  • Loading branch information
filo87 and tibohei authored Nov 8, 2022
1 parent 1204d7d commit 514d398
Show file tree
Hide file tree
Showing 21 changed files with 3,578 additions and 671 deletions.
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export DB_USER=postgres
export DB_PASS=postgres
export DB_DATABASE=postgres
export DB_HOST=localhost
export DB_PORT=5432
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,23 @@ jobs:
node-version: '16'
- name: 'Install Dependencies'
run: yarn install
- name: 'Generate Entities'
run: yarn codegen
- name: 'Run Linter'
run: yarn lint
test:
name: 'Run Tests'
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Setup Node'
uses: actions/setup-node@v3
with:
node-version: '16'
- name: 'Install Dependencies'
run: yarn install
- name: 'Generate Entities'
run: yarn codegen
- name: 'Run Tests'
run: yarn test
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Debug SubQL Node",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/subql-node", "-f", "${workspaceRoot}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
164 changes: 15 additions & 149 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Use GraphQL query endpoint at [https://api.subquery.network/sq/embrio-tech/centr
- node: version specified in [`.nvmrc`](/.nvmrc)
- [Yarn](https://classic.yarnpkg.com/en/)


### Code generation

To generate the entities based on `schema.graphql`, run:
Expand Down Expand Up @@ -72,172 +71,39 @@ This repository uses commitlint to enforce commit message conventions. You have

```mermaid
erDiagram
Timekeeper {
string id PK
date lastPeriodStart
}
Pool ||--|| PoolState: ""
Pool {
String id PK
String type "idx"
Date timestamp
Int blockNumber
Account ||--o{ TrancheBalance: ""
Account ||--o{ CurrencyBalance: ""
String currency
String metadata
Int minEpochTime
Int maxNavAge
Int currentEpoch
Int lastEpochClosed
Int lastEpochExecuted
String stateId FK
}
Loan ||--|| LoanState: ""
Loan ||--o{ LoanSnapshot: ""
LoanState ||..|| LoanSnapshot: "onNewPeriod"
Pool ||--|| PoolState: ""
Pool ||--o{ PoolSnapshot: ""
PoolState ||..|| PoolSnapshot: "onNewPeriod"
PoolState{
String id PK
String type "idx"
BigInt netAssetValue
BigInt totalReserve
BigInt availableReserve
BigInt maxReserve
BigInt totalDebt
BigInt totalBorrowed_
BigInt totalRepaid_
BigInt totalInvested_
BigInt totalRedeemed_
BigInt totalNumberOfLoans_
BigInt totalEverBorrowed
BigInt totalEverNumberOfLoans
}
PoolSnapshot }o--|| Pool: ""
PoolSnapshot {
String id PK
String poolId FK
Date timestamp
Int blockNumber
BigInt netAssetValue
BigInt totalReserve
BigInt availableReserve
BigInt maxReserve
BigInt totalDebt
BigInt totalBorrowed
BigInt totalRepaid
BigInt totalInvested
BigInt totalRedeemed
BigInt totalBorrowed_
BigInt totalRepaid_
BigInt totalInvested_
BigInt totalRedeemed_
BigInt totalNumberOfLoans_
BigInt totalEverBorrowed
BigInt totalEverNumberOfLoans
}
Tranche }o--|| Pool: ""
Tranche ||--|| TrancheState: ""
Tranche {
String id PK
String type "idx"
String poolId FK
String trancheId
Bool isResidual
Int seniority
BigInt interestRatePerSec
BigInt minRiskBuffer
String state FK
}
Tranche ||--o{ TrancheSnapshot: ""
TrancheState ||..|| TrancheSnapshot: "onNewPeriod"
TrancheState {
String id PK
String type "idx"
BigInt supply
Float price
BigInt outstandingInvestOrders
BigInt outstandingRedeemOrders
BigInt yield30Days
BigInt yield90Days
BigInt yieldSinceInception
}
TrancheSnapshot }o--|| Tranche: ""
TrancheSnapshot {
String id PK
String trancheId FK
Date timestamp
Int blockNumber
BigInt supply
Float price
BigInt outstandingInvestOrders
BigInt outstandingRedeemOrders
BigInt yield30Days
BigInt yield90Days
BigInt yieldSinceInception
}
Epoch }|--|| Pool: ""
Epoch {
String id PK
String poolId FK
Int index
Date openedAt
Date closedAt
Date executedAt
BigInt totalBorrowed
BigInt totalRepaid
BigInt totalInvested
BigInt totalRedeemed
}
Epoch }o--|| EpochState: ""
EpochState ||--|| Tranche: ""
InvestorTransaction }o--|| Account: ""
InvestorTransaction ||--|| Pool: ""
InvestorTransaction ||--|| Tranche: ""
InvestorTransaction ||--|| Epoch: ""
InvestorTransaction {}
BorrowerTransaction }o--|| Account: ""
BorrowerTransaction ||--|| Epoch: ""
BorrowerTransaction ||--|| Loan: ""
BorrowerTransaction {}
OutstandingOrder }o--|| Account: ""
OutstandingOrder ||--|| Pool: ""
OutstandingOrder ||--|| Tranche: ""
OutstandingOrder ||--|| Epoch: ""
OutstandingOrder {}
Account {}
AccountBalance {}
Loan {}
Proxy {}
AnonymousProxy {}
BorrowerTransaction }o--|| Account: ""
BorrowerTransaction ||--|| Epoch: ""
BorrowerTransaction ||--|| Loan: ""
Currency ||--|{ Pool: ""
```
20 changes: 20 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from 'jest'

const config: Config = {
verbose: true,
preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ['./jest/globals.ts'],
transform: {
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
'^.+\\.ts?$': [
'ts-jest',
{
tsconfig: './jest/tsconfig.jest.json',
},
],
},
}

export default config
4 changes: 4 additions & 0 deletions jest/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
declare const api: any
declare const logger: any
declare const store: any
26 changes: 26 additions & 0 deletions jest/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { jest } from '@jest/globals'

const globalHere: any = global

globalHere.store = {
get: jest.fn(),
getByField: jest.fn(),
getOneByField: jest.fn(),
set: jest.fn((...args) => args[2]),
bulkCreate: jest.fn(),
bulkUpdate: jest.fn(),
remove: jest.fn(),
}

globalHere.logger = {
fatal: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
trace: jest.fn(),
}

globalHere.api = { query: {}, rpc: {} }
21 changes: 21 additions & 0 deletions jest/tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"declaration": true,
"importHelpers": true,
"resolveJsonModule": true,
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"target": "es2017",
"paths": {
"centrifuge-subql/*": ["./src/*"]
}
},
"include": ["./src/**/*", "./jest/*.ts"],
"exports": {
"chaintypes": "./src/chaintypes.ts"
}
}
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,29 @@
"license": "MIT",
"dependencies": {},
"devDependencies": {
"node-fetch": "2.6.7",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@polkadot/api": "^9",
"@polkadot/typegen": "^9",
"@polkadot/types": "^9",
"@polkadot/util": "^9",
"@subql/cli": "latest",
"@subql/types": "latest",
"@subql/node": "1.9.2",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"husky": "^7.0.0",
"eslint": "^8.17.0",
"lint-staged": "^13.0.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.0",
"lint-staged": "^13.0.1",
"jest": "^29.2.0",
"@types/jest": "^29.1.2",
"@jest/globals": "^29.2.0",
"prettier": "^2.7.0",
"prettier-eslint": "^15.0.1",
"ts-jest": "^29.0.3",
"ts-node": "^8.6.2",
"typescript": "^4.4.4"
"typescript": "^4.1.3"
},
"lint-staged": {
"src/**/*.{js,ts}": [
Expand Down
Loading

0 comments on commit 514d398

Please sign in to comment.