Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add docs generation #43

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
486a30f
add docs generation
onnovisser Jan 13, 2025
e8ba866
[bot] New pkg version: 0.0.0-alpha.6
actions-user Jan 13, 2025
6ca9ccf
Test docs automation
sophialittlejohn Jan 13, 2025
eadf434
Force yarn@stable in workflow
sophialittlejohn Jan 13, 2025
4a05f36
Try setting stable version manually
sophialittlejohn Jan 13, 2025
d825475
Update order
sophialittlejohn Jan 13, 2025
07bed06
Install deps before gen:docs
sophialittlejohn Jan 13, 2025
2f5fb40
Add user to github
sophialittlejohn Jan 13, 2025
ef531bd
Convert script to cjs file
sophialittlejohn Jan 13, 2025
095efe0
Update clone url
sophialittlejohn Jan 13, 2025
5b6fde1
Add org name
sophialittlejohn Jan 13, 2025
c313385
Remove docs
sophialittlejohn Jan 14, 2025
1c2f461
Checkout branch later
sophialittlejohn Jan 14, 2025
20104b1
Update docs
actions-user Jan 14, 2025
20f6f74
Login to github
sophialittlejohn Jan 14, 2025
60a8a25
Update docs
actions-user Jan 14, 2025
fef7676
Use PAT token to allow pushing to repo
sophialittlejohn Jan 14, 2025
d97b7f1
Use auth url
sophialittlejohn Jan 14, 2025
20843ed
oauth for authorization
sophialittlejohn Jan 14, 2025
c380e23
Update docs
actions-user Jan 14, 2025
8477ffd
Regular auth?
sophialittlejohn Jan 14, 2025
53d1140
Fix naming
sophialittlejohn Jan 14, 2025
f6a84e5
Update docs
actions-user Jan 14, 2025
06481dd
Exclude readme and improve copy
sophialittlejohn Jan 14, 2025
2da740f
[ci:bot] Update docs
actions-user Jan 14, 2025
5924ed5
Unique branch names and earlier auth
sophialittlejohn Jan 14, 2025
e6c77e4
[ci:bot] Update docs
actions-user Jan 14, 2025
212732e
Fix branch name
sophialittlejohn Jan 14, 2025
da56da0
[ci:bot] Update docs
actions-user Jan 14, 2025
f4a0555
Exclude readme in typedoc generation
sophialittlejohn Jan 14, 2025
7cb1f39
[ci:bot] Update docs
actions-user Jan 14, 2025
862f7f1
Exclude _globals.md
sophialittlejohn Jan 14, 2025
95301cd
[ci:bot] Update docs
actions-user Jan 14, 2025
ae12cdc
Fix typo
sophialittlejohn Jan 14, 2025
34d731a
[ci:bot] Update docs
actions-user Jan 14, 2025
79d4569
Add note in readme and switch trigger branch to main
sophialittlejohn Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@centrifuge/sdk",
"version": "0.0.0-alpha.5",
"version": "0.0.0-alpha.6",
"description": "",
"homepage": "https://github.com/centrifuge/sdk/tree/main#readme",
"author": "",
Expand Down Expand Up @@ -33,7 +33,8 @@
"test:simple:single": "mocha --loader=ts-node/esm --exit --timeout 60000",
"test:single": "mocha --loader=ts-node/esm --require $(pwd)/src/tests/setup.ts --exit --timeout 60000",
"test:ci": "yarn test --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
"test:coverage": "c8 yarn test:ci"
"test:coverage": "c8 yarn test:ci",
"gen:docs": "typedoc --out docs --skipErrorChecking --excludeExternals src/index.ts"
},
"dependencies": {
"decimal.js-light": "^2.5.1",
Expand Down Expand Up @@ -61,6 +62,8 @@
"sinon-chai": "^4.0.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.2",
"typedoc": "^0.27.6",
"typedoc-plugin-markdown": "^4.4.1",
"typescript": "~5.6.3",
"typescript-eslint": "^8.8.1",
"viem": "^2.21.25"
Expand Down
27 changes: 5 additions & 22 deletions src/Centrifuge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
type Abi,
type Account as AccountType,
type Chain,
type PublicClient,
type WalletClient,
type WatchEventOnLogsParameter,
} from 'viem'
Expand All @@ -34,31 +33,14 @@ import { chains } from './config/chains.js'
import type { CurrencyMetadata } from './config/lp.js'
import { PERMIT_TYPEHASH } from './constants.js'
import { Pool } from './Pool.js'
import type { HexString } from './types/index.js'
import type { Client, DerivedConfig, EnvConfig, HexString, UserProvidedConfig } from './types/index.js'
import type { CentrifugeQueryOptions, Query } from './types/query.js'
import type { OperationStatus, Signer, Transaction, TransactionCallbackParams } from './types/transaction.js'
import { Currency } from './utils/BigInt.js'
import { hashKey } from './utils/query.js'
import { makeThenable, repeatOnEvents, shareReplayWithDelayedReset } from './utils/rx.js'
import { doTransaction, isLocalAccount } from './utils/transaction.js'

