@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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenPriceOracle = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const MulticallProvider_1 = require("../multicall/MulticallProvider");
|
|
6
|
+
const TokenDefaults_1 = require("../../domain/config/TokenDefaults");
|
|
7
|
+
const ILogger_1 = require("../../application/ports/ILogger");
|
|
8
|
+
const ProtocolTokenConfig_1 = require("../config/ProtocolTokenConfig");
|
|
9
|
+
/**
|
|
10
|
+
* TokenPriceOracle
|
|
11
|
+
* Fetches token prices from OffchainOracle using Multicall
|
|
12
|
+
* Based on @tornado/tornado-oracles TokenPriceOracle
|
|
13
|
+
*
|
|
14
|
+
* Uses protocol-configured OffchainOracle from @mixerx/config
|
|
15
|
+
* Returns price rate to ETH in wei (how much ETH 1 token = X wei)
|
|
16
|
+
*
|
|
17
|
+
* NOTE: Uses centralized TokenDefaults to avoid duplication
|
|
18
|
+
*/
|
|
19
|
+
class TokenPriceOracle {
|
|
20
|
+
multicall;
|
|
21
|
+
offchainOracleAddress;
|
|
22
|
+
offchainOracleAbi = [
|
|
23
|
+
'function getRateToEth(address srcToken, bool useSrcWrappers) external view returns (uint256 weightedRate)',
|
|
24
|
+
];
|
|
25
|
+
// Default tokens from @mixerx/config by chain
|
|
26
|
+
defaultTokens;
|
|
27
|
+
// Default prices as fallback (in wei) - from TokenDefaults
|
|
28
|
+
defaultPrices = TokenDefaults_1.DEFAULT_TOKEN_PRICES;
|
|
29
|
+
logger;
|
|
30
|
+
constructor(rpcUrl, chainId, offchainOracleAddress, multicallAddress, tokens, logger) {
|
|
31
|
+
this.multicall = new MulticallProvider_1.MulticallProvider(rpcUrl, multicallAddress);
|
|
32
|
+
this.offchainOracleAddress = offchainOracleAddress ?? (0, ProtocolTokenConfig_1.resolveOffchainOracleAddress)(chainId);
|
|
33
|
+
this.defaultTokens = tokens ?? (0, ProtocolTokenConfig_1.resolveDefaultTokens)(chainId);
|
|
34
|
+
this.logger = logger ?? new ILogger_1.NullLogger();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetch prices for tokens
|
|
38
|
+
* Uses multicall to batch requests
|
|
39
|
+
*/
|
|
40
|
+
async fetchPrices(tokens = this.defaultTokens) {
|
|
41
|
+
try {
|
|
42
|
+
if (tokens.length === 0) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
// Prepare multicall data
|
|
46
|
+
const calls = tokens.map(token => ({
|
|
47
|
+
target: this.offchainOracleAddress,
|
|
48
|
+
callData: this.encodeGetRateToEth(token.address),
|
|
49
|
+
}));
|
|
50
|
+
// Execute multicall
|
|
51
|
+
const results = await this.multicall.aggregate(calls);
|
|
52
|
+
const prices = {};
|
|
53
|
+
for (let i = 0; i < results.length; i++) {
|
|
54
|
+
const token = tokens[i];
|
|
55
|
+
const result = results[i];
|
|
56
|
+
if (!result.success) {
|
|
57
|
+
// Use default price if available
|
|
58
|
+
const defaultPrice = this.defaultPrices[token.symbol.toLowerCase()];
|
|
59
|
+
if (defaultPrice) {
|
|
60
|
+
prices[token.symbol.toLowerCase()] = defaultPrice;
|
|
61
|
+
this.logger.warn('TokenPriceOracle default price used (call failed)', {
|
|
62
|
+
symbol: token.symbol,
|
|
63
|
+
address: token.address,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
// Decode result
|
|
70
|
+
const rateWei = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(['uint256'], result.returnData)[0];
|
|
71
|
+
// Convert rate to proper decimals
|
|
72
|
+
// Formula: (rate * 10^tokenDecimals) / 10^18
|
|
73
|
+
const tokenDecimals = 10n ** BigInt(token.decimals);
|
|
74
|
+
const ethDecimals = 10n ** 18n;
|
|
75
|
+
const price = (rateWei * tokenDecimals) / ethDecimals;
|
|
76
|
+
prices[token.symbol.toLowerCase()] = price.toString();
|
|
77
|
+
}
|
|
78
|
+
catch (decodeError) {
|
|
79
|
+
// Use default if decoding fails
|
|
80
|
+
const defaultPrice = this.defaultPrices[token.symbol.toLowerCase()];
|
|
81
|
+
if (defaultPrice) {
|
|
82
|
+
prices[token.symbol.toLowerCase()] = defaultPrice;
|
|
83
|
+
this.logger.warn('TokenPriceOracle default price used (decode failed)', {
|
|
84
|
+
symbol: token.symbol,
|
|
85
|
+
address: token.address,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return prices;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.logger.error('Failed to fetch token prices:', error);
|
|
94
|
+
// Return defaults on complete failure
|
|
95
|
+
this.logger.warn('TokenPriceOracle using default prices (fetch failed)');
|
|
96
|
+
return this.defaultPrices;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Fetch price for single token
|
|
101
|
+
*/
|
|
102
|
+
async fetchPrice(token) {
|
|
103
|
+
const prices = await this.fetchPrices([token]);
|
|
104
|
+
return prices[token.symbol.toLowerCase()] || null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get default prices
|
|
108
|
+
*/
|
|
109
|
+
getDefaultPrices() {
|
|
110
|
+
return { ...this.defaultPrices };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get supported tokens
|
|
114
|
+
*/
|
|
115
|
+
getSupportedTokens() {
|
|
116
|
+
return [...this.defaultTokens];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Add custom tokens
|
|
120
|
+
*/
|
|
121
|
+
addTokens(tokens) {
|
|
122
|
+
this.defaultTokens = [...this.defaultTokens, ...tokens];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Encode getRateToEth call
|
|
126
|
+
*/
|
|
127
|
+
encodeGetRateToEth(tokenAddress) {
|
|
128
|
+
const iface = new ethers_1.ethers.Interface(this.offchainOracleAbi);
|
|
129
|
+
return iface.encodeFunctionData('getRateToEth', [tokenAddress, true]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.TokenPriceOracle = TokenPriceOracle;
|
|
133
|
+
//# sourceMappingURL=TokenPriceOracle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenPriceOracle.js","sourceRoot":"","sources":["../../../src/infrastructure/token-price/TokenPriceOracle.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,sEAAyE;AACzE,qEAE2C;AAC3C,6DAAsE;AAEtE,uEAAmG;AAMnG;;;;;;;;;GASG;AACH,MAAa,gBAAgB;IACnB,SAAS,CAAoB;IAC7B,qBAAqB,CAAS;IAC9B,iBAAiB,GAAa;QACpC,2GAA2G;KAC5G,CAAC;IAEF,8CAA8C;IACtC,aAAa,CAAU;IAE/B,2DAA2D;IACnD,aAAa,GAAgB,oCAAoB,CAAC;IAElD,MAAM,CAAU;IAExB,YACE,MAAc,EACd,OAAyB,EACzB,qBAA8B,EAC9B,gBAAyB,EACzB,MAAgB,EAChB,MAAgB;QAEhB,IAAI,CAAC,SAAS,GAAG,IAAI,qCAAiB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACjE,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,IAAI,IAAA,kDAA4B,EAAC,OAAO,CAAC,CAAC;QAC5F,IAAI,CAAC,aAAa,GAAG,MAAM,IAAI,IAAA,0CAAoB,EAAC,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,oBAAU,EAAE,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,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AK,CAAC,UAAU,CAAC,KAAY;QAC3B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,MAAe;QACvB,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,GAAG,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,YAAoB;QAC7C,MAAM,KAAK,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AA3ID,4CA2IC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/token-price/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenPriceOracle = void 0;
|
|
4
|
+
var TokenPriceOracle_1 = require("./TokenPriceOracle");
|
|
5
|
+
Object.defineProperty(exports, "TokenPriceOracle", { enumerable: true, get: function () { return TokenPriceOracle_1.TokenPriceOracle; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/infrastructure/token-price/index.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AAA1D,oHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { GasPriceOracle, GasPriceParams } from '../gas/GasPriceOracle';
|
|
2
|
+
import { TokenPriceOracle } from '../token-price/TokenPriceOracle';
|
|
3
|
+
import { ITokenPriceRepository } from '../../domain/repositories';
|
|
4
|
+
import { ChainId } from '../config/gasOracleConfigs';
|
|
5
|
+
import { ILogger } from '../../application/ports/ILogger';
|
|
6
|
+
export interface TornadoFeeOracleOptions {
|
|
7
|
+
chainId: ChainId;
|
|
8
|
+
rpcUrl: string;
|
|
9
|
+
relayerFeePercent: number;
|
|
10
|
+
gasPriceOracle?: GasPriceOracle;
|
|
11
|
+
tokenPriceOracle?: TokenPriceOracle;
|
|
12
|
+
priceRepository?: ITokenPriceRepository;
|
|
13
|
+
logger?: ILogger;
|
|
14
|
+
multicallAddress?: string;
|
|
15
|
+
offchainOracleAddress?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface WithdrawalFeeInput {
|
|
18
|
+
currency: string;
|
|
19
|
+
amount: bigint;
|
|
20
|
+
decimals: number;
|
|
21
|
+
refund?: string;
|
|
22
|
+
txType?: 'relayer_withdrawal' | 'user_withdrawal' | 'relayer_withdrawal_check_v4';
|
|
23
|
+
}
|
|
24
|
+
export interface FeeCalculationResult {
|
|
25
|
+
gasCost: bigint;
|
|
26
|
+
relayerFee: bigint;
|
|
27
|
+
refundAmount: bigint;
|
|
28
|
+
totalFee: bigint;
|
|
29
|
+
currency: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* TornadoFeeOracle
|
|
33
|
+
* Calculates fees for Tornado Cash withdrawals
|
|
34
|
+
* Based on @tornado/tornado-oracles TornadoFeeOracleV5
|
|
35
|
+
*
|
|
36
|
+
* Features:
|
|
37
|
+
* - Smart gas limit bumping (10% for relayer, 30% for user)
|
|
38
|
+
* - Token price conversion (ETH↔Token)
|
|
39
|
+
* - Refund calculation for non-ETH tokens
|
|
40
|
+
* - EIP-1559 and Legacy support
|
|
41
|
+
*/
|
|
42
|
+
export declare class TornadoFeeOracle {
|
|
43
|
+
private chainId;
|
|
44
|
+
private relayerFeePercent;
|
|
45
|
+
private gasPriceOracle;
|
|
46
|
+
private tokenPriceOracle?;
|
|
47
|
+
private priceRepository?;
|
|
48
|
+
private logger;
|
|
49
|
+
constructor(options: TornadoFeeOracleOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Calculate withdrawal fee
|
|
52
|
+
* Main method matching TornadoFeeOracleV5.calculateWithdrawalFeeViaRelayer
|
|
53
|
+
*/
|
|
54
|
+
calculateWithdrawalFee(input: WithdrawalFeeInput): Promise<FeeCalculationResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Get gas parameters for transaction
|
|
57
|
+
*/
|
|
58
|
+
private getGasParams;
|
|
59
|
+
/**
|
|
60
|
+
* Calculate gas cost in wei
|
|
61
|
+
*/
|
|
62
|
+
private calculateGasCost;
|
|
63
|
+
/**
|
|
64
|
+
* Calculate relayer fee
|
|
65
|
+
*/
|
|
66
|
+
private calculateRelayerFee;
|
|
67
|
+
/**
|
|
68
|
+
* Get gas limit for operation and token
|
|
69
|
+
* Uses centralized TokenDefaults to eliminate duplication
|
|
70
|
+
*/
|
|
71
|
+
private getGasLimit;
|
|
72
|
+
/**
|
|
73
|
+
* Get bump percent based on transaction type (V5 smart bumping)
|
|
74
|
+
* Uses centralized TokenDefaults to eliminate duplication
|
|
75
|
+
*/
|
|
76
|
+
private getBumpPercent;
|
|
77
|
+
/**
|
|
78
|
+
* Get token price in ETH (wei per token unit)
|
|
79
|
+
*/
|
|
80
|
+
private getTokenPrice;
|
|
81
|
+
/**
|
|
82
|
+
* Get gas parameters for direct use
|
|
83
|
+
*/
|
|
84
|
+
getGasParameters(isLegacy?: boolean): Promise<GasPriceParams>;
|
|
85
|
+
/**
|
|
86
|
+
* Get chain ID
|
|
87
|
+
*/
|
|
88
|
+
getChainId(): ChainId;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=TornadoFeeOracle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TornadoFeeOracle.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/tornado/TornadoFeeOracle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAoB,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,OAAO,EAAiB,MAAM,iCAAiC,CAAC;AASzE,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,oBAAoB,GAAG,iBAAiB,GAAG,6BAA6B,CAAC;CACnF;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAKD;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,gBAAgB,CAAC,CAAmB;IAC5C,OAAO,CAAC,eAAe,CAAC,CAAwB;IAChD,OAAO,CAAC,MAAM,CAAU;gBAEZ,OAAO,EAAE,uBAAuB;IA2B5C;;;OAGG;IACG,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA6FtF;;OAEG;YACW,YAAY;IAU1B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;;OAGG;IACH,OAAO,CAAC,WAAW;IAWnB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;YACW,aAAa;IAqB3B;;OAEG;IACG,gBAAgB,CAAC,QAAQ,GAAE,OAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAI1E;;OAEG;IACH,UAAU,IAAI,OAAO;CAGtB"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TornadoFeeOracle = void 0;
|
|
4
|
+
const GasPriceOracle_1 = require("../gas/GasPriceOracle");
|
|
5
|
+
const TokenPriceOracle_1 = require("../token-price/TokenPriceOracle");
|
|
6
|
+
const ILogger_1 = require("../../application/ports/ILogger");
|
|
7
|
+
const TokenDefaults_1 = require("../../domain/config/TokenDefaults");
|
|
8
|
+
// NOTE: Gas limits now imported from TokenDefaults (centralized configuration)
|
|
9
|
+
// This eliminates duplication between TornadoFeeOracle, ChainConfigs, and FeeCalculator
|
|
10
|
+
/**
|
|
11
|
+
* TornadoFeeOracle
|
|
12
|
+
* Calculates fees for Tornado Cash withdrawals
|
|
13
|
+
* Based on @tornado/tornado-oracles TornadoFeeOracleV5
|
|
14
|
+
*
|
|
15
|
+
* Features:
|
|
16
|
+
* - Smart gas limit bumping (10% for relayer, 30% for user)
|
|
17
|
+
* - Token price conversion (ETH↔Token)
|
|
18
|
+
* - Refund calculation for non-ETH tokens
|
|
19
|
+
* - EIP-1559 and Legacy support
|
|
20
|
+
*/
|
|
21
|
+
class TornadoFeeOracle {
|
|
22
|
+
chainId;
|
|
23
|
+
relayerFeePercent;
|
|
24
|
+
gasPriceOracle;
|
|
25
|
+
tokenPriceOracle;
|
|
26
|
+
priceRepository;
|
|
27
|
+
logger;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.chainId = options.chainId;
|
|
30
|
+
this.relayerFeePercent = options.relayerFeePercent;
|
|
31
|
+
// Initialize gas price oracle
|
|
32
|
+
this.gasPriceOracle = options.gasPriceOracle ?? new GasPriceOracle_1.GasPriceOracle({
|
|
33
|
+
chainId: options.chainId,
|
|
34
|
+
rpcUrl: options.rpcUrl,
|
|
35
|
+
logger: options.logger ?? new ILogger_1.ConsoleLogger('LegacyGasOracle'),
|
|
36
|
+
});
|
|
37
|
+
// Initialize token price oracle if RPC provided
|
|
38
|
+
if (options.tokenPriceOracle) {
|
|
39
|
+
this.tokenPriceOracle = options.tokenPriceOracle;
|
|
40
|
+
}
|
|
41
|
+
else if (options.rpcUrl) {
|
|
42
|
+
this.tokenPriceOracle = new TokenPriceOracle_1.TokenPriceOracle(options.rpcUrl, options.chainId, options.offchainOracleAddress, options.multicallAddress);
|
|
43
|
+
}
|
|
44
|
+
this.priceRepository = options.priceRepository;
|
|
45
|
+
this.logger = options.logger ?? new ILogger_1.ConsoleLogger('TornadoFeeOracle');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Calculate withdrawal fee
|
|
49
|
+
* Main method matching TornadoFeeOracleV5.calculateWithdrawalFeeViaRelayer
|
|
50
|
+
*/
|
|
51
|
+
async calculateWithdrawalFee(input) {
|
|
52
|
+
const { currency, amount, decimals, refund, txType = 'relayer_withdrawal' } = input;
|
|
53
|
+
const currencyLower = currency.toLowerCase();
|
|
54
|
+
// 1. Get gas parameters
|
|
55
|
+
const gasParams = await this.getGasParams(txType);
|
|
56
|
+
const gasLimit = this.getGasLimit(currencyLower, txType);
|
|
57
|
+
const gasPriceWei = gasParams.maxFeePerGas
|
|
58
|
+
? BigInt(gasParams.maxFeePerGas)
|
|
59
|
+
: gasParams.gasPrice
|
|
60
|
+
? BigInt(gasParams.gasPrice)
|
|
61
|
+
: 0n;
|
|
62
|
+
// 2. Calculate gas cost in wei
|
|
63
|
+
const gasCostWei = this.calculateGasCost(gasParams, currencyLower, txType);
|
|
64
|
+
// 3. Calculate relayer fee
|
|
65
|
+
const relayerFee = this.calculateRelayerFee(amount);
|
|
66
|
+
this.logger.debug('TornadoFeeOracle fee inputs', {
|
|
67
|
+
chainId: this.chainId,
|
|
68
|
+
currency: currencyLower,
|
|
69
|
+
amount: amount.toString(),
|
|
70
|
+
decimals,
|
|
71
|
+
refund,
|
|
72
|
+
txType,
|
|
73
|
+
gasLimit,
|
|
74
|
+
gasPriceWei: gasPriceWei.toString(),
|
|
75
|
+
maxFeePerGas: gasParams.maxFeePerGas,
|
|
76
|
+
maxPriorityFeePerGas: gasParams.maxPriorityFeePerGas,
|
|
77
|
+
gasPrice: gasParams.gasPrice,
|
|
78
|
+
relayerFeePercent: this.relayerFeePercent,
|
|
79
|
+
});
|
|
80
|
+
// 4. For ETH, calculation is simple
|
|
81
|
+
if (currencyLower === 'eth') {
|
|
82
|
+
const totalFee = gasCostWei + relayerFee;
|
|
83
|
+
this.logger.debug('TornadoFeeOracle fee breakdown', {
|
|
84
|
+
gasCost: gasCostWei.toString(),
|
|
85
|
+
relayerFee: relayerFee.toString(),
|
|
86
|
+
totalFee: totalFee.toString(),
|
|
87
|
+
currency: 'eth',
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
gasCost: gasCostWei,
|
|
91
|
+
relayerFee,
|
|
92
|
+
refundAmount: 0n,
|
|
93
|
+
totalFee,
|
|
94
|
+
currency: 'eth',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// 5. For tokens, convert ETH costs to token
|
|
98
|
+
const tokenPriceInEth = await this.getTokenPrice(currencyLower);
|
|
99
|
+
if (!tokenPriceInEth) {
|
|
100
|
+
throw new Error(`No price available for ${currency}`);
|
|
101
|
+
}
|
|
102
|
+
// Convert gas cost from ETH to token
|
|
103
|
+
// Formula: (ethAmount * 10^decimals) / price
|
|
104
|
+
const decimalsFactor = BigInt(10 ** decimals);
|
|
105
|
+
const gasCostInToken = (gasCostWei * decimalsFactor) / tokenPriceInEth;
|
|
106
|
+
// Relayer fee is already in token units
|
|
107
|
+
const relayerFeeInToken = relayerFee;
|
|
108
|
+
// Calculate refund in token if provided
|
|
109
|
+
let refundInToken = 0n;
|
|
110
|
+
if (refund && BigInt(refund) > 0) {
|
|
111
|
+
const refundWei = BigInt(refund);
|
|
112
|
+
refundInToken = (refundWei * decimalsFactor) / tokenPriceInEth;
|
|
113
|
+
}
|
|
114
|
+
// Total fee
|
|
115
|
+
const totalFee = gasCostInToken + relayerFeeInToken + refundInToken;
|
|
116
|
+
this.logger.debug('TornadoFeeOracle fee breakdown', {
|
|
117
|
+
tokenPriceInEth: tokenPriceInEth.toString(),
|
|
118
|
+
gasCostInToken: gasCostInToken.toString(),
|
|
119
|
+
relayerFeeInToken: relayerFeeInToken.toString(),
|
|
120
|
+
refundInToken: refundInToken.toString(),
|
|
121
|
+
totalFee: totalFee.toString(),
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
gasCost: gasCostInToken,
|
|
125
|
+
relayerFee: relayerFeeInToken,
|
|
126
|
+
refundAmount: refundInToken,
|
|
127
|
+
totalFee,
|
|
128
|
+
currency: currencyLower,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get gas parameters for transaction
|
|
133
|
+
*/
|
|
134
|
+
async getGasParams(txType) {
|
|
135
|
+
const bumpPercent = this.getBumpPercent(txType);
|
|
136
|
+
return this.gasPriceOracle.getTxGasParams({
|
|
137
|
+
isLegacy: false,
|
|
138
|
+
bumpPercent,
|
|
139
|
+
legacySpeed: 'fast',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Calculate gas cost in wei
|
|
144
|
+
*/
|
|
145
|
+
calculateGasCost(gasParams, currency, txType) {
|
|
146
|
+
const gasLimit = this.getGasLimit(currency, txType);
|
|
147
|
+
// Extract gas price from params (EIP-1559 or Legacy)
|
|
148
|
+
let gasPriceWei;
|
|
149
|
+
if (gasParams.maxFeePerGas) {
|
|
150
|
+
// EIP-1559: use maxFeePerGas
|
|
151
|
+
gasPriceWei = BigInt(gasParams.maxFeePerGas);
|
|
152
|
+
}
|
|
153
|
+
else if (gasParams.gasPrice) {
|
|
154
|
+
// Legacy: use gasPrice
|
|
155
|
+
gasPriceWei = BigInt(gasParams.gasPrice);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw new Error('Invalid gas parameters');
|
|
159
|
+
}
|
|
160
|
+
return gasPriceWei * BigInt(gasLimit);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Calculate relayer fee
|
|
164
|
+
*/
|
|
165
|
+
calculateRelayerFee(amount) {
|
|
166
|
+
const percent = this.relayerFeePercent;
|
|
167
|
+
// Apply fee percentage
|
|
168
|
+
// Formula: amount * percent (where percent is 0.004 for 0.4%)
|
|
169
|
+
const fee = (amount * BigInt(Math.round(percent * 1e6))) / BigInt(1e6);
|
|
170
|
+
return fee;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get gas limit for operation and token
|
|
174
|
+
* Uses centralized TokenDefaults to eliminate duplication
|
|
175
|
+
*/
|
|
176
|
+
getGasLimit(currency, txType) {
|
|
177
|
+
// Check if it's a mining operation
|
|
178
|
+
if (txType.includes('mining')) {
|
|
179
|
+
const operation = txType.includes('reward') ? 'reward' : 'withdraw';
|
|
180
|
+
return (0, TokenDefaults_1.getMiningGasLimit)(operation);
|
|
181
|
+
}
|
|
182
|
+
// Regular Tornado withdraw
|
|
183
|
+
return (0, TokenDefaults_1.getTornadoGasLimit)(currency);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get bump percent based on transaction type (V5 smart bumping)
|
|
187
|
+
* Uses centralized TokenDefaults to eliminate duplication
|
|
188
|
+
*/
|
|
189
|
+
getBumpPercent(txType) {
|
|
190
|
+
return (0, TokenDefaults_1.getBumpPercent)(txType);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get token price in ETH (wei per token unit)
|
|
194
|
+
*/
|
|
195
|
+
async getTokenPrice(symbol) {
|
|
196
|
+
// Try price repository first (Redis)
|
|
197
|
+
if (this.priceRepository) {
|
|
198
|
+
const price = await this.priceRepository.getPrice(symbol);
|
|
199
|
+
if (price)
|
|
200
|
+
return price;
|
|
201
|
+
}
|
|
202
|
+
// Fallback to token price oracle
|
|
203
|
+
if (this.tokenPriceOracle) {
|
|
204
|
+
try {
|
|
205
|
+
const prices = await this.tokenPriceOracle.fetchPrices();
|
|
206
|
+
const price = prices[symbol.toLowerCase()];
|
|
207
|
+
if (price)
|
|
208
|
+
return BigInt(price);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// Ignore error, will return null
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get gas parameters for direct use
|
|
218
|
+
*/
|
|
219
|
+
async getGasParameters(isLegacy = false) {
|
|
220
|
+
return this.gasPriceOracle.getTxGasParams({ isLegacy });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get chain ID
|
|
224
|
+
*/
|
|
225
|
+
getChainId() {
|
|
226
|
+
return this.chainId;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.TornadoFeeOracle = TornadoFeeOracle;
|
|
230
|
+
//# sourceMappingURL=TornadoFeeOracle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TornadoFeeOracle.js","sourceRoot":"","sources":["../../../src/infrastructure/tornado/TornadoFeeOracle.ts"],"names":[],"mappings":";;;AAAA,0DAAuE;AACvE,sEAAmE;AAGnE,6DAAyE;AACzE,qEAM2C;AA8B3C,+EAA+E;AAC/E,wFAAwF;AAExF;;;;;;;;;;GAUG;AACH,MAAa,gBAAgB;IACnB,OAAO,CAAU;IACjB,iBAAiB,CAAS;IAC1B,cAAc,CAAiB;IAC/B,gBAAgB,CAAoB;IACpC,eAAe,CAAyB;IACxC,MAAM,CAAU;IAExB,YAAY,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAEnD,8BAA8B;QAC9B,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,+BAAc,CAAC;YACjE,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,uBAAa,CAAC,iBAAiB,CAAC;SAC/D,CAAC,CAAC;QAEH,gDAAgD;QAChD,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC7B,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACnD,CAAC;aAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAC1B,IAAI,CAAC,gBAAgB,GAAG,IAAI,mCAAgB,CAC1C,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,OAAO,EACf,OA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e,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC1D,IAAI,KAAK;gBAAE,OAAO,KAAK,CAAC;QAC1B,CAAC;QAED,iCAAiC;QACjC,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC;gBACzD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;gBAC3C,IAAI,KAAK;oBAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;YAAC,MAAM,CAAC;gBACP,iCAAiC;YACnC,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB,CAAC,WAAoB,KAAK;QAC9C,OAAO,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA9OD,4CA8OC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,KAAK;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mixerx/oracles",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Complete oracle library for MixerX - gas prices (EIP-1559 + Legacy), token prices, and Tornado fee calculations",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"packageManager": "yarn@4.12.0",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/**/*",
|
|
10
|
+
"abis/**/*"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
15
|
+
"prepare": "yarn build",
|
|
16
|
+
"prepublishOnly": "yarn clean && yarn build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mixerx",
|
|
20
|
+
"tornado",
|
|
21
|
+
"ethereum",
|
|
22
|
+
"gas",
|
|
23
|
+
"oracle",
|
|
24
|
+
"fees"
|
|
25
|
+
],
|
|
26
|
+
"author": "MixerX Team",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@mixerx/config": "npm:^0.2.0",
|
|
30
|
+
"axios": "^1.13.5",
|
|
31
|
+
"ethers": "^6.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^24.0.0",
|
|
35
|
+
"typescript": "^5.0.0"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=24.12.0"
|
|
39
|
+
}
|
|
40
|
+
}
|