@mento-protocol/mento-sdk 3.0.0-beta.6 → 3.0.0-beta.7
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 +34 -0
- package/dist/cache/routes.d.ts.map +1 -1
- package/dist/cache/routes.js +2 -4
- package/dist/cache/routes.js.map +1 -1
- package/dist/core/abis/erc20.d.ts +7 -0
- package/dist/core/abis/erc20.d.ts.map +1 -1
- package/dist/core/abis/erc20.js +7 -0
- package/dist/core/abis/erc20.js.map +1 -1
- package/dist/core/constants/aaveConfig.js +2 -2
- package/dist/core/constants/addresses.d.ts.map +1 -1
- package/dist/core/constants/addresses.js +3 -1
- package/dist/core/constants/addresses.js.map +1 -1
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/core/types/provider.d.ts.map +1 -0
- package/dist/core/types/provider.js +3 -0
- package/dist/core/types/provider.js.map +1 -0
- package/dist/core/types/route.d.ts +3 -3
- package/dist/core/types/route.d.ts.map +1 -1
- package/dist/core/types/token.d.ts +13 -3
- package/dist/core/types/token.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/services/pools/PoolService.d.ts +1 -1
- package/dist/services/pools/PoolService.d.ts.map +1 -1
- package/dist/services/pools/PoolService.js +17 -11
- package/dist/services/pools/PoolService.js.map +1 -1
- package/dist/services/quotes/QuoteService.d.ts +21 -12
- package/dist/services/quotes/QuoteService.d.ts.map +1 -1
- package/dist/services/quotes/QuoteService.js +23 -11
- package/dist/services/quotes/QuoteService.js.map +1 -1
- package/dist/services/routes/RouteService.d.ts +3 -3
- package/dist/services/routes/RouteService.d.ts.map +1 -1
- package/dist/services/routes/RouteService.js +3 -5
- package/dist/services/routes/RouteService.js.map +1 -1
- package/dist/services/swap/SwapService.d.ts +18 -14
- package/dist/services/swap/SwapService.d.ts.map +1 -1
- package/dist/services/swap/SwapService.js +31 -14
- package/dist/services/swap/SwapService.js.map +1 -1
- package/dist/services/tokens/supplyAdjustmentService.d.ts +0 -4
- package/dist/services/tokens/supplyAdjustmentService.d.ts.map +1 -1
- package/dist/services/tokens/supplyAdjustmentService.js +3 -8
- package/dist/services/tokens/supplyAdjustmentService.js.map +1 -1
- package/dist/services/tokens/tokenService.d.ts.map +1 -1
- package/dist/services/tokens/tokenService.js +2 -2
- package/dist/services/tokens/tokenService.js.map +1 -1
- package/dist/services/trading/TradingService.d.ts +1 -1
- package/dist/services/trading/TradingService.js +1 -1
- package/dist/utils/costUtils.js +4 -4
- package/dist/utils/costUtils.js.map +1 -1
- package/dist/utils/pathEncoder.d.ts +3 -2
- package/dist/utils/pathEncoder.d.ts.map +1 -1
- package/dist/utils/pathEncoder.js +19 -3
- package/dist/utils/pathEncoder.js.map +1 -1
- package/dist/utils/routeUtils.d.ts +53 -53
- package/dist/utils/routeUtils.d.ts.map +1 -1
- package/dist/utils/routeUtils.js +41 -41
- package/dist/utils/routeUtils.js.map +1 -1
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +34 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,40 @@ pnpm build
|
|
|
84
84
|
pnpm test
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
#### Cache Generation Scripts
|
|
88
|
+
|
|
89
|
+
The SDK includes scripts to generate and update cached route and token data:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Generate route cache
|
|
93
|
+
pnpm cacheRoutes
|
|
94
|
+
|
|
95
|
+
# Generate token cache
|
|
96
|
+
pnpm cacheTokens
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Environment Variables:**
|
|
100
|
+
|
|
101
|
+
You can override the default RPC URLs used by cache generation scripts:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Use custom RPC for Celo mainnet
|
|
105
|
+
export CELO_RPC_URL=https://your-custom-rpc.example.com
|
|
106
|
+
pnpm cacheRoutes
|
|
107
|
+
|
|
108
|
+
# Use custom RPC for Celo Sepolia testnet
|
|
109
|
+
export CELO_SEPOLIA_RPC_URL=https://your-sepolia-rpc.example.com
|
|
110
|
+
pnpm cacheRoutes
|
|
111
|
+
|
|
112
|
+
# Or set both
|
|
113
|
+
CELO_RPC_URL=https://your-rpc.com CELO_SEPOLIA_RPC_URL=https://your-sepolia.com pnpm cacheRoutes
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
By default, scripts use the public Forno RPC endpoints:
|
|
117
|
+
|
|
118
|
+
- Celo mainnet: `https://forno.celo.org`
|
|
119
|
+
- Celo Sepolia: `https://forno.celo-sepolia.celo-testnet.org`
|
|
120
|
+
|
|
87
121
|
### Project Structure
|
|
88
122
|
|
|
89
123
|
```bash
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/cache/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/cache/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,CA8GxD,CAAA;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CAEhE"}
|
package/dist/cache/routes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is auto-generated. Do not edit manually.
|
|
3
|
-
// Generated on
|
|
3
|
+
// Generated on 2026-01-21T20:27:37.682Z
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.cachedRoutes = void 0;
|
|
6
6
|
exports.getCachedRoutes = getCachedRoutes;
|
|
@@ -104,7 +104,7 @@ exports.cachedRoutes = {
|
|
|
104
104
|
}
|
|
105
105
|
],
|
|
106
106
|
"costData": {
|
|
107
|
-
"totalCostPercent": 1.
|
|
107
|
+
"totalCostPercent": 1.297,
|
|
108
108
|
"hops": [
|
|
109
109
|
{
|
|
110
110
|
"poolAddress": "0x5c3919258a040D203260880401E3201a82d224c4",
|
|
@@ -118,8 +118,6 @@ exports.cachedRoutes = {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
],
|
|
121
|
-
// Chain 11142220
|
|
122
|
-
11142220: [],
|
|
123
121
|
};
|
|
124
122
|
/**
|
|
125
123
|
* Get cached routes for a specific chain
|
package/dist/cache/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/cache/routes.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,wCAAwC;;;
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/cache/routes.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,wCAAwC;;;AA6HxC,0CAEC;AA3HD;;;GAGG;AACU,QAAA,YAAY,GAAoC;IAC3D,cAAc;IACd,KAAK,EAAE;QACL;YACE,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE;gBACR;oBACE,SAAS,EAAE,4CAA4C;oBACvD,QAAQ,EAAE,MAAM;iBACjB;gBACD;oBACE,SAAS,EAAE,4CAA4C;oBACvD,QAAQ,EAAE,MAAM;iBACjB;aACF;YACD,MAAM,EAAE;gBACN;oBACE,aAAa,EAAE,4CAA4C;oBAC3D,UAAU,EAAE,4CAA4C;oBACxD,QAAQ,EAAE,4CAA4C;oBACtD,QAAQ,EAAE,4CAA4C;oBACtD,UAAU,EAAE,MAAM;iBACnB;aACF;YACD,UAAU,EAAE;gBACV,kBA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B,MAAM,EAAE;oBACN;wBACE,aAAa,EAAE,4CAA4C;wBAC3D,aAAa,EAAE,GAAG;qBACnB;oBACD;wBACE,aAAa,EAAE,4CAA4C;wBAC3D,aAAa,EAAE,CAAC;qBACjB;iBACF;aACF;SACF;KACF;CACF,CAAA;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,OAAe;IAC7C,OAAO,oBAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;AACpC,CAAC"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ERC20 ABI for standard token operations
|
|
3
|
+
*
|
|
4
|
+
* Note: `as any` is used because viem's parseAbi returns a complex readonly tuple type
|
|
5
|
+
* that can cause type verbosity. This doesn't compromise type safety - viem's
|
|
6
|
+
* readContract/writeContract still infer types correctly from the ABI at usage sites.
|
|
7
|
+
*/
|
|
1
8
|
export declare const ERC20_ABI: any;
|
|
2
9
|
//# sourceMappingURL=erc20.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erc20.d.ts","sourceRoot":"","sources":["../../../src/core/abis/erc20.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,EAQhB,GAAG,CAAA"}
|
|
1
|
+
{"version":3,"file":"erc20.d.ts","sourceRoot":"","sources":["../../../src/core/abis/erc20.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAQhB,GAAG,CAAA"}
|
package/dist/core/abis/erc20.js
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ERC20_ABI = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* ERC20 ABI for standard token operations
|
|
7
|
+
*
|
|
8
|
+
* Note: `as any` is used because viem's parseAbi returns a complex readonly tuple type
|
|
9
|
+
* that can cause type verbosity. This doesn't compromise type safety - viem's
|
|
10
|
+
* readContract/writeContract still infer types correctly from the ABI at usage sites.
|
|
11
|
+
*/
|
|
5
12
|
exports.ERC20_ABI = (0, viem_1.parseAbi)([
|
|
6
13
|
'function name() view returns (string)',
|
|
7
14
|
'function symbol() view returns (string)',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erc20.js","sourceRoot":"","sources":["../../../src/core/abis/erc20.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;
|
|
1
|
+
{"version":3,"file":"erc20.js","sourceRoot":"","sources":["../../../src/core/abis/erc20.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAE/B;;;;;;GAMG;AACU,QAAA,SAAS,GAAG,IAAA,eAAQ,EAAC;IAChC,uCAAuC;IACvC,yCAAyC;IACzC,0CAA0C;IAC1C,+CAA+C;IAC/C,oDAAoD;IACpD,kEAAkE;IAClE,2EAA2E;CAC5E,CAAQ,CAAA"}
|
|
@@ -9,9 +9,9 @@ const chainId_1 = require("./chainId");
|
|
|
9
9
|
*/
|
|
10
10
|
exports.AAVE_TOKEN_MAPPINGS = {
|
|
11
11
|
[chainId_1.ChainId.CELO]: {
|
|
12
|
-
//
|
|
12
|
+
// USDm -> aCelcUSD
|
|
13
13
|
'0x765DE816845861e75A25fCA122bb6898B8B1282a': '0xBba98352628B0B0c4b40583F593fFCb630935a45',
|
|
14
|
-
//
|
|
14
|
+
// EURm -> aCelcEUR
|
|
15
15
|
'0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73': '0x34c02571094e08E935B8cf8dC10F1Ad6795f1f81',
|
|
16
16
|
// USDT -> aCelUSDT
|
|
17
17
|
'0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e': '0xDeE98402A302e4D707fB9bf2bac66fAEEc31e8Df',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../../src/core/constants/addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAEhE,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../../src/core/constants/addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAEhE,eAAO,MAAM,SAAS,EAAE,kBAyDvB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAA;AAEhD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,UAAU,GACvB,MAAM,CAcR"}
|
|
@@ -17,8 +17,10 @@ exports.addresses = {
|
|
|
17
17
|
ConstantSumPricingModule: '0xDebED1F6f6ce9F6e73AA25F95acBFFE2397550Fb',
|
|
18
18
|
MentoRouter: '0xbe729350f8cdfc19db6866e8579841188ee57f67',
|
|
19
19
|
Reserve: '0x9380fA34Fd9e4Fd14c06305fd7B6199089eD4eb9',
|
|
20
|
+
// TODO: Find and remove references to this. This should be replaced
|
|
21
|
+
// with the token cache
|
|
20
22
|
// Stable Tokens
|
|
21
|
-
StableToken: '0x765DE816845861e75A25fCA122bb6898B8B1282a', //
|
|
23
|
+
StableToken: '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
22
24
|
// Governance
|
|
23
25
|
Airgrab: '0x7D8E73deafDBAfc98fDBe7974168cFA6d8B9AE0C',
|
|
24
26
|
Emission: '0x5C789592E2611df1873b46D394c69f75faB99778',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../../src/core/constants/addresses.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../../src/core/constants/addresses.ts"],"names":[],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AA4C;QACxD,kBAAkB,EAAE,4CAA4C;KACjE;CACF,CAAA;AAID;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,OAAgB,EAChB,YAAwB;IAExB,MAAM,iBAAiB,GAAG,iBAAS,CAAC,OAAO,CAAC,CAAA;IAC5C,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAA;IAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,kCAAkC,YAAY,gBAAgB,OAAO,EAAE,CACxE,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface ContractCallOptions {
|
|
2
|
+
address: string;
|
|
3
|
+
abi: string[] | unknown[];
|
|
4
|
+
functionName: string;
|
|
5
|
+
args?: unknown[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Contract write options for building call parameters
|
|
9
|
+
*
|
|
10
|
+
* Configuration for building transaction call parameters for write operations.
|
|
11
|
+
* These parameters can be used by consumers to execute transactions themselves.
|
|
12
|
+
*/
|
|
13
|
+
export interface ContractWriteOptions extends ContractCallOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Optional gas limit override
|
|
16
|
+
* If not provided, will be estimated automatically
|
|
17
|
+
*/
|
|
18
|
+
gasLimit?: bigint;
|
|
19
|
+
/**
|
|
20
|
+
* Transaction value in wei
|
|
21
|
+
* For payable functions only
|
|
22
|
+
*/
|
|
23
|
+
value?: bigint;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Call parameters for executing a contract transaction
|
|
27
|
+
*
|
|
28
|
+
* Contains all the data needed to execute a contract call.
|
|
29
|
+
* Consumers can use these parameters with their own wallet/signer to execute transactions.
|
|
30
|
+
*/
|
|
31
|
+
export interface CallParams {
|
|
32
|
+
/**
|
|
33
|
+
* Contract address to call
|
|
34
|
+
*/
|
|
35
|
+
to: string;
|
|
36
|
+
/**
|
|
37
|
+
* Encoded function call data (hex string)
|
|
38
|
+
*/
|
|
39
|
+
data: string;
|
|
40
|
+
/**
|
|
41
|
+
* Transaction value in wei (hex string with 0x prefix)
|
|
42
|
+
*/
|
|
43
|
+
value: string;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/core/types/provider.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IAEV;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/core/types/provider.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool } from './pool';
|
|
2
|
-
import {
|
|
2
|
+
import { RouteToken } from './token';
|
|
3
3
|
/**
|
|
4
4
|
* Route identifier: sorted symbols joined with hyphen
|
|
5
5
|
* Represents the two endpoint tokens regardless of the path taken
|
|
@@ -11,7 +11,7 @@ export type RouteID = `${string}-${string}`;
|
|
|
11
11
|
export interface Route {
|
|
12
12
|
/**
|
|
13
13
|
* Canonical identifier: sorted symbols joined with hyphen
|
|
14
|
-
* Always uses alphabetical order (e.g., '
|
|
14
|
+
* Always uses alphabetical order (e.g., 'EURm-USDm' not 'USDm-EURm')
|
|
15
15
|
* Ensures consistent identification regardless of query direction
|
|
16
16
|
*/
|
|
17
17
|
id: RouteID;
|
|
@@ -19,7 +19,7 @@ export interface Route {
|
|
|
19
19
|
* The two tokens being traded, in alphabetical order by symbol
|
|
20
20
|
* Always [symbolA, symbolB] where symbolA < symbolB alphabetically
|
|
21
21
|
*/
|
|
22
|
-
tokens: [
|
|
22
|
+
tokens: [RouteToken, RouteToken];
|
|
23
23
|
/**
|
|
24
24
|
* Array of exchange hops needed to execute the trade
|
|
25
25
|
* Length 1: Direct route (single pool)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/core/types/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/core/types/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpC;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAA;AAE3C;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB;;;;OAIG;IACH,EAAE,EAAE,OAAO,CAAA;IAEX;;;OAGG;IACH,MAAM,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IAEhC;;;;;OAKG;IACH,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C;;;OAGG;IACH,QAAQ,EAAE;QACR;;;;WAIG;QACH,gBAAgB,EAAE,MAAM,CAAA;QAExB;;;WAGG;QACH,IAAI,EAAE,KAAK,CAAC;YACV;;eAEG;YACH,WAAW,EAAE,MAAM,CAAA;YAEnB;;eAEG;YACH,WAAW,EAAE,MAAM,CAAA;SACpB,CAAC,CAAA;KACH,CAAA;CACF"}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { ISupplyCalculator } from '../../services';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Minimal token info for routing purposes.
|
|
4
|
+
* Contains only the fields needed to identify and route between tokens.
|
|
5
|
+
*/
|
|
6
|
+
export interface RouteToken {
|
|
3
7
|
address: string;
|
|
4
8
|
symbol: string;
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Full token info for consumer-facing operations.
|
|
12
|
+
* Extends RouteToken with display and transaction fields.
|
|
13
|
+
*/
|
|
14
|
+
export interface Token extends RouteToken {
|
|
15
|
+
name: string;
|
|
16
|
+
decimals: number;
|
|
7
17
|
}
|
|
8
18
|
export interface StableToken extends Token {
|
|
9
19
|
totalSupply: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/core/types/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/core/types/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,KAAM,SAAQ,UAAU;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,MAAM,eAAe,GAAG,KAAK,CAAA;AAEnC;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,iBAAiB,CAAA;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,gBAAgB,EAAE,CAAA;CACnD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,16 +24,16 @@ import { TradingService } from './services/trading';
|
|
|
24
24
|
* const pools = await mento.pools.getPools();
|
|
25
25
|
*
|
|
26
26
|
* // Find a route between tokens
|
|
27
|
-
* const route = await mento.routes.findRoute(
|
|
27
|
+
* const route = await mento.routes.findRoute(USDm, CELO);
|
|
28
28
|
*
|
|
29
29
|
* // Get a quote for a swap
|
|
30
|
-
* const amountOut = await mento.quotes.getAmountOut(
|
|
30
|
+
* const amountOut = await mento.quotes.getAmountOut(USDm, CELO, amountIn);
|
|
31
31
|
*
|
|
32
32
|
* // Build swap parameters
|
|
33
|
-
* const swapDetails = await mento.swap.buildSwapParams(
|
|
33
|
+
* const swapDetails = await mento.swap.buildSwapParams(USDm, CELO, amountIn, { slippageTolerance: 0.5 });
|
|
34
34
|
*
|
|
35
35
|
* // Check if a pair is tradable (circuit breaker check)
|
|
36
|
-
* const isTradable = await mento.trading.isPairTradable(
|
|
36
|
+
* const isTradable = await mento.trading.isPairTradable(USDm, CELO);
|
|
37
37
|
*
|
|
38
38
|
* // Get trading limits for a pool
|
|
39
39
|
* const limits = await mento.trading.getPoolTradingLimits(pool);
|
package/dist/index.js
CHANGED
|
@@ -43,16 +43,16 @@ const trading_1 = require("./services/trading");
|
|
|
43
43
|
* const pools = await mento.pools.getPools();
|
|
44
44
|
*
|
|
45
45
|
* // Find a route between tokens
|
|
46
|
-
* const route = await mento.routes.findRoute(
|
|
46
|
+
* const route = await mento.routes.findRoute(USDm, CELO);
|
|
47
47
|
*
|
|
48
48
|
* // Get a quote for a swap
|
|
49
|
-
* const amountOut = await mento.quotes.getAmountOut(
|
|
49
|
+
* const amountOut = await mento.quotes.getAmountOut(USDm, CELO, amountIn);
|
|
50
50
|
*
|
|
51
51
|
* // Build swap parameters
|
|
52
|
-
* const swapDetails = await mento.swap.buildSwapParams(
|
|
52
|
+
* const swapDetails = await mento.swap.buildSwapParams(USDm, CELO, amountIn, { slippageTolerance: 0.5 });
|
|
53
53
|
*
|
|
54
54
|
* // Check if a pair is tradable (circuit breaker check)
|
|
55
|
-
* const isTradable = await mento.trading.isPairTradable(
|
|
55
|
+
* const isTradable = await mento.trading.isPairTradable(USDm, CELO);
|
|
56
56
|
*
|
|
57
57
|
* // Get trading limits for a pool
|
|
58
58
|
* const limits = await mento.trading.getPoolTradingLimits(pool);
|
|
@@ -14,7 +14,7 @@ export declare class PoolService {
|
|
|
14
14
|
* Results are cached in memory for the service instance lifetime
|
|
15
15
|
*
|
|
16
16
|
* @returns Array of all pools available in the protocol
|
|
17
|
-
* @throws {Error} If
|
|
17
|
+
* @throws {Error} If no pools can be discovered from any factory
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAY,MAAM,kBAAkB,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAW,MAAM,MAAM,CAAA;AAK5C;;;GAGG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;IAF/D,OAAO,CAAC,UAAU,CAAsB;gBAEpB,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM;IAEvE;;;;;;;;;;;;OAYG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAY,MAAM,kBAAkB,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAW,MAAM,MAAM,CAAA;AAK5C;;;GAGG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;IAF/D,OAAO,CAAC,UAAU,CAAsB;gBAEpB,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM;IAEvE;;;;;;;;;;;;OAYG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAgCjC;;OAEG;YACW,cAAc;IAgD5B;;;;OAIG;YACW,iBAAiB;CAkEhC"}
|
|
@@ -21,7 +21,7 @@ class PoolService {
|
|
|
21
21
|
* Results are cached in memory for the service instance lifetime
|
|
22
22
|
*
|
|
23
23
|
* @returns Array of all pools available in the protocol
|
|
24
|
-
* @throws {Error} If
|
|
24
|
+
* @throws {Error} If no pools can be discovered from any factory
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
27
27
|
* ```typescript
|
|
@@ -37,10 +37,21 @@ class PoolService {
|
|
|
37
37
|
// for dynamic factory discovery. For now we will use
|
|
38
38
|
// the hardcoded factory addresses for the chain for v1.
|
|
39
39
|
const pools = [];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
try {
|
|
41
|
+
const fpmmPools = await this.fetchFPMMPools();
|
|
42
|
+
pools.push(...fpmmPools);
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
try {
|
|
46
|
+
const virtualPools = await this.fetchVirtualPools();
|
|
47
|
+
pools.push(...virtualPools);
|
|
48
|
+
}
|
|
49
|
+
catch { }
|
|
50
|
+
// Only throw if NO pools were discovered from any factory
|
|
51
|
+
if (pools.length === 0) {
|
|
52
|
+
throw new Error('Failed to discover any pools from any factory. ' +
|
|
53
|
+
'All pool factory queries failed. Check network connectivity and RPC endpoint.');
|
|
54
|
+
}
|
|
44
55
|
this.poolsCache = pools;
|
|
45
56
|
return pools;
|
|
46
57
|
}
|
|
@@ -50,7 +61,6 @@ class PoolService {
|
|
|
50
61
|
async fetchFPMMPools() {
|
|
51
62
|
const fpmmFactoryAddress = (0, constants_1.getContractAddress)(this.chainId, 'FPMMFactory');
|
|
52
63
|
if (!fpmmFactoryAddress) {
|
|
53
|
-
console.warn('FPMM Factory address not found for this chain');
|
|
54
64
|
return [];
|
|
55
65
|
}
|
|
56
66
|
try {
|
|
@@ -87,7 +97,6 @@ class PoolService {
|
|
|
87
97
|
return await Promise.all(poolDataPromises);
|
|
88
98
|
}
|
|
89
99
|
catch (error) {
|
|
90
|
-
console.error('Failed to fetch FPMM pools:', error);
|
|
91
100
|
throw new Error(`Failed to fetch FPMM pools: ${error.message}`);
|
|
92
101
|
}
|
|
93
102
|
}
|
|
@@ -100,11 +109,10 @@ class PoolService {
|
|
|
100
109
|
const virtualPoolFactoryAddress = (0, constants_1.getContractAddress)(this.chainId, 'VirtualPoolFactory');
|
|
101
110
|
const biPoolManagerAddress = (0, constants_1.getContractAddress)(this.chainId, 'BiPoolManager');
|
|
102
111
|
if (!virtualPoolFactoryAddress || !biPoolManagerAddress) {
|
|
103
|
-
console.warn('VirtualPoolFactory or BiPoolManager address not found for this chain');
|
|
104
112
|
return [];
|
|
105
113
|
}
|
|
106
114
|
try {
|
|
107
|
-
// TODO: When
|
|
115
|
+
// TODO: When the latest virtual pool factory contract is deployed
|
|
108
116
|
// we can simplify this by using VirtualPoolFactory.getAllPools() returns(address[])
|
|
109
117
|
// Get all exchanges from BiPoolManager
|
|
110
118
|
const exchangesData = (await this.publicClient.readContract({
|
|
@@ -118,7 +126,6 @@ class PoolService {
|
|
|
118
126
|
// For each exchange, check if a virtual pool exists, and if so, return the pool address.
|
|
119
127
|
const poolPromises = exchangesData.map(async (exchange) => {
|
|
120
128
|
if (exchange.assets.length !== 2) {
|
|
121
|
-
console.warn(`Skipping invalid exchange ${exchange.exchangeId}: expected 2 assets`);
|
|
122
129
|
return null;
|
|
123
130
|
}
|
|
124
131
|
const [token0, token1] = (0, sortUtils_1.sortTokenAddresses)(exchange.assets[0], exchange.assets[1]);
|
|
@@ -151,7 +158,6 @@ class PoolService {
|
|
|
151
158
|
return results.filter((pool) => pool !== null);
|
|
152
159
|
}
|
|
153
160
|
catch (error) {
|
|
154
|
-
console.error('Failed to fetch Virtual pools:', error);
|
|
155
161
|
throw new Error(`Failed to fetch Virtual pools: ${error.message}`);
|
|
156
162
|
}
|
|
157
163
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PoolService.js","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":";;;AAAA,oDAAkE;AAClE,4CAAiD;AACjD,0CAA0G;AAE1G,qDAA0D;AAE1D,iGAAiG;AAEjG;;;GAGG;AACH,MAAa,WAAW;IAGtB,YAAoB,YAA0B,EAAU,OAAe;QAAnD,iBAAY,GAAZ,YAAY,CAAc;QAAU,YAAO,GAAP,OAAO,CAAQ;QAF/D,eAAU,GAAkB,IAAI,CAAA;IAEkC,CAAC;IAE3E;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,UAAU,CAAA;QACxB,CAAC;QAED,6DAA6D;QAC7D,2DAA2D;QAC3D,8DAA8D;QAC9D,MAAM,KAAK,GAAW,EAAE,CAAA;QAExB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"PoolService.js","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":";;;AAAA,oDAAkE;AAClE,4CAAiD;AACjD,0CAA0G;AAE1G,qDAA0D;AAE1D,iGAAiG;A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AE,+BAAwB;oBAC7B,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,CAAC,WAAW,CAAC;iBACpB,CAAC,CAAY,CAAA;gBAEd,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,OAAO,IAAI,CAAA;gBACb,CAAC;gBAED,MAAM,IAAI,GAAS;oBACjB,WAAW,EAAE,yBAAyB;oBACtC,QAAQ,EAAE,WAAqB;oBAC/B,MAAM,EAAE,MAAgB;oBACxB,MAAM,EAAE,MAAgB;oBACxB,QAAQ,EAAE,gBAAQ,CAAC,OAAwB;oBAC3C,UAAU,EAAE,QAAQ,CAAC,UAAU;iBAChC,CAAA;gBACD,OAAO,IAAI,CAAA;YACb,CAAC,CAAC,CAAA;YAEF,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;YAC/C,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAgB,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;QAC9D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,kCAAmC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;QAC/E,CAAC;IACH,CAAC;CACF;AA5KD,kCA4KC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
2
|
import { RouteService } from '../routes';
|
|
3
3
|
import { Route } from '../../core/types';
|
|
4
4
|
/**
|
|
@@ -13,8 +13,8 @@ export declare class QuoteService {
|
|
|
13
13
|
/**
|
|
14
14
|
* Calculates the expected output amount for a swap between two tokens.
|
|
15
15
|
*
|
|
16
|
-
* @param tokenIn - The address of the input token
|
|
17
|
-
* @param tokenOut - The address of the output token
|
|
16
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
17
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
18
18
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
19
19
|
* @param route - Optional pre-fetched route. If not provided, the optimal route will be found automatically.
|
|
20
20
|
* @returns The expected output amount (in wei/smallest unit)
|
|
@@ -23,19 +23,28 @@ export declare class QuoteService {
|
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
|
-
*
|
|
27
|
-
* const
|
|
28
|
-
*
|
|
29
|
-
* //
|
|
30
|
-
*
|
|
31
|
-
*
|
|
26
|
+
* // Calculate output for 100 USDm
|
|
27
|
+
* const amountIn = BigInt(100) * BigInt(10 ** 18) // 100 USDm in wei
|
|
28
|
+
* const expectedOut = await quoteService.getAmountOut(
|
|
29
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
30
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
31
|
+
* amountIn
|
|
32
|
+
* )
|
|
32
33
|
* console.log(`Expected CELO output: ${expectedOut}`)
|
|
33
34
|
*
|
|
34
35
|
* // Or provide a pre-fetched route for better performance
|
|
35
|
-
* const route = await routeService.findRoute(
|
|
36
|
-
*
|
|
36
|
+
* const route = await routeService.findRoute(
|
|
37
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
38
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438'
|
|
39
|
+
* )
|
|
40
|
+
* const expectedOut2 = await quoteService.getAmountOut(
|
|
41
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
42
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438',
|
|
43
|
+
* amountIn,
|
|
44
|
+
* route
|
|
45
|
+
* )
|
|
37
46
|
* ```
|
|
38
47
|
*/
|
|
39
|
-
getAmountOut(tokenIn:
|
|
48
|
+
getAmountOut(tokenIn: string, tokenOut: string, amountIn: bigint, route?: Route): Promise<bigint>;
|
|
40
49
|
}
|
|
41
50
|
//# sourceMappingURL=QuoteService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteService.d.ts","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"QuoteService.d.ts","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,MAAM,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAMxC;;;GAGG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;gBAFZ,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY;IAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;CAuBxG"}
|
|
@@ -4,6 +4,7 @@ exports.QuoteService = void 0;
|
|
|
4
4
|
const abis_1 = require("../../core/abis");
|
|
5
5
|
const constants_1 = require("../../core/constants");
|
|
6
6
|
const pathEncoder_1 = require("../../utils/pathEncoder");
|
|
7
|
+
const validation_1 = require("../../utils/validation");
|
|
7
8
|
/**
|
|
8
9
|
* Service for getting swap quotes from the Mento protocol.
|
|
9
10
|
* Calculates expected output amounts for trades without executing them.
|
|
@@ -14,12 +15,11 @@ class QuoteService {
|
|
|
14
15
|
this.chainId = chainId;
|
|
15
16
|
this.routeService = routeService;
|
|
16
17
|
}
|
|
17
|
-
// TODO: Go through codebase and update token/symbol/name references to the old ones.
|
|
18
18
|
/**
|
|
19
19
|
* Calculates the expected output amount for a swap between two tokens.
|
|
20
20
|
*
|
|
21
|
-
* @param tokenIn - The address of the input token
|
|
22
|
-
* @param tokenOut - The address of the output token
|
|
21
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
22
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
23
23
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
24
24
|
* @param route - Optional pre-fetched route. If not provided, the optimal route will be found automatically.
|
|
25
25
|
* @returns The expected output amount (in wei/smallest unit)
|
|
@@ -28,20 +28,32 @@ class QuoteService {
|
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```typescript
|
|
31
|
-
*
|
|
32
|
-
* const
|
|
33
|
-
*
|
|
34
|
-
* //
|
|
35
|
-
*
|
|
36
|
-
*
|
|
31
|
+
* // Calculate output for 100 USDm
|
|
32
|
+
* const amountIn = BigInt(100) * BigInt(10 ** 18) // 100 USDm in wei
|
|
33
|
+
* const expectedOut = await quoteService.getAmountOut(
|
|
34
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
35
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
36
|
+
* amountIn
|
|
37
|
+
* )
|
|
37
38
|
* console.log(`Expected CELO output: ${expectedOut}`)
|
|
38
39
|
*
|
|
39
40
|
* // Or provide a pre-fetched route for better performance
|
|
40
|
-
* const route = await routeService.findRoute(
|
|
41
|
-
*
|
|
41
|
+
* const route = await routeService.findRoute(
|
|
42
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
43
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438'
|
|
44
|
+
* )
|
|
45
|
+
* const expectedOut2 = await quoteService.getAmountOut(
|
|
46
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
47
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438',
|
|
48
|
+
* amountIn,
|
|
49
|
+
* route
|
|
50
|
+
* )
|
|
42
51
|
* ```
|
|
43
52
|
*/
|
|
44
53
|
async getAmountOut(tokenIn, tokenOut, amountIn, route) {
|
|
54
|
+
// Validate address inputs
|
|
55
|
+
(0, validation_1.validateAddress)(tokenIn, 'tokenIn');
|
|
56
|
+
(0, validation_1.validateAddress)(tokenOut, 'tokenOut');
|
|
45
57
|
// If the consumer does not provide a route then we find the best route.
|
|
46
58
|
if (!route) {
|
|
47
59
|
route = await this.routeService.findRoute(tokenIn, tokenOut);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteService.js","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":";;;AAGA,0CAA4C;AAC5C,oDAAkE;AAClE,yDAAyD;
|
|
1
|
+
{"version":3,"file":"QuoteService.js","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":";;;AAGA,0CAA4C;AAC5C,oDAAkE;AAClE,yDAAyD;AACzD,uDAAwD;AAExD;;;GAGG;AACH,MAAa,YAAY;IACvB,YACU,YAA0B,EAC1B,OAAe,EACf,YAA0B;QAF1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,QAAgB,EAAE,QAAgB,EAAE,KAAa;QACnF,0BAA0B;QAC1B,IAAA,4BAAe,EAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QACnC,IAAA,4BAAe,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QAErC,wEAAwE;QACxE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC9D,CAAC;QAED,yDAAyD;QACzD,MAAM,YAAY,GAAG,IAAA,6BAAe,EAAC,KAAK,CAAC,IAAI,EAAE,OAAkB,EAAE,QAAmB,CAAC,CAAA;QACzF,MAAM,aAAa,GAAG,IAAA,8BAAkB,EAAC,IAAI,CAAC,OAAkB,EAAE,QAAQ,CAAC,CAAA;QAE3E,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YACpD,OAAO,EAAE,aAA8B;YACvC,GAAG,EAAE,iBAAU;YACf,YAAY,EAAE,eAAe;YAC7B,IAAI,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC;SAC/B,CAAC,CAAa,CAAA;QAEf,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACpC,CAAC;CACF;AAjED,oCAiEC"}
|
|
@@ -72,9 +72,9 @@ export declare class RouteService {
|
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
74
74
|
* ```typescript
|
|
75
|
-
* const
|
|
76
|
-
* const
|
|
77
|
-
* const route = await routeService.findRoute(
|
|
75
|
+
* const USDm = '0x765DE816845861e75A25fCA122bb6898B8B1282a'
|
|
76
|
+
* const BRLm = '0xE4D5...'
|
|
77
|
+
* const route = await routeService.findRoute(USDm, BRLm)
|
|
78
78
|
*
|
|
79
79
|
* if (route.path.length === 1) {
|
|
80
80
|
* console.log('Direct route available')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteService.d.ts","sourceRoot":"","sources":["../../../src/services/routes/RouteService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGtC,OAAO,EAAE,KAAK,EAAiB,aAAa,
|
|
1
|
+
{"version":3,"file":"RouteService.d.ts","sourceRoot":"","sources":["../../../src/services/routes/RouteService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGtC,OAAO,EAAE,KAAK,EAAiB,aAAa,EAAc,MAAM,kBAAkB,CAAA;AAGlF,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEnC,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,qBAAa,YAAY;IAGX,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;IAAU,OAAO,CAAC,WAAW;IAF5F,OAAO,CAAC,WAAW,CAAiC;gBAEhC,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM,EAAU,WAAW,EAAE,WAAW;IAEzG;;;;;;;;;;;;OAYG;IACG,eAAe,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAuDzC;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,SAAS,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,GAAG,aAAa,CAAC,EAAE,CAAC;IAoBpF;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IAuBlG;;;;OAIG;YACW,mBAAmB;IAoBjC;;;OAGG;YACW,gBAAgB;IAM9B;;;;;;OAMG;YACW,gBAAgB;CAuB/B"}
|