Skip to content

Commit

Permalink
Cleanup types
Browse files Browse the repository at this point in the history
  • Loading branch information
kattylucy committed Nov 28, 2024
1 parent 945bf45 commit 86cf627
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export const PoolDetailsSection = () => {
placeholder="Type here..."
maxLength={1000}
errorMessage={meta.touched && meta.error ? meta.error : undefined}
// disabled={waitingForStoredIssuer}
/>
)}
</Field>
Expand Down
65 changes: 41 additions & 24 deletions centrifuge-app/src/pages/IssuerCreatePool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { config } from '../../config'
import { PoolDetailsSection } from './PoolDetailsSection'
import { PoolSetupSection } from './PoolSetupSection'
import { Line, PoolStructureSection } from './PoolStructureSection'
import { CreatePoolValues, initialValues } from './types'
import { CreatePoolValues, initialValues, PoolFee } from './types'
import { pinFileIfExists, pinFiles } from './utils'
import { validateValues } from './validate'

Expand Down Expand Up @@ -252,36 +252,53 @@ const IssuerCreatePoolPage = () => {
metadataValues.poolRatings = ratings
}

// Organize tranches
const nonJuniorTranches = metadataValues.tranches.slice(1)
const tranches = [
{},
...nonJuniorTranches.map((tranche) => ({
interestRatePerSec: Rate.fromAprPercent(tranche.interestRate),
minRiskBuffer: Perquintill.fromPercent(tranche.minRiskBuffer),
})),
]
// Tranches
const tranches = metadataValues.tranches.map((tranche, index) => {
const trancheType =
index === 0
? 'Residual'
: {
NonResidual: {
interestRatePerSec: Rate.fromAprPercent(tranche.interestRate).toString(),
minRiskBuffer: Perquintill.fromPercent(tranche.minRiskBuffer).toString(),
},
}

return {
trancheType,
metadata: {
tokenName: tranche.tokenName,
tokenSymbol: tranche.symbolName,
},
}
})

// Pool fees
const feeId = await firstValueFrom(centrifuge.pools.getNextPoolFeeId())
const poolFees: AddFee['fee'][] = values.poolFees.map((fee, i) => {
return {
const metadataPoolFees: Pick<PoolFee, 'name' | 'id' | 'feePosition' | 'feeType'>[] = []
const feeInput: Array<[string, { destination: string; editor: any; feeType: any }]> = []

values.poolFees.forEach((fee, index) => {
metadataPoolFees.push({
name: fee.name,
destination: fee.walletAddress,
amount: Rate.fromPercent(fee.percentOfNav),
feeType: fee.feeType,
limit: 'ShareOfPortfolioValuation',
account: fee.feeType === 'chargedUpTo' ? fee.walletAddress : undefined,
id: feeId ? feeId + index : 0,
feePosition: fee.feePosition,
}
feeType: fee.feeType,
})

feeInput.push([
'Top',
{
destination: fee.walletAddress,
editor: fee.feeType === 'chargedUpTo' ? { account: fee.walletAddress } : 'Root',
feeType: {
[fee.feeType]: { limit: { ['ShareOfPortfolioValuation']: Rate.fromPercent(fee.percentOfNav) } },
},
},
])
})

metadataValues.poolFees = poolFees.map((fee, i) => ({
name: fee.name,
id: feeId + i,
feePosition: fee.feePosition,
feeType: fee.feeType,
}))
metadataValues.poolFees = metadataPoolFees

// Multisign
metadataValues.adminMultisig =
Expand Down
30 changes: 16 additions & 14 deletions centrifuge-app/src/pages/IssuerCreatePool/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ export interface Tranche {
apy: string
interestRate: number | ''
}

export interface PoolFee {
id: number
name: string
feeType: FeeTypes
percentOfNav: string
walletAddress: string
feePosition: 'Top of waterfall'
category: string
}
export interface WriteOffGroupInput {
days: number | ''
writeOff: number | ''
Expand All @@ -24,11 +34,12 @@ export const createEmptyTranche = (trancheName: string): Tranche => ({
apy: '90d',
})

export const createPoolFee = () => ({
export const createPoolFee = (): PoolFee => ({
id: 0,
name: '',
category: '',
feePosition: '',
feeType: '',
feePosition: 'Top of waterfall',
feeType: '' as FeeTypes,
percentOfNav: '',
walletAddress: '',
})
Expand All @@ -52,15 +63,7 @@ export type CreatePoolValues = Omit<
reportUrl: string
adminMultisigEnabled: boolean
adminMultisig: Exclude<PoolMetadataInput['adminMultisig'], undefined>
poolFees: {
id?: number
name: string
feeType: FeeTypes
percentOfNav: number | ''
walletAddress: string
feePosition: 'Top of waterfall'
category: string
}[]
poolFees: PoolFee[]
poolRatings: {
agency?: string
value?: string
Expand All @@ -73,14 +76,13 @@ export const initialValues: CreatePoolValues = {
// pool structure
poolStructure: 'revolving',
assetClass: 'Private credit',
assetDenomination: '',
assetDenomination: isTestEnv ? 'USDC' : 'Native USDC',
subAssetClass: '',
tranches: [createEmptyTranche('Junior')],

// pool details section
poolName: '',
poolIcon: null,
currency: isTestEnv ? 'USDC' : 'Native USDC',
maxReserve: 1000000,
investorType: '',
issuerName: '',
Expand Down
29 changes: 2 additions & 27 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1040,31 +1040,6 @@ export function getPoolsModule(inst: Centrifuge) {
options?: TransactionOptions
) {
const [admin, poolId, tranches, currency, maxReserve, metadata, fees] = args
const trancheInput = tranches.map((t, i) => ({
trancheType: t.interestRatePerSec
? {
NonResidual: {
interestRatePerSec: t.interestRatePerSec.toString(),
minRiskBuffer: t.minRiskBuffer?.toString(),
},
}
: 'Residual',
metadata: {
tokenName: metadata.tranches[i].tokenName,
tokenSymbol: metadata.tranches[i].symbolName,
},
}))

const feeInput = fees.map((fee) => {
return [
'Top',
{
destination: fee.destination,
editor: fee?.account ? { account: fee.account } : 'Root',
feeType: { [fee.feeType]: { limit: { [fee.limit]: fee?.amount } } },
},
]
})

return inst.getApi().pipe(
switchMap((api) =>
Expand All @@ -1078,12 +1053,12 @@ export function getPoolsModule(inst: Centrifuge) {
const tx = api.tx.poolRegistry.register(
admin,
poolId,
trancheInput,
tranches,
currency,
maxReserve.toString(),
pinnedMetadata.ipfsHash,
[],
feeInput
fees
)
if (options?.createType === 'propose') {
const proposalTx = api.tx.utility.batchAll([
Expand Down

0 comments on commit 86cf627

Please sign in to comment.