@leofcoin/standards 0.2.16 → 0.3.0
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/.gitattributes +2 -2
- package/.github/workflows/test.yml +33 -0
- package/.prettierrc +8 -8
- package/CHANGELOG.md +16 -3
- package/LICENSE +21 -21
- package/README.md +25 -23
- package/exports/helpers.js +1 -1
- package/exports/i-public-voting.js +1 -0
- package/exports/index.d.ts +2 -1
- package/exports/index.js +2 -3
- package/exports/meta-D7uruGOw.js +28 -0
- package/exports/meta.d.ts +11 -0
- package/exports/private-voting.js +104 -11
- package/exports/public-voting.js +103 -4
- package/exports/roles.d.ts +5 -10
- package/exports/roles.js +7 -8
- package/exports/token-receiver.d.ts +5 -7
- package/exports/token-receiver.js +25 -14
- package/exports/token.d.ts +14 -27
- package/exports/token.js +14 -48
- package/exports/types.d.ts +21 -0
- package/exports/voting/private-voting.d.ts +108 -11
- package/exports/voting/public-voting.d.ts +45 -8
- package/exports/voting/types.d.ts +11 -7
- package/package.json +10 -18
- package/rollup.config.js +28 -28
- package/src/helpers.ts +19 -19
- package/src/index.ts +8 -7
- package/src/meta.ts +31 -0
- package/src/roles.ts +88 -89
- package/src/token-receiver.ts +196 -175
- package/src/token.ts +162 -198
- package/src/types.ts +15 -0
- package/src/voting/interfaces/i-public-voting.ts +4 -0
- package/src/voting/private-voting.ts +187 -69
- package/src/voting/public-voting.ts +134 -14
- package/src/voting/types.ts +30 -24
- package/test/helpers.js +51 -0
- package/test/public-voting.js +365 -6
- package/test/roles.js +186 -0
- package/test/token.js +211 -0
- package/tsconfig.json +16 -12
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/exports/contract-creator.d.ts +0 -11
- package/exports/contract-creator.js +0 -20
- package/exports/decorators/time.d.ts +0 -1
- package/exports/interfaces/i-token.d.ts +0 -10
- package/exports/lock.d.ts +0 -37
- package/exports/staking.d.ts +0 -40
- package/exports/voting/interfaces/i-voting.d.ts +0 -6
- package/exports/voting/voting.d.ts +0 -38
- package/exports/voting-C0KVNQO3.js +0 -112
- package/exports/voting-xYjJlN2h.js +0 -112
- package/src/contract-creator.ts +0 -24
- package/src/decorators/time.ts +0 -9
- package/src/interfaces/i-token.ts +0 -10
- package/src/lock.ts +0 -167
- package/src/staking.ts +0 -166
- package/src/voting/interfaces/i-voting.ts +0 -7
- package/src/voting/voting.ts +0 -123
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import PublicVoting from './public-voting.js';
|
|
2
|
-
import './
|
|
3
|
-
import './contract-creator.js';
|
|
2
|
+
import './meta-D7uruGOw.js';
|
|
4
3
|
|
|
5
4
|
class TokenReceiver extends PublicVoting {
|
|
6
5
|
#tokenToReceive;
|
|
@@ -42,7 +41,9 @@ class TokenReceiver extends PublicVoting {
|
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
43
|
async #canVote() {
|
|
45
|
-
const amount = (await msg.staticCall(this.#tokenToReceive, 'balanceOf', [
|
|
44
|
+
const amount = (await msg.staticCall(this.#tokenToReceive, 'balanceOf', [
|
|
45
|
+
msg.sender
|
|
46
|
+
]));
|
|
46
47
|
return amount >= this.#tokenAmountToReceive;
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
@@ -54,11 +55,17 @@ class TokenReceiver extends PublicVoting {
|
|
|
54
55
|
}
|
|
55
56
|
async #beforeVote() {
|
|
56
57
|
if (this.#voteType === 'burn')
|
|
57
|
-
return msg.staticCall(this.tokenToReceive, 'burn', [
|
|
58
|
-
|
|
58
|
+
return msg.staticCall(this.tokenToReceive, 'burn', [
|
|
59
|
+
this.tokenAmountToReceive
|
|
60
|
+
]);
|
|
61
|
+
return msg.staticCall(this.tokenToReceive, 'transfer', [
|
|
62
|
+
msg.sender,
|
|
63
|
+
this.tokenReceiver,
|
|
64
|
+
this.tokenAmountToReceive
|
|
65
|
+
]);
|
|
59
66
|
}
|
|
60
67
|
async _beforeVote() {
|
|
61
|
-
|
|
68
|
+
await this.#beforeVote();
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* check if sender can pay
|
|
@@ -76,11 +83,9 @@ class TokenReceiver extends PublicVoting {
|
|
|
76
83
|
* @returns {boolean} promise
|
|
77
84
|
*/
|
|
78
85
|
async _burnTokenToReceive() {
|
|
79
|
-
return msg.staticCall(this.#tokenToReceive, 'burn', [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const amount = await msg.call(this.#tokenToReceive, 'balance', []);
|
|
83
|
-
return amount.gte(this.tokenAmountToReceive);
|
|
86
|
+
return msg.staticCall(this.#tokenToReceive, 'burn', [
|
|
87
|
+
this.#tokenAmountToReceive
|
|
88
|
+
]);
|
|
84
89
|
}
|
|
85
90
|
#changeTokenToReceive(address) {
|
|
86
91
|
this.#tokenToReceive = address;
|
|
@@ -92,7 +97,11 @@ class TokenReceiver extends PublicVoting {
|
|
|
92
97
|
this.#voteType = type;
|
|
93
98
|
}
|
|
94
99
|
#getTokensOut(amount, receiver) {
|
|
95
|
-
return msg.call(this.#tokenReceiver, 'transfer', [
|
|
100
|
+
return msg.call(this.#tokenReceiver, 'transfer', [
|
|
101
|
+
this.#tokenReceiver,
|
|
102
|
+
receiver,
|
|
103
|
+
amount
|
|
104
|
+
]);
|
|
96
105
|
}
|
|
97
106
|
async changeVoteType(type) {
|
|
98
107
|
if (!this.#canVote())
|
|
@@ -118,12 +127,14 @@ class TokenReceiver extends PublicVoting {
|
|
|
118
127
|
}
|
|
119
128
|
}
|
|
120
129
|
#balance() {
|
|
121
|
-
return msg.staticCall(this.#tokenToReceive, 'balanceOf', [
|
|
130
|
+
return msg.staticCall(this.#tokenToReceive, 'balanceOf', [
|
|
131
|
+
this.#tokenReceiver
|
|
132
|
+
]);
|
|
122
133
|
}
|
|
123
134
|
async changeTokenToReceive() {
|
|
124
135
|
if (!this.#canVote())
|
|
125
136
|
throw new Error('not a allowed');
|
|
126
|
-
if ((await this.#balance())
|
|
137
|
+
if ((await this.#balance()) !== 0n && this.#voteType === 'transfer')
|
|
127
138
|
throw new Error('get tokens out first or they be lost forever');
|
|
128
139
|
else {
|
|
129
140
|
this.createVote(`change the token to receive`, `set tokenToReceive to a new address`, new Date().getTime() + this.votingDuration, '#changeTokenToReceive', []);
|
package/exports/token.d.ts
CHANGED
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare interface TokenState extends RolesState {
|
|
4
|
-
name: string;
|
|
5
|
-
symbol: string;
|
|
6
|
-
decimals: number;
|
|
7
|
-
holders: bigint;
|
|
8
|
-
balances: {
|
|
9
|
-
[address: address]: bigint;
|
|
10
|
-
};
|
|
11
|
-
approvals: {
|
|
12
|
-
[owner: address]: {
|
|
13
|
-
[operator: address]: bigint;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
totalSupply: bigint;
|
|
17
|
-
maxSupply: bigint;
|
|
18
|
-
}
|
|
1
|
+
import Roles from './roles.js';
|
|
2
|
+
import { TokenState } from './types.js';
|
|
19
3
|
export default class Token extends Roles {
|
|
20
4
|
#private;
|
|
21
5
|
constructor(name: string, symbol: string, decimals?: number, state?: TokenState);
|
|
22
6
|
/**
|
|
23
7
|
* @return {Object} {holders, balances, ...}
|
|
24
8
|
*/
|
|
25
|
-
get state():
|
|
26
|
-
get
|
|
27
|
-
get
|
|
28
|
-
get
|
|
29
|
-
get
|
|
30
|
-
get
|
|
31
|
-
get
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
get state(): {};
|
|
10
|
+
get totalSupply(): bigint;
|
|
11
|
+
get name(): string;
|
|
12
|
+
get symbol(): string;
|
|
13
|
+
get holders(): {};
|
|
14
|
+
get balances(): {};
|
|
15
|
+
get approvals(): {
|
|
16
|
+
[owner: string]: {
|
|
17
|
+
[operator: string]: bigint;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
get decimals(): number;
|
|
34
21
|
mint(to: address, amount: bigint): void;
|
|
35
22
|
burn(from: address, amount: bigint): void;
|
|
36
23
|
balance(): any;
|
package/exports/token.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { restoreBalances, restoreApprovals } from './helpers.js';
|
|
2
2
|
import Roles from './roles.js';
|
|
3
|
-
import './
|
|
3
|
+
import './meta-D7uruGOw.js';
|
|
4
4
|
|
|
5
5
|
class Token extends Roles {
|
|
6
6
|
/**
|
|
@@ -14,7 +14,7 @@ class Token extends Roles {
|
|
|
14
14
|
/**
|
|
15
15
|
* uint
|
|
16
16
|
*/
|
|
17
|
-
#holders =
|
|
17
|
+
#holders = 0n;
|
|
18
18
|
/**
|
|
19
19
|
* Object => Object => uint
|
|
20
20
|
*/
|
|
@@ -24,9 +24,7 @@ class Token extends Roles {
|
|
|
24
24
|
*/
|
|
25
25
|
#approvals = {};
|
|
26
26
|
#decimals = 18;
|
|
27
|
-
#totalSupply =
|
|
28
|
-
#maxSupply = BigInt(0);
|
|
29
|
-
#stakingContract;
|
|
27
|
+
#totalSupply = 0n;
|
|
30
28
|
constructor(name, symbol, decimals = 18, state) {
|
|
31
29
|
if (!name)
|
|
32
30
|
throw new Error(`name undefined`);
|
|
@@ -38,10 +36,6 @@ class Token extends Roles {
|
|
|
38
36
|
this.#approvals = restoreApprovals(state.approvals);
|
|
39
37
|
this.#holders = BigInt(state.holders);
|
|
40
38
|
this.#totalSupply = BigInt(state.totalSupply);
|
|
41
|
-
this.#name = name;
|
|
42
|
-
this.#symbol = symbol;
|
|
43
|
-
this.#decimals = decimals;
|
|
44
|
-
this.#maxSupply = BigInt(state.maxSupply);
|
|
45
39
|
}
|
|
46
40
|
else {
|
|
47
41
|
this.#name = name;
|
|
@@ -52,26 +46,18 @@ class Token extends Roles {
|
|
|
52
46
|
// enables snapshotting
|
|
53
47
|
// needs dev attention so nothing breaks after snapshot happens
|
|
54
48
|
// iow everything that is not static needs to be included in the stateObject
|
|
55
|
-
// TODO: implement snapshotting test
|
|
56
49
|
/**
|
|
57
50
|
* @return {Object} {holders, balances, ...}
|
|
58
51
|
*/
|
|
59
52
|
get state() {
|
|
60
53
|
return {
|
|
61
54
|
...super.state,
|
|
62
|
-
name: this.#name,
|
|
63
|
-
symbol: this.#symbol,
|
|
64
|
-
decimals: this.#decimals,
|
|
65
55
|
holders: this.holders,
|
|
66
56
|
balances: this.balances,
|
|
67
57
|
approvals: { ...this.#approvals },
|
|
68
|
-
totalSupply: this.totalSupply
|
|
69
|
-
maxSupply: this.#maxSupply
|
|
58
|
+
totalSupply: this.totalSupply
|
|
70
59
|
};
|
|
71
60
|
}
|
|
72
|
-
get maxSupply() {
|
|
73
|
-
return this.#maxSupply;
|
|
74
|
-
}
|
|
75
61
|
get totalSupply() {
|
|
76
62
|
return this.#totalSupply;
|
|
77
63
|
}
|
|
@@ -95,35 +81,15 @@ class Token extends Roles {
|
|
|
95
81
|
}
|
|
96
82
|
mint(to, amount) {
|
|
97
83
|
if (!this.hasRole(msg.sender, 'MINT'))
|
|
98
|
-
throw new Error('
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.#totalSupply = supply;
|
|
102
|
-
this.#increaseBalance(to, amount);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
if (supply <= this.#maxSupply) {
|
|
106
|
-
this.#totalSupply = supply;
|
|
107
|
-
this.#increaseBalance(to, amount);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
throw new Error('amount exceeds max supply');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
84
|
+
throw new Error('not allowed');
|
|
85
|
+
this.#totalSupply = this.#totalSupply + amount;
|
|
86
|
+
this.#increaseBalance(to, amount);
|
|
113
87
|
}
|
|
114
88
|
burn(from, amount) {
|
|
115
|
-
if (!this.hasRole(msg.sender, 'BURN')
|
|
116
|
-
throw new Error('not
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const total = this.#totalSupply - amount;
|
|
120
|
-
if (total >= 0) {
|
|
121
|
-
this.#totalSupply = total;
|
|
122
|
-
this.#decreaseBalance(from, amount);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
throw new Error('amount exceeds total supply');
|
|
126
|
-
}
|
|
89
|
+
if (!this.hasRole(msg.sender, 'BURN'))
|
|
90
|
+
throw new Error('not allowed');
|
|
91
|
+
this.#totalSupply = this.#totalSupply - amount;
|
|
92
|
+
this.#decreaseBalance(from, amount);
|
|
127
93
|
}
|
|
128
94
|
#beforeTransfer(from, to, amount) {
|
|
129
95
|
if (!this.#balances[from] || this.#balances[from] < amount)
|
|
@@ -137,14 +103,14 @@ class Token extends Roles {
|
|
|
137
103
|
}
|
|
138
104
|
#increaseBalance(address, amount) {
|
|
139
105
|
if (!this.#balances[address])
|
|
140
|
-
this.#balances[address] =
|
|
106
|
+
this.#balances[address] = 0n;
|
|
141
107
|
const previousBalance = this.#balances[address];
|
|
142
|
-
this.#balances[address] = this.#balances[address]
|
|
108
|
+
this.#balances[address] = this.#balances[address] + amount;
|
|
143
109
|
this.#updateHolders(address, previousBalance);
|
|
144
110
|
}
|
|
145
111
|
#decreaseBalance(address, amount) {
|
|
146
112
|
const previousBalance = this.#balances[address];
|
|
147
|
-
this.#balances[address] = this.#balances[address]
|
|
113
|
+
this.#balances[address] = this.#balances[address] - amount;
|
|
148
114
|
this.#updateHolders(address, previousBalance);
|
|
149
115
|
}
|
|
150
116
|
balance() {
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -1,16 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { VotingState } from './types.js';
|
|
5
|
-
import Voting from './voting.js';
|
|
6
|
-
export interface PrivateVotingState extends VotingState, ContractCreatorState {
|
|
7
|
-
voters: address[];
|
|
8
|
-
}
|
|
9
|
-
export default class PrivateVoting extends Voting implements IVoting {
|
|
1
|
+
import Meta from '../meta.js';
|
|
2
|
+
import { PrivateVotingState, VoteResult, VoteView } from './types.js';
|
|
3
|
+
export default class PrivateVoting extends Meta {
|
|
10
4
|
#private;
|
|
11
5
|
constructor(state: PrivateVotingState);
|
|
12
|
-
get
|
|
13
|
-
|
|
6
|
+
get votes(): {
|
|
7
|
+
[x: string]: import("./types.js").Vote;
|
|
8
|
+
};
|
|
9
|
+
get voters(): {
|
|
10
|
+
[x: number]: string;
|
|
11
|
+
length: number;
|
|
12
|
+
toString(): string;
|
|
13
|
+
toLocaleString(): string;
|
|
14
|
+
pop(): string;
|
|
15
|
+
push(...items: string[]): number;
|
|
16
|
+
concat(...items: ConcatArray<string>[]): string[];
|
|
17
|
+
concat(...items: (string | ConcatArray<string>)[]): string[];
|
|
18
|
+
join(separator?: string): string;
|
|
19
|
+
reverse(): string[];
|
|
20
|
+
shift(): string;
|
|
21
|
+
slice(start?: number, end?: number): string[];
|
|
22
|
+
sort(compareFn?: (a: string, b: string) => number): string[];
|
|
23
|
+
splice(start: number, deleteCount?: number): string[];
|
|
24
|
+
splice(start: number, deleteCount: number, ...items: string[]): string[];
|
|
25
|
+
unshift(...items: string[]): number;
|
|
26
|
+
indexOf(searchElement: string, fromIndex?: number): number;
|
|
27
|
+
lastIndexOf(searchElement: string, fromIndex?: number): number;
|
|
28
|
+
every<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[];
|
|
29
|
+
every(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
|
|
30
|
+
some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
|
|
31
|
+
forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void;
|
|
32
|
+
map<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[];
|
|
33
|
+
filter<S_1 extends string>(predicate: (value: string, index: number, array: string[]) => value is S_1, thisArg?: any): S_1[];
|
|
34
|
+
filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
|
|
35
|
+
reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
|
|
36
|
+
reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
|
|
37
|
+
reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: string, currentIndex: number, array: string[]) => U_1, initialValue: U_1): U_1;
|
|
38
|
+
reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
|
|
39
|
+
reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
|
|
40
|
+
reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: string, currentIndex: number, array: string[]) => U_2, initialValue: U_2): U_2;
|
|
41
|
+
find<S_2 extends string>(predicate: (value: string, index: number, obj: string[]) => value is S_2, thisArg?: any): S_2;
|
|
42
|
+
find(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string;
|
|
43
|
+
findIndex(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): number;
|
|
44
|
+
fill(value: string, start?: number, end?: number): string[];
|
|
45
|
+
copyWithin(target: number, start: number, end?: number): string[];
|
|
46
|
+
entries(): IterableIterator<[number, string]>;
|
|
47
|
+
keys(): IterableIterator<number>;
|
|
48
|
+
values(): IterableIterator<string>;
|
|
49
|
+
includes(searchElement: string, fromIndex?: number): boolean;
|
|
50
|
+
flatMap<U_3, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U_3 | readonly U_3[], thisArg?: This): U_3[];
|
|
51
|
+
flat<A, D extends number = 1>(this: A, depth?: D): FlatArray<A, D>[];
|
|
52
|
+
at(index: number): string;
|
|
53
|
+
[Symbol.iterator](): IterableIterator<string>;
|
|
54
|
+
[Symbol.unscopables]: {
|
|
55
|
+
[x: number]: boolean;
|
|
56
|
+
length?: boolean;
|
|
57
|
+
toString?: boolean;
|
|
58
|
+
toLocaleString?: boolean;
|
|
59
|
+
pop?: boolean;
|
|
60
|
+
push?: boolean;
|
|
61
|
+
concat?: boolean;
|
|
62
|
+
join?: boolean;
|
|
63
|
+
reverse?: boolean;
|
|
64
|
+
shift?: boolean;
|
|
65
|
+
slice?: boolean;
|
|
66
|
+
sort?: boolean;
|
|
67
|
+
splice?: boolean;
|
|
68
|
+
unshift?: boolean;
|
|
69
|
+
indexOf?: boolean;
|
|
70
|
+
lastIndexOf?: boolean;
|
|
71
|
+
every?: boolean;
|
|
72
|
+
some?: boolean;
|
|
73
|
+
forEach?: boolean;
|
|
74
|
+
map?: boolean;
|
|
75
|
+
filter?: boolean;
|
|
76
|
+
reduce?: boolean;
|
|
77
|
+
reduceRight?: boolean;
|
|
78
|
+
find?: boolean;
|
|
79
|
+
findIndex?: boolean;
|
|
80
|
+
fill?: boolean;
|
|
81
|
+
copyWithin?: boolean;
|
|
82
|
+
entries?: boolean;
|
|
83
|
+
keys?: boolean;
|
|
84
|
+
values?: boolean;
|
|
85
|
+
includes?: boolean;
|
|
86
|
+
flatMap?: boolean;
|
|
87
|
+
flat?: boolean;
|
|
88
|
+
at?: boolean;
|
|
89
|
+
[Symbol.iterator]?: boolean;
|
|
90
|
+
readonly [Symbol.unscopables]?: boolean;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
get votingDisabled(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
get state(): {};
|
|
98
|
+
get inProgress(): VoteView[];
|
|
99
|
+
/**
|
|
100
|
+
* create vote
|
|
101
|
+
* @param {string} vote
|
|
102
|
+
* @param {string} description
|
|
103
|
+
* @param {number} endTime
|
|
104
|
+
* @param {string} method function to run when agree amount is bigger
|
|
105
|
+
*/
|
|
106
|
+
createVote(title: string, description: string, endTime: EpochTimeStamp, method: string, args?: any[]): void;
|
|
107
|
+
canVote(address: address): boolean;
|
|
108
|
+
vote(voteId: string, vote: VoteResult): void;
|
|
109
|
+
disableVoting(): void;
|
|
14
110
|
grantVotingPower(address: address, voteId: string): void;
|
|
15
111
|
revokeVotingPower(address: address, voteId: string): void;
|
|
112
|
+
sync(): void;
|
|
16
113
|
}
|
|
@@ -1,11 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { VotingState } from './types.js';
|
|
3
|
-
import Voting from './voting.js';
|
|
4
|
-
export declare interface PublicVotingState extends VotingState, ContractCreatorState {
|
|
5
|
-
}
|
|
1
|
+
import Meta from '../meta.js';
|
|
2
|
+
import { VotingState, VoteResult } from './types.js';
|
|
6
3
|
/**
|
|
7
|
-
* allows everybody that has a balance greater or
|
|
4
|
+
* allows everybody that has a balance greater or equal to tokenAmountToReceive to vote
|
|
8
5
|
*/
|
|
9
|
-
export default class PublicVoting extends
|
|
10
|
-
|
|
6
|
+
export default class PublicVoting extends Meta {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(state: VotingState);
|
|
9
|
+
get votes(): {
|
|
10
|
+
[x: string]: import("./types.js").Vote;
|
|
11
|
+
};
|
|
12
|
+
get votingDuration(): number;
|
|
13
|
+
get votingDisabled(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
get state(): {
|
|
18
|
+
votes: {
|
|
19
|
+
[id: string]: import("./types.js").Vote;
|
|
20
|
+
};
|
|
21
|
+
votingDisabled: boolean;
|
|
22
|
+
votingDuration: number;
|
|
23
|
+
};
|
|
24
|
+
get inProgress(): {
|
|
25
|
+
id: string;
|
|
26
|
+
title: string;
|
|
27
|
+
method: string;
|
|
28
|
+
args: any[];
|
|
29
|
+
description: string;
|
|
30
|
+
endTime: number;
|
|
31
|
+
results?: {
|
|
32
|
+
[address: string]: VoteResult;
|
|
33
|
+
};
|
|
34
|
+
finished?: boolean;
|
|
35
|
+
enoughVotes?: boolean;
|
|
36
|
+
}[];
|
|
37
|
+
/**
|
|
38
|
+
* create vote
|
|
39
|
+
* @param {string} vote
|
|
40
|
+
* @param {string} description
|
|
41
|
+
* @param {number} endTime
|
|
42
|
+
* @param {string} method function to run when agree amount is bigger
|
|
43
|
+
*/
|
|
44
|
+
createVote(title: string, description: string, endTime: EpochTimeStamp, method: string, args?: any[]): void;
|
|
45
|
+
vote(voteId: string, vote: VoteResult): Promise<void>;
|
|
46
|
+
disableVoting(): void;
|
|
47
|
+
_sync(): void;
|
|
11
48
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { MetaState } from '../types.js';
|
|
2
|
+
export interface VotingState extends MetaState {
|
|
3
|
+
votes: {
|
|
4
|
+
[id: string]: Vote;
|
|
5
|
+
};
|
|
6
|
+
votingDisabled: boolean;
|
|
7
|
+
votingDuration: number;
|
|
8
|
+
}
|
|
9
|
+
export interface PrivateVotingState extends VotingState {
|
|
10
|
+
voters: address[];
|
|
11
|
+
}
|
|
1
12
|
export type VoteResult = 0 | 0.5 | 1;
|
|
2
13
|
export type Vote = {
|
|
3
14
|
title: string;
|
|
@@ -11,13 +22,6 @@ export type Vote = {
|
|
|
11
22
|
finished?: boolean;
|
|
12
23
|
enoughVotes?: boolean;
|
|
13
24
|
};
|
|
14
|
-
export interface VotingState {
|
|
15
|
-
votes: {
|
|
16
|
-
[id: string]: Vote;
|
|
17
|
-
};
|
|
18
|
-
votingDisabled: boolean;
|
|
19
|
-
votingDuration: number;
|
|
20
|
-
}
|
|
21
25
|
export interface VoteView extends Vote {
|
|
22
26
|
id: string;
|
|
23
27
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/standards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Contract standards",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,19 +24,13 @@
|
|
|
24
24
|
"import": "./exports/private-voting.js",
|
|
25
25
|
"types": "./exports/private-voting.d.ts"
|
|
26
26
|
},
|
|
27
|
-
"./contract-creator": {
|
|
28
|
-
"import": "./exports/contract-creator.js",
|
|
29
|
-
"types": "./exports/contract-creator.d.ts"
|
|
30
|
-
},
|
|
31
27
|
"./token-receiver": {
|
|
32
28
|
"import": "./exports/token-receiver.js",
|
|
33
29
|
"types": "./exports/token-receiver.d.ts"
|
|
34
30
|
},
|
|
35
|
-
"./interfaces/i-voting": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
"./interfaces/i-token": {
|
|
39
|
-
"types": "./exports/interfaces/i-token.d.ts"
|
|
31
|
+
"./interfaces/i-public-voting": {
|
|
32
|
+
"import": "./exports/i-public-voting.js",
|
|
33
|
+
"types": "./exports/i-public-voting.d.ts"
|
|
40
34
|
},
|
|
41
35
|
"./helpers": {
|
|
42
36
|
"import": "./exports/helpers.js",
|
|
@@ -45,13 +39,13 @@
|
|
|
45
39
|
"./token.js": "./exports/token.js",
|
|
46
40
|
"./roles.js": "./exports/roles.js",
|
|
47
41
|
"./public-voting.js": "./exports/public-voting.js",
|
|
42
|
+
"./interfaces/i-public-voting.js": "./exports/i-public-voting.js",
|
|
48
43
|
"./private-voting.js": "./exports/private-voting.js",
|
|
49
|
-
"./contract-creator.js": "./exports/contract-creator.js",
|
|
50
44
|
"./helpers.js": "./exports/helpers.js"
|
|
51
45
|
},
|
|
52
46
|
"scripts": {
|
|
53
47
|
"build": "rollup -c",
|
|
54
|
-
"test": "
|
|
48
|
+
"test": "node --test ./test/**/*.js"
|
|
55
49
|
},
|
|
56
50
|
"repository": {
|
|
57
51
|
"type": "git",
|
|
@@ -65,11 +59,9 @@
|
|
|
65
59
|
},
|
|
66
60
|
"homepage": "https://github.com/ArteonToken/standards#readme",
|
|
67
61
|
"devDependencies": {
|
|
68
|
-
"@leofcoin/types": "^1.0.
|
|
69
|
-
"@rollup/plugin-typescript": "^
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"rollup": "^4.22.1",
|
|
73
|
-
"tslib": "^2.7.0"
|
|
62
|
+
"@leofcoin/global-types": "^1.0.2",
|
|
63
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
64
|
+
"rollup": "^4.54.0",
|
|
65
|
+
"tslib": "^2.8.1"
|
|
74
66
|
}
|
|
75
67
|
}
|
package/rollup.config.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import typescript from '@rollup/plugin-typescript'
|
|
2
|
-
import { execSync } from 'child_process'
|
|
3
|
-
|
|
4
|
-
// const templates = (await readdir('./src/templates')).map(path => join('./src/templates', path))
|
|
5
|
-
const clean = () => {
|
|
6
|
-
execSync('rm -rf www/*.js')
|
|
7
|
-
return
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default [
|
|
11
|
-
{
|
|
12
|
-
input: [
|
|
13
|
-
'src/index.ts',
|
|
14
|
-
'src/token.ts',
|
|
15
|
-
'src/roles.ts',
|
|
16
|
-
'src/voting/public-voting.ts',
|
|
17
|
-
'src/voting/
|
|
18
|
-
'src/
|
|
19
|
-
'src/
|
|
20
|
-
'src/token-receiver.ts'
|
|
21
|
-
],
|
|
22
|
-
output: {
|
|
23
|
-
dir: './exports',
|
|
24
|
-
format: 'es'
|
|
25
|
-
},
|
|
26
|
-
plugins: [typescript()]
|
|
27
|
-
}
|
|
28
|
-
]
|
|
1
|
+
import typescript from '@rollup/plugin-typescript'
|
|
2
|
+
import { execSync } from 'child_process'
|
|
3
|
+
|
|
4
|
+
// const templates = (await readdir('./src/templates')).map(path => join('./src/templates', path))
|
|
5
|
+
const clean = () => {
|
|
6
|
+
execSync('rm -rf www/*.js')
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default [
|
|
11
|
+
{
|
|
12
|
+
input: [
|
|
13
|
+
'src/index.ts',
|
|
14
|
+
'src/token.ts',
|
|
15
|
+
'src/roles.ts',
|
|
16
|
+
'src/voting/public-voting.ts',
|
|
17
|
+
'src/voting/interfaces/i-public-voting.ts',
|
|
18
|
+
'src/voting/private-voting.ts',
|
|
19
|
+
'src/helpers.ts',
|
|
20
|
+
'src/token-receiver.ts'
|
|
21
|
+
],
|
|
22
|
+
output: {
|
|
23
|
+
dir: './exports',
|
|
24
|
+
format: 'es'
|
|
25
|
+
},
|
|
26
|
+
plugins: [typescript()]
|
|
27
|
+
}
|
|
28
|
+
]
|
package/src/helpers.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
// when state is stored it get encoded as a string to so we need to reformat balances back to
|
|
2
|
-
export const restoreBalances = (balances) => {
|
|
3
|
-
const _balances = {}
|
|
4
|
-
for (const address in balances) {
|
|
5
|
-
_balances[address] = BigInt(balances[address])
|
|
6
|
-
}
|
|
7
|
-
return _balances
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const restoreApprovals = (approvals) => {
|
|
11
|
-
const _approvals = {}
|
|
12
|
-
for (const owner in approvals) {
|
|
13
|
-
_approvals[owner] = {}
|
|
14
|
-
for (const operator in approvals[owner]) {
|
|
15
|
-
_approvals[owner][operator] = BigInt(approvals[owner][operator])
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return _approvals
|
|
19
|
-
}
|
|
1
|
+
// when state is stored it get encoded as a string to so we need to reformat balances back to BigInts
|
|
2
|
+
export const restoreBalances = (balances) => {
|
|
3
|
+
const _balances = {}
|
|
4
|
+
for (const address in balances) {
|
|
5
|
+
_balances[address] = BigInt(balances[address])
|
|
6
|
+
}
|
|
7
|
+
return _balances
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const restoreApprovals = (approvals) => {
|
|
11
|
+
const _approvals = {}
|
|
12
|
+
for (const owner in approvals) {
|
|
13
|
+
_approvals[owner] = {}
|
|
14
|
+
for (const operator in approvals[owner]) {
|
|
15
|
+
_approvals[owner][operator] = BigInt(approvals[owner][operator])
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return _approvals
|
|
19
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export { default as Roles } from './roles.js'
|
|
3
|
-
export { default as
|
|
4
|
-
export { default as
|
|
5
|
-
export { default as
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export { default as Meta } from './meta.js'
|
|
2
|
+
export { default as Roles } from './roles.js'
|
|
3
|
+
export { default as Token } from './token.js'
|
|
4
|
+
export { default as TokenReceiver } from './token-receiver.js'
|
|
5
|
+
export { default as PublicVoting } from './voting/public-voting.js'
|
|
6
|
+
export { default as PrivateVoting } from './voting/private-voting.js'
|
|
7
|
+
|
|
8
|
+
export * from './helpers.js'
|