@claritydao/midnight-agora-contracts 0.1.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/.prettierrc +1 -0
- package/README.md +435 -0
- package/dist/Governor.compact +875 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/witnesses.d.ts +29 -0
- package/dist/witnesses.js +10 -0
- package/dist/witnesses.js.map +1 -0
- package/eslint.config.mjs +38 -0
- package/package.json +31 -0
- package/src/contracts/DAO/EffectModule.compact +282 -0
- package/src/contracts/DAO/Governor.compact +875 -0
- package/src/contracts/DAO/ProposalModule.compact +331 -0
- package/src/contracts/DAO/StakeModule.compact +301 -0
- package/src/contracts/DAO/TreasuryModule.compact +326 -0
- package/src/contracts/fungigleToken/FungibleToken.compact +570 -0
- package/src/contracts/utils/DivModule.compact +39 -0
- package/src/contracts/utils/Initializable.compact +42 -0
- package/src/contracts/utils/Pausable.compact +61 -0
- package/src/contracts/utils/TypesModule.compact +285 -0
- package/src/contracts/utils/Utils.compact +76 -0
- package/src/index.ts +37 -0
- package/src/test/governance-simulator.ts +703 -0
- package/src/test/governor-contract.test.ts +1655 -0
- package/src/test/utils/address.ts +82 -0
- package/src/witnesses.ts +38 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +21 -0
- package/vitest.config.ts +40 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// import {
|
|
2
|
+
// convert_bigint_to_Uint8Array,
|
|
3
|
+
// encodeCoinPublicKey,
|
|
4
|
+
// } from '@midnight-ntwrk/compact-runtime';
|
|
5
|
+
// import { encodeContractAddress } from '@midnight-ntwrk/ledger';
|
|
6
|
+
// import type { ZswapCoinPublicKey } from '@midnight-ntwrk/zswap';
|
|
7
|
+
// import type { ContractAddress } from '@midnight-ntwrk/ledger';
|
|
8
|
+
|
|
9
|
+
// const PREFIX_ADDRESS = '0200';
|
|
10
|
+
|
|
11
|
+
// /**
|
|
12
|
+
// * @description Converts an ASCII string to its hexadecimal representation,
|
|
13
|
+
// * left-padded with zeros to a specified length. Useful for generating
|
|
14
|
+
// * fixed-size hex strings for encoding.
|
|
15
|
+
// * @param str ASCII string to convert.
|
|
16
|
+
// * @param len Total desired length of the resulting hex string. Defaults to 64.
|
|
17
|
+
// * @returns Hexadecimal string representation of `str`, padded to `length` characters.
|
|
18
|
+
// */
|
|
19
|
+
// export const toHexPadded = (str: string, len = 64) =>
|
|
20
|
+
// Buffer.from(str, 'ascii').toString('hex').padStart(len, '0');
|
|
21
|
+
|
|
22
|
+
// /**
|
|
23
|
+
// * @description Generates ZswapCoinPublicKey from `str` for testing purposes.
|
|
24
|
+
// * @param str String to hexify and encode.
|
|
25
|
+
// * @returns Encoded `ZswapCoinPublicKey`.
|
|
26
|
+
// */
|
|
27
|
+
// export const encodeToPK = (str: string): ZswapCoinPublicKey => {
|
|
28
|
+
// const toHex = Buffer.from(str, 'ascii').toString('hex');
|
|
29
|
+
// return { bytes: encodeCoinPublicKey(String(toHex).padStart(64, '0')) };
|
|
30
|
+
// };
|
|
31
|
+
|
|
32
|
+
// /**
|
|
33
|
+
// * @description Generates ContractAddress from `str` for testing purposes.
|
|
34
|
+
// * Prepends 32-byte hex with PREFIX_ADDRESS before encoding.
|
|
35
|
+
// * @param str String to hexify and encode.
|
|
36
|
+
// * @returns Encoded `ZswapCoinPublicKey`.
|
|
37
|
+
// */
|
|
38
|
+
// export const encodeToAddress = (str: string): ContractAddress => {
|
|
39
|
+
// const toHex = Buffer.from(str, 'ascii').toString('hex');
|
|
40
|
+
// const fullAddress = PREFIX_ADDRESS + String(toHex).padStart(64, '0');
|
|
41
|
+
// return { bytes: encodeContractAddress(fullAddress) };
|
|
42
|
+
// };
|
|
43
|
+
|
|
44
|
+
// /**
|
|
45
|
+
// * @description Generates an Either object for ZswapCoinPublicKey for testing.
|
|
46
|
+
// * For use when an Either argument is expected.
|
|
47
|
+
// * @param str String to hexify and encode.
|
|
48
|
+
// * @returns Defined Either object for ZswapCoinPublicKey.
|
|
49
|
+
// */
|
|
50
|
+
// export const createEitherTestUser = (str: string) => {
|
|
51
|
+
// return {
|
|
52
|
+
// is_left: true,
|
|
53
|
+
// left: encodeToPK(str),
|
|
54
|
+
// right: encodeToAddress(''),
|
|
55
|
+
// };
|
|
56
|
+
// };
|
|
57
|
+
|
|
58
|
+
// /**
|
|
59
|
+
// * @description Generates an Either object for ContractAddress for testing.
|
|
60
|
+
// * For use when an Either argument is expected.
|
|
61
|
+
// * @param str String to hexify and encode.
|
|
62
|
+
// * @returns Defined Either object for ContractAddress.
|
|
63
|
+
// */
|
|
64
|
+
// export const createEitherTestContractAddress = (str: string) => {
|
|
65
|
+
// return {
|
|
66
|
+
// is_left: false,
|
|
67
|
+
// left: encodeToPK(''),
|
|
68
|
+
// right: encodeToAddress(str),
|
|
69
|
+
// };
|
|
70
|
+
// };
|
|
71
|
+
|
|
72
|
+
// export const ZERO_KEY = {
|
|
73
|
+
// is_left: true,
|
|
74
|
+
// left: { bytes: convert_bigint_to_Uint8Array(32, BigInt(0)) },
|
|
75
|
+
// right: encodeToAddress(''),
|
|
76
|
+
// };
|
|
77
|
+
|
|
78
|
+
// export const ZERO_ADDRESS = {
|
|
79
|
+
// is_left: false,
|
|
80
|
+
// left: encodeToPK(''),
|
|
81
|
+
// right: { bytes: convert_bigint_to_Uint8Array(32, BigInt(0)) },
|
|
82
|
+
// };
|
package/src/witnesses.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { WitnessContext } from '@midnight-ntwrk/compact-runtime';
|
|
2
|
+
import type { Ledger } from './managed/governor/contract/index.cjs';
|
|
3
|
+
|
|
4
|
+
// Define your private state type
|
|
5
|
+
export type GovernorPrivateState = {
|
|
6
|
+
secretKey: Uint8Array | null;
|
|
7
|
+
currentTime: bigint;
|
|
8
|
+
userStake: {
|
|
9
|
+
amount: bigint;
|
|
10
|
+
delegatedTo: Uint8Array;
|
|
11
|
+
stakedAt: bigint;
|
|
12
|
+
};
|
|
13
|
+
votingHistory: any[];
|
|
14
|
+
proposalHistory: any[];
|
|
15
|
+
governanceConfig: {
|
|
16
|
+
votingPeriod: bigint;
|
|
17
|
+
quorumThreshold: bigint;
|
|
18
|
+
proposalThreshold: bigint;
|
|
19
|
+
proposalLifetime: bigint;
|
|
20
|
+
executionDelay: bigint;
|
|
21
|
+
gracePeriod: bigint;
|
|
22
|
+
minStakeAmount: bigint;
|
|
23
|
+
stakingPeriod: bigint;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Implement the witnesses object
|
|
29
|
+
export const witnesses = {
|
|
30
|
+
local_secret_key: (
|
|
31
|
+
{ privateState }: WitnessContext<Ledger, GovernorPrivateState>
|
|
32
|
+
): [GovernorPrivateState, { is_some: boolean; value: Uint8Array }] => [
|
|
33
|
+
privateState,
|
|
34
|
+
privateState.secretKey
|
|
35
|
+
? { is_some: true, value: privateState.secretKey }
|
|
36
|
+
: { is_some: false, value: new Uint8Array(32) },
|
|
37
|
+
],
|
|
38
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["src/**/*.ts"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"lib": ["ESNext"],
|
|
8
|
+
"target": "ES2022",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"allowJs": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"sourceMap": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"esModuleInterop": true,
|
|
19
|
+
"skipLibCheck": true
|
|
20
|
+
}
|
|
21
|
+
}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
mode: "node",
|
|
5
|
+
test: {
|
|
6
|
+
deps: {
|
|
7
|
+
interopDefault: true
|
|
8
|
+
},
|
|
9
|
+
globals: true,
|
|
10
|
+
environment: "node",
|
|
11
|
+
include: ["**/*.test.ts"],
|
|
12
|
+
exclude: ["node_modules"],
|
|
13
|
+
root: ".",
|
|
14
|
+
coverage: {
|
|
15
|
+
provider: "v8",
|
|
16
|
+
reporter: ["text", "json", "html"],
|
|
17
|
+
include: [
|
|
18
|
+
"src/managed/**/*.js",
|
|
19
|
+
"src/managed/**/*.cjs"
|
|
20
|
+
],
|
|
21
|
+
exclude: [
|
|
22
|
+
"node_modules/**",
|
|
23
|
+
"src/test/**",
|
|
24
|
+
"**/*.test.ts",
|
|
25
|
+
"**/*.spec.ts"
|
|
26
|
+
],
|
|
27
|
+
thresholds: {
|
|
28
|
+
branches: 50,
|
|
29
|
+
functions: 73,
|
|
30
|
+
lines: 72,
|
|
31
|
+
statements: -269
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
reporters: ["default", ["junit", { outputFile: "reports/report.xml" }]]
|
|
35
|
+
},
|
|
36
|
+
resolve: {
|
|
37
|
+
extensions: [".ts", ".js"],
|
|
38
|
+
conditions: ["import", "node", "default"]
|
|
39
|
+
}
|
|
40
|
+
});
|