@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
package/dist/errors.js DELETED
@@ -1,293 +0,0 @@
1
- "use strict";
2
- /**
3
- * Custom Error Classes for OttoChain SDK
4
- *
5
- * Provides structured error handling with error codes and causes.
6
- *
7
- * @packageDocumentation
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.wrapError = exports.isErrorCode = exports.TransactionError = exports.SigningError = exports.ValidationError = exports.NetworkError = exports.OttoChainError = exports.ErrorCode = void 0;
11
- /**
12
- * Error codes for OttoChain SDK errors
13
- */
14
- var ErrorCode;
15
- (function (ErrorCode) {
16
- /** Unknown or unclassified error */
17
- ErrorCode["UNKNOWN"] = "UNKNOWN";
18
- /** Network/HTTP connection failure */
19
- ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
20
- /** Request timeout */
21
- ErrorCode["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
22
- /** Input validation failed */
23
- ErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
24
- /** Invalid private key format */
25
- ErrorCode["INVALID_PRIVATE_KEY"] = "INVALID_PRIVATE_KEY";
26
- /** Invalid public key format */
27
- ErrorCode["INVALID_PUBLIC_KEY"] = "INVALID_PUBLIC_KEY";
28
- /** Invalid DAG address format */
29
- ErrorCode["INVALID_ADDRESS"] = "INVALID_ADDRESS";
30
- /** Signature creation failed */
31
- ErrorCode["SIGNING_ERROR"] = "SIGNING_ERROR";
32
- /** Signature verification failed */
33
- ErrorCode["VERIFICATION_ERROR"] = "VERIFICATION_ERROR";
34
- /** Transaction rejected by network */
35
- ErrorCode["TRANSACTION_REJECTED"] = "TRANSACTION_REJECTED";
36
- /** Transaction not found */
37
- ErrorCode["TRANSACTION_NOT_FOUND"] = "TRANSACTION_NOT_FOUND";
38
- /** Invalid transaction format */
39
- ErrorCode["INVALID_TRANSACTION"] = "INVALID_TRANSACTION";
40
- })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
41
- /**
42
- * Base error class for all OttoChain SDK errors
43
- *
44
- * Provides consistent error structure with:
45
- * - Error code for programmatic handling
46
- * - Human-readable message
47
- * - Optional cause for error chaining
48
- *
49
- * @example
50
- * ```typescript
51
- * try {
52
- * await signTransaction(data, invalidKey);
53
- * } catch (error) {
54
- * if (error instanceof OttoChainError) {
55
- * console.log(error.code); // 'INVALID_PRIVATE_KEY'
56
- * console.log(error.message); // 'Invalid private key format'
57
- * }
58
- * }
59
- * ```
60
- */
61
- class OttoChainError extends Error {
62
- constructor(code, message, cause) {
63
- super(message);
64
- this.name = 'OttoChainError';
65
- this.code = code;
66
- this.cause = cause;
67
- // Maintains proper stack trace for where error was thrown (V8 engines)
68
- if (Error.captureStackTrace) {
69
- Error.captureStackTrace(this, this.constructor);
70
- }
71
- }
72
- /**
73
- * Create a string representation of the error
74
- */
75
- toString() {
76
- let result = `${this.name} [${this.code}]: ${this.message}`;
77
- if (this.cause) {
78
- result += `\nCaused by: ${this.cause.message}`;
79
- }
80
- return result;
81
- }
82
- /**
83
- * Convert error to a plain object for logging/serialization
84
- */
85
- toJSON() {
86
- return {
87
- name: this.name,
88
- code: this.code,
89
- message: this.message,
90
- cause: this.cause?.message,
91
- stack: this.stack,
92
- };
93
- }
94
- }
95
- exports.OttoChainError = OttoChainError;
96
- /**
97
- * Error thrown when network operations fail
98
- *
99
- * Covers HTTP failures, connection errors, and timeouts.
100
- *
101
- * @example
102
- * ```typescript
103
- * try {
104
- * await client.postTransaction(signed);
105
- * } catch (error) {
106
- * if (error instanceof NetworkError) {
107
- * console.log(error.statusCode); // 503
108
- * console.log(error.responseBody); // '{"error": "Service unavailable"}'
109
- * }
110
- * }
111
- * ```
112
- */
113
- class NetworkError extends OttoChainError {
114
- constructor(message, statusCode, responseBody, cause) {
115
- const code = statusCode === undefined ? ErrorCode.NETWORK_ERROR : ErrorCode.NETWORK_ERROR;
116
- super(code, message, cause);
117
- this.name = 'NetworkError';
118
- this.statusCode = statusCode;
119
- this.responseBody = responseBody;
120
- }
121
- /**
122
- * Create a timeout error
123
- */
124
- static timeout(timeoutMs) {
125
- const error = new NetworkError(`Request timed out after ${timeoutMs}ms`);
126
- error.code = ErrorCode.NETWORK_TIMEOUT;
127
- return error;
128
- }
129
- toJSON() {
130
- return {
131
- ...super.toJSON(),
132
- statusCode: this.statusCode,
133
- responseBody: this.responseBody,
134
- };
135
- }
136
- }
137
- exports.NetworkError = NetworkError;
138
- /**
139
- * Error thrown when input validation fails
140
- *
141
- * Used when function parameters don't meet expected format or constraints.
142
- *
143
- * @example
144
- * ```typescript
145
- * try {
146
- * const keyPair = keyPairFromPrivateKey('invalid');
147
- * } catch (error) {
148
- * if (error instanceof ValidationError) {
149
- * console.log(error.field); // 'privateKey'
150
- * console.log(error.value); // 'invalid'
151
- * }
152
- * }
153
- * ```
154
- */
155
- class ValidationError extends OttoChainError {
156
- constructor(message, options) {
157
- super(ErrorCode.VALIDATION_ERROR, message, options?.cause);
158
- this.name = 'ValidationError';
159
- this.field = options?.field;
160
- this.value = options?.value;
161
- this.details = options?.details;
162
- }
163
- toJSON() {
164
- return {
165
- ...super.toJSON(),
166
- field: this.field,
167
- value: this.value,
168
- details: this.details,
169
- };
170
- }
171
- }
172
- exports.ValidationError = ValidationError;
173
- /**
174
- * Error thrown when cryptographic signing operations fail
175
- *
176
- * Covers key derivation, signature creation, and related crypto operations.
177
- *
178
- * @example
179
- * ```typescript
180
- * try {
181
- * const signature = await signHash(hash, privateKey);
182
- * } catch (error) {
183
- * if (error instanceof SigningError) {
184
- * console.log(error.operation); // 'sign'
185
- * }
186
- * }
187
- * ```
188
- */
189
- class SigningError extends OttoChainError {
190
- constructor(message, options) {
191
- super(ErrorCode.SIGNING_ERROR, message, options?.cause);
192
- this.name = 'SigningError';
193
- this.operation = options?.operation;
194
- }
195
- toJSON() {
196
- return {
197
- ...super.toJSON(),
198
- operation: this.operation,
199
- };
200
- }
201
- }
202
- exports.SigningError = SigningError;
203
- /**
204
- * Error thrown when transaction operations fail
205
- *
206
- * Used when transactions are rejected, not found, or invalid.
207
- *
208
- * @example
209
- * ```typescript
210
- * try {
211
- * await client.postTransaction(signed);
212
- * } catch (error) {
213
- * if (error instanceof TransactionError) {
214
- * console.log(error.transactionHash); // 'abc123...'
215
- * console.log(error.rejectionReason); // 'Insufficient balance'
216
- * }
217
- * }
218
- * ```
219
- */
220
- class TransactionError extends OttoChainError {
221
- constructor(code, message, options) {
222
- super(code, message, options?.cause);
223
- this.name = 'TransactionError';
224
- this.transactionHash = options?.transactionHash;
225
- this.rejectionReason = options?.rejectionReason;
226
- }
227
- /**
228
- * Create a transaction rejected error
229
- */
230
- static rejected(reason, transactionHash) {
231
- return new TransactionError(ErrorCode.TRANSACTION_REJECTED, `Transaction rejected: ${reason}`, {
232
- transactionHash,
233
- rejectionReason: reason,
234
- });
235
- }
236
- /**
237
- * Create a transaction not found error
238
- */
239
- static notFound(transactionHash) {
240
- return new TransactionError(ErrorCode.TRANSACTION_NOT_FOUND, `Transaction not found: ${transactionHash}`, {
241
- transactionHash,
242
- });
243
- }
244
- /**
245
- * Create an invalid transaction error
246
- */
247
- static invalid(message, cause) {
248
- return new TransactionError(ErrorCode.INVALID_TRANSACTION, message, { cause });
249
- }
250
- toJSON() {
251
- return {
252
- ...super.toJSON(),
253
- transactionHash: this.transactionHash,
254
- rejectionReason: this.rejectionReason,
255
- };
256
- }
257
- }
258
- exports.TransactionError = TransactionError;
259
- /**
260
- * Check if an error is an OttoChain error with a specific code
261
- *
262
- * @param error - Error to check
263
- * @param code - Error code to match
264
- * @returns True if error matches the code
265
- *
266
- * @example
267
- * ```typescript
268
- * if (isErrorCode(error, ErrorCode.NETWORK_TIMEOUT)) {
269
- * // Retry the request
270
- * }
271
- * ```
272
- */
273
- function isErrorCode(error, code) {
274
- return error instanceof OttoChainError && error.code === code;
275
- }
276
- exports.isErrorCode = isErrorCode;
277
- /**
278
- * Wrap an unknown error in an OttoChainError
279
- *
280
- * @param error - Error to wrap
281
- * @param defaultMessage - Default message if error has no message
282
- * @returns OttoChainError wrapping the original error
283
- */
284
- function wrapError(error, defaultMessage = 'An error occurred') {
285
- if (error instanceof OttoChainError) {
286
- return error;
287
- }
288
- if (error instanceof Error) {
289
- return new OttoChainError(ErrorCode.UNKNOWN, error.message || defaultMessage, error);
290
- }
291
- return new OttoChainError(ErrorCode.UNKNOWN, String(error) || defaultMessage);
292
- }
293
- exports.wrapError = wrapError;
@@ -1,44 +0,0 @@
1
- /**
2
- * Contract Utilities
3
- *
4
- * Constants and utilities for the Contract application.
5
- * Core types are generated from protobuf - see the generated exports.
6
- *
7
- * @packageDocumentation
8
- */
9
- import { ContractState } from '../../generated/ottochain/apps/contracts/v1/contract_pb.js';
10
- // ---------------------------------------------------------------------------
11
- // Configuration Defaults
12
- // ---------------------------------------------------------------------------
13
- /**
14
- * Default contract configuration
15
- */
16
- export const DEFAULT_CONTRACT_CONFIG = {
17
- requireBothSignatures: false,
18
- disputeWindowEpochs: 10,
19
- };
20
- // ---------------------------------------------------------------------------
21
- // State Machine Transitions
22
- // ---------------------------------------------------------------------------
23
- /**
24
- * Valid transitions for each contract state
25
- */
26
- export const CONTRACT_TRANSITIONS = {
27
- [ContractState.UNSPECIFIED]: [],
28
- [ContractState.PROPOSED]: ['accept', 'reject', 'cancel'],
29
- [ContractState.ACTIVE]: ['complete', 'dispute'],
30
- [ContractState.DISPUTED]: ['resolve_for_completer', 'resolve_for_disputant'],
31
- [ContractState.COMPLETED]: [], // Terminal state
32
- [ContractState.REJECTED]: [], // Terminal state
33
- [ContractState.CANCELLED]: [], // Terminal state
34
- };
35
- /**
36
- * Check if a contract state is terminal (no further transitions allowed)
37
- */
38
- export function isTerminalState(state) {
39
- return [
40
- ContractState.COMPLETED,
41
- ContractState.REJECTED,
42
- ContractState.CANCELLED,
43
- ].includes(state);
44
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * Corporate Governance type definitions
3
- *
4
- * TypeScript interfaces for corporate governance state machines covering
5
- * entity lifecycle, board management, shareholder meetings, officers,
6
- * bylaws, committees, resolutions, proxy voting, securities, and compliance.
7
- *
8
- * @see corporate/*.json for JSON state machine definitions
9
- * @packageDocumentation
10
- */
11
- // ---------------------------------------------------------------------------
12
- // State Machine Imports
13
- // ---------------------------------------------------------------------------
14
- import CorporateEntityDefinition from './state-machines/corporate-entity.json';
15
- import CorporateBoardDefinition from './state-machines/corporate-board.json';
16
- import CorporateShareholdersDefinition from './state-machines/corporate-shareholders.json';
17
- import CorporateOfficersDefinition from './state-machines/corporate-officers.json';
18
- import CorporateBylawsDefinition from './state-machines/corporate-bylaws.json';
19
- import CorporateCommitteeDefinition from './state-machines/corporate-committee.json';
20
- import CorporateResolutionDefinition from './state-machines/corporate-resolution.json';
21
- import CorporateProxyDefinition from './state-machines/corporate-proxy.json';
22
- import CorporateSecuritiesDefinition from './state-machines/corporate-securities.json';
23
- import CorporateComplianceDefinition from './state-machines/corporate-compliance.json';
24
- /**
25
- * Corporate governance state machine definitions.
26
- */
27
- export const CORPORATE_DEFINITIONS = {
28
- Entity: CorporateEntityDefinition,
29
- Board: CorporateBoardDefinition,
30
- Shareholders: CorporateShareholdersDefinition,
31
- Officers: CorporateOfficersDefinition,
32
- Bylaws: CorporateBylawsDefinition,
33
- Committee: CorporateCommitteeDefinition,
34
- Resolution: CorporateResolutionDefinition,
35
- Proxy: CorporateProxyDefinition,
36
- Securities: CorporateSecuritiesDefinition,
37
- Compliance: CorporateComplianceDefinition,
38
- };
@@ -1,35 +0,0 @@
1
- /**
2
- * Governance & DAO Types
3
- *
4
- * TypeScript types matching the JSON Logic state machine definitions
5
- * in ottochain/docs/trust-graph/state-machines/dao/
6
- *
7
- * @packageDocumentation
8
- */
9
- // =============================================================================
10
- // Helpers
11
- // =============================================================================
12
- /**
13
- * Type guard for SingleOwnerDAO
14
- */
15
- export function isSingleOwnerDAO(state) {
16
- return state.schema === 'SingleOwnerDAO';
17
- }
18
- /**
19
- * Type guard for MultisigDAO
20
- */
21
- export function isMultisigDAO(state) {
22
- return state.schema === 'MultisigDAO';
23
- }
24
- /**
25
- * Type guard for TokenDAO
26
- */
27
- export function isTokenDAO(state) {
28
- return state.schema === 'TokenDAO';
29
- }
30
- /**
31
- * Type guard for ThresholdDAO
32
- */
33
- export function isThresholdDAO(state) {
34
- return state.schema === 'ThresholdDAO';
35
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * Agent Identity Utilities
3
- *
4
- * Constants and utilities for the Agent Identity application.
5
- * Core types are generated from protobuf - see the generated exports.
6
- *
7
- * @packageDocumentation
8
- */
9
- import { AgentState } from '../../generated/ottochain/apps/identity/v1/agent_pb.js';
10
- import { AttestationType } from '../../generated/ottochain/apps/identity/v1/attestation_pb.js';
11
- // ---------------------------------------------------------------------------
12
- // Configuration Defaults
13
- // ---------------------------------------------------------------------------
14
- /**
15
- * Default reputation configuration for agent identity
16
- */
17
- export const DEFAULT_REPUTATION_CONFIG = {
18
- baseReputation: 10,
19
- completionDelta: 5,
20
- vouchDelta: 2,
21
- violationDelta: -10,
22
- behavioralDelta: 3,
23
- minReputation: 0,
24
- challengeThreshold: 5,
25
- };
26
- // ---------------------------------------------------------------------------
27
- // State Machine Transitions
28
- // ---------------------------------------------------------------------------
29
- /**
30
- * Valid transitions for each agent state
31
- */
32
- export const AGENT_TRANSITIONS = {
33
- [AgentState.UNSPECIFIED]: [],
34
- [AgentState.REGISTERED]: ['activate', 'withdraw'],
35
- [AgentState.ACTIVE]: ['challenge', 'withdraw'],
36
- [AgentState.CHALLENGED]: ['uphold_challenge', 'dismiss_challenge'],
37
- [AgentState.SUSPENDED]: ['begin_probation'],
38
- [AgentState.PROBATION]: ['complete_probation'],
39
- [AgentState.WITHDRAWN]: [], // Terminal state
40
- };
41
- /**
42
- * Reputation delta by attestation type
43
- */
44
- export const ATTESTATION_DELTAS = {
45
- [AttestationType.UNSPECIFIED]: 0,
46
- [AttestationType.COMPLETION]: 5,
47
- [AttestationType.VOUCH]: 2,
48
- [AttestationType.VIOLATION]: -10,
49
- [AttestationType.BEHAVIORAL]: 3,
50
- };
@@ -1,206 +0,0 @@
1
- /**
2
- * Markets Application Types
3
- *
4
- * Constants, types, and utilities for the Markets application on OttoChain.
5
- *
6
- * Core types (MarketType, MarketState, Market, Commitment, Resolution) are
7
- * exported from proto-generated types in index.ts.
8
- *
9
- * @packageDocumentation
10
- */
11
- import { MarketType, MarketState } from '../../generated/ottochain/apps/markets/v1/market_pb.js';
12
- /**
13
- * Commitment direction (for prediction markets)
14
- */
15
- export var CommitmentSide;
16
- (function (CommitmentSide) {
17
- CommitmentSide[CommitmentSide["UNSPECIFIED"] = 0] = "UNSPECIFIED";
18
- CommitmentSide[CommitmentSide["YES"] = 1] = "YES";
19
- CommitmentSide[CommitmentSide["NO"] = 2] = "NO";
20
- })(CommitmentSide || (CommitmentSide = {}));
21
- /**
22
- * Default market configuration
23
- */
24
- export const DEFAULT_MARKET_CONFIG = {
25
- platformFeePercent: 0.01,
26
- creatorFeePercent: 0.02,
27
- oracleFeePercent: 0.01,
28
- minQuorum: 100n,
29
- resolutionWindowEpochs: 24,
30
- disputeWindowEpochs: 12,
31
- minCommitment: 1n,
32
- maxSlippagePercent: 0.05,
33
- };
34
- /**
35
- * Type-specific market configurations
36
- */
37
- export const MARKET_TYPE_CONFIGS = {
38
- [MarketType.UNSPECIFIED]: {},
39
- [MarketType.PREDICTION]: {
40
- platformFeePercent: 0.02,
41
- oracleFeePercent: 0.02,
42
- },
43
- [MarketType.AUCTION]: {
44
- platformFeePercent: 0.025,
45
- creatorFeePercent: 0,
46
- oracleFeePercent: 0,
47
- minQuorum: 1n,
48
- },
49
- [MarketType.CROWDFUND]: {
50
- platformFeePercent: 0.03,
51
- creatorFeePercent: 0,
52
- oracleFeePercent: 0,
53
- disputeWindowEpochs: 0,
54
- },
55
- [MarketType.GROUP_BUY]: {
56
- platformFeePercent: 0.015,
57
- creatorFeePercent: 0.01,
58
- oracleFeePercent: 0,
59
- },
60
- };
61
- // ---------------------------------------------------------------------------
62
- // State Machine Transitions
63
- // ---------------------------------------------------------------------------
64
- /**
65
- * Valid transitions for each market state (aligned with proto MarketState enum)
66
- */
67
- export const MARKET_TRANSITIONS = {
68
- [MarketState.UNSPECIFIED]: [],
69
- [MarketState.PROPOSED]: ['open', 'cancel'],
70
- [MarketState.OPEN]: ['close', 'cancel', 'commit'],
71
- [MarketState.CLOSED]: ['submit_resolution', 'refund'],
72
- [MarketState.RESOLVING]: ['submit_resolution', 'finalize', 'refund'],
73
- [MarketState.SETTLED]: ['claim'], // Terminal (only claims allowed)
74
- [MarketState.REFUNDED]: [], // Terminal state
75
- [MarketState.CANCELLED]: [], // Terminal state
76
- };
77
- /**
78
- * Check if a market state is terminal
79
- */
80
- export function isTerminalMarketState(state) {
81
- return [
82
- MarketState.SETTLED,
83
- MarketState.REFUNDED,
84
- MarketState.CANCELLED,
85
- ].includes(state);
86
- }
87
- // ---------------------------------------------------------------------------
88
- // Commitment Calculations
89
- // ---------------------------------------------------------------------------
90
- /**
91
- * Calculate effective commitment after fees
92
- *
93
- * @param amount - Raw commitment amount
94
- * @param config - Market configuration (uses defaults if not provided)
95
- * @returns Net commitment amount after platform fees
96
- */
97
- export function calculateNetCommitment(amount, config = {}) {
98
- const feePercent = config.platformFeePercent ?? DEFAULT_MARKET_CONFIG.platformFeePercent;
99
- const feeAmount = (amount * BigInt(Math.floor(feePercent * 10000))) / 10000n;
100
- return amount - feeAmount;
101
- }
102
- /**
103
- * Calculate total fees for a commitment
104
- *
105
- * @param amount - Commitment amount
106
- * @param marketType - Type of market for type-specific fees
107
- * @returns Fee breakdown object
108
- */
109
- export function calculateFees(amount, marketType = MarketType.PREDICTION) {
110
- const typeConfig = { ...DEFAULT_MARKET_CONFIG, ...MARKET_TYPE_CONFIGS[marketType] };
111
- const platform = (amount * BigInt(Math.floor(typeConfig.platformFeePercent * 10000))) / 10000n;
112
- const creator = (amount * BigInt(Math.floor(typeConfig.creatorFeePercent * 10000))) / 10000n;
113
- const oracle = (amount * BigInt(Math.floor(typeConfig.oracleFeePercent * 10000))) / 10000n;
114
- return {
115
- platform,
116
- creator,
117
- oracle,
118
- total: platform + creator + oracle,
119
- };
120
- }
121
- /**
122
- * Calculate payout for a winning commitment in a prediction market
123
- *
124
- * Winner receives: their original + proportional share of losing pool (minus fees)
125
- *
126
- * @param shares - Pool and commitment details
127
- * @param marketType - Type of market for fee calculation
128
- * @returns Payout amount
129
- */
130
- export function calculatePayout(shares, marketType = MarketType.PREDICTION) {
131
- if (shares.winningPool === 0n)
132
- return 0n;
133
- const fees = calculateFees(shares.losingPool, marketType);
134
- const distributablePool = shares.losingPool - fees.total;
135
- // Proportional share of losing pool
136
- const winnings = (distributablePool * shares.userCommitment) / shares.winningPool;
137
- // Return original commitment + winnings
138
- return shares.userCommitment + winnings;
139
- }
140
- /**
141
- * Calculate refund for cancelled market
142
- *
143
- * @param commitment - Original commitment amount
144
- * @param refundFeePercent - Optional fee retained on refund (default 0)
145
- * @returns Refund amount
146
- */
147
- export function calculateRefund(commitment, refundFeePercent = 0) {
148
- const fee = (commitment * BigInt(Math.floor(refundFeePercent * 10000))) / 10000n;
149
- return commitment - fee;
150
- }
151
- /**
152
- * Validate a commitment against market rules
153
- */
154
- export function validateCommitment(amount, marketState, config = {}) {
155
- const minCommitment = config.minCommitment ?? DEFAULT_MARKET_CONFIG.minCommitment;
156
- if (marketState !== MarketState.OPEN) {
157
- return { valid: false, reason: 'Market is not open for commitments' };
158
- }
159
- if (amount < minCommitment) {
160
- return { valid: false, reason: `Commitment below minimum: ${minCommitment}` };
161
- }
162
- return { valid: true };
163
- }
164
- /**
165
- * Calculate crowdfund campaign progress
166
- */
167
- export function calculateCrowdfundProgress(current, goal) {
168
- if (goal === 0n) {
169
- return { current, goal, percentComplete: 0, goalReached: false };
170
- }
171
- const percentComplete = Number((current * 10000n) / goal) / 100;
172
- return {
173
- current,
174
- goal,
175
- percentComplete: Math.min(percentComplete, 100),
176
- goalReached: current >= goal,
177
- };
178
- }
179
- /**
180
- * Calculate applicable discount based on participant count
181
- */
182
- export function calculateGroupBuyDiscount(participantCount, tiers) {
183
- // Sort tiers descending by minParticipants
184
- const sortedTiers = [...tiers].sort((a, b) => b.minParticipants - a.minParticipants);
185
- for (const tier of sortedTiers) {
186
- if (participantCount >= tier.minParticipants) {
187
- return tier.discountPercent;
188
- }
189
- }
190
- return 0;
191
- }
192
- // ---------------------------------------------------------------------------
193
- // Type Guards
194
- // ---------------------------------------------------------------------------
195
- /**
196
- * Check if a value is a valid MarketState
197
- */
198
- export function isMarketState(value) {
199
- return typeof value === 'number' && value in MarketState;
200
- }
201
- /**
202
- * Check if a value is a valid MarketType
203
- */
204
- export function isMarketType(value) {
205
- return typeof value === 'number' && value in MarketType;
206
- }