@leofcoin/standards 0.2.2 → 0.2.4
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/.changeset/config.json +11 -11
- package/exports/contract-creator.d.ts +10 -0
- package/exports/contract-creator.js +20 -0
- package/exports/index.js +1 -0
- package/exports/roles.d.ts +9 -5
- package/exports/roles.js +9 -6
- package/exports/token-receiver.d.ts +1 -0
- package/exports/token-receiver.js +4 -0
- package/exports/token.js +1 -0
- package/package.json +6 -1
- package/rollup.config.js +1 -0
- package/src/contract-creator.ts +24 -0
- package/src/roles.ts +14 -7
- package/src/token-receiver.ts +5 -0
package/.changeset/config.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
|
|
3
|
-
"changelog": "@changesets/cli/changelog",
|
|
4
|
-
"commit": true,
|
|
5
|
-
"fixed": [],
|
|
6
|
-
"linked": [],
|
|
7
|
-
"access": "public",
|
|
8
|
-
"baseBranch": "main",
|
|
9
|
-
"updateInternalDependencies": "patch",
|
|
10
|
-
"ignore": []
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
|
|
3
|
+
"changelog": "@changesets/cli/changelog",
|
|
4
|
+
"commit": true,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "main",
|
|
9
|
+
"updateInternalDependencies": "patch",
|
|
10
|
+
"ignore": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ContractCreatorState = {
|
|
2
|
+
contractCreator: address;
|
|
3
|
+
};
|
|
4
|
+
export default class ContractCreator {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(state: ContractCreatorState);
|
|
7
|
+
get _contractCreator(): string;
|
|
8
|
+
get state(): ContractCreatorState;
|
|
9
|
+
get _isContractCreator(): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class ContractCreator {
|
|
2
|
+
#creator;
|
|
3
|
+
constructor(state) {
|
|
4
|
+
if (state)
|
|
5
|
+
this.#creator = state.contractCreator;
|
|
6
|
+
else
|
|
7
|
+
this.#creator = msg.sender;
|
|
8
|
+
}
|
|
9
|
+
get _contractCreator() {
|
|
10
|
+
return this.#creator;
|
|
11
|
+
}
|
|
12
|
+
get state() {
|
|
13
|
+
return { contractCreator: this.#creator };
|
|
14
|
+
}
|
|
15
|
+
get _isContractCreator() {
|
|
16
|
+
return msg.sender === this.#creator;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { ContractCreator as default };
|
package/exports/index.js
CHANGED
|
@@ -4,3 +4,4 @@ export { default as TokenReceiver } from './token-receiver.js';
|
|
|
4
4
|
export { default as PublicVoting } from './public-voting.js';
|
|
5
5
|
export { default as PrivateVoting } from './private-voting.js';
|
|
6
6
|
export { restoreApprovals, restoreBalances } from './helpers.js';
|
|
7
|
+
import './contract-creator.js';
|
package/exports/roles.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import ContractCreator, { ContractCreatorState } from './contract-creator.js';
|
|
2
|
+
export interface RolesState extends ContractCreatorState {
|
|
3
|
+
roles: {
|
|
4
4
|
[index: string]: address[];
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export default class Roles extends ContractCreator {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(state: any);
|
|
6
10
|
/**
|
|
7
11
|
*
|
|
8
12
|
*/
|
|
9
|
-
get state():
|
|
13
|
+
get state(): RolesState;
|
|
10
14
|
get roles(): {};
|
|
11
15
|
/**
|
|
12
16
|
* @param {address} address
|
package/exports/roles.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import ContractCreator from './contract-creator.js';
|
|
2
|
+
|
|
3
|
+
class Roles extends ContractCreator {
|
|
2
4
|
/**
|
|
3
5
|
* Object => Array
|
|
4
6
|
*/
|
|
@@ -7,14 +9,15 @@ class Roles {
|
|
|
7
9
|
MINT: [],
|
|
8
10
|
BURN: []
|
|
9
11
|
};
|
|
10
|
-
constructor(
|
|
12
|
+
constructor(state) {
|
|
13
|
+
super(state);
|
|
11
14
|
// allow devs to set their own roles but always keep the default ones included
|
|
12
15
|
// also allows roles to be loaded from the stateStore
|
|
13
16
|
// carefull when including the roles make sure to add the owner
|
|
14
17
|
// because no roles are granted by default when using custom roles
|
|
15
|
-
if (roles) {
|
|
16
|
-
if (roles instanceof Object) {
|
|
17
|
-
this.#roles = { ...roles, ...this.#roles };
|
|
18
|
+
if (state.roles) {
|
|
19
|
+
if (state.roles instanceof Object) {
|
|
20
|
+
this.#roles = { ...state.roles, ...this.#roles };
|
|
18
21
|
}
|
|
19
22
|
else {
|
|
20
23
|
throw new TypeError(`expected roles to be an object`);
|
|
@@ -29,7 +32,7 @@ class Roles {
|
|
|
29
32
|
*
|
|
30
33
|
*/
|
|
31
34
|
get state() {
|
|
32
|
-
return { roles: this.roles };
|
|
35
|
+
return { ...super.state, roles: this.roles };
|
|
33
36
|
}
|
|
34
37
|
get roles() {
|
|
35
38
|
return { ...this.#roles };
|
|
@@ -40,6 +40,7 @@ export default class TokenReceiver extends PublicVoting implements IPublicVoting
|
|
|
40
40
|
* @returns {boolean} promise
|
|
41
41
|
*/
|
|
42
42
|
_burnTokenToReceive(): Promise<boolean>;
|
|
43
|
+
_canPay(): Promise<any>;
|
|
43
44
|
changeVoteType(type: TokenReceiverState['voteType']): Promise<void>;
|
|
44
45
|
getTokensOut(amount: typeof BigNumber, receiver: address): void;
|
|
45
46
|
changeTokenAmountToReceive(): void;
|
|
@@ -76,6 +76,10 @@ class TokenReceiver extends PublicVoting {
|
|
|
76
76
|
async _burnTokenToReceive() {
|
|
77
77
|
return msg.staticCall(this.#tokenToReceive, 'burn', [this.#tokenAmountToReceive]);
|
|
78
78
|
}
|
|
79
|
+
async _canPay() {
|
|
80
|
+
const amount = await msg.call(this.#tokenToReceive, 'balance', []);
|
|
81
|
+
return amount.gte(this.tokenAmountToReceive);
|
|
82
|
+
}
|
|
79
83
|
#changeTokenToReceive(address) {
|
|
80
84
|
this.#tokenToReceive = address;
|
|
81
85
|
}
|
package/exports/token.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/standards",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Contract standards",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,6 +24,10 @@
|
|
|
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
|
+
},
|
|
27
31
|
"./token-receiver": {
|
|
28
32
|
"import": "./exports/token-receiver.js",
|
|
29
33
|
"types": "./exports/token-receiver.d.ts"
|
|
@@ -39,6 +43,7 @@
|
|
|
39
43
|
"./roles.js": "./exports/roles.js",
|
|
40
44
|
"./public-voting.js": "./exports/public-voting.js",
|
|
41
45
|
"./private-voting.js": "./exports/private-voting.js",
|
|
46
|
+
"./contract-creator.js": "./exports/contract-creator.js",
|
|
42
47
|
"./helpers.js": "./exports/helpers.js"
|
|
43
48
|
},
|
|
44
49
|
"scripts": {
|
package/rollup.config.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ContractCreatorState = {
|
|
2
|
+
contractCreator: address
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export default class ContractCreator {
|
|
6
|
+
#creator: address
|
|
7
|
+
|
|
8
|
+
constructor(state: ContractCreatorState) {
|
|
9
|
+
if (state) this.#creator = state.contractCreator
|
|
10
|
+
else this.#creator = msg.sender
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get _contractCreator() {
|
|
14
|
+
return this.#creator
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get state(): ContractCreatorState {
|
|
18
|
+
return { contractCreator: this.#creator }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get _isContractCreator() {
|
|
22
|
+
return msg.sender === this.#creator
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/roles.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import ContractCreator, { ContractCreatorState } from './contract-creator.js'
|
|
2
|
+
|
|
3
|
+
export interface RolesState extends ContractCreatorState {
|
|
4
|
+
roles: { [index: string]: address[] }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default class Roles extends ContractCreator {
|
|
2
8
|
/**
|
|
3
9
|
* Object => Array
|
|
4
10
|
*/
|
|
@@ -8,14 +14,15 @@ export default class Roles {
|
|
|
8
14
|
BURN: []
|
|
9
15
|
}
|
|
10
16
|
|
|
11
|
-
constructor(
|
|
17
|
+
constructor(state) {
|
|
18
|
+
super(state)
|
|
12
19
|
// allow devs to set their own roles but always keep the default ones included
|
|
13
20
|
// also allows roles to be loaded from the stateStore
|
|
14
21
|
// carefull when including the roles make sure to add the owner
|
|
15
22
|
// because no roles are granted by default when using custom roles
|
|
16
|
-
if (roles) {
|
|
17
|
-
if (roles instanceof Object) {
|
|
18
|
-
this.#roles = { ...roles, ...this.#roles }
|
|
23
|
+
if (state.roles) {
|
|
24
|
+
if (state.roles instanceof Object) {
|
|
25
|
+
this.#roles = { ...state.roles, ...this.#roles }
|
|
19
26
|
} else {
|
|
20
27
|
throw new TypeError(`expected roles to be an object`)
|
|
21
28
|
}
|
|
@@ -28,8 +35,8 @@ export default class Roles {
|
|
|
28
35
|
/**
|
|
29
36
|
*
|
|
30
37
|
*/
|
|
31
|
-
get state():
|
|
32
|
-
return { roles: this.roles }
|
|
38
|
+
get state(): RolesState {
|
|
39
|
+
return { ...super.state, roles: this.roles }
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
get roles(): {} {
|
package/src/token-receiver.ts
CHANGED
|
@@ -98,6 +98,11 @@ export default class TokenReceiver extends PublicVoting implements IPublicVoting
|
|
|
98
98
|
return msg.staticCall(this.#tokenToReceive, 'burn', [this.#tokenAmountToReceive])
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
async _canPay() {
|
|
102
|
+
const amount = await msg.call(this.#tokenToReceive, 'balance', [])
|
|
103
|
+
return amount.gte(this.tokenAmountToReceive)
|
|
104
|
+
}
|
|
105
|
+
|
|
101
106
|
#changeTokenToReceive(address: address) {
|
|
102
107
|
this.#tokenToReceive = address
|
|
103
108
|
}
|