@across-protocol/contracts 6.0.0-beta.2 → 6.0.0-beta.4

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.
Files changed (138) hide show
  1. package/README.md +195 -34
  2. package/contracts/chain-adapters/Solana_Adapter.sol +4 -7
  3. package/contracts/handlers/HyperliquidDepositHandler.sol +2 -2
  4. package/contracts/interfaces/SpokePoolPeripheryInterface.sol +16 -4
  5. package/contracts/libraries/HyperCoreLib.sol +113 -20
  6. package/contracts/libraries/PeripherySigningLib.sol +56 -0
  7. package/contracts/periphery/SpokePoolPeriphery.sol +58 -10
  8. package/dist/broadcast/deployed-addresses.json +19 -0
  9. package/dist/evm/artifacts/Constants.sol/Constants.json +1 -1
  10. package/dist/evm/artifacts/DeploymentUtils.sol/DeploymentUtils.json +1 -1
  11. package/dist/evm/artifacts/DstOFTHandler.sol/DstOFTHandler.json +1 -1
  12. package/dist/evm/artifacts/HubPoolTestBase.sol/MockAddressWhitelist.json +1 -1
  13. package/dist/evm/artifacts/HubPoolTestBase.sol/MockFinder.json +1 -1
  14. package/dist/evm/artifacts/HubPoolTestBase.sol/MockIdentifierWhitelist.json +1 -1
  15. package/dist/evm/artifacts/HubPoolTestBase.sol/MockLpTokenFactory.json +1 -1
  16. package/dist/evm/artifacts/HubPoolTestBase.sol/MockOptimisticOracle.json +1 -1
  17. package/dist/evm/artifacts/HubPoolTestBase.sol/MockStore.json +1 -1
  18. package/dist/evm/artifacts/HyperCoreFlowExecutor.sol/HyperCoreFlowExecutor.json +1 -1
  19. package/dist/evm/artifacts/HyperCoreLib.sol/HyperCoreLib.json +1 -1
  20. package/dist/evm/artifacts/HyperliquidDepositHandler.sol/HyperliquidDepositHandler.json +1 -1
  21. package/dist/evm/artifacts/PeripherySigningLib.sol/PeripherySigningLib.json +1 -1
  22. package/dist/evm/artifacts/Solana_Adapter.sol/Solana_Adapter.json +1 -1
  23. package/dist/evm/artifacts/SpokePoolPeriphery.sol/SpokePoolPeriphery.json +1 -1
  24. package/dist/evm/artifacts/SpokePoolPeriphery.sol/SwapProxy.json +1 -1
  25. package/dist/evm/artifacts/SponsoredCCTPDstPeriphery.sol/SponsoredCCTPDstPeriphery.json +1 -1
  26. package/dist/evm/artifacts/SponsoredCCTPSrcPeriphery.sol/SponsoredCCTPSrcPeriphery.json +1 -1
  27. package/dist/evm/artifacts/SponsoredOFTSrcPeriphery.sol/SponsoredOFTSrcPeriphery.json +1 -1
  28. package/dist/evm/artifacts/SwapHandler.sol/SwapHandler.json +1 -1
  29. package/dist/evm/artifacts/Tron_SpokePoolPeriphery.sol/Tron_SpokePoolPeriphery.json +1 -1
  30. package/dist/evm/artifacts/Tron_SpokePoolPeriphery.sol/Tron_SwapProxy.json +1 -1
  31. package/dist/src/consts.js +1 -0
  32. package/dist/src/svm/assets/idl/index.d.ts +5 -7
  33. package/dist/src/svm/assets/idl/index.js +6 -14
  34. package/dist/src/svm/assets/idl/sponsored_cctp_src_periphery.json +41 -24
  35. package/dist/src/svm/assets/idl/svm_spoke.json +1001 -2171
  36. package/dist/src/svm/assets/index.d.ts +2 -3
  37. package/dist/src/svm/assets/index.js +0 -1
  38. package/dist/src/svm/assets/sponsored_cctp_src_periphery.d.ts +41 -24
  39. package/dist/src/svm/assets/svm_spoke.d.ts +996 -2166
  40. package/dist/src/svm/assets/token_messenger_minter_v2.d.ts +18 -18
  41. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/index.d.ts +0 -1
  42. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/index.js +0 -1
  43. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/errors/sponsoredCctpSrcPeriphery.d.ts +24 -12
  44. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/errors/sponsoredCctpSrcPeriphery.js +30 -12
  45. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/programs/sponsoredCctpSrcPeriphery.d.ts +4 -5
  46. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/programs/sponsoredCctpSrcPeriphery.js +4 -8
  47. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/index.d.ts +1 -0
  48. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/index.js +1 -0
  49. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/messageSent.d.ts +21 -0
  50. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/messageSent.js +30 -0
  51. package/dist/src/svm/clients/SvmSpoke/accounts/fillStatusAccount.d.ts +2 -2
  52. package/dist/src/svm/clients/SvmSpoke/accounts/fillStatusAccount.js +2 -2
  53. package/dist/src/svm/clients/SvmSpoke/accounts/index.d.ts +0 -3
  54. package/dist/src/svm/clients/SvmSpoke/accounts/index.js +0 -3
  55. package/dist/src/svm/clients/SvmSpoke/errors/svmSpoke.d.ts +94 -22
  56. package/dist/src/svm/clients/SvmSpoke/errors/svmSpoke.js +133 -24
  57. package/dist/src/svm/clients/SvmSpoke/instructions/adapterExecuteAcrossV5.d.ts +75 -0
  58. package/dist/src/svm/clients/SvmSpoke/instructions/adapterExecuteAcrossV5.js +144 -0
  59. package/dist/src/svm/clients/SvmSpoke/instructions/closeFillPda.d.ts +16 -8
  60. package/dist/src/svm/clients/SvmSpoke/instructions/closeFillPda.js +3 -3
  61. package/dist/src/svm/clients/SvmSpoke/instructions/index.d.ts +2 -7
  62. package/dist/src/svm/clients/SvmSpoke/instructions/index.js +2 -7
  63. package/dist/src/svm/clients/SvmSpoke/instructions/withdrawV5FillPayer.d.ts +58 -0
  64. package/dist/src/svm/clients/SvmSpoke/instructions/withdrawV5FillPayer.js +134 -0
  65. package/dist/src/svm/clients/SvmSpoke/programs/svmSpoke.d.ts +29 -47
  66. package/dist/src/svm/clients/SvmSpoke/programs/svmSpoke.js +29 -61
  67. package/dist/src/svm/clients/SvmSpoke/types/acrossDepositInput.d.ts +25 -0
  68. package/dist/src/svm/clients/SvmSpoke/types/acrossDepositInput.js +33 -0
  69. package/dist/src/svm/clients/SvmSpoke/types/acrossDepositJitParams.d.ts +18 -0
  70. package/dist/src/svm/clients/SvmSpoke/types/acrossDepositJitParams.js +30 -0
  71. package/dist/src/svm/clients/SvmSpoke/types/acrossDepositParams.d.ts +43 -0
  72. package/dist/src/svm/clients/SvmSpoke/types/acrossDepositParams.js +48 -0
  73. package/dist/src/svm/clients/SvmSpoke/types/index.d.ts +9 -1
  74. package/dist/src/svm/clients/SvmSpoke/types/index.js +9 -1
  75. package/dist/src/svm/clients/SvmSpoke/types/v5AdapterInput.d.ts +39 -0
  76. package/dist/src/svm/clients/SvmSpoke/types/v5AdapterInput.js +59 -0
  77. package/dist/src/svm/clients/SvmSpoke/types/v5DepositModificationRules.d.ts +17 -0
  78. package/dist/src/svm/clients/SvmSpoke/types/v5DepositModificationRules.js +30 -0
  79. package/dist/src/svm/clients/SvmSpoke/types/v5FillFloatWithdrawn.d.ts +19 -0
  80. package/dist/src/svm/clients/SvmSpoke/types/v5FillFloatWithdrawn.js +28 -0
  81. package/dist/src/svm/clients/SvmSpoke/types/v5FillInput.d.ts +25 -0
  82. package/dist/src/svm/clients/SvmSpoke/types/v5FillInput.js +30 -0
  83. package/dist/src/svm/clients/SvmSpoke/types/v5FillJit.d.ts +22 -0
  84. package/dist/src/svm/clients/SvmSpoke/types/{slowFill.js → v5FillJit.js} +11 -11
  85. package/dist/src/svm/clients/SvmSpoke/types/v5InputAmountMode.d.ts +29 -0
  86. package/dist/src/svm/clients/SvmSpoke/types/v5InputAmountMode.js +38 -0
  87. package/dist/src/svm/web3-v1/cctpV2Helpers.d.ts +51 -65
  88. package/dist/src/svm/web3-v1/cctpV2Helpers.js +1 -1
  89. package/dist/src/svm/web3-v1/coders.d.ts +1 -1
  90. package/dist/src/svm/web3-v1/coders.js +4 -4
  91. package/dist/src/svm/web3-v1/conversionUtils.d.ts +1 -1
  92. package/dist/src/svm/web3-v1/conversionUtils.js +3 -3
  93. package/dist/src/svm/web3-v1/helpers.d.ts +1 -114
  94. package/dist/src/svm/web3-v1/helpers.js +1 -179
  95. package/dist/src/svm/web3-v1/instructionParamsUtils.d.ts +11 -26
  96. package/dist/src/svm/web3-v1/instructionParamsUtils.js +5 -90
  97. package/dist/src/svm/web3-v1/programConnectors.d.ts +1 -1
  98. package/dist/src/svm/web3-v1/programConnectors.js +2 -2
  99. package/dist/src/svm/web3-v1/relayHashUtils.d.ts +2 -6
  100. package/dist/src/svm/web3-v1/relayHashUtils.js +5 -66
  101. package/dist/src/svm/web3-v1/solanaProgramUtils.d.ts +1 -1
  102. package/dist/src/svm/web3-v1/solanaProgramUtils.js +7 -7
  103. package/dist/src/svm/web3-v1/transactionUtils.js +3 -3
  104. package/dist/src/svm/web3-v2/solanaProgramUtils.d.ts +1 -1
  105. package/dist/src/svm/web3-v2/solanaProgramUtils.js +4 -4
  106. package/dist/src/types/svm.d.ts +1 -46
  107. package/package.json +28 -13
  108. package/svm/idl/multicall_handler.json +31 -0
  109. package/svm/idl/sponsored_cctp_src_periphery.json +1982 -0
  110. package/svm/idl/svm_spoke.json +3930 -0
  111. package/dist/src/svm/assets/idl/test.json +0 -243
  112. package/dist/src/svm/assets/test.d.ts +0 -249
  113. package/dist/src/svm/assets/test.js +0 -2
  114. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/messageSent.d.ts +0 -30
  115. package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/messageSent.js +0 -66
  116. package/dist/src/svm/clients/SvmSpoke/accounts/executeSlowRelayLeafParams.d.ts +0 -31
  117. package/dist/src/svm/clients/SvmSpoke/accounts/executeSlowRelayLeafParams.js +0 -70
  118. package/dist/src/svm/clients/SvmSpoke/accounts/fillRelayParams.d.ts +0 -31
  119. package/dist/src/svm/clients/SvmSpoke/accounts/fillRelayParams.js +0 -67
  120. package/dist/src/svm/clients/SvmSpoke/accounts/requestSlowFillParams.d.ts +0 -27
  121. package/dist/src/svm/clients/SvmSpoke/accounts/requestSlowFillParams.js +0 -66
  122. package/dist/src/svm/clients/SvmSpoke/instructions/deposit.d.ts +0 -131
  123. package/dist/src/svm/clients/SvmSpoke/instructions/deposit.js +0 -241
  124. package/dist/src/svm/clients/SvmSpoke/instructions/depositNow.d.ts +0 -127
  125. package/dist/src/svm/clients/SvmSpoke/instructions/depositNow.js +0 -239
  126. package/dist/src/svm/clients/SvmSpoke/instructions/executeSlowRelayLeaf.d.ts +0 -104
  127. package/dist/src/svm/clients/SvmSpoke/instructions/executeSlowRelayLeaf.js +0 -259
  128. package/dist/src/svm/clients/SvmSpoke/instructions/fillRelay.d.ts +0 -108
  129. package/dist/src/svm/clients/SvmSpoke/instructions/fillRelay.js +0 -265
  130. package/dist/src/svm/clients/SvmSpoke/instructions/getUnsafeDepositId.d.ts +0 -39
  131. package/dist/src/svm/clients/SvmSpoke/instructions/getUnsafeDepositId.js +0 -63
  132. package/dist/src/svm/clients/SvmSpoke/instructions/requestSlowFill.d.ts +0 -76
  133. package/dist/src/svm/clients/SvmSpoke/instructions/requestSlowFill.js +0 -187
  134. package/dist/src/svm/clients/SvmSpoke/instructions/unsafeDeposit.d.ts +0 -135
  135. package/dist/src/svm/clients/SvmSpoke/instructions/unsafeDeposit.js +0 -243
  136. package/dist/src/svm/clients/SvmSpoke/types/slowFill.d.ts +0 -22
  137. package/dist/target/types/svm_spoke.d.ts +0 -5106
  138. package/dist/target/types/svm_spoke.js +0 -2
