@vultisig/rujira 1.0.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 (118) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +254 -0
  3. package/dist/assets/amount.d.ts +80 -0
  4. package/dist/assets/amount.d.ts.map +1 -0
  5. package/dist/assets/amount.js +186 -0
  6. package/dist/assets/asset.d.ts +43 -0
  7. package/dist/assets/asset.d.ts.map +1 -0
  8. package/dist/assets/asset.js +1 -0
  9. package/dist/assets/formats.d.ts +54 -0
  10. package/dist/assets/formats.d.ts.map +1 -0
  11. package/dist/assets/formats.js +164 -0
  12. package/dist/assets/index.d.ts +27 -0
  13. package/dist/assets/index.d.ts.map +1 -0
  14. package/dist/assets/index.js +45 -0
  15. package/dist/assets/registry.d.ts +37 -0
  16. package/dist/assets/registry.d.ts.map +1 -0
  17. package/dist/assets/registry.js +487 -0
  18. package/dist/assets/router.d.ts +44 -0
  19. package/dist/assets/router.d.ts.map +1 -0
  20. package/dist/assets/router.js +142 -0
  21. package/dist/client.d.ts +70 -0
  22. package/dist/client.d.ts.map +1 -0
  23. package/dist/client.js +250 -0
  24. package/dist/config/constants.d.ts +25 -0
  25. package/dist/config/constants.d.ts.map +1 -0
  26. package/dist/config/constants.js +36 -0
  27. package/dist/config.d.ts +41 -0
  28. package/dist/config.d.ts.map +1 -0
  29. package/dist/config.js +72 -0
  30. package/dist/discovery/discovery.d.ts +39 -0
  31. package/dist/discovery/discovery.d.ts.map +1 -0
  32. package/dist/discovery/discovery.js +250 -0
  33. package/dist/discovery/graphql-client.d.ts +46 -0
  34. package/dist/discovery/graphql-client.d.ts.map +1 -0
  35. package/dist/discovery/graphql-client.js +137 -0
  36. package/dist/discovery/index.d.ts +9 -0
  37. package/dist/discovery/index.d.ts.map +1 -0
  38. package/dist/discovery/index.js +7 -0
  39. package/dist/discovery/types.d.ts +62 -0
  40. package/dist/discovery/types.d.ts.map +1 -0
  41. package/dist/discovery/types.js +5 -0
  42. package/dist/easy-routes.d.ts +216 -0
  43. package/dist/easy-routes.d.ts.map +1 -0
  44. package/dist/easy-routes.js +241 -0
  45. package/dist/errors.d.ts +65 -0
  46. package/dist/errors.d.ts.map +1 -0
  47. package/dist/errors.js +184 -0
  48. package/dist/index.d.ts +46 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +46 -0
  51. package/dist/modules/assets.d.ts +68 -0
  52. package/dist/modules/assets.d.ts.map +1 -0
  53. package/dist/modules/assets.js +127 -0
  54. package/dist/modules/deposit.d.ts +152 -0
  55. package/dist/modules/deposit.d.ts.map +1 -0
  56. package/dist/modules/deposit.js +233 -0
  57. package/dist/modules/index.d.ts +12 -0
  58. package/dist/modules/index.d.ts.map +1 -0
  59. package/dist/modules/index.js +9 -0
  60. package/dist/modules/orderbook.d.ts +80 -0
  61. package/dist/modules/orderbook.d.ts.map +1 -0
  62. package/dist/modules/orderbook.js +320 -0
  63. package/dist/modules/swap.d.ts +48 -0
  64. package/dist/modules/swap.d.ts.map +1 -0
  65. package/dist/modules/swap.js +318 -0
  66. package/dist/modules/withdraw.d.ts +46 -0
  67. package/dist/modules/withdraw.d.ts.map +1 -0
  68. package/dist/modules/withdraw.js +218 -0
  69. package/dist/services/fee-estimator.d.ts +14 -0
  70. package/dist/services/fee-estimator.d.ts.map +1 -0
  71. package/dist/services/fee-estimator.js +89 -0
  72. package/dist/services/price-impact.d.ts +11 -0
  73. package/dist/services/price-impact.d.ts.map +1 -0
  74. package/dist/services/price-impact.js +58 -0
  75. package/dist/signer/index.d.ts +3 -0
  76. package/dist/signer/index.d.ts.map +1 -0
  77. package/dist/signer/index.js +1 -0
  78. package/dist/signer/keysign-builder.d.ts +21 -0
  79. package/dist/signer/keysign-builder.d.ts.map +1 -0
  80. package/dist/signer/keysign-builder.js +106 -0
  81. package/dist/signer/types.d.ts +81 -0
  82. package/dist/signer/types.d.ts.map +1 -0
  83. package/dist/signer/types.js +8 -0
  84. package/dist/signer/vultisig-provider.d.ts +33 -0
  85. package/dist/signer/vultisig-provider.d.ts.map +1 -0
  86. package/dist/signer/vultisig-provider.js +242 -0
  87. package/dist/types.d.ts +375 -0
  88. package/dist/types.d.ts.map +1 -0
  89. package/dist/types.js +18 -0
  90. package/dist/utils/cache.d.ts +87 -0
  91. package/dist/utils/cache.d.ts.map +1 -0
  92. package/dist/utils/cache.js +124 -0
  93. package/dist/utils/denom-conversion.d.ts +47 -0
  94. package/dist/utils/denom-conversion.d.ts.map +1 -0
  95. package/dist/utils/denom-conversion.js +105 -0
  96. package/dist/utils/encoding.d.ts +17 -0
  97. package/dist/utils/encoding.d.ts.map +1 -0
  98. package/dist/utils/encoding.js +55 -0
  99. package/dist/utils/format.d.ts +108 -0
  100. package/dist/utils/format.d.ts.map +1 -0
  101. package/dist/utils/format.js +213 -0
  102. package/dist/utils/index.d.ts +10 -0
  103. package/dist/utils/index.d.ts.map +1 -0
  104. package/dist/utils/index.js +9 -0
  105. package/dist/utils/memo.d.ts +107 -0
  106. package/dist/utils/memo.d.ts.map +1 -0
  107. package/dist/utils/memo.js +190 -0
  108. package/dist/utils/rate-limiter.d.ts +38 -0
  109. package/dist/utils/rate-limiter.d.ts.map +1 -0
  110. package/dist/utils/rate-limiter.js +67 -0
  111. package/dist/utils/type-guards.d.ts +22 -0
  112. package/dist/utils/type-guards.d.ts.map +1 -0
  113. package/dist/utils/type-guards.js +27 -0
  114. package/dist/validation/address-validator.d.ts +15 -0
  115. package/dist/validation/address-validator.d.ts.map +1 -0
  116. package/dist/validation/address-validator.js +75 -0
  117. package/package.json +98 -0
  118. package/src/__tests__/live/README.md +47 -0
@@ -0,0 +1,242 @@
1
+ import { base64Encode, bytesToBase64, hexEncode } from '../utils/encoding.js';
2
+ const THORCHAIN_CONFIG = {
3
+ chain: 'THORChain',
4
+ ticker: 'RUNE',
5
+ decimals: 8,
6
+ };
7
+ export class VultisigRujiraProvider {
8
+ constructor(vault, chainId = 'thorchain-1') {
9
+ this.cachedAddress = null;
10
+ this.cachedChainPubKey = null;
11
+ this.vault = vault;
12
+ this.chainId = chainId;
13
+ }
14
+ getVault() {
15
+ return this.vault;
16
+ }
17
+ async getChainPublicKey() {
18
+ if (this.cachedChainPubKey) {
19
+ return this.cachedChainPubKey;
20
+ }
21
+ const address = await this.getAddress();
22
+ const keysignPayload = await this.vault.prepareSignDirectTx({
23
+ chain: THORCHAIN_CONFIG.chain,
24
+ coin: {
25
+ chain: THORCHAIN_CONFIG.chain,
26
+ address,
27
+ decimals: THORCHAIN_CONFIG.decimals,
28
+ ticker: THORCHAIN_CONFIG.ticker,
29
+ },
30
+ bodyBytes: base64Encode('dummy'),
31
+ authInfoBytes: base64Encode('dummy'),
32
+ chainId: this.chainId,
33
+ accountNumber: '0',
34
+ });
35
+ const hexPubKey = keysignPayload.coin?.hexPublicKey;
36
+ if (!hexPubKey) {
37
+ throw new Error(`VultisigRujiraProvider: Could not derive public key for chain ${THORCHAIN_CONFIG.chain}. Verify vault supports this chain.`);
38
+ }
39
+ this.cachedChainPubKey = this.hexToBytes(hexPubKey);
40
+ return this.cachedChainPubKey;
41
+ }
42
+ async getAccounts() {
43
+ const address = await this.getAddress();
44
+ const pubkey = await this.getChainPublicKey();
45
+ return [{ address, pubkey, algo: 'secp256k1' }];
46
+ }
47
+ async signDirect(signerAddress, signDoc) {
48
+ const ourAddress = await this.getAddress();
49
+ if (signerAddress !== ourAddress) {
50
+ throw new Error(`Signer address mismatch: expected ${ourAddress}, got ${signerAddress}`);
51
+ }
52
+ if (signDoc.chainId !== this.chainId) {
53
+ throw new Error(`Chain ID mismatch: expected ${this.chainId}, got ${signDoc.chainId}`);
54
+ }
55
+ const keysignPayload = await this.vault.prepareSignDirectTx({
56
+ chain: THORCHAIN_CONFIG.chain,
57
+ coin: {
58
+ chain: THORCHAIN_CONFIG.chain,
59
+ address: ourAddress,
60
+ decimals: THORCHAIN_CONFIG.decimals,
61
+ ticker: THORCHAIN_CONFIG.ticker,
62
+ },
63
+ bodyBytes: this.uint8ArrayToBase64(signDoc.bodyBytes),
64
+ authInfoBytes: this.uint8ArrayToBase64(signDoc.authInfoBytes),
65
+ chainId: signDoc.chainId,
66
+ accountNumber: signDoc.accountNumber.toString(),
67
+ });
68
+ const messageHashes = await this.vault.extractMessageHashes(keysignPayload);
69
+ const signature = await this.vault.sign({
70
+ transaction: keysignPayload,
71
+ chain: THORCHAIN_CONFIG.chain,
72
+ messageHashes,
73
+ });
74
+ const normalizedSig = this.normalizeSignature(signature);
75
+ const coinPubKey = keysignPayload.coin?.hexPublicKey;
76
+ if (!coinPubKey) {
77
+ throw new Error(`VultisigRujiraProvider: Missing public key in signed payload for ${THORCHAIN_CONFIG.chain}`);
78
+ }
79
+ const pubKey = this.hexToBytes(coinPubKey);
80
+ return {
81
+ signed: signDoc,
82
+ signature: {
83
+ pub_key: {
84
+ type: 'tendermint/PubKeySecp256k1',
85
+ value: bytesToBase64(pubKey),
86
+ },
87
+ signature: this.hexToBase64(normalizedSig),
88
+ },
89
+ };
90
+ }
91
+ derToRaw(derHex) {
92
+ const der = this.hexToBytes(derHex);
93
+ if (der[0] !== 0x30) {
94
+ return derHex;
95
+ }
96
+ let offset = 2;
97
+ if (der[offset] !== 0x02)
98
+ throw new Error('Invalid DER: expected 0x02 for r');
99
+ offset++;
100
+ const rLen = der[offset++];
101
+ let r = der.slice(offset, offset + rLen);
102
+ offset += rLen;
103
+ if (der[offset] !== 0x02)
104
+ throw new Error('Invalid DER: expected 0x02 for s');
105
+ offset++;
106
+ const sLen = der[offset++];
107
+ let s = der.slice(offset, offset + sLen);
108
+ while (r.length > 32 && r[0] === 0)
109
+ r = r.slice(1);
110
+ while (s.length > 32 && s[0] === 0)
111
+ s = s.slice(1);
112
+ while (r.length < 32)
113
+ r = new Uint8Array([0, ...r]);
114
+ while (s.length < 32)
115
+ s = new Uint8Array([0, ...s]);
116
+ const raw = new Uint8Array(64);
117
+ raw.set(r, 0);
118
+ raw.set(s, 32);
119
+ return hexEncode(raw);
120
+ }
121
+ normalizeSignature(signature) {
122
+ if (!signature || typeof signature !== 'object') {
123
+ throw new Error('Invalid signature: expected object, got ' + typeof signature);
124
+ }
125
+ if (!signature.signature || typeof signature.signature !== 'string') {
126
+ throw new Error('Invalid signature: missing or invalid signature field');
127
+ }
128
+ let sig = signature.signature.trim();
129
+ // Check for empty signature after trimming
130
+ if (sig.length === 0) {
131
+ throw new Error('Invalid signature: empty signature string');
132
+ }
133
+ const hexRegex = /^(0x)?[0-9a-fA-F]+$/;
134
+ if (!hexRegex.test(sig)) {
135
+ throw new Error('Invalid signature format: expected hex string, got non-hex characters');
136
+ }
137
+ sig = sig.startsWith('0x') ? sig.slice(2) : sig;
138
+ if (sig.length < 128) {
139
+ throw new Error(`Invalid signature length: too short, expected at least 128 hex chars, got ${sig.length}`);
140
+ }
141
+ if (sig.length > 200) {
142
+ throw new Error(`Invalid signature length: too long, got ${sig.length} hex chars`);
143
+ }
144
+ if (sig.length > 130) {
145
+ try {
146
+ sig = this.derToRaw(sig);
147
+ }
148
+ catch (error) {
149
+ throw new Error(`Failed to convert DER signature to raw format: ${error instanceof Error ? error.message : String(error)}`);
150
+ }
151
+ }
152
+ if (sig.length !== 128 && sig.length !== 130) {
153
+ throw new Error(`Invalid signature length: expected exactly 128 or 130 hex chars, got ${sig.length}`);
154
+ }
155
+ const rHex = sig.slice(0, 64);
156
+ const sHex = sig.slice(64, 128);
157
+ if (rHex === '0'.repeat(64) || sHex === '0'.repeat(64)) {
158
+ throw new Error('Invalid signature: r or s value is zero');
159
+ }
160
+ const secp256k1Order = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141');
161
+ const r = BigInt('0x' + rHex);
162
+ const s = BigInt('0x' + sHex);
163
+ if (r >= secp256k1Order || s >= secp256k1Order) {
164
+ throw new Error('Invalid signature: r or s value exceeds secp256k1 curve order');
165
+ }
166
+ return sig.slice(0, 128);
167
+ }
168
+ async getAddress() {
169
+ if (this.cachedAddress === null) {
170
+ this.cachedAddress = await this.vault.address(THORCHAIN_CONFIG.chain);
171
+ }
172
+ return this.cachedAddress;
173
+ }
174
+ getPublicKeyBytes() {
175
+ return this.hexToBytes(this.vault.publicKeys.ecdsa);
176
+ }
177
+ getPublicKeyHex() {
178
+ return this.vault.publicKeys.ecdsa;
179
+ }
180
+ getChainId() {
181
+ return this.chainId;
182
+ }
183
+ clearCache() {
184
+ this.cachedAddress = null;
185
+ }
186
+ async signAndBroadcast(signDoc) {
187
+ if (signDoc.chainId !== this.chainId) {
188
+ throw new Error(`Chain ID mismatch: expected ${this.chainId}, got ${signDoc.chainId}`);
189
+ }
190
+ const address = await this.getAddress();
191
+ const keysignPayload = await this.vault.prepareSignDirectTx({
192
+ chain: THORCHAIN_CONFIG.chain,
193
+ coin: {
194
+ chain: THORCHAIN_CONFIG.chain,
195
+ address,
196
+ decimals: THORCHAIN_CONFIG.decimals,
197
+ ticker: THORCHAIN_CONFIG.ticker,
198
+ },
199
+ bodyBytes: this.uint8ArrayToBase64(signDoc.bodyBytes),
200
+ authInfoBytes: this.uint8ArrayToBase64(signDoc.authInfoBytes),
201
+ chainId: signDoc.chainId,
202
+ accountNumber: signDoc.accountNumber.toString(),
203
+ });
204
+ const messageHashes = await this.vault.extractMessageHashes(keysignPayload);
205
+ const signature = await this.vault.sign({
206
+ transaction: keysignPayload,
207
+ chain: THORCHAIN_CONFIG.chain,
208
+ messageHashes,
209
+ });
210
+ return this.vault.broadcastTx({
211
+ chain: THORCHAIN_CONFIG.chain,
212
+ keysignPayload,
213
+ signature,
214
+ });
215
+ }
216
+ hexToBytes(hex) {
217
+ const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
218
+ const bytes = new Uint8Array(cleanHex.length / 2);
219
+ for (let i = 0; i < cleanHex.length; i += 2) {
220
+ bytes[i / 2] = parseInt(cleanHex.slice(i, i + 2), 16);
221
+ }
222
+ return bytes;
223
+ }
224
+ hexToBase64(hex) {
225
+ return bytesToBase64(this.hexToBytes(hex));
226
+ }
227
+ uint8ArrayToBase64(bytes) {
228
+ return bytesToBase64(bytes);
229
+ }
230
+ }
231
+ export function isVultisigVault(vault) {
232
+ if (!vault || typeof vault !== 'object')
233
+ return false;
234
+ const v = vault;
235
+ return (typeof v.address === 'function' &&
236
+ typeof v.publicKeys === 'object' &&
237
+ v.publicKeys !== null &&
238
+ typeof v.publicKeys.ecdsa === 'string' &&
239
+ typeof v.prepareSignDirectTx === 'function' &&
240
+ typeof v.extractMessageHashes === 'function' &&
241
+ typeof v.sign === 'function');
242
+ }
@@ -0,0 +1,375 @@
1
+ /**
2
+ * Core type definitions for Rujira SDK
3
+ * @module types
4
+ */
5
+ /**
6
+ * Rujira asset representation
7
+ * Format: "CHAIN.SYMBOL" (e.g., "THOR.RUNE", "BTC.BTC")
8
+ */
9
+ export type RujiraAsset = {
10
+ /** Full asset identifier (e.g., "THOR.RUNE") */
11
+ asset: string;
12
+ /** Chain identifier */
13
+ chain: string;
14
+ /** Symbol on the chain */
15
+ symbol: string;
16
+ /** Display ticker */
17
+ ticker: string;
18
+ /** Decimal places */
19
+ decimals: number;
20
+ /** Asset type */
21
+ type: 'native' | 'secured' | 'synthetic';
22
+ /** Native denom on THORChain */
23
+ denom: string;
24
+ /** Contract address (for CW20 tokens) */
25
+ contractAddress?: string;
26
+ };
27
+ /**
28
+ * Trading pair on Rujira DEX
29
+ */
30
+ export type TradingPair = {
31
+ /** Base asset (e.g., "BTC.BTC") */
32
+ base: string;
33
+ /** Quote asset (e.g., "THOR.RUNE") */
34
+ quote: string;
35
+ /** FIN contract address for this pair */
36
+ contractAddress: string;
37
+ /** Tick size for price precision */
38
+ tick: string;
39
+ /** Taker fee (e.g., "0.0015" for 0.15%) */
40
+ takerFee: string;
41
+ /** Maker fee (e.g., "0.00075" for 0.075%) */
42
+ makerFee: string;
43
+ };
44
+ /**
45
+ * Structured price impact information
46
+ */
47
+ export type PriceImpact = {
48
+ /** Exact price impact percentage (null if cannot be calculated) */
49
+ value: number | null;
50
+ /** Whether this is an estimate (true if orderbook data unavailable) */
51
+ estimated: boolean;
52
+ /** Estimated range [min, max] when exact value unavailable */
53
+ range?: [number, number];
54
+ /** Human-readable display string */
55
+ display: string;
56
+ };
57
+ /**
58
+ * Parameters for requesting a swap quote
59
+ */
60
+ export type QuoteParams = {
61
+ /** Source asset (e.g., "THOR.RUNE") */
62
+ fromAsset: string;
63
+ /** Destination asset (e.g., "BTC.BTC") */
64
+ toAsset: string;
65
+ /** Amount in base units (8 decimals) */
66
+ amount: string;
67
+ /** Slippage tolerance in basis points (default: 100 = 1%) */
68
+ slippageBps?: number;
69
+ /** Destination address (optional, defaults to sender) */
70
+ destination?: string;
71
+ /** Affiliate address for fee sharing */
72
+ affiliate?: string;
73
+ /** Affiliate fee in basis points */
74
+ affiliateBps?: number;
75
+ };
76
+ /**
77
+ * Swap quote response
78
+ */
79
+ export type SwapQuote = {
80
+ /** Quote parameters */
81
+ params: QuoteParams;
82
+ /** Expected output amount in base units */
83
+ expectedOutput: string;
84
+ /** Minimum output after slippage */
85
+ minimumOutput: string;
86
+ /** Exchange rate (output per input) */
87
+ rate: string;
88
+ /** Price impact percentage */
89
+ priceImpact: string;
90
+ /** Estimated fees */
91
+ fees: {
92
+ /** Network/gas fee */
93
+ network: string;
94
+ /** Protocol fee */
95
+ protocol: string;
96
+ /** Affiliate fee (if applicable) */
97
+ affiliate: string;
98
+ /** Total fees */
99
+ total: string;
100
+ };
101
+ /** FIN contract to execute on */
102
+ contractAddress: string;
103
+ /** Quote expiration timestamp */
104
+ expiresAt: number;
105
+ /** Unique quote ID for tracking */
106
+ quoteId: string;
107
+ /** When this quote was created/cached (for staleness checks) */
108
+ cachedAt?: number;
109
+ /** Warning message if any (e.g., stale cache, estimated price impact) */
110
+ warning?: string;
111
+ };
112
+ /**
113
+ * Swap execution options
114
+ */
115
+ export type SwapOptions = {
116
+ /** Override slippage from quote (basis points) */
117
+ slippageBps?: number;
118
+ /** Custom gas limit */
119
+ gasLimit?: number;
120
+ /** Custom gas price */
121
+ gasPrice?: string;
122
+ /** Memo to include in transaction */
123
+ memo?: string;
124
+ /** Skip balance validation (internal use) */
125
+ skipBalanceValidation?: boolean;
126
+ };
127
+ /**
128
+ * Swap execution result
129
+ */
130
+ export type SwapResult = {
131
+ /** Transaction hash */
132
+ txHash: string;
133
+ /** Transaction status */
134
+ status: 'pending' | 'success' | 'failed';
135
+ /** Input amount */
136
+ fromAmount: string;
137
+ /** Actual output amount (available after confirmation) */
138
+ toAmount?: string;
139
+ /** Fees paid */
140
+ fee: string;
141
+ /** Block height (available after confirmation) */
142
+ blockHeight?: number;
143
+ /** Timestamp */
144
+ timestamp: number;
145
+ };
146
+ /**
147
+ * SDK order side - user-friendly representation.
148
+ *
149
+ * - `'buy'` = acquire base asset by offering quote asset
150
+ * - `'sell'` = dispose base asset to receive quote asset
151
+ */
152
+ export type OrderSide = 'buy' | 'sell';
153
+ /**
154
+ * Contract order side - matches FIN contract's `Side` enum.
155
+ *
156
+ * The Rujira FIN contract uses `Side::Base` and `Side::Quote` internally.
157
+ * With CosmWasm's `#[cw_serde]` (which applies `#[serde(rename_all = "snake_case")]`),
158
+ * these serialize to `"base"` and `"quote"` in JSON.
159
+ *
160
+ * Mapping:
161
+ * - `'base'` = selling base asset (offers base, receives quote) = SDK `'sell'`
162
+ * - `'quote'` = buying base asset (offers quote, receives base) = SDK `'buy'`
163
+ *
164
+ * Verified via:
165
+ * - FIN contract book query returns `{ base: [...], quote: [...] }` arrays
166
+ * - Halborn audit (Jan 2025) references `Side::Base` in Rust source
167
+ * - CosmWasm snake_case serialization confirmed
168
+ *
169
+ * @internal Used for contract communication only
170
+ */
171
+ export type ContractSide = 'base' | 'quote';
172
+ /**
173
+ * Convert SDK OrderSide to contract's Side enum value.
174
+ * @internal
175
+ */
176
+ export declare function toContractSide(side: OrderSide): ContractSide;
177
+ /**
178
+ * Convert contract's Side enum value to SDK OrderSide.
179
+ * @internal
180
+ */
181
+ export declare function fromContractSide(side: ContractSide): OrderSide;
182
+ /**
183
+ * Order status
184
+ */
185
+ export type OrderStatus = 'open' | 'partial' | 'filled' | 'cancelled';
186
+ /**
187
+ * Time in force options for limit orders
188
+ */
189
+ export type TimeInForce = 'GTC' | 'IOC' | 'FOK';
190
+ /**
191
+ * Limit order parameters
192
+ */
193
+ export type LimitOrderParams = {
194
+ /** Trading pair */
195
+ pair: TradingPair | string;
196
+ /** Order side */
197
+ side: OrderSide;
198
+ /** Limit price */
199
+ price: string;
200
+ /** Order amount in base asset */
201
+ amount: string;
202
+ /** Time in force (default: GTC) */
203
+ timeInForce?: TimeInForce;
204
+ };
205
+ /**
206
+ * Order details
207
+ */
208
+ export type Order = {
209
+ /** Unique order ID */
210
+ orderId: string;
211
+ /** Owner address */
212
+ owner: string;
213
+ /** Trading pair */
214
+ pair: TradingPair;
215
+ /** Order side */
216
+ side: OrderSide;
217
+ /** Order price */
218
+ price: string;
219
+ /** Original order amount */
220
+ amount: string;
221
+ /** Filled amount */
222
+ filled: string;
223
+ /** Remaining amount */
224
+ remaining: string;
225
+ /** Order status */
226
+ status: OrderStatus;
227
+ /** Creation timestamp */
228
+ createdAt: number;
229
+ /** Last update timestamp */
230
+ updatedAt: number;
231
+ };
232
+ /**
233
+ * Order result after placement
234
+ */
235
+ export type OrderResult = {
236
+ /** Order ID */
237
+ orderId: string;
238
+ /** Transaction hash */
239
+ txHash: string;
240
+ /** Order details */
241
+ order: Order;
242
+ };
243
+ /**
244
+ * Order book entry
245
+ */
246
+ export type OrderBookEntry = {
247
+ /** Price level */
248
+ price: string;
249
+ /** Total amount at this price */
250
+ amount: string;
251
+ /** Total value (price * amount) */
252
+ total: string;
253
+ };
254
+ /**
255
+ * Full order book
256
+ */
257
+ export type OrderBook = {
258
+ /** Trading pair */
259
+ pair: TradingPair;
260
+ /** Buy orders (bids) - sorted high to low */
261
+ bids: OrderBookEntry[];
262
+ /** Sell orders (asks) - sorted low to high */
263
+ asks: OrderBookEntry[];
264
+ /** Bid-ask spread percentage */
265
+ spread: string;
266
+ /** Last traded price */
267
+ lastPrice: string;
268
+ /** Timestamp */
269
+ timestamp: number;
270
+ };
271
+ /** Base64-encoded binary data, matching CosmWasm `Binary` type */
272
+ export type Base64Binary = string;
273
+ /**
274
+ * FIN contract ExecuteMsg variants
275
+ * @internal
276
+ */
277
+ export type FinExecuteMsg = {
278
+ swap: SwapRequest;
279
+ } | {
280
+ order: [OrderTarget[], CallbackData | null];
281
+ } | {
282
+ arb: {
283
+ then?: Base64Binary;
284
+ };
285
+ };
286
+ /**
287
+ * Swap request variants
288
+ * @internal
289
+ */
290
+ export type SwapRequest = {
291
+ yolo: {
292
+ to?: string;
293
+ callback?: CallbackData;
294
+ };
295
+ } | {
296
+ min: {
297
+ min_return: string;
298
+ to?: string;
299
+ callback?: CallbackData;
300
+ };
301
+ } | {
302
+ exact: {
303
+ exact_return: string;
304
+ to?: string;
305
+ callback?: CallbackData;
306
+ };
307
+ } | {
308
+ limit: {
309
+ price: string;
310
+ to?: string;
311
+ callback?: CallbackData;
312
+ };
313
+ };
314
+ /**
315
+ * Order target tuple - uses ContractSide for contract communication
316
+ * @internal
317
+ */
318
+ export type OrderTarget = [ContractSide, string, string | null];
319
+ /**
320
+ * Callback data for contract composition
321
+ * @internal
322
+ */
323
+ export type CallbackData = {
324
+ contract: string;
325
+ msg: string;
326
+ };
327
+ /**
328
+ * FIN contract QueryMsg variants - uses ContractSide for contract communication
329
+ * @internal
330
+ */
331
+ export type FinQueryMsg = {
332
+ config: Record<string, never>;
333
+ } | {
334
+ simulate: {
335
+ denom: string;
336
+ amount: string;
337
+ };
338
+ } | {
339
+ order: [string, ContractSide, string];
340
+ } | {
341
+ orders: {
342
+ owner: string;
343
+ side?: ContractSide;
344
+ offset?: number;
345
+ limit?: number;
346
+ };
347
+ } | {
348
+ book: {
349
+ limit?: number;
350
+ offset?: number;
351
+ };
352
+ };
353
+ /**
354
+ * Simulation response from FIN contract
355
+ * @internal
356
+ */
357
+ export type SimulationResponse = {
358
+ returned: string;
359
+ fee: string;
360
+ };
361
+ /**
362
+ * Book response from FIN contract
363
+ * @internal
364
+ */
365
+ export type BookResponse = {
366
+ base: Array<{
367
+ price: string;
368
+ total: string;
369
+ }>;
370
+ quote: Array<{
371
+ price: string;
372
+ total: string;
373
+ }>;
374
+ };
375
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAA;IACb,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB;IACjB,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAA;IACxC,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,yCAAyC;IACzC,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAA;IACb,yCAAyC;IACzC,eAAe,EAAE,MAAM,CAAA;IACvB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAID;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,mEAAmE;IACnE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,uEAAuE;IACvE,SAAS,EAAE,OAAO,CAA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K
3
+ * @module types
4
+ */
5
+ /**
6
+ * Convert SDK OrderSide to contract's Side enum value.
7
+ * @internal
8
+ */
9
+ export function toContractSide(side) {
10
+ return side === 'buy' ? 'quote' : 'base';
11
+ }
12
+ /**
13
+ * Convert contract's Side enum value to SDK OrderSide.
14
+ * @internal
15
+ */
16
+ export function fromContractSide(side) {
17
+ return side === 'quote' ? 'buy' : 'sell';
18
+ }