@across-protocol/contracts 6.0.0-beta.2 → 6.0.0-beta.3
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/README.md +138 -34
- package/contracts/chain-adapters/Solana_Adapter.sol +4 -7
- package/contracts/handlers/HyperliquidDepositHandler.sol +2 -2
- package/contracts/interfaces/SpokePoolPeripheryInterface.sol +16 -4
- package/contracts/libraries/HyperCoreLib.sol +113 -20
- package/contracts/libraries/PeripherySigningLib.sol +56 -0
- package/contracts/periphery/SpokePoolPeriphery.sol +58 -10
- package/dist/broadcast/deployed-addresses.json +19 -0
- package/dist/evm/artifacts/Constants.sol/Constants.json +1 -1
- package/dist/evm/artifacts/DeploymentUtils.sol/DeploymentUtils.json +1 -1
- package/dist/evm/artifacts/DstOFTHandler.sol/DstOFTHandler.json +1 -1
- package/dist/evm/artifacts/HubPoolTestBase.sol/MockAddressWhitelist.json +1 -1
- package/dist/evm/artifacts/HubPoolTestBase.sol/MockFinder.json +1 -1
- package/dist/evm/artifacts/HubPoolTestBase.sol/MockIdentifierWhitelist.json +1 -1
- package/dist/evm/artifacts/HubPoolTestBase.sol/MockLpTokenFactory.json +1 -1
- package/dist/evm/artifacts/HubPoolTestBase.sol/MockOptimisticOracle.json +1 -1
- package/dist/evm/artifacts/HubPoolTestBase.sol/MockStore.json +1 -1
- package/dist/evm/artifacts/HyperCoreFlowExecutor.sol/HyperCoreFlowExecutor.json +1 -1
- package/dist/evm/artifacts/HyperCoreLib.sol/HyperCoreLib.json +1 -1
- package/dist/evm/artifacts/HyperliquidDepositHandler.sol/HyperliquidDepositHandler.json +1 -1
- package/dist/evm/artifacts/PeripherySigningLib.sol/PeripherySigningLib.json +1 -1
- package/dist/evm/artifacts/Solana_Adapter.sol/Solana_Adapter.json +1 -1
- package/dist/evm/artifacts/SpokePoolPeriphery.sol/SpokePoolPeriphery.json +1 -1
- package/dist/evm/artifacts/SpokePoolPeriphery.sol/SwapProxy.json +1 -1
- package/dist/evm/artifacts/SponsoredCCTPDstPeriphery.sol/SponsoredCCTPDstPeriphery.json +1 -1
- package/dist/evm/artifacts/SponsoredCCTPSrcPeriphery.sol/SponsoredCCTPSrcPeriphery.json +1 -1
- package/dist/evm/artifacts/SponsoredOFTSrcPeriphery.sol/SponsoredOFTSrcPeriphery.json +1 -1
- package/dist/evm/artifacts/SwapHandler.sol/SwapHandler.json +1 -1
- package/dist/evm/artifacts/Tron_SpokePoolPeriphery.sol/Tron_SpokePoolPeriphery.json +1 -1
- package/dist/evm/artifacts/Tron_SpokePoolPeriphery.sol/Tron_SwapProxy.json +1 -1
- package/dist/src/consts.js +1 -0
- package/dist/src/svm/assets/idl/sponsored_cctp_src_periphery.json +41 -24
- package/dist/src/svm/assets/idl/svm_spoke.json +1001 -2171
- package/dist/src/svm/assets/sponsored_cctp_src_periphery.d.ts +41 -24
- package/dist/src/svm/assets/svm_spoke.d.ts +996 -2166
- package/dist/src/svm/assets/token_messenger_minter_v2.d.ts +18 -18
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/index.d.ts +0 -1
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/index.js +0 -1
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/errors/sponsoredCctpSrcPeriphery.d.ts +24 -12
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/errors/sponsoredCctpSrcPeriphery.js +30 -12
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/programs/sponsoredCctpSrcPeriphery.d.ts +4 -5
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/programs/sponsoredCctpSrcPeriphery.js +4 -8
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/index.d.ts +1 -0
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/index.js +1 -0
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/messageSent.d.ts +21 -0
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/types/messageSent.js +30 -0
- package/dist/src/svm/clients/SvmSpoke/accounts/fillStatusAccount.d.ts +2 -2
- package/dist/src/svm/clients/SvmSpoke/accounts/fillStatusAccount.js +2 -2
- package/dist/src/svm/clients/SvmSpoke/accounts/index.d.ts +0 -3
- package/dist/src/svm/clients/SvmSpoke/accounts/index.js +0 -3
- package/dist/src/svm/clients/SvmSpoke/errors/svmSpoke.d.ts +94 -22
- package/dist/src/svm/clients/SvmSpoke/errors/svmSpoke.js +133 -24
- package/dist/src/svm/clients/SvmSpoke/instructions/adapterExecuteAcrossV5.d.ts +75 -0
- package/dist/src/svm/clients/SvmSpoke/instructions/adapterExecuteAcrossV5.js +144 -0
- package/dist/src/svm/clients/SvmSpoke/instructions/closeFillPda.d.ts +16 -8
- package/dist/src/svm/clients/SvmSpoke/instructions/closeFillPda.js +3 -3
- package/dist/src/svm/clients/SvmSpoke/instructions/index.d.ts +2 -7
- package/dist/src/svm/clients/SvmSpoke/instructions/index.js +2 -7
- package/dist/src/svm/clients/SvmSpoke/instructions/withdrawV5FillPayer.d.ts +58 -0
- package/dist/src/svm/clients/SvmSpoke/instructions/withdrawV5FillPayer.js +134 -0
- package/dist/src/svm/clients/SvmSpoke/programs/svmSpoke.d.ts +29 -47
- package/dist/src/svm/clients/SvmSpoke/programs/svmSpoke.js +29 -61
- package/dist/src/svm/clients/SvmSpoke/types/acrossDepositInput.d.ts +25 -0
- package/dist/src/svm/clients/SvmSpoke/types/acrossDepositInput.js +33 -0
- package/dist/src/svm/clients/SvmSpoke/types/acrossDepositJitParams.d.ts +18 -0
- package/dist/src/svm/clients/SvmSpoke/types/acrossDepositJitParams.js +30 -0
- package/dist/src/svm/clients/SvmSpoke/types/acrossDepositParams.d.ts +43 -0
- package/dist/src/svm/clients/SvmSpoke/types/acrossDepositParams.js +48 -0
- package/dist/src/svm/clients/SvmSpoke/types/index.d.ts +9 -1
- package/dist/src/svm/clients/SvmSpoke/types/index.js +9 -1
- package/dist/src/svm/clients/SvmSpoke/types/v5AdapterInput.d.ts +39 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5AdapterInput.js +59 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5DepositModificationRules.d.ts +17 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5DepositModificationRules.js +30 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5FillFloatWithdrawn.d.ts +19 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5FillFloatWithdrawn.js +28 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5FillInput.d.ts +25 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5FillInput.js +30 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5FillJit.d.ts +22 -0
- package/dist/src/svm/clients/SvmSpoke/types/{slowFill.js → v5FillJit.js} +11 -11
- package/dist/src/svm/clients/SvmSpoke/types/v5InputAmountMode.d.ts +29 -0
- package/dist/src/svm/clients/SvmSpoke/types/v5InputAmountMode.js +38 -0
- package/dist/src/svm/web3-v1/cctpV2Helpers.d.ts +83 -97
- package/dist/src/svm/web3-v1/cctpV2Helpers.js +1 -1
- package/dist/src/svm/web3-v1/coders.d.ts +1 -1
- package/dist/src/svm/web3-v1/coders.js +4 -4
- package/dist/src/svm/web3-v1/conversionUtils.d.ts +1 -1
- package/dist/src/svm/web3-v1/conversionUtils.js +3 -3
- package/dist/src/svm/web3-v1/helpers.d.ts +1 -114
- package/dist/src/svm/web3-v1/helpers.js +1 -179
- package/dist/src/svm/web3-v1/instructionParamsUtils.d.ts +11 -26
- package/dist/src/svm/web3-v1/instructionParamsUtils.js +5 -90
- package/dist/src/svm/web3-v1/programConnectors.d.ts +1 -1
- package/dist/src/svm/web3-v1/programConnectors.js +2 -2
- package/dist/src/svm/web3-v1/relayHashUtils.d.ts +2 -6
- package/dist/src/svm/web3-v1/relayHashUtils.js +5 -66
- package/dist/src/svm/web3-v1/solanaProgramUtils.d.ts +1 -1
- package/dist/src/svm/web3-v1/solanaProgramUtils.js +7 -7
- package/dist/src/svm/web3-v1/transactionUtils.js +3 -3
- package/dist/src/svm/web3-v2/solanaProgramUtils.d.ts +1 -1
- package/dist/src/svm/web3-v2/solanaProgramUtils.js +4 -4
- package/dist/src/types/svm.d.ts +1 -46
- package/package.json +17 -6
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/messageSent.d.ts +0 -30
- package/dist/src/svm/clients/SponsoredCctpSrcPeriphery/accounts/messageSent.js +0 -66
- package/dist/src/svm/clients/SvmSpoke/accounts/executeSlowRelayLeafParams.d.ts +0 -31
- package/dist/src/svm/clients/SvmSpoke/accounts/executeSlowRelayLeafParams.js +0 -70
- package/dist/src/svm/clients/SvmSpoke/accounts/fillRelayParams.d.ts +0 -31
- package/dist/src/svm/clients/SvmSpoke/accounts/fillRelayParams.js +0 -67
- package/dist/src/svm/clients/SvmSpoke/accounts/requestSlowFillParams.d.ts +0 -27
- package/dist/src/svm/clients/SvmSpoke/accounts/requestSlowFillParams.js +0 -66
- package/dist/src/svm/clients/SvmSpoke/instructions/deposit.d.ts +0 -131
- package/dist/src/svm/clients/SvmSpoke/instructions/deposit.js +0 -241
- package/dist/src/svm/clients/SvmSpoke/instructions/depositNow.d.ts +0 -127
- package/dist/src/svm/clients/SvmSpoke/instructions/depositNow.js +0 -239
- package/dist/src/svm/clients/SvmSpoke/instructions/executeSlowRelayLeaf.d.ts +0 -104
- package/dist/src/svm/clients/SvmSpoke/instructions/executeSlowRelayLeaf.js +0 -259
- package/dist/src/svm/clients/SvmSpoke/instructions/fillRelay.d.ts +0 -108
- package/dist/src/svm/clients/SvmSpoke/instructions/fillRelay.js +0 -265
- package/dist/src/svm/clients/SvmSpoke/instructions/getUnsafeDepositId.d.ts +0 -39
- package/dist/src/svm/clients/SvmSpoke/instructions/getUnsafeDepositId.js +0 -63
- package/dist/src/svm/clients/SvmSpoke/instructions/requestSlowFill.d.ts +0 -76
- package/dist/src/svm/clients/SvmSpoke/instructions/requestSlowFill.js +0 -187
- package/dist/src/svm/clients/SvmSpoke/instructions/unsafeDeposit.d.ts +0 -135
- package/dist/src/svm/clients/SvmSpoke/instructions/unsafeDeposit.js +0 -243
- package/dist/src/svm/clients/SvmSpoke/types/slowFill.d.ts +0 -22
- package/dist/target/types/svm_spoke.d.ts +0 -5106
- package/dist/target/types/svm_spoke.js +0 -2
package/README.md
CHANGED
|
@@ -23,9 +23,16 @@ 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
|
|
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
|
-
|
|
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.
|
|
29
36
|
|
|
30
37
|
## Build
|
|
31
38
|
|
|
@@ -39,6 +46,15 @@ EVM builds and tests use the Foundry version pinned in `.foundry-version`; CI in
|
|
|
39
46
|
`foundry-rs/foundry-toolchain`. Run `yarn pin-foundry` to switch your local toolchain to it (a no-op when it already
|
|
40
47
|
matches). Bump the pin by editing that file.
|
|
41
48
|
|
|
49
|
+
SVM local, verified, and real-Gateway builds fail on stack-overflow diagnostics even when the compiler exits
|
|
50
|
+
successfully. The shared guard is `scripts/svm/buildHelpers/runSbfBuild.sh`; run `yarn test-svm-build-guard` to test it
|
|
51
|
+
without a validator or Rust build. CI invalidates cached SVM builds when these build helpers change.
|
|
52
|
+
Host IDL generation and Rust tests use Rust 1.97.1, pinned in the SVM setup action; use that version locally
|
|
53
|
+
when reproducing CI artifacts. CI installs Agave, Anchor and `solana-verify` with
|
|
54
|
+
`scripts/svm/buildHelpers/installSvmTools.sh`, which checks the Linux x86_64 release assets against the
|
|
55
|
+
SHA-256 pins in `verified-build.json` on fresh downloads and cache hits alike. These host tools are separate from the
|
|
56
|
+
release image's SBF compiler.
|
|
57
|
+
|
|
42
58
|
## Test
|
|
43
59
|
|
|
44
60
|
```shell
|
|
@@ -49,8 +65,13 @@ yarn test:report-gas # Run unit tests with gas reporting enabled
|
|
|
49
65
|
yarn test-evm # Only test EVM code
|
|
50
66
|
yarn test-svm # Only test SVM code (local toolchain build)
|
|
51
67
|
yarn test-svm-solana-verify # Only test SVM code (verified docker build)
|
|
68
|
+
yarn typecheck-tests # Typecheck all TypeScript tests without emitting files
|
|
52
69
|
```
|
|
53
70
|
|
|
71
|
+
The test typecheck uses `tsconfig.test.json` and requires generated clients and test-feature IDLs. Run
|
|
72
|
+
`yarn generate-svm-artifacts && yarn generate-svm-test-idls` first. CI runs this check after preparing these artifacts,
|
|
73
|
+
before the verified SVM build and runtime tests. The package build continues to use `tsconfig.json`.
|
|
74
|
+
|
|
54
75
|
## Lint
|
|
55
76
|
|
|
56
77
|
```shell
|
|
@@ -94,9 +115,51 @@ yarn forge-script-zksync script/016DeployZkSyncSpokePool.s.sol:DeployZkSyncSpoke
|
|
|
94
115
|
|
|
95
116
|
For CCTP V2 root/admin finalization, pause recovery and light-chain intent examples, see the [Solana operational scripts guide](scripts/svm/README.md).
|
|
96
117
|
|
|
118
|
+
V5 `svm_spoke` is configured for mainnet and local-validator testing. Its public-devnet deployment and supporting
|
|
119
|
+
offchain infrastructure are not configured, so `Anchor.toml` has no devnet Spoke entry. The devnet deployment examples
|
|
120
|
+
below require a separately configured deployment; the legacy devnet Spoke address is not a V5 target.
|
|
121
|
+
|
|
97
122
|
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
123
|
|
|
99
|
-
|
|
124
|
+
V5 PDA addresses and bumps are pinned to the configured Spoke and Gateway IDs to avoid runtime derivation costs.
|
|
125
|
+
If either program ID changes, update its dependent PDA constants and run `cargo test -p svm-spoke --lib` to check consistency.
|
|
126
|
+
|
|
127
|
+
Use `solana-verify` 0.5.1, matching CI, to build the verified Docker binaries. The build removes each
|
|
128
|
+
previous binary before compilation and rejects missing or empty output; failed builds must not be used for deployment.
|
|
129
|
+
Keep the stack-diagnostic guard enabled, since SBF compilers can report stack overflows with a successful exit status.
|
|
130
|
+
On Linux, Docker can leave `target/deploy` owned by root. If the next verified build reports a permissions error,
|
|
131
|
+
restore ownership from the repository root with `sudo chown -R "$(id -u):$(id -g)" target/deploy`, then rerun the build.
|
|
132
|
+
|
|
133
|
+
`verified-build.json` pins the release image by immutable digest: Agave 4.0.3,
|
|
134
|
+
`cargo-build-sbf` 4.0.0, platform-tools 1.53, and SBF architecture `v0`. This release recipe is separate
|
|
135
|
+
from the Agave 4.1.2 validator/development toolchain. It was selected because the pinned verifier's
|
|
136
|
+
0.5.1 image registry did not include Agave 4.1.2. Newer upstream images exist; updating this recipe
|
|
137
|
+
requires rebuilding and testing the release binaries. Never infer the image from Solana SDK crate versions.
|
|
138
|
+
`yarn test-svm-solana-verify` runs the full suite against **test-feature** binaries: it retains the
|
|
139
|
+
mocked clock and per-test state seeds. `yarn test-svm-production` then rebuilds without that feature
|
|
140
|
+
and tests seed-zero initialization, disabled test controls, Clock-sysvar expiry and event self-CPI
|
|
141
|
+
in a fresh ledger. Deploy only the latter production artifacts; a test-feature build overwrites
|
|
142
|
+
`target/deploy` and must never be deployed.
|
|
143
|
+
|
|
144
|
+
Validator tests share `test/svm/provider.ts`, which sets the connection, transaction confirmation and
|
|
145
|
+
preflight commitments to `confirmed`. Use this provider for fixture writes and dependent transactions
|
|
146
|
+
so simulations cannot run against a bank that predates the fixture state.
|
|
147
|
+
|
|
148
|
+
All workspace programs use Anchor 1.1.2. The Spoke retains the pre-upgrade V5 branch's custom error numbers;
|
|
149
|
+
its IDL now exposes all four ranges from one enum. Sponsored CCTP's formerly overlapping enums
|
|
150
|
+
now use Common 6000–6002, SVM 7000–7010 and CCTP 8000–8002. This changes error numbers in a **new**
|
|
151
|
+
Sponsored CCTP build, not its existing deployment. Upgrading the source does not require redeploying
|
|
152
|
+
retiring Sponsored CCTP or multicall programs.
|
|
153
|
+
The bundled Sponsored CCTP IDL/client error tables describe that new build, not the existing deployment.
|
|
154
|
+
For live or historical transactions from the old deployment, use the error name in the program logs and
|
|
155
|
+
the matching release artifacts; numeric codes alone are ambiguous across its old enums.
|
|
156
|
+
|
|
157
|
+
Before an audited release, build from a clean checkout of the reviewed commit and record the commit,
|
|
158
|
+
`Cargo.lock`, `verified-build.json`, enabled features (none for production), program IDs and executable
|
|
159
|
+
hashes. Release Cargo profiles use `lto = "fat"`, one codegen unit, and overflow checks.
|
|
160
|
+
The lockfile pins the SBF dependency graph, including the Solana hash/secp256k1 crates.
|
|
161
|
+
Verify reproducibility by comparing executable hashes; matching CLI versions alone does not prove
|
|
162
|
+
byte-identical builds.
|
|
100
163
|
|
|
101
164
|
```shell
|
|
102
165
|
unset IS_TEST # Ensures the production build is used (not the test feature)
|
|
@@ -112,7 +175,7 @@ export KEYPAIR=~/.config/solana/dev-wallet.json
|
|
|
112
175
|
export PROGRAM=svm_spoke # Also repeat the deployment process for multicall_handler
|
|
113
176
|
export PROGRAM_ID=$(cat target/idl/$PROGRAM.json | jq -r ".address")
|
|
114
177
|
export MULTISIG= # Export the Squads vault, not the multisig address!
|
|
115
|
-
export
|
|
178
|
+
export BUILD_IMAGE=$(node -p 'require("./verified-build.json").image')
|
|
116
179
|
```
|
|
117
180
|
|
|
118
181
|
For the initial deployment also need these:
|
|
@@ -139,6 +202,11 @@ solana program deploy \
|
|
|
139
202
|
--max-sign-attempts 100 \
|
|
140
203
|
--use-rpc \
|
|
141
204
|
target/deploy/$PROGRAM.so
|
|
205
|
+
anchor idl init \
|
|
206
|
+
--provider.cluster $RPC_URL \
|
|
207
|
+
--provider.wallet $KEYPAIR \
|
|
208
|
+
--filepath target/idl/$PROGRAM.json \
|
|
209
|
+
$PROGRAM_ID
|
|
142
210
|
solana program set-upgrade-authority \
|
|
143
211
|
--url $RPC_URL \
|
|
144
212
|
--keypair $KEYPAIR \
|
|
@@ -149,20 +217,10 @@ solana program set-upgrade-authority \
|
|
|
149
217
|
|
|
150
218
|
Update and commit `deployments/legacy-addresses.json` with the deployed program ID and deployment slot.
|
|
151
219
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
```
|
|
220
|
+
Anchor 1.1.2 stores canonical IDLs in the separate Program Metadata program. Its authority follows the
|
|
221
|
+
program upgrade authority; there is no separate `anchor idl set-authority` step. The sequence above initializes
|
|
222
|
+
the canonical IDL before transferring program authority. If Squads already holds authority,
|
|
223
|
+
perform the canonical metadata write through Squads as described below.
|
|
166
224
|
|
|
167
225
|
`svm_spoke` also requires initialization and transfer of ownership on the first deployment:
|
|
168
226
|
|
|
@@ -224,35 +282,81 @@ solana program set-buffer-authority \
|
|
|
224
282
|
--new-buffer-authority $MULTISIG
|
|
225
283
|
```
|
|
226
284
|
|
|
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.
|
|
285
|
+
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
286
|
|
|
229
|
-
|
|
287
|
+
Prepare an Anchor 1.1.2 Program Metadata buffer and transfer its authority to the Squads vault:
|
|
230
288
|
|
|
231
289
|
```shell
|
|
232
|
-
anchor idl
|
|
290
|
+
anchor idl create-buffer \
|
|
233
291
|
--provider.cluster $RPC_URL \
|
|
234
292
|
--provider.wallet $KEYPAIR \
|
|
235
|
-
--filepath target/idl/$PROGRAM.json
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
anchor idl set-authority \
|
|
293
|
+
--filepath target/idl/$PROGRAM.json
|
|
294
|
+
export IDL_BUFFER= # Export the logged metadata buffer address
|
|
295
|
+
anchor idl set-buffer-authority \
|
|
239
296
|
--provider.cluster $RPC_URL \
|
|
240
297
|
--provider.wallet $KEYPAIR \
|
|
241
|
-
--program-id $PROGRAM_ID \
|
|
242
298
|
--new-authority $MULTISIG \
|
|
243
299
|
$IDL_BUFFER
|
|
244
300
|
```
|
|
245
301
|
|
|
246
|
-
|
|
302
|
+
Export the canonical IDL update using the official [Program Metadata CLI](https://github.com/solana-program/program-metadata#squads-multisig).
|
|
303
|
+
This replaces `scripts/svm/squadsIdlUpgrade.ts` for Anchor 1.1.2 programs:
|
|
247
304
|
|
|
248
305
|
```shell
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
--idlBuffer $IDL_BUFFER \
|
|
252
|
-
--multisig $MULTISIG \
|
|
253
|
-
--closeRecipient $(solana address --keypair $KEYPAIR)
|
|
306
|
+
export IDL_REFUND_RECIPIENT=$(solana-keygen pubkey "$KEYPAIR") # Refund the operator that funded the IDL buffer
|
|
307
|
+
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
308
|
```
|
|
255
309
|
|
|
310
|
+
`--export` prints unsigned transactions without submitting them. `$MULTISIG` must be the **Squads vault
|
|
311
|
+
PDA that holds program and buffer authority**, not the Squads multisig account. Transferring buffer
|
|
312
|
+
authority does not reimburse the operator: `--close-buffer` returns that buffer's rent to the operator
|
|
313
|
+
wallet above. The vault separately funds any canonical metadata account rent, so it needs sufficient
|
|
314
|
+
SOL. The command creates the canonical metadata account if absent, including the first upgrade from
|
|
315
|
+
Anchor 0.31, or updates it if it already exists.
|
|
316
|
+
|
|
317
|
+
For the **first upgrade from Anchor 0.31**, also prepare closure of the old canonical IDL while the
|
|
318
|
+
old binary still supports its dispatcher. Check its authority with the old CLI; it must match the
|
|
319
|
+
Squads vault used below. The legacy IDL authority is independent of the program upgrade authority.
|
|
320
|
+
|
|
321
|
+
```shell
|
|
322
|
+
export LEGACY_ANCHOR="$HOME/.avm/bin/anchor-0.31.1"
|
|
323
|
+
"$LEGACY_ANCHOR" idl authority --provider.cluster "$RPC_URL" "$PROGRAM_ID"
|
|
324
|
+
export LEGACY_IDL_REFUND_RECIPIENT= # Set the reviewed recipient of the old canonical IDL's rent
|
|
325
|
+
yarn ts-node scripts/svm/squadsIdlUpgrade.ts --programId "$PROGRAM_ID" --multisig "$MULTISIG" --closeIdl --closeRecipient "$LEGACY_IDL_REFUND_RECIPIENT"
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
This helper prints a single unsigned Base58 message containing only the legacy IDL close instruction.
|
|
329
|
+
Import it **before the binary upgrade instruction in the same Squads transaction**. It closes the old
|
|
330
|
+
canonical account, not the new Program Metadata buffer. Skip this step when no legacy IDL exists.
|
|
331
|
+
Coordinate client updates first: old `@coral-xyz/anchor` readers stop fetching that IDL after closure.
|
|
332
|
+
|
|
333
|
+
In Squads, use **Developers → Transaction Builder → Create Transaction → Add Instruction → Import as
|
|
334
|
+
Base58** to import each printed transaction. Review the program ID, canonical metadata account, vault
|
|
335
|
+
signer and buffer-rent recipient. Include the final IDL write and buffer closure with the binary upgrade
|
|
336
|
+
in one reviewed transaction where possible. Extra transactions can be needed to create or grow the
|
|
337
|
+
destination account; the uploaded buffer data does not need to be uploaded again. If the CLI prints
|
|
338
|
+
multiple transactions, retain their order; `--single-extend-per-tx` limits account growth to 10 KiB per
|
|
339
|
+
Squads execution. Execute any preparatory allocation/growth transactions before the final write, and do not combine those exports into
|
|
340
|
+
one transaction. Then collect the required approvals and execute the release. If the binary upgrade and
|
|
341
|
+
final IDL write must be separate, execute the IDL write immediately after the binary upgrade.
|
|
342
|
+
|
|
343
|
+
After execution, fetch the canonical IDL and compare its JSON content with the release artifact:
|
|
344
|
+
|
|
345
|
+
```shell
|
|
346
|
+
anchor idl fetch --provider.cluster "$RPC_URL" --commitment finalized --out /tmp/deployed-idl.json "$PROGRAM_ID"
|
|
347
|
+
jq -S . "target/idl/$PROGRAM.json" > /tmp/release-idl.sorted.json
|
|
348
|
+
jq -S . /tmp/deployed-idl.json > /tmp/deployed-idl.sorted.json
|
|
349
|
+
diff -u /tmp/release-idl.sorted.json /tmp/deployed-idl.sorted.json
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Do not run `anchor idl write-buffer` directly from the operator wallet after Squads takes authority;
|
|
353
|
+
the vault must authorize that write. `scripts/svm/squadsIdlUpgrade.ts` encodes the old Anchor 0.31
|
|
354
|
+
dispatcher instructions and remains usable only for legacy deployments with Anchor 0.31.1. It does not
|
|
355
|
+
update Program Metadata accounts. Leaving the old IDL open does not block publication of the new one,
|
|
356
|
+
but old clients continue reading stale data. The upgraded binary has no legacy IDL dispatcher, so it
|
|
357
|
+
cannot update or close that account or recover its rent; doing so later would require another program
|
|
358
|
+
upgrade restoring that functionality. The sequence above avoids leaving that stale account behind.
|
|
359
|
+
|
|
256
360
|
#### Verify
|
|
257
361
|
|
|
258
362
|
Start with verifying locally that the deployed program matches the source code of the public repository:
|
|
@@ -262,7 +366,7 @@ solana-verify verify-from-repo \
|
|
|
262
366
|
--url $RPC_URL \
|
|
263
367
|
--program-id $PROGRAM_ID \
|
|
264
368
|
--library-name $PROGRAM \
|
|
265
|
-
--base-image "
|
|
369
|
+
--base-image "$BUILD_IMAGE" \
|
|
266
370
|
https://github.com/across-protocol/contracts
|
|
267
371
|
```
|
|
268
372
|
|
|
@@ -273,7 +377,7 @@ solana-verify export-pda-tx \
|
|
|
273
377
|
--url $RPC_URL \
|
|
274
378
|
--program-id $PROGRAM_ID \
|
|
275
379
|
--library-name $PROGRAM \
|
|
276
|
-
--base-image "
|
|
380
|
+
--base-image "$BUILD_IMAGE" \
|
|
277
381
|
--uploader $MULTISIG \
|
|
278
382
|
https://github.com/across-protocol/contracts
|
|
279
383
|
```
|
|
@@ -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.
|
|
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
|
|
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
|
|
39
|
-
//
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
124
|
+
ICoreDepositWallet depositWallet = usdcCoreDepositWallet();
|
|
125
|
+
IERC20(erc20EVMAddress).forceApprove(address(depositWallet), _amountEVMToSend);
|
|
110
126
|
if (to == address(this)) {
|
|
111
|
-
|
|
127
|
+
depositWallet.deposit(_amountEVMToSend, destinationDex);
|
|
112
128
|
} else {
|
|
113
|
-
|
|
114
|
-
to,
|
|
115
|
-
_amountEVMToSend,
|
|
116
|
-
destinationDex
|
|
117
|
-
);
|
|
129
|
+
depositWallet.depositFor(to, _amountEVMToSend, destinationDex);
|
|
118
130
|
}
|
|
119
131
|
} else {
|
|
120
|
-
IERC20(erc20EVMAddress).safeTransfer(
|
|
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
|
-
|
|
249
|
-
|
|
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(
|
|
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
|
-
|
|
370
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
382
|
-
|
|
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
|
/**
|
|
@@ -9,6 +9,10 @@ library PeripherySigningLib {
|
|
|
9
9
|
"BaseDepositData(address inputToken,bytes32 outputToken,uint256 outputAmount,address depositor,bytes32 recipient,uint256 destinationChainId,bytes32 exclusiveRelayer,uint32 quoteTimestamp,uint32 fillDeadline,uint32 exclusivityParameter,bytes message)";
|
|
10
10
|
string internal constant EIP712_DEPOSIT_DATA_TYPE =
|
|
11
11
|
"DepositData(Fees submissionFees,BaseDepositData baseDepositData,uint256 inputAmount,address spokePool,uint256 nonce)";
|
|
12
|
+
string internal constant EIP712_SIGNED_DEPOSIT_DATA_TYPE =
|
|
13
|
+
"SignedDepositData(DepositData depositData,uint256 deadline)";
|
|
14
|
+
string internal constant EIP712_SIGNED_SWAP_AND_DEPOSIT_DATA_TYPE =
|
|
15
|
+
"SignedSwapAndDepositData(SwapAndDepositData swapAndDepositData,uint256 deadline)";
|
|
12
16
|
string internal constant EIP712_SWAP_AND_DEPOSIT_DATA_TYPE =
|
|
13
17
|
"SwapAndDepositData(Fees submissionFees,BaseDepositData depositData,address swapToken,address exchange,uint8 transferType,uint256 swapTokenAmount,uint256 minExpectedInputTokenAmount,bytes routerCalldata,bool enableProportionalAdjustment,address spokePool,uint256 nonce)";
|
|
14
18
|
|
|
@@ -18,6 +22,24 @@ library PeripherySigningLib {
|
|
|
18
22
|
keccak256(abi.encodePacked(EIP712_BASE_DEPOSIT_DATA_TYPE));
|
|
19
23
|
bytes32 internal constant EIP712_DEPOSIT_DATA_TYPEHASH =
|
|
20
24
|
keccak256(abi.encodePacked(EIP712_DEPOSIT_DATA_TYPE, EIP712_BASE_DEPOSIT_DATA_TYPE, EIP712_FEES_TYPE));
|
|
25
|
+
bytes32 internal constant EIP712_SIGNED_DEPOSIT_DATA_TYPEHASH =
|
|
26
|
+
keccak256(
|
|
27
|
+
abi.encodePacked(
|
|
28
|
+
EIP712_SIGNED_DEPOSIT_DATA_TYPE,
|
|
29
|
+
EIP712_BASE_DEPOSIT_DATA_TYPE,
|
|
30
|
+
EIP712_DEPOSIT_DATA_TYPE,
|
|
31
|
+
EIP712_FEES_TYPE
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
bytes32 internal constant EIP712_SIGNED_SWAP_AND_DEPOSIT_DATA_TYPEHASH =
|
|
35
|
+
keccak256(
|
|
36
|
+
abi.encodePacked(
|
|
37
|
+
EIP712_SIGNED_SWAP_AND_DEPOSIT_DATA_TYPE,
|
|
38
|
+
EIP712_BASE_DEPOSIT_DATA_TYPE,
|
|
39
|
+
EIP712_FEES_TYPE,
|
|
40
|
+
EIP712_SWAP_AND_DEPOSIT_DATA_TYPE
|
|
41
|
+
)
|
|
42
|
+
);
|
|
21
43
|
bytes32 internal constant EIP712_SWAP_AND_DEPOSIT_DATA_TYPEHASH =
|
|
22
44
|
keccak256(abi.encodePacked(EIP712_SWAP_AND_DEPOSIT_DATA_TYPE, EIP712_BASE_DEPOSIT_DATA_TYPE, EIP712_FEES_TYPE));
|
|
23
45
|
|
|
@@ -128,6 +150,40 @@ library PeripherySigningLib {
|
|
|
128
150
|
);
|
|
129
151
|
}
|
|
130
152
|
|
|
153
|
+
/**
|
|
154
|
+
* @notice Hashes a DepositData together with the deadline the signer authorized it until.
|
|
155
|
+
* @dev The permit entrypoints verify this rather than the bare DepositData hash, so the deadline cannot be
|
|
156
|
+
* swapped out by the submitter. Permit2 and ERC-3009 bind their own deadline alongside the witness the same
|
|
157
|
+
* way, so their entrypoints keep using the bare hash.
|
|
158
|
+
* @param depositData Input struct whose values are hashed.
|
|
159
|
+
* @param deadline Timestamp after which the signature is no longer redeemable.
|
|
160
|
+
*/
|
|
161
|
+
function hashSignedDepositData(
|
|
162
|
+
SpokePoolPeripheryInterface.DepositData calldata depositData,
|
|
163
|
+
uint256 deadline
|
|
164
|
+
) internal pure returns (bytes32) {
|
|
165
|
+
return keccak256(abi.encode(EIP712_SIGNED_DEPOSIT_DATA_TYPEHASH, hashDepositData(depositData), deadline));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @notice Hashes a SwapAndDepositData together with the deadline the signer authorized it until.
|
|
170
|
+
* @param swapAndDepositData Input struct whose values are hashed.
|
|
171
|
+
* @param deadline Timestamp after which the signature is no longer redeemable.
|
|
172
|
+
*/
|
|
173
|
+
function hashSignedSwapAndDepositData(
|
|
174
|
+
SpokePoolPeripheryInterface.SwapAndDepositData calldata swapAndDepositData,
|
|
175
|
+
uint256 deadline
|
|
176
|
+
) internal pure returns (bytes32) {
|
|
177
|
+
return
|
|
178
|
+
keccak256(
|
|
179
|
+
abi.encode(
|
|
180
|
+
EIP712_SIGNED_SWAP_AND_DEPOSIT_DATA_TYPEHASH,
|
|
181
|
+
hashSwapAndDepositData(swapAndDepositData),
|
|
182
|
+
deadline
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
131
187
|
/**
|
|
132
188
|
* @notice Reads an input bytes, and, assuming it is a signature for a 32-byte hash, returns the v, r, and s values.
|
|
133
189
|
* @param _signature The input signature to deserialize.
|