@paraswap/dex-lib 3.4.1 → 3.4.2-idle
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/Redstone.json +739 -0
- package/build/abi/angle-transmuter/MorphoOracle.json +193 -0
- package/build/abi/angle-transmuter/MorphoVault.json +2506 -0
- package/build/abi/angle-transmuter/Pyth.json +1534 -0
- package/build/abi/angle-transmuter/Transmuter.json +1711 -0
- package/build/abi/angle-transmuter/TransmuterSidechain.json +1798 -0
- package/build/abi/idle-dao/idle-cdo-factory.json +38 -0
- package/build/abi/idle-dao/idle-cdo.json +1245 -0
- package/build/abi/pharaoh/PharaohPool.abi.json +1582 -0
- package/build/abi/smardex/smardex-factory.json +185 -0
- package/build/abi/smardex/smardex-pool.json +578 -0
- package/build/abi/smardex/smardex-router.json +648 -0
- package/build/abi/trader-joe-v2_1/FactoryABI.json +1208 -0
- package/build/abi/trader-joe-v2_1/PairABI.json +1493 -0
- package/build/abi/trader-joe-v2_1/RouterABI.json +1489 -0
- package/build/abi/trader-joe-v2_1/StateMulticall.json +193 -0
- package/build/config.js +11 -5
- package/build/config.js.map +1 -1
- package/build/dex/aave-v1/aave-v1.js +0 -1
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/angle-transmuter/angle-transmuter-pool.d.ts +61 -0
- package/build/dex/angle-transmuter/angle-transmuter-pool.js +424 -0
- package/build/dex/angle-transmuter/angle-transmuter-pool.js.map +1 -0
- package/build/dex/angle-transmuter/angle-transmuter.d.ts +60 -0
- package/build/dex/angle-transmuter/angle-transmuter.js +281 -0
- package/build/dex/angle-transmuter/angle-transmuter.js.map +1 -0
- package/build/dex/angle-transmuter/backedOracle.d.ts +19 -0
- package/build/dex/angle-transmuter/backedOracle.js +56 -0
- package/build/dex/angle-transmuter/backedOracle.js.map +1 -0
- package/build/dex/angle-transmuter/config.d.ts +4 -0
- package/build/dex/angle-transmuter/config.js +50 -0
- package/build/dex/angle-transmuter/config.js.map +1 -0
- package/build/dex/angle-transmuter/constants.d.ts +10 -0
- package/build/dex/angle-transmuter/constants.js +137 -0
- package/build/dex/angle-transmuter/constants.js.map +1 -0
- package/build/dex/angle-transmuter/morphoOracle.d.ts +42 -0
- package/build/dex/angle-transmuter/morphoOracle.js +179 -0
- package/build/dex/angle-transmuter/morphoOracle.js.map +1 -0
- package/build/dex/angle-transmuter/morphoVault.d.ts +20 -0
- package/build/dex/angle-transmuter/morphoVault.js +84 -0
- package/build/dex/angle-transmuter/morphoVault.js.map +1 -0
- package/build/dex/angle-transmuter/pyth.d.ts +19 -0
- package/build/dex/angle-transmuter/pyth.js +70 -0
- package/build/dex/angle-transmuter/pyth.js.map +1 -0
- package/build/dex/angle-transmuter/redstone.d.ts +20 -0
- package/build/dex/angle-transmuter/redstone.js +73 -0
- package/build/dex/angle-transmuter/redstone.js.map +1 -0
- package/build/dex/angle-transmuter/transmuter.d.ts +55 -0
- package/build/dex/angle-transmuter/transmuter.js +412 -0
- package/build/dex/angle-transmuter/transmuter.js.map +1 -0
- package/build/dex/angle-transmuter/types.d.ts +189 -0
- package/build/dex/angle-transmuter/types.js +33 -0
- package/build/dex/angle-transmuter/types.js.map +1 -0
- package/build/dex/angle-transmuter/utils.d.ts +9 -0
- package/build/dex/angle-transmuter/utils.js +257 -0
- package/build/dex/angle-transmuter/utils.js.map +1 -0
- package/build/dex/idle-dao/config.d.ts +7 -0
- package/build/dex/idle-dao/config.js +571 -0
- package/build/dex/idle-dao/config.js.map +1 -0
- package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
- package/build/dex/idle-dao/idle-dao-pool.js +176 -0
- package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
- package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
- package/build/dex/idle-dao/idle-dao.d.ts +52 -0
- package/build/dex/idle-dao/idle-dao.js +321 -0
- package/build/dex/idle-dao/idle-dao.js.map +1 -0
- package/build/dex/idle-dao/tokens.d.ts +16 -0
- package/build/dex/idle-dao/tokens.js +87 -0
- package/build/dex/idle-dao/tokens.js.map +1 -0
- package/build/dex/idle-dao/types.d.ts +37 -0
- package/build/dex/idle-dao/types.js +11 -0
- package/build/dex/idle-dao/types.js.map +1 -0
- package/build/dex/idle-dao/utils.d.ts +8 -0
- package/build/dex/idle-dao/utils.js +147 -0
- package/build/dex/idle-dao/utils.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/platypus/platypus.js +3 -17
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/smardex/subgraph-queries.d.ts +1 -0
- package/build/dex/smardex/subgraph-queries.js +17 -0
- package/build/dex/smardex/subgraph-queries.js.map +1 -0
- package/build/dex/smardex/usd-reserves.d.ts +23 -0
- package/build/dex/smardex/usd-reserves.js +86 -0
- package/build/dex/smardex/usd-reserves.js.map +1 -0
- package/build/dex/stable-pool.js +8 -1
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.js +0 -4
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/swaap-v2/config.js +15 -0
- package/build/dex/swaap-v2/config.js.map +1 -1
- package/build/dex/trader-joe-v2-1-2/config.d.ts +4 -0
- package/build/dex/trader-joe-v2-1-2/config.js +47 -0
- package/build/dex/trader-joe-v2-1-2/config.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/constants.d.ts +20 -0
- package/build/dex/trader-joe-v2-1-2/constants.js +22 -0
- package/build/dex/trader-joe-v2-1-2/constants.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/math/index.d.ts +37 -0
- package/build/dex/trader-joe-v2-1-2/math/index.js +291 -0
- package/build/dex/trader-joe-v2-1-2/math/index.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.d.ts +60 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js +248 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.d.ts +53 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js +307 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/types.d.ts +82 -0
- package/build/dex/trader-joe-v2-1-2/types.js +9 -0
- package/build/dex/trader-joe-v2-1-2/types.js.map +1 -0
- package/build/dex/trader-joe-v2_1/config.d.ts +4 -0
- package/build/dex/trader-joe-v2_1/config.js +47 -0
- package/build/dex/trader-joe-v2_1/config.js.map +1 -0
- package/build/dex/trader-joe-v2_1/constants.d.ts +20 -0
- package/build/dex/trader-joe-v2_1/constants.js +22 -0
- package/build/dex/trader-joe-v2_1/constants.js.map +1 -0
- package/build/dex/trader-joe-v2_1/math/index.d.ts +37 -0
- package/build/dex/trader-joe-v2_1/math/index.js +291 -0
- package/build/dex/trader-joe-v2_1/math/index.js.map +1 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.d.ts +0 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js +384 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js.map +1 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.d.ts +60 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js +247 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js.map +1 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.d.ts +53 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js +307 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js.map +1 -0
- package/build/dex/trader-joe-v2_1/types.d.ts +82 -0
- package/build/dex/trader-joe-v2_1/types.js +9 -0
- package/build/dex/trader-joe-v2_1/types.js.map +1 -0
- package/build/dex/wombat/wombat-pool-poller.d.ts +22 -0
- package/build/dex/wombat/wombat-pool-poller.js +164 -0
- package/build/dex/wombat/wombat-pool-poller.js.map +1 -0
- package/build/dex-helper/Cache.d.ts +31 -0
- package/build/dex-helper/Cache.js +106 -0
- package/build/dex-helper/Cache.js.map +1 -0
- package/build/dex-helper/RedisBatcher.d.ts +20 -0
- package/build/dex-helper/RedisBatcher.js +75 -0
- package/build/dex-helper/RedisBatcher.js.map +1 -0
- package/build/dex-helper/RedisWrapper.d.ts +37 -0
- package/build/dex-helper/RedisWrapper.js +165 -0
- package/build/dex-helper/RedisWrapper.js.map +1 -0
- package/build/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/abi/idle-dao/idle-cdo-factory.json +38 -0
- package/src/abi/idle-dao/idle-cdo.json +1245 -0
- package/src/config.ts +12 -5
- package/src/dex/idle-dao/config.ts +574 -0
- package/src/dex/idle-dao/idle-dao-e2e.test.ts +113 -0
- package/src/dex/idle-dao/idle-dao-events.test.ts +133 -0
- package/src/dex/idle-dao/idle-dao-integration.test.ts +166 -0
- package/src/dex/idle-dao/idle-dao-pool.ts +304 -0
- package/src/dex/idle-dao/idle-dao-pooling-pool.ts +87 -0
- package/src/dex/idle-dao/idle-dao.ts +509 -0
- package/src/dex/idle-dao/tokens.ts +117 -0
- package/src/dex/idle-dao/types.ts +48 -0
- package/src/dex/idle-dao/utils.ts +216 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/swaap-v2/config.ts +15 -0
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +233 -17
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +1 -1
- package/src/types.ts +1 -0
- package/tests/constants-e2e.ts +82 -6
- package/.vscode/launch.json +0 -53
- package/.vscode/settings.json +0 -2
- package/.vscode/tasks.json +0 -15
- package/abis.txt +0 -92
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
- package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
|
@@ -0,0 +1,176 @@
|
|
|
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.IdleDaoEventPool = void 0;
|
|
7
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const abi_1 = require("@ethersproject/abi");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const erc20_json_1 = __importDefault(require("../../abi/erc20.json"));
|
|
11
|
+
const idle_cdo_json_1 = __importDefault(require("../../abi/idle-dao/idle-cdo.json"));
|
|
12
|
+
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
13
|
+
const idle_dao_pooling_pool_1 = require("./idle-dao-pooling-pool");
|
|
14
|
+
const tokens_1 = require("./tokens");
|
|
15
|
+
class IdleDaoEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
16
|
+
constructor(parentName, network, dexHelper, logger, idleToken, IdleDao) {
|
|
17
|
+
// TODO: Add pool name
|
|
18
|
+
super(parentName, idleToken.idleSymbol, dexHelper, logger);
|
|
19
|
+
this.parentName = parentName;
|
|
20
|
+
this.network = network;
|
|
21
|
+
this.dexHelper = dexHelper;
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this.idleToken = idleToken;
|
|
24
|
+
this.IdleDao = IdleDao;
|
|
25
|
+
this.handlers = {};
|
|
26
|
+
this.blocksTransfers = {};
|
|
27
|
+
this.poolInterface = new abi_1.Interface(erc20_json_1.default);
|
|
28
|
+
// TODO: make logDecoder decode logs that
|
|
29
|
+
this.logDecoder = (log) => this.poolInterface.parseLog(log);
|
|
30
|
+
this.addressesSubscribed = [idleToken.address.toLowerCase()];
|
|
31
|
+
const cdoTokens = (0, tokens_1.getTokensByCdoAddress)(this.idleToken.cdoAddress);
|
|
32
|
+
if (cdoTokens) {
|
|
33
|
+
cdoTokens.forEach((idleToken) => {
|
|
34
|
+
if (!this.addressesSubscribed.includes(idleToken.idleAddress.toLowerCase())) {
|
|
35
|
+
this.addressesSubscribed.push(idleToken.idleAddress.toLowerCase());
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// this.logger.debug('addressesSubscribed', this.idleToken.idleAddress, this.addressesSubscribed)
|
|
40
|
+
// Add handlers
|
|
41
|
+
this.handlers['Transfer'] = this.handleCoinTransfer.bind(this);
|
|
42
|
+
this.idleToken = idleToken;
|
|
43
|
+
this.cdoContract = new dexHelper.web3Provider.eth.Contract(idle_cdo_json_1.default, this.idleToken.cdoAddress);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The function is called every time any of the subscribed
|
|
47
|
+
* addresses release log. The function accepts the current
|
|
48
|
+
* state, updates the state according to the log, and returns
|
|
49
|
+
* the updated state.
|
|
50
|
+
* @param state - Current state of event subscriber
|
|
51
|
+
* @param log - Log released by one of the subscribed addresses
|
|
52
|
+
* @returns Updates state of the event subscriber after the log
|
|
53
|
+
*/
|
|
54
|
+
async processLog(state, log) {
|
|
55
|
+
try {
|
|
56
|
+
const event = this.logDecoder(log);
|
|
57
|
+
if (event.name in this.handlers) {
|
|
58
|
+
const result = await this.handlers[event.name](event, state, log);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
(0, utils_1.catchParseLogError)(e, this.logger);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The function generates state using on-chain calls. This
|
|
69
|
+
* function is called to regenerate state if the event based
|
|
70
|
+
* system fails to fetch events and the local state is no
|
|
71
|
+
* more correct.
|
|
72
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
73
|
+
* should be generated
|
|
74
|
+
* @returns state of the event subscriber at blocknumber
|
|
75
|
+
*/
|
|
76
|
+
async generateState(blockNumber) {
|
|
77
|
+
const tranchePrice = await this.cdoContract.methods['virtualPrice'](this.idleToken.idleAddress).call({}, blockNumber);
|
|
78
|
+
return {
|
|
79
|
+
tokenPrice: BigInt(tranchePrice),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
setBlockState(blockNumber, state) {
|
|
83
|
+
this.logger.debug('setBlockState', blockNumber, this.idleToken.idleAddress, state);
|
|
84
|
+
return this._setState(state, blockNumber);
|
|
85
|
+
}
|
|
86
|
+
async handleCoinTransfer(event, state, log) {
|
|
87
|
+
const idleTokens = (0, tokens_1.getTokensByCdoAddress)(this.idleToken.cdoAddress);
|
|
88
|
+
if (!idleTokens)
|
|
89
|
+
return null;
|
|
90
|
+
const pollingPool = new idle_dao_pooling_pool_1.IdleDaoPollingPool(this.parentName, this.parentName, this.dexHelper, idleTokens, this.logger);
|
|
91
|
+
const blockNumber = log.blockNumber;
|
|
92
|
+
let poolsState = null;
|
|
93
|
+
if (log.address.toLowerCase() === this.idleToken.address.toLowerCase()) {
|
|
94
|
+
if (event.args.dst.toLowerCase() ===
|
|
95
|
+
this.idleToken.cdoAddress.toLowerCase() ||
|
|
96
|
+
event.args.src.toLowerCase() === this.idleToken.cdoAddress.toLowerCase()) {
|
|
97
|
+
poolsState = await pollingPool.getAggregatedBlockData(blockNumber);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (this.addressesSubscribed.includes(log.address.toLowerCase())) {
|
|
101
|
+
poolsState = await pollingPool.getAggregatedBlockData(blockNumber);
|
|
102
|
+
}
|
|
103
|
+
// Update pools with the new state
|
|
104
|
+
if (poolsState) {
|
|
105
|
+
Object.keys(poolsState.value).forEach((idleAddress) => {
|
|
106
|
+
const poolState = poolsState?.value?.[idleAddress];
|
|
107
|
+
if (poolState) {
|
|
108
|
+
this.IdleDao.setEventPoolStateBlock(idleAddress, poolsState.blockNumber, poolState);
|
|
109
|
+
// Overwrite state
|
|
110
|
+
if (idleAddress === this.idleToken.idleAddress) {
|
|
111
|
+
state = poolState;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return state;
|
|
117
|
+
}
|
|
118
|
+
processBlockTransfer(blockNumber, state) {
|
|
119
|
+
if (!this.blocksTransfers[blockNumber] ||
|
|
120
|
+
this.blocksTransfers[blockNumber].processed)
|
|
121
|
+
return state;
|
|
122
|
+
const idleAmount = this.blocksTransfers[blockNumber].idleAmount.div(1e18);
|
|
123
|
+
const underlyingAmount = this.blocksTransfers[blockNumber].underlyingAmount.div(`1e${this.idleToken.decimals}`);
|
|
124
|
+
if (idleAmount.gt(0) && underlyingAmount.gt(0)) {
|
|
125
|
+
const tokenPrice = BigInt(bignumber_js_1.default.maximum(idleAmount, underlyingAmount)
|
|
126
|
+
.div(bignumber_js_1.default.minimum(idleAmount, underlyingAmount))
|
|
127
|
+
.times(`1e${this.idleToken.decimals}`)
|
|
128
|
+
.toFixed(0));
|
|
129
|
+
this.logger.debug('tokenPrice', blockNumber, this.idleToken.idleSymbol, this.idleToken.decimals, idleAmount.toString(), underlyingAmount.toString(), tokenPrice.toString());
|
|
130
|
+
this.blocksTransfers[blockNumber].processed = true;
|
|
131
|
+
return {
|
|
132
|
+
tokenPrice,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return state;
|
|
136
|
+
}
|
|
137
|
+
async handleCoinTransfer_old(event, state, log) {
|
|
138
|
+
// Handle underlying token transfer
|
|
139
|
+
if (log.address.toLowerCase() === this.idleToken.address.toLowerCase()) {
|
|
140
|
+
if (event.args.dst.toLowerCase() ===
|
|
141
|
+
this.idleToken.cdoAddress.toLowerCase() ||
|
|
142
|
+
event.args.src.toLowerCase() === this.idleToken.cdoAddress.toLowerCase()) {
|
|
143
|
+
if (!this.blocksTransfers[log.blockNumber]) {
|
|
144
|
+
this.blocksTransfers[log.blockNumber] = {
|
|
145
|
+
processed: false,
|
|
146
|
+
idleAmount: (0, bignumber_js_1.default)(0),
|
|
147
|
+
underlyingAmount: (0, bignumber_js_1.default)(0),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
this.logger.debug('UnderlyingAmount', log.blockNumber, 'event', event, 'log', log, (0, bignumber_js_1.default)(BigInt(event.args.wad).toString()).toFixed());
|
|
151
|
+
this.blocksTransfers[log.blockNumber].underlyingAmount = (0, bignumber_js_1.default)(BigInt(event.args.wad).toString());
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Handle idle token transfer
|
|
155
|
+
else if (log.address.toLowerCase() === this.idleToken.idleAddress.toLowerCase()) {
|
|
156
|
+
this.logger.debug('IdleToken Transfer', log.blockNumber, 'event', event, 'log', log);
|
|
157
|
+
if (event.args.src.toLowerCase() ===
|
|
158
|
+
'0x0000000000000000000000000000000000000000' ||
|
|
159
|
+
event.args.dst.toLowerCase() ===
|
|
160
|
+
'0x0000000000000000000000000000000000000000') {
|
|
161
|
+
if (!this.blocksTransfers[log.blockNumber]) {
|
|
162
|
+
this.blocksTransfers[log.blockNumber] = {
|
|
163
|
+
processed: false,
|
|
164
|
+
idleAmount: (0, bignumber_js_1.default)(0),
|
|
165
|
+
underlyingAmount: (0, bignumber_js_1.default)(0),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
this.logger.debug('IdleAmount', log.blockNumber, 'event', event, 'log', log, (0, bignumber_js_1.default)(BigInt(event.args.wad).toString()).toFixed());
|
|
169
|
+
this.blocksTransfers[log.blockNumber].idleAmount = (0, bignumber_js_1.default)(BigInt(event.args.wad).toString());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return this.processBlockTransfer(log.blockNumber, state);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.IdleDaoEventPool = IdleDaoEventPool;
|
|
176
|
+
//# sourceMappingURL=idle-dao-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idle-dao-pool.js","sourceRoot":"","sources":["../../../src/dex/idle-dao/idle-dao-pool.ts"],"names":[],"mappings":";;;;;;AACA,gEAAqC;AAErC,4CAA+C;AAG/C,uCAAiD;AACjD,sEAA6C;AAC7C,qFAAuD;AACvD,+EAA0E;AAG1E,mEAA6D;AAC7D,qCAAiD;AAajD,MAAa,gBAAiB,SAAQ,mDAAkC;IAgBtE,YACW,UAAkB,EACjB,OAAe,EACf,SAAqB,EACrB,MAAc,EACd,SAAoB,EACpB,OAAgB;QAE1B,sBAAsB;QACtB,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QARlD,eAAU,GAAV,UAAU,CAAQ;QACjB,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAY;QACrB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OAAO,CAAS;QArB5B,aAAQ,GAMJ,EAAE,CAAC;QAOP,oBAAe,GAAoB,EAAE,CAAC;QAapC,IAAI,CAAC,aAAa,GAAG,IAAI,eAAS,CAAC,oBAAS,CAAC,CAAC;QAE9C,yCAAyC;QACzC,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEjE,IAAI,CAAC,mBAAmB,GAAG,CAAC,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1C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG;wBACtC,SAAS,EAAE,KAAK;wBAChB,UAAU,EAAE,IAAA,sBAAS,EAAC,CAAC,CAAC;wBACxB,gBAAgB,EAAE,IAAA,sBAAS,EAAC,CAAC,CAAC;qBAC/B,CAAC;iBACH;gBACD,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,YAAY,EACZ,GAAG,CAAC,WAAW,EACf,OAAO,EACP,KAAK,EACL,KAAK,EACL,GAAG,EACH,IAAA,sBAAS,EAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CACvD,CAAC;gBACF,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,UAAU,GAAG,IAAA,sBAAS,EAC1D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAClC,CAAC;aACH;SACF;QAED,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;CACF;AArRD,4CAqRC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
2
|
+
import { IdleToken, PoolsState } from './types';
|
|
3
|
+
import { MultiCallParams } from '../../lib/multi-wrapper';
|
|
4
|
+
import { StatefulRpcPoller } from '../../lib/stateful-rpc-poller/stateful-rpc-poller';
|
|
5
|
+
import { Logger } from '../../types';
|
|
6
|
+
import { ObjWithUpdateInfo } from '../../lib/stateful-rpc-poller/types';
|
|
7
|
+
declare type MulticallResultOutputs = bigint;
|
|
8
|
+
export declare class IdleDaoPollingPool extends StatefulRpcPoller<PoolsState, MulticallResultOutputs> {
|
|
9
|
+
protected idleTokens: IdleToken[];
|
|
10
|
+
protected logger: Logger;
|
|
11
|
+
constructor(dexKey: string, poolIdentifier: string, dexHelper: IDexHelper, idleTokens: IdleToken[], logger: Logger);
|
|
12
|
+
getAggregatedBlockData(blockNumber: number): Promise<ObjWithUpdateInfo<PoolsState> | null>;
|
|
13
|
+
protected _getFetchStateMultiCalls(): MultiCallParams<MulticallResultOutputs>[];
|
|
14
|
+
protected _parseStateFromMultiResults(multiOutputs: MulticallResultOutputs[]): PoolsState;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
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.IdleDaoPollingPool = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const decoders_1 = require("../../lib/decoders");
|
|
9
|
+
const idle_cdo_json_1 = __importDefault(require("../../abi/idle-dao/idle-cdo.json"));
|
|
10
|
+
const utils_1 = require("../../lib/stateful-rpc-poller/utils");
|
|
11
|
+
const stateful_rpc_poller_1 = require("../../lib/stateful-rpc-poller/stateful-rpc-poller");
|
|
12
|
+
const state_polling_manager_1 = require("../../lib/stateful-rpc-poller/state-polling-manager");
|
|
13
|
+
class IdleDaoPollingPool extends stateful_rpc_poller_1.StatefulRpcPoller {
|
|
14
|
+
constructor(dexKey, poolIdentifier, dexHelper, idleTokens, logger) {
|
|
15
|
+
const callbacks = (0, utils_1.pollingManagerCbExtractor)(state_polling_manager_1.StatePollingManager.getInstance(dexHelper));
|
|
16
|
+
super(dexKey, poolIdentifier, dexHelper, 0, 0, false, callbacks);
|
|
17
|
+
this.idleTokens = idleTokens;
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
}
|
|
20
|
+
async getAggregatedBlockData(blockNumber) {
|
|
21
|
+
const multiCalls = this.getFetchStateWithBlockInfoMultiCalls();
|
|
22
|
+
try {
|
|
23
|
+
const lastUpdatedAtMs = Date.now();
|
|
24
|
+
const aggregatedResults = (await this.dexHelper.multiWrapper.tryAggregate(true, multiCalls, blockNumber));
|
|
25
|
+
return this.parseStateFromMultiResultsWithBlockInfo(aggregatedResults, lastUpdatedAtMs);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
// this.logger.debug('ERROR fetching multicall data', blockNumber, e)
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
_getFetchStateMultiCalls() {
|
|
33
|
+
const cdoInterface = new abi_1.Interface(idle_cdo_json_1.default);
|
|
34
|
+
return this.idleTokens.map(idleToken => ({
|
|
35
|
+
target: idleToken.cdoAddress,
|
|
36
|
+
callData: cdoInterface.encodeFunctionData('virtualPrice', [
|
|
37
|
+
idleToken.idleAddress,
|
|
38
|
+
]),
|
|
39
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
_parseStateFromMultiResults(multiOutputs) {
|
|
43
|
+
const output = multiOutputs.reduce((acc, output, index) => {
|
|
44
|
+
const tokenPrice = output;
|
|
45
|
+
const idleToken = this.idleTokens[index];
|
|
46
|
+
return {
|
|
47
|
+
...acc,
|
|
48
|
+
[idleToken.idleAddress]: {
|
|
49
|
+
tokenPrice,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}, {});
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.IdleDaoPollingPool = IdleDaoPollingPool;
|
|
57
|
+
//# sourceMappingURL=idle-dao-pooling-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idle-dao-pooling-pool.js","sourceRoot":"","sources":["../../../src/dex/idle-dao/idle-dao-pooling-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAC/C,iDAAqD;AACrD,qFAAuD;AAIvD,+DAAgF;AAChF,2FAAsF;AACtF,+FAA0F;AAM1F,MAA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,CAAC,MAAM,CAC5C,CAAC,GAAe,EAAE,MAA8B,EAAE,KAAa,EAAE,EAAE;YACjE,MAAM,UAAU,GAAG,MAAgB,CAAC;YACpC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACzC,OAAO;gBACL,GAAG,GAAG;gBACN,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE;oBACvB,UAAU;iBACX;aACF,CAAC;QACJ,CAAC,EACD,EAAE,CACH,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxED,gDAwEC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, PoolLiquidity, Logger, NumberAsString, DexExchangeParam } from '../../types';
|
|
2
|
+
import { SwapSide, Network } from '../../constants';
|
|
3
|
+
import { Context, IDex } from '../../dex/idex';
|
|
4
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
5
|
+
import { IdleDaoData, IdleToken, PoolState } from './types';
|
|
6
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
7
|
+
import { IdleDaoEventPool } from './idle-dao-pool';
|
|
8
|
+
import { IdleDaoPollingPool } from './idle-dao-pooling-pool';
|
|
9
|
+
import { StatePollingManager } from '../../lib/stateful-rpc-poller/state-polling-manager';
|
|
10
|
+
export declare const TOKEN_LIST_CACHE_KEY = "token-list";
|
|
11
|
+
export declare class IdleDao extends SimpleExchange implements IDex<IdleDaoData> {
|
|
12
|
+
readonly network: Network;
|
|
13
|
+
readonly dexKey: string;
|
|
14
|
+
readonly dexHelper: IDexHelper;
|
|
15
|
+
protected config: import("./types").DexParams;
|
|
16
|
+
protected adapters: import("../../types").AdapterMappings;
|
|
17
|
+
protected eventPools: Record<string, IdleDaoEventPool>;
|
|
18
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
19
|
+
readonly needWrapNative = true;
|
|
20
|
+
readonly isFeeOnTransferSupported = false;
|
|
21
|
+
static dexKeysWithNetwork: {
|
|
22
|
+
key: string;
|
|
23
|
+
networks: Network[];
|
|
24
|
+
}[];
|
|
25
|
+
logger: Logger;
|
|
26
|
+
private cdo;
|
|
27
|
+
private factory;
|
|
28
|
+
private tokenList;
|
|
29
|
+
private idleDaoAuthToken;
|
|
30
|
+
protected pollingPool?: IdleDaoPollingPool;
|
|
31
|
+
protected pollingManager: StatePollingManager;
|
|
32
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, config?: import("./types").DexParams, adapters?: import("../../types").AdapterMappings);
|
|
33
|
+
getEventPool(idleAddress: string): IdleDaoEventPool | null;
|
|
34
|
+
setEventPoolStateBlock(idleAddress: string, blockNumber: number, state: PoolState): void;
|
|
35
|
+
setupEventPool(idleToken: IdleToken, blockNumber: number): Promise<IdleDaoEventPool>;
|
|
36
|
+
getTokensList(blockNumber: number): Promise<Record<string, IdleToken>>;
|
|
37
|
+
initializePricing(blockNumber: number): Promise<void>;
|
|
38
|
+
getAdapters(side: SwapSide): {
|
|
39
|
+
name: string;
|
|
40
|
+
index: number;
|
|
41
|
+
}[] | null;
|
|
42
|
+
getIdentifier(): string;
|
|
43
|
+
private _initializePollingPool;
|
|
44
|
+
private _getPoolIdentifier;
|
|
45
|
+
getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
46
|
+
getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<IdleDaoData>>;
|
|
47
|
+
getCalldataGasCost(poolPrices: PoolPrices<IdleDaoData>): number | number[];
|
|
48
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: IdleDaoData, side: SwapSide): AdapterExchangeParam;
|
|
49
|
+
getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: IdleDaoData, side: SwapSide, _: Context, executorAddress: Address): DexExchangeParam;
|
|
50
|
+
updatePoolState(): Promise<void>;
|
|
51
|
+
getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
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.IdleDao = exports.TOKEN_LIST_CACHE_KEY = void 0;
|
|
30
|
+
const ts_essentials_1 = require("ts-essentials");
|
|
31
|
+
const abi_1 = require("@ethersproject/abi");
|
|
32
|
+
const constants_1 = require("../../constants");
|
|
33
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
34
|
+
const utils_1 = require("../../utils");
|
|
35
|
+
const types_1 = require("./types");
|
|
36
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
37
|
+
const config_1 = require("./config");
|
|
38
|
+
const idle_dao_pool_1 = require("./idle-dao-pool");
|
|
39
|
+
const utils_2 = require("./utils");
|
|
40
|
+
const tokens_1 = require("./tokens");
|
|
41
|
+
const idle_cdo_factory_json_1 = __importDefault(require("../../abi/idle-dao/idle-cdo-factory.json"));
|
|
42
|
+
const idle_cdo_json_1 = __importDefault(require("../../abi/idle-dao/idle-cdo.json"));
|
|
43
|
+
const idle_dao_pooling_pool_1 = require("./idle-dao-pooling-pool");
|
|
44
|
+
const state_polling_manager_1 = require("../../lib/stateful-rpc-poller/state-polling-manager");
|
|
45
|
+
exports.TOKEN_LIST_CACHE_KEY = 'token-list';
|
|
46
|
+
const TOKEN_LIST_TTL_SECONDS = 24 * 60 * 60;
|
|
47
|
+
const TOKEN_LIST_LOCAL_TTL_SECONDS = 3 * 60 * 60;
|
|
48
|
+
class IdleDao extends simple_exchange_1.SimpleExchange {
|
|
49
|
+
constructor(network, dexKey, dexHelper, config = config_1.Config[dexKey][network], adapters = config_1.Adapters[network] || {}) {
|
|
50
|
+
super(dexHelper, dexKey);
|
|
51
|
+
this.network = network;
|
|
52
|
+
this.dexKey = dexKey;
|
|
53
|
+
this.dexHelper = dexHelper;
|
|
54
|
+
this.config = config;
|
|
55
|
+
this.adapters = adapters;
|
|
56
|
+
this.eventPools = {};
|
|
57
|
+
this.hasConstantPriceLargeAmounts = false;
|
|
58
|
+
// TODO: set true here if protocols works only with wrapped asset
|
|
59
|
+
this.needWrapNative = true;
|
|
60
|
+
this.isFeeOnTransferSupported = false;
|
|
61
|
+
this.tokenList = [];
|
|
62
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
63
|
+
this.cdo = new abi_1.Interface(idle_cdo_json_1.default);
|
|
64
|
+
this.factory = new abi_1.Interface(idle_cdo_factory_json_1.default);
|
|
65
|
+
this.pollingManager = state_polling_manager_1.StatePollingManager.getInstance(dexHelper);
|
|
66
|
+
const idleDaoAuthToken = dexHelper.config.data.idleDaoAuthToken;
|
|
67
|
+
(0, ts_essentials_1.assert)(idleDaoAuthToken !== undefined, 'idleDaoAuthToken auth token is not specified with env variable');
|
|
68
|
+
this.idleDaoAuthToken = idleDaoAuthToken;
|
|
69
|
+
}
|
|
70
|
+
getEventPool(idleAddress) {
|
|
71
|
+
return this.eventPools[idleAddress] || null;
|
|
72
|
+
}
|
|
73
|
+
setEventPoolStateBlock(idleAddress, blockNumber, state) {
|
|
74
|
+
const eventPool = this.getEventPool(idleAddress);
|
|
75
|
+
if (!eventPool)
|
|
76
|
+
return;
|
|
77
|
+
return eventPool.setBlockState(blockNumber, state);
|
|
78
|
+
}
|
|
79
|
+
async setupEventPool(idleToken, blockNumber) {
|
|
80
|
+
const idleDaoEventPool = new idle_dao_pool_1.IdleDaoEventPool(this.dexKey, this.network, this.dexHelper, this.logger, idleToken, this);
|
|
81
|
+
await idleDaoEventPool.initialize(blockNumber);
|
|
82
|
+
this.eventPools[idleToken.idleAddress] = idleDaoEventPool;
|
|
83
|
+
return idleDaoEventPool;
|
|
84
|
+
}
|
|
85
|
+
async getTokensList(blockNumber) {
|
|
86
|
+
if (!this.tokenList) {
|
|
87
|
+
this.tokenList = await (0, utils_2.fetchTokenList_api)(this.network, this.dexHelper, blockNumber, this.cdo, this.erc20Interface, this.dexHelper.multiWrapper, this.idleDaoAuthToken);
|
|
88
|
+
}
|
|
89
|
+
return this.tokenList.reduce((acc, idleToken) => {
|
|
90
|
+
return {
|
|
91
|
+
...acc,
|
|
92
|
+
[idleToken.idleAddress]: idleToken,
|
|
93
|
+
};
|
|
94
|
+
}, {});
|
|
95
|
+
}
|
|
96
|
+
// Initialize pricing is called once in the start of
|
|
97
|
+
// pricing service. It is intended to setup the integration
|
|
98
|
+
// for pricing requests. It is optional for a DEX to
|
|
99
|
+
// implement this function
|
|
100
|
+
async initializePricing(blockNumber) {
|
|
101
|
+
let cachedTokenList = await this.dexHelper.cache.getAndCacheLocally(this.dexKey, this.network, exports.TOKEN_LIST_CACHE_KEY, TOKEN_LIST_LOCAL_TTL_SECONDS);
|
|
102
|
+
if (cachedTokenList !== null) {
|
|
103
|
+
const tokens = JSON.parse(cachedTokenList);
|
|
104
|
+
(0, tokens_1.setTokensOnNetwork)(this.network, tokens);
|
|
105
|
+
await Promise.all(tokens.map((idleToken) => this.setupEventPool(idleToken, blockNumber)));
|
|
106
|
+
this.tokenList = tokens;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.tokenList = await (0, utils_2.fetchTokenList_api)(this.network, this.dexHelper, blockNumber, this.cdo, this.erc20Interface, this.dexHelper.multiWrapper, this.idleDaoAuthToken);
|
|
110
|
+
// console.log('api_tokenList', this.tokenList);
|
|
111
|
+
await this.dexHelper.cache.setex(this.dexKey, this.network, exports.TOKEN_LIST_CACHE_KEY, TOKEN_LIST_TTL_SECONDS, JSON.stringify(this.tokenList));
|
|
112
|
+
(0, tokens_1.setTokensOnNetwork)(this.network, this.tokenList);
|
|
113
|
+
await Promise.all(this.tokenList.map((idleToken) => this.setupEventPool(idleToken, blockNumber)));
|
|
114
|
+
// Initialize polling pool
|
|
115
|
+
if (this.pollingPool === undefined) {
|
|
116
|
+
this._initializePollingPool(this.tokenList);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Returns the list of contract adapters (name and index)
|
|
120
|
+
// for a buy/sell. Return null if there are no adapters.
|
|
121
|
+
getAdapters(side) {
|
|
122
|
+
return this.adapters[side] ? this.adapters[side] : null;
|
|
123
|
+
}
|
|
124
|
+
getIdentifier() {
|
|
125
|
+
return `${this.dexKey}_idledaov1`;
|
|
126
|
+
}
|
|
127
|
+
_initializePollingPool(idleTokens) {
|
|
128
|
+
this.pollingPool = new idle_dao_pooling_pool_1.IdleDaoPollingPool(this.dexKey, this.getIdentifier(), this.dexHelper, idleTokens, this.logger);
|
|
129
|
+
this.pollingManager.initializeAllPendingPools();
|
|
130
|
+
}
|
|
131
|
+
_getPoolIdentifier(srcToken, destToken) {
|
|
132
|
+
return (this.dexKey +
|
|
133
|
+
[srcToken.address.toLowerCase(), destToken.address.toLowerCase()]
|
|
134
|
+
.sort((a, b) => (a > b ? 1 : -1))
|
|
135
|
+
.join('_'));
|
|
136
|
+
}
|
|
137
|
+
// Returns list of pool identifiers that can be used
|
|
138
|
+
// for a given swap. poolIdentifiers must be unique
|
|
139
|
+
// across DEXes. It is recommended to use
|
|
140
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
141
|
+
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
142
|
+
const idleToken = (0, tokens_1.getIdleTokenIfIdleDaoPair)(this.network, this.dexHelper.config.wrapETH(srcToken), this.dexHelper.config.wrapETH(destToken));
|
|
143
|
+
if (idleToken === null)
|
|
144
|
+
return [];
|
|
145
|
+
return [this._getPoolIdentifier(srcToken, destToken)];
|
|
146
|
+
}
|
|
147
|
+
// Returns pool prices for amounts.
|
|
148
|
+
// If limitPools is defined only pools in limitPools
|
|
149
|
+
// should be used. If limitPools is undefined then
|
|
150
|
+
// any pools can be used.
|
|
151
|
+
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
152
|
+
try {
|
|
153
|
+
const _src = this.dexHelper.config.wrapETH(srcToken);
|
|
154
|
+
const _dst = this.dexHelper.config.wrapETH(destToken);
|
|
155
|
+
// Look for idleToken
|
|
156
|
+
const idleToken = (0, tokens_1.getIdleTokenIfIdleDaoPair)(this.network, _src, _dst);
|
|
157
|
+
if (!idleToken) {
|
|
158
|
+
// console.log(
|
|
159
|
+
// 'IdleToken NOT FOUND -',
|
|
160
|
+
// blockNumber,
|
|
161
|
+
// this.network,
|
|
162
|
+
// _src,
|
|
163
|
+
// _dst,
|
|
164
|
+
// );
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const fromIdleToken = idleToken.idleAddress.toLowerCase() == _src.address.toLowerCase();
|
|
168
|
+
// Cannot buy with IdleTokens
|
|
169
|
+
// if (fromIdleToken && side === SwapSide.BUY) return null
|
|
170
|
+
const eventPool = this.eventPools[idleToken.idleAddress];
|
|
171
|
+
const eventPoolState = eventPool.getState(blockNumber);
|
|
172
|
+
// this.logger.debug(
|
|
173
|
+
// 'eventPoolState',
|
|
174
|
+
// blockNumber,
|
|
175
|
+
// idleToken.idleAddress,
|
|
176
|
+
// eventPoolState,
|
|
177
|
+
// );
|
|
178
|
+
if (!eventPoolState) {
|
|
179
|
+
// console.log('eventPoolState is NULL -', blockNumber, idleToken.idleAddress, eventPoolState)
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const tokenPrice = eventPoolState.tokenPrice;
|
|
183
|
+
const unitVolume = (0, utils_1.getBigIntPow)((side === constants_1.SwapSide.SELL ? srcToken : destToken).decimals);
|
|
184
|
+
const prices = [unitVolume, ...amounts].map((amount) => {
|
|
185
|
+
let output = 0;
|
|
186
|
+
if (side === constants_1.SwapSide.SELL) {
|
|
187
|
+
// SELL idleToken (amount = 1000000000000000000 AA_idle_cpPOR-USDC, output = 1000000000000000000*tokenPrice/1e18)
|
|
188
|
+
if (fromIdleToken) {
|
|
189
|
+
output = Math.round((parseFloat('' + tokenPrice) * parseFloat('' + amount)) /
|
|
190
|
+
parseFloat(`1e${idleToken.decimals}`));
|
|
191
|
+
// SELL underlyingToken (amount = 1000000 USDC), output = 1000000/tokenPrice*1e18
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
output = Math.round((parseFloat('' + amount) / parseFloat('' + tokenPrice)) *
|
|
195
|
+
parseFloat(`1e${idleToken.decimals}`));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// BUY idleToken (amount = 1000000 USDC, output = 1000000/tokenPrice*1e18)
|
|
200
|
+
if (fromIdleToken) {
|
|
201
|
+
output = Math.round((parseFloat('' + amount) / parseFloat('' + tokenPrice)) *
|
|
202
|
+
parseFloat(`1e${idleToken.decimals}`));
|
|
203
|
+
// BUY underlyingToken (amount = 1000000000000000000 AA_idle_cpPOR-USDC, output = 1000000000000000000*tokenPrice/1e18)
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
output = Math.round((parseFloat('' + tokenPrice) * parseFloat('' + amount)) /
|
|
207
|
+
parseFloat(`1e${idleToken.decimals}`));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return BigInt(output);
|
|
211
|
+
});
|
|
212
|
+
// console.log('getPricesVolume', srcToken.address, destToken.address, fromIdleToken, side, unitVolume, amounts, prices)
|
|
213
|
+
// const unit = side === SwapSide.SELL ? prices[0] : unitVolume;
|
|
214
|
+
return [
|
|
215
|
+
{
|
|
216
|
+
unit: prices[0],
|
|
217
|
+
prices: prices.slice(1),
|
|
218
|
+
gasCost: this.config.lendingGasCost,
|
|
219
|
+
exchange: this.dexKey,
|
|
220
|
+
data: {
|
|
221
|
+
idleToken,
|
|
222
|
+
fromIdleToken,
|
|
223
|
+
},
|
|
224
|
+
poolAddresses: [fromIdleToken ? srcToken.address : destToken.address],
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
if (blockNumber === 0)
|
|
230
|
+
this.logger.error(`Error_getPricesVolume: Aurelius block manager not yet instantiated`);
|
|
231
|
+
this.logger.error(`Error_getPrices:`, e);
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
236
|
+
getCalldataGasCost(poolPrices) {
|
|
237
|
+
// TODO: update if there is any payload in getAdapterParam
|
|
238
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
239
|
+
}
|
|
240
|
+
// Encode params required by the exchange adapter
|
|
241
|
+
// Used for multiSwap, buy & megaSwap
|
|
242
|
+
// Hint: abiCoder.encodeParameter() could be useful
|
|
243
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
244
|
+
const idleToken = data.fromIdleToken ? srcToken : destToken; // Warning
|
|
245
|
+
const payload = this.abiCoder.encodeParameter({
|
|
246
|
+
ParentStruct: {
|
|
247
|
+
idleToken: 'address',
|
|
248
|
+
},
|
|
249
|
+
}, { idleToken });
|
|
250
|
+
return {
|
|
251
|
+
// target exchange is not used by the contract
|
|
252
|
+
targetExchange: constants_1.NULL_ADDRESS,
|
|
253
|
+
payload,
|
|
254
|
+
networkFee: '0',
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, _, executorAddress) {
|
|
258
|
+
const [Interface, swapCallee, swapFunction, swapFunctionParams] = (() => {
|
|
259
|
+
if (data.fromIdleToken) {
|
|
260
|
+
return [
|
|
261
|
+
this.cdo,
|
|
262
|
+
data.idleToken.cdoAddress,
|
|
263
|
+
types_1.PoolFunctions[`withdraw${data.idleToken.tokenType}`],
|
|
264
|
+
[srcAmount],
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
return [
|
|
268
|
+
this.cdo,
|
|
269
|
+
data.idleToken.cdoAddress,
|
|
270
|
+
types_1.PoolFunctions[`deposit${data.idleToken.tokenType}`],
|
|
271
|
+
[srcAmount, recipient],
|
|
272
|
+
];
|
|
273
|
+
})();
|
|
274
|
+
const exchangeData = Interface.encodeFunctionData(swapFunction, swapFunctionParams);
|
|
275
|
+
return {
|
|
276
|
+
needWrapNative: this.needWrapNative,
|
|
277
|
+
dexFuncHasRecipient: false,
|
|
278
|
+
exchangeData,
|
|
279
|
+
targetExchange: swapCallee,
|
|
280
|
+
returnAmountPos: undefined,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
async updatePoolState() {
|
|
284
|
+
const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
|
|
285
|
+
let idleTokens = (0, tokens_1.getTokensByNetwork)(this.network);
|
|
286
|
+
if (!idleTokens) {
|
|
287
|
+
await this.initializePricing(blockNumber);
|
|
288
|
+
}
|
|
289
|
+
idleTokens = (0, tokens_1.getTokensByNetwork)(this.network);
|
|
290
|
+
const state = await this.pollingPool.getState();
|
|
291
|
+
// this.logger.debug('updatePoolState', blockNumber, state)
|
|
292
|
+
if (!state) {
|
|
293
|
+
this.logger.error(`Failed to updatePoolState. State is null.`);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
Object.entries(state).forEach((state) => {
|
|
297
|
+
const idleAddress = state[0];
|
|
298
|
+
const poolState = state[1];
|
|
299
|
+
const eventPool = this.eventPools[idleAddress];
|
|
300
|
+
// this.logger.debug('Get eventPool', state, idleAddress, eventPool)
|
|
301
|
+
if (eventPool) {
|
|
302
|
+
// this.logger.debug('Set pool state', idleAddress, poolState.blockNumber, poolState.value)
|
|
303
|
+
eventPool.setBlockState(poolState.blockNumber, poolState.value);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
async getTopPoolsForToken(tokenAddress, limit) {
|
|
308
|
+
const idleTokens = (0, tokens_1.getPoolsByTokenAddress)(tokenAddress);
|
|
309
|
+
return idleTokens
|
|
310
|
+
.map((idleToken, i) => ({
|
|
311
|
+
liquidityUSD: 0,
|
|
312
|
+
exchange: this.dexKey,
|
|
313
|
+
address: idleToken.idleAddress,
|
|
314
|
+
connectorTokens: [(0, tokens_1.getTokenFromIdleToken)(idleToken)],
|
|
315
|
+
}))
|
|
316
|
+
.slice(0, limit);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
exports.IdleDao = IdleDao;
|
|
320
|
+
IdleDao.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.Config);
|
|
321
|
+
//# sourceMappingURL=idle-dao.js.map
|