@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.
Files changed (98) hide show
  1. package/README.md +331 -2
  2. package/artifact-v2.schema.json +58 -0
  3. package/artifact.schema.json +19 -0
  4. package/dist/ast.d.ts +292 -0
  5. package/dist/ast.js +150 -0
  6. package/dist/bindings.d.ts +6 -0
  7. package/dist/bindings.js +134 -0
  8. package/dist/call-runtime.d.ts +84 -0
  9. package/dist/call-runtime.js +249 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +22 -0
  12. package/dist/compiler.d.ts +79 -0
  13. package/dist/compiler.js +125 -0
  14. package/dist/diagnostics.d.ts +163 -0
  15. package/dist/diagnostics.js +498 -0
  16. package/dist/ecash.d.ts +41 -0
  17. package/dist/ecash.js +190 -0
  18. package/dist/fees.d.ts +164 -0
  19. package/dist/fees.js +208 -0
  20. package/dist/fixture-cli.d.ts +2 -0
  21. package/dist/fixture-cli.js +41 -0
  22. package/dist/fixtures.d.ts +68 -0
  23. package/dist/fixtures.js +46 -0
  24. package/dist/forth-ir.d.ts +73 -0
  25. package/dist/forth-ir.js +147 -0
  26. package/dist/generic-cli.d.ts +2 -0
  27. package/dist/generic-cli.js +140 -0
  28. package/dist/generic.d.ts +48 -0
  29. package/dist/generic.js +2566 -0
  30. package/dist/lints.d.ts +8 -0
  31. package/dist/lints.js +204 -0
  32. package/dist/names.d.ts +1 -0
  33. package/dist/names.js +7 -0
  34. package/dist/opcodes.d.ts +154 -0
  35. package/dist/opcodes.js +162 -0
  36. package/dist/optimizer.d.ts +58 -0
  37. package/dist/optimizer.js +786 -0
  38. package/dist/package-fetch-cli.d.ts +2 -0
  39. package/dist/package-fetch-cli.js +17 -0
  40. package/dist/package-lock-cli.d.ts +2 -0
  41. package/dist/package-lock-cli.js +28 -0
  42. package/dist/package-sources.d.ts +82 -0
  43. package/dist/package-sources.js +785 -0
  44. package/dist/package-update-cli.d.ts +2 -0
  45. package/dist/package-update-cli.js +20 -0
  46. package/dist/packages.d.ts +231 -0
  47. package/dist/packages.js +1324 -0
  48. package/dist/parser.d.ts +32 -0
  49. package/dist/parser.js +575 -0
  50. package/dist/policy.d.ts +83 -0
  51. package/dist/policy.js +207 -0
  52. package/dist/runtime.d.ts +58 -0
  53. package/dist/runtime.js +126 -0
  54. package/dist/scheduler.d.ts +38 -0
  55. package/dist/scheduler.js +76 -0
  56. package/dist/semantic-ir.d.ts +76 -0
  57. package/dist/semantic-ir.js +231 -0
  58. package/dist/std.d.ts +27 -0
  59. package/dist/std.js +282 -0
  60. package/dist/target-compiler.d.ts +9 -0
  61. package/dist/target-compiler.js +139 -0
  62. package/dist/targets.d.ts +53 -0
  63. package/dist/targets.js +67 -0
  64. package/dist/token-cli.d.ts +2 -0
  65. package/dist/token-cli.js +82 -0
  66. package/dist/token-metadata.d.ts +43 -0
  67. package/dist/token-metadata.js +166 -0
  68. package/dist/toml-subset.d.ts +19 -0
  69. package/dist/toml-subset.js +81 -0
  70. package/dist/transaction-runtime.d.ts +182 -0
  71. package/dist/transaction-runtime.js +646 -0
  72. package/dist/version.d.ts +3 -0
  73. package/dist/version.js +3 -0
  74. package/dist/vm-cost.d.ts +11 -0
  75. package/dist/vm-cost.js +541 -0
  76. package/package.json +74 -4
  77. package/policy-artifact.schema.json +20 -0
  78. package/std/custody/arbiter-escrow.lotus +20 -0
  79. package/std/custody/htlc.lotus +15 -0
  80. package/std/custody/multisig-2of3.lotus +13 -0
  81. package/std/custody/single-owner-wallet.lotus +9 -0
  82. package/std/custody/vault-with-recovery.lotus +14 -0
  83. package/std/defi/amm-pool-v2.lotus +97 -0
  84. package/std/defi/indexed-limit-order.lotus +37 -0
  85. package/std/nft/nft-collection.lotus +51 -0
  86. package/std/nft/royalty-transfer-rules.lotus +38 -0
  87. package/std/nft/unique-nft.lotus +30 -0
  88. package/std/tokens/capped-supply-token.lotus +76 -0
  89. package/std/tokens/fixed-supply-token.lotus +29 -0
  90. package/std/tokens/lrc20.lotus +26 -0
  91. package/std/tokens/standard-transfer-rules.lotus +15 -0
  92. package/std/tokens/stateful-token-merge.lotus +132 -0
  93. package/std/tokens/upgradable-token-rules.lotus +70 -0
  94. package/std/tokens/voucher-mint-token.lotus +31 -0
  95. package/std-pkg/lotus.toml +9 -0
  96. package/std-pkg/src/lrc20.lotus +38 -0
  97. package/std-pkg/src/stateful_token.lotus +131 -0
  98. package/std-pkg/src/upgradable.lotus +68 -0
