@ottochain/sdk 1.0.3 → 1.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.
Files changed (153) hide show
  1. package/dist/cjs/generated/index.js +11 -1
  2. package/dist/cjs/metakit/drop-nulls.js +50 -0
  3. package/dist/cjs/metakit/normalize.js +147 -0
  4. package/dist/cjs/ottochain/metagraph-client.js +147 -0
  5. package/dist/cjs/validation.js +1 -1
  6. package/dist/esm/generated/index.js +11 -1
  7. package/dist/esm/metakit/drop-nulls.js +46 -0
  8. package/dist/esm/metakit/normalize.js +140 -0
  9. package/dist/esm/ottochain/metagraph-client.js +147 -0
  10. package/dist/esm/validation.js +1 -1
  11. package/dist/types/generated/index.d.ts +11 -1
  12. package/dist/types/metakit/drop-nulls.d.ts +29 -0
  13. package/dist/types/metakit/normalize.d.ts +67 -0
  14. package/dist/types/ottochain/index.d.ts +1 -1
  15. package/dist/types/ottochain/metagraph-client.d.ts +90 -0
  16. package/package.json +12 -12
  17. package/dist/apps/contracts/index.d.ts +0 -21
  18. package/dist/apps/contracts/index.js +0 -39
  19. package/dist/apps/contracts/types.d.ts +0 -24
  20. package/dist/apps/contracts/types.js +0 -48
  21. package/dist/apps/identity/index.d.ts +0 -22
  22. package/dist/apps/identity/index.js +0 -40
  23. package/dist/apps/identity/types.d.ts +0 -30
  24. package/dist/apps/identity/types.js +0 -53
  25. package/dist/apps/index.d.ts +0 -29
  26. package/dist/apps/index.js +0 -60
  27. package/dist/apps/markets/index.d.ts +0 -26
  28. package/dist/apps/markets/index.js +0 -46
  29. package/dist/apps/markets/types.d.ts +0 -185
  30. package/dist/apps/markets/types.js +0 -252
  31. package/dist/apps/oracles/index.d.ts +0 -26
  32. package/dist/apps/oracles/index.js +0 -46
  33. package/dist/apps/oracles/types.d.ts +0 -211
  34. package/dist/apps/oracles/types.js +0 -306
  35. package/dist/cjs/apps/contracts/types.js +0 -48
  36. package/dist/cjs/apps/corporate/types.js +0 -44
  37. package/dist/cjs/apps/governance/types.js +0 -42
  38. package/dist/cjs/apps/identity/types.js +0 -53
  39. package/dist/cjs/apps/markets/types.js +0 -219
  40. package/dist/cjs/apps/oracles/types.js +0 -282
  41. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
  42. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -392
  43. package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +0 -235
  44. package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
  45. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
  46. package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
  47. package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
  48. package/dist/cjs/generated/ottochain/v1/common_pb.js +0 -37
  49. package/dist/cjs/generated/ottochain/v1/fiber_pb.js +0 -86
  50. package/dist/cjs/generated/ottochain/v1/messages_pb.js +0 -44
  51. package/dist/cjs/generated/ottochain/v1/records_pb.js +0 -44
  52. package/dist/errors.d.ts +0 -221
  53. package/dist/errors.js +0 -293
  54. package/dist/esm/apps/contracts/types.js +0 -44
  55. package/dist/esm/apps/corporate/types.js +0 -38
  56. package/dist/esm/apps/governance/types.js +0 -35
  57. package/dist/esm/apps/identity/types.js +0 -50
  58. package/dist/esm/apps/markets/types.js +0 -206
  59. package/dist/esm/apps/oracles/types.js +0 -267
  60. package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -97
  61. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -389
  62. package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +0 -232
  63. package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +0 -113
  64. package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -76
  65. package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +0 -148
  66. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -106
  67. package/dist/esm/generated/ottochain/v1/common_pb.js +0 -34
  68. package/dist/esm/generated/ottochain/v1/fiber_pb.js +0 -83
  69. package/dist/esm/generated/ottochain/v1/messages_pb.js +0 -41
  70. package/dist/esm/generated/ottochain/v1/records_pb.js +0 -41
  71. package/dist/generated/index.d.ts +0 -15
  72. package/dist/generated/index.js +0 -34
  73. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
  74. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
  75. package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
  76. package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
  77. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
  78. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
  79. package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
  80. package/dist/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
  81. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
  82. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
  83. package/dist/generated/ottochain/v1/common_pb.d.ts +0 -86
  84. package/dist/generated/ottochain/v1/common_pb.js +0 -37
  85. package/dist/generated/ottochain/v1/fiber_pb.d.ts +0 -292
  86. package/dist/generated/ottochain/v1/fiber_pb.js +0 -86
  87. package/dist/generated/ottochain/v1/messages_pb.d.ts +0 -190
  88. package/dist/generated/ottochain/v1/messages_pb.js +0 -44
  89. package/dist/generated/ottochain/v1/records_pb.d.ts +0 -221
  90. package/dist/generated/ottochain/v1/records_pb.js +0 -44
  91. package/dist/index.d.ts +0 -21
  92. package/dist/index.js +0 -77
  93. package/dist/metakit/binary.d.ts +0 -38
  94. package/dist/metakit/binary.js +0 -58
  95. package/dist/metakit/canonicalize.d.ts +0 -26
  96. package/dist/metakit/canonicalize.js +0 -40
  97. package/dist/metakit/codec.d.ts +0 -16
  98. package/dist/metakit/codec.js +0 -45
  99. package/dist/metakit/currency-transaction.d.ts +0 -157
  100. package/dist/metakit/currency-transaction.js +0 -319
  101. package/dist/metakit/currency-types.d.ts +0 -55
  102. package/dist/metakit/currency-types.js +0 -13
  103. package/dist/metakit/hash.d.ts +0 -50
  104. package/dist/metakit/hash.js +0 -84
  105. package/dist/metakit/index.d.ts +0 -23
  106. package/dist/metakit/index.js +0 -74
  107. package/dist/metakit/network/client.d.ts +0 -23
  108. package/dist/metakit/network/client.js +0 -78
  109. package/dist/metakit/network/currency-l1-client.d.ts +0 -71
  110. package/dist/metakit/network/currency-l1-client.js +0 -101
  111. package/dist/metakit/network/data-l1-client.d.ts +0 -57
  112. package/dist/metakit/network/data-l1-client.js +0 -76
  113. package/dist/metakit/network/index.d.ts +0 -10
  114. package/dist/metakit/network/index.js +0 -16
  115. package/dist/metakit/network/types.d.ts +0 -74
  116. package/dist/metakit/network/types.js +0 -20
  117. package/dist/metakit/sign.d.ts +0 -65
  118. package/dist/metakit/sign.js +0 -120
  119. package/dist/metakit/signed-object.d.ts +0 -66
  120. package/dist/metakit/signed-object.js +0 -100
  121. package/dist/metakit/types.d.ts +0 -67
  122. package/dist/metakit/types.js +0 -14
  123. package/dist/metakit/verify.d.ts +0 -55
  124. package/dist/metakit/verify.js +0 -217
  125. package/dist/metakit/wallet.d.ts +0 -70
  126. package/dist/metakit/wallet.js +0 -127
  127. package/dist/ottochain/index.d.ts +0 -13
  128. package/dist/ottochain/index.js +0 -45
  129. package/dist/ottochain/metagraph-client.d.ts +0 -111
  130. package/dist/ottochain/metagraph-client.js +0 -157
  131. package/dist/ottochain/snapshot.d.ts +0 -86
  132. package/dist/ottochain/snapshot.js +0 -110
  133. package/dist/ottochain/types.d.ts +0 -278
  134. package/dist/ottochain/types.js +0 -11
  135. package/dist/types/apps/contracts/types.d.ts +0 -24
  136. package/dist/types/apps/corporate/types.d.ts +0 -9861
  137. package/dist/types/apps/governance/types.d.ts +0 -344
  138. package/dist/types/apps/identity/types.d.ts +0 -30
  139. package/dist/types/apps/markets/types.d.ts +0 -155
  140. package/dist/types/apps/oracles/types.d.ts +0 -193
  141. package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
  142. package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +0 -1172
  143. package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +0 -772
  144. package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
  145. package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
  146. package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
  147. package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
  148. package/dist/types/generated/ottochain/v1/common_pb.d.ts +0 -86
  149. package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +0 -292
  150. package/dist/types/generated/ottochain/v1/messages_pb.d.ts +0 -190
  151. package/dist/types/generated/ottochain/v1/records_pb.d.ts +0 -221
  152. package/dist/validation.d.ts +0 -449
  153. package/dist/validation.js +0 -312
