@mento-protocol/mento-sdk 1.10.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/package.json +1 -1
  2. package/dist/cjs/scripts/cacheTradablePairs/config.d.ts +0 -5
  3. package/dist/cjs/scripts/cacheTradablePairs/config.js +0 -6
  4. package/dist/cjs/scripts/quotes/config.d.ts +0 -20
  5. package/dist/cjs/scripts/quotes/config.js +0 -33
  6. package/dist/cjs/scripts/quotes/spread.d.ts +0 -25
  7. package/dist/cjs/scripts/quotes/spread.js +0 -166
  8. package/dist/cjs/scripts/shared/network.d.ts +0 -23
  9. package/dist/cjs/scripts/shared/network.js +0 -57
  10. package/dist/esm/scripts/cacheTradablePairs/config.d.ts +0 -5
  11. package/dist/esm/scripts/cacheTradablePairs/config.js +0 -3
  12. package/dist/esm/scripts/quotes/config.d.ts +0 -20
  13. package/dist/esm/scripts/quotes/config.js +0 -30
  14. package/dist/esm/scripts/quotes/spread.d.ts +0 -25
  15. package/dist/esm/scripts/quotes/spread.js +0 -161
  16. package/dist/esm/scripts/shared/network.d.ts +0 -23
  17. package/dist/esm/scripts/shared/network.js +0 -52
  18. /package/dist/cjs/{src/ChainClient.d.ts → ChainClient.d.ts} +0 -0
  19. /package/dist/cjs/{src/ChainClient.js → ChainClient.js} +0 -0
  20. /package/dist/cjs/{src/TestChainClient.d.ts → TestChainClient.d.ts} +0 -0
  21. /package/dist/cjs/{src/TestChainClient.js → TestChainClient.js} +0 -0
  22. /package/dist/cjs/{src/constants → constants}/addresses.d.ts +0 -0
  23. /package/dist/cjs/{src/constants → constants}/addresses.js +0 -0
  24. /package/dist/cjs/{src/constants → constants}/index.d.ts +0 -0
  25. /package/dist/cjs/{src/constants → constants}/index.js +0 -0
  26. /package/dist/cjs/{src/constants → constants}/tradablePairs.42220.d.ts +0 -0
  27. /package/dist/cjs/{src/constants → constants}/tradablePairs.42220.js +0 -0
  28. /package/dist/cjs/{src/constants → constants}/tradablePairs.44787.d.ts +0 -0
  29. /package/dist/cjs/{src/constants → constants}/tradablePairs.44787.js +0 -0
  30. /package/dist/cjs/{src/constants → constants}/tradablePairs.d.ts +0 -0
  31. /package/dist/cjs/{src/constants → constants}/tradablePairs.js +0 -0
  32. /package/dist/cjs/{src/enums → enums}/chainId.d.ts +0 -0
  33. /package/dist/cjs/{src/enums → enums}/chainId.js +0 -0
  34. /package/dist/cjs/{src/enums → enums}/index.d.ts +0 -0
  35. /package/dist/cjs/{src/enums → enums}/index.js +0 -0
  36. /package/dist/cjs/{src/enums → enums}/proposalState.d.ts +0 -0
  37. /package/dist/cjs/{src/enums → enums}/proposalState.js +0 -0
  38. /package/dist/cjs/{src/governance.d.ts → governance.d.ts} +0 -0
  39. /package/dist/cjs/{src/governance.js → governance.js} +0 -0
  40. /package/dist/cjs/{src/index.d.ts → index.d.ts} +0 -0
  41. /package/dist/cjs/{src/index.js → index.js} +0 -0
  42. /package/dist/cjs/{src/interfaces → interfaces}/IChainClient.d.ts +0 -0
  43. /package/dist/cjs/{src/interfaces → interfaces}/IChainClient.js +0 -0
  44. /package/dist/cjs/{src/interfaces → interfaces}/index.d.ts +0 -0
  45. /package/dist/cjs/{src/interfaces → interfaces}/index.js +0 -0
  46. /package/dist/cjs/{src/interfaces → interfaces}/tradingLimit.d.ts +0 -0
  47. /package/dist/cjs/{src/interfaces → interfaces}/tradingLimit.js +0 -0
  48. /package/dist/cjs/{src/interfaces → interfaces}/tradingLimitsConfig.d.ts +0 -0
  49. /package/dist/cjs/{src/interfaces → interfaces}/tradingLimitsConfig.js +0 -0
  50. /package/dist/cjs/{src/interfaces → interfaces}/tradingLimitsState.d.ts +0 -0
  51. /package/dist/cjs/{src/interfaces → interfaces}/tradingLimitsState.js +0 -0
  52. /package/dist/cjs/{src/limits.d.ts → limits.d.ts} +0 -0
  53. /package/dist/cjs/{src/limits.js → limits.js} +0 -0
  54. /package/dist/cjs/{src/mento.d.ts → mento.d.ts} +0 -0
  55. /package/dist/cjs/{src/mento.js → mento.js} +0 -0
  56. /package/dist/cjs/{src/routeUtils.d.ts → routeUtils.d.ts} +0 -0
  57. /package/dist/cjs/{src/routeUtils.js → routeUtils.js} +0 -0
  58. /package/dist/cjs/{src/types → types}/contractAddressMap.d.ts +0 -0
  59. /package/dist/cjs/{src/types → types}/contractAddressMap.js +0 -0
  60. /package/dist/cjs/{src/types → types}/contractAddresses.d.ts +0 -0
  61. /package/dist/cjs/{src/types → types}/contractAddresses.js +0 -0
  62. /package/dist/cjs/{src/types → types}/index.d.ts +0 -0
  63. /package/dist/cjs/{src/types → types}/index.js +0 -0
  64. /package/dist/cjs/{src/utils.d.ts → utils.d.ts} +0 -0
  65. /package/dist/cjs/{src/utils.js → utils.js} +0 -0
  66. /package/dist/esm/{src/ChainClient.d.ts → ChainClient.d.ts} +0 -0
  67. /package/dist/esm/{src/ChainClient.js → ChainClient.js} +0 -0
  68. /package/dist/esm/{src/TestChainClient.d.ts → TestChainClient.d.ts} +0 -0
  69. /package/dist/esm/{src/TestChainClient.js → TestChainClient.js} +0 -0
  70. /package/dist/esm/{src/constants → constants}/addresses.d.ts +0 -0
  71. /package/dist/esm/{src/constants → constants}/addresses.js +0 -0
  72. /package/dist/esm/{src/constants → constants}/index.d.ts +0 -0
  73. /package/dist/esm/{src/constants → constants}/index.js +0 -0
  74. /package/dist/esm/{src/constants → constants}/tradablePairs.42220.d.ts +0 -0
  75. /package/dist/esm/{src/constants → constants}/tradablePairs.42220.js +0 -0
  76. /package/dist/esm/{src/constants → constants}/tradablePairs.44787.d.ts +0 -0
  77. /package/dist/esm/{src/constants → constants}/tradablePairs.44787.js +0 -0
  78. /package/dist/esm/{src/constants → constants}/tradablePairs.d.ts +0 -0
  79. /package/dist/esm/{src/constants → constants}/tradablePairs.js +0 -0
  80. /package/dist/esm/{src/enums → enums}/chainId.d.ts +0 -0
  81. /package/dist/esm/{src/enums → enums}/chainId.js +0 -0
  82. /package/dist/esm/{src/enums → enums}/index.d.ts +0 -0
  83. /package/dist/esm/{src/enums → enums}/index.js +0 -0
  84. /package/dist/esm/{src/enums → enums}/proposalState.d.ts +0 -0
  85. /package/dist/esm/{src/enums → enums}/proposalState.js +0 -0
  86. /package/dist/esm/{src/governance.d.ts → governance.d.ts} +0 -0
  87. /package/dist/esm/{src/governance.js → governance.js} +0 -0
  88. /package/dist/esm/{src/index.d.ts → index.d.ts} +0 -0
  89. /package/dist/esm/{src/index.js → index.js} +0 -0
  90. /package/dist/esm/{src/interfaces → interfaces}/IChainClient.d.ts +0 -0
  91. /package/dist/esm/{src/interfaces → interfaces}/IChainClient.js +0 -0
  92. /package/dist/esm/{src/interfaces → interfaces}/index.d.ts +0 -0
  93. /package/dist/esm/{src/interfaces → interfaces}/index.js +0 -0
  94. /package/dist/esm/{src/interfaces → interfaces}/tradingLimit.d.ts +0 -0
  95. /package/dist/esm/{src/interfaces → interfaces}/tradingLimit.js +0 -0
  96. /package/dist/esm/{src/interfaces → interfaces}/tradingLimitsConfig.d.ts +0 -0
  97. /package/dist/esm/{src/interfaces → interfaces}/tradingLimitsConfig.js +0 -0
  98. /package/dist/esm/{src/interfaces → interfaces}/tradingLimitsState.d.ts +0 -0
  99. /package/dist/esm/{src/interfaces → interfaces}/tradingLimitsState.js +0 -0
  100. /package/dist/esm/{src/limits.d.ts → limits.d.ts} +0 -0
  101. /package/dist/esm/{src/limits.js → limits.js} +0 -0
  102. /package/dist/esm/{src/mento.d.ts → mento.d.ts} +0 -0
  103. /package/dist/esm/{src/mento.js → mento.js} +0 -0
  104. /package/dist/esm/{src/routeUtils.d.ts → routeUtils.d.ts} +0 -0
  105. /package/dist/esm/{src/routeUtils.js → routeUtils.js} +0 -0
  106. /package/dist/esm/{src/types → types}/contractAddressMap.d.ts +0 -0
  107. /package/dist/esm/{src/types → types}/contractAddressMap.js +0 -0
  108. /package/dist/esm/{src/types → types}/contractAddresses.d.ts +0 -0
  109. /package/dist/esm/{src/types → types}/contractAddresses.js +0 -0
  110. /package/dist/esm/{src/types → types}/index.d.ts +0 -0
  111. /package/dist/esm/{src/types → types}/index.js +0 -0
  112. /package/dist/esm/{src/utils.d.ts → utils.d.ts} +0 -0
  113. /package/dist/esm/{src/utils.js → utils.js} +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mento-protocol/mento-sdk",
