@btc-vision/btc-runtime 1.1.7 → 1.1.9

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 +208 -197
  49. package/runtime/types/index.ts +8 -8
  50. package/runtime/universal/ABIRegistry.ts +72 -72
@@ -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,76 +1,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
+ import { IBTC } from '../interfaces/IBTC';
2
+ import { Address, ADDRESS_BYTE_LENGTH } 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
+ let response: BytesWriter;
44
+
45
+ switch (method) {
46
+ case encodeSelector('address'):
47
+ response = new BytesWriter(ADDRESS_BYTE_LENGTH);
48
+ response.writeAddress(this.address);
49
+ break;
50
+ case encodeSelector('owner'):
51
+ response = new BytesWriter(ADDRESS_BYTE_LENGTH);
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,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
+ }