@@ -1,46 +0,0 @@
1
- "use strict";
2
- /**
3
- * Oracles Application
4
- *
5
- * Types and utilities for the Oracle system on OttoChain.
6
- * Oracles provide truth resolution for markets, disputes, and attestations.
7
- *
8
- * @example
9
- * ```typescript
10
- * import {
11
- * OracleState,
12
- * SlashingReason,
13
- * calculateReputation,
14
- * calculateSlashAmount,
15
- * DEFAULT_ORACLE_CONFIG
16
- * } from '@ottochain/sdk/apps/oracles';
17
- *
18
- * // Calculate new reputation after successful resolution
19
- * const newRep = calculateReputation(50, REPUTATION_DELTAS.successfulResolution);
20
- *
21
- * // Calculate slash for timeout
22
- * const slashAmount = calculateSlashAmount(10000n, SlashingReason.TIMEOUT);
23
- * ```
24
- *
25
- * @packageDocumentation
26
- */
27
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
28
- if (k2 === undefined) k2 = k;
29
- var desc = Object.getOwnPropertyDescriptor(m, k);
30
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
31
- desc = { enumerable: true, get: function() { return m[k]; } };
32
- }
33
- Object.defineProperty(o, k2, desc);
34
- }) : (function(o, m, k, k2) {
35
- if (k2 === undefined) k2 = k;
36
- o[k2] = m[k];
37
- }));
38
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
39
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- // Note: Once proto files are generated, uncomment these exports:
43
- // export * from '../../generated/ottochain/apps/oracles/v1/oracle_pb.js';
44
- // export * from '../../generated/ottochain/apps/oracles/v1/resolution_pb.js';
45
- // Export convenience types, constants, and helpers
46
- __exportStar(require("./types.js"), exports);
@@ -1,211 +0,0 @@
1
- /**
2
- * Oracles Application Types
3
- *
4
- * Constants, types, and utilities for the Oracle system on OttoChain.
5
- * Oracles provide truth resolution for markets and disputes.
6
- *
7
- * Note: When proto files are generated, enums will move to generated types.
8
- *
9
- * @packageDocumentation
10
- */
11
- /**
12
- * Oracle lifecycle states
13
- */
14
- export declare enum OracleState {
15
- UNSPECIFIED = 0,
16
- /** Oracle has registered but not yet staked */
17
- REGISTERED = 1,
18
- /** Oracle is staked and available for assignments */
19
- ACTIVE = 2,
20
- /** Oracle is currently assigned to resolve a market */
21
- ASSIGNED = 3,
22
- /** Oracle has submitted a resolution, in challenge period */
23
- SUBMITTED = 4,
24
- /** Oracle is under review due to dispute */
25
- CHALLENGED = 5,
26
- /** Oracle is suspended due to slashing */
27
- SUSPENDED = 6,
28
- /** Oracle has withdrawn stake and exited */
29
- WITHDRAWN = 7
30
- }
31
- /**
32
- * Types of oracle resolutions
33
- */
34
- export declare enum ResolutionType {
35
- UNSPECIFIED = 0,
36
- /** Binary yes/no outcome */
37
- BINARY = 1,
38
- /** One of multiple predefined outcomes */
39
- MULTI_CHOICE = 2,
40
- /** Numeric value (e.g., price) */
41
- NUMERIC = 3,
42
- /** Free-form attestation */
43
- ATTESTATION = 4
44
- }
45
- /**
46
- * Reasons for slashing oracle stake
47
- */
48
- export declare enum SlashingReason {
49
- UNSPECIFIED = 0,
50
- /** Failed to submit resolution in time */
51
- TIMEOUT = 1,
52
- /** Resolution overturned by dispute */
53
- INCORRECT_RESOLUTION = 2,
54
- /** Evidence of collusion or manipulation */
55
- COLLUSION = 3,
56
- /** Violation of oracle protocol */
57
- PROTOCOL_VIOLATION = 4
58
- }
59
- /**
60
- * Oracle configuration type
61
- */
62
- export interface OracleConfig {
63
- /** Minimum stake required to become an oracle (in base units) */
64
- minStake: bigint;
65
- /** Stake slashed for timeout (percentage) */
66
- timeoutSlashPercent: number;
67
- /** Stake slashed for incorrect resolution (percentage) */
68
- incorrectSlashPercent: number;
69
- /** Stake slashed for collusion (percentage) */
70
- collusionSlashPercent: number;
71
- /** Stake slashed for protocol violation (percentage) */
72
- violationSlashPercent: number;
73
- /** Epochs to wait before withdrawal after unstaking */
74
- cooldownEpochs: number;
75
- /** Base reputation for new oracles */
76
- baseReputation: number;
77
- /** Minimum reputation to accept high-value markets */
78
- highValueThreshold: number;
79
- /** Resolution window in epochs */
80
- resolutionWindowEpochs: number;
81
- /** Challenge window after submission in epochs */
82
- challengeWindowEpochs: number;
83
- /** Reward percentage from resolved market fees */
84
- oracleRewardPercent: number;
85
- }
86
- /**
87
- * Default oracle configuration
88
- */
89
- export declare const DEFAULT_ORACLE_CONFIG: OracleConfig;
90
- /**
91
- * Slashing percentages by reason
92
- */
93
- export declare const SLASHING_PERCENTAGES: Record<SlashingReason, number>;
94
- /**
95
- * Valid transitions for each oracle state
96
- */
97
- export declare const ORACLE_TRANSITIONS: Record<OracleState, readonly string[]>;
98
- /**
99
- * Check if an oracle state is terminal
100
- */
101
- export declare function isTerminalOracleState(state: OracleState): boolean;
102
- /**
103
- * Check if an oracle can accept new assignments
104
- */
105
- export declare function canAcceptAssignment(state: OracleState): boolean;
106
- /**
107
- * Reputation update factors
108
- */
109
- export declare const REPUTATION_DELTAS: {
110
- /** Successfully resolved market without challenge */
111
- readonly successfulResolution: 5;
112
- /** Resolution upheld after challenge */
113
- readonly upheldChallenge: 10;
114
- /** Resolution overturned (negative) */
115
- readonly overturnedResolution: -25;
116
- /** Timeout on assigned market (negative) */
117
- readonly timeout: -15;
118
- /** Collusion detected (negative) */
119
- readonly collusion: -100;
120
- /** Protocol violation (negative) */
121
- readonly violation: -20;
122
- /** Bonus for high-value market resolution */
123
- readonly highValueBonus: 3;
124
- };
125
- /**
126
- * Calculate new reputation after an event
127
- *
128
- * @param currentReputation - Current reputation score
129
- * @param delta - Reputation change (positive or negative)
130
- * @param minReputation - Minimum reputation floor (default 0)
131
- * @returns New reputation score
132
- */
133
- export declare function calculateReputation(currentReputation: number, delta: number, minReputation?: number): number;
134
- /**
135
- * Calculate weighted reputation considering history
136
- *
137
- * @param baseReputation - Current base reputation
138
- * @param successCount - Number of successful resolutions
139
- * @param failureCount - Number of failed/overturned resolutions
140
- * @returns Weighted reputation score
141
- */
142
- export declare function calculateWeightedReputation(baseReputation: number, successCount: number, failureCount: number): number;
143
- /**
144
- * Check if oracle qualifies for high-value markets
145
- */
146
- export declare function qualifiesForHighValue(reputation: number, stake: bigint, threshold?: number, minStakeMultiplier?: number): boolean;
147
- /**
148
- * Slashing condition definition
149
- */
150
- export interface SlashingCondition {
151
- reason: SlashingReason;
152
- slashPercent: number;
153
- description: string;
154
- appealable: boolean;
155
- suspensionEpochs: number;
156
- }
157
- /**
158
- * Predefined slashing conditions
159
- */
160
- export declare const SLASHING_CONDITIONS: Record<SlashingReason, SlashingCondition>;
161
- /**
162
- * Calculate slash amount for a given stake and reason
163
- *
164
- * @param stake - Oracle's current stake
165
- * @param reason - Reason for slashing
166
- * @returns Amount to be slashed
167
- */
168
- export declare function calculateSlashAmount(stake: bigint, reason: SlashingReason): bigint;
169
- /**
170
- * Calculate remaining stake after slashing
171
- */
172
- export declare function calculateStakeAfterSlash(stake: bigint, reason: SlashingReason): bigint;
173
- /**
174
- * Oracle candidate for selection
175
- */
176
- export interface OracleCandidate {
177
- address: string;
178
- reputation: number;
179
- stake: bigint;
180
- activeAssignments: number;
181
- successRate: number;
182
- }
183
- /**
184
- * Calculate oracle selection score
185
- * Higher score = more likely to be selected
186
- *
187
- * @param candidate - Oracle candidate details
188
- * @param marketValue - Value of market to resolve (affects weight for high-value markets)
189
- * @returns Selection score
190
- */
191
- export declare function calculateSelectionScore(candidate: OracleCandidate, marketValue?: bigint): number;
192
- /**
193
- * Calculate oracle reward for successful resolution
194
- *
195
- * @param marketFees - Total fees collected from market
196
- * @param rewardPercent - Oracle's reward percentage (default from config)
197
- * @returns Oracle reward amount
198
- */
199
- export declare function calculateOracleReward(marketFees: bigint, rewardPercent?: number): bigint;
200
- /**
201
- * Check if a value is a valid OracleState
202
- */
203
- export declare function isOracleState(value: unknown): value is OracleState;
204
- /**
205
- * Check if a value is a valid SlashingReason
206
- */
207
- export declare function isSlashingReason(value: unknown): value is SlashingReason;
208
- /**
209
- * Check if a value is a valid ResolutionType
210
- */
211
- export declare function isResolutionType(value: unknown): value is ResolutionType;
@@ -1,306 +0,0 @@
1
- "use strict";
2
- /**
3
- * Oracles Application Types
4
- *
5
- * Constants, types, and utilities for the Oracle system on OttoChain.
6
- * Oracles provide truth resolution for markets and disputes.
7
- *
8
- * Note: When proto files are generated, enums will move to generated types.
9
- *
10
- * @packageDocumentation
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.isResolutionType = exports.isSlashingReason = exports.isOracleState = exports.calculateOracleReward = exports.calculateSelectionScore = exports.calculateStakeAfterSlash = exports.calculateSlashAmount = exports.SLASHING_CONDITIONS = exports.qualifiesForHighValue = exports.calculateWeightedReputation = exports.calculateReputation = exports.REPUTATION_DELTAS = exports.canAcceptAssignment = exports.isTerminalOracleState = exports.ORACLE_TRANSITIONS = exports.SLASHING_PERCENTAGES = exports.DEFAULT_ORACLE_CONFIG = exports.SlashingReason = exports.ResolutionType = exports.OracleState = void 0;
14
- // ---------------------------------------------------------------------------
15
- // Enums (will be replaced by proto-generated versions)
16
- // ---------------------------------------------------------------------------
17
- /**
18
- * Oracle lifecycle states
19
- */
20
- var OracleState;
21
- (function (OracleState) {
22
- OracleState[OracleState["UNSPECIFIED"] = 0] = "UNSPECIFIED";
23
- /** Oracle has registered but not yet staked */
24
- OracleState[OracleState["REGISTERED"] = 1] = "REGISTERED";
25
- /** Oracle is staked and available for assignments */
26
- OracleState[OracleState["ACTIVE"] = 2] = "ACTIVE";
27
- /** Oracle is currently assigned to resolve a market */
28
- OracleState[OracleState["ASSIGNED"] = 3] = "ASSIGNED";
29
- /** Oracle has submitted a resolution, in challenge period */
30
- OracleState[OracleState["SUBMITTED"] = 4] = "SUBMITTED";
31
- /** Oracle is under review due to dispute */
32
- OracleState[OracleState["CHALLENGED"] = 5] = "CHALLENGED";
33
- /** Oracle is suspended due to slashing */
34
- OracleState[OracleState["SUSPENDED"] = 6] = "SUSPENDED";
35
- /** Oracle has withdrawn stake and exited */
36
- OracleState[OracleState["WITHDRAWN"] = 7] = "WITHDRAWN";
37
- })(OracleState || (exports.OracleState = OracleState = {}));
38
- /**
39
- * Types of oracle resolutions
40
- */
41
- var ResolutionType;
42
- (function (ResolutionType) {
43
- ResolutionType[ResolutionType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
44
- /** Binary yes/no outcome */
45
- ResolutionType[ResolutionType["BINARY"] = 1] = "BINARY";
46
- /** One of multiple predefined outcomes */
47
- ResolutionType[ResolutionType["MULTI_CHOICE"] = 2] = "MULTI_CHOICE";
48
- /** Numeric value (e.g., price) */
49
- ResolutionType[ResolutionType["NUMERIC"] = 3] = "NUMERIC";
50
- /** Free-form attestation */
51
- ResolutionType[ResolutionType["ATTESTATION"] = 4] = "ATTESTATION";
52
- })(ResolutionType || (exports.ResolutionType = ResolutionType = {}));
53
- /**
54
- * Reasons for slashing oracle stake
55
- */
56
- var SlashingReason;
57
- (function (SlashingReason) {
58
- SlashingReason[SlashingReason["UNSPECIFIED"] = 0] = "UNSPECIFIED";
59
- /** Failed to submit resolution in time */
60
- SlashingReason[SlashingReason["TIMEOUT"] = 1] = "TIMEOUT";
61
- /** Resolution overturned by dispute */
62
- SlashingReason[SlashingReason["INCORRECT_RESOLUTION"] = 2] = "INCORRECT_RESOLUTION";
63
- /** Evidence of collusion or manipulation */
64
- SlashingReason[SlashingReason["COLLUSION"] = 3] = "COLLUSION";
65
- /** Violation of oracle protocol */
66
- SlashingReason[SlashingReason["PROTOCOL_VIOLATION"] = 4] = "PROTOCOL_VIOLATION";
67
- })(SlashingReason || (exports.SlashingReason = SlashingReason = {}));
68
- /**
69
- * Default oracle configuration
70
- */
71
- exports.DEFAULT_ORACLE_CONFIG = {
72
- minStake: 10000n,
73
- timeoutSlashPercent: 0.05,
74
- incorrectSlashPercent: 0.25,
75
- collusionSlashPercent: 1.0,
76
- violationSlashPercent: 0.10,
77
- cooldownEpochs: 48,
78
- baseReputation: 50,
79
- highValueThreshold: 100,
80
- resolutionWindowEpochs: 12,
81
- challengeWindowEpochs: 6,
82
- oracleRewardPercent: 0.01,
83
- };
84
- /**
85
- * Slashing percentages by reason
86
- */
87
- exports.SLASHING_PERCENTAGES = {
88
- [SlashingReason.UNSPECIFIED]: 0,
89
- [SlashingReason.TIMEOUT]: exports.DEFAULT_ORACLE_CONFIG.timeoutSlashPercent,
90
- [SlashingReason.INCORRECT_RESOLUTION]: exports.DEFAULT_ORACLE_CONFIG.incorrectSlashPercent,
91
- [SlashingReason.COLLUSION]: exports.DEFAULT_ORACLE_CONFIG.collusionSlashPercent,
92
- [SlashingReason.PROTOCOL_VIOLATION]: exports.DEFAULT_ORACLE_CONFIG.violationSlashPercent,
93
- };
94
- // ---------------------------------------------------------------------------
95
- // State Machine Transitions
96
- // ---------------------------------------------------------------------------
97
- /**
98
- * Valid transitions for each oracle state
99
- */
100
- exports.ORACLE_TRANSITIONS = {
101
- [OracleState.UNSPECIFIED]: [],
102
- [OracleState.REGISTERED]: ['stake', 'withdraw'],
103
- [OracleState.ACTIVE]: ['assign', 'unstake'],
104
- [OracleState.ASSIGNED]: ['submit', 'timeout'],
105
- [OracleState.SUBMITTED]: ['finalize', 'challenge'],
106
- [OracleState.CHALLENGED]: ['uphold', 'overturn'],
107
- [OracleState.SUSPENDED]: ['begin_probation', 'permanent_ban'],
108
- [OracleState.WITHDRAWN]: [], // Terminal state
109
- };
110
- /**
111
- * Check if an oracle state is terminal
112
- */
113
- function isTerminalOracleState(state) {
114
- return state === OracleState.WITHDRAWN;
115
- }
116
- exports.isTerminalOracleState = isTerminalOracleState;
117
- /**
118
- * Check if an oracle can accept new assignments
119
- */
120
- function canAcceptAssignment(state) {
121
- return state === OracleState.ACTIVE;
122
- }
123
- exports.canAcceptAssignment = canAcceptAssignment;
124
- // ---------------------------------------------------------------------------
125
- // Reputation Calculations
126
- // ---------------------------------------------------------------------------
127
- /**
128
- * Reputation update factors
129
- */
130
- exports.REPUTATION_DELTAS = {
131
- /** Successfully resolved market without challenge */
132
- successfulResolution: 5,
133
- /** Resolution upheld after challenge */
134
- upheldChallenge: 10,
135
- /** Resolution overturned (negative) */
136
- overturnedResolution: -25,
137
- /** Timeout on assigned market (negative) */
138
- timeout: -15,
139
- /** Collusion detected (negative) */
140
- collusion: -100,
141
- /** Protocol violation (negative) */
142
- violation: -20,
143
- /** Bonus for high-value market resolution */
144
- highValueBonus: 3,
145
- };
146
- /**
147
- * Calculate new reputation after an event
148
- *
149
- * @param currentReputation - Current reputation score
150
- * @param delta - Reputation change (positive or negative)
151
- * @param minReputation - Minimum reputation floor (default 0)
152
- * @returns New reputation score
153
- */
154
- function calculateReputation(currentReputation, delta, minReputation = 0) {
155
- return Math.max(minReputation, currentReputation + delta);
156
- }
157
- exports.calculateReputation = calculateReputation;
158
- /**
159
- * Calculate weighted reputation considering history
160
- *
161
- * @param baseReputation - Current base reputation
162
- * @param successCount - Number of successful resolutions
163
- * @param failureCount - Number of failed/overturned resolutions
164
- * @returns Weighted reputation score
165
- */
166
- function calculateWeightedReputation(baseReputation, successCount, failureCount) {
167
- const totalAttempts = successCount + failureCount;
168
- if (totalAttempts === 0)
169
- return baseReputation;
170
- const successRate = successCount / totalAttempts;
171
- const experienceMultiplier = Math.min(1 + Math.log10(totalAttempts + 1) * 0.2, 1.5);
172
- return Math.round(baseReputation * successRate * experienceMultiplier);
173
- }
174
- exports.calculateWeightedReputation = calculateWeightedReputation;
175
- /**
176
- * Check if oracle qualifies for high-value markets
177
- */
178
- function qualifiesForHighValue(reputation, stake, threshold = exports.DEFAULT_ORACLE_CONFIG.highValueThreshold, minStakeMultiplier = 5) {
179
- return (reputation >= threshold &&
180
- stake >= exports.DEFAULT_ORACLE_CONFIG.minStake * BigInt(minStakeMultiplier));
181
- }
182
- exports.qualifiesForHighValue = qualifiesForHighValue;
183
- /**
184
- * Predefined slashing conditions
185
- */
186
- exports.SLASHING_CONDITIONS = {
187
- [SlashingReason.UNSPECIFIED]: {
188
- reason: SlashingReason.UNSPECIFIED,
189
- slashPercent: 0,
190
- description: 'No slashing',
191
- appealable: false,
192
- suspensionEpochs: 0,
193
- },
194
- [SlashingReason.TIMEOUT]: {
195
- reason: SlashingReason.TIMEOUT,
196
- slashPercent: exports.DEFAULT_ORACLE_CONFIG.timeoutSlashPercent,
197
- description: 'Failed to submit resolution within deadline',
198
- appealable: true,
199
- suspensionEpochs: 12,
200
- },
201
- [SlashingReason.INCORRECT_RESOLUTION]: {
202
- reason: SlashingReason.INCORRECT_RESOLUTION,
203
- slashPercent: exports.DEFAULT_ORACLE_CONFIG.incorrectSlashPercent,
204
- description: 'Resolution overturned by dispute process',
205
- appealable: true,
206
- suspensionEpochs: 48,
207
- },
208
- [SlashingReason.COLLUSION]: {
209
- reason: SlashingReason.COLLUSION,
210
- slashPercent: exports.DEFAULT_ORACLE_CONFIG.collusionSlashPercent,
211
- description: 'Evidence of collusion or market manipulation',
212
- appealable: false,
213
- suspensionEpochs: -1, // Permanent
214
- },
215
- [SlashingReason.PROTOCOL_VIOLATION]: {
216
- reason: SlashingReason.PROTOCOL_VIOLATION,
217
- slashPercent: exports.DEFAULT_ORACLE_CONFIG.violationSlashPercent,
218
- description: 'Violation of oracle operating protocol',
219
- appealable: true,
220
- suspensionEpochs: 24,
221
- },
222
- };
223
- /**
224
- * Calculate slash amount for a given stake and reason
225
- *
226
- * @param stake - Oracle's current stake
227
- * @param reason - Reason for slashing
228
- * @returns Amount to be slashed
229
- */
230
- function calculateSlashAmount(stake, reason) {
231
- const condition = exports.SLASHING_CONDITIONS[reason];
232
- return (stake * BigInt(Math.floor(condition.slashPercent * 10000))) / 10000n;
233
- }
234
- exports.calculateSlashAmount = calculateSlashAmount;
235
- /**
236
- * Calculate remaining stake after slashing
237
- */
238
- function calculateStakeAfterSlash(stake, reason) {
239
- return stake - calculateSlashAmount(stake, reason);
240
- }
241
- exports.calculateStakeAfterSlash = calculateStakeAfterSlash;
242
- /**
243
- * Calculate oracle selection score
244
- * Higher score = more likely to be selected
245
- *
246
- * @param candidate - Oracle candidate details
247
- * @param marketValue - Value of market to resolve (affects weight for high-value markets)
248
- * @returns Selection score
249
- */
250
- function calculateSelectionScore(candidate, marketValue = 0n) {
251
- const reputationWeight = 0.4;
252
- const stakeWeight = 0.3;
253
- const successWeight = 0.2;
254
- const loadWeight = 0.1;
255
- // Normalize stake to 0-100 range (assuming 1M max)
256
- const normalizedStake = Math.min(Number(candidate.stake / 10000n), 100);
257
- // Load penalty (fewer active = better)
258
- const loadScore = Math.max(0, 100 - candidate.activeAssignments * 20);
259
- // High-value market bonus for qualified oracles
260
- const highValueBonus = marketValue > 100000n &&
261
- qualifiesForHighValue(candidate.reputation, candidate.stake) ? 10 : 0;
262
- return (candidate.reputation * reputationWeight +
263
- normalizedStake * stakeWeight +
264
- candidate.successRate * 100 * successWeight +
265
- loadScore * loadWeight +
266
- highValueBonus);
267
- }
268
- exports.calculateSelectionScore = calculateSelectionScore;
269
- // ---------------------------------------------------------------------------
270
- // Reward Calculations
271
- // ---------------------------------------------------------------------------
272
- /**
273
- * Calculate oracle reward for successful resolution
274
- *
275
- * @param marketFees - Total fees collected from market
276
- * @param rewardPercent - Oracle's reward percentage (default from config)
277
- * @returns Oracle reward amount
278
- */
279
- function calculateOracleReward(marketFees, rewardPercent = exports.DEFAULT_ORACLE_CONFIG.oracleRewardPercent) {
280
- return (marketFees * BigInt(Math.floor(rewardPercent * 10000))) / 10000n;
281
- }
282
- exports.calculateOracleReward = calculateOracleReward;
283
- // ---------------------------------------------------------------------------
284
- // Type Guards
285
- // ---------------------------------------------------------------------------
286
- /**
287
- * Check if a value is a valid OracleState
288
- */
289
- function isOracleState(value) {
290
- return typeof value === 'number' && value in OracleState;
291
- }
292
- exports.isOracleState = isOracleState;
293
- /**
294
- * Check if a value is a valid SlashingReason
295
- */
296
- function isSlashingReason(value) {
297
- return typeof value === 'number' && value in SlashingReason;
298
- }
299
- exports.isSlashingReason = isSlashingReason;
300
- /**
301
- * Check if a value is a valid ResolutionType
302
- */
303
- function isResolutionType(value) {
304
- return typeof value === 'number' && value in ResolutionType;
305
- }
306
- exports.isResolutionType = isResolutionType;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- /**
3
- * Contract Utilities
4
- *
5
- * Constants and utilities for the Contract application.
6
- * Core types are generated from protobuf - see the generated exports.
7
- *
8
- * @packageDocumentation
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.isTerminalState = exports.CONTRACT_TRANSITIONS = exports.DEFAULT_CONTRACT_CONFIG = void 0;
12
- const contract_pb_js_1 = require("../../generated/ottochain/apps/contracts/v1/contract_pb.js");
13
- // ---------------------------------------------------------------------------
14
- // Configuration Defaults
15
- // ---------------------------------------------------------------------------
16
- /**
17
- * Default contract configuration
18
- */
19
- exports.DEFAULT_CONTRACT_CONFIG = {
20
- requireBothSignatures: false,
21
- disputeWindowEpochs: 10,
22
- };
23
- // ---------------------------------------------------------------------------
24
- // State Machine Transitions
25
- // ---------------------------------------------------------------------------
26
- /**
27
- * Valid transitions for each contract state
28
- */
29
- exports.CONTRACT_TRANSITIONS = {
30
- [contract_pb_js_1.ContractState.UNSPECIFIED]: [],
31
- [contract_pb_js_1.ContractState.PROPOSED]: ['accept', 'reject', 'cancel'],
32
- [contract_pb_js_1.ContractState.ACTIVE]: ['complete', 'dispute'],
33
- [contract_pb_js_1.ContractState.DISPUTED]: ['resolve_for_completer', 'resolve_for_disputant'],
34
- [contract_pb_js_1.ContractState.COMPLETED]: [], // Terminal state
35
- [contract_pb_js_1.ContractState.REJECTED]: [], // Terminal state
36
- [contract_pb_js_1.ContractState.CANCELLED]: [], // Terminal state
37
- };
38
- /**
39
- * Check if a contract state is terminal (no further transitions allowed)
40
- */
41
- function isTerminalState(state) {
42
- return [
43
- contract_pb_js_1.ContractState.COMPLETED,
44
- contract_pb_js_1.ContractState.REJECTED,
45
- contract_pb_js_1.ContractState.CANCELLED,
46
- ].includes(state);
47
- }
48
- exports.isTerminalState = isTerminalState;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- /**
3
- * Corporate Governance type definitions
4
- *
5
- * TypeScript interfaces for corporate governance state machines covering
6
- * entity lifecycle, board management, shareholder meetings, officers,
7
- * bylaws, committees, resolutions, proxy voting, securities, and compliance.
8
- *
9
- * @see corporate/*.json for JSON state machine definitions
10
- * @packageDocumentation
11
- */
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.CORPORATE_DEFINITIONS = void 0;
17
- // ---------------------------------------------------------------------------
18
- // State Machine Imports
19
- // ---------------------------------------------------------------------------
20
- const corporate_entity_json_1 = __importDefault(require("./state-machines/corporate-entity.json"));
21
- const corporate_board_json_1 = __importDefault(require("./state-machines/corporate-board.json"));
22
- const corporate_shareholders_json_1 = __importDefault(require("./state-machines/corporate-shareholders.json"));
23
- const corporate_officers_json_1 = __importDefault(require("./state-machines/corporate-officers.json"));
24
- const corporate_bylaws_json_1 = __importDefault(require("./state-machines/corporate-bylaws.json"));
25
- const corporate_committee_json_1 = __importDefault(require("./state-machines/corporate-committee.json"));
26
- const corporate_resolution_json_1 = __importDefault(require("./state-machines/corporate-resolution.json"));
27
- const corporate_proxy_json_1 = __importDefault(require("./state-machines/corporate-proxy.json"));
28
- const corporate_securities_json_1 = __importDefault(require("./state-machines/corporate-securities.json"));
29
- const corporate_compliance_json_1 = __importDefault(require("./state-machines/corporate-compliance.json"));
30
- /**
31
- * Corporate governance state machine definitions.
32
- */
33
- exports.CORPORATE_DEFINITIONS = {
34
- Entity: corporate_entity_json_1.default,
35
- Board: corporate_board_json_1.default,
36
- Shareholders: corporate_shareholders_json_1.default,
37
- Officers: corporate_officers_json_1.default,
38
- Bylaws: corporate_bylaws_json_1.default,
39
- Committee: corporate_committee_json_1.default,
40
- Resolution: corporate_resolution_json_1.default,
41
- Proxy: corporate_proxy_json_1.default,
42
- Securities: corporate_securities_json_1.default,
43
- Compliance: corporate_compliance_json_1.default,
44
- };