@btc-vision/btc-runtime 1.0.28 → 1.0.30

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 (43) hide show
  1. package/package.json +1 -1
  2. package/runtime/buffer/BytesReader.ts +200 -200
  3. package/runtime/buffer/BytesWriter.ts +346 -342
  4. package/runtime/contracts/OP_20.ts +341 -341
  5. package/runtime/contracts/OP_NET.ts +73 -73
  6. package/runtime/contracts/interfaces/IOP_20.ts +21 -21
  7. package/runtime/env/BTCEnvironment.ts +319 -314
  8. package/runtime/env/index.ts +3 -3
  9. package/runtime/events/NetEvent.ts +27 -27
  10. package/runtime/events/predefined/ApproveEvent.ts +16 -16
  11. package/runtime/events/predefined/BurnEvent.ts +13 -13
  12. package/runtime/events/predefined/ClaimEvent.ts +13 -13
  13. package/runtime/events/predefined/MintEvent.ts +15 -15
  14. package/runtime/events/predefined/StakeEvent.ts +13 -13
  15. package/runtime/events/predefined/TransferEvent.ts +16 -16
  16. package/runtime/events/predefined/UnstakeEvent.ts +13 -13
  17. package/runtime/events/predefined/index.ts +7 -7
  18. package/runtime/exports/index.ts +37 -37
  19. package/runtime/generic/Map.ts +65 -65
  20. package/runtime/generic/MapU256.ts +57 -57
  21. package/runtime/index.ts +53 -52
  22. package/runtime/interfaces/DeployContractResponse.ts +12 -12
  23. package/runtime/interfaces/IBTC.ts +6 -6
  24. package/runtime/lang/Definitions.ts +1 -1
  25. package/runtime/math/abi.ts +37 -37
  26. package/runtime/math/bytes.ts +34 -34
  27. package/runtime/math/cyrb53.ts +46 -46
  28. package/runtime/math/rnd.ts +51 -51
  29. package/runtime/math/sha256.ts +12 -12
  30. package/runtime/memory/AddressMemoryMap.ts +44 -44
  31. package/runtime/memory/KeyMerger.ts +53 -53
  32. package/runtime/memory/MemorySlot.ts +1 -1
  33. package/runtime/memory/MemorySlotPointer.ts +3 -3
  34. package/runtime/memory/MultiAddressMemoryMap.ts +62 -62
  35. package/runtime/shared-libraries/TransferHelper.ts +64 -64
  36. package/runtime/storage/Serializable.ts +75 -0
  37. package/runtime/storage/StoredString.ts +145 -145
  38. package/runtime/storage/StoredU256.ts +246 -246
  39. package/runtime/types/Address.ts +5 -5
  40. package/runtime/types/Revert.ts +5 -5
  41. package/runtime/types/SafeMath.ts +197 -197
  42. package/runtime/types/index.ts +8 -8
  43. package/runtime/universal/ABIRegistry.ts +72 -72
