@btc-vision/btc-runtime 1.1.6 → 1.1.7

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 (46) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +5 -3
  3. package/runtime/buffer/BytesWriter.ts +350 -350
  4. package/runtime/contracts/DeployableOP_20.ts +2 -2
  5. package/runtime/contracts/OP_20.ts +9 -9
  6. package/runtime/contracts/OP_NET.ts +76 -78
  7. package/runtime/contracts/interfaces/IOP_20.ts +21 -21
  8. package/runtime/contracts/interfaces/OP20InitParameters.ts +15 -15
  9. package/runtime/env/BTCEnvironment.ts +330 -328
  10. package/runtime/env/index.ts +3 -3
  11. package/runtime/events/NetEvent.ts +27 -27
  12. package/runtime/events/predefined/ApproveEvent.ts +16 -16
  13. package/runtime/events/predefined/BurnEvent.ts +13 -13
  14. package/runtime/events/predefined/ClaimEvent.ts +13 -13
  15. package/runtime/events/predefined/MintEvent.ts +15 -15
  16. package/runtime/events/predefined/StakeEvent.ts +13 -13
  17. package/runtime/events/predefined/TransferEvent.ts +16 -16
  18. package/runtime/events/predefined/UnstakeEvent.ts +13 -13
  19. package/runtime/events/predefined/index.ts +7 -7
  20. package/runtime/exports/index.ts +37 -37
  21. package/runtime/generic/Map.ts +65 -65
  22. package/runtime/generic/MapU256.ts +57 -57
  23. package/runtime/index.ts +57 -57
  24. package/runtime/interfaces/DeployContractResponse.ts +12 -12
  25. package/runtime/interfaces/IBTC.ts +6 -6
  26. package/runtime/lang/Definitions.ts +1 -1
  27. package/runtime/math/abi.ts +37 -37
  28. package/runtime/math/bytes.ts +34 -34
  29. package/runtime/math/cyrb53.ts +48 -46
  30. package/runtime/math/rnd.ts +55 -51
  31. package/runtime/math/sha256.ts +12 -12
  32. package/runtime/memory/AddressMemoryMap.ts +44 -44
  33. package/runtime/memory/KeyMerger.ts +53 -53
  34. package/runtime/memory/MemorySlot.ts +1 -1
  35. package/runtime/memory/MemorySlotPointer.ts +3 -3
  36. package/runtime/memory/MultiAddressMemoryMap.ts +62 -62
  37. package/runtime/shared-libraries/TransferHelper.ts +64 -64
  38. package/runtime/storage/StoredBoolean.ts +48 -48
  39. package/runtime/storage/StoredString.ts +145 -145
  40. package/runtime/storage/StoredU256.ts +250 -250
  41. package/runtime/types/Address.ts +5 -5
  42. package/runtime/types/Revert.ts +5 -5
  43. package/runtime/types/SafeMath.ts +197 -197
  44. package/runtime/types/index.ts +8 -8
  45. package/runtime/universal/ABIRegistry.ts +72 -72
  46. package/LICENSE.md +0 -63
@@ -270,7 +270,7 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
270
270
  const newBalance: u256 = SafeMath.sub(balance, value);
271
271
  this.balanceOfMap.set(Blockchain.msgSender, newBalance);
272
272
 
273
- // @ts-ignore
273
+ // @ts-expect-error TODO: Fix the typing because this is valid assembly-script syntax
274
274
  this._totalSupply -= value;
275
275
 
276
276
  this.createBurnEvent(value);
@@ -289,7 +289,7 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
289
289
  this.balanceOfMap.set(to, newToBalance);
290
290
  }
291
291
 
292
- // @ts-ignore
292
+ // @ts-expect-error TODO: Fix the typing because this is valid assembly-script syntax
293
293
  this._totalSupply += value;
294
294
 
295
295
  if (this._totalSupply.value > this.maxSupply) throw new Revert('Max supply reached');
