@deeeed/metamask-harness 0.47.4 → 0.49.0
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 +12 -0
- package/README.md +3 -2
- package/adapters/extension/lib/macos-focus.cjs +2 -2
- package/adapters/extension/live.sh +6 -8
- package/adapters/mobile/bridge-runtime/lib/bridge-errors.cjs +1 -0
- package/adapters/shared/ensure-runner-deps.sh +6 -0
- package/dist/adapters/extension/runtime-decision.js +18 -1
- package/dist/adapters/extension/runtime.js +5 -5
- package/dist/adapters/extension/surface.js +1 -0
- package/dist/app-lifecycle.js +3 -1
- package/dist/command-contract.js +2 -0
- package/dist/commands/call.js +1 -8
- package/dist/commands/device-target.js +12 -3
- package/dist/commands/doctor.js +7 -5
- package/dist/commands/fixtures.js +1 -1
- package/dist/commands/help.js +17 -5
- package/dist/commands/launch/index.js +10 -0
- package/dist/commands/manifest.js +3 -1
- package/dist/commands/mobile-device-view.js +13 -3
- package/dist/commands/parse-args.js +2 -0
- package/dist/commands/run-engine.js +29 -4
- package/dist/commands/run.js +1 -1
- package/dist/commands/runtime-launch.js +10 -1
- package/dist/commands/status.js +8 -4
- package/dist/devices.js +31 -9
- package/dist/execution-provenance.js +8 -7
- package/dist/funding-execution-context.js +62 -17
- package/dist/heal-bounds.js +3 -3
- package/dist/live-adapter-contract.js +4 -0
- package/dist/manifest.js +2 -13
- package/dist/metamask-action-validation.js +3 -2
- package/dist/mm-harness-cli.js +4 -2
- package/dist/runner.js +14 -3
- package/docs/RECIPES.md +135 -24
- package/docs/RELEASE-QA-CAPABILITY-MAP.md +3 -2
- package/library/actions/core/perps/_controller.mjs +24 -24
- package/library/actions/core/perps/assert_orders.mjs +3 -5
- package/library/actions/core/perps/assert_positions.mjs +3 -5
- package/library/actions/core/perps/close_orders.mjs +39 -19
- package/library/actions/core/perps/close_positions.mjs +53 -12
- package/library/actions/core/perps/edit_order.mjs +2 -0
- package/library/actions/core/perps/ensure_orders.mjs +3 -4
- package/library/actions/core/perps/ensure_positions.mjs +4 -5
- package/library/actions/core/perps/place_order.mjs +7 -14
- package/library/actions/core/perps/read_account.mjs +2 -0
- package/library/actions/core/perps/read_orders.mjs +2 -0
- package/library/actions/core/perps/read_positions.mjs +3 -1
- package/library/actions/core/perps/read_snapshot.mjs +3 -0
- package/library/actions/core/perps/start_state.mjs +3 -14
- package/library/actions/core/perps/teardown_state.mjs +3 -14
- package/library/actions/core/perps/update_position_tpsl.mjs +13 -19
- package/library/actions/core/wallet/list_accounts.mjs +3 -0
- package/library/actions/extension/analytics/consent.mjs +2 -0
- package/library/actions/extension/analytics/set_consent.mjs +2 -0
- package/library/actions/extension/assets/home-token-identity.mjs +31 -0
- package/library/actions/extension/assets/import_custom_token.mjs +63 -79
- package/library/actions/extension/assets/open_details.mjs +19 -7
- package/library/actions/extension/assets/prepare_send.mjs +1 -0
- package/library/actions/extension/assets/read_details.mjs +62 -29
- package/library/actions/extension/assets/read_visible_state.mjs +5 -1
- package/library/actions/extension/assets/review_send.mjs +1 -0
- package/library/actions/extension/assets/select_network_scope.mjs +17 -9
- package/library/actions/extension/assets/send.mjs +2 -0
- package/library/actions/extension/assets/set_custom_gas.mjs +1 -0
- package/library/actions/extension/assets/set_token_visibility.mjs +86 -17
- package/library/actions/extension/assets/verify_sorting.mjs +63 -14
- package/library/actions/extension/deeplink/open.mjs +1 -0
- package/library/actions/extension/networks/add_chainlist.mjs +2 -0
- package/library/actions/extension/networks/add_custom.mjs +21 -17
- package/library/actions/extension/networks/custom_network.mjs +10 -3
- package/library/actions/extension/networks/read_visible_state.mjs +2 -0
- package/library/actions/extension/networks/remove_custom.mjs +1 -0
- package/library/actions/extension/performance/_navigation-memory.mjs +37 -6
- package/library/actions/extension/performance/compare_idle_navigation_memory.mjs +5 -2
- package/library/actions/extension/performance/measure_detached_dom.mjs +5 -2
- package/library/actions/extension/performance/measure_navigation_memory.mjs +5 -2
- package/library/actions/extension/perps/assert_orders.mjs +1 -0
- package/library/actions/extension/perps/assert_positions.mjs +1 -0
- package/library/actions/extension/perps/assert_visible_consistency.mjs +11 -4
- package/library/actions/extension/perps/close_orders.mjs +4 -1
- package/library/actions/extension/perps/close_positions.mjs +1 -0
- package/library/actions/extension/perps/close_visible_position.mjs +160 -11
- package/library/actions/extension/perps/compare_provider_market.mjs +2 -0
- package/library/actions/extension/perps/edit_margin.mjs +3 -1
- package/library/actions/extension/perps/ensure_orders.mjs +1 -0
- package/library/actions/extension/perps/ensure_positions.mjs +1 -0
- package/library/actions/extension/perps/mutation-receipt.mjs +54 -3
- package/library/actions/extension/perps/open_balance_action.mjs +17 -7
- package/library/actions/extension/perps/open_position_action.mjs +1 -0
- package/library/actions/extension/perps/perps.mjs +550 -69
- package/library/actions/extension/perps/place_order.mjs +1 -0
- package/library/actions/extension/perps/read_eligibility.mjs +1 -0
- package/library/actions/extension/perps/read_funds_confirmation.mjs +10 -0
- package/library/actions/extension/perps/read_orders.mjs +1 -0
- package/library/actions/extension/perps/read_positions.mjs +1 -0
- package/library/actions/extension/perps/read_snapshot.mjs +4 -1
- package/library/actions/extension/perps/read_visible_state.mjs +12 -6
- package/library/actions/extension/perps/search_markets.mjs +8 -2
- package/library/actions/extension/perps/select_activity_filter.mjs +2 -1
- package/library/actions/extension/perps/select_market_filter.mjs +75 -45
- package/library/actions/extension/perps/set_market_favorite.mjs +7 -3
- package/library/actions/extension/perps/state.mjs +2 -0
- package/library/actions/extension/perps/update_position_tpsl.mjs +3 -1
- package/library/actions/extension/perps/visible-mutation-identity.mjs +6 -2
- package/library/actions/extension/platform/cdp.mjs +50 -142
- package/library/actions/extension/settings/set_basic_functionality.mjs +1 -0
- package/library/actions/extension/swap_bridge/quote-state.mjs +56 -0
- package/library/actions/extension/swap_bridge/read_visible_state.mjs +5 -1
- package/library/actions/extension/swap_bridge/select_assets.mjs +12 -1
- package/library/actions/extension/swap_bridge/set_amount.mjs +11 -8
- package/library/actions/extension/swap_bridge/set_max_amount.mjs +18 -18
- package/library/actions/extension/swap_bridge/set_slippage.mjs +1 -9
- package/library/actions/extension/ui/locators.mjs +1 -0
- package/library/actions/extension/ui/navigate.mjs +60 -14
- package/library/actions/extension/wallet/ensure_unlocked.mjs +2 -0
- package/library/actions/extension/wallet/import.mjs +2 -0
- package/library/actions/extension/wallet/list_accounts.mjs +1 -0
- package/library/actions/extension/wallet/lock.mjs +4 -1
- package/library/actions/extension/wallet/read_state.mjs +1 -0
- package/library/actions/extension/wallet/reset.mjs +2 -0
- package/library/actions/extension/wallet/secret-input.mjs +2 -0
- package/library/actions/extension/wallet/select_account.mjs +2 -0
- package/library/actions/extension/wallet/setup.mjs +1 -0
- package/library/actions/extension/wallet/state.mjs +2 -0
- package/library/actions/extension/wallet/visible-session.mjs +2 -0
- package/library/actions/mobile/analytics/consent-settings.mjs +1 -0
- package/library/actions/mobile/analytics/set_consent.mjs +1 -0
- package/library/actions/mobile/app/network-control.mjs +2 -0
- package/library/actions/mobile/app/network.mjs +1 -0
- package/library/actions/mobile/app/network_assert.mjs +1 -0
- package/library/actions/mobile/app/network_capture.mjs +1 -0
- package/library/actions/mobile/assets/import_custom_token.mjs +3 -0
- package/library/actions/mobile/assets/open_details.mjs +1 -0
- package/library/actions/mobile/assets/read_details.mjs +1 -0
- package/library/actions/mobile/assets/read_visible_state.mjs +4 -1
- package/library/actions/mobile/assets/set_token_visibility.mjs +15 -9
- package/library/actions/mobile/assets/verify_sorting.mjs +90 -7
- package/library/actions/mobile/deeplink/open.mjs +1 -0
- package/library/actions/mobile/networks/add_custom.mjs +1 -0
- package/library/actions/mobile/networks/network-management.mjs +23 -15
- package/library/actions/mobile/networks/read_visible_state.mjs +1 -0
- package/library/actions/mobile/networks/remove_custom.mjs +7 -2
- package/library/actions/mobile/perps/assert_orders.mjs +1 -0
- package/library/actions/mobile/perps/assert_positions.mjs +1 -0
- package/library/actions/mobile/perps/capture_performance.mjs +1 -0
- package/library/actions/mobile/perps/close_orders.mjs +1 -0
- package/library/actions/mobile/perps/close_positions.mjs +1 -0
- package/library/actions/mobile/perps/ensure_orders.mjs +1 -0
- package/library/actions/mobile/perps/ensure_positions.mjs +1 -0
- package/library/actions/mobile/perps/measure_homepage_visible.mjs +1 -0
- package/library/actions/mobile/perps/performance-capture.mjs +2 -0
- package/library/actions/mobile/perps/perps.mjs +8 -1
- package/library/actions/mobile/perps/place_order.mjs +1 -0
- package/library/actions/mobile/perps/prepare_local_snapshot_endpoint.mjs +2 -0
- package/library/actions/mobile/perps/read-visible-state-loop.mjs +3 -0
- package/library/actions/mobile/perps/read_orders.mjs +1 -0
- package/library/actions/mobile/perps/read_positions.mjs +1 -0
- package/library/actions/mobile/perps/read_visible_state.mjs +1 -0
- package/library/actions/mobile/perps/search_markets.mjs +1 -0
- package/library/actions/mobile/perps/set_market_favorite.mjs +17 -19
- package/library/actions/mobile/platform/bridge.mjs +16 -4
- package/library/actions/mobile/platform/native-session-name.mjs +1 -0
- package/library/actions/mobile/platform/native-session.mjs +28 -17
- package/library/actions/mobile/platform/observe-ui.mjs +4 -2
- package/library/actions/mobile/platform/tool-paths.mjs +1 -0
- package/library/actions/mobile/swap_bridge/native-session.mjs +1 -0
- package/library/actions/mobile/swap_bridge/read_visible_state.mjs +1 -0
- package/library/actions/mobile/swap_bridge/select_assets.mjs +2 -0
- package/library/actions/mobile/swap_bridge/set_amount.mjs +1 -0
- package/library/actions/mobile/swap_bridge/set_max_amount.mjs +1 -0
- package/library/actions/mobile/swap_bridge/set_slippage.mjs +1 -0
- package/library/actions/mobile/swap_bridge/submit_transaction.mjs +2 -0
- package/library/actions/mobile/ui/locators.mjs +1 -0
- package/library/actions/mobile/ui/native-navigation.mjs +2 -0
- package/library/actions/mobile/ui/navigate.mjs +3 -1
- package/library/actions/mobile/wallet/ensure_unlocked.mjs +2 -0
- package/library/actions/mobile/wallet/home.mjs +1 -0
- package/library/actions/mobile/wallet/import.mjs +2 -0
- package/library/actions/mobile/wallet/list_accounts.mjs +1 -0
- package/library/actions/mobile/wallet/lock.mjs +1 -0
- package/library/actions/mobile/wallet/native-ui.mjs +2 -0
- package/library/actions/mobile/wallet/read_state.mjs +2 -0
- package/library/actions/mobile/wallet/reset-helper.mjs +1 -0
- package/library/actions/mobile/wallet/reset.mjs +1 -0
- package/library/actions/mobile/wallet/select_account.mjs +2 -0
- package/library/actions/mobile/wallet/setup.mjs +2 -0
- package/library/actions/shared/analytics/assert_events.mjs +3 -0
- package/library/actions/shared/analytics/consent.mjs +3 -0
- package/library/actions/shared/analytics/read_events.mjs +2 -0
- package/library/actions/shared/analytics/start_capture.mjs +3 -0
- package/library/actions/shared/app/network-artifact.mjs +2 -0
- package/library/actions/shared/app/network-assert.mjs +2 -0
- package/library/actions/shared/assets/visible-state.mjs +2 -0
- package/library/actions/shared/deeplink/url.mjs +3 -0
- package/library/actions/shared/networks/visible-state.mjs +2 -0
- package/library/actions/shared/perps/visible-state.mjs +16 -3
- package/library/actions/shared/swap-bridge/transaction.mjs +3 -0
- package/library/actions/shared/swap-bridge/visible-state.mjs +2 -0
- package/library/actions/shared/ui/locators.mjs +2 -0
- package/library/actions/shared/wallet/import-source.mjs +3 -0
- package/library/manifests/core.action-manifest.json +34 -2
- package/library/manifests/extension.action-manifest.json +50 -17
- package/library/manifests/mobile.action-manifest.json +11 -10
- package/library/recipes/core/perps/smoke.recipe.json +23 -0
- package/library/recipes/core/perps/snapshot.recipe.json +26 -1
- package/library/recipes/extension/assets/release-custom-network-token-persistence.recipe.json +25 -8
- package/library/recipes/extension/performance/navigation-memory-suite.recipe.json +219 -0
- package/library/recipes/extension/performance/navigation-memory.recipe.json +61 -156
- package/library/recipes/extension/wallet/smoke.recipe.json +17 -8
- package/library/recipes/mobile/app/lifecycle-smoke.recipe.json +89 -0
- package/library/recipes/mobile/networks/release-custom-network-persistence.recipe.json +31 -6
- package/library/recipes/mobile/networks/release-multichain-visibility.recipe.json +5 -4
- package/library/recipes/mobile/wallet/smoke.recipe.json +17 -8
- package/library/recipes/{assets → shared/assets}/release-token-address-import.recipe.json +7 -0
- package/library/recipes/{assets → shared/assets}/release-token-details.recipe.json +2 -2
- package/library/recipes/shared/assets/release-token-hide-readd.recipe.json +91 -0
- package/library/recipes/{assets → shared/assets}/release-token-persistence.recipe.json +3 -0
- package/library/recipes/{assets → shared/assets}/release-token-search-import.recipe.json +4 -1
- package/library/recipes/{assets → shared/assets}/release-token-sorting.recipe.json +13 -2
- package/library/recipes/{swap-bridge → shared/swap-bridge}/release-quote.recipe.json +29 -3
- package/package.json +3 -3
- package/site/assets/help-recipes.json +220 -27
- package/library/recipes/assets/release-token-hide-readd.recipe.json +0 -57
- package/library/recipes/core/perps/clean-market-testnet.recipe.json +0 -44
- package/library/recipes/core/perps/order-lifecycle.recipe.json +0 -82
- package/library/recipes/core/perps/read-markets.recipe.json +0 -36
- package/library/recipes/core/perps/trading-lifecycle.recipe.json +0 -80
- package/library/recipes/extension/perps/release-activity-filters.recipe.json +0 -51
- package/library/recipes/extension/perps/release-funds-flows.recipe.json +0 -76
- package/library/recipes/extension/perps/release-live-limit-order.recipe.json +0 -109
- package/library/recipes/extension/perps/release-market-filters.recipe.json +0 -97
- package/library/recipes/extension/perps/release-order-entry.recipe.json +0 -158
- package/library/recipes/extension/perps/release-order-validation.recipe.json +0 -259
- package/library/recipes/extension/perps/release-visible-consistency.recipe.json +0 -47
- package/library/recipes/extension/perps/source-dev-snapshot-consistency.recipe.json +0 -76
- package/library/recipes/mobile/app/lifecycle.android-smoke.recipe.json +0 -69
- package/library/recipes/mobile/perps/chase-assert-running.recipe.json +0 -110
- package/library/recipes/mobile/perps/chase-place.recipe.json +0 -145
- package/library/recipes/mobile/perps/chase-terminate.recipe.json +0 -98
- package/library/recipes/mobile/perps/performance.recipe.json +0 -722
- package/library/recipes/mobile/perps/pro-order-setup.recipe.json +0 -111
- package/library/recipes/mobile/perps/pro-order-start-state.recipe.json +0 -53
- package/library/recipes/mobile/perps/scale-assert-orders.recipe.json +0 -126
- package/library/recipes/mobile/perps/scale-place.recipe.json +0 -186
- package/library/recipes/mobile/perps/twap-assert-active.recipe.json +0 -97
- package/library/recipes/mobile/perps/twap-place.recipe.json +0 -146
- package/library/recipes/mobile/runner/action-validation.recipe.json +0 -336
- package/library/recipes/perps/clean-market-testnet.recipe.json +0 -49
- package/library/recipes/perps/lifecycle.recipe.json +0 -144
- package/library/recipes/perps/release-live-market-order.recipe.json +0 -139
- package/library/recipes/perps/release-watchlist.recipe.json +0 -111
- package/library/recipes/swap-bridge/release-max-quote.recipe.json +0 -72
- /package/library/recipes/{assets → shared/assets}/release-token-list.recipe.json +0 -0
- /package/library/recipes/{perps → shared/perps}/release-market-details.recipe.json +0 -0
- /package/library/recipes/{perps → shared/perps}/release-market-search.recipe.json +0 -0
- /package/library/recipes/{swap-bridge → shared/swap-bridge}/release-custom-slippage.recipe.json +0 -0
- /package/library/recipes/{swap-bridge → shared/swap-bridge}/release-live-max-swap.recipe.json +0 -0
- /package/library/recipes/{swap-bridge → shared/swap-bridge}/release-live-swap.recipe.json +0 -0
- /package/library/recipes/{swap-bridge → shared/swap-bridge}/release-surface.recipe.json +0 -0
- /package/library/recipes/{wallet → shared/wallet}/import.recipe.json +0 -0
- /package/library/recipes/{wallet → shared/wallet}/reset-import.recipe.json +0 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Persist trusted mutation intent, accepted order identities and observed outcomes.
|
|
2
|
+
// Resume observation without redispatching an already recorded operation.
|
|
3
|
+
|
|
1
4
|
import { createHash } from 'node:crypto';
|
|
2
5
|
import { constants as fsConstants } from 'node:fs';
|
|
3
6
|
import {
|
|
@@ -461,7 +464,8 @@ function validateIdentity(input, identity) {
|
|
|
461
464
|
|| !/^(?:market|limit|close|margin|tpsl)$/u.test(value.orderType)
|
|
462
465
|
|| !/^(?:new|modify|close)$/u.test(value.positionMode)
|
|
463
466
|
|| !/^(?:0|[1-9][0-9]{0,29})$/u.test(value.roundingToleranceBaseUnits)
|
|
464
|
-
|| (value.limitPrice !== null && !/^[1-9][0-9]*(?:\.[0-9]{1,6})?$/u.test(value.limitPrice)
|
|
467
|
+
|| (value.limitPrice !== null && (!/^(?:0|[1-9][0-9]*)(?:\.[0-9]{1,6})?$/u.test(value.limitPrice)
|
|
468
|
+
|| !(Number(value.limitPrice) > 0)))
|
|
465
469
|
|| (value.offsetPct !== null && !/^-?[0-9]+(?:\.[0-9]{1,6})?$/u.test(value.offsetPct))
|
|
466
470
|
|| (value.partialCloseAmount !== null && !/^[1-9][0-9]*(?:\.[0-9]{1,6})?$/u.test(value.partialCloseAmount))) {
|
|
467
471
|
throw new Error('External mutation receipt operation parameters are invalid.');
|
|
@@ -738,8 +742,54 @@ export async function recordExternalMutationCleanupCandidate(input, receipt, can
|
|
|
738
742
|
});
|
|
739
743
|
}
|
|
740
744
|
|
|
745
|
+
async function recordSubmissionAcceptance(input, receipt, acceptance) {
|
|
746
|
+
const { venueOrderId, status, requestId, serviceWorkerTargetId, asset, size, limitPriceBaseUnits, filledSize, averagePrice } = acceptance;
|
|
747
|
+
const closing = receipt.record.identity.operation === 'perps-close-position';
|
|
748
|
+
const market = closing || receipt.record.identity.operation === 'perps-market-order';
|
|
749
|
+
const sizing = closing ? receipt.record.facts?.closeSizing
|
|
750
|
+
: market ? receipt.record.facts?.marketSizing : receipt.record.facts?.limitSizing;
|
|
751
|
+
if (!['perps-limit-order', 'perps-market-order', 'perps-close-position'].includes(receipt.record.identity.operation)
|
|
752
|
+
|| receipt.record.identity.provider !== 'hyperliquid'
|
|
753
|
+
|| Number(sizing?.size) !== Number(size)
|
|
754
|
+
|| (closing && sizing?.side !== (receipt.record.identity.side === 'long' ? 'short' : 'long'))
|
|
755
|
+
|| !/^[1-9][0-9]{0,19}$/u.test(String(venueOrderId)) || !['resting', 'filled'].includes(status)
|
|
756
|
+
|| !/^[A-Za-z0-9._:-]{1,128}$/u.test(String(requestId))
|
|
757
|
+
|| !/^[A-Za-z0-9._:-]{1,128}$/u.test(String(serviceWorkerTargetId))
|
|
758
|
+
|| !Number.isInteger(asset) || asset < 0 || asset > 100_000
|
|
759
|
+
|| !/^(?:0|[1-9][0-9]{0,19})(?:\.[0-9]{1,8})?$/u.test(String(size)) || !(Number(size) > 0)
|
|
760
|
+
|| !BASE_UNITS.test(String(limitPriceBaseUnits))) {
|
|
761
|
+
throw recoveryError(receipt, 'submission acceptance has invalid order identity');
|
|
762
|
+
}
|
|
763
|
+
if (market && status === 'filled' && (!/^(?:0|[1-9][0-9]{0,19})(?:\.[0-9]{1,8})?$/u.test(String(filledSize))
|
|
764
|
+
|| !(Number(filledSize) > 0) || Number(filledSize) > Number(size)
|
|
765
|
+
|| !/^(?:0|[1-9][0-9]{0,19})(?:\.[0-9]{1,18})?$/u.test(String(averagePrice)) || !(Number(averagePrice) > 0))) {
|
|
766
|
+
throw recoveryError(receipt, 'market acceptance has invalid filled size or price');
|
|
767
|
+
}
|
|
768
|
+
const destination = await receiptDestination(input);
|
|
769
|
+
const current = await readPublished(destination);
|
|
770
|
+
if (!current || current.sha256 !== receipt.sha256 || current.record?.state !== 'outcome-unknown') {
|
|
771
|
+
throw recoveryError(receipt, 'the receipt changed before submission acceptance was recorded');
|
|
772
|
+
}
|
|
773
|
+
const record = { ...current.record, acceptance: {
|
|
774
|
+
venueOrderId, status, requestId, serviceWorkerTargetId, asset, size, limitPriceBaseUnits,
|
|
775
|
+
...(market && status === 'filled' ? { filledSize, averagePrice } : {}),
|
|
776
|
+
} };
|
|
777
|
+
const staged = await stagedRecord(destination.directory, record);
|
|
778
|
+
try {
|
|
779
|
+
await rename(staged.stagedPath, destination.absolute);
|
|
780
|
+
await durableDirectorySync(destination.directory);
|
|
781
|
+
} finally {
|
|
782
|
+
await rm(staged.stagingDirectory, { recursive: true, force: true });
|
|
783
|
+
}
|
|
784
|
+
const published = await readPublished(destination);
|
|
785
|
+
if (!published || canonical(published.record) !== canonical(record)) {
|
|
786
|
+
throw recoveryError(receipt, 'submission acceptance could not be reread');
|
|
787
|
+
}
|
|
788
|
+
return { ...published, resumed: receipt.resumed };
|
|
789
|
+
}
|
|
790
|
+
|
|
741
791
|
export async function runGuardedExternalMutation({ input, identity, dispatch, observe, publicationFacts, receiptIo }) {
|
|
742
|
-
|
|
792
|
+
let receipt = await beginExternalMutation(input, identity, receiptIo, publicationFacts);
|
|
743
793
|
if (receipt.record?.state === 'observed-policy-violation') {
|
|
744
794
|
throw new Error('External mutation receipt records an observed policy violation and is cleanup-only.');
|
|
745
795
|
}
|
|
@@ -748,7 +798,8 @@ export async function runGuardedExternalMutation({ input, identity, dispatch, ob
|
|
|
748
798
|
}
|
|
749
799
|
if (!receipt.resumed) {
|
|
750
800
|
try {
|
|
751
|
-
await dispatch();
|
|
801
|
+
const acceptance = await dispatch();
|
|
802
|
+
if (acceptance?.venueOrderId) receipt = await recordSubmissionAcceptance(input, receipt, acceptance);
|
|
752
803
|
} catch (error) {
|
|
753
804
|
if (error instanceof ExternalMutationNotDispatchedError) {
|
|
754
805
|
await markExternalMutationNotDispatched(input, receipt, error, receiptIo);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Open the Perps deposit or withdrawal flow through balance controls and report the displayed page.
|
|
1
2
|
import { dataTestId, runAdapter, withExtensionPage } from '../platform/cdp.mjs';
|
|
2
3
|
|
|
3
4
|
const ACTIONS = new Map([
|
|
@@ -11,13 +12,22 @@ runAdapter(async (input) => withExtensionPage(input, async (page) => {
|
|
|
11
12
|
if (!actionTestId) {
|
|
12
13
|
throw new Error(`metamask.perps.open_balance_action received unsupported balance_action ${JSON.stringify(balanceAction)}.`);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const directSelector = dataTestId(`perps-balance-actions-${balanceAction}`);
|
|
16
|
+
const directVisible = await page.evaluate(`(() => {
|
|
17
|
+
const element = document.querySelector(${JSON.stringify(directSelector)});
|
|
18
|
+
if (!element) return false;
|
|
19
|
+
const style = getComputedStyle(element), rect = element.getBoundingClientRect();
|
|
20
|
+
return style.display !== 'none' && style.visibility !== 'hidden' && rect.width > 0 && rect.height > 0;
|
|
21
|
+
})()`);
|
|
22
|
+
const actionSelector = directVisible ? directSelector : dataTestId(actionTestId);
|
|
23
|
+
if (!directVisible) {
|
|
24
|
+
await page.click(dataTestId('perps-balance-dropdown-balance'));
|
|
25
|
+
await page.waitForSelector(actionSelector, { timeoutMs: 10_000 });
|
|
26
|
+
}
|
|
17
27
|
await page.click(actionSelector);
|
|
18
28
|
const expected = balanceAction === 'withdraw'
|
|
19
|
-
? ['perps-withdraw-page', 'perps-withdraw-container', 'perps-withdraw-view']
|
|
20
|
-
: ['confirm-page-container-content', 'confirm-page-container', 'transaction-confirmation'];
|
|
29
|
+
? ['parent-selector-perps-withdraw', 'parent-selector-confirmation-page', 'perps-withdraw-page', 'perps-withdraw-container', 'perps-withdraw-view']
|
|
30
|
+
: ['parent-selector-confirmation-page', 'confirm-page-container-content', 'confirm-page-container', 'transaction-confirmation'];
|
|
21
31
|
const resultDeadline = Date.now() + 15_000;
|
|
22
32
|
let observed;
|
|
23
33
|
while (Date.now() <= resultDeadline) {
|
|
@@ -38,10 +48,10 @@ runAdapter(async (input) => withExtensionPage(input, async (page) => {
|
|
|
38
48
|
text: String(document.body?.innerText || '').replace(/\\s+/gu, ' ').trim().slice(0, 10_000),
|
|
39
49
|
};
|
|
40
50
|
})()`);
|
|
41
|
-
if (observed.matched.length > 0
|
|
51
|
+
if (observed.matched.length > 0) break;
|
|
42
52
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
43
53
|
}
|
|
44
|
-
if (!observed ||
|
|
54
|
+
if (!observed || observed.matched.length === 0) {
|
|
45
55
|
throw new Error(`Perps ${balanceAction} did not open: ${JSON.stringify(observed)}.`);
|
|
46
56
|
}
|
|
47
57
|
return {
|