@leofcoin/standards 0.3.0 → 0.3.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @leofcoin/standards
2
2
 
3
- ## Unreleased
3
+ ## 0.3.0
4
4
 
5
5
  ### Changed
6
6
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ### Added
11
11
 
12
- - GitHub Actions workflow for automated testing across Node.js versions 18.x, 20.x, 22.x
12
+ - GitHub Actions workflow for automated testing across Node.js versions 22.x and latest
13
13
  - Test status badge in README
14
14
  - Comprehensive unit tests for helpers, roles, token, and voting modules
15
15
  - Meta base class for state management
@@ -4,4 +4,5 @@ export { default as Token } from './token.js';
4
4
  export { default as TokenReceiver } from './token-receiver.js';
5
5
  export { default as PublicVoting } from './voting/public-voting.js';
6
6
  export { default as PrivateVoting } from './voting/private-voting.js';
7
+ export type * from './interfaces.js';
7
8
  export * from './helpers.js';
@@ -0,0 +1,47 @@
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
+ }
@@ -0,0 +1 @@
1
+
package/exports/meta.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MetaState } from './types.js';
1
+ import { MetaState } from './interfaces.js';
2
2
  export default class Meta {
3
3
  #private;
4
4
  constructor(state?: MetaState);
@@ -1,5 +1,5 @@
1
1
  import Meta from './meta.js';
2
- import { RolesState } from './types.js';
2
+ import { RolesState } from './interfaces.js';
3
3
  export default class Roles extends Meta {
4
4
  #private;
5
5
  constructor(state?: RolesState);
@@ -1,6 +1,6 @@
1
1
  import { IPublicVoting } from './voting/interfaces/i-public-voting.js';
2
2
  import PublicVoting from './voting/public-voting.js';
3
- import { VotingState } from './voting/types.js';
3
+ import { VotingState } from './interfaces.js';
4
4
  export interface TokenReceiverState extends VotingState {
5
5
  tokenToReceive: address;
6
6
  tokenReceiver: address;
@@ -19,7 +19,7 @@ export default class TokenReceiver extends PublicVoting implements IPublicVoting
19
19
  tokenAmountToReceive: bigint;
20
20
  voteType: "burn" | "transfer";
21
21
  votes: {
22
- [id: string]: import("./voting/types.js").Vote;
22
+ [id: string]: import("./interfaces.js").Vote;
23
23
  };
24
24
  votingDisabled: boolean;
25
25
  votingDuration: number;
@@ -1,5 +1,5 @@
1
1
  import Roles from './roles.js';
2
- import { TokenState } from './types.js';
2
+ import { TokenState } from './interfaces.js';
3
3
  export default class Token extends Roles {
4
4
  #private;
5
5
  constructor(name: string, symbol: string, decimals?: number, state?: TokenState);
@@ -19,3 +19,29 @@ export declare interface TokenState extends RolesState {
19
19
  };
20
20
  totalSupply: bigint;
21
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
+ }
@@ -0,0 +1 @@
1
+
@@ -1,16 +1,17 @@
1
1
  import Meta from '../meta.js';
2
- import { PrivateVotingState, VoteResult, VoteView } from './types.js';
2
+ import { PrivateVotingState, VoteResult, VoteView } from '../interfaces.js';
3
3
  export default class PrivateVoting extends Meta {
4
4
  #private;
5
5
  constructor(state: PrivateVotingState);
6
6
  get votes(): {
7
- [x: string]: import("./types.js").Vote;
7
+ [id: string]: import("../interfaces.js").Vote;
8
8
  };
9
9
  get voters(): {
10
- [x: number]: string;
10
+ [n: number]: string;
11
11
  length: number;
12
12
  toString(): string;
13
13
  toLocaleString(): string;
14
+ toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
14
15
  pop(): string;
15
16
  push(...items: string[]): number;
16
17
  concat(...items: ConcatArray<string>[]): string[];
@@ -30,27 +31,27 @@ export default class PrivateVoting extends Meta {
30
31
  some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
31
32
  forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void;
32
33
  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<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): S[];
34
35
  filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
35
36
  reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
36
37
  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
+ reduce<U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U;
38
39
  reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
39
40
  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;
41
+ reduceRight<U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U;
42
+ find<S extends string>(predicate: (value: string, index: number, obj: string[]) => value is S, thisArg?: any): S;
42
43
  find(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string;
43
44
  findIndex(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): number;
44
45
  fill(value: string, start?: number, end?: number): string[];
45
46
  copyWithin(target: number, start: number, end?: number): string[];
46
- entries(): IterableIterator<[number, string]>;
47
- keys(): IterableIterator<number>;
48
- values(): IterableIterator<string>;
47
+ entries(): ArrayIterator<[number, string]>;
48
+ keys(): ArrayIterator<number>;
49
+ values(): ArrayIterator<string>;
49
50
  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
+ flatMap<U, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U | readonly U[], thisArg?: This): U[];
51
52
  flat<A, D extends number = 1>(this: A, depth?: D): FlatArray<A, D>[];
52
53
  at(index: number): string;
53
- [Symbol.iterator](): IterableIterator<string>;
54
+ [Symbol.iterator](): ArrayIterator<string>;
54
55
  [Symbol.unscopables]: {
55
56
  [x: number]: boolean;
56
57
  length?: boolean;
@@ -1,5 +1,5 @@
1
1
  import Meta from '../meta.js';
2
- import { VotingState, VoteResult } from './types.js';
2
+ import { VotingState, VoteResult } from '../interfaces.js';
3
3
  /**
4
4
  * allows everybody that has a balance greater or equal to tokenAmountToReceive to vote
5
5
  */
@@ -7,7 +7,7 @@ export default class PublicVoting extends Meta {
7
7
  #private;
8
8
  constructor(state: VotingState);
9
9
  get votes(): {
10
- [x: string]: import("./types.js").Vote;
10
+ [id: string]: import("../interfaces.js").Vote;
11
11
  };
12
12
  get votingDuration(): number;
13
13
  get votingDisabled(): boolean;
@@ -16,7 +16,7 @@ export default class PublicVoting extends Meta {
16
16
  */
17
17
  get state(): {
18
18
  votes: {
19
- [id: string]: import("./types.js").Vote;
19
+ [id: string]: import("../interfaces.js").Vote;
20
20
  };
21
21
  votingDisabled: boolean;
22
22
  votingDuration: number;
@@ -27,7 +27,7 @@ export default class PublicVoting extends Meta {
27
27
  method: string;
28
28
  args: any[];
29
29
  description: string;
30
- endTime: number;
30
+ endTime: EpochTimeStamp;
31
31
  results?: {
32
32
  [address: string]: VoteResult;
33
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/standards",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Contract standards",
5
5
  "type": "module",
6
6
  "exports": {
@@ -8,40 +8,98 @@
8
8
  "import": "./exports/index.js",
9
9
  "types": "./exports/index.d.ts"
10
10
  },
11
- "./token": {
12
- "import": "./exports/token.js",
13
- "types": "./exports/token.d.ts"
11
+ "./helpers": {
12
+ "import": "./exports/helpers.js",
13
+ "types": "./exports/helpers.d.ts"
14
14
  },
15
- "./roles": {
16
- "import": "./exports/roles.js",
17
- "types": "./exports/roles.d.ts"
15
+ "./helpers.js": {
16
+ "import": "./exports/helpers.js",
17
+ "types": "./exports/helpers.d.ts"
18
18
  },
19
- "./public-voting": {
20
- "import": "./exports/public-voting.js",
21
- "types": "./exports/public-voting.d.ts"
19
+ "./i-public-voting": {
20
+ "import": "./exports/i-public-voting.js",
21
+ "types": "./exports/voting/interfaces/i-public-voting.d.ts"
22
+ },
23
+ "./i-public-voting.js": {
24
+ "import": "./exports/i-public-voting.js",
25
+ "types": "./exports/voting/interfaces/i-public-voting.d.ts"
26
+ },
27
+ "./index.js": {
28
+ "import": "./exports/index.js",
29
+ "types": "./exports/index.d.ts"
30
+ },
31
+ "./interfaces": {
32
+ "import": "./exports/interfaces.js",
33
+ "types": "./exports/interfaces.d.ts"
34
+ },
35
+ "./interfaces.js": {
36
+ "import": "./exports/interfaces.js",
37
+ "types": "./exports/interfaces.d.ts"
38
+ },
39
+ "./meta": {
40
+ "import": "./exports/meta.js",
41
+ "types": "./exports/meta.d.ts"
42
+ },
43
+ "./meta.js": {
44
+ "import": "./exports/meta.js",
45
+ "types": "./exports/meta.d.ts"
22
46
  },
23
47
  "./private-voting": {
24
48
  "import": "./exports/private-voting.js",
25
- "types": "./exports/private-voting.d.ts"
49
+ "types": "./exports/voting/private-voting.d.ts"
50
+ },
51
+ "./private-voting.js": {
52
+ "import": "./exports/private-voting.js",
53
+ "types": "./exports/voting/private-voting.d.ts"
54
+ },
55
+ "./public-voting": {
56
+ "import": "./exports/public-voting.js",
57
+ "types": "./exports/voting/interfaces/public-voting.d.ts"
58
+ },
59
+ "./public-voting.js": {
60
+ "import": "./exports/public-voting.js",
61
+ "types": "./exports/voting/interfaces/public-voting.d.ts"
62
+ },
63
+ "./roles": {
64
+ "import": "./exports/roles.js",
65
+ "types": "./exports/roles.d.ts"
66
+ },
67
+ "./roles.js": {
68
+ "import": "./exports/roles.js",
69
+ "types": "./exports/roles.d.ts"
26
70
  },
27
71
  "./token-receiver": {
28
72
  "import": "./exports/token-receiver.js",
29
73
  "types": "./exports/token-receiver.d.ts"
30
74
  },
31
- "./interfaces/i-public-voting": {
32
- "import": "./exports/i-public-voting.js",
33
- "types": "./exports/i-public-voting.d.ts"
75
+ "./token-receiver.js": {
76
+ "import": "./exports/token-receiver.js",
77
+ "types": "./exports/token-receiver.d.ts"
34
78
  },
35
- "./helpers": {
36
- "import": "./exports/helpers.js",
37
- "types": "./exports/helpers.d.ts"
79
+ "./token": {
80
+ "import": "./exports/token.js",
81
+ "types": "./exports/token.d.ts"
82
+ },
83
+ "./token.js": {
84
+ "import": "./exports/token.js",
85
+ "types": "./exports/token.d.ts"
86
+ },
87
+ "./types": {
88
+ "import": "./exports/types.js",
89
+ "types": "./exports/voting/types.d.ts"
90
+ },
91
+ "./types.js": {
92
+ "import": "./exports/types.js",
93
+ "types": "./exports/voting/types.d.ts"
94
+ },
95
+ "./voting": {
96
+ "import": "./exports/voting.js",
97
+ "types": "./exports/voting.d.ts"
38
98
  },
39
- "./token.js": "./exports/token.js",
40
- "./roles.js": "./exports/roles.js",
41
- "./public-voting.js": "./exports/public-voting.js",
42
- "./interfaces/i-public-voting.js": "./exports/i-public-voting.js",
43
- "./private-voting.js": "./exports/private-voting.js",
44
- "./helpers.js": "./exports/helpers.js"
99
+ "./voting.js": {
100
+ "import": "./exports/voting.js",
101
+ "types": "./exports/voting.d.ts"
102
+ }
45
103
  },
46
104
  "scripts": {
47
105
  "build": "rollup -c",
@@ -62,6 +120,7 @@
62
120
  "@leofcoin/global-types": "^1.0.2",
63
121
  "@rollup/plugin-typescript": "^12.3.0",
64
122
  "rollup": "^4.54.0",
123
+ "rollup-plugin-auto-exports": "^1.1.1",
65
124
  "tslib": "^2.8.1"
66
125
  }
67
126
  }
package/rollup.config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import typescript from '@rollup/plugin-typescript'
2
2
  import { execSync } from 'child_process'
3
+ import autoExports from 'rollup-plugin-auto-exports'
3
4
 
4
5
  // const templates = (await readdir('./src/templates')).map(path => join('./src/templates', path))
5
6
  const clean = () => {
@@ -17,12 +18,24 @@ export default [
17
18
  'src/voting/interfaces/i-public-voting.ts',
18
19
  'src/voting/private-voting.ts',
19
20
  'src/helpers.ts',
20
- 'src/token-receiver.ts'
21
+ 'src/token-receiver.ts',
22
+ 'src/interfaces.ts'
21
23
  ],
22
24
  output: {
23
25
  dir: './exports',
24
26
  format: 'es'
25
27
  },
26
- plugins: [typescript()]
28
+ plugins: [
29
+ typescript(),
30
+ autoExports({
31
+ exportsDir: 'exports',
32
+ defaultExports: {
33
+ '.': {
34
+ import: 'exports/index.js',
35
+ types: 'exports/index.d.ts'
36
+ }
37
+ }
38
+ })
39
+ ]
27
40
  }
28
41
  ]
package/src/index.ts CHANGED
@@ -4,5 +4,5 @@ export { default as Token } from './token.js'
4
4
  export { default as TokenReceiver } from './token-receiver.js'
5
5
  export { default as PublicVoting } from './voting/public-voting.js'
6
6
  export { default as PrivateVoting } from './voting/private-voting.js'
7
-
7
+ export type * from './interfaces.js'
8
8
  export * from './helpers.js'
@@ -1,4 +1,18 @@
1
- import { MetaState } from '../types.js'
1
+ export interface MetaState {
2
+ creator: address
3
+ createdAt: bigint
4
+ }
5
+
6
+ export declare interface RolesState extends MetaState {
7
+ roles: { [index: string]: address[] }
8
+ }
9
+
10
+ export declare interface TokenState extends RolesState {
11
+ holders: bigint
12
+ balances: { [address: address]: bigint }
13
+ approvals: { [owner: address]: { [operator: address]: bigint } }
14
+ totalSupply: bigint
15
+ }
2
16
 
3
17
  export interface VotingState extends MetaState {
4
18
  votes: {
package/src/meta.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MetaState } from './types.js'
1
+ import { MetaState } from './interfaces.js'
2
2
 
3
3
  export default class Meta {
4
4
  #creator: address
package/src/roles.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Meta from './meta.js'
2
- import { RolesState } from './types.js'
2
+ import { RolesState } from './interfaces.js'
3
3
 
4
4
  export default class Roles extends Meta {
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  import { IPublicVoting } from './voting/interfaces/i-public-voting.js'
2
2
  import PublicVoting from './voting/public-voting.js'
3
- import { VotingState } from './voting/types.js'
3
+ import { VotingState } from './interfaces.js'
4
4
 
5
5
  export interface TokenReceiverState extends VotingState {
6
6
  tokenToReceive: address
package/src/token.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { restoreApprovals, restoreBalances } from './helpers.js'
2
2
  import Roles from './roles.js'
3
- import { TokenState } from './types.js'
3
+ import { TokenState } from './interfaces.js'
4
4
 
5
5
  export default class Token extends Roles {
6
6
  /**
@@ -4,7 +4,7 @@ import {
4
4
  VoteResult,
5
5
  VoteView,
6
6
  VotingState
7
- } from './types.js'
7
+ } from '../interfaces.js'
8
8
 
9
9
  export default class PrivateVoting extends Meta {
10
10
  #voters: PrivateVotingState['voters']
@@ -1,5 +1,5 @@
1
1
  import Meta from '../meta.js'
2
- import { VotingState, VoteResult } from './types.js'
2
+ import { VotingState, VoteResult } from '../interfaces.js'
3
3
 
4
4
  /**
5
5
  * allows everybody that has a balance greater or equal to tokenAmountToReceive to vote
package/src/types.ts DELETED
@@ -1,15 +0,0 @@
1
- export interface MetaState {
2
- creator: address
3
- createdAt: bigint
4
- }
5
-
6
- export declare interface RolesState extends MetaState {
7
- roles: { [index: string]: address[] }
8
- }
9
-
10
- export declare interface TokenState extends RolesState {
11
- holders: bigint
12
- balances: { [address: address]: bigint }
13
- approvals: { [owner: address]: { [operator: address]: bigint } }
14
- totalSupply: bigint
15
- }