Skip to content

Commit

Permalink
feat: add spv and fixedincometypes to portfolio assets
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed May 28, 2024
1 parent 9f0eed4 commit 1a14939
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 36 deletions.
20 changes: 16 additions & 4 deletions api/src/graphql/server/generated/drive/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ export interface NexusGenObjects {
balance: number; // Float!
currency: string; // String!
id: string; // ID!
spvId: string; // ID!
spv?: NexusGenRootTypes['Spv'] | null; // Spv
spvId?: string | null; // ID
}
Challenge: { // root type
hex: string; // String!
Expand Down Expand Up @@ -298,6 +299,7 @@ export interface NexusGenObjects {
ISIN?: string | null; // String
annualizedYield: number; // Float!
coupon?: number | null; // Float
fixedIncomeType: NexusGenRootTypes['FixedIncomeType']; // FixedIncomeType!
fixedIncomeTypeId: string; // ID!
id: string; // ID!
maturity: NexusGenScalars['Date']; // Date!
Expand All @@ -308,7 +310,8 @@ export interface NexusGenObjects {
purchaseProceeds: number; // Float!
realizedSurplus: number; // Float!
salesProceeds?: number | null; // Float
spvId: string; // ID!
spv?: NexusGenRootTypes['Spv'] | null; // Spv
spvId?: string | null; // ID
totalDiscount: number; // Float!
}
FixedIncomeType: { // root type
Expand Down Expand Up @@ -721,7 +724,8 @@ export interface NexusGenFieldTypes {
balance: number; // Float!
currency: string; // String!
id: string; // ID!
spvId: string; // ID!
spv: NexusGenRootTypes['Spv'] | null; // Spv
spvId: string | null; // ID
}
Challenge: { // field return type
hex: string; // String!
Expand Down Expand Up @@ -782,6 +786,7 @@ export interface NexusGenFieldTypes {
ISIN: string | null; // String
annualizedYield: number; // Float!
coupon: number | null; // Float
fixedIncomeType: NexusGenRootTypes['FixedIncomeType']; // FixedIncomeType!
fixedIncomeTypeId: string; // ID!
id: string; // ID!
maturity: NexusGenScalars['Date']; // Date!
Expand All @@ -792,7 +797,8 @@ export interface NexusGenFieldTypes {
purchaseProceeds: number; // Float!
realizedSurplus: number; // Float!
salesProceeds: number | null; // Float
spvId: string; // ID!
spv: NexusGenRootTypes['Spv'] | null; // Spv
spvId: string | null; // ID
totalDiscount: number; // Float!
}
FixedIncomeType: { // field return type
Expand Down Expand Up @@ -1241,6 +1247,7 @@ export interface NexusGenFieldTypeNames {
balance: 'Float'
currency: 'String'
id: 'ID'
spv: 'Spv'
spvId: 'ID'
}
Challenge: { // field return type name
Expand Down Expand Up @@ -1302,6 +1309,7 @@ export interface NexusGenFieldTypeNames {
ISIN: 'String'
annualizedYield: 'Float'
coupon: 'Float'
fixedIncomeType: 'FixedIncomeType'
fixedIncomeTypeId: 'ID'
id: 'ID'
maturity: 'Date'
Expand All @@ -1312,6 +1320,7 @@ export interface NexusGenFieldTypeNames {
purchaseProceeds: 'Float'
realizedSurplus: 'Float'
salesProceeds: 'Float'
spv: 'Spv'
spvId: 'ID'
totalDiscount: 'Float'
}
Expand Down Expand Up @@ -1698,6 +1707,9 @@ export interface NexusGenArgTypes {
document: { // args
id: string; // String!
}
rwaPortfolios: { // args
id?: string | null; // String
}
}
Sync: {
strands: { // args
Expand Down
9 changes: 6 additions & 3 deletions api/src/graphql/server/generated/drive/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ type Cash {
balance: Float!
currency: String!
id: ID!
spvId: ID!
spv: Spv
spvId: ID
}

type Challenge {
Expand Down Expand Up @@ -208,6 +209,7 @@ type FixedIncome {
ISIN: String
annualizedYield: Float!
coupon: Float
fixedIncomeType: FixedIncomeType!
fixedIncomeTypeId: ID!
id: ID!
maturity: Date!
Expand All @@ -218,7 +220,8 @@ type FixedIncome {
purchaseProceeds: Float!
realizedSurplus: Float!
salesProceeds: Float
spvId: ID!
spv: Spv
spvId: ID
totalDiscount: Float!
}

Expand Down Expand Up @@ -474,7 +477,7 @@ type Query {
document(id: String!): IDocument
documents: [IDocument]
drive: DocumentDriveState
rwaPortfolios: [RealWorldAssetsPortfolio]
rwaPortfolios(id: String): [RealWorldAssetsPortfolio]
system: SwitchboardDrive
}

Expand Down
8 changes: 4 additions & 4 deletions api/src/graphql/server/generated/index/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,20 @@ declare global {
* resolver from executing.
*/
authorize?: FieldAuthorizeResolver<TypeName, FieldName>

/**
* Async validation function. Reject when validation fails. Resolve otherwise.
*/
validate?:
validate?:
NexusGenArgTypes extends HasTypeField<TypeName, FieldName>
? ArgsValidationConfig<NexusGenArgTypes[TypeName][FieldName]>
: never

}
interface NexusGenPluginInputFieldConfig<TypeName extends string, FieldName extends string> {
}
interface NexusGenPluginSchemaConfig {
}
interface NexusGenPluginArgConfig {
}
}
}
30 changes: 17 additions & 13 deletions api/src/modules/real-world-assets/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { enumType, interfaceType, list, objectType, queryField, unionType } from 'nexus';
import { arg, enumType, interfaceType, list, objectType, queryField, stringArg, unionType } from 'nexus';
import { GQLDateBase } from '../system';
import { documentModelInterface } from '../document';
import { getChildLogger } from '../../logger';
import { string } from 'zod';

const logger = getChildLogger({ msgPrefix: 'REAL WORLD ASSETS RESOLVER' });

Expand Down Expand Up @@ -31,7 +32,8 @@ export const Cash = objectType({
name: "Cash",
definition(t) {
t.nonNull.id("id")
t.nonNull.id("spvId")
t.id("spvId")
t.field("spv", { type: Spv })
t.nonNull.string("currency")
t.nonNull.float("balance")
}
Expand All @@ -41,8 +43,10 @@ export const FixedIncome = objectType({
definition(t) {
t.nonNull.id("id")
t.nonNull.id("fixedIncomeTypeId")
t.nonNull.field("fixedIncomeType", { type: FixedIncomeType })
t.nonNull.string("name")
t.nonNull.id("spvId")
t.id("spvId")
t.field("spv", { type: Spv })
t.nonNull.field("maturity", { type: GQLDateBase })
t.nonNull.field("purchaseDate", { type: GQLDateBase })
t.nonNull.float("notional")
Expand Down Expand Up @@ -160,17 +164,17 @@ export const RealWorldAssetsDocument = objectType({

export const rwaQuery = queryField('rwaPortfolios', {
type: list(RealWorldAssetsPortfolio),
// args: {
// filter: arg(
// {
// type: filterInput,
// }
// ),
// },
resolve: async (_root, args, ctx) => {
args: {
id: stringArg(),
},
resolve: async (_root, { id }, ctx) => {
try {
const doc = await ctx.prisma.rWAPortfolio.findRWAPortfolios({ driveId: ctx.driveId });
return doc;
const docs = await ctx.prisma.rWAPortfolio.findRWAPortfolios({ driveId: ctx.driveId });
if (id) {
return docs.filter(e => e.id === id);
}

return docs;
} catch (e: any) {
logger.error({ msg: e.message });
}
Expand Down
35 changes: 23 additions & 12 deletions api/src/modules/real-world-assets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export function transformPortfolioToState(portfolios: Prisma.RWAPortfolioGetPayl
return portfolios.map(portfolio => ({
id: portfolio.documentId,
principalLenderAccountId: portfolio.principalLenderAccountId,
// spvs: [],
spvs: portfolio.spvs.map(spv => ({
id: spv.spv.id,
name: spv.spv.name
Expand All @@ -59,18 +58,30 @@ export function transformPortfolioToState(portfolios: Prisma.RWAPortfolioGetPayl
id: feeType.spv.id,
name: feeType.spv.name
})),
portfolio: portfolio.portfolio.map(asset => ({
...asset,
id: asset.id,
purchasePrice: asset.purchasePrice,
purchaseDate: asset.purchaseDate,
name: asset.name,
salesProceeds: asset.salesProceeds,
fixedIncomeType: {
id: asset.fixedIncomeType?.id,
name: asset.fixedIncomeType?.name
portfolio: portfolio.portfolio.map(asset => {
const spv = portfolio.spvs.map(spv => ({
id: spv.spv.id,
name: spv.spv.name
})).find(e => e.id === asset.spvId)

const fixedIncomeType = portfolio.fixedIncomeTypes.map(fixedIncomeType => ({
id: fixedIncomeType.fixedIncome.id,
name: fixedIncomeType.fixedIncome.name
})).find(e => e.id == asset.fixedIncomeTypeId);

return {
...asset,
id: asset.id,
purchasePrice: asset.purchasePrice,
purchaseDate: asset.purchaseDate,
name: asset.name,
salesProceeds: asset.salesProceeds,
fixedIncomeType: fixedIncomeType,
spv: spv,
spvId: asset.spvId,
fixedIncomeTypeId: asset.fixedIncomeTypeId
}
})),
}),
serviceProviderFeeTypes: portfolio.RWAPortfolioServiceProviderFeeType.map(serviceProviderFeeType => ({
...serviceProviderFeeType
})),
Expand Down

0 comments on commit 1a14939

Please sign in to comment.