@helios-lang/contract-utils 0.3.11 → 0.3.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helios-lang/contract-utils",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "Convenience and type-safety utilities for using Helios validators from within Typescript",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -1,8 +1,10 @@
1
1
  import { makeStringWriter } from "@helios-lang/codec-utils"
2
2
  import { expectDefined } from "@helios-lang/type-utils"
3
+ import { collectBuiltinTypes } from "../codegen/TypeSchema.js"
3
4
 
4
5
  /**
5
6
  * @import { StringWriter } from "@helios-lang/codec-utils"
7
+ * @import { TypeSchema } from "@helios-lang/type-utils"
6
8
  * @import { FileSystem } from "../index.js"
7
9
  */
8
10
 
@@ -53,14 +55,25 @@ export class ArtifactWriter {
53
55
  /**
54
56
  * @param {string} name
55
57
  * @param {string} from
56
- * @param {boolean} [isType]
58
+ * @param {boolean} isType
57
59
  * @returns {ArtifactWriter}
58
60
  */
59
- addImport(name, from, isType = false) {
61
+ addImport(name, from, isType) {
60
62
  this.imports.push([name, from, isType])
61
63
  return this
62
64
  }
63
65
 
66
+ /**
67
+ * @param {TypeSchema} schema
68
+ */
69
+ collectAndImportTypes(schema) {
70
+ const internalTypes = collectBuiltinTypes(schema)
71
+
72
+ Array.from(internalTypes.entries()).forEach(([name, from]) => {
73
+ this.addImport(name, from, true)
74
+ })
75
+ }
76
+
64
77
  /**
65
78
  * @param {string} line
66
79
  * @returns {ArtifactWriter}
@@ -45,6 +45,14 @@ export class ChildArtifactWriter extends ArtifactWriter {
45
45
  * @returns {ChildArtifactWriter}
46
46
  */
47
47
  writeProgram(name, program, includeDef) {
48
+ this.writeDeclLine(`export const $programCborHex: string`)
49
+
50
+ if (includeDef) {
51
+ this.writeDefLine(
52
+ `export const $programCborHex = "${bytesToHex(program.toCbor())}"`
53
+ )
54
+ }
55
+
48
56
  if (program.plutusVersion == "PlutusScriptV1") {
49
57
  this.addImport("UplcProgramV1", "@helios-lang/uplc", true)
50
58
  this.writeDeclLine(`export const ${name}: UplcProgramV1`)
@@ -52,7 +60,8 @@ export class ChildArtifactWriter extends ArtifactWriter {
52
60
  if (includeDef) {
53
61
  this.addImport(
54
62
  "decodeUplcProgramV1FromCbor",
55
- "@helios-lang/uplc"
63
+ "@helios-lang/uplc",
64
+ false
56
65
  )
57
66
  this.writeDefLine(
58
67
  `export const ${name} = ${stringifyProgram("decodeUplcProgramV1FromCbor", program)}`
@@ -65,7 +74,8 @@ export class ChildArtifactWriter extends ArtifactWriter {
65
74
  if (includeDef) {
66
75
  this.addImport(
67
76
  "decodeUplcProgramV2FromCbor",
68
- "@helios-lang/uplc"
77
+ "@helios-lang/uplc",
78
+ false
69
79
  )
70
80
  this.writeDefLine(
71
81
  `export const ${name} = ${stringifyProgram("decodeUplcProgramV2FromCbor", program)}`
@@ -78,7 +88,8 @@ export class ChildArtifactWriter extends ArtifactWriter {
78
88
  if (includeDef) {
79
89
  this.addImport(
80
90
  "decodeUplcProgramV3FromCbor",
81
- "@helios-lang/uplc"
91
+ "@helios-lang/uplc",
92
+ false
82
93
  )
83
94
  this.writeDefLine(
84
95
  `export const ${name} = ${stringifyProgram("decodeUplcProgramV3FromCbor", program)}`
@@ -102,7 +113,7 @@ function stringifyProgram(decoderName, program) {
102
113
  const sourceMap = makeUplcSourceMap({ term: program.root })
103
114
 
104
115
  return `/* @__PURE__ */ ${decoderName}(
105
- "${bytesToHex(program.toCbor())}",
116
+ $programCborHex,
106
117
  {${stringifyAlt("decodeUplcProgramV2FromCbor", program.alt)}
107
118
  sourceMap: ${JSON.stringify(sourceMap.toJsonSafe(), undefined, 4).split("\n").join("\n ")}
108
119
  }
@@ -1,13 +1,17 @@
1
1
  import { bytesToHex } from "@helios-lang/codec-utils"
2
2
  import { expectDefined, isRight } from "@helios-lang/type-utils"
3
+ import { convertFromUplcData } from "../cast/index.js"
3
4
  import {
4
5
  genUserFuncArgsType,
5
6
  genUserFuncRetType
6
7
  } from "../codegen/LoadedScriptsWriter.js"
8
+ import { genTypes } from "../codegen/TypeSchema.js"
7
9
  import { ChildArtifactWriter } from "./ChildArtifactWriter.js"
8
10
 
9
11
  /**
10
- * @import { UplcProgram } from "@helios-lang/uplc"
12
+ * @import { Address, AssetClass } from "@helios-lang/ledger"
13
+ * @import { TypeSchema } from "@helios-lang/type-utils"
14
+ * @import { UplcData, UplcProgram } from "@helios-lang/uplc"
11
15
  * @import { UserFuncProps } from "../index.js"
12
16
  * @import { Artifact } from "./Artifact.js"
13
17
  * @import { FunctionDetails } from "./symbols.js"
@@ -65,7 +69,7 @@ export const $props = ${JSON.stringify(props, undefined, 4)}`)
65
69
  this.addImport("UplcData", "@helios-lang/uplc", true)
66
70
  this.addImport("CekResult", "@helios-lang/uplc", true)
67
71
 
68
- this.addImport("evalUserFunc", "@helios-lang/contract-utils")
72
+ this.addImport("evalUserFunc", "@helios-lang/contract-utils", false)
69
73
  .writeDeclLine(
70
74
  `export function $eval(args${isConst ? "?" : ""}: ${safeArgsType}, logOptions?: UplcLogger | undefined): ${retType}`
71
75
  )
@@ -74,7 +78,11 @@ export const $props = ${JSON.stringify(props, undefined, 4)}`)
74
78
  return evalUserFunc($program, $props, args, logOptions)
75
79
  }`
76
80
  )
77
- .addImport("evalUserFuncUnsafe", "@helios-lang/contract-utils")
81
+ .addImport(
82
+ "evalUserFuncUnsafe",
83
+ "@helios-lang/contract-utils",
84
+ false
85
+ )
78
86
  .writeDeclLine(
79
87
  `export function $evalUnsafe(args${isConst ? "?" : ""}: ${unsafeArgsType}, logOptions?: UplcLogger | undefined): ${unsafeRetType}`
80
88
  )
@@ -83,7 +91,7 @@ export const $props = ${JSON.stringify(props, undefined, 4)}`)
83
91
  return evalUserFuncUnsafe($program, $props, args, logOptions)
84
92
  }`
85
93
  )
86
- .addImport("profileUserFunc", "@helios-lang/contract-utils")
94
+ .addImport("profileUserFunc", "@helios-lang/contract-utils", false)
87
95
  .writeDeclLine(
88
96
  `export function $profile(args${isConst ? "?" : ""}: ${unsafeArgsType}, logOptions?: UplcLogger | undefined): CekResult`
89
97
  )
@@ -91,8 +99,8 @@ export const $props = ${JSON.stringify(props, undefined, 4)}`)
91
99
  return profileUserFunc($program, $props, args, logOptions)
92
100
  }`)
93
101
 
94
- if (isConst) {
95
- // attempt to evaluate, and add $data
102
+ if (isConst && props.returns) {
103
+ // attempt to evaluate, and add $constData and $constValue
96
104
  try {
97
105
  const result = program.eval([])
98
106
 
@@ -114,19 +122,144 @@ export const $props = ${JSON.stringify(props, undefined, 4)}`)
114
122
  )
115
123
 
116
124
  this.addImport(uplcDataType, "@helios-lang/uplc", true)
125
+ .writeDeclLine(`export const $constCborHex: string`)
126
+ .writeDefLine(
127
+ `export const $constCborHex = "${bytesToHex(data.toCbor())}"`
128
+ )
117
129
  .writeDeclLine(
118
130
  `export const $constData: ${uplcDataType}`
119
131
  )
120
132
  .addImport("decodeUplcData", "@helios-lang/uplc", false)
121
133
  .writeDefLine(
122
- `export const $constData = /* @__PURE__ */ decodeUplcData("${bytesToHex(data.toCbor())}")`
134
+ `export const $constData = /* @__PURE__ */ decodeUplcData($constCborHex)`
123
135
  )
124
136
 
125
- // TODO: $constValue
137
+ const valueTypeSchema = props.returns
138
+ const valueTypes = genTypes(valueTypeSchema)
139
+ this.collectAndImportTypes(valueTypeSchema)
140
+ this.writeDeclLine(
141
+ `export const $constValue: ${valueTypes[0]}`
142
+ )
143
+
144
+ const value = convertFromUplcData(valueTypeSchema, data, {
145
+ isMainnet: this.isMainnet
146
+ })
147
+ const constValueStr = this.stringifyConstValue(
148
+ valueTypeSchema,
149
+ data,
150
+ value
151
+ )
152
+
153
+ if (constValueStr !== undefined) {
154
+ this.writeDefLine(
155
+ `export const $constValue = ${constValueStr}`
156
+ )
157
+ } else {
158
+ // fallback
159
+ this.addImport(
160
+ "convertFromUplcData",
161
+ "@helios-lang/contract-utils",
162
+ false
163
+ )
164
+ .writeDefLine(`export const $constValue = /* @__PURE__ */ convertFromUplcData(${JSON.stringify(valueTypeSchema)}, $constData, {
165
+ isMainnet: ${this.isMainnet}
166
+ })`)
167
+ }
126
168
  }
127
169
  } catch (_e) {
128
170
  // don't do anything, simply ignore
129
171
  }
130
172
  }
131
173
  }
174
+
175
+ /**
176
+ * @param {TypeSchema} schema
177
+ * @param {UplcData} data
178
+ * @param {any} value
179
+ * @returns {string | undefined}
180
+ */
181
+ stringifyConstValue(schema, data, value) {
182
+ // TODO: it might be more efficient to represent the following directly as a primitive value
183
+ if (schema.kind == "internal" && schema.name == "Address") {
184
+ /**
185
+ * @type {Address}
186
+ */
187
+ const v = value
188
+ if (v.era == "Shelley") {
189
+ this.addImport(
190
+ "makeShelleyAddress",
191
+ "@helios-lang/ledger",
192
+ false
193
+ )
194
+ return `/* @__PURE__ */ makeShelleyAddress("${v.toBech32()}")`
195
+ }
196
+ } else if (schema.kind == "internal" && schema.name == "AssetClass") {
197
+ /**
198
+ * @type {AssetClass}
199
+ */
200
+ const v = value
201
+ this.addImport("parseAssetClass", "@helios-lang/ledger", false)
202
+ return `/* @__PURE__ */ parseAssetClass("${v.toString()}")`
203
+ } else if (schema.kind == "internal" && schema.name == "Bool") {
204
+ /**
205
+ * @type {boolean}
206
+ */
207
+ const v = value
208
+ return v.toString()
209
+ } else if (schema.kind == "internal" && schema.name == "ByteArray") {
210
+ /**
211
+ * @type {number[]}
212
+ */
213
+ const v = value
214
+ return `[${v.map((b) => b.toString()).join(", ")}]`
215
+ } else if (
216
+ schema.kind == "internal" &&
217
+ ["Any", "Data"].includes(schema.name)
218
+ ) {
219
+ return "$constData"
220
+ } else if (
221
+ schema.kind == "internal" &&
222
+ ["Duration", "Int"].includes(schema.name)
223
+ ) {
224
+ /**
225
+ * @type {bigint}
226
+ */
227
+ const v = value
228
+ return `${v.toString()}n`
229
+ } else if (
230
+ schema.kind == "internal" &&
231
+ [
232
+ "MintingPolicyHash",
233
+ "PubKeyHash",
234
+ "StakingValidatorHash",
235
+ "TxId",
236
+ "ValidatorHash"
237
+ ].includes(schema.name)
238
+ ) {
239
+ /**
240
+ * @type {{bytes: number[]}}
241
+ */
242
+ const v = value
243
+ const makerFunc = `make${schema.name}`
244
+ this.addImport(makerFunc, "@helios-lang/ledger", false)
245
+ return `/* @__PURE__ */ ${makerFunc}("${bytesToHex(v.bytes)}")`
246
+ } else if (
247
+ schema.kind == "internal" &&
248
+ ["Real", "Time"].includes(schema.name)
249
+ ) {
250
+ /**
251
+ * @type {number}
252
+ */
253
+ const v = value
254
+ return v.toString()
255
+ } else if (schema.kind == "internal" && schema.name == "String") {
256
+ /**
257
+ * @type {string}
258
+ */
259
+ const v = value
260
+ return `"${v.toString()}"`
261
+ }
262
+
263
+ return undefined
264
+ }
132
265
  }
@@ -33,6 +33,7 @@ export function writeContractContextArtifacts(context, options) {
33
33
  root,
34
34
  moduleName,
35
35
  moduleDetails.$hash,
36
+ moduleDetails.$purpose,
36
37
  moduleDetails
37
38
  )
38
39
 
@@ -1,4 +1,4 @@
1
- import { collectBuiltinTypes, genTypes } from "../codegen/TypeSchema.js"
1
+ import { genTypes } from "../codegen/TypeSchema.js"
2
2
  import { ChildArtifactWriter } from "./ChildArtifactWriter.js"
3
3
  import { writeFunctionArtifact } from "./FunctionArtifact.js"
4
4
 
@@ -73,16 +73,20 @@ export const $schema = ${JSON.stringify(schema, undefined, 4)}`
73
73
  this.writeDeclLine(`export type $StrictType = ${types[0]}`)
74
74
  this.writeDeclLine(`export type $PermissiveType = ${types[1]}`)
75
75
 
76
- const internalTypes = collectBuiltinTypes(schema)
77
-
78
- Array.from(internalTypes.entries()).forEach(([name, from]) => {
79
- this.addImport(name, from, true)
80
- })
76
+ this.collectAndImportTypes(schema)
81
77
  }
82
78
 
83
79
  writeConverters() {
84
- this.addImport("convertToUplcData", "@helios-lang/contract-utils")
85
- this.addImport("convertFromUplcData", "@helios-lang/contract-utils")
80
+ this.addImport(
81
+ "convertToUplcData",
82
+ "@helios-lang/contract-utils",
83
+ false
84
+ )
85
+ this.addImport(
86
+ "convertFromUplcData",
87
+ "@helios-lang/contract-utils",
88
+ false
89
+ )
86
90
  this.addImport("UplcData", "@helios-lang/uplc", true)
87
91
 
88
92
  this.writeDeclLine(
@@ -12,14 +12,15 @@ import { ModuleArtifact } from "./ModuleArtifact.js"
12
12
  * @param {Artifact} parent
13
13
  * @param {string} name
14
14
  * @param {ScriptHash} hash
15
+ * @param {string} purpose
15
16
  * @param {ModuleSymbols} symbols
16
17
  */
17
- export function writeValidatorArtifact(parent, name, hash, symbols) {
18
+ export function writeValidatorArtifact(parent, name, hash, purpose, symbols) {
18
19
  const artifact = new ValdiatorArtifact(parent, name)
19
20
 
20
21
  artifact.writeSymbols(symbols)
21
22
 
22
- artifact.writeHash(hash)
23
+ artifact.writeHash(hash, purpose)
23
24
 
24
25
  artifact.save()
25
26
 
@@ -47,17 +48,149 @@ class ValdiatorArtifact extends ModuleArtifact {
47
48
 
48
49
  /**
49
50
  * @param {ScriptHash} hash
51
+ * @param {string} purpose
50
52
  */
51
- writeHash(hash) {
53
+ writeHash(hash, purpose) {
52
54
  this.writeDeclLine(`export const $hashHex: string`)
53
55
  this.writeDefLine(`export const $hashHex = "${hash.toHex()}"`)
54
56
 
55
- if (hash.kind == "MintingPolicyHash") {
57
+ if (purpose == "mixed") {
58
+ this.addImport("ValidatorHash", "@helios-lang/ledger", true)
59
+ .addImport("makeValidatorHash", "@helios-lang/ledger", false)
60
+ .addImport("MintingPolicyHash", "@helios-lang/ledger", true)
61
+ .addImport(
62
+ "makeMintingPolicyHash",
63
+ "@helios-lang/ledger",
64
+ false
65
+ )
66
+ .addImport("StakingValidatorHash", "@helios-lang/ledger", true)
67
+ .addImport(
68
+ "makeStakingValidatorHash",
69
+ "@helios-lang/ledger",
70
+ false
71
+ )
72
+
73
+ if (!hash.context) {
74
+ this.writeDeclLine(`export const $validatorHash: ValidatorHash`)
75
+ .writeDefLine(
76
+ `export const $validatorHash = /* @__PURE__ */ makeValidatorHash($hashHex)`
77
+ )
78
+ .writeDeclLine(
79
+ `export const $mintingPolicyHash: MintingPolicyHash`
80
+ )
81
+ .writeDefLine(
82
+ `export const $mintingPolicyHash = /* @__PURE__ */ makeMintingPolicyHash($hashHex)`
83
+ )
84
+ .writeDeclLine(
85
+ `export const $stakingValidatorHash: StakingValidatorHash`
86
+ )
87
+ .writeDefLine(
88
+ `export const $stakingValidatorHash = /* @__PURE__ */ makeStakingValidatorHash($hashHex)`
89
+ )
90
+ .addImport("ShelleyAddress", "@helios-lang/ledger", true)
91
+ .writeDeclLine(
92
+ `export const $validatorAddress: ShelleyAddress`
93
+ )
94
+ .addImport(
95
+ "makeShelleyAddress",
96
+ "@helios-lang/ledger",
97
+ false
98
+ )
99
+ .writeDefLine(
100
+ `export const $validatorAddress = /* @__PURE__ */ makeShelleyAddress(${this.isMainnet}, $validatorHash)`
101
+ )
102
+ } else {
103
+ this.writeDeclLine(
104
+ `export const $validatorHashWithoutContext: ValidatorHash`
105
+ )
106
+ .writeDefLine(
107
+ `export const $validatorHashWithoutContext = /* @__PURE__ */ makeValidatorHash($hashHex)`
108
+ )
109
+ .writeDeclLine(
110
+ `export const $mintingPolicyHashWithoutContext: MintingPolicyHash`
111
+ )
112
+ .writeDefLine(
113
+ `export const $mintingPolicyHashWithoutContext = /* @__PURE__ */ makeMintingPolicyHash($hashHex)`
114
+ )
115
+ .writeDeclLine(
116
+ `export const $stakingValidatorHashWithoutContext: StakingValidatorHash`
117
+ )
118
+ .writeDefLine(
119
+ `export const $stakingValidatorHashWithoutContext = /* @__PURE__ */ makeStakingValidatorHash($hashHex)`
120
+ )
121
+ .addImport("ShelleyAddress", "@helios-lang/ledger", true)
122
+ .writeDeclLine(
123
+ `export const $addressWithoutContext: ShelleyAddress`
124
+ )
125
+ .addImport(
126
+ "makeShelleyAddress",
127
+ "@helios-lang/ledger",
128
+ false
129
+ )
130
+ .writeDefLine(
131
+ `export const $addressWithoutContext = /* @__PURE__ */ makeShelleyAddress(${this.isMainnet}, $validatorHashWithoutContext)`
132
+ )
133
+
134
+ this.addImport("makeCast", "@helios-lang/contract-utils", false)
135
+ this.addImport("SpendingContext", "@helios-lang/ledger", true)
136
+
137
+ const context =
138
+ /** @type {SpendingContext<unknown, unknown, unknown, unknown>} */ (
139
+ hash.context
140
+ )
141
+ const program = context.program
142
+ const datum = /** @type {Cast<unknown, unknown>} */ (
143
+ context.datum
144
+ )
145
+ const redeemer = /** @type {Cast<unknown, unknown>} */ (
146
+ context.redeemer
147
+ )
148
+ const dTypes = genTypes(datum.schema)
149
+ const rTypes = genTypes(redeemer.schema)
150
+
151
+ this.writeProgram("$program", program, !this.hasMainFunction)
152
+
153
+ this.writeDeclLine(
154
+ `export type $ContextType = SpendingContext<${dTypes[0]}, ${dTypes[1]}, ${rTypes[0]}, ${rTypes[1]}>`
155
+ )
156
+ .writeDeclLine(
157
+ `export const $validatorHash: ValidatorHash<$ContextType>`
158
+ )
159
+ .writeDefLine(
160
+ `const $context = {
161
+ program: $program,
162
+ datum: /* @__PURE__ */ makeCast(${JSON.stringify(datum.schema, undefined, 4).split("\n").join("\n ")}, {isMainnet: ${this.isMainnet}}),
163
+ redeemer: /* @__PURE__ */ makeCast(${JSON.stringify(redeemer.schema, undefined, 4).split("\n").join("\n ")}, {isMainnet: ${this.isMainnet}})
164
+ })`
165
+ )
166
+ .writeDefLine(
167
+ `export const $validatorHash = /* @__PURE__ */ makeValidatorHash($hashHex, $context)`
168
+ )
169
+ .writeDeclLine(
170
+ `export const $mintingPolicyHash: MintingPolicyHash<$ContextType>`
171
+ )
172
+ .writeDefLine(
173
+ `export const $mintingPolicyHash = /* @__PURE__ */ makeMintingPolicyHash($hashHex, $context)`
174
+ )
175
+ .writeDeclLine(
176
+ `export const $stakingValidatorHash: StakingValidatorHash<$ContextType>`
177
+ )
178
+ .writeDefLine(
179
+ `export const $stakingValidatorHash = /* @__PURE__ */ makeStakingValidatorHash($hashHex, $context)`
180
+ )
181
+ .writeDeclLine(
182
+ `export const $address: ShelleyAddress<ValidatorHash<$ContextType>>`
183
+ )
184
+ .writeDefLine(
185
+ `export const $address = /* @__PURE__ */ makeShelleyAddress(${this.isMainnet}, $validatorHash)`
186
+ )
187
+ }
188
+ } else if (hash.kind == "MintingPolicyHash") {
56
189
  this.addImport(
57
190
  "MintingPolicyHash",
58
191
  "@helios-lang/ledger",
59
192
  true
60
- ).addImport("makeMintingPolicyHash", "@helios-lang/ledger")
193
+ ).addImport("makeMintingPolicyHash", "@helios-lang/ledger", false)
61
194
 
62
195
  if (!hash.context) {
63
196
  this.writeDeclLine(
@@ -72,7 +205,7 @@ class ValdiatorArtifact extends ModuleArtifact {
72
205
  `export const $hashWithoutContext = /* @__PURE__ */ makeMintingPolicyHash($hashHex)`
73
206
  )
74
207
 
75
- this.addImport("makeCast", "@helios-lang/contract-utils")
208
+ this.addImport("makeCast", "@helios-lang/contract-utils", false)
76
209
  this.addImport("MintingContext", "@helios-lang/ledger", true)
77
210
 
78
211
  const context =
@@ -102,7 +235,11 @@ class ValdiatorArtifact extends ModuleArtifact {
102
235
  "StakingValidatorHash",
103
236
  "@helios-lang/ledger",
104
237
  true
105
- ).addImport("makeStakingValidatorHash", "@helios-lang/ledger")
238
+ ).addImport(
239
+ "makeStakingValidatorHash",
240
+ "@helios-lang/ledger",
241
+ false
242
+ )
106
243
 
107
244
  if (!hash.context) {
108
245
  this.writeDeclLine(
@@ -117,7 +254,7 @@ class ValdiatorArtifact extends ModuleArtifact {
117
254
  `export const $hashWithoutContext = /* @__PURE__*/ makeStakingValidatorHash($hashHex)`
118
255
  )
119
256
 
120
- this.addImport("makeCast", "@helios-lang/contract-utils")
257
+ this.addImport("makeCast", "@helios-lang/contract-utils", false)
121
258
  this.addImport("StakingContext", "@helios-lang/ledger", true)
122
259
 
123
260
  const context =
@@ -147,22 +284,44 @@ class ValdiatorArtifact extends ModuleArtifact {
147
284
  "ValidatorHash",
148
285
  "@helios-lang/ledger",
149
286
  true
150
- ).addImport("makeValidatorHash", "@helios-lang/ledger")
287
+ ).addImport("makeValidatorHash", "@helios-lang/ledger", false)
151
288
 
152
289
  if (!hash.context) {
153
- this.writeDeclLine(
154
- `export const $hash: ValidatorHash`
155
- ).writeDefLine(
156
- `export const $hash = /* @__PURE__ */ makeValidatorHash($hashHex)`
157
- )
290
+ this.writeDeclLine(`export const $hash: ValidatorHash`)
291
+ .writeDefLine(
292
+ `export const $hash = /* @__PURE__ */ makeValidatorHash($hashHex)`
293
+ )
294
+ .addImport("ShelleyAddress", "@helios-lang/ledger", true)
295
+ .writeDeclLine(`export const $address: ShelleyAddress`)
296
+ .addImport(
297
+ "makeShelleyAddress",
298
+ "@helios-lang/ledger",
299
+ false
300
+ )
301
+ .writeDefLine(
302
+ `export const $address = /* @__PURE__ */ makeShelleyAddress(${this.isMainnet}, $hash)`
303
+ )
158
304
  } else {
159
305
  this.writeDeclLine(
160
306
  `export const $hashWithoutContext: ValidatorHash`
161
- ).writeDefLine(
162
- `export const $hashWithoutContext = /* @__PURE__ */ makeValidatorHash($hashHex)`
163
307
  )
308
+ .writeDefLine(
309
+ `export const $hashWithoutContext = /* @__PURE__ */ makeValidatorHash($hashHex)`
310
+ )
311
+ .addImport("ShelleyAddress", "@helios-lang/ledger", true)
312
+ .writeDeclLine(
313
+ `export const $addressWithoutContext: ShelleyAddress`
314
+ )
315
+ .addImport(
316
+ "makeShelleyAddress",
317
+ "@helios-lang/ledger",
318
+ false
319
+ )
320
+ .writeDefLine(
321
+ `export const $addressWithoutContext = /* @__PURE__ */ makeShelleyAddress(${this.isMainnet}, $hashWithoutContext)`
322
+ )
164
323
 
165
- this.addImport("makeCast", "@helios-lang/contract-utils")
324
+ this.addImport("makeCast", "@helios-lang/contract-utils", false)
166
325
  this.addImport("SpendingContext", "@helios-lang/ledger", true)
167
326
 
168
327
  const context =
@@ -188,11 +347,20 @@ class ValdiatorArtifact extends ModuleArtifact {
188
347
  `export const $hash: ValidatorHash<$ContextType>`
189
348
  )
190
349
  .writeDefLine(
191
- `export const $hash = /* @__PURE__ */ makeValidatorHash($hashHex, {
350
+ `const $context = {
192
351
  program: $program,
193
352
  datum: /* @__PURE__ */ makeCast(${JSON.stringify(datum.schema, undefined, 4).split("\n").join("\n ")}, {isMainnet: ${this.isMainnet}}),
194
353
  redeemer: /* @__PURE__ */ makeCast(${JSON.stringify(redeemer.schema, undefined, 4).split("\n").join("\n ")}, {isMainnet: ${this.isMainnet}})
195
- })`
354
+ }`
355
+ )
356
+ .writeDefLine(
357
+ `export const $hash = /* @__PURE__ */ makeValidatorHash($hashHex, $context)`
358
+ )
359
+ .writeDeclLine(
360
+ `export const $address: ShelleyAddress<ValidatorHash<$ContextType>>`
361
+ )
362
+ .writeDefLine(
363
+ `export const $address = /* @__PURE__ */ makeShelleyAddress(${this.isMainnet}, $hash)`
196
364
  )
197
365
  }
198
366
  }
@@ -206,9 +374,11 @@ class ValdiatorArtifact extends ModuleArtifact {
206
374
  super.writeAggregateExport(name)
207
375
 
208
376
  if (name == "main") {
209
- this.writeDefLine(
210
- `import { $program } from "./${name}/index.js"`
211
- ).writeDefLine(`export { $program }`)
377
+ this.writeDefLine(`import { $program } from "./${name}/index.js"`)
378
+ .writeDefLine(`export { $program }`)
379
+ .writeDefLine(
380
+ `export { $programCborHex } from "./${name}/index.js"`
381
+ )
212
382
  this.hasMainFunction = true
213
383
  }
214
384
 
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * @import { StringWriter } from "@helios-lang/codec-utils"
3
+ * @import { TypeSchema } from "@helios-lang/type-utils"
3
4
  * @import { FileSystem } from "../index.js"
4
5
  */
5
6
  export class ArtifactWriter {
@@ -36,10 +37,14 @@ export class ArtifactWriter {
36
37
  /**
37
38
  * @param {string} name
38
39
  * @param {string} from
39
- * @param {boolean} [isType]
40
+ * @param {boolean} isType
40
41
  * @returns {ArtifactWriter}
41
42
  */
42
- addImport(name: string, from: string, isType?: boolean): ArtifactWriter;
43
+ addImport(name: string, from: string, isType: boolean): ArtifactWriter;
44
+ /**
45
+ * @param {TypeSchema} schema
46
+ */
47
+ collectAndImportTypes(schema: TypeSchema): void;
43
48
  /**
44
49
  * @param {string} line
45
50
  * @returns {ArtifactWriter}
@@ -61,4 +66,5 @@ export class ArtifactWriter {
61
66
  save(): void;
62
67
  }
63
68
  import type { FileSystem } from "../index.js";
69
+ import type { TypeSchema } from "@helios-lang/type-utils";
64
70
  //# sourceMappingURL=ArtifactWriter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ArtifactWriter.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;IA+BI;;;OAGG;IACH,gBAHW,UAAU,OACV,MAAM,EAShB;IAzCD;;;OAGG;IACH,aAFU,UAAU,CAElB;IAEF;;;OAGG;IACH,cAFU,MAAM,CAEb;IAEH;;;OAGG;IACH,aAAI;IAEJ;;;OAGG;IACH,YAAG;IAEH;;;OAGG;IACH,gBAAO;IAeP;;;;;OAKG;IACH,gBALW,MAAM,QACN,MAAM,WACN,OAAO,GACL,cAAc,CAK1B;IAED;;;OAGG;IACH,oBAHW,MAAM,GACJ,cAAc,CAK1B;IAED;;;OAGG;IACH,mBAHW,MAAM,GACJ,cAAc,CAK1B;IAED;;;OAGG;IACH,2BAHW,MAAM,GACJ,cAAc,CAM1B;IAED;;OAEG;IACH,aA8DC;CACJ;gCAxJ8B,aAAa"}
1
+ {"version":3,"file":"ArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ArtifactWriter.js"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH;IA+BI;;;OAGG;IACH,gBAHW,UAAU,OACV,MAAM,EAShB;IAzCD;;;OAGG;IACH,aAFU,UAAU,CAElB;IAEF;;;OAGG;IACH,cAFU,MAAM,CAEb;IAEH;;;OAGG;IACH,aAAI;IAEJ;;;OAGG;IACH,YAAG;IAEH;;;OAGG;IACH,gBAAO;IAeP;;;;;OAKG;IACH,gBALW,MAAM,QACN,MAAM,UACN,OAAO,GACL,cAAc,CAK1B;IAED;;OAEG;IACH,8BAFW,UAAU,QAQpB;IAED;;;OAGG;IACH,oBAHW,MAAM,GACJ,cAAc,CAK1B;IAED;;;OAGG;IACH,mBAHW,MAAM,GACJ,cAAc,CAK1B;IAED;;;OAGG;IACH,2BAHW,MAAM,GACJ,cAAc,CAM1B;IAED;;OAEG;IACH,aA8DC;CACJ;gCAnK8B,aAAa;gCADb,yBAAyB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ChildArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ChildArtifactWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;IAaI;;;OAGG;IACH,oBAHW,QAAQ,QACR,MAAM,EAOhB;IArBD;;;OAGG;IACH,iBAFU,QAAQ,CAEZ;IAEN;;;OAGG;IACH,eAFU,MAAM,CAEZ;IAaJ;;OAEG;IACH,iBAFU,OAAO,CAIhB;IAED;;;;;OAKG;IACH,mBALW,MAAM,WACN,WAAW,cACX,OAAO,GACL,mBAAmB,CA+C/B;CACJ;+BA1F8B,qBAAqB;8BAIvB,eAAe;iCADZ,mBAAmB"}
1
+ {"version":3,"file":"ChildArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ChildArtifactWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;IAaI;;;OAGG;IACH,oBAHW,QAAQ,QACR,MAAM,EAOhB;IArBD;;;OAGG;IACH,iBAFU,QAAQ,CAEZ;IAEN;;;OAGG;IACH,eAFU,MAAM,CAEZ;IAaJ;;OAEG;IACH,iBAFU,OAAO,CAIhB;IAED;;;;;OAKG;IACH,mBALW,MAAM,WACN,WAAW,cACX,OAAO,GACL,mBAAmB,CA0D/B;CACJ;+BArG8B,qBAAqB;8BAIvB,eAAe;iCADZ,mBAAmB"}
@@ -1,5 +1,7 @@
1
1
  /**
2
- * @import { UplcProgram } from "@helios-lang/uplc"
2
+ * @import { Address, AssetClass } from "@helios-lang/ledger"
3
+ * @import { TypeSchema } from "@helios-lang/type-utils"
4
+ * @import { UplcData, UplcProgram } from "@helios-lang/uplc"
3
5
  * @import { UserFuncProps } from "../index.js"
4
6
  * @import { Artifact } from "./Artifact.js"
5
7
  * @import { FunctionDetails } from "./symbols.js"
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/FunctionArtifact.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AAEH;;;;GAIG;AACH,8CAJW,QAAQ,QACR,MAAM,WACN,eAAe,QAezB;8BAtB4B,eAAe;qCACR,cAAc"}
1
+ {"version":3,"file":"FunctionArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/FunctionArtifact.js"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,8CAJW,QAAQ,QACR,MAAM,WACN,eAAe,QAezB;8BAtB4B,eAAe;qCACR,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"RootArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/RootArtifact.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,uDAHW,GAAG,WACH,oCAAoC,QAmC9C;0DAzCyJ,aAAa"}
1
+ {"version":3,"file":"RootArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/RootArtifact.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,uDAHW,GAAG,WACH,oCAAoC,QAoC9C;0DA1CyJ,aAAa"}
@@ -8,9 +8,10 @@
8
8
  * @param {Artifact} parent
9
9
  * @param {string} name
10
10
  * @param {ScriptHash} hash
11
+ * @param {string} purpose
11
12
  * @param {ModuleSymbols} symbols
12
13
  */
13
- export function writeValidatorArtifact(parent: Artifact, name: string, hash: ScriptHash, symbols: ModuleSymbols): void;
14
+ export function writeValidatorArtifact(parent: Artifact, name: string, hash: ScriptHash, purpose: string, symbols: ModuleSymbols): void;
14
15
  import type { Artifact } from "./Artifact.js";
15
16
  import type { ScriptHash } from "@helios-lang/ledger";
16
17
  import type { ModuleSymbols } from "./symbols.js";
@@ -1 +1 @@
1
- {"version":3,"file":"ValidatorArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/ValidatorArtifact.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;;;;GAKG;AACH,+CALW,QAAQ,QACR,MAAM,QACN,UAAU,WACV,aAAa,QAYvB;8BApB4B,eAAe;gCAFoC,qBAAqB;mCAGnE,cAAc"}
1
+ {"version":3,"file":"ValidatorArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/ValidatorArtifact.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,+CANW,QAAQ,QACR,MAAM,QACN,UAAU,WACV,MAAM,WACN,aAAa,QAYvB;8BArB4B,eAAe;gCAFoC,qBAAqB;mCAGnE,cAAc"}