package/README.md CHANGED
@@ -23,9 +23,73 @@ The latest contract deployments can be found in `/broadcast/deployed-addresses.j
23
23
 
24
24
  ## Requirements
25
25
 
26
- This repository assumes you have [Node](https://nodejs.org/en/download/package-manager) installed, with a minimum version of 16.18.0. Depending on what you want to do with the repo you might also need [foundry](https://book.getfoundry.sh/getting-started/installation) and [anchor](https://www.anchor-lang.com/docs/installation) to also be installed. If you have build issues please ensure these are both installed first.
26
+ This repository assumes you have [Node](https://nodejs.org/en/download/package-manager) installed, with a minimum version of 22.18.0. Depending on what you want to do with the repo you might also need [foundry](https://book.getfoundry.sh/getting-started/installation) and [anchor](https://www.anchor-lang.com/docs/installation) to also be installed. If you have build issues please ensure these are both installed first.
27
27
 
28
- Note if you get build issues on the initial `yarn` command try downgrading to node 20.17 (`nvm use 20.17`). If you've never used anchor before you might need to run `avm use latest` as well.
28
+ Use Node 22 for SVM development. `Anchor.toml` pins Anchor 1.1.2 and Agave 4.1.2;
29
+ install these versions instead of selecting a moving `latest` toolchain.
30
+ The generated Anchor client types now use `@anchor-lang/core` 1.1.2. Consumers updating this package
31
+ should replace their `@coral-xyz/anchor` imports where they exchange Anchor providers or program types.
32
+ For the 6.0.0 release, coordinate the SDK/relayer package updates and Anchor import changes with the
33
+ program and canonical IDL upgrade. Legacy `Program.at`/`fetchIdl` readers do not follow the new metadata address.
34
+ Artifact generation restores the canonical event-authority PDA seeds omitted by Anchor 1.1's IDL output,
35
+ preserving typed account resolution and Codama async builders. This metadata does not change program bytes.
36
+
37
+ ## SVM JSON interfaces
38
+
39
+ The npm package exposes these stable JSON paths for downstream Anchor clients and Codama generation:
40
+
41
+ ```text
42
+ @across-protocol/contracts/svm/idl/svm_spoke.json
43
+ @across-protocol/contracts/svm/idl/multicall_handler.json
44
+ @across-protocol/contracts/svm/idl/sponsored_cctp_src_periphery.json
45
+ ```
46
+
47
+ `svm_spoke` is the V5 interface. `multicall_handler` and `sponsored_cctp_src_periphery` are legacy
48
+ compatibility interfaces for existing quote construction and event indexing; they are not used by V5 flows.
49
+
50
+ For example, load an IDL without loading the package's runtime clients:
51
+
52
+ ```js
53
+ const spokeIdl = require("@across-protocol/contracts/svm/idl/svm_spoke.json")
54
+ ```
55
+
56
+ Pin an exact contracts package version and commit your lockfile, together with compatible versions of your
57
+ client generator and runtime. IDLs are versioned with the npm package; `metadata.version` identifies the program's
58
+ declared version and is not the npm release version. Consumers can generate clients from the installed JSON without
59
+ a contracts checkout or Rust, Anchor CLI, or Foundry. Select the deployed program address for your environment;
60
+ installing a package does not deploy or upgrade programs.
61
+
62
+ The Spoke IDL includes the Rust-derived `V5AdapterInput`, `AcrossDepositJitParams`, and `V5FillJit` schemas
63
+ carried inside opaque instruction bytes. Event-authority PDA seeds are preserved for account resolution.
64
+ Circle owns the MessageTransmitterV2 and TokenMessengerMinterV2 schemas. They have no stable `/svm/idl/`
65
+ exports here; downstream generators should use reviewed, commit-pinned IDLs from
66
+ [Circle's repository](https://github.com/circlefin/solana-cctp-contracts/tree/master/examples/target/idl),
67
+ with the source revision recorded and compatibility checked against the intended deployment.
68
+ The reviewed Circle V2 snapshots in `idls/` remain available through the existing legacy IDL/client exports
69
+ during migration. SDK owns the downstream Circle client generation; this does not remove CCTP support.
70
+ Existing production generated clients, runtime helpers, legacy IDL deep imports, and EVM/shared exports remain available
71
+ during downstream migration. `MulticallHandlerCoder` is a handwritten compilation helper, not generated from
72
+ the program IDL; migrating it requires moving its logic downstream separately from IDL-based client generation.
73
+
74
+ Compatibility change from `6.0.0-beta.3`: the test program's root `TestIdl` and `TestAnchor` exports and
75
+ `dist/src/svm/assets/idl/test.json`, `dist/src/svm/assets/test.js` and `dist/src/svm/assets/test.d.ts` are removed.
76
+ Tests that need these interfaces must generate them from the matching source tag; they are not production APIs.
77
+
78
+ For maintainers, `yarn generate-svm-artifacts` always generates production interfaces, even with `IS_TEST=true`.
79
+ `yarn generate-svm-test-idls` writes test-feature and mock interfaces only under `target/`.
80
+ The explicit `/svm/idl/` entries in `package.json` allowlist the public Across IDLs. `yarn build-ts` exports those JSON
81
+ files to both the stable paths and the legacy `dist` paths, and retains Circle V2 JSON only in the legacy paths.
82
+ `npm pack` and `npm publish` run the same `prepack`
83
+ build, including EVM artifact export. Generate production artifacts first (and build EVM artifacts with
84
+ `yarn build-evm-foundry`). Run `yarn test-svm-idl-package` to inspect a real tarball and generate/compile clients
85
+ in an external fixture using only its IDLs. This check requires no validator or network access.
86
+
87
+ SVM binaries are a separate [GitHub Releases](https://github.com/across-protocol/contracts/releases) channel:
88
+ `svm-verified-test-binaries.tar.gz` contains test-feature binaries for downstream integration tests;
89
+ `svm-verified-production-binaries.tar.gz` contains production binaries. Both archives contain `target/deploy`.
90
+ Pin the release tag corresponding to the npm package version when pairing interfaces and binaries.
91
+ Test-only IDLs and mock interfaces are not npm exports; tests needing those interfaces must generate them
92
+ from the matching source tag. Test binaries must never be used for production deployment.
29
93
 
30
94
  ## Build
31
95
 
@@ -39,6 +103,15 @@ EVM builds and tests use the Foundry version pinned in `.foundry-version`; CI in
39
103
  `foundry-rs/foundry-toolchain`. Run `yarn pin-foundry` to switch your local toolchain to it (a no-op when it already
40
104
  matches). Bump the pin by editing that file.
41
105
 
106
+ SVM local, verified, and real-Gateway builds fail on stack-overflow diagnostics even when the compiler exits
107
+ successfully. The shared guard is `scripts/svm/buildHelpers/runSbfBuild.sh`; run `yarn test-svm-build-guard` to test it
108
+ without a validator or Rust build. CI invalidates cached SVM builds when these build helpers change.
109
+ Host IDL generation and Rust tests use Rust 1.97.1, pinned in the SVM setup action; use that version locally
110
+ when reproducing CI artifacts. CI installs Agave, Anchor and `solana-verify` with
111
+ `scripts/svm/buildHelpers/installSvmTools.sh`, which checks the Linux x86_64 release assets against the
112
+ SHA-256 pins in `verified-build.json` on fresh downloads and cache hits alike. These host tools are separate from the
113
+ release image's SBF compiler.
114
+
42
115
  ## Test
43
116
 
44
117
  ```shell
