{
  "title": "Helios One-Shot Mint",
  "description": "Parameterizes and compiles an Helios Smart Contract on the fly on user wallet, a One-Shot Mint validator pattern. The UTXO required for the one-shot mint is produced on a first transaction, but a previously-generated one can be provided to avoid this first step.",
  "type": "script",
  "args": {
    "asset-name": "KeepCalmAndUseGC",
    "quantity": "1"
  },
  "exportAs": "OneShotMinter",
  "return": {
    "mode": "last"
  },
  "run": {
    "generateUTXOs": {
      "type": "script",
      "isolateCache": true,
      "return": {
        "mode": "last"
      },
      "run": {
        "build": {
          "type": "buildTx",
          "title": "UTXO Generator",
          "tx": {}
        },
        "sign": {
          "detailedPermissions": false,
          "type": "signTxs",
          "txs": [
            "{get('cache.build.txHex')}"
          ]
        },
        "submit": {
          "type": "submitTxs",
          "txs": "{get('cache.sign')}"
        },
        "utxo": {
          "type": "macro",
          "run": {
            "txHash": "{get('cache.build.txHash')}",
            "outputs": "{get('cache.build.indexMap.output')}"
          }
        }
      }
    },
    "data": {
      "type": "macro",
      "run": {
        "assetNameHex": "{strToHex(get('args.asset-name'))}",
        "utxo": {
          "txHash": "{get('cache.generateUTXOs.txHash')}",
          "txOutIdx": "{get('cache.generateUTXOs.outputs.output:0')}"
        }
      }
    },
    "parameterizingSourceCode": {
      "type": "macro",
      "run": [
        "{set('tempSourceCode',base64ToStr('bWludGluZyB1dHhvX25mdAoKY29uc3QgYXNzZXRfbmFtZTogQnl0ZUFycmF5ID0gI0FTU0VUTkFNRV9IRVgKY29uc3Qgb3V0cHV0X2lkOiBUeE91dHB1dElkID0gVHhPdXRwdXRJZDo6bmV3KFR4SWQ6Om5ldygjVFhIQVNIKSwgVFhPVVRJRFgpCgpmdW5jIG1haW4oXywgY3R4OiBTY3JpcHRDb250ZXh0KSAtPiBCb29sIHsKICAgIHR4OiBUeCA9IGN0eC50eDsKCiAgICBuZnRfYXNzZXRjbGFzczogQXNzZXRDbGFzcyA9IEFzc2V0Q2xhc3M6Om5ldygKICAgICAgICBjdHguZ2V0X2N1cnJlbnRfbWludGluZ19wb2xpY3lfaGFzaCgpLAogICAgICAgIGFzc2V0X25hbWUKICAgICk7CgogICAgdmFsdWVfbWludGVkOiBWYWx1ZSA9IHR4Lm1pbnRlZDsKCiAgICB2YWx1ZV9taW50ZWQgPT0gVmFsdWU6Om5ldyhuZnRfYXNzZXRjbGFzcywgMSkgJiYKICAgIHR4LmlucHV0cwogICAgICAgIC5hbnkoKGlucHV0OiBUeElucHV0KSAtPiBCb29sIHtpbnB1dC5vdXRwdXRfaWQgPT0gb3V0cHV0X2lkfSkKfQo='))}",
        "{set('tempSourceCode',replaceAll(get('global.tempSourceCode'),'ASSETNAME_HEX',get('cache.data.assetNameHex')))}",
        "{set('tempSourceCode',replaceAll(get('global.tempSourceCode'),'TXHASH'       ,get('cache.data.utxo.txHash')))}",
        "{set('tempSourceCode',replaceAll(get('global.tempSourceCode'),'TXOUTIDX'     ,get('cache.data.utxo.txOutIdx')))}"
      ]
    },
    "validator": {
      "type": "plutusScript",
      "script": {
        "simplify": false,
        "heliosCode": "{get('global.tempSourceCode')}",
        "version": "0.15.2"
      }
    },
    "build": {
      "type": "buildTx",
      "title": "Helios One-Shot Mint",
      "tx": {
        "mints": [
          {
            "policyId": "{get('cache.validator.scriptHashHex')}",
            "assets": [
              {
                "assetNameHex": "{get('cache.data.assetNameHex')}",
                "quantity": "{get('args.quantity')}"
              }
            ]
          }
        ],
        "inputs": [
          {
            "txHash": "{get('cache.data.utxo.txHash')}",
            "index": "{get('cache.data.utxo.txOutIdx')}"
          }
        ],
        "witnesses": {
          "plutus": {
            "scripts": [
              {
                "scriptHex": "{get('cache.validator.scriptHex')}",
                "lang": "{get('cache.validator.lang')}"
              }
            ]
          }
        },
        "options": {
          "collateralCoinSelection": "LASLAD"
        }
      }
    },
    "sign": {
      "detailedPermissions": false,
      "type": "signTxs",
      "txs": [
        "{get('cache.build.txHex')}"
      ]
    },
    "submit": {
      "type": "submitTxs",
      "txs": "{get('cache.sign')}"
    },
    "finally": {
      "type": "macro",
      "run": {
        "policyId": "{get('cache.validator.scriptHashHex')}",
        "assetNameHex": "{get('cache.data.assetNameHex')}",
        "utxo": "{get('cache.data.utxo')}",
        "quantity": "{get('args.quantity')}",
        "smartContract": "{get('cache.validator.scriptHex')}",
        "txHash": "{get('cache.build.txHash')}"
      }
    }
  }
}