@btc-vision/btc-runtime 1.1.7 → 1.1.8

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