Skip to content

Commit 0cf778b

Browse files
committed
Merge branch 'main' into codex/identify-devex-gaps-in-lzapp-migration
2 parents 430c257 + 62efaf0 commit 0cf778b

24 files changed

Lines changed: 693 additions & 322 deletions

examples/oft-hyperliquid/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @layerzerolabs/oft-hyperliquid-example
22

3+
## 0.0.8
4+
5+
### Patch Changes
6+
7+
- 9c0c90c: using CoreWriter instead of WritePrecompile
8+
39
## 0.0.7
410

511
### Patch Changes

examples/oft-hyperliquid/HYPERLIQUID.CHECKLIST.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Block switching is not present in the default oft deploy script.
104104
- [ ] Follow the [guide](https://github.com/LayerZero-Labs/devtools/blob/main/examples/oft-hyperliquid/HYPERLIQUID.README.md#step-56-createspotdeployment)
105105
- Step MUST be run even though we set `noHyperliquidity=true` in genesis
106106
- This can be run even after deployment and linking
107+
- [ ] Run this step only before market makers are ready to provide liquidity. Otherwise users can trade your token at arbitrary prices.
107108

108109
### Step 2.6 : Set deployer fee share
109110

examples/oft-hyperliquid/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@layerzerolabs/oft-hyperliquid-example",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"private": true,
55
"license": "MIT",
66
"scripts": {
@@ -27,7 +27,7 @@
2727
"@babel/core": "^7.23.9",
2828
"@layerzerolabs/devtools-evm-hardhat": "^3.0.0",
2929
"@layerzerolabs/eslint-config-next": "~2.3.39",
30-
"@layerzerolabs/hyperliquid-composer": "^0.0.12",
30+
"@layerzerolabs/hyperliquid-composer": "^0.0.13",
3131
"@layerzerolabs/lz-definitions": "^3.0.59",
3232
"@layerzerolabs/lz-evm-messagelib-v2": "^3.0.12",
3333
"@layerzerolabs/lz-evm-protocol-v2": "^3.0.12",

examples/oft-hyperliquid/test/foundry/HyperLiquidComposer.t.sol

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import { OFTComposeMsgCodec } from "@layerzerolabs/oft-evm/contracts/libs/OFTCom
88
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
99

1010
import { HyperLiquidComposer, IHyperAsset } from "@layerzerolabs/hyperliquid-composer/contracts/HyperLiquidComposer.sol";
11-
import { IHyperLiquidWritePrecompile } from "@layerzerolabs/hyperliquid-composer/contracts/interfaces/IHyperLiquidWritePrecompile.sol";
12-
13-
import { HyperLiquidComposer, IHyperAsset } from "@layerzerolabs/hyperliquid-composer/contracts/HyperLiquidComposer.sol";
14-
import { IHyperLiquidWritePrecompile } from "@layerzerolabs/hyperliquid-composer/contracts/interfaces/IHyperLiquidWritePrecompile.sol";
11+
import { ICoreWriter } from "@layerzerolabs/hyperliquid-composer/contracts/interfaces/ICoreWriter.sol";
1512

1613
import { HyperLiquidComposerCodec } from "@layerzerolabs/hyperliquid-composer/contracts/library/HyperLiquidComposerCodec.sol";
1714

@@ -25,7 +22,7 @@ contract HyperLiquidComposerTest is Test {
2522
IHyperAsset public ALICE;
2623
IHyperAsset public HYPE;
2724
address public constant HL_LZ_ENDPOINT_V2 = 0xf9e1815F151024bDE4B7C10BAC10e8Ba9F6b53E1;
28-
address public constant HLP_PRECOMPILE_WRITE = 0x3333333333333333333333333333333333333333;
25+
address public constant HLP_CORE_WRITER = 0x3333333333333333333333333333333333333333;
2926
address public constant HLP_PRECOMPILE_READ_SPOT_BALANCE = 0x0000000000000000000000000000000000000801;
3027
// Ethereum Sepolia
3128
uint32 public constant SRC_EID = 40161;
@@ -124,14 +121,11 @@ contract HyperLiquidComposerTest is Test {
124121
vm.expectEmit(address(oft));
125122
emit IERC20.Transfer(address(hyperLiquidComposer), ALICE.assetBridgeAddress, AMOUNT_TO_SEND);
126123

127-
// Expect the SpotSend event to be emitted
128-
vm.expectEmit(hyperLiquidComposer.HLP_PRECOMPILE_WRITE());
129-
emit IHyperLiquidWritePrecompile.SpotSend(
130-
address(hyperLiquidComposer),
131-
userB,
132-
ALICE.coreIndexId,
133-
uint64(AMOUNT_TO_SEND / 10 ** uint64(ALICE.decimalDiff))
134-
);
124+
uint64 coreAmount = hyperLiquidComposer.quoteHyperCoreAmount(AMOUNT_TO_SEND, true).core;
125+
bytes memory action = abi.encode(userB, ALICE.coreIndexId, coreAmount);
126+
bytes memory payload = abi.encodePacked(hyperLiquidComposer.SPOT_SEND_HEADER(), action);
127+
vm.expectEmit(HLP_CORE_WRITER);
128+
emit ICoreWriter.RawAction(address(hyperLiquidComposer), payload);
135129

136130
uint256 balanceBefore = oft.balanceOf(userB);
137131

@@ -165,14 +159,11 @@ contract HyperLiquidComposerTest is Test {
165159
vm.expectEmit(address(oft));
166160
emit IERC20.Transfer(address(hyperLiquidComposer), ALICE.assetBridgeAddress, AMOUNT_TO_SEND);
167161

168-
// Expect the SpotSend event to be emitted - this is for the ALICE asset bridge
169-
vm.expectEmit(hyperLiquidComposer.HLP_PRECOMPILE_WRITE());
170-
emit IHyperLiquidWritePrecompile.SpotSend(
171-
address(hyperLiquidComposer),
172-
userB,
173-
ALICE.coreIndexId,
174-
uint64(AMOUNT_TO_SEND / 10 ** uint64(ALICE.decimalDiff))
175-
);
162+
uint64 coreAmount = hyperLiquidComposer.quoteHyperCoreAmount(AMOUNT_TO_SEND, true).core;
163+
bytes memory action = abi.encode(userB, ALICE.coreIndexId, coreAmount);
164+
bytes memory payload = abi.encodePacked(hyperLiquidComposer.SPOT_SEND_HEADER(), action);
165+
vm.expectEmit(HLP_CORE_WRITER);
166+
emit ICoreWriter.RawAction(address(hyperLiquidComposer), payload);
176167

177168
uint256 balanceBeforeBridge = HYPE.assetBridgeAddress.balance;
178169
uint256 balanceBeforeUserB = userB.balance;

packages/hyperliquid-composer/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @layerzerolabs/hyperliquid-composer
22

3+
## 0.0.13
4+
5+
### Patch Changes
6+
7+
- 9c0c90c: using CoreWriter instead of WritePrecompile
8+
39
## 0.0.12
410

511
### Patch Changes

packages/hyperliquid-composer/HYPERLIQUID.README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The system contracts are:
118118
and `L1ActionPrecompiles`
119119

120120
- `0x0000000000000000000000000000000000000000` is one of the many `L1Read` precompiles.
121-
- `0x3333333333333333333333333333333333333333` is the `L1WritePrecompile` and is used to send transactions to HyperCore.
121+
- `0x3333333333333333333333333333333333333333` is the `CoreWriter` and is used to send transactions to HyperCore.
122122

123123
More `L1ActionPrecompiles` found [here](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/hyperevm/interacting-with-hypercore).
124124

@@ -229,7 +229,7 @@ struct SendParam {
229229
}
230230
```
231231

232-
Now that the token is with the `Composer` on HyperCore it then performs a `L1WritePrecompile` transaction to `0x33...333` (the `L1WritePrecompile` address) telling it to perform a `spot transfer` of the tokens from it's address to the `receiver`.
232+
Now that the token is with the `Composer` on HyperCore it then performs a `CoreWriter` transaction to `0x33...333` (the `CoreWriter` address) telling it to perform a `spot transfer` of the tokens from it's address to the `receiver`.
233233

234234
It must be noted that due to the token decimal difference between the `EVM::ERC20` and `HyperCore::HIP1` the tokens you see on `HyperCore` would be different with the wei decimal different (`HIP1.decimals()` - `ERC20.decimals()` in range `[-2,18]`). But when converting them back from `HyperCore` to `HyperEVM` the token decimals gets restored.
235235

@@ -284,11 +284,16 @@ function _sendAssetToHyperCore(
284284
285285
if (amounts.evm > 0) {
286286
token.safeTransfer(oftAsset.assetBridgeAddress, amounts.evm);
287-
IHyperLiquidWritePrecompile(HLP_PRECOMPILE_WRITE).sendSpot(
287+
bytes memory action = abi.encodePacked(
288288
_receiver,
289289
oftAsset.coreIndexId,
290290
amounts.core
291291
);
292+
bytes memory payload = abi.encodePacked(
293+
abi.encodePacked(hex"1600", action) // 1600 is the [version][actionId][actionBytes] - https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/hyperevm/interacting-with-hypercore#action-encoding-details
294+
);
295+
/// Transfers tokens from the composer address on HyperCore to the _receiver
296+
ICoreWriter(HLP_PRECOMPILE_WRITE).sendRawAction(payload);
292297
}
293298
if (amounts.dust > 0) {
294299
token.safeTransfer(_receiver, amounts.dust);

packages/hyperliquid-composer/artifacts/HyperLiquidComposer.sol/HyperLiquidComposer.json

Lines changed: 225 additions & 40 deletions
Large diffs are not rendered by default.

packages/hyperliquid-composer/artifacts/HyperLiquidComposer.t.sol/HyperLiquidComposerTest.json

Lines changed: 68 additions & 92 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)