Skip to content

Commit

Permalink
fix: subquery asset renamings (#1970)
Browse files Browse the repository at this point in the history
* Subquery asset renames

* Update prod endpoint
  • Loading branch information
hieronx authored Feb 21, 2024
1 parent fcda765 commit 827124f
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion centrifuge-app/.env-config/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REACT_APP_ONBOARDING_API_URL=https://europe-central2-centrifuge-production-x.clo
REACT_APP_PINNING_API_URL=https://europe-central2-centrifuge-production-x.cloudfunctions.net/pinning-api-production
REACT_APP_POOL_CREATION_TYPE=propose
REACT_APP_RELAY_WSS_URL=wss://rpc.polkadot.io
REACT_APP_SUBQUERY_URL=https://api.subquery.network/sq/centrifuge/pools-centrifuge
REACT_APP_SUBQUERY_URL=https://api.subquery.network/sq/centrifuge/pools
REACT_APP_SUBSCAN_URL=https://centrifuge.subscan.io
REACT_APP_TINLAKE_NETWORK=mainnet
REACT_APP_INFURA_KEY=bf808e7d3d924fbeb74672d9341d0550
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BorrowerTransactionType, InvestorTransactionType } from '@centrifuge/centrifuge-js'
import { AssetTransactionType, InvestorTransactionType } from '@centrifuge/centrifuge-js'
import { StatusChip } from '@centrifuge/fabric'
import * as React from 'react'
import { formatTransactionsType } from '../Report/utils'

