Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions packages/token-sdk/src/types/WithContractId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ContractId } from "./daml.js";

export type WithContractId<ContractParams = Record<string, unknown>> =
ContractParams & {
contractId: ContractId;
};
1 change: 1 addition & 0 deletions packages/token-sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./CreatedEvent.js";
export * from "./daml.js";
export * from "./InstrumentId.js";
export * from "./UserKeyPair.js";
export * from "./WithContractId.js";
65 changes: 31 additions & 34 deletions packages/token-sdk/src/wrappedSdk/bonds/lifecycleEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@ import { LedgerController } from "@canton-network/wallet-sdk";
import { ActiveContractResponse } from "../../types/ActiveContractResponse.js";
import { ContractId, Party } from "../../types/daml.js";
import { bondLifecycleEffectTemplateId } from "../../constants/templateIds.js";
import { InstrumentId } from "../../types/InstrumentId.js";
import { WithContractId } from "../../types/WithContractId.js";

export interface BondLifecycleEffectParams {
producedVersion: string | null;
eventType: "CouponPayment" | "Redemption";
targetInstrumentId: string;
targetVersion: string;
eventDate: string;
amount: number;
}
export type LifecycleEventType = "CouponPayment" | "Redemption";

export interface BondLifecycleEffect {
contractId: ContractId;
producedVersion: string | null;
eventType: "CouponPayment" | "Redemption";
export interface BondLifecycleEffectParams {
issuer: Party;
depository: Party;
eventType: LifecycleEventType;
targetInstrumentId: string;
targetVersion: string;
eventDate: string;
producedVersion?: string;
eventDate: number;
settlementTime?: number;
amount: number;
currencyInstrumentId: InstrumentId;
}

export async function getLatestBondLifecycleEffect(
Expand Down Expand Up @@ -58,34 +56,33 @@ export async function getLatestBondLifecycleEffect(
export async function getAllBondLifecycleEffects(
ledger: LedgerController,
party: Party
): Promise<BondLifecycleEffect[]> {
): Promise<WithContractId<BondLifecycleEffectParams>[]> {
const end = await ledger.ledgerEnd();
const effects = (await ledger.activeContracts({
const activeContracts = (await ledger.activeContracts({
offset: end.offset,
templateIds: [bondLifecycleEffectTemplateId],
filterByParty: true,
parties: [party],
})) as ActiveContractResponse<BondLifecycleEffectParams>[];

return effects
.map((contract) => {
const jsActive = contract.contractEntry.JsActiveContract;
if (!jsActive) return null;
const filteredEntries = activeContracts.filter(({ contractEntry }) => {
const jsActive = contractEntry.JsActiveContract;
if (!jsActive) return false;
return true;
// TODO: consider filtering by issuer or other criteria
// const { createArgument } = jsActive.createdEvent;
});

const createArg = jsActive.createdEvent.createArgument;
const contractId = jsActive.createdEvent.contractId;
return filteredEntries.map((contract) => {
const bondLifecycleEffect =
contract.contractEntry.JsActiveContract!.createdEvent
.createArgument;

return {
contractId,
producedVersion: createArg.producedVersion,
eventType: createArg.eventType,
targetInstrumentId: createArg.targetInstrumentId,
targetVersion: createArg.targetVersion,
eventDate: createArg.eventDate,
amount: createArg.amount,
};
})
.filter(
(effect): effect is NonNullable<typeof effect> => effect !== null
);
return {
...bondLifecycleEffect,
contractId:
contract.contractEntry.JsActiveContract!.createdEvent
.contractId,
};
});
}
16 changes: 1 addition & 15 deletions packages/token-sdk/src/wrappedSdk/bonds/lifecycleInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,7 @@ import { ActiveContractResponse } from "../../types/ActiveContractResponse.js";
import { getContractDisclosure } from "../contractDisclosure.js";
import { InstrumentId } from "../../types/InstrumentId.js";
import { CreatedEvent } from "../../types/CreatedEvent.js";

export type LifecycleEventType = "CouponPayment" | "Redemption";

export interface BondLifecycleEffect {
issuer: Party;
depository: Party;
eventType: LifecycleEventType;
targetInstrumentId: string;
targetVersion: string;
producedVersion?: string;
eventDate: number;
settlementTime?: number;
amount: number;
currencyInstrumentId: InstrumentId;
}
import { LifecycleEventType } from "./lifecycleEffect.js";

export interface BondLifecycleInstructionParams {
eventType: LifecycleEventType;
Expand Down
Loading