@leofcoin/standards 0.3.4 → 0.3.6
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/CHANGELOG.md +31 -0
- package/exports/token.js +8 -0
- package/package.json +5 -5
- package/src/token.ts +8 -1
- package/exports/types.d.ts +0 -47
- package/exports/types.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @leofcoin/standards
|
|
2
2
|
|
|
3
|
+
## 0.3.5
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Removed types definitions from exports directory for cleaner package structure
|
|
8
|
+
|
|
9
|
+
## 0.3.4
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Removed unused interfaces.ts file
|
|
14
|
+
- Updated rollup configuration
|
|
15
|
+
|
|
16
|
+
## 0.3.3
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Refactored type exports and moved interfaces to source files
|
|
21
|
+
|
|
22
|
+
## 0.3.2
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Refactored type imports to use new interfaces module
|
|
27
|
+
|
|
28
|
+
## 0.3.1
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- Updated voting type definitions and dependencies
|
|
33
|
+
|
|
3
34
|
## 0.3.0
|
|
4
35
|
|
|
5
36
|
### Changed
|
package/exports/token.js
CHANGED
|
@@ -25,6 +25,7 @@ class Token extends Roles {
|
|
|
25
25
|
#approvals = {};
|
|
26
26
|
#decimals = 18;
|
|
27
27
|
#totalSupply = 0n;
|
|
28
|
+
// #blacklist: { [address: string]: boolean } = {}
|
|
28
29
|
constructor(name, symbol, decimals = 18, state) {
|
|
29
30
|
if (!name)
|
|
30
31
|
throw new Error(`name undefined`);
|
|
@@ -89,9 +90,16 @@ class Token extends Roles {
|
|
|
89
90
|
if (!this.hasRole(msg.sender, 'BURN'))
|
|
90
91
|
throw new Error('not allowed');
|
|
91
92
|
this.#totalSupply = this.#totalSupply - amount;
|
|
93
|
+
this.#beforeTransfer(from, from, amount);
|
|
92
94
|
this.#decreaseBalance(from, amount);
|
|
93
95
|
}
|
|
94
96
|
#beforeTransfer(from, to, amount) {
|
|
97
|
+
if (!from)
|
|
98
|
+
throw new Error('address undefined');
|
|
99
|
+
// if (this.#blacklist[from]) throw new Error('address blacklisted')
|
|
100
|
+
// if (this.#blacklist[to]) throw new Error('address blacklisted')
|
|
101
|
+
if (amount < 0n)
|
|
102
|
+
throw new Error('amount must be positive');
|
|
95
103
|
if (!this.#balances[from] || this.#balances[from] < amount)
|
|
96
104
|
throw new Error('amount exceeds balance');
|
|
97
105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/standards",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Contract standards",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -107,17 +107,17 @@
|
|
|
107
107
|
},
|
|
108
108
|
"repository": {
|
|
109
109
|
"type": "git",
|
|
110
|
-
"url": "git+https://github.com/
|
|
110
|
+
"url": "git+https://github.com/leofcoin/standards.git"
|
|
111
111
|
},
|
|
112
112
|
"keywords": [],
|
|
113
113
|
"author": "",
|
|
114
114
|
"license": "MIT",
|
|
115
115
|
"bugs": {
|
|
116
|
-
"url": "https://github.com/
|
|
116
|
+
"url": "https://github.com/leofcoin/standards/issues"
|
|
117
117
|
},
|
|
118
|
-
"homepage": "https://github.com/
|
|
118
|
+
"homepage": "https://github.com/leofcoin/standards#readme",
|
|
119
119
|
"devDependencies": {
|
|
120
|
-
"@leofcoin/global-types": "^1.0.
|
|
120
|
+
"@leofcoin/global-types": "^1.0.3",
|
|
121
121
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
122
122
|
"rollup": "^4.54.0",
|
|
123
123
|
"rollup-plugin-auto-exports": "^1.1.1",
|
package/src/token.ts
CHANGED
|
@@ -33,6 +33,7 @@ export default class Token extends Roles {
|
|
|
33
33
|
#decimals = 18
|
|
34
34
|
|
|
35
35
|
#totalSupply: bigint = 0n
|
|
36
|
+
// #blacklist: { [address: string]: boolean } = {}
|
|
36
37
|
|
|
37
38
|
constructor(
|
|
38
39
|
name: string,
|
|
@@ -112,10 +113,16 @@ export default class Token extends Roles {
|
|
|
112
113
|
if (!this.hasRole(msg.sender, 'BURN')) throw new Error('not allowed')
|
|
113
114
|
|
|
114
115
|
this.#totalSupply = this.#totalSupply - amount
|
|
116
|
+
|
|
117
|
+
this.#beforeTransfer(from, from, amount)
|
|
115
118
|
this.#decreaseBalance(from, amount)
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
#beforeTransfer(from: address, to: address, amount: bigint) {
|
|
122
|
+
if (!from) throw new Error('address undefined')
|
|
123
|
+
// if (this.#blacklist[from]) throw new Error('address blacklisted')
|
|
124
|
+
// if (this.#blacklist[to]) throw new Error('address blacklisted')
|
|
125
|
+
if (amount < 0n) throw new Error('amount must be positive')
|
|
119
126
|
if (!this.#balances[from] || this.#balances[from] < amount)
|
|
120
127
|
throw new Error('amount exceeds balance')
|
|
121
128
|
}
|
|
@@ -128,8 +135,8 @@ export default class Token extends Roles {
|
|
|
128
135
|
|
|
129
136
|
#increaseBalance(address: address, amount: bigint) {
|
|
130
137
|
if (!this.#balances[address]) this.#balances[address] = 0n
|
|
131
|
-
const previousBalance = this.#balances[address]
|
|
132
138
|
|
|
139
|
+
const previousBalance = this.#balances[address]
|
|
133
140
|
this.#balances[address] = this.#balances[address] + amount
|
|
134
141
|
this.#updateHolders(address, previousBalance)
|
|
135
142
|
}
|
package/exports/types.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export interface MetaState {
|
|
2
|
-
creator: address;
|
|
3
|
-
createdAt: bigint;
|
|
4
|
-
}
|
|
5
|
-
export declare interface RolesState extends MetaState {
|
|
6
|
-
roles: {
|
|
7
|
-
[index: string]: address[];
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export declare interface TokenState extends RolesState {
|
|
11
|
-
holders: bigint;
|
|
12
|
-
balances: {
|
|
13
|
-
[address: address]: bigint;
|
|
14
|
-
};
|
|
15
|
-
approvals: {
|
|
16
|
-
[owner: address]: {
|
|
17
|
-
[operator: address]: bigint;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
totalSupply: bigint;
|
|
21
|
-
}
|
|
22
|
-
export interface VotingState extends MetaState {
|
|
23
|
-
votes: {
|
|
24
|
-
[id: string]: Vote;
|
|
25
|
-
};
|
|
26
|
-
votingDisabled: boolean;
|
|
27
|
-
votingDuration: number;
|
|
28
|
-
}
|
|
29
|
-
export interface PrivateVotingState extends VotingState {
|
|
30
|
-
voters: address[];
|
|
31
|
-
}
|
|
32
|
-
export type VoteResult = 0 | 0.5 | 1;
|
|
33
|
-
export type Vote = {
|
|
34
|
-
title: string;
|
|
35
|
-
method: string;
|
|
36
|
-
args: any[];
|
|
37
|
-
description: string;
|
|
38
|
-
endTime: EpochTimeStamp;
|
|
39
|
-
results?: {
|
|
40
|
-
[address: string]: VoteResult;
|
|
41
|
-
};
|
|
42
|
-
finished?: boolean;
|
|
43
|
-
enoughVotes?: boolean;
|
|
44
|
-
};
|
|
45
|
-
export interface VoteView extends Vote {
|
|
46
|
-
id: string;
|
|
47
|
-
}
|
package/exports/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|