Skip to content

Commit

Permalink
various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
JP Angelle committed Sep 8, 2023
1 parent 41d843a commit 4be2503
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 43 deletions.
7 changes: 5 additions & 2 deletions centrifuge-app/src/pages/IssuerPool/Assets/CreateLoan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export type CreateLoanFormValues = {
maxBorrowQuantity: number | ''
Isin: string
notional: number | ''
maxPriceVariation: number | ''
}
}

Expand Down Expand Up @@ -224,6 +225,7 @@ function IssuerCreateLoan() {
maxBorrowQuantity: '',
Isin: '',
notional: '',
maxPriceVariation: '',
},
},
onSubmit: async (values, { setSubmitting }) => {
Expand All @@ -233,14 +235,15 @@ function IssuerCreateLoan() {
values.pricing.valuationMethod === 'oracle'
? {
valuationMethod: values.pricing.valuationMethod,
// maxPriceVariation: Rate.fromPercent(values.pricing.maxPriceVariation),
maxPriceVariation: '1000000000000000000000000000000',
maxBorrowAmount: values.pricing.maxBorrowQuantity
? CurrencyBalance.fromFloat(values.pricing.maxBorrowQuantity, decimals)
: null,
Isin: values.pricing.Isin || '',
maturityDate: new Date(values.pricing.maturityDate),
maturityExtensionDays: values.pricing.maturityExtensionDays,
interestRate: Rate.fromPercent(values.pricing.interestRate),
notional: CurrencyBalance.fromFloat(values.pricing.notional, decimals),
notional: CurrencyBalance.fromFloat(values.pricing.notional, 18),
}
: {
valuationMethod: values.pricing.valuationMethod,
Expand Down
4 changes: 2 additions & 2 deletions centrifuge-app/src/pages/IssuerPool/Assets/PricingInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ export function PricingInput({ poolId }: { poolId: string }) {
// Max 5 years from now
max={new Date(Date.now() + 5 * 365 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10)}
/>
<FieldWithErrorMessage
{/* <FieldWithErrorMessage
as={NumberInput}
label={<Tooltips type="maxPriceVariation" variant="secondary" label="Max price variation*" />}
placeholder={0}
rightElement="%"
name="pricing.maxPriceVariation"
validate={validate.maxPriceVariation}
/>
/> */}

{(values.pricing.valuationMethod === 'discountedCashFlow' ||
values.pricing.valuationMethod === 'outstandingDebt') && (
Expand Down
11 changes: 4 additions & 7 deletions centrifuge-app/src/pages/Loan/ExternalFinanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export function ExternalFinanceForm({ loan }: { loan: LoanType }) {
},
onSubmit: (values, actions) => {
const price = CurrencyBalance.fromFloat(values.price, pool.currency.decimals)
const faceValue = CurrencyBalance.fromFloat(values.faceValue, 18)
const quantity = CurrencyBalance.fromFloat((values.faceValue as number) / (values.price as number), 18)

doFinanceTransaction([loan.poolId, loan.id, faceValue, price, account.actingAddress])
doFinanceTransaction([loan.poolId, loan.id, quantity, price, account.actingAddress])
actions.setSubmitting(false)
},
validateOnMount: true,
Expand All @@ -76,10 +76,7 @@ export function ExternalFinanceForm({ loan }: { loan: LoanType }) {
},
onSubmit: (values, actions) => {
const price = CurrencyBalance.fromFloat(values.price, pool.currency.decimals)
const quantity = CurrencyBalance.fromFloat(
(values.faceValue as number) / (values.price as number),
pool.currency.decimals
)
const quantity = CurrencyBalance.fromFloat((values.faceValue as number) / (values.price as number), 18)

doRepayTransaction([loan.poolId, loan.id, quantity, new BN(0), new BN(0), price, account.actingAddress])
actions.setSubmitting(false)
Expand Down Expand Up @@ -207,7 +204,7 @@ export function ExternalFinanceForm({ loan }: { loan: LoanType }) {
{/* outstandingDebt needs to be rounded down, b/c onSetMax displays the rounded down value as well */}
<Text variant="label2">
{'valuationMethod' in loan.pricing && loan.pricing.valuationMethod === 'oracle'
? `${loan.pricing.outstandingQuantity.toFloat()} @ ${formatBalance(
? `${Dec(loan.pricing.outstandingQuantity.toString()).div('1e18').toFixed(2)} @ ${formatBalance(
new CurrencyBalance(loan.pricing.oracle.value, 18),
pool?.currency.symbol,
2
Expand Down
27 changes: 6 additions & 21 deletions centrifuge-app/src/pages/Loan/HoldingsValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ type Props = {
}

export function HoldingsValues({ loan: { pricing }, pool, transactions }: Props) {
const totalFinanced =
const currentTotalFace =
transactions?.reduce((sum, trx) => {
if (trx.type === 'BORROWED') {
sum = new CurrencyBalance(sum.add(trx.amount || new CurrencyBalance(0, 27)), 27)
if (trx.type === 'REPAID') {
sum = new CurrencyBalance(sum.sub(trx.amount || new CurrencyBalance(0, 27)), 27)
}

return sum
}, new CurrencyBalance(0, 27)) || new CurrencyBalance(0, 27)

const totalRepaid =
transactions?.reduce((sum, trx) => {
if (trx.type === 'REPAID') {
if (trx.type === 'BORROWED') {
sum = new CurrencyBalance(sum.add(trx.amount || new CurrencyBalance(0, 27)), 27)
}

Expand All @@ -31,27 +26,17 @@ export function HoldingsValues({ loan: { pricing }, pool, transactions }: Props)
<>
<LabelValueStack
label="Current total face"
value={`${formatBalance(
new CurrencyBalance(pricing.notional.mul(pricing.outstandingQuantity), 27),
pool.currency.symbol,
6,
2
)}`}
value={`${formatBalance(new CurrencyBalance(currentTotalFace, 24), pool.currency.symbol, 6, 2)}`}
/>
<LabelValueStack
label="Current value"
value={`${formatBalance(
new CurrencyBalance(pricing.oracle.value.mul(pricing.outstandingQuantity), 36),
new CurrencyBalance(currentTotalFace.mul(pricing.oracle.value), 44),
pool.currency.symbol,
6,
2
)}`}
/>
<LabelValueStack
label="Total face purchased"
value={`${formatBalance(totalFinanced, pool.currency.symbol, 6, 2)}`}
/>
<LabelValueStack label="Total face sold" value={`${formatBalance(totalRepaid, pool.currency.symbol, 6, 2)}`} />
</>
)
}
14 changes: 9 additions & 5 deletions centrifuge-app/src/pages/Loan/TransactionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { formatBalance } from '../../utils/formatting'

type Props = {
transactions: BorrowerTransaction[]
currency: string
}

export const TransactionTable = ({ transactions }: Props) => {
export const TransactionTable = ({ transactions, currency }: Props) => {
const assetTransactions = useMemo(() => {
const sortedTransactions = transactions.sort((a, b) => {
if (a.timestamp > b.timestamp) {
Expand Down Expand Up @@ -75,19 +76,22 @@ export const TransactionTable = ({ transactions }: Props) => {
// {
// align: 'left',
// header: 'Settle price',
// cell: (row) => formatBalance(row.settlePrice, 'USD'),
// cell: (row) => formatBalance(row.settlePrice, currency),
// flex: '3',
// },
{
align: 'left',
header: 'Net flow',
cell: (row) => (row.netFlow ? formatBalance(new CurrencyBalance(row.netFlow, 27), 'USD') : '-'),
header: 'Face flow',
cell: (row) =>
row.netFlow
? `${row.type === 'REPAID' ? '-' : ''}${formatBalance(new CurrencyBalance(row.netFlow, 24), currency)}`
: '-',
flex: '3',
},
{
align: 'left',
header: 'Position',
cell: (row) => formatBalance(row.position, 'USD'),
cell: (row) => formatBalance(new CurrencyBalance(row.position, 24), currency),
flex: '3',
},
// TODO: add link to transaction
Expand Down
10 changes: 7 additions & 3 deletions centrifuge-app/src/pages/Loan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ const Loan: React.FC<{ setShowOraclePricing?: () => void }> = ({ setShowOraclePr
{
label: 'Current value',
value: formatBalance(
'outstandingDebt' in loan ? loan.outstandingDebt : new CurrencyBalance(0, pool.currency.decimals),
pool?.currency.symbol
'outstandingDebt' in loan
? new CurrencyBalance(loan.outstandingDebt, 21)
: new CurrencyBalance(0, 18),
pool?.currency.symbol,
6,
2
),
},
]}
Expand Down Expand Up @@ -271,7 +275,7 @@ const Loan: React.FC<{ setShowOraclePricing?: () => void }> = ({ setShowOraclePr
</Flex>
}
>
<TransactionTable transactions={borrowerAssetTransactions} />
<TransactionTable transactions={borrowerAssetTransactions} currency={pool.currency.symbol} />
</PageSection>
) : null}
</>
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/utils/validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const positiveNumber = (err?: CustomError) => (val?: any) => {
}

export const settlementPrice = (err?: CustomError) => (val?: any) => {
const regex = new RegExp(/^\d{1,3}\.\d{0,6}$/)
const regex = new RegExp(/^\d{1,3}(?:\.\d{1,6})?$/)
return regex.test(val) ? '' : getError(`Value must be in the format of (1-3).(0-6) digits`, err, val)
}

Expand Down
6 changes: 4 additions & 2 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ type LoanInfoInput =
| {
valuationMethod: 'oracle'
maxBorrowAmount: BN | null
maxPriceVariation: BN
Isin: string
maturityDate: Date
maturityExtensionDays: number
interestRate: BN
notional: BN
}
Expand Down Expand Up @@ -127,6 +127,7 @@ export type LoanInfoData = {
}
maxBorrowAmount: { noLimit: null } | { quantity: string }
notional: string
maxPriceVariation: string
}
}
| {
Expand Down Expand Up @@ -1319,7 +1320,7 @@ export function getPoolsModule(inst: Centrifuge) {
maturity: {
fixed: {
date: Math.round(infoInput.maturityDate.getTime() / 1000),
extension: infoInput.maturityExtensionDays * SEC_PER_DAY,
extension: 'maturityExtensionDays' in infoInput ? infoInput.maturityExtensionDays * SEC_PER_DAY : 0,
},
},
interestPayments: 'None',
Expand All @@ -1343,6 +1344,7 @@ export function getPoolsModule(inst: Centrifuge) {
infoInput.maxBorrowAmount === null
? { noLimit: null }
: { quantity: infoInput.maxBorrowAmount.toString() },
maxPriceVariation: infoInput.maxPriceVariation!.toString(),
notional: infoInput.notional.toString(),
},
}
Expand Down

0 comments on commit 4be2503

Please sign in to comment.