@mento-protocol/mento-sdk 3.2.4 → 3.2.5
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isTradingEnabled, } from '../../core/types';
|
|
1
|
+
import { isTradingEnabled, PoolType, } from '../../core/types';
|
|
2
2
|
import { TradingLimitsService } from './TradingLimitsService';
|
|
3
|
-
import { BREAKERBOX_ABI, FPMM_ABI } from '../../core/abis';
|
|
4
|
-
import { getContractAddress } from '../../core/constants';
|
|
3
|
+
import { BIPOOL_MANAGER_ABI, BREAKERBOX_ABI, FPMM_ABI } from '../../core/abis';
|
|
4
|
+
import { getContractAddress, tryGetContractAddress } from '../../core/constants';
|
|
5
5
|
import { multicall } from '../../utils/multicall';
|
|
6
6
|
/**
|
|
7
7
|
* Service for checking trading status and circuit breaker state in the Mento protocol.
|
|
@@ -136,7 +136,9 @@ export class TradingService {
|
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* Get the reference rate feed ID for a pool.
|
|
139
|
-
*
|
|
139
|
+
* FPMM pools expose this via referenceRateFeedID() directly.
|
|
140
|
+
* Virtual pools wrap a BiPoolManager exchange; the rate feed is read from
|
|
141
|
+
* BiPoolManager.getPoolExchange(exchangeId).config.referenceRateFeedID.
|
|
140
142
|
*
|
|
141
143
|
* @param pool - The pool to get rate feed ID for
|
|
142
144
|
* @returns The rate feed ID address
|
|
@@ -153,16 +155,40 @@ export class TradingService {
|
|
|
153
155
|
if (pools.length === 0) {
|
|
154
156
|
return [];
|
|
155
157
|
}
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
const biPoolManagerAddr = pools.some((pool) => pool.poolType === PoolType.Virtual)
|
|
159
|
+
? tryGetContractAddress(this.chainId, 'BiPoolManager')
|
|
160
|
+
: undefined;
|
|
161
|
+
const contracts = pools.map((pool) => {
|
|
162
|
+
if (pool.poolType === PoolType.Virtual) {
|
|
163
|
+
if (!pool.exchangeId) {
|
|
164
|
+
throw new Error(`Virtual pool ${pool.poolAddr} is missing exchangeId`);
|
|
165
|
+
}
|
|
166
|
+
if (!biPoolManagerAddr) {
|
|
167
|
+
throw new Error(`BiPoolManager address not configured for chain ID ${this.chainId}; cannot resolve rate feed for virtual pool ${pool.poolAddr}`);
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
address: biPoolManagerAddr,
|
|
171
|
+
abi: BIPOOL_MANAGER_ABI,
|
|
172
|
+
functionName: 'getPoolExchange',
|
|
173
|
+
args: [pool.exchangeId],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
address: pool.poolAddr,
|
|
178
|
+
abi: FPMM_ABI,
|
|
179
|
+
functionName: 'referenceRateFeedID',
|
|
180
|
+
args: [],
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
const results = await multicall(this.publicClient, contracts, { allowFailure: false });
|
|
184
|
+
return results.map((result, index) => {
|
|
163
185
|
if (result.status === 'failure') {
|
|
164
186
|
throw result.error;
|
|
165
187
|
}
|
|
188
|
+
if (pools[index].poolType === PoolType.Virtual) {
|
|
189
|
+
const exchange = result.result;
|
|
190
|
+
return exchange.config.referenceRateFeedID;
|
|
191
|
+
}
|
|
166
192
|
return result.result;
|
|
167
193
|
});
|
|
168
194
|
}
|
|
@@ -100,7 +100,9 @@ export declare class TradingService {
|
|
|
100
100
|
getPoolTradabilityStatus(pool: Pool): Promise<PoolTradabilityStatus>;
|
|
101
101
|
/**
|
|
102
102
|
* Get the reference rate feed ID for a pool.
|
|
103
|
-
*
|
|
103
|
+
* FPMM pools expose this via referenceRateFeedID() directly.
|
|
104
|
+
* Virtual pools wrap a BiPoolManager exchange; the rate feed is read from
|
|
105
|
+
* BiPoolManager.getPoolExchange(exchangeId).config.referenceRateFeedID.
|
|
104
106
|
*
|
|
105
107
|
* @param pool - The pool to get rate feed ID for
|
|
106
108
|
* @returns The rate feed ID address
|
|
@@ -139,7 +139,9 @@ class TradingService {
|
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* Get the reference rate feed ID for a pool.
|
|
142
|
-
*
|
|
142
|
+
* FPMM pools expose this via referenceRateFeedID() directly.
|
|
143
|
+
* Virtual pools wrap a BiPoolManager exchange; the rate feed is read from
|
|
144
|
+
* BiPoolManager.getPoolExchange(exchangeId).config.referenceRateFeedID.
|
|
143
145
|
*
|
|
144
146
|
* @param pool - The pool to get rate feed ID for
|
|
145
147
|
* @returns The rate feed ID address
|
|
@@ -156,16 +158,40 @@ class TradingService {
|
|
|
156
158
|
if (pools.length === 0) {
|
|
157
159
|
return [];
|
|
158
160
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
const biPoolManagerAddr = pools.some((pool) => pool.poolType === types_1.PoolType.Virtual)
|
|
162
|
+
? (0, constants_1.tryGetContractAddress)(this.chainId, 'BiPoolManager')
|
|
163
|
+
: undefined;
|
|
164
|
+
const contracts = pools.map((pool) => {
|
|
165
|
+
if (pool.poolType === types_1.PoolType.Virtual) {
|
|
166
|
+
if (!pool.exchangeId) {
|
|
167
|
+
throw new Error(`Virtual pool ${pool.poolAddr} is missing exchangeId`);
|
|
168
|
+
}
|
|
169
|
+
if (!biPoolManagerAddr) {
|
|
170
|
+
throw new Error(`BiPoolManager address not configured for chain ID ${this.chainId}; cannot resolve rate feed for virtual pool ${pool.poolAddr}`);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
address: biPoolManagerAddr,
|
|
174
|
+
abi: abis_1.BIPOOL_MANAGER_ABI,
|
|
175
|
+
functionName: 'getPoolExchange',
|
|
176
|
+
args: [pool.exchangeId],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
address: pool.poolAddr,
|
|
181
|
+
abi: abis_1.FPMM_ABI,
|
|
182
|
+
functionName: 'referenceRateFeedID',
|
|
183
|
+
args: [],
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
const results = await (0, multicall_1.multicall)(this.publicClient, contracts, { allowFailure: false });
|
|
187
|
+
return results.map((result, index) => {
|
|
166
188
|
if (result.status === 'failure') {
|
|
167
189
|
throw result.error;
|
|
168
190
|
}
|
|
191
|
+
if (pools[index].poolType === types_1.PoolType.Virtual) {
|
|
192
|
+
const exchange = result.result;
|
|
193
|
+
return exchange.config.referenceRateFeedID;
|
|
194
|
+
}
|
|
169
195
|
return result.result;
|
|
170
196
|
});
|
|
171
197
|
}
|