Skip to content

Commit

Permalink
Merge branch 'main' into oft-and-adapter-fee-upgradeable
Browse files Browse the repository at this point in the history
  • Loading branch information
DanL0 committed Feb 17, 2025
2 parents e3e604e + 7254d5d commit c435199
Show file tree
Hide file tree
Showing 12 changed files with 1,639 additions and 86 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-cars-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/devtools-ton": minor
---

Added tool to debug TON lz messages
1 change: 1 addition & 0 deletions examples/lzapp-migration/layerzero.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const config: OAppOmniGraphHardhat = {
},
sendConfig: {
executorConfig: {
maxMessageSize: 200,
executor: '0x718B92b5CB0a5552039B593faF724D182A881eDA',
},
ulnConfig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pragma solidity ^0.8.22;
import { OFTAdapterUpgradeable } from "@layerzerolabs/oft-evm-upgradeable/contracts/oft/OFTAdapterUpgradeable.sol";

contract MyOFTAdapterUpgradeable is OFTAdapterUpgradeable {
constructor(address _token, address _lzEndpoint) OFTAdapterUpgradeable(_token, _lzEndpoint) {}
constructor(address _token, address _lzEndpoint) OFTAdapterUpgradeable(_token, _lzEndpoint) {
_disableInitializers();
}

function initialize(address _delegate) public initializer {
__OFTAdapter_init(_delegate);
Expand Down
4 changes: 3 additions & 1 deletion examples/oft-upgradeable/contracts/MyOFTUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pragma solidity ^0.8.22;
import { OFTUpgradeable } from "@layerzerolabs/oft-evm-upgradeable/contracts/oft/OFTUpgradeable.sol";

contract MyOFTUpgradeable is OFTUpgradeable {
constructor(address _lzEndpoint) OFTUpgradeable(_lzEndpoint) {}
constructor(address _lzEndpoint) OFTUpgradeable(_lzEndpoint) {
_disableInitializers();
}

function initialize(string memory _name, string memory _symbol, address _delegate) public initializer {
__OFT_init(_name, _symbol, _delegate);
Expand Down
8 changes: 0 additions & 8 deletions examples/oft-upgradeable/test/foundry/MyOFTUpgradeable.sol

This file was deleted.

61 changes: 61 additions & 0 deletions examples/oft-upgradeable/test/foundry/MyOFTUpgradeable.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import { OFTTest } from "@layerzerolabs/oft-evm-upgradeable/test/OFT.t.sol";
import { MyOFTAdapterUpgradeable } from "../../contracts/MyOFTAdapterUpgradeable.sol";
import { EndpointV2Mock } from "@layerzerolabs/test-devtools-evm-foundry/contracts/mocks/EndpointV2Mock.sol";
import { MyOFTUpgradeable } from "../../contracts/MyOFTUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract MyOFTUpgradeableTest is OFTTest {
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

function test_oft_implementation_initialization_disabled() public {
MyOFTUpgradeable oftUpgradeable = MyOFTUpgradeable(
_deployContractAndProxy(
type(MyOFTUpgradeable).creationCode,
abi.encode(address(endpoints[aEid])),
abi.encodeWithSelector(
MyOFTUpgradeable.initialize.selector,
"oftUpgradeable",
"oftUpgradeable",
address(this)
)
)
);

bytes32 implementationRaw = vm.load(address(oftUpgradeable), IMPLEMENTATION_SLOT);
address implementationAddress = address(uint160(uint256(implementationRaw)));

MyOFTUpgradeable oftUpgradeableImplementation = MyOFTUpgradeable(implementationAddress);

vm.expectRevert(Initializable.InvalidInitialization.selector);
oftUpgradeableImplementation.initialize("oftUpgradeable", "oftUpgradeable", address(this));

EndpointV2Mock endpoint = EndpointV2Mock(address(oftUpgradeable.endpoint()));
assertEq(endpoint.delegates(address(oftUpgradeable)), address(this));
assertEq(endpoint.delegates(implementationAddress), address(0));
}

function test_oft_adapter_implementation_initialization_disabled() public {
MyOFTAdapterUpgradeable oftAdapter = MyOFTAdapterUpgradeable(
_deployContractAndProxy(
type(MyOFTAdapterUpgradeable).creationCode,
abi.encode(address(cERC20Mock), address(endpoints[cEid])),
abi.encodeWithSelector(MyOFTAdapterUpgradeable.initialize.selector, address(this))
)
);

bytes32 implementationRaw = vm.load(address(oftAdapter), IMPLEMENTATION_SLOT);
address implementationAddress = address(uint160(uint256(implementationRaw)));

MyOFTAdapterUpgradeable oftAdapterImplementation = MyOFTAdapterUpgradeable(implementationAddress);

vm.expectRevert(Initializable.InvalidInitialization.selector);
oftAdapterImplementation.initialize(address(this));

EndpointV2Mock endpoint = EndpointV2Mock(address(oftAdapter.endpoint()));
assertEq(endpoint.delegates(address(oftAdapter)), address(this));
assertEq(endpoint.delegates(implementationAddress), address(0));
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"test:jest": "$npm_execpath turbo run test:jest $DOCKER_COMPOSE_RUN_TESTS_TURBO_ARGS",
"test:local": ". bin/env && $npm_execpath start && $npm_execpath test",
"test:local:jest": ". bin/env && $npm_execpath start && $npm_execpath test:jest",
"test:user": "docker compose -f docker-compose.registry.yaml run --build --rm $DOCKER_COMPOSE_ARGS tests"
"test:user": "docker compose -f docker-compose.registry.yaml run --build --rm $DOCKER_COMPOSE_ARGS tests",
"ton:message-info": "ts-node packages/devtools-ton/scripts/debugTon.ts"
},
"lint-staged": {
"**/*.{js,ts,tsx,json}": [
Expand All @@ -33,6 +34,7 @@
]
},
"resolutions": {
"@ton/ton": "npm:@layerzerolabs/[email protected]",
"es5-ext": "git://github.com/LayerZero-Labs/es5-ext",
"ethers": "^5.7.2",
"hardhat-deploy": "^0.12.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@ton/core": "^0.59.0",
"@ton/crypto": "^3.3.0",
"@ton/ton": "^15.1.0",
"@ton/ton": "^14.0.0",
"p-memoize": "~4.0.4"
},
"devDependencies": {
Expand All @@ -59,7 +59,7 @@
"@layerzerolabs/lz-definitions": "^3.0.59",
"@ton/core": "^0.59.0",
"@ton/crypto": "^3.3.0",
"@ton/ton": "^15.1.0"
"@ton/ton": "^14.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
Loading

0 comments on commit c435199

Please sign in to comment.