@hazbase/simplicity 0.1.1 → 0.2.0
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.
- package/README.md +139 -1534
- package/dist/cli.js +1107 -1
- package/dist/client/SimplicityClient.d.ts +30 -3
- package/dist/client/SimplicityClient.js +28 -0
- package/dist/core/lineage.d.ts +18 -0
- package/dist/core/lineage.js +30 -0
- package/dist/core/reporting.d.ts +22 -0
- package/dist/core/reporting.js +40 -0
- package/dist/core/schnorr.d.ts +3 -3
- package/dist/core/schnorr.js +19 -7
- package/dist/core/types.d.ts +251 -5
- package/dist/docs/definitions/fund-capital-call-refund-only.simf +36 -2
- package/dist/docs/definitions/receivable-definition.json +9 -0
- package/dist/docs/definitions/receivable-funding-claim.json +13 -0
- package/dist/docs/definitions/receivable-funding-claim.simf +58 -0
- package/dist/docs/definitions/receivable-repayment-claim.json +13 -0
- package/dist/docs/definitions/receivable-repayment-claim.simf +59 -0
- package/dist/docs/definitions/receivable-state-funded.json +20 -0
- package/dist/docs/definitions/receivable-state-originated.json +19 -0
- package/dist/docs/definitions/receivable-state-repaid.json +20 -0
- package/dist/domain/bond.d.ts +82 -15
- package/dist/domain/bond.js +159 -10
- package/dist/domain/bondValidation.d.ts +31 -1
- package/dist/domain/bondValidation.js +73 -9
- package/dist/domain/fund.d.ts +451 -68
- package/dist/domain/fund.js +460 -88
- package/dist/domain/fundValidation.d.ts +33 -3
- package/dist/domain/fundValidation.js +137 -5
- package/dist/domain/policies.d.ts +13 -0
- package/dist/domain/policies.js +50 -30
- package/dist/domain/receivable.d.ts +824 -0
- package/dist/domain/receivable.js +1375 -0
- package/dist/domain/receivableValidation.d.ts +147 -0
- package/dist/domain/receivableValidation.js +831 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +55 -3
- package/package.json +6 -1
|
@@ -7,8 +7,10 @@ exports.validateBondCrossChecks = validateBondCrossChecks;
|
|
|
7
7
|
exports.validateBondStateTransition = validateBondStateTransition;
|
|
8
8
|
exports.buildRedeemedBondIssuanceState = buildRedeemedBondIssuanceState;
|
|
9
9
|
exports.buildClosedBondIssuanceState = buildClosedBondIssuanceState;
|
|
10
|
-
|
|
10
|
+
exports.verifyBondIssuanceHistory = verifyBondIssuanceHistory;
|
|
11
11
|
const errors_1 = require("../core/errors");
|
|
12
|
+
const lineage_1 = require("../core/lineage");
|
|
13
|
+
const summary_1 = require("../core/summary");
|
|
12
14
|
function assertNonEmptyString(value, code, message) {
|
|
13
15
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
14
16
|
throw new errors_1.ValidationError(message, { code });
|
|
@@ -276,21 +278,29 @@ function validateBondStateTransition(previous, next) {
|
|
|
276
278
|
code: "BOND_TRANSITION_TYPE_INVALID",
|
|
277
279
|
});
|
|
278
280
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
281
|
+
if (previous.status === "REDEEMED" && next.status === "CLOSED") {
|
|
282
|
+
result.redemptionArithmeticValid =
|
|
283
|
+
next.outstandingPrincipal === previous.outstandingPrincipal &&
|
|
284
|
+
next.redeemedPrincipal === previous.redeemedPrincipal;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const expectedOutstanding = previous.outstandingPrincipal - transition.amount;
|
|
288
|
+
const expectedRedeemed = previous.redeemedPrincipal + transition.amount;
|
|
289
|
+
result.redemptionArithmeticValid =
|
|
290
|
+
expectedOutstanding >= 0 &&
|
|
291
|
+
next.outstandingPrincipal === expectedOutstanding &&
|
|
292
|
+
next.redeemedPrincipal === expectedRedeemed;
|
|
293
|
+
}
|
|
285
294
|
if (!result.redemptionArithmeticValid) {
|
|
286
295
|
throw new errors_1.ValidationError("Bond issuance redemption arithmetic is invalid", {
|
|
287
296
|
code: "BOND_REDEMPTION_ARITHMETIC_INVALID",
|
|
288
297
|
});
|
|
289
298
|
}
|
|
290
299
|
result.statusProgressionValid =
|
|
291
|
-
(previous.status === "ISSUED" || previous.status === "PARTIALLY_REDEEMED") &&
|
|
300
|
+
(((previous.status === "ISSUED" || previous.status === "PARTIALLY_REDEEMED") &&
|
|
292
301
|
((next.status === "PARTIALLY_REDEEMED" && next.outstandingPrincipal > 0) ||
|
|
293
|
-
(
|
|
302
|
+
(next.status === "REDEEMED" && next.outstandingPrincipal === 0))) ||
|
|
303
|
+
(previous.status === "REDEEMED" && next.status === "CLOSED" && next.outstandingPrincipal === 0));
|
|
294
304
|
if (!result.statusProgressionValid) {
|
|
295
305
|
throw new errors_1.ValidationError("Bond issuance status progression is invalid", {
|
|
296
306
|
code: "BOND_STATUS_TRANSITION_INVALID",
|
|
@@ -363,3 +373,57 @@ function buildClosedBondIssuanceState(input) {
|
|
|
363
373
|
finalSettlementDescriptorHash: input.finalSettlementDescriptorHash,
|
|
364
374
|
});
|
|
365
375
|
}
|
|
376
|
+
function verifyBondIssuanceHistory(input) {
|
|
377
|
+
if (input.history.length === 0) {
|
|
378
|
+
throw new errors_1.ValidationError("bond issuance history must include at least one state", {
|
|
379
|
+
code: "BOND_ISSUANCE_HISTORY_REQUIRED",
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
const history = input.history.map((state) => validateBondIssuanceState(state));
|
|
383
|
+
const lineage = (0, lineage_1.verifyHashLinkedLineage)({
|
|
384
|
+
entries: history,
|
|
385
|
+
summarize: summarizeBondIssuanceState,
|
|
386
|
+
getPreviousHash: (state) => state.previousStateHash,
|
|
387
|
+
isGenesis: (state) => state.status === "ISSUED" && !state.previousStateHash,
|
|
388
|
+
consistencyChecks: {
|
|
389
|
+
issuanceIdConsistent: (state, first) => state.issuanceId === first.issuanceId,
|
|
390
|
+
bondIdConsistent: (state, first) => state.bondId === first.bondId,
|
|
391
|
+
currencyConsistent: (state, first) => state.currencyAssetId === first.currencyAssetId,
|
|
392
|
+
controllerConsistent: (state, first) => state.controllerXonly === first.controllerXonly,
|
|
393
|
+
issuerEntityConsistent: (state, first) => state.issuerEntityId === first.issuerEntityId,
|
|
394
|
+
issuedPrincipalConsistent: (state, first) => state.issuedPrincipal === first.issuedPrincipal,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
const transitionChecks = history.slice(1).map((state, index) => validateBondStateTransition(history[index], state));
|
|
398
|
+
const allPreviousStateHashMatch = transitionChecks.every((check) => check.previousStateHashMatch);
|
|
399
|
+
const allRedemptionArithmeticValid = transitionChecks.every((check) => check.redemptionArithmeticValid);
|
|
400
|
+
const allStatusProgressionValid = transitionChecks.every((check) => check.statusProgressionValid);
|
|
401
|
+
const allTransitionIdentitiesMatch = transitionChecks.every((check) => (check.issuanceIdMatch
|
|
402
|
+
&& check.bondIdMatch
|
|
403
|
+
&& check.currencyMatch
|
|
404
|
+
&& check.controllerMatch
|
|
405
|
+
&& check.issuerEntityMatch
|
|
406
|
+
&& check.issuedPrincipalMatch));
|
|
407
|
+
return {
|
|
408
|
+
chainLength: history.length,
|
|
409
|
+
latestStatus: history.at(-1)?.status,
|
|
410
|
+
startsAtGenesis: lineage.startsAtGenesis,
|
|
411
|
+
previousStateHashLinked: lineage.previousHashLinked,
|
|
412
|
+
issuanceIdConsistent: lineage.consistency.issuanceIdConsistent,
|
|
413
|
+
bondIdConsistent: lineage.consistency.bondIdConsistent,
|
|
414
|
+
currencyConsistent: lineage.consistency.currencyConsistent,
|
|
415
|
+
controllerConsistent: lineage.consistency.controllerConsistent,
|
|
416
|
+
issuerEntityConsistent: lineage.consistency.issuerEntityConsistent,
|
|
417
|
+
issuedPrincipalConsistent: lineage.consistency.issuedPrincipalConsistent,
|
|
418
|
+
allPreviousStateHashMatch,
|
|
419
|
+
allRedemptionArithmeticValid,
|
|
420
|
+
allStatusProgressionValid,
|
|
421
|
+
allTransitionIdentitiesMatch,
|
|
422
|
+
fullHistoryVerified: lineage.fullLineageVerified
|
|
423
|
+
&& allPreviousStateHashMatch
|
|
424
|
+
&& allRedemptionArithmeticValid
|
|
425
|
+
&& allStatusProgressionValid
|
|
426
|
+
&& allTransitionIdentitiesMatch,
|
|
427
|
+
transitionChecks,
|
|
428
|
+
};
|
|
429
|
+
}
|