@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,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
- };
@@ -1,29 +0,0 @@
1
- /**
2
- * OttoChain Applications
3
- *
4
- * Application-specific types and utilities for OttoChain SDK.
5
- *
6
- * @example
7
- * ```typescript
8
- * import { identity, contracts, markets, oracles } from '@ottochain/sdk/apps';
9
- *
10
- * // Use identity types
11
- * const { AgentState, AGENT_TRANSITIONS } = identity;
12
- *
13
- * // Use market calculations
14
- * const payout = markets.calculatePayout(shares);
15
- *
16
- * // Check oracle reputation
17
- * const newRep = oracles.calculateReputation(current, delta);
18
- * ```
19
- *
20
- * @packageDocumentation
21
- */
22
- export * as identity from './identity/index.js';
23
- export * as contracts from './contracts/index.js';
24
- export * as markets from './markets/index.js';
25
- export * as oracles from './oracles/index.js';
26
- export * from './identity/index.js';
27
- export * from './contracts/index.js';
28
- export * from './markets/index.js';
29
- export * from './oracles/index.js';
@@ -1,60 +0,0 @@
1
- "use strict";
2
- /**
3
- * OttoChain Applications
4
- *
5
- * Application-specific types and utilities for OttoChain SDK.
6
- *
7
- * @example
8
- * ```typescript
9
- * import { identity, contracts, markets, oracles } from '@ottochain/sdk/apps';
10
- *
11
- * // Use identity types
12
- * const { AgentState, AGENT_TRANSITIONS } = identity;
13
- *
14
- * // Use market calculations
15
- * const payout = markets.calculatePayout(shares);
16
- *
17
- * // Check oracle reputation
18
- * const newRep = oracles.calculateReputation(current, delta);
19
- * ```
20
- *
21
- * @packageDocumentation
22
- */
23
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- var desc = Object.getOwnPropertyDescriptor(m, k);
26
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
- desc = { enumerable: true, get: function() { return m[k]; } };
28
- }
29
- Object.defineProperty(o, k2, desc);
30
- }) : (function(o, m, k, k2) {
31
- if (k2 === undefined) k2 = k;
32
- o[k2] = m[k];
33
- }));
34
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
- Object.defineProperty(o, "default", { enumerable: true, value: v });
36
- }) : function(o, v) {
37
- o["default"] = v;
38
- });
39
- var __importStar = (this && this.__importStar) || function (mod) {
40
- if (mod && mod.__esModule) return mod;
41
- var result = {};
42
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
- __setModuleDefault(result, mod);
44
- return result;
45
- };
46
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
47
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.oracles = exports.markets = exports.contracts = exports.identity = void 0;
51
- // Re-export as namespaces for organized access
52
- exports.identity = __importStar(require("./identity/index.js"));
53
- exports.contracts = __importStar(require("./contracts/index.js"));
54
- exports.markets = __importStar(require("./markets/index.js"));
55
- exports.oracles = __importStar(require("./oracles/index.js"));
56
- // Also allow direct imports
57
- __exportStar(require("./identity/index.js"), exports);
58
- __exportStar(require("./contracts/index.js"), exports);
59
- __exportStar(require("./markets/index.js"), exports);
60
- __exportStar(require("./oracles/index.js"), exports);
@@ -1,26 +0,0 @@
1
- /**
2
- * Markets Application
3
- *
4
- * Types and utilities for the Markets system on OttoChain.
5
- * Supports prediction markets, auctions, crowdfunding, and group buys.
6
- *
7
- * @example
8
- * ```typescript
9
- * import {
10
- * MarketState,
11
- * MarketType,
12
- * calculatePayout,
13
- * DEFAULT_MARKET_CONFIG
14
- * } from '@ottochain/sdk/apps/markets';
15
- *
16
- * // Calculate payout for a winning prediction
17
- * const payout = calculatePayout({
18
- * winningPool: 1000n,
19
- * losingPool: 500n,
20
- * userCommitment: 100n,
21
- * });
22
- * ```
23
- *
24
- * @packageDocumentation
25
- */
26
- export * from './types.js';
@@ -1,46 +0,0 @@
1
- "use strict";
2
- /**
3
- * Markets Application
4
- *
5
- * Types and utilities for the Markets system on OttoChain.
6
- * Supports prediction markets, auctions, crowdfunding, and group buys.
7
- *
8
- * @example
9
- * ```typescript
10
- * import {
11
- * MarketState,
12
- * MarketType,
13
- * calculatePayout,
14
- * DEFAULT_MARKET_CONFIG
15
- * } from '@ottochain/sdk/apps/markets';
16
- *
17
- * // Calculate payout for a winning prediction
18
- * const payout = calculatePayout({
19
- * winningPool: 1000n,
20
- * losingPool: 500n,
21
- * userCommitment: 100n,
22
- * });
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/markets/v1/market_pb.js';
44
- // export * from '../../generated/ottochain/apps/markets/v1/commitment_pb.js';
45
- // Export convenience types, constants, and helpers
46
- __exportStar(require("./types.js"), exports);
@@ -1,185 +0,0 @@
1
- /**
2
- * Markets Application Types
3
- *
4
- * Constants, types, and utilities for the Markets application on OttoChain.
5
- *
6
- * Note: When proto files are generated, enums will move to generated types.
7
- *
8
- * @packageDocumentation
9
- */
10
- /**
11
- * Market lifecycle states
12
- */
13
- export declare enum MarketState {
14
- UNSPECIFIED = 0,
15
- /** Market is open for commitments */
16
- OPEN = 1,
17
- /** Commitment period has ended, awaiting resolution */
18
- CLOSED = 2,
19
- /** Oracle has resolved the outcome */
20
- RESOLVED = 3,
21
- /** Payouts distributed to winners */
22
- SETTLED = 4,
23
- /** Market cancelled, refunds issued */
24
- CANCELLED = 5,
25
- /** Market is disputed */
26
- DISPUTED = 6
27
- }
28
- /**
29
- * Types of markets supported
30
- */
31
- export declare enum MarketType {
32
- UNSPECIFIED = 0,
33
- /** Binary or multi-outcome prediction market */
34
- PREDICTION = 1,
35
- /** Ascending/descending price auction */
36
- AUCTION = 2,
37
- /** All-or-nothing crowdfunding */
38
- CROWDFUND = 3,
39
- /** Group buying with volume discounts */
40
- GROUP_BUY = 4
41
- }
42
- /**
43
- * Commitment direction (for prediction markets)
44
- */
45
- export declare enum CommitmentSide {
46
- UNSPECIFIED = 0,
47
- YES = 1,
48
- NO = 2
49
- }
50
- /**
51
- * Market configuration type
52
- */
53
- export interface MarketConfig {
54
- /** Platform fee as percentage (0.01 = 1%) */
55
- platformFeePercent: number;
56
- /** Market creator fee as percentage */
57
- creatorFeePercent: number;
58
- /** Oracle fee as percentage */
59
- oracleFeePercent: number;
60
- /** Minimum quorum for market validity (in tokens) */
61
- minQuorum: bigint;
62
- /** Default resolution window in epochs */
63
- resolutionWindowEpochs: number;
64
- /** Dispute window after resolution in epochs */
65
- disputeWindowEpochs: number;
66
- /** Minimum commitment amount */
67
- minCommitment: bigint;
68
- /** Maximum slippage for AMM-style markets */
69
- maxSlippagePercent: number;
70
- }
71
- /**
72
- * Default market configuration
73
- */
74
- export declare const DEFAULT_MARKET_CONFIG: MarketConfig;
75
- /**
76
- * Type-specific market configurations
77
- */
78
- export declare const MARKET_TYPE_CONFIGS: Record<MarketType, Partial<MarketConfig>>;
79
- /**
80
- * Valid transitions for each market state
81
- */
82
- export declare const MARKET_TRANSITIONS: Record<MarketState, readonly string[]>;
83
- /**
84
- * Check if a market state is terminal
85
- */
86
- export declare function isTerminalMarketState(state: MarketState): boolean;
87
- /**
88
- * Calculate effective commitment after fees
89
- *
90
- * @param amount - Raw commitment amount
91
- * @param config - Market configuration (uses defaults if not provided)
92
- * @returns Net commitment amount after platform fees
93
- */
94
- export declare function calculateNetCommitment(amount: bigint, config?: Partial<MarketConfig>): bigint;
95
- /**
96
- * Calculate total fees for a commitment
97
- *
98
- * @param amount - Commitment amount
99
- * @param marketType - Type of market for type-specific fees
100
- * @returns Fee breakdown object
101
- */
102
- export declare function calculateFees(amount: bigint, marketType?: MarketType): {
103
- platform: bigint;
104
- creator: bigint;
105
- oracle: bigint;
106
- total: bigint;
107
- };
108
- /**
109
- * Outcome shares for payout calculation
110
- */
111
- export interface OutcomeShares {
112
- /** Total committed to winning outcome */
113
- winningPool: bigint;
114
- /** Total committed to losing outcome(s) */
115
- losingPool: bigint;
116
- /** Individual's commitment to winning outcome */
117
- userCommitment: bigint;
118
- }
119
- /**
120
- * Calculate payout for a winning commitment in a prediction market
121
- *
122
- * Winner receives: their original + proportional share of losing pool (minus fees)
123
- *
124
- * @param shares - Pool and commitment details
125
- * @param marketType - Type of market for fee calculation
126
- * @returns Payout amount
127
- */
128
- export declare function calculatePayout(shares: OutcomeShares, marketType?: MarketType): bigint;
129
- /**
130
- * Calculate refund for cancelled market
131
- *
132
- * @param commitment - Original commitment amount
133
- * @param refundFeePercent - Optional fee retained on refund (default 0)
134
- * @returns Refund amount
135
- */
136
- export declare function calculateRefund(commitment: bigint, refundFeePercent?: number): bigint;
137
- /**
138
- * Validate a commitment meets market requirements
139
- */
140
- export interface CommitmentValidation {
141
- valid: boolean;
142
- reason?: string;
143
- }
144
- /**
145
- * Validate a commitment against market rules
146
- */
147
- export declare function validateCommitment(amount: bigint, marketState: MarketState, config?: Partial<MarketConfig>): CommitmentValidation;
148
- /**
149
- * Calculate crowdfund progress
150
- */
151
- export interface CrowdfundProgress {
152
- /** Current total committed */
153
- current: bigint;
154
- /** Target goal */
155
- goal: bigint;
156
- /** Percentage complete (0-100) */
157
- percentComplete: number;
158
- /** Whether goal has been reached */
159
- goalReached: boolean;
160
- }
161
- /**
162
- * Calculate crowdfund campaign progress
163
- */
164
- export declare function calculateCrowdfundProgress(current: bigint, goal: bigint): CrowdfundProgress;
165
- /**
166
- * Tier definition for group buys
167
- */
168
- export interface GroupBuyTier {
169
- /** Minimum participants for this tier */
170
- minParticipants: number;
171
- /** Discount percentage for this tier */
172
- discountPercent: number;
173
- }
174
- /**
175
- * Calculate applicable discount based on participant count
176
- */
177
- export declare function calculateGroupBuyDiscount(participantCount: number, tiers: GroupBuyTier[]): number;
178
- /**
179
- * Check if a value is a valid MarketState
180
- */
181
- export declare function isMarketState(value: unknown): value is MarketState;
182
- /**
183
- * Check if a value is a valid MarketType
184
- */
185
- export declare function isMarketType(value: unknown): value is MarketType;
@@ -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';