@paraswap/dex-lib 3.10.0 → 3.10.2
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/dexFactory.abi.json +506 -0
- package/build/abi/fluid-dex/fluid-dex.abi.json +922 -0
- package/build/abi/fluid-dex/liquidityUserModule.abi.json +145 -0
- package/build/abi/fluid-dex/resolver.abi.json +999 -0
- package/build/dex/fluid-dex/config.d.ts +4 -0
- package/build/dex/fluid-dex/config.js +20 -0
- package/build/dex/fluid-dex/config.js.map +1 -0
- package/build/dex/fluid-dex/fluid-dex-factory.d.ts +49 -0
- package/build/dex/fluid-dex/fluid-dex-factory.js +104 -0
- package/build/dex/fluid-dex/fluid-dex-factory.js.map +1 -0
- package/build/dex/fluid-dex/fluid-dex-pool.d.ts +47 -0
- package/build/dex/fluid-dex/fluid-dex-pool.js +119 -0
- package/build/dex/fluid-dex/fluid-dex-pool.js.map +1 -0
- package/build/dex/fluid-dex/fluid-dex.d.ts +127 -0
- package/build/dex/fluid-dex/fluid-dex.js +502 -0
- package/build/dex/fluid-dex/fluid-dex.js.map +1 -0
- package/build/dex/fluid-dex/types.d.ts +52 -0
- package/build/dex/fluid-dex/types.js +3 -0
- package/build/dex/fluid-dex/types.js.map +1 -0
- package/build/dex/fluid-dex/utils.d.ts +2 -0
- package/build/dex/fluid-dex/utils.js +18 -0
- package/build/dex/fluid-dex/utils.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js +1 -1
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/fluid-dex/dexFactory.abi.json +506 -0
- package/src/abi/fluid-dex/fluid-dex.abi.json +922 -0
- package/src/abi/fluid-dex/liquidityUserModule.abi.json +145 -0
- package/src/abi/fluid-dex/resolver.abi.json +999 -0
- package/src/dex/fluid-dex/config.ts +20 -0
- package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +153 -0
- package/src/dex/fluid-dex/fluid-dex-events.test.ts +293 -0
- package/src/dex/fluid-dex/fluid-dex-factory.ts +143 -0
- package/src/dex/fluid-dex/fluid-dex-integration.test.ts +299 -0
- package/src/dex/fluid-dex/fluid-dex-pool.ts +178 -0
- package/src/dex/fluid-dex/fluid-dex.ts +790 -0
- package/src/dex/fluid-dex/types.ts +62 -0
- package/src/dex/fluid-dex/utils.ts +15 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +1 -1
- package/tests/constants-e2e.ts +2 -2
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.FluidDex = void 0;
|
|
30
|
+
const abi_1 = require("@ethersproject/abi");
|
|
31
|
+
const constants_1 = require("../../constants");
|
|
32
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
33
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
34
|
+
const fluid_dex_abi_json_1 = __importDefault(require("../../abi/fluid-dex/fluid-dex.abi.json"));
|
|
35
|
+
const config_1 = require("./config");
|
|
36
|
+
const fluid_dex_pool_1 = require("./fluid-dex-pool");
|
|
37
|
+
const fluid_dex_factory_1 = require("./fluid-dex-factory");
|
|
38
|
+
const utils_1 = require("../../utils");
|
|
39
|
+
const utils_2 = require("../../executor/utils");
|
|
40
|
+
const decoders_1 = require("../../lib/decoders");
|
|
41
|
+
const ethers_1 = require("ethers");
|
|
42
|
+
const utils_3 = require("./utils");
|
|
43
|
+
class FluidDex extends simple_exchange_1.SimpleExchange {
|
|
44
|
+
constructor(network, dexKey, dexHelper) {
|
|
45
|
+
super(dexHelper, dexKey);
|
|
46
|
+
this.network = network;
|
|
47
|
+
this.dexKey = dexKey;
|
|
48
|
+
this.dexHelper = dexHelper;
|
|
49
|
+
this.eventPools = {};
|
|
50
|
+
this.hasConstantPriceLargeAmounts = false;
|
|
51
|
+
this.needWrapNative = false;
|
|
52
|
+
this.isFeeOnTransferSupported = false;
|
|
53
|
+
this.pools = [];
|
|
54
|
+
this.FEE_100_PERCENT = BigInt(1000000);
|
|
55
|
+
this.decodePools = (result) => {
|
|
56
|
+
return (0, decoders_1.generalDecoder)(result, ['tuple(address pool, address token0, address token1)[]'], undefined, decoded => {
|
|
57
|
+
return decoded.map((decodedPool) => ({
|
|
58
|
+
address: decodedPool[0][0].toLowerCase(),
|
|
59
|
+
token0: decodedPool[0][1].toLowerCase(),
|
|
60
|
+
token1: decodedPool[0][2].toLowerCase(),
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
65
|
+
this.factory = new fluid_dex_factory_1.FluidDexFactory('FluidDex', config_1.FluidDexConfig['FluidDex'][network].commonAddresses, network, dexHelper, this.logger);
|
|
66
|
+
this.fluidDexPoolIface = new abi_1.Interface(fluid_dex_abi_json_1.default);
|
|
67
|
+
}
|
|
68
|
+
async fetchFluidDexPools(blockNumber) {
|
|
69
|
+
const poolsFromResolver = await this.factory.getStateOrGenerate(blockNumber, false);
|
|
70
|
+
return poolsFromResolver.map(pool => ({
|
|
71
|
+
id: `FluidDex_${pool.address.toLowerCase()}`,
|
|
72
|
+
address: pool.address.toLowerCase(),
|
|
73
|
+
token0: pool.token0.toLowerCase(),
|
|
74
|
+
token1: pool.token1.toLowerCase(),
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
// Initialize pricing is called once in the start of
|
|
78
|
+
// pricing service. It is intended to setup the integration
|
|
79
|
+
// for pricing requests. It is optional for a DEX to
|
|
80
|
+
// implement this function
|
|
81
|
+
async initializePricing(blockNumber) {
|
|
82
|
+
await this.factory.initialize(blockNumber);
|
|
83
|
+
this.pools = await this.fetchFluidDexPools(blockNumber);
|
|
84
|
+
for (const pool of this.pools) {
|
|
85
|
+
if (!this.eventPools[pool.id]) {
|
|
86
|
+
this.eventPools[pool.id] = new fluid_dex_pool_1.FluidDexEventPool('FluidDex', pool.address, this.factory.commonAddresses, this.network, this.dexHelper, this.logger);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
await Promise.all(Object.values(this.eventPools).map(async (eventPool) => {
|
|
90
|
+
return eventPool.initialize(blockNumber);
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
getAdapters(side) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
// Returns list of pool identifiers that can be used
|
|
97
|
+
// for a given swap. poolIdentifiers must be unique
|
|
98
|
+
// across DEXes. It is recommended to use
|
|
99
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
100
|
+
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
101
|
+
if (side === constants_1.SwapSide.BUY)
|
|
102
|
+
return [];
|
|
103
|
+
const pool = await this.getPoolByTokenPair(srcToken.address, destToken.address);
|
|
104
|
+
return pool ? [pool.id] : [];
|
|
105
|
+
}
|
|
106
|
+
async getPoolByTokenPair(srcToken, destToken) {
|
|
107
|
+
const srcAddress = srcToken.toLowerCase();
|
|
108
|
+
const destAddress = destToken.toLowerCase();
|
|
109
|
+
// A pair must have 2 different tokens.
|
|
110
|
+
if (srcAddress === destAddress)
|
|
111
|
+
return null;
|
|
112
|
+
for (const pool of this.pools) {
|
|
113
|
+
if ((srcAddress === pool.token0 && destAddress === pool.token1) ||
|
|
114
|
+
(srcAddress === pool.token1 && destAddress === pool.token0)) {
|
|
115
|
+
return pool;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
// Returns pool prices for amounts.
|
|
121
|
+
// If limitPools is defined only pools in limitPools
|
|
122
|
+
// should be used. If limitPools is undefined then
|
|
123
|
+
// any pools can be used.
|
|
124
|
+
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
125
|
+
try {
|
|
126
|
+
if (srcToken.address.toLowerCase() === destToken.address.toLowerCase())
|
|
127
|
+
return null;
|
|
128
|
+
if (side === constants_1.SwapSide.BUY)
|
|
129
|
+
return null;
|
|
130
|
+
// Get the pool to use.
|
|
131
|
+
const pool = await this.getPoolByTokenPair(srcToken.address, destToken.address);
|
|
132
|
+
if (!pool)
|
|
133
|
+
return null;
|
|
134
|
+
// Make sure the pool meets the optional limitPools filter.
|
|
135
|
+
if (limitPools && !limitPools.includes(pool.id))
|
|
136
|
+
return null;
|
|
137
|
+
const eventPool = this.eventPools[pool.id];
|
|
138
|
+
if (!eventPool) {
|
|
139
|
+
this.logger.error(`fluid-dex pool ${pool.id}: No EventPool found.`);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const state = await eventPool.getState(blockNumber);
|
|
143
|
+
if (!state)
|
|
144
|
+
return null;
|
|
145
|
+
const prices = amounts.map(amount => {
|
|
146
|
+
return this.swapIn(srcToken.address.toLowerCase() === pool.token0.toLowerCase(), amount, state.collateralReserves, state.debtReserves, srcToken.decimals, destToken.decimals, BigInt(state.fee));
|
|
147
|
+
});
|
|
148
|
+
return [
|
|
149
|
+
{
|
|
150
|
+
prices: prices,
|
|
151
|
+
unit: (0, utils_1.getBigIntPow)((side === constants_1.SwapSide.SELL ? destToken : srcToken).decimals),
|
|
152
|
+
data: {
|
|
153
|
+
colReserves: state.collateralReserves,
|
|
154
|
+
debtReserves: state.debtReserves,
|
|
155
|
+
exchange: this.dexKey,
|
|
156
|
+
},
|
|
157
|
+
exchange: this.dexKey,
|
|
158
|
+
poolIdentifier: pool.id,
|
|
159
|
+
gasCost: config_1.FLUID_DEX_GAS_COST,
|
|
160
|
+
poolAddresses: [pool.address],
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
this.logger.error(`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${destToken.address || destToken.symbol}, ${side}:`, e);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
170
|
+
getCalldataGasCost(poolPrices) {
|
|
171
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
172
|
+
}
|
|
173
|
+
// Encode params required by the exchange adapter
|
|
174
|
+
// V5: Used for multiSwap, buy & megaSwap
|
|
175
|
+
// V6: Not used, can be left blank
|
|
176
|
+
// Hint: abiCoder.encodeParameter() could be useful
|
|
177
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
178
|
+
if (side === constants_1.SwapSide.BUY)
|
|
179
|
+
throw new Error(`Buy not supported`);
|
|
180
|
+
const { exchange } = data;
|
|
181
|
+
// Encode here the payload for adapter
|
|
182
|
+
const payload = '';
|
|
183
|
+
return {
|
|
184
|
+
targetExchange: exchange,
|
|
185
|
+
payload,
|
|
186
|
+
networkFee: '0',
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
// Returns list of top pools based on liquidity. Max
|
|
190
|
+
// limit number pools should be returned.
|
|
191
|
+
async getTopPoolsForToken(tokenAddress, limit) {
|
|
192
|
+
//@TODO
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
async getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, context, executorAddress) {
|
|
196
|
+
if (side === constants_1.SwapSide.BUY)
|
|
197
|
+
throw new Error(`Buy not supported`);
|
|
198
|
+
let args;
|
|
199
|
+
let returnAmountPos;
|
|
200
|
+
const method = 'swapIn';
|
|
201
|
+
returnAmountPos = (0, utils_2.extractReturnAmountPosition)(this.fluidDexPoolIface, method, 'amountOut_', 1);
|
|
202
|
+
const pool = await this.getPoolByTokenPair(srcToken, destToken);
|
|
203
|
+
if (pool.token0.toLowerCase() !== srcToken.toLowerCase()) {
|
|
204
|
+
args = [false, BigInt(srcAmount), BigInt(destAmount), recipient];
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
args = [true, BigInt(srcAmount), BigInt(destAmount), recipient];
|
|
208
|
+
}
|
|
209
|
+
const swapData = this.fluidDexPoolIface.encodeFunctionData(method, args);
|
|
210
|
+
return {
|
|
211
|
+
needWrapNative: this.needWrapNative,
|
|
212
|
+
dexFuncHasRecipient: true,
|
|
213
|
+
exchangeData: swapData,
|
|
214
|
+
targetExchange: pool.address,
|
|
215
|
+
returnAmountPos,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Calculates the output amount for a given input amount in a swap operation.
|
|
220
|
+
* @param swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
221
|
+
* @param amountIn - The amount of input token to be swapped (as a BigInt).
|
|
222
|
+
* @param colReserves - The reserves of the collateral pool.
|
|
223
|
+
* @param debtReserves - The reserves of the debt pool.
|
|
224
|
+
* @param inDecimals - The number of decimals for the input token.
|
|
225
|
+
* @param outDecimals - The number of decimals for the output token.
|
|
226
|
+
* @returns The calculated output amount (as a BigInt).
|
|
227
|
+
*/
|
|
228
|
+
swapIn(swap0To1, amountIn, colReserves, debtReserves, inDecimals, outDecimals, fee) {
|
|
229
|
+
if (amountIn === 0n) {
|
|
230
|
+
return 0n; // Return 0 if input amount is 0
|
|
231
|
+
}
|
|
232
|
+
if (colReserves.token0RealReserves + debtReserves.token0RealReserves == 0n &&
|
|
233
|
+
colReserves.token1RealReserves + debtReserves.token1RealReserves == 0n) {
|
|
234
|
+
return 0n;
|
|
235
|
+
}
|
|
236
|
+
const amountInAdjusted = (amountIn * BigInt(10 ** 12)) / BigInt(10 ** inDecimals);
|
|
237
|
+
const amountOut = this.swapInAdjusted(swap0To1, amountInAdjusted, // Convert back to number for internal calculations
|
|
238
|
+
colReserves, debtReserves, fee);
|
|
239
|
+
const result = (amountOut * BigInt(10 ** outDecimals)) / BigInt(10 ** 12);
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Calculates the output amount for a given input amount in a swap operation.
|
|
244
|
+
* @param swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
245
|
+
* @param amountToSwap - The amount of input token to be swapped.
|
|
246
|
+
* @param colReserves - The reserves of the collateral pool.
|
|
247
|
+
* @param debtReserves - The reserves of the debt pool.
|
|
248
|
+
* @returns The calculated output amount.
|
|
249
|
+
*/
|
|
250
|
+
swapInAdjusted(swap0To1, amountToSwap, colReserves, debtReserves, fee) {
|
|
251
|
+
const { token0RealReserves, token1RealReserves, token0ImaginaryReserves, token1ImaginaryReserves, } = colReserves;
|
|
252
|
+
const { token0RealReserves: debtToken0RealReserves, token1RealReserves: debtToken1RealReserves, token0ImaginaryReserves: debtToken0ImaginaryReserves, token1ImaginaryReserves: debtToken1ImaginaryReserves, } = debtReserves;
|
|
253
|
+
// Check if all reserves of collateral pool are greater than 0
|
|
254
|
+
const colPoolEnabled = token0RealReserves > BigInt(0) &&
|
|
255
|
+
token1RealReserves > BigInt(0) &&
|
|
256
|
+
token0ImaginaryReserves > BigInt(0) &&
|
|
257
|
+
token1ImaginaryReserves > BigInt(0);
|
|
258
|
+
// Check if all reserves of debt pool are greater than 0
|
|
259
|
+
const debtPoolEnabled = debtToken0RealReserves > BigInt(0) &&
|
|
260
|
+
debtToken1RealReserves > BigInt(0) &&
|
|
261
|
+
debtToken0ImaginaryReserves > BigInt(0) &&
|
|
262
|
+
debtToken1ImaginaryReserves > BigInt(0);
|
|
263
|
+
let colReserveIn, colReserveOut, debtReserveIn, debtReserveOut;
|
|
264
|
+
let colIReserveIn, colIReserveOut, debtIReserveIn, debtIReserveOut;
|
|
265
|
+
if (swap0To1) {
|
|
266
|
+
colReserveIn = token0RealReserves;
|
|
267
|
+
colReserveOut = token1RealReserves;
|
|
268
|
+
colIReserveIn = token0ImaginaryReserves;
|
|
269
|
+
colIReserveOut = token1ImaginaryReserves;
|
|
270
|
+
debtReserveIn = debtToken0RealReserves;
|
|
271
|
+
debtReserveOut = debtToken1RealReserves;
|
|
272
|
+
debtIReserveIn = debtToken0ImaginaryReserves;
|
|
273
|
+
debtIReserveOut = debtToken1ImaginaryReserves;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
colReserveIn = token1RealReserves;
|
|
277
|
+
colReserveOut = token0RealReserves;
|
|
278
|
+
colIReserveIn = token1ImaginaryReserves;
|
|
279
|
+
colIReserveOut = token0ImaginaryReserves;
|
|
280
|
+
debtReserveIn = debtToken1RealReserves;
|
|
281
|
+
debtReserveOut = debtToken0RealReserves;
|
|
282
|
+
debtIReserveIn = debtToken1ImaginaryReserves;
|
|
283
|
+
debtIReserveOut = debtToken0ImaginaryReserves;
|
|
284
|
+
}
|
|
285
|
+
let a;
|
|
286
|
+
if (colPoolEnabled && debtPoolEnabled) {
|
|
287
|
+
a = this.swapRoutingIn(amountToSwap, colIReserveOut, colIReserveIn, debtIReserveOut, debtIReserveIn);
|
|
288
|
+
}
|
|
289
|
+
else if (debtPoolEnabled) {
|
|
290
|
+
a = BigInt(-1); // Route from debt pool
|
|
291
|
+
}
|
|
292
|
+
else if (colPoolEnabled) {
|
|
293
|
+
a = amountToSwap + BigInt(1); // Route from collateral pool
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
throw new Error('No pools are enabled');
|
|
297
|
+
}
|
|
298
|
+
let amountOutCollateral = BigInt(0);
|
|
299
|
+
let amountOutDebt = BigInt(0);
|
|
300
|
+
if (a <= BigInt(0)) {
|
|
301
|
+
// Entire trade routes through debt pool
|
|
302
|
+
amountOutDebt = this.getAmountOut(this.applyFee(amountToSwap, fee), debtIReserveIn, debtIReserveOut);
|
|
303
|
+
}
|
|
304
|
+
else if (a >= amountToSwap) {
|
|
305
|
+
// Entire trade routes through collateral pool
|
|
306
|
+
amountOutCollateral = this.getAmountOut(this.applyFee(amountToSwap, fee), colIReserveIn, colIReserveOut);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
// Trade routes through both pools
|
|
310
|
+
amountOutCollateral = this.getAmountOut(this.applyFee(a, fee), colIReserveIn, colIReserveOut);
|
|
311
|
+
amountOutDebt = this.getAmountOut(this.applyFee(amountToSwap - a, fee), debtIReserveIn, debtIReserveOut);
|
|
312
|
+
}
|
|
313
|
+
if (amountOutDebt > debtReserveOut) {
|
|
314
|
+
return 0n;
|
|
315
|
+
}
|
|
316
|
+
if (amountOutCollateral > colReserveOut) {
|
|
317
|
+
return 0n;
|
|
318
|
+
}
|
|
319
|
+
const totalAmountOut = amountOutCollateral + amountOutDebt;
|
|
320
|
+
return totalAmountOut;
|
|
321
|
+
}
|
|
322
|
+
applyFee(amount, fee) {
|
|
323
|
+
return (amount * (this.FEE_100_PERCENT - fee)) / this.FEE_100_PERCENT;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Given an input amount of asset and pair reserves, returns the maximum output amount of the other asset.
|
|
327
|
+
* @param amountIn - The amount of input asset.
|
|
328
|
+
* @param iReserveIn - Imaginary token reserve with input amount.
|
|
329
|
+
* @param iReserveOut - Imaginary token reserve of output amount.
|
|
330
|
+
* @returns The maximum output amount of the other asset.
|
|
331
|
+
*/
|
|
332
|
+
getAmountOut(amountIn, iReserveIn, iReserveOut) {
|
|
333
|
+
// Both numerator and denominator are scaled to 1e6 to factor in fee scaling.
|
|
334
|
+
const numerator = amountIn * iReserveOut;
|
|
335
|
+
const denominator = iReserveIn + amountIn;
|
|
336
|
+
// Using the swap formula: (AmountIn * iReserveY) / (iReserveX + AmountIn)
|
|
337
|
+
// We use division with rounding down, which is the default for bigint division
|
|
338
|
+
return numerator / denominator;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Given an output amount of asset and pair reserves, returns the input amount of the other asset
|
|
342
|
+
* @param amountOut - Desired output amount of the asset.
|
|
343
|
+
* @param iReserveIn - Imaginary token reserve of input amount.
|
|
344
|
+
* @param iReserveOut - Imaginary token reserve of output amount.
|
|
345
|
+
* @returns The input amount of the other asset.
|
|
346
|
+
*/
|
|
347
|
+
getAmountIn(amountOut, iReserveIn, iReserveOut) {
|
|
348
|
+
// Both numerator and denominator are scaled to 1e6 to factor in fee scaling.
|
|
349
|
+
const numerator = amountOut * iReserveIn;
|
|
350
|
+
const denominator = iReserveOut - amountOut;
|
|
351
|
+
// Using the swap formula: (AmountOut * iReserveX) / (iReserveY - AmountOut)
|
|
352
|
+
return numerator / denominator;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Calculates how much of a swap should go through the collateral pool for output amount.
|
|
356
|
+
* @param t - Total amount out.
|
|
357
|
+
* @param x - Imaginary reserves of token in of collateral.
|
|
358
|
+
* @param y - Imaginary reserves of token out of collateral.
|
|
359
|
+
* @param x2 - Imaginary reserves of token in of debt.
|
|
360
|
+
* @param y2 - Imaginary reserves of token out of debt.
|
|
361
|
+
* @returns How much swap should go through collateral pool. Remaining will go from debt.
|
|
362
|
+
* @note If a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool.
|
|
363
|
+
* @note If a > t then entire trade route through col pool and col pool arbitrage with debt pool.
|
|
364
|
+
* @note If a > 0 & a < t then swap will route through both pools.
|
|
365
|
+
*/
|
|
366
|
+
swapRoutingOut(t, x, y, x2, y2) {
|
|
367
|
+
// Adding 1e18 precision
|
|
368
|
+
const xyRoot = BigInt(Math.floor(Math.sqrt(Number(x * y * BigInt(10n ** 18n)))));
|
|
369
|
+
const x2y2Root = BigInt(Math.floor(Math.sqrt(Number(x2 * y2 * BigInt(10n ** 18n)))));
|
|
370
|
+
// 1e18 precision gets cancelled out in division
|
|
371
|
+
const numerator = t * xyRoot + y * x2y2Root - y2 * xyRoot;
|
|
372
|
+
const denominator = xyRoot + x2y2Root;
|
|
373
|
+
// Use integer division (rounds down)
|
|
374
|
+
const a = numerator / denominator;
|
|
375
|
+
return a;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Calculates how much of a swap should go through the collateral pool.
|
|
379
|
+
* @param t - Total amount in.
|
|
380
|
+
* @param x - Imaginary reserves of token out of collateral.
|
|
381
|
+
* @param y - Imaginary reserves of token in of collateral.
|
|
382
|
+
* @param x2 - Imaginary reserves of token out of debt.
|
|
383
|
+
* @param y2 - Imaginary reserves of token in of debt.
|
|
384
|
+
* @returns How much swap should go through collateral pool. Remaining will go from debt.
|
|
385
|
+
* @note If a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool.
|
|
386
|
+
* @note If a > t then entire trade route through col pool and col pool arbitrage with debt pool.
|
|
387
|
+
* @note If a > 0 & a < t then swap will route through both pools.
|
|
388
|
+
*/
|
|
389
|
+
swapRoutingIn(t, x, y, x2, y2) {
|
|
390
|
+
// Adding 1e18 precision
|
|
391
|
+
const xyRoot = (0, utils_3.sqrt)(ethers_1.BigNumber.from(x).mul(y).mul(BigInt(1e18))).toBigInt();
|
|
392
|
+
const x2y2Root = (0, utils_3.sqrt)(ethers_1.BigNumber.from(x2).mul(y2).mul(BigInt(1e18))).toBigInt();
|
|
393
|
+
// Calculating 'a' using the given formula
|
|
394
|
+
const a = (y2 * xyRoot + t * xyRoot - y * x2y2Root) / (xyRoot + x2y2Root);
|
|
395
|
+
return a;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Calculates the input amount for a given output amount in a swap operation.
|
|
399
|
+
* @param {boolean} swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
400
|
+
* @param {bigint} amountOut - The amount of output token to be swapped.
|
|
401
|
+
* @param {Reserves} colReserves - The reserves of the collateral pool.
|
|
402
|
+
* @param {Reserves} debtReserves - The reserves of the debt pool.
|
|
403
|
+
* @param {number} inDecimals - The number of decimals for the input token.
|
|
404
|
+
* @param {number} outDecimals - The number of decimals for the output token.
|
|
405
|
+
* @param {number} fee - The fee for the swap. 1e4 = 1%
|
|
406
|
+
* @returns {bigint} amountIn - The calculated input amount required for the swap.
|
|
407
|
+
*/
|
|
408
|
+
swapOut(swap0to1, amountOut, colReserves, debtReserves, inDecimals, outDecimals, fee) {
|
|
409
|
+
const amountOutAdjusted = (amountOut * BigInt(10 ** 12)) / BigInt(10 ** outDecimals);
|
|
410
|
+
const amountIn = this.swapOutAdjusted(swap0to1, amountOutAdjusted, colReserves, debtReserves);
|
|
411
|
+
const FEE_100_PERCENT = BigInt(1e6); // Assuming this constant is defined elsewhere
|
|
412
|
+
const result = ((amountIn * FEE_100_PERCENT) / (FEE_100_PERCENT - fee)) *
|
|
413
|
+
BigInt(10 ** (inDecimals - 12));
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Calculates the input amount for a given output amount in a swap operation.
|
|
418
|
+
* @param {boolean} swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise.
|
|
419
|
+
* @param {bigint} amountOut - The amount of output token to be swapped.
|
|
420
|
+
* @param {CollateralReserves} colReserves - The reserves of the collateral pool.
|
|
421
|
+
* @param {DebtReserves} debtReserves - The reserves of the debt pool.
|
|
422
|
+
* @returns {bigint} The calculated input amount required for the swap.
|
|
423
|
+
*/
|
|
424
|
+
swapOutAdjusted(swap0to1, amountOut, colReserves, debtReserves) {
|
|
425
|
+
const { token0RealReserves, token1RealReserves, token0ImaginaryReserves, token1ImaginaryReserves, } = colReserves;
|
|
426
|
+
const { token0RealReserves: debtToken0RealReserves, token1RealReserves: debtToken1RealReserves, token0ImaginaryReserves: debtToken0ImaginaryReserves, token1ImaginaryReserves: debtToken1ImaginaryReserves, } = debtReserves;
|
|
427
|
+
// Check if all reserves of collateral pool are greater than 0
|
|
428
|
+
const colPoolEnabled = token0RealReserves > 0n &&
|
|
429
|
+
token1RealReserves > 0n &&
|
|
430
|
+
token0ImaginaryReserves > 0n &&
|
|
431
|
+
token1ImaginaryReserves > 0n;
|
|
432
|
+
// Check if all reserves of debt pool are greater than 0
|
|
433
|
+
const debtPoolEnabled = debtToken0RealReserves > 0n &&
|
|
434
|
+
debtToken1RealReserves > 0n &&
|
|
435
|
+
debtToken0ImaginaryReserves > 0n &&
|
|
436
|
+
debtToken1ImaginaryReserves > 0n;
|
|
437
|
+
let colReserveIn, colReserveOut, debtReserveIn, debtReserveOut;
|
|
438
|
+
let colIReserveIn, colIReserveOut, debtIReserveIn, debtIReserveOut;
|
|
439
|
+
if (swap0to1) {
|
|
440
|
+
colReserveIn = token0RealReserves;
|
|
441
|
+
colReserveOut = token1RealReserves;
|
|
442
|
+
colIReserveIn = token0ImaginaryReserves;
|
|
443
|
+
colIReserveOut = token1ImaginaryReserves;
|
|
444
|
+
debtReserveIn = debtToken0RealReserves;
|
|
445
|
+
debtReserveOut = debtToken1RealReserves;
|
|
446
|
+
debtIReserveIn = debtToken0ImaginaryReserves;
|
|
447
|
+
debtIReserveOut = debtToken1ImaginaryReserves;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
colReserveIn = token1RealReserves;
|
|
451
|
+
colReserveOut = token0RealReserves;
|
|
452
|
+
colIReserveIn = token1ImaginaryReserves;
|
|
453
|
+
colIReserveOut = token0ImaginaryReserves;
|
|
454
|
+
debtReserveIn = debtToken1RealReserves;
|
|
455
|
+
debtReserveOut = debtToken0RealReserves;
|
|
456
|
+
debtIReserveIn = debtToken1ImaginaryReserves;
|
|
457
|
+
debtIReserveOut = debtToken0ImaginaryReserves;
|
|
458
|
+
}
|
|
459
|
+
let a;
|
|
460
|
+
if (colPoolEnabled && debtPoolEnabled) {
|
|
461
|
+
a = this.swapRoutingOut(amountOut, colIReserveIn, colIReserveOut, debtIReserveIn, debtIReserveOut);
|
|
462
|
+
}
|
|
463
|
+
else if (debtPoolEnabled) {
|
|
464
|
+
a = -1n; // Route from debt pool
|
|
465
|
+
}
|
|
466
|
+
else if (colPoolEnabled) {
|
|
467
|
+
a = amountOut + 1n; // Route from collateral pool
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
throw new Error('No pools are enabled');
|
|
471
|
+
}
|
|
472
|
+
let amountInCollateral = 0n;
|
|
473
|
+
let amountInDebt = 0n;
|
|
474
|
+
if (a <= 0n) {
|
|
475
|
+
// Entire trade routes through debt pool
|
|
476
|
+
amountInDebt = this.getAmountIn(amountOut, debtIReserveIn, debtIReserveOut);
|
|
477
|
+
if (amountOut > debtReserveOut) {
|
|
478
|
+
return 2n ** 64n - 1n; // BigInt max value
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
else if (a >= amountOut) {
|
|
482
|
+
// Entire trade routes through collateral pool
|
|
483
|
+
amountInCollateral = this.getAmountIn(amountOut, colIReserveIn, colIReserveOut);
|
|
484
|
+
if (amountOut > colReserveOut) {
|
|
485
|
+
return 2n ** 64n - 1n; // BigInt max value
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
// Trade routes through both pools
|
|
490
|
+
amountInCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut);
|
|
491
|
+
amountInDebt = this.getAmountIn(amountOut - a, debtIReserveIn, debtIReserveOut);
|
|
492
|
+
if (amountOut - a > debtReserveOut || a > debtReserveOut) {
|
|
493
|
+
return 2n ** 64n - 1n; // BigInt max value
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const totalAmountIn = amountInCollateral + amountInDebt;
|
|
497
|
+
return totalAmountIn;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
exports.FluidDex = FluidDex;
|
|
501
|
+
FluidDex.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.FluidDexConfig);
|
|
502
|
+
//# sourceMappingURL=fluid-dex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fluid-dex.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/fluid-dex.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAA+C;AAW/C,+CAAoD;AACpD,2EAA6D;AAW7D,wDAAoD;AACpD,gGAAqE;AACrE,qCAA8D;AAC9D,qDAAqD;AACrD,2DAAsD;AACtD,uCAAkE;AAClE,gDAAmE;AAEnE,iDAAoD;AACpD,mCAAmC;AACnC,mCAA+B;AAE/B,MAAa,QAAS,SAAQ,gCAAc;IAkB1C,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB;QAE9B,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAJhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QApBhC,eAAU,GAAwC,EAAE,CAAC;QAC5C,iCAA4B,GAAG,KAAK,CAAC;QACrC,mBAAc,GAAG,KAAK,CAAC;QACvB,6BAAwB,GAAG,KAAK,CA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E,cAAc,CAAC,CAAC;YACxE,YAAY,GAAG,IAAI,CAAC,WAAW,CAC7B,SAAS,GAAG,CAAC,EACb,cAAc,EACd,eAAe,CAChB,CAAC;YACF,IAAI,SAAS,GAAG,CAAC,GAAG,cAAc,IAAI,CAAC,GAAG,cAAc,EAAE;gBACxD,OAAO,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,mBAAmB;aAC3C;SACF;QAED,MAAM,aAAa,GAAG,kBAAkB,GAAG,YAAY,CAAC;QAExD,OAAO,aAAa,CAAC;IACvB,CAAC;;AAhvBH,4BAivBC;AA5uBe,2BAAkB,GAC9B,IAAA,6BAAqB,EAAC,uBAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Address } from '../../types';
|
|
2
|
+
export declare type FluidDexPoolState = {
|
|
3
|
+
collateralReserves: CollateralReserves;
|
|
4
|
+
debtReserves: DebtReserves;
|
|
5
|
+
fee: number;
|
|
6
|
+
};
|
|
7
|
+
export declare type CollateralReserves = {
|
|
8
|
+
token0RealReserves: bigint;
|
|
9
|
+
token1RealReserves: bigint;
|
|
10
|
+
token0ImaginaryReserves: bigint;
|
|
11
|
+
token1ImaginaryReserves: bigint;
|
|
12
|
+
};
|
|
13
|
+
export declare type DebtReserves = {
|
|
14
|
+
token0Debt: bigint;
|
|
15
|
+
token1Debt: bigint;
|
|
16
|
+
token0RealReserves: bigint;
|
|
17
|
+
token1RealReserves: bigint;
|
|
18
|
+
token0ImaginaryReserves: bigint;
|
|
19
|
+
token1ImaginaryReserves: bigint;
|
|
20
|
+
};
|
|
21
|
+
export interface PoolWithReserves {
|
|
22
|
+
pool: string;
|
|
23
|
+
token0: string;
|
|
24
|
+
token1: string;
|
|
25
|
+
fee: number;
|
|
26
|
+
collateralReserves: CollateralReserves;
|
|
27
|
+
debtReserves: DebtReserves;
|
|
28
|
+
}
|
|
29
|
+
export declare type FluidDexData = {
|
|
30
|
+
colReserves: CollateralReserves;
|
|
31
|
+
debtReserves: DebtReserves;
|
|
32
|
+
exchange: Address;
|
|
33
|
+
};
|
|
34
|
+
export declare type FluidDexPool = {
|
|
35
|
+
id: string;
|
|
36
|
+
address: Address;
|
|
37
|
+
token0: Address;
|
|
38
|
+
token1: Address;
|
|
39
|
+
};
|
|
40
|
+
export declare type DexParams = {
|
|
41
|
+
commonAddresses: CommonAddresses;
|
|
42
|
+
};
|
|
43
|
+
export declare type CommonAddresses = {
|
|
44
|
+
liquidityProxy: Address;
|
|
45
|
+
resolver: Address;
|
|
46
|
+
dexFactory: Address;
|
|
47
|
+
};
|
|
48
|
+
export declare type Pool = {
|
|
49
|
+
address: Address;
|
|
50
|
+
token0: Address;
|
|
51
|
+
token1: Address;
|
|
52
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sqrt = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const ONE = ethers_1.BigNumber.from(1);
|
|
6
|
+
const TWO = ethers_1.BigNumber.from(2);
|
|
7
|
+
function sqrt(value) {
|
|
8
|
+
let x = value;
|
|
9
|
+
let z = x.add(ONE).div(TWO);
|
|
10
|
+
let y = x;
|
|
11
|
+
while (z.sub(y).isNegative()) {
|
|
12
|
+
y = z;
|
|
13
|
+
z = x.div(z).add(z).div(TWO);
|
|
14
|
+
}
|
|
15
|
+
return y;
|
|
16
|
+
}
|
|
17
|
+
exports.sqrt = sqrt;
|
|
18
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/utils.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAEnC,MAAM,GAAG,GAAG,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC9B,MAAM,GAAG,GAAG,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE9B,SAAgB,IAAI,CAAC,KAAgB;IACnC,IAAI,CAAC,GAAG,KAAK,CAAC;IACd,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,EAAE;QAC5B,CAAC,GAAG,CAAC,CAAC;QACN,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC9B;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AATD,oBASC"}
|
package/build/dex/index.js
CHANGED
|
@@ -88,6 +88,7 @@ const spark_1 = require("./spark/spark");
|
|
|
88
88
|
const velodrome_slipstream_1 = require("./uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream");
|
|
89
89
|
const aave_v3_stata_1 = require("./aave-v3-stata/aave-v3-stata");
|
|
90
90
|
const oswap_1 = require("./oswap/oswap");
|
|
91
|
+
const fluid_dex_1 = require("./fluid-dex/fluid-dex");
|
|
91
92
|
const concentrator_arusd_1 = require("./concentrator-arusd/concentrator-arusd");
|
|
92
93
|
const fx_protocol_rusd_1 = require("./fx-protocol-rusd/fx-protocol-rusd");
|
|
93
94
|
const aave_gsm_1 = require("./aave-gsm/aave-gsm");
|
|
@@ -181,6 +182,7 @@ const Dexes = [
|
|
|
181
182
|
usual_bond_1.UsualBond,
|
|
182
183
|
stkgho_1.StkGHO,
|
|
183
184
|
sky_converter_1.SkyConverter,
|
|
185
|
+
fluid_dex_1.FluidDex,
|
|
184
186
|
];
|
|
185
187
|
class DexAdapterService {
|
|
186
188
|
constructor(dexHelper, network, sellAdapters = {}, buyAdapters = {}) {
|