3
3
  "description": "Official SDK for interacting with the Mento Protocol",
4
- "version": "1.10.0",
4
+ "version": "1.10.1",
5
5
  "license": "MIT",
6
6
  "author": "Mento Labs",
7
7
  "keywords": [
@@ -1,5 +0,0 @@
1
- import { TradablePairWithSpread } from '../../src/constants/tradablePairs';
2
- import { NETWORK_MAP, rpcUrls, SupportedChainId } from '../shared/network';
3
- export { NETWORK_MAP, rpcUrls };
4
- export { TradablePairWithSpread };
5
- export type { SupportedChainId };
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rpcUrls = exports.NETWORK_MAP = void 0;
4
- const network_1 = require("../shared/network");
5
- Object.defineProperty(exports, "NETWORK_MAP", { enumerable: true, get: function () { return network_1.NETWORK_MAP; } });
6
- Object.defineProperty(exports, "rpcUrls", { enumerable: true, get: function () { return network_1.rpcUrls; } });
@@ -1,20 +0,0 @@
1
- export declare const RPC_URLS: Record<number, string>;
2
- export declare const CHAIN_NAMES: Record<number, string>;
3
- export declare const CHAIN_NAME_TO_ID: Record<string, number>;
4
- export declare const DEFAULT_CHAIN_ID = 42220;
5
- export declare const DEFAULT_TIMEOUT_MS = 10000;
6
- export declare const QUOTE_TIMEOUT_MS = 8000;
7
- export declare const DEFAULT_BATCH_SIZE = 10;
8
- export declare const DEFAULT_BATCH_DELAY_MS = 100;
9
- export declare const DEFAULT_SPREAD_FALLBACK = 0.25;
10
- export declare const MAX_DECIMAL_PLACES = 4;
11
- export declare const TOKEN_ABI_FRAGMENT: readonly [{
12
- readonly name: "decimals";
13
- readonly type: "function";
14
- readonly inputs: readonly [];
15
- readonly outputs: readonly [{
16
- readonly type: "uint8";
17
- }];
18
- readonly stateMutability: "view";
19
- }];
20
- export declare const DEFAULT_DECIMALS = 18;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_DECIMALS = exports.TOKEN_ABI_FRAGMENT = exports.MAX_DECIMAL_PLACES = exports.DEFAULT_SPREAD_FALLBACK = exports.DEFAULT_BATCH_DELAY_MS = exports.DEFAULT_BATCH_SIZE = exports.QUOTE_TIMEOUT_MS = exports.DEFAULT_TIMEOUT_MS = exports.DEFAULT_CHAIN_ID = exports.CHAIN_NAME_TO_ID = exports.CHAIN_NAMES = exports.RPC_URLS = void 0;
4
- exports.RPC_URLS = {
5
- 42220: 'https://forno.celo.org',
6
- 44787: 'https://alfajores-forno.celo-testnet.org',
7
- };
8
- exports.CHAIN_NAMES = {
9
- 42220: 'Celo',
10
- 44787: 'Alfajores',
11
- };
12
- exports.CHAIN_NAME_TO_ID = {
13
- celo: 42220,
14
- alfajores: 44787,
15
- };
16
- exports.DEFAULT_CHAIN_ID = 42220;
17
- exports.DEFAULT_TIMEOUT_MS = 10000;
18
- exports.QUOTE_TIMEOUT_MS = 8000; // Timeout for individual quote calculations
19
- exports.DEFAULT_BATCH_SIZE = 10;
20
- exports.DEFAULT_BATCH_DELAY_MS = 100;
21
- exports.DEFAULT_SPREAD_FALLBACK = 0.25;
22
- exports.MAX_DECIMAL_PLACES = 4;
23
- // ERC20 token ABI fragment for decimals
24
- exports.TOKEN_ABI_FRAGMENT = [
25
- {
26
- name: 'decimals',
27
- type: 'function',
28
- inputs: [],
29
- outputs: [{ type: 'uint8' }],
30
- stateMutability: 'view',
31
- },
32
- ];
33
- exports.DEFAULT_DECIMALS = 18;
@@ -1,25 +0,0 @@
1
- import { TradablePair } from '../../src/mento';
2
- import { TradablePairWithSpread } from '../cacheTradablePairs/config';
3
- /**
4
- * Calculates the total spread for a trading route by compounding spreads across all hops.
5
- *
6
- * For multi-hop routes, spreads compound multiplicatively:
7
- * - Single hop: spread = pairSpread
8
- * - Multi-hop: spread = (1 - ((1 - spread1) * (1 - spread2) * ...))
9
- *
10
- * @param route - The route to calculate spread for
11
- * @param allPairs - All available pairs with spread data
12
- * @returns Total spread as a decimal (e.g., 0.005 = 0.5%)
13
- */
14
- export declare function calculateCompoundSpread(route: TradablePair, allPairs: readonly TradablePair[] | readonly TradablePairWithSpread[]): number;
15
- /**
16
- * Creates a human-readable display string for a trading route.
17
- * Shows token symbols and route structure (e.g., "USDC → cUSD → cEUR").
18
- *
19
- * @param tradablePair - The route to display
20
- * @param fromSymbol - Symbol of the input token
21
- * @param toSymbol - Symbol of the output token
22
- * @param allPairs - All pairs data for symbol resolution
23
- * @returns Formatted route string
24
- */
25
- export declare function buildRouteDisplay(tradablePair: TradablePair, fromSymbol: string, toSymbol: string, allPairs: readonly TradablePair[] | readonly TradablePairWithSpread[]): string;
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildRouteDisplay = exports.calculateCompoundSpread = void 0;
4
- const config_1 = require("./config");
5
- /**
6
- * Calculates the total spread for a trading route by compounding spreads across all hops.
7
- *
8
- * For multi-hop routes, spreads compound multiplicatively:
9
- * - Single hop: spread = pairSpread
10
- * - Multi-hop: spread = (1 - ((1 - spread1) * (1 - spread2) * ...))
11
- *
12
- * @param route - The route to calculate spread for
13
- * @param allPairs - All available pairs with spread data
14
- * @returns Total spread as a decimal (e.g., 0.005 = 0.5%)
15
- */
16
- function calculateCompoundSpread(route, allPairs) {
17
- if (route.path.length === 1) {
18
- return getFixedSpreadForRoute(route, allPairs);
19
- }
20
- // For multi-hop routes, calculate compound spread
21
- let compoundRate = 1; // Start with 100% (no loss)
22
- for (const hop of route.path) {
23
- const hopSpreadPercent = getHopSpreadPercent(hop, allPairs);
24
- // Convert spread percentage to rate multiplier
25
- // If spread is 0.25%, rate multiplier is 0.9975 (1 - 0.0025)
26
- const hopRate = 1 - hopSpreadPercent / 100;
27
- compoundRate *= hopRate;
28
- }
29
- // Convert back to spread percentage
30
- return (1 - compoundRate) * 100;
31
- }
32
- exports.calculateCompoundSpread = calculateCompoundSpread;
33
- /**
34
- * Creates a human-readable display string for a trading route.
35
- * Shows token symbols and route structure (e.g., "USDC → cUSD → cEUR").
36
- *
37
- * @param tradablePair - The route to display
38
- * @param fromSymbol - Symbol of the input token
39
- * @param toSymbol - Symbol of the output token
40
- * @param allPairs - All pairs data for symbol resolution
41
- * @returns Formatted route string
42
- */
43
- function buildRouteDisplay(tradablePair, fromSymbol, toSymbol, allPairs) {
44
- if (tradablePair.path.length === 1) {
45
- return `${fromSymbol} → ${toSymbol}`;
46
- }
47
- const routeSymbols = buildRouteSymbols(tradablePair, fromSymbol, toSymbol, allPairs);
48
- return routeSymbols.length < tradablePair.path.length + 1
49
- ? `${fromSymbol} → ${toSymbol} (${tradablePair.path.length} hops)`
50
- : routeSymbols.join(' → ');
51
- }
52
- exports.buildRouteDisplay = buildRouteDisplay;
53
- function getFixedSpreadForRoute(route, allPairs) {
54
- const matchingPair = findMatchingPair(route, allPairs);
55
- if (matchingPair && hasSpreadData(matchingPair)) {
56
- return matchingPair.spreadData
57
- .totalSpreadPercent;
58
- }
59
- return route.path.length * config_1.DEFAULT_SPREAD_FALLBACK;
60
- }
61
- function getHopSpreadPercent(hop, allPairs) {
62
- const directPair = allPairs.find((pair) => pair.path.length === 1 &&
63
- // @ts-ignore - hop structure is known
64
- pair.path[0].id === hop.id &&
65
- // @ts-ignore - hop structure is known
66
- pair.path[0].providerAddr === hop.providerAddr);
67
- if (directPair && hasSpreadData(directPair)) {
68
- return directPair.spreadData
69
- .totalSpreadPercent;
70
- }
71
- return config_1.DEFAULT_SPREAD_FALLBACK;
72
- }
73
- function findMatchingPair(route, allPairs) {
74
- return allPairs.find((pair) => {
75
- if (pair.path.length !== route.path.length)
76
- return false;
77
- return route.path.every((hop, index) => {
78
- const pairHop = pair.path[index];
79
- return (hop.id === pairHop.id &&
80
- hop.providerAddr === pairHop.providerAddr &&
81
- hop.assets[0] === pairHop.assets[0] &&
82
- hop.assets[1] === pairHop.assets[1]);
83
- });
84
- });
85
- }
86
- function hasSpreadData(pair) {
87
- return ('spreadData' in pair &&
88
- pair.spreadData &&
89
- typeof pair.spreadData === 'object' &&
90
- 'totalSpreadPercent' in pair.spreadData);
91
- }
92
- function buildRouteSymbols(tradablePair, fromSymbol, toSymbol, allPairs) {
93
- var _a, _b;
94
- const addressToSymbol = createAddressToSymbolMap(allPairs);
95
- // Handle special case where user input might be different from actual symbol
96
- // For example, user inputs "USDT" but actual symbol is "USD₮"
97
- const actualFromSymbol = findActualSymbolForInput(fromSymbol, tradablePair.assets);
98
- const actualToSymbol = findActualSymbolForInput(toSymbol, tradablePair.assets);
99
- // Get the addresses from tradablePair.assets using actual symbols
100
- const fromAddress = (_a = tradablePair.assets
101
- .find((asset) => asset.symbol === actualFromSymbol)) === null || _a === void 0 ? void 0 : _a.address.toLowerCase();
102
- const toAddress = (_b = tradablePair.assets
103
- .find((asset) => asset.symbol === actualToSymbol)) === null || _b === void 0 ? void 0 : _b.address.toLowerCase();
104
- if (!fromAddress || !toAddress) {
105
- return [fromSymbol, toSymbol];
106
- }
107
- // For multi-hop routes, we need to find the common intermediate tokens
108
- // First, collect all unique addresses in the path
109
- const allAddresses = new Set();
110
- tradablePair.path.forEach((hop) => {
111
- hop.assets.forEach((addr) => {
112
- allAddresses.add(addr.toLowerCase());
113
- });
114
- });
115
- // Remove our from and to addresses to find intermediates
116
- allAddresses.delete(fromAddress);
117
- allAddresses.delete(toAddress);
118
- // Convert intermediate addresses to symbols
119
- const intermediateTokens = Array.from(allAddresses)
120
- .map((addr) => addressToSymbol.get(addr))
121
- .filter((symbol) => symbol !== undefined);
122
- // Build the route: from -> intermediates -> to
123
- const route = [fromSymbol];
124
- // Add intermediate tokens
125
- intermediateTokens.forEach((token) => {
126
- if (!route.includes(token)) {
127
- route.push(token);
128
- }
129
- });
130
- // Add destination
131
- route.push(toSymbol);
132
- return route;
133
- }
134
- /**
135
- * Finds the actual symbol in the tradable pair assets for a given input symbol.
136
- * Handles special cases like "USDT" mapping to "USD₮".
137
- */
138
- function findActualSymbolForInput(inputSymbol, assets) {
139
- // First try exact match
140
- const exactMatch = assets.find((asset) => asset.symbol === inputSymbol);
141
- if (exactMatch) {
142
- return inputSymbol;
143
- }
144
- // Handle USDT special case
145
- if (inputSymbol.toLowerCase() === 'usdt') {
146
- // Look for USD₮ or other USDT variants
147
- const usdtVariant = assets.find((asset) => {
148
- const normalizedSymbol = asset.symbol.replace(/[^\w]/g, '').toLowerCase();
149
- return normalizedSymbol === 'usdt' || asset.symbol === 'USD₮';
150
- });
151
- if (usdtVariant) {
152
- return usdtVariant.symbol;
153
- }
154
- }
155
- // Fallback to original input
156
- return inputSymbol;
157
- }
158
- function createAddressToSymbolMap(allPairs) {
159
- const addressToSymbol = new Map();
160
- allPairs.forEach((pair) => {
161
- pair.assets.forEach((asset) => {
162
- addressToSymbol.set(asset.address.toLowerCase(), asset.symbol);
163
- });
164
- });
165
- return addressToSymbol;
166
- }
@@ -1,23 +0,0 @@
1
- export declare const NETWORK_MAP: Record<string, number>;
2
- export declare const rpcUrls: {
3
- readonly 42220: "https://forno.celo.org";
4
- readonly 44787: "https://alfajores-forno.celo-testnet.org";
5
- };
6
- export type SupportedChainId = keyof typeof rpcUrls;
7
- export interface NetworkConfig {
8
- chainId: number;
9
- rpcUrl: string;
10
- }
11
- /**
12
- * Parse network arguments and return network configuration
13
- * @param networkArg - The network name argument (e.g., 'celo', 'alfajores')
14
- * @param chainIdArg - The chainId argument (e.g., '42220', '44787')
15
- * @returns NetworkConfig with chainId and rpcUrl
16
- */
17
- export declare function parseNetworkArgs(networkArg?: string, chainIdArg?: string): NetworkConfig;
18
- /**
19
- * Get the network name from chainId
20
- * @param chainId - The chain ID
21
- * @returns The network name or 'Unknown' if not found
22
- */
23
- export declare function getNetworkName(chainId: number): string;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNetworkName = exports.parseNetworkArgs = exports.rpcUrls = exports.NETWORK_MAP = void 0;
4
- // Network name to chainId mapping
5
- exports.NETWORK_MAP = {
6
- celo: 42220,
7
- alfajores: 44787,
8
- };
9
- // RPC URLs for different networks
10
- exports.rpcUrls = {
11
- 42220: 'https://forno.celo.org',
12
- 44787: 'https://alfajores-forno.celo-testnet.org',
13
- };
14
- /**
15
- * Parse network arguments and return network configuration
16
- * @param networkArg - The network name argument (e.g., 'celo', 'alfajores')
17
- * @param chainIdArg - The chainId argument (e.g., '42220', '44787')
18
- * @returns NetworkConfig with chainId and rpcUrl
19
- */
20
- function parseNetworkArgs(networkArg, chainIdArg) {
21
- let chainId;
22
- let rpcUrl;
23
- if (networkArg) {
24
- const networkName = networkArg.toLowerCase();
25
- if (!exports.NETWORK_MAP[networkName]) {
26
- console.error(`❌ Invalid network "${networkArg}". Valid networks: ${Object.keys(exports.NETWORK_MAP).join(', ')}`);
27
- process.exit(1);
28
- }
29
- chainId = exports.NETWORK_MAP[networkName];
30
- rpcUrl = exports.rpcUrls[chainId];
31
- }
32
- else if (chainIdArg) {
33
- chainId = Number(chainIdArg);
34
- if (!exports.rpcUrls[chainId]) {
35
- console.error(`❌ Invalid chainId "${chainId}". Valid chainIds: ${Object.keys(exports.rpcUrls).join(', ')}`);
36
- process.exit(1);
37
- }
38
- rpcUrl = exports.rpcUrls[chainId];
39
- }
40
- else {
41
- // Default to Celo mainnet if no network specified
42
- chainId = 42220;
43
- rpcUrl = exports.rpcUrls[42220];
44
- }
45
- return { chainId, rpcUrl };
46
- }
47
- exports.parseNetworkArgs = parseNetworkArgs;
48
- /**
49
- * Get the network name from chainId
50
- * @param chainId - The chain ID
51
- * @returns The network name or 'Unknown' if not found
52
- */
53
- function getNetworkName(chainId) {
54
- const networkEntry = Object.entries(exports.NETWORK_MAP).find(([, id]) => id === chainId);
55
- return networkEntry ? networkEntry[0] : 'Unknown';
56
- }
57
- exports.getNetworkName = getNetworkName;
@@ -1,5 +0,0 @@
1
- import { TradablePairWithSpread } from '../../src/constants/tradablePairs';
2
- import { NETWORK_MAP, rpcUrls, SupportedChainId } from '../shared/network';
3
- export { NETWORK_MAP, rpcUrls };
4
- export { TradablePairWithSpread };
5
- export type { SupportedChainId };
@@ -1,3 +0,0 @@
1
- import { NETWORK_MAP, rpcUrls } from '../shared/network';
2
- // Re-export network constants for backward compatibility
3
- export { NETWORK_MAP, rpcUrls };
@@ -1,20 +0,0 @@
1
- export declare const RPC_URLS: Record<number, string>;
2
- export declare const CHAIN_NAMES: Record<number, string>;
3
- export declare const CHAIN_NAME_TO_ID: Record<string, number>;
4
- export declare const DEFAULT_CHAIN_ID = 42220;
5
- export declare const DEFAULT_TIMEOUT_MS = 10000;
6
- export declare const QUOTE_TIMEOUT_MS = 8000;
7
- export declare const DEFAULT_BATCH_SIZE = 10;
8
- export declare const DEFAULT_BATCH_DELAY_MS = 100;
9
- export declare const DEFAULT_SPREAD_FALLBACK = 0.25;
10
- export declare const MAX_DECIMAL_PLACES = 4;
11
- export declare const TOKEN_ABI_FRAGMENT: readonly [{
12
- readonly name: "decimals";
13
- readonly type: "function";
14
- readonly inputs: readonly [];
15
- readonly outputs: readonly [{
16
- readonly type: "uint8";
17
- }];
18
- readonly stateMutability: "view";
19
- }];
20
- export declare const DEFAULT_DECIMALS = 18;
@@ -1,30 +0,0 @@
1
- export const RPC_URLS = {
2
- 42220: 'https://forno.celo.org',
3
- 44787: 'https://alfajores-forno.celo-testnet.org',
4
- };
5
- export const CHAIN_NAMES = {
6
- 42220: 'Celo',
7
- 44787: 'Alfajores',
8
- };
9
- export const CHAIN_NAME_TO_ID = {
10
- celo: 42220,
11
- alfajores: 44787,
12
- };
13
- export const DEFAULT_CHAIN_ID = 42220;
14
- export const DEFAULT_TIMEOUT_MS = 10000;
15
- export const QUOTE_TIMEOUT_MS = 8000; // Timeout for individual quote calculations
16
- export const DEFAULT_BATCH_SIZE = 10;
17
- export const DEFAULT_BATCH_DELAY_MS = 100;
18
- export const DEFAULT_SPREAD_FALLBACK = 0.25;
19
- export const MAX_DECIMAL_PLACES = 4;
20
- // ERC20 token ABI fragment for decimals
21
- export const TOKEN_ABI_FRAGMENT = [
22
- {
23
- name: 'decimals',
24
- type: 'function',
25
- inputs: [],
26
- outputs: [{ type: 'uint8' }],
27
- stateMutability: 'view',
28
- },
29
- ];
30
- export const DEFAULT_DECIMALS = 18;
@@ -1,25 +0,0 @@
1
- import { TradablePair } from '../../src/mento';
2
- import { TradablePairWithSpread } from '../cacheTradablePairs/config';
3
- /**
4
- * Calculates the total spread for a trading route by compounding spreads across all hops.
5
- *
6
- * For multi-hop routes, spreads compound multiplicatively:
7
- * - Single hop: spread = pairSpread
8
- * - Multi-hop: spread = (1 - ((1 - spread1) * (1 - spread2) * ...))
9
- *
10
- * @param route - The route to calculate spread for
11
- * @param allPairs - All available pairs with spread data
12
- * @returns Total spread as a decimal (e.g., 0.005 = 0.5%)
13
- */
14
- export declare function calculateCompoundSpread(route: TradablePair, allPairs: readonly TradablePair[] | readonly TradablePairWithSpread[]): number;
15
- /**
16
- * Creates a human-readable display string for a trading route.
17
- * Shows token symbols and route structure (e.g., "USDC → cUSD → cEUR").
18
- *
19
- * @param tradablePair - The route to display
20
- * @param fromSymbol - Symbol of the input token
21
- * @param toSymbol - Symbol of the output token
22
- * @param allPairs - All pairs data for symbol resolution
23
- * @returns Formatted route string
24
- */
25
- export declare function buildRouteDisplay(tradablePair: TradablePair, fromSymbol: string, toSymbol: string, allPairs: readonly TradablePair[] | readonly TradablePairWithSpread[]): string;
@@ -1,161 +0,0 @@
1
- import { DEFAULT_SPREAD_FALLBACK } from './config';
2
- /**
3
- * Calculates the total spread for a trading route by compounding spreads across all hops.
4
- *
5
- * For multi-hop routes, spreads compound multiplicatively:
6
- * - Single hop: spread = pairSpread
7
- * - Multi-hop: spread = (1 - ((1 - spread1) * (1 - spread2) * ...))
8
- *
9
- * @param route - The route to calculate spread for
10
- * @param allPairs - All available pairs with spread data
11
- * @returns Total spread as a decimal (e.g., 0.005 = 0.5%)
12
- */
13
- export function calculateCompoundSpread(route, allPairs) {
14
- if (route.path.length === 1) {
15
- return getFixedSpreadForRoute(route, allPairs);
16
- }
17
- // For multi-hop routes, calculate compound spread
18
- let compoundRate = 1; // Start with 100% (no loss)
19
- for (const hop of route.path) {
20
- const hopSpreadPercent = getHopSpreadPercent(hop, allPairs);
21
- // Convert spread percentage to rate multiplier
22
- // If spread is 0.25%, rate multiplier is 0.9975 (1 - 0.0025)
23
- const hopRate = 1 - hopSpreadPercent / 100;
24
- compoundRate *= hopRate;
25
- }
26
- // Convert back to spread percentage
27
- return (1 - compoundRate) * 100;
28
- }
29
- /**
30
- * Creates a human-readable display string for a trading route.
31
- * Shows token symbols and route structure (e.g., "USDC → cUSD → cEUR").
32
- *
33
- * @param tradablePair - The route to display
34
- * @param fromSymbol - Symbol of the input token
35
- * @param toSymbol - Symbol of the output token
36
- * @param allPairs - All pairs data for symbol resolution
37
- * @returns Formatted route string
38
- */
39
- export function buildRouteDisplay(tradablePair, fromSymbol, toSymbol, allPairs) {
40
- if (tradablePair.path.length === 1) {
41
- return `${fromSymbol} → ${toSymbol}`;
42
- }
43
- const routeSymbols = buildRouteSymbols(tradablePair, fromSymbol, toSymbol, allPairs);
44
- return routeSymbols.length < tradablePair.path.length + 1
45
- ? `${fromSymbol} → ${toSymbol} (${tradablePair.path.length} hops)`
46
- : routeSymbols.join(' → ');
47
- }
48
- function getFixedSpreadForRoute(route, allPairs) {
49
- const matchingPair = findMatchingPair(route, allPairs);
50
- if (matchingPair && hasSpreadData(matchingPair)) {
51
- return matchingPair.spreadData
52
- .totalSpreadPercent;
53
- }
54
- return route.path.length * DEFAULT_SPREAD_FALLBACK;
55
- }
56
- function getHopSpreadPercent(hop, allPairs) {
57
- const directPair = allPairs.find((pair) => pair.path.length === 1 &&
58
- // @ts-ignore - hop structure is known
59
- pair.path[0].id === hop.id &&
60
- // @ts-ignore - hop structure is known
61
- pair.path[0].providerAddr === hop.providerAddr);
62
- if (directPair && hasSpreadData(directPair)) {
63
- return directPair.spreadData
64
- .totalSpreadPercent;
65
- }
66
- return DEFAULT_SPREAD_FALLBACK;
67
- }
68
- function findMatchingPair(route, allPairs) {
69
- return allPairs.find((pair) => {
70
- if (pair.path.length !== route.path.length)
71
- return false;
72
- return route.path.every((hop, index) => {
73
- const pairHop = pair.path[index];
74
- return (hop.id === pairHop.id &&
75
- hop.providerAddr === pairHop.providerAddr &&
76
- hop.assets[0] === pairHop.assets[0] &&
77
- hop.assets[1] === pairHop.assets[1]);
78
- });
79
- });
80
- }
81
- function hasSpreadData(pair) {
82
- return ('spreadData' in pair &&
83
- pair.spreadData &&
84
- typeof pair.spreadData === 'object' &&
85
- 'totalSpreadPercent' in pair.spreadData);
86
- }
87
- function buildRouteSymbols(tradablePair, fromSymbol, toSymbol, allPairs) {
88
- var _a, _b;
89
- const addressToSymbol = createAddressToSymbolMap(allPairs);
90
- // Handle special case where user input might be different from actual symbol
91
- // For example, user inputs "USDT" but actual symbol is "USD₮"
92
- const actualFromSymbol = findActualSymbolForInput(fromSymbol, tradablePair.assets);
93
- const actualToSymbol = findActualSymbolForInput(toSymbol, tradablePair.assets);
94
- // Get the addresses from tradablePair.assets using actual symbols
95
- const fromAddress = (_a = tradablePair.assets
96
- .find((asset) => asset.symbol === actualFromSymbol)) === null || _a === void 0 ? void 0 : _a.address.toLowerCase();
97
- const toAddress = (_b = tradablePair.assets
98
- .find((asset) => asset.symbol === actualToSymbol)) === null || _b === void 0 ? void 0 : _b.address.toLowerCase();
99
- if (!fromAddress || !toAddress) {
100
- return [fromSymbol, toSymbol];
101
- }
102
- // For multi-hop routes, we need to find the common intermediate tokens
103
- // First, collect all unique addresses in the path
104
- const allAddresses = new Set();
105
- tradablePair.path.forEach((hop) => {
106
- hop.assets.forEach((addr) => {
107
- allAddresses.add(addr.toLowerCase());
108
- });
109
- });
110
- // Remove our from and to addresses to find intermediates
111
- allAddresses.delete(fromAddress);
112
- allAddresses.delete(toAddress);
113
- // Convert intermediate addresses to symbols
114
- const intermediateTokens = Array.from(allAddresses)
115
- .map((addr) => addressToSymbol.get(addr))
116
- .filter((symbol) => symbol !== undefined);
117
- // Build the route: from -> intermediates -> to
118
- const route = [fromSymbol];
119
- // Add intermediate tokens
120
- intermediateTokens.forEach((token) => {
121
- if (!route.includes(token)) {
122
- route.push(token);
123
- }
124
- });
125
- // Add destination
126
- route.push(toSymbol);
127
- return route;
128
- }
129
- /**
130
- * Finds the actual symbol in the tradable pair assets for a given input symbol.
131
- * Handles special cases like "USDT" mapping to "USD₮".
132
- */
133
- function findActualSymbolForInput(inputSymbol, assets) {
134
- // First try exact match
135
- const exactMatch = assets.find((asset) => asset.symbol === inputSymbol);
136
- if (exactMatch) {
137
- return inputSymbol;
138
- }
139
- // Handle USDT special case
140
- if (inputSymbol.toLowerCase() === 'usdt') {
141
- // Look for USD₮ or other USDT variants
142
- const usdtVariant = assets.find((asset) => {
143
- const normalizedSymbol = asset.symbol.replace(/[^\w]/g, '').toLowerCase();
144
- return normalizedSymbol === 'usdt' || asset.symbol === 'USD₮';
145
- });
146
- if (usdtVariant) {
147
- return usdtVariant.symbol;
148
- }
149
- }
150
- // Fallback to original input
151
- return inputSymbol;
152
- }
153
- function createAddressToSymbolMap(allPairs) {
154
- const addressToSymbol = new Map();
155
- allPairs.forEach((pair) => {
156
- pair.assets.forEach((asset) => {
157
- addressToSymbol.set(asset.address.toLowerCase(), asset.symbol);
158
- });
159
- });
160
- return addressToSymbol;
161
- }
@@ -1,23 +0,0 @@
1
- export declare const NETWORK_MAP: Record<string, number>;
2
- export declare const rpcUrls: {
3
- readonly 42220: "https://forno.celo.org";
4
- readonly 44787: "https://alfajores-forno.celo-testnet.org";
5
- };
6
- export type SupportedChainId = keyof typeof rpcUrls;
7
- export interface NetworkConfig {
8
- chainId: number;
9
- rpcUrl: string;
10
- }
11
- /**
12
- * Parse network arguments and return network configuration
13
- * @param networkArg - The network name argument (e.g., 'celo', 'alfajores')
14
- * @param chainIdArg - The chainId argument (e.g., '42220', '44787')
15
- * @returns NetworkConfig with chainId and rpcUrl
16
- */
17
- export declare function parseNetworkArgs(networkArg?: string, chainIdArg?: string): NetworkConfig;
18
- /**
19
- * Get the network name from chainId
20
- * @param chainId - The chain ID
21
- * @returns The network name or 'Unknown' if not found
22
- */
23
- export declare function getNetworkName(chainId: number): string;
@@ -1,52 +0,0 @@
1
- // Network name to chainId mapping
2
- export const NETWORK_MAP = {
3
- celo: 42220,
4
- alfajores: 44787,
5
- };
6
- // RPC URLs for different networks
7
- export const rpcUrls = {
8
- 42220: 'https://forno.celo.org',
9
- 44787: 'https://alfajores-forno.celo-testnet.org',
10
- };
11
- /**
12
- * Parse network arguments and return network configuration
13
- * @param networkArg - The network name argument (e.g., 'celo', 'alfajores')
14
- * @param chainIdArg - The chainId argument (e.g., '42220', '44787')
15
- * @returns NetworkConfig with chainId and rpcUrl
16
- */
17
- export function parseNetworkArgs(networkArg, chainIdArg) {
18
- let chainId;
19
- let rpcUrl;
20
- if (networkArg) {
21
- const networkName = networkArg.toLowerCase();
22
- if (!NETWORK_MAP[networkName]) {
23
- console.error(`❌ Invalid network "${networkArg}". Valid networks: ${Object.keys(NETWORK_MAP).join(', ')}`);
24
- process.exit(1);
25
- }
26
- chainId = NETWORK_MAP[networkName];
27
- rpcUrl = rpcUrls[chainId];
28
- }
29
- else if (chainIdArg) {
30
- chainId = Number(chainIdArg);
31
- if (!rpcUrls[chainId]) {
32
- console.error(`❌ Invalid chainId "${chainId}". Valid chainIds: ${Object.keys(rpcUrls).join(', ')}`);
33
- process.exit(1);
34
- }
35
- rpcUrl = rpcUrls[chainId];
36
- }
37
- else {
38
- // Default to Celo mainnet if no network specified
39
- chainId = 42220;
40
- rpcUrl = rpcUrls[42220];
41
- }
42
- return { chainId, rpcUrl };
43
- }
44
- /**
45
- * Get the network name from chainId
46
- * @param chainId - The chain ID
47
- * @returns The network name or 'Unknown' if not found
48
- */
49
- export function getNetworkName(chainId) {
50
- const networkEntry = Object.entries(NETWORK_MAP).find(([, id]) => id === chainId);
51
- return networkEntry ? networkEntry[0] : 'Unknown';
52
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes