@leofcoin/standards 0.2.7 → 0.2.8
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/exports/index.js +1 -0
- package/exports/private-voting.js +11 -105
- package/exports/public-voting.js +2 -110
- package/exports/staking.d.ts +39 -0
- package/exports/token-receiver.d.ts +2 -2
- package/exports/token-receiver.js +2 -1
- package/exports/token.d.ts +3 -0
- package/exports/token.js +13 -3
- package/exports/voting/interfaces/i-voting.d.ts +5 -0
- package/exports/voting/private-voting.d.ts +7 -25
- package/exports/voting/voting.d.ts +5 -5
- package/exports/voting-C0KVNQO3.js +112 -0
- package/exports/voting-xYjJlN2h.js +112 -0
- package/package.json +1 -1
- package/src/decorators/time.ts +1 -1
- package/src/interfaces/i-token.ts +0 -0
- package/src/lock.ts +166 -0
- package/src/staking.ts +165 -0
- package/src/token-receiver.ts +3 -3
- package/src/token.ts +17 -4
- package/src/voting/interfaces/i-voting.ts +5 -0
- package/src/voting/private-voting.ts +12 -113
- package/src/voting/voting.ts +7 -7
- package/src/voting/interfaces/i-private-voting.ts +0 -4
- package/src/voting/interfaces/i-public-voting.ts +0 -4
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import ContractCreator from './contract-creator.js';
|
|
2
|
+
|
|
3
|
+
class Voting extends ContractCreator {
|
|
4
|
+
#votes = {};
|
|
5
|
+
#votingDisabled = false;
|
|
6
|
+
#votingDuration = 172800000;
|
|
7
|
+
constructor(state) {
|
|
8
|
+
super(state);
|
|
9
|
+
if (state) {
|
|
10
|
+
this.#votes = state.votes;
|
|
11
|
+
this.#votingDisabled = state.votingDisabled;
|
|
12
|
+
this.#votingDuration = state.votingDuration;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
get votes() {
|
|
16
|
+
return { ...this.#votes };
|
|
17
|
+
}
|
|
18
|
+
get votingDuration() {
|
|
19
|
+
return this.#votingDuration;
|
|
20
|
+
}
|
|
21
|
+
get votingDisabled() {
|
|
22
|
+
return this.#votingDisabled;
|
|
23
|
+
}
|
|
24
|
+
get state() {
|
|
25
|
+
return {
|
|
26
|
+
...super.state,
|
|
27
|
+
votes: this.#votes,
|
|
28
|
+
votingDisabled: this.#votingDisabled,
|
|
29
|
+
votingDuration: this.#votingDuration
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
#canVote() {
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
return this._canVote?.();
|
|
35
|
+
}
|
|
36
|
+
#beforeVote() {
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
return this._beforeVote?.();
|
|
39
|
+
}
|
|
40
|
+
#afterVote() {
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
return this._afterVote?.();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* create vote
|
|
46
|
+
* @param {string} vote
|
|
47
|
+
* @param {string} description
|
|
48
|
+
* @param {number} endTime
|
|
49
|
+
* @param {string} method function to run when agree amount is bigger
|
|
50
|
+
*/
|
|
51
|
+
createVote(title, description, endTime, method, args = []) {
|
|
52
|
+
if (!this.#canVote())
|
|
53
|
+
throw new Error(`Not allowed to create a vote`);
|
|
54
|
+
const id = crypto.randomUUID();
|
|
55
|
+
this.#votes[id] = {
|
|
56
|
+
title,
|
|
57
|
+
description,
|
|
58
|
+
method,
|
|
59
|
+
endTime,
|
|
60
|
+
args
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
#endVoting(voteId) {
|
|
64
|
+
let agree = Object.values(this.#votes[voteId].results).filter((result) => result === 1);
|
|
65
|
+
let disagree = Object.values(this.#votes[voteId].results).filter((result) => result === 0);
|
|
66
|
+
if (agree.length > disagree.length)
|
|
67
|
+
this[this.#votes[voteId].method](...this.#votes[voteId].args);
|
|
68
|
+
this.#votes[voteId].finished = true;
|
|
69
|
+
}
|
|
70
|
+
async vote(voteId, vote) {
|
|
71
|
+
vote = Number(vote);
|
|
72
|
+
if (vote !== 0 && vote !== 0.5 && vote !== 1)
|
|
73
|
+
throw new Error(`invalid vote value ${vote}`);
|
|
74
|
+
if (!this.#votes[voteId])
|
|
75
|
+
throw new Error(`Nothing found for ${voteId}`);
|
|
76
|
+
const ended = new Date().getTime() > this.#votes[voteId].endTime;
|
|
77
|
+
if (ended && !this.#votes[voteId].finished)
|
|
78
|
+
this.#endVoting(voteId);
|
|
79
|
+
if (ended)
|
|
80
|
+
throw new Error('voting already ended');
|
|
81
|
+
if (!this.#canVote())
|
|
82
|
+
throw new Error(`Not allowed to vote`);
|
|
83
|
+
await this.#beforeVote();
|
|
84
|
+
this.#votes[voteId][msg.sender] = vote;
|
|
85
|
+
await this.#afterVote();
|
|
86
|
+
}
|
|
87
|
+
get votesInProgress() {
|
|
88
|
+
return Object.entries(this.#votes)
|
|
89
|
+
.filter(([id, vote]) => !vote.finished)
|
|
90
|
+
.map(([id, vote]) => {
|
|
91
|
+
return { ...vote, id };
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
#disableVoting() {
|
|
95
|
+
this.#votingDisabled = true;
|
|
96
|
+
}
|
|
97
|
+
disableVoting() {
|
|
98
|
+
if (!this.#canVote())
|
|
99
|
+
throw new Error('not a allowed');
|
|
100
|
+
else {
|
|
101
|
+
this.createVote(`disable voting`, `Warning this disables all voting features forever`, new Date().getTime() + this.#votingDuration, '#disableVoting', []);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
sync() {
|
|
105
|
+
for (const vote of this.votesInProgress) {
|
|
106
|
+
if (vote.endTime < new Date().getTime())
|
|
107
|
+
this.#endVoting(vote.id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { Voting as V };
|
package/package.json
CHANGED
package/src/decorators/time.ts
CHANGED
|
@@ -2,7 +2,7 @@ export function time(target, descriptor) {
|
|
|
2
2
|
console.log({ descriptor }, { target })
|
|
3
3
|
if (descriptor.kind !== 'method') throw new Error(`expected ${descriptor.name} to be a method`)
|
|
4
4
|
descriptor.addInitializer(function () {
|
|
5
|
-
pubsub.subscribe('time-interval', (value) => {
|
|
5
|
+
globalThis.pubsub.subscribe('time-interval', (value) => {
|
|
6
6
|
this.onTimeChange?.(value)
|
|
7
7
|
})
|
|
8
8
|
})
|
|
File without changes
|
package/src/lock.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { restoreApprovals, restoreBalances } from './helpers.js'
|
|
2
|
+
import Roles, { RolesState } from './roles.js'
|
|
3
|
+
|
|
4
|
+
export declare interface LockState extends RolesState {
|
|
5
|
+
holders: BigNumberish
|
|
6
|
+
balances: { [address: address]: BigNumberish }
|
|
7
|
+
totalSupply: BigNumberish
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default class Lock extends PublicVoting {
|
|
11
|
+
/**
|
|
12
|
+
* string
|
|
13
|
+
*/
|
|
14
|
+
#name: string
|
|
15
|
+
/**
|
|
16
|
+
* String
|
|
17
|
+
*/
|
|
18
|
+
#symbol: string
|
|
19
|
+
/**
|
|
20
|
+
* uint
|
|
21
|
+
*/
|
|
22
|
+
#holders: typeof BigNumber = BigNumber['from'](0)
|
|
23
|
+
/**
|
|
24
|
+
* Object => Object => uint
|
|
25
|
+
*/
|
|
26
|
+
#balances = {}
|
|
27
|
+
/**
|
|
28
|
+
* Object => Object => uint
|
|
29
|
+
*/
|
|
30
|
+
#approvals: { [owner: string]: { [operator: string]: typeof BigNumber } } = {}
|
|
31
|
+
|
|
32
|
+
#decimals = 18
|
|
33
|
+
|
|
34
|
+
#totalSupply: typeof BigNumber = BigNumber['from'](0)
|
|
35
|
+
|
|
36
|
+
#stakingContract: address
|
|
37
|
+
|
|
38
|
+
// this.#privateField2 = 1
|
|
39
|
+
constructor(name: string, symbol: string, decimals: number = 18, state?: TokenState) {
|
|
40
|
+
if (!name) throw new Error(`name undefined`)
|
|
41
|
+
if (!symbol) throw new Error(`symbol undefined`)
|
|
42
|
+
|
|
43
|
+
super(state)
|
|
44
|
+
|
|
45
|
+
if (state) {
|
|
46
|
+
this.#balances = restoreBalances(state.balances)
|
|
47
|
+
this.#approvals = restoreApprovals(state.approvals)
|
|
48
|
+
this.#holders = BigNumber['from'](state.holders)
|
|
49
|
+
this.#totalSupply = BigNumber['from'](state.totalSupply)
|
|
50
|
+
} else {
|
|
51
|
+
this.#name = name
|
|
52
|
+
this.#symbol = symbol
|
|
53
|
+
this.#decimals = decimals
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// enables snapshotting
|
|
58
|
+
// needs dev attention so nothing breaks after snapshot happens
|
|
59
|
+
// iow everything that is not static needs to be included in the stateObject
|
|
60
|
+
/**
|
|
61
|
+
* @return {Object} {holders, balances, ...}
|
|
62
|
+
*/
|
|
63
|
+
get state(): TokenState {
|
|
64
|
+
return {
|
|
65
|
+
...super.state,
|
|
66
|
+
holders: this.holders,
|
|
67
|
+
balances: this.balances,
|
|
68
|
+
approvals: { ...this.#approvals },
|
|
69
|
+
totalSupply: this.totalSupply
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get totalSupply(): BigNumberish {
|
|
74
|
+
return this.#totalSupply
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get name(): string {
|
|
78
|
+
return this.#name
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get symbol(): string {
|
|
82
|
+
return this.#symbol
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get holders(): TokenState['holders'] {
|
|
86
|
+
return this.#holders
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get balances(): TokenState['balances'] {
|
|
90
|
+
return { ...this.#balances }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get approvals() {
|
|
94
|
+
return this.#approvals
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get decimals() {
|
|
98
|
+
return this.#decimals
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
mint(to: address, amount: BigNumberish) {
|
|
102
|
+
if (!this.hasRole(msg.sender, 'MINT')) throw new Error('not allowed')
|
|
103
|
+
|
|
104
|
+
this.#totalSupply = this.#totalSupply.add(amount)
|
|
105
|
+
this.#increaseBalance(to, amount)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
burn(from: address, amount: BigNumberish) {
|
|
109
|
+
if (!this.hasRole(msg.sender, 'BURN') || msg.sender !== from) throw new Error('not allowed')
|
|
110
|
+
const total = this.#totalSupply.sub(amount)
|
|
111
|
+
if (total.gte(0)) {
|
|
112
|
+
this.#totalSupply = total
|
|
113
|
+
this.#decreaseBalance(from, amount)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#beforeTransfer(from: address, to: address, amount: BigNumberish) {
|
|
118
|
+
if (!this.#balances[from] || this.#balances[from] < amount) throw new Error('amount exceeds balance')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#updateHolders(address: address, previousBalance: typeof BigNumber) {
|
|
122
|
+
if (this.#balances[address].toHexString() === '0x00') this.#holders.sub(1)
|
|
123
|
+
else if (this.#balances[address].toHexString() !== '0x00' && previousBalance.toHexString() === '0x00')
|
|
124
|
+
this.#holders.add(1)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#increaseBalance(address: address, amount: BigNumberish) {
|
|
128
|
+
if (!this.#balances[address]) this.#balances[address] = BigNumber['from'](0)
|
|
129
|
+
const previousBalance = this.#balances[address]
|
|
130
|
+
|
|
131
|
+
this.#balances[address] = this.#balances[address].add(amount)
|
|
132
|
+
this.#updateHolders(address, previousBalance)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#decreaseBalance(address: address, amount: BigNumberish) {
|
|
136
|
+
const previousBalance = this.#balances[address]
|
|
137
|
+
this.#balances[address] = this.#balances[address].sub(amount)
|
|
138
|
+
this.#updateHolders(address, previousBalance)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
balance() {
|
|
142
|
+
return this.#balances[msg.sender]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
balanceOf(address: address): BigNumberish {
|
|
146
|
+
return this.#balances[address]
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
setApproval(operator: address, amount: BigNumberish) {
|
|
150
|
+
const owner = msg.sender
|
|
151
|
+
if (!this.#approvals[owner]) this.#approvals[owner] = {}
|
|
152
|
+
this.#approvals[owner][operator] = BigNumber['from'](amount)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
approved(owner: address, operator: address, amount: BigNumberish): boolean {
|
|
156
|
+
return this.#approvals[owner][operator] === amount
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
transfer(from: address, to: address, amount: BigNumberish) {
|
|
160
|
+
// TODO: is BigNumber?
|
|
161
|
+
amount = BigNumber['from'](amount)
|
|
162
|
+
this.#beforeTransfer(from, to, amount)
|
|
163
|
+
this.#decreaseBalance(from, amount)
|
|
164
|
+
this.#increaseBalance(to, amount)
|
|
165
|
+
}
|
|
166
|
+
}
|
package/src/staking.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { restoreApprovals, restoreBalances } from './helpers.js'
|
|
2
|
+
import Roles, { RolesState } from './roles.js'
|
|
3
|
+
|
|
4
|
+
export declare interface TokenState extends RolesState {
|
|
5
|
+
holders: BigNumberish
|
|
6
|
+
balances: { [address: address]: BigNumberish }
|
|
7
|
+
approvals: { [owner: address]: { [operator: address]: BigNumberish } }
|
|
8
|
+
totalSupply: BigNumberish
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class Token extends Roles {
|
|
12
|
+
/**
|
|
13
|
+
* string
|
|
14
|
+
*/
|
|
15
|
+
#name: string
|
|
16
|
+
/**
|
|
17
|
+
* String
|
|
18
|
+
*/
|
|
19
|
+
#symbol: string
|
|
20
|
+
/**
|
|
21
|
+
* uint
|
|
22
|
+
*/
|
|
23
|
+
#holders: typeof BigNumber = BigNumber['from'](0)
|
|
24
|
+
/**
|
|
25
|
+
* Object => Object => uint
|
|
26
|
+
*/
|
|
27
|
+
#balances = {}
|
|
28
|
+
/**
|
|
29
|
+
* Object => Object => uint
|
|
30
|
+
*/
|
|
31
|
+
#approvals: { [owner: string]: { [operator: string]: typeof BigNumber } } = {}
|
|
32
|
+
|
|
33
|
+
#decimals = 18
|
|
34
|
+
|
|
35
|
+
#totalSupply: typeof BigNumber = BigNumber['from'](0)
|
|
36
|
+
|
|
37
|
+
// this.#privateField2 = 1
|
|
38
|
+
constructor(name: string, symbol: string, decimals: number = 18, state?: TokenState) {
|
|
39
|
+
if (!name) throw new Error(`name undefined`)
|
|
40
|
+
if (!symbol) throw new Error(`symbol undefined`)
|
|
41
|
+
|
|
42
|
+
super(state)
|
|
43
|
+
|
|
44
|
+
if (state) {
|
|
45
|
+
this.#balances = restoreBalances(state.balances)
|
|
46
|
+
this.#approvals = restoreApprovals(state.approvals)
|
|
47
|
+
this.#holders = BigNumber['from'](state.holders)
|
|
48
|
+
this.#totalSupply = BigNumber['from'](state.totalSupply)
|
|
49
|
+
} else {
|
|
50
|
+
this.#name = name
|
|
51
|
+
this.#symbol = symbol
|
|
52
|
+
this.#decimals = decimals
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// enables snapshotting
|
|
57
|
+
// needs dev attention so nothing breaks after snapshot happens
|
|
58
|
+
// iow everything that is not static needs to be included in the stateObject
|
|
59
|
+
/**
|
|
60
|
+
* @return {Object} {holders, balances, ...}
|
|
61
|
+
*/
|
|
62
|
+
get state(): TokenState {
|
|
63
|
+
return {
|
|
64
|
+
...super.state,
|
|
65
|
+
holders: this.holders,
|
|
66
|
+
balances: this.balances,
|
|
67
|
+
approvals: { ...this.#approvals },
|
|
68
|
+
totalSupply: this.totalSupply
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get totalSupply(): BigNumberish {
|
|
73
|
+
return this.#totalSupply
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get name(): string {
|
|
77
|
+
return this.#name
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get symbol(): string {
|
|
81
|
+
return this.#symbol
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get holders(): TokenState['holders'] {
|
|
85
|
+
return this.#holders
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get balances(): TokenState['balances'] {
|
|
89
|
+
return { ...this.#balances }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get approvals() {
|
|
93
|
+
return this.#approvals
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get decimals() {
|
|
97
|
+
return this.#decimals
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
mint(to: address, amount: BigNumberish) {
|
|
101
|
+
if (!this.hasRole(msg.sender, 'MINT')) throw new Error('not allowed')
|
|
102
|
+
|
|
103
|
+
this.#totalSupply = this.#totalSupply.add(amount)
|
|
104
|
+
this.#increaseBalance(to, amount)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
burn(from: address, amount: BigNumberish) {
|
|
108
|
+
if (!this.hasRole(msg.sender, 'BURN') || msg.sender !== from) throw new Error('not allowed')
|
|
109
|
+
const total = this.#totalSupply.sub(amount)
|
|
110
|
+
if (total.gte(0)) {
|
|
111
|
+
this.#totalSupply = total
|
|
112
|
+
this.#decreaseBalance(from, amount)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#beforeTransfer(from: address, to: address, amount: BigNumberish) {
|
|
117
|
+
if (!this.#balances[from] || this.#balances[from] < amount) throw new Error('amount exceeds balance')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#updateHolders(address: address, previousBalance: typeof BigNumber) {
|
|
121
|
+
if (this.#balances[address].toHexString() === '0x00') this.#holders.sub(1)
|
|
122
|
+
else if (this.#balances[address].toHexString() !== '0x00' && previousBalance.toHexString() === '0x00')
|
|
123
|
+
this.#holders.add(1)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#increaseBalance(address: address, amount: BigNumberish) {
|
|
127
|
+
if (!this.#balances[address]) this.#balances[address] = BigNumber['from'](0)
|
|
128
|
+
const previousBalance = this.#balances[address]
|
|
129
|
+
|
|
130
|
+
this.#balances[address] = this.#balances[address].add(amount)
|
|
131
|
+
this.#updateHolders(address, previousBalance)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#decreaseBalance(address: address, amount: BigNumberish) {
|
|
135
|
+
const previousBalance = this.#balances[address]
|
|
136
|
+
this.#balances[address] = this.#balances[address].sub(amount)
|
|
137
|
+
this.#updateHolders(address, previousBalance)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
balance() {
|
|
141
|
+
return this.#balances[msg.sender]
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
balanceOf(address: address): BigNumberish {
|
|
145
|
+
return this.#balances[address]
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
setApproval(operator: address, amount: BigNumberish) {
|
|
149
|
+
const owner = msg.sender
|
|
150
|
+
if (!this.#approvals[owner]) this.#approvals[owner] = {}
|
|
151
|
+
this.#approvals[owner][operator] = BigNumber['from'](amount)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
approved(owner: address, operator: address, amount: BigNumberish): boolean {
|
|
155
|
+
return this.#approvals[owner][operator] === amount
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
transfer(from: address, to: address, amount: BigNumberish) {
|
|
159
|
+
// TODO: is BigNumber?
|
|
160
|
+
amount = BigNumber['from'](amount)
|
|
161
|
+
this.#beforeTransfer(from, to, amount)
|
|
162
|
+
this.#decreaseBalance(from, amount)
|
|
163
|
+
this.#increaseBalance(to, amount)
|
|
164
|
+
}
|
|
165
|
+
}
|
package/src/token-receiver.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IVoting } from './voting/interfaces/i-voting.js'
|
|
2
2
|
import PublicVoting, { PublicVotingState } from './voting/public-voting.js'
|
|
3
3
|
|
|
4
4
|
export interface TokenReceiverState extends PublicVotingState {
|
|
@@ -7,7 +7,7 @@ export interface TokenReceiverState extends PublicVotingState {
|
|
|
7
7
|
tokenAmountToReceive: typeof BigNumber
|
|
8
8
|
voteType: 'burn' | 'transfer'
|
|
9
9
|
}
|
|
10
|
-
export default class TokenReceiver extends PublicVoting implements
|
|
10
|
+
export default class TokenReceiver extends PublicVoting implements IVoting {
|
|
11
11
|
#tokenToReceive: address
|
|
12
12
|
#tokenAmountToReceive: typeof BigNumber
|
|
13
13
|
#tokenReceiver: address
|
|
@@ -74,7 +74,7 @@ export default class TokenReceiver extends PublicVoting implements IPublicVoting
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
async _beforeVote(): Promise<any> {
|
|
77
|
-
|
|
77
|
+
return this.#beforeVote()
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
package/src/token.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { restoreApprovals, restoreBalances } from './helpers.js'
|
|
|
2
2
|
import Roles, { RolesState } from './roles.js'
|
|
3
3
|
|
|
4
4
|
export declare interface TokenState extends RolesState {
|
|
5
|
+
name: string
|
|
6
|
+
symbol: string
|
|
7
|
+
decimals: number
|
|
5
8
|
holders: BigNumberish
|
|
6
9
|
balances: { [address: address]: BigNumberish }
|
|
7
10
|
approvals: { [owner: address]: { [operator: address]: BigNumberish } }
|
|
@@ -34,6 +37,8 @@ export default class Token extends Roles {
|
|
|
34
37
|
|
|
35
38
|
#totalSupply: typeof BigNumber = BigNumber['from'](0)
|
|
36
39
|
|
|
40
|
+
#stakingContract: address
|
|
41
|
+
|
|
37
42
|
// this.#privateField2 = 1
|
|
38
43
|
constructor(name: string, symbol: string, decimals: number = 18, state?: TokenState) {
|
|
39
44
|
if (!name) throw new Error(`name undefined`)
|
|
@@ -46,6 +51,9 @@ export default class Token extends Roles {
|
|
|
46
51
|
this.#approvals = restoreApprovals(state.approvals)
|
|
47
52
|
this.#holders = BigNumber['from'](state.holders)
|
|
48
53
|
this.#totalSupply = BigNumber['from'](state.totalSupply)
|
|
54
|
+
this.#name = name
|
|
55
|
+
this.#symbol = symbol
|
|
56
|
+
this.#decimals = decimals
|
|
49
57
|
} else {
|
|
50
58
|
this.#name = name
|
|
51
59
|
this.#symbol = symbol
|
|
@@ -62,6 +70,9 @@ export default class Token extends Roles {
|
|
|
62
70
|
get state(): TokenState {
|
|
63
71
|
return {
|
|
64
72
|
...super.state,
|
|
73
|
+
name: this.#name,
|
|
74
|
+
symbol: this.#symbol,
|
|
75
|
+
decimals: this.#decimals,
|
|
65
76
|
holders: this.holders,
|
|
66
77
|
balances: this.balances,
|
|
67
78
|
approvals: { ...this.#approvals },
|
|
@@ -105,10 +116,12 @@ export default class Token extends Roles {
|
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
burn(from: address, amount: BigNumberish) {
|
|
108
|
-
if (!this.hasRole(msg.sender, 'BURN')) throw new Error('not allowed')
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
if (!this.hasRole(msg.sender, 'BURN') || msg.sender !== from) throw new Error('not allowed')
|
|
120
|
+
const total = this.#totalSupply.sub(amount)
|
|
121
|
+
if (total.gte(0)) {
|
|
122
|
+
this.#totalSupply = total
|
|
123
|
+
this.#decreaseBalance(from, amount)
|
|
124
|
+
}
|
|
112
125
|
}
|
|
113
126
|
|
|
114
127
|
#beforeTransfer(from: address, to: address, amount: BigNumberish) {
|