@givelotus/compiler 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +331 -2
- package/artifact-v2.schema.json +58 -0
- package/artifact.schema.json +19 -0
- package/dist/ast.d.ts +292 -0
- package/dist/ast.js +150 -0
- package/dist/bindings.d.ts +6 -0
- package/dist/bindings.js +134 -0
- package/dist/call-runtime.d.ts +84 -0
- package/dist/call-runtime.js +249 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +22 -0
- package/dist/compiler.d.ts +79 -0
- package/dist/compiler.js +125 -0
- package/dist/diagnostics.d.ts +163 -0
- package/dist/diagnostics.js +498 -0
- package/dist/ecash.d.ts +41 -0
- package/dist/ecash.js +190 -0
- package/dist/fees.d.ts +164 -0
- package/dist/fees.js +208 -0
- package/dist/fixture-cli.d.ts +2 -0
- package/dist/fixture-cli.js +41 -0
- package/dist/fixtures.d.ts +68 -0
- package/dist/fixtures.js +46 -0
- package/dist/forth-ir.d.ts +73 -0
- package/dist/forth-ir.js +147 -0
- package/dist/generic-cli.d.ts +2 -0
- package/dist/generic-cli.js +140 -0
- package/dist/generic.d.ts +48 -0
- package/dist/generic.js +2566 -0
- package/dist/lints.d.ts +8 -0
- package/dist/lints.js +204 -0
- package/dist/names.d.ts +1 -0
- package/dist/names.js +7 -0
- package/dist/opcodes.d.ts +154 -0
- package/dist/opcodes.js +162 -0
- package/dist/optimizer.d.ts +58 -0
- package/dist/optimizer.js +786 -0
- package/dist/package-fetch-cli.d.ts +2 -0
- package/dist/package-fetch-cli.js +17 -0
- package/dist/package-lock-cli.d.ts +2 -0
- package/dist/package-lock-cli.js +28 -0
- package/dist/package-sources.d.ts +82 -0
- package/dist/package-sources.js +785 -0
- package/dist/package-update-cli.d.ts +2 -0
- package/dist/package-update-cli.js +20 -0
- package/dist/packages.d.ts +231 -0
- package/dist/packages.js +1324 -0
- package/dist/parser.d.ts +32 -0
- package/dist/parser.js +575 -0
- package/dist/policy.d.ts +83 -0
- package/dist/policy.js +207 -0
- package/dist/runtime.d.ts +58 -0
- package/dist/runtime.js +126 -0
- package/dist/scheduler.d.ts +38 -0
- package/dist/scheduler.js +76 -0
- package/dist/semantic-ir.d.ts +76 -0
- package/dist/semantic-ir.js +231 -0
- package/dist/std.d.ts +27 -0
- package/dist/std.js +282 -0
- package/dist/target-compiler.d.ts +9 -0
- package/dist/target-compiler.js +139 -0
- package/dist/targets.d.ts +53 -0
- package/dist/targets.js +67 -0
- package/dist/token-cli.d.ts +2 -0
- package/dist/token-cli.js +82 -0
- package/dist/token-metadata.d.ts +43 -0
- package/dist/token-metadata.js +166 -0
- package/dist/toml-subset.d.ts +19 -0
- package/dist/toml-subset.js +81 -0
- package/dist/transaction-runtime.d.ts +182 -0
- package/dist/transaction-runtime.js +646 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +3 -0
- package/dist/vm-cost.d.ts +11 -0
- package/dist/vm-cost.js +541 -0
- package/package.json +74 -4
- package/policy-artifact.schema.json +20 -0
- package/std/custody/arbiter-escrow.lotus +20 -0
- package/std/custody/htlc.lotus +15 -0
- package/std/custody/multisig-2of3.lotus +13 -0
- package/std/custody/single-owner-wallet.lotus +9 -0
- package/std/custody/vault-with-recovery.lotus +14 -0
- package/std/defi/amm-pool-v2.lotus +97 -0
- package/std/defi/indexed-limit-order.lotus +37 -0
- package/std/nft/nft-collection.lotus +51 -0
- package/std/nft/royalty-transfer-rules.lotus +38 -0
- package/std/nft/unique-nft.lotus +30 -0
- package/std/tokens/capped-supply-token.lotus +76 -0
- package/std/tokens/fixed-supply-token.lotus +29 -0
- package/std/tokens/lrc20.lotus +26 -0
- package/std/tokens/standard-transfer-rules.lotus +15 -0
- package/std/tokens/stateful-token-merge.lotus +132 -0
- package/std/tokens/upgradable-token-rules.lotus +70 -0
- package/std/tokens/voucher-mint-token.lotus +31 -0
- package/std-pkg/lotus.toml +9 -0
- package/std-pkg/src/lrc20.lotus +38 -0
- package/std-pkg/src/stateful_token.lotus +131 -0
- package/std-pkg/src/upgradable.lotus +68 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// 2-of-3 Threshold Multisig (supports BIP-340 abstain via 64 zero-byte signature slots).
|
|
5
|
+
contract Multisig2of3<pk1: PublicKey, pk2: PublicKey, pk3: PublicKey> {
|
|
6
|
+
function spend(sig1: Signature, sig2: Signature, sig3: Signature) {
|
|
7
|
+
valid = 0;
|
|
8
|
+
if checksig(sig1, pk1) { valid += 1; }
|
|
9
|
+
if checksig(sig2, pk2) { valid += 1; }
|
|
10
|
+
if checksig(sig3, pk3) { valid += 1; }
|
|
11
|
+
require(valid >= 2);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Vault with Guardian Recovery: owner spends immediately; guardian recovers after absolute lock height.
|
|
5
|
+
contract VaultWithRecovery<owner: PublicKey, guardian: PublicKey, recovery_height: Int> {
|
|
6
|
+
function spend(owner_sig: Signature) {
|
|
7
|
+
require(checksig(owner_sig, owner));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function recover(guardian_sig: Signature) {
|
|
11
|
+
require(check_lock(1, recovery_height));
|
|
12
|
+
require(checksig(guardian_sig, guardian));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Constant-Product AMM Controller using separate-branch STATEHASH commitment (branch 1),
|
|
5
|
+
// MUL128_WIDE (full 256-bit constant-product invariant — no < 2^50 reserve cap), and SQRT
|
|
6
|
+
// for LP share minting. Binds reserve asset custody via reserve_branch and zero admin keys.
|
|
7
|
+
contract AmmPoolV2<
|
|
8
|
+
token0: TokenId,
|
|
9
|
+
token1: TokenId,
|
|
10
|
+
reserve_branch: ContractRootHash,
|
|
11
|
+
fee_bps: Int,
|
|
12
|
+
min_liquidity: Amount
|
|
13
|
+
> {
|
|
14
|
+
function first_deposit(x: Amount, y: Amount) {
|
|
15
|
+
require(fee_bps >= 0 && fee_bps < 10000);
|
|
16
|
+
require(x > 0 && y > 0);
|
|
17
|
+
require(this.coin.branch_count() == 2);
|
|
18
|
+
require(this.coin.branch(1) == state_hash(num2bin(0, 16), num2bin(0, 16), num2bin(0, 16)));
|
|
19
|
+
lp = sqrt(x * y) - min_liquidity;
|
|
20
|
+
require(lp > 0);
|
|
21
|
+
seen_in = 0;
|
|
22
|
+
for inp in tx.inputs {
|
|
23
|
+
if inp.is_spend && inp.requires_branch(this.root) { seen_in += 1; }
|
|
24
|
+
}
|
|
25
|
+
require(seen_in == 1);
|
|
26
|
+
continued = 0;
|
|
27
|
+
r0_out = 0;
|
|
28
|
+
r1_out = 0;
|
|
29
|
+
for out in tx.outputs {
|
|
30
|
+
if out.flags == this.coin.flags &&
|
|
31
|
+
out.value == this.coin.value &&
|
|
32
|
+
out.continues_branch(this.root) &&
|
|
33
|
+
out.branch_count() == 2 &&
|
|
34
|
+
out.branch(1) == state_hash(num2bin(x, 16), num2bin(y, 16), num2bin(lp + min_liquidity, 16)) {
|
|
35
|
+
continued += 1;
|
|
36
|
+
}
|
|
37
|
+
if out.token_id == token0 && out.exclusive_branch(reserve_branch) && out.value == x {
|
|
38
|
+
r0_out += 1;
|
|
39
|
+
}
|
|
40
|
+
if out.token_id == token1 && out.exclusive_branch(reserve_branch) && out.value == y {
|
|
41
|
+
r1_out += 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
require(continued == 1 && r0_out == 1 && r1_out == 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function swap_0_for_1(old_x: Amount, old_y: Amount, total_lp: Amount, dx: Amount, dy: Amount, min_out: Amount) {
|
|
48
|
+
require(fee_bps >= 0 && fee_bps < 10000);
|
|
49
|
+
require(old_x > 0 && old_y > 0 && total_lp > 0);
|
|
50
|
+
require(dx > 0 && dy > 0 && dy >= min_out && dy < old_y);
|
|
51
|
+
require(this.coin.branch_count() == 2);
|
|
52
|
+
require(this.coin.branch(1) == state_hash(num2bin(old_x, 16), num2bin(old_y, 16), num2bin(total_lp, 16)));
|
|
53
|
+
next_x = old_x + dx;
|
|
54
|
+
next_y = old_y - dy;
|
|
55
|
+
let (lhs_hi, lhs_lo) = mul128_wide(next_x * 10000 - dx * fee_bps, next_y * 10000);
|
|
56
|
+
let (rhs_hi, rhs_lo) = mul128_wide(old_x * 10000, old_y * 10000);
|
|
57
|
+
let (min_hi, max_hi) = less_swap(lhs_hi, rhs_hi);
|
|
58
|
+
let (min_lo, max_lo) = less_swap(lhs_lo, rhs_lo);
|
|
59
|
+
require(
|
|
60
|
+
(lhs_hi != rhs_hi && max_hi == lhs_hi) ||
|
|
61
|
+
(lhs_hi == rhs_hi && (lhs_lo == rhs_lo || max_lo == lhs_lo))
|
|
62
|
+
);
|
|
63
|
+
require(size(min_hi) == 16 && size(min_lo) == 16);
|
|
64
|
+
seen_in = 0;
|
|
65
|
+
r0_in = 0;
|
|
66
|
+
r1_in = 0;
|
|
67
|
+
for inp in tx.inputs {
|
|
68
|
+
if inp.is_spend && inp.requires_branch(this.root) { seen_in += 1; }
|
|
69
|
+
if inp.is_spend && inp.coin.token_id == token0 && inp.requires_branch(reserve_branch) && inp.coin.value == old_x {
|
|
70
|
+
r0_in += 1;
|
|
71
|
+
}
|
|
72
|
+
if inp.is_spend && inp.coin.token_id == token1 && inp.requires_branch(reserve_branch) && inp.coin.value == old_y {
|
|
73
|
+
r1_in += 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
require(seen_in == 1 && r0_in == 1 && r1_in == 1);
|
|
77
|
+
continued = 0;
|
|
78
|
+
r0_out = 0;
|
|
79
|
+
r1_out = 0;
|
|
80
|
+
for out in tx.outputs {
|
|
81
|
+
if out.flags == this.coin.flags &&
|
|
82
|
+
out.value == this.coin.value &&
|
|
83
|
+
out.continues_branch(this.root) &&
|
|
84
|
+
out.branch_count() == 2 &&
|
|
85
|
+
out.branch(1) == state_hash(num2bin(next_x, 16), num2bin(next_y, 16), num2bin(total_lp, 16)) {
|
|
86
|
+
continued += 1;
|
|
87
|
+
}
|
|
88
|
+
if out.token_id == token0 && out.exclusive_branch(reserve_branch) && out.value == next_x {
|
|
89
|
+
r0_out += 1;
|
|
90
|
+
}
|
|
91
|
+
if out.token_id == token1 && out.exclusive_branch(reserve_branch) && out.value == next_y {
|
|
92
|
+
r1_out += 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
require(continued == 1 && r0_out == 1 && r1_out == 1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// 0x-Style Partial-Fill Limit Order with Pratt-indexed injective payouts:
|
|
5
|
+
// For order input at index i: outputs[2*i] = maker payout (exclusive_branch),
|
|
6
|
+
// outputs[2*i+1] = order remainder (continues_branch).
|
|
7
|
+
// Enforces anti-dust atomic remainder rule: fill > 0 && fill >= min_fill && (rem == 0 || rem >= min_fill).
|
|
8
|
+
contract IndexedLimitOrder<
|
|
9
|
+
maker: PublicKey,
|
|
10
|
+
maker_payout: ContractRootHash,
|
|
11
|
+
quote_token: TokenId,
|
|
12
|
+
price_num: Int,
|
|
13
|
+
price_den: Int,
|
|
14
|
+
min_fill: Amount
|
|
15
|
+
> {
|
|
16
|
+
function fill(fill_amount: Amount, payout_idx: Int, remainder_idx: Int) {
|
|
17
|
+
require(price_num > 0 && price_den > 0);
|
|
18
|
+
require(fill_amount > 0 && fill_amount >= min_fill);
|
|
19
|
+
require(fill_amount <= this.coin.value);
|
|
20
|
+
rem = this.coin.value - fill_amount;
|
|
21
|
+
require(rem <= 0 || rem >= min_fill);
|
|
22
|
+
require(payout_idx == 2 * this.input_index);
|
|
23
|
+
require(remainder_idx == 2 * this.input_index + 1);
|
|
24
|
+
require(tx.outputs[payout_idx].token_id == quote_token);
|
|
25
|
+
require(tx.outputs[payout_idx].exclusive_branch(maker_payout));
|
|
26
|
+
require(tx.outputs[payout_idx].value * price_den >= fill_amount * price_num);
|
|
27
|
+
if rem > 0 {
|
|
28
|
+
require(tx.outputs[remainder_idx].token_id == this.coin.token_id);
|
|
29
|
+
require(tx.outputs[remainder_idx].value == rem);
|
|
30
|
+
require(tx.outputs[remainder_idx].continues_branch(this.root));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function cancel(maker_sig: Signature) {
|
|
35
|
+
require(checksig(maker_sig, maker));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// NFT Collection: bounded collection authority tracking minted serials via separate-branch
|
|
5
|
+
// STATEHASH commitment (branch 1), paired with a collection token mint enforcing value == 1.
|
|
6
|
+
contract NFTCollectionAuthority<creator: PublicKey, collection_token: TokenId, max_items: Int> {
|
|
7
|
+
function mint_next(sig: Signature, prev_count: Int) {
|
|
8
|
+
require(checksig(sig, creator));
|
|
9
|
+
require(prev_count >= 0);
|
|
10
|
+
next_count = prev_count + 1;
|
|
11
|
+
require(next_count <= max_items);
|
|
12
|
+
require(this.coin.branch_count() == 2);
|
|
13
|
+
require(this.coin.branch(1) == state_hash(num2bin(prev_count, 16)));
|
|
14
|
+
let (tin, tout) = tx_token_balance(collection_token);
|
|
15
|
+
require(tout - tin >= 1 && tout - tin <= 1);
|
|
16
|
+
seen_in = 0;
|
|
17
|
+
for inp in tx.inputs {
|
|
18
|
+
if inp.is_spend && inp.requires_branch(this.root) { seen_in += 1; }
|
|
19
|
+
}
|
|
20
|
+
require(seen_in == 1);
|
|
21
|
+
continued = 0;
|
|
22
|
+
for out in tx.outputs {
|
|
23
|
+
if out.flags == this.coin.flags &&
|
|
24
|
+
out.value == this.coin.value &&
|
|
25
|
+
out.continues_branch(this.root) &&
|
|
26
|
+
out.branch_count() == 2 &&
|
|
27
|
+
out.branch(1) == state_hash(num2bin(next_count, 16)) {
|
|
28
|
+
continued += 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
require(continued == 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
token NFTCollectionMint<authority: ContractRootHash, transfer_rules: ContractRootHash> {
|
|
36
|
+
function mint_item(amount: Amount) {
|
|
37
|
+
require(amount >= 1 && amount <= 1);
|
|
38
|
+
auth = 0;
|
|
39
|
+
for inp in tx.inputs {
|
|
40
|
+
if inp.is_spend && inp.requires_branch(authority) { auth += 1; }
|
|
41
|
+
}
|
|
42
|
+
require(auth == 1);
|
|
43
|
+
for out in tx.outputs {
|
|
44
|
+
if out.token_id == this.root {
|
|
45
|
+
require(out.value >= 1 && out.value <= 1);
|
|
46
|
+
require(out.requires_branch(transfer_rules));
|
|
47
|
+
require(!out.exclusive_branch(transfer_rules));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Royalty-Bearing Transfer Rules (distinct from StandardTransferRules so wallets badge it accurately).
|
|
5
|
+
// Requires exclusive_branch(creator_wallet) native XPI royalty scaled by the number of royalty-bearing
|
|
6
|
+
// inputs in the transaction (preventing both ransom-lock and multi-input batching bypasses).
|
|
7
|
+
contract RoyaltyTransferRules<creator: PublicKey, creator_wallet: ContractRootHash, min_royalty_xpi: Amount> {
|
|
8
|
+
function transfer_with_royalty() {
|
|
9
|
+
same_in = 0;
|
|
10
|
+
for inp in tx.inputs {
|
|
11
|
+
if inp.is_spend && inp.coin.token_id == this.coin.token_id && inp.requires_branch(this.root) {
|
|
12
|
+
same_in += 1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
require(same_in >= 1);
|
|
16
|
+
royalty_paid = 0;
|
|
17
|
+
for out in tx.outputs {
|
|
18
|
+
if out.token_id == this.coin.token_id {
|
|
19
|
+
require(out.requires_branch(this.root));
|
|
20
|
+
require(!out.exclusive_branch(this.root));
|
|
21
|
+
}
|
|
22
|
+
if out.flags == 0 && out.exclusive_branch(creator_wallet) {
|
|
23
|
+
royalty_paid += out.value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
require(royalty_paid >= same_in * min_royalty_xpi);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function creator_exempt_transfer(creator_sig: Signature) {
|
|
30
|
+
require(checksig(creator_sig, creator));
|
|
31
|
+
for out in tx.outputs {
|
|
32
|
+
if out.token_id == this.coin.token_id {
|
|
33
|
+
require(out.requires_branch(this.root));
|
|
34
|
+
require(!out.exclusive_branch(this.root));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Unique 1-of-1 NFT: singleton value == 1 genesis mint bound to a unique creator seed outpoint
|
|
5
|
+
// and an immutable metadata commitment hash (anchored alongside an IS_BURN metadata output).
|
|
6
|
+
token UniqueNFT<
|
|
7
|
+
seed_txid: Bytes32,
|
|
8
|
+
seed_vout: Int,
|
|
9
|
+
metadata_hash: Bytes32,
|
|
10
|
+
transfer_rules: ContractRootHash
|
|
11
|
+
> {
|
|
12
|
+
function mint(amount: Amount, commitment: Bytes32) {
|
|
13
|
+
require(amount >= 1 && amount <= 1);
|
|
14
|
+
require(commitment == metadata_hash);
|
|
15
|
+
seed_spent = 0;
|
|
16
|
+
for inp in tx.inputs {
|
|
17
|
+
if inp.is_spend && inp.txid == seed_txid && inp.vout == seed_vout {
|
|
18
|
+
seed_spent += 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
require(seed_spent == 1);
|
|
22
|
+
for out in tx.outputs {
|
|
23
|
+
if out.token_id == this.root {
|
|
24
|
+
require(out.value >= 1 && out.value <= 1);
|
|
25
|
+
require(out.requires_branch(transfer_rules));
|
|
26
|
+
require(!out.exclusive_branch(transfer_rules));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Capped-Supply Fungible Token using separate-branch STATEHASH commitment (branch 1)
|
|
5
|
+
// for supply tracking + irreversible lock_mint. Binds token_id via TXTOKENBALANCE so
|
|
6
|
+
// minted delta cannot exceed authorized delta and lock_mint cannot mint new supply.
|
|
7
|
+
contract SupplyController<issuer: PublicKey, token_id: TokenId, max_supply: Amount> {
|
|
8
|
+
function mint(sig: Signature, prev_issued: Amount, delta: Amount) {
|
|
9
|
+
require(checksig(sig, issuer));
|
|
10
|
+
require(delta > 0);
|
|
11
|
+
require(prev_issued >= 0);
|
|
12
|
+
next_issued = prev_issued + delta;
|
|
13
|
+
require(next_issued <= max_supply);
|
|
14
|
+
require(this.coin.branch_count() == 2);
|
|
15
|
+
require(this.coin.branch(1) == state_hash(num2bin(prev_issued, 16), num2bin(0, 16)));
|
|
16
|
+
let (tin, tout) = tx_token_balance(token_id);
|
|
17
|
+
require(tout - tin == delta);
|
|
18
|
+
seen_in = 0;
|
|
19
|
+
for inp in tx.inputs {
|
|
20
|
+
if inp.is_spend && inp.requires_branch(this.root) { seen_in += 1; }
|
|
21
|
+
}
|
|
22
|
+
require(seen_in == 1);
|
|
23
|
+
continued = 0;
|
|
24
|
+
for out in tx.outputs {
|
|
25
|
+
if out.flags == this.coin.flags &&
|
|
26
|
+
out.value == this.coin.value &&
|
|
27
|
+
out.continues_branch(this.root) &&
|
|
28
|
+
out.branch_count() == 2 &&
|
|
29
|
+
out.branch(1) == state_hash(num2bin(next_issued, 16), num2bin(0, 16)) {
|
|
30
|
+
continued += 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
require(continued == 1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function lock_mint(sig: Signature, prev_issued: Amount) {
|
|
37
|
+
require(checksig(sig, issuer));
|
|
38
|
+
require(this.coin.branch_count() == 2);
|
|
39
|
+
require(this.coin.branch(1) == state_hash(num2bin(prev_issued, 16), num2bin(0, 16)));
|
|
40
|
+
let (tin, tout) = tx_token_balance(token_id);
|
|
41
|
+
require(tout <= tin);
|
|
42
|
+
seen_in = 0;
|
|
43
|
+
for inp in tx.inputs {
|
|
44
|
+
if inp.is_spend && inp.requires_branch(this.root) { seen_in += 1; }
|
|
45
|
+
}
|
|
46
|
+
require(seen_in == 1);
|
|
47
|
+
continued = 0;
|
|
48
|
+
for out in tx.outputs {
|
|
49
|
+
if out.flags == this.coin.flags &&
|
|
50
|
+
out.value == this.coin.value &&
|
|
51
|
+
out.continues_branch(this.root) &&
|
|
52
|
+
out.branch_count() == 2 &&
|
|
53
|
+
out.branch(1) == state_hash(num2bin(prev_issued, 16), num2bin(1, 16)) {
|
|
54
|
+
continued += 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
require(continued == 1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
token CappedSupplyToken<controller: ContractRootHash, transfer_rules: ContractRootHash> {
|
|
62
|
+
function issue(amount: Amount) {
|
|
63
|
+
require(amount > 0);
|
|
64
|
+
auth = 0;
|
|
65
|
+
for inp in tx.inputs {
|
|
66
|
+
if inp.is_spend && inp.requires_branch(controller) { auth += 1; }
|
|
67
|
+
}
|
|
68
|
+
require(auth == 1);
|
|
69
|
+
for out in tx.outputs {
|
|
70
|
+
if out.token_id == this.root {
|
|
71
|
+
require(out.requires_branch(transfer_rules));
|
|
72
|
+
require(!out.exclusive_branch(transfer_rules));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Fixed-Supply Fungible Token: one-shot genesis mint bound to a unique creator seed outpoint.
|
|
5
|
+
// Because (seed_txid, seed_vout) can only be spent once in UTXO consensus, future minting is
|
|
6
|
+
// permanently impossible without needing a separate revocation transaction.
|
|
7
|
+
token FixedSupplyToken<
|
|
8
|
+
seed_txid: Bytes32,
|
|
9
|
+
seed_vout: Int,
|
|
10
|
+
total_supply: Amount,
|
|
11
|
+
transfer_rules: ContractRootHash
|
|
12
|
+
> {
|
|
13
|
+
function issue(amount: Amount) {
|
|
14
|
+
require(amount == total_supply);
|
|
15
|
+
seed_spent = 0;
|
|
16
|
+
for inp in tx.inputs {
|
|
17
|
+
if inp.is_spend && inp.txid == seed_txid && inp.vout == seed_vout {
|
|
18
|
+
seed_spent += 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
require(seed_spent == 1);
|
|
22
|
+
for out in tx.outputs {
|
|
23
|
+
if out.token_id == this.root {
|
|
24
|
+
require(out.requires_branch(transfer_rules));
|
|
25
|
+
require(!out.exclusive_branch(transfer_rules));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
pragma edition "2026.2";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Lotus Standard Fungible Token (LRC-20) with immutable BLAKE3 metadata commitment.
|
|
5
|
+
//
|
|
6
|
+
// `metadata_hash` commits the canonical `lotus/token-metadata/1` JSON manifest
|
|
7
|
+
// directly into the `token_id` (the MAST root of this mint tree).
|
|
8
|
+
// `transfer_rules` defaults to `UNIVERSAL_STANDARD_TRANSFER_RULES_ROOT` for
|
|
9
|
+
// unrestricted fungible tokens, or any custom/upgradable rules BranchRoot.
|
|
10
|
+
|
|
11
|
+
token MetadataFungibleToken<
|
|
12
|
+
issuer: PublicKey,
|
|
13
|
+
metadata_hash: Bytes32,
|
|
14
|
+
transfer_rules: BranchRoot
|
|
15
|
+
> {
|
|
16
|
+
function issue(amount: Amount, commitment: Bytes32, signature: Signature) {
|
|
17
|
+
require(checksig(signature, issuer));
|
|
18
|
+
require(commitment == metadata_hash);
|
|
19
|
+
for output in tx.outputs {
|
|
20
|
+
if output.token_id == this.root {
|
|
21
|
+
require(output.requires_branch(transfer_rules));
|
|
22
|
+
require(!output.exclusive_branch(transfer_rules));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v1";
|
|
3
|
+
|
|
4
|
+
// Lotus V2 Canonical Standard Transfer Rules (zero-parameter, zero-freeze, zero-tax).
|
|
5
|
+
// Universal BranchRoot: 985e7562c70c1577cd7acdd208c0dfa36683860e0ed1931ed77574866389dbdc
|
|
6
|
+
contract StandardTransferRules {
|
|
7
|
+
function transfer() {
|
|
8
|
+
for output in tx.outputs {
|
|
9
|
+
if output.token_id == this.coin.token_id {
|
|
10
|
+
require(output.requires_branch(this.root));
|
|
11
|
+
require(!output.exclusive_branch(this.root));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
pragma edition "2026.2";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Stateful fungible token supporting transfer, 1-to-2 split, and 2-to-1 UTXO merge
|
|
5
|
+
// while conserving per-UTXO TokenState { weight, min_lock_height }.
|
|
6
|
+
|
|
7
|
+
state inline TokenState {
|
|
8
|
+
weight: Int,
|
|
9
|
+
min_lock_height: Int,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
contract StatefulTokenRules {
|
|
13
|
+
function transfer(weight: Int, lock_h: Int) {
|
|
14
|
+
require(weight >= 0);
|
|
15
|
+
require(lock_h >= 0);
|
|
16
|
+
require(TokenState.verify(weight, lock_h));
|
|
17
|
+
|
|
18
|
+
in_count = 0;
|
|
19
|
+
for input in tx.inputs {
|
|
20
|
+
if input.is_spend && input.coin.token_id == this.coin.token_id {
|
|
21
|
+
in_count += 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
require(in_count == 1);
|
|
25
|
+
|
|
26
|
+
out_count = 0;
|
|
27
|
+
for output in tx.outputs {
|
|
28
|
+
if output.token_id == this.coin.token_id {
|
|
29
|
+
out_count += 1;
|
|
30
|
+
require(output.value == this.coin.value);
|
|
31
|
+
require(output.requires_branch(this.root));
|
|
32
|
+
require(!output.exclusive_branch(this.root));
|
|
33
|
+
require(TokenState.matches(output, weight, lock_h));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
require(out_count == 1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function split(weight_in: Int, weight_0: Int, weight_1: Int, lock_h: Int) {
|
|
40
|
+
require(weight_0 >= 0);
|
|
41
|
+
require(weight_1 >= 0);
|
|
42
|
+
require(weight_0 + weight_1 == weight_in);
|
|
43
|
+
require(lock_h >= 0);
|
|
44
|
+
require(TokenState.verify(weight_in, lock_h));
|
|
45
|
+
|
|
46
|
+
in_count = 0;
|
|
47
|
+
for input in tx.inputs {
|
|
48
|
+
if input.is_spend && input.coin.token_id == this.coin.token_id {
|
|
49
|
+
in_count += 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
require(in_count == 1);
|
|
53
|
+
|
|
54
|
+
out_count = 0;
|
|
55
|
+
out_value = 0;
|
|
56
|
+
for output in tx.outputs {
|
|
57
|
+
if output.token_id == this.coin.token_id {
|
|
58
|
+
require(output.requires_branch(this.root));
|
|
59
|
+
require(!output.exclusive_branch(this.root));
|
|
60
|
+
out_value += output.value;
|
|
61
|
+
if out_count == 0 {
|
|
62
|
+
require(TokenState.matches(output, weight_0, lock_h));
|
|
63
|
+
} else {
|
|
64
|
+
require(TokenState.matches(output, weight_1, lock_h));
|
|
65
|
+
}
|
|
66
|
+
out_count += 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
require(out_count == 2);
|
|
70
|
+
require(out_value == this.coin.value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function merge(weight_a: Int, lock_a: Int, weight_b: Int, lock_b: Int) {
|
|
74
|
+
require(weight_a >= 0);
|
|
75
|
+
require(weight_b >= 0);
|
|
76
|
+
require(lock_a >= 0);
|
|
77
|
+
require(lock_b >= 0);
|
|
78
|
+
|
|
79
|
+
in_count = 0;
|
|
80
|
+
total_value = 0;
|
|
81
|
+
for input in tx.inputs {
|
|
82
|
+
if input.is_spend && input.coin.token_id == this.coin.token_id {
|
|
83
|
+
require(input.coin.requires_branch(this.root));
|
|
84
|
+
if in_count == 0 {
|
|
85
|
+
require(input.coin.state_root == TokenState.hash(weight_a, lock_a));
|
|
86
|
+
} else {
|
|
87
|
+
require(input.coin.state_root == TokenState.hash(weight_b, lock_b));
|
|
88
|
+
}
|
|
89
|
+
total_value += input.coin.value;
|
|
90
|
+
in_count += 1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
require(in_count == 2);
|
|
94
|
+
|
|
95
|
+
merged_lock = lock_a;
|
|
96
|
+
if lock_b > lock_a {
|
|
97
|
+
merged_lock = lock_b;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
out_count = 0;
|
|
101
|
+
for output in tx.outputs {
|
|
102
|
+
if output.token_id == this.coin.token_id {
|
|
103
|
+
out_count += 1;
|
|
104
|
+
require(output.value == total_value);
|
|
105
|
+
require(output.requires_branch(this.root));
|
|
106
|
+
require(!output.exclusive_branch(this.root));
|
|
107
|
+
require(TokenState.matches(output, weight_a + weight_b, merged_lock));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
require(out_count == 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
token StatefulToken<issuer: PublicKey> {
|
|
115
|
+
function issue(amount: Amount, init_weight: Int, init_lock: Int, signature: Signature) {
|
|
116
|
+
require(checksig(signature, issuer));
|
|
117
|
+
require(init_weight >= 0);
|
|
118
|
+
require(init_lock >= 0);
|
|
119
|
+
|
|
120
|
+
out_count = 0;
|
|
121
|
+
for output in tx.outputs {
|
|
122
|
+
if output.token_id == this.root {
|
|
123
|
+
out_count += 1;
|
|
124
|
+
require(output.value == amount);
|
|
125
|
+
require(output.requires_branch(contract_root(StatefulTokenRules)));
|
|
126
|
+
require(!output.exclusive_branch(contract_root(StatefulTokenRules)));
|
|
127
|
+
require(TokenState.matches(output, init_weight, init_lock));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
require(out_count == 1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
pragma edition "2026.2";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// In-place token contract upgrade keeping the exact same token_id.
|
|
5
|
+
// Governance publishes one reusable checkdatasig attestation over
|
|
6
|
+
// blake3(token_id || new_rules || upgrade_version).
|
|
7
|
+
|
|
8
|
+
contract UpgradableRules<governance: PublicKey> {
|
|
9
|
+
function transfer() {
|
|
10
|
+
for output in tx.outputs {
|
|
11
|
+
if output.token_id == this.coin.token_id {
|
|
12
|
+
require(output.requires_branch(this.root));
|
|
13
|
+
require(!output.exclusive_branch(this.root));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function upgrade_contract(
|
|
19
|
+
new_rules: ContractRootHash,
|
|
20
|
+
upgrade_version: Int,
|
|
21
|
+
gov_sig: Signature
|
|
22
|
+
) {
|
|
23
|
+
require(upgrade_version > 0);
|
|
24
|
+
require(new_rules != this.root);
|
|
25
|
+
|
|
26
|
+
require(
|
|
27
|
+
checkdatasig(
|
|
28
|
+
gov_sig,
|
|
29
|
+
blake3(
|
|
30
|
+
cat(
|
|
31
|
+
bytes32(this.coin.token_id),
|
|
32
|
+
cat(bytes32(new_rules), num2bin(upgrade_version, 8))
|
|
33
|
+
)
|
|
34
|
+
),
|
|
35
|
+
governance,
|
|
36
|
+
0
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
in_total = 0;
|
|
41
|
+
for input in tx.inputs {
|
|
42
|
+
if input.is_spend && input.coin.token_id == this.coin.token_id {
|
|
43
|
+
require(input.coin.requires_branch(this.root));
|
|
44
|
+
in_total += input.coin.value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
out_total = 0;
|
|
49
|
+
for output in tx.outputs {
|
|
50
|
+
if output.token_id == this.coin.token_id {
|
|
51
|
+
require(output.requires_branch(new_rules));
|
|
52
|
+
require(!output.exclusive_branch(new_rules));
|
|
53
|
+
out_total += output.value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
require(out_total == in_total);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
token UpgradableToken<issuer: PublicKey, initial_rules: ContractRootHash> {
|
|
61
|
+
function issue(amount: Amount, signature: Signature) {
|
|
62
|
+
require(checksig(signature, issuer));
|
|
63
|
+
for output in tx.outputs {
|
|
64
|
+
if output.token_id == this.root {
|
|
65
|
+
require(output.requires_branch(initial_rules));
|
|
66
|
+
require(!output.exclusive_branch(initial_rules));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
pragma edition "2026.1";
|
|
2
|
+
pragma optimizer "v2";
|
|
3
|
+
|
|
4
|
+
// Outpoint-Bound Signed Voucher Mint Token:
|
|
5
|
+
// Issuer signs (chain_id, token_id, bound_txid, bound_vout, amount) off-chain; user mints
|
|
6
|
+
// directly without global state contention. Single-use is enforced by UTXO consensus on
|
|
7
|
+
// (bound_txid, bound_vout) and domain-separated across networks via tx.chain_id.
|
|
8
|
+
token VoucherMintToken<issuer: PublicKey, transfer_rules: ContractRootHash> {
|
|
9
|
+
function mint_with_voucher(amount: Amount, voucher_sig: Signature, bound_txid: Bytes32, bound_vout: Int) {
|
|
10
|
+
require(amount > 0);
|
|
11
|
+
found = 0;
|
|
12
|
+
for inp in tx.inputs {
|
|
13
|
+
if inp.is_spend && inp.txid == bound_txid && inp.vout == bound_vout {
|
|
14
|
+
found += 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
require(found == 1);
|
|
18
|
+
require(checkdatasig(
|
|
19
|
+
voucher_sig,
|
|
20
|
+
blake3(cat(cat(tx.chain_id, this.root), cat(bound_txid, cat(num2bin(bound_vout, 16), num2bin(amount, 16))))),
|
|
21
|
+
issuer,
|
|
22
|
+
0
|
|
23
|
+
));
|
|
24
|
+
for out in tx.outputs {
|
|
25
|
+
if out.token_id == this.root {
|
|
26
|
+
require(out.requires_branch(transfer_rules));
|
|
27
|
+
require(!out.exclusive_branch(transfer_rules));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|