@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.
- package/LICENSE +21 -0
- package/package.json +5 -3
- package/runtime/buffer/BytesWriter.ts +350 -350
- package/runtime/contracts/DeployableOP_20.ts +2 -2
- package/runtime/contracts/OP_20.ts +9 -9
- package/runtime/contracts/OP_NET.ts +76 -78
- package/runtime/contracts/interfaces/IOP_20.ts +21 -21
- package/runtime/contracts/interfaces/OP20InitParameters.ts +15 -15
- package/runtime/env/BTCEnvironment.ts +330 -328
- package/runtime/env/index.ts +3 -3
- package/runtime/events/NetEvent.ts +27 -27
- package/runtime/events/predefined/ApproveEvent.ts +16 -16
- package/runtime/events/predefined/BurnEvent.ts +13 -13
- package/runtime/events/predefined/ClaimEvent.ts +13 -13
- package/runtime/events/predefined/MintEvent.ts +15 -15
- package/runtime/events/predefined/StakeEvent.ts +13 -13
- package/runtime/events/predefined/TransferEvent.ts +16 -16
- package/runtime/events/predefined/UnstakeEvent.ts +13 -13
- package/runtime/events/predefined/index.ts +7 -7
- package/runtime/exports/index.ts +37 -37
- package/runtime/generic/Map.ts +65 -65
- package/runtime/generic/MapU256.ts +57 -57
- package/runtime/index.ts +57 -57
- package/runtime/interfaces/DeployContractResponse.ts +12 -12
- package/runtime/interfaces/IBTC.ts +6 -6
- package/runtime/lang/Definitions.ts +1 -1
- package/runtime/math/abi.ts +37 -37
- package/runtime/math/bytes.ts +34 -34
- package/runtime/math/cyrb53.ts +48 -46
- package/runtime/math/rnd.ts +55 -51
- package/runtime/math/sha256.ts +12 -12
- package/runtime/memory/AddressMemoryMap.ts +44 -44
- package/runtime/memory/KeyMerger.ts +53 -53
- package/runtime/memory/MemorySlot.ts +1 -1
- package/runtime/memory/MemorySlotPointer.ts +3 -3
- package/runtime/memory/MultiAddressMemoryMap.ts +62 -62
- package/runtime/shared-libraries/TransferHelper.ts +64 -64
- package/runtime/storage/StoredBoolean.ts +48 -48
- package/runtime/storage/StoredString.ts +145 -145
- package/runtime/storage/StoredU256.ts +250 -250
- package/runtime/types/Address.ts +5 -5
- package/runtime/types/Revert.ts +5 -5
- package/runtime/types/SafeMath.ts +197 -197
- package/runtime/types/index.ts +8 -8
- package/runtime/universal/ABIRegistry.ts +72 -72
- 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-
|
|
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-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
}
|