type TransactionTypeProps = {
type: InvestorTransactionType | BorrowerTransactionType
type: InvestorTransactionType | AssetTransactionType
trancheTokenSymbol: string
poolCurrencySymbol: string
currencyAmount: number | null
Expand Down
4 changes: 2 additions & 2 deletions centrifuge-app/src/components/Portfolio/Transactions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BorrowerTransactionType, InvestorTransactionType, Pool, Token, TokenBalance } from '@centrifuge/centrifuge-js'
import { AssetTransactionType, InvestorTransactionType, Pool, Token, TokenBalance } from '@centrifuge/centrifuge-js'
import { formatBalance } from '@centrifuge/centrifuge-react'
import {
AnchorButton,
Expand Down Expand Up @@ -30,7 +30,7 @@ type TransactionsProps = {
}

type Row = {
action: InvestorTransactionType | BorrowerTransactionType
action: InvestorTransactionType | AssetTransactionType
date: number
tranche?: Token
tranchePrice: string
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/components/Report/AssetTransactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function AssetTransactions({ pool }: { pool: Pool }) {
return transactions?.map((tx) => ({
name: '',
value: [
tx.loanId.split('-').at(-1)!,
tx.assetId.split('-').at(-1)!,
tx.epochId.split('-').at(-1)!,
formatDate(tx.timestamp.toString()),
formatAssetTransactionType(tx.type),
Expand Down
12 changes: 6 additions & 6 deletions centrifuge-app/src/components/Report/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BorrowerTransactionType, InvestorTransactionType } from '@centrifuge/centrifuge-js/dist/types/subquery'
import { AssetTransactionType, InvestorTransactionType } from '@centrifuge/centrifuge-js/dist/types/subquery'
import { Text } from '@centrifuge/fabric'
import { copyToClipboard } from '../../utils/copyToClipboard'
import { truncate } from '../../utils/web3'
Expand Down Expand Up @@ -48,7 +48,7 @@ export function formatInvestorTransactionsType({
}

const assetTransactionTypes: {
[key in BorrowerTransactionType]: string
[key in AssetTransactionType]: string
} = {
CREATED: 'Created',
PRICED: 'Priced',
Expand All @@ -57,9 +57,9 @@ const assetTransactionTypes: {
CLOSED: 'Closed',
}

export function formatAssetTransactionType(type: BorrowerTransactionType) {
export function formatAssetTransactionType(type: AssetTransactionType) {
if (!assetTransactionTypes[type]) {
console.warn(`Type '${type}' is not assignable to type 'BorrowerTransactionType'`)
console.warn(`Type '${type}' is not assignable to type 'AssetTransactionType'`)
return type
}

Expand All @@ -72,7 +72,7 @@ export function formatTransactionsType({
poolCurrencySymbol,
currencyAmount,
}: {
type: InvestorTransactionType | BorrowerTransactionType
type: InvestorTransactionType | AssetTransactionType
trancheTokenSymbol: string
poolCurrencySymbol: string
currencyAmount: number | null
Expand All @@ -89,7 +89,7 @@ export function formatTransactionsType({
})
}

function isAssetType(type: InvestorTransactionType | BorrowerTransactionType): type is BorrowerTransactionType {
function isAssetType(type: InvestorTransactionType | AssetTransactionType): type is AssetTransactionType {
return ['CREATED', 'PRICED', 'BORROWED', 'REPAID', 'CLOSED'].includes(type)
}

Expand Down
4 changes: 2 additions & 2 deletions centrifuge-app/src/pages/Loan/HoldingsValues.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BorrowerTransaction, CurrencyBalance, ExternalPricingInfo, Pool } from '@centrifuge/centrifuge-js'
import { AssetTransaction, CurrencyBalance, ExternalPricingInfo, Pool } from '@centrifuge/centrifuge-js'
import Decimal from 'decimal.js-light'
import { LabelValueStack } from '../../components/LabelValueStack'
import { Dec } from '../../utils/Decimal'
import { formatBalance } from '../../utils/formatting'

type Props = {
pool: Pool
transactions?: BorrowerTransaction[] | null
transactions?: AssetTransaction[] | null
currentFace: Decimal | null
pricing: ExternalPricingInfo
}
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/pages/Loan/PricingValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function PricingValues({ loan, pool }: Props) {
const days = getAge(new Date(pricing.oracle.timestamp).toISOString())

const borrowerAssetTransactions = assetTransactions?.filter(
(borrowerTransaction) => borrowerTransaction.loanId === `${loan.poolId}-${loan.id}`
(assetTransaction) => assetTransaction.loanId === `${loan.poolId}-${loan.id}`
)
const latestPrice = getLatestPrice(pricing.oracle.value, borrowerAssetTransactions, pool.currency.decimals)

Expand Down
12 changes: 6 additions & 6 deletions centrifuge-app/src/pages/Loan/TransactionTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BorrowerTransaction, CurrencyBalance, ExternalPricingInfo, PricingInfo } from '@centrifuge/centrifuge-js'
import { BorrowerTransactionType } from '@centrifuge/centrifuge-js/dist/types/subquery'
import { AssetTransaction, CurrencyBalance, ExternalPricingInfo, PricingInfo } from '@centrifuge/centrifuge-js'
import { AssetTransactionType } from '@centrifuge/centrifuge-js/dist/types/subquery'
import { StatusChip, Tooltip } from '@centrifuge/fabric'
import BN from 'bn.js'
import { useMemo } from 'react'
Expand All @@ -9,7 +9,7 @@ import { Dec } from '../../utils/Decimal'
import { formatBalance } from '../../utils/formatting'

type Props = {
transactions: BorrowerTransaction[]
transactions: AssetTransaction[]
currency: string
decimals: number
loanType: 'external' | 'internal'
Expand Down Expand Up @@ -76,13 +76,13 @@ export const TransactionTable = ({ transactions, currency, loanType, decimals, p
}))
}, [transactions, decimals, pricing])

const getStatusChipType = (type: BorrowerTransactionType) => {
const getStatusChipType = (type: AssetTransactionType) => {
if (type === 'BORROWED' || type === 'CREATED' || type === 'PRICED') return 'info'
if (type === 'REPAID') return 'ok'
return 'default'
}

const getStatusText = (type: BorrowerTransactionType) => {
const getStatusText = (type: AssetTransactionType) => {
if (loanType === 'external' && type === 'BORROWED') return 'Purchase'
if (loanType === 'external' && type === 'REPAID') return 'Sale'

Expand All @@ -99,7 +99,7 @@ export const TransactionTable = ({ transactions, currency, loanType, decimals, p
{
align: 'left',
header: 'Type',
cell: (row: { type: BorrowerTransactionType }) => (
cell: (row: { type: AssetTransactionType }) => (
<StatusChip status={getStatusChipType(row.type)}>{getStatusText(row.type)}</StatusChip>
),
},
Expand Down
4 changes: 2 additions & 2 deletions centrifuge-app/src/utils/getLatestPrice.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BorrowerTransaction, CurrencyBalance } from '@centrifuge/centrifuge-js'
import { AssetTransaction, CurrencyBalance } from '@centrifuge/centrifuge-js'

export const getLatestPrice = (
oracleValue: CurrencyBalance,
borrowerAssetTransactions: BorrowerTransaction[] | undefined,
borrowerAssetTransactions: AssetTransaction[] | undefined,
decimals: number
) => {
if (!borrowerAssetTransactions) return null
Expand Down
12 changes: 6 additions & 6 deletions centrifuge-app/src/utils/usePools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Centrifuge, { addressToHex, BorrowerTransaction, Loan, Pool, PoolMetadata } from '@centrifuge/centrifuge-js'
import Centrifuge, { addressToHex, AssetTransaction, Loan, Pool, PoolMetadata } from '@centrifuge/centrifuge-js'
import { useCentrifugeApi, useCentrifugeConsts, useCentrifugeQuery, useWallet } from '@centrifuge/centrifuge-react'
import BN from 'bn.js'
import { useEffect, useMemo } from 'react'
Expand Down Expand Up @@ -83,7 +83,7 @@ export function useInvestorTransactions(poolId: string, trancheId?: string, from
export function useAssetTransactions(poolId: string, from?: Date, to?: Date) {
const [result] = useCentrifugeQuery(
['assetTransactions', poolId, from, to],
(cent) => cent.pools.getBorrowerTransactions([poolId, from, to]),
(cent) => cent.pools.getAssetTransactions([poolId, from, to]),
{
enabled: !poolId.startsWith('0x'),
}
Expand Down Expand Up @@ -113,11 +113,11 @@ export function useBorrowerAssetTransactions(poolId: string, assetId: string, fr
const [result] = useCentrifugeQuery(
['borrowerAssetTransactions', poolId, assetId, from, to],
(cent) => {
const borrowerTransactions = cent.pools.getBorrowerTransactions([poolId, from, to])
const assetTransactions = cent.pools.getAssetTransactions([poolId, from, to])

return borrowerTransactions.pipe(
map((transactions: BorrowerTransaction[]) =>
transactions.filter((transaction) => transaction.loanId.split('-')[1] === assetId)
return assetTransactions.pipe(
map((transactions: AssetTransaction[]) =>
transactions.filter((transaction) => transaction.assetId.split('-')[1] === assetId)
)
)
},
Expand Down
22 changes: 11 additions & 11 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { SolverResult, calculateOptimalSolution } from '..'
import { Centrifuge } from '../Centrifuge'
import { Account, TransactionOptions } from '../types'
import {
BorrowerTransactionType,
AssetTransactionType,
InvestorTransactionType,
SubqueryBorrowerTransaction,
SubqueryAssetTransaction,
SubqueryCurrencyBalances,
SubqueryInvestorTransaction,
SubqueryPoolSnapshot,
Expand Down Expand Up @@ -725,14 +725,14 @@ type InvestorTransaction = {
evmAddress?: string
}

export type BorrowerTransaction = {
export type AssetTransaction = {
id: string
timestamp: string
poolId: string
accountId: string
epochId: string
loanId: string
type: BorrowerTransactionType
type: AssetTransactionType
amount: CurrencyBalance | undefined
settlementPrice: string | null
quantity: string | null
Expand Down Expand Up @@ -2507,21 +2507,21 @@ export function getPoolsModule(inst: Centrifuge) {
)
}

function getBorrowerTransactions(args: [poolId: string, from?: Date, to?: Date]) {
function getAssetTransactions(args: [poolId: string, from?: Date, to?: Date]) {
const [poolId, from, to] = args

const $query = inst.getSubqueryObservable<{
borrowerTransactions: { nodes: SubqueryBorrowerTransaction[] }
assetTransactions: { nodes: SubqueryAssetTransaction[] }
}>(
`query($poolId: String!, $from: Datetime!, $to: Datetime!) {
borrowerTransactions(
assetTransactions(
orderBy: TIMESTAMP_ASC,
filter: {
poolId: { equalTo: $poolId },
timestamp: { greaterThan: $from, lessThan: $to },
}) {
nodes {
loanId
assetId
epochId
type
timestamp
Expand All @@ -2543,11 +2543,11 @@ export function getPoolsModule(inst: Centrifuge) {
return $query.pipe(
switchMap(() => combineLatest([$query, getPoolCurrency([poolId])])),
map(([data, currency]) => {
return data!.borrowerTransactions.nodes.map((tx) => ({
return data!.assetTransactions.nodes.map((tx) => ({
...tx,
amount: tx.amount ? new CurrencyBalance(tx.amount, currency.decimals) : undefined,
timestamp: new Date(`${tx.timestamp}+00:00`),
})) as unknown as BorrowerTransaction[]
})) as unknown as AssetTransaction[]
})
)
}
Expand Down Expand Up @@ -3446,7 +3446,7 @@ export function getPoolsModule(inst: Centrifuge) {
getDailyPoolStates,
getMonthlyPoolStates,
getInvestorTransactions,
getBorrowerTransactions,
getAssetTransactions,
getNativeCurrency,
getCurrencies,
getDailyTrancheStates,
Expand Down
10 changes: 5 additions & 5 deletions centrifuge-js/src/types/subquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ export type SubqueryInvestorTransaction = {
transactionFee?: number | null
}

export type BorrowerTransactionType = 'CREATED' | 'PRICED' | 'BORROWED' | 'REPAID' | 'CLOSED'
export type AssetTransactionType = 'CREATED' | 'PRICED' | 'BORROWED' | 'REPAID' | 'CLOSED'

export type SubqueryBorrowerTransaction = {
__typename?: 'BorrowerTransaction'
export type SubqueryAssetTransaction = {
__typename?: 'AssetTransaction'
id: string
timestamp: string
poolId: string
accountId: string
epochId: string
loanId: string
type: BorrowerTransactionType
assetId: string
type: AssetTransactionType
amount?: number | null
settlementPrice: string | null
quantity: string | null
Expand Down

0 comments on commit 827124f

Please sign in to comment.