@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.
Files changed (157) hide show
  1. package/dist/cjs/apps/contracts/state-machines/contract.json +1 -29
  2. package/dist/cjs/apps/contracts/state-machines/escrow.json +2 -32
  3. package/dist/cjs/generated/index.js +11 -1
  4. package/dist/cjs/metakit/drop-nulls.js +50 -0
  5. package/dist/cjs/metakit/normalize.js +147 -0
  6. package/dist/cjs/ottochain/metagraph-client.js +147 -0
  7. package/dist/cjs/validation.js +1 -1
  8. package/dist/esm/apps/contracts/state-machines/contract.json +1 -29
  9. package/dist/esm/apps/contracts/state-machines/escrow.json +2 -32
  10. package/dist/esm/generated/index.js +11 -1
  11. package/dist/esm/metakit/drop-nulls.js +46 -0
  12. package/dist/esm/metakit/normalize.js +140 -0
  13. package/dist/esm/ottochain/metagraph-client.js +147 -0
  14. package/dist/esm/validation.js +1 -1
  15. package/dist/types/generated/index.d.ts +11 -1
  16. package/dist/types/metakit/drop-nulls.d.ts +29 -0
  17. package/dist/types/metakit/normalize.d.ts +67 -0
  18. package/dist/types/ottochain/index.d.ts +1 -1
  19. package/dist/types/ottochain/metagraph-client.d.ts +90 -0
  20. package/package.json +12 -12
  21. package/dist/apps/contracts/index.d.ts +0 -21
  22. package/dist/apps/contracts/index.js +0 -39
  23. package/dist/apps/contracts/types.d.ts +0 -24
  24. package/dist/apps/contracts/types.js +0 -48
  25. package/dist/apps/identity/index.d.ts +0 -22
  26. package/dist/apps/identity/index.js +0 -40
  27. package/dist/apps/identity/types.d.ts +0 -30
  28. package/dist/apps/identity/types.js +0 -53
  29. package/dist/apps/index.d.ts +0 -29
  30. package/dist/apps/index.js +0 -60
  31. package/dist/apps/markets/index.d.ts +0 -26
  32. package/dist/apps/markets/index.js +0 -46
  33. package/dist/apps/markets/types.d.ts +0 -185
  34. package/dist/apps/markets/types.js +0 -252
  35. package/dist/apps/oracles/index.d.ts +0 -26
  36. package/dist/apps/oracles/index.js +0 -46
  37. package/dist/apps/oracles/types.d.ts +0 -211
  38. package/dist/apps/oracles/types.js +0 -306
  39. package/dist/cjs/apps/contracts/types.js +0 -48
  40. package/dist/cjs/apps/corporate/types.js +0 -44
  41. package/dist/cjs/apps/governance/types.js +0 -42
  42. package/dist/cjs/apps/identity/types.js +0 -53
  43. package/dist/cjs/apps/markets/types.js +0 -219
  44. package/dist/cjs/apps/oracles/types.js +0 -282
  45. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
  46. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -392
  47. package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +0 -235
  48. package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
  49. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
  50. package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
  51. package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
  52. package/dist/cjs/generated/ottochain/v1/common_pb.js +0 -37
  53. package/dist/cjs/generated/ottochain/v1/fiber_pb.js +0 -86
  54. package/dist/cjs/generated/ottochain/v1/messages_pb.js +0 -44
  55. package/dist/cjs/generated/ottochain/v1/records_pb.js +0 -44
  56. package/dist/errors.d.ts +0 -221
  57. package/dist/errors.js +0 -293
  58. package/dist/esm/apps/contracts/types.js +0 -44
  59. package/dist/esm/apps/corporate/types.js +0 -38
  60. package/dist/esm/apps/governance/types.js +0 -35
  61. package/dist/esm/apps/identity/types.js +0 -50
  62. package/dist/esm/apps/markets/types.js +0 -206
  63. package/dist/esm/apps/oracles/types.js +0 -267
  64. package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -97
  65. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -389
  66. package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +0 -232
  67. package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +0 -113
  68. package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -76
  69. package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +0 -148
  70. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -106
  71. package/dist/esm/generated/ottochain/v1/common_pb.js +0 -34
  72. package/dist/esm/generated/ottochain/v1/fiber_pb.js +0 -83
  73. package/dist/esm/generated/ottochain/v1/messages_pb.js +0 -41
  74. package/dist/esm/generated/ottochain/v1/records_pb.js +0 -41
  75. package/dist/generated/index.d.ts +0 -15
  76. package/dist/generated/index.js +0 -34
  77. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
  78. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
  79. package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
  80. package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
  81. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
  82. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
  83. package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
  84. package/dist/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
  85. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
  86. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
  87. package/dist/generated/ottochain/v1/common_pb.d.ts +0 -86
  88. package/dist/generated/ottochain/v1/common_pb.js +0 -37
  89. package/dist/generated/ottochain/v1/fiber_pb.d.ts +0 -292
  90. package/dist/generated/ottochain/v1/fiber_pb.js +0 -86
  91. package/dist/generated/ottochain/v1/messages_pb.d.ts +0 -190
  92. package/dist/generated/ottochain/v1/messages_pb.js +0 -44
  93. package/dist/generated/ottochain/v1/records_pb.d.ts +0 -221
  94. package/dist/generated/ottochain/v1/records_pb.js +0 -44
  95. package/dist/index.d.ts +0 -21
  96. package/dist/index.js +0 -77
  97. package/dist/metakit/binary.d.ts +0 -38
  98. package/dist/metakit/binary.js +0 -58
  99. package/dist/metakit/canonicalize.d.ts +0 -26
  100. package/dist/metakit/canonicalize.js +0 -40
  101. package/dist/metakit/codec.d.ts +0 -16
  102. package/dist/metakit/codec.js +0 -45
  103. package/dist/metakit/currency-transaction.d.ts +0 -157
  104. package/dist/metakit/currency-transaction.js +0 -319
  105. package/dist/metakit/currency-types.d.ts +0 -55
  106. package/dist/metakit/currency-types.js +0 -13
  107. package/dist/metakit/hash.d.ts +0 -50
  108. package/dist/metakit/hash.js +0 -84
  109. package/dist/metakit/index.d.ts +0 -23
  110. package/dist/metakit/index.js +0 -74
  111. package/dist/metakit/network/client.d.ts +0 -23
  112. package/dist/metakit/network/client.js +0 -78
  113. package/dist/metakit/network/currency-l1-client.d.ts +0 -71
  114. package/dist/metakit/network/currency-l1-client.js +0 -101
  115. package/dist/metakit/network/data-l1-client.d.ts +0 -57
  116. package/dist/metakit/network/data-l1-client.js +0 -76
  117. package/dist/metakit/network/index.d.ts +0 -10
  118. package/dist/metakit/network/index.js +0 -16
  119. package/dist/metakit/network/types.d.ts +0 -74
  120. package/dist/metakit/network/types.js +0 -20
  121. package/dist/metakit/sign.d.ts +0 -65
  122. package/dist/metakit/sign.js +0 -120
  123. package/dist/metakit/signed-object.d.ts +0 -66
  124. package/dist/metakit/signed-object.js +0 -100
  125. package/dist/metakit/types.d.ts +0 -67
  126. package/dist/metakit/types.js +0 -14
  127. package/dist/metakit/verify.d.ts +0 -55
  128. package/dist/metakit/verify.js +0 -217
  129. package/dist/metakit/wallet.d.ts +0 -70
  130. package/dist/metakit/wallet.js +0 -127
  131. package/dist/ottochain/index.d.ts +0 -13
  132. package/dist/ottochain/index.js +0 -45
  133. package/dist/ottochain/metagraph-client.d.ts +0 -111
  134. package/dist/ottochain/metagraph-client.js +0 -157
  135. package/dist/ottochain/snapshot.d.ts +0 -86
  136. package/dist/ottochain/snapshot.js +0 -110
  137. package/dist/ottochain/types.d.ts +0 -278
  138. package/dist/ottochain/types.js +0 -11
  139. package/dist/types/apps/contracts/types.d.ts +0 -24
  140. package/dist/types/apps/corporate/types.d.ts +0 -9861
  141. package/dist/types/apps/governance/types.d.ts +0 -344
  142. package/dist/types/apps/identity/types.d.ts +0 -30
  143. package/dist/types/apps/markets/types.d.ts +0 -155
  144. package/dist/types/apps/oracles/types.d.ts +0 -193
  145. package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
  146. package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +0 -1172
  147. package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +0 -772
  148. package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
  149. package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
  150. package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
  151. package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
  152. package/dist/types/generated/ottochain/v1/common_pb.d.ts +0 -86
  153. package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +0 -292
  154. package/dist/types/generated/ottochain/v1/messages_pb.d.ts +0 -190
  155. package/dist/types/generated/ottochain/v1/records_pb.d.ts +0 -221
  156. package/dist/validation.d.ts +0 -449
  157. package/dist/validation.js +0 -312