@@ -49,8 +122,13 @@ yarn test:report-gas # Run unit tests with gas reporting enabled
49
122
  yarn test-evm # Only test EVM code
50
123
  yarn test-svm # Only test SVM code (local toolchain build)
51
124
  yarn test-svm-solana-verify # Only test SVM code (verified docker build)
125
+ yarn typecheck-tests # Typecheck all TypeScript tests without emitting files
52
126
  ```
53
127
 
128
+ The test typecheck uses `tsconfig.test.json` and requires generated clients and test-feature IDLs. Run
129
+ `yarn generate-svm-artifacts && yarn generate-svm-test-idls` first. CI runs this check after preparing these artifacts,
130
+ before the verified SVM build and runtime tests. The package build continues to use `tsconfig.json`.
131
+
54
132
  ## Lint
55
133
 
56
134
  ```shell
@@ -94,9 +172,51 @@ yarn forge-script-zksync script/016DeployZkSyncSpokePool.s.sol:DeployZkSyncSpoke
94
172
 
95
173
  For CCTP V2 root/admin finalization, pause recovery and light-chain intent examples, see the [Solana operational scripts guide](scripts/svm/README.md).
96
174
 
175
+ V5 `svm_spoke` is configured for mainnet and local-validator testing. Its public-devnet deployment and supporting
176
+ offchain infrastructure are not configured, so `Anchor.toml` has no devnet Spoke entry. The devnet deployment examples
177
+ below require a separately configured deployment; the legacy devnet Spoke address is not a V5 target.
178
+
97
179
  Before deploying for the first time make sure all program IDs in `lib.rs` and `Anchor.toml` are the same as listed when running `anchor keys list`. If not, update them to match the deployment keypairs under `target/deploy/` and commit the changes.
