@ottochain/sdk 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +305 -0
- package/dist/apps/contracts/index.d.ts +21 -0
- package/dist/apps/contracts/index.js +39 -0
- package/dist/apps/contracts/types.d.ts +24 -0
- package/dist/apps/contracts/types.js +48 -0
- package/dist/apps/identity/index.d.ts +22 -0
- package/dist/apps/identity/index.js +40 -0
- package/dist/apps/identity/types.d.ts +30 -0
- package/dist/apps/identity/types.js +53 -0
- package/dist/apps/index.d.ts +29 -0
- package/dist/apps/index.js +60 -0
- package/dist/apps/markets/index.d.ts +26 -0
- package/dist/apps/markets/index.js +46 -0
- package/dist/apps/markets/types.d.ts +185 -0
- package/dist/apps/markets/types.js +252 -0
- package/dist/apps/oracles/index.d.ts +26 -0
- package/dist/apps/oracles/index.js +46 -0
- package/dist/apps/oracles/types.d.ts +211 -0
- package/dist/apps/oracles/types.js +306 -0
- package/dist/cjs/apps/contracts/index.js +60 -0
- package/dist/cjs/apps/contracts/state-machines/contract.json +420 -0
- package/dist/cjs/apps/contracts/state-machines/escrow.json +426 -0
- package/dist/cjs/apps/contracts/types.js +48 -0
- package/dist/cjs/apps/corporate/index.js +112 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-board.json +1064 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-bylaws.json +751 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-committee.json +957 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-compliance.json +1293 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-entity.json +861 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-officers.json +843 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-proxy.json +783 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-resolution.json +1174 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-securities.json +1215 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-shareholders.json +1298 -0
- package/dist/cjs/apps/corporate/types.js +44 -0
- package/dist/cjs/apps/governance/index.js +203 -0
- package/dist/cjs/apps/governance/state-machines/dao-multisig.json +711 -0
- package/dist/cjs/apps/governance/state-machines/dao-single.json +258 -0
- package/dist/cjs/apps/governance/state-machines/dao-threshold.json +660 -0
- package/dist/cjs/apps/governance/state-machines/dao-token.json +680 -0
- package/dist/cjs/apps/governance/state-machines/governance-constitution.json +401 -0
- package/dist/cjs/apps/governance/state-machines/governance-executive.json +441 -0
- package/dist/cjs/apps/governance/state-machines/governance-judiciary.json +626 -0
- package/dist/cjs/apps/governance/state-machines/governance-legislature.json +726 -0
- package/dist/cjs/apps/governance/state-machines/governance-simple.json +679 -0
- package/dist/cjs/apps/governance/types.js +42 -0
- package/dist/cjs/apps/identity/constants.js +58 -0
- package/dist/cjs/apps/identity/index.js +78 -0
- package/dist/cjs/apps/identity/state-machines/agent-identity.json +320 -0
- package/dist/cjs/apps/identity/types.js +53 -0
- package/dist/cjs/apps/index.js +58 -0
- package/dist/cjs/apps/markets/index.js +55 -0
- package/dist/cjs/apps/markets/state-machines/market-universal.json +354 -0
- package/dist/cjs/apps/markets/types.js +219 -0
- package/dist/cjs/apps/oracles/index.js +62 -0
- package/dist/cjs/apps/oracles/state-machines/oracle.json +452 -0
- package/dist/cjs/apps/oracles/types.js +282 -0
- package/dist/cjs/errors.js +293 -0
- package/dist/cjs/generated/google/protobuf/struct.js +514 -0
- package/dist/cjs/generated/google/protobuf/timestamp.js +92 -0
- package/dist/cjs/generated/index.js +150 -0
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +873 -0
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +100 -0
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +4515 -0
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +392 -0
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +3255 -0
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +235 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/agent.js +619 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +116 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +780 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +79 -0
- package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +1261 -0
- package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +151 -0
- package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle.js +1223 -0
- package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +109 -0
- package/dist/cjs/generated/ottochain/v1/common.js +10 -0
- package/dist/cjs/generated/ottochain/v1/common_pb.js +37 -0
- package/dist/cjs/generated/ottochain/v1/fiber.js +1057 -0
- package/dist/cjs/generated/ottochain/v1/fiber_pb.js +86 -0
- package/dist/cjs/generated/ottochain/v1/messages.js +740 -0
- package/dist/cjs/generated/ottochain/v1/messages_pb.js +44 -0
- package/dist/cjs/generated/ottochain/v1/records.js +1253 -0
- package/dist/cjs/generated/ottochain/v1/records_pb.js +44 -0
- package/dist/cjs/index.js +79 -0
- package/dist/cjs/metakit/binary.js +58 -0
- package/dist/cjs/metakit/canonicalize.js +40 -0
- package/dist/cjs/metakit/codec.js +45 -0
- package/dist/cjs/metakit/currency-transaction.js +319 -0
- package/dist/cjs/metakit/currency-types.js +13 -0
- package/dist/cjs/metakit/hash.js +84 -0
- package/dist/cjs/metakit/index.js +74 -0
- package/dist/cjs/metakit/network/client.js +78 -0
- package/dist/cjs/metakit/network/currency-l1-client.js +101 -0
- package/dist/cjs/metakit/network/data-l1-client.js +76 -0
- package/dist/cjs/metakit/network/index.js +16 -0
- package/dist/cjs/metakit/network/types.js +20 -0
- package/dist/cjs/metakit/sign.js +120 -0
- package/dist/cjs/metakit/signed-object.js +100 -0
- package/dist/cjs/metakit/types.js +14 -0
- package/dist/cjs/metakit/verify.js +217 -0
- package/dist/cjs/metakit/wallet.js +127 -0
- package/dist/cjs/ottochain/index.js +47 -0
- package/dist/cjs/ottochain/metagraph-client.js +157 -0
- package/dist/cjs/ottochain/snapshot.js +110 -0
- package/dist/cjs/ottochain/types.js +11 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.js +25 -0
- package/dist/cjs/validation.js +312 -0
- package/dist/errors.d.ts +221 -0
- package/dist/errors.js +293 -0
- package/dist/esm/apps/contracts/index.js +42 -0
- package/dist/esm/apps/contracts/state-machines/contract.json +420 -0
- package/dist/esm/apps/contracts/state-machines/escrow.json +426 -0
- package/dist/esm/apps/contracts/types.js +44 -0
- package/dist/esm/apps/corporate/index.js +57 -0
- package/dist/esm/apps/corporate/state-machines/corporate-board.json +1064 -0
- package/dist/esm/apps/corporate/state-machines/corporate-bylaws.json +751 -0
- package/dist/esm/apps/corporate/state-machines/corporate-committee.json +957 -0
- package/dist/esm/apps/corporate/state-machines/corporate-compliance.json +1293 -0
- package/dist/esm/apps/corporate/state-machines/corporate-entity.json +861 -0
- package/dist/esm/apps/corporate/state-machines/corporate-officers.json +843 -0
- package/dist/esm/apps/corporate/state-machines/corporate-proxy.json +783 -0
- package/dist/esm/apps/corporate/state-machines/corporate-resolution.json +1174 -0
- package/dist/esm/apps/corporate/state-machines/corporate-securities.json +1215 -0
- package/dist/esm/apps/corporate/state-machines/corporate-shareholders.json +1298 -0
- package/dist/esm/apps/corporate/types.js +38 -0
- package/dist/esm/apps/governance/index.js +154 -0
- package/dist/esm/apps/governance/state-machines/dao-multisig.json +711 -0
- package/dist/esm/apps/governance/state-machines/dao-single.json +258 -0
- package/dist/esm/apps/governance/state-machines/dao-threshold.json +660 -0
- package/dist/esm/apps/governance/state-machines/dao-token.json +680 -0
- package/dist/esm/apps/governance/state-machines/governance-constitution.json +401 -0
- package/dist/esm/apps/governance/state-machines/governance-executive.json +441 -0
- package/dist/esm/apps/governance/state-machines/governance-judiciary.json +626 -0
- package/dist/esm/apps/governance/state-machines/governance-legislature.json +726 -0
- package/dist/esm/apps/governance/state-machines/governance-simple.json +679 -0
- package/dist/esm/apps/governance/types.js +35 -0
- package/dist/esm/apps/identity/constants.js +53 -0
- package/dist/esm/apps/identity/index.js +50 -0
- package/dist/esm/apps/identity/state-machines/agent-identity.json +320 -0
- package/dist/esm/apps/identity/types.js +50 -0
- package/dist/esm/apps/index.js +32 -0
- package/dist/esm/apps/markets/index.js +34 -0
- package/dist/esm/apps/markets/state-machines/market-universal.json +354 -0
- package/dist/esm/apps/markets/types.js +206 -0
- package/dist/esm/apps/oracles/index.js +42 -0
- package/dist/esm/apps/oracles/state-machines/oracle.json +452 -0
- package/dist/esm/apps/oracles/types.js +267 -0
- package/dist/esm/errors.js +283 -0
- package/dist/esm/generated/google/protobuf/struct.js +508 -0
- package/dist/esm/generated/google/protobuf/timestamp.js +89 -0
- package/dist/esm/generated/index.js +26 -0
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +867 -0
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +97 -0
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +4493 -0
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +389 -0
- package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +3240 -0
- package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +232 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/agent.js +610 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +113 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +774 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +76 -0
- package/dist/esm/generated/ottochain/apps/markets/v1/market.js +1252 -0
- package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +148 -0
- package/dist/esm/generated/ottochain/apps/oracles/v1/oracle.js +1217 -0
- package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +106 -0
- package/dist/esm/generated/ottochain/v1/common.js +7 -0
- package/dist/esm/generated/ottochain/v1/common_pb.js +34 -0
- package/dist/esm/generated/ottochain/v1/fiber.js +1051 -0
- package/dist/esm/generated/ottochain/v1/fiber_pb.js +83 -0
- package/dist/esm/generated/ottochain/v1/messages.js +737 -0
- package/dist/esm/generated/ottochain/v1/messages_pb.js +41 -0
- package/dist/esm/generated/ottochain/v1/records.js +1250 -0
- package/dist/esm/generated/ottochain/v1/records_pb.js +41 -0
- package/dist/esm/index.js +33 -0
- package/dist/esm/metakit/binary.js +53 -0
- package/dist/esm/metakit/canonicalize.js +33 -0
- package/dist/esm/metakit/codec.js +38 -0
- package/dist/esm/metakit/currency-transaction.js +306 -0
- package/dist/esm/metakit/currency-types.js +10 -0
- package/dist/esm/metakit/hash.js +77 -0
- package/dist/esm/metakit/index.js +30 -0
- package/dist/esm/metakit/network/client.js +74 -0
- package/dist/esm/metakit/network/currency-l1-client.js +97 -0
- package/dist/esm/metakit/network/data-l1-client.js +72 -0
- package/dist/esm/metakit/network/index.js +9 -0
- package/dist/esm/metakit/network/types.js +16 -0
- package/dist/esm/metakit/sign.js +114 -0
- package/dist/esm/metakit/signed-object.js +94 -0
- package/dist/esm/metakit/types.js +11 -0
- package/dist/esm/metakit/verify.js +210 -0
- package/dist/esm/metakit/wallet.js +117 -0
- package/dist/esm/ottochain/index.js +13 -0
- package/dist/esm/ottochain/metagraph-client.js +153 -0
- package/dist/esm/ottochain/snapshot.js +100 -0
- package/dist/esm/ottochain/types.js +10 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.js +20 -0
- package/dist/esm/validation.js +301 -0
- package/dist/generated/index.d.ts +15 -0
- package/dist/generated/index.js +34 -0
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +274 -0
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +100 -0
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +211 -0
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +116 -0
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +238 -0
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +79 -0
- package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +436 -0
- package/dist/generated/ottochain/apps/markets/v1/market_pb.js +151 -0
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +393 -0
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +109 -0
- package/dist/generated/ottochain/v1/common_pb.d.ts +86 -0
- package/dist/generated/ottochain/v1/common_pb.js +37 -0
- package/dist/generated/ottochain/v1/fiber_pb.d.ts +292 -0
- package/dist/generated/ottochain/v1/fiber_pb.js +86 -0
- package/dist/generated/ottochain/v1/messages_pb.d.ts +190 -0
- package/dist/generated/ottochain/v1/messages_pb.js +44 -0
- package/dist/generated/ottochain/v1/records_pb.d.ts +221 -0
- package/dist/generated/ottochain/v1/records_pb.js +44 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +77 -0
- package/dist/metakit/binary.d.ts +38 -0
- package/dist/metakit/binary.js +58 -0
- package/dist/metakit/canonicalize.d.ts +26 -0
- package/dist/metakit/canonicalize.js +40 -0
- package/dist/metakit/codec.d.ts +16 -0
- package/dist/metakit/codec.js +45 -0
- package/dist/metakit/currency-transaction.d.ts +157 -0
- package/dist/metakit/currency-transaction.js +319 -0
- package/dist/metakit/currency-types.d.ts +55 -0
- package/dist/metakit/currency-types.js +13 -0
- package/dist/metakit/hash.d.ts +50 -0
- package/dist/metakit/hash.js +84 -0
- package/dist/metakit/index.d.ts +23 -0
- package/dist/metakit/index.js +74 -0
- package/dist/metakit/network/client.d.ts +23 -0
- package/dist/metakit/network/client.js +78 -0
- package/dist/metakit/network/currency-l1-client.d.ts +71 -0
- package/dist/metakit/network/currency-l1-client.js +101 -0
- package/dist/metakit/network/data-l1-client.d.ts +57 -0
- package/dist/metakit/network/data-l1-client.js +76 -0
- package/dist/metakit/network/index.d.ts +10 -0
- package/dist/metakit/network/index.js +16 -0
- package/dist/metakit/network/types.d.ts +74 -0
- package/dist/metakit/network/types.js +20 -0
- package/dist/metakit/sign.d.ts +65 -0
- package/dist/metakit/sign.js +120 -0
- package/dist/metakit/signed-object.d.ts +66 -0
- package/dist/metakit/signed-object.js +100 -0
- package/dist/metakit/types.d.ts +67 -0
- package/dist/metakit/types.js +14 -0
- package/dist/metakit/verify.d.ts +55 -0
- package/dist/metakit/verify.js +217 -0
- package/dist/metakit/wallet.d.ts +70 -0
- package/dist/metakit/wallet.js +127 -0
- package/dist/ottochain/index.d.ts +13 -0
- package/dist/ottochain/index.js +45 -0
- package/dist/ottochain/metagraph-client.d.ts +111 -0
- package/dist/ottochain/metagraph-client.js +157 -0
- package/dist/ottochain/snapshot.d.ts +86 -0
- package/dist/ottochain/snapshot.js +110 -0
- package/dist/ottochain/types.d.ts +278 -0
- package/dist/ottochain/types.js +11 -0
- package/dist/types/apps/contracts/index.d.ts +30 -0
- package/dist/types/apps/contracts/types.d.ts +24 -0
- package/dist/types/apps/corporate/index.d.ts +27 -0
- package/dist/types/apps/corporate/types.d.ts +9861 -0
- package/dist/types/apps/governance/index.d.ts +77 -0
- package/dist/types/apps/governance/types.d.ts +344 -0
- package/dist/types/apps/identity/constants.d.ts +27 -0
- package/dist/types/apps/identity/index.d.ts +39 -0
- package/dist/types/apps/identity/types.d.ts +30 -0
- package/dist/types/apps/index.d.ts +31 -0
- package/dist/types/apps/markets/index.d.ts +26 -0
- package/dist/types/apps/markets/types.d.ts +155 -0
- package/dist/types/apps/oracles/index.d.ts +34 -0
- package/dist/types/apps/oracles/types.d.ts +193 -0
- package/dist/types/errors.d.ts +221 -0
- package/dist/types/generated/google/protobuf/struct.d.ts +134 -0
- package/dist/types/generated/google/protobuf/timestamp.d.ts +134 -0
- package/dist/types/generated/index.d.ts +18 -0
- package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +112 -0
- package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +274 -0
- package/dist/types/generated/ottochain/apps/corporate/v1/corporate.d.ts +376 -0
- package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +1172 -0
- package/dist/types/generated/ottochain/apps/governance/v1/governance.d.ts +296 -0
- package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +772 -0
- package/dist/types/generated/ottochain/apps/identity/v1/agent.d.ts +94 -0
- package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +211 -0
- package/dist/types/generated/ottochain/apps/identity/v1/attestation.d.ts +102 -0
- package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +238 -0
- package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +174 -0
- package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +436 -0
- package/dist/types/generated/ottochain/apps/oracles/v1/oracle.d.ts +150 -0
- package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +393 -0
- package/dist/types/generated/ottochain/v1/common.d.ts +1 -0
- package/dist/types/generated/ottochain/v1/common_pb.d.ts +86 -0
- package/dist/types/generated/ottochain/v1/fiber.d.ts +130 -0
- package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +292 -0
- package/dist/types/generated/ottochain/v1/messages.d.ts +89 -0
- package/dist/types/generated/ottochain/v1/messages_pb.d.ts +190 -0
- package/dist/types/generated/ottochain/v1/records.d.ts +128 -0
- package/dist/types/generated/ottochain/v1/records_pb.d.ts +221 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/metakit/binary.d.ts +38 -0
- package/dist/types/metakit/canonicalize.d.ts +26 -0
- package/dist/types/metakit/codec.d.ts +16 -0
- package/dist/types/metakit/currency-transaction.d.ts +157 -0
- package/dist/types/metakit/currency-types.d.ts +55 -0
- package/dist/types/metakit/hash.d.ts +50 -0
- package/dist/types/metakit/index.d.ts +23 -0
- package/dist/types/metakit/network/client.d.ts +23 -0
- package/dist/types/metakit/network/currency-l1-client.d.ts +71 -0
- package/dist/types/metakit/network/data-l1-client.d.ts +57 -0
- package/dist/types/metakit/network/index.d.ts +10 -0
- package/dist/types/metakit/network/types.d.ts +74 -0
- package/dist/types/metakit/sign.d.ts +65 -0
- package/dist/types/metakit/signed-object.d.ts +66 -0
- package/dist/types/metakit/types.d.ts +67 -0
- package/dist/types/metakit/verify.d.ts +55 -0
- package/dist/types/metakit/wallet.d.ts +70 -0
- package/dist/types/ottochain/index.d.ts +13 -0
- package/dist/types/ottochain/metagraph-client.d.ts +111 -0
- package/dist/types/ottochain/snapshot.d.ts +86 -0
- package/dist/types/ottochain/types.d.ts +210 -0
- package/dist/types/types.d.ts +51 -0
- package/dist/types/validation.d.ts +449 -0
- package/dist/validation.d.ts +449 -0
- package/dist/validation.js +312 -0
- package/package.json +136 -0
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
* Core types (OracleState, Oracle, etc.) are exported from proto-generated
|
|
8
|
+
* types in index.ts.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import { OracleState } from '../../generated/ottochain/apps/oracles/v1/oracle_pb.js';
|
|
13
|
+
/**
|
|
14
|
+
* Types of oracle resolutions
|
|
15
|
+
*/
|
|
16
|
+
export var ResolutionType;
|
|
17
|
+
(function (ResolutionType) {
|
|
18
|
+
ResolutionType[ResolutionType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
19
|
+
/** Binary yes/no outcome */
|
|
20
|
+
ResolutionType[ResolutionType["BINARY"] = 1] = "BINARY";
|
|
21
|
+
/** One of multiple predefined outcomes */
|
|
22
|
+
ResolutionType[ResolutionType["MULTI_CHOICE"] = 2] = "MULTI_CHOICE";
|
|
23
|
+
/** Numeric value (e.g., price) */
|
|
24
|
+
ResolutionType[ResolutionType["NUMERIC"] = 3] = "NUMERIC";
|
|
25
|
+
/** Free-form attestation */
|
|
26
|
+
ResolutionType[ResolutionType["ATTESTATION"] = 4] = "ATTESTATION";
|
|
27
|
+
})(ResolutionType || (ResolutionType = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Reasons for slashing oracle stake
|
|
30
|
+
*/
|
|
31
|
+
export var SlashingReason;
|
|
32
|
+
(function (SlashingReason) {
|
|
33
|
+
SlashingReason[SlashingReason["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
34
|
+
/** Failed to submit resolution in time */
|
|
35
|
+
SlashingReason[SlashingReason["TIMEOUT"] = 1] = "TIMEOUT";
|
|
36
|
+
/** Resolution overturned by dispute */
|
|
37
|
+
SlashingReason[SlashingReason["INCORRECT_RESOLUTION"] = 2] = "INCORRECT_RESOLUTION";
|
|
38
|
+
/** Evidence of collusion or manipulation */
|
|
39
|
+
SlashingReason[SlashingReason["COLLUSION"] = 3] = "COLLUSION";
|
|
40
|
+
/** Violation of oracle protocol */
|
|
41
|
+
SlashingReason[SlashingReason["PROTOCOL_VIOLATION"] = 4] = "PROTOCOL_VIOLATION";
|
|
42
|
+
})(SlashingReason || (SlashingReason = {}));
|
|
43
|
+
/**
|
|
44
|
+
* Default oracle configuration
|
|
45
|
+
*/
|
|
46
|
+
export const DEFAULT_ORACLE_CONFIG = {
|
|
47
|
+
minStake: 10000n,
|
|
48
|
+
timeoutSlashPercent: 0.05,
|
|
49
|
+
incorrectSlashPercent: 0.25,
|
|
50
|
+
collusionSlashPercent: 1.0,
|
|
51
|
+
violationSlashPercent: 0.10,
|
|
52
|
+
cooldownEpochs: 48,
|
|
53
|
+
baseReputation: 50,
|
|
54
|
+
highValueThreshold: 100,
|
|
55
|
+
resolutionWindowEpochs: 12,
|
|
56
|
+
challengeWindowEpochs: 6,
|
|
57
|
+
oracleRewardPercent: 0.01,
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Slashing percentages by reason
|
|
61
|
+
*/
|
|
62
|
+
export const SLASHING_PERCENTAGES = {
|
|
63
|
+
[SlashingReason.UNSPECIFIED]: 0,
|
|
64
|
+
[SlashingReason.TIMEOUT]: DEFAULT_ORACLE_CONFIG.timeoutSlashPercent,
|
|
65
|
+
[SlashingReason.INCORRECT_RESOLUTION]: DEFAULT_ORACLE_CONFIG.incorrectSlashPercent,
|
|
66
|
+
[SlashingReason.COLLUSION]: DEFAULT_ORACLE_CONFIG.collusionSlashPercent,
|
|
67
|
+
[SlashingReason.PROTOCOL_VIOLATION]: DEFAULT_ORACLE_CONFIG.violationSlashPercent,
|
|
68
|
+
};
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// State Machine Transitions
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
/**
|
|
73
|
+
* Valid transitions for each oracle state (aligned with proto OracleState enum)
|
|
74
|
+
*/
|
|
75
|
+
export const ORACLE_TRANSITIONS = {
|
|
76
|
+
[OracleState.UNSPECIFIED]: [],
|
|
77
|
+
[OracleState.UNREGISTERED]: ['register'],
|
|
78
|
+
[OracleState.REGISTERED]: ['activate', 'withdraw'],
|
|
79
|
+
[OracleState.ACTIVE]: ['add_stake', 'record_resolution', 'slash', 'withdraw'],
|
|
80
|
+
[OracleState.SLASHED]: ['reactivate', 'withdraw'],
|
|
81
|
+
[OracleState.WITHDRAWN]: [], // Terminal state
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Check if an oracle state is terminal
|
|
85
|
+
*/
|
|
86
|
+
export function isTerminalOracleState(state) {
|
|
87
|
+
return state === OracleState.WITHDRAWN;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if an oracle can accept new assignments
|
|
91
|
+
*/
|
|
92
|
+
export function canAcceptAssignment(state) {
|
|
93
|
+
return state === OracleState.ACTIVE;
|
|
94
|
+
}
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Reputation Calculations
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
/**
|
|
99
|
+
* Reputation update factors
|
|
100
|
+
*/
|
|
101
|
+
export const REPUTATION_DELTAS = {
|
|
102
|
+
/** Successfully resolved market without challenge */
|
|
103
|
+
successfulResolution: 5,
|
|
104
|
+
/** Resolution upheld after challenge */
|
|
105
|
+
upheldChallenge: 10,
|
|
106
|
+
/** Resolution overturned (negative) */
|
|
107
|
+
overturnedResolution: -25,
|
|
108
|
+
/** Timeout on assigned market (negative) */
|
|
109
|
+
timeout: -15,
|
|
110
|
+
/** Collusion detected (negative) */
|
|
111
|
+
collusion: -100,
|
|
112
|
+
/** Protocol violation (negative) */
|
|
113
|
+
violation: -20,
|
|
114
|
+
/** Bonus for high-value market resolution */
|
|
115
|
+
highValueBonus: 3,
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Calculate new reputation after an event
|
|
119
|
+
*
|
|
120
|
+
* @param currentReputation - Current reputation score
|
|
121
|
+
* @param delta - Reputation change (positive or negative)
|
|
122
|
+
* @param minReputation - Minimum reputation floor (default 0)
|
|
123
|
+
* @returns New reputation score
|
|
124
|
+
*/
|
|
125
|
+
export function calculateReputation(currentReputation, delta, minReputation = 0) {
|
|
126
|
+
return Math.max(minReputation, currentReputation + delta);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Calculate weighted reputation considering history
|
|
130
|
+
*
|
|
131
|
+
* @param baseReputation - Current base reputation
|
|
132
|
+
* @param successCount - Number of successful resolutions
|
|
133
|
+
* @param failureCount - Number of failed/overturned resolutions
|
|
134
|
+
* @returns Weighted reputation score
|
|
135
|
+
*/
|
|
136
|
+
export function calculateWeightedReputation(baseReputation, successCount, failureCount) {
|
|
137
|
+
const totalAttempts = successCount + failureCount;
|
|
138
|
+
if (totalAttempts === 0)
|
|
139
|
+
return baseReputation;
|
|
140
|
+
const successRate = successCount / totalAttempts;
|
|
141
|
+
const experienceMultiplier = Math.min(1 + Math.log10(totalAttempts + 1) * 0.2, 1.5);
|
|
142
|
+
return Math.round(baseReputation * successRate * experienceMultiplier);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if oracle qualifies for high-value markets
|
|
146
|
+
*/
|
|
147
|
+
export function qualifiesForHighValue(reputation, stake, threshold = DEFAULT_ORACLE_CONFIG.highValueThreshold, minStakeMultiplier = 5) {
|
|
148
|
+
return (reputation >= threshold &&
|
|
149
|
+
stake >= DEFAULT_ORACLE_CONFIG.minStake * BigInt(minStakeMultiplier));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Predefined slashing conditions
|
|
153
|
+
*/
|
|
154
|
+
export const SLASHING_CONDITIONS = {
|
|
155
|
+
[SlashingReason.UNSPECIFIED]: {
|
|
156
|
+
reason: SlashingReason.UNSPECIFIED,
|
|
157
|
+
slashPercent: 0,
|
|
158
|
+
description: 'No slashing',
|
|
159
|
+
appealable: false,
|
|
160
|
+
suspensionEpochs: 0,
|
|
161
|
+
},
|
|
162
|
+
[SlashingReason.TIMEOUT]: {
|
|
163
|
+
reason: SlashingReason.TIMEOUT,
|
|
164
|
+
slashPercent: DEFAULT_ORACLE_CONFIG.timeoutSlashPercent,
|
|
165
|
+
description: 'Failed to submit resolution within deadline',
|
|
166
|
+
appealable: true,
|
|
167
|
+
suspensionEpochs: 12,
|
|
168
|
+
},
|
|
169
|
+
[SlashingReason.INCORRECT_RESOLUTION]: {
|
|
170
|
+
reason: SlashingReason.INCORRECT_RESOLUTION,
|
|
171
|
+
slashPercent: DEFAULT_ORACLE_CONFIG.incorrectSlashPercent,
|
|
172
|
+
description: 'Resolution overturned by dispute process',
|
|
173
|
+
appealable: true,
|
|
174
|
+
suspensionEpochs: 48,
|
|
175
|
+
},
|
|
176
|
+
[SlashingReason.COLLUSION]: {
|
|
177
|
+
reason: SlashingReason.COLLUSION,
|
|
178
|
+
slashPercent: DEFAULT_ORACLE_CONFIG.collusionSlashPercent,
|
|
179
|
+
description: 'Evidence of collusion or market manipulation',
|
|
180
|
+
appealable: false,
|
|
181
|
+
suspensionEpochs: -1, // Permanent
|
|
182
|
+
},
|
|
183
|
+
[SlashingReason.PROTOCOL_VIOLATION]: {
|
|
184
|
+
reason: SlashingReason.PROTOCOL_VIOLATION,
|
|
185
|
+
slashPercent: DEFAULT_ORACLE_CONFIG.violationSlashPercent,
|
|
186
|
+
description: 'Violation of oracle operating protocol',
|
|
187
|
+
appealable: true,
|
|
188
|
+
suspensionEpochs: 24,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Calculate slash amount for a given stake and reason
|
|
193
|
+
*
|
|
194
|
+
* @param stake - Oracle's current stake
|
|
195
|
+
* @param reason - Reason for slashing
|
|
196
|
+
* @returns Amount to be slashed
|
|
197
|
+
*/
|
|
198
|
+
export function calculateSlashAmount(stake, reason) {
|
|
199
|
+
const condition = SLASHING_CONDITIONS[reason];
|
|
200
|
+
return (stake * BigInt(Math.floor(condition.slashPercent * 10000))) / 10000n;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Calculate remaining stake after slashing
|
|
204
|
+
*/
|
|
205
|
+
export function calculateStakeAfterSlash(stake, reason) {
|
|
206
|
+
return stake - calculateSlashAmount(stake, reason);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Calculate oracle selection score
|
|
210
|
+
* Higher score = more likely to be selected
|
|
211
|
+
*
|
|
212
|
+
* @param candidate - Oracle candidate details
|
|
213
|
+
* @param marketValue - Value of market to resolve (affects weight for high-value markets)
|
|
214
|
+
* @returns Selection score
|
|
215
|
+
*/
|
|
216
|
+
export function calculateSelectionScore(candidate, marketValue = 0n) {
|
|
217
|
+
const reputationWeight = 0.4;
|
|
218
|
+
const stakeWeight = 0.3;
|
|
219
|
+
const successWeight = 0.2;
|
|
220
|
+
const loadWeight = 0.1;
|
|
221
|
+
// Normalize stake to 0-100 range (assuming 1M max)
|
|
222
|
+
const normalizedStake = Math.min(Number(candidate.stake / 10000n), 100);
|
|
223
|
+
// Load penalty (fewer active = better)
|
|
224
|
+
const loadScore = Math.max(0, 100 - candidate.activeAssignments * 20);
|
|
225
|
+
// High-value market bonus for qualified oracles
|
|
226
|
+
const highValueBonus = marketValue > 100000n &&
|
|
227
|
+
qualifiesForHighValue(candidate.reputation, candidate.stake) ? 10 : 0;
|
|
228
|
+
return (candidate.reputation * reputationWeight +
|
|
229
|
+
normalizedStake * stakeWeight +
|
|
230
|
+
candidate.successRate * 100 * successWeight +
|
|
231
|
+
loadScore * loadWeight +
|
|
232
|
+
highValueBonus);
|
|
233
|
+
}
|
|
234
|
+
// ---------------------------------------------------------------------------
|
|
235
|
+
// Reward Calculations
|
|
236
|
+
// ---------------------------------------------------------------------------
|
|
237
|
+
/**
|
|
238
|
+
* Calculate oracle reward for successful resolution
|
|
239
|
+
*
|
|
240
|
+
* @param marketFees - Total fees collected from market
|
|
241
|
+
* @param rewardPercent - Oracle's reward percentage (default from config)
|
|
242
|
+
* @returns Oracle reward amount
|
|
243
|
+
*/
|
|
244
|
+
export function calculateOracleReward(marketFees, rewardPercent = DEFAULT_ORACLE_CONFIG.oracleRewardPercent) {
|
|
245
|
+
return (marketFees * BigInt(Math.floor(rewardPercent * 10000))) / 10000n;
|
|
246
|
+
}
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
// Type Guards
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
/**
|
|
251
|
+
* Check if a value is a valid OracleState
|
|
252
|
+
*/
|
|
253
|
+
export function isOracleState(value) {
|
|
254
|
+
return typeof value === 'number' && value in OracleState;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Check if a value is a valid SlashingReason
|
|
258
|
+
*/
|
|
259
|
+
export function isSlashingReason(value) {
|
|
260
|
+
return typeof value === 'number' && value in SlashingReason;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Check if a value is a valid ResolutionType
|
|
264
|
+
*/
|
|
265
|
+
export function isResolutionType(value) {
|
|
266
|
+
return typeof value === 'number' && value in ResolutionType;
|
|
267
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Error Classes for OttoChain SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides structured error handling with error codes and causes.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Error codes for OttoChain SDK errors
|
|
10
|
+
*/
|
|
11
|
+
export var ErrorCode;
|
|
12
|
+
(function (ErrorCode) {
|
|
13
|
+
/** Unknown or unclassified error */
|
|
14
|
+
ErrorCode["UNKNOWN"] = "UNKNOWN";
|
|
15
|
+
/** Network/HTTP connection failure */
|
|
16
|
+
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
17
|
+
/** Request timeout */
|
|
18
|
+
ErrorCode["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
|
|
19
|
+
/** Input validation failed */
|
|
20
|
+
ErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
21
|
+
/** Invalid private key format */
|
|
22
|
+
ErrorCode["INVALID_PRIVATE_KEY"] = "INVALID_PRIVATE_KEY";
|
|
23
|
+
/** Invalid public key format */
|
|
24
|
+
ErrorCode["INVALID_PUBLIC_KEY"] = "INVALID_PUBLIC_KEY";
|
|
25
|
+
/** Invalid DAG address format */
|
|
26
|
+
ErrorCode["INVALID_ADDRESS"] = "INVALID_ADDRESS";
|
|
27
|
+
/** Signature creation failed */
|
|
28
|
+
ErrorCode["SIGNING_ERROR"] = "SIGNING_ERROR";
|
|
29
|
+
/** Signature verification failed */
|
|
30
|
+
ErrorCode["VERIFICATION_ERROR"] = "VERIFICATION_ERROR";
|
|
31
|
+
/** Transaction rejected by network */
|
|
32
|
+
ErrorCode["TRANSACTION_REJECTED"] = "TRANSACTION_REJECTED";
|
|
33
|
+
/** Transaction not found */
|
|
34
|
+
ErrorCode["TRANSACTION_NOT_FOUND"] = "TRANSACTION_NOT_FOUND";
|
|
35
|
+
/** Invalid transaction format */
|
|
36
|
+
ErrorCode["INVALID_TRANSACTION"] = "INVALID_TRANSACTION";
|
|
37
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
38
|
+
/**
|
|
39
|
+
* Base error class for all OttoChain SDK errors
|
|
40
|
+
*
|
|
41
|
+
* Provides consistent error structure with:
|
|
42
|
+
* - Error code for programmatic handling
|
|
43
|
+
* - Human-readable message
|
|
44
|
+
* - Optional cause for error chaining
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* try {
|
|
49
|
+
* await signTransaction(data, invalidKey);
|
|
50
|
+
* } catch (error) {
|
|
51
|
+
* if (error instanceof OttoChainError) {
|
|
52
|
+
* console.log(error.code); // 'INVALID_PRIVATE_KEY'
|
|
53
|
+
* console.log(error.message); // 'Invalid private key format'
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export class OttoChainError extends Error {
|
|
59
|
+
constructor(code, message, cause) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = 'OttoChainError';
|
|
62
|
+
this.code = code;
|
|
63
|
+
this.cause = cause;
|
|
64
|
+
// Maintains proper stack trace for where error was thrown (V8 engines)
|
|
65
|
+
if (Error.captureStackTrace) {
|
|
66
|
+
Error.captureStackTrace(this, this.constructor);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a string representation of the error
|
|
71
|
+
*/
|
|
72
|
+
toString() {
|
|
73
|
+
let result = `${this.name} [${this.code}]: ${this.message}`;
|
|
74
|
+
if (this.cause) {
|
|
75
|
+
result += `\nCaused by: ${this.cause.message}`;
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Convert error to a plain object for logging/serialization
|
|
81
|
+
*/
|
|
82
|
+
toJSON() {
|
|
83
|
+
return {
|
|
84
|
+
name: this.name,
|
|
85
|
+
code: this.code,
|
|
86
|
+
message: this.message,
|
|
87
|
+
cause: this.cause?.message,
|
|
88
|
+
stack: this.stack,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Error thrown when network operations fail
|
|
94
|
+
*
|
|
95
|
+
* Covers HTTP failures, connection errors, and timeouts.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* try {
|
|
100
|
+
* await client.postTransaction(signed);
|
|
101
|
+
* } catch (error) {
|
|
102
|
+
* if (error instanceof NetworkError) {
|
|
103
|
+
* console.log(error.statusCode); // 503
|
|
104
|
+
* console.log(error.responseBody); // '{"error": "Service unavailable"}'
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export class NetworkError extends OttoChainError {
|
|
110
|
+
constructor(message, statusCode, responseBody, cause) {
|
|
111
|
+
const code = statusCode === undefined ? ErrorCode.NETWORK_ERROR : ErrorCode.NETWORK_ERROR;
|
|
112
|
+
super(code, message, cause);
|
|
113
|
+
this.name = 'NetworkError';
|
|
114
|
+
this.statusCode = statusCode;
|
|
115
|
+
this.responseBody = responseBody;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create a timeout error
|
|
119
|
+
*/
|
|
120
|
+
static timeout(timeoutMs) {
|
|
121
|
+
const error = new NetworkError(`Request timed out after ${timeoutMs}ms`);
|
|
122
|
+
error.code = ErrorCode.NETWORK_TIMEOUT;
|
|
123
|
+
return error;
|
|
124
|
+
}
|
|
125
|
+
toJSON() {
|
|
126
|
+
return {
|
|
127
|
+
...super.toJSON(),
|
|
128
|
+
statusCode: this.statusCode,
|
|
129
|
+
responseBody: this.responseBody,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Error thrown when input validation fails
|
|
135
|
+
*
|
|
136
|
+
* Used when function parameters don't meet expected format or constraints.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* try {
|
|
141
|
+
* const keyPair = keyPairFromPrivateKey('invalid');
|
|
142
|
+
* } catch (error) {
|
|
143
|
+
* if (error instanceof ValidationError) {
|
|
144
|
+
* console.log(error.field); // 'privateKey'
|
|
145
|
+
* console.log(error.value); // 'invalid'
|
|
146
|
+
* }
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export class ValidationError extends OttoChainError {
|
|
151
|
+
constructor(message, options) {
|
|
152
|
+
super(ErrorCode.VALIDATION_ERROR, message, options?.cause);
|
|
153
|
+
this.name = 'ValidationError';
|
|
154
|
+
this.field = options?.field;
|
|
155
|
+
this.value = options?.value;
|
|
156
|
+
this.details = options?.details;
|
|
157
|
+
}
|
|
158
|
+
toJSON() {
|
|
159
|
+
return {
|
|
160
|
+
...super.toJSON(),
|
|
161
|
+
field: this.field,
|
|
162
|
+
value: this.value,
|
|
163
|
+
details: this.details,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Error thrown when cryptographic signing operations fail
|
|
169
|
+
*
|
|
170
|
+
* Covers key derivation, signature creation, and related crypto operations.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* try {
|
|
175
|
+
* const signature = await signHash(hash, privateKey);
|
|
176
|
+
* } catch (error) {
|
|
177
|
+
* if (error instanceof SigningError) {
|
|
178
|
+
* console.log(error.operation); // 'sign'
|
|
179
|
+
* }
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export class SigningError extends OttoChainError {
|
|
184
|
+
constructor(message, options) {
|
|
185
|
+
super(ErrorCode.SIGNING_ERROR, message, options?.cause);
|
|
186
|
+
this.name = 'SigningError';
|
|
187
|
+
this.operation = options?.operation;
|
|
188
|
+
}
|
|
189
|
+
toJSON() {
|
|
190
|
+
return {
|
|
191
|
+
...super.toJSON(),
|
|
192
|
+
operation: this.operation,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Error thrown when transaction operations fail
|
|
198
|
+
*
|
|
199
|
+
* Used when transactions are rejected, not found, or invalid.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* try {
|
|
204
|
+
* await client.postTransaction(signed);
|
|
205
|
+
* } catch (error) {
|
|
206
|
+
* if (error instanceof TransactionError) {
|
|
207
|
+
* console.log(error.transactionHash); // 'abc123...'
|
|
208
|
+
* console.log(error.rejectionReason); // 'Insufficient balance'
|
|
209
|
+
* }
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export class TransactionError extends OttoChainError {
|
|
214
|
+
constructor(code, message, options) {
|
|
215
|
+
super(code, message, options?.cause);
|
|
216
|
+
this.name = 'TransactionError';
|
|
217
|
+
this.transactionHash = options?.transactionHash;
|
|
218
|
+
this.rejectionReason = options?.rejectionReason;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Create a transaction rejected error
|
|
222
|
+
*/
|
|
223
|
+
static rejected(reason, transactionHash) {
|
|
224
|
+
return new TransactionError(ErrorCode.TRANSACTION_REJECTED, `Transaction rejected: ${reason}`, {
|
|
225
|
+
transactionHash,
|
|
226
|
+
rejectionReason: reason,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Create a transaction not found error
|
|
231
|
+
*/
|
|
232
|
+
static notFound(transactionHash) {
|
|
233
|
+
return new TransactionError(ErrorCode.TRANSACTION_NOT_FOUND, `Transaction not found: ${transactionHash}`, {
|
|
234
|
+
transactionHash,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Create an invalid transaction error
|
|
239
|
+
*/
|
|
240
|
+
static invalid(message, cause) {
|
|
241
|
+
return new TransactionError(ErrorCode.INVALID_TRANSACTION, message, { cause });
|
|
242
|
+
}
|
|
243
|
+
toJSON() {
|
|
244
|
+
return {
|
|
245
|
+
...super.toJSON(),
|
|
246
|
+
transactionHash: this.transactionHash,
|
|
247
|
+
rejectionReason: this.rejectionReason,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Check if an error is an OttoChain error with a specific code
|
|
253
|
+
*
|
|
254
|
+
* @param error - Error to check
|
|
255
|
+
* @param code - Error code to match
|
|
256
|
+
* @returns True if error matches the code
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* if (isErrorCode(error, ErrorCode.NETWORK_TIMEOUT)) {
|
|
261
|
+
* // Retry the request
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
export function isErrorCode(error, code) {
|
|
266
|
+
return error instanceof OttoChainError && error.code === code;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Wrap an unknown error in an OttoChainError
|
|
270
|
+
*
|
|
271
|
+
* @param error - Error to wrap
|
|
272
|
+
* @param defaultMessage - Default message if error has no message
|
|
273
|
+
* @returns OttoChainError wrapping the original error
|
|
274
|
+
*/
|
|
275
|
+
export function wrapError(error, defaultMessage = 'An error occurred') {
|
|
276
|
+
if (error instanceof OttoChainError) {
|
|
277
|
+
return error;
|
|
278
|
+
}
|
|
279
|
+
if (error instanceof Error) {
|
|
280
|
+
return new OttoChainError(ErrorCode.UNKNOWN, error.message || defaultMessage, error);
|
|
281
|
+
}
|
|
282
|
+
return new OttoChainError(ErrorCode.UNKNOWN, String(error) || defaultMessage);
|
|
283
|
+
}
|