@pbgtoken/rwa-contract 1.1.8 → 1.1.17
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/dist/index.js +535 -51
- package/package.json +5 -3
- package/types/BullionVaultProvider.d.ts +1 -0
- package/types/RWAMetadata.d.ts +3708 -0
- package/{dist → types}/index.d.ts +2 -2
- package/types/validators/index.d.ts +954 -0
- package/dist/tokens.d.ts +0 -2
- package/dist/validators/index.d.ts +0 -460
- /package/{dist → types}/BSCAccountProvider.d.ts +0 -0
- /package/{dist → types}/BinanceAccountProvider.d.ts +0 -0
- /package/{dist → types}/BitcoinWalletProvider.d.ts +0 -0
- /package/{dist → types}/CardanoWalletProvider.d.ts +0 -0
- /package/{dist → types}/CoinGeckoProvider.d.ts +0 -0
- /package/{dist → types}/EthereumERC20AccountProvider.d.ts +0 -0
- /package/{dist → types}/PricesProvider.d.ts +0 -0
- /package/{dist → types}/RWADatumProvider.d.ts +0 -0
- /package/{dist → types}/TokenizedAccountProvider.d.ts +0 -0
- /package/{dist → types}/TransferID.d.ts +0 -0
- /package/{dist → types}/retryExpBackoff.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -161,10 +161,82 @@ var CardanoWalletProviderImpl = class {
|
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
-
// src/
|
|
165
|
-
import {
|
|
166
|
-
import {
|
|
167
|
-
|
|
164
|
+
// src/RWAMetadata.ts
|
|
165
|
+
import { Schema } from "effect";
|
|
166
|
+
import { Ledger, Uplc } from "@helios-lang/effect";
|
|
167
|
+
var WrappedAssetMetadata = Uplc.Data.EnumVariant(0, {
|
|
168
|
+
state: Uplc.Data.StructFromMap({
|
|
169
|
+
supply: Uplc.Data.BigInt,
|
|
170
|
+
type: Uplc.Data.LiteralString("WrappedAsset"),
|
|
171
|
+
venue: Uplc.Data.String,
|
|
172
|
+
policy: Uplc.Data.String,
|
|
173
|
+
account: Uplc.Data.String,
|
|
174
|
+
ticker: Uplc.Data.String,
|
|
175
|
+
name: Uplc.Data.String,
|
|
176
|
+
description: Uplc.Data.String,
|
|
177
|
+
decimals: Uplc.Data.Int,
|
|
178
|
+
url: Uplc.Data.String,
|
|
179
|
+
logo: Uplc.Data.String,
|
|
180
|
+
quorum: Uplc.Data.Int,
|
|
181
|
+
oracles: Uplc.Data.Array(Ledger.PubKeyHash.FromUplcData),
|
|
182
|
+
seed: Ledger.TxOutputId.FromUplcData
|
|
183
|
+
}),
|
|
184
|
+
version: Uplc.Data.Int,
|
|
185
|
+
extra: Uplc.Data.EnumVariant(0, {})
|
|
186
|
+
});
|
|
187
|
+
var SelfReportedAssetMetadata = Uplc.Data.EnumVariant(0, {
|
|
188
|
+
state: Uplc.Data.StructFromMap({
|
|
189
|
+
supply: Uplc.Data.BigInt,
|
|
190
|
+
type: Uplc.Data.LiteralString("SelfReportedAsset"),
|
|
191
|
+
asset: Uplc.Data.String,
|
|
192
|
+
ticker: Uplc.Data.String,
|
|
193
|
+
name: Uplc.Data.String,
|
|
194
|
+
description: Uplc.Data.String,
|
|
195
|
+
decimals: Uplc.Data.Int,
|
|
196
|
+
url: Uplc.Data.String,
|
|
197
|
+
logo: Uplc.Data.String,
|
|
198
|
+
owner: Ledger.PubKeyHash.FromUplcData,
|
|
199
|
+
seed: Ledger.TxOutputId.FromUplcData
|
|
200
|
+
}),
|
|
201
|
+
version: Uplc.Data.Int,
|
|
202
|
+
extra: Uplc.Data.EnumVariant(0, {})
|
|
203
|
+
});
|
|
204
|
+
var CorporateBondV1Metadata = Uplc.Data.EnumVariant(0, {
|
|
205
|
+
state: Uplc.Data.StructFromMap({
|
|
206
|
+
type: Uplc.Data.LiteralString("CorporateBondV1"),
|
|
207
|
+
company: Uplc.Data.String,
|
|
208
|
+
asset: Ledger.AssetClass.FromUplcData,
|
|
209
|
+
principal: Uplc.Data.BigInt,
|
|
210
|
+
rate: Uplc.Data.Int,
|
|
211
|
+
start: Uplc.Data.Int,
|
|
212
|
+
duration: Uplc.Data.Int,
|
|
213
|
+
interval: Uplc.Data.Int,
|
|
214
|
+
ticker: Uplc.Data.String,
|
|
215
|
+
name: Uplc.Data.String,
|
|
216
|
+
description: Uplc.Data.String,
|
|
217
|
+
decimals: Uplc.Data.Int,
|
|
218
|
+
url: Uplc.Data.String,
|
|
219
|
+
logo: Uplc.Data.String,
|
|
220
|
+
seed: Ledger.TxOutputId.FromUplcData
|
|
221
|
+
}),
|
|
222
|
+
version: Uplc.Data.Int,
|
|
223
|
+
extra: Uplc.Data.EnumVariant(0, {})
|
|
224
|
+
});
|
|
225
|
+
var RWAMetadata = Schema.Union(
|
|
226
|
+
WrappedAssetMetadata,
|
|
227
|
+
SelfReportedAssetMetadata,
|
|
228
|
+
CorporateBondV1Metadata
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
// src/TransferID.ts
|
|
232
|
+
function filterTransfersAfter(transfers, after) {
|
|
233
|
+
const cutOff = transfers.findIndex((id) => id == after);
|
|
234
|
+
if (cutOff != -1) {
|
|
235
|
+
return transfers.slice(cutOff + 1);
|
|
236
|
+
} else {
|
|
237
|
+
return transfers;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
168
240
|
|
|
169
241
|
// src/validators/index.ts
|
|
170
242
|
import { makeCast, makeUserFunc } from "@helios-lang/contract-utils";
|
|
@@ -421,10 +493,461 @@ func main(args: MixedArgs) -> () {
|
|
|
421
493
|
"main": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "main", "arguments": [{ "name": "$datum", "isOptional": true, "type": { "kind": "internal", "name": "Data" } }, { "name": "args", "isOptional": false, "type": { "kind": "enum", "id": "__helios__mixedargs", "name": "MixedArgs", "variantTypes": [{ "kind": "variant", "name": "Other", "id": "__helios__mixedargs__other", "tag": 0, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }, { "kind": "variant", "name": "Spending", "id": "__helios__mixedargs__spending", "tag": 1, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }] } }], "requiresCurrentScript": false, "requiresScriptContext": true }, castConfig: config, validatorIndices: __validatorIndices })
|
|
422
494
|
}
|
|
423
495
|
};
|
|
496
|
+
var corporate_bond_v1 = {
|
|
497
|
+
$name: "corporate_bond_v1",
|
|
498
|
+
$purpose: "mixed",
|
|
499
|
+
$currentScriptIndex: 1,
|
|
500
|
+
$sourceCode: `mixed corporate_bond_v1
|
|
501
|
+
|
|
502
|
+
import { get_current_input, tx } from ScriptContext
|
|
503
|
+
|
|
504
|
+
struct Metadata {
|
|
505
|
+
type: String "type" // "CorporateBondV1", can't change
|
|
506
|
+
|
|
507
|
+
company: String "company" // the company issuing the bond, eg. "PBG", can't change
|
|
508
|
+
asset: AssetClass "asset" // denomination of bond
|
|
509
|
+
principal: Int "principal" // number of "asset" required to pay back the bond
|
|
510
|
+
rate: Int "rate" // annual repay rate in basis points, eg. 12% is 1200 basis points
|
|
511
|
+
start: Time "start" // when the bond was issued
|
|
512
|
+
duration: Duration "duration" // end=start+duration, the time the bond can be returned to redeem the underlying principal
|
|
513
|
+
interval: Duration "interval" // payment interval
|
|
514
|
+
|
|
515
|
+
ticker: String "ticker" // can't change
|
|
516
|
+
name: String "name"
|
|
517
|
+
description: String "description"
|
|
518
|
+
decimals: Int "decimals" // always 0, can't change
|
|
519
|
+
url: String "url"
|
|
520
|
+
logo: String "logo"
|
|
521
|
+
|
|
522
|
+
seed: TxOutputId "seed" // can't change
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
enum Cip68Extra {
|
|
526
|
+
Unused
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
enum MetadataWrapper {
|
|
530
|
+
Cip68 {
|
|
531
|
+
metadata: Metadata
|
|
532
|
+
version: Int
|
|
533
|
+
extra: Cip68Extra
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
func metadata(self) -> Metadata {
|
|
537
|
+
self.switch{
|
|
538
|
+
x: Cip68 => x.metadata
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
func version(self) -> Int {
|
|
543
|
+
self.switch{
|
|
544
|
+
x: Cip68 => x.version
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
func extra(self) -> Cip68Extra {
|
|
549
|
+
self.switch{
|
|
550
|
+
x: Cip68 => x.extra
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// TODO: ability to leave const params unset during hl2ts transpilation
|
|
556
|
+
const TYPE = "CorporateBondV1"
|
|
557
|
+
const COMPANY = "COMPANY"
|
|
558
|
+
const ASSET = AssetClass::ADA
|
|
559
|
+
const PRINCIPAL = 100000000000
|
|
560
|
+
const RATE = 1200
|
|
561
|
+
const START = Time::new(0)
|
|
562
|
+
const DURATION = Duration::DAY*365
|
|
563
|
+
const INTERVAL = Duration::DAY*30
|
|
564
|
+
|
|
565
|
+
const TICKER = "TICKER"
|
|
566
|
+
|
|
567
|
+
const SEED = TxOutputId::new(TxId::new(#), 0)
|
|
568
|
+
|
|
569
|
+
const ticker_bytes = TICKER.encode_utf8()
|
|
570
|
+
const user_token_name = Cip67::user_token_label + ticker_bytes
|
|
571
|
+
const ref_token_name = Cip67::reference_token_label + ticker_bytes
|
|
572
|
+
|
|
573
|
+
const own_hash = Scripts::corporate_bond_v1
|
|
574
|
+
const own_mph = MintingPolicyHash::from_script_hash(own_hash)
|
|
575
|
+
const own_address = Address::new(
|
|
576
|
+
SpendingCredential::new_validator(
|
|
577
|
+
ValidatorHash::from_script_hash(own_hash)
|
|
578
|
+
),
|
|
579
|
+
Option[StakingCredential]::None
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
const ref_token_asset_class = AssetClass::new(own_mph, ref_token_name)
|
|
583
|
+
const user_token_asset_class = AssetClass::new(own_mph, user_token_name)
|
|
584
|
+
|
|
585
|
+
func validate_initialization() -> () {
|
|
586
|
+
assert(tx.inputs.any((input: TxInput) -> {
|
|
587
|
+
input.output_id == SEED
|
|
588
|
+
}), "seed not spent")
|
|
589
|
+
|
|
590
|
+
ref_utxo = tx.outputs.find((output: TxOutput) -> {
|
|
591
|
+
output.address == own_address
|
|
592
|
+
&& output.value.get_safe(ref_token_asset_class) == 1
|
|
593
|
+
})
|
|
594
|
+
|
|
595
|
+
metadata_wrapper = ref_utxo.datum.inline.as_strictly[MetadataWrapper]
|
|
596
|
+
metadata = metadata_wrapper.metadata()
|
|
597
|
+
|
|
598
|
+
assert(metadata.type == TYPE, "unexpected type")
|
|
599
|
+
assert(metadata.company == COMPANY, "unexpected company")
|
|
600
|
+
assert(metadata.asset == ASSET, "unexpected asset")
|
|
601
|
+
assert(metadata.principal == PRINCIPAL, "unexpected principal")
|
|
602
|
+
assert(metadata.rate == RATE, "unexpected rate")
|
|
603
|
+
assert(metadata.start == START, "unexpected start")
|
|
604
|
+
assert(metadata.duration == DURATION, "unexpected duration")
|
|
605
|
+
assert(metadata.interval == INTERVAL, "unexpected interval")
|
|
606
|
+
|
|
607
|
+
assert(metadata.ticker == TICKER, "unexpected ticker")
|
|
608
|
+
assert(metadata.decimals == 0, "unexpected decimals")
|
|
609
|
+
|
|
610
|
+
assert(metadata.seed == SEED, "unexpected seed")
|
|
611
|
+
|
|
612
|
+
assert(metadata_wrapper.version() == 1, "unexpected metadata version")
|
|
613
|
+
assert(metadata_wrapper.extra() == Cip68Extra::Unused, "unexpected metadata extra values")
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
func validate_metadata_change(input: TxInput) -> () {
|
|
617
|
+
metadata0 = input.datum.inline.as[MetadataWrapper].metadata()
|
|
618
|
+
|
|
619
|
+
output = tx.outputs.find((output: TxOutput) -> {
|
|
620
|
+
output.address == own_address
|
|
621
|
+
&& output.value.get_safe(ref_token_asset_class) > 0
|
|
622
|
+
})
|
|
623
|
+
|
|
624
|
+
metadata1 = output.datum.inline.as_strictly[MetadataWrapper].metadata()
|
|
625
|
+
|
|
626
|
+
// ensure constant metadata fields don't change
|
|
627
|
+
assert(metadata1.type == TYPE, "type changed")
|
|
628
|
+
assert(metadata1.company == metadata0.company, "company changed")
|
|
629
|
+
assert(metadata1.asset == metadata0.asset, "asset changed")
|
|
630
|
+
assert(metadata1.principal == metadata0.principal, "principal changed")
|
|
631
|
+
assert(metadata1.rate == metadata0.rate, "rate changed")
|
|
632
|
+
assert(metadata1.start == metadata0.start, "start changed")
|
|
633
|
+
assert(metadata1.duration == metadata0.duration, "duration changed")
|
|
634
|
+
assert(metadata1.interval == metadata0.interval, "interval changed")
|
|
635
|
+
|
|
636
|
+
assert(metadata1.ticker == metadata0.ticker, "ticker changed")
|
|
637
|
+
assert(metadata1.decimals == 0, "decimals changed")
|
|
638
|
+
|
|
639
|
+
assert(metadata1.seed == SEED, "seed changed")
|
|
640
|
+
|
|
641
|
+
assert(tx.minted.get_policy(own_mph).is_empty(), "unexpected tokens minted")
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
func main(args: MixedArgs) -> () {
|
|
645
|
+
args.switch{
|
|
646
|
+
Spending => {
|
|
647
|
+
|
|
648
|
+
utxo = get_current_input()
|
|
649
|
+
|
|
650
|
+
tokens = utxo.value.get_policy(own_mph)
|
|
651
|
+
|
|
652
|
+
if (tokens.is_empty()) {
|
|
653
|
+
// UTXOs that don't contain any tokens from current policy can always be spent.
|
|
654
|
+
// This can be used to remove garbage.
|
|
655
|
+
()
|
|
656
|
+
} else {
|
|
657
|
+
(name, _) = tokens.head
|
|
658
|
+
|
|
659
|
+
if (name == ref_token_name) {
|
|
660
|
+
validate_metadata_change(utxo)
|
|
661
|
+
} else {
|
|
662
|
+
error("unexpected token name")
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
Other => {
|
|
667
|
+
tokens = tx.minted.get_policy(own_mph)
|
|
668
|
+
n = tokens.length
|
|
669
|
+
|
|
670
|
+
if (n == 1) {
|
|
671
|
+
// must be burned
|
|
672
|
+
(name, qty) = tokens.head
|
|
673
|
+
|
|
674
|
+
assert(qty == -1, "must be burned")
|
|
675
|
+
assert(name == user_token_name, "only nft can be burned")
|
|
676
|
+
} else if (n == 2) {
|
|
677
|
+
user_token_qty = tokens.get(user_token_name)
|
|
678
|
+
assert(user_token_qty == 1, "only one nft can be minted")
|
|
679
|
+
|
|
680
|
+
ref_token_qty = tokens.get(ref_token_name)
|
|
681
|
+
|
|
682
|
+
assert(ref_token_qty == 1, "only one ref token can be minted")
|
|
683
|
+
|
|
684
|
+
validate_initialization()
|
|
685
|
+
} else {
|
|
686
|
+
error("invalid minted/burned tokens")
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}`,
|
|
691
|
+
$dependencies: [],
|
|
692
|
+
$hashDependencies: [],
|
|
693
|
+
$dependsOnOwnHash: true,
|
|
694
|
+
$Redeemer: (config) => makeCast({ "kind": "enum", "id": "__helios__mixedargs", "name": "MixedArgs", "variantTypes": [{ "kind": "variant", "name": "Other", "id": "__helios__mixedargs__other", "tag": 0, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }, { "kind": "variant", "name": "Spending", "id": "__helios__mixedargs__spending", "tag": 1, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }] }, config),
|
|
695
|
+
$Datum: (config) => makeCast({ "kind": "internal", "name": "Data" }, config),
|
|
696
|
+
$types: {
|
|
697
|
+
Metadata: (config) => makeCast({ "kind": "struct", "format": "map", "id": "__module__corporate_bond_v1__Metadata[]", "name": "Metadata", "fieldTypes": [{ "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "company", "type": { "kind": "internal", "name": "String" }, "key": "company" }, { "name": "asset", "type": { "kind": "internal", "name": "AssetClass" }, "key": "asset" }, { "name": "principal", "type": { "kind": "internal", "name": "Int" }, "key": "principal" }, { "name": "rate", "type": { "kind": "internal", "name": "Int" }, "key": "rate" }, { "name": "start", "type": { "kind": "internal", "name": "Time" }, "key": "start" }, { "name": "duration", "type": { "kind": "internal", "name": "Duration" }, "key": "duration" }, { "name": "interval", "type": { "kind": "internal", "name": "Duration" }, "key": "interval" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] }, config),
|
|
698
|
+
Cip68Extra: (config) => makeCast({ "kind": "enum", "name": "Cip68Extra", "id": "__module__corporate_bond_v1__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] }, config),
|
|
699
|
+
MetadataWrapper: (config) => makeCast({ "kind": "enum", "name": "MetadataWrapper", "id": "__module__corporate_bond_v1__MetadataWrapper[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__MetadataWrapper[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "metadata", "type": { "kind": "struct", "format": "map", "id": "__module__corporate_bond_v1__Metadata[]", "name": "Metadata", "fieldTypes": [{ "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "company", "type": { "kind": "internal", "name": "String" }, "key": "company" }, { "name": "asset", "type": { "kind": "internal", "name": "AssetClass" }, "key": "asset" }, { "name": "principal", "type": { "kind": "internal", "name": "Int" }, "key": "principal" }, { "name": "rate", "type": { "kind": "internal", "name": "Int" }, "key": "rate" }, { "name": "start", "type": { "kind": "internal", "name": "Time" }, "key": "start" }, { "name": "duration", "type": { "kind": "internal", "name": "Duration" }, "key": "duration" }, { "name": "interval", "type": { "kind": "internal", "name": "Duration" }, "key": "interval" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__corporate_bond_v1__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] }, config)
|
|
700
|
+
},
|
|
701
|
+
$functions: {
|
|
702
|
+
"MetadataWrapper::metadata": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "MetadataWrapper::metadata", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [{ "name": "self", "isOptional": false, "type": { "kind": "enum", "name": "MetadataWrapper", "id": "__module__corporate_bond_v1__MetadataWrapper[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__MetadataWrapper[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "metadata", "type": { "kind": "struct", "format": "map", "id": "__module__corporate_bond_v1__Metadata[]", "name": "Metadata", "fieldTypes": [{ "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "company", "type": { "kind": "internal", "name": "String" }, "key": "company" }, { "name": "asset", "type": { "kind": "internal", "name": "AssetClass" }, "key": "asset" }, { "name": "principal", "type": { "kind": "internal", "name": "Int" }, "key": "principal" }, { "name": "rate", "type": { "kind": "internal", "name": "Int" }, "key": "rate" }, { "name": "start", "type": { "kind": "internal", "name": "Time" }, "key": "start" }, { "name": "duration", "type": { "kind": "internal", "name": "Duration" }, "key": "duration" }, { "name": "interval", "type": { "kind": "internal", "name": "Duration" }, "key": "interval" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__corporate_bond_v1__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] } }], "returns": { "kind": "struct", "format": "map", "id": "__module__corporate_bond_v1__Metadata[]", "name": "Metadata", "fieldTypes": [{ "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "company", "type": { "kind": "internal", "name": "String" }, "key": "company" }, { "name": "asset", "type": { "kind": "internal", "name": "AssetClass" }, "key": "asset" }, { "name": "principal", "type": { "kind": "internal", "name": "Int" }, "key": "principal" }, { "name": "rate", "type": { "kind": "internal", "name": "Int" }, "key": "rate" }, { "name": "start", "type": { "kind": "internal", "name": "Time" }, "key": "start" }, { "name": "duration", "type": { "kind": "internal", "name": "Duration" }, "key": "duration" }, { "name": "interval", "type": { "kind": "internal", "name": "Duration" }, "key": "interval" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
703
|
+
"MetadataWrapper::version": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "MetadataWrapper::version", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [{ "name": "self", "isOptional": false, "type": { "kind": "enum", "name": "MetadataWrapper", "id": "__module__corporate_bond_v1__MetadataWrapper[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__MetadataWrapper[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "metadata", "type": { "kind": "struct", "format": "map", "id": "__module__corporate_bond_v1__Metadata[]", "name": "Metadata", "fieldTypes": [{ "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "company", "type": { "kind": "internal", "name": "String" }, "key": "company" }, { "name": "asset", "type": { "kind": "internal", "name": "AssetClass" }, "key": "asset" }, { "name": "principal", "type": { "kind": "internal", "name": "Int" }, "key": "principal" }, { "name": "rate", "type": { "kind": "internal", "name": "Int" }, "key": "rate" }, { "name": "start", "type": { "kind": "internal", "name": "Time" }, "key": "start" }, { "name": "duration", "type": { "kind": "internal", "name": "Duration" }, "key": "duration" }, { "name": "interval", "type": { "kind": "internal", "name": "Duration" }, "key": "interval" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__corporate_bond_v1__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] } }], "returns": { "kind": "internal", "name": "Int" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
704
|
+
"MetadataWrapper::extra": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "MetadataWrapper::extra", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [{ "name": "self", "isOptional": false, "type": { "kind": "enum", "name": "MetadataWrapper", "id": "__module__corporate_bond_v1__MetadataWrapper[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__MetadataWrapper[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "metadata", "type": { "kind": "struct", "format": "map", "id": "__module__corporate_bond_v1__Metadata[]", "name": "Metadata", "fieldTypes": [{ "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "company", "type": { "kind": "internal", "name": "String" }, "key": "company" }, { "name": "asset", "type": { "kind": "internal", "name": "AssetClass" }, "key": "asset" }, { "name": "principal", "type": { "kind": "internal", "name": "Int" }, "key": "principal" }, { "name": "rate", "type": { "kind": "internal", "name": "Int" }, "key": "rate" }, { "name": "start", "type": { "kind": "internal", "name": "Time" }, "key": "start" }, { "name": "duration", "type": { "kind": "internal", "name": "Duration" }, "key": "duration" }, { "name": "interval", "type": { "kind": "internal", "name": "Duration" }, "key": "interval" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__corporate_bond_v1__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] } }], "returns": { "kind": "enum", "name": "Cip68Extra", "id": "__module__corporate_bond_v1__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__corporate_bond_v1__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
705
|
+
"TYPE": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "TYPE", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "String" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
706
|
+
"COMPANY": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "COMPANY", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "String" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
707
|
+
"ASSET": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ASSET", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "AssetClass" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
708
|
+
"PRINCIPAL": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "PRINCIPAL", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Int" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
709
|
+
"RATE": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "RATE", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Int" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
710
|
+
"START": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "START", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Time" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
711
|
+
"DURATION": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "DURATION", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Duration" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
712
|
+
"INTERVAL": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "INTERVAL", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Duration" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
713
|
+
"TICKER": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "TICKER", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "String" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
714
|
+
"SEED": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "SEED", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "TxOutputId" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
715
|
+
"ticker_bytes": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ticker_bytes", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ByteArray" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
716
|
+
"user_token_name": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "user_token_name", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ByteArray" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
717
|
+
"ref_token_name": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ref_token_name", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ByteArray" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
718
|
+
"own_hash": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "own_hash", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ScriptHash" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
719
|
+
"own_mph": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "own_mph", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "MintingPolicyHash" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
720
|
+
"own_address": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "own_address", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Address" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
721
|
+
"ref_token_asset_class": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ref_token_asset_class", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "AssetClass" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
722
|
+
"user_token_asset_class": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "user_token_asset_class", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "AssetClass" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
723
|
+
"validate_initialization": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "validate_initialization", "requiresCurrentScript": false, "requiresScriptContext": true, "arguments": [] }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
724
|
+
"validate_metadata_change": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "validate_metadata_change", "requiresCurrentScript": false, "requiresScriptContext": true, "arguments": [{ "name": "input", "isOptional": false, "type": { "kind": "internal", "name": "TxInput" } }] }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
725
|
+
"main": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "main", "arguments": [{ "name": "$datum", "isOptional": true, "type": { "kind": "internal", "name": "Data" } }, { "name": "args", "isOptional": false, "type": { "kind": "enum", "id": "__helios__mixedargs", "name": "MixedArgs", "variantTypes": [{ "kind": "variant", "name": "Other", "id": "__helios__mixedargs__other", "tag": 0, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }, { "kind": "variant", "name": "Spending", "id": "__helios__mixedargs__spending", "tag": 1, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }] } }], "requiresCurrentScript": false, "requiresScriptContext": true }, castConfig: config, validatorIndices: __validatorIndices })
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
var self_reported_asset = {
|
|
729
|
+
$name: "self_reported_asset",
|
|
730
|
+
$purpose: "mixed",
|
|
731
|
+
$currentScriptIndex: 2,
|
|
732
|
+
$sourceCode: `mixed self_reported_asset
|
|
733
|
+
|
|
734
|
+
import { get_current_input, tx } from ScriptContext
|
|
735
|
+
|
|
736
|
+
struct State {
|
|
737
|
+
supply: Int "supply"
|
|
738
|
+
|
|
739
|
+
type: String "type" // "SelfReportedAsset", can't change
|
|
740
|
+
asset: String "asset" // eg. "Silver" or "Silver OZ"
|
|
741
|
+
|
|
742
|
+
ticker: String "ticker" // can't change
|
|
743
|
+
name: String "name"
|
|
744
|
+
description: String "description"
|
|
745
|
+
decimals: Int "decimals" // can't change
|
|
746
|
+
url: String "url"
|
|
747
|
+
logo: String "logo"
|
|
748
|
+
|
|
749
|
+
owner: PubKeyHash "owner" // can't change
|
|
750
|
+
seed: TxOutputId "seed" // can't change
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
enum Cip68Extra {
|
|
754
|
+
Unused
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
enum Metadata {
|
|
758
|
+
Cip68 {
|
|
759
|
+
state: State
|
|
760
|
+
version: Int
|
|
761
|
+
extra: Cip68Extra
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
func state(self) -> State {
|
|
765
|
+
self.switch{
|
|
766
|
+
x: Cip68 => x.state
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
func version(self) -> Int {
|
|
771
|
+
self.switch{
|
|
772
|
+
x: Cip68 => x.version
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
func extra(self) -> Cip68Extra {
|
|
777
|
+
self.switch{
|
|
778
|
+
x: Cip68 => x.extra
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
struct Redeemer {
|
|
784
|
+
reserves: Int
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// TODO: ability to leave const params unset during hl2ts transpilation
|
|
788
|
+
const TYPE = "SelfReportedAsset"
|
|
789
|
+
const ASSET = "ASSET"
|
|
790
|
+
|
|
791
|
+
const TICKER = "TICKER"
|
|
792
|
+
const DECIMALS = 0
|
|
793
|
+
|
|
794
|
+
const OWNER = PubKeyHash::new(#)
|
|
795
|
+
const SEED = TxOutputId::new(TxId::new(#), 0)
|
|
796
|
+
|
|
797
|
+
const ticker_bytes = TICKER.encode_utf8()
|
|
798
|
+
const user_token_name = Cip67::fungible_token_label + ticker_bytes
|
|
799
|
+
const ref_token_name = Cip67::reference_token_label + ticker_bytes
|
|
800
|
+
|
|
801
|
+
const own_hash = Scripts::self_reported_asset
|
|
802
|
+
const own_mph = MintingPolicyHash::from_script_hash(own_hash)
|
|
803
|
+
const own_address = Address::new(
|
|
804
|
+
SpendingCredential::new_validator(
|
|
805
|
+
ValidatorHash::from_script_hash(own_hash)
|
|
806
|
+
),
|
|
807
|
+
Option[StakingCredential]::None
|
|
808
|
+
)
|
|
809
|
+
|
|
810
|
+
const ref_token_asset_class = AssetClass::new(own_mph, ref_token_name)
|
|
811
|
+
const user_token_asset_class = AssetClass::new(own_mph, user_token_name)
|
|
812
|
+
|
|
813
|
+
func validate_initialization() -> () {
|
|
814
|
+
assert(tx.inputs.any((input: TxInput) -> {
|
|
815
|
+
input.output_id == SEED
|
|
816
|
+
}), "seed not spent")
|
|
817
|
+
|
|
818
|
+
ref_utxo = tx.outputs.find((output: TxOutput) -> {
|
|
819
|
+
output.address == own_address
|
|
820
|
+
&& output.value.get_safe(ref_token_asset_class) == 1
|
|
821
|
+
})
|
|
822
|
+
|
|
823
|
+
metadata = ref_utxo.datum.inline.as_strictly[Metadata]
|
|
824
|
+
state = metadata.state()
|
|
825
|
+
|
|
826
|
+
assert(state.supply == 0, "supply not initialized at 0")
|
|
827
|
+
|
|
828
|
+
assert(state.type == TYPE, "unexpected type")
|
|
829
|
+
assert(state.asset == ASSET, "unexpected asset")
|
|
830
|
+
|
|
831
|
+
assert(state.ticker == TICKER, "unexpected ticker")
|
|
832
|
+
assert(state.decimals == DECIMALS, "unexpected decimals")
|
|
833
|
+
|
|
834
|
+
assert(state.seed == SEED, "unexpected seed")
|
|
835
|
+
|
|
836
|
+
assert(metadata.version() == 1, "unexpected metadata version")
|
|
837
|
+
assert(metadata.extra() == Cip68Extra::Unused, "unexpected metadata extra values")
|
|
838
|
+
|
|
839
|
+
assert(tx.is_signed_by(OWNER), "tx not signed by owner")
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
func validate_state_change(input: TxInput) -> () {
|
|
843
|
+
state0 = input.datum.inline.as[Metadata].state()
|
|
844
|
+
|
|
845
|
+
output = tx.outputs.find((output: TxOutput) -> {
|
|
846
|
+
output.address == own_address
|
|
847
|
+
&& output.value.get_safe(ref_token_asset_class) > 0
|
|
848
|
+
})
|
|
849
|
+
|
|
850
|
+
state1 = output.datum.inline.as_strictly[Metadata].state()
|
|
851
|
+
|
|
852
|
+
// ensure constant metadata fields don't change
|
|
853
|
+
assert(state1.type == TYPE, "type changed")
|
|
854
|
+
assert(state1.asset == state0.asset, "asset changed")
|
|
855
|
+
|
|
856
|
+
assert(state1.ticker == state0.ticker, "ticker changed")
|
|
857
|
+
assert(state1.decimals == state0.decimals, "decimals changed")
|
|
858
|
+
assert(state1.owner == OWNER, "owner changed")
|
|
859
|
+
assert(state1.seed == SEED, "seed changed")
|
|
860
|
+
|
|
861
|
+
n = tx.minted.get_safe(user_token_asset_class)
|
|
862
|
+
|
|
863
|
+
assert((state1.supply - state0.supply) == n, "current token supply not updated correctly")
|
|
864
|
+
|
|
865
|
+
if (n > 0) {
|
|
866
|
+
assert(tx.is_signed_by(OWNER), "tx not signed by owner")
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
func main(args: MixedArgs) -> () {
|
|
871
|
+
args.switch{
|
|
872
|
+
Spending => {
|
|
873
|
+
utxo = get_current_input()
|
|
874
|
+
|
|
875
|
+
tokens = utxo.value.get_policy(own_mph)
|
|
876
|
+
|
|
877
|
+
if (tokens.is_empty()) {
|
|
878
|
+
// UTXOs that don't contain any tokens from current policy canref_token_name always be spent.
|
|
879
|
+
// This can be used to remove garbage.
|
|
880
|
+
()
|
|
881
|
+
} else {
|
|
882
|
+
(name, _) = tokens.head
|
|
883
|
+
|
|
884
|
+
if (name == ref_token_name) {
|
|
885
|
+
validate_state_change(utxo)
|
|
886
|
+
} else {
|
|
887
|
+
error("unexpected token name")
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
Other => {
|
|
892
|
+
tokens = tx.minted.get_policy(own_mph)
|
|
893
|
+
|
|
894
|
+
(name, qty) = tokens.head
|
|
895
|
+
tail = tokens.tail
|
|
896
|
+
|
|
897
|
+
assert(tail.is_empty(), "only one token kind can be minted or burned")
|
|
898
|
+
|
|
899
|
+
if (name == user_token_name && qty != 0) {
|
|
900
|
+
// metadata token must be spent, which triggers Spending witness, and makes sure supply is correctly updated
|
|
901
|
+
assert(tx.inputs.any((input: TxInput) -> {
|
|
902
|
+
input.address == own_address
|
|
903
|
+
&& input.value.get_safe(ref_token_asset_class) > 0
|
|
904
|
+
}), "ref token not spent")
|
|
905
|
+
} else if (name == ref_token_name && qty == 1) {
|
|
906
|
+
validate_initialization()
|
|
907
|
+
} else {
|
|
908
|
+
error("invalid minted tokens")
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}`,
|
|
913
|
+
$dependencies: [],
|
|
914
|
+
$hashDependencies: [],
|
|
915
|
+
$dependsOnOwnHash: true,
|
|
916
|
+
$Redeemer: (config) => makeCast({ "kind": "enum", "id": "__helios__mixedargs", "name": "MixedArgs", "variantTypes": [{ "kind": "variant", "name": "Other", "id": "__helios__mixedargs__other", "tag": 0, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }, { "kind": "variant", "name": "Spending", "id": "__helios__mixedargs__spending", "tag": 1, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }] }, config),
|
|
917
|
+
$Datum: (config) => makeCast({ "kind": "internal", "name": "Data" }, config),
|
|
918
|
+
$types: {
|
|
919
|
+
State: (config) => makeCast({ "kind": "struct", "format": "map", "id": "__module__self_reported_asset__State[]", "name": "State", "fieldTypes": [{ "name": "supply", "type": { "kind": "internal", "name": "Int" }, "key": "supply" }, { "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "asset", "type": { "kind": "internal", "name": "String" }, "key": "asset" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "owner", "type": { "kind": "internal", "name": "PubKeyHash" }, "key": "owner" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] }, config),
|
|
920
|
+
Cip68Extra: (config) => makeCast({ "kind": "enum", "name": "Cip68Extra", "id": "__module__self_reported_asset__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] }, config),
|
|
921
|
+
Metadata: (config) => makeCast({ "kind": "enum", "name": "Metadata", "id": "__module__self_reported_asset__Metadata[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Metadata[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "state", "type": { "kind": "struct", "format": "map", "id": "__module__self_reported_asset__State[]", "name": "State", "fieldTypes": [{ "name": "supply", "type": { "kind": "internal", "name": "Int" }, "key": "supply" }, { "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "asset", "type": { "kind": "internal", "name": "String" }, "key": "asset" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "owner", "type": { "kind": "internal", "name": "PubKeyHash" }, "key": "owner" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__self_reported_asset__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] }, config),
|
|
922
|
+
Redeemer: (config) => makeCast({ "kind": "struct", "format": "singleton", "id": "__module__self_reported_asset__Redeemer[]", "name": "Redeemer", "fieldTypes": [{ "name": "reserves", "type": { "kind": "internal", "name": "Int" } }] }, config)
|
|
923
|
+
},
|
|
924
|
+
$functions: {
|
|
925
|
+
"Metadata::state": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "Metadata::state", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [{ "name": "self", "isOptional": false, "type": { "kind": "enum", "name": "Metadata", "id": "__module__self_reported_asset__Metadata[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Metadata[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "state", "type": { "kind": "struct", "format": "map", "id": "__module__self_reported_asset__State[]", "name": "State", "fieldTypes": [{ "name": "supply", "type": { "kind": "internal", "name": "Int" }, "key": "supply" }, { "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "asset", "type": { "kind": "internal", "name": "String" }, "key": "asset" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "owner", "type": { "kind": "internal", "name": "PubKeyHash" }, "key": "owner" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__self_reported_asset__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] } }], "returns": { "kind": "struct", "format": "map", "id": "__module__self_reported_asset__State[]", "name": "State", "fieldTypes": [{ "name": "supply", "type": { "kind": "internal", "name": "Int" }, "key": "supply" }, { "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "asset", "type": { "kind": "internal", "name": "String" }, "key": "asset" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "owner", "type": { "kind": "internal", "name": "PubKeyHash" }, "key": "owner" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
926
|
+
"Metadata::version": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "Metadata::version", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [{ "name": "self", "isOptional": false, "type": { "kind": "enum", "name": "Metadata", "id": "__module__self_reported_asset__Metadata[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Metadata[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "state", "type": { "kind": "struct", "format": "map", "id": "__module__self_reported_asset__State[]", "name": "State", "fieldTypes": [{ "name": "supply", "type": { "kind": "internal", "name": "Int" }, "key": "supply" }, { "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "asset", "type": { "kind": "internal", "name": "String" }, "key": "asset" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "owner", "type": { "kind": "internal", "name": "PubKeyHash" }, "key": "owner" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__self_reported_asset__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] } }], "returns": { "kind": "internal", "name": "Int" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
927
|
+
"Metadata::extra": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "Metadata::extra", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [{ "name": "self", "isOptional": false, "type": { "kind": "enum", "name": "Metadata", "id": "__module__self_reported_asset__Metadata[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Metadata[]__Cip68", "name": "Cip68", "fieldTypes": [{ "name": "state", "type": { "kind": "struct", "format": "map", "id": "__module__self_reported_asset__State[]", "name": "State", "fieldTypes": [{ "name": "supply", "type": { "kind": "internal", "name": "Int" }, "key": "supply" }, { "name": "type", "type": { "kind": "internal", "name": "String" }, "key": "type" }, { "name": "asset", "type": { "kind": "internal", "name": "String" }, "key": "asset" }, { "name": "ticker", "type": { "kind": "internal", "name": "String" }, "key": "ticker" }, { "name": "name", "type": { "kind": "internal", "name": "String" }, "key": "name" }, { "name": "description", "type": { "kind": "internal", "name": "String" }, "key": "description" }, { "name": "decimals", "type": { "kind": "internal", "name": "Int" }, "key": "decimals" }, { "name": "url", "type": { "kind": "internal", "name": "String" }, "key": "url" }, { "name": "logo", "type": { "kind": "internal", "name": "String" }, "key": "logo" }, { "name": "owner", "type": { "kind": "internal", "name": "PubKeyHash" }, "key": "owner" }, { "name": "seed", "type": { "kind": "internal", "name": "TxOutputId" }, "key": "seed" }] } }, { "name": "version", "type": { "kind": "internal", "name": "Int" } }, { "name": "extra", "type": { "kind": "enum", "name": "Cip68Extra", "id": "__module__self_reported_asset__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }] }] } }], "returns": { "kind": "enum", "name": "Cip68Extra", "id": "__module__self_reported_asset__Cip68Extra[]", "variantTypes": [{ "kind": "variant", "tag": 0, "id": "__module__self_reported_asset__Cip68Extra[]__Unused", "name": "Unused", "fieldTypes": [] }] } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
928
|
+
"TYPE": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "TYPE", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "String" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
929
|
+
"ASSET": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ASSET", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "String" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
930
|
+
"TICKER": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "TICKER", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "String" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
931
|
+
"DECIMALS": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "DECIMALS", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Int" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
932
|
+
"OWNER": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "OWNER", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "PubKeyHash" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
933
|
+
"SEED": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "SEED", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "TxOutputId" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
934
|
+
"ticker_bytes": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ticker_bytes", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ByteArray" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
935
|
+
"user_token_name": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "user_token_name", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ByteArray" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
936
|
+
"ref_token_name": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ref_token_name", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ByteArray" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
937
|
+
"own_hash": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "own_hash", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "ScriptHash" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
938
|
+
"own_mph": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "own_mph", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "MintingPolicyHash" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
939
|
+
"own_address": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "own_address", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "Address" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
940
|
+
"ref_token_asset_class": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "ref_token_asset_class", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "AssetClass" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
941
|
+
"user_token_asset_class": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "user_token_asset_class", "requiresCurrentScript": false, "requiresScriptContext": false, "arguments": [], "returns": { "kind": "internal", "name": "AssetClass" } }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
942
|
+
"validate_initialization": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "validate_initialization", "requiresCurrentScript": false, "requiresScriptContext": true, "arguments": [] }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
943
|
+
"validate_state_change": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "validate_state_change", "requiresCurrentScript": false, "requiresScriptContext": true, "arguments": [{ "name": "input", "isOptional": false, "type": { "kind": "internal", "name": "TxInput" } }] }, castConfig: config, validatorIndices: __validatorIndices }),
|
|
944
|
+
"main": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "main", "arguments": [{ "name": "$datum", "isOptional": true, "type": { "kind": "internal", "name": "Data" } }, { "name": "args", "isOptional": false, "type": { "kind": "enum", "id": "__helios__mixedargs", "name": "MixedArgs", "variantTypes": [{ "kind": "variant", "name": "Other", "id": "__helios__mixedargs__other", "tag": 0, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }, { "kind": "variant", "name": "Spending", "id": "__helios__mixedargs__spending", "tag": 1, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }] } }], "requiresCurrentScript": false, "requiresScriptContext": true }, castConfig: config, validatorIndices: __validatorIndices })
|
|
945
|
+
}
|
|
946
|
+
};
|
|
424
947
|
var wrapped_asset = {
|
|
425
948
|
$name: "wrapped_asset",
|
|
426
949
|
$purpose: "mixed",
|
|
427
|
-
$currentScriptIndex:
|
|
950
|
+
$currentScriptIndex: 3,
|
|
428
951
|
$sourceCode: `mixed wrapped_asset
|
|
429
952
|
|
|
430
953
|
import { get_current_input, tx } from ScriptContext
|
|
@@ -671,51 +1194,7 @@ func main(args: MixedArgs) -> () {
|
|
|
671
1194
|
"main": (uplc, config) => makeUserFunc(uplc, { ...{ "name": "main", "arguments": [{ "name": "$datum", "isOptional": true, "type": { "kind": "internal", "name": "Data" } }, { "name": "args", "isOptional": false, "type": { "kind": "enum", "id": "__helios__mixedargs", "name": "MixedArgs", "variantTypes": [{ "kind": "variant", "name": "Other", "id": "__helios__mixedargs__other", "tag": 0, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }, { "kind": "variant", "name": "Spending", "id": "__helios__mixedargs__spending", "tag": 1, "fieldTypes": [{ "name": "redeemer", "type": { "kind": "internal", "name": "Data" } }] }] } }], "requiresCurrentScript": false, "requiresScriptContext": true }, castConfig: config, validatorIndices: __validatorIndices })
|
|
672
1195
|
}
|
|
673
1196
|
};
|
|
674
|
-
var __validatorIndices = { "account_aggregate": 0, "
|
|
675
|
-
|
|
676
|
-
// src/RWADatumProvider.ts
|
|
677
|
-
var castMetadata = account_aggregate.$types.Metadata;
|
|
678
|
-
var castDatum = account_aggregate.$types.State;
|
|
679
|
-
function makeRWADatumProvider(provider) {
|
|
680
|
-
return new RWADatumProviderImpl(provider);
|
|
681
|
-
}
|
|
682
|
-
var RWADatumProviderImpl = class {
|
|
683
|
-
provider;
|
|
684
|
-
constructor(provider) {
|
|
685
|
-
this.provider = provider;
|
|
686
|
-
}
|
|
687
|
-
async fetch(policy) {
|
|
688
|
-
const utxo = await this.fetchMetadataUTXO(policy);
|
|
689
|
-
const metadata = castMetadata({ isMainnet: this.isMainnet }).fromUplcData(expectDefined(utxo.datum?.data, "metadata UTXO doesn't have datum"));
|
|
690
|
-
return metadata.Cip68.state;
|
|
691
|
-
}
|
|
692
|
-
get isMainnet() {
|
|
693
|
-
return this.provider.isMainnet();
|
|
694
|
-
}
|
|
695
|
-
async fetchMetadataUTXO(policy) {
|
|
696
|
-
const vh = makeValidatorHash(policy.bytes);
|
|
697
|
-
const addr = makeShelleyAddress(this.isMainnet, vh);
|
|
698
|
-
let utxos = await this.provider.getUtxos(addr);
|
|
699
|
-
utxos = utxos.filter(
|
|
700
|
-
(utxo) => utxo.value.assets.assets.some(
|
|
701
|
-
([mph, tokens]) => mph.isEqual(policy) && tokens.some(
|
|
702
|
-
([tokenName, qty]) => bytesToHex(tokenName.slice(0, 4)) == "000643b0" && qty == 1n
|
|
703
|
-
)
|
|
704
|
-
)
|
|
705
|
-
);
|
|
706
|
-
return expectDefined(utxos[0], "expected 1 metadata UTXO");
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
// src/TransferID.ts
|
|
711
|
-
function filterTransfersAfter(transfers, after) {
|
|
712
|
-
const cutOff = transfers.findIndex((id) => id == after);
|
|
713
|
-
if (cutOff != -1) {
|
|
714
|
-
return transfers.slice(cutOff + 1);
|
|
715
|
-
} else {
|
|
716
|
-
return transfers;
|
|
717
|
-
}
|
|
718
|
-
}
|
|
1197
|
+
var __validatorIndices = { "account_aggregate": 0, "corporate_bond_v1": 1, "self_reported_asset": 2, "wrapped_asset": 3 };
|
|
719
1198
|
|
|
720
1199
|
// src/CoinGeckoProvider.ts
|
|
721
1200
|
var CoinGeckoProvider = class {
|
|
@@ -1364,7 +1843,12 @@ function makeBSCAccountProvider(walletAddress, priceProvider, alchemyApiKey, tok
|
|
|
1364
1843
|
return new BSCAccountProvider(walletAddress, priceProvider, alchemyApiKey, tokenContractAddress, rpcUrl);
|
|
1365
1844
|
}
|
|
1366
1845
|
export {
|
|
1846
|
+
CorporateBondV1Metadata,
|
|
1847
|
+
RWAMetadata,
|
|
1848
|
+
SelfReportedAssetMetadata,
|
|
1849
|
+
WrappedAssetMetadata,
|
|
1367
1850
|
account_aggregate,
|
|
1851
|
+
corporate_bond_v1,
|
|
1368
1852
|
filterTransfersAfter,
|
|
1369
1853
|
makeBSCAccountProvider,
|
|
1370
1854
|
makeBinanceAccountProvider,
|
|
@@ -1372,6 +1856,6 @@ export {
|
|
|
1372
1856
|
makeCardanoWalletProvider,
|
|
1373
1857
|
makeCoinGeckoProvider,
|
|
1374
1858
|
makeEthereumERC20AccountProvider,
|
|
1375
|
-
|
|
1859
|
+
self_reported_asset,
|
|
1376
1860
|
wrapped_asset
|
|
1377
1861
|
};
|