98
180
 
99
- Make sure to use the verified docker binaries that can be built:
181
+ V5 PDA addresses and bumps are pinned to the configured Spoke and Gateway IDs to avoid runtime derivation costs.
182
+ If either program ID changes, update its dependent PDA constants and run `cargo test -p svm-spoke --lib` to check consistency.
183
+
184
+ Use `solana-verify` 0.5.1, matching CI, to build the verified Docker binaries. The build removes each
185
+ previous binary before compilation and rejects missing or empty output; failed builds must not be used for deployment.
186
+ Keep the stack-diagnostic guard enabled, since SBF compilers can report stack overflows with a successful exit status.
187
+ On Linux, Docker can leave `target/deploy` owned by root. If the next verified build reports a permissions error,
188
+ restore ownership from the repository root with `sudo chown -R "$(id -u):$(id -g)" target/deploy`, then rerun the build.
189
+
190
+ `verified-build.json` pins the release image by immutable digest: Agave 4.0.3,
191
+ `cargo-build-sbf` 4.0.0, platform-tools 1.53, and SBF architecture `v0`. This release recipe is separate
192
+ from the Agave 4.1.2 validator/development toolchain. It was selected because the pinned verifier's
193
+ 0.5.1 image registry did not include Agave 4.1.2. Newer upstream images exist; updating this recipe
194
+ requires rebuilding and testing the release binaries. Never infer the image from Solana SDK crate versions.
195
+ `yarn test-svm-solana-verify` runs the full suite against **test-feature** binaries: it retains the
196
+ mocked clock and per-test state seeds. `yarn test-svm-production` then rebuilds without that feature
197
+ and tests seed-zero initialization, disabled test controls, Clock-sysvar expiry and event self-CPI
198
+ in a fresh ledger. Deploy only the latter production artifacts; a test-feature build overwrites
199
+ `target/deploy` and must never be deployed.
200
+
201
+ Validator tests share `test/svm/provider.ts`, which sets the connection, transaction confirmation and
202
+ preflight commitments to `confirmed`. Use this provider for fixture writes and dependent transactions
203
+ so simulations cannot run against a bank that predates the fixture state.
204
+
205
+ All workspace programs use Anchor 1.1.2. The Spoke retains the pre-upgrade V5 branch's custom error numbers;
206
+ its IDL now exposes all four ranges from one enum. Sponsored CCTP's formerly overlapping enums
207
+ now use Common 6000–6002, SVM 7000–7010 and CCTP 8000–8002. This changes error numbers in a **new**
208
+ Sponsored CCTP build, not its existing deployment. Upgrading the source does not require redeploying
209
+ retiring Sponsored CCTP or multicall programs.
210
+ The bundled Sponsored CCTP IDL/client error tables describe that new build, not the existing deployment.
211
+ For live or historical transactions from the old deployment, use the error name in the program logs and
212
+ the matching release artifacts; numeric codes alone are ambiguous across its old enums.
213
+
214
+ Before an audited release, build from a clean checkout of the reviewed commit and record the commit,
215
+ `Cargo.lock`, `verified-build.json`, enabled features (none for production), program IDs and executable
216
+ hashes. Release Cargo profiles use `lto = "fat"`, one codegen unit, and overflow checks.
217
+ The lockfile pins the SBF dependency graph, including the Solana hash/secp256k1 crates.
218
+ Verify reproducibility by comparing executable hashes; matching CLI versions alone does not prove
219
+ byte-identical builds.
100
220
 
101
221
  ```shell
102
222
  unset IS_TEST # Ensures the production build is used (not the test feature)
@@ -112,7 +232,7 @@ export KEYPAIR=~/.config/solana/dev-wallet.json
112
232
  export PROGRAM=svm_spoke # Also repeat the deployment process for multicall_handler
113
233
  export PROGRAM_ID=$(cat target/idl/$PROGRAM.json | jq -r ".address")
114
234
  export MULTISIG= # Export the Squads vault, not the multisig address!
115
- export SOLANA_VERSION=$(grep -A 2 'name = "solana-program"' Cargo.lock | grep 'version' | head -n 1 | cut -d'"' -f2)
235
+ export BUILD_IMAGE=$(node -p 'require("./verified-build.json").image')
116
236
  ```
117
237
 
118
238
  For the initial deployment also need these:
@@ -139,6 +259,11 @@ solana program deploy \
139
259
  --max-sign-attempts 100 \
140
260
  --use-rpc \
141
261
  target/deploy/$PROGRAM.so
262
+ anchor idl init \
263
+ --provider.cluster $RPC_URL \
264
+ --provider.wallet $KEYPAIR \
265
+ --filepath target/idl/$PROGRAM.json \
266
+ $PROGRAM_ID
142
267
  solana program set-upgrade-authority \
143
268
  --url $RPC_URL \
144
269
  --keypair $KEYPAIR \
@@ -149,20 +274,10 @@ solana program set-upgrade-authority \
149
274
 
150
275
  Update and commit `deployments/legacy-addresses.json` with the deployed program ID and deployment slot.
151
276
 
152
- Upload the IDL and set the upgrade authority to the multisig:
153
-
154
- ```shell
155
- anchor idl init \
156
- --provider.cluster $RPC_URL \
157
- --provider.wallet $KEYPAIR \
158
- --filepath target/idl/$PROGRAM.json \
159
- $PROGRAM_ID
160
- anchor idl set-authority \
161
- --provider.cluster $RPC_URL \
162
- --provider.wallet $KEYPAIR \
163
- --program-id $PROGRAM_ID \
164
- --new-authority $MULTISIG
165
- ```
277
+ Anchor 1.1.2 stores canonical IDLs in the separate Program Metadata program. Its authority follows the
278
+ program upgrade authority; there is no separate `anchor idl set-authority` step. The sequence above initializes
279
+ the canonical IDL before transferring program authority. If Squads already holds authority,
280
+ perform the canonical metadata write through Squads as described below.
166
281
 
167
282
  `svm_spoke` also requires initialization and transfer of ownership on the first deployment:
168
283
 
@@ -224,35 +339,81 @@ solana program set-buffer-authority \
224
339
  --new-buffer-authority $MULTISIG
225
340
  ```
226
341
 
227
- Add the program ID to Squads multisig (`https://devnet.squads.so/` for devnet and `https://app.squads.so/` for mainnet) in the Developers/Programs section. Then add the upgrade filling in the buffer address and buffer refund. After creating the upgrade verify the buffer authority as prompted and proceed with initiating the upgrade. Once all required signers have approved, execute the upgrade in the transactions section.
342
+ Add the program ID to Squads multisig (`https://devnet.squads.so/` for devnet and `https://app.squads.so/` for mainnet) in the Developers/Programs section. Prepare the upgrade with the binary buffer address and refund recipient, and verify the buffer authority as prompted. Prepare the IDL update below before approving and executing the release.
228
343
 
229
- Start the IDL upgrade by writing it to the buffer:
344
+ Prepare an Anchor 1.1.2 Program Metadata buffer and transfer its authority to the Squads vault:
230
345
 