export type Config = {
environment: 'mainnet' | 'demo' | 'dev'
rpcUrls?: Record<number | string, string>
indexerUrl: string
ipfsUrl: string
}

export type UserProvidedConfig = Partial<Config>
type EnvConfig = {
indexerUrl: string
alchemyKey: string
infuraKey: string
defaultChain: number
ipfsUrl: string
}
type DerivedConfig = Config & EnvConfig

const envConfig = {
mainnet: {
indexerUrl: 'https://subql.embrio.tech/',
Expand Down Expand Up @@ -93,7 +75,7 @@ export class Centrifuge {
return this.#config
}

#clients = new Map<number, PublicClient<any, Chain>>()
#clients = new Map<number, Client>()
getClient(chainId?: number) {
return this.#clients.get(chainId ?? this.config.defaultChain)
}
Expand Down Expand Up @@ -134,8 +116,8 @@ export class Centrifuge {
})
}

pool(id: string, metadataHash?: string) {
return this._query(null, () => of(new Pool(this, id, metadataHash)))
pool(id: string | number, metadataHash?: string) {
return this._query(null, () => of(new Pool(this, String(id), metadataHash)))
}

account(address: string, chainId?: number) {
Expand Down Expand Up @@ -535,6 +517,7 @@ export class Centrifuge {
* // { type: 'SigningTransaction', title: 'Invest' }
* // { type: 'TransactionPending', title: 'Invest', hash: '0x123...abc' }
* // { type: 'TransactionConfirmed', title: 'Invest', hash: '0x123...abc', receipt: { ... } }
* ```
*
* @internal
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import type { CentrifugeQueryOptions } from './types/query.js'

export class Entity {
#baseKeys: (string | number)[]
/** @internal */
_transact: Centrifuge['_transact']
/** @internal */
_transactSequence: Centrifuge['_transactSequence']
constructor(
/** @internal */
protected _root: Centrifuge,
queryKeys: (string | number)[]
) {
Expand All @@ -15,6 +18,7 @@ export class Entity {
this._transactSequence = this._root._transactSequence.bind(this._root)
}

/** @internal */
protected _query<T>(
keys: (string | number | undefined)[] | null,
observableCallback: () => Observable<T>,
Expand Down
5 changes: 4 additions & 1 deletion src/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Reports } from './Reports/index.js'
import { PoolMetadata } from './types/poolMetadata.js'

export class Pool extends Entity {
/** @internal */
constructor(
_root: Centrifuge,
public id: string,
Expand All @@ -19,7 +20,9 @@ export class Pool extends Entity {
}

metadata() {
return this.metadataHash ? this._root._queryIPFS<PoolMetadata>(this.metadataHash) : of(undefined)
return this.metadataHash
? this._root._queryIPFS<PoolMetadata>(this.metadataHash)
: this._query(null, () => of(null))
}

trancheIds() {
Expand Down
4 changes: 3 additions & 1 deletion src/PoolNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Vault } from './Vault.js'
* Query and interact with a pool on a specific network.
*/
export class PoolNetwork extends Entity {
/** @internal */
constructor(
_root: Centrifuge,
public pool: Pool,
Expand Down Expand Up @@ -192,9 +193,10 @@ export class PoolNetwork extends Entity {

/**
* Get all Vaults for all tranches in the pool.
* @returns An object of tranche ID to Vault.
*/
vaultsByTranche() {
return this._query(null, () =>
return this._query<Record<string, Vault>>(null, () =>
this.pool.trancheIds().pipe(
switchMap((tranches) => {
return combineLatest(tranches.map((trancheId) => this.vaults(trancheId))).pipe(
Expand Down
47 changes: 24 additions & 23 deletions src/Reports/Processor.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { AssetTransaction } from '../IndexerQueries/assetTransactions.js'
import { InvestorTransaction } from '../IndexerQueries/investorTransactions.js'
import { Currency, Price, Rate, Token } from '../utils/BigInt.js'
import { groupByPeriod } from '../utils/date.js'
import { PoolFeeTransaction } from '../IndexerQueries/poolFeeTransactions.js'
import {
AssetListData,
AssetListReport,
AssetListReportFilter,
AssetListReportPrivateCredit,
AssetListReportPublicCredit,
AssetTransactionReport,
AssetTransactionReportFilter,
AssetTransactionsData,
BalanceSheetData,
BalanceSheetReport,
CashflowData,
CashflowReport,
ProfitAndLossReport,
ProfitAndLossData,
ReportFilter,
FeeTransactionReport,
FeeTransactionReportFilter,
FeeTransactionsData,
InvestorListData,
InvestorListReport,
InvestorListReportFilter,
InvestorTransactionsData,
InvestorTransactionsReport,
InvestorTransactionsReportFilter,
AssetTransactionReport,
AssetTransactionsData,
AssetTransactionReportFilter,
FeeTransactionsData,
FeeTransactionReportFilter,
FeeTransactionReport,
ProfitAndLossData,
ProfitAndLossReport,
ReportFilter,
TokenPriceData,
TokenPriceReport,
TokenPriceReportFilter,
TokenPriceData,
AssetListReport,
AssetListReportFilter,
AssetListData,
AssetListReportPublicCredit,
AssetListReportPrivateCredit,
InvestorListData,
InvestorListReportFilter,
InvestorListReport,
} from '../types/reports.js'
import { PoolFeeTransaction } from '../IndexerQueries/poolFeeTransactions.js'
import { Currency, Price, Rate, Token } from '../utils/BigInt.js'
import { groupByPeriod } from '../utils/date.js'

export class Processor {
/**
Expand Down Expand Up @@ -299,7 +299,7 @@ export class Processor {
if (Object.values(data.trancheSnapshots).length === 0) return []
const items = Object.entries(data.trancheSnapshots).map(([timestamp, snapshots]) => ({
type: 'tokenPrice' as const,
timestamp: timestamp,
timestamp,
tranches: snapshots.map((snapshot) => ({
timestamp: snapshot.timestamp,
id: snapshot.trancheId,
Expand Down Expand Up @@ -327,7 +327,8 @@ export class Processor {
return isMaturityDatePassed && isDebtZero
} else if (filter?.status === 'overdue') {
return isMaturityDatePassed && !isDebtZero
} else return true
}
return true
})
.sort((a, b) => {
// Sort by actualMaturityDate in descending order
Expand Down
41 changes: 21 additions & 20 deletions src/Reports/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import { Entity } from '../Entity.js'
import { combineLatest, map } from 'rxjs'
import { Centrifuge } from '../Centrifuge.js'
import { combineLatest } from 'rxjs'
import { processor } from './Processor.js'

import { map } from 'rxjs'
import { Entity } from '../Entity.js'
import { IndexerQueries } from '../IndexerQueries/index.js'
import { Pool } from '../Pool.js'
import { Query } from '../types/query.js'
import {
AssetListReport,
AssetListReportFilter,
AssetTransactionReport,
AssetTransactionReportFilter,
BalanceSheetReport,
CashflowReport,
InvestorTransactionsReport,
ProfitAndLossReport,
ReportFilter,
Report,
DataReport,
DataReportFilter,
InvestorTransactionsReportFilter,
AssetTransactionReport,
AssetTransactionReportFilter,
TokenPriceReport,
TokenPriceReportFilter,
FeeTransactionReport,
FeeTransactionReportFilter,
AssetListReportFilter,
AssetListReport,
InvestorListReportFilter,
InvestorListReport,
InvestorListReportFilter,
InvestorTransactionsReport,
InvestorTransactionsReportFilter,
ProfitAndLossReport,
Report,
ReportFilter,
TokenPriceReport,
TokenPriceReportFilter,
} from '../types/reports.js'
import { Query } from '../types/query.js'
import { Pool } from '../Pool.js'
import { IndexerQueries } from '../IndexerQueries/index.js'
import { processor } from './Processor.js'

const DEFAULT_FILTER: ReportFilter = {
from: '2024-01-01T00:00:00.000Z',
to: new Date().toISOString(),
}
export class Reports extends Entity {
private queries: IndexerQueries
/** @internal */
constructor(
centrifuge: Centrifuge,
public pool: Pool
Expand Down Expand Up @@ -83,6 +82,8 @@ export class Reports extends Entity {
* Reports are split into two types:
* - A `Report` is a standard report: balanceSheet, cashflow, profitAndLoss
* - A `DataReport` is a custom report: investorTransactions, assetTransactions, feeTransactions, tokenPrice, assetList, investorList
*
* @internal
*/
_generateReport<T>(type: Report, filter?: ReportFilter): Query<T[]>
_generateReport<T>(type: DataReport, filter?: DataReportFilter): Query<T[]>
Expand Down
1 change: 1 addition & 0 deletions src/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Vault extends Entity {
* The contract address of the vault.
*/
address: HexString
/** @internal */
constructor(
_root: Centrifuge,
public network: PoolNetwork,
Expand Down
50 changes: 47 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
import { Centrifuge } from './Centrifuge.js'
export type { CurrencyMetadata } from './config/lp.js'
export * from './Pool.js'
export * from './PoolNetwork.js'
export * from './types/index.js'
export * from './types/query.js'
export * from './types/transaction.js'
export * from './Reports/index.js'
export type { Client, Config, HexString } from './types/index.js'
export type { Query } from './types/query.js'
export type {
AssetListReport,
AssetListReportBase,
AssetListReportFilter,
AssetListReportPrivateCredit,
AssetListReportPublicCredit,
AssetTransactionReport,
AssetTransactionReportFilter,
BalanceSheetReport,
CashflowReport,
CashflowReportBase,
CashflowReportPrivateCredit,
CashflowReportPublicCredit,
FeeTransactionReport,
FeeTransactionReportFilter,
InvestorListReport,
InvestorListReportFilter,
InvestorTransactionsReport,
InvestorTransactionsReportFilter,
ProfitAndLossReport,
ProfitAndLossReportBase,
ProfitAndLossReportPrivateCredit,
ProfitAndLossReportPublicCredit,
ReportFilter,
TokenPriceReport,
TokenPriceReportFilter,
} from './types/reports.js'
export type {
EIP1193ProviderLike,
OperationConfirmedStatus,
OperationPendingStatus,
OperationSignedMessageStatus,
OperationSigningMessageStatus,
OperationSigningStatus,
OperationStatus,
OperationStatusType,
OperationSwitchChainStatus,
Signer,
Transaction,
} from './types/transaction.js'
export { Currency, Perquintill, Price, Rate } from './utils/BigInt.js'
export type { GroupBy } from './utils/date.js'
export * from './Vault.js'

export { Centrifuge }
export default Centrifuge
19 changes: 19 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
import { Chain, PublicClient } from 'viem'

export type Config = {
environment: 'mainnet' | 'demo' | 'dev'
rpcUrls?: Record<number | string, string>
indexerUrl: string
ipfsUrl: string
}

export type UserProvidedConfig = Partial<Config>
export type EnvConfig = {
indexerUrl: string
alchemyKey: string
infuraKey: string
defaultChain: number
ipfsUrl: string
}
export type DerivedConfig = Config & EnvConfig
export type Client = PublicClient<any, Chain>
export type HexString = `0x${string}`
Loading
Loading