@btc-vision/btc-runtime 1.1.0 → 1.1.1
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/package.json
CHANGED
|
@@ -14,48 +14,56 @@ import { MultiAddressMemoryMap } from '../memory/MultiAddressMemoryMap';
|
|
|
14
14
|
import { StoredU256 } from '../storage/StoredU256';
|
|
15
15
|
import { ApproveEvent, BurnEvent, MintEvent, TransferEvent } from '../events/predefined';
|
|
16
16
|
import { StoredString } from '../storage/StoredString';
|
|
17
|
+
import { OP20InitParameters } from './interfaces/OP20InitParameters';
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.maxSupply = maxSupply;
|
|
26
|
-
this.decimals = decimals;
|
|
27
|
-
this.name = name;
|
|
28
|
-
this.symbol = symbol;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
19
|
+
const maxSupplyPointer: u16 = Blockchain.nextPointer;
|
|
20
|
+
const decimalsPointer: u16 = Blockchain.nextPointer;
|
|
21
|
+
const namePointer: u16 = Blockchain.nextPointer;
|
|
22
|
+
const symbolPointer: u16 = Blockchain.nextPointer;
|
|
23
|
+
const totalSupplyPointer: u16 = Blockchain.nextPointer;
|
|
24
|
+
const allowanceMapPointer: u16 = Blockchain.nextPointer;
|
|
25
|
+
const balanceOfMapPointer: u16 = Blockchain.nextPointer;
|
|
31
26
|
|
|
32
27
|
export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
33
28
|
protected readonly allowanceMap: MultiAddressMemoryMap<Address, Address, MemorySlotData<u256>>;
|
|
34
29
|
protected readonly balanceOfMap: AddressMemoryMap<Address, MemorySlotData<u256>>;
|
|
35
30
|
|
|
31
|
+
protected readonly _maxSupply: StoredU256;
|
|
32
|
+
protected readonly _decimals: StoredU256;
|
|
33
|
+
protected readonly _name: StoredString;
|
|
34
|
+
protected readonly _symbol: StoredString;
|
|
35
|
+
|
|
36
36
|
protected constructor(params?: OP20InitParameters) {
|
|
37
37
|
super();
|
|
38
38
|
|
|
39
|
-
if (params) {
|
|
40
|
-
this.instantiate(params);
|
|
41
|
-
} else {
|
|
42
|
-
this.instantiate(new OP20InitParameters(u256.Zero, 0, '', ''));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
39
|
this.allowanceMap = new MultiAddressMemoryMap<Address, Address, MemorySlotData<u256>>(
|
|
46
|
-
|
|
40
|
+
allowanceMapPointer,
|
|
47
41
|
u256.Zero,
|
|
48
42
|
);
|
|
49
43
|
|
|
50
44
|
this.balanceOfMap = new AddressMemoryMap<Address, MemorySlotData<u256>>(
|
|
51
|
-
|
|
45
|
+
balanceOfMapPointer,
|
|
52
46
|
u256.Zero,
|
|
53
47
|
);
|
|
54
48
|
|
|
55
|
-
this._totalSupply = new StoredU256(
|
|
49
|
+
this._totalSupply = new StoredU256(totalSupplyPointer, u256.Zero, u256.Zero);
|
|
50
|
+
|
|
51
|
+
this._maxSupply = new StoredU256(maxSupplyPointer, u256.Zero, u256.Zero);
|
|
52
|
+
this._decimals = new StoredU256(decimalsPointer, u256.Zero, u256.Zero);
|
|
53
|
+
|
|
54
|
+
this._name = new StoredString(namePointer, '');
|
|
55
|
+
this._symbol = new StoredString(symbolPointer, '');
|
|
56
|
+
|
|
57
|
+
if (params && this._maxSupply.value.isZero()) {
|
|
58
|
+
this.instantiate(params, true);
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
public _totalSupply: StoredU256;
|
|
63
|
+
|
|
64
|
+
public get totalSupply(): u256 {
|
|
65
|
+
return this._totalSupply.value;
|
|
66
|
+
}
|
|
59
67
|
|
|
60
68
|
public get maxSupply(): u256 {
|
|
61
69
|
if (!this._maxSupply) throw new Revert('Max supply not set');
|
|
@@ -63,54 +71,39 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
|
63
71
|
return this._maxSupply.value;
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
private _decimals: StoredU256 | undefined;
|
|
67
|
-
|
|
68
74
|
public get decimals(): u8 {
|
|
69
75
|
if (!this._decimals) throw new Revert('Decimals not set');
|
|
70
76
|
|
|
71
|
-
return u8(this._decimals.value);
|
|
77
|
+
return u8(this._decimals.value.toU32());
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
private _name: StoredString | undefined;
|
|
75
|
-
|
|
76
80
|
public get name(): string {
|
|
77
81
|
if (!this._name) throw new Revert('Name not set');
|
|
78
82
|
|
|
79
83
|
return this._name.value;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
private _symbol: StoredString | undefined;
|
|
83
|
-
|
|
84
86
|
public get symbol(): string {
|
|
85
87
|
if (!this._symbol) throw new Revert('Symbol not set');
|
|
86
88
|
|
|
87
89
|
return this._symbol.value;
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
public
|
|
91
|
-
|
|
92
|
-
public get totalSupply(): u256 {
|
|
93
|
-
return this._totalSupply.value;
|
|
94
|
-
}
|
|
92
|
+
public instantiate(params: OP20InitParameters, skipOwnerVerification: boolean = false): void {
|
|
93
|
+
if (!skipOwnerVerification) this.onlyOwner(Blockchain.from());
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
this.onlyOwner(Blockchain.from());
|
|
98
|
-
|
|
99
|
-
this._maxSupply = new StoredU256(Blockchain.nextPointer, u256.Zero, u256.Zero);
|
|
100
|
-
if (u256.ne(this._maxSupply.value, u256.Zero)) {
|
|
95
|
+
if (!this._maxSupply.value.isZero()) {
|
|
101
96
|
throw new Revert('Already initialized');
|
|
102
97
|
}
|
|
103
98
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
Blockchain.nextPointer,
|
|
108
|
-
u256.Zero,
|
|
109
|
-
u256.fromU32(u32(params.decimals)),
|
|
110
|
-
);
|
|
99
|
+
if (params.decimals > 32) {
|
|
100
|
+
throw new Revert('Decimals can not be more than 32');
|
|
101
|
+
}
|
|
111
102
|
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
103
|
+
this._maxSupply.value = params.maxSupply;
|
|
104
|
+
this._decimals.value = u256.fromU32(u32(params.decimals));
|
|
105
|
+
this._name.value = params.name;
|
|
106
|
+
this._symbol.value = params.symbol;
|
|
114
107
|
}
|
|
115
108
|
|
|
116
109
|
/** METHODS */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DeployableOP_20
|
|
2
|
-
import { u256 } from 'as-bignum';
|
|
1
|
+
import { DeployableOP_20 } from './DeployableOP_20';
|
|
2
|
+
import { u256 } from 'as-bignum/assembly';
|
|
3
|
+
import { OP20InitParameters } from './interfaces/OP20InitParameters';
|
|
3
4
|
|
|
4
5
|
export abstract class OP_20 extends DeployableOP_20 {
|
|
5
6
|
protected constructor(maxSupply: u256, decimals: u8, name: string, symbol: string) {
|
|
@@ -0,0 +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
|
+
}
|
package/runtime/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './contracts/interfaces/IOP_20';
|
|
|
6
6
|
export * from './contracts/OP_20';
|
|
7
7
|
export * from './contracts/DeployableOP_20';
|
|
8
8
|
export * from './contracts/OP_NET';
|
|
9
|
+
export * from './contracts/interfaces/OP20InitParameters';
|
|
9
10
|
|
|
10
11
|
/** Buffer */
|
|
11
12
|
export * from './buffer/BytesReader';
|