@lifi/sdk 2.3.1 → 3.0.0-alpha.10
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/dist/cjs/LiFi.js +222 -250
- package/dist/cjs/LiFi.js.map +1 -0
- package/dist/cjs/allowance/getAllowance.js +82 -0
- package/dist/cjs/allowance/getAllowance.js.map +1 -0
- package/dist/cjs/allowance/index.js +5 -16
- package/dist/cjs/allowance/index.js.map +1 -0
- package/dist/cjs/allowance/setAllowance.js +71 -0
- package/dist/cjs/allowance/setAllowance.js.map +1 -0
- package/dist/cjs/{types/internal.types.js → allowance/types.js} +1 -0
- package/dist/cjs/allowance/types.js.map +1 -0
- package/dist/cjs/balance/getBalance.js +97 -0
- package/dist/cjs/balance/getBalance.js.map +1 -0
- package/dist/cjs/balance/getTokenBalance.js +7 -10
- package/dist/cjs/balance/getTokenBalance.js.map +1 -0
- package/dist/cjs/balance/index.js +4 -24
- package/dist/cjs/balance/index.js.map +1 -0
- package/dist/cjs/connectors.js +28 -48
- package/dist/cjs/connectors.js.map +1 -0
- package/dist/cjs/constants.js +7 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/execution/BaseStepExecutor.js +54 -0
- package/dist/cjs/execution/BaseStepExecutor.js.map +1 -0
- package/dist/cjs/execution/EVMStepExecutor.js +271 -0
- package/dist/cjs/execution/EVMStepExecutor.js.map +1 -0
- package/dist/cjs/execution/RouteExecutionManager.js +196 -197
- package/dist/cjs/execution/RouteExecutionManager.js.map +1 -0
- package/dist/cjs/execution/StatusManager.js +142 -136
- package/dist/cjs/execution/StatusManager.js.map +1 -0
- package/dist/cjs/execution/StepExecutionManager.js +220 -233
- package/dist/cjs/execution/StepExecutionManager.js.map +1 -0
- package/dist/cjs/execution/checkAllowance.js +76 -0
- package/dist/cjs/execution/checkAllowance.js.map +1 -0
- package/dist/cjs/execution/checkBalance.js +42 -0
- package/dist/cjs/execution/checkBalance.js.map +1 -0
- package/dist/cjs/execution/index.js +4 -15
- package/dist/cjs/execution/index.js.map +1 -0
- package/dist/cjs/execution/multisig.js +13 -17
- package/dist/cjs/execution/multisig.js.map +1 -0
- package/dist/cjs/execution/prepareRestart.js +23 -0
- package/dist/cjs/execution/prepareRestart.js.map +1 -0
- package/dist/cjs/execution/stepComparison.js +5 -17
- package/dist/cjs/execution/stepComparison.js.map +1 -0
- package/dist/cjs/execution/switchChain.js +10 -22
- package/dist/cjs/execution/switchChain.js.map +1 -0
- package/dist/cjs/execution/types.js +3 -0
- package/dist/cjs/execution/types.js.map +1 -0
- package/dist/cjs/execution/utils.js +12 -67
- package/dist/cjs/execution/utils.js.map +1 -0
- package/dist/cjs/execution/waitForReceivingTransaction.js +56 -0
- package/dist/cjs/execution/waitForReceivingTransaction.js.map +1 -0
- package/dist/cjs/helpers.js +12 -58
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.js +16 -22
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/providers/EVM.js +35 -0
- package/dist/cjs/providers/EVM.js.map +1 -0
- package/dist/cjs/providers/Solana.js +38 -0
- package/dist/cjs/providers/Solana.js.map +1 -0
- package/dist/cjs/providers/index.js +5 -0
- package/dist/cjs/providers/index.js.map +1 -0
- package/dist/cjs/providers/types.js +9 -0
- package/dist/cjs/providers/types.js.map +1 -0
- package/dist/cjs/request.js +10 -13
- package/dist/cjs/request.js.map +1 -0
- package/dist/cjs/services/ApiService.js +70 -86
- package/dist/cjs/services/ApiService.js.map +1 -0
- package/dist/cjs/services/ChainsService.js +19 -9
- package/dist/cjs/services/ChainsService.js.map +1 -0
- package/dist/cjs/services/ConfigService.js +94 -67
- package/dist/cjs/services/ConfigService.js.map +1 -0
- package/dist/cjs/typeguards.js +1 -0
- package/dist/cjs/typeguards.js.map +1 -0
- package/dist/cjs/types/abi.js +46 -0
- package/dist/cjs/types/abi.js.map +1 -0
- package/dist/cjs/types/index.js +4 -20
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/internal.js +3 -0
- package/dist/cjs/types/internal.js.map +1 -0
- package/dist/cjs/utils/errors.js +63 -40
- package/dist/cjs/utils/errors.js.map +1 -0
- package/dist/cjs/utils/getMaxPriorityFeePerGas.js +23 -0
- package/dist/cjs/utils/getMaxPriorityFeePerGas.js.map +1 -0
- package/dist/cjs/utils/index.js +9 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/median.js +16 -0
- package/dist/cjs/utils/median.js.map +1 -0
- package/dist/cjs/utils/parseError.js +55 -92
- package/dist/cjs/utils/parseError.js.map +1 -0
- package/dist/cjs/utils/utils.js +10 -85
- package/dist/cjs/utils/utils.js.map +1 -0
- package/dist/cjs/version.js +2 -1
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/LiFi.js +375 -0
- package/dist/esm/LiFi.js.map +1 -0
- package/dist/esm/allowance/getAllowance.js +79 -0
- package/dist/esm/allowance/getAllowance.js.map +1 -0
- package/dist/esm/allowance/index.js +4 -0
- package/dist/esm/allowance/index.js.map +1 -0
- package/dist/esm/allowance/setAllowance.js +67 -0
- package/dist/esm/allowance/setAllowance.js.map +1 -0
- package/dist/esm/allowance/types.js +2 -0
- package/dist/esm/allowance/types.js.map +1 -0
- package/dist/esm/balance/getBalance.js +93 -0
- package/dist/esm/balance/getBalance.js.map +1 -0
- package/dist/{balance → esm/balance}/getTokenBalance.js +5 -4
- package/dist/esm/balance/getTokenBalance.js.map +1 -0
- package/dist/esm/balance/index.js +3 -0
- package/dist/esm/balance/index.js.map +1 -0
- package/dist/esm/connectors.js +42 -0
- package/dist/esm/connectors.js.map +1 -0
- package/dist/esm/constants.js +7 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/execution/BaseStepExecutor.js +51 -0
- package/dist/esm/execution/BaseStepExecutor.js.map +1 -0
- package/dist/esm/execution/EVMStepExecutor.js +299 -0
- package/dist/esm/execution/EVMStepExecutor.js.map +1 -0
- package/dist/esm/execution/RouteExecutionManager.js +268 -0
- package/dist/esm/execution/RouteExecutionManager.js.map +1 -0
- package/dist/esm/execution/StatusManager.js +216 -0
- package/dist/esm/execution/StatusManager.js.map +1 -0
- package/dist/esm/execution/StepExecutionManager.js +280 -0
- package/dist/esm/execution/StepExecutionManager.js.map +1 -0
- package/dist/esm/execution/checkAllowance.js +74 -0
- package/dist/esm/execution/checkAllowance.js.map +1 -0
- package/dist/esm/execution/checkBalance.js +39 -0
- package/dist/esm/execution/checkBalance.js.map +1 -0
- package/dist/esm/execution/index.js +3 -0
- package/dist/esm/execution/index.js.map +1 -0
- package/dist/esm/execution/multisig.js +26 -0
- package/dist/esm/execution/multisig.js.map +1 -0
- package/dist/esm/execution/prepareRestart.js +64 -0
- package/dist/esm/execution/prepareRestart.js.map +1 -0
- package/dist/{execution → esm/execution}/stepComparison.js +5 -4
- package/dist/esm/execution/stepComparison.js.map +1 -0
- package/dist/{execution → esm/execution}/switchChain.js +19 -12
- package/dist/esm/execution/switchChain.js.map +1 -0
- package/dist/esm/execution/types.js +2 -0
- package/dist/esm/execution/types.js.map +1 -0
- package/dist/esm/execution/utils.js +80 -0
- package/dist/esm/execution/utils.js.map +1 -0
- package/dist/esm/execution/waitForReceivingTransaction.js +52 -0
- package/dist/esm/execution/waitForReceivingTransaction.js.map +1 -0
- package/dist/{helpers.js → esm/helpers.js} +9 -37
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/providers/EVM.js +30 -0
- package/dist/esm/providers/EVM.js.map +1 -0
- package/dist/esm/providers/Solana.js +34 -0
- package/dist/esm/providers/Solana.js.map +1 -0
- package/dist/esm/providers/index.js +2 -0
- package/dist/esm/providers/index.js.map +1 -0
- package/dist/esm/providers/types.js +6 -0
- package/dist/esm/providers/types.js.map +1 -0
- package/dist/{request.js → esm/request.js} +6 -5
- package/dist/esm/request.js.map +1 -0
- package/dist/{services → esm/services}/ApiService.js +29 -26
- package/dist/esm/services/ApiService.js.map +1 -0
- package/dist/{services → esm/services}/ChainsService.js +16 -4
- package/dist/esm/services/ChainsService.js.map +1 -0
- package/dist/esm/services/ConfigService.js +143 -0
- package/dist/esm/services/ConfigService.js.map +1 -0
- package/dist/{typeguards.js → esm/typeguards.js} +1 -0
- package/dist/esm/typeguards.js.map +1 -0
- package/dist/esm/types/abi.js +43 -0
- package/dist/esm/types/abi.js.map +1 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/internal.js +2 -0
- package/dist/esm/types/internal.js.map +1 -0
- package/dist/{utils → esm/utils}/errors.js +61 -35
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/getMaxPriorityFeePerGas.js +19 -0
- package/dist/esm/utils/getMaxPriorityFeePerGas.js.map +1 -0
- package/dist/esm/utils/index.js +6 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/median.js +12 -0
- package/dist/esm/utils/median.js.map +1 -0
- package/dist/{utils → esm/utils}/parseError.js +45 -41
- package/dist/esm/utils/parseError.js.map +1 -0
- package/dist/esm/utils/utils.js +38 -0
- package/dist/esm/utils/utils.js.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/LiFi.d.ts +179 -0
- package/dist/types/LiFi.d.ts.map +1 -0
- package/dist/types/allowance/getAllowance.d.ts +7 -0
- package/dist/types/allowance/getAllowance.d.ts.map +1 -0
- package/dist/types/allowance/index.d.ts +4 -0
- package/dist/types/allowance/index.d.ts.map +1 -0
- package/dist/types/allowance/setAllowance.d.ts +7 -0
- package/dist/types/allowance/setAllowance.d.ts.map +1 -0
- package/dist/types/allowance/types.d.ts +28 -0
- package/dist/types/allowance/types.d.ts.map +1 -0
- package/dist/types/balance/getBalance.d.ts +3 -0
- package/dist/types/balance/getBalance.d.ts.map +1 -0
- package/dist/{balance → types/balance}/getTokenBalance.d.ts +3 -2
- package/dist/types/balance/getTokenBalance.d.ts.map +1 -0
- package/dist/types/balance/index.d.ts +3 -0
- package/dist/types/balance/index.d.ts.map +1 -0
- package/dist/types/connectors.d.ts +9 -0
- package/dist/types/connectors.d.ts.map +1 -0
- package/dist/types/constants.d.ts +7 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/execution/BaseStepExecutor.d.ts +13 -0
- package/dist/types/execution/BaseStepExecutor.d.ts.map +1 -0
- package/dist/types/execution/EVMStepExecutor.d.ts +14 -0
- package/dist/types/execution/EVMStepExecutor.d.ts.map +1 -0
- package/dist/types/execution/RouteExecutionManager.d.ts +61 -0
- package/dist/types/execution/RouteExecutionManager.d.ts.map +1 -0
- package/dist/types/execution/StatusManager.d.ts +69 -0
- package/dist/types/execution/StatusManager.d.ts.map +1 -0
- package/dist/types/execution/StepExecutionManager.d.ts +8 -0
- package/dist/types/execution/StepExecutionManager.d.ts.map +1 -0
- package/dist/types/execution/checkAllowance.d.ts +6 -0
- package/dist/types/execution/checkAllowance.d.ts.map +1 -0
- package/dist/types/execution/checkBalance.d.ts +3 -0
- package/dist/types/execution/checkBalance.d.ts.map +1 -0
- package/dist/types/execution/index.d.ts +3 -0
- package/dist/types/execution/index.d.ts.map +1 -0
- package/dist/types/execution/multisig.d.ts +5 -0
- package/dist/types/execution/multisig.d.ts.map +1 -0
- package/dist/types/execution/prepareRestart.d.ts +3 -0
- package/dist/types/execution/prepareRestart.d.ts.map +1 -0
- package/dist/{execution → types/execution}/stepComparison.d.ts +6 -4
- package/dist/types/execution/stepComparison.d.ts.map +1 -0
- package/dist/types/execution/switchChain.d.ts +23 -0
- package/dist/types/execution/switchChain.d.ts.map +1 -0
- package/dist/types/execution/types.d.ts +83 -0
- package/dist/types/execution/types.d.ts.map +1 -0
- package/dist/types/execution/utils.d.ts +13 -0
- package/dist/types/execution/utils.d.ts.map +1 -0
- package/dist/types/execution/waitForReceivingTransaction.d.ts +4 -0
- package/dist/types/execution/waitForReceivingTransaction.d.ts.map +1 -0
- package/dist/types/helpers.d.ts +19 -0
- package/dist/types/helpers.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -3
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/providers/EVM.d.ts +11 -0
- package/dist/types/providers/EVM.d.ts.map +1 -0
- package/dist/types/providers/Solana.d.ts +10 -0
- package/dist/types/providers/Solana.d.ts.map +1 -0
- package/dist/types/providers/index.d.ts +2 -0
- package/dist/types/providers/index.d.ts.map +1 -0
- package/dist/types/providers/types.d.ts +13 -0
- package/dist/types/providers/types.d.ts.map +1 -0
- package/dist/{request.d.ts → types/request.d.ts} +1 -0
- package/dist/types/request.d.ts.map +1 -0
- package/dist/{cjs → types}/services/ApiService.d.ts +5 -5
- package/dist/types/services/ApiService.d.ts.map +1 -0
- package/dist/{services → types/services}/ChainsService.d.ts +3 -2
- package/dist/types/services/ChainsService.d.ts.map +1 -0
- package/dist/{services → types/services}/ConfigService.d.ts +10 -6
- package/dist/types/services/ConfigService.d.ts.map +1 -0
- package/dist/{cjs → types}/typeguards.d.ts +3 -2
- package/dist/types/typeguards.d.ts.map +1 -0
- package/dist/types/types/abi.d.ts +6 -0
- package/dist/types/types/abi.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/internal.d.ts +61 -0
- package/dist/types/types/internal.d.ts.map +1 -0
- package/dist/{cjs → types}/utils/errors.d.ts +16 -14
- package/dist/types/utils/errors.d.ts.map +1 -0
- package/dist/types/utils/getMaxPriorityFeePerGas.d.ts +3 -0
- package/dist/types/utils/getMaxPriorityFeePerGas.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/median.d.ts +2 -0
- package/dist/types/utils/median.d.ts.map +1 -0
- package/dist/{utils → types/utils}/parseError.d.ts +7 -6
- package/dist/types/utils/parseError.d.ts.map +1 -0
- package/dist/types/utils/utils.d.ts +11 -0
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/types/version.d.ts +3 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +37 -95
- package/dist/LiFi.d.ts +0 -164
- package/dist/LiFi.js +0 -235
- package/dist/allowance/checkAllowance.d.ts +0 -4
- package/dist/allowance/checkAllowance.js +0 -96
- package/dist/allowance/index.d.ts +0 -2
- package/dist/allowance/index.js +0 -2
- package/dist/allowance/tokenApproval.d.ts +0 -22
- package/dist/allowance/tokenApproval.js +0 -59
- package/dist/allowance/utils.d.ts +0 -14
- package/dist/allowance/utils.js +0 -72
- package/dist/balance/checkBalance.d.ts +0 -3
- package/dist/balance/checkBalance.js +0 -38
- package/dist/balance/index.d.ts +0 -13
- package/dist/balance/index.js +0 -10
- package/dist/balance/utils.d.ts +0 -6
- package/dist/balance/utils.js +0 -143
- package/dist/cjs/LiFi.d.ts +0 -164
- package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
- package/dist/cjs/allowance/checkAllowance.js +0 -103
- package/dist/cjs/allowance/index.d.ts +0 -2
- package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
- package/dist/cjs/allowance/tokenApproval.js +0 -69
- package/dist/cjs/allowance/utils.d.ts +0 -14
- package/dist/cjs/allowance/utils.js +0 -82
- package/dist/cjs/balance/checkBalance.d.ts +0 -3
- package/dist/cjs/balance/checkBalance.js +0 -45
- package/dist/cjs/balance/getTokenBalance.d.ts +0 -8
- package/dist/cjs/balance/index.d.ts +0 -13
- package/dist/cjs/balance/utils.d.ts +0 -6
- package/dist/cjs/balance/utils.js +0 -150
- package/dist/cjs/connectors.d.ts +0 -6
- package/dist/cjs/execution/RouteExecutionManager.d.ts +0 -65
- package/dist/cjs/execution/StatusManager.d.ts +0 -68
- package/dist/cjs/execution/StepExecutionManager.d.ts +0 -7
- package/dist/cjs/execution/StepExecutor.d.ts +0 -15
- package/dist/cjs/execution/StepExecutor.js +0 -62
- package/dist/cjs/execution/index.d.ts +0 -1
- package/dist/cjs/execution/multisig.d.ts +0 -3
- package/dist/cjs/execution/stepComparison.d.ts +0 -14
- package/dist/cjs/execution/switchChain.d.ts +0 -16
- package/dist/cjs/execution/utils.d.ts +0 -6
- package/dist/cjs/helpers.d.ts +0 -28
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/request.d.ts +0 -9
- package/dist/cjs/services/ChainsService.d.ts +0 -11
- package/dist/cjs/services/ConfigService.d.ts +0 -23
- package/dist/cjs/types/ERC20.d.ts +0 -22
- package/dist/cjs/types/ERC20.js +0 -53
- package/dist/cjs/types/index.d.ts +0 -4
- package/dist/cjs/types/internal.types.d.ts +0 -151
- package/dist/cjs/utils/getProvider.d.ts +0 -3
- package/dist/cjs/utils/getProvider.js +0 -11
- package/dist/cjs/utils/multicall.d.ts +0 -10
- package/dist/cjs/utils/multicall.js +0 -68
- package/dist/cjs/utils/multicallAbi.json +0 -313
- package/dist/cjs/utils/parseError.d.ts +0 -37
- package/dist/cjs/utils/preRestart.d.ts +0 -3
- package/dist/cjs/utils/preRestart.js +0 -56
- package/dist/cjs/utils/utils.d.ts +0 -25
- package/dist/cjs/version.d.ts +0 -2
- package/dist/connectors.d.ts +0 -6
- package/dist/connectors.js +0 -57
- package/dist/execution/RouteExecutionManager.d.ts +0 -65
- package/dist/execution/RouteExecutionManager.js +0 -213
- package/dist/execution/StatusManager.d.ts +0 -68
- package/dist/execution/StatusManager.js +0 -168
- package/dist/execution/StepExecutionManager.d.ts +0 -7
- package/dist/execution/StepExecutionManager.js +0 -267
- package/dist/execution/StepExecutor.d.ts +0 -15
- package/dist/execution/StepExecutor.js +0 -58
- package/dist/execution/index.d.ts +0 -1
- package/dist/execution/index.js +0 -1
- package/dist/execution/multisig.d.ts +0 -3
- package/dist/execution/multisig.js +0 -27
- package/dist/execution/switchChain.d.ts +0 -16
- package/dist/execution/utils.d.ts +0 -6
- package/dist/execution/utils.js +0 -122
- package/dist/helpers.d.ts +0 -28
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -6
- package/dist/services/ApiService.d.ts +0 -17
- package/dist/services/ConfigService.js +0 -101
- package/dist/typeguards.d.ts +0 -4
- package/dist/types/ERC20.d.ts +0 -22
- package/dist/types/ERC20.js +0 -50
- package/dist/types/index.js +0 -4
- package/dist/types/internal.types.d.ts +0 -151
- package/dist/types/internal.types.js +0 -1
- package/dist/utils/errors.d.ts +0 -106
- package/dist/utils/getProvider.d.ts +0 -3
- package/dist/utils/getProvider.js +0 -7
- package/dist/utils/multicall.d.ts +0 -10
- package/dist/utils/multicall.js +0 -61
- package/dist/utils/multicallAbi.json +0 -313
- package/dist/utils/preRestart.d.ts +0 -3
- package/dist/utils/preRestart.js +0 -52
- package/dist/utils/utils.d.ts +0 -25
- package/dist/utils/utils.js +0 -99
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -2
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from 'ethers';
|
|
2
|
-
import { checkAllowance } from '../allowance';
|
|
3
|
-
import { checkBalance } from '../balance';
|
|
4
|
-
import ApiService from '../services/ApiService';
|
|
5
|
-
import ChainsService from '../services/ChainsService';
|
|
6
|
-
import { LifiErrorCode, TransactionError, ValidationError, } from '../utils/errors';
|
|
7
|
-
import { getProvider } from '../utils/getProvider';
|
|
8
|
-
import { getTransactionFailedMessage, parseError } from '../utils/parseError';
|
|
9
|
-
import { isZeroAddress, personalizeStep } from '../utils/utils';
|
|
10
|
-
import { stepComparison } from './stepComparison';
|
|
11
|
-
import { switchChain } from './switchChain';
|
|
12
|
-
import { getSubstatusMessage, waitForReceivingTransaction } from './utils';
|
|
13
|
-
import ConfigService from '../services/ConfigService';
|
|
14
|
-
import { updateMultisigRouteProcess } from './multisig';
|
|
15
|
-
export class StepExecutionManager {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.allowUserInteraction = true;
|
|
18
|
-
this.allowInteraction = (value) => {
|
|
19
|
-
this.allowUserInteraction = value;
|
|
20
|
-
};
|
|
21
|
-
this.execute = async ({ signer, step, statusManager, settings, }) => {
|
|
22
|
-
const config = ConfigService.getInstance().getConfig();
|
|
23
|
-
const isMultisigSigner = !!config.multisigConfig?.isMultisigSigner;
|
|
24
|
-
const multisigBatchTransactions = [];
|
|
25
|
-
const shouldBatchTransactions = config.multisigConfig?.shouldBatchTransactions &&
|
|
26
|
-
!!config.multisigConfig.sendBatchTransaction;
|
|
27
|
-
step.execution = statusManager.initExecutionObject(step);
|
|
28
|
-
const chainsService = ChainsService.getInstance();
|
|
29
|
-
const fromChain = await chainsService.getChainById(step.action.fromChainId);
|
|
30
|
-
const toChain = await chainsService.getChainById(step.action.toChainId);
|
|
31
|
-
const isBridgeExecution = fromChain.id !== toChain.id;
|
|
32
|
-
const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP';
|
|
33
|
-
// STEP 1: Check allowance
|
|
34
|
-
const existingProcess = step.execution.process.find((p) => p.type === currentProcessType);
|
|
35
|
-
// Check token approval only if fromToken is not the native token => no approval needed in that case
|
|
36
|
-
const checkForAllowance = !existingProcess?.txHash &&
|
|
37
|
-
!isZeroAddress(step.action.fromToken.address) &&
|
|
38
|
-
(shouldBatchTransactions || !isMultisigSigner);
|
|
39
|
-
if (checkForAllowance) {
|
|
40
|
-
const populatedTransaction = await checkAllowance(signer, step, statusManager, settings, fromChain, this.allowUserInteraction, shouldBatchTransactions);
|
|
41
|
-
if (populatedTransaction) {
|
|
42
|
-
const { to, data } = populatedTransaction;
|
|
43
|
-
if (to && data) {
|
|
44
|
-
// allowance doesn't need value
|
|
45
|
-
const cleanedPopulatedTransaction = {
|
|
46
|
-
value: BigNumber.from(0).toString(),
|
|
47
|
-
to,
|
|
48
|
-
data,
|
|
49
|
-
};
|
|
50
|
-
multisigBatchTransactions.push(cleanedPopulatedTransaction);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// STEP 2: Get transaction
|
|
55
|
-
let process = statusManager.findOrCreateProcess(step, currentProcessType);
|
|
56
|
-
if (process.status !== 'DONE') {
|
|
57
|
-
const multisigProcess = step.execution.process.find((p) => !!p.multisigTxHash);
|
|
58
|
-
try {
|
|
59
|
-
if (isMultisigSigner && multisigProcess) {
|
|
60
|
-
if (!multisigProcess) {
|
|
61
|
-
throw new ValidationError('Multisig process is undefined.');
|
|
62
|
-
}
|
|
63
|
-
if (!config.multisigConfig?.getMultisigTransactionDetails) {
|
|
64
|
-
throw new ValidationError('"getMultisigTransactionDetails()" is missing in Multisig config.');
|
|
65
|
-
}
|
|
66
|
-
const multisigTxHash = multisigProcess.multisigTxHash;
|
|
67
|
-
if (!multisigTxHash) {
|
|
68
|
-
// need to check what happens in failed tx
|
|
69
|
-
throw new ValidationError('Multisig internal transaction hash is undefined.');
|
|
70
|
-
}
|
|
71
|
-
await updateMultisigRouteProcess(multisigTxHash, step, statusManager, process, fromChain);
|
|
72
|
-
}
|
|
73
|
-
let transaction;
|
|
74
|
-
if (process.txHash) {
|
|
75
|
-
// Make sure that the chain is still correct
|
|
76
|
-
const updatedSigner = await switchChain(signer, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
77
|
-
if (!updatedSigner) {
|
|
78
|
-
// Chain switch was not successful, stop execution here
|
|
79
|
-
return step.execution;
|
|
80
|
-
}
|
|
81
|
-
signer = updatedSigner;
|
|
82
|
-
// Load exiting transaction
|
|
83
|
-
transaction = await getProvider(signer).getTransaction(process.txHash);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
process = statusManager.updateProcess(step, process.type, 'STARTED');
|
|
87
|
-
// Check balance
|
|
88
|
-
await checkBalance(signer, step);
|
|
89
|
-
// Create new transaction
|
|
90
|
-
if (!step.transactionRequest) {
|
|
91
|
-
const personalizedStep = await personalizeStep(signer, step);
|
|
92
|
-
const updatedStep = await ApiService.getStepTransaction(personalizedStep);
|
|
93
|
-
const comparedStep = await stepComparison(statusManager, personalizedStep, updatedStep, settings, this.allowUserInteraction);
|
|
94
|
-
step = {
|
|
95
|
-
...comparedStep,
|
|
96
|
-
execution: step.execution,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
const { transactionRequest } = step;
|
|
100
|
-
if (!transactionRequest) {
|
|
101
|
-
throw new TransactionError(LifiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
102
|
-
}
|
|
103
|
-
// STEP 3: Send the transaction
|
|
104
|
-
// Make sure that the chain is still correct
|
|
105
|
-
const updatedSigner = await switchChain(signer, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
106
|
-
if (!updatedSigner) {
|
|
107
|
-
// Chain switch was not successful, stop execution here
|
|
108
|
-
return step.execution;
|
|
109
|
-
}
|
|
110
|
-
signer = updatedSigner;
|
|
111
|
-
process = statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED');
|
|
112
|
-
if (!this.allowUserInteraction) {
|
|
113
|
-
return step.execution;
|
|
114
|
-
}
|
|
115
|
-
if (settings.updateTransactionRequestHook) {
|
|
116
|
-
const customConfig = await settings.updateTransactionRequestHook(transactionRequest);
|
|
117
|
-
transactionRequest.gasLimit = customConfig.gasLimit;
|
|
118
|
-
transactionRequest.gasPrice = customConfig.gasPrice;
|
|
119
|
-
transactionRequest.maxPriorityFeePerGas =
|
|
120
|
-
customConfig.maxPriorityFeePerGas;
|
|
121
|
-
transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
try {
|
|
125
|
-
const estimatedGasLimit = await signer.estimateGas(transactionRequest);
|
|
126
|
-
if (estimatedGasLimit) {
|
|
127
|
-
transactionRequest.gasLimit = BigNumber.from(`${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`);
|
|
128
|
-
}
|
|
129
|
-
// Fetch latest gasPrice from provider and use it
|
|
130
|
-
const gasPrice = await signer.getGasPrice();
|
|
131
|
-
if (gasPrice) {
|
|
132
|
-
transactionRequest.gasPrice = gasPrice;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch (error) { }
|
|
136
|
-
}
|
|
137
|
-
// Submit the transaction
|
|
138
|
-
if (shouldBatchTransactions &&
|
|
139
|
-
config.multisigConfig?.sendBatchTransaction) {
|
|
140
|
-
const { to, data, value } = await signer.populateTransaction(transactionRequest);
|
|
141
|
-
const isValidTransaction = to && data;
|
|
142
|
-
if (isValidTransaction) {
|
|
143
|
-
const populatedTransaction = {
|
|
144
|
-
value: value?.toString() ?? BigNumber.from(0).toString(),
|
|
145
|
-
to,
|
|
146
|
-
data: data.toString(),
|
|
147
|
-
};
|
|
148
|
-
multisigBatchTransactions.push(populatedTransaction);
|
|
149
|
-
transaction = await config.multisigConfig?.sendBatchTransaction(multisigBatchTransactions);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
throw new TransactionError(LifiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
transaction = await signer.sendTransaction(transactionRequest);
|
|
157
|
-
}
|
|
158
|
-
// STEP 4: Wait for the transaction
|
|
159
|
-
if (isMultisigSigner) {
|
|
160
|
-
process = statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED', {
|
|
161
|
-
multisigTxHash: transaction.hash,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
process = statusManager.updateProcess(step, process.type, 'PENDING', {
|
|
166
|
-
txHash: transaction.hash,
|
|
167
|
-
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
168
|
-
'tx/' +
|
|
169
|
-
transaction.hash,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
await transaction.wait?.();
|
|
174
|
-
// if it's multisig signer and the process is in ACTION_REQUIRED
|
|
175
|
-
// then signatures are still needed
|
|
176
|
-
if (isMultisigSigner &&
|
|
177
|
-
process.status === 'ACTION_REQUIRED' &&
|
|
178
|
-
transaction.hash) {
|
|
179
|
-
// Return the execution object without updating the process
|
|
180
|
-
// The execution would progress once all multisigs signer approve
|
|
181
|
-
await updateMultisigRouteProcess(transaction.hash, step, statusManager, process, fromChain);
|
|
182
|
-
}
|
|
183
|
-
if (!isMultisigSigner) {
|
|
184
|
-
process = statusManager.updateProcess(step, process.type, 'PENDING', {
|
|
185
|
-
txHash: transaction.hash,
|
|
186
|
-
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
187
|
-
'tx/' +
|
|
188
|
-
transaction.hash,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
if (isBridgeExecution) {
|
|
192
|
-
process = statusManager.updateProcess(step, process.type, 'DONE');
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
catch (e) {
|
|
196
|
-
if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
|
|
197
|
-
process = statusManager.updateProcess(step, process.type, 'DONE', {
|
|
198
|
-
txHash: e.replacement.hash,
|
|
199
|
-
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
200
|
-
'tx/' +
|
|
201
|
-
e.replacement.hash,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
const error = await parseError(e, step, process);
|
|
206
|
-
process = statusManager.updateProcess(step, process.type, 'FAILED', {
|
|
207
|
-
error: {
|
|
208
|
-
message: error.message,
|
|
209
|
-
htmlMessage: error.htmlMessage,
|
|
210
|
-
code: error.code,
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
statusManager.updateExecution(step, 'FAILED');
|
|
214
|
-
throw error;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
// STEP 5: Wait for the receiving chain
|
|
219
|
-
const processTxHash = process.txHash;
|
|
220
|
-
if (isBridgeExecution) {
|
|
221
|
-
process = statusManager.findOrCreateProcess(step, 'RECEIVING_CHAIN', 'PENDING');
|
|
222
|
-
}
|
|
223
|
-
let statusResponse;
|
|
224
|
-
try {
|
|
225
|
-
if (!processTxHash) {
|
|
226
|
-
throw new Error('Transaction hash is undefined.');
|
|
227
|
-
}
|
|
228
|
-
statusResponse = (await waitForReceivingTransaction(processTxHash, statusManager, process.type, step));
|
|
229
|
-
const statusReceiving = statusResponse.receiving;
|
|
230
|
-
process = statusManager.updateProcess(step, process.type, 'DONE', {
|
|
231
|
-
substatus: statusResponse.substatus,
|
|
232
|
-
substatusMessage: statusResponse.substatusMessage ||
|
|
233
|
-
getSubstatusMessage(statusResponse.status, statusResponse.substatus),
|
|
234
|
-
txHash: statusReceiving?.txHash,
|
|
235
|
-
txLink: toChain.metamask.blockExplorerUrls[0] +
|
|
236
|
-
'tx/' +
|
|
237
|
-
statusReceiving?.txHash,
|
|
238
|
-
});
|
|
239
|
-
statusManager.updateExecution(step, 'DONE', {
|
|
240
|
-
fromAmount: statusResponse.sending.amount,
|
|
241
|
-
toAmount: statusReceiving?.amount,
|
|
242
|
-
toToken: statusReceiving?.token,
|
|
243
|
-
gasAmount: statusResponse.sending.gasAmount,
|
|
244
|
-
gasAmountUSD: statusResponse.sending.gasAmountUSD,
|
|
245
|
-
gasPrice: statusResponse.sending.gasPrice,
|
|
246
|
-
gasToken: statusResponse.sending.gasToken,
|
|
247
|
-
gasUsed: statusResponse.sending.gasUsed,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
catch (e) {
|
|
251
|
-
const htmlMessage = await getTransactionFailedMessage(step, process.txLink);
|
|
252
|
-
process = statusManager.updateProcess(step, process.type, 'FAILED', {
|
|
253
|
-
error: {
|
|
254
|
-
code: LifiErrorCode.TransactionFailed,
|
|
255
|
-
message: 'Failed while waiting for receiving chain.',
|
|
256
|
-
htmlMessage,
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
statusManager.updateExecution(step, 'FAILED');
|
|
260
|
-
console.warn(e);
|
|
261
|
-
throw e;
|
|
262
|
-
}
|
|
263
|
-
// DONE
|
|
264
|
-
return step.execution;
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Signer } from 'ethers';
|
|
2
|
-
import { InteractionSettings, InternalExecutionSettings, LifiStep } from '../types';
|
|
3
|
-
import { StatusManager } from './StatusManager';
|
|
4
|
-
import { StepExecutionManager } from './StepExecutionManager';
|
|
5
|
-
export declare class StepExecutor {
|
|
6
|
-
stepExecutionManager: StepExecutionManager;
|
|
7
|
-
statusManager: StatusManager;
|
|
8
|
-
settings: InternalExecutionSettings;
|
|
9
|
-
allowUserInteraction: boolean;
|
|
10
|
-
executionStopped: boolean;
|
|
11
|
-
constructor(statusManager: StatusManager, settings: InternalExecutionSettings);
|
|
12
|
-
setInteraction: (settings?: InteractionSettings) => void;
|
|
13
|
-
checkChain: () => never;
|
|
14
|
-
executeStep: (signer: Signer, step: LifiStep) => Promise<LifiStep>;
|
|
15
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { StepExecutionManager } from './StepExecutionManager';
|
|
2
|
-
import { switchChain } from './switchChain';
|
|
3
|
-
// Please be careful when changing the defaults as it may break the behavior (e.g., background execution)
|
|
4
|
-
const defaultInteractionSettings = {
|
|
5
|
-
allowInteraction: true,
|
|
6
|
-
allowUpdates: true,
|
|
7
|
-
stopExecution: false,
|
|
8
|
-
};
|
|
9
|
-
export class StepExecutor {
|
|
10
|
-
constructor(statusManager, settings) {
|
|
11
|
-
this.allowUserInteraction = true;
|
|
12
|
-
this.executionStopped = false;
|
|
13
|
-
this.setInteraction = (settings) => {
|
|
14
|
-
const interactionSettings = {
|
|
15
|
-
...defaultInteractionSettings,
|
|
16
|
-
...settings,
|
|
17
|
-
};
|
|
18
|
-
this.allowUserInteraction = interactionSettings.allowInteraction;
|
|
19
|
-
this.stepExecutionManager.allowInteraction(interactionSettings.allowInteraction);
|
|
20
|
-
this.statusManager.allowUpdates(interactionSettings.allowUpdates);
|
|
21
|
-
this.executionStopped = interactionSettings.stopExecution;
|
|
22
|
-
};
|
|
23
|
-
// TODO: add checkChain method and update signer inside executors
|
|
24
|
-
// This can come in handy when we execute multiple routes simultaneously and
|
|
25
|
-
// should be sure that we are on the right chain when waiting for transactions.
|
|
26
|
-
this.checkChain = () => {
|
|
27
|
-
throw new Error('checkChain is not implemented.');
|
|
28
|
-
};
|
|
29
|
-
this.executeStep = async (signer, step) => {
|
|
30
|
-
// Make sure that the chain is still correct
|
|
31
|
-
// Find if it's bridging and the step is waiting for a transaction on the receiving chain
|
|
32
|
-
const recievingChainProcess = step.execution?.process.find((process) => process.type === 'RECEIVING_CHAIN');
|
|
33
|
-
// If the step is waiting for a transaction on the receiving chain, we do not switch the chain
|
|
34
|
-
// All changes are already done from the source chain
|
|
35
|
-
// Return the step
|
|
36
|
-
if (recievingChainProcess?.substatus !== 'WAIT_DESTINATION_TRANSACTION' ||
|
|
37
|
-
!recievingChainProcess) {
|
|
38
|
-
const updatedSigner = await switchChain(signer, this.statusManager, step, this.settings.switchChainHook, this.allowUserInteraction);
|
|
39
|
-
if (!updatedSigner) {
|
|
40
|
-
// Chain switch was not successful, stop execution here
|
|
41
|
-
return step;
|
|
42
|
-
}
|
|
43
|
-
signer = updatedSigner;
|
|
44
|
-
}
|
|
45
|
-
const parameters = {
|
|
46
|
-
signer,
|
|
47
|
-
step,
|
|
48
|
-
settings: this.settings,
|
|
49
|
-
statusManager: this.statusManager,
|
|
50
|
-
};
|
|
51
|
-
await this.stepExecutionManager.execute(parameters);
|
|
52
|
-
return step;
|
|
53
|
-
};
|
|
54
|
-
this.stepExecutionManager = new StepExecutionManager();
|
|
55
|
-
this.statusManager = statusManager;
|
|
56
|
-
this.settings = settings;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './StatusManager';
|
package/dist/execution/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './StatusManager';
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ExtendedChain, LifiStep, Process } from '@lifi/types';
|
|
2
|
-
import { StatusManager } from '.';
|
|
3
|
-
export declare const updateMultisigRouteProcess: (internalTxHash: string, step: LifiStep, statusManager: StatusManager, process: Process, fromChain: ExtendedChain) => Promise<void>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import ConfigService from '../services/ConfigService';
|
|
2
|
-
import { LifiErrorCode, TransactionError } from '../utils/errors';
|
|
3
|
-
export const updateMultisigRouteProcess = async (internalTxHash, step, statusManager, process, fromChain) => {
|
|
4
|
-
const config = ConfigService.getInstance().getConfig();
|
|
5
|
-
if (!config.multisigConfig?.getMultisigTransactionDetails) {
|
|
6
|
-
throw new Error('"getMultisigTransactionDetails()" is missing in Multisig config.');
|
|
7
|
-
}
|
|
8
|
-
const updateIntermediateMultisigStatus = () => {
|
|
9
|
-
process = statusManager.updateProcess(step, process.type, 'PENDING');
|
|
10
|
-
};
|
|
11
|
-
const multisigStatusResponse = await config.multisigConfig?.getMultisigTransactionDetails(internalTxHash, fromChain.id, updateIntermediateMultisigStatus);
|
|
12
|
-
if (multisigStatusResponse.status === 'DONE') {
|
|
13
|
-
process = statusManager.updateProcess(step, process.type, 'PENDING', {
|
|
14
|
-
txHash: multisigStatusResponse.txHash,
|
|
15
|
-
multisigTxHash: undefined,
|
|
16
|
-
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
17
|
-
'tx/' +
|
|
18
|
-
multisigStatusResponse.txHash,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
if (multisigStatusResponse.status === 'FAILED') {
|
|
22
|
-
throw new TransactionError(LifiErrorCode.TransactionFailed, 'Multisig transaction failed.');
|
|
23
|
-
}
|
|
24
|
-
if (multisigStatusResponse.status === 'CANCELLED') {
|
|
25
|
-
throw new TransactionError(LifiErrorCode.TransactionRejected, 'Transaction was rejected by users.');
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { LifiStep } from '@lifi/types';
|
|
2
|
-
import { Signer } from 'ethers';
|
|
3
|
-
import { SwitchChainHook } from '../types';
|
|
4
|
-
import { StatusManager } from './StatusManager';
|
|
5
|
-
/**
|
|
6
|
-
* This method checks whether the signer is configured for the correct chain.
|
|
7
|
-
* If yes it returns the signer.
|
|
8
|
-
* If no and if user interaction is allowed it triggers the switchChainHook. If no user interaction is allowed it aborts.
|
|
9
|
-
*
|
|
10
|
-
* @param signer
|
|
11
|
-
* @param statusManager
|
|
12
|
-
* @param step
|
|
13
|
-
* @param switchChainHook
|
|
14
|
-
* @param allowUserInteraction
|
|
15
|
-
*/
|
|
16
|
-
export declare const switchChain: (signer: Signer, statusManager: StatusManager, step: LifiStep, switchChainHook: SwitchChainHook, allowUserInteraction: boolean) => Promise<Signer | undefined>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { LifiStep, ProcessType, Status, StatusMessage, StatusResponse, Substatus } from '@lifi/types';
|
|
2
|
-
import { StatusManager } from '..';
|
|
3
|
-
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: LifiStep): Promise<StatusResponse>;
|
|
4
|
-
export declare function getProcessMessage(type: ProcessType, status: Status): string | undefined;
|
|
5
|
-
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
|
|
6
|
-
export declare function checkStepSlippageThreshold(oldStep: LifiStep, newStep: LifiStep): boolean;
|
package/dist/execution/utils.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import ApiService from '../services/ApiService';
|
|
3
|
-
import { ServerError } from '../utils/errors';
|
|
4
|
-
import { repeatUntilDone } from '../utils/utils';
|
|
5
|
-
const TRANSACTION_HASH_OBSERVERS = {};
|
|
6
|
-
export async function waitForReceivingTransaction(txHash, statusManager, processType, step) {
|
|
7
|
-
const getStatus = () => new Promise(async (resolve, reject) => {
|
|
8
|
-
let statusResponse;
|
|
9
|
-
try {
|
|
10
|
-
statusResponse = await ApiService.getStatus({
|
|
11
|
-
bridge: step.tool,
|
|
12
|
-
fromChain: step.action.fromChainId,
|
|
13
|
-
toChain: step.action.toChainId,
|
|
14
|
-
txHash,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
console.debug('Fetching status from backend failed.', e);
|
|
19
|
-
return resolve(undefined);
|
|
20
|
-
}
|
|
21
|
-
switch (statusResponse.status) {
|
|
22
|
-
case 'DONE':
|
|
23
|
-
return resolve(statusResponse);
|
|
24
|
-
case 'PENDING':
|
|
25
|
-
statusManager?.updateProcess(step, processType, 'PENDING', {
|
|
26
|
-
substatus: statusResponse.substatus,
|
|
27
|
-
substatusMessage: statusResponse.substatusMessage ||
|
|
28
|
-
getSubstatusMessage(statusResponse.status, statusResponse.substatus),
|
|
29
|
-
txLink: statusResponse.bridgeExplorerLink,
|
|
30
|
-
});
|
|
31
|
-
return resolve(undefined);
|
|
32
|
-
case 'NOT_FOUND':
|
|
33
|
-
return resolve(undefined);
|
|
34
|
-
case 'FAILED':
|
|
35
|
-
default:
|
|
36
|
-
return reject();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
let status;
|
|
40
|
-
if (txHash in TRANSACTION_HASH_OBSERVERS) {
|
|
41
|
-
status = await TRANSACTION_HASH_OBSERVERS[txHash];
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
TRANSACTION_HASH_OBSERVERS[txHash] = repeatUntilDone(getStatus, 5000);
|
|
45
|
-
status = await TRANSACTION_HASH_OBSERVERS[txHash];
|
|
46
|
-
}
|
|
47
|
-
if (!status.receiving) {
|
|
48
|
-
throw new ServerError("Status doesn't contain receiving information.");
|
|
49
|
-
}
|
|
50
|
-
return status;
|
|
51
|
-
}
|
|
52
|
-
const processMessages = {
|
|
53
|
-
TOKEN_ALLOWANCE: {
|
|
54
|
-
STARTED: 'Setting token allowance.',
|
|
55
|
-
PENDING: 'Waiting for token allowance.',
|
|
56
|
-
DONE: 'Token allowance set.',
|
|
57
|
-
},
|
|
58
|
-
SWITCH_CHAIN: {
|
|
59
|
-
PENDING: 'Chain switch required.',
|
|
60
|
-
DONE: 'Chain switched successfully.',
|
|
61
|
-
},
|
|
62
|
-
SWAP: {
|
|
63
|
-
STARTED: 'Preparing swap transaction.',
|
|
64
|
-
ACTION_REQUIRED: 'Please sign the transaction.',
|
|
65
|
-
PENDING: 'Waiting for swap transaction.',
|
|
66
|
-
DONE: 'Swap completed.',
|
|
67
|
-
},
|
|
68
|
-
CROSS_CHAIN: {
|
|
69
|
-
STARTED: 'Preparing bridge transaction.',
|
|
70
|
-
ACTION_REQUIRED: 'Please sign the transaction.',
|
|
71
|
-
PENDING: 'Waiting for bridge transaction.',
|
|
72
|
-
DONE: 'Bridge transaction confirmed.',
|
|
73
|
-
},
|
|
74
|
-
RECEIVING_CHAIN: {
|
|
75
|
-
PENDING: 'Waiting for destination chain.',
|
|
76
|
-
DONE: 'Bridge completed.',
|
|
77
|
-
},
|
|
78
|
-
TRANSACTION: {},
|
|
79
|
-
};
|
|
80
|
-
const substatusMessages = {
|
|
81
|
-
PENDING: {
|
|
82
|
-
BRIDGE_NOT_AVAILABLE: 'Bridge communication is temporarily unavailable.',
|
|
83
|
-
CHAIN_NOT_AVAILABLE: 'RPC communication is temporarily unavailable.',
|
|
84
|
-
NOT_PROCESSABLE_REFUND_NEEDED: 'The transfer cannot be completed successfully. A refund operation is required.',
|
|
85
|
-
UNKNOWN_ERROR: 'An unexpected error occurred. Please seek assistance in the LI.FI discord server.',
|
|
86
|
-
WAIT_SOURCE_CONFIRMATIONS: 'The bridge deposit has been received. The bridge is waiting for more confirmations to start the off-chain logic.',
|
|
87
|
-
WAIT_DESTINATION_TRANSACTION: 'The bridge off-chain logic is being executed. Wait for the transaction to appear on the destination chain.',
|
|
88
|
-
},
|
|
89
|
-
DONE: {
|
|
90
|
-
PARTIAL: 'Some of the received tokens are not the requested destination tokens.',
|
|
91
|
-
REFUNDED: 'The tokens were refunded to the sender address.',
|
|
92
|
-
COMPLETED: 'The transfer is complete.',
|
|
93
|
-
},
|
|
94
|
-
FAILED: {},
|
|
95
|
-
INVALID: {},
|
|
96
|
-
NOT_FOUND: {},
|
|
97
|
-
};
|
|
98
|
-
export function getProcessMessage(type, status) {
|
|
99
|
-
const processMessage = processMessages[type][status];
|
|
100
|
-
return processMessage;
|
|
101
|
-
}
|
|
102
|
-
export function getSubstatusMessage(status, substatus) {
|
|
103
|
-
if (!substatus) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const message = substatusMessages[status][substatus];
|
|
107
|
-
return message;
|
|
108
|
-
}
|
|
109
|
-
// Used to check if changed exchange rate is in the range of slippage threshold
|
|
110
|
-
export function checkStepSlippageThreshold(oldStep, newStep) {
|
|
111
|
-
const setSlippage = new BigNumber(oldStep.action.slippage);
|
|
112
|
-
const oldEstimatedToAmount = new BigNumber(oldStep.estimate.toAmountMin);
|
|
113
|
-
const newEstimatedToAmount = new BigNumber(newStep.estimate.toAmountMin);
|
|
114
|
-
const amountDifference = oldEstimatedToAmount.minus(newEstimatedToAmount);
|
|
115
|
-
// oldEstimatedToAmount can be 0 when we use conract calls
|
|
116
|
-
let actualSlippage = new BigNumber(0);
|
|
117
|
-
if (oldEstimatedToAmount.gt(0)) {
|
|
118
|
-
actualSlippage = amountDifference.dividedBy(oldEstimatedToAmount);
|
|
119
|
-
}
|
|
120
|
-
return (newEstimatedToAmount.gte(oldEstimatedToAmount) &&
|
|
121
|
-
actualSlippage.lte(setSlippage));
|
|
122
|
-
}
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { LifiStep, Route, Token } from '@lifi/types';
|
|
2
|
-
import { TenderlyResponse } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Predefined hook that decrypts calldata using EIP-1193 compliant wallet functions.
|
|
5
|
-
* @param {string} walletAddress - The wallet address of the user that should decrypt the calldata.
|
|
6
|
-
* @return {(encryptedData: string) => Promise<any>} A function that decrypts data using EIP-1193 compliant wallet functions.
|
|
7
|
-
*/
|
|
8
|
-
export declare const getEthereumDecryptionHook: (walletAddress: string) => (encryptedData: string) => Promise<string>;
|
|
9
|
-
/**
|
|
10
|
-
* Predefined hook that get the public encryption key of a user using EIP-1193 compliant wallet functions.
|
|
11
|
-
* @param {string} walletAddress - The wallet address of the user.
|
|
12
|
-
* @return {(walletAddress: string) => () => Promise<any>} A function that return the public encryption key using EIP-1193 compliant wallet functions.
|
|
13
|
-
*/
|
|
14
|
-
export declare const getEthereumPublicKeyHook: (walletAddress: string) => () => Promise<string>;
|
|
15
|
-
/**
|
|
16
|
-
* Returns a random number between min (inclusive) and max (inclusive)
|
|
17
|
-
*/
|
|
18
|
-
export declare const getRandomNumber: (min: number, max: number) => number;
|
|
19
|
-
export declare const isSameToken: (tokenA: Token, tokenB: Token) => boolean;
|
|
20
|
-
export declare const checkPackageUpdates: (packageName?: string, packageVersion?: string, disableCheck?: boolean) => Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Converts a quote to Route
|
|
23
|
-
* @param {LifiStep} step - Step returned from the quote endpoint.
|
|
24
|
-
* @return {Route} - The route to be executed.
|
|
25
|
-
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
26
|
-
*/
|
|
27
|
-
export declare const convertQuoteToRoute: (step: LifiStep) => Route;
|
|
28
|
-
export declare const fetchTxErrorDetails: (txHash: string, chainId: number) => Promise<TenderlyResponse>;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
2
|
-
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
3
|
-
declare const _default: {
|
|
4
|
-
getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
|
|
5
|
-
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
6
|
-
getGasRecommendation: ({ chainId, fromChain, fromToken }: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
|
|
7
|
-
getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
8
|
-
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
9
|
-
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
|
-
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
|
-
getStepTransaction: (step: LifiStep, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
12
|
-
getToken: (chain: ChainId | ChainKey, token: string, options?: RequestOptions | undefined) => Promise<Token>;
|
|
13
|
-
getTokens: (requestConfig?: TokensRequest | undefined, options?: RequestOptions | undefined) => Promise<TokensResponse>;
|
|
14
|
-
getTools: (requestConfig?: ToolsRequest | undefined, options?: RequestOptions | undefined) => Promise<ToolsResponse>;
|
|
15
|
-
getAvailableConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
|
16
|
-
};
|
|
17
|
-
export default _default;
|