@mento-protocol/mento-sdk 3.1.0-beta.2 → 3.1.0-beta.4
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/dist/esm/services/pools/poolDetails.js +7 -8
- package/dist/esm/services/pools/poolDiscovery.js +3 -2
- package/dist/esm/utils/chainConfig.js +12 -0
- package/dist/esm/utils/costUtils.js +8 -9
- package/dist/esm/utils/multicall.js +15 -0
- package/dist/services/pools/poolDetails.js +7 -8
- package/dist/services/pools/poolDiscovery.js +3 -2
- package/dist/utils/chainConfig.js +12 -0
- package/dist/utils/costUtils.js +8 -9
- package/dist/utils/multicall.d.ts +26 -0
- package/dist/utils/multicall.js +20 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addresses } from '../../core/constants';
|
|
2
2
|
import { FPMM_ABI, VIRTUAL_POOL_ABI } from '../../core/abis';
|
|
3
3
|
import { getAddress } from 'viem';
|
|
4
|
+
import { multicall } from '../../utils/multicall';
|
|
4
5
|
/**
|
|
5
6
|
* Fetches enriched details for an FPMM pool
|
|
6
7
|
*/
|
|
@@ -28,7 +29,7 @@ export async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
28
29
|
// Include getRebalancingState in the same multicall (allowFailure handles FXMarketClosed)
|
|
29
30
|
{ address, abi: FPMM_ABI, functionName: 'getRebalancingState' },
|
|
30
31
|
];
|
|
31
|
-
const results = await
|
|
32
|
+
const results = await multicall(publicClient, coreContracts);
|
|
32
33
|
// Parse core results (first 8 are fixed)
|
|
33
34
|
const reservesRes = results[0];
|
|
34
35
|
const decimals0Res = results[1];
|
|
@@ -117,13 +118,11 @@ export async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
117
118
|
export async function fetchVirtualPoolDetails(publicClient, pool) {
|
|
118
119
|
const address = pool.poolAddr;
|
|
119
120
|
try {
|
|
120
|
-
const results = await
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
],
|
|
126
|
-
});
|
|
121
|
+
const results = await multicall(publicClient, [
|
|
122
|
+
{ address, abi: VIRTUAL_POOL_ABI, functionName: 'getReserves' },
|
|
123
|
+
{ address, abi: VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
|
|
124
|
+
{ address, abi: VIRTUAL_POOL_ABI, functionName: 'metadata' },
|
|
125
|
+
]);
|
|
127
126
|
if (results[0].status === 'failure' || results[1].status === 'failure' || results[2].status === 'failure') {
|
|
128
127
|
throw new Error('One or more virtual pool reads failed');
|
|
129
128
|
}
|
|
@@ -2,6 +2,7 @@ import { tryGetContractAddress } from '../../core/constants';
|
|
|
2
2
|
import { PoolType } from '../../core/types';
|
|
3
3
|
import { FPMM_FACTORY_ABI, FPMM_ABI, VIRTUAL_POOL_FACTORY_ABI, VIRTUAL_POOL_ABI, BIPOOL_MANAGER_ABI, } from '../../core/abis';
|
|
4
4
|
import { sortTokenAddresses } from '../../utils/sortUtils';
|
|
5
|
+
import { multicall } from '../../utils/multicall';
|
|
5
6
|
/**
|
|
6
7
|
* Fetches all FPMM pools from the FPMM Factory
|
|
7
8
|
*/
|
|
@@ -25,7 +26,7 @@ export async function fetchFPMMPools(publicClient, chainId) {
|
|
|
25
26
|
{ address: poolAddress, abi: FPMM_ABI, functionName: 'token0' },
|
|
26
27
|
{ address: poolAddress, abi: FPMM_ABI, functionName: 'token1' },
|
|
27
28
|
]);
|
|
28
|
-
const results = await
|
|
29
|
+
const results = await multicall(publicClient, contracts);
|
|
29
30
|
return poolAddresses.map((poolAddress, i) => {
|
|
30
31
|
const token0Result = results[i * 2];
|
|
31
32
|
const token1Result = results[i * 2 + 1];
|
|
@@ -86,7 +87,7 @@ export async function fetchVirtualPools(publicClient, chainId) {
|
|
|
86
87
|
abi: VIRTUAL_POOL_ABI,
|
|
87
88
|
functionName: 'tokens',
|
|
88
89
|
}));
|
|
89
|
-
const results = await
|
|
90
|
+
const results = await multicall(publicClient, contracts);
|
|
90
91
|
return poolAddresses.map((poolAddress, i) => {
|
|
91
92
|
const result = results[i];
|
|
92
93
|
if (result.status === 'failure') {
|
|
@@ -42,6 +42,12 @@ const monadTestnet = defineChain({
|
|
|
42
42
|
url: 'https://testnet.monadexplorer.com',
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
+
contracts: {
|
|
46
|
+
multicall3: {
|
|
47
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
48
|
+
blockCreated: 251449,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
45
51
|
testnet: true,
|
|
46
52
|
});
|
|
47
53
|
const monad = defineChain({
|
|
@@ -63,6 +69,12 @@ const monad = defineChain({
|
|
|
63
69
|
url: 'https://monadvision.com',
|
|
64
70
|
},
|
|
65
71
|
},
|
|
72
|
+
contracts: {
|
|
73
|
+
multicall3: {
|
|
74
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
75
|
+
blockCreated: 9248132,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
66
78
|
});
|
|
67
79
|
/**
|
|
68
80
|
* Get the default RPC URL for a given chain ID
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PoolType } from '../core/types';
|
|
2
2
|
import { FPMM_ABI } from '../core/abis';
|
|
3
3
|
import { VIRTUAL_POOL_ABI } from '../core/abis/virtualPool';
|
|
4
|
+
import { multicall } from './multicall';
|
|
4
5
|
/**
|
|
5
6
|
* Calculate cost percentage for a pool based on its type
|
|
6
7
|
* Returns cost as a percentage (e.g., 0.5 = 0.5%)
|
|
@@ -25,12 +26,10 @@ export async function getPoolCostPercent(pool, publicClient) {
|
|
|
25
26
|
* FPMM pools use lpFee + protocolFee in basis points (10000 = 100%)
|
|
26
27
|
*/
|
|
27
28
|
async function getFPMMCostPercent(poolAddress, publicClient) {
|
|
28
|
-
const results = await
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
],
|
|
33
|
-
});
|
|
29
|
+
const results = await multicall(publicClient, [
|
|
30
|
+
{ address: poolAddress, abi: FPMM_ABI, functionName: 'lpFee' },
|
|
31
|
+
{ address: poolAddress, abi: FPMM_ABI, functionName: 'protocolFee' },
|
|
32
|
+
]);
|
|
34
33
|
if (results[0].status === 'failure' || results[1].status === 'failure') {
|
|
35
34
|
throw new Error(`Failed to read fees for pool ${poolAddress}`);
|
|
36
35
|
}
|
|
@@ -45,9 +44,9 @@ async function getFPMMCostPercent(poolAddress, publicClient) {
|
|
|
45
44
|
* Calculate cost for Virtual pools
|
|
46
45
|
*/
|
|
47
46
|
async function getVirtualPoolCostPercent(poolAddress, publicClient) {
|
|
48
|
-
const results = await
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
const results = await multicall(publicClient, [
|
|
48
|
+
{ address: poolAddress, abi: VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
|
|
49
|
+
]);
|
|
51
50
|
if (results[0].status === 'failure') {
|
|
52
51
|
throw new Error(`Failed to read protocolFee for pool ${poolAddress}`);
|
|
53
52
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard Multicall3 contract address, deployed at the same address on all EVM chains.
|
|
3
|
+
* https://www.multicall3.com/
|
|
4
|
+
*/
|
|
5
|
+
export const MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
6
|
+
/**
|
|
7
|
+
* Wrapper around viem's multicall that explicitly provides the Multicall3 address.
|
|
8
|
+
* This ensures multicall works even when the PublicClient was created without a `chain` config.
|
|
9
|
+
*/
|
|
10
|
+
export async function multicall(publicClient, contracts) {
|
|
11
|
+
return publicClient.multicall({
|
|
12
|
+
contracts: contracts,
|
|
13
|
+
multicallAddress: MULTICALL3_ADDRESS,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -5,6 +5,7 @@ exports.fetchVirtualPoolDetails = fetchVirtualPoolDetails;
|
|
|
5
5
|
const constants_1 = require("../../core/constants");
|
|
6
6
|
const abis_1 = require("../../core/abis");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
|
+
const multicall_1 = require("../../utils/multicall");
|
|
8
9
|
/**
|
|
9
10
|
* Fetches enriched details for an FPMM pool
|
|
10
11
|
*/
|
|
@@ -32,7 +33,7 @@ async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
32
33
|
// Include getRebalancingState in the same multicall (allowFailure handles FXMarketClosed)
|
|
33
34
|
{ address, abi: abis_1.FPMM_ABI, functionName: 'getRebalancingState' },
|
|
34
35
|
];
|
|
35
|
-
const results = await
|
|
36
|
+
const results = await (0, multicall_1.multicall)(publicClient, coreContracts);
|
|
36
37
|
// Parse core results (first 8 are fixed)
|
|
37
38
|
const reservesRes = results[0];
|
|
38
39
|
const decimals0Res = results[1];
|
|
@@ -121,13 +122,11 @@ async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
|
|
|
121
122
|
async function fetchVirtualPoolDetails(publicClient, pool) {
|
|
122
123
|
const address = pool.poolAddr;
|
|
123
124
|
try {
|
|
124
|
-
const results = await
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
],
|
|
130
|
-
});
|
|
125
|
+
const results = await (0, multicall_1.multicall)(publicClient, [
|
|
126
|
+
{ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'getReserves' },
|
|
127
|
+
{ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
|
|
128
|
+
{ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'metadata' },
|
|
129
|
+
]);
|
|
131
130
|
if (results[0].status === 'failure' || results[1].status === 'failure' || results[2].status === 'failure') {
|
|
132
131
|
throw new Error('One or more virtual pool reads failed');
|
|
133
132
|
}
|
|
@@ -6,6 +6,7 @@ const constants_1 = require("../../core/constants");
|
|
|
6
6
|
const types_1 = require("../../core/types");
|
|
7
7
|
const abis_1 = require("../../core/abis");
|
|
8
8
|
const sortUtils_1 = require("../../utils/sortUtils");
|
|
9
|
+
const multicall_1 = require("../../utils/multicall");
|
|
9
10
|
/**
|
|
10
11
|
* Fetches all FPMM pools from the FPMM Factory
|
|
11
12
|
*/
|
|
@@ -29,7 +30,7 @@ async function fetchFPMMPools(publicClient, chainId) {
|
|
|
29
30
|
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'token0' },
|
|
30
31
|
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'token1' },
|
|
31
32
|
]);
|
|
32
|
-
const results = await
|
|
33
|
+
const results = await (0, multicall_1.multicall)(publicClient, contracts);
|
|
33
34
|
return poolAddresses.map((poolAddress, i) => {
|
|
34
35
|
const token0Result = results[i * 2];
|
|
35
36
|
const token1Result = results[i * 2 + 1];
|
|
@@ -90,7 +91,7 @@ async function fetchVirtualPools(publicClient, chainId) {
|
|
|
90
91
|
abi: abis_1.VIRTUAL_POOL_ABI,
|
|
91
92
|
functionName: 'tokens',
|
|
92
93
|
}));
|
|
93
|
-
const results = await
|
|
94
|
+
const results = await (0, multicall_1.multicall)(publicClient, contracts);
|
|
94
95
|
return poolAddresses.map((poolAddress, i) => {
|
|
95
96
|
const result = results[i];
|
|
96
97
|
if (result.status === 'failure') {
|
|
@@ -46,6 +46,12 @@ const monadTestnet = (0, viem_1.defineChain)({
|
|
|
46
46
|
url: 'https://testnet.monadexplorer.com',
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
|
+
contracts: {
|
|
50
|
+
multicall3: {
|
|
51
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
52
|
+
blockCreated: 251449,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
49
55
|
testnet: true,
|
|
50
56
|
});
|
|
51
57
|
const monad = (0, viem_1.defineChain)({
|
|
@@ -67,6 +73,12 @@ const monad = (0, viem_1.defineChain)({
|
|
|
67
73
|
url: 'https://monadvision.com',
|
|
68
74
|
},
|
|
69
75
|
},
|
|
76
|
+
contracts: {
|
|
77
|
+
multicall3: {
|
|
78
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
79
|
+
blockCreated: 9248132,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
70
82
|
});
|
|
71
83
|
/**
|
|
72
84
|
* Get the default RPC URL for a given chain ID
|
package/dist/utils/costUtils.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.getPoolCostPercent = getPoolCostPercent;
|
|
|
4
4
|
const types_1 = require("../core/types");
|
|
5
5
|
const abis_1 = require("../core/abis");
|
|
6
6
|
const virtualPool_1 = require("../core/abis/virtualPool");
|
|
7
|
+
const multicall_1 = require("./multicall");
|
|
7
8
|
/**
|
|
8
9
|
* Calculate cost percentage for a pool based on its type
|
|
9
10
|
* Returns cost as a percentage (e.g., 0.5 = 0.5%)
|
|
@@ -28,12 +29,10 @@ async function getPoolCostPercent(pool, publicClient) {
|
|
|
28
29
|
* FPMM pools use lpFee + protocolFee in basis points (10000 = 100%)
|
|
29
30
|
*/
|
|
30
31
|
async function getFPMMCostPercent(poolAddress, publicClient) {
|
|
31
|
-
const results = await
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
],
|
|
36
|
-
});
|
|
32
|
+
const results = await (0, multicall_1.multicall)(publicClient, [
|
|
33
|
+
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'lpFee' },
|
|
34
|
+
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'protocolFee' },
|
|
35
|
+
]);
|
|
37
36
|
if (results[0].status === 'failure' || results[1].status === 'failure') {
|
|
38
37
|
throw new Error(`Failed to read fees for pool ${poolAddress}`);
|
|
39
38
|
}
|
|
@@ -48,9 +47,9 @@ async function getFPMMCostPercent(poolAddress, publicClient) {
|
|
|
48
47
|
* Calculate cost for Virtual pools
|
|
49
48
|
*/
|
|
50
49
|
async function getVirtualPoolCostPercent(poolAddress, publicClient) {
|
|
51
|
-
const results = await
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
const results = await (0, multicall_1.multicall)(publicClient, [
|
|
51
|
+
{ address: poolAddress, abi: virtualPool_1.VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
|
|
52
|
+
]);
|
|
54
53
|
if (results[0].status === 'failure') {
|
|
55
54
|
throw new Error(`Failed to read protocolFee for pool ${poolAddress}`);
|
|
56
55
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Abi, PublicClient } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Standard Multicall3 contract address, deployed at the same address on all EVM chains.
|
|
4
|
+
* https://www.multicall3.com/
|
|
5
|
+
*/
|
|
6
|
+
export declare const MULTICALL3_ADDRESS: "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
7
|
+
type MulticallResult = {
|
|
8
|
+
status: 'success';
|
|
9
|
+
result: unknown;
|
|
10
|
+
} | {
|
|
11
|
+
status: 'failure';
|
|
12
|
+
error: Error;
|
|
13
|
+
};
|
|
14
|
+
interface ContractCall {
|
|
15
|
+
address: `0x${string}`;
|
|
16
|
+
abi: Abi | readonly unknown[];
|
|
17
|
+
functionName: string;
|
|
18
|
+
args?: readonly unknown[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Wrapper around viem's multicall that explicitly provides the Multicall3 address.
|
|
22
|
+
* This ensures multicall works even when the PublicClient was created without a `chain` config.
|
|
23
|
+
*/
|
|
24
|
+
export declare function multicall(publicClient: PublicClient, contracts: ContractCall[]): Promise<MulticallResult[]>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=multicall.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MULTICALL3_ADDRESS = void 0;
|
|
4
|
+
exports.multicall = multicall;
|
|
5
|
+
/**
|
|
6
|
+
* Standard Multicall3 contract address, deployed at the same address on all EVM chains.
|
|
7
|
+
* https://www.multicall3.com/
|
|
8
|
+
*/
|
|
9
|
+
exports.MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
10
|
+
/**
|
|
11
|
+
* Wrapper around viem's multicall that explicitly provides the Multicall3 address.
|
|
12
|
+
* This ensures multicall works even when the PublicClient was created without a `chain` config.
|
|
13
|
+
*/
|
|
14
|
+
async function multicall(publicClient, contracts) {
|
|
15
|
+
return publicClient.multicall({
|
|
16
|
+
contracts: contracts,
|
|
17
|
+
multicallAddress: exports.MULTICALL3_ADDRESS,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=multicall.js.map
|