@@ -1,9 +1,9 @@
1
- import { DeployableOP_20 } from './DeployableOP_20';
2
- import { u256 } from 'as-bignum/assembly';
3
- import { OP20InitParameters } from './interfaces/OP20InitParameters';
4
-
5
- export abstract class OP_20 extends DeployableOP_20 {
6
- protected constructor(maxSupply: u256, decimals: u8, name: string, symbol: string) {
7
- super(new OP20InitParameters(maxSupply, decimals, name, symbol));
8
- }
9
- }
1
+ import { DeployableOP_20 } from './DeployableOP_20';
2
+ import { u256 } from 'as-bignum/assembly';
3
+ import { OP20InitParameters } from './interfaces/OP20InitParameters';
4
+
5
+ export abstract class OP_20 extends DeployableOP_20 {
6
+ protected constructor(maxSupply: u256, decimals: u8, name: string, symbol: string) {
7
+ super(new OP20InitParameters(maxSupply, decimals, name, symbol));
8
+ }
9
+ }
@@ -1,78 +1,76 @@
1
- import { IBTC } from '../interfaces/IBTC';
2
- import { Address } from '../types/Address';
3
- import { Blockchain } from '../env';
4
- import { Calldata } from '../universal/ABIRegistry';
5
- import { BytesWriter } from '../buffer/BytesWriter';
6
- import { encodeSelector, Selector } from '../math/abi';
7
- import { Revert } from '../types/Revert';
8
- import { MAX_EVENT_DATA_SIZE, NetEvent } from '../events/NetEvent';
9
- import { StoredBoolean } from '../storage/StoredBoolean';
10
-
11
- export class OP_NET implements IBTC {
12
- protected readonly instantiated: StoredBoolean = new StoredBoolean(
13
- Blockchain.nextPointer,
14
- false,
15
- );
16
-
17
- constructor() {}
18
-
19
- public get address(): string {
20
- return Blockchain.contractAddress;
21
- }
22
-
23
- public get owner(): string {
24
- return Blockchain.owner;
25
- }
26
-
27
- public get isInstantiated(): bool {
28
- return this.instantiated.value;
29
- }
30
-
31
- public onInstantiated(): void {
32
- if (!this.isInstantiated) {
33
- this.instantiated.value = true;
34
- }
35
- }
36
-
37
- public callMethod(method: Selector, _calldata: Calldata): BytesWriter {
38
- switch (method) {
39
- default:
40
- throw new Revert('Method not found');
41
- }
42
- }
43
-
44
- public callView(method: Selector): BytesWriter {
45
- const response = new BytesWriter();
46
-
47
- switch (method) {
48
- case encodeSelector('address'):
49
- response.writeAddress(this.address);
50
- break;
51
- case encodeSelector('owner'):
52
- response.writeAddress(this.owner);
53
- break;
54
- default:
55
- throw new Revert('Method not found');
56
- }
57
-
58
- return response;
59
- }
60
-
61
- protected emitEvent(event: NetEvent): void {
62
- if (event.length > MAX_EVENT_DATA_SIZE) {
63
- throw new Error('Event data length exceeds maximum length.');
64
- }
65
-
66
- Blockchain.addEvent(event);
67
- }
68
-
69
- protected isSelf(address: Address): boolean {
70
- return this.address === address;
71
- }
72
-
73
- protected onlyOwner(caller: Address): void {
74
- if (this.owner !== caller) {
75
- throw new Revert('Only owner can call this method');
76
- }
77
- }
78
- }
1
+ import { IBTC } from '../interfaces/IBTC';
2
+ import { Address } from '../types/Address';
3
+ import { Blockchain } from '../env';
4
+ import { Calldata } from '../universal/ABIRegistry';
5
+ import { BytesWriter } from '../buffer/BytesWriter';
6
+ import { encodeSelector, Selector } from '../math/abi';
7
+ import { Revert } from '../types/Revert';
8
+ import { MAX_EVENT_DATA_SIZE, NetEvent } from '../events/NetEvent';
9
+ import { StoredBoolean } from '../storage/StoredBoolean';
10
+
11
+ export class OP_NET implements IBTC {
12
+ protected readonly instantiated: StoredBoolean = new StoredBoolean(
13
+ Blockchain.nextPointer,
14
+ false,
15
+ );
16
+
17
+ public get address(): string {
18
+ return Blockchain.contractAddress;
19
+ }
20
+
21
+ public get owner(): string {
22
+ return Blockchain.owner;
23
+ }
24
+
25
+ public get isInstantiated(): bool {
26
+ return this.instantiated.value;
27
+ }
28
+
29
+ public onInstantiated(): void {
30
+ if (!this.isInstantiated) {
31
+ this.instantiated.value = true;
32
+ }
33
+ }
34
+
35
+ public callMethod(method: Selector, _calldata: Calldata): BytesWriter {
36
+ switch (method) {
37
+ default:
38
+ throw new Revert('Method not found');
39
+ }
40
+ }
41
+
42
+ public callView(method: Selector): BytesWriter {
43
+ const response = new BytesWriter();
44
+
45
+ switch (method) {
46
+ case encodeSelector('address'):
47
+ response.writeAddress(this.address);
48
+ break;
49
+ case encodeSelector('owner'):
50
+ response.writeAddress(this.owner);
51
+ break;
52
+ default:
53
+ throw new Revert('Method not found');
54
+ }
55
+
56
+ return response;
57
+ }
58
+
59
+ protected emitEvent(event: NetEvent): void {
60
+ if (event.length > MAX_EVENT_DATA_SIZE) {
61
+ throw new Error('Event data length exceeds maximum length.');
62
+ }
63
+
64
+ Blockchain.addEvent(event);
65
+ }
66
+
67
+ protected isSelf(address: Address): boolean {
68
+ return this.address === address;
69
+ }
70
+
71
+ protected onlyOwner(caller: Address): void {
72
+ if (this.owner !== caller) {
73
+ throw new Revert('Only owner can call this method');
74
+ }
75
+ }
76
+ }
@@ -1,21 +1,21 @@
1
- import { BytesWriter } from '../../buffer/BytesWriter';
2
- import { Calldata } from '../../universal/ABIRegistry';
3
- import { StoredU256 } from '../../storage/StoredU256';
4
-
5
- export interface IOP_20 {
6
- readonly _totalSupply: StoredU256;
7
-
8
- balanceOf(callData: Calldata): BytesWriter;
9
-
10
- transfer(callData: Calldata): BytesWriter;
11
-
12
- transferFrom(callData: Calldata): BytesWriter;
13
-
14
- approve(callData: Calldata): BytesWriter;
15
-
16
- allowance(callData: Calldata): BytesWriter;
17
-
18
- burn(callData: Calldata): BytesWriter;
19
-
20
- mint(callData: Calldata): BytesWriter;
21
- }
1
+ import { BytesWriter } from '../../buffer/BytesWriter';
2
+ import { Calldata } from '../../universal/ABIRegistry';
3
+ import { StoredU256 } from '../../storage/StoredU256';
4
+
5
+ export interface IOP_20 {
6
+ readonly _totalSupply: StoredU256;
7
+
8
+ balanceOf(callData: Calldata): BytesWriter;
9
+
10
+ transfer(callData: Calldata): BytesWriter;
11
+
12
+ transferFrom(callData: Calldata): BytesWriter;
13
+
14
+ approve(callData: Calldata): BytesWriter;
15
+
16
+ allowance(callData: Calldata): BytesWriter;
17
+
18
+ burn(callData: Calldata): BytesWriter;
19
+
20
+ mint(callData: Calldata): BytesWriter;
21
+ }
@@ -1,15 +1,15 @@
1
- import { u256 } from 'as-bignum/assembly';
2
-
3
- export class OP20InitParameters {
4
- readonly maxSupply: u256;
5
- readonly decimals: u8;
6
- readonly name: string;
7
- readonly symbol: string;
8
-
9
- constructor(maxSupply: u256, decimals: u8, name: string, symbol: string) {
10
- this.maxSupply = maxSupply;
11
- this.decimals = decimals;
12
- this.name = name;
13
- this.symbol = symbol;
14
- }
15
- }
1
+ import { u256 } from 'as-bignum/assembly';
2
+
3
+ export class OP20InitParameters {
4
+ readonly maxSupply: u256;
5
+ readonly decimals: u8;
6
+ readonly name: string;
7
+ readonly symbol: string;
8
+
9
+ constructor(maxSupply: u256, decimals: u8, name: string, symbol: string) {
10
+ this.maxSupply = maxSupply;
11
+ this.decimals = decimals;
12
+ this.name = name;
13
+ this.symbol = symbol;
14
+ }
15
+ }