@hazbase/simplicity 0.0.3 → 0.0.4
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 +89 -0
- package/dist/cli.js +91 -1
- package/dist/client/ContractFactory.d.ts +2 -1
- package/dist/client/ContractFactory.js +3 -0
- package/dist/client/DeployedContract.d.ts +15 -1
- package/dist/client/DeployedContract.js +22 -0
- package/dist/client/SimplicityClient.d.ts +39 -1
- package/dist/client/SimplicityClient.js +29 -0
- package/dist/core/artifact.js +8 -0
- package/dist/core/compiler.js +60 -5
- package/dist/core/executor.js +24 -0
- package/dist/core/state.d.ts +18 -0
- package/dist/core/state.js +278 -0
- package/dist/core/types.d.ts +73 -0
- package/dist/domain/bond.d.ts +59 -0
- package/dist/domain/bond.js +128 -0
- package/dist/domain/bondValidation.d.ts +9 -0
- package/dist/domain/bondValidation.js +90 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +14 -1
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateBondDefinition = validateBondDefinition;
|
|
4
|
+
exports.validateBondIssuanceState = validateBondIssuanceState;
|
|
5
|
+
exports.validateBondCrossChecks = validateBondCrossChecks;
|
|
6
|
+
const errors_1 = require("../core/errors");
|
|
7
|
+
function assertNonEmptyString(value, code, message) {
|
|
8
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
9
|
+
throw new errors_1.ValidationError(message, { code });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function assertFiniteNumber(value, code, message) {
|
|
13
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
14
|
+
throw new errors_1.ValidationError(message, { code });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function validateBondDefinition(value) {
|
|
18
|
+
const definition = value;
|
|
19
|
+
assertNonEmptyString(definition?.bondId, "BOND_ID_INVALID", "bondId must be a non-empty string");
|
|
20
|
+
assertNonEmptyString(definition?.issuer, "BOND_ISSUER_INVALID", "issuer must be a non-empty string");
|
|
21
|
+
assertFiniteNumber(definition?.faceValue, "BOND_FACE_VALUE_INVALID", "faceValue must be a finite number");
|
|
22
|
+
assertFiniteNumber(definition?.couponBps, "BOND_COUPON_INVALID", "couponBps must be a finite number");
|
|
23
|
+
assertNonEmptyString(definition?.issueDate, "BOND_ISSUE_DATE_INVALID", "issueDate must be a non-empty string");
|
|
24
|
+
assertFiniteNumber(definition?.maturityDate, "BOND_MATURITY_DATE_INVALID", "maturityDate must be a finite number");
|
|
25
|
+
assertNonEmptyString(definition?.currencyAssetId, "BOND_CURRENCY_INVALID", "currencyAssetId must be a non-empty string");
|
|
26
|
+
assertNonEmptyString(definition?.controllerXonly, "BOND_CONTROLLER_INVALID", "controllerXonly must be a non-empty string");
|
|
27
|
+
return definition;
|
|
28
|
+
}
|
|
29
|
+
function validateBondIssuanceState(value) {
|
|
30
|
+
const issuance = value;
|
|
31
|
+
assertNonEmptyString(issuance?.issuanceId, "BOND_ISSUANCE_ID_INVALID", "issuanceId must be a non-empty string");
|
|
32
|
+
assertNonEmptyString(issuance?.bondId, "BOND_ID_INVALID", "bondId must be a non-empty string");
|
|
33
|
+
assertNonEmptyString(issuance?.issuerEntityId, "BOND_ISSUER_ENTITY_INVALID", "issuerEntityId must be a non-empty string");
|
|
34
|
+
assertFiniteNumber(issuance?.issuedPrincipal, "BOND_ISSUED_PRINCIPAL_INVALID", "issuedPrincipal must be a finite number");
|
|
35
|
+
assertFiniteNumber(issuance?.outstandingPrincipal, "BOND_OUTSTANDING_PRINCIPAL_INVALID", "outstandingPrincipal must be a finite number");
|
|
36
|
+
assertFiniteNumber(issuance?.redeemedPrincipal, "BOND_REDEEMED_PRINCIPAL_INVALID", "redeemedPrincipal must be a finite number");
|
|
37
|
+
assertNonEmptyString(issuance?.currencyAssetId, "BOND_CURRENCY_INVALID", "currencyAssetId must be a non-empty string");
|
|
38
|
+
assertNonEmptyString(issuance?.controllerXonly, "BOND_CONTROLLER_INVALID", "controllerXonly must be a non-empty string");
|
|
39
|
+
assertNonEmptyString(issuance?.issuedAt, "BOND_ISSUED_AT_INVALID", "issuedAt must be a non-empty string");
|
|
40
|
+
if (issuance.status !== "ISSUED" && issuance.status !== "REDEEMED") {
|
|
41
|
+
throw new errors_1.ValidationError("status must be ISSUED or REDEEMED", { code: "BOND_STATUS_INVALID" });
|
|
42
|
+
}
|
|
43
|
+
if (issuance.issuedPrincipal <= 0) {
|
|
44
|
+
throw new errors_1.ValidationError("issuedPrincipal must be greater than 0", { code: "BOND_PRINCIPAL_INVARIANT_INVALID" });
|
|
45
|
+
}
|
|
46
|
+
if (issuance.outstandingPrincipal < 0 || issuance.redeemedPrincipal < 0) {
|
|
47
|
+
throw new errors_1.ValidationError("principal values must not be negative", { code: "BOND_PRINCIPAL_INVARIANT_INVALID" });
|
|
48
|
+
}
|
|
49
|
+
if (issuance.issuedPrincipal !== issuance.outstandingPrincipal + issuance.redeemedPrincipal) {
|
|
50
|
+
throw new errors_1.ValidationError("issuedPrincipal must equal outstandingPrincipal + redeemedPrincipal", {
|
|
51
|
+
code: "BOND_PRINCIPAL_INVARIANT_INVALID",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (Number.isNaN(Date.parse(issuance.issuedAt))) {
|
|
55
|
+
throw new errors_1.ValidationError("issuedAt must be an ISO8601 string", { code: "BOND_ISSUED_AT_INVALID" });
|
|
56
|
+
}
|
|
57
|
+
return issuance;
|
|
58
|
+
}
|
|
59
|
+
function validateBondCrossChecks(definition, issuance) {
|
|
60
|
+
const result = {
|
|
61
|
+
bondIdMatch: definition.bondId === issuance.bondId,
|
|
62
|
+
currencyMatch: definition.currencyAssetId === issuance.currencyAssetId,
|
|
63
|
+
controllerMatch: definition.controllerXonly === issuance.controllerXonly,
|
|
64
|
+
principalInvariantValid: issuance.issuedPrincipal > 0 &&
|
|
65
|
+
issuance.outstandingPrincipal >= 0 &&
|
|
66
|
+
issuance.redeemedPrincipal >= 0 &&
|
|
67
|
+
issuance.issuedPrincipal === issuance.outstandingPrincipal + issuance.redeemedPrincipal,
|
|
68
|
+
};
|
|
69
|
+
if (!result.bondIdMatch) {
|
|
70
|
+
throw new errors_1.ValidationError("Bond definition and issuance state bondId do not match", {
|
|
71
|
+
code: "BOND_ID_MISMATCH",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (!result.currencyMatch) {
|
|
75
|
+
throw new errors_1.ValidationError("Bond definition and issuance state currencyAssetId do not match", {
|
|
76
|
+
code: "BOND_CURRENCY_MISMATCH",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (!result.controllerMatch) {
|
|
80
|
+
throw new errors_1.ValidationError("Bond definition and issuance state controllerXonly do not match", {
|
|
81
|
+
code: "BOND_CONTROLLER_MISMATCH",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (!result.principalInvariantValid) {
|
|
85
|
+
throw new errors_1.ValidationError("Bond issuance principal invariants are invalid", {
|
|
86
|
+
code: "BOND_PRINCIPAL_INVARIANT_INVALID",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,3 +7,6 @@ export * from "./core/errors";
|
|
|
7
7
|
export { listPresets, getPresetOrThrow } from "./core/presets";
|
|
8
8
|
export { loadArtifact, saveArtifact, normalizeArtifact } from "./core/artifact";
|
|
9
9
|
export { loadDefinitionInput, buildArtifactDefinitionMetadata, verifyDefinitionAgainstArtifact, verifyDefinitionDescriptorAgainstArtifact, } from "./core/definition";
|
|
10
|
+
export { loadStateInput, buildArtifactStateMetadata, verifyStateAgainstArtifact, verifyStateDescriptorAgainstArtifact, } from "./core/state";
|
|
11
|
+
export { defineBond, verifyBond, loadBond } from "./domain/bond";
|
|
12
|
+
export { validateBondDefinition, validateBondIssuanceState, validateBondCrossChecks, } from "./domain/bondValidation";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.verifyDefinitionDescriptorAgainstArtifact = exports.verifyDefinitionAgainstArtifact = exports.buildArtifactDefinitionMetadata = exports.loadDefinitionInput = exports.normalizeArtifact = exports.saveArtifact = exports.loadArtifact = exports.getPresetOrThrow = exports.listPresets = exports.RelayerClient = exports.DeployedContract = exports.CompiledContract = exports.SimplicityClient = exports.createSimplicityClient = void 0;
|
|
17
|
+
exports.validateBondCrossChecks = exports.validateBondIssuanceState = exports.validateBondDefinition = exports.loadBond = exports.verifyBond = exports.defineBond = exports.verifyStateDescriptorAgainstArtifact = exports.verifyStateAgainstArtifact = exports.buildArtifactStateMetadata = exports.loadStateInput = exports.verifyDefinitionDescriptorAgainstArtifact = exports.verifyDefinitionAgainstArtifact = exports.buildArtifactDefinitionMetadata = exports.loadDefinitionInput = exports.normalizeArtifact = exports.saveArtifact = exports.loadArtifact = exports.getPresetOrThrow = exports.listPresets = exports.RelayerClient = exports.DeployedContract = exports.CompiledContract = exports.SimplicityClient = exports.createSimplicityClient = void 0;
|
|
18
18
|
var SimplicityClient_1 = require("./client/SimplicityClient");
|
|
19
19
|
Object.defineProperty(exports, "createSimplicityClient", { enumerable: true, get: function () { return SimplicityClient_1.createSimplicityClient; } });
|
|
20
20
|
Object.defineProperty(exports, "SimplicityClient", { enumerable: true, get: function () { return SimplicityClient_1.SimplicityClient; } });
|
|
@@ -38,3 +38,16 @@ Object.defineProperty(exports, "loadDefinitionInput", { enumerable: true, get: f
|
|
|
38
38
|
Object.defineProperty(exports, "buildArtifactDefinitionMetadata", { enumerable: true, get: function () { return definition_1.buildArtifactDefinitionMetadata; } });
|
|
39
39
|
Object.defineProperty(exports, "verifyDefinitionAgainstArtifact", { enumerable: true, get: function () { return definition_1.verifyDefinitionAgainstArtifact; } });
|
|
40
40
|
Object.defineProperty(exports, "verifyDefinitionDescriptorAgainstArtifact", { enumerable: true, get: function () { return definition_1.verifyDefinitionDescriptorAgainstArtifact; } });
|
|
41
|
+
var state_1 = require("./core/state");
|
|
42
|
+
Object.defineProperty(exports, "loadStateInput", { enumerable: true, get: function () { return state_1.loadStateInput; } });
|
|
43
|
+
Object.defineProperty(exports, "buildArtifactStateMetadata", { enumerable: true, get: function () { return state_1.buildArtifactStateMetadata; } });
|
|
44
|
+
Object.defineProperty(exports, "verifyStateAgainstArtifact", { enumerable: true, get: function () { return state_1.verifyStateAgainstArtifact; } });
|
|
45
|
+
Object.defineProperty(exports, "verifyStateDescriptorAgainstArtifact", { enumerable: true, get: function () { return state_1.verifyStateDescriptorAgainstArtifact; } });
|
|
46
|
+
var bond_1 = require("./domain/bond");
|
|
47
|
+
Object.defineProperty(exports, "defineBond", { enumerable: true, get: function () { return bond_1.defineBond; } });
|
|
48
|
+
Object.defineProperty(exports, "verifyBond", { enumerable: true, get: function () { return bond_1.verifyBond; } });
|
|
49
|
+
Object.defineProperty(exports, "loadBond", { enumerable: true, get: function () { return bond_1.loadBond; } });
|
|
50
|
+
var bondValidation_1 = require("./domain/bondValidation");
|
|
51
|
+
Object.defineProperty(exports, "validateBondDefinition", { enumerable: true, get: function () { return bondValidation_1.validateBondDefinition; } });
|
|
52
|
+
Object.defineProperty(exports, "validateBondIssuanceState", { enumerable: true, get: function () { return bondValidation_1.validateBondIssuanceState; } });
|
|
53
|
+
Object.defineProperty(exports, "validateBondCrossChecks", { enumerable: true, get: function () { return bondValidation_1.validateBondCrossChecks; } });
|