@open-captable-protocol/canton 0.2.222 → 0.2.224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/functions/OpenCapTable/capTable/damlToOcf.d.ts +3 -4
  2. package/dist/functions/OpenCapTable/capTable/damlToOcf.d.ts.map +1 -1
  3. package/dist/functions/OpenCapTable/capTable/damlToOcf.js +55 -2
  4. package/dist/functions/OpenCapTable/capTable/damlToOcf.js.map +1 -1
  5. package/dist/functions/OpenCapTable/convertibleCancellation/createConvertibleCancellation.d.ts.map +1 -1
  6. package/dist/functions/OpenCapTable/convertibleCancellation/createConvertibleCancellation.js +1 -0
  7. package/dist/functions/OpenCapTable/convertibleCancellation/createConvertibleCancellation.js.map +1 -1
  8. package/dist/functions/OpenCapTable/convertibleCancellation/damlToOcf.d.ts +9 -0
  9. package/dist/functions/OpenCapTable/convertibleCancellation/damlToOcf.d.ts.map +1 -1
  10. package/dist/functions/OpenCapTable/convertibleCancellation/damlToOcf.js +7 -0
  11. package/dist/functions/OpenCapTable/convertibleCancellation/damlToOcf.js.map +1 -1
  12. package/dist/functions/OpenCapTable/convertibleIssuance/getConvertibleIssuanceAsOcf.d.ts +3 -1
  13. package/dist/functions/OpenCapTable/convertibleIssuance/getConvertibleIssuanceAsOcf.d.ts.map +1 -1
  14. package/dist/functions/OpenCapTable/convertibleIssuance/getConvertibleIssuanceAsOcf.js +396 -405
  15. package/dist/functions/OpenCapTable/convertibleIssuance/getConvertibleIssuanceAsOcf.js.map +1 -1
  16. package/dist/functions/OpenCapTable/document/getDocumentAsOcf.d.ts +2 -0
  17. package/dist/functions/OpenCapTable/document/getDocumentAsOcf.d.ts.map +1 -1
  18. package/dist/functions/OpenCapTable/document/getDocumentAsOcf.js +1 -0
  19. package/dist/functions/OpenCapTable/document/getDocumentAsOcf.js.map +1 -1
  20. package/dist/functions/OpenCapTable/equityCompensationExercise/getEquityCompensationExerciseAsOcf.d.ts +9 -12
  21. package/dist/functions/OpenCapTable/equityCompensationExercise/getEquityCompensationExerciseAsOcf.d.ts.map +1 -1
  22. package/dist/functions/OpenCapTable/equityCompensationExercise/getEquityCompensationExerciseAsOcf.js +48 -19
  23. package/dist/functions/OpenCapTable/equityCompensationExercise/getEquityCompensationExerciseAsOcf.js.map +1 -1
  24. package/dist/functions/OpenCapTable/equityCompensationExercise/index.d.ts +1 -1
  25. package/dist/functions/OpenCapTable/equityCompensationExercise/index.d.ts.map +1 -1
  26. package/dist/functions/OpenCapTable/equityCompensationExercise/index.js +4 -15
  27. package/dist/functions/OpenCapTable/equityCompensationExercise/index.js.map +1 -1
  28. package/dist/functions/OpenCapTable/equityCompensationIssuance/getEquityCompensationIssuanceAsOcf.d.ts +9 -39
  29. package/dist/functions/OpenCapTable/equityCompensationIssuance/getEquityCompensationIssuanceAsOcf.d.ts.map +1 -1
  30. package/dist/functions/OpenCapTable/equityCompensationIssuance/getEquityCompensationIssuanceAsOcf.js +60 -69
  31. package/dist/functions/OpenCapTable/equityCompensationIssuance/getEquityCompensationIssuanceAsOcf.js.map +1 -1
  32. package/dist/functions/OpenCapTable/issuer/getIssuerAsOcf.d.ts +3 -0
  33. package/dist/functions/OpenCapTable/issuer/getIssuerAsOcf.d.ts.map +1 -1
  34. package/dist/functions/OpenCapTable/issuer/getIssuerAsOcf.js +1 -0
  35. package/dist/functions/OpenCapTable/issuer/getIssuerAsOcf.js.map +1 -1
  36. package/dist/functions/OpenCapTable/issuerAuthorizedSharesAdjustment/getIssuerAuthorizedSharesAdjustmentAsOcf.d.ts +9 -11
  37. package/dist/functions/OpenCapTable/issuerAuthorizedSharesAdjustment/getIssuerAuthorizedSharesAdjustmentAsOcf.d.ts.map +1 -1
  38. package/dist/functions/OpenCapTable/issuerAuthorizedSharesAdjustment/getIssuerAuthorizedSharesAdjustmentAsOcf.js +27 -15
  39. package/dist/functions/OpenCapTable/issuerAuthorizedSharesAdjustment/getIssuerAuthorizedSharesAdjustmentAsOcf.js.map +1 -1
  40. package/dist/functions/OpenCapTable/stakeholder/getStakeholderAsOcf.d.ts +2 -0
  41. package/dist/functions/OpenCapTable/stakeholder/getStakeholderAsOcf.d.ts.map +1 -1
  42. package/dist/functions/OpenCapTable/stakeholder/getStakeholderAsOcf.js +1 -0
  43. package/dist/functions/OpenCapTable/stakeholder/getStakeholderAsOcf.js.map +1 -1
  44. package/dist/functions/OpenCapTable/stockClass/getStockClassAsOcf.d.ts +24 -1
  45. package/dist/functions/OpenCapTable/stockClass/getStockClassAsOcf.d.ts.map +1 -1
  46. package/dist/functions/OpenCapTable/stockClass/getStockClassAsOcf.js +1 -0
  47. package/dist/functions/OpenCapTable/stockClass/getStockClassAsOcf.js.map +1 -1
  48. package/dist/functions/OpenCapTable/stockClassAuthorizedSharesAdjustment/getStockClassAuthorizedSharesAdjustmentAsOcf.d.ts +7 -0
  49. package/dist/functions/OpenCapTable/stockClassAuthorizedSharesAdjustment/getStockClassAuthorizedSharesAdjustmentAsOcf.d.ts.map +1 -1
  50. package/dist/functions/OpenCapTable/stockClassAuthorizedSharesAdjustment/getStockClassAuthorizedSharesAdjustmentAsOcf.js +27 -13
  51. package/dist/functions/OpenCapTable/stockClassAuthorizedSharesAdjustment/getStockClassAuthorizedSharesAdjustmentAsOcf.js.map +1 -1
  52. package/dist/functions/OpenCapTable/stockIssuance/getStockIssuanceAsOcf.d.ts +2 -0
  53. package/dist/functions/OpenCapTable/stockIssuance/getStockIssuanceAsOcf.d.ts.map +1 -1
  54. package/dist/functions/OpenCapTable/stockIssuance/getStockIssuanceAsOcf.js +1 -0
  55. package/dist/functions/OpenCapTable/stockIssuance/getStockIssuanceAsOcf.js.map +1 -1
  56. package/dist/functions/OpenCapTable/stockLegendTemplate/getStockLegendTemplateAsOcf.d.ts +3 -0
  57. package/dist/functions/OpenCapTable/stockLegendTemplate/getStockLegendTemplateAsOcf.d.ts.map +1 -1
  58. package/dist/functions/OpenCapTable/stockLegendTemplate/getStockLegendTemplateAsOcf.js +1 -0
  59. package/dist/functions/OpenCapTable/stockLegendTemplate/getStockLegendTemplateAsOcf.js.map +1 -1
  60. package/dist/functions/OpenCapTable/stockPlan/getStockPlanAsOcf.d.ts +2 -0
  61. package/dist/functions/OpenCapTable/stockPlan/getStockPlanAsOcf.d.ts.map +1 -1
  62. package/dist/functions/OpenCapTable/stockPlan/getStockPlanAsOcf.js +1 -0
  63. package/dist/functions/OpenCapTable/stockPlan/getStockPlanAsOcf.js.map +1 -1
  64. package/dist/functions/OpenCapTable/stockPlanPoolAdjustment/getStockPlanPoolAdjustmentAsOcf.d.ts +13 -11
  65. package/dist/functions/OpenCapTable/stockPlanPoolAdjustment/getStockPlanPoolAdjustmentAsOcf.d.ts.map +1 -1
  66. package/dist/functions/OpenCapTable/stockPlanPoolAdjustment/getStockPlanPoolAdjustmentAsOcf.js +23 -12
  67. package/dist/functions/OpenCapTable/stockPlanPoolAdjustment/getStockPlanPoolAdjustmentAsOcf.js.map +1 -1
  68. package/dist/functions/OpenCapTable/vestingTerms/getVestingTermsAsOcf.d.ts +2 -0
  69. package/dist/functions/OpenCapTable/vestingTerms/getVestingTermsAsOcf.d.ts.map +1 -1
  70. package/dist/functions/OpenCapTable/vestingTerms/getVestingTermsAsOcf.js +1 -0
  71. package/dist/functions/OpenCapTable/vestingTerms/getVestingTermsAsOcf.js.map +1 -1
  72. package/dist/functions/OpenCapTable/warrantExercise/damlToOcf.d.ts +3 -16
  73. package/dist/functions/OpenCapTable/warrantExercise/damlToOcf.d.ts.map +1 -1
  74. package/dist/functions/OpenCapTable/warrantExercise/damlToOcf.js +35 -5
  75. package/dist/functions/OpenCapTable/warrantExercise/damlToOcf.js.map +1 -1
  76. package/dist/functions/OpenCapTable/warrantExercise/getWarrantExerciseAsOcf.d.ts.map +1 -1
  77. package/dist/functions/OpenCapTable/warrantExercise/getWarrantExerciseAsOcf.js +6 -29
  78. package/dist/functions/OpenCapTable/warrantExercise/getWarrantExerciseAsOcf.js.map +1 -1
  79. package/dist/functions/OpenCapTable/warrantExercise/warrantExerciseDataToDaml.d.ts.map +1 -1
  80. package/dist/functions/OpenCapTable/warrantExercise/warrantExerciseDataToDaml.js +7 -0
  81. package/dist/functions/OpenCapTable/warrantExercise/warrantExerciseDataToDaml.js.map +1 -1
  82. package/dist/functions/OpenCapTable/warrantIssuance/getWarrantIssuanceAsOcf.d.ts +9 -79
  83. package/dist/functions/OpenCapTable/warrantIssuance/getWarrantIssuanceAsOcf.d.ts.map +1 -1
  84. package/dist/functions/OpenCapTable/warrantIssuance/getWarrantIssuanceAsOcf.js +177 -205
  85. package/dist/functions/OpenCapTable/warrantIssuance/getWarrantIssuanceAsOcf.js.map +1 -1
  86. package/dist/types/native.d.ts +4 -0
  87. package/dist/types/native.d.ts.map +1 -1
  88. package/dist/utils/cantonOcfExtractor.js +2 -2
  89. package/dist/utils/cantonOcfExtractor.js.map +1 -1
  90. package/dist/utils/typeConversions.d.ts +20 -1
  91. package/dist/utils/typeConversions.d.ts.map +1 -1
  92. package/dist/utils/typeConversions.js +62 -0
  93. package/dist/utils/typeConversions.js.map +1 -1
  94. package/package.json +4 -4