@@ -1,252 +0,0 @@
1
- "use strict";
2
- /**
3
- * Markets Application Types
4
- *
5
- * Constants, types, and utilities for the Markets application on OttoChain.
6
- *
7
- * Note: When proto files are generated, enums will move to generated types.
8
- *
9
- * @packageDocumentation
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isMarketType = exports.isMarketState = exports.calculateGroupBuyDiscount = exports.calculateCrowdfundProgress = exports.validateCommitment = exports.calculateRefund = exports.calculatePayout = exports.calculateFees = exports.calculateNetCommitment = exports.isTerminalMarketState = exports.MARKET_TRANSITIONS = exports.MARKET_TYPE_CONFIGS = exports.DEFAULT_MARKET_CONFIG = exports.CommitmentSide = exports.MarketType = exports.MarketState = void 0;
13
- // ---------------------------------------------------------------------------
14
- // Enums (will be replaced by proto-generated versions)
15
- // ---------------------------------------------------------------------------
16
- /**
17
- * Market lifecycle states
18
- */
19
- var MarketState;
20
- (function (MarketState) {
21
- MarketState[MarketState["UNSPECIFIED"] = 0] = "UNSPECIFIED";
22
- /** Market is open for commitments */
23
- MarketState[MarketState["OPEN"] = 1] = "OPEN";
24
- /** Commitment period has ended, awaiting resolution */
25
- MarketState[MarketState["CLOSED"] = 2] = "CLOSED";
26
- /** Oracle has resolved the outcome */
27
- MarketState[MarketState["RESOLVED"] = 3] = "RESOLVED";
28
- /** Payouts distributed to winners */
29
- MarketState[MarketState["SETTLED"] = 4] = "SETTLED";
30
- /** Market cancelled, refunds issued */
31
- MarketState[MarketState["CANCELLED"] = 5] = "CANCELLED";
32
- /** Market is disputed */
33
- MarketState[MarketState["DISPUTED"] = 6] = "DISPUTED";
34
- })(MarketState || (exports.MarketState = MarketState = {}));
35
- /**
36
- * Types of markets supported
37
- */
38
- var MarketType;
39
- (function (MarketType) {
40
- MarketType[MarketType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
41
- /** Binary or multi-outcome prediction market */
42
- MarketType[MarketType["PREDICTION"] = 1] = "PREDICTION";
43
- /** Ascending/descending price auction */
44
- MarketType[MarketType["AUCTION"] = 2] = "AUCTION";
45
- /** All-or-nothing crowdfunding */
46
- MarketType[MarketType["CROWDFUND"] = 3] = "CROWDFUND";
47
- /** Group buying with volume discounts */
48
- MarketType[MarketType["GROUP_BUY"] = 4] = "GROUP_BUY";
49
- })(MarketType || (exports.MarketType = MarketType = {}));
50
- /**
51
- * Commitment direction (for prediction markets)
52
- */
53
- var CommitmentSide;
54
- (function (CommitmentSide) {
55
- CommitmentSide[CommitmentSide["UNSPECIFIED"] = 0] = "UNSPECIFIED";
56
- CommitmentSide[CommitmentSide["YES"] = 1] = "YES";
57
- CommitmentSide[CommitmentSide["NO"] = 2] = "NO";
58
- })(CommitmentSide || (exports.CommitmentSide = CommitmentSide = {}));
59
- /**
60
- * Default market configuration
61
- */
62
- exports.DEFAULT_MARKET_CONFIG = {
63
- platformFeePercent: 0.01,
64
- creatorFeePercent: 0.02,
65
- oracleFeePercent: 0.01,
66
- minQuorum: 100n,
67
- resolutionWindowEpochs: 24,
68
- disputeWindowEpochs: 12,
69
- minCommitment: 1n,
70
- maxSlippagePercent: 0.05,
71
- };
72
- /**
73
- * Type-specific market configurations
74
- */
75
- exports.MARKET_TYPE_CONFIGS = {
76
- [MarketType.UNSPECIFIED]: {},
77
- [MarketType.PREDICTION]: {
78
- platformFeePercent: 0.02,
79
- oracleFeePercent: 0.02,
80
- },
81
- [MarketType.AUCTION]: {
82
- platformFeePercent: 0.025,
83
- creatorFeePercent: 0,
84
- oracleFeePercent: 0,
85
- minQuorum: 1n,
86
- },
87
- [MarketType.CROWDFUND]: {
88
- platformFeePercent: 0.03,
89
- creatorFeePercent: 0,
90
- oracleFeePercent: 0,
91
- disputeWindowEpochs: 0,
92
- },
93
- [MarketType.GROUP_BUY]: {
94
- platformFeePercent: 0.015,
95
- creatorFeePercent: 0.01,
96
- oracleFeePercent: 0,
97
- },
98
- };
99
- // ---------------------------------------------------------------------------
100
- // State Machine Transitions
101
- // ---------------------------------------------------------------------------
102
- /**
103
- * Valid transitions for each market state
104
- */
105
- exports.MARKET_TRANSITIONS = {
106
- [MarketState.UNSPECIFIED]: [],
107
- [MarketState.OPEN]: ['close', 'cancel'],
108
- [MarketState.CLOSED]: ['resolve', 'dispute', 'cancel'],
109
- [MarketState.RESOLVED]: ['settle', 'dispute'],
110
- [MarketState.SETTLED]: [], // Terminal state
111
- [MarketState.CANCELLED]: [], // Terminal state
112
- [MarketState.DISPUTED]: ['resolve_dispute', 'cancel'],
113
- };
114
- /**
115
- * Check if a market state is terminal
116
- */
117
- function isTerminalMarketState(state) {
118
- return [
119
- MarketState.SETTLED,
120
- MarketState.CANCELLED,
121
- ].includes(state);
122
- }
123
- exports.isTerminalMarketState = isTerminalMarketState;
124
- // ---------------------------------------------------------------------------
125
- // Commitment Calculations
126
- // ---------------------------------------------------------------------------
127
- /**
128
- * Calculate effective commitment after fees
129
- *
130
- * @param amount - Raw commitment amount
131
- * @param config - Market configuration (uses defaults if not provided)
132
- * @returns Net commitment amount after platform fees
133
- */
134
- function calculateNetCommitment(amount, config = {}) {
135
- const feePercent = config.platformFeePercent ?? exports.DEFAULT_MARKET_CONFIG.platformFeePercent;
136
- const feeAmount = (amount * BigInt(Math.floor(feePercent * 10000))) / 10000n;
137
- return amount - feeAmount;
138
- }
139
- exports.calculateNetCommitment = calculateNetCommitment;
140
- /**
141
- * Calculate total fees for a commitment
142
- *
143
- * @param amount - Commitment amount
144
- * @param marketType - Type of market for type-specific fees
145
- * @returns Fee breakdown object
146
- */
147
- function calculateFees(amount, marketType = MarketType.PREDICTION) {
148
- const typeConfig = { ...exports.DEFAULT_MARKET_CONFIG, ...exports.MARKET_TYPE_CONFIGS[marketType] };
149
- const platform = (amount * BigInt(Math.floor(typeConfig.platformFeePercent * 10000))) / 10000n;
150
- const creator = (amount * BigInt(Math.floor(typeConfig.creatorFeePercent * 10000))) / 10000n;
151
- const oracle = (amount * BigInt(Math.floor(typeConfig.oracleFeePercent * 10000))) / 10000n;
152
- return {
153
- platform,
154
- creator,
155
- oracle,
156
- total: platform + creator + oracle,
157
- };
158
- }
159
- exports.calculateFees = calculateFees;
160
- /**
161
- * Calculate payout for a winning commitment in a prediction market
162
- *
163
- * Winner receives: their original + proportional share of losing pool (minus fees)
164
- *
165
- * @param shares - Pool and commitment details
166
- * @param marketType - Type of market for fee calculation
167
- * @returns Payout amount
168
- */
169
- function calculatePayout(shares, marketType = MarketType.PREDICTION) {
170
- if (shares.winningPool === 0n)
171
- return 0n;
172
- const fees = calculateFees(shares.losingPool, marketType);
173
- const distributablePool = shares.losingPool - fees.total;
174
- // Proportional share of losing pool
175
- const winnings = (distributablePool * shares.userCommitment) / shares.winningPool;
176
- // Return original commitment + winnings
177
- return shares.userCommitment + winnings;
178
- }
179
- exports.calculatePayout = calculatePayout;
180
- /**
181
- * Calculate refund for cancelled market
182
- *
183
- * @param commitment - Original commitment amount
184
- * @param refundFeePercent - Optional fee retained on refund (default 0)
185
- * @returns Refund amount
186
- */
187
- function calculateRefund(commitment, refundFeePercent = 0) {
188
- const fee = (commitment * BigInt(Math.floor(refundFeePercent * 10000))) / 10000n;
189
- return commitment - fee;
190
- }
191
- exports.calculateRefund = calculateRefund;
192
- /**
193
- * Validate a commitment against market rules
194
- */
195
- function validateCommitment(amount, marketState, config = {}) {
196
- const minCommitment = config.minCommitment ?? exports.DEFAULT_MARKET_CONFIG.minCommitment;
197
- if (marketState !== MarketState.OPEN) {
198
- return { valid: false, reason: 'Market is not open for commitments' };
199
- }
200
- if (amount < minCommitment) {
201
- return { valid: false, reason: `Commitment below minimum: ${minCommitment}` };
202
- }
203
- return { valid: true };
204
- }
205
- exports.validateCommitment = validateCommitment;
206
- /**
207
- * Calculate crowdfund campaign progress
208
- */
209
- function calculateCrowdfundProgress(current, goal) {
210
- if (goal === 0n) {
211
- return { current, goal, percentComplete: 0, goalReached: false };
212
- }
213
- const percentComplete = Number((current * 10000n) / goal) / 100;
214
- return {
215
- current,
216
- goal,
217
- percentComplete: Math.min(percentComplete, 100),
218
- goalReached: current >= goal,
219
- };
220
- }
221
- exports.calculateCrowdfundProgress = calculateCrowdfundProgress;
222
- /**
223
- * Calculate applicable discount based on participant count
224
- */
225
- function calculateGroupBuyDiscount(participantCount, tiers) {
226
- // Sort tiers descending by minParticipants
227
- const sortedTiers = [...tiers].sort((a, b) => b.minParticipants - a.minParticipants);
228
- for (const tier of sortedTiers) {
229
- if (participantCount >= tier.minParticipants) {
230
- return tier.discountPercent;
231
- }
232
- }
233
- return 0;
234
- }
235
- exports.calculateGroupBuyDiscount = calculateGroupBuyDiscount;
236
- // ---------------------------------------------------------------------------
237
- // Type Guards
238
- // ---------------------------------------------------------------------------
239
- /**
240
- * Check if a value is a valid MarketState
241
- */
242
- function isMarketState(value) {
243
- return typeof value === 'number' && value in MarketState;
244
- }
245
- exports.isMarketState = isMarketState;
246
- /**
247
- * Check if a value is a valid MarketType
248
- */
249
- function isMarketType(value) {
250
- return typeof value === 'number' && value in MarketType;
251
- }
252
- exports.isMarketType = isMarketType;
@@ -1,26 +0,0 @@
1
- /**
2
- * Oracles Application
3
- *
4
- * Types and utilities for the Oracle system on OttoChain.
5
- * Oracles provide truth resolution for markets, disputes, and attestations.
6
- *
7
- * @example
8
- * ```typescript
9
- * import {
10
- * OracleState,
11
- * SlashingReason,
12
- * calculateReputation,
13
- * calculateSlashAmount,
14
- * DEFAULT_ORACLE_CONFIG
15
- * } from '@ottochain/sdk/apps/oracles';
16
- *
17
- * // Calculate new reputation after successful resolution
18
- * const newRep = calculateReputation(50, REPUTATION_DELTAS.successfulResolution);
19
- *
20
- * // Calculate slash for timeout
21
- * const slashAmount = calculateSlashAmount(10000n, SlashingReason.TIMEOUT);
22
- * ```
23
- *
24
- * @packageDocumentation
25
- */
26
- export * from './types.js';
@@ -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;