@paraswap/dex-lib 4.8.25 → 4.8.26
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/BProtocol.json +1155 -0
- package/build/abi/Jarvis.json +1172 -0
- package/build/abi/MStableAsset.json +1545 -0
- package/build/abi/OneInchLp.json +1304 -0
- package/build/abi/Onebit.json +736 -0
- package/build/abi/Shell.json +1294 -0
- package/build/abi/TraderJoeV2Router.json +50 -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/infusion/InfusionFactory.json +147 -0
- package/build/abi/infusion/InfusionPair.json +658 -0
- package/build/abi/infusion/InfusionRouter.json +442 -0
- package/build/abi/maker-psm/pot.json +322 -0
- package/build/abi/maker-psm/psm.json +243 -0
- package/build/abi/maker-psm/vat.json +363 -0
- package/build/abi/nomiswap-v2/nomiswap-v2-pool.json +773 -0
- package/build/abi/quick-perps/fast-price-events.json +70 -0
- package/build/abi/quick-perps/fast-price-feed.json +741 -0
- package/build/abi/quick-perps/reader.json +313 -0
- package/build/abi/quick-perps/vault-price-feed.json +323 -0
- package/build/abi/quick-perps/vault.json +1953 -0
- package/build/abi/uniswap-v2/excalibur-pool.json +881 -0
- package/build/abi/uniswap-v2/mdex-factory.json +759 -0
- package/build/abi/wUSDM.json +757 -0
- package/build/abi/zrx.v2.json +1967 -0
- package/build/abi/zrx.v3.json +3454 -0
- package/build/abi/zrx.v4.json +2193 -0
- package/build/config.js +12 -12
- package/build/dex/OneInchLp.d.ts +24 -0
- package/build/dex/OneInchLp.js +43 -0
- package/build/dex/OneInchLp.js.map +1 -0
- package/build/dex/bProtocol/bProtocol.d.ts +15 -0
- package/build/dex/bProtocol/bProtocol.js +56 -0
- package/build/dex/bProtocol/bProtocol.js.map +1 -0
- package/build/dex/bProtocol/types.d.ts +11 -0
- package/build/dex/bProtocol/types.js +8 -0
- package/build/dex/bProtocol/types.js.map +1 -0
- package/build/dex/ekubo/pools/base-pool.d.ts +47 -0
- package/build/dex/ekubo/pools/base-pool.js +184 -0
- package/build/dex/ekubo/pools/base-pool.js.map +1 -0
- package/build/dex/ekubo/pools/iface.d.ts +46 -0
- package/build/dex/ekubo/pools/iface.js +75 -0
- package/build/dex/ekubo/pools/iface.js.map +1 -0
- package/build/dex/ekubo/pools/math/price.d.ts +7 -0
- package/build/dex/ekubo/pools/math/price.js +112 -0
- package/build/dex/ekubo/pools/math/price.js.map +1 -0
- package/build/dex/ekubo/pools/oracle-pool.d.ts +10 -0
- package/build/dex/ekubo/pools/oracle-pool.js +19 -0
- package/build/dex/ekubo/pools/oracle-pool.js.map +1 -0
- package/build/dex/ekubo/pools/pool-utils.d.ts +44 -0
- package/build/dex/ekubo/pools/pool-utils.js +240 -0
- package/build/dex/ekubo/pools/pool-utils.js.map +1 -0
- package/build/dex/ekubo-v3/ekubo-v3.js +1 -0
- package/build/dex/ekubo-v3/ekubo-v3.js.map +1 -1
- package/build/dex/idle-dao/config.d.ts +5 -0
- package/build/dex/idle-dao/config.js +24 -0
- package/build/dex/idle-dao/config.js.map +1 -0
- package/build/dex/idle-dao/idle-dao.d.ts +42 -0
- package/build/dex/idle-dao/idle-dao.js +279 -0
- package/build/dex/idle-dao/idle-dao.js.map +1 -0
- package/build/dex/idle-dao/token_list.d.ts +4 -0
- package/build/dex/idle-dao/token_list.js +289 -0
- package/build/dex/idle-dao/token_list.js.map +1 -0
- package/build/dex/idle-dao/tokens.d.ts +9 -0
- package/build/dex/idle-dao/tokens.js +68 -0
- package/build/dex/idle-dao/tokens.js.map +1 -0
- package/build/dex/idle-dao/types.d.ts +35 -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 +149 -0
- package/build/dex/idle-dao/utils.js.map +1 -0
- package/build/dex/infusion/config.d.ts +3 -0
- package/build/dex/infusion/config.js +20 -0
- package/build/dex/infusion/config.js.map +1 -0
- package/build/dex/infusion/infusion-stable-pool.d.ts +4 -0
- package/build/dex/infusion/infusion-stable-pool.js +74 -0
- package/build/dex/infusion/infusion-stable-pool.js.map +1 -0
- package/build/dex/infusion/infusion.d.ts +51 -0
- package/build/dex/infusion/infusion.js +500 -0
- package/build/dex/infusion/infusion.js.map +1 -0
- package/build/dex/infusion/types.d.ts +45 -0
- package/build/dex/infusion/types.js +3 -0
- package/build/dex/infusion/types.js.map +1 -0
- package/build/dex/infusion/utils/isStablePair.d.ts +2 -0
- package/build/dex/infusion/utils/isStablePair.js +18 -0
- package/build/dex/infusion/utils/isStablePair.js.map +1 -0
- package/build/dex/jarvis.d.ts +56 -0
- package/build/dex/jarvis.js +163 -0
- package/build/dex/jarvis.js.map +1 -0
- package/build/dex/mStable.d.ts +44 -0
- package/build/dex/mStable.js +75 -0
- package/build/dex/mStable.js.map +1 -0
- package/build/dex/maker-psm/config.d.ts +11 -0
- package/build/dex/maker-psm/config.js +53 -0
- package/build/dex/maker-psm/config.js.map +1 -0
- package/build/dex/maker-psm/maker-psm.d.ts +103 -0
- package/build/dex/maker-psm/maker-psm.js +493 -0
- package/build/dex/maker-psm/maker-psm.js.map +1 -0
- package/build/dex/maker-psm/types.d.ts +39 -0
- package/build/dex/maker-psm/types.js +3 -0
- package/build/dex/maker-psm/types.js.map +1 -0
- package/build/dex/onebit/onebit.d.ts +16 -0
- package/build/dex/onebit/onebit.js +61 -0
- package/build/dex/onebit/onebit.js.map +1 -0
- package/build/dex/onebit/types.d.ts +14 -0
- package/build/dex/onebit/types.js +8 -0
- package/build/dex/onebit/types.js.map +1 -0
- package/build/dex/quick-perps/config.d.ts +11 -0
- package/build/dex/quick-perps/config.js +27 -0
- package/build/dex/quick-perps/config.js.map +1 -0
- package/build/dex/quick-perps/fast-price-feed.d.ts +26 -0
- package/build/dex/quick-perps/fast-price-feed.js +184 -0
- package/build/dex/quick-perps/fast-price-feed.js.map +1 -0
- package/build/dex/quick-perps/pool.d.ts +21 -0
- package/build/dex/quick-perps/pool.js +229 -0
- package/build/dex/quick-perps/pool.js.map +1 -0
- package/build/dex/quick-perps/quick-perps.d.ts +53 -0
- package/build/dex/quick-perps/quick-perps.js +247 -0
- package/build/dex/quick-perps/quick-perps.js.map +1 -0
- package/build/dex/quick-perps/types.d.ts +98 -0
- package/build/dex/quick-perps/types.js +3 -0
- package/build/dex/quick-perps/types.js.map +1 -0
- package/build/dex/quick-perps/usdq.d.ts +15 -0
- package/build/dex/quick-perps/usdq.js +62 -0
- package/build/dex/quick-perps/usdq.js.map +1 -0
- package/build/dex/quick-perps/vault-price-feed.d.ts +43 -0
- package/build/dex/quick-perps/vault-price-feed.js +203 -0
- package/build/dex/quick-perps/vault-price-feed.js.map +1 -0
- package/build/dex/quick-perps/vault-utils.d.ts +8 -0
- package/build/dex/quick-perps/vault-utils.js +42 -0
- package/build/dex/quick-perps/vault-utils.js.map +1 -0
- package/build/dex/quick-perps/vault.d.ts +46 -0
- package/build/dex/quick-perps/vault.js +182 -0
- package/build/dex/quick-perps/vault.js.map +1 -0
- package/build/dex/se-vlr/config.d.ts +3 -0
- package/build/dex/se-vlr/config.js +24 -0
- package/build/dex/se-vlr/config.js.map +1 -0
- package/build/dex/se-vlr/se-vlr-pool.d.ts +39 -0
- package/build/dex/se-vlr/se-vlr-pool.js +70 -0
- package/build/dex/se-vlr/se-vlr-pool.js.map +1 -0
- package/build/dex/se-vlr/se-vlr.d.ts +35 -0
- package/build/dex/se-vlr/se-vlr.js +131 -0
- package/build/dex/se-vlr/se-vlr.js.map +1 -0
- package/build/dex/se-vlr/types.d.ts +6 -0
- package/build/dex/se-vlr/types.js +3 -0
- package/build/dex/se-vlr/types.js.map +1 -0
- package/build/dex/shell.d.ts +25 -0
- package/build/dex/shell.js +41 -0
- package/build/dex/shell.js.map +1 -0
- package/build/dex/solidly/forks-override/aerodrome.d.ts +14 -0
- package/build/dex/solidly/forks-override/aerodrome.js +46 -0
- package/build/dex/solidly/forks-override/aerodrome.js.map +1 -0
- package/build/dex/solidly/forks-override/chronos.d.ts +23 -0
- package/build/dex/solidly/forks-override/chronos.js +141 -0
- package/build/dex/solidly/forks-override/chronos.js.map +1 -0
- package/build/dex/solidly/forks-override/usdfi.d.ts +8 -0
- package/build/dex/solidly/forks-override/usdfi.js +15 -0
- package/build/dex/solidly/forks-override/usdfi.js.map +1 -0
- package/build/dex/solidly/forks-override/velocimeter.d.ts +23 -0
- package/build/dex/solidly/forks-override/velocimeter.js +77 -0
- package/build/dex/solidly/forks-override/velocimeter.js.map +1 -0
- package/build/dex/trader-joe-v2.d.ts +40 -0
- package/build/dex/trader-joe-v2.js +74 -0
- package/build/dex/trader-joe-v2.js.map +1 -0
- package/build/dex/uniswap-v2/dfyn.d.ts +19 -0
- package/build/dex/uniswap-v2/dfyn.js +61 -0
- package/build/dex/uniswap-v2/dfyn.js.map +1 -0
- package/build/dex/uniswap-v2/excalibur.d.ts +24 -0
- package/build/dex/uniswap-v2/excalibur.js +47 -0
- package/build/dex/uniswap-v2/excalibur.js.map +1 -0
- package/build/dex/uniswap-v2/mdex.d.ts +24 -0
- package/build/dex/uniswap-v2/mdex.js +50 -0
- package/build/dex/uniswap-v2/mdex.js.map +1 -0
- package/build/dex/uniswap-v2/nomiswap-v2.d.ts +24 -0
- package/build/dex/uniswap-v2/nomiswap-v2.js +57 -0
- package/build/dex/uniswap-v2/nomiswap-v2.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-new.d.ts +94 -0
- package/build/dex/uniswap-v3/uniswap-v3-new.js +923 -0
- package/build/dex/uniswap-v3/uniswap-v3-new.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/Position.d.ts +3 -0
- package/build/dex/uniswap-v4/contract-math/Position.js +10 -0
- package/build/dex/uniswap-v4/contract-math/Position.js.map +1 -0
- package/build/dex/usual-bond/config.d.ts +3 -0
- package/build/dex/usual-bond/config.js +13 -0
- package/build/dex/usual-bond/config.js.map +1 -0
- package/build/dex/usual-bond/types.d.ts +7 -0
- package/build/dex/usual-bond/types.js +3 -0
- package/build/dex/usual-bond/types.js.map +1 -0
- package/build/dex/usual-bond/usual-bond.d.ts +35 -0
- package/build/dex/usual-bond/usual-bond.js +176 -0
- package/build/dex/usual-bond/usual-bond.js.map +1 -0
- package/build/dex/wusdm/config.d.ts +3 -0
- package/build/dex/wusdm/config.js +43 -0
- package/build/dex/wusdm/config.js.map +1 -0
- package/build/dex/wusdm/constants.d.ts +2 -0
- package/build/dex/wusdm/constants.js +6 -0
- package/build/dex/wusdm/constants.js.map +1 -0
- package/build/dex/wusdm/types.d.ts +18 -0
- package/build/dex/wusdm/types.js +11 -0
- package/build/dex/wusdm/types.js.map +1 -0
- package/build/dex/wusdm/wusdm-pool.d.ts +21 -0
- package/build/dex/wusdm/wusdm-pool.js +74 -0
- package/build/dex/wusdm/wusdm-pool.js.map +1 -0
- package/build/dex/wusdm/wusdm.d.ts +46 -0
- package/build/dex/wusdm/wusdm.js +243 -0
- package/build/dex/wusdm/wusdm.js.map +1 -0
- package/build/dex/zerox/config.d.ts +2 -0
- package/build/dex/zerox/config.js +33 -0
- package/build/dex/zerox/config.js.map +1 -0
- package/build/dex/zerox/index.d.ts +22 -0
- package/build/dex/zerox/index.js +225 -0
- package/build/dex/zerox/index.js.map +1 -0
- package/build/dex/zerox/order.d.ts +88 -0
- package/build/dex/zerox/order.js +53 -0
- package/build/dex/zerox/order.js.map +1 -0
- package/build/dex/zerox/types.d.ts +73 -0
- package/build/dex/zerox/types.js +21 -0
- package/build/dex/zerox/types.js.map +1 -0
- package/build/executor/Executor03BytecodeBuilder.d.ts +15 -0
- package/build/executor/Executor03BytecodeBuilder.js +67 -6
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/types.d.ts +1 -0
- package/package.json +1 -1
- package/build/dex/uniswap-v4/api-go/compare-pricing.d.ts +0 -1
- package/build/dex/uniswap-v4/api-go/compare-pricing.js +0 -187
- package/build/dex/uniswap-v4/api-go/compare-pricing.js.map +0 -1
- package/build/dex/uniswap-v4/api-go/compare-states.d.ts +0 -1
- package/build/dex/uniswap-v4/api-go/compare-states.js +0 -149
- package/build/dex/uniswap-v4/api-go/compare-states.js.map +0 -1
- package/build/dex/uniswap-v4/api-go/fetch-pool-key.d.ts +0 -0
- package/build/dex/uniswap-v4/api-go/fetch-pool-key.js +0 -140
- package/build/dex/uniswap-v4/api-go/fetch-pool-key.js.map +0 -1
- package/build/tenderly-simulation.d.ts +0 -221
- package/build/tenderly-simulation.js +0 -517
- package/build/tenderly-simulation.js.map +0 -1
package/build/config.js
CHANGED
|
@@ -22,7 +22,7 @@ const baseConfigs = {
|
|
|
22
22
|
executorsAddresses: {
|
|
23
23
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
24
24
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
25
|
-
Executor03: '
|
|
25
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
26
26
|
},
|
|
27
27
|
adapterAddresses: {
|
|
28
28
|
Adapter01: '0x9bE264469eF954c139Da4A45Cf76CbCC5e3A6A73',
|
|
@@ -119,7 +119,7 @@ const baseConfigs = {
|
|
|
119
119
|
executorsAddresses: {
|
|
120
120
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
121
121
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
122
|
-
Executor03: '
|
|
122
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
123
123
|
},
|
|
124
124
|
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
125
125
|
swaapV2AuthToken: process.env.API_KEY_SWAAP_V2_AUTH_TOKEN || '',
|
|
@@ -154,7 +154,7 @@ const baseConfigs = {
|
|
|
154
154
|
executorsAddresses: {
|
|
155
155
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
156
156
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
157
|
-
Executor03: '
|
|
157
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
158
158
|
},
|
|
159
159
|
bebopAuthName: process.env.API_KEY_BEBOP_AUTH_NAME || '',
|
|
160
160
|
bebopAuthToken: process.env.API_KEY_BEBOP_AUTH_TOKEN || '',
|
|
@@ -196,7 +196,7 @@ const baseConfigs = {
|
|
|
196
196
|
executorsAddresses: {
|
|
197
197
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
198
198
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
199
|
-
Executor03: '
|
|
199
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
200
200
|
},
|
|
201
201
|
adapterAddresses: {
|
|
202
202
|
AvalancheAdapter01: '0x745Ec73855CeC7249E5fF4c9DD81cc65b4D297a9',
|
|
@@ -229,7 +229,7 @@ const baseConfigs = {
|
|
|
229
229
|
executorsAddresses: {
|
|
230
230
|
Executor01: '0x67dd00d00d000003a383b096091f0a3060000d08',
|
|
231
231
|
Executor02: '0x700602C7b720200a09000f38B0d00Ee00c54f000',
|
|
232
|
-
Executor03: '
|
|
232
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
233
233
|
},
|
|
234
234
|
adapterAddresses: {},
|
|
235
235
|
uniswapV2ExchangeRouterAddress: '0xCd8eA16F74d96E1000df8a57267e098c58399e8b',
|
|
@@ -259,7 +259,7 @@ const baseConfigs = {
|
|
|
259
259
|
executorsAddresses: {
|
|
260
260
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
261
261
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
262
|
-
Executor03: '
|
|
262
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
263
263
|
},
|
|
264
264
|
dexalotAuthToken: process.env.API_KEY_DEXALOT_AUTH_TOKEN || '',
|
|
265
265
|
bebopAuthName: process.env.API_KEY_BEBOP_AUTH_NAME || '',
|
|
@@ -295,7 +295,7 @@ const baseConfigs = {
|
|
|
295
295
|
executorsAddresses: {
|
|
296
296
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
297
297
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
298
|
-
Executor03: '
|
|
298
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
299
299
|
},
|
|
300
300
|
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
301
301
|
swaapV2AuthToken: process.env.API_KEY_SWAAP_V2_AUTH_TOKEN || '',
|
|
@@ -332,7 +332,7 @@ const baseConfigs = {
|
|
|
332
332
|
executorsAddresses: {
|
|
333
333
|
Executor01: '0x000010036c0190e009a000d0fc3541100a07380a',
|
|
334
334
|
Executor02: '0x00c600b30fb0400701010f4b080409018b9006e0',
|
|
335
|
-
Executor03: '
|
|
335
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
336
336
|
},
|
|
337
337
|
rpcPollingMaxAllowedStateDelayInBlocks: 0,
|
|
338
338
|
rpcPollingBlocksBackToTriggerUpdate: 0,
|
|
@@ -366,7 +366,7 @@ const baseConfigs = {
|
|
|
366
366
|
executorsAddresses: {
|
|
367
367
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
368
368
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
369
|
-
Executor03: '
|
|
369
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
370
370
|
},
|
|
371
371
|
adapterAddresses: {
|
|
372
372
|
BaseAdapter01: '0xe53d24CD81cC81bbf271AD7B02D0d67f851D727c',
|
|
@@ -398,7 +398,7 @@ const baseConfigs = {
|
|
|
398
398
|
executorsAddresses: {
|
|
399
399
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
400
400
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
401
|
-
Executor03: '
|
|
401
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
402
402
|
},
|
|
403
403
|
rpcPollingMaxAllowedStateDelayInBlocks: 0,
|
|
404
404
|
rpcPollingBlocksBackToTriggerUpdate: 0,
|
|
@@ -428,7 +428,7 @@ const baseConfigs = {
|
|
|
428
428
|
executorsAddresses: {
|
|
429
429
|
Executor01: '0x000010036c0190e009a000d0fc3541100a07380a',
|
|
430
430
|
Executor02: '0x00c600b30fb0400701010f4b080409018b9006e0',
|
|
431
|
-
Executor03: '
|
|
431
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
432
432
|
},
|
|
433
433
|
uniswapV2ExchangeRouterAddress: '0x0000000000000000000000000000000000000000',
|
|
434
434
|
rpcPollingMaxAllowedStateDelayInBlocks: 0,
|
|
@@ -454,7 +454,7 @@ const baseConfigs = {
|
|
|
454
454
|
executorsAddresses: {
|
|
455
455
|
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
|
|
456
456
|
Executor02: '0x00C600b30fb0400701010F4b080409018B9006E0',
|
|
457
|
-
Executor03: '
|
|
457
|
+
Executor03: '0xa000b020c290d000020aac04026b5306d60050f0',
|
|
458
458
|
},
|
|
459
459
|
rpcPollingMaxAllowedStateDelayInBlocks: 0,
|
|
460
460
|
rpcPollingBlocksBackToTriggerUpdate: 0,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { SwapSide } from '../constants';
|
|
3
|
+
import { AdapterExchangeParam, SimpleExchangeParam } from '../types';
|
|
4
|
+
import { IDexTxBuilder } from './idex';
|
|
5
|
+
import { SimpleExchange } from './simple-exchange';
|
|
6
|
+
import { IDexHelper } from '../dex-helper';
|
|
7
|
+
export declare type OneInchLpData = {
|
|
8
|
+
exchange: string;
|
|
9
|
+
};
|
|
10
|
+
declare type OneInchLpParam = [
|
|
11
|
+
src: string,
|
|
12
|
+
dst: string,
|
|
13
|
+
amount: string,
|
|
14
|
+
minReturn: string,
|
|
15
|
+
referral: string
|
|
16
|
+
];
|
|
17
|
+
export declare class OneInchLp extends SimpleExchange implements IDexTxBuilder<OneInchLpData, OneInchLpParam> {
|
|
18
|
+
static dexKeys: string[];
|
|
19
|
+
exchangeRouterInterface: Interface;
|
|
20
|
+
constructor(dexHelper: IDexHelper);
|
|
21
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: OneInchLpData, side: SwapSide): AdapterExchangeParam;
|
|
22
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: OneInchLpData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
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.OneInchLp = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const simple_exchange_1 = require("./simple-exchange");
|
|
10
|
+
const OneInchLp_json_1 = __importDefault(require("../abi/OneInchLp.json"));
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
var OneInchLpFunctions;
|
|
13
|
+
(function (OneInchLpFunctions) {
|
|
14
|
+
OneInchLpFunctions["swap"] = "swap";
|
|
15
|
+
})(OneInchLpFunctions || (OneInchLpFunctions = {}));
|
|
16
|
+
class OneInchLp extends simple_exchange_1.SimpleExchange {
|
|
17
|
+
constructor(dexHelper) {
|
|
18
|
+
super(dexHelper, 'oneinchlp');
|
|
19
|
+
this.exchangeRouterInterface = new abi_1.Interface(OneInchLp_json_1.default);
|
|
20
|
+
}
|
|
21
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
22
|
+
return {
|
|
23
|
+
targetExchange: data.exchange,
|
|
24
|
+
payload: '0x',
|
|
25
|
+
networkFee: '0',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
29
|
+
const swapFunction = OneInchLpFunctions.swap;
|
|
30
|
+
const swapFunctionParams = [
|
|
31
|
+
(0, utils_1.isETHAddress)(srcToken) ? constants_1.NULL_ADDRESS : srcToken,
|
|
32
|
+
(0, utils_1.isETHAddress)(destToken) ? constants_1.NULL_ADDRESS : destToken,
|
|
33
|
+
srcAmount,
|
|
34
|
+
destAmount,
|
|
35
|
+
constants_1.NULL_ADDRESS,
|
|
36
|
+
];
|
|
37
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(swapFunction, swapFunctionParams);
|
|
38
|
+
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, data.exchange);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.OneInchLp = OneInchLp;
|
|
42
|
+
OneInchLp.dexKeys = ['oneinchlp'];
|
|
43
|
+
//# sourceMappingURL=OneInchLp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneInchLp.js","sourceRoot":"","sources":["../../src/dex/OneInchLp.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA6D;AAC7D,4CAAsD;AAGtD,uDAAmD;AACnD,2EAAiD;AACjD,oCAAwC;AAcxC,IAAK,kBAEJ;AAFD,WAAK,kBAAkB;IACrB,mCAAa,CAAA;AACf,CAAC,EAFI,kBAAkB,KAAlB,kBAAkB,QAEtB;AAED,MAAa,SACX,SAAQ,gCAAc;IAMtB,YAAY,SAAqB;QAC/B,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC9B,IAAI,CAAC,uBAAuB,GAAG,IAAI,eAAS,CAC1C,wBAA8B,CAC/B,CAAC;IACJ,CAAC;IAED,eAAe,CACb,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAmB,EACnB,IAAc;QAEd,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,QAAQ;YAC7B,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,GAAG;SAChB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAmB,EACnB,IAAc;QAEd,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC;QAC7C,MAAM,kBAAkB,GAAmB;YACzC,IAAA,oBAAY,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,wBAAY,CAAC,CAAC,CAAC,QAAQ;YAChD,IAAA,oBAAY,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,wBAAY,CAAC,CAAC,CAAC,SAAS;YAClD,SAAS;YACT,UAAU;YACV,wBAAY;SACb,CAAC;QACF,MAAM,QAAQ,GAAG,IAAI,CAAC,uBAAuB,CAAC,kBAAkB,CAC9D,YAAY,EACZ,kBAAkB,CACnB,CAAC;QAEF,OAAO,IAAI,CAAC,qCAAqC,CAC/C,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ,EACR,IAAI,CAAC,QAAQ,CACd,CAAC;IACJ,CAAC;;AA1DH,8BA2DC;AAvDQ,iBAAO,GAAG,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { SwapSide } from '../../constants';
|
|
3
|
+
import { AdapterExchangeParam, Address, DexExchangeParam, NumberAsString, SimpleExchangeParam } from '../../types';
|
|
4
|
+
import { IDexTxBuilder } from '../idex';
|
|
5
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
6
|
+
import { IDexHelper } from '../../dex-helper';
|
|
7
|
+
import { BProtocolData, BProtocolParam } from './types';
|
|
8
|
+
export declare class BProtocol extends SimpleExchange implements IDexTxBuilder<BProtocolData, BProtocolParam> {
|
|
9
|
+
static dexKeys: string[];
|
|
10
|
+
exchangeRouterInterface: Interface;
|
|
11
|
+
constructor(dexHelper: IDexHelper);
|
|
12
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: BProtocolData, side: SwapSide): AdapterExchangeParam;
|
|
13
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: BProtocolData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
14
|
+
getDexParam(_srcToken: Address, _destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: BProtocolData, _side: SwapSide): DexExchangeParam;
|
|
15
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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.BProtocol = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
9
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
10
|
+
const BProtocol_json_1 = __importDefault(require("../../abi/BProtocol.json"));
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const utils_1 = require("../../executor/utils");
|
|
13
|
+
class BProtocol extends simple_exchange_1.SimpleExchange {
|
|
14
|
+
constructor(dexHelper) {
|
|
15
|
+
super(dexHelper, 'bprotocol');
|
|
16
|
+
this.exchangeRouterInterface = new abi_1.Interface(BProtocol_json_1.default);
|
|
17
|
+
}
|
|
18
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
19
|
+
return {
|
|
20
|
+
targetExchange: data.exchange,
|
|
21
|
+
payload: '0x',
|
|
22
|
+
networkFee: '0',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
26
|
+
const swapFunction = types_1.BProtocolFunctions.swap;
|
|
27
|
+
const swapFunctionParams = [
|
|
28
|
+
srcAmount,
|
|
29
|
+
destAmount,
|
|
30
|
+
this.augustusAddress,
|
|
31
|
+
];
|
|
32
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(swapFunction, swapFunctionParams);
|
|
33
|
+
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, data.exchange);
|
|
34
|
+
}
|
|
35
|
+
getDexParam(_srcToken, _destToken, srcAmount, destAmount, recipient, data, _side) {
|
|
36
|
+
const swapFunction = types_1.BProtocolFunctions.swap;
|
|
37
|
+
const swapFunctionParams = [
|
|
38
|
+
srcAmount,
|
|
39
|
+
destAmount,
|
|
40
|
+
recipient,
|
|
41
|
+
];
|
|
42
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(swapFunction, swapFunctionParams);
|
|
43
|
+
return {
|
|
44
|
+
needWrapNative: this.needWrapNative,
|
|
45
|
+
dexFuncHasRecipient: true,
|
|
46
|
+
exchangeData: swapData,
|
|
47
|
+
targetExchange: data.exchange,
|
|
48
|
+
returnAmountPos: _side === constants_1.SwapSide.SELL
|
|
49
|
+
? (0, utils_1.extractReturnAmountPosition)(this.exchangeRouterInterface, swapFunction)
|
|
50
|
+
: undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.BProtocol = BProtocol;
|
|
55
|
+
BProtocol.dexKeys = ['bprotocol'];
|
|
56
|
+
//# sourceMappingURL=bProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bProtocol.js","sourceRoot":"","sources":["../../../src/dex/bProtocol/bProtocol.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA6D;AAC7D,+CAA2C;AAS3C,wDAAoD;AACpD,8EAAoD;AAEpD,mCAA4E;AAC5E,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,IAAI,CAAC,cAAc;YACnC,mBAAmB,EAAE,IAAI;YACzB,YAAY,EAAE,QAAQ;YACtB,cAAc,EAAE,IAAI,CAAC,QAAQ;YAC7B,eAAe,EACb,KAAK,KAAK,oBAAQ,CAAC,IAAI;gBACrB,CAAC,CAAC,IAAA,mCAA2B,EACzB,IAAI,CAAC,uBAAuB,EAC5B,YAAY,CACb;gBACH,CAAC,CAAC,SAAS;SAChB,CAAC;IACJ,CAAC;;AA1FH,8BA2FC;AAvFQ,iBAAO,GAAG,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BProtocolFunctions = void 0;
|
|
4
|
+
var BProtocolFunctions;
|
|
5
|
+
(function (BProtocolFunctions) {
|
|
6
|
+
BProtocolFunctions["swap"] = "swap";
|
|
7
|
+
})(BProtocolFunctions = exports.BProtocolFunctions || (exports.BProtocolFunctions = {}));
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/bProtocol/types.ts"],"names":[],"mappings":";;;AAUA,IAAY,kBAEX;AAFD,WAAY,kBAAkB;IAC5B,mCAAa,CAAA;AACf,CAAC,EAFW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAE7B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Interface, Result } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import { Log, Logger } from '../../../types';
|
|
4
|
+
import { StatefulEventSubscriber } from '../../../stateful-event-subscriber';
|
|
5
|
+
import { IDexHelper } from '../../../dex-helper/idex-helper';
|
|
6
|
+
import { Contract } from 'ethers';
|
|
7
|
+
import { PoolState, PoolKey } from './pool-utils';
|
|
8
|
+
export interface Quote {
|
|
9
|
+
consumedAmount: bigint;
|
|
10
|
+
calculatedAmount: bigint;
|
|
11
|
+
gasConsumed: number;
|
|
12
|
+
skipAhead: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class BasePool extends StatefulEventSubscriber<PoolState.Object> {
|
|
15
|
+
readonly parentName: string;
|
|
16
|
+
protected network: number;
|
|
17
|
+
protected dexHelper: IDexHelper;
|
|
18
|
+
private readonly coreIface;
|
|
19
|
+
private readonly dataFetcher;
|
|
20
|
+
readonly key: PoolKey;
|
|
21
|
+
readonly addressesSubscribed: string[];
|
|
22
|
+
constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, coreIface: Interface, dataFetcher: Contract, key: PoolKey, core: Contract);
|
|
23
|
+
/**
|
|
24
|
+
* The function is called every time any of the subscribed
|
|
25
|
+
* addresses release log. The function accepts the current
|
|
26
|
+
* state, updates the state according to the log, and returns
|
|
27
|
+
* the updated state.
|
|
28
|
+
* @param state - Current state of event subscriber
|
|
29
|
+
* @param log - Log released by one of the subscribed addresses
|
|
30
|
+
* @returns Updates state of the event subscriber after the log
|
|
31
|
+
*/
|
|
32
|
+
protected processLog(state: DeepReadonly<PoolState.Object>, log: Readonly<Log>): DeepReadonly<PoolState.Object> | null;
|
|
33
|
+
/**
|
|
34
|
+
* The function generates state using on-chain calls. This
|
|
35
|
+
* function is called to regenerate state if the event based
|
|
36
|
+
* system fails to fetch events and the local state is no
|
|
37
|
+
* more correct.
|
|
38
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
39
|
+
* should be generated
|
|
40
|
+
* @returns state of the event subscriber at blocknumber
|
|
41
|
+
*/
|
|
42
|
+
generateState(blockNumber: number): Promise<DeepReadonly<PoolState.Object>>;
|
|
43
|
+
handleSwappedEvent(data: string, oldState: DeepReadonly<PoolState.Object>): DeepReadonly<PoolState.Object> | null;
|
|
44
|
+
handlePositionUpdatedEvent(args: Result, oldState: DeepReadonly<PoolState.Object>): DeepReadonly<PoolState.Object> | null;
|
|
45
|
+
quote(amount: bigint, token: bigint, blockNumber: number): Quote;
|
|
46
|
+
computeTvl(): [bigint, bigint] | null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasePool = void 0;
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
|
+
const stateful_event_subscriber_1 = require("../../../stateful-event-subscriber");
|
|
6
|
+
const swap_1 = require("./math/swap");
|
|
7
|
+
const tick_1 = require("./math/tick");
|
|
8
|
+
const price_1 = require("./math/price");
|
|
9
|
+
const pool_utils_1 = require("./pool-utils");
|
|
10
|
+
const BASE_GAS_COST = 46_000;
|
|
11
|
+
const GAS_COST_OF_ONE_INITIALIZED_TICK_CROSSED = 9_400;
|
|
12
|
+
const GAS_COST_OF_ONE_TICK_SPACING_CROSSED = 4_000;
|
|
13
|
+
class BasePool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
14
|
+
parentName;
|
|
15
|
+
network;
|
|
16
|
+
dexHelper;
|
|
17
|
+
coreIface;
|
|
18
|
+
dataFetcher;
|
|
19
|
+
key;
|
|
20
|
+
addressesSubscribed;
|
|
21
|
+
constructor(parentName, network, dexHelper, logger, coreIface, dataFetcher, key, core) {
|
|
22
|
+
super(parentName, key.string_id, dexHelper, logger);
|
|
23
|
+
this.parentName = parentName;
|
|
24
|
+
this.network = network;
|
|
25
|
+
this.dexHelper = dexHelper;
|
|
26
|
+
this.coreIface = coreIface;
|
|
27
|
+
this.dataFetcher = dataFetcher;
|
|
28
|
+
this.key = key;
|
|
29
|
+
this.addressesSubscribed = [core.address];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The function is called every time any of the subscribed
|
|
33
|
+
* addresses release log. The function accepts the current
|
|
34
|
+
* state, updates the state according to the log, and returns
|
|
35
|
+
* the updated state.
|
|
36
|
+
* @param state - Current state of event subscriber
|
|
37
|
+
* @param log - Log released by one of the subscribed addresses
|
|
38
|
+
* @returns Updates state of the event subscriber after the log
|
|
39
|
+
*/
|
|
40
|
+
processLog(state, log) {
|
|
41
|
+
if (log.topics.length === 0) {
|
|
42
|
+
return this.handleSwappedEvent(log.data, state);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const event = this.coreIface.parseLog(log);
|
|
46
|
+
if (event.name === 'PositionUpdated') {
|
|
47
|
+
return this.handlePositionUpdatedEvent(event.args, state);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
(0, utils_1.catchParseLogError)(e, this.logger);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The function generates state using on-chain calls. This
|
|
57
|
+
* function is called to regenerate state if the event based
|
|
58
|
+
* system fails to fetch events and the local state is no
|
|
59
|
+
* more correct.
|
|
60
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
61
|
+
* should be generated
|
|
62
|
+
* @returns state of the event subscriber at blocknumber
|
|
63
|
+
*/
|
|
64
|
+
async generateState(blockNumber) {
|
|
65
|
+
const data = await this.dataFetcher.getQuoteData([this.key.toAbi()], 10, {
|
|
66
|
+
blockTag: blockNumber,
|
|
67
|
+
});
|
|
68
|
+
return pool_utils_1.PoolState.fromQuoter(data[0], this.key.config.tickSpacing === tick_1.FULL_RANGE_TICK_SPACING);
|
|
69
|
+
}
|
|
70
|
+
handleSwappedEvent(data, oldState) {
|
|
71
|
+
let n = BigInt(data);
|
|
72
|
+
const poolId = (n >> 512n) & ((1n << 256n) - 1n);
|
|
73
|
+
if (this.key.num_id !== poolId) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
// tick: int32 (4 bytes)
|
|
77
|
+
const tickRaw = n & ((1n << 32n) - 1n);
|
|
78
|
+
const tickAfter = Number(toSigned(tickRaw, 32));
|
|
79
|
+
n >>= 32n;
|
|
80
|
+
// sqrtRatio: uint96 (12 bytes)
|
|
81
|
+
const sqrtRatioAfterCompact = n & ((1n << 96n) - 1n);
|
|
82
|
+
n >>= 96n;
|
|
83
|
+
const sqrtRatioAfter = (0, price_1.floatSqrtRatioToFixed)(sqrtRatioAfterCompact);
|
|
84
|
+
// liquidity: uint128 (16 bytes)
|
|
85
|
+
const liquidityAfter = n & ((1n << 128n) - 1n);
|
|
86
|
+
return pool_utils_1.PoolState.fromSwappedEvent(oldState, sqrtRatioAfter, liquidityAfter, tickAfter);
|
|
87
|
+
}
|
|
88
|
+
handlePositionUpdatedEvent(args, oldState) {
|
|
89
|
+
if (this.key.num_id !== BigInt(args.poolId)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const params = args.params;
|
|
93
|
+
return pool_utils_1.PoolState.fromPositionUpdatedEvent(oldState, [params.bounds.lower, params.bounds.upper], params.liquidityDelta.toBigInt());
|
|
94
|
+
}
|
|
95
|
+
quote(amount, token, blockNumber) {
|
|
96
|
+
const isToken1 = token === this.key.token1;
|
|
97
|
+
if (!isToken1 && this.key.token0 !== token) {
|
|
98
|
+
throw new Error('Invalid token');
|
|
99
|
+
}
|
|
100
|
+
if (amount === 0n) {
|
|
101
|
+
return {
|
|
102
|
+
consumedAmount: 0n,
|
|
103
|
+
calculatedAmount: 0n,
|
|
104
|
+
gasConsumed: 0,
|
|
105
|
+
skipAhead: 0,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const isIncreasing = (0, swap_1.isPriceIncreasing)(amount, isToken1);
|
|
109
|
+
let state = this.getState(blockNumber);
|
|
110
|
+
if (state === null) {
|
|
111
|
+
throw new Error(`Quote for block number ${blockNumber} requested but state is not recent enough`);
|
|
112
|
+
}
|
|
113
|
+
let { sqrtRatio, liquidity, activeTickIndex, sortedTicks } = state;
|
|
114
|
+
const sqrtRatioLimit = isIncreasing ? tick_1.MAX_SQRT_RATIO : tick_1.MIN_SQRT_RATIO;
|
|
115
|
+
let calculatedAmount = 0n;
|
|
116
|
+
let initializedTicksCrossed = 0;
|
|
117
|
+
let amountRemaining = amount;
|
|
118
|
+
const startingSqrtRatio = sqrtRatio;
|
|
119
|
+
while (amountRemaining !== 0n && sqrtRatio !== sqrtRatioLimit) {
|
|
120
|
+
const nextInitializedTick = (isIncreasing
|
|
121
|
+
? sortedTicks[activeTickIndex === null ? 0 : activeTickIndex + 1]
|
|
122
|
+
: activeTickIndex === null
|
|
123
|
+
? null
|
|
124
|
+
: sortedTicks[activeTickIndex]) ?? null;
|
|
125
|
+
const nextInitializedTickSqrtRatio = nextInitializedTick
|
|
126
|
+
? (0, tick_1.toSqrtRatio)(nextInitializedTick.number)
|
|
127
|
+
: null;
|
|
128
|
+
const stepSqrtRatioLimit = nextInitializedTickSqrtRatio === null
|
|
129
|
+
? sqrtRatioLimit
|
|
130
|
+
: nextInitializedTickSqrtRatio < sqrtRatioLimit === isIncreasing
|
|
131
|
+
? nextInitializedTickSqrtRatio
|
|
132
|
+
: sqrtRatioLimit;
|
|
133
|
+
const step = (0, swap_1.computeStep)({
|
|
134
|
+
fee: this.key.config.fee,
|
|
135
|
+
sqrtRatio,
|
|
136
|
+
liquidity,
|
|
137
|
+
isToken1,
|
|
138
|
+
sqrtRatioLimit: stepSqrtRatioLimit,
|
|
139
|
+
amount: amountRemaining,
|
|
140
|
+
});
|
|
141
|
+
amountRemaining -= step.consumedAmount;
|
|
142
|
+
calculatedAmount += step.calculatedAmount;
|
|
143
|
+
sqrtRatio = step.sqrtRatioNext;
|
|
144
|
+
// cross the tick if the price moved all the way to the next initialized tick price
|
|
145
|
+
if (nextInitializedTick && sqrtRatio === nextInitializedTickSqrtRatio) {
|
|
146
|
+
activeTickIndex = isIncreasing
|
|
147
|
+
? activeTickIndex === null
|
|
148
|
+
? 0
|
|
149
|
+
: activeTickIndex + 1
|
|
150
|
+
: activeTickIndex
|
|
151
|
+
? activeTickIndex - 1
|
|
152
|
+
: null;
|
|
153
|
+
initializedTicksCrossed++;
|
|
154
|
+
liquidity += isIncreasing
|
|
155
|
+
? nextInitializedTick.liquidityDelta
|
|
156
|
+
: -nextInitializedTick.liquidityDelta;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const tickSpacingsCrossed = (0, tick_1.approximateNumberOfTickSpacingsCrossed)(startingSqrtRatio, sqrtRatio, this.key.config.tickSpacing);
|
|
160
|
+
return {
|
|
161
|
+
consumedAmount: amount - amountRemaining,
|
|
162
|
+
calculatedAmount,
|
|
163
|
+
gasConsumed: BASE_GAS_COST +
|
|
164
|
+
initializedTicksCrossed * GAS_COST_OF_ONE_INITIALIZED_TICK_CROSSED +
|
|
165
|
+
tickSpacingsCrossed * GAS_COST_OF_ONE_TICK_SPACING_CROSSED,
|
|
166
|
+
skipAhead: initializedTicksCrossed === 0
|
|
167
|
+
? 0
|
|
168
|
+
: Math.floor(tickSpacingsCrossed / initializedTicksCrossed),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
computeTvl() {
|
|
172
|
+
const state = this.getStaleState();
|
|
173
|
+
if (state === null) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return pool_utils_1.PoolState.computeTvl(state);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.BasePool = BasePool;
|
|
180
|
+
function toSigned(value, bits) {
|
|
181
|
+
const half = 1n << BigInt(bits - 1);
|
|
182
|
+
return value >= half ? value - (1n << BigInt(bits)) : value;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=base-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-pool.js","sourceRoot":"","sources":["../../../../src/dex/ekubo/pools/base-pool.ts"],"names":[],"mappings":";;;AAGA,0CAAoD;AACpD,kFAA6E;AAI7E,sCAA6D;AAC7D,sCAMqB;AACrB,wCAAqD;AACrD,6CAAkD;AASlD,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,wCAAwC,GAAG,KAAK,CAAC;AACvD,MAAM,oCAAoC,GAAG,KAAK,CAAC;AAEnD,MAAa,QAAS,SAAQ,mD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,GAAG,CAAC,CAAC,CAAC;IACpC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Interface, Result } from '@ethersproject/abi';
|
|
2
|
+
import { Logger } from 'log4js';
|
|
3
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
4
|
+
import { IDexHelper } from '../../../dex-helper/idex-helper';
|
|
5
|
+
import { StatefulEventSubscriber } from '../../../stateful-event-subscriber';
|
|
6
|
+
import { BlockHeader, Log } from '../../../types';
|
|
7
|
+
import { PoolKey } from './utils';
|
|
8
|
+
export interface Quote {
|
|
9
|
+
consumedAmount: bigint;
|
|
10
|
+
calculatedAmount: bigint;
|
|
11
|
+
gasConsumed: number;
|
|
12
|
+
skipAhead: number;
|
|
13
|
+
}
|
|
14
|
+
export interface PoolKeyed {
|
|
15
|
+
key: PoolKey;
|
|
16
|
+
}
|
|
17
|
+
export interface IEkuboPool extends PoolKeyed {
|
|
18
|
+
quote(amount: bigint, token: bigint, blockNumber: number): Quote;
|
|
19
|
+
}
|
|
20
|
+
export type QuoteFn<State> = (amount: bigint, isToken1: boolean, state: DeepReadonly<State>) => Quote;
|
|
21
|
+
export type NamedEventHandler<State> = (args: Result, oldState: DeepReadonly<State>, blockHeader: Readonly<BlockHeader>) => DeepReadonly<State> | null;
|
|
22
|
+
export type AnonymousEventHandler<State> = (data: string, oldState: DeepReadonly<State>, blockHeader: Readonly<BlockHeader>) => DeepReadonly<State> | null;
|
|
23
|
+
export declare class NamedEventHandlers<State> {
|
|
24
|
+
private readonly iface;
|
|
25
|
+
private readonly handlers;
|
|
26
|
+
constructor(iface: Interface, handlers: Record<string, NamedEventHandler<State>>);
|
|
27
|
+
parseLog(log: Readonly<Log>, oldState: DeepReadonly<State>, blockHeader: Readonly<BlockHeader>): DeepReadonly<State> | null;
|
|
28
|
+
}
|
|
29
|
+
export declare abstract class EkuboPool<State> extends StatefulEventSubscriber<State> implements IEkuboPool {
|
|
30
|
+
readonly key: PoolKey;
|
|
31
|
+
private readonly namedEventHandlers;
|
|
32
|
+
private readonly anonymousEventHandlers;
|
|
33
|
+
private readonly quoteFn;
|
|
34
|
+
protected constructor(parentName: string, dexHelper: IDexHelper, logger: Logger, key: PoolKey, namedEventHandlers: Record<string, NamedEventHandlers<State>>, anonymousEventHandlers: Record<string, AnonymousEventHandler<State>>, quoteFn: QuoteFn<State>);
|
|
35
|
+
/**
|
|
36
|
+
* The function is called every time any of the subscribed
|
|
37
|
+
* addresses release log. The function accepts the current
|
|
38
|
+
* state, updates the state according to the log, and returns
|
|
39
|
+
* the updated state.
|
|
40
|
+
* @param state - Current state of event subscriber
|
|
41
|
+
* @param log - Log released by one of the subscribed addresses
|
|
42
|
+
* @returns Updates state of the event subscriber after the log
|
|
43
|
+
*/
|
|
44
|
+
protected processLog(state: DeepReadonly<State>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): DeepReadonly<State> | null;
|
|
45
|
+
quote(amount: bigint, token: bigint, blockNumber: number): Quote;
|
|
46
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EkuboPool = exports.NamedEventHandlers = void 0;
|
|
4
|
+
const stateful_event_subscriber_1 = require("../../../stateful-event-subscriber");
|
|
5
|
+
class NamedEventHandlers {
|
|
6
|
+
iface;
|
|
7
|
+
handlers;
|
|
8
|
+
constructor(iface, handlers) {
|
|
9
|
+
this.iface = iface;
|
|
10
|
+
this.handlers = handlers;
|
|
11
|
+
}
|
|
12
|
+
parseLog(log, oldState, blockHeader) {
|
|
13
|
+
const event = this.iface.parseLog(log);
|
|
14
|
+
return this.handlers[event.name]?.(event.args, oldState, blockHeader);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.NamedEventHandlers = NamedEventHandlers;
|
|
18
|
+
const BASE_GAS_COST = 22_000;
|
|
19
|
+
class EkuboPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
20
|
+
key;
|
|
21
|
+
namedEventHandlers;
|
|
22
|
+
anonymousEventHandlers;
|
|
23
|
+
quoteFn;
|
|
24
|
+
constructor(parentName, dexHelper, logger, key, namedEventHandlers, anonymousEventHandlers, quoteFn) {
|
|
25
|
+
super(parentName, key.string_id, dexHelper, logger);
|
|
26
|
+
this.key = key;
|
|
27
|
+
this.namedEventHandlers = namedEventHandlers;
|
|
28
|
+
this.anonymousEventHandlers = anonymousEventHandlers;
|
|
29
|
+
this.quoteFn = quoteFn;
|
|
30
|
+
this.addressesSubscribed = [
|
|
31
|
+
...new Set(Object.keys(namedEventHandlers).concat(Object.keys(anonymousEventHandlers))),
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The function is called every time any of the subscribed
|
|
36
|
+
* addresses release log. The function accepts the current
|
|
37
|
+
* state, updates the state according to the log, and returns
|
|
38
|
+
* the updated state.
|
|
39
|
+
* @param state - Current state of event subscriber
|
|
40
|
+
* @param log - Log released by one of the subscribed addresses
|
|
41
|
+
* @returns Updates state of the event subscriber after the log
|
|
42
|
+
*/
|
|
43
|
+
processLog(state, log, blockHeader) {
|
|
44
|
+
const emitter = log.address;
|
|
45
|
+
if (log.topics.length === 0) {
|
|
46
|
+
return this.anonymousEventHandlers[emitter]?.(log.data, state, blockHeader);
|
|
47
|
+
}
|
|
48
|
+
return this.namedEventHandlers[emitter]?.parseLog(log, state, blockHeader);
|
|
49
|
+
}
|
|
50
|
+
quote(amount, token, blockNumber) {
|
|
51
|
+
const isToken1 = token === this.key.token1;
|
|
52
|
+
if (!isToken1 && this.key.token0 !== token) {
|
|
53
|
+
throw new Error('Invalid token');
|
|
54
|
+
}
|
|
55
|
+
if (amount === 0n) {
|
|
56
|
+
return {
|
|
57
|
+
consumedAmount: 0n,
|
|
58
|
+
calculatedAmount: 0n,
|
|
59
|
+
gasConsumed: 0,
|
|
60
|
+
skipAhead: 0,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const state = this.getState(blockNumber);
|
|
64
|
+
if (state === null) {
|
|
65
|
+
throw new Error(`Quote for block number ${blockNumber} requested but state is not recent enough`);
|
|
66
|
+
}
|
|
67
|
+
const quote = this.quoteFn(amount, isToken1, state);
|
|
68
|
+
if (quote.calculatedAmount !== 0n) {
|
|
69
|
+
quote.gasConsumed += BASE_GAS_COST;
|
|
70
|
+
}
|
|
71
|
+
return quote;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.EkuboPool = EkuboPool;
|
|
75
|
+
//# sourceMappingURL=iface.js.map
|