@paraswap/dex-lib 2.42.4 → 2.42.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/baseswap-v3/baseswap-v3-pool.d.ts +46 -0
- package/build/dex/baseswap-v3/baseswap-v3-pool.js +312 -0
- 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/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/uniswap-v3/config.js +14 -0
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.js +1 -0
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/wombat/config.d.ts +5 -0
- package/build/dex/wombat/config.js +36 -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/uniswap-v3/config.ts +14 -0
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +24 -0
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +331 -0
- package/src/dex/uniswap-v3/uniswap-v3.ts +1 -0
- package/.vscode/launch.json +0 -16
- package/build/test.js +0 -26
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WombatBmw = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
10
|
+
const bmw_json_1 = __importDefault(require("../../abi/wombat/bmw.json"));
|
|
11
|
+
const asset_json_1 = __importDefault(require("../../abi/wombat/asset.json"));
|
|
12
|
+
const pool_json_1 = __importDefault(require("../../abi/wombat/pool.json"));
|
|
13
|
+
class WombatBmw extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
14
|
+
constructor(dexKey, name, network, dexHelper, logger, bmwAddress, onAssetAdded) {
|
|
15
|
+
super(`${dexKey} ${name}`, `${dexKey}-${network} ${name}`, dexHelper, logger);
|
|
16
|
+
this.network = network;
|
|
17
|
+
this.dexHelper = dexHelper;
|
|
18
|
+
this.bmwAddress = bmwAddress;
|
|
19
|
+
this.onAssetAdded = onAssetAdded;
|
|
20
|
+
this.handlers = {};
|
|
21
|
+
this.logDecoder = (log) => WombatBmw.bmwInterface.parseLog(log);
|
|
22
|
+
this.addressesSubscribed = [this.bmwAddress];
|
|
23
|
+
this.bmwContract = new this.dexHelper.web3Provider.eth.Contract(bmw_json_1.default, this.bmwAddress);
|
|
24
|
+
// users-actions handlers
|
|
25
|
+
this.handlers['Add'] = this.handleAdd.bind(this);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The function is called every time any of the subscribed
|
|
29
|
+
* addresses release log. The function accepts the current
|
|
30
|
+
* state, updates the state according to the log, and returns
|
|
31
|
+
* the updated state.
|
|
32
|
+
* @param state - Current state of event subscriber
|
|
33
|
+
* @param log - Log released by one of the subscribed addresses
|
|
34
|
+
* @returns Updates state of the event subscriber after the log
|
|
35
|
+
*/
|
|
36
|
+
async processLog(state, log) {
|
|
37
|
+
try {
|
|
38
|
+
const event = this.logDecoder(log);
|
|
39
|
+
if (event.name in this.handlers) {
|
|
40
|
+
return await this.handlers[event.name](event, state, log);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
(0, utils_1.catchParseLogError)(e, this.logger);
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The function generates state using on-chain calls. This
|
|
50
|
+
* function is called to regenerate state if the event based
|
|
51
|
+
* system fails to fetch events and the local state is no
|
|
52
|
+
* more correct.
|
|
53
|
+
* should be generated
|
|
54
|
+
* @returns state of the event subscriber at blocknumber
|
|
55
|
+
*/
|
|
56
|
+
async generateState(blockNumber) {
|
|
57
|
+
const bmwState = { pools: [] };
|
|
58
|
+
let inputs = [];
|
|
59
|
+
const poolLength = await this.bmwContract.methods
|
|
60
|
+
.poolLength()
|
|
61
|
+
.call({}, blockNumber);
|
|
62
|
+
for (let i = 0; i < poolLength; i++) {
|
|
63
|
+
inputs.push({
|
|
64
|
+
target: this.bmwAddress,
|
|
65
|
+
callData: WombatBmw.bmwInterface.encodeFunctionData('poolInfo', [i]),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
let returnData = (await this.dexHelper.multiContract.methods
|
|
69
|
+
.aggregate(inputs)
|
|
70
|
+
.call({}, blockNumber)).returnData;
|
|
71
|
+
const lpTokens = returnData.map((data) => WombatBmw.bmwInterface
|
|
72
|
+
.decodeFunctionResult('poolInfo', data)[0]
|
|
73
|
+
.toLowerCase());
|
|
74
|
+
inputs = [];
|
|
75
|
+
for (const lpToken of lpTokens) {
|
|
76
|
+
inputs.push({
|
|
77
|
+
target: lpToken,
|
|
78
|
+
callData: WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
|
|
79
|
+
});
|
|
80
|
+
inputs.push({
|
|
81
|
+
target: lpToken,
|
|
82
|
+
callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
returnData = (await this.dexHelper.multiContract.methods
|
|
86
|
+
.aggregate(inputs)
|
|
87
|
+
.call({}, blockNumber)).returnData;
|
|
88
|
+
const pool2AssetInfo = new Map();
|
|
89
|
+
let i = 0;
|
|
90
|
+
for (const lpToken of lpTokens) {
|
|
91
|
+
const underlyingToken = WombatBmw.assetInterface
|
|
92
|
+
.decodeFunctionResult('underlyingToken', returnData[i++])[0]
|
|
93
|
+
.toLowerCase();
|
|
94
|
+
const pool = WombatBmw.assetInterface
|
|
95
|
+
.decodeFunctionResult('pool', returnData[i++])[0]
|
|
96
|
+
.toLowerCase();
|
|
97
|
+
if (!pool2AssetInfo.has(pool)) {
|
|
98
|
+
pool2AssetInfo.set(pool, new Map());
|
|
99
|
+
}
|
|
100
|
+
pool2AssetInfo.get(pool).set(lpToken, underlyingToken);
|
|
101
|
+
}
|
|
102
|
+
pool2AssetInfo.forEach((asset2TokenMap, pool) => {
|
|
103
|
+
bmwState.pools.push(pool);
|
|
104
|
+
this.onAssetAdded(pool, asset2TokenMap, blockNumber);
|
|
105
|
+
});
|
|
106
|
+
return bmwState;
|
|
107
|
+
}
|
|
108
|
+
async handleAdd(event, state, log) {
|
|
109
|
+
const lpToken = event.args.lpToken.toString().toLowerCase();
|
|
110
|
+
let multiCallInputs = [];
|
|
111
|
+
multiCallInputs.push({
|
|
112
|
+
target: lpToken,
|
|
113
|
+
callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
|
|
114
|
+
});
|
|
115
|
+
multiCallInputs.push({
|
|
116
|
+
target: lpToken,
|
|
117
|
+
callData: WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
|
|
118
|
+
});
|
|
119
|
+
const returnData = (await this.dexHelper.multiContract.methods
|
|
120
|
+
.aggregate(multiCallInputs)
|
|
121
|
+
.call({}, log.blockNumber)).returnData;
|
|
122
|
+
const pool = WombatBmw.assetInterface
|
|
123
|
+
.decodeFunctionResult('pool', returnData[0])[0]
|
|
124
|
+
.toLowerCase();
|
|
125
|
+
const underlyingToken = WombatBmw.assetInterface
|
|
126
|
+
.decodeFunctionResult('underlyingToken', returnData[1])[0]
|
|
127
|
+
.toLowerCase();
|
|
128
|
+
this.onAssetAdded(pool, new Map().set(lpToken, underlyingToken), log.blockNumber);
|
|
129
|
+
if (!state.pools.includes(pool)) {
|
|
130
|
+
return {
|
|
131
|
+
pools: [...state.pools, pool],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return {
|
|
136
|
+
pools: state.pools,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.WombatBmw = WombatBmw;
|
|
142
|
+
WombatBmw.bmwInterface = new abi_1.Interface(bmw_json_1.default);
|
|
143
|
+
WombatBmw.assetInterface = new abi_1.Interface(asset_json_1.default);
|
|
144
|
+
WombatBmw.poolInterface = new abi_1.Interface(pool_json_1.default);
|
|
145
|
+
//# sourceMappingURL=wombat-bmw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wombat-bmw.js","sourceRoot":"","sources":["../../../src/dex/wombat/wombat-bmw.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAM/C,uCAAiD;AACjD,+EAA0E;AAG1E,yEAA+C;AAC/C,6EAAmD;AACnD,2EAAiD;AAEjD,MAAa,SAAU,SAAQ,mDAAiC;IAe9D,YACE,MAAc,EACd,IAAY,EACF,OAAe,EACf,SAAqB,EAC/B,MAAc,EACJ,UAAmB,EACnB,YAID;QAET,KAAK,CACH,GAAG,MAAM,IAAI,IAAI,EAAE,EACnB,GAAG,MAAM,IAAI,OAAO,IAAI,IAAI,EAAE,EAC9B,SAAS,EACT,MAAM,CACP,CAAC;QAfQ,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAY;QAErB,eAAU,GAAV,UAAU,CAAS;QACnB,iBAAY,GAAZ,YAAY,CAIb;QAnBH,aAAQ,GAMZ,EAAE,CAAC;QAsBL,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACrE,IAAI,CAAC,mBAAmB,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAC7D,kBAAa,EACb,IAAI,CAAC,UAAU,CAChB,CAAC;QAEF,yBAAyB;QACzB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;;OAQG;IACO,KAAK,CAAC,UAAU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AAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACzD,WAAW,EAAE,CAAC;QAEjB,IAAI,CAAC,YAAY,CACf,IAAI,EACJ,IAAI,GAAG,EAAoB,CAAC,GAAG,CAAC,OAAO,EAAE,eAAe,CAAC,EACzD,GAAG,CAAC,WAAW,CAChB,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC/B,OAAO;gBACL,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;aAC9B,CAAC;SACH;aAAM;YACL,OAAO;gBACL,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC;SACH;IACH,CAAC;;AA/LH,8BAgMC;AA/LiB,sBAAY,GAAG,IAAI,eAAS,CAAC,kBAAM,CAAC,CAAC;AACrC,wBAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC;AACzC,uBAAa,GAAG,IAAI,eAAS,CAAC,mBAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { Address } from '@paraswap/core';
|
|
3
|
+
import { MultiCallParams, MultiResult } from '../../lib/multi-wrapper';
|
|
4
|
+
import { IDexHelper } from '../../dex-helper';
|
|
5
|
+
import { StatefulRpcPoller } from '../../lib/stateful-rpc-poller/stateful-rpc-poller';
|
|
6
|
+
import { ObjWithUpdateInfo } from '../../lib/stateful-rpc-poller/types';
|
|
7
|
+
import { MulticallResultOutputs, PoolState } from './types';
|
|
8
|
+
export declare class WombatPool extends StatefulRpcPoller<PoolState, MulticallResultOutputs> {
|
|
9
|
+
protected poolAddress: Address;
|
|
10
|
+
protected asset2TokenMap: Map<Address, Address>;
|
|
11
|
+
static readonly poolInterface: Interface;
|
|
12
|
+
static readonly assetInterface: Interface;
|
|
13
|
+
constructor(dexKey: string, poolIdentifier: string, dexHelper: IDexHelper, poolAddress: Address, asset2TokenMap: Map<Address, Address>);
|
|
14
|
+
protected _getFetchStateMultiCalls(): MultiCallParams<MulticallResultOutputs>[];
|
|
15
|
+
protected _parseStateFromMultiResults(multiOutputs: MulticallResultOutputs[]): PoolState;
|
|
16
|
+
fetchLatestStateFromRpc(): Promise<ObjWithUpdateInfo<PoolState> | null>;
|
|
17
|
+
parseStateFromMultiResultsWithBlockInfo(multiOutputs: [
|
|
18
|
+
MultiResult<number>,
|
|
19
|
+
...MultiResult<MulticallResultOutputs>[]
|
|
20
|
+
], lastUpdatedAtMs: number): ObjWithUpdateInfo<PoolState>;
|
|
21
|
+
addAssets(asset2TokenMap: Map<Address, Address>): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WombatPool = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const stateful_rpc_poller_1 = require("../../lib/stateful-rpc-poller/stateful-rpc-poller");
|
|
10
|
+
const state_polling_manager_1 = require("../../lib/stateful-rpc-poller/state-polling-manager");
|
|
11
|
+
const utils_1 = require("../../lib/stateful-rpc-poller/utils");
|
|
12
|
+
const decoders_1 = require("../../lib/decoders");
|
|
13
|
+
const pool_json_1 = __importDefault(require("../../abi/wombat/pool.json"));
|
|
14
|
+
const asset_json_1 = __importDefault(require("../../abi/wombat/asset.json"));
|
|
15
|
+
const utils_2 = require("./utils");
|
|
16
|
+
class WombatPool extends stateful_rpc_poller_1.StatefulRpcPoller {
|
|
17
|
+
constructor(dexKey, poolIdentifier, dexHelper, poolAddress, asset2TokenMap) {
|
|
18
|
+
const callbacks = (0, utils_1.pollingManagerCbExtractor)(state_polling_manager_1.StatePollingManager.getInstance(dexHelper));
|
|
19
|
+
super(dexKey, poolIdentifier, dexHelper, 0, 0, false, callbacks);
|
|
20
|
+
this.poolAddress = poolAddress;
|
|
21
|
+
this.asset2TokenMap = asset2TokenMap;
|
|
22
|
+
}
|
|
23
|
+
_getFetchStateMultiCalls() {
|
|
24
|
+
const params = [];
|
|
25
|
+
params.push({
|
|
26
|
+
target: this.poolAddress,
|
|
27
|
+
callData: WombatPool.poolInterface.encodeFunctionData('paused'),
|
|
28
|
+
decodeFunction: decoders_1.booleanDecode,
|
|
29
|
+
});
|
|
30
|
+
params.push({
|
|
31
|
+
target: this.poolAddress,
|
|
32
|
+
callData: WombatPool.poolInterface.encodeFunctionData('ampFactor'),
|
|
33
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
34
|
+
});
|
|
35
|
+
params.push({
|
|
36
|
+
target: this.poolAddress,
|
|
37
|
+
callData: WombatPool.poolInterface.encodeFunctionData('haircutRate'),
|
|
38
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
39
|
+
});
|
|
40
|
+
params.push({
|
|
41
|
+
target: this.poolAddress,
|
|
42
|
+
callData: WombatPool.poolInterface.encodeFunctionData('startCovRatio'),
|
|
43
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
44
|
+
});
|
|
45
|
+
params.push({
|
|
46
|
+
target: this.poolAddress,
|
|
47
|
+
callData: WombatPool.poolInterface.encodeFunctionData('endCovRatio'),
|
|
48
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
49
|
+
});
|
|
50
|
+
params.push({
|
|
51
|
+
target: this.poolAddress,
|
|
52
|
+
callData: WombatPool.poolInterface.encodeFunctionData('getTokens'),
|
|
53
|
+
decodeFunction: decoders_1.addressArrayDecode,
|
|
54
|
+
});
|
|
55
|
+
this.asset2TokenMap.forEach((token, asset) => {
|
|
56
|
+
params.push({
|
|
57
|
+
target: this.poolAddress,
|
|
58
|
+
callData: WombatPool.poolInterface.encodeFunctionData('isPaused', [
|
|
59
|
+
token,
|
|
60
|
+
]),
|
|
61
|
+
decodeFunction: decoders_1.booleanDecode,
|
|
62
|
+
});
|
|
63
|
+
params.push({
|
|
64
|
+
target: asset,
|
|
65
|
+
callData: WombatPool.assetInterface.encodeFunctionData('cash'),
|
|
66
|
+
decodeFunction: utils_2.uint120ToBigInt,
|
|
67
|
+
});
|
|
68
|
+
params.push({
|
|
69
|
+
target: asset,
|
|
70
|
+
callData: WombatPool.assetInterface.encodeFunctionData('liability'),
|
|
71
|
+
decodeFunction: utils_2.uint120ToBigInt,
|
|
72
|
+
});
|
|
73
|
+
params.push({
|
|
74
|
+
target: asset,
|
|
75
|
+
callData: WombatPool.assetInterface.encodeFunctionData('underlyingTokenDecimals'),
|
|
76
|
+
decodeFunction: decoders_1.uint8ToNumber,
|
|
77
|
+
});
|
|
78
|
+
params.push({
|
|
79
|
+
target: asset,
|
|
80
|
+
callData: WombatPool.assetInterface.encodeFunctionData('getRelativePrice'),
|
|
81
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return params;
|
|
85
|
+
}
|
|
86
|
+
_parseStateFromMultiResults(multiOutputs) {
|
|
87
|
+
const [paused, ampFactor, haircutRate, startCovRatio, endCovRatio, tokens, ...remained] = multiOutputs;
|
|
88
|
+
const assetTokenArray = Array.from(this.asset2TokenMap.entries());
|
|
89
|
+
const token2AssetStates = new Map();
|
|
90
|
+
lodash_1.default.chunk(remained, 5).forEach((chunk, i) => {
|
|
91
|
+
const [paused, cash, liability, underlyingTokenDecimals, relativePrice] = chunk;
|
|
92
|
+
const [asset, token] = assetTokenArray[i];
|
|
93
|
+
token2AssetStates.set(token, {
|
|
94
|
+
address: asset,
|
|
95
|
+
paused,
|
|
96
|
+
cash,
|
|
97
|
+
liability,
|
|
98
|
+
underlyingTokenDecimals,
|
|
99
|
+
relativePrice,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
const poolState = {
|
|
103
|
+
params: {
|
|
104
|
+
paused,
|
|
105
|
+
ampFactor,
|
|
106
|
+
haircutRate,
|
|
107
|
+
startCovRatio,
|
|
108
|
+
endCovRatio,
|
|
109
|
+
},
|
|
110
|
+
underlyingAddresses: tokens,
|
|
111
|
+
asset: {},
|
|
112
|
+
};
|
|
113
|
+
const isMainPool = Array.from(token2AssetStates.values()).filter(assetState => assetState.relativePrice === undefined).length > 0;
|
|
114
|
+
for (const token of poolState.underlyingAddresses) {
|
|
115
|
+
if (!token2AssetStates.has(token)) {
|
|
116
|
+
// this happens when asset has been added to pool but is not added to BMW yet
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
poolState.asset[token] = token2AssetStates.get(token);
|
|
120
|
+
if (isMainPool) {
|
|
121
|
+
poolState.asset[token].relativePrice = undefined;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return poolState;
|
|
125
|
+
}
|
|
126
|
+
async fetchLatestStateFromRpc() {
|
|
127
|
+
const multiCalls = this.getFetchStateWithBlockInfoMultiCalls();
|
|
128
|
+
try {
|
|
129
|
+
const lastUpdatedAtMs = Date.now();
|
|
130
|
+
const aggregatedResults = (await this.dexHelper.multiWrapper.tryAggregate(false, multiCalls));
|
|
131
|
+
return this.parseStateFromMultiResultsWithBlockInfo(aggregatedResults, lastUpdatedAtMs);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
this._logMessageWithSuppression('ERROR_FETCHING_STATE_FROM_RPC', e);
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
parseStateFromMultiResultsWithBlockInfo(multiOutputs, lastUpdatedAtMs) {
|
|
139
|
+
const [blockNumber, ...outputsForAbstract] = multiOutputs.map((m, i) => {
|
|
140
|
+
return m.returnData;
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
value: this._parseStateFromMultiResults(outputsForAbstract),
|
|
144
|
+
blockNumber,
|
|
145
|
+
lastUpdatedAtMs,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
addAssets(asset2TokenMap) {
|
|
149
|
+
for (const [asset, token] of asset2TokenMap) {
|
|
150
|
+
if (this.asset2TokenMap.has(asset)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
this.asset2TokenMap.set(asset, token);
|
|
154
|
+
this._cachedMultiCallData = undefined;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.WombatPool = WombatPool;
|
|
159
|
+
WombatPool.poolInterface = new abi_1.Interface(pool_json_1.default);
|
|
160
|
+
WombatPool.assetInterface = new abi_1.Interface(asset_json_1.default);
|
|
161
|
+
//# sourceMappingURL=wombat-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wombat-pool.js","sourceRoot":"","sources":["../../../src/dex/wombat/wombat-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAE/C,oDAAuB;AAIvB,2FAAsF;AACtF,+FAA0F;AAE1F,+DAAgF;AAChF,iDAK4B;AAC5B,2EAAiD;AACjD,6EAAmD;AACnD,mCAA0C;AAG1C,MAAa,UAAW,SAAQ,uCAG/B;IAIC,YACE,MAAc,EACd,cAAsB,EACtB,SAAqB,EACX,WAAoB,EACpB,cAAqC;QAE/C,MAAM,SAAS,GAAG,IAAA,iCAAyB,EACzC,2CAAmB,CAAC,WAAW,CAAC,SAAS,CAAC,CAC3C,CAAC;QAEF,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAPvD,gBAAW,GAAX,WAAW,CAAS;QACpB,mBAAc,GAAd,cAAc,CAAuB;IAOjD,CAAC;IAES,wBAAwB;QAChC,MAAM,MAAM,GAA8C,EAAE,CAAC;QAE7D,MAAM,CAAC,IAAI,CAAC;YACV,MAAM,EAAE,IAAI,CAAC,WAAW;YACxB,QAA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,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,YAAY,CAGvE,KAAK,EACL,UAAgE,CACjE,CAAoE,CAAC;YAEtE,OAAO,IAAI,CAAC,uCAAuC,CACjD,iBAAiB,EACjB,eAAe,CAChB,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,0BAA0B,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC;SACrE;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,uCAAuC,CAC5C,YAGC,EACD,eAAuB;QAEvB,MAAM,CAAC,WAAW,EAAE,GAAG,kBAAkB,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACrE,OAAO,CAAC,CAAC,UAAU,CAAC;QACtB,CAAC,CAA0C,CAAC;QAE5C,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,2BAA2B,CAAC,kBAAkB,CAAC;YAC3D,WAAW;YACX,eAAe;SAChB,CAAC;IACJ,CAAC;IAEM,SAAS,CAAC,cAAqC;QACpD,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,cAAc,EAAE;YAC3C,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;gBAClC,SAAS;aACV;YAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACtC,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;SACvC;IACH,CAAC;;AAhNH,gCAiNC;AA7MiB,wBAAa,GAAG,IAAI,eAAS,CAAC,mBAAO,CAAC,CAAC;AACvC,yBAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AssetState, PoolParams } from './types';
|
|
2
|
+
export declare class WombatQuoter {
|
|
3
|
+
private readonly ampFactor;
|
|
4
|
+
private readonly haircutRate;
|
|
5
|
+
private readonly startCovRatio;
|
|
6
|
+
private readonly endCovRatio;
|
|
7
|
+
constructor(poolParams: PoolParams);
|
|
8
|
+
getQuote(fromAsset: AssetState, toAsset: AssetState, fromAmount: bigint): bigint;
|
|
9
|
+
private _highCovRatioPoolQuoteFrom;
|
|
10
|
+
private _highCovRatioFee;
|
|
11
|
+
private _quoteFrom;
|
|
12
|
+
private _findUpperBound;
|
|
13
|
+
private _quoteFactor;
|
|
14
|
+
static solveQuad(b: bigint, c: bigint): bigint;
|
|
15
|
+
static swapQuoteFunc(aX: bigint, aY: bigint, lX: bigint, lY: bigint, dX: bigint, a: bigint): bigint;
|
|
16
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WombatQuoter = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class WombatQuoter {
|
|
6
|
+
constructor(poolParams) {
|
|
7
|
+
this.ampFactor = poolParams.ampFactor;
|
|
8
|
+
this.haircutRate = poolParams.haircutRate;
|
|
9
|
+
this.startCovRatio = poolParams.startCovRatio;
|
|
10
|
+
this.endCovRatio = poolParams.endCovRatio;
|
|
11
|
+
}
|
|
12
|
+
getQuote(fromAsset, toAsset, fromAmount) {
|
|
13
|
+
if (fromAmount === 0n || fromAsset.paused) {
|
|
14
|
+
return 0n;
|
|
15
|
+
}
|
|
16
|
+
fromAmount = (0, utils_1.toWad)(fromAmount, BigInt(fromAsset.underlyingTokenDecimals));
|
|
17
|
+
try {
|
|
18
|
+
const { actualToAmount, haircut } = this._highCovRatioPoolQuoteFrom(fromAsset, toAsset, fromAmount);
|
|
19
|
+
const toCash = toAsset.cash - actualToAmount - haircut;
|
|
20
|
+
if ((0, utils_1.wdiv)(toCash, toAsset.liability) < utils_1.WAD / 100n) {
|
|
21
|
+
return 0n;
|
|
22
|
+
}
|
|
23
|
+
return (0, utils_1.fromWad)(actualToAmount, BigInt(toAsset.underlyingTokenDecimals));
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return 0n;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
_highCovRatioPoolQuoteFrom(fromAsset, toAsset, fromAmount) {
|
|
30
|
+
let { actualToAmount, haircut } = this._quoteFrom(fromAsset, toAsset, fromAmount);
|
|
31
|
+
if (fromAmount > 0n) {
|
|
32
|
+
const fromCash = fromAsset.cash;
|
|
33
|
+
const fromLiability = fromAsset.liability;
|
|
34
|
+
const finalFromAssetCovRatio = (0, utils_1.wdiv)(fromCash + fromAmount, fromLiability);
|
|
35
|
+
if (finalFromAssetCovRatio > this.startCovRatio) {
|
|
36
|
+
// charge high cov ratio fee
|
|
37
|
+
const highCovRatioFee = (0, utils_1.wmul)(this._highCovRatioFee((0, utils_1.wdiv)(fromCash, fromLiability), finalFromAssetCovRatio), actualToAmount);
|
|
38
|
+
actualToAmount -= highCovRatioFee;
|
|
39
|
+
haircut += highCovRatioFee;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// reverse quote
|
|
44
|
+
const toCash = toAsset.cash;
|
|
45
|
+
const toLiability = toAsset.liability;
|
|
46
|
+
const finalToAssetCovRatio = (0, utils_1.wdiv)(toCash + actualToAmount, toLiability);
|
|
47
|
+
if (finalToAssetCovRatio <= this.startCovRatio) {
|
|
48
|
+
// happy path: no high cov ratio fee is charged
|
|
49
|
+
return { actualToAmount, haircut };
|
|
50
|
+
}
|
|
51
|
+
else if ((0, utils_1.wdiv)(toCash, toLiability) >= this.endCovRatio) {
|
|
52
|
+
// the to-asset exceeds it's cov ratio limit, further swap to increase cov ratio is impossible
|
|
53
|
+
throw new Error('WOMBAT_COV_RATIO_LIMIT_EXCEEDED');
|
|
54
|
+
}
|
|
55
|
+
// reverse quote: cov ratio of the to-asset exceed endCovRatio. direct reverse quote is not supported
|
|
56
|
+
// we binary search for a upper bound
|
|
57
|
+
actualToAmount = this._findUpperBound(toAsset, fromAsset, -fromAmount);
|
|
58
|
+
const result = this._highCovRatioPoolQuoteFrom(toAsset, fromAsset, actualToAmount);
|
|
59
|
+
haircut = result.haircut;
|
|
60
|
+
}
|
|
61
|
+
return { actualToAmount, haircut };
|
|
62
|
+
}
|
|
63
|
+
_highCovRatioFee(initCovRatio, finalCovRatio) {
|
|
64
|
+
const startCovRatio = this.startCovRatio;
|
|
65
|
+
const endCovRatio = this.endCovRatio;
|
|
66
|
+
if (finalCovRatio > endCovRatio) {
|
|
67
|
+
// invalid swap
|
|
68
|
+
throw new Error('WOMBAT_COV_RATIO_LIMIT_EXCEEDED');
|
|
69
|
+
}
|
|
70
|
+
else if (finalCovRatio <= startCovRatio ||
|
|
71
|
+
finalCovRatio <= initCovRatio) {
|
|
72
|
+
return 0n;
|
|
73
|
+
}
|
|
74
|
+
// 1. Calculate the area of fee(r) = (r - startCovRatio) / (endCovRatio - startCovRatio)
|
|
75
|
+
// when r increase from initCovRatio to finalCovRatio
|
|
76
|
+
// 2. Then multiply it by (endCovRatio - startCovRatio) / (finalCovRatio - initCovRatio)
|
|
77
|
+
// to get the average fee over the range
|
|
78
|
+
const a = initCovRatio <= startCovRatio
|
|
79
|
+
? 0n
|
|
80
|
+
: (initCovRatio - startCovRatio) * (initCovRatio - startCovRatio);
|
|
81
|
+
const b = (finalCovRatio - startCovRatio) * (finalCovRatio - startCovRatio);
|
|
82
|
+
return (0, utils_1.wdiv)((b - a) / (finalCovRatio - initCovRatio) / BigInt(2), endCovRatio - startCovRatio);
|
|
83
|
+
}
|
|
84
|
+
_quoteFrom(fromAsset, toAsset, fromAmount) {
|
|
85
|
+
if (fromAmount < 0n) {
|
|
86
|
+
fromAmount = (0, utils_1.wdiv)(fromAmount, utils_1.WAD - this.haircutRate);
|
|
87
|
+
}
|
|
88
|
+
let fromCash = fromAsset.cash;
|
|
89
|
+
const toCash = toAsset.cash;
|
|
90
|
+
let fromLiability = fromAsset.liability;
|
|
91
|
+
const toLiability = toAsset.liability;
|
|
92
|
+
const scaleFactor = this._quoteFactor(fromAsset, toAsset);
|
|
93
|
+
if (scaleFactor !== utils_1.WAD) {
|
|
94
|
+
fromCash = (fromCash * scaleFactor) / utils_1.WAD;
|
|
95
|
+
fromLiability = (fromLiability * scaleFactor) / utils_1.WAD;
|
|
96
|
+
fromAmount = (fromAmount * scaleFactor) / utils_1.WAD;
|
|
97
|
+
}
|
|
98
|
+
const idealToAmount = WombatQuoter.swapQuoteFunc(fromCash, toCash, fromLiability, toLiability, fromAmount, this.ampFactor);
|
|
99
|
+
if ((fromAmount > 0n && toCash < idealToAmount) ||
|
|
100
|
+
(fromAmount < 0n && fromCash < -fromAmount)) {
|
|
101
|
+
throw new Error('WOMBAT_CASH_NOT_ENOUGH');
|
|
102
|
+
}
|
|
103
|
+
let actualToAmount, haircut;
|
|
104
|
+
if (fromAmount > 0) {
|
|
105
|
+
haircut = (0, utils_1.wmul)(idealToAmount, this.haircutRate);
|
|
106
|
+
actualToAmount = idealToAmount - haircut;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
actualToAmount = idealToAmount;
|
|
110
|
+
haircut = (0, utils_1.wmul)(-fromAmount, this.haircutRate);
|
|
111
|
+
}
|
|
112
|
+
return { actualToAmount, haircut };
|
|
113
|
+
}
|
|
114
|
+
_findUpperBound(fromAsset, toAsset, toAmount) {
|
|
115
|
+
const decimals = BigInt(fromAsset.underlyingTokenDecimals);
|
|
116
|
+
const toWadFactor = (0, utils_1.toWad)(1n, decimals);
|
|
117
|
+
// the search value uses the same number of digits as the token
|
|
118
|
+
let high = (0, utils_1.fromWad)((0, utils_1.wmul)(fromAsset.liability, this.endCovRatio) - fromAsset.cash, decimals);
|
|
119
|
+
let low = 1n;
|
|
120
|
+
// verify `high` is a valid upper bound
|
|
121
|
+
const { actualToAmount: quote } = this._highCovRatioPoolQuoteFrom(fromAsset, toAsset, high * toWadFactor);
|
|
122
|
+
if (quote < toAmount) {
|
|
123
|
+
throw new Error('WOMBAT_COV_RATIO_LIMIT_EXCEEDED');
|
|
124
|
+
}
|
|
125
|
+
// Note: we might limit the maximum number of rounds if the request is always rejected by the RPC server
|
|
126
|
+
while (low < high) {
|
|
127
|
+
const mid = (low + high) / BigInt(2);
|
|
128
|
+
const { actualToAmount: quote } = this._highCovRatioPoolQuoteFrom(fromAsset, toAsset, mid * toWadFactor);
|
|
129
|
+
if (quote >= toAmount) {
|
|
130
|
+
high = mid;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
low = mid + 1n;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return high * toWadFactor;
|
|
137
|
+
}
|
|
138
|
+
_quoteFactor(fromAsset, toAsset) {
|
|
139
|
+
if (!fromAsset.relativePrice || !toAsset.relativePrice) {
|
|
140
|
+
return utils_1.WAD;
|
|
141
|
+
}
|
|
142
|
+
return (utils_1.WAD * fromAsset.relativePrice) / toAsset.relativePrice;
|
|
143
|
+
}
|
|
144
|
+
static solveQuad(b, c) {
|
|
145
|
+
return ((0, utils_1.sqrt)(b * b + c * 4n * utils_1.WAD, b) - b) / 2n;
|
|
146
|
+
}
|
|
147
|
+
static swapQuoteFunc(aX, aY, lX, lY, dX, a) {
|
|
148
|
+
if (lX == 0n || lY == 0n) {
|
|
149
|
+
// in case div of 0, CORE_UNDERFLOW
|
|
150
|
+
return 0n;
|
|
151
|
+
}
|
|
152
|
+
// int256 D = Ax + Ay - A.wmul((Lx * Lx) / Ax + (Ly * Ly) / Ay); // flattened _invariantFunc
|
|
153
|
+
const d = aX + aY - (0, utils_1.wmul)(a, (lX * lX) / aX + (lY * lY) / aY);
|
|
154
|
+
// int256 rx_ = (Ax + Dx).wdiv(Lx);
|
|
155
|
+
const rX = (0, utils_1.wdiv)(aX + dX, lX);
|
|
156
|
+
// int256 b = (Lx * (rx_ - A.wdiv(rx_))) / Ly - D.wdiv(Ly); // flattened _coefficientFunc
|
|
157
|
+
const b = (lX * (rX - (0, utils_1.wdiv)(a, rX))) / lY - (0, utils_1.wdiv)(d, lY);
|
|
158
|
+
// int256 ry_ = _solveQuad(b, A);
|
|
159
|
+
const rY = WombatQuoter.solveQuad(b, a);
|
|
160
|
+
// int256 Dy = Ly.wmul(ry_) - Ay;
|
|
161
|
+
const dY = (0, utils_1.wmul)(lY, rY) - aY;
|
|
162
|
+
// if (Dy < 0) {
|
|
163
|
+
// quote = uint256(-Dy);
|
|
164
|
+
// } else {
|
|
165
|
+
// quote = uint256(Dy);
|
|
166
|
+
// }
|
|
167
|
+
if (dY < 0n) {
|
|
168
|
+
return -dY;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
return dY;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.WombatQuoter = WombatQuoter;
|
|
176
|
+
//# sourceMappingURL=wombat-quoter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wombat-quoter.js","sourceRoot":"","sources":["../../../src/dex/wombat/wombat-quoter.ts"],"names":[],"mappings":";;;AACA,mCAAgE;AAEhE,MAAa,YAAY;IAMvB,YAAY,UAAsB;QAChC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAEM,QAAQ,CACb,SAAqB,EACrB,OAAmB,EACnB,UAAkB;QAElB,IAAI,UAAU,KAAK,EAAE,IAAI,SAAS,CAAC,MAAM,EAAE;YACzC,OAAO,EAAE,CAAC;SACX;QAED,UAAU,GAAG,IAAA,aAAK,EAAC,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,CAAC;QAE1E,IAAI;YACF,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,0BA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,yFAAyF;QACzF,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,IAAA,YAAI,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAA,YAAI,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvD,iCAAiC;QACjC,MAAM,EAAE,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,iCAAiC;QACjC,MAAM,EAAE,GAAG,IAAA,YAAI,EAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;QAE7B,gBAAgB;QAChB,4BAA4B;QAC5B,WAAW;QACX,2BAA2B;QAC3B,IAAI;QACJ,IAAI,EAAE,GAAG,EAAE,EAAE;YACX,OAAO,CAAC,EAAE,CAAC;SACZ;aAAM;YACL,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CACF;AAzQD,oCAyQC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
2
|
+
import { Interface } from '@ethersproject/abi';
|
|
3
|
+
import { SwapSide } from '@paraswap/core';
|
|
4
|
+
import { AdapterExchangeParam, Address, ExchangePrices, Logger, PoolLiquidity, PoolPrices, SimpleExchangeParam, Token } from '../../types';
|
|
5
|
+
import { Network } from '../../constants';
|
|
6
|
+
import { IDex } from '../idex';
|
|
7
|
+
import { IDexHelper } from '../../dex-helper';
|
|
8
|
+
import { DexParams, PoolState, WombatData } from './types';
|
|
9
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
10
|
+
import { WombatBmw } from './wombat-bmw';
|
|
11
|
+
import { WombatPool } from './wombat-pool';
|
|
12
|
+
export declare class Wombat extends SimpleExchange implements IDex<WombatData> {
|
|
13
|
+
readonly network: Network;
|
|
14
|
+
readonly dexKey: string;
|
|
15
|
+
readonly dexHelper: IDexHelper;
|
|
16
|
+
protected adapters: import("../../types").AdapterMappings;
|
|
17
|
+
static readonly erc20Interface: Interface;
|
|
18
|
+
static readonly poolInterface: Interface;
|
|
19
|
+
static readonly assetInterface: Interface;
|
|
20
|
+
protected config: DexParams;
|
|
21
|
+
protected poolLiquidityUSD?: {
|
|
22
|
+
[poolAddress: string]: number;
|
|
23
|
+
};
|
|
24
|
+
bmw: WombatBmw;
|
|
25
|
+
pools: {
|
|
26
|
+
[poolAddress: string]: WombatPool;
|
|
27
|
+
};
|
|
28
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
29
|
+
readonly needWrapNative = true;
|
|
30
|
+
readonly isFeeOnTransferSupported = false;
|
|
31
|
+
static dexKeysWithNetwork: {
|
|
32
|
+
key: string;
|
|
33
|
+
networks: Network[];
|
|
34
|
+
}[];
|
|
35
|
+
logger: Logger;
|
|
36
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: import("../../types").AdapterMappings);
|
|
37
|
+
init(blockNumber: number): Promise<void>;
|
|
38
|
+
initializePricing(blockNumber: number): Promise<void>;
|
|
39
|
+
onAssetAdded: (pool: Address, asset2TokenMap: Map<Address, Address>, blockNumber: number) => void;
|
|
40
|
+
getAdapters(side: SwapSide): {
|
|
41
|
+
name: string;
|
|
42
|
+
index: number;
|
|
43
|
+
}[] | null;
|
|
44
|
+
getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
45
|
+
protected getPoolIdentifier(poolAddress: Address): string;
|
|
46
|
+
getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<WombatData>>;
|
|
47
|
+
protected computePrices(srcTokenAddress: Address, destTokenAddress: Address, amounts: bigint[], side: SwapSide, state: DeepReadonly<PoolState>): bigint[];
|
|
48
|
+
protected findPools(srcTokenAddress: Address, destTokenAddress: Address, blockNumber: number, liquidityThresholdInUSD?: number): Promise<Address[]>;
|
|
49
|
+
getCalldataGasCost(poolPrices: PoolPrices<WombatData>): number | number[];
|
|
50
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: WombatData, side: SwapSide): AdapterExchangeParam;
|
|
51
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: WombatData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
52
|
+
updatePoolState(): Promise<void>;
|
|
53
|
+
getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
|
|
54
|
+
releaseResources(): AsyncOrSync<void>;
|
|
55
|
+
}
|