@rango-dev/queue-manager-rango-preset 0.53.0 → 0.53.1-next.1
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/CHANGELOG.md +9 -0
- package/dist/actions/common/checkEnvironmentBeforeExecuteTransaction.d.ts +8 -0
- package/dist/actions/common/checkEnvironmentBeforeExecuteTransaction.d.ts.map +1 -0
- package/dist/actions/common/produceNextStateForTransaction.d.ts +17 -0
- package/dist/actions/common/produceNextStateForTransaction.d.ts.map +1 -0
- package/dist/actions/common/utils.d.ts +5 -0
- package/dist/actions/common/utils.d.ts.map +1 -0
- package/dist/actions/{executeTransaction.d.ts → executeTransaction/executeTransaction.d.ts} +2 -1
- package/dist/actions/executeTransaction/executeTransaction.d.ts.map +1 -0
- package/dist/actions/executeTransaction/index.d.ts +2 -0
- package/dist/actions/executeTransaction/index.d.ts.map +1 -0
- package/dist/helpers.d.ts +7 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/queue-manager-rango-preset.build.json +1 -1
- package/package.json +2 -1
- package/src/actions/{executeTransaction.ts → common/checkEnvironmentBeforeExecuteTransaction.ts} +83 -64
- package/src/actions/common/produceNextStateForTransaction.ts +167 -0
- package/src/actions/common/utils.ts +25 -0
- package/src/actions/executeTransaction/executeTransaction.ts +107 -0
- package/src/actions/executeTransaction/index.ts +1 -0
- package/src/helpers.ts +43 -158
- package/dist/actions/executeTransaction.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/configs.ts":{"bytes":816,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":7596,"imports":[],"format":"esm"},"src/constants.ts":{"bytes":742,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/services/httpService.ts":{"bytes":284,"imports":[{"path":"rango-sdk","kind":"import-statement","external":true},{"path":"src/configs.ts","kind":"import-statement","original":"../configs"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/services/index.ts":{"bytes":45,"imports":[{"path":"src/services/httpService.ts","kind":"import-statement","original":"./httpService"}],"format":"esm"},"src/numbers.ts":{"bytes":1637,"imports":[{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/shared-errors.ts":{"bytes":4547,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/shared.ts":{"bytes":12672,"imports":[{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"src/numbers.ts","kind":"import-statement","original":"./numbers"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"./shared-errors"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/services/eventEmitter.ts":{"bytes":8276,"imports":[{"path":"src/configs.ts","kind":"import-statement","original":"../configs"},{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/shared.ts","kind":"import-statement","original":"../shared"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/helpers.ts":{"bytes":47862,"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"src/services/index.ts","kind":"import-statement","original":"./services"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"./services/eventEmitter"},{"path":"src/shared.ts","kind":"import-statement","original":"./shared"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"./shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/checkStatus.ts":{"bytes":17008,"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/services/index.ts","kind":"import-statement","original":"../services"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"src/shared.ts","kind":"import-statement","original":"../shared"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"../shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/createTransaction.ts":{"bytes":3220,"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/services/index.ts","kind":"import-statement","original":"../services"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"../shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/executeTransaction.ts":{"bytes":4510,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../constants"},{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/shared.ts","kind":"import-statement","original":"../shared"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/scheduleNextStep.ts":{"bytes":2758,"imports":[{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/start.ts":{"bytes":484,"imports":[{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/queueDef.ts":{"bytes":1523,"imports":[{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/actions/checkStatus.ts","kind":"import-statement","original":"./actions/checkStatus"},{"path":"src/actions/createTransaction.ts","kind":"import-statement","original":"./actions/createTransaction"},{"path":"src/actions/executeTransaction.ts","kind":"import-statement","original":"./actions/executeTransaction"},{"path":"src/actions/scheduleNextStep.ts","kind":"import-statement","original":"./actions/scheduleNextStep"},{"path":"src/actions/start.ts","kind":"import-statement","original":"./actions/start"},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers"}],"format":"esm"},"src/migration.ts":{"bytes":3321,"imports":[{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"uuid","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/hooks.ts":{"bytes":2290,"imports":[{"path":"@rango-dev/queue-manager-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers"},{"path":"src/migration.ts","kind":"import-statement","original":"./migration"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1522,"imports":[{"path":"src/configs.ts","kind":"import-statement","original":"./configs"},{"path":"src/queueDef.ts","kind":"import-statement","original":"./queueDef"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"./shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/shared.ts","kind":"import-statement","original":"./shared"},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers"},{"path":"src/hooks.ts","kind":"import-statement","original":"./hooks"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":181618},"dist/index.js":{"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"rango-sdk","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"uuid","kind":"import-statement","external":true}],"exports":["EventSeverity","MessageSeverity","PrettyError","RouteEventType","StepEventType","StepExecutionBlockedEventStatus","StepExecutionEventStatus","WidgetEvents","calculatePendingSwap","cancelSwap","checkWaitingForNetworkChange","getCurrentNamespaceOfOrNull","getCurrentStep","getLastSuccessfulStep","getRelatedWallet","getRelatedWalletOrNull","getRequiredWallet","getRunningSwaps","getUsdPrice","isApprovalTX","makeQueueDefinition","prettifyErrorMessage","resetRunningSwapNotifsOnPageLoad","updateSwapStatus","useMigration","useQueueManager"],"entryPoint":"src/index.ts","inputs":{"src/configs.ts":{"bytesInOutput":167},"src/types.ts":{"bytesInOutput":848},"src/actions/checkStatus.ts":{"bytesInOutput":6225},"src/helpers.ts":{"bytesInOutput":16725},"src/constants.ts":{"bytesInOutput":431},"src/services/httpService.ts":{"bytesInOutput":118},"src/services/index.ts":{"bytesInOutput":0},"src/shared.ts":{"bytesInOutput":5346},"src/numbers.ts":{"bytesInOutput":689},"src/shared-errors.ts":{"bytesInOutput":2212},"src/services/eventEmitter.ts":{"bytesInOutput":3596},"src/actions/createTransaction.ts":{"bytesInOutput":1036},"src/actions/executeTransaction.ts":{"bytesInOutput":1001},"src/actions/scheduleNextStep.ts":{"bytesInOutput":804},"src/actions/start.ts":{"bytesInOutput":155},"src/queueDef.ts":{"bytesInOutput":340},"src/index.ts":{"bytesInOutput":59},"src/hooks.ts":{"bytesInOutput":652},"src/migration.ts":{"bytesInOutput":1138}},"bytes":42299}}}
|
|
1
|
+
{"inputs":{"src/configs.ts":{"bytes":816,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":7596,"imports":[],"format":"esm"},"src/constants.ts":{"bytes":742,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/services/httpService.ts":{"bytes":284,"imports":[{"path":"rango-sdk","kind":"import-statement","external":true},{"path":"src/configs.ts","kind":"import-statement","original":"../configs"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/services/index.ts":{"bytes":45,"imports":[{"path":"src/services/httpService.ts","kind":"import-statement","original":"./httpService"}],"format":"esm"},"src/numbers.ts":{"bytes":1637,"imports":[{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/shared-errors.ts":{"bytes":4547,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/shared.ts":{"bytes":12672,"imports":[{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"src/numbers.ts","kind":"import-statement","original":"./numbers"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"./shared-errors"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/services/eventEmitter.ts":{"bytes":8276,"imports":[{"path":"src/configs.ts","kind":"import-statement","original":"../configs"},{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/shared.ts","kind":"import-statement","original":"../shared"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/helpers.ts":{"bytes":44611,"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"src/services/index.ts","kind":"import-statement","original":"./services"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"./services/eventEmitter"},{"path":"src/shared.ts","kind":"import-statement","original":"./shared"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"./shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/checkStatus.ts":{"bytes":17008,"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/services/index.ts","kind":"import-statement","original":"../services"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"src/shared.ts","kind":"import-statement","original":"../shared"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"../shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/createTransaction.ts":{"bytes":3220,"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/services/index.ts","kind":"import-statement","original":"../services"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"../shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/common/utils.ts":{"bytes":645,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/common/checkEnvironmentBeforeExecuteTransaction.ts":{"bytes":4916,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"ts-results","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../../constants"},{"path":"src/helpers.ts","kind":"import-statement","original":"../../helpers"},{"path":"src/shared.ts","kind":"import-statement","original":"../../shared"},{"path":"src/types.ts","kind":"import-statement","original":"../../types"},{"path":"src/actions/common/utils.ts","kind":"import-statement","original":"./utils"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/common/produceNextStateForTransaction.ts":{"bytes":4634,"imports":[{"path":"ts-results","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../../constants"},{"path":"src/helpers.ts","kind":"import-statement","original":"../../helpers"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../../services/eventEmitter"},{"path":"src/shared.ts","kind":"import-statement","original":"../../shared"},{"path":"src/types.ts","kind":"import-statement","original":"../../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/executeTransaction/executeTransaction.ts":{"bytes":3262,"imports":[{"path":"src/helpers.ts","kind":"import-statement","original":"../../helpers"},{"path":"src/shared.ts","kind":"import-statement","original":"../../shared"},{"path":"src/actions/common/checkEnvironmentBeforeExecuteTransaction.ts","kind":"import-statement","original":"../common/checkEnvironmentBeforeExecuteTransaction"},{"path":"src/actions/common/produceNextStateForTransaction.ts","kind":"import-statement","original":"../common/produceNextStateForTransaction"},{"path":"src/actions/common/utils.ts","kind":"import-statement","original":"../common/utils"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/executeTransaction/index.ts":{"bytes":62,"imports":[{"path":"src/actions/executeTransaction/executeTransaction.ts","kind":"import-statement","original":"./executeTransaction.js"}],"format":"esm"},"src/actions/scheduleNextStep.ts":{"bytes":2758,"imports":[{"path":"src/helpers.ts","kind":"import-statement","original":"../helpers"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/actions/start.ts":{"bytes":484,"imports":[{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"src/services/eventEmitter.ts","kind":"import-statement","original":"../services/eventEmitter"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/queueDef.ts":{"bytes":1523,"imports":[{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/actions/checkStatus.ts","kind":"import-statement","original":"./actions/checkStatus"},{"path":"src/actions/createTransaction.ts","kind":"import-statement","original":"./actions/createTransaction"},{"path":"src/actions/executeTransaction/index.ts","kind":"import-statement","original":"./actions/executeTransaction"},{"path":"src/actions/scheduleNextStep.ts","kind":"import-statement","original":"./actions/scheduleNextStep"},{"path":"src/actions/start.ts","kind":"import-statement","original":"./actions/start"},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers"}],"format":"esm"},"src/migration.ts":{"bytes":3321,"imports":[{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"uuid","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/hooks.ts":{"bytes":2290,"imports":[{"path":"@rango-dev/queue-manager-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers"},{"path":"src/migration.ts","kind":"import-statement","original":"./migration"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1522,"imports":[{"path":"src/configs.ts","kind":"import-statement","original":"./configs"},{"path":"src/queueDef.ts","kind":"import-statement","original":"./queueDef"},{"path":"src/shared-errors.ts","kind":"import-statement","original":"./shared-errors"},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/shared.ts","kind":"import-statement","original":"./shared"},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers"},{"path":"src/hooks.ts","kind":"import-statement","original":"./hooks"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":190781},"dist/index.js":{"imports":[{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"rango-sdk","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"bignumber.js","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/logging-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"ts-results","kind":"import-statement","external":true},{"path":"ts-results","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@rango-dev/queue-manager-core","kind":"import-statement","external":true},{"path":"uuid","kind":"import-statement","external":true}],"exports":["EventSeverity","MessageSeverity","PrettyError","RouteEventType","StepEventType","StepExecutionBlockedEventStatus","StepExecutionEventStatus","WidgetEvents","calculatePendingSwap","cancelSwap","checkWaitingForNetworkChange","getCurrentNamespaceOfOrNull","getCurrentStep","getLastSuccessfulStep","getRelatedWallet","getRelatedWalletOrNull","getRequiredWallet","getRunningSwaps","getUsdPrice","isApprovalTX","makeQueueDefinition","prettifyErrorMessage","resetRunningSwapNotifsOnPageLoad","updateSwapStatus","useMigration","useQueueManager"],"entryPoint":"src/index.ts","inputs":{"src/configs.ts":{"bytesInOutput":167},"src/types.ts":{"bytesInOutput":846},"src/actions/checkStatus.ts":{"bytesInOutput":6227},"src/helpers.ts":{"bytesInOutput":15354},"src/constants.ts":{"bytesInOutput":431},"src/services/httpService.ts":{"bytesInOutput":118},"src/services/index.ts":{"bytesInOutput":0},"src/shared.ts":{"bytesInOutput":5345},"src/numbers.ts":{"bytesInOutput":689},"src/shared-errors.ts":{"bytesInOutput":2212},"src/services/eventEmitter.ts":{"bytesInOutput":3594},"src/actions/createTransaction.ts":{"bytesInOutput":1035},"src/actions/common/checkEnvironmentBeforeExecuteTransaction.ts":{"bytesInOutput":1311},"src/actions/common/utils.ts":{"bytesInOutput":203},"src/actions/common/produceNextStateForTransaction.ts":{"bytesInOutput":1781},"src/actions/executeTransaction/executeTransaction.ts":{"bytesInOutput":557},"src/actions/executeTransaction/index.ts":{"bytesInOutput":0},"src/actions/scheduleNextStep.ts":{"bytesInOutput":804},"src/actions/start.ts":{"bytesInOutput":155},"src/queueDef.ts":{"bytesInOutput":340},"src/index.ts":{"bytesInOutput":59},"src/hooks.ts":{"bytesInOutput":652},"src/migration.ts":{"bytesInOutput":1138}},"bytes":43774}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/queue-manager-rango-preset",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.1-next.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@rango-dev/logging-core": "^0.11.0",
|
|
38
38
|
"rango-types": "^0.1.89",
|
|
39
|
+
"ts-results": "^3.3.0",
|
|
39
40
|
"uuid": "^9.0.0"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
package/src/actions/{executeTransaction.ts → common/checkEnvironmentBeforeExecuteTransaction.ts}
RENAMED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
SwapActionTypes,
|
|
3
|
+
SwapQueueContext,
|
|
4
|
+
SwapStorage,
|
|
5
|
+
} from '../../types';
|
|
6
|
+
import type {
|
|
7
|
+
BlockedReason,
|
|
8
|
+
ExecuterActions,
|
|
9
|
+
} from '@rango-dev/queue-manager-core';
|
|
3
10
|
|
|
4
11
|
import { PendingSwapNetworkStatus } from 'rango-types';
|
|
12
|
+
import { Err, Ok, type Result } from 'ts-results';
|
|
5
13
|
|
|
6
14
|
import {
|
|
7
15
|
ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES,
|
|
8
16
|
ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK,
|
|
9
17
|
ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION,
|
|
10
18
|
ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET,
|
|
11
|
-
} from '
|
|
19
|
+
} from '../../constants';
|
|
12
20
|
import {
|
|
13
21
|
claimQueue,
|
|
14
22
|
getCurrentStep,
|
|
@@ -17,42 +25,71 @@ import {
|
|
|
17
25
|
isNetworkMatchedForTransaction,
|
|
18
26
|
isRequiredWalletConnected,
|
|
19
27
|
isWalletNull,
|
|
20
|
-
resetNetworkStatus,
|
|
21
|
-
signTransaction,
|
|
22
28
|
updateNetworkStatus,
|
|
23
|
-
} from '
|
|
24
|
-
import { getCurrentNamespaceOf } from '
|
|
25
|
-
import { BlockReason } from '
|
|
29
|
+
} from '../../helpers';
|
|
30
|
+
import { getCurrentNamespaceOf } from '../../shared';
|
|
31
|
+
import { BlockReason } from '../../types';
|
|
32
|
+
|
|
33
|
+
import { isClaimedByCurrentQueue } from './utils';
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* This function implemented the parallel mode by `claim` mechanism which means
|
|
31
|
-
* All the queues the meet certain situation (like multiple evm transaction) will go through
|
|
32
|
-
* a `claim` mechanims that decides which queue should be run and it blocks other ones.
|
|
33
|
-
*
|
|
34
|
-
* A queue will be go to sign process, if the wallet and network is matched.
|
|
36
|
+
* Check for network & address be matched and queue to not be blocked and update the swap accordingly.
|
|
35
37
|
*/
|
|
36
|
-
export async function
|
|
38
|
+
export async function checkEnvironmentBeforeExecuteTransaction(
|
|
37
39
|
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
38
|
-
): Promise<
|
|
40
|
+
): Promise<Result<true, BlockedReason>> {
|
|
39
41
|
const { getStorage, context } = actions;
|
|
40
|
-
const { meta, wallets, providers } = context;
|
|
41
|
-
const { claimedBy } = claimQueue();
|
|
42
|
-
|
|
43
|
-
const isClaimed = context.claimedBy === context._queue?.id;
|
|
44
|
-
const requestBlock: typeof actions.block = (blockedFor) => {
|
|
45
|
-
actions.block(blockedFor);
|
|
46
|
-
if (isClaimed && actions.context.resetClaimedBy) {
|
|
47
|
-
actions.context.resetClaimedBy();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
42
|
|
|
51
43
|
const swap = getStorage().swapDetails;
|
|
52
44
|
|
|
53
45
|
const currentStep = getCurrentStep(swap)!;
|
|
54
46
|
|
|
55
47
|
/* Make sure wallet is connected and also the connected wallet is matched with tx by checking address. */
|
|
48
|
+
const addressCheckResult = ensureRequiredWalletIsConnected(actions);
|
|
49
|
+
if (addressCheckResult.err) {
|
|
50
|
+
return addressCheckResult;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Wallet should be on correct network */
|
|
54
|
+
const networkResult = await ensureWalletIsOnCorrectNetwork(actions);
|
|
55
|
+
if (networkResult.err) {
|
|
56
|
+
return networkResult;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (currentStep.networkStatus === PendingSwapNetworkStatus.NetworkChanged) {
|
|
60
|
+
// Considering that network is matched now, if currently network status of the current step is equal to `NetworkChanged`, we need to update the network status to mark it as network changed successfully.
|
|
61
|
+
updateNetworkStatus(actions, {
|
|
62
|
+
message: '',
|
|
63
|
+
details: 'The network has been successfully changed.',
|
|
64
|
+
status: PendingSwapNetworkStatus.NetworkChanged,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
*For avoiding conflict by making too many requests to wallet, we need to make sure
|
|
70
|
+
*We only run one request at a time (In parallel mode).
|
|
71
|
+
*/
|
|
72
|
+
const needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
|
|
73
|
+
const isClaimed = isClaimedByCurrentQueue(context);
|
|
74
|
+
if (needsToBlockQueue && !isClaimed) {
|
|
75
|
+
const blockedFor = {
|
|
76
|
+
reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
|
|
77
|
+
description: ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES,
|
|
78
|
+
details: {},
|
|
79
|
+
};
|
|
80
|
+
return new Err(blockedFor);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return new Ok(true);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function ensureRequiredWalletIsConnected(
|
|
87
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
88
|
+
): Result<true, BlockedReason> {
|
|
89
|
+
const { getStorage, context } = actions;
|
|
90
|
+
const { wallets } = context;
|
|
91
|
+
const swap = getStorage().swapDetails;
|
|
92
|
+
|
|
56
93
|
const isWrongAddress = !isRequiredWalletConnected(swap, context.state).ok;
|
|
57
94
|
if (isWrongAddress) {
|
|
58
95
|
const { type, address } = getRequiredWallet(swap);
|
|
@@ -68,11 +105,20 @@ export async function executeTransaction(
|
|
|
68
105
|
reason: BlockReason.WAIT_FOR_CONNECT_WALLET,
|
|
69
106
|
description,
|
|
70
107
|
};
|
|
71
|
-
|
|
72
|
-
return;
|
|
108
|
+
return new Err(blockedFor);
|
|
73
109
|
}
|
|
74
110
|
|
|
75
|
-
|
|
111
|
+
return new Ok(true);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function ensureWalletIsOnCorrectNetwork(
|
|
115
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
116
|
+
): Promise<Result<true, BlockedReason>> {
|
|
117
|
+
const { getStorage, context } = actions;
|
|
118
|
+
const { meta, wallets, providers } = context;
|
|
119
|
+
const swap = getStorage().swapDetails;
|
|
120
|
+
const currentStep = getCurrentStep(swap)!;
|
|
121
|
+
|
|
76
122
|
const networkMatched = await isNetworkMatchedForTransaction(
|
|
77
123
|
swap,
|
|
78
124
|
currentStep,
|
|
@@ -80,8 +126,11 @@ export async function executeTransaction(
|
|
|
80
126
|
meta,
|
|
81
127
|
providers
|
|
82
128
|
);
|
|
129
|
+
|
|
130
|
+
const { claimedBy } = claimQueue();
|
|
83
131
|
const claimerId = claimedBy();
|
|
84
|
-
const isClaimedByAnyQueue = !!claimerId && !
|
|
132
|
+
const isClaimedByAnyQueue = !!claimerId && !isClaimedByCurrentQueue(context);
|
|
133
|
+
|
|
85
134
|
if (isClaimedByAnyQueue && !networkMatched) {
|
|
86
135
|
const details = ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES;
|
|
87
136
|
|
|
@@ -89,8 +138,7 @@ export async function executeTransaction(
|
|
|
89
138
|
reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
|
|
90
139
|
details: details,
|
|
91
140
|
};
|
|
92
|
-
|
|
93
|
-
return;
|
|
141
|
+
return new Err(blockedFor);
|
|
94
142
|
} else if (!networkMatched) {
|
|
95
143
|
const fromNamespace = getCurrentNamespaceOf(swap, currentStep);
|
|
96
144
|
const details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(
|
|
@@ -101,37 +149,8 @@ export async function executeTransaction(
|
|
|
101
149
|
reason: BlockReason.WAIT_FOR_NETWORK_CHANGE,
|
|
102
150
|
details: details,
|
|
103
151
|
};
|
|
104
|
-
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (currentStep.networkStatus === PendingSwapNetworkStatus.NetworkChanged) {
|
|
109
|
-
// Considering that network is matched now, if currently network status of the current step is equal to `NetworkChanged`, we need to update the network status to mark it as network changed successfully.
|
|
110
|
-
updateNetworkStatus(actions, {
|
|
111
|
-
message: '',
|
|
112
|
-
details: 'The network has been successfully changed.',
|
|
113
|
-
status: PendingSwapNetworkStatus.NetworkChanged,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/*
|
|
118
|
-
*For avoiding conflict by making too many requests to wallet, we need to make sure
|
|
119
|
-
*We only run one request at a time (In parallel mode).
|
|
120
|
-
*/
|
|
121
|
-
const needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
|
|
122
|
-
|
|
123
|
-
if (needsToBlockQueue && !isClaimed) {
|
|
124
|
-
const blockedFor = {
|
|
125
|
-
reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
|
|
126
|
-
description: ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES,
|
|
127
|
-
details: {},
|
|
128
|
-
};
|
|
129
|
-
requestBlock(blockedFor);
|
|
130
|
-
return;
|
|
152
|
+
return new Err(blockedFor);
|
|
131
153
|
}
|
|
132
154
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// All the conditions are met. We can safely send the tx to wallet for sign.
|
|
136
|
-
await signTransaction(actions);
|
|
155
|
+
return new Ok(true);
|
|
137
156
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
2
|
+
import type {
|
|
3
|
+
APIErrorCode,
|
|
4
|
+
SignerErrorCode,
|
|
5
|
+
StepStatus,
|
|
6
|
+
SwapStatus,
|
|
7
|
+
} from 'rango-types';
|
|
8
|
+
|
|
9
|
+
import { Err, Ok, type Result } from 'ts-results';
|
|
10
|
+
|
|
11
|
+
import { DEFAULT_ERROR_CODE } from '../../constants';
|
|
12
|
+
import {
|
|
13
|
+
getCurrentStep,
|
|
14
|
+
getCurrentStepTx,
|
|
15
|
+
getLastFinishedStepInput,
|
|
16
|
+
getLastFinishedStepInputUsd,
|
|
17
|
+
isApprovalCurrentStepTx,
|
|
18
|
+
updateSwapStatus,
|
|
19
|
+
} from '../../helpers';
|
|
20
|
+
import { notifier } from '../../services/eventEmitter';
|
|
21
|
+
import { getRelatedWallet } from '../../shared';
|
|
22
|
+
import {
|
|
23
|
+
StepEventType,
|
|
24
|
+
StepExecutionEventStatus,
|
|
25
|
+
type SwapActionTypes,
|
|
26
|
+
type SwapQueueContext,
|
|
27
|
+
type SwapStorage,
|
|
28
|
+
} from '../../types';
|
|
29
|
+
|
|
30
|
+
export interface NextTransactionState {
|
|
31
|
+
nextStatus?: SwapStatus;
|
|
32
|
+
nextStepStatus: StepStatus;
|
|
33
|
+
|
|
34
|
+
message: string;
|
|
35
|
+
details?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface NextTransactionStateError extends NextTransactionState {
|
|
39
|
+
errorCode: APIErrorCode | SignerErrorCode | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function produceNextStateForTransaction(
|
|
43
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
44
|
+
): Result<NextTransactionState, NextTransactionStateError> {
|
|
45
|
+
const { getStorage, context } = actions;
|
|
46
|
+
const { isMobileWallet } = context;
|
|
47
|
+
const swap = getStorage().swapDetails;
|
|
48
|
+
|
|
49
|
+
const currentStep = getCurrentStep(swap)!;
|
|
50
|
+
|
|
51
|
+
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
52
|
+
const mobileWallet = isMobileWallet(sourceWallet?.walletType);
|
|
53
|
+
const tx = getCurrentStepTx(currentStep);
|
|
54
|
+
const isApproval = isApprovalCurrentStepTx(currentStep);
|
|
55
|
+
|
|
56
|
+
if (!tx || !tx.type) {
|
|
57
|
+
return new Err({
|
|
58
|
+
nextStatus: 'failed',
|
|
59
|
+
nextStepStatus: 'failed',
|
|
60
|
+
message: 'Unexpected Error: tx is null!',
|
|
61
|
+
details: undefined,
|
|
62
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const hasAlreadyProceededToSign =
|
|
67
|
+
typeof swap.hasAlreadyProceededToSign === 'boolean';
|
|
68
|
+
|
|
69
|
+
if (isApproval) {
|
|
70
|
+
return new Ok({
|
|
71
|
+
nextStatus: undefined,
|
|
72
|
+
nextStepStatus: 'waitingForApproval',
|
|
73
|
+
details:
|
|
74
|
+
'Waiting for approve transaction to be mined and confirmed successfully',
|
|
75
|
+
message: `Waiting for approval of ${currentStep?.fromSymbol} coin ${
|
|
76
|
+
mobileWallet ? 'on your mobile phone!' : ''
|
|
77
|
+
}`,
|
|
78
|
+
});
|
|
79
|
+
} else if (hasAlreadyProceededToSign) {
|
|
80
|
+
return new Err({
|
|
81
|
+
message: 'Transaction is expired. Please try again.',
|
|
82
|
+
nextStepStatus: 'failed',
|
|
83
|
+
nextStatus: 'failed',
|
|
84
|
+
details: '',
|
|
85
|
+
errorCode: 'TX_EXPIRED',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return new Ok({
|
|
90
|
+
message: 'Executing transaction ...',
|
|
91
|
+
nextStepStatus: 'running',
|
|
92
|
+
nextStatus: 'running',
|
|
93
|
+
details: `${mobileWallet ? 'Check your mobile phone!' : ''}`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function onNextStateError(
|
|
98
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>,
|
|
99
|
+
error: NextTransactionStateError
|
|
100
|
+
) {
|
|
101
|
+
const { getStorage, setStorage } = actions;
|
|
102
|
+
const swap = getStorage().swapDetails;
|
|
103
|
+
const currentStep = getCurrentStep(swap)!;
|
|
104
|
+
const isApproval = isApprovalCurrentStepTx(currentStep);
|
|
105
|
+
|
|
106
|
+
const hasAlreadyProceededToSign =
|
|
107
|
+
typeof swap.hasAlreadyProceededToSign === 'boolean';
|
|
108
|
+
|
|
109
|
+
const updatedResult = updateSwapStatus({
|
|
110
|
+
getStorage,
|
|
111
|
+
setStorage,
|
|
112
|
+
|
|
113
|
+
nextStepStatus: error.nextStepStatus,
|
|
114
|
+
nextStatus: error.nextStatus,
|
|
115
|
+
message: error.message,
|
|
116
|
+
details: error.details,
|
|
117
|
+
errorCode: error.errorCode,
|
|
118
|
+
|
|
119
|
+
hasAlreadyProceededToSign: isApproval
|
|
120
|
+
? undefined
|
|
121
|
+
: hasAlreadyProceededToSign,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
notifier({
|
|
125
|
+
event: {
|
|
126
|
+
type: StepEventType.FAILED,
|
|
127
|
+
reason: error.message,
|
|
128
|
+
reasonCode: updatedResult.failureType ?? DEFAULT_ERROR_CODE,
|
|
129
|
+
inputAmount: getLastFinishedStepInput(swap),
|
|
130
|
+
inputAmountUsd: getLastFinishedStepInputUsd(swap),
|
|
131
|
+
},
|
|
132
|
+
...updatedResult,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function onNextStateOk(
|
|
137
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>,
|
|
138
|
+
ok: NextTransactionState
|
|
139
|
+
) {
|
|
140
|
+
const { getStorage, setStorage } = actions;
|
|
141
|
+
const swap = getStorage().swapDetails;
|
|
142
|
+
const currentStep = getCurrentStep(swap)!;
|
|
143
|
+
const isApproval = isApprovalCurrentStepTx(currentStep);
|
|
144
|
+
|
|
145
|
+
const hasAlreadyProceededToSign =
|
|
146
|
+
typeof swap.hasAlreadyProceededToSign === 'boolean';
|
|
147
|
+
|
|
148
|
+
const updateResult = updateSwapStatus({
|
|
149
|
+
getStorage,
|
|
150
|
+
setStorage,
|
|
151
|
+
nextStepStatus: ok.nextStepStatus,
|
|
152
|
+
nextStatus: ok.nextStatus,
|
|
153
|
+
message: ok.message,
|
|
154
|
+
details: ok.details,
|
|
155
|
+
hasAlreadyProceededToSign: isApproval
|
|
156
|
+
? undefined
|
|
157
|
+
: hasAlreadyProceededToSign,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
notifier({
|
|
161
|
+
event: {
|
|
162
|
+
type: StepEventType.TX_EXECUTION,
|
|
163
|
+
status: StepExecutionEventStatus.SEND_TX,
|
|
164
|
+
},
|
|
165
|
+
...updateResult,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SwapActionTypes,
|
|
3
|
+
SwapQueueContext,
|
|
4
|
+
SwapStorage,
|
|
5
|
+
} from '../../types';
|
|
6
|
+
import type {
|
|
7
|
+
BlockedReason,
|
|
8
|
+
ExecuterActions,
|
|
9
|
+
} from '@rango-dev/queue-manager-core';
|
|
10
|
+
|
|
11
|
+
export function isClaimedByCurrentQueue(context: SwapQueueContext): boolean {
|
|
12
|
+
return context.claimedBy === context._queue?.id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function requestBlockQueue(
|
|
16
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>,
|
|
17
|
+
blockedFor: BlockedReason
|
|
18
|
+
) {
|
|
19
|
+
actions.block(blockedFor);
|
|
20
|
+
|
|
21
|
+
const isClaimed = isClaimedByCurrentQueue(actions.context);
|
|
22
|
+
if (isClaimed && actions.context.resetClaimedBy) {
|
|
23
|
+
actions.context.resetClaimedBy();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SwapActionTypes,
|
|
3
|
+
SwapQueueContext,
|
|
4
|
+
SwapStorage,
|
|
5
|
+
} from '../../types';
|
|
6
|
+
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
7
|
+
import type { SignerFactory } from 'rango-types';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
getCurrentStep,
|
|
11
|
+
getCurrentStepTx,
|
|
12
|
+
handleRejectedSign,
|
|
13
|
+
handleSuccessfulSign,
|
|
14
|
+
isApprovalCurrentStepTx,
|
|
15
|
+
resetNetworkStatus,
|
|
16
|
+
} from '../../helpers';
|
|
17
|
+
import { getCurrentAddressOf, getRelatedWallet } from '../../shared';
|
|
18
|
+
import { checkEnvironmentBeforeExecuteTransaction } from '../common/checkEnvironmentBeforeExecuteTransaction';
|
|
19
|
+
import {
|
|
20
|
+
onNextStateError,
|
|
21
|
+
onNextStateOk,
|
|
22
|
+
produceNextStateForTransaction,
|
|
23
|
+
} from '../common/produceNextStateForTransaction';
|
|
24
|
+
import { requestBlockQueue } from '../common/utils';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* Excecute a created transaction.
|
|
29
|
+
*
|
|
30
|
+
* This function implemented the parallel mode by `claim` mechanism which means
|
|
31
|
+
* All the queues the meet certain situation (like multiple evm transaction) will go through
|
|
32
|
+
* a `claim` mechanims that decides which queue should be run and it blocks other ones.
|
|
33
|
+
*
|
|
34
|
+
* A queue will be go to sign process, if the wallet and network is matched.
|
|
35
|
+
*/
|
|
36
|
+
export async function executeTransaction(
|
|
37
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const checkResult = await checkEnvironmentBeforeExecuteTransaction(actions);
|
|
40
|
+
if (checkResult.err) {
|
|
41
|
+
requestBlockQueue(actions, checkResult.val);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
resetNetworkStatus(actions);
|
|
46
|
+
|
|
47
|
+
// All the conditions are met. We can safely send the tx to wallet for sign.
|
|
48
|
+
const { failed, getStorage, context } = actions;
|
|
49
|
+
const { meta, getSigners } = context;
|
|
50
|
+
|
|
51
|
+
const swap = getStorage().swapDetails;
|
|
52
|
+
const currentStep = getCurrentStep(swap)!;
|
|
53
|
+
const isApproval = isApprovalCurrentStepTx(currentStep);
|
|
54
|
+
|
|
55
|
+
const onFinish = () => {
|
|
56
|
+
// TODO resetClaimedBy is undefined here
|
|
57
|
+
if (actions.context.resetClaimedBy) {
|
|
58
|
+
actions.context.resetClaimedBy();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* Checking the current transaction state to determine the next step.
|
|
64
|
+
* It will either be Err, indicating process should stop, or Ok, indicating process should continu.
|
|
65
|
+
*/
|
|
66
|
+
const nextStateResult = produceNextStateForTransaction(actions);
|
|
67
|
+
|
|
68
|
+
if (nextStateResult.err) {
|
|
69
|
+
onNextStateError(actions, nextStateResult.val);
|
|
70
|
+
failed();
|
|
71
|
+
onFinish();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// On sucess, we should update Swap object and also call notifier
|
|
76
|
+
onNextStateOk(actions, nextStateResult.val);
|
|
77
|
+
|
|
78
|
+
// when we are producing next step, it will check to tx shouldn't be null. So ! here is safe.
|
|
79
|
+
const tx = getCurrentStepTx(currentStep)!;
|
|
80
|
+
|
|
81
|
+
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
82
|
+
const walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
83
|
+
|
|
84
|
+
const chainId = meta.blockchains?.[tx.blockChain]?.chainId;
|
|
85
|
+
|
|
86
|
+
let walletSigners: SignerFactory;
|
|
87
|
+
try {
|
|
88
|
+
walletSigners = await getSigners(sourceWallet.walletType);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
handleRejectedSign(actions)(error);
|
|
91
|
+
onFinish();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const signer = walletSigners.getSigner(tx.type);
|
|
96
|
+
await signer
|
|
97
|
+
.signAndSendTx(tx, walletAddress, chainId)
|
|
98
|
+
.then(
|
|
99
|
+
handleSuccessfulSign(actions, {
|
|
100
|
+
isApproval,
|
|
101
|
+
}),
|
|
102
|
+
handleRejectedSign(actions)
|
|
103
|
+
)
|
|
104
|
+
.finally(() => {
|
|
105
|
+
onFinish();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { executeTransaction } from './executeTransaction.js';
|