@paraswap/dex-lib 3.11.5-cables.0 → 3.11.5-fluid-dex-changes.0
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/build/abi/fluid-dex/resolver.abi.json +731 -4
- package/build/dex/balancer-v2/balancer-v2.js +0 -1
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/bebop/bebop.js +1 -1
- package/build/dex/bebop/bebop.js.map +1 -1
- package/build/dex/cables/cables.js +10 -2
- package/build/dex/cables/cables.js.map +1 -1
- package/build/dex/fluid-dex/config.js +1 -1
- package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +28 -1
- package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
- package/build/dex/fluid-dex/fluid-dex.d.ts +17 -10
- package/build/dex/fluid-dex/fluid-dex.js +218 -67
- package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
- package/build/dex/fluid-dex/types.d.ts +22 -2
- package/build/dex/index.js +0 -2
- package/build/dex/index.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/fluid-dex/resolver.abi.json +731 -4
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -78
- package/src/dex/balancer-v2/balancer-v2.ts +0 -2
- package/src/dex/bebop/bebop.ts +1 -1
- package/src/dex/fluid-dex/config.ts +1 -1
- package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +151 -3
- package/src/dex/fluid-dex/fluid-dex-events.test.ts +2 -4
- package/src/dex/fluid-dex/fluid-dex-integration.test.ts +79 -11
- package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +33 -0
- package/src/dex/fluid-dex/fluid-dex.ts +302 -104
- package/src/dex/fluid-dex/types.ts +25 -1
- package/src/dex/index.ts +0 -2
- package/tests/constants-e2e.ts +2 -2
- package/.env.example +0 -7
- package/src/abi/cables/CablesMainnetRFQ.json +0 -1083
- package/src/dex/cables/cables-e2e.test.ts +0 -171
- package/src/dex/cables/cables-integration.test.ts +0 -319
- package/src/dex/cables/cables.ts +0 -911
- package/src/dex/cables/config.ts +0 -13
- package/src/dex/cables/constants.ts +0 -35
- package/src/dex/cables/rate-fetcher.ts +0 -212
- package/src/dex/cables/types.ts +0 -128
- package/src/dex/cables/validators.test.ts +0 -151
- package/src/dex/cables/validators.ts +0 -61
|
@@ -41,7 +41,6 @@ function testForNetwork(
|
|
|
41
41
|
// ContractMethod.multiSwap,
|
|
42
42
|
// ContractMethod.megaSwap,
|
|
43
43
|
ContractMethod.swapExactAmountIn,
|
|
44
|
-
ContractMethod.swapExactAmountInOnBalancerV2,
|
|
45
44
|
],
|
|
46
45
|
],
|
|
47
46
|
[
|
|
@@ -51,7 +50,6 @@ function testForNetwork(
|
|
|
51
50
|
// ContractMethod.buy,
|
|
52
51
|
// DirectMethodsV6.directBuy,
|
|
53
52
|
ContractMethod.swapExactAmountOut,
|
|
54
|
-
ContractMethod.swapExactAmountOutOnBalancerV2,
|
|
55
53
|
],
|
|
56
54
|
],
|
|
57
55
|
]);
|
|
@@ -130,82 +128,6 @@ describe('BalancerV2 E2E', () => {
|
|
|
130
128
|
network,
|
|
131
129
|
);
|
|
132
130
|
|
|
133
|
-
describe.only('GHO -> USDT', () => {
|
|
134
|
-
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
135
|
-
[
|
|
136
|
-
[
|
|
137
|
-
{
|
|
138
|
-
name: 'GHO',
|
|
139
|
-
sellAmount: '1000000000000000000000',
|
|
140
|
-
buyAmount: '1000000000',
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
name: 'USDT',
|
|
144
|
-
sellAmount: '1000000000',
|
|
145
|
-
buyAmount: '1000000000000000000000',
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
];
|
|
149
|
-
|
|
150
|
-
const sideToContractMethods = new Map([
|
|
151
|
-
[
|
|
152
|
-
SwapSide.SELL,
|
|
153
|
-
[
|
|
154
|
-
ContractMethod.swapExactAmountIn,
|
|
155
|
-
ContractMethod.swapExactAmountInOnBalancerV2,
|
|
156
|
-
],
|
|
157
|
-
],
|
|
158
|
-
[
|
|
159
|
-
SwapSide.BUY,
|
|
160
|
-
[
|
|
161
|
-
ContractMethod.swapExactAmountOut,
|
|
162
|
-
ContractMethod.swapExactAmountOutOnBalancerV2,
|
|
163
|
-
],
|
|
164
|
-
],
|
|
165
|
-
]);
|
|
166
|
-
|
|
167
|
-
sideToContractMethods.forEach((contractMethods, side) =>
|
|
168
|
-
describe(`${side}`, () => {
|
|
169
|
-
contractMethods.forEach((contractMethod: string) => {
|
|
170
|
-
pairs.forEach(pair => {
|
|
171
|
-
describe(`${contractMethod}`, () => {
|
|
172
|
-
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
|
|
173
|
-
await testE2E(
|
|
174
|
-
tokens[pair[0].name],
|
|
175
|
-
tokens[pair[1].name],
|
|
176
|
-
holders[pair[0].name],
|
|
177
|
-
side === SwapSide.SELL
|
|
178
|
-
? pair[0].sellAmount
|
|
179
|
-
: pair[0].buyAmount,
|
|
180
|
-
side,
|
|
181
|
-
dexKey,
|
|
182
|
-
contractMethod as any,
|
|
183
|
-
network,
|
|
184
|
-
provider,
|
|
185
|
-
);
|
|
186
|
-
});
|
|
187
|
-
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
|
|
188
|
-
await testE2E(
|
|
189
|
-
tokens[pair[1].name],
|
|
190
|
-
tokens[pair[0].name],
|
|
191
|
-
holders[pair[1].name],
|
|
192
|
-
side === SwapSide.SELL
|
|
193
|
-
? pair[1].sellAmount
|
|
194
|
-
: pair[1].buyAmount,
|
|
195
|
-
side,
|
|
196
|
-
dexKey,
|
|
197
|
-
contractMethod as any,
|
|
198
|
-
network,
|
|
199
|
-
provider,
|
|
200
|
-
);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}),
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
131
|
describe('Weighted Pool', () => {
|
|
210
132
|
const sideToContractMethods = new Map([
|
|
211
133
|
[
|
|
@@ -266,7 +266,6 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
|
|
|
266
266
|
buySupportedPoolTypes: Set<BalancerPoolTypes> = new Set([
|
|
267
267
|
BalancerPoolTypes.Weighted,
|
|
268
268
|
BalancerPoolTypes.GyroE,
|
|
269
|
-
BalancerPoolTypes.ComposableStable,
|
|
270
269
|
]);
|
|
271
270
|
|
|
272
271
|
eventSupportedPoolTypes: BalancerPoolTypes[] = [
|
|
@@ -869,7 +868,6 @@ export class BalancerV2
|
|
|
869
868
|
this.logger.error(`getState returned null`);
|
|
870
869
|
}
|
|
871
870
|
const eventPoolStates = { ...(eventPoolStatesRO || {}) };
|
|
872
|
-
|
|
873
871
|
for (const addr of this.eventDisabledPools) delete eventPoolStates[addr];
|
|
874
872
|
|
|
875
873
|
// Fetch previously cached non-event pool states
|
package/src/dex/bebop/bebop.ts
CHANGED
|
@@ -723,7 +723,7 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
|
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
725
|
|
|
726
|
-
if (side
|
|
726
|
+
if (side == SwapSide.SELL) {
|
|
727
727
|
const requiredAmount = BigInt(optimalSwapExchange.destAmount);
|
|
728
728
|
const quoteAmount = BigInt(
|
|
729
729
|
response.buyTokens[utils.getAddress(destToken.address)].amount,
|
|
@@ -7,7 +7,7 @@ export const FluidDexConfig: DexConfigMap<DexParams> = {
|
|
|
7
7
|
[Network.MAINNET]: {
|
|
8
8
|
commonAddresses: {
|
|
9
9
|
liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497',
|
|
10
|
-
resolver: '
|
|
10
|
+
resolver: '0x45f4ad57e300da55c33dea579a40fcee000d7b94',
|
|
11
11
|
dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
|
|
12
12
|
},
|
|
13
13
|
},
|
|
@@ -3,7 +3,6 @@ import dotenv from 'dotenv';
|
|
|
3
3
|
dotenv.config();
|
|
4
4
|
|
|
5
5
|
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
6
|
-
|
|
7
6
|
import { testE2E } from '../../../tests/utils-e2e';
|
|
8
7
|
import {
|
|
9
8
|
Tokens,
|
|
@@ -12,6 +11,9 @@ import {
|
|
|
12
11
|
} from '../../../tests/constants-e2e';
|
|
13
12
|
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
14
13
|
import { generateConfig } from '../../config';
|
|
14
|
+
import { CollateralReserves, DebtReserves, DexLimits } from './types';
|
|
15
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
16
|
+
import { FluidDex } from './fluid-dex';
|
|
15
17
|
|
|
16
18
|
/*
|
|
17
19
|
README
|
|
@@ -70,6 +72,7 @@ function testForNetwork(
|
|
|
70
72
|
|
|
71
73
|
const sideToContractMethods = new Map([
|
|
72
74
|
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
|
|
75
|
+
[SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
|
|
73
76
|
]);
|
|
74
77
|
|
|
75
78
|
describe(`${network}`, () => {
|
|
@@ -137,8 +140,8 @@ describe('FluidDex E2E', () => {
|
|
|
137
140
|
const tokenASymbol: string = 'USDC';
|
|
138
141
|
const tokenBSymbol: string = 'USDT';
|
|
139
142
|
|
|
140
|
-
const tokenAAmount: string = '
|
|
141
|
-
const tokenBAmount: string = '
|
|
143
|
+
const tokenAAmount: string = '10000';
|
|
144
|
+
const tokenBAmount: string = '1000000';
|
|
142
145
|
|
|
143
146
|
testForNetwork(
|
|
144
147
|
network,
|
|
@@ -151,3 +154,148 @@ describe('FluidDex E2E', () => {
|
|
|
151
154
|
});
|
|
152
155
|
});
|
|
153
156
|
});
|
|
157
|
+
|
|
158
|
+
function NewColReservesOne(): CollateralReserves {
|
|
159
|
+
return {
|
|
160
|
+
token0RealReserves: BigInt(20000000006000000),
|
|
161
|
+
token1RealReserves: BigInt(20000000000500000),
|
|
162
|
+
token0ImaginaryReserves: BigInt(389736659726997981),
|
|
163
|
+
token1ImaginaryReserves: BigInt(389736659619871949),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function NewDebtReservesOne(): DebtReserves {
|
|
168
|
+
return {
|
|
169
|
+
token0Debt: BigInt(1e18),
|
|
170
|
+
token1Debt: BigInt(1e18),
|
|
171
|
+
token0RealReserves: BigInt(9486832995556050),
|
|
172
|
+
token1RealReserves: BigInt(9486832993079885),
|
|
173
|
+
token0ImaginaryReserves: BigInt(184868330099560759),
|
|
174
|
+
token1ImaginaryReserves: BigInt(184868330048879109),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const limitsTight: DexLimits = {
|
|
179
|
+
withdrawableToken0: {
|
|
180
|
+
available: 456740438880263n,
|
|
181
|
+
expandsTo: 711907234052361388866n,
|
|
182
|
+
expandsDuration: 600n,
|
|
183
|
+
},
|
|
184
|
+
withdrawableToken1: {
|
|
185
|
+
available: 825179383432029n,
|
|
186
|
+
expandsTo: 711907234052361388866n,
|
|
187
|
+
expandsDuration: 600n,
|
|
188
|
+
},
|
|
189
|
+
borrowableToken0: {
|
|
190
|
+
available: 941825058374170n,
|
|
191
|
+
expandsTo: 711907234052361388866n,
|
|
192
|
+
expandsDuration: 600n,
|
|
193
|
+
},
|
|
194
|
+
borrowableToken1: {
|
|
195
|
+
available: 941825058374170n,
|
|
196
|
+
expandsTo: 711907234052361388866n,
|
|
197
|
+
expandsDuration: 600n,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const limitsWide: DexLimits = {
|
|
202
|
+
withdrawableToken0: {
|
|
203
|
+
available: BigInt(34242332879776515083099999),
|
|
204
|
+
expandsTo: BigInt(34242332879776515083099999),
|
|
205
|
+
expandsDuration: BigInt(0),
|
|
206
|
+
},
|
|
207
|
+
withdrawableToken1: {
|
|
208
|
+
available: BigInt(34242332879776515083099999),
|
|
209
|
+
expandsTo: BigInt(34242332879776515083099999),
|
|
210
|
+
expandsDuration: BigInt(22),
|
|
211
|
+
},
|
|
212
|
+
borrowableToken0: {
|
|
213
|
+
available: BigInt(34242332879776515083099999),
|
|
214
|
+
expandsTo: BigInt(34242332879776515083099999),
|
|
215
|
+
expandsDuration: BigInt(0),
|
|
216
|
+
},
|
|
217
|
+
borrowableToken1: {
|
|
218
|
+
available: BigInt(34242332879776515083099999),
|
|
219
|
+
expandsTo: BigInt(34242332879776515083099999),
|
|
220
|
+
expandsDuration: BigInt(308),
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const ErrInsufficientBorrowable = new Error('insufficient borrowable');
|
|
225
|
+
const ErrInsufficientMaxPrice = new Error('insufficient max price');
|
|
226
|
+
const ErrInsufficientReserve = new Error('insufficient reserve');
|
|
227
|
+
|
|
228
|
+
describe('TestPoolSimulator_SwapInLimits', () => {
|
|
229
|
+
const network = Network.MAINNET;
|
|
230
|
+
const dexHelper = new DummyDexHelper(network);
|
|
231
|
+
const dexKey = 'FluidDex';
|
|
232
|
+
const fluidDex = new FluidDex(network, dexKey, dexHelper);
|
|
233
|
+
|
|
234
|
+
it('when limits hit', () => {
|
|
235
|
+
let outAmt;
|
|
236
|
+
try {
|
|
237
|
+
outAmt = fluidDex.swapInAdjusted(
|
|
238
|
+
true,
|
|
239
|
+
BigInt(1e15),
|
|
240
|
+
NewColReservesOne(),
|
|
241
|
+
NewDebtReservesOne(),
|
|
242
|
+
18,
|
|
243
|
+
limitsTight,
|
|
244
|
+
Math.floor(Date.now() / 1000) - 10,
|
|
245
|
+
);
|
|
246
|
+
expect(outAmt).toEqual(0n);
|
|
247
|
+
} catch (err: any) {
|
|
248
|
+
expect(err.message).toEqual(ErrInsufficientBorrowable.message);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('when expanded', () => {
|
|
253
|
+
const outAmt = fluidDex.swapInAdjusted(
|
|
254
|
+
true,
|
|
255
|
+
BigInt(1e15),
|
|
256
|
+
NewColReservesOne(),
|
|
257
|
+
NewDebtReservesOne(),
|
|
258
|
+
18,
|
|
259
|
+
limitsTight,
|
|
260
|
+
Math.floor(Date.now() / 1000) - 6000,
|
|
261
|
+
);
|
|
262
|
+
console.log('outAmt: ', outAmt);
|
|
263
|
+
expect(outAmt?.toString()).toEqual('998262697204710');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('when price diff hit', () => {
|
|
267
|
+
let outAmt;
|
|
268
|
+
try {
|
|
269
|
+
outAmt = fluidDex.swapInAdjusted(
|
|
270
|
+
true,
|
|
271
|
+
BigInt(3e16),
|
|
272
|
+
NewColReservesOne(),
|
|
273
|
+
NewDebtReservesOne(),
|
|
274
|
+
18,
|
|
275
|
+
limitsWide,
|
|
276
|
+
Math.floor(Date.now() / 1000) - 10,
|
|
277
|
+
);
|
|
278
|
+
expect(outAmt).toEqual(0n);
|
|
279
|
+
} catch (err: any) {
|
|
280
|
+
expect(err.message).toEqual(ErrInsufficientMaxPrice.message);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('when reserves limit is hit', () => {
|
|
285
|
+
let outAmt;
|
|
286
|
+
try {
|
|
287
|
+
outAmt = fluidDex.swapInAdjusted(
|
|
288
|
+
true,
|
|
289
|
+
BigInt(5e16),
|
|
290
|
+
NewColReservesOne(),
|
|
291
|
+
NewDebtReservesOne(),
|
|
292
|
+
18,
|
|
293
|
+
limitsWide,
|
|
294
|
+
Math.floor(Date.now() / 1000) - 10,
|
|
295
|
+
);
|
|
296
|
+
expect(outAmt).toEqual(0n);
|
|
297
|
+
} catch (err: any) {
|
|
298
|
+
expect(err.message).toEqual(ErrInsufficientReserve.message);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
});
|
|
@@ -38,9 +38,7 @@ describe('FluidDex EventPool Mainnet', function () {
|
|
|
38
38
|
const eventsToTest: Record<Address, EventMappings> = {
|
|
39
39
|
'0x52aa899454998be5b000ad077a46bbe360f4e497': {
|
|
40
40
|
LogOperate: [
|
|
41
|
-
|
|
42
|
-
21092142, 21092176, 21092187, 21092230, 21092286, 21092289, 21092295,
|
|
43
|
-
21092319, 21092352, 21092360, 21092368, 21092378, 21092383,
|
|
41
|
+
21190399, 21190405, 21190420, 21190452, 21190454, 21190465, 21190506,
|
|
44
42
|
],
|
|
45
43
|
},
|
|
46
44
|
};
|
|
@@ -86,7 +84,7 @@ describe('FluidDex EventPool Mainnet', function () {
|
|
|
86
84
|
|
|
87
85
|
const eventsToTest: Record<Address, EventMappings> = {
|
|
88
86
|
'0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085': {
|
|
89
|
-
LogDexDeployed: [
|
|
87
|
+
LogDexDeployed: [21199929],
|
|
90
88
|
},
|
|
91
89
|
};
|
|
92
90
|
|
|
@@ -39,14 +39,13 @@ function getReaderCalldata(
|
|
|
39
39
|
const pool = pools.find(
|
|
40
40
|
item => item.address.toLowerCase() === poolAddress.toLowerCase(),
|
|
41
41
|
);
|
|
42
|
-
|
|
43
42
|
return amounts.map(amount => ({
|
|
44
43
|
target: exchangeAddress,
|
|
45
44
|
callData: readerIface.encodeFunctionData(funcName, [
|
|
46
45
|
poolAddress,
|
|
47
46
|
pool!.token0.toLowerCase() === srcToken.toLowerCase() ? true : false,
|
|
48
47
|
amount,
|
|
49
|
-
|
|
48
|
+
0,
|
|
50
49
|
]),
|
|
51
50
|
}));
|
|
52
51
|
}
|
|
@@ -71,7 +70,7 @@ async function checkOnChainPricing(
|
|
|
71
70
|
dexHelper: DummyDexHelper,
|
|
72
71
|
srcToken: string,
|
|
73
72
|
) {
|
|
74
|
-
const resolverAddress = '
|
|
73
|
+
const resolverAddress = '0x45f4ad57e300da55c33dea579a40fcee000d7b94';
|
|
75
74
|
|
|
76
75
|
const readerIface = new Interface(ResolverABI);
|
|
77
76
|
|
|
@@ -110,7 +109,16 @@ async function checkOnChainPricing(
|
|
|
110
109
|
decodeReaderResult(readerResult, readerIface, funcName),
|
|
111
110
|
);
|
|
112
111
|
|
|
113
|
-
expect(
|
|
112
|
+
expect(
|
|
113
|
+
prices.every((price, index) => {
|
|
114
|
+
const expectedPrice = expectedPrices[index];
|
|
115
|
+
if (expectedPrice === 0n) {
|
|
116
|
+
return price === 0n;
|
|
117
|
+
}
|
|
118
|
+
const percentDiff = ((price - expectedPrice) * 100n) / expectedPrice;
|
|
119
|
+
return percentDiff <= 0.01 && percentDiff >= -0.01;
|
|
120
|
+
}),
|
|
121
|
+
).toBe(true);
|
|
114
122
|
}
|
|
115
123
|
|
|
116
124
|
async function testPricingOnNetwork(
|
|
@@ -197,7 +205,7 @@ describe('FluidDex', function () {
|
|
|
197
205
|
const tokenASymbol = 'wstETH';
|
|
198
206
|
const tokenBSymbol = 'ETH';
|
|
199
207
|
|
|
200
|
-
const
|
|
208
|
+
const amountsForSwap = [
|
|
201
209
|
0n,
|
|
202
210
|
1n * BI_POWS[18],
|
|
203
211
|
2n * BI_POWS[18],
|
|
@@ -220,12 +228,27 @@ describe('FluidDex', function () {
|
|
|
220
228
|
tokenASymbol,
|
|
221
229
|
tokenBSymbol,
|
|
222
230
|
SwapSide.SELL,
|
|
223
|
-
|
|
231
|
+
amountsForSwap,
|
|
224
232
|
'estimateSwapIn',
|
|
225
233
|
dexHelper,
|
|
226
234
|
);
|
|
227
235
|
});
|
|
228
236
|
|
|
237
|
+
it('wstETH -> ETH, getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
238
|
+
await testPricingOnNetwork(
|
|
239
|
+
fluidDex,
|
|
240
|
+
network,
|
|
241
|
+
dexKey,
|
|
242
|
+
blockNumber,
|
|
243
|
+
tokenASymbol,
|
|
244
|
+
tokenBSymbol,
|
|
245
|
+
SwapSide.BUY,
|
|
246
|
+
amountsForSwap,
|
|
247
|
+
'estimateSwapOut',
|
|
248
|
+
dexHelper,
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
|
|
229
252
|
it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
230
253
|
await testPricingOnNetwork(
|
|
231
254
|
fluidDex,
|
|
@@ -235,18 +258,33 @@ describe('FluidDex', function () {
|
|
|
235
258
|
tokenBSymbol,
|
|
236
259
|
tokenASymbol,
|
|
237
260
|
SwapSide.SELL,
|
|
238
|
-
|
|
261
|
+
amountsForSwap,
|
|
239
262
|
'estimateSwapIn',
|
|
240
263
|
dexHelper,
|
|
241
264
|
);
|
|
242
265
|
});
|
|
266
|
+
|
|
267
|
+
it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
268
|
+
await testPricingOnNetwork(
|
|
269
|
+
fluidDex,
|
|
270
|
+
network,
|
|
271
|
+
dexKey,
|
|
272
|
+
blockNumber,
|
|
273
|
+
tokenBSymbol,
|
|
274
|
+
tokenASymbol,
|
|
275
|
+
SwapSide.BUY,
|
|
276
|
+
amountsForSwap,
|
|
277
|
+
'estimateSwapOut',
|
|
278
|
+
dexHelper,
|
|
279
|
+
);
|
|
280
|
+
});
|
|
243
281
|
});
|
|
244
282
|
|
|
245
283
|
describe('USDC -> USDT', () => {
|
|
246
284
|
const tokenASymbol = 'USDC';
|
|
247
285
|
const tokenBSymbol = 'USDT';
|
|
248
286
|
|
|
249
|
-
const
|
|
287
|
+
const amountsForSwap = [
|
|
250
288
|
0n,
|
|
251
289
|
10n * BI_POWS[6],
|
|
252
290
|
20n * BI_POWS[6],
|
|
@@ -258,7 +296,7 @@ describe('FluidDex', function () {
|
|
|
258
296
|
80n * BI_POWS[6],
|
|
259
297
|
90n * BI_POWS[6],
|
|
260
298
|
100n * BI_POWS[6],
|
|
261
|
-
|
|
299
|
+
1000n * BI_POWS[6],
|
|
262
300
|
];
|
|
263
301
|
|
|
264
302
|
it('USDC -> USDT getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
@@ -270,12 +308,27 @@ describe('FluidDex', function () {
|
|
|
270
308
|
tokenASymbol,
|
|
271
309
|
tokenBSymbol,
|
|
272
310
|
SwapSide.SELL,
|
|
273
|
-
|
|
311
|
+
amountsForSwap,
|
|
274
312
|
'estimateSwapIn',
|
|
275
313
|
dexHelper,
|
|
276
314
|
);
|
|
277
315
|
});
|
|
278
316
|
|
|
317
|
+
it('USDC -> USDT getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
318
|
+
await testPricingOnNetwork(
|
|
319
|
+
fluidDex,
|
|
320
|
+
network,
|
|
321
|
+
dexKey,
|
|
322
|
+
blockNumber,
|
|
323
|
+
tokenASymbol,
|
|
324
|
+
tokenBSymbol,
|
|
325
|
+
SwapSide.BUY,
|
|
326
|
+
amountsForSwap,
|
|
327
|
+
'estimateSwapOut',
|
|
328
|
+
dexHelper,
|
|
329
|
+
);
|
|
330
|
+
});
|
|
331
|
+
|
|
279
332
|
it('USDT -> USDC getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
280
333
|
await testPricingOnNetwork(
|
|
281
334
|
fluidDex,
|
|
@@ -285,11 +338,26 @@ describe('FluidDex', function () {
|
|
|
285
338
|
tokenBSymbol,
|
|
286
339
|
tokenASymbol,
|
|
287
340
|
SwapSide.SELL,
|
|
288
|
-
|
|
341
|
+
amountsForSwap,
|
|
289
342
|
'estimateSwapIn',
|
|
290
343
|
dexHelper,
|
|
291
344
|
);
|
|
292
345
|
});
|
|
346
|
+
|
|
347
|
+
it('USDT -> USDC getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
348
|
+
await testPricingOnNetwork(
|
|
349
|
+
fluidDex,
|
|
350
|
+
network,
|
|
351
|
+
dexKey,
|
|
352
|
+
blockNumber,
|
|
353
|
+
tokenBSymbol,
|
|
354
|
+
tokenASymbol,
|
|
355
|
+
SwapSide.BUY,
|
|
356
|
+
amountsForSwap,
|
|
357
|
+
'estimateSwapOut',
|
|
358
|
+
dexHelper,
|
|
359
|
+
);
|
|
360
|
+
});
|
|
293
361
|
});
|
|
294
362
|
});
|
|
295
363
|
});
|
|
@@ -140,6 +140,7 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
|
|
|
140
140
|
feeHex,
|
|
141
141
|
collateralReservesHex,
|
|
142
142
|
debtReservesHex,
|
|
143
|
+
dexLimitsHex,
|
|
143
144
|
] = poolReserve;
|
|
144
145
|
|
|
145
146
|
const fee = Number(feeHex.toString());
|
|
@@ -160,6 +161,37 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
|
|
|
160
161
|
token1ImaginaryReserves: bigIntify(debtReservesHex[5]),
|
|
161
162
|
};
|
|
162
163
|
|
|
164
|
+
const withdrawableToken0 = {
|
|
165
|
+
available: bigIntify(dexLimitsHex[0][0]),
|
|
166
|
+
expandsTo: bigIntify(dexLimitsHex[0][1]),
|
|
167
|
+
expandsDuration: bigIntify(dexLimitsHex[0][2]),
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const withdrawableToken1 = {
|
|
171
|
+
available: bigIntify(dexLimitsHex[1][0]),
|
|
172
|
+
expandsTo: bigIntify(dexLimitsHex[1][1]),
|
|
173
|
+
expandsDuration: bigIntify(dexLimitsHex[1][2]),
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const borrowableToken0 = {
|
|
177
|
+
available: bigIntify(dexLimitsHex[2][0]),
|
|
178
|
+
expandsTo: bigIntify(dexLimitsHex[2][1]),
|
|
179
|
+
expandsDuration: bigIntify(dexLimitsHex[2][2]),
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const borrowableToken1 = {
|
|
183
|
+
available: bigIntify(dexLimitsHex[3][0]),
|
|
184
|
+
expandsTo: bigIntify(dexLimitsHex[3][1]),
|
|
185
|
+
expandsDuration: bigIntify(dexLimitsHex[3][2]),
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const dexLimits = {
|
|
189
|
+
withdrawableToken0,
|
|
190
|
+
withdrawableToken1,
|
|
191
|
+
borrowableToken0,
|
|
192
|
+
borrowableToken1,
|
|
193
|
+
};
|
|
194
|
+
|
|
163
195
|
return {
|
|
164
196
|
pool,
|
|
165
197
|
token0,
|
|
@@ -167,6 +199,7 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
|
|
|
167
199
|
fee,
|
|
168
200
|
collateralReserves,
|
|
169
201
|
debtReserves,
|
|
202
|
+
dexLimits,
|
|
170
203
|
};
|
|
171
204
|
});
|
|
172
205
|
|