@mixerx/oracles 1.0.0 → 2.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.
- package/README.md +78 -111
- package/dist/application/ports/ILogger.d.ts +0 -1
- package/dist/application/ports/ILogger.js.map +1 -1
- package/dist/application/ports/index.d.ts +0 -1
- package/dist/application/ports/index.js.map +1 -1
- package/dist/domain/config/TokenDefaults.d.ts +0 -32
- package/dist/domain/config/TokenDefaults.js +7 -72
- package/dist/domain/config/TokenDefaults.js.map +1 -1
- package/dist/domain/config/index.d.ts +1 -2
- package/dist/domain/config/index.js +1 -13
- package/dist/domain/config/index.js.map +1 -1
- package/dist/domain/exceptions.d.ts +8 -4
- package/dist/domain/exceptions.js +12 -3
- package/dist/domain/exceptions.js.map +1 -1
- package/dist/domain/repositories.d.ts +3 -1
- package/dist/domain/repositories.js +10 -0
- package/dist/domain/repositories.js.map +1 -1
- package/dist/factory.d.ts +11 -32
- package/dist/factory.js +16 -26
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/blockchain/staticProvider.d.ts +3 -0
- package/dist/infrastructure/blockchain/staticProvider.js +37 -0
- package/dist/infrastructure/blockchain/staticProvider.js.map +1 -0
- package/dist/infrastructure/config/ProtocolTokenConfig.d.ts +0 -1
- package/dist/infrastructure/config/ProtocolTokenConfig.js +2 -0
- package/dist/infrastructure/config/ProtocolTokenConfig.js.map +1 -1
- package/dist/infrastructure/config/gasOracleConfigs.d.ts +2 -13
- package/dist/infrastructure/config/gasOracleConfigs.js +7 -33
- package/dist/infrastructure/config/gasOracleConfigs.js.map +1 -1
- package/dist/infrastructure/config/index.d.ts +0 -1
- package/dist/infrastructure/config/index.js.map +1 -1
- package/dist/infrastructure/gas/GasPriceOracle.d.ts +12 -2
- package/dist/infrastructure/gas/GasPriceOracle.js +77 -38
- package/dist/infrastructure/gas/GasPriceOracle.js.map +1 -1
- package/dist/infrastructure/mixerx/MixerXFeeOracle.d.ts +88 -0
- package/dist/infrastructure/mixerx/MixerXFeeOracle.js +220 -0
- package/dist/infrastructure/mixerx/MixerXFeeOracle.js.map +1 -0
- package/dist/infrastructure/multicall/MulticallProvider.d.ts +5 -3
- package/dist/infrastructure/multicall/MulticallProvider.js +44 -9
- package/dist/infrastructure/multicall/MulticallProvider.js.map +1 -1
- package/dist/infrastructure/token-price/TokenPriceOracle.d.ts +11 -46
- package/dist/infrastructure/token-price/TokenPriceOracle.js +68 -101
- package/dist/infrastructure/token-price/TokenPriceOracle.js.map +1 -1
- package/dist/infrastructure/token-price/index.d.ts +2 -2
- package/dist/infrastructure/token-price/index.js.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.js.map +1 -1
- package/package.json +56 -40
- package/dist/application/ports/ILogger.d.ts.map +0 -1
- package/dist/application/ports/index.d.ts.map +0 -1
- package/dist/application/services/TokenPriceService.d.ts +0 -61
- package/dist/application/services/TokenPriceService.d.ts.map +0 -1
- package/dist/application/services/TokenPriceService.js +0 -137
- package/dist/application/services/TokenPriceService.js.map +0 -1
- package/dist/domain/config/TokenDefaults.d.ts.map +0 -1
- package/dist/domain/config/index.d.ts.map +0 -1
- package/dist/domain/exceptions.d.ts.map +0 -1
- package/dist/domain/repositories.d.ts.map +0 -1
- package/dist/factory.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/infrastructure/blockchain/contracts.d.ts +0 -20
- package/dist/infrastructure/blockchain/contracts.d.ts.map +0 -1
- package/dist/infrastructure/blockchain/contracts.js +0 -10
- package/dist/infrastructure/blockchain/contracts.js.map +0 -1
- package/dist/infrastructure/config/ProtocolTokenConfig.d.ts.map +0 -1
- package/dist/infrastructure/config/gasOracleConfigs.d.ts.map +0 -1
- package/dist/infrastructure/config/index.d.ts.map +0 -1
- package/dist/infrastructure/gas/GasPriceOracle.d.ts.map +0 -1
- package/dist/infrastructure/multicall/MulticallProvider.d.ts.map +0 -1
- package/dist/infrastructure/token-price/TokenPriceOracle.d.ts.map +0 -1
- package/dist/infrastructure/token-price/index.d.ts.map +0 -1
- package/dist/infrastructure/tornado/TornadoFeeOracle.d.ts +0 -90
- package/dist/infrastructure/tornado/TornadoFeeOracle.d.ts.map +0 -1
- package/dist/infrastructure/tornado/TornadoFeeOracle.js +0 -230
- package/dist/infrastructure/tornado/TornadoFeeOracle.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,139 +1,106 @@
|
|
|
1
1
|
# MixerX Oracles
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
Fail-closed Sepolia pricing and gas policy for MixerX. Version 2.0.0 removes
|
|
4
|
+
historical Tornado price fallbacks and rejects a withdrawal quote when its
|
|
5
|
+
price is missing, stale or economically unsafe.
|
|
6
|
+
|
|
7
|
+
## Security contract
|
|
8
|
+
|
|
9
|
+
- Sepolia (`11155111`) is the only accepted chain.
|
|
10
|
+
- RPC endpoints must use HTTPS, are time-bounded and are checked against the
|
|
11
|
+
real `eth_chainId` response.
|
|
12
|
+
- Token calls use Multicall3 atomically at one block. Any failed token rejects
|
|
13
|
+
the batch; no historical constant is substituted.
|
|
14
|
+
- Non-native withdrawal fees require a repository price plus its observation
|
|
15
|
+
timestamp. The default maximum age is two minutes.
|
|
16
|
+
- Gas data, service fee, refund, decimals and total fee are bounded before a
|
|
17
|
+
result is returned.
|
|
18
|
+
- The exact withdrawal gas limit is mandatory input and must come from
|
|
19
|
+
simulation or `eth_estimateGas`; the package contains no token-specific
|
|
20
|
+
limits inherited from another protocol.
|
|
21
|
+
- Logging is disabled by default. Inject an `ILogger` that follows the host
|
|
22
|
+
service's privacy policy if operational events are required.
|
|
23
|
+
|
|
24
|
+
The Sepolia OffchainOracle deployment must contain valid rates and must be
|
|
25
|
+
protected by the protocol's TWAP/deviation policy. The library cannot create or
|
|
26
|
+
initialize that on-chain state. Call `assertReady()` during application startup;
|
|
27
|
+
do not accept traffic if it fails.
|
|
15
28
|
|
|
16
29
|
## Installation
|
|
17
30
|
|
|
18
31
|
```bash
|
|
19
|
-
yarn add @mixerx/oracles
|
|
32
|
+
yarn add @mixerx/oracles@2.0.0
|
|
20
33
|
```
|
|
21
34
|
|
|
22
|
-
|
|
35
|
+
Node.js 22.12 or newer is required.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import {
|
|
41
|
+
createMixerxOraclesModule,
|
|
42
|
+
type ITokenPriceRepository,
|
|
43
|
+
} from '@mixerx/oracles';
|
|
23
44
|
|
|
24
|
-
|
|
25
|
-
|
|
45
|
+
const priceRepository: ITokenPriceRepository = {
|
|
46
|
+
getPrice: async (symbol) => readCachedPrice(symbol),
|
|
47
|
+
getLastUpdateTimestamp: async () => readLastPriceUpdate(),
|
|
48
|
+
};
|
|
26
49
|
|
|
27
|
-
// Create module
|
|
28
50
|
const oracles = createMixerxOraclesModule({
|
|
29
|
-
chainId:
|
|
30
|
-
rpcUrl:
|
|
31
|
-
relayerFeePercent: 0.004,
|
|
32
|
-
priceRepository
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
},
|
|
51
|
+
chainId: 11155111,
|
|
52
|
+
rpcUrl: process.env.SEPOLIA_RPC_URL!,
|
|
53
|
+
relayerFeePercent: 0.004,
|
|
54
|
+
priceRepository,
|
|
55
|
+
maxGasPriceGwei: 100,
|
|
56
|
+
maxPriceAgeMs: 120_000,
|
|
40
57
|
});
|
|
41
58
|
|
|
42
|
-
|
|
43
|
-
const prices = await oracles.fetchPrices();
|
|
44
|
-
console.log(prices); // { dai: '603108348359886', usdc: '601311723569085', ... }
|
|
59
|
+
await oracles.assertReady();
|
|
45
60
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
amount: BigInt('100000000000000000000'), // 100 DAI
|
|
61
|
+
const fee = await oracles.mixerXFeeOracle.calculateWithdrawalFee({
|
|
62
|
+
currency: 'fds',
|
|
63
|
+
amount: 1_000_000_000_000_000_000n,
|
|
50
64
|
decimals: 18,
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
gasLimit: estimatedWithdrawalGas,
|
|
66
|
+
refund: '0',
|
|
67
|
+
purpose: 'fee',
|
|
53
68
|
});
|
|
54
69
|
|
|
55
|
-
console.log(
|
|
70
|
+
console.log({
|
|
71
|
+
totalFee: fee.totalFee,
|
|
72
|
+
tokenPriceInEth: fee.tokenPriceInEth,
|
|
73
|
+
priceSource: fee.priceSource,
|
|
74
|
+
priceObservedAtMs: fee.priceObservedAtMs,
|
|
75
|
+
baseFeePerGas: fee.baseFeePerGas,
|
|
76
|
+
});
|
|
56
77
|
```
|
|
57
78
|
|
|
58
|
-
|
|
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
|
|
79
|
+
`fee_quote` and `fee_validation` remain accepted as input aliases for migration,
|
|
80
|
+
but both normalize to the single `fee` policy in returned data.
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
## Price-feed operation
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
`fetchPrices()` reads all configured Sepolia tokens through Multicall3. It
|
|
85
|
+
returns `Record<string, string>` only when every token succeeds. The host price
|
|
86
|
+
feed must persist both the values and one observation timestamp atomically.
|
|
87
|
+
Fee calculation never falls back from that repository to a spot value.
|
|
82
88
|
|
|
83
|
-
|
|
89
|
+
The default Multicall3 address is
|
|
90
|
+
`0xcA11bde05977b3631167028862bE2a173976CA11`; an explicit verified address can
|
|
91
|
+
be supplied with `multicallAddress`.
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
- Anonymity Mining withdrawal calculations
|
|
87
|
-
- Automatic conversion between points and TORN
|
|
93
|
+
## Development
|
|
88
94
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
|
95
|
+
```bash
|
|
96
|
+
yarn install --immutable
|
|
97
|
+
yarn validate
|
|
98
|
+
yarn npm audit --all --recursive --severity high
|
|
99
|
+
```
|
|
131
100
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
- `failedTokens`: Tokens that failed to fetch
|
|
135
|
-
- `usedDefaults`: Whether defaults were used
|
|
101
|
+
CI executes those gates for every pull request. Published packages pin the
|
|
102
|
+
protocol configuration dependency exactly.
|
|
136
103
|
|
|
137
104
|
## License
|
|
138
105
|
|
|
139
|
-
|
|
106
|
+
GPL-3.0-only. See `LICENSE`.
|
|
@@ -1 +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"}
|
|
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","sourcesContent":["export interface ILogger {\r\n debug(message: string, meta?: unknown): void;\r\n warn(message: string, meta?: unknown): void;\r\n error(message: string, meta?: unknown): void;\r\n}\r\n\r\nexport class NullLogger implements ILogger {\r\n debug(_message: string, _meta?: unknown): void {}\r\n warn(_message: string, _meta?: unknown): void {}\r\n error(_message: string, _meta?: unknown): void {}\r\n}\r\n\r\nexport class ConsoleLogger implements ILogger {\r\n constructor(private readonly scope = 'mixerx-oracles') {}\r\n\r\n debug(message: string, meta?: unknown): void {\r\n console.debug(`[${this.scope}] ${message}`, meta ?? '');\r\n }\r\n\r\n warn(message: string, meta?: unknown): void {\r\n console.warn(`[${this.scope}] ${message}`, meta ?? '');\r\n }\r\n\r\n error(message: string, meta?: unknown): void {\r\n console.error(`[${this.scope}] ${message}`, meta ?? '');\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/ports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,4CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/ports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,4CAA0B","sourcesContent":["import type { Token, TokenPrices } from '../../types';\r\n\r\nexport interface ITokenPriceFetcher {\r\n fetchPrices(tokens?: Token[]): Promise<TokenPrices>;\r\n}\r\n\r\nexport * from './ILogger';\r\n"]}
|
|
@@ -1,33 +1 @@
|
|
|
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
1
|
export declare function getBumpPercent(txType: string): number;
|
|
33
|
-
//# sourceMappingURL=TokenDefaults.d.ts.map
|
|
@@ -1,78 +1,13 @@
|
|
|
1
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
2
|
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
3
|
exports.getBumpPercent = getBumpPercent;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
*/
|
|
4
|
+
const BUMP_PERCENTAGES = new Map([
|
|
5
|
+
['relayer_withdrawal', 10],
|
|
6
|
+
['user_withdrawal', 30],
|
|
7
|
+
['relayer_withdrawal_check_v4', 0],
|
|
8
|
+
]);
|
|
75
9
|
function getBumpPercent(txType) {
|
|
76
|
-
|
|
10
|
+
const key = txType.trim().toLowerCase();
|
|
11
|
+
return BUMP_PERCENTAGES.get(key) ?? 10;
|
|
77
12
|
}
|
|
78
13
|
//# sourceMappingURL=TokenDefaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenDefaults.js","sourceRoot":"","sources":["../../../src/domain/config/TokenDefaults.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TokenDefaults.js","sourceRoot":"","sources":["../../../src/domain/config/TokenDefaults.ts"],"names":[],"mappings":";;AAMA,wCAGC;AATD,MAAM,gBAAgB,GAAgC,IAAI,GAAG,CAAC;IAC5D,CAAC,oBAAoB,EAAE,EAAE,CAAC;IAC1B,CAAC,iBAAiB,EAAE,EAAE,CAAC;IACvB,CAAC,6BAA6B,EAAE,CAAC,CAAC;CACnC,CAAC,CAAC;AAEH,SAAgB,cAAc,CAAC,MAAc;IAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACxC,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC","sourcesContent":["const BUMP_PERCENTAGES: ReadonlyMap<string, number> = new Map([\r\n ['relayer_withdrawal', 10],\r\n ['user_withdrawal', 30],\r\n ['relayer_withdrawal_check_v4', 0],\r\n]);\r\n\r\nexport function getBumpPercent(txType: string): number {\r\n const key = txType.trim().toLowerCase();\r\n return BUMP_PERCENTAGES.get(key) ?? 10;\r\n}\r\n"]}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export { getBumpPercent, } from './TokenDefaults';
|
|
@@ -2,19 +2,7 @@
|
|
|
2
2
|
// Domain configuration exports
|
|
3
3
|
// Centralized defaults to eliminate duplication across the codebase
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getBumpPercent =
|
|
5
|
+
exports.getBumpPercent = void 0;
|
|
6
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
7
|
Object.defineProperty(exports, "getBumpPercent", { enumerable: true, get: function () { return TokenDefaults_1.getBumpPercent; } });
|
|
20
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/config/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,oEAAoE;;;AAEpE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/config/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,oEAAoE;;;AAEpE,iDAEyB;AADvB,+GAAA,cAAc,OAAA","sourcesContent":["// Domain configuration exports\r\n// Centralized defaults to eliminate duplication across the codebase\r\n\r\nexport {\r\n getBumpPercent,\r\n} from './TokenDefaults';\r\n"]}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type OracleErrorCode = 'INVALID_CONFIG' | 'INVALID_INPUT' | 'NETWORK_MISMATCH' | 'RPC_REQUEST_FAILED' | 'TOKEN_PRICE_UNAVAILABLE' | 'TOKEN_PRICE_STALE' | 'ECONOMIC_LIMIT_EXCEEDED';
|
|
2
|
+
export declare class OracleError extends Error {
|
|
3
|
+
readonly code: OracleErrorCode;
|
|
4
|
+
constructor(code: OracleErrorCode, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class TokenPriceError extends OracleError {
|
|
7
|
+
readonly symbols: readonly string[];
|
|
8
|
+
constructor(message: string, symbols?: readonly string[]);
|
|
4
9
|
}
|
|
5
|
-
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenPriceError = void 0;
|
|
4
|
-
class
|
|
3
|
+
exports.TokenPriceError = exports.OracleError = void 0;
|
|
4
|
+
class OracleError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.name = 'OracleError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.OracleError = OracleError;
|
|
13
|
+
class TokenPriceError extends OracleError {
|
|
5
14
|
symbols;
|
|
6
15
|
constructor(message, symbols = []) {
|
|
7
|
-
super(message);
|
|
16
|
+
super('TOKEN_PRICE_UNAVAILABLE', message);
|
|
8
17
|
this.symbols = symbols;
|
|
9
18
|
this.name = 'TokenPriceError';
|
|
10
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/domain/exceptions.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/domain/exceptions.ts"],"names":[],"mappings":";;;AASA,MAAa,WAAY,SAAQ,KAAK;IAElB;IADlB,YACkB,IAAqB,EACrC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAiB;QAIrC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AARD,kCAQC;AAED,MAAa,eAAgB,SAAQ,WAAW;IACD;IAA7C,YAAY,OAAe,EAAkB,UAA6B,EAAE;QAC1E,KAAK,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;QADC,YAAO,GAAP,OAAO,CAAwB;QAE1E,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC","sourcesContent":["export type OracleErrorCode =\r\n | 'INVALID_CONFIG'\r\n | 'INVALID_INPUT'\r\n | 'NETWORK_MISMATCH'\r\n | 'RPC_REQUEST_FAILED'\r\n | 'TOKEN_PRICE_UNAVAILABLE'\r\n | 'TOKEN_PRICE_STALE'\r\n | 'ECONOMIC_LIMIT_EXCEEDED';\r\n\r\nexport class OracleError extends Error {\r\n constructor(\r\n public readonly code: OracleErrorCode,\r\n message: string,\r\n ) {\r\n super(message);\r\n this.name = 'OracleError';\r\n }\r\n}\r\n\r\nexport class TokenPriceError extends OracleError {\r\n constructor(message: string, public readonly symbols: readonly string[] = []) {\r\n super('TOKEN_PRICE_UNAVAILABLE', message);\r\n this.name = 'TokenPriceError';\r\n }\r\n}\r\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { TokenPriceQuote } from '../types';
|
|
1
2
|
export interface ITokenPriceRepository {
|
|
2
3
|
getPrice(symbol: string): Promise<bigint | null | undefined>;
|
|
4
|
+
getLastUpdateTimestamp(symbol: string): Promise<number | null | undefined>;
|
|
3
5
|
}
|
|
4
|
-
|
|
6
|
+
export declare function toPriceQuote(price: bigint | null | undefined, observedAtMs: number | null | undefined): TokenPriceQuote | null;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toPriceQuote = toPriceQuote;
|
|
4
|
+
function toPriceQuote(price, observedAtMs) {
|
|
5
|
+
if (price === null || price === undefined || price <= 0n) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
if (!Number.isSafeInteger(observedAtMs) || (observedAtMs ?? -1) < 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return { priceInEthWei: price, observedAtMs: observedAtMs, source: 'repository' };
|
|
12
|
+
}
|
|
3
13
|
//# sourceMappingURL=repositories.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../src/domain/repositories.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../src/domain/repositories.ts"],"names":[],"mappings":";;AAOA,oCAaC;AAbD,SAAgB,YAAY,CAC1B,KAAgC,EAChC,YAAuC;IAEvC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,YAAsB,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;AAC9F,CAAC","sourcesContent":["import type { TokenPriceQuote } from '../types';\r\n\r\nexport interface ITokenPriceRepository {\r\n getPrice(symbol: string): Promise<bigint | null | undefined>;\r\n getLastUpdateTimestamp(symbol: string): Promise<number | null | undefined>;\r\n}\r\n\r\nexport function toPriceQuote(\r\n price: bigint | null | undefined,\r\n observedAtMs: number | null | undefined,\r\n): TokenPriceQuote | null {\r\n if (price === null || price === undefined || price <= 0n) {\r\n return null;\r\n }\r\n\r\n if (!Number.isSafeInteger(observedAtMs) || (observedAtMs ?? -1) < 0) {\r\n return null;\r\n }\r\n\r\n return { priceInEthWei: price, observedAtMs: observedAtMs as number, source: 'repository' };\r\n}\r\n"]}
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
+
import type { ILogger } from './application/ports/ILogger';
|
|
2
|
+
import type { ITokenPriceRepository } from './domain/repositories';
|
|
1
3
|
import { GasPriceOracle } from './infrastructure/gas/GasPriceOracle';
|
|
4
|
+
import { MixerXFeeOracle } from './infrastructure/mixerx/MixerXFeeOracle';
|
|
2
5
|
import { TokenPriceOracle } from './infrastructure/token-price/TokenPriceOracle';
|
|
3
|
-
import {
|
|
4
|
-
import { ITokenPriceRepository } from './domain/repositories';
|
|
5
|
-
import { ChainId } from './infrastructure/config/gasOracleConfigs';
|
|
6
|
-
import { TokenPrices } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* Simplified Configuration for mixerx-oracles module
|
|
9
|
-
*/
|
|
6
|
+
import type { ChainId, TokenPrices } from './types';
|
|
10
7
|
export interface MixerxOraclesConfig {
|
|
11
|
-
/** Chain ID */
|
|
12
8
|
chainId: ChainId;
|
|
13
|
-
/** RPC URL for blockchain connection */
|
|
14
9
|
rpcUrl: string;
|
|
15
|
-
/** Relayer fee percentage (e.g., 0.004 for 0.4%) */
|
|
16
10
|
relayerFeePercent: number;
|
|
17
|
-
/** Token price repository (for reading prices from Redis/cache) - optional */
|
|
18
11
|
priceRepository?: ITokenPriceRepository;
|
|
19
|
-
/** Multicall contract address (optional, uses default) */
|
|
20
12
|
multicallAddress?: string;
|
|
21
|
-
/** Offchain oracle contract address (optional, falls back to @mixerx/config by chain) */
|
|
22
13
|
offchainOracleAddress?: string;
|
|
23
|
-
|
|
14
|
+
logger?: ILogger;
|
|
15
|
+
rpcTimeoutMs?: number;
|
|
16
|
+
maxGasPriceGwei?: number;
|
|
17
|
+
maxPriceAgeMs?: number;
|
|
18
|
+
maxRefundWei?: bigint;
|
|
24
19
|
fallbackGasPrices?: {
|
|
25
20
|
legacy?: {
|
|
26
21
|
instant: number;
|
|
@@ -35,28 +30,12 @@ export interface MixerxOraclesConfig {
|
|
|
35
30
|
};
|
|
36
31
|
};
|
|
37
32
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Mixerx Oracles Module Interface
|
|
40
|
-
*/
|
|
41
33
|
export interface IMixerxOraclesModule {
|
|
42
|
-
/** Gas price oracle (EIP-1559 + Legacy) */
|
|
43
34
|
gasPriceOracle: GasPriceOracle;
|
|
44
|
-
/** Token price oracle (Multicall + OffchainOracle) */
|
|
45
35
|
tokenPriceOracle: TokenPriceOracle;
|
|
46
|
-
|
|
47
|
-
tornadoFeeOracle: TornadoFeeOracle;
|
|
48
|
-
/** Convenience method to fetch token prices */
|
|
36
|
+
mixerXFeeOracle: MixerXFeeOracle;
|
|
49
37
|
fetchPrices(): Promise<TokenPrices>;
|
|
50
|
-
|
|
38
|
+
assertReady(): Promise<void>;
|
|
51
39
|
chainId: ChainId;
|
|
52
40
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Factory function to create mixerx-oracles module
|
|
55
|
-
*
|
|
56
|
-
* This creates a complete oracle module with:
|
|
57
|
-
* - GasPriceOracle: Fetches EIP-1559 and Legacy gas prices from multiple sources
|
|
58
|
-
* - TokenPriceOracle: Fetches token prices using Multicall to OffchainOracle
|
|
59
|
-
* - TornadoFeeOracle: Calculates Tornado Cash withdrawal fees
|
|
60
|
-
*/
|
|
61
41
|
export declare function createMixerxOraclesModule(config: MixerxOraclesConfig): IMixerxOraclesModule;
|
|
62
|
-
//# sourceMappingURL=factory.d.ts.map
|
package/dist/factory.js
CHANGED
|
@@ -1,51 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMixerxOraclesModule = createMixerxOraclesModule;
|
|
4
|
+
const ILogger_1 = require("./application/ports/ILogger");
|
|
4
5
|
const GasPriceOracle_1 = require("./infrastructure/gas/GasPriceOracle");
|
|
6
|
+
const MixerXFeeOracle_1 = require("./infrastructure/mixerx/MixerXFeeOracle");
|
|
5
7
|
const TokenPriceOracle_1 = require("./infrastructure/token-price/TokenPriceOracle");
|
|
6
|
-
const TornadoFeeOracle_1 = require("./infrastructure/tornado/TornadoFeeOracle");
|
|
7
|
-
const ProtocolTokenConfig_1 = require("./infrastructure/config/ProtocolTokenConfig");
|
|
8
|
-
/**
|
|
9
|
-
* Factory function to create mixerx-oracles module
|
|
10
|
-
*
|
|
11
|
-
* This creates a complete oracle module with:
|
|
12
|
-
* - GasPriceOracle: Fetches EIP-1559 and Legacy gas prices from multiple sources
|
|
13
|
-
* - TokenPriceOracle: Fetches token prices using Multicall to OffchainOracle
|
|
14
|
-
* - TornadoFeeOracle: Calculates Tornado Cash withdrawal fees
|
|
15
|
-
*/
|
|
16
8
|
function createMixerxOraclesModule(config) {
|
|
17
|
-
|
|
18
|
-
const multicallAddress = config.multicallAddress || '0xeefBa1e63905eF1D7ACbA5a8513c70307C1cE441';
|
|
19
|
-
const offchainOracleAddress = config.offchainOracleAddress || (0, ProtocolTokenConfig_1.resolveOffchainOracleAddress)(config.chainId);
|
|
20
|
-
const defaultTokens = (0, ProtocolTokenConfig_1.resolveDefaultTokens)(config.chainId);
|
|
21
|
-
// Create gas price oracle
|
|
9
|
+
const logger = config.logger ?? new ILogger_1.NullLogger();
|
|
22
10
|
const gasPriceOracle = new GasPriceOracle_1.GasPriceOracle({
|
|
23
11
|
chainId: config.chainId,
|
|
24
12
|
rpcUrl: config.rpcUrl,
|
|
13
|
+
logger,
|
|
25
14
|
fallbackGasPrices: config.fallbackGasPrices,
|
|
15
|
+
rpcTimeoutMs: config.rpcTimeoutMs,
|
|
16
|
+
maxGasPriceGwei: config.maxGasPriceGwei,
|
|
26
17
|
});
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
// Create tornado fee oracle
|
|
30
|
-
const tornadoFeeOracle = new TornadoFeeOracle_1.TornadoFeeOracle({
|
|
18
|
+
const tokenPriceOracle = new TokenPriceOracle_1.TokenPriceOracle(config.rpcUrl, config.chainId, config.offchainOracleAddress, config.multicallAddress, undefined, logger, config.rpcTimeoutMs);
|
|
19
|
+
const mixerXFeeOracle = new MixerXFeeOracle_1.MixerXFeeOracle({
|
|
31
20
|
chainId: config.chainId,
|
|
32
21
|
rpcUrl: config.rpcUrl,
|
|
33
22
|
relayerFeePercent: config.relayerFeePercent,
|
|
34
23
|
gasPriceOracle,
|
|
35
24
|
tokenPriceOracle,
|
|
36
25
|
priceRepository: config.priceRepository,
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
logger,
|
|
27
|
+
rpcTimeoutMs: config.rpcTimeoutMs,
|
|
28
|
+
maxGasPriceGwei: config.maxGasPriceGwei,
|
|
29
|
+
maxPriceAgeMs: config.maxPriceAgeMs,
|
|
30
|
+
maxRefundWei: config.maxRefundWei,
|
|
39
31
|
});
|
|
40
32
|
return {
|
|
41
33
|
gasPriceOracle,
|
|
42
34
|
tokenPriceOracle,
|
|
43
|
-
|
|
35
|
+
mixerXFeeOracle,
|
|
44
36
|
chainId: config.chainId,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return tokenPriceOracle.fetchPrices();
|
|
48
|
-
},
|
|
37
|
+
fetchPrices: () => tokenPriceOracle.fetchPrices(),
|
|
38
|
+
assertReady: () => mixerXFeeOracle.assertReady(),
|
|
49
39
|
};
|
|
50
40
|
}
|
|
51
41
|
//# sourceMappingURL=factory.js.map
|
package/dist/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;AAmCA,8DAyCC;AA3ED,yDAAyD;AAEzD,wEAAqE;AACrE,6EAA0E;AAC1E,oFAAiF;AA8BjF,SAAgB,yBAAyB,CAAC,MAA2B;IACnE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,oBAAU,EAAE,CAAC;IACjD,MAAM,cAAc,GAAG,IAAI,+BAAc,CAAC;QACxC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM;QACN,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,eAAe,EAAE,MAAM,CAAC,eAAe;KACxC,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,IAAI,mCAAgB,CAC3C,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,qBAAqB,EAC5B,MAAM,CAAC,gBAAgB,EACvB,SAAS,EACT,MAAM,EACN,MAAM,CAAC,YAAY,CACpB,CAAC;IACF,MAAM,eAAe,GAAG,IAAI,iCAAe,CAAC;QAC1C,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,cAAc;QACd,gBAAgB;QAChB,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,MAAM;QACN,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,YAAY,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC,CAAC;IAEH,OAAO;QACL,cAAc;QACd,gBAAgB;QAChB,eAAe;QACf,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,WAAW,EAAE;QACjD,WAAW,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import type { ILogger } from './application/ports/ILogger';\r\nimport { NullLogger } from './application/ports/ILogger';\r\nimport type { ITokenPriceRepository } from './domain/repositories';\r\nimport { GasPriceOracle } from './infrastructure/gas/GasPriceOracle';\r\nimport { MixerXFeeOracle } from './infrastructure/mixerx/MixerXFeeOracle';\r\nimport { TokenPriceOracle } from './infrastructure/token-price/TokenPriceOracle';\r\nimport type { ChainId, TokenPrices } from './types';\r\n\r\nexport interface MixerxOraclesConfig {\r\n chainId: ChainId;\r\n rpcUrl: string;\r\n relayerFeePercent: number;\r\n priceRepository?: ITokenPriceRepository;\r\n multicallAddress?: string;\r\n offchainOracleAddress?: string;\r\n logger?: ILogger;\r\n rpcTimeoutMs?: number;\r\n maxGasPriceGwei?: number;\r\n maxPriceAgeMs?: number;\r\n maxRefundWei?: bigint;\r\n fallbackGasPrices?: {\r\n legacy?: { instant: number; fast: number; standard: number; low: number };\r\n eip1559?: { baseFee: number; maxFeePerGas: number; maxPriorityFeePerGas: number };\r\n };\r\n}\r\n\r\nexport interface IMixerxOraclesModule {\r\n gasPriceOracle: GasPriceOracle;\r\n tokenPriceOracle: TokenPriceOracle;\r\n mixerXFeeOracle: MixerXFeeOracle;\r\n fetchPrices(): Promise<TokenPrices>;\r\n assertReady(): Promise<void>;\r\n chainId: ChainId;\r\n}\r\n\r\nexport function createMixerxOraclesModule(config: MixerxOraclesConfig): IMixerxOraclesModule {\r\n const logger = config.logger ?? new NullLogger();\r\n const gasPriceOracle = new GasPriceOracle({\r\n chainId: config.chainId,\r\n rpcUrl: config.rpcUrl,\r\n logger,\r\n fallbackGasPrices: config.fallbackGasPrices,\r\n rpcTimeoutMs: config.rpcTimeoutMs,\r\n maxGasPriceGwei: config.maxGasPriceGwei,\r\n });\r\n const tokenPriceOracle = new TokenPriceOracle(\r\n config.rpcUrl,\r\n config.chainId,\r\n config.offchainOracleAddress,\r\n config.multicallAddress,\r\n undefined,\r\n logger,\r\n config.rpcTimeoutMs,\r\n );\r\n const mixerXFeeOracle = new MixerXFeeOracle({\r\n chainId: config.chainId,\r\n rpcUrl: config.rpcUrl,\r\n relayerFeePercent: config.relayerFeePercent,\r\n gasPriceOracle,\r\n tokenPriceOracle,\r\n priceRepository: config.priceRepository,\r\n logger,\r\n rpcTimeoutMs: config.rpcTimeoutMs,\r\n maxGasPriceGwei: config.maxGasPriceGwei,\r\n maxPriceAgeMs: config.maxPriceAgeMs,\r\n maxRefundWei: config.maxRefundWei,\r\n });\r\n\r\n return {\r\n gasPriceOracle,\r\n tokenPriceOracle,\r\n mixerXFeeOracle,\r\n chainId: config.chainId,\r\n fetchPrices: () => tokenPriceOracle.fetchPrices(),\r\n assertReady: () => mixerXFeeOracle.assertReady(),\r\n };\r\n}\r\n"]}
|