@gearbox-protocol/sdk 3.0.0-next.136 → 3.0.0-next.138
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/lib/core/endpoint.js +1 -1
- package/lib/pathfinder/pathfinder.js +10 -4
- package/package.json +1 -1
package/lib/core/endpoint.js
CHANGED
|
@@ -13,7 +13,7 @@ const CHARTS_BACKEND_ADDRESSES = {
|
|
|
13
13
|
[exports.TESTNET_CHAINS.Mainnet]: "https://testnet.gearbox.foundation",
|
|
14
14
|
// !& test server for optimism
|
|
15
15
|
[exports.TESTNET_CHAINS.Optimism]: "https://testnet.gearbox.foundation",
|
|
16
|
-
[exports.TESTNET_CHAINS.Arbitrum]: "https://
|
|
16
|
+
[exports.TESTNET_CHAINS.Arbitrum]: "https://arbtest.gearbox.foundation",
|
|
17
17
|
};
|
|
18
18
|
class ChartsApi {
|
|
19
19
|
static getUrl = (url, chainId, options, priceSource) => [
|
|
@@ -108,10 +108,16 @@ class PathFinder {
|
|
|
108
108
|
async findBestClosePath({ creditAccount, creditManager: cm, expectedBalances, leftoverBalances, slippage, noConcurrency = false, }) {
|
|
109
109
|
const loopsPerTx = Math.floor(GAS_PER_BLOCK / MAX_GAS_PER_ROUTE);
|
|
110
110
|
const pathOptions = pathOptions_1.PathOptionFactory.generatePathOptions(creditAccount.allBalances, loopsPerTx);
|
|
111
|
-
const expected = cm.collateralTokens.map(token =>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
const expected = cm.collateralTokens.map(token => {
|
|
112
|
+
// When we pass expected balances explicitly, we need to mimic router behaviour by filtering out leftover tokens
|
|
113
|
+
// for example, we can have stETH balance of 2, because 1 transforms to 2 because of rebasing
|
|
114
|
+
// https://github.com/Gearbox-protocol/router-v3/blob/c230a3aa568bb432e50463cfddc877fec8940cf5/contracts/RouterV3.sol#L222
|
|
115
|
+
const actual = expectedBalances[token]?.balance || 0n;
|
|
116
|
+
return {
|
|
117
|
+
token,
|
|
118
|
+
balance: actual > 10n ? actual : 0n,
|
|
119
|
+
};
|
|
120
|
+
});
|
|
115
121
|
const leftover = cm.collateralTokens.map(token => ({
|
|
116
122
|
token,
|
|
117
123
|
balance: leftoverBalances[token]?.balance || 1n,
|