@ottochain/sdk 1.0.2 → 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.
- package/dist/cjs/apps/contracts/state-machines/contract.json +1 -29
- package/dist/cjs/apps/contracts/state-machines/escrow.json +2 -32
- package/dist/cjs/generated/index.js +11 -1
- package/dist/cjs/metakit/drop-nulls.js +50 -0
- package/dist/cjs/metakit/normalize.js +147 -0
- package/dist/cjs/ottochain/metagraph-client.js +147 -0
- package/dist/cjs/validation.js +1 -1
- package/dist/esm/apps/contracts/state-machines/contract.json +1 -29
- package/dist/esm/apps/contracts/state-machines/escrow.json +2 -32
- package/dist/esm/generated/index.js +11 -1
- package/dist/esm/metakit/drop-nulls.js +46 -0
- package/dist/esm/metakit/normalize.js +140 -0
- package/dist/esm/ottochain/metagraph-client.js +147 -0
- package/dist/esm/validation.js +1 -1
- package/dist/types/generated/index.d.ts +11 -1
- package/dist/types/metakit/drop-nulls.d.ts +29 -0
- package/dist/types/metakit/normalize.d.ts +67 -0
- package/dist/types/ottochain/index.d.ts +1 -1
- package/dist/types/ottochain/metagraph-client.d.ts +90 -0
- package/package.json +12 -12
- package/dist/apps/contracts/index.d.ts +0 -21
- package/dist/apps/contracts/index.js +0 -39
- package/dist/apps/contracts/types.d.ts +0 -24
- package/dist/apps/contracts/types.js +0 -48
- package/dist/apps/identity/index.d.ts +0 -22
- package/dist/apps/identity/index.js +0 -40
- package/dist/apps/identity/types.d.ts +0 -30
- package/dist/apps/identity/types.js +0 -53
- package/dist/apps/index.d.ts +0 -29
- package/dist/apps/index.js +0 -60
- package/dist/apps/markets/index.d.ts +0 -26
- package/dist/apps/markets/index.js +0 -46
- package/dist/apps/markets/types.d.ts +0 -185
- package/dist/apps/markets/types.js +0 -252
- package/dist/apps/oracles/index.d.ts +0 -26
- package/dist/apps/oracles/index.js +0 -46
- package/dist/apps/oracles/types.d.ts +0 -211
- package/dist/apps/oracles/types.js +0 -306
- package/dist/cjs/apps/contracts/types.js +0 -48
- package/dist/cjs/apps/corporate/types.js +0 -44
- package/dist/cjs/apps/governance/types.js +0 -42
- package/dist/cjs/apps/identity/types.js +0 -53
- package/dist/cjs/apps/markets/types.js +0 -219
- package/dist/cjs/apps/oracles/types.js +0 -282
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -392
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +0 -235
- package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
- package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
- package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
- package/dist/cjs/generated/ottochain/v1/common_pb.js +0 -37
- package/dist/cjs/generated/ottochain/v1/fiber_pb.js +0 -86
- package/dist/cjs/generated/ottochain/v1/messages_pb.js +0 -44
- package/dist/cjs/generated/ottochain/v1/records_pb.js +0 -44
- package/dist/errors.d.ts +0 -221
- package/dist/errors.js +0 -293
- package/dist/esm/apps/contracts/types.js +0 -44
- package/dist/esm/apps/corporate/types.js +0 -38
- package/dist/esm/apps/governance/types.js +0 -35
- package/dist/esm/apps/identity/types.js +0 -50
- package/dist/esm/apps/markets/types.js +0 -206
- package/dist/esm/apps/oracles/types.js +0 -267
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -97
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -389
- package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +0 -232
- package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +0 -113
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -76
- package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +0 -148
- package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -106
- package/dist/esm/generated/ottochain/v1/common_pb.js +0 -34
- package/dist/esm/generated/ottochain/v1/fiber_pb.js +0 -83
- package/dist/esm/generated/ottochain/v1/messages_pb.js +0 -41
- package/dist/esm/generated/ottochain/v1/records_pb.js +0 -41
- package/dist/generated/index.d.ts +0 -15
- package/dist/generated/index.js +0 -34
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
- package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
- package/dist/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
- package/dist/generated/ottochain/v1/common_pb.d.ts +0 -86
- package/dist/generated/ottochain/v1/common_pb.js +0 -37
- package/dist/generated/ottochain/v1/fiber_pb.d.ts +0 -292
- package/dist/generated/ottochain/v1/fiber_pb.js +0 -86
- package/dist/generated/ottochain/v1/messages_pb.d.ts +0 -190
- package/dist/generated/ottochain/v1/messages_pb.js +0 -44
- package/dist/generated/ottochain/v1/records_pb.d.ts +0 -221
- package/dist/generated/ottochain/v1/records_pb.js +0 -44
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -77
- package/dist/metakit/binary.d.ts +0 -38
- package/dist/metakit/binary.js +0 -58
- package/dist/metakit/canonicalize.d.ts +0 -26
- package/dist/metakit/canonicalize.js +0 -40
- package/dist/metakit/codec.d.ts +0 -16
- package/dist/metakit/codec.js +0 -45
- package/dist/metakit/currency-transaction.d.ts +0 -157
- package/dist/metakit/currency-transaction.js +0 -319
- package/dist/metakit/currency-types.d.ts +0 -55
- package/dist/metakit/currency-types.js +0 -13
- package/dist/metakit/hash.d.ts +0 -50
- package/dist/metakit/hash.js +0 -84
- package/dist/metakit/index.d.ts +0 -23
- package/dist/metakit/index.js +0 -74
- package/dist/metakit/network/client.d.ts +0 -23
- package/dist/metakit/network/client.js +0 -78
- package/dist/metakit/network/currency-l1-client.d.ts +0 -71
- package/dist/metakit/network/currency-l1-client.js +0 -101
- package/dist/metakit/network/data-l1-client.d.ts +0 -57
- package/dist/metakit/network/data-l1-client.js +0 -76
- package/dist/metakit/network/index.d.ts +0 -10
- package/dist/metakit/network/index.js +0 -16
- package/dist/metakit/network/types.d.ts +0 -74
- package/dist/metakit/network/types.js +0 -20
- package/dist/metakit/sign.d.ts +0 -65
- package/dist/metakit/sign.js +0 -120
- package/dist/metakit/signed-object.d.ts +0 -66
- package/dist/metakit/signed-object.js +0 -100
- package/dist/metakit/types.d.ts +0 -67
- package/dist/metakit/types.js +0 -14
- package/dist/metakit/verify.d.ts +0 -55
- package/dist/metakit/verify.js +0 -217
- package/dist/metakit/wallet.d.ts +0 -70
- package/dist/metakit/wallet.js +0 -127
- package/dist/ottochain/index.d.ts +0 -13
- package/dist/ottochain/index.js +0 -45
- package/dist/ottochain/metagraph-client.d.ts +0 -111
- package/dist/ottochain/metagraph-client.js +0 -157
- package/dist/ottochain/snapshot.d.ts +0 -86
- package/dist/ottochain/snapshot.js +0 -110
- package/dist/ottochain/types.d.ts +0 -278
- package/dist/ottochain/types.js +0 -11
- package/dist/types/apps/contracts/types.d.ts +0 -24
- package/dist/types/apps/corporate/types.d.ts +0 -9861
- package/dist/types/apps/governance/types.d.ts +0 -344
- package/dist/types/apps/identity/types.d.ts +0 -30
- package/dist/types/apps/markets/types.d.ts +0 -155
- package/dist/types/apps/oracles/types.d.ts +0 -193
- package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
- package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +0 -1172
- package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +0 -772
- package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
- package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
- package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
- package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
- package/dist/types/generated/ottochain/v1/common_pb.d.ts +0 -86
- package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +0 -292
- package/dist/types/generated/ottochain/v1/messages_pb.d.ts +0 -190
- package/dist/types/generated/ottochain/v1/records_pb.d.ts +0 -221
- package/dist/validation.d.ts +0 -449
- package/dist/validation.js +0 -312
|
@@ -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
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Governance & DAO Types
|
|
4
|
-
*
|
|
5
|
-
* TypeScript types matching the JSON Logic state machine definitions
|
|
6
|
-
* in ottochain/docs/trust-graph/state-machines/dao/
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.isThresholdDAO = exports.isTokenDAO = exports.isMultisigDAO = exports.isSingleOwnerDAO = void 0;
|
|
12
|
-
// =============================================================================
|
|
13
|
-
// Helpers
|
|
14
|
-
// =============================================================================
|
|
15
|
-
/**
|
|
16
|
-
* Type guard for SingleOwnerDAO
|
|
17
|
-
*/
|
|
18
|
-
function isSingleOwnerDAO(state) {
|
|
19
|
-
return state.schema === 'SingleOwnerDAO';
|
|
20
|
-
}
|
|
21
|
-
exports.isSingleOwnerDAO = isSingleOwnerDAO;
|
|
22
|
-
/**
|
|
23
|
-
* Type guard for MultisigDAO
|
|
24
|
-
*/
|
|
25
|
-
function isMultisigDAO(state) {
|
|
26
|
-
return state.schema === 'MultisigDAO';
|
|
27
|
-
}
|
|
28
|
-
exports.isMultisigDAO = isMultisigDAO;
|
|
29
|
-
/**
|
|
30
|
-
* Type guard for TokenDAO
|
|
31
|
-
*/
|
|
32
|
-
function isTokenDAO(state) {
|
|
33
|
-
return state.schema === 'TokenDAO';
|
|
34
|
-
}
|
|
35
|
-
exports.isTokenDAO = isTokenDAO;
|
|
36
|
-
/**
|
|
37
|
-
* Type guard for ThresholdDAO
|
|
38
|
-
*/
|
|
39
|
-
function isThresholdDAO(state) {
|
|
40
|
-
return state.schema === 'ThresholdDAO';
|
|
41
|
-
}
|
|
42
|
-
exports.isThresholdDAO = isThresholdDAO;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Agent Identity Utilities
|
|
4
|
-
*
|
|
5
|
-
* Constants and utilities for the Agent Identity 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.ATTESTATION_DELTAS = exports.AGENT_TRANSITIONS = exports.DEFAULT_REPUTATION_CONFIG = void 0;
|
|
12
|
-
const agent_pb_js_1 = require("../../generated/ottochain/apps/identity/v1/agent_pb.js");
|
|
13
|
-
const attestation_pb_js_1 = require("../../generated/ottochain/apps/identity/v1/attestation_pb.js");
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
// Configuration Defaults
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
/**
|
|
18
|
-
* Default reputation configuration for agent identity
|
|
19
|
-
*/
|
|
20
|
-
exports.DEFAULT_REPUTATION_CONFIG = {
|
|
21
|
-
baseReputation: 10,
|
|
22
|
-
completionDelta: 5,
|
|
23
|
-
vouchDelta: 2,
|
|
24
|
-
violationDelta: -10,
|
|
25
|
-
behavioralDelta: 3,
|
|
26
|
-
minReputation: 0,
|
|
27
|
-
challengeThreshold: 5,
|
|
28
|
-
};
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
// State Machine Transitions
|
|
31
|
-
// ---------------------------------------------------------------------------
|
|
32
|
-
/**
|
|
33
|
-
* Valid transitions for each agent state
|
|
34
|
-
*/
|
|
35
|
-
exports.AGENT_TRANSITIONS = {
|
|
36
|
-
[agent_pb_js_1.AgentState.UNSPECIFIED]: [],
|
|
37
|
-
[agent_pb_js_1.AgentState.REGISTERED]: ['activate', 'withdraw'],
|
|
38
|
-
[agent_pb_js_1.AgentState.ACTIVE]: ['challenge', 'withdraw'],
|
|
39
|
-
[agent_pb_js_1.AgentState.CHALLENGED]: ['uphold_challenge', 'dismiss_challenge'],
|
|
40
|
-
[agent_pb_js_1.AgentState.SUSPENDED]: ['begin_probation'],
|
|
41
|
-
[agent_pb_js_1.AgentState.PROBATION]: ['complete_probation'],
|
|
42
|
-
[agent_pb_js_1.AgentState.WITHDRAWN]: [], // Terminal state
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Reputation delta by attestation type
|
|
46
|
-
*/
|
|
47
|
-
exports.ATTESTATION_DELTAS = {
|
|
48
|
-
[attestation_pb_js_1.AttestationType.UNSPECIFIED]: 0,
|
|
49
|
-
[attestation_pb_js_1.AttestationType.COMPLETION]: 5,
|
|
50
|
-
[attestation_pb_js_1.AttestationType.VOUCH]: 2,
|
|
51
|
-
[attestation_pb_js_1.AttestationType.VIOLATION]: -10,
|
|
52
|
-
[attestation_pb_js_1.AttestationType.BEHAVIORAL]: 3,
|
|
53
|
-
};
|