@paraswap/dex-lib 2.42.11 → 2.42.12
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/kyberswap-elastic/IAntiSnipAttackPositionManager.json +1276 -0
- package/build/abi/kyberswap-elastic/IFactory.json +550 -0
- package/build/abi/kyberswap-elastic/IPool.json +1042 -0
- package/build/abi/kyberswap-elastic/IQuoterV2.json +226 -0
- package/build/abi/kyberswap-elastic/IRouter.json +239 -0
- package/build/abi/kyberswap-elastic/TicksFeesReader.json +142 -0
- package/build/abi/wombat/asset.json +769 -0
- package/build/abi/wombat/bmw.json +1247 -0
- package/build/abi/wombat/pool.json +1364 -0
- package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +26 -0
- package/build/dex/baseswap-v3/baseswap-v3-factory.js +44 -0
- package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +1 -0
- package/build/dex/{algebra/algebra-pool.d.ts → baseswap-v3/baseswap-v3-pool.d.ts} +16 -16
- package/build/dex/{algebra/algebra-pool.js → baseswap-v3/baseswap-v3-pool.js} +137 -161
- package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +1 -0
- package/build/dex/baseswap-v3/baseswap-v3.d.ts +71 -0
- package/build/dex/baseswap-v3/baseswap-v3.js +752 -0
- package/build/dex/baseswap-v3/baseswap-v3.js.map +1 -0
- package/build/dex/baseswap-v3/config.d.ts +9 -0
- package/build/dex/baseswap-v3/config.js +48 -0
- package/build/dex/baseswap-v3/config.js.map +1 -0
- package/build/dex/baseswap-v3/constants.d.ts +28 -0
- package/build/dex/baseswap-v3/constants.js +35 -0
- package/build/dex/baseswap-v3/constants.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.js +93 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.js +8 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.js +9 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.js +19 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.js +22 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.d.ts +10 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.js +133 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.js +70 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/Tick.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/Tick.js +45 -0
- package/build/dex/baseswap-v3/contract-math/Tick.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.js +84 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.d.ts +8 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.js +162 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.js +10 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.d.ts +37 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js +393 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/utils.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/utils.js +42 -0
- package/build/dex/baseswap-v3/contract-math/utils.js.map +1 -0
- package/build/dex/baseswap-v3/types.d.ts +164 -0
- package/build/dex/baseswap-v3/types.js +9 -0
- package/build/dex/baseswap-v3/types.js.map +1 -0
- package/build/dex/baseswap-v3/utils.d.ts +6 -0
- package/build/dex/baseswap-v3/utils.js +65 -0
- package/build/dex/baseswap-v3/utils.js.map +1 -0
- package/build/dex/dexalot/dexalot.d.ts +3 -2
- package/build/dex/dexalot/dexalot.js +33 -19
- package/build/dex/dexalot/dexalot.js.map +1 -1
- package/build/dex/hello/config.d.ts +4 -0
- package/build/dex/hello/config.js +15 -0
- package/build/dex/hello/config.js.map +1 -0
- package/build/dex/hello/hello-pool.d.ts +39 -0
- package/build/dex/hello/hello-pool.js +64 -0
- package/build/dex/hello/hello-pool.js.map +1 -0
- package/build/dex/hello/hello.d.ts +37 -0
- package/build/dex/hello/hello.js +126 -0
- package/build/dex/hello/hello.js.map +1 -0
- package/build/dex/hello/types.d.ts +6 -0
- package/build/dex/hello/types.js +3 -0
- package/build/dex/hello/types.js.map +1 -0
- package/build/dex/kyberswap-elastic/config.d.ts +4 -0
- package/build/dex/kyberswap-elastic/config.js +80 -0
- package/build/dex/kyberswap-elastic/config.js.map +1 -0
- package/build/dex/kyberswap-elastic/constants.d.ts +17 -0
- package/build/dex/kyberswap-elastic/constants.js +42 -0
- package/build/dex/kyberswap-elastic/constants.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js +9 -0
- package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/FullMath.d.ts +5 -0
- package/build/dex/kyberswap-elastic/contract-math/FullMath.js +22 -0
- package/build/dex/kyberswap-elastic/contract-math/FullMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js +12 -0
- package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js +22 -0
- package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.d.ts +5 -0
- package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js +25 -0
- package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/QuadMath.d.ts +4 -0
- package/build/dex/kyberswap-elastic/contract-math/QuadMath.js +27 -0
- package/build/dex/kyberswap-elastic/contract-math/QuadMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js +14 -0
- package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/SafeCast.d.ts +8 -0
- package/build/dex/kyberswap-elastic/contract-math/SafeCast.js +30 -0
- package/build/dex/kyberswap-elastic/contract-math/SafeCast.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/SwapMath.d.ts +13 -0
- package/build/dex/kyberswap-elastic/contract-math/SwapMath.js +188 -0
- package/build/dex/kyberswap-elastic/contract-math/SwapMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.d.ts +6 -0
- package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js +41 -0
- package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/TickMath.d.ts +9 -0
- package/build/dex/kyberswap-elastic/contract-math/TickMath.js +165 -0
- package/build/dex/kyberswap-elastic/contract-math/TickMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js +10 -0
- package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.d.ts +28 -0
- package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js +502 -0
- package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/utils.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/utils.js +16 -0
- package/build/dex/kyberswap-elastic/contract-math/utils.js.map +1 -0
- package/build/dex/kyberswap-elastic/errors.d.ts +2 -0
- package/build/dex/kyberswap-elastic/errors.js +6 -0
- package/build/dex/kyberswap-elastic/errors.js.map +1 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.d.ts +80 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js +458 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js.map +1 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic.d.ts +53 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic.js +610 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic.js.map +1 -0
- package/build/dex/kyberswap-elastic/types.d.ts +134 -0
- package/build/dex/kyberswap-elastic/types.js +9 -0
- package/build/dex/kyberswap-elastic/types.js.map +1 -0
- package/build/dex/kyberswap-elastic/utils/decoders.d.ts +9 -0
- package/build/dex/kyberswap-elastic/utils/decoders.js +78 -0
- package/build/dex/kyberswap-elastic/utils/decoders.js.map +1 -0
- package/build/dex/morphex/config.d.ts +11 -0
- package/build/dex/morphex/config.js +43 -0
- package/build/dex/morphex/config.js.map +1 -0
- package/build/dex/morphex/morphex.d.ts +25 -0
- package/build/dex/morphex/morphex.js +19 -0
- package/build/dex/morphex/morphex.js.map +1 -0
- package/build/dex/my-test-dex/config.d.ts +4 -0
- package/build/dex/my-test-dex/config.js +15 -0
- package/build/dex/my-test-dex/config.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
- package/build/dex/my-test-dex/my-test-dex.js +126 -0
- package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
- package/build/dex/my-test-dex/types.d.ts +6 -0
- package/build/dex/my-test-dex/types.js +3 -0
- package/build/dex/my-test-dex/types.js.map +1 -0
- package/build/dex/solidly/forks-override/fvm.d.ts +20 -0
- package/build/dex/solidly/forks-override/fvm.js +42 -0
- package/build/dex/solidly/forks-override/fvm.js.map +1 -0
- package/build/dex/wombat/config.d.ts +5 -0
- package/build/dex/wombat/config.js +50 -0
- package/build/dex/wombat/config.js.map +1 -0
- package/build/dex/wombat/types.d.ts +33 -0
- package/build/dex/wombat/types.js +3 -0
- package/build/dex/wombat/types.js.map +1 -0
- package/build/dex/wombat/utils.d.ts +9 -0
- package/build/dex/wombat/utils.js +66 -0
- package/build/dex/wombat/utils.js.map +1 -0
- package/build/dex/wombat/wombat-bmw.d.ts +40 -0
- package/build/dex/wombat/wombat-bmw.js +145 -0
- package/build/dex/wombat/wombat-bmw.js.map +1 -0
- package/build/dex/wombat/wombat-pool.d.ts +22 -0
- package/build/dex/wombat/wombat-pool.js +161 -0
- package/build/dex/wombat/wombat-pool.js.map +1 -0
- package/build/dex/wombat/wombat-quoter.d.ts +16 -0
- package/build/dex/wombat/wombat-quoter.js +176 -0
- package/build/dex/wombat/wombat-quoter.js.map +1 -0
- package/build/dex/wombat/wombat.d.ts +55 -0
- package/build/dex/wombat/wombat.js +292 -0
- package/build/dex/wombat/wombat.js.map +1 -0
- package/package.json +1 -1
- package/src/dex/dexalot/dexalot.ts +48 -22
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/quickswap/camelot-v3.d.ts +0 -6
- package/build/dex/quickswap/camelot-v3.js +0 -19
- package/build/dex/quickswap/camelot-v3.js.map +0 -1
- package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
- package/build/dex/quickswap/zyberswap-v3.js +0 -19
- package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
|
@@ -0,0 +1,292 @@
|
|
|
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.Wombat = void 0;
|
|
30
|
+
const abi_1 = require("@ethersproject/abi");
|
|
31
|
+
const core_1 = require("@paraswap/core");
|
|
32
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
33
|
+
const utils_1 = require("../../utils");
|
|
34
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
35
|
+
const config_1 = require("./config");
|
|
36
|
+
const pool_json_1 = __importDefault(require("../../abi/wombat/pool.json"));
|
|
37
|
+
const asset_json_1 = __importDefault(require("../../abi/wombat/asset.json"));
|
|
38
|
+
const erc20_json_1 = __importDefault(require("../../abi/erc20.json"));
|
|
39
|
+
const wombat_quoter_1 = require("./wombat-quoter");
|
|
40
|
+
const wombat_bmw_1 = require("./wombat-bmw");
|
|
41
|
+
const utils_2 = require("./utils");
|
|
42
|
+
const wombat_pool_1 = require("./wombat-pool");
|
|
43
|
+
class Wombat extends simple_exchange_1.SimpleExchange {
|
|
44
|
+
constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
|
|
45
|
+
super(dexHelper, dexKey);
|
|
46
|
+
this.network = network;
|
|
47
|
+
this.dexKey = dexKey;
|
|
48
|
+
this.dexHelper = dexHelper;
|
|
49
|
+
this.adapters = adapters;
|
|
50
|
+
this.pools = {};
|
|
51
|
+
this.hasConstantPriceLargeAmounts = false;
|
|
52
|
+
this.needWrapNative = true;
|
|
53
|
+
this.isFeeOnTransferSupported = false;
|
|
54
|
+
this.onAssetAdded = (pool, asset2TokenMap, blockNumber) => {
|
|
55
|
+
if (!this.pools[pool]) {
|
|
56
|
+
this.pools[pool] = new wombat_pool_1.WombatPool(this.dexKey, this.getPoolIdentifier(pool), this.dexHelper, pool, asset2TokenMap);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.pools[pool].addAssets(asset2TokenMap);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
63
|
+
this.config = config_1.WombatConfig[dexKey][network];
|
|
64
|
+
this.bmw = new wombat_bmw_1.WombatBmw(dexKey, this.config.bmwAddress, network, dexHelper, this.logger, this.config.bmwAddress, this.onAssetAdded.bind(this));
|
|
65
|
+
}
|
|
66
|
+
async init(blockNumber) {
|
|
67
|
+
if (!this.bmw.isInitialized) {
|
|
68
|
+
await this.bmw.initialize(blockNumber);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Initialize pricing is called once in the start of
|
|
72
|
+
// pricing service. It is intended to setup the integration
|
|
73
|
+
// for pricing requests. It is optional for a DEX to
|
|
74
|
+
// implement this function
|
|
75
|
+
async initializePricing(blockNumber) {
|
|
76
|
+
await this.init(blockNumber);
|
|
77
|
+
const bmwState = this.bmw.getState(blockNumber);
|
|
78
|
+
if (!bmwState) {
|
|
79
|
+
throw new Error('initializePricing: bmwState still null after init');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Returns the list of contract adapters (name and index)
|
|
83
|
+
// for a buy/sell. Return null if there are no adapters.
|
|
84
|
+
getAdapters(side) {
|
|
85
|
+
return this.adapters[side] ? this.adapters[side] : null;
|
|
86
|
+
}
|
|
87
|
+
// Returns list of pool identifiers that can be used
|
|
88
|
+
// for a given swap. poolIdentifiers must be unique
|
|
89
|
+
// across DEXes. It is recommended to use
|
|
90
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
91
|
+
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
92
|
+
await this.updatePoolState();
|
|
93
|
+
return (await this.findPools(srcToken.address.toLowerCase(), destToken.address.toLowerCase(), blockNumber, config_1.LIQUIDITY_THRESHOLD_IN_USD)).map(p => this.getPoolIdentifier(p));
|
|
94
|
+
}
|
|
95
|
+
getPoolIdentifier(poolAddress) {
|
|
96
|
+
return `${this.dexKey}_${poolAddress}`;
|
|
97
|
+
}
|
|
98
|
+
// Returns pool prices for amounts.
|
|
99
|
+
// If limitPools is defined only pools in limitPools
|
|
100
|
+
// should be used. If limitPools is undefined then
|
|
101
|
+
// any pools can be used.
|
|
102
|
+
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
103
|
+
if (!this.pools) {
|
|
104
|
+
this.logger.error(`Missing pools for ${this.dexKey} in getPricesVolume`);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const srcTokenAddress = srcToken.address.toLowerCase();
|
|
108
|
+
const destTokenAddress = destToken.address.toLowerCase();
|
|
109
|
+
if (srcTokenAddress === destTokenAddress)
|
|
110
|
+
return null;
|
|
111
|
+
const pools = (await this.findPools(srcTokenAddress, destTokenAddress, blockNumber)).filter(poolAddress => !limitPools || limitPools.includes(this.getPoolIdentifier(poolAddress)));
|
|
112
|
+
const promises = [];
|
|
113
|
+
for (const poolAddress of pools) {
|
|
114
|
+
let state = await this.pools[poolAddress].getState(blockNumber);
|
|
115
|
+
if (!state) {
|
|
116
|
+
this.logger.warn(`State of pool ${poolAddress} is null in getPricesVolume, skipping...`);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const [unit, ...prices] = this.computePrices(srcTokenAddress, destTokenAddress, [(0, utils_1.getBigIntPow)(srcToken.decimals), ...amounts], side, state.value);
|
|
120
|
+
promises.push({
|
|
121
|
+
prices,
|
|
122
|
+
unit,
|
|
123
|
+
data: {
|
|
124
|
+
exchange: poolAddress,
|
|
125
|
+
},
|
|
126
|
+
poolAddresses: [poolAddress],
|
|
127
|
+
exchange: this.dexKey,
|
|
128
|
+
/** @todo specify gas cost */
|
|
129
|
+
gasCost: 260 * 1000,
|
|
130
|
+
poolIdentifier: this.getPoolIdentifier(poolAddress),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return await Promise.all(promises);
|
|
134
|
+
}
|
|
135
|
+
// take PoolState to compute price
|
|
136
|
+
computePrices(srcTokenAddress, destTokenAddress, amounts, side, state) {
|
|
137
|
+
const srcAsset = state.asset[srcTokenAddress];
|
|
138
|
+
const destAsset = state.asset[destTokenAddress];
|
|
139
|
+
const quoter = new wombat_quoter_1.WombatQuoter(state.params);
|
|
140
|
+
return amounts.map(fromAmount => {
|
|
141
|
+
return side === core_1.SwapSide.SELL
|
|
142
|
+
? quoter.getQuote(srcAsset, destAsset, fromAmount)
|
|
143
|
+
: quoter.getQuote(destAsset, srcAsset, -fromAmount);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async findPools(srcTokenAddress, destTokenAddress, blockNumber, liquidityThresholdInUSD = 0) {
|
|
147
|
+
const pools = [];
|
|
148
|
+
for (const [poolAddress, pool] of Object.entries(this.pools)) {
|
|
149
|
+
let stateOj = await pool.getState(blockNumber);
|
|
150
|
+
if (!stateOj) {
|
|
151
|
+
this.logger.warn(`State of pool ${poolAddress} is null in findPools, skipping...`);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const state = stateOj.value;
|
|
155
|
+
if (state &&
|
|
156
|
+
!state.params.paused &&
|
|
157
|
+
state.asset[srcTokenAddress] &&
|
|
158
|
+
state.asset[destTokenAddress] &&
|
|
159
|
+
(liquidityThresholdInUSD === 0 ||
|
|
160
|
+
(this.poolLiquidityUSD[poolAddress] &&
|
|
161
|
+
this.poolLiquidityUSD[poolAddress] > liquidityThresholdInUSD))) {
|
|
162
|
+
pools.push(poolAddress);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return pools;
|
|
166
|
+
}
|
|
167
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
168
|
+
getCalldataGasCost(poolPrices) {
|
|
169
|
+
// TODO: update if there is any payload in getAdapterParam
|
|
170
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
171
|
+
}
|
|
172
|
+
// Encode params required by the exchange adapter
|
|
173
|
+
// Used for multiSwap, buy & megaSwap
|
|
174
|
+
// Hint: abiCoder.encodeParameter() could be useful
|
|
175
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
176
|
+
// TODO: complete me!
|
|
177
|
+
const { exchange } = data;
|
|
178
|
+
// Encode here the payload for adapter
|
|
179
|
+
const payload = '0x';
|
|
180
|
+
return {
|
|
181
|
+
targetExchange: exchange,
|
|
182
|
+
payload,
|
|
183
|
+
networkFee: '0',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// Encode call data used by simpleSwap like routers
|
|
187
|
+
// Used for simpleSwap & simpleBuy
|
|
188
|
+
// Hint: this.buildSimpleParamWithoutWETHConversion
|
|
189
|
+
// could be useful
|
|
190
|
+
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
191
|
+
const { exchange } = data;
|
|
192
|
+
// Encode here the transaction arguments
|
|
193
|
+
const swapData = Wombat.poolInterface.encodeFunctionData('swap', [
|
|
194
|
+
srcToken,
|
|
195
|
+
destToken,
|
|
196
|
+
srcAmount,
|
|
197
|
+
1 /** @todo assume slippage tolorence is 2% and set the minimum receive accordingly */,
|
|
198
|
+
this.augustusAddress,
|
|
199
|
+
(0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
200
|
+
]);
|
|
201
|
+
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, exchange);
|
|
202
|
+
}
|
|
203
|
+
// This is called once before getTopPoolsForToken is
|
|
204
|
+
// called for multiple tokens. This can be helpful to
|
|
205
|
+
// update common state required for calculating
|
|
206
|
+
// getTopPoolsForToken. For example, poolLiquidityUSD.
|
|
207
|
+
async updatePoolState() {
|
|
208
|
+
const blockNumber = await this.dexHelper.provider.getBlockNumber();
|
|
209
|
+
await this.init(blockNumber);
|
|
210
|
+
const bmwState = this.bmw.getState(blockNumber);
|
|
211
|
+
if (!bmwState) {
|
|
212
|
+
throw new Error('updatePoolState: bmwState still null after init');
|
|
213
|
+
}
|
|
214
|
+
// All tokens are USD stablecoins so to estimate liquidity can just add
|
|
215
|
+
// the cash balances of all the tokens
|
|
216
|
+
const poolLiquidityUSD = {};
|
|
217
|
+
const usdPromises = [];
|
|
218
|
+
const poolStates = {};
|
|
219
|
+
const poolStateObjs = await Promise.all(Object.values(this.pools).map(pool => pool.getState()));
|
|
220
|
+
for (const [poolAddress, pool] of Object.entries(this.pools)) {
|
|
221
|
+
const index = Object.keys(this.pools).indexOf(poolAddress);
|
|
222
|
+
let state = poolStateObjs[index];
|
|
223
|
+
if (!state) {
|
|
224
|
+
this.logger.warn(`State of ${poolAddress} is null in updatePoolState, skipping...`);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
poolStates[poolAddress] = state.value;
|
|
228
|
+
for (const [tokenAddress, assetState] of Object.entries(state.value.asset)) {
|
|
229
|
+
usdPromises.push(this.dexHelper.getTokenUSDPrice({
|
|
230
|
+
address: tokenAddress,
|
|
231
|
+
decimals: assetState.underlyingTokenDecimals,
|
|
232
|
+
}, (0, utils_2.fromWad)(assetState.cash, BigInt(assetState.underlyingTokenDecimals))));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const usdValues = await Promise.all(usdPromises);
|
|
236
|
+
for (const [poolAddress, poolState] of Object.entries(poolStates)) {
|
|
237
|
+
poolLiquidityUSD[poolAddress] = 0;
|
|
238
|
+
for (let i = 0; i < poolState.underlyingAddresses.length; i++) {
|
|
239
|
+
poolLiquidityUSD[poolAddress] += usdValues[i];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
this.poolLiquidityUSD = poolLiquidityUSD;
|
|
243
|
+
}
|
|
244
|
+
// Returns list of top pools based on liquidity. Max
|
|
245
|
+
// limit number pools should be returned.
|
|
246
|
+
async getTopPoolsForToken(tokenAddress, limit) {
|
|
247
|
+
if (!this.poolLiquidityUSD)
|
|
248
|
+
await this.updatePoolState();
|
|
249
|
+
tokenAddress = tokenAddress.toLowerCase();
|
|
250
|
+
const pools = [];
|
|
251
|
+
const poolStates = {};
|
|
252
|
+
for (const [poolAddress, eventPool] of Object.entries(this.pools)) {
|
|
253
|
+
let state = await eventPool.getState();
|
|
254
|
+
if (!state) {
|
|
255
|
+
this.logger.warn(`State of ${poolAddress} is null in getTopPoolsForToken, skipping...`);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (state.value.underlyingAddresses.includes(tokenAddress) &&
|
|
259
|
+
this.poolLiquidityUSD[poolAddress]) {
|
|
260
|
+
poolStates[poolAddress] = state.value;
|
|
261
|
+
pools.push(poolAddress);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// sort by liquidity
|
|
265
|
+
pools.sort((a, b) => this.poolLiquidityUSD[b] - this.poolLiquidityUSD[a]);
|
|
266
|
+
return pools.slice(0, limit).map(poolAddress => ({
|
|
267
|
+
exchange: this.dexKey,
|
|
268
|
+
address: poolAddress,
|
|
269
|
+
// other tokens in the same pool
|
|
270
|
+
connectorTokens: poolStates[poolAddress].underlyingAddresses
|
|
271
|
+
.filter(t => t !== tokenAddress)
|
|
272
|
+
.map(t => ({
|
|
273
|
+
decimals: poolStates[poolAddress].asset[t].underlyingTokenDecimals,
|
|
274
|
+
address: t,
|
|
275
|
+
})),
|
|
276
|
+
liquidityUSD: this.poolLiquidityUSD[poolAddress],
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
// This is optional function in case if your implementation has acquired any resources
|
|
280
|
+
// you need to release for graceful shutdown. For example, it may be any interval timer
|
|
281
|
+
releaseResources() {
|
|
282
|
+
// TODO: complete me!
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.Wombat = Wombat;
|
|
286
|
+
// export class Wombat implements IDex<WombatData> {
|
|
287
|
+
// contract interfaces
|
|
288
|
+
Wombat.erc20Interface = new abi_1.Interface(erc20_json_1.default);
|
|
289
|
+
Wombat.poolInterface = new abi_1.Interface(pool_json_1.default);
|
|
290
|
+
Wombat.assetInterface = new abi_1.Interface(asset_json_1.default);
|
|
291
|
+
Wombat.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.WombatConfig);
|
|
292
|
+
//# sourceMappingURL=wombat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wombat.js","sourceRoot":"","sources":["../../../src/dex/wombat/wombat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAA+C;AAC/C,yCAA0C;AAa1C,2EAA6D;AAC7D,uCAAkE;AAIlE,wDAG4B;AAC5B,qCAA8E;AAC9E,2EAAiD;AACjD,6EAAmD;AACnD,sEAA4C;AAC5C,mDAA+C;AAC/C,6CAAyC;AACzC,mCAAkC;AAClC,+CAA2C;AAG3C,MAAa,MAAO,SAAQ,gCAAc;IAwBxC,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,iBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QAE5C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QALhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAA0B;QAlBvC,UAAK,GAA0C,EAAE,CAAC;QAEhD,iCAA4B,GAAG,KAAK,CAAC;QACrC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CAAC;YACL,YAAY,EAAE,IAAI,CAAC,gBAAiB,CAAC,WAAW,CAAC;SAClD,CAAC,CAAC,CAAC;IACN,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,gBAAgB;QACd,qBAAqB;IACvB,CAAC;;AA1YH,wBA2YC;AA1YC,oDAAoD;AACpD,sBAAsB;AACN,qBAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC;AACzC,oBAAa,GAAG,IAAI,eAAS,CAAC,mBAAO,CAAC,CAAC;AACvC,qBAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC;AAY3C,yBAAkB,GAG1B,IAAA,6BAAqB,EAAC,qBAAY,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -395,7 +395,8 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
395
395
|
.toString(),
|
|
396
396
|
);
|
|
397
397
|
if (isInputQuote) {
|
|
398
|
-
lQty =
|
|
398
|
+
lQty =
|
|
399
|
+
(lQty * BigInt(10 ** (baseToken.decimals * 2))) /
|
|
399
400
|
(lPrice * BigInt(10 ** quoteToken.decimals));
|
|
400
401
|
rQty =
|
|
401
402
|
(rQty * BigInt(10 ** (baseToken.decimals * 2))) /
|
|
@@ -432,10 +433,6 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
432
433
|
transferFees?: TransferFeeParams,
|
|
433
434
|
): Promise<null | ExchangePrices<DexalotData>> {
|
|
434
435
|
try {
|
|
435
|
-
if (await this.isRestricted()) {
|
|
436
|
-
return null;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
436
|
const normalizedSrcToken = this.normalizeToken(srcToken);
|
|
440
437
|
const normalizedDestToken = this.normalizeToken(destToken);
|
|
441
438
|
|
|
@@ -444,7 +441,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
444
441
|
return null;
|
|
445
442
|
}
|
|
446
443
|
|
|
447
|
-
|
|
444
|
+
let pools = limitPools
|
|
448
445
|
? limitPools.filter(
|
|
449
446
|
p =>
|
|
450
447
|
p ===
|
|
@@ -455,6 +452,9 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
455
452
|
)
|
|
456
453
|
: await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);
|
|
457
454
|
|
|
455
|
+
pools = await Promise.all(
|
|
456
|
+
pools.map(async p => !(await this.isRestrictedPool(p))),
|
|
457
|
+
).then(res => pools.filter((_v, i) => res[i]));
|
|
458
458
|
if (pools.length === 0) {
|
|
459
459
|
return null;
|
|
460
460
|
}
|
|
@@ -505,14 +505,16 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
505
505
|
throw new Error(`Empty orderbook for ${pairKey}`);
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
-
const isInputQuote =
|
|
508
|
+
const isInputQuote =
|
|
509
|
+
(clobSide === ClobSide.ASK && side === SwapSide.SELL) ||
|
|
510
|
+
(clobSide === ClobSide.BID && side === SwapSide.BUY);
|
|
509
511
|
|
|
510
512
|
const prices = this.calculateOrderPrice(
|
|
511
513
|
amounts,
|
|
512
514
|
orderbook,
|
|
513
515
|
baseToken,
|
|
514
516
|
quoteToken,
|
|
515
|
-
isInputQuote
|
|
517
|
+
isInputQuote,
|
|
516
518
|
);
|
|
517
519
|
const outDecimals =
|
|
518
520
|
clobSide === ClobSide.BID ? baseToken.decimals : quoteToken.decimals;
|
|
@@ -579,15 +581,24 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
579
581
|
const makerToken = normalizedDestToken;
|
|
580
582
|
const takerToken = normalizedSrcToken;
|
|
581
583
|
|
|
584
|
+
const isSell = side === SwapSide.SELL;
|
|
585
|
+
const isBuy = side === SwapSide.BUY;
|
|
586
|
+
|
|
587
|
+
const slippageBps = isSell
|
|
588
|
+
? BigNumber(1)
|
|
589
|
+
.minus(options.slippageFactor)
|
|
590
|
+
.multipliedBy(10000)
|
|
591
|
+
.toFixed(0)
|
|
592
|
+
: options.slippageFactor.minus(1).multipliedBy(10000).toFixed(0);
|
|
582
593
|
const rfqParams = {
|
|
583
594
|
makerAsset: ethers.utils.getAddress(makerToken.address),
|
|
584
595
|
takerAsset: ethers.utils.getAddress(takerToken.address),
|
|
585
|
-
makerAmount:
|
|
586
|
-
|
|
587
|
-
takerAmount:
|
|
588
|
-
side === SwapSide.SELL ? optimalSwapExchange.srcAmount : undefined,
|
|
596
|
+
makerAmount: isBuy ? optimalSwapExchange.destAmount : undefined,
|
|
597
|
+
takerAmount: isSell ? optimalSwapExchange.srcAmount : undefined,
|
|
589
598
|
userAddress: options.txOrigin,
|
|
590
599
|
chainid: this.network,
|
|
600
|
+
partner: options.partner,
|
|
601
|
+
slippage: slippageBps,
|
|
591
602
|
};
|
|
592
603
|
|
|
593
604
|
const rfq: RFQResponse = await this.dexHelper.httpRequest.post(
|
|
@@ -616,7 +627,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
616
627
|
order.takerAsset.toLowerCase() === takerToken.address,
|
|
617
628
|
`QuoteData takerAsset=${order.takerAsset} is different from Paraswap takerAsset=${takerToken.address}`,
|
|
618
629
|
);
|
|
619
|
-
if (
|
|
630
|
+
if (isSell) {
|
|
620
631
|
assert(
|
|
621
632
|
order.takerAmount === optimalSwapExchange.srcAmount,
|
|
622
633
|
`QuoteData takerAmount=${order.takerAmount} is different from Paraswap srcAmount=${optimalSwapExchange.srcAmount}`,
|
|
@@ -635,7 +646,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
635
646
|
let isFailOnSlippage = false;
|
|
636
647
|
let slippageErrorMessage = '';
|
|
637
648
|
|
|
638
|
-
if (
|
|
649
|
+
if (isSell) {
|
|
639
650
|
if (
|
|
640
651
|
BigInt(order.makerAmount) <
|
|
641
652
|
BigInt(
|
|
@@ -674,7 +685,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
674
685
|
let isTooStrictSlippage = false;
|
|
675
686
|
if (
|
|
676
687
|
isFailOnSlippage &&
|
|
677
|
-
|
|
688
|
+
isSell &&
|
|
678
689
|
new BigNumber(1)
|
|
679
690
|
.minus(slippageFactor)
|
|
680
691
|
.lt(DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)
|
|
@@ -682,7 +693,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
682
693
|
isTooStrictSlippage = true;
|
|
683
694
|
} else if (
|
|
684
695
|
isFailOnSlippage &&
|
|
685
|
-
|
|
696
|
+
isBuy &&
|
|
686
697
|
slippageFactor
|
|
687
698
|
.minus(1)
|
|
688
699
|
.lt(DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)
|
|
@@ -725,10 +736,18 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
725
736
|
`${this.dexKey}-${this.network}: failed to build transaction on side ${side} with too strict slippage. Skipping restriction`,
|
|
726
737
|
);
|
|
727
738
|
} else {
|
|
739
|
+
const poolIdentifiers = await this.getPoolIdentifiers(
|
|
740
|
+
srcToken,
|
|
741
|
+
destToken,
|
|
742
|
+
side,
|
|
743
|
+
0,
|
|
744
|
+
);
|
|
728
745
|
this.logger.warn(
|
|
729
|
-
`${this.dexKey}-${this.network}: protocol is restricted`,
|
|
746
|
+
`${this.dexKey}-${this.network}: protocol is restricted for pools ${poolIdentifiers} due to swap: ${swapIdentifier}`,
|
|
747
|
+
);
|
|
748
|
+
await Promise.all(
|
|
749
|
+
poolIdentifiers.map(async p => await this.restrictPool(p)),
|
|
730
750
|
);
|
|
731
|
-
await this.restrict();
|
|
732
751
|
}
|
|
733
752
|
}
|
|
734
753
|
|
|
@@ -813,22 +832,29 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
813
832
|
};
|
|
814
833
|
}
|
|
815
834
|
|
|
816
|
-
|
|
835
|
+
getRestrictedPoolKey(poolIdentifier: string): string {
|
|
836
|
+
return `${DEXALOT_RESTRICTED_CACHE_KEY}-${poolIdentifier}`;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
async restrictPool(
|
|
840
|
+
poolIdentifier: string,
|
|
841
|
+
ttl: number = DEXALOT_RESTRICT_TTL_S,
|
|
842
|
+
): Promise<boolean> {
|
|
817
843
|
await this.dexHelper.cache.setex(
|
|
818
844
|
this.dexKey,
|
|
819
845
|
this.network,
|
|
820
|
-
|
|
846
|
+
this.getRestrictedPoolKey(poolIdentifier),
|
|
821
847
|
ttl,
|
|
822
848
|
'true',
|
|
823
849
|
);
|
|
824
850
|
return true;
|
|
825
851
|
}
|
|
826
852
|
|
|
827
|
-
async
|
|
853
|
+
async isRestrictedPool(poolIdentifier: string): Promise<boolean> {
|
|
828
854
|
const result = await this.dexHelper.cache.get(
|
|
829
855
|
this.dexKey,
|
|
830
856
|
this.network,
|
|
831
|
-
|
|
857
|
+
this.getRestrictedPoolKey(poolIdentifier),
|
|
832
858
|
);
|
|
833
859
|
|
|
834
860
|
return result === 'true';
|