@@ -0,0 +1,9 @@
1
+ [package]
2
+ name = "std"
3
+ version = "0.2.0"
4
+ kind = "library"
5
+ source = "src"
6
+ edition = "2026.2"
7
+ optimizer = "v2"
8
+ modules = ["lrc20", "stateful_token", "upgradable"]
9
+ exports = ["lrc20", "stateful_token", "upgradable"]
@@ -0,0 +1,38 @@
1
+ pragma edition "2026.2";
2
+ pragma optimizer "v2";
3
+
4
+ // Standard Lotus fungible token (LRC-20) templates.
5
+
6
+ export contract TokenWallet<owner: PublicKey> {
7
+ function spend(signature: Signature) {
8
+ require(checksig(signature, owner));
9
+ }
10
+ }
11
+
12
+ export contract StandardTransferRules {
13
+ function transfer() {
14
+ for output in tx.outputs {
15
+ if output.token_id == this.coin.token_id {
16
+ require(output.requires_branch(this.root));
17
+ require(!output.exclusive_branch(this.root));
18
+ }
19
+ }
20
+ }
21
+ }
22
+
23
+ export token MetadataFungibleToken<
24
+ issuer: PublicKey,
25
+ metadata_hash: Bytes32,
26
+ transfer_rules: BranchRoot
27
+ > {
28
+ function issue(amount: Amount, commitment: Bytes32, signature: Signature) {
29
+ require(checksig(signature, issuer));
30
+ require(commitment == metadata_hash);
31
+ for output in tx.outputs {
32
+ if output.token_id == this.root {
33
+ require(output.requires_branch(transfer_rules));
34
+ require(!output.exclusive_branch(transfer_rules));
35
+ }
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,131 @@
1
+ pragma edition "2026.2";
2
+ pragma optimizer "v2";
3
+
4
+ // Stateful fungible token with transfer, 1-to-2 split, and 2-to-1 UTXO merge.
5
+
6
+ state inline TokenState {
7
+ weight: Int,
8
+ min_lock_height: Int,
9
+ }
10
+
11
+ export contract StatefulTokenRules {
12
+ function transfer(weight: Int, lock_h: Int) {
13
+ require(weight >= 0);
14
+ require(lock_h >= 0);
15
+ require(TokenState.verify(weight, lock_h));
16
+
17
+ in_count = 0;
18
+ for input in tx.inputs {
19
+ if input.is_spend && input.coin.token_id == this.coin.token_id {
20
+ in_count += 1;
21
+ }
22
+ }
23
+ require(in_count == 1);
24
+
25
+ out_count = 0;
26
+ for output in tx.outputs {
27
+ if output.token_id == this.coin.token_id {
28
+ out_count += 1;
29
+ require(output.value == this.coin.value);
30
+ require(output.requires_branch(this.root));
31
+ require(!output.exclusive_branch(this.root));
32
+ require(TokenState.matches(output, weight, lock_h));
33
+ }
34
+ }
35
+ require(out_count == 1);
36
+ }
37
+
38
+ function split(weight_in: Int, weight_0: Int, weight_1: Int, lock_h: Int) {
39
+ require(weight_0 >= 0);
40
+ require(weight_1 >= 0);
41
+ require(weight_0 + weight_1 == weight_in);
42
+ require(lock_h >= 0);
43
+ require(TokenState.verify(weight_in, lock_h));
44
+
45
+ in_count = 0;
46
+ for input in tx.inputs {
47
+ if input.is_spend && input.coin.token_id == this.coin.token_id {
48
+ in_count += 1;
49
+ }
50
+ }
51
+ require(in_count == 1);
52
+
53
+ out_count = 0;
54
+ out_value = 0;
55
+ for output in tx.outputs {
56
+ if output.token_id == this.coin.token_id {
57
+ require(output.requires_branch(this.root));
58
+ require(!output.exclusive_branch(this.root));
59
+ out_value += output.value;
60
+ if out_count == 0 {
61
+ require(TokenState.matches(output, weight_0, lock_h));
62
+ } else {
63
+ require(TokenState.matches(output, weight_1, lock_h));
64
+ }
65
+ out_count += 1;
66
+ }
67
+ }
68
+ require(out_count == 2);
69
+ require(out_value == this.coin.value);
70
+ }
71
+
72
+ function merge(weight_a: Int, lock_a: Int, weight_b: Int, lock_b: Int) {
73
+ require(weight_a >= 0);
74
+ require(weight_b >= 0);
75
+ require(lock_a >= 0);
76
+ require(lock_b >= 0);
77
+
78
+ in_count = 0;
79
+ total_value = 0;
80
+ for input in tx.inputs {
81
+ if input.is_spend && input.coin.token_id == this.coin.token_id {
82
+ require(input.coin.requires_branch(this.root));
83
+ if in_count == 0 {
84
+ require(input.coin.state_root == TokenState.hash(weight_a, lock_a));
85
+ } else {
86
+ require(input.coin.state_root == TokenState.hash(weight_b, lock_b));
87
+ }
88
+ total_value += input.coin.value;
89
+ in_count += 1;
90
+ }
91
+ }
92
+ require(in_count == 2);
93
+
94
+ merged_lock = lock_a;
95
+ if lock_b > lock_a {
96
+ merged_lock = lock_b;
97
+ }
98
+
99
+ out_count = 0;
100
+ for output in tx.outputs {
101
+ if output.token_id == this.coin.token_id {
102
+ out_count += 1;
103
+ require(output.value == total_value);
104
+ require(output.requires_branch(this.root));
105
+ require(!output.exclusive_branch(this.root));
106
+ require(TokenState.matches(output, weight_a + weight_b, merged_lock));
107
+ }
108
+ }
109
+ require(out_count == 1);
110
+ }
111
+ }
112
+
113
+ export token StatefulToken<issuer: PublicKey> {
114
+ function issue(amount: Amount, init_weight: Int, init_lock: Int, signature: Signature) {
115
+ require(checksig(signature, issuer));
116
+ require(init_weight >= 0);
117
+ require(init_lock >= 0);
118
+
119
+ out_count = 0;
120
+ for output in tx.outputs {
121
+ if output.token_id == this.root {
122
+ out_count += 1;
123
+ require(output.value == amount);
124
+ require(output.requires_branch(contract_root(StatefulTokenRules)));
125
+ require(!output.exclusive_branch(contract_root(StatefulTokenRules)));
126
+ require(TokenState.matches(output, init_weight, init_lock));
127
+ }
128
+ }
129
+ require(out_count == 1);
130
+ }
131
+ }
@@ -0,0 +1,68 @@
1
+ pragma edition "2026.2";
2
+ pragma optimizer "v2";
3
+
4
+ // In-place token contract upgrade keeping the exact same token_id.
5
+
6
+ export contract UpgradableRules<governance: PublicKey> {
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
+
16
+ function upgrade_contract(
17
+ new_rules: ContractRootHash,
18
+ upgrade_version: Int,
19
+ gov_sig: Signature
20
+ ) {
21
+ require(upgrade_version > 0);
22
+ require(new_rules != this.root);
23
+
24
+ require(
25
+ checkdatasig(
26
+ gov_sig,
27
+ blake3(
28
+ cat(
29
+ bytes32(this.coin.token_id),
30
+ cat(bytes32(new_rules), num2bin(upgrade_version, 8))
31
+ )
32
+ ),
33
+ governance,
34
+ 0
35
+ )
36
+ );
37
+
38
+ in_total = 0;
39
+ for input in tx.inputs {
40
+ if input.is_spend && input.coin.token_id == this.coin.token_id {
41
+ require(input.coin.requires_branch(this.root));
42
+ in_total += input.coin.value;
43
+ }
44
+ }
45
+
46
+ out_total = 0;
47
+ for output in tx.outputs {
48
+ if output.token_id == this.coin.token_id {
49
+ require(output.requires_branch(new_rules));
50
+ require(!output.exclusive_branch(new_rules));
51
+ out_total += output.value;
52
+ }
53
+ }
54
+ require(out_total == in_total);
55
+ }
56
+ }
57
+
58
+ export token UpgradableToken<issuer: PublicKey, initial_rules: ContractRootHash> {
59
+ function issue(amount: Amount, signature: Signature) {
60
+ require(checksig(signature, issuer));
61
+ for output in tx.outputs {
62
+ if output.token_id == this.root {
63
+ require(output.requires_branch(initial_rules));
64
+ require(!output.exclusive_branch(initial_rules));
65
+ }
66
+ }
67
+ }
68
+ }