@@ -1,246 +1,246 @@
1
- import { u256 } from 'as-bignum/assembly';
2
- import { SafeMath } from '../types/SafeMath';
3
- import { MemorySlotPointer } from '../memory/MemorySlotPointer';
4
- import { Blockchain } from '../env';
5
-
6
- @final
7
- export class StoredU256 {
8
- constructor(
9
- public pointer: u16,
10
- public subPointer: MemorySlotPointer,
11
- private defaultValue: u256,
12
- ) {}
13
-
14
- private _value: u256 = u256.Zero;
15
-
16
- @inline
17
- public get value(): u256 {
18
- this.ensureValue();
19
-
20
- return this._value;
21
- }
22
-
23
- @inline
24
- public set value(value: u256) {
25
- this._value = value;
26
-
27
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
28
- }
29
-
30
- @inline
31
- public get toBytes(): Uint8Array {
32
- return this._value.toUint8Array(false);
33
- }
34
-
35
- @inline
36
- @operator('+')
37
- public add(value: u256): this {
38
- this.ensureValue();
39
-
40
- this._value = SafeMath.add(this._value, value);
41
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
42
-
43
- return this;
44
- }
45
-
46
- @inline
47
- @operator('-')
48
- public sub(value: u256): this {
49
- this.ensureValue();
50
-
51
- this._value = SafeMath.sub(this._value, value);
52
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
53
-
54
- return this;
55
- }
56
-
57
- @inline
58
- @operator('*')
59
- public mul(value: u256): this {
60
- this.ensureValue();
61
-
62
- this._value = SafeMath.mul(this._value, value);
63
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
64
-
65
- return this;
66
- }
67
-
68
- @inline
69
- @operator('==')
70
- public eq(value: u256): boolean {
71
- this.ensureValue();
72
-
73
- return this._value === value;
74
- }
75
-
76
- @inline
77
- @operator('!=')
78
- public ne(value: u256): boolean {
79
- this.ensureValue();
80
-
81
- return this._value !== value;
82
- }
83
-
84
- @inline
85
- @operator('<')
86
- public lt(value: u256): boolean {
87
- this.ensureValue();
88
-
89
- return this._value < value;
90
- }
91
-
92
- @inline
93
- @operator('>')
94
- public gt(value: u256): boolean {
95
- this.ensureValue();
96
-
97
- return this._value > value;
98
- }
99
-
100
- @inline
101
- @operator('<=')
102
- public le(value: u256): boolean {
103
- this.ensureValue();
104
-
105
- return this._value <= value;
106
- }
107
-
108
- @inline
109
- @operator('>=')
110
- public ge(value: u256): boolean {
111
- this.ensureValue();
112
-
113
- return this._value >= value;
114
- }
115
-
116
- @inline
117
- @operator('>>')
118
- public shr(value: i32): this {
119
- this.ensureValue();
120
-
121
- this._value = u256.shr(this._value, value);
122
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
123
-
124
- return this;
125
- }
126
-
127
- @inline
128
- @operator('&')
129
- public and(value: u256): this {
130
- this.ensureValue();
131
-
132
- this._value = u256.and(this._value, value);
133
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
134
-
135
- return this;
136
- }
137
-
138
- @inline
139
- @operator('|')
140
- public or(value: u256): this {
141
- this.ensureValue();
142
-
143
- this._value = u256.or(this._value, value);
144
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
145
-
146
- return this;
147
- }
148
-
149
- @inline
150
- @operator('^')
151
- public xor(value: u256): this {
152
- this.ensureValue();
153
-
154
- this._value = u256.xor(this._value, value);
155
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
156
-
157
- return this;
158
- }
159
-
160
- @inline
161
- @operator('**')
162
- public pow(value: u256): this {
163
- this.ensureValue();
164
-
165
- // code pow from scratch
166
- let result: u256 = u256.One;
167
-
168
- while (value > u256.Zero) {
169
- if (u256.and(value, u256.One)) {
170
- result = SafeMath.mul(result, this._value);
171
- }
172
-
173
- this._value = SafeMath.mul(this._value, this._value);
174
- value = u256.shr(value, 1);
175
- }
176
-
177
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
178
-
179
- return this;
180
- }
181
-
182
- @inline
183
- @operator('%')
184
- public mod(value: u256): this {
185
- this.ensureValue();
186
-
187
- // code mod from scratch
188
- let result: u256 = u256.Zero;
189
- let base: u256 = this._value;
190
- let exp: u256 = value;
191
-
192
- while (exp > u256.Zero) {
193
- if (u256.and(exp, u256.One)) {
194
- result = SafeMath.add(result, base);
195
- }
196
-
197
- base = SafeMath.add(base, base);
198
- exp = u256.shr(exp, 1);
199
- }
200
-
201
- this._value = result;
202
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
203
-
204
- return this;
205
- }
206
-
207
- @inline
208
- @operator.postfix('++')
209
- public inc(): this {
210
- this.ensureValue();
211
-
212
- this._value = SafeMath.add(this._value, u256.One);
213
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
214
-
215
- return this;
216
- }
217
-
218
- @inline
219
- @operator.postfix('--')
220
- public dec(): this {
221
- this.ensureValue();
222
-
223
- this._value = SafeMath.sub(this._value, u256.One);
224
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
225
-
226
- return this;
227
- }
228
-
229
- @inline
230
- public set(value: u256): this {
231
- this._value = value;
232
-
233
- Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
234
-
235
- return this;
236
- }
237
-
238
- @inline
239
- public toUint8Array(): Uint8Array {
240
- return this._value.toUint8Array(true);
241
- }
242
-
243
- private ensureValue(): void {
244
- this._value = Blockchain.getStorageAt(this.pointer, this.subPointer, this.defaultValue);
245
- }
246
- }
1
+ import { u256 } from 'as-bignum/assembly';
2
+ import { SafeMath } from '../types/SafeMath';
3
+ import { MemorySlotPointer } from '../memory/MemorySlotPointer';
4
+ import { Blockchain } from '../env';
5
+
6
+ @final
7
+ export class StoredU256 {
8
+ constructor(
9
+ public pointer: u16,
10
+ public subPointer: MemorySlotPointer,
11
+ private defaultValue: u256,
12
+ ) {}
13
+
14
+ private _value: u256 = u256.Zero;
15
+
16
+ @inline
17
+ public get value(): u256 {
18
+ this.ensureValue();
19
+
20
+ return this._value;
21
+ }
22
+
23
+ @inline
24
+ public set value(value: u256) {
25
+ this._value = value;
26
+
27
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
28
+ }
29
+
30
+ @inline
31
+ public get toBytes(): Uint8Array {
32
+ return this._value.toUint8Array(false);
33
+ }
34
+
35
+ @inline
36
+ @operator('+')
37
+ public add(value: u256): this {
38
+ this.ensureValue();
39
+
40
+ this._value = SafeMath.add(this._value, value);
41
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
42
+
43
+ return this;
44
+ }
45
+
46
+ @inline
47
+ @operator('-')
48
+ public sub(value: u256): this {
49
+ this.ensureValue();
50
+
51
+ this._value = SafeMath.sub(this._value, value);
52
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
53
+
54
+ return this;
55
+ }
56
+
57
+ @inline
58
+ @operator('*')
59
+ public mul(value: u256): this {
60
+ this.ensureValue();
61
+
62
+ this._value = SafeMath.mul(this._value, value);
63
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
64
+
65
+ return this;
66
+ }
67
+
68
+ @inline
69
+ @operator('==')
70
+ public eq(value: u256): boolean {
71
+ this.ensureValue();
72
+
73
+ return this._value === value;
74
+ }
75
+
76
+ @inline
77
+ @operator('!=')
78
+ public ne(value: u256): boolean {
79
+ this.ensureValue();
80
+
81
+ return this._value !== value;
82
+ }
83
+
84
+ @inline
85
+ @operator('<')
86
+ public lt(value: u256): boolean {
87
+ this.ensureValue();
88
+
89
+ return this._value < value;
90
+ }
91
+
92
+ @inline
93
+ @operator('>')
94
+ public gt(value: u256): boolean {
95
+ this.ensureValue();
96
+
97
+ return this._value > value;
98
+ }
99
+
100
+ @inline
101
+ @operator('<=')
102
+ public le(value: u256): boolean {
103
+ this.ensureValue();
104
+
105
+ return this._value <= value;
106
+ }
107
+
108
+ @inline
109
+ @operator('>=')
110
+ public ge(value: u256): boolean {
111
+ this.ensureValue();
112
+
113
+ return this._value >= value;
114
+ }
115
+
116
+ @inline
117
+ @operator('>>')
118
+ public shr(value: i32): this {
119
+ this.ensureValue();
120
+
121
+ this._value = u256.shr(this._value, value);
122
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
123
+
124
+ return this;
125
+ }
126
+
127
+ @inline
128
+ @operator('&')
129
+ public and(value: u256): this {
130
+ this.ensureValue();
131
+
132
+ this._value = u256.and(this._value, value);
133
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
134
+
135
+ return this;
136
+ }
137
+
138
+ @inline
139
+ @operator('|')
140
+ public or(value: u256): this {
141
+ this.ensureValue();
142
+
143
+ this._value = u256.or(this._value, value);
144
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
145
+
146
+ return this;
147
+ }
148
+
149
+ @inline
150
+ @operator('^')
151
+ public xor(value: u256): this {
152
+ this.ensureValue();
153
+
154
+ this._value = u256.xor(this._value, value);
155
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
156
+
157
+ return this;
158
+ }
159
+
160
+ @inline
161
+ @operator('**')
162
+ public pow(value: u256): this {
163
+ this.ensureValue();
164
+
165
+ // code pow from scratch
166
+ let result: u256 = u256.One;
167
+
168
+ while (value > u256.Zero) {
169
+ if (u256.and(value, u256.One)) {
170
+ result = SafeMath.mul(result, this._value);
171
+ }
172
+
173
+ this._value = SafeMath.mul(this._value, this._value);
174
+ value = u256.shr(value, 1);
175
+ }
176
+
177
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
178
+
179
+ return this;
180
+ }
181
+
182
+ @inline
183
+ @operator('%')
184
+ public mod(value: u256): this {
185
+ this.ensureValue();
186
+
187
+ // code mod from scratch
188
+ let result: u256 = u256.Zero;
189
+ let base: u256 = this._value;
190
+ let exp: u256 = value;
191
+
192
+ while (exp > u256.Zero) {
193
+ if (u256.and(exp, u256.One)) {
194
+ result = SafeMath.add(result, base);
195
+ }
196
+
197
+ base = SafeMath.add(base, base);
198
+ exp = u256.shr(exp, 1);
199
+ }
200
+
201
+ this._value = result;
202
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
203
+
204
+ return this;
205
+ }
206
+
207
+ @inline
208
+ @operator.postfix('++')
209
+ public inc(): this {
210
+ this.ensureValue();
211
+
212
+ this._value = SafeMath.add(this._value, u256.One);
213
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
214
+
215
+ return this;
216
+ }
217
+
218
+ @inline
219
+ @operator.postfix('--')
220
+ public dec(): this {
221
+ this.ensureValue();
222
+
223
+ this._value = SafeMath.sub(this._value, u256.One);
224
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
225
+
226
+ return this;
227
+ }
228
+
229
+ @inline
230
+ public set(value: u256): this {
231
+ this._value = value;
232
+
233
+ Blockchain.setStorageAt(this.pointer, this.subPointer, this._value);
234
+
235
+ return this;
236
+ }
237
+
238
+ @inline
239
+ public toUint8Array(): Uint8Array {
240
+ return this._value.toUint8Array(true);
241
+ }
242
+
243
+ private ensureValue(): void {
244
+ this._value = Blockchain.getStorageAt(this.pointer, this.subPointer, this.defaultValue);
245
+ }
246
+ }
@@ -1,5 +1,5 @@
1
- import { Potential } from '../lang/Definitions';
2
-
3
- export const ADDRESS_BYTE_LENGTH: u8 = 66;
4
- export declare type Address = string;
5
- export declare type PotentialAddress = Potential<Address>;
1
+ import { Potential } from '../lang/Definitions';
2
+
3
+ export const ADDRESS_BYTE_LENGTH: u8 = 66;
4
+ export declare type Address = string;
5
+ export declare type PotentialAddress = Potential<Address>;
@@ -1,5 +1,5 @@
1
- export class Revert extends Error {
2
- constructor(msg: string = '') {
3
- super(`Execution reverted ${msg}`);
4
- }
5
- }
1
+ export class Revert extends Error {
2
+ constructor(msg: string = '') {
3
+ super(`Execution reverted ${msg}`);
4
+ }
5
+ }