231
346
  ```shell
232
- anchor idl write-buffer \
347
+ anchor idl create-buffer \
233
348
  --provider.cluster $RPC_URL \
234
349
  --provider.wallet $KEYPAIR \
235
- --filepath target/idl/$PROGRAM.json \
236
- $PROGRAM_ID
237
- export IDL_BUFFER= # Export the logged IDL buffer address from the command above
238
- anchor idl set-authority \
350
+ --filepath target/idl/$PROGRAM.json
351
+ export IDL_BUFFER= # Export the logged metadata buffer address
352
+ anchor idl set-buffer-authority \
239
353
  --provider.cluster $RPC_URL \
240
354
  --provider.wallet $KEYPAIR \
241
- --program-id $PROGRAM_ID \
242
355
  --new-authority $MULTISIG \
243
356
  $IDL_BUFFER
244
357
  ```
245
358
 
246
- Construct the multisig transaction for finalizing the IDL upgrade. Copy the printed base58 encoded transaction from below command and import it into the Squads multisig for approval and execution:
359
+ Export the canonical IDL update using the official [Program Metadata CLI](https://github.com/solana-program/program-metadata#squads-multisig).
360
+ This replaces `scripts/svm/squadsIdlUpgrade.ts` for Anchor 1.1.2 programs:
247
361
 
248
362
  ```shell
249
- anchor run squadsIdlUpgrade -- \
250
- --programId $PROGRAM_ID \
251
- --idlBuffer $IDL_BUFFER \
252
- --multisig $MULTISIG \
253
- --closeRecipient $(solana address --keypair $KEYPAIR)
363
+ export IDL_REFUND_RECIPIENT=$(solana-keygen pubkey "$KEYPAIR") # Refund the operator that funded the IDL buffer
364
+ npx --yes @solana-program/program-metadata@0.10.0 write idl "$PROGRAM_ID" --rpc "$RPC_URL" --buffer "$IDL_BUFFER" --export "$MULTISIG" --export-encoding base58 --tx-version legacy --single-extend-per-tx --close-buffer "$IDL_REFUND_RECIPIENT"
254
365
  ```
255
366
 
367
+ `--export` prints unsigned transactions without submitting them. `$MULTISIG` must be the **Squads vault
368
+ PDA that holds program and buffer authority**, not the Squads multisig account. Transferring buffer
369
+ authority does not reimburse the operator: `--close-buffer` returns that buffer's rent to the operator
370
+ wallet above. The vault separately funds any canonical metadata account rent, so it needs sufficient
371
+ SOL. The command creates the canonical metadata account if absent, including the first upgrade from
372
+ Anchor 0.31, or updates it if it already exists.
373
+
374
+ For the **first upgrade from Anchor 0.31**, also prepare closure of the old canonical IDL while the
375
+ old binary still supports its dispatcher. Check its authority with the old CLI; it must match the
376
+ Squads vault used below. The legacy IDL authority is independent of the program upgrade authority.
377
+
378
+ ```shell
379
+ export LEGACY_ANCHOR="$HOME/.avm/bin/anchor-0.31.1"
380
+ "$LEGACY_ANCHOR" idl authority --provider.cluster "$RPC_URL" "$PROGRAM_ID"
381
+ export LEGACY_IDL_REFUND_RECIPIENT= # Set the reviewed recipient of the old canonical IDL's rent
382
+ yarn ts-node scripts/svm/squadsIdlUpgrade.ts --programId "$PROGRAM_ID" --multisig "$MULTISIG" --closeIdl --closeRecipient "$LEGACY_IDL_REFUND_RECIPIENT"
383
+ ```
384
+
385
+ This helper prints a single unsigned Base58 message containing only the legacy IDL close instruction.
386
+ Import it **before the binary upgrade instruction in the same Squads transaction**. It closes the old
387
+ canonical account, not the new Program Metadata buffer. Skip this step when no legacy IDL exists.
388
+ Coordinate client updates first: old `@coral-xyz/anchor` readers stop fetching that IDL after closure.
389
+
390
+ In Squads, use **Developers → Transaction Builder → Create Transaction → Add Instruction → Import as
391
+ Base58** to import each printed transaction. Review the program ID, canonical metadata account, vault
392
+ signer and buffer-rent recipient. Include the final IDL write and buffer closure with the binary upgrade
393
+ in one reviewed transaction where possible. Extra transactions can be needed to create or grow the
394
+ destination account; the uploaded buffer data does not need to be uploaded again. If the CLI prints
395
+ multiple transactions, retain their order; `--single-extend-per-tx` limits account growth to 10 KiB per
396
+ Squads execution. Execute any preparatory allocation/growth transactions before the final write, and do not combine those exports into
397
+ one transaction. Then collect the required approvals and execute the release. If the binary upgrade and
398
+ final IDL write must be separate, execute the IDL write immediately after the binary upgrade.
399
+
400
+ After execution, fetch the canonical IDL and compare its JSON content with the release artifact:
401
+
402
+ ```shell
403
+ anchor idl fetch --provider.cluster "$RPC_URL" --commitment finalized --out /tmp/deployed-idl.json "$PROGRAM_ID"
404
+ jq -S . "target/idl/$PROGRAM.json" > /tmp/release-idl.sorted.json
405
+ jq -S . /tmp/deployed-idl.json > /tmp/deployed-idl.sorted.json
406
+ diff -u /tmp/release-idl.sorted.json /tmp/deployed-idl.sorted.json
407
+ ```
408
+
409
+ Do not run `anchor idl write-buffer` directly from the operator wallet after Squads takes authority;
410
+ the vault must authorize that write. `scripts/svm/squadsIdlUpgrade.ts` encodes the old Anchor 0.31
411
+ dispatcher instructions and remains usable only for legacy deployments with Anchor 0.31.1. It does not
412
+ update Program Metadata accounts. Leaving the old IDL open does not block publication of the new one,
413
+ but old clients continue reading stale data. The upgraded binary has no legacy IDL dispatcher, so it
414
+ cannot update or close that account or recover its rent; doing so later would require another program
415
+ upgrade restoring that functionality. The sequence above avoids leaving that stale account behind.
416
+
256
417
  #### Verify
257
418
 
258
419
  Start with verifying locally that the deployed program matches the source code of the public repository:
@@ -262,7 +423,7 @@ solana-verify verify-from-repo \
262
423
  --url $RPC_URL \
263
424
  --program-id $PROGRAM_ID \
264
425
  --library-name $PROGRAM \
265
- --base-image "solanafoundation/solana-verifiable-build:$SOLANA_VERSION" \
426
+ --base-image "$BUILD_IMAGE" \
266
427
  https://github.com/across-protocol/contracts
267
428
  ```
268
429
 
@@ -273,7 +434,7 @@ solana-verify export-pda-tx \
273
434
  --url $RPC_URL \
274
435
  --program-id $PROGRAM_ID \
275
436
  --library-name $PROGRAM \
276
- --base-image "solanafoundation/solana-verifiable-build:$SOLANA_VERSION" \
437
+ --base-image "$BUILD_IMAGE" \
277
438
  --uploader $MULTISIG \
278
439
  https://github.com/across-protocol/contracts
279
440
  ```
@@ -38,9 +38,10 @@ contract Solana_Adapter is AdapterInterface, CircleCCTPAdapter {
38
38
  * @notice Minimum CCTP finality threshold at which Circle attests messages relayed to Solana.
39
39
  * @dev Circle attests "finalized" (2000) messages only after the source chain reached hard finality. The Solana
40
40
  * spoke pool only implements the finalized message handler, so any message attested below Circle's finalized
41
- * threshold could never be consumed. Kept configurable in case Circle redefines its threshold values.
41
+ * threshold could never be consumed.
42
+ * https://github.com/circlefin/evm-cctp-contracts/blob/63ab1f0ac06ce0793c0bbfbb8d09816bc211386d/src/v2/FinalityThresholds.sol#L21
42
43
  */
43
- uint32 public immutable CCTP_MIN_FINALITY_THRESHOLD;
44
+ uint32 public constant CCTP_MIN_FINALITY_THRESHOLD = 2000;
44
45
 
45
46
  // Solana spoke pool address, decoded from Base58 to bytes32.
46
47
  bytes32 public immutable SOLANA_SPOKE_POOL_BYTES32;
@@ -75,8 +76,6 @@ contract Solana_Adapter is AdapterInterface, CircleCCTPAdapter {
75
76
  * @param solanaSpokePool Solana spoke pool address, decoded from Base58 to bytes32.
76
77
  * @param solanaUsdc USDC mint address on Solana, decoded from Base58 to bytes32.
77
78
  * @param solanaSpokePoolUsdcVault USDC token address on Solana for the spoke pool, decoded from Base58 to bytes32.
78
- * @param _cctpMinFinalityThreshold Minimum CCTP finality threshold for relayed messages. Should be Circle's
79
- * finalized threshold (2000) as the Solana spoke pool only accepts finalized messages.
80
79
  */
81
80
  constructor(
82
81
  IERC20 _l1Usdc,
@@ -84,8 +83,7 @@ contract Solana_Adapter is AdapterInterface, CircleCCTPAdapter {
84
83
  IMessageTransmitterV2 _cctpMessageTransmitter,
85
84
  bytes32 solanaSpokePool,
86
85
  bytes32 solanaUsdc,
87
- bytes32 solanaSpokePoolUsdcVault,
88
- uint32 _cctpMinFinalityThreshold
86
+ bytes32 solanaSpokePoolUsdcVault
89
87
  ) CircleCCTPAdapter(_l1Usdc, _cctpTokenMessenger, CircleDomainIds.Solana) {
90
88
  // Solana adapter requires CCTP TokenMessenger and MessageTransmitter contracts to be set.
91
89
  if (address(_cctpTokenMessenger) == address(0)) {
@@ -96,7 +94,6 @@ contract Solana_Adapter is AdapterInterface, CircleCCTPAdapter {
96
94
  }
97
95
 
98
96
  cctpMessageTransmitter = _cctpMessageTransmitter;
99
- CCTP_MIN_FINALITY_THRESHOLD = _cctpMinFinalityThreshold;
100
97
 
101
98
  SOLANA_SPOKE_POOL_BYTES32 = solanaSpokePool;
102
99
  SOLANA_SPOKE_POOL_ADDRESS = solanaSpokePool.toAddressUnchecked();
@@ -35,8 +35,8 @@ contract HyperliquidDepositHandler is AcrossMessageHandler, ReentrancyGuard, Own
35
35
  // Address of the SpokePool contract that can call handleV3AcrossMessage.
36
36
  address public spokePool;
37
37
 
38
- // Track which accounts we have already sponsored for activation. Used to prevent griefing attacks when the same account is activated multiple times
39
- // due to Hyperliquid's policy of removing dust from small accounts which technically could be taken advantage of by a griefer.
38
+ // Track which accounts this contract has already activated. HyperCore accounts persist once created (Hyperliquid's
39
+ // dust removal only sweeps balances), so this acts as replay protection for the nonce-less activation signature.
40
40
  mapping(address => bool) public accountsActivated;
41
41
 
42
42
  // EIP-712 type hash for activation signatures
@@ -51,9 +51,13 @@ interface SpokePoolPeripheryInterface {
51
51
  // The account that can exclusively fill the deposit before the exclusivity parameter.
52
52
  bytes32 exclusiveRelayer;
53
53
  // Timestamp of the deposit used by system to charge fees. Must be within short window of time into the past
54
- // relative to this chain's current time or deposit will revert.
54
+ // relative to this chain's current time or deposit will revert. If this value is at most
55
+ // SpokePoolPeriphery.MAX_RELATIVE_TIME_SECONDS (one year), it is instead interpreted as an age in seconds
56
+ // which the periphery subtracts from block.timestamp; 0 therefore means "as of the current block".
55
57
  uint32 quoteTimestamp;
56
- // The timestamp on the destination chain after which this deposit can no longer be filled.
58
+ // The timestamp on the destination chain after which this deposit can no longer be filled. If this value is
59
+ // at most SpokePoolPeriphery.MAX_RELATIVE_TIME_SECONDS (one year), it is instead interpreted as an offset
60
+ // which the periphery adds to block.timestamp.
57
61
  uint32 fillDeadline;
58
62
  // The timestamp or offset on the destination chain after which anyone can fill the deposit. A detailed description on
59
63
  // how the parameter is interpreted by the V3 spoke pool can be found at https://github.com/across-protocol/contracts/blob/fa67f5e97eabade68c67127f2261c2d44d9b007e/contracts/SpokePool.sol#L476
@@ -122,8 +126,10 @@ interface SpokePoolPeripheryInterface {
122
126
  * @param exclusiveRelayer Address (as bytes32) of the relayer who has exclusive rights to fill this deposit. Can be set to
123
127
  * 0x0 if no period is desired. If so, then must set exclusivityParameter to 0.
124
128
  * @param quoteTimestamp Timestamp used by relayers to compute this deposit's realizedLPFeePct which is paid
125
- * to LP pool on HubPool.
126
- * @param fillDeadline Timestamp after which this deposit can no longer be filled.
129
+ * to LP pool on HubPool. Values at or below SpokePoolPeriphery.MAX_RELATIVE_TIME_SECONDS (one year) are interpreted as
130
+ * an age in seconds subtracted from block.timestamp.
131
+ * @param fillDeadline Timestamp after which this deposit can no longer be filled. Values at or below
132
+ * SpokePoolPeriphery.MAX_RELATIVE_TIME_SECONDS (one year) are interpreted as an offset added to block.timestamp.
127
133
  * @param exclusivityParameter Timestamp or offset, after which any relayer can fill this deposit. Must set
128
134
  * to 0 if exclusiveRelayer is set to 0x0, and vice versa.
129
135
  * @param message Arbitrary data that can be used to pass additional information to the recipient along with the tokens.
@@ -159,6 +165,9 @@ interface SpokePoolPeripheryInterface {
159
165
  * @dev If the swapToken does not implement `permit` to the specifications of EIP-2612, the permit call result will be ignored and the function will continue.
160
166
  * @dev If the swapToken in swapData does not implement `permit` to the specifications of EIP-2612, this function will fail.
161
167
  * @dev The nonce for the swapAndDepositData signature must be retrieved from permitNonces(signatureOwner).
168
+ * @dev `deadline` is bound into the swapAndDepositData signature as well as the permit, and is checked here.
169
+ * `permit` is called inside a try/catch, so an expired ERC-2612 signature alone would not stop a
170
+ * standing allowance from funding the pull; this check is what bounds the payload's lifetime.
162
171
  * @dev Design Decision: We use separate nonce tracking for permit-based functions versus
163
172
  * receiveWithAuthorization-based functions, which creates a theoretical replay attack that we think is
164
173
  * incredibly unlikely because this would require:
@@ -248,6 +257,9 @@ interface SpokePoolPeripheryInterface {
248
257
  * @dev If the token does not implement `permit` to the specifications of EIP-2612, the permit call result will be ignored and the function will continue.
249
258
  * @dev If `acrossInputToken` does not implement `permit` to the specifications of EIP-2612, this function will fail.
250
259
  * @dev The nonce for the depositData signature must be retrieved from permitNonces(signatureOwner).
260
+ * @dev `deadline` is bound into the depositData signature as well as the permit, and is checked here.
261
+ * `permit` is called inside a try/catch, so an expired ERC-2612 signature alone would not stop a
262
+ * standing allowance from funding the pull; this check is what bounds the payload's lifetime.
251
263
  * @dev Design Decision: We use separate nonce tracking for permit-based functions versus
252
264
  * receiveWithAuthorization-based functions, which creates a theoretical replay attack that we think is
253
265
  * incredibly unlikely because this would require:
@@ -53,10 +53,23 @@ library HyperCoreLib {
53
53
  address public constant TOKEN_INFO_PRECOMPILE_ADDRESS = 0x000000000000000000000000000000000000080C;
54
54
  address public constant CORE_WRITER_PRECOMPILE_ADDRESS = 0x3333333333333333333333333333333333333333;
55
55
 
56
- // USDC
56
+ // USDC. Circle's CoreDepositWallet is deployed at a different address on mainnet and testnet.
57
57
  address public constant USDC_CORE_DEPOSIT_WALLET_ADDRESS = 0x6B9E773128f453f5c2C60935Ee2DE2CBc5390A24;
58
+ address public constant USDC_CORE_DEPOSIT_WALLET_ADDRESS_TESTNET = 0x0B80659a4076E9E93C7DbE0f10675A16a3e5C206;
58
59
  uint64 public constant USDC_CORE_INDEX = 0;
59
60
 
61
+ // Native HYPE. Unlike every other token, HYPE bridges through a fixed system address rather than one
62
+ // derived from its Core index, and that index differs between mainnet and testnet.
63
+ address public constant HYPE_SYSTEM_ADDRESS = 0x2222222222222222222222222222222222222222;
64
+ uint32 public constant HYPE_CORE_INDEX = 150;
65
+ uint32 public constant HYPE_CORE_INDEX_TESTNET = 1105;
66
+ // HYPE has 18 decimals on HyperEVM and 8 on HyperCore, so only EVM amounts aligned to 1e10 wei are representable
67
+ int8 public constant HYPE_DECIMAL_DIFF = 10;
68
+
69
+ // HyperEVM chain ids. The precompiles and CoreWriter below only exist on these chains.
70
+ uint256 public constant HYPEREVM_CHAIN_ID = 999;
71
+ uint256 public constant HYPEREVM_TESTNET_CHAIN_ID = 998;
72
+
60
73
  // CoreWriter action headers
61
74
  bytes4 public constant LIMIT_ORDER_HEADER = 0x01000001; // version=1, action=1
62
75
  bytes4 public constant SPOT_SEND_HEADER = 0x01000006; // version=1, action=6
@@ -75,7 +88,9 @@ library HyperCoreLib {
75
88
  error TokenInfoPrecompileCallFailed();
76
89
  error SpotPxPrecompileCallFailed();
77
90
  error InsufficientAmountForAccountActivation();
78
- error MaximumEVMSendAmountTooLarge();
91
+ error TokenNotBridgeable(uint64 erc20CoreIndex);
92
+ error NativeTransferFailed();
93
+ error UnsupportedChain();
79
94
 
80
95
  /**
81
96
  * @notice Transfer `amountEVM` from HyperEVM to `to` on HyperCore.
@@ -106,18 +121,15 @@ library HyperCoreLib {
106
121
  if (_amountEVMToSend != 0) {
107
122
  if (erc20CoreIndex == USDC_CORE_INDEX) {
108
123
  // USDC flow takes care of account creation fee for us, we don't need to reduce `_amountEVMToSend`
109
- IERC20(erc20EVMAddress).forceApprove(USDC_CORE_DEPOSIT_WALLET_ADDRESS, _amountEVMToSend);
124
+ ICoreDepositWallet depositWallet = usdcCoreDepositWallet();
125
+ IERC20(erc20EVMAddress).forceApprove(address(depositWallet), _amountEVMToSend);
110
126
  if (to == address(this)) {
111
- ICoreDepositWallet(USDC_CORE_DEPOSIT_WALLET_ADDRESS).deposit(_amountEVMToSend, destinationDex);
127
+ depositWallet.deposit(_amountEVMToSend, destinationDex);
112
128
  } else {
113
- ICoreDepositWallet(USDC_CORE_DEPOSIT_WALLET_ADDRESS).depositFor(
114
- to,
115
- _amountEVMToSend,
116
- destinationDex
117
- );
129
+ depositWallet.depositFor(to, _amountEVMToSend, destinationDex);
118
130
  }
119
131
  } else {
120
- IERC20(erc20EVMAddress).safeTransfer(toAssetBridgeAddress(erc20CoreIndex), _amountEVMToSend);
132
+ IERC20(erc20EVMAddress).safeTransfer(toSystemAddress(erc20CoreIndex), _amountEVMToSend);
121
133
  // Transfer the tokens from this contract on HyperCore to the `to` address on HyperCore
122
134
  if (to != address(this) || destinationDex != CORE_SPOT_DEX_ID) {
123
135
  transferERC20CoreToCore(
@@ -192,6 +204,25 @@ library HyperCoreLib {
192
204
  );
193
205
  }
194
206
 
207
+ /**
208
+ * @notice Bridges up to `amountEVM` of native HYPE from this address on HyperEVM to this address on HyperCore.
209
+ * @dev A native transfer to the HYPE system address credits the sender's spot HYPE on Core. Core only credits
210
+ * whole multiples of 1e10 wei and silently drops the remainder, so, like the ERC20 path, this rounds the
211
+ * amount down before sending and leaves the dust in the calling contract. Sends nothing if the aligned
212
+ * amount is zero.
213
+ * @param amountEVM The maximum amount of native HYPE to transfer, in EVM wei.
214
+ * @return amountEVMSent The amount actually sent on HyperEVM, in wei
215
+ * @return amountCoreToReceive The amount credited on Core, in Core units
216
+ */
217
+ function transferNativeEVMToSelfOnSpot(
218
+ uint256 amountEVM
219
+ ) internal returns (uint256 amountEVMSent, uint64 amountCoreToReceive) {
220
+ (amountEVMSent, amountCoreToReceive) = maximumEVMSendAmountToAmounts(amountEVM, HYPE_DECIMAL_DIFF);
221
+ if (amountEVMSent == 0) return (0, 0);
222
+ (bool success, ) = HYPE_SYSTEM_ADDRESS.call{ value: amountEVMSent }("");
223
+ if (!success) revert NativeTransferFailed();
224
+ }
225
+
195
226
  /**
196
227
  * @notice Transfers tokens from this contract on HyperCore to the `to` address on HyperCore on the Spot DEX.
197
228
  * @param erc20CoreIndex The HyperCore index id of the token
@@ -245,10 +276,11 @@ library HyperCoreLib {
245
276
  uint256 amountEVM
246
277
  ) internal {
247
278
  if (erc20CoreIndex == USDC_CORE_INDEX) {
248
- IERC20(erc20EVMAddress).forceApprove(USDC_CORE_DEPOSIT_WALLET_ADDRESS, amountEVM);
249
- ICoreDepositWallet(USDC_CORE_DEPOSIT_WALLET_ADDRESS).depositFor(user, amountEVM, CORE_SPOT_DEX_ID);
279
+ ICoreDepositWallet depositWallet = usdcCoreDepositWallet();
280
+ IERC20(erc20EVMAddress).forceApprove(address(depositWallet), amountEVM);
281
+ depositWallet.depositFor(user, amountEVM, CORE_SPOT_DEX_ID);
250
282
  } else {
251
- IERC20(erc20EVMAddress).safeTransfer(toAssetBridgeAddress(erc20CoreIndex), amountEVM);
283
+ IERC20(erc20EVMAddress).safeTransfer(toSystemAddress(erc20CoreIndex), amountEVM);
252
284
  // Transfer 1 wei to user on HyperCore to activate account
253
285
  transferERC20CoreToCore(erc20CoreIndex, user, 1, CORE_SPOT_DEX_ID, CORE_SPOT_DEX_ID);
254
286
  }
@@ -353,6 +385,40 @@ library HyperCoreLib {
353
385
  return _tokenInfo;
354
386
  }
355
387
 
388
+ /**
389
+ * @notice Whether the current chain is HyperEVM (mainnet or testnet), and therefore whether the HyperCore
390
+ * precompiles and CoreWriter this library reads and writes actually exist.
391
+ * @return True on HyperEVM mainnet or testnet, false otherwise
392
+ */
393
+ function isHyperEVMChain() internal view returns (bool) {
394
+ return block.chainid == HYPEREVM_CHAIN_ID || block.chainid == HYPEREVM_TESTNET_CHAIN_ID;
395
+ }
396
+
397
+ /**
398
+ * @notice The Core index of native HYPE on the current chain.
399
+ * @dev Differs between mainnet and testnet, so it cannot be a plain constant at the call site. Reverts off
400
+ * HyperEVM rather than defaulting, since the index has no meaning there.
401
+ * @return The HyperCore index id of native HYPE
402
+ */
403
+ function hypeCoreIndex() internal view returns (uint32) {
404
+ if (block.chainid == HYPEREVM_CHAIN_ID) return HYPE_CORE_INDEX;
405
+ if (block.chainid == HYPEREVM_TESTNET_CHAIN_ID) return HYPE_CORE_INDEX_TESTNET;
406
+ revert UnsupportedChain();
407
+ }
408
+
409
+ /**
410
+ * @notice Circle's USDC CoreDepositWallet on the current chain.
411
+ * @dev Differs between mainnet and testnet; the mainnet address has no code on testnet, so using it there
412
+ * would revert every USDC bridge and account activation. Reverts off HyperEVM rather than defaulting.
413
+ * @return The CoreDepositWallet to approve and deposit USDC through
414
+ */
415
+ function usdcCoreDepositWallet() internal view returns (ICoreDepositWallet) {
416
+ if (block.chainid == HYPEREVM_CHAIN_ID) return ICoreDepositWallet(USDC_CORE_DEPOSIT_WALLET_ADDRESS);
417
+ if (block.chainid == HYPEREVM_TESTNET_CHAIN_ID)
418
+ return ICoreDepositWallet(USDC_CORE_DEPOSIT_WALLET_ADDRESS_TESTNET);
419
+ revert UnsupportedChain();
420
+ }
421
+
356
422
  /**
357
423
  * @notice Checks if an amount is safe to bridge from HyperEVM to HyperCore
358
424
  * @dev Verifies that the asset bridge has sufficient balance to cover the amount plus a buffer
@@ -366,20 +432,47 @@ library HyperCoreLib {
366
432
  uint64 coreAmount,
367
433
  uint64 coreBufferAmount
368
434
  ) internal view returns (bool) {
369
- address bridgeAddress = toAssetBridgeAddress(erc20CoreIndex);
370
- uint64 currentBridgeBalance = spotBalance(bridgeAddress, erc20CoreIndex);
435
+ // A predicate answers rather than reverts: an unbridgeable token is simply not safe to bridge, so the fill
436
+ // path keeps its HyperEVM fallback instead of failing.
437
+ (address systemAddress, bool bridgeable) = tryToSystemAddress(erc20CoreIndex);
438
+ if (!bridgeable) return false;
371
439
 
372
440
  // Return true if currentBridgeBalance >= coreAmount + coreBufferAmount
373
- return currentBridgeBalance >= coreAmount + coreBufferAmount;
441
+ return spotBalance(systemAddress, erc20CoreIndex) >= coreAmount + coreBufferAmount;
442
+ }
443
+
444
+ /**
445
+ * @notice Resolves a core index id to its system address, the bridge account shared by both chains. On HyperEVM,
446
+ * a transfer to it credits the sender's spot balance on HyperCore; on HyperCore, a spot send to it
447
+ * credits the sender's balance on HyperEVM.
448
+ * @dev Reverts if the token is not bridgeable, since a send to such an address would strand the funds. For a
449
+ * non-reverting answer, use `tryToSystemAddress`.
450
+ * @param erc20CoreIndex The core token index id to convert
451
+ * @return The token's system address, valid as a destination on either chain
452
+ */
453
+ function toSystemAddress(uint64 erc20CoreIndex) internal view returns (address) {
454
+ (address systemAddress, bool bridgeable) = tryToSystemAddress(erc20CoreIndex);
455
+ if (!bridgeable) revert TokenNotBridgeable(erc20CoreIndex);
456
+ return systemAddress;
374
457
  }
375
458
 
376
459
  /**
377
- * @notice Converts a core index id to an asset bridge address
460
+ * @notice `toSystemAddress` that reports bridgeability instead of reverting on it.
461
+ * @dev Native HYPE uses a fixed system address and is always bridgeable; every other token derives one from
462
+ * its Core index and is bridgeable only if linked to a HyperEVM contract. Still reverts if the tokenInfo
463
+ * precompile call itself fails, like every other precompile read in this library.
378
464
  * @param erc20CoreIndex The core token index id to convert
379
- * @return assetBridgeAddress The asset bridge address
465
+ * @return systemAddress The token's system address, valid as a destination on either chain
466
+ * @return bridgeable False if a send to `systemAddress` would not be credited on the other side
380
467
  */
381
- function toAssetBridgeAddress(uint64 erc20CoreIndex) internal pure returns (address) {
382
- return address(uint160(BASE_ASSET_BRIDGE_ADDRESS_UINT256 + erc20CoreIndex));
468
+ function tryToSystemAddress(uint64 erc20CoreIndex) internal view returns (address systemAddress, bool bridgeable) {
469
+ // A uint64 above the uint32 domain can never equal the uint32 HYPE index, so no range check is needed
470
+ if (erc20CoreIndex == hypeCoreIndex()) return (HYPE_SYSTEM_ADDRESS, true);
471
+ systemAddress = address(uint160(BASE_ASSET_BRIDGE_ADDRESS_UINT256 + erc20CoreIndex));
472
+ // Only linked tokens convert between Core and EVM (docs: "HyperCore <> HyperEVM transfers"), and
473
+ // linkage resolves via tokenInfo, declared `tokenInfo(uint32)` in canonical L1Read.sol — an id
474
+ // beyond that domain (spotBalance's uint64 also carries encoded outcome asset ids) can't be resolved.
475
+ bridgeable = erc20CoreIndex <= type(uint32).max && tokenInfo(uint32(erc20CoreIndex)).evmContract != address(0);
383
476
  }
384
477
 
385
478
  /**