@@ -1,428 +1,391 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.damlConvertibleIssuanceDataToNative = damlConvertibleIssuanceDataToNative;
3
4
  exports.getConvertibleIssuanceAsOcf = getConvertibleIssuanceAsOcf;
4
5
  const errors_1 = require("../../../errors");
5
6
  const typeConversions_1 = require("../../../utils/typeConversions");
6
- /** Retrieve a ConvertibleIssuance contract and return it as an OCF JSON object */
7
- async function getConvertibleIssuanceAsOcf(client, params) {
8
- const res = await client.getEventsByContractId({ contractId: params.contractId });
9
- const created = res.created?.createdEvent;
10
- if (!created?.createArgument) {
11
- throw new errors_1.OcpContractError('Missing createArgument for ConvertibleIssuance', {
12
- contractId: params.contractId,
13
- code: errors_1.OcpErrorCodes.RESULT_NOT_FOUND,
14
- });
15
- }
16
- const arg = created.createArgument;
17
- if (typeof arg !== 'object' || !('issuance_data' in arg)) {
18
- throw new errors_1.OcpParseError('Unexpected createArgument for ConvertibleIssuance', {
19
- source: 'ConvertibleIssuance.createArgument',
20
- code: errors_1.OcpErrorCodes.SCHEMA_MISMATCH,
21
- });
22
- }
23
- const d = arg.issuance_data;
24
- const typeMap = {
25
- OcfConvertibleNote: 'NOTE',
26
- OcfConvertibleSafe: 'SAFE',
27
- OcfConvertibleSecurity: 'SECURITY',
28
- };
29
- const convertTriggers = (ts, convertibleType, issuanceId) => {
30
- if (!Array.isArray(ts))
31
- return [];
32
- const mapTagToType = (tag) => {
33
- if (tag === 'OcfTriggerTypeTypeAutomaticOnDate')
34
- return 'AUTOMATIC_ON_DATE';
35
- if (tag === 'OcfTriggerTypeTypeElectiveInRange')
36
- return 'ELECTIVE_IN_RANGE';
37
- if (tag === 'OcfTriggerTypeTypeElectiveOnCondition')
38
- return 'ELECTIVE_ON_CONDITION';
39
- if (tag === 'OcfTriggerTypeTypeElectiveAtWill')
40
- return 'ELECTIVE_AT_WILL';
41
- if (tag === 'OcfTriggerTypeTypeUnspecified')
42
- return 'UNSPECIFIED';
43
- return 'AUTOMATIC_ON_CONDITION';
7
+ const typeMap = {
8
+ OcfConvertibleNote: 'NOTE',
9
+ OcfConvertibleSafe: 'SAFE',
10
+ OcfConvertibleSecurity: 'SECURITY',
11
+ };
12
+ const convertTriggers = (ts, issuanceId) => {
13
+ if (!Array.isArray(ts))
14
+ return [];
15
+ const mapMechanism = (m) => {
16
+ // Handle both string enum and DAML variant { tag, value }
17
+ const mapTiming = (t) => {
18
+ const s = (0, typeConversions_1.safeString)(t);
19
+ if (s.endsWith('PreMoney'))
20
+ return 'PRE_MONEY';
21
+ if (s.endsWith('PostMoney'))
22
+ return 'POST_MONEY';
23
+ return undefined;
44
24
  };
45
- const mapMechanism = (m) => {
46
- // Handle both string enum and DAML variant { tag, value }
47
- const mapMonetary = (mon) => {
48
- if (!mon || typeof mon !== 'object')
49
- return undefined;
50
- const monObj = mon;
51
- // Validate amount exists and is string or number
52
- if (monObj.amount === undefined || monObj.amount === null) {
53
- throw new errors_1.OcpValidationError('monetary.amount', 'Required field is missing', {
54
- code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
55
- });
56
- }
57
- if (typeof monObj.amount !== 'string' && typeof monObj.amount !== 'number') {
58
- throw new errors_1.OcpValidationError('monetary.amount', `Must be string or number, got ${typeof monObj.amount}`, {
59
- code: errors_1.OcpErrorCodes.INVALID_TYPE,
60
- expectedType: 'string | number',
61
- receivedValue: monObj.amount,
62
- });
63
- }
64
- // Validate currency exists and is string
65
- if (typeof monObj.currency !== 'string' || !monObj.currency) {
66
- throw new errors_1.OcpValidationError('monetary.currency', 'Required field must be a non-empty string', {
67
- code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
68
- expectedType: 'string',
69
- receivedValue: monObj.currency,
70
- });
71
- }
72
- const amount = (0, typeConversions_1.normalizeNumericString)(typeof monObj.amount === 'number' ? monObj.amount.toString() : monObj.amount);
73
- return {
74
- amount,
75
- currency: monObj.currency,
76
- };
77
- };
78
- const mapTiming = (t) => {
79
- const s = (0, typeConversions_1.safeString)(t);
80
- if (s.endsWith('PreMoney'))
81
- return 'PRE_MONEY';
82
- if (s.endsWith('PostMoney'))
83
- return 'POST_MONEY';
84
- return undefined;
85
- };
86
- if (typeof m === 'string') {
87
- throw new errors_1.OcpParseError(`conversion_mechanism missing variant value (got tag '${m}')`, {
88
- source: 'conversionRight.conversion_mechanism',
89
- code: errors_1.OcpErrorCodes.SCHEMA_MISMATCH,
25
+ if (typeof m === 'string') {
26
+ throw new errors_1.OcpParseError(`conversion_mechanism missing variant value (got tag '${m}')`, {
27
+ source: 'conversionRight.conversion_mechanism',
28
+ code: errors_1.OcpErrorCodes.SCHEMA_MISMATCH,
29
+ });
30
+ }
31
+ if (m && typeof m === 'object') {
32
+ const tag = m.tag;
33
+ const value = m.value;
34
+ if (!tag || !value) {
35
+ throw new errors_1.OcpValidationError('conversion_mechanism', 'Tag and value are required', {
36
+ code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
90
37
  });
91
38
  }
92
- if (m && typeof m === 'object') {
93
- const tag = m.tag;
94
- const value = m.value;
95
- if (!tag || !value) {
96
- throw new errors_1.OcpValidationError('conversion_mechanism', 'Tag and value are required', {
97
- code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
98
- });
99
- }
100
- switch (tag) {
101
- case 'OcfConvMechSAFE': {
102
- const mech = {
103
- type: 'SAFE_CONVERSION',
104
- conversion_mfn: Boolean(value.conversion_mfn),
105
- ...(typeof value.conversion_discount === 'number' || typeof value.conversion_discount === 'string'
106
- ? {
107
- conversion_discount: (0, typeConversions_1.normalizeNumericString)(typeof value.conversion_discount === 'number'
108
- ? value.conversion_discount.toString()
109
- : value.conversion_discount),
110
- }
111
- : {}),
112
- ...(value.conversion_valuation_cap
113
- ? {
114
- conversion_valuation_cap: mapMonetary(value.conversion_valuation_cap) ?? {
115
- amount: '',
116
- currency: '',
117
- },
118
- }
119
- : {}),
120
- ...(value.conversion_timing ? { conversion_timing: mapTiming(value.conversion_timing) } : {}),
121
- ...(value.capitalization_definition
122
- ? { capitalization_definition: value.capitalization_definition }
123
- : {}),
124
- ...(value.capitalization_definition_rules
125
- ? { capitalization_definition_rules: value.capitalization_definition_rules }
126
- : {}),
127
- ...(value.exit_multiple
128
- ? {
129
- exit_multiple: {
130
- numerator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.numerator)),
131
- denominator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.denominator)),
132
- },
133
- }
134
- : {}),
135
- };
136
- return mech;
137
- }
138
- case 'OcfConvMechPercentCapitalization': {
139
- const mech = {
140
- type: 'FIXED_PERCENT_OF_CAPITALIZATION_CONVERSION',
141
- converts_to_percent: (0, typeConversions_1.normalizeNumericString)(typeof value.converts_to_percent === 'number'
142
- ? value.converts_to_percent.toString()
143
- : (() => {
144
- if (typeof value.converts_to_percent !== 'string') {
145
- throw new errors_1.OcpValidationError('conversion_mechanism.converts_to_percent', `Must be string or number, got ${typeof value.converts_to_percent}`, {
146
- code: errors_1.OcpErrorCodes.INVALID_TYPE,
147
- expectedType: 'string | number',
148
- receivedValue: value.converts_to_percent,
149
- });
150
- }
151
- return value.converts_to_percent;
152
- })()),
153
- ...(value.capitalization_definition
154
- ? { capitalization_definition: value.capitalization_definition }
155
- : {}),
156
- ...(value.capitalization_definition_rules
157
- ? { capitalization_definition_rules: value.capitalization_definition_rules }
158
- : {}),
159
- };
160
- return mech;
161
- }
162
- case 'OcfConvMechFixedAmount': {
163
- const mech = {
164
- type: 'FIXED_AMOUNT_CONVERSION',
165
- converts_to_quantity: (0, typeConversions_1.normalizeNumericString)(typeof value.converts_to_quantity === 'number'
166
- ? value.converts_to_quantity.toString()
167
- : (() => {
168
- if (typeof value.converts_to_quantity !== 'string') {
169
- throw new errors_1.OcpValidationError('conversion_mechanism.converts_to_quantity', `Must be string or number, got ${typeof value.converts_to_quantity}`, {
170
- code: errors_1.OcpErrorCodes.INVALID_TYPE,
171
- expectedType: 'string | number',
172
- receivedValue: value.converts_to_quantity,
173
- });
39
+ switch (tag) {
40
+ case 'OcfConvMechSAFE': {
41
+ const mech = {
42
+ type: 'SAFE_CONVERSION',
43
+ conversion_mfn: Boolean(value.conversion_mfn),
44
+ ...(typeof value.conversion_discount === 'number' || typeof value.conversion_discount === 'string'
45
+ ? {
46
+ conversion_discount: (0, typeConversions_1.normalizeNumericString)(typeof value.conversion_discount === 'number'
47
+ ? value.conversion_discount.toString()
48
+ : value.conversion_discount),
49
+ }
50
+ : {}),
51
+ ...(value.conversion_valuation_cap
52
+ ? {
53
+ conversion_valuation_cap: (() => {
54
+ const monetary = (0, typeConversions_1.damlMonetaryToNativeWithValidation)(value.conversion_valuation_cap);
55
+ if (!monetary) {
56
+ throw new errors_1.OcpValidationError('convertibleIssuance.conversion_valuation_cap', 'Invalid monetary value for conversion_valuation_cap', { code: errors_1.OcpErrorCodes.INVALID_TYPE, receivedValue: value.conversion_valuation_cap });
174
57
  }
175
- return value.converts_to_quantity;
176
- })()),
177
- };
178
- return mech;
179
- }
180
- case 'OcfConvMechValuationBased': {
181
- const mech = {
182
- type: 'VALUATION_BASED_CONVERSION',
183
- valuation_type: value.valuation_type,
184
- ...(value.valuation_amount
185
- ? {
186
- valuation_amount: mapMonetary(value.valuation_amount) ?? {
187
- amount: '',
188
- currency: '',
189
- },
190
- }
191
- : {}),
192
- ...(value.capitalization_definition
193
- ? { capitalization_definition: value.capitalization_definition }
194
- : {}),
195
- ...(value.capitalization_definition_rules
196
- ? { capitalization_definition_rules: value.capitalization_definition_rules }
197
- : {}),
198
- };
199
- return mech;
200
- }
201
- case 'OcfConvMechSharePriceBased': {
202
- const mech = {
203
- type: 'SHARE_PRICE_BASED_CONVERSION',
204
- description: value.description,
205
- discount: Boolean(value.discount),
206
- ...(value.discount_percentage !== undefined && value.discount_percentage !== null
207
- ? {
208
- discount_percentage: (0, typeConversions_1.normalizeNumericString)(typeof value.discount_percentage === 'number'
209
- ? value.discount_percentage.toString()
210
- : typeof value.discount_percentage === 'string'
211
- ? value.discount_percentage
212
- : (() => {
213
- throw new errors_1.OcpValidationError('conversion_mechanism.discount_percentage', `Must be string or number, got ${typeof value.discount_percentage}`, {
214
- code: errors_1.OcpErrorCodes.INVALID_TYPE,
215
- expectedType: 'string | number',
216
- receivedValue: value.discount_percentage,
217
- });
218
- })()),
219
- }
220
- : {}),
221
- ...(value.discount_amount
222
- ? {
223
- discount_amount: mapMonetary(value.discount_amount) ?? {
224
- amount: '',
225
- currency: '',
226
- },
227
- }
228
- : {}),
229
- };
230
- return mech;
231
- }
232
- case 'OcfConvMechNote': {
233
- const interest_rates = Array.isArray(value.interest_rates)
234
- ? value.interest_rates.map((ir) => {
235
- const irObj = ir;
236
- // Validate interest rate
237
- if (irObj.rate === undefined || irObj.rate === null) {
238
- throw new errors_1.OcpValidationError('interest_rate.rate', 'Required field is missing', {
239
- code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
240
- });
241
- }
242
- if (typeof irObj.rate !== 'string' && typeof irObj.rate !== 'number') {
243
- throw new errors_1.OcpValidationError('interest_rate.rate', `Must be string or number, got ${typeof irObj.rate}`, {
58
+ return monetary;
59
+ })(),
60
+ }
61
+ : {}),
62
+ ...(value.conversion_timing ? { conversion_timing: mapTiming(value.conversion_timing) } : {}),
63
+ ...(value.capitalization_definition ? { capitalization_definition: value.capitalization_definition } : {}),
64
+ ...(value.capitalization_definition_rules
65
+ ? { capitalization_definition_rules: value.capitalization_definition_rules }
66
+ : {}),
67
+ ...(value.exit_multiple
68
+ ? {
69
+ exit_multiple: {
70
+ numerator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.numerator)),
71
+ denominator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.denominator)),
72
+ },
73
+ }
74
+ : {}),
75
+ };
76
+ return mech;
77
+ }
78
+ case 'OcfConvMechPercentCapitalization': {
79
+ const mech = {
80
+ type: 'FIXED_PERCENT_OF_CAPITALIZATION_CONVERSION',
81
+ converts_to_percent: (0, typeConversions_1.normalizeNumericString)(typeof value.converts_to_percent === 'number'
82
+ ? value.converts_to_percent.toString()
83
+ : (() => {
84
+ if (typeof value.converts_to_percent !== 'string') {
85
+ throw new errors_1.OcpValidationError('conversion_mechanism.converts_to_percent', `Must be string or number, got ${typeof value.converts_to_percent}`, {
244
86
  code: errors_1.OcpErrorCodes.INVALID_TYPE,
245
87
  expectedType: 'string | number',
246
- receivedValue: irObj.rate,
88
+ receivedValue: value.converts_to_percent,
247
89
  });
248
90
  }
249
- // Validate accrual_start_date
250
- if (typeof irObj.accrual_start_date !== 'string' || !irObj.accrual_start_date) {
251
- throw new errors_1.OcpValidationError('interest_rate.accrual_start_date', 'Required field must be a non-empty string', {
252
- code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
253
- expectedType: 'string',
254
- receivedValue: irObj.accrual_start_date,
91
+ return value.converts_to_percent;
92
+ })()),
93
+ ...(value.capitalization_definition ? { capitalization_definition: value.capitalization_definition } : {}),
94
+ ...(value.capitalization_definition_rules
95
+ ? { capitalization_definition_rules: value.capitalization_definition_rules }
96
+ : {}),
97
+ };
98
+ return mech;
99
+ }
100
+ case 'OcfConvMechFixedAmount': {
101
+ const mech = {
102
+ type: 'FIXED_AMOUNT_CONVERSION',
103
+ converts_to_quantity: (0, typeConversions_1.normalizeNumericString)(typeof value.converts_to_quantity === 'number'
104
+ ? value.converts_to_quantity.toString()
105
+ : (() => {
106
+ if (typeof value.converts_to_quantity !== 'string') {
107
+ throw new errors_1.OcpValidationError('conversion_mechanism.converts_to_quantity', `Must be string or number, got ${typeof value.converts_to_quantity}`, {
108
+ code: errors_1.OcpErrorCodes.INVALID_TYPE,
109
+ expectedType: 'string | number',
110
+ receivedValue: value.converts_to_quantity,
255
111
  });
256
112
  }
257
- return {
258
- rate: (0, typeConversions_1.normalizeNumericString)(typeof irObj.rate === 'number' ? irObj.rate.toString() : irObj.rate),
259
- accrual_start_date: irObj.accrual_start_date.split('T')[0],
260
- ...(irObj.accrual_end_date
261
- ? { accrual_end_date: irObj.accrual_end_date.split('T')[0] }
262
- : {}),
263
- };
264
- })
265
- : null;
266
- const accrualFromDaml = (v) => {
267
- const s = (0, typeConversions_1.safeString)(v);
268
- if (s.endsWith('OcfAccrualDaily') || s === 'OcfAccrualDaily')
269
- return 'DAILY';
270
- if (s.endsWith('OcfAccrualMonthly') || s === 'OcfAccrualMonthly')
271
- return 'MONTHLY';
272
- if (s.endsWith('OcfAccrualQuarterly') || s === 'OcfAccrualQuarterly')
273
- return 'QUARTERLY';
274
- if (s.endsWith('OcfAccrualSemiAnnual') || s === 'OcfAccrualSemiAnnual')
275
- return 'SEMI_ANNUAL';
276
- if (s.endsWith('OcfAccrualAnnual') || s === 'OcfAccrualAnnual')
277
- return 'ANNUAL';
113
+ return value.converts_to_quantity;
114
+ })()),
115
+ };
116
+ return mech;
117
+ }
118
+ case 'OcfConvMechValuationBased': {
119
+ const mech = {
120
+ type: 'VALUATION_BASED_CONVERSION',
121
+ valuation_type: value.valuation_type,
122
+ ...(value.valuation_amount
123
+ ? {
124
+ valuation_amount: (() => {
125
+ const monetary = (0, typeConversions_1.damlMonetaryToNativeWithValidation)(value.valuation_amount);
126
+ if (!monetary) {
127
+ throw new errors_1.OcpValidationError('convertibleIssuance.valuation_amount', 'Invalid monetary value for valuation_amount', { code: errors_1.OcpErrorCodes.INVALID_TYPE, receivedValue: value.valuation_amount });
128
+ }
129
+ return monetary;
130
+ })(),
131
+ }
132
+ : {}),
133
+ ...(value.capitalization_definition ? { capitalization_definition: value.capitalization_definition } : {}),
134
+ ...(value.capitalization_definition_rules
135
+ ? { capitalization_definition_rules: value.capitalization_definition_rules }
136
+ : {}),
137
+ };
138
+ return mech;
139
+ }
140
+ case 'OcfConvMechSharePriceBased': {
141
+ const mech = {
142
+ type: 'SHARE_PRICE_BASED_CONVERSION',
143
+ description: value.description,
144
+ discount: Boolean(value.discount),
145
+ ...(value.discount_percentage !== undefined && value.discount_percentage !== null
146
+ ? {
147
+ discount_percentage: (0, typeConversions_1.normalizeNumericString)(typeof value.discount_percentage === 'number'
148
+ ? value.discount_percentage.toString()
149
+ : typeof value.discount_percentage === 'string'
150
+ ? value.discount_percentage
151
+ : (() => {
152
+ throw new errors_1.OcpValidationError('conversion_mechanism.discount_percentage', `Must be string or number, got ${typeof value.discount_percentage}`, {
153
+ code: errors_1.OcpErrorCodes.INVALID_TYPE,
154
+ expectedType: 'string | number',
155
+ receivedValue: value.discount_percentage,
156
+ });
157
+ })()),
158
+ }
159
+ : {}),
160
+ ...(value.discount_amount
161
+ ? {
162
+ discount_amount: (() => {
163
+ const monetary = (0, typeConversions_1.damlMonetaryToNativeWithValidation)(value.discount_amount);
164
+ if (!monetary) {
165
+ throw new errors_1.OcpValidationError('convertibleIssuance.discount_amount', 'Invalid monetary value for discount_amount', { code: errors_1.OcpErrorCodes.INVALID_TYPE, receivedValue: value.discount_amount });
166
+ }
167
+ return monetary;
168
+ })(),
169
+ }
170
+ : {}),
171
+ };
172
+ return mech;
173
+ }
174
+ case 'OcfConvMechNote': {
175
+ const interest_rates = Array.isArray(value.interest_rates)
176
+ ? value.interest_rates.map((ir) => {
177
+ const irObj = ir;
178
+ // Validate interest rate
179
+ if (irObj.rate === undefined || irObj.rate === null) {
180
+ throw new errors_1.OcpValidationError('interest_rate.rate', 'Required field is missing', {
181
+ code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
182
+ });
183
+ }
184
+ if (typeof irObj.rate !== 'string' && typeof irObj.rate !== 'number') {
185
+ throw new errors_1.OcpValidationError('interest_rate.rate', `Must be string or number, got ${typeof irObj.rate}`, {
186
+ code: errors_1.OcpErrorCodes.INVALID_TYPE,
187
+ expectedType: 'string | number',
188
+ receivedValue: irObj.rate,
189
+ });
190
+ }
191
+ // Validate accrual_start_date
192
+ if (typeof irObj.accrual_start_date !== 'string' || !irObj.accrual_start_date) {
193
+ throw new errors_1.OcpValidationError('interest_rate.accrual_start_date', 'Required field must be a non-empty string', {
194
+ code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
195
+ expectedType: 'string',
196
+ receivedValue: irObj.accrual_start_date,
197
+ });
198
+ }
199
+ return {
200
+ rate: (0, typeConversions_1.normalizeNumericString)(typeof irObj.rate === 'number' ? irObj.rate.toString() : irObj.rate),
201
+ accrual_start_date: irObj.accrual_start_date.split('T')[0],
202
+ ...(irObj.accrual_end_date
203
+ ? { accrual_end_date: irObj.accrual_end_date.split('T')[0] }
204
+ : {}),
205
+ };
206
+ })
207
+ : null;
208
+ const accrualFromDaml = (v) => {
209
+ const s = (0, typeConversions_1.safeString)(v);
210
+ if (s.endsWith('OcfAccrualDaily') || s === 'OcfAccrualDaily')
211
+ return 'DAILY';
212
+ if (s.endsWith('OcfAccrualMonthly') || s === 'OcfAccrualMonthly')
213
+ return 'MONTHLY';
214
+ if (s.endsWith('OcfAccrualQuarterly') || s === 'OcfAccrualQuarterly')
215
+ return 'QUARTERLY';
216
+ if (s.endsWith('OcfAccrualSemiAnnual') || s === 'OcfAccrualSemiAnnual')
217
+ return 'SEMI_ANNUAL';
218
+ if (s.endsWith('OcfAccrualAnnual') || s === 'OcfAccrualAnnual')
219
+ return 'ANNUAL';
220
+ return undefined;
221
+ };
222
+ const compoundingFromDaml = (v) => {
223
+ const s = (0, typeConversions_1.safeString)(v);
224
+ if (!s)
278
225
  return undefined;
279
- };
280
- const compoundingFromDaml = (v) => {
281
- const s = (0, typeConversions_1.safeString)(v);
282
- if (!s)
283
- return undefined;
284
- if (s === 'OcfSimple')
285
- return 'SIMPLE';
286
- if (s === 'OcfCompounding')
287
- return 'COMPOUNDING';
288
- throw new errors_1.OcpParseError(`Unknown compounding_type: ${(0, typeConversions_1.safeString)(v)}`, {
289
- source: 'conversion_mechanism.compounding_type',
290
- code: errors_1.OcpErrorCodes.UNKNOWN_ENUM_VALUE,
291
- });
292
- };
293
- const mech = {
294
- type: 'CONVERTIBLE_NOTE_CONVERSION',
295
- interest_rates,
296
- ...(value.day_count_convention
297
- ? {
298
- day_count_convention: (0, typeConversions_1.safeString)(value.day_count_convention).endsWith('Actual365')
299
- ? 'ACTUAL_365'
300
- : '30_360',
301
- }
302
- : {}),
303
- ...(value.interest_payout
304
- ? {
305
- interest_payout: (0, typeConversions_1.safeString)(value.interest_payout).endsWith('Deferred') ? 'DEFERRED' : 'CASH',
306
- }
307
- : {}),
308
- ...(value.interest_accrual_period
309
- ? { interest_accrual_period: accrualFromDaml(value.interest_accrual_period) }
310
- : {}),
311
- ...(value.compounding_type ? { compounding_type: compoundingFromDaml(value.compounding_type) } : {}),
312
- ...(typeof value.conversion_discount === 'number' || typeof value.conversion_discount === 'string'
313
- ? {
314
- conversion_discount: (0, typeConversions_1.normalizeNumericString)(typeof value.conversion_discount === 'number'
315
- ? value.conversion_discount.toString()
316
- : value.conversion_discount),
317
- }
318
- : {}),
319
- ...(value.conversion_valuation_cap
320
- ? {
321
- conversion_valuation_cap: mapMonetary(value.conversion_valuation_cap) ?? {
322
- amount: '',
323
- currency: '',
324
- },
325
- }
326
- : {}),
327
- ...(value.capitalization_definition
328
- ? { capitalization_definition: value.capitalization_definition }
329
- : {}),
330
- ...(value.capitalization_definition_rules
331
- ? { capitalization_definition_rules: value.capitalization_definition_rules }
332
- : {}),
333
- ...(value.exit_multiple
334
- ? {
335
- exit_multiple: {
336
- numerator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.numerator)),
337
- denominator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.denominator)),
338
- },
339
- }
340
- : {}),
341
- ...(value.conversion_mfn ? { conversion_mfn: Boolean(value.conversion_mfn) } : {}),
342
- };
343
- return mech;
344
- }
345
- case 'OcfConvMechCustom': {
346
- if (!value.custom_conversion_description) {
347
- throw new errors_1.OcpValidationError('conversion_mechanism.custom_conversion_description', 'Required for CUSTOM_CONVERSION', { code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING });
348
- }
349
- const mech = {
350
- type: 'CUSTOM_CONVERSION',
351
- custom_conversion_description: value.custom_conversion_description,
352
- };
353
- return mech;
354
- }
355
- default:
356
- throw new errors_1.OcpParseError(`Unknown convertible conversion mechanism tag: ${String(tag)}`, {
357
- source: 'conversion_mechanism.tag',
226
+ if (s === 'OcfSimple')
227
+ return 'SIMPLE';
228
+ if (s === 'OcfCompounding')
229
+ return 'COMPOUNDING';
230
+ throw new errors_1.OcpParseError(`Unknown compounding_type: ${(0, typeConversions_1.safeString)(v)}`, {
231
+ source: 'conversion_mechanism.compounding_type',
358
232
  code: errors_1.OcpErrorCodes.UNKNOWN_ENUM_VALUE,
359
233
  });
234
+ };
235
+ const mech = {
236
+ type: 'CONVERTIBLE_NOTE_CONVERSION',
237
+ interest_rates,
238
+ ...(value.day_count_convention
239
+ ? {
240
+ day_count_convention: (0, typeConversions_1.safeString)(value.day_count_convention).endsWith('Actual365')
241
+ ? 'ACTUAL_365'
242
+ : '30_360',
243
+ }
244
+ : {}),
245
+ ...(value.interest_payout
246
+ ? {
247
+ interest_payout: (0, typeConversions_1.safeString)(value.interest_payout).endsWith('Deferred') ? 'DEFERRED' : 'CASH',
248
+ }
249
+ : {}),
250
+ ...(value.interest_accrual_period
251
+ ? { interest_accrual_period: accrualFromDaml(value.interest_accrual_period) }
252
+ : {}),
253
+ ...(value.compounding_type ? { compounding_type: compoundingFromDaml(value.compounding_type) } : {}),
254
+ ...(typeof value.conversion_discount === 'number' || typeof value.conversion_discount === 'string'
255
+ ? {
256
+ conversion_discount: (0, typeConversions_1.normalizeNumericString)(typeof value.conversion_discount === 'number'
257
+ ? value.conversion_discount.toString()
258
+ : value.conversion_discount),
259
+ }
260
+ : {}),
261
+ ...(value.conversion_valuation_cap
262
+ ? {
263
+ conversion_valuation_cap: (() => {
264
+ const monetary = (0, typeConversions_1.damlMonetaryToNativeWithValidation)(value.conversion_valuation_cap);
265
+ if (!monetary) {
266
+ throw new errors_1.OcpValidationError('convertibleIssuance.conversion_valuation_cap', 'Invalid monetary value for conversion_valuation_cap', { code: errors_1.OcpErrorCodes.INVALID_TYPE, receivedValue: value.conversion_valuation_cap });
267
+ }
268
+ return monetary;
269
+ })(),
270
+ }
271
+ : {}),
272
+ ...(value.capitalization_definition ? { capitalization_definition: value.capitalization_definition } : {}),
273
+ ...(value.capitalization_definition_rules
274
+ ? { capitalization_definition_rules: value.capitalization_definition_rules }
275
+ : {}),
276
+ ...(value.exit_multiple
277
+ ? {
278
+ exit_multiple: {
279
+ numerator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.numerator)),
280
+ denominator: (0, typeConversions_1.normalizeNumericString)(String(value.exit_multiple.denominator)),
281
+ },
282
+ }
283
+ : {}),
284
+ ...(value.conversion_mfn ? { conversion_mfn: Boolean(value.conversion_mfn) } : {}),
285
+ };
286
+ return mech;
360
287
  }
288
+ case 'OcfConvMechCustom': {
289
+ if (!value.custom_conversion_description) {
290
+ throw new errors_1.OcpValidationError('conversion_mechanism.custom_conversion_description', 'Required for CUSTOM_CONVERSION', { code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING });
291
+ }
292
+ const mech = {
293
+ type: 'CUSTOM_CONVERSION',
294
+ custom_conversion_description: value.custom_conversion_description,
295
+ };
296
+ return mech;
297
+ }
298
+ default:
299
+ throw new errors_1.OcpParseError(`Unknown convertible conversion mechanism tag: ${String(tag)}`, {
300
+ source: 'conversion_mechanism.tag',
301
+ code: errors_1.OcpErrorCodes.UNKNOWN_ENUM_VALUE,
302
+ });
361
303
  }
362
- throw new errors_1.OcpParseError('Unknown conversion_mechanism shape', {
363
- source: 'conversionRight.conversion_mechanism',
364
- code: errors_1.OcpErrorCodes.SCHEMA_MISMATCH,
304
+ }
305
+ throw new errors_1.OcpParseError('Unknown conversion_mechanism shape', {
306
+ source: 'conversionRight.conversion_mechanism',
307
+ code: errors_1.OcpErrorCodes.SCHEMA_MISMATCH,
308
+ });
309
+ };
310
+ return ts.map((raw, idx) => {
311
+ const r = (raw ?? {});
312
+ const tag = typeof r.type_ === 'string' ? r.type_ : typeof r.tag === 'string' ? r.tag : typeof raw === 'string' ? raw : '';
313
+ const type = (0, typeConversions_1.mapDamlTriggerTypeToOcf)(String(tag));
314
+ const trigger_id = typeof r.trigger_id === 'string' && r.trigger_id.length ? r.trigger_id : `${issuanceId}-trigger-${idx + 1}`;
315
+ const nickname = typeof r.nickname === 'string' && r.nickname.length ? r.nickname : undefined;
316
+ const trigger_description = typeof r.trigger_description === 'string' && r.trigger_description.length ? r.trigger_description : undefined;
317
+ const trigger_date = typeof r.trigger_date === 'string' && r.trigger_date.length ? r.trigger_date.split('T')[0] : undefined;
318
+ const trigger_condition = typeof r.trigger_condition === 'string' && r.trigger_condition.length ? r.trigger_condition : undefined;
319
+ // Parse conversion_right if present and convertible variant is used
320
+ let conversion_right;
321
+ if (r.conversion_right && typeof r.conversion_right === 'object' && 'OcfRightConvertible' in r.conversion_right) {
322
+ const right = r.conversion_right.OcfRightConvertible;
323
+ conversion_right = {
324
+ type: 'CONVERTIBLE_CONVERSION_RIGHT',
325
+ conversion_mechanism: mapMechanism(right.conversion_mechanism),
326
+ ...(typeof right.converts_to_future_round === 'boolean'
327
+ ? { converts_to_future_round: right.converts_to_future_round }
328
+ : {}),
329
+ ...(typeof right.converts_to_stock_class_id === 'string' && right.converts_to_stock_class_id.length
330
+ ? { converts_to_stock_class_id: right.converts_to_stock_class_id }
331
+ : {}),
332
+ };
333
+ }
334
+ else if (r.conversion_right &&
335
+ typeof r.conversion_right === 'object' &&
336
+ 'conversion_mechanism' in r.conversion_right) {
337
+ // Handle direct convertible right shape (no OcfRightConvertible wrapper)
338
+ const right = r.conversion_right;
339
+ conversion_right = {
340
+ type: 'CONVERTIBLE_CONVERSION_RIGHT',
341
+ conversion_mechanism: mapMechanism(right.conversion_mechanism),
342
+ ...(typeof right.converts_to_future_round === 'boolean'
343
+ ? { converts_to_future_round: right.converts_to_future_round }
344
+ : {}),
345
+ ...(typeof right.converts_to_stock_class_id === 'string' && right.converts_to_stock_class_id.length
346
+ ? { converts_to_stock_class_id: right.converts_to_stock_class_id }
347
+ : {}),
348
+ };
349
+ }
350
+ if (!conversion_right) {
351
+ throw new errors_1.OcpValidationError('conversionTrigger.conversion_right', 'Required field is missing', {
352
+ code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
365
353
  });
354
+ }
355
+ const trigger = {
356
+ type,
357
+ trigger_id,
358
+ conversion_right,
359
+ ...(nickname ? { nickname } : {}),
360
+ ...(trigger_description ? { trigger_description } : {}),
361
+ ...(trigger_date ? { trigger_date } : {}),
362
+ ...(trigger_condition ? { trigger_condition } : {}),
366
363
  };
367
- return ts.map((raw, idx) => {
368
- const r = (raw ?? {});
369
- const tag = typeof r.type_ === 'string' ? r.type_ : typeof r.tag === 'string' ? r.tag : typeof raw === 'string' ? raw : '';
370
- const type = mapTagToType(String(tag));
371
- const trigger_id = typeof r.trigger_id === 'string' && r.trigger_id.length ? r.trigger_id : `${issuanceId}-trigger-${idx + 1}`;
372
- const nickname = typeof r.nickname === 'string' && r.nickname.length ? r.nickname : undefined;
373
- const trigger_description = typeof r.trigger_description === 'string' && r.trigger_description.length ? r.trigger_description : undefined;
374
- const trigger_date = typeof r.trigger_date === 'string' && r.trigger_date.length ? r.trigger_date.split('T')[0] : undefined;
375
- const trigger_condition = typeof r.trigger_condition === 'string' && r.trigger_condition.length ? r.trigger_condition : undefined;
376
- // Parse conversion_right if present and convertible variant is used
377
- let conversion_right;
378
- if (r.conversion_right && typeof r.conversion_right === 'object' && 'OcfRightConvertible' in r.conversion_right) {
379
- const right = r.conversion_right.OcfRightConvertible;
380
- conversion_right = {
381
- type: 'CONVERTIBLE_CONVERSION_RIGHT',
382
- conversion_mechanism: mapMechanism(right.conversion_mechanism),
383
- ...(typeof right.converts_to_future_round === 'boolean'
384
- ? { converts_to_future_round: right.converts_to_future_round }
385
- : {}),
386
- ...(typeof right.converts_to_stock_class_id === 'string' && right.converts_to_stock_class_id.length
387
- ? { converts_to_stock_class_id: right.converts_to_stock_class_id }
388
- : {}),
389
- };
390
- }
391
- else if (r.conversion_right &&
392
- typeof r.conversion_right === 'object' &&
393
- 'conversion_mechanism' in r.conversion_right) {
394
- // Handle direct convertible right shape (no OcfRightConvertible wrapper)
395
- const right = r.conversion_right;
396
- conversion_right = {
397
- type: 'CONVERTIBLE_CONVERSION_RIGHT',
398
- conversion_mechanism: mapMechanism(right.conversion_mechanism),
399
- ...(typeof right.converts_to_future_round === 'boolean'
400
- ? { converts_to_future_round: right.converts_to_future_round }
401
- : {}),
402
- ...(typeof right.converts_to_stock_class_id === 'string' && right.converts_to_stock_class_id.length
403
- ? { converts_to_stock_class_id: right.converts_to_stock_class_id }
404
- : {}),
405
- };
406
- }
407
- if (!conversion_right) {
408
- throw new errors_1.OcpValidationError('conversionTrigger.conversion_right', 'Required field is missing', {
409
- code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
410
- });
411
- }
412
- const trigger = {
413
- type,
414
- trigger_id,
415
- conversion_right,
416
- ...(nickname ? { nickname } : {}),
417
- ...(trigger_description ? { trigger_description } : {}),
418
- ...(trigger_date ? { trigger_date } : {}),
419
- ...(trigger_condition ? { trigger_condition } : {}),
420
- };
421
- return trigger;
364
+ return trigger;
365
+ });
366
+ };
367
+ /** Convert DAML ConvertibleIssuance data to native OCF format */
368
+ function damlConvertibleIssuanceDataToNative(d) {
369
+ // Validate required fields
370
+ if (typeof d.id !== 'string' || !d.id) {
371
+ throw new errors_1.OcpValidationError('convertibleIssuance.id', 'Required field is missing or invalid', {
372
+ code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
373
+ receivedValue: d.id,
422
374
  });
423
- };
375
+ }
376
+ if (typeof d.date !== 'string' || !d.date) {
377
+ throw new errors_1.OcpValidationError('convertibleIssuance.date', 'Required field is missing or invalid', {
378
+ code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
379
+ receivedValue: d.date,
380
+ });
381
+ }
382
+ if (typeof d.security_id !== 'string' || !d.security_id) {
383
+ throw new errors_1.OcpValidationError('convertibleIssuance.security_id', 'Required field is missing or invalid', {
384
+ code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
385
+ receivedValue: d.security_id,
386
+ });
387
+ }
424
388
  const investmentAmount = d.investment_amount;
425
- const comments = d.comments;
426
389
  // Validate investment amount
427
390
  if (!investmentAmount ||
428
391
  (typeof investmentAmount.amount !== 'string' && typeof investmentAmount.amount !== 'number')) {
@@ -441,8 +404,10 @@ async function getConvertibleIssuanceAsOcf(client, params) {
441
404
  }
442
405
  // Convert to string after validation
443
406
  const investmentAmountStr = typeof investmentAmount.amount === 'number' ? investmentAmount.amount.toString() : investmentAmount.amount;
444
- const event = {
445
- object_type: 'TX_CONVERTIBLE_ISSUANCE',
407
+ // Build the issuance object - use type assertion because the local helper types
408
+ // (ConversionTrigger, etc.) have compatible structure but different TypeScript definitions
409
+ // than the native types (ConvertibleConversionTrigger, etc.)
410
+ const issuance = {
446
411
  id: d.id,
447
412
  date: d.date.split('T')[0],
448
413
  security_id: d.security_id,
@@ -462,7 +427,7 @@ async function getConvertibleIssuanceAsOcf(client, params) {
462
427
  ? { consideration_text: d.consideration_text }
463
428
  : {}),
464
429
  convertible_type: typeMap[d.convertible_type || 'OcfConvertibleNote'],
465
- conversion_triggers: convertTriggers(d.conversion_triggers, typeMap[d.convertible_type || 'OcfConvertibleNote'], d.id),
430
+ conversion_triggers: convertTriggers(d.conversion_triggers, d.id),
466
431
  ...(typeof d.pro_rata === 'number' || typeof d.pro_rata === 'string'
467
432
  ? {
468
433
  pro_rata: (0, typeConversions_1.normalizeNumericString)(typeof d.pro_rata === 'number' ? d.pro_rata.toString() : d.pro_rata),
@@ -470,7 +435,33 @@ async function getConvertibleIssuanceAsOcf(client, params) {
470
435
  : {}),
471
436
  seniority: typeof d.seniority === 'number' ? d.seniority : Number(d.seniority),
472
437
  security_law_exemptions: d.security_law_exemptions,
473
- ...(comments.length ? { comments } : {}),
438
+ ...(Array.isArray(d.comments) && d.comments.length > 0 ? { comments: d.comments } : {}),
439
+ };
440
+ return issuance;
441
+ }
442
+ /** Retrieve a ConvertibleIssuance contract and return it as an OCF JSON object */
443
+ async function getConvertibleIssuanceAsOcf(client, params) {
444
+ const res = await client.getEventsByContractId({ contractId: params.contractId });
445
+ const created = res.created?.createdEvent;
446
+ if (!created?.createArgument) {
447
+ throw new errors_1.OcpContractError('Missing createArgument for ConvertibleIssuance', {
448
+ contractId: params.contractId,
449
+ code: errors_1.OcpErrorCodes.RESULT_NOT_FOUND,
450
+ });
451
+ }
452
+ const arg = created.createArgument;
453
+ if (typeof arg !== 'object' || !('issuance_data' in arg)) {
454
+ throw new errors_1.OcpParseError('Unexpected createArgument for ConvertibleIssuance', {
455
+ source: 'ConvertibleIssuance.createArgument',
456
+ code: errors_1.OcpErrorCodes.SCHEMA_MISMATCH,
457
+ });
458
+ }
459
+ const d = arg.issuance_data;
460
+ const native = damlConvertibleIssuanceDataToNative(d);
461
+ // Add object_type to create the full event type
462
+ const event = {
463
+ object_type: 'TX_CONVERTIBLE_ISSUANCE',
464
+ ...native,
474
465
  };
475
466
  return { event, contractId: params.contractId };
476
467
  }