@mixerx/oracles 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/LICENSE +674 -0
- package/README.md +139 -0
- package/dist/application/ports/ILogger.d.ts +18 -0
- package/dist/application/ports/ILogger.d.ts.map +1 -0
- package/dist/application/ports/ILogger.js +26 -0
- package/dist/application/ports/ILogger.js.map +1 -0
- package/dist/application/ports/index.d.ts +6 -0
- package/dist/application/ports/index.d.ts.map +1 -0
- package/dist/application/ports/index.js +18 -0
- package/dist/application/ports/index.js.map +1 -0
- package/dist/application/services/TokenPriceService.d.ts +61 -0
- package/dist/application/services/TokenPriceService.d.ts.map +1 -0
- package/dist/application/services/TokenPriceService.js +137 -0
- package/dist/application/services/TokenPriceService.js.map +1 -0
- package/dist/domain/config/TokenDefaults.d.ts +33 -0
- package/dist/domain/config/TokenDefaults.d.ts.map +1 -0
- package/dist/domain/config/TokenDefaults.js +78 -0
- package/dist/domain/config/TokenDefaults.js.map +1 -0
- package/dist/domain/config/index.d.ts +2 -0
- package/dist/domain/config/index.d.ts.map +1 -0
- package/dist/domain/config/index.js +20 -0
- package/dist/domain/config/index.js.map +1 -0
- package/dist/domain/exceptions.d.ts +5 -0
- package/dist/domain/exceptions.d.ts.map +1 -0
- package/dist/domain/exceptions.js +13 -0
- package/dist/domain/exceptions.js.map +1 -0
- package/dist/domain/repositories.d.ts +4 -0
- package/dist/domain/repositories.d.ts.map +1 -0
- package/dist/domain/repositories.js +3 -0
- package/dist/domain/repositories.js.map +1 -0
- package/dist/factory.d.ts +62 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +51 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/blockchain/contracts.d.ts +20 -0
- package/dist/infrastructure/blockchain/contracts.d.ts.map +1 -0
- package/dist/infrastructure/blockchain/contracts.js +10 -0
- package/dist/infrastructure/blockchain/contracts.js.map +1 -0
- package/dist/infrastructure/config/ProtocolTokenConfig.d.ts +4 -0
- package/dist/infrastructure/config/ProtocolTokenConfig.d.ts.map +1 -0
- package/dist/infrastructure/config/ProtocolTokenConfig.js +54 -0
- package/dist/infrastructure/config/ProtocolTokenConfig.js.map +1 -0
- package/dist/infrastructure/config/gasOracleConfigs.d.ts +14 -0
- package/dist/infrastructure/config/gasOracleConfigs.d.ts.map +1 -0
- package/dist/infrastructure/config/gasOracleConfigs.js +38 -0
- package/dist/infrastructure/config/gasOracleConfigs.js.map +1 -0
- package/dist/infrastructure/config/index.d.ts +5 -0
- package/dist/infrastructure/config/index.d.ts.map +1 -0
- package/dist/infrastructure/config/index.js +11 -0
- package/dist/infrastructure/config/index.js.map +1 -0
- package/dist/infrastructure/gas/GasPriceOracle.d.ts +41 -0
- package/dist/infrastructure/gas/GasPriceOracle.d.ts.map +1 -0
- package/dist/infrastructure/gas/GasPriceOracle.js +77 -0
- package/dist/infrastructure/gas/GasPriceOracle.js.map +1 -0
- package/dist/infrastructure/multicall/MulticallProvider.d.ts +14 -0
- package/dist/infrastructure/multicall/MulticallProvider.d.ts.map +1 -0
- package/dist/infrastructure/multicall/MulticallProvider.js +23 -0
- package/dist/infrastructure/multicall/MulticallProvider.js.map +1 -0
- package/dist/infrastructure/token-price/TokenPriceOracle.d.ts +50 -0
- package/dist/infrastructure/token-price/TokenPriceOracle.d.ts.map +1 -0
- package/dist/infrastructure/token-price/TokenPriceOracle.js +133 -0
- package/dist/infrastructure/token-price/TokenPriceOracle.js.map +1 -0
- package/dist/infrastructure/token-price/index.d.ts +3 -0
- package/dist/infrastructure/token-price/index.d.ts.map +1 -0
- package/dist/infrastructure/token-price/index.js +6 -0
- package/dist/infrastructure/token-price/index.js.map +1 -0
- package/dist/infrastructure/tornado/TornadoFeeOracle.d.ts +90 -0
- package/dist/infrastructure/tornado/TornadoFeeOracle.d.ts.map +1 -0
- package/dist/infrastructure/tornado/TornadoFeeOracle.js +230 -0
- package/dist/infrastructure/tornado/TornadoFeeOracle.js.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# MixerX Oracles
|
|
2
|
+
|
|
3
|
+
Oracle library for MixerX Relayer - fee calculation and token pricing for Tornado Cash operations.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js >= 24.12.0
|
|
8
|
+
- Yarn 4.12.0 (nodeLinker: node-modules)
|
|
9
|
+
|
|
10
|
+
Create `./.yarnrc.yml` (repository-root relative path, works on Linux/macOS/Windows):
|
|
11
|
+
|
|
12
|
+
```yaml
|
|
13
|
+
nodeLinker: node-modules
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn add @mixerx/oracles
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createMixerxOraclesModule } from '@mixerx/oracles';
|
|
26
|
+
|
|
27
|
+
// Create module
|
|
28
|
+
const oracles = createMixerxOraclesModule({
|
|
29
|
+
chainId: 1, // Mainnet
|
|
30
|
+
rpcUrl: 'https://mainnet.infura.io/v3/YOUR_KEY',
|
|
31
|
+
relayerFeePercent: 0.004, // 0.4%
|
|
32
|
+
priceRepository: yourRedisRepository, // Implementation of ITokenPriceRepository
|
|
33
|
+
multicallAddress: '0xeefBa1e63905eF1D7ACbA5a8513c70307C1cE441', // optional
|
|
34
|
+
// offchainOracleAddress is optional:
|
|
35
|
+
// if omitted, it is resolved from @mixerx/config by chainId
|
|
36
|
+
fallbackGasPrices: {
|
|
37
|
+
legacy: { instant: 25, fast: 20, standard: 18, low: 15 },
|
|
38
|
+
eip1559: { baseFee: 10, maxFeePerGas: 20, maxPriorityFeePerGas: 2 },
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Fetch token prices
|
|
43
|
+
const prices = await oracles.fetchPrices();
|
|
44
|
+
console.log(prices); // { dai: '603108348359886', usdc: '601311723569085', ... }
|
|
45
|
+
|
|
46
|
+
// Calculate withdrawal fee
|
|
47
|
+
const fee = await oracles.tornadoFeeOracle.calculateWithdrawalFee({
|
|
48
|
+
currency: 'dai',
|
|
49
|
+
amount: BigInt('100000000000000000000'), // 100 DAI
|
|
50
|
+
decimals: 18,
|
|
51
|
+
refund: '0x0',
|
|
52
|
+
txType: 'relayer_withdrawal',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.log(`Total fee: ${fee.totalFee.toString()}`);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Architecture
|
|
59
|
+
|
|
60
|
+
This library follows Domain-Driven Design (DDD) principles:
|
|
61
|
+
|
|
62
|
+
- **Domain**: Value objects and entities for fees, gas, and tokens
|
|
63
|
+
- **Application**: Services and use cases for fee calculation and price fetching
|
|
64
|
+
- **Infrastructure**: Adapters for blockchain interaction (ethers)
|
|
65
|
+
|
|
66
|
+
## Features
|
|
67
|
+
|
|
68
|
+
### Fee Calculation (V5)
|
|
69
|
+
|
|
70
|
+
- Smart gas limit bumping (10% for relayer, 30% for user)
|
|
71
|
+
- On-chain gas estimation with fallback to defaults
|
|
72
|
+
- Support for ETH and ERC-20 tokens
|
|
73
|
+
- Automatic conversion between ETH and token units
|
|
74
|
+
- EIP-1559 and Legacy gas price support
|
|
75
|
+
|
|
76
|
+
### Token Price Fetching
|
|
77
|
+
|
|
78
|
+
- Fetches prices from on-chain OffchainOracle
|
|
79
|
+
- Uses Multicall for efficient batch requests
|
|
80
|
+
- Fallback to default prices if fetching fails
|
|
81
|
+
- Token list is resolved from `@mixerx/config` by `chainId`
|
|
82
|
+
|
|
83
|
+
### Mining Fee Support
|
|
84
|
+
|
|
85
|
+
- Anonymity Mining reward calculations
|
|
86
|
+
- Anonymity Mining withdrawal calculations
|
|
87
|
+
- Automatic conversion between points and TORN
|
|
88
|
+
|
|
89
|
+
## API Reference
|
|
90
|
+
|
|
91
|
+
### `createMixerxOraclesModule(config)`
|
|
92
|
+
|
|
93
|
+
Factory function to create the oracles module.
|
|
94
|
+
|
|
95
|
+
**Config:**
|
|
96
|
+
- `chainId`: Chain ID (1 for Mainnet)
|
|
97
|
+
- `rpcUrl`: RPC endpoint URL
|
|
98
|
+
- `relayerFeePercent`: Fee percentage (e.g., 0.004 for 0.4%)
|
|
99
|
+
- `priceRepository`: Implementation of `ITokenPriceRepository`
|
|
100
|
+
- `multicallAddress?`: Multicall contract address
|
|
101
|
+
- `offchainOracleAddress?`: OffchainOracle contract address (fallback to `@mixerx/config` by `chainId`)
|
|
102
|
+
- `fallbackGasPrices?`: Optional fallback gas prices
|
|
103
|
+
|
|
104
|
+
### Use Cases
|
|
105
|
+
|
|
106
|
+
#### `tornadoFeeOracle.calculateWithdrawalFee(input)`
|
|
107
|
+
|
|
108
|
+
Calculate and validate fees for Tornado Cash withdrawals.
|
|
109
|
+
|
|
110
|
+
**Input:**
|
|
111
|
+
- `currency`: Token symbol (eth, dai, usdc, etc.)
|
|
112
|
+
- `amount`: Withdrawal amount in base units (`bigint`)
|
|
113
|
+
- `decimals`: Token decimals
|
|
114
|
+
- `refund?`: Optional refund amount (hex string)
|
|
115
|
+
- `txType?`: `'relayer_withdrawal' | 'user_withdrawal' | 'relayer_withdrawal_check_v4'`
|
|
116
|
+
|
|
117
|
+
**Output:**
|
|
118
|
+
- `gasCost`: bigint
|
|
119
|
+
- `relayerFee`: bigint
|
|
120
|
+
- `refundAmount`: bigint
|
|
121
|
+
- `totalFee`: bigint
|
|
122
|
+
- `currency`: string
|
|
123
|
+
|
|
124
|
+
#### `fetchTokenPrices.execute(input?)`
|
|
125
|
+
|
|
126
|
+
Fetch current token prices from on-chain oracle.
|
|
127
|
+
|
|
128
|
+
**Input (optional):**
|
|
129
|
+
- `tokens?`: Specific tokens to fetch
|
|
130
|
+
- `useDefaults?`: Use default prices as fallback
|
|
131
|
+
|
|
132
|
+
**Output:**
|
|
133
|
+
- `prices`: TokenPrices map
|
|
134
|
+
- `failedTokens`: Tokens that failed to fetch
|
|
135
|
+
- `usedDefaults`: Whether defaults were used
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
MIT
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ILogger {
|
|
2
|
+
debug(message: string, meta?: unknown): void;
|
|
3
|
+
warn(message: string, meta?: unknown): void;
|
|
4
|
+
error(message: string, meta?: unknown): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class NullLogger implements ILogger {
|
|
7
|
+
debug(_message: string, _meta?: unknown): void;
|
|
8
|
+
warn(_message: string, _meta?: unknown): void;
|
|
9
|
+
error(_message: string, _meta?: unknown): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class ConsoleLogger implements ILogger {
|
|
12
|
+
private readonly scope;
|
|
13
|
+
constructor(scope?: string);
|
|
14
|
+
debug(message: string, meta?: unknown): void;
|
|
15
|
+
warn(message: string, meta?: unknown): void;
|
|
16
|
+
error(message: string, meta?: unknown): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ILogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILogger.d.ts","sourceRoot":"","sources":["../../../src/application/ports/ILogger.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9C;AAED,qBAAa,UAAW,YAAW,OAAO;IACxC,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAC9C,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAC7C,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;CAC/C;AAED,qBAAa,aAAc,YAAW,OAAO;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,SAAmB;IAErD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;CAG7C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleLogger = exports.NullLogger = void 0;
|
|
4
|
+
class NullLogger {
|
|
5
|
+
debug(_message, _meta) { }
|
|
6
|
+
warn(_message, _meta) { }
|
|
7
|
+
error(_message, _meta) { }
|
|
8
|
+
}
|
|
9
|
+
exports.NullLogger = NullLogger;
|
|
10
|
+
class ConsoleLogger {
|
|
11
|
+
scope;
|
|
12
|
+
constructor(scope = 'mixerx-oracles') {
|
|
13
|
+
this.scope = scope;
|
|
14
|
+
}
|
|
15
|
+
debug(message, meta) {
|
|
16
|
+
console.debug(`[${this.scope}] ${message}`, meta ?? '');
|
|
17
|
+
}
|
|
18
|
+
warn(message, meta) {
|
|
19
|
+
console.warn(`[${this.scope}] ${message}`, meta ?? '');
|
|
20
|
+
}
|
|
21
|
+
error(message, meta) {
|
|
22
|
+
console.error(`[${this.scope}] ${message}`, meta ?? '');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
26
|
+
//# sourceMappingURL=ILogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILogger.js","sourceRoot":"","sources":["../../../src/application/ports/ILogger.ts"],"names":[],"mappings":";;;AAMA,MAAa,UAAU;IACrB,KAAK,CAAC,QAAgB,EAAE,KAAe,IAAS,CAAC;IACjD,IAAI,CAAC,QAAgB,EAAE,KAAe,IAAS,CAAC;IAChD,KAAK,CAAC,QAAgB,EAAE,KAAe,IAAS,CAAC;CAClD;AAJD,gCAIC;AAED,MAAa,aAAa;IACK;IAA7B,YAA6B,QAAQ,gBAAgB;QAAxB,UAAK,GAAL,KAAK,CAAmB;IAAG,CAAC;IAEzD,KAAK,CAAC,OAAe,EAAE,IAAc;QACnC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,IAAc;QAClC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,IAAc;QACnC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAdD,sCAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/ports/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACrD;AAED,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ILogger"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/ports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,4CAA0B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ITokenPriceFetcher } from '../ports';
|
|
2
|
+
import { Token, TokenPrices } from '../../types';
|
|
3
|
+
import { ChainId } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for TokenPriceService
|
|
6
|
+
*/
|
|
7
|
+
export interface TokenPriceServiceConfig {
|
|
8
|
+
/** Chain ID used to resolve default tokens from @mixerx/config */
|
|
9
|
+
chainId: ChainId | number;
|
|
10
|
+
/** RPC URL for Ethereum Mainnet */
|
|
11
|
+
rpcUrl: string;
|
|
12
|
+
/** Multicall contract address */
|
|
13
|
+
multicallAddress: string;
|
|
14
|
+
/** Offchain Oracle contract address */
|
|
15
|
+
offchainOracleAddress: string;
|
|
16
|
+
/** Default token prices (fallback) */
|
|
17
|
+
defaultTokenPrices?: TokenPrices;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Token Price Service
|
|
21
|
+
* Fetches token prices from on-chain oracles using multicall
|
|
22
|
+
* Based on TokenPriceOracle from tornado-oracles
|
|
23
|
+
*/
|
|
24
|
+
export declare class TokenPriceService implements ITokenPriceFetcher {
|
|
25
|
+
private readonly config;
|
|
26
|
+
private provider;
|
|
27
|
+
private oracle;
|
|
28
|
+
private multicall;
|
|
29
|
+
private supportedTokens;
|
|
30
|
+
constructor(config: TokenPriceServiceConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Fetch prices for tokens
|
|
33
|
+
* Uses multicall to batch requests
|
|
34
|
+
*/
|
|
35
|
+
fetchPrices(tokens?: Token[]): Promise<TokenPrices>;
|
|
36
|
+
/**
|
|
37
|
+
* Fetch price for a single token
|
|
38
|
+
*/
|
|
39
|
+
fetchSinglePrice(token: Token): Promise<string | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Get default prices (fallback)
|
|
42
|
+
*/
|
|
43
|
+
getDefaultPrices(): TokenPrices;
|
|
44
|
+
/**
|
|
45
|
+
* Get supported tokens
|
|
46
|
+
*/
|
|
47
|
+
getSupportedTokens(): Token[];
|
|
48
|
+
/**
|
|
49
|
+
* Add custom tokens
|
|
50
|
+
*/
|
|
51
|
+
addTokens(tokens: Token[]): void;
|
|
52
|
+
/**
|
|
53
|
+
* ABI for Offchain Oracle (simplified)
|
|
54
|
+
*/
|
|
55
|
+
private getOracleAbi;
|
|
56
|
+
/**
|
|
57
|
+
* ABI for Multicall (simplified)
|
|
58
|
+
*/
|
|
59
|
+
private getMulticallAbi;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=TokenPriceService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenPriceService.d.ts","sourceRoot":"","sources":["../../../src/application/services/TokenPriceService.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,KAAK,EACL,WAAW,EACZ,MAAM,aAAa,CAAC;AAMrB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,kEAAkE;IAClE,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC;IAE1B,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IAEf,iCAAiC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IAEzB,uCAAuC;IACvC,qBAAqB,EAAE,MAAM,CAAC;IAE9B,sCAAsC;IACtC,kBAAkB,CAAC,EAAE,WAAW,CAAC;CAClC;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;IAM9C,OAAO,CAAC,QAAQ,CAAC,MAAM;IALnC,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,eAAe,CAAU;gBAEJ,MAAM,EAAE,uBAAuB;IAiB5D;;;OAGG;IACG,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAkEzD;;OAEG;IACG,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAS5D;;OAEG;IACH,gBAAgB,IAAI,WAAW;IAY/B;;OAEG;IACH,kBAAkB,IAAI,KAAK,EAAE;IAI7B;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI;IAIhC;;OAEG;IACH,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACH,OAAO,CAAC,eAAe;CAKxB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenPriceService = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const TokenDefaults_1 = require("../../domain/config/TokenDefaults");
|
|
6
|
+
const exceptions_1 = require("../../domain/exceptions");
|
|
7
|
+
const ProtocolTokenConfig_1 = require("../../infrastructure/config/ProtocolTokenConfig");
|
|
8
|
+
/**
|
|
9
|
+
* Token Price Service
|
|
10
|
+
* Fetches token prices from on-chain oracles using multicall
|
|
11
|
+
* Based on TokenPriceOracle from tornado-oracles
|
|
12
|
+
*/
|
|
13
|
+
class TokenPriceService {
|
|
14
|
+
config;
|
|
15
|
+
provider;
|
|
16
|
+
oracle;
|
|
17
|
+
multicall;
|
|
18
|
+
supportedTokens;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.provider = new ethers_1.ethers.JsonRpcProvider(config.rpcUrl);
|
|
22
|
+
this.oracle = new ethers_1.ethers.Contract(config.offchainOracleAddress, this.getOracleAbi(), this.provider);
|
|
23
|
+
this.multicall = new ethers_1.ethers.Contract(config.multicallAddress, this.getMulticallAbi(), this.provider);
|
|
24
|
+
this.supportedTokens = (0, ProtocolTokenConfig_1.resolveDefaultTokens)(config.chainId);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Fetch prices for tokens
|
|
28
|
+
* Uses multicall to batch requests
|
|
29
|
+
*/
|
|
30
|
+
async fetchPrices(tokens) {
|
|
31
|
+
const tokensToFetch = tokens || this.supportedTokens;
|
|
32
|
+
try {
|
|
33
|
+
if (!tokensToFetch?.length) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
// Prepare call data for multicall
|
|
37
|
+
const callData = tokensToFetch.map((token) => ({
|
|
38
|
+
to: this.oracle.target,
|
|
39
|
+
data: this.oracle.interface.encodeFunctionData('getRateToEth', [
|
|
40
|
+
token.address,
|
|
41
|
+
true // use wrappers
|
|
42
|
+
]),
|
|
43
|
+
}));
|
|
44
|
+
// Execute multicall
|
|
45
|
+
const { results, success } = await this.multicall.multicall(callData);
|
|
46
|
+
const prices = {};
|
|
47
|
+
// Decode results
|
|
48
|
+
for (let i = 0; i < results.length; i++) {
|
|
49
|
+
const tokenSymbol = tokensToFetch[i].symbol.toLowerCase();
|
|
50
|
+
if (!success[i]) {
|
|
51
|
+
// Use default if call failed
|
|
52
|
+
const defaultPrice = this.getDefaultPrices()[tokenSymbol];
|
|
53
|
+
if (defaultPrice) {
|
|
54
|
+
prices[tokenSymbol] = defaultPrice;
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
// Decode the rate
|
|
60
|
+
const decodedRate = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(['uint256'], results[i])[0];
|
|
61
|
+
// Calculate price with decimals adjustment
|
|
62
|
+
// Formula: (rate * 10^tokenDecimals) / 10^18
|
|
63
|
+
const tokenDecimals = 10n ** BigInt(tokensToFetch[i].decimals);
|
|
64
|
+
const ethDecimals = 10n ** 18n;
|
|
65
|
+
const price = (decodedRate * tokenDecimals) / ethDecimals;
|
|
66
|
+
prices[tokenSymbol] = price.toString();
|
|
67
|
+
}
|
|
68
|
+
catch (decodeError) {
|
|
69
|
+
// Use default if decoding failed
|
|
70
|
+
const defaultPrice = this.getDefaultPrices()[tokenSymbol];
|
|
71
|
+
if (defaultPrice) {
|
|
72
|
+
prices[tokenSymbol] = defaultPrice;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return prices;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new exceptions_1.TokenPriceError(`Failed to fetch prices: ${error instanceof Error ? error.message : String(error)}`, tokensToFetch.map(t => t.symbol));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Fetch price for a single token
|
|
84
|
+
*/
|
|
85
|
+
async fetchSinglePrice(token) {
|
|
86
|
+
try {
|
|
87
|
+
const prices = await this.fetchPrices([token]);
|
|
88
|
+
return prices[token.symbol.toLowerCase()] || null;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get default prices (fallback)
|
|
96
|
+
*/
|
|
97
|
+
getDefaultPrices() {
|
|
98
|
+
if (!this.config.defaultTokenPrices) {
|
|
99
|
+
return TokenDefaults_1.DEFAULT_TOKEN_PRICES;
|
|
100
|
+
}
|
|
101
|
+
const normalized = {};
|
|
102
|
+
for (const [symbol, value] of Object.entries(this.config.defaultTokenPrices)) {
|
|
103
|
+
normalized[symbol.toLowerCase()] = value;
|
|
104
|
+
}
|
|
105
|
+
return normalized;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get supported tokens
|
|
109
|
+
*/
|
|
110
|
+
getSupportedTokens() {
|
|
111
|
+
return this.supportedTokens;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Add custom tokens
|
|
115
|
+
*/
|
|
116
|
+
addTokens(tokens) {
|
|
117
|
+
this.supportedTokens = [...this.supportedTokens, ...tokens];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* ABI for Offchain Oracle (simplified)
|
|
121
|
+
*/
|
|
122
|
+
getOracleAbi() {
|
|
123
|
+
return [
|
|
124
|
+
'function getRateToEth(address srcToken, bool useSrcWrappers) external view returns (uint256 weightedRate)',
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* ABI for Multicall (simplified)
|
|
129
|
+
*/
|
|
130
|
+
getMulticallAbi() {
|
|
131
|
+
return [
|
|
132
|
+
'function multicall(tuple(address to, bytes data)[] calls) external view returns (bytes[] results, bool[] success)',
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.TokenPriceService = TokenPriceService;
|
|
137
|
+
//# sourceMappingURL=TokenPriceService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenPriceService.js","sourceRoot":"","sources":["../../../src/application/services/TokenPriceService.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAYhC,qEAE2C;AAC3C,wDAA0D;AAC1D,yFAAuF;AAuBvF;;;;GAIG;AACH,MAAa,iBAAiB;IAMC;IALrB,QAAQ,CAAyB;IACjC,MAAM,CAAoB;IAC1B,SAAS,CAAe;IACxB,eAAe,CAAU;IAEjC,YAA6B,MAA+B;QAA/B,WAAM,GAAN,MAAM,CAAyB;QAC1D,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,QAAQ,CAC/B,MAAM,CAAC,qBAAqB,EAC5B,IAAI,CAAC,YAAY,EAAE,EACnB,IAAI,CAAC,QAAQ,CACkB,CAAC;QAElC,IAAI,CAAC,SAAS,GAAG,IAAI,eAAM,CAAC,QAAQ,CAClC,MAAM,CAAC,gBAAgB,EACvB,IAAI,CAAC,eAAe,EAAE,EACtB,IAAI,CAAC,QAAQ,CACa,CAAC;QAE7B,IAAI,CAAC,eAAe,GAAG,IAAA,0CAAoB,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,MAAgB;QAChC,MAAM,aAAa,GAAG,MAAM,IAAI,IAAI,CAAC,eAAe,CAAC;QAErD,IAAI,CAAC;YACH,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;gBAC3B,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,kCAAkC;YAClC,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gB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AAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC7E,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;QAC3C,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,MAAe;QACvB,IAAI,CAAC,eAAe,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,GAAG,MAAM,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACK,YAAY;QAClB,OAAO;YACL,2GAA2G;SAC5G,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,eAAe;QACrB,OAAO;YACL,mHAAmH;SACpH,CAAC;IACJ,CAAC;CACF;AAvJD,8CAuJC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Defaults
|
|
3
|
+
* Centralized configuration for Tornado Cash tokens
|
|
4
|
+
*
|
|
5
|
+
* This eliminates duplication between:
|
|
6
|
+
* - TokenPriceOracle
|
|
7
|
+
* - TokenPriceService
|
|
8
|
+
* - FeeCalculator
|
|
9
|
+
*
|
|
10
|
+
* All token addresses, decimals, and default prices in one place
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_TOKEN_PRICES: Record<string, string>;
|
|
13
|
+
export declare const TORNADO_GAS_LIMITS: Record<string, number>;
|
|
14
|
+
export declare const MINING_GAS_LIMITS: Record<string, number>;
|
|
15
|
+
export declare const DEFAULT_RELAYER_FEE_PERCENT = 0.004;
|
|
16
|
+
export declare const BUMP_PERCENTAGES: Record<string, number>;
|
|
17
|
+
/**
|
|
18
|
+
* Get default price for token
|
|
19
|
+
*/
|
|
20
|
+
export declare function getDefaultTokenPrice(symbol: string): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Get gas limit for Tornado operation
|
|
23
|
+
*/
|
|
24
|
+
export declare function getTornadoGasLimit(currency: string): number;
|
|
25
|
+
/**
|
|
26
|
+
* Get mining gas limit
|
|
27
|
+
*/
|
|
28
|
+
export declare function getMiningGasLimit(operation: 'reward' | 'withdraw'): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get bump percent for transaction type
|
|
31
|
+
*/
|
|
32
|
+
export declare function getBumpPercent(txType: string): number;
|
|
33
|
+
//# sourceMappingURL=TokenDefaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenDefaults.d.ts","sourceRoot":"","sources":["../../../src/domain/config/TokenDefaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAOvD,CAAC;AAGF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAOrD,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGpD,CAAC;AAGF,eAAO,MAAM,2BAA2B,QAAQ,CAAC;AAGjD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKnD,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAE1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Token Defaults
|
|
4
|
+
* Centralized configuration for Tornado Cash tokens
|
|
5
|
+
*
|
|
6
|
+
* This eliminates duplication between:
|
|
7
|
+
* - TokenPriceOracle
|
|
8
|
+
* - TokenPriceService
|
|
9
|
+
* - FeeCalculator
|
|
10
|
+
*
|
|
11
|
+
* All token addresses, decimals, and default prices in one place
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.BUMP_PERCENTAGES = exports.DEFAULT_RELAYER_FEE_PERCENT = exports.MINING_GAS_LIMITS = exports.TORNADO_GAS_LIMITS = exports.DEFAULT_TOKEN_PRICES = void 0;
|
|
15
|
+
exports.getDefaultTokenPrice = getDefaultTokenPrice;
|
|
16
|
+
exports.getTornadoGasLimit = getTornadoGasLimit;
|
|
17
|
+
exports.getMiningGasLimit = getMiningGasLimit;
|
|
18
|
+
exports.getBumpPercent = getBumpPercent;
|
|
19
|
+
// Token contract addresses and metadata are sourced from @mixerx/config
|
|
20
|
+
// via infrastructure/config/ProtocolTokenConfig.ts.
|
|
21
|
+
// Default prices as fallback (in wei per token unit, relative to ETH)
|
|
22
|
+
// These represent the rate: 1 token = X wei of ETH
|
|
23
|
+
exports.DEFAULT_TOKEN_PRICES = {
|
|
24
|
+
torn: '1689423546359032',
|
|
25
|
+
dai: '598416104472725',
|
|
26
|
+
cdai: '13384388487019',
|
|
27
|
+
usdc: '599013776676721',
|
|
28
|
+
usdt: '599323410893614',
|
|
29
|
+
wbtc: '15659889148334216720',
|
|
30
|
+
};
|
|
31
|
+
// Gas limits for Tornado operations by token (in gas units)
|
|
32
|
+
exports.TORNADO_GAS_LIMITS = {
|
|
33
|
+
eth: 390000,
|
|
34
|
+
dai: 550000,
|
|
35
|
+
cdai: 425000,
|
|
36
|
+
usdc: 80000,
|
|
37
|
+
usdt: 100000,
|
|
38
|
+
wbtc: 85000,
|
|
39
|
+
};
|
|
40
|
+
// Mining operation gas limits
|
|
41
|
+
exports.MINING_GAS_LIMITS = {
|
|
42
|
+
reward: 455000,
|
|
43
|
+
withdraw: 400000,
|
|
44
|
+
};
|
|
45
|
+
// Relayer fee percentage (0.4% default)
|
|
46
|
+
exports.DEFAULT_RELAYER_FEE_PERCENT = 0.004;
|
|
47
|
+
// Bump percentages by transaction type
|
|
48
|
+
exports.BUMP_PERCENTAGES = {
|
|
49
|
+
relayer_withdrawal: 10,
|
|
50
|
+
user_withdrawal: 30,
|
|
51
|
+
relayer_withdrawal_check_v4: 0,
|
|
52
|
+
default: 10,
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Get default price for token
|
|
56
|
+
*/
|
|
57
|
+
function getDefaultTokenPrice(symbol) {
|
|
58
|
+
return exports.DEFAULT_TOKEN_PRICES[symbol.toLowerCase()];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get gas limit for Tornado operation
|
|
62
|
+
*/
|
|
63
|
+
function getTornadoGasLimit(currency) {
|
|
64
|
+
return exports.TORNADO_GAS_LIMITS[currency.toLowerCase()] ?? exports.TORNADO_GAS_LIMITS.eth;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get mining gas limit
|
|
68
|
+
*/
|
|
69
|
+
function getMiningGasLimit(operation) {
|
|
70
|
+
return exports.MINING_GAS_LIMITS[operation] ?? 400000;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get bump percent for transaction type
|
|
74
|
+
*/
|
|
75
|
+
function getBumpPercent(txType) {
|
|
76
|
+
return exports.BUMP_PERCENTAGES[txType] ?? exports.BUMP_PERCENTAGES.default;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=TokenDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenDefaults.js","sourceRoot":"","sources":["../../../src/domain/config/TokenDefaults.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AA8CH,oDAEC;AAKD,gDAEC;AAKD,8CAEC;AAKD,wCAEC;AAnED,wEAAwE;AACxE,oDAAoD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AO,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/config/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,oBAAoB,EAGpB,kBAAkB,EAClB,iBAAiB,EAGjB,2BAA2B,EAC3B,gBAAgB,EAGhB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Domain configuration exports
|
|
3
|
+
// Centralized defaults to eliminate duplication across the codebase
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getBumpPercent = exports.getMiningGasLimit = exports.getTornadoGasLimit = exports.getDefaultTokenPrice = exports.BUMP_PERCENTAGES = exports.DEFAULT_RELAYER_FEE_PERCENT = exports.MINING_GAS_LIMITS = exports.TORNADO_GAS_LIMITS = exports.DEFAULT_TOKEN_PRICES = void 0;
|
|
6
|
+
var TokenDefaults_1 = require("./TokenDefaults");
|
|
7
|
+
// Token price fallbacks
|
|
8
|
+
Object.defineProperty(exports, "DEFAULT_TOKEN_PRICES", { enumerable: true, get: function () { return TokenDefaults_1.DEFAULT_TOKEN_PRICES; } });
|
|
9
|
+
// Gas limits
|
|
10
|
+
Object.defineProperty(exports, "TORNADO_GAS_LIMITS", { enumerable: true, get: function () { return TokenDefaults_1.TORNADO_GAS_LIMITS; } });
|
|
11
|
+
Object.defineProperty(exports, "MINING_GAS_LIMITS", { enumerable: true, get: function () { return TokenDefaults_1.MINING_GAS_LIMITS; } });
|
|
12
|
+
// Fee configuration
|
|
13
|
+
Object.defineProperty(exports, "DEFAULT_RELAYER_FEE_PERCENT", { enumerable: true, get: function () { return TokenDefaults_1.DEFAULT_RELAYER_FEE_PERCENT; } });
|
|
14
|
+
Object.defineProperty(exports, "BUMP_PERCENTAGES", { enumerable: true, get: function () { return TokenDefaults_1.BUMP_PERCENTAGES; } });
|
|
15
|
+
// Helper functions
|
|
16
|
+
Object.defineProperty(exports, "getDefaultTokenPrice", { enumerable: true, get: function () { return TokenDefaults_1.getDefaultTokenPrice; } });
|
|
17
|
+
Object.defineProperty(exports, "getTornadoGasLimit", { enumerable: true, get: function () { return TokenDefaults_1.getTornadoGasLimit; } });
|
|
18
|
+
Object.defineProperty(exports, "getMiningGasLimit", { enumerable: true, get: function () { return TokenDefaults_1.getMiningGasLimit; } });
|
|
19
|
+
Object.defineProperty(exports, "getBumpPercent", { enumerable: true, get: function () { return TokenDefaults_1.getBumpPercent; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/config/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,oEAAoE;;;AAEpE,iDAiByB;AAhBvB,wBAAwB;AACxB,qHAAA,oBAAoB,OAAA;AAEpB,aAAa;AACb,mHAAA,kBAAkB,OAAA;AAClB,kHAAA,iBAAiB,OAAA;AAEjB,oBAAoB;AACpB,4HAAA,2BAA2B,OAAA;AAC3B,iHAAA,gBAAgB,OAAA;AAEhB,mBAAmB;AACnB,qHAAA,oBAAoB,OAAA;AACpB,mHAAA,kBAAkB,OAAA;AAClB,kHAAA,iBAAiB,OAAA;AACjB,+GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/domain/exceptions.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;aACK,OAAO,EAAE,MAAM,EAAE;gBAAlD,OAAO,EAAE,MAAM,EAAkB,OAAO,GAAE,MAAM,EAAO;CAIpE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenPriceError = void 0;
|
|
4
|
+
class TokenPriceError extends Error {
|
|
5
|
+
symbols;
|
|
6
|
+
constructor(message, symbols = []) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.symbols = symbols;
|
|
9
|
+
this.name = 'TokenPriceError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.TokenPriceError = TokenPriceError;
|
|
13
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/domain/exceptions.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;IACK;IAA7C,YAAY,OAAe,EAAkB,UAAoB,EAAE;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,YAAO,GAAP,OAAO,CAAe;QAEjE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repositories.d.ts","sourceRoot":"","sources":["../../src/domain/repositories.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CAC9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../src/domain/repositories.ts"],"names":[],"mappings":""}
|