Skip to content

Commit

Permalink
fix: Passthrough and local adapter (#384)
Browse files Browse the repository at this point in the history
* fix: fix passthrough and local adapter

* fix: build

* fix: lints

* chore: Make testing adapters great again !

* chore: Update Sepolia deployment configuration

---------

Co-authored-by: John <bulk.yard@protonmail.com>
  • Loading branch information
mustermeiszer and peculiarity authored Jul 29, 2024
1 parent 223a0f3 commit 1f92ebd
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 43 deletions.
36 changes: 18 additions & 18 deletions deployments/testnet/ethereum-sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
"chainId": 11155111,
"rpcUrl": "https://sepolia.infura.io/v3/ed5e0e19bcbc427cbf8f661736d44516",
"config": {
"commitHash": "333cc86042891d25c72e9a66dc9068652c0e02e0",
"deployer": "0x423420Ae467df6e90291fd0252c0A8a637C1e03f",
"commitHash": "93c59a531c9529e92949bd50aaf2a346be8c9a0a",
"deployer": "0x7c0E0200c7451d16F667665B39E3C78669a24BC3",
"adapter": {
"name": "Axelar",
"axelarGateway": "0xe432150cce91c13a887f7D836923d5597adD8E31"
"name": "Passthrough"
},
"admin": "0x423420Ae467df6e90291fd0252c0A8a637C1e03f",
"etherscanUrl": "https://api.etherscan.io/api/"
},
"contracts": {
"root": "0x5efaE490cf5B54a614852b31540BF3F0B6011717",
"investmentManager": "0xE3C901F6756e40dca041Dc58A1742e515bf58924",
"poolManager": "0x5c8657b827a138D52a4e3f03683A28B1FaD86893",
"gateway": "0xa0eBf95b390F38a50f0F0d44149EDd74279fA374",
"escrow": "0x1AB6cD0c08120215E241a6108ae7458c995E1694",
"userEscrow": "0x80EFf9C87f48c50BF9c6c3998D26174410647621",
"adapter": "0x1724a512567Bb0FFc7a543C7033979852eDb084f",
"trancheFactory": "0xf4D51485313248b48237502403A86875707cC94D",
"liquidityPoolFactory": "0x8048eAFA883fA3CB5C27c5dcBE501877D106b21C",
"restrictionManagerFactory": "0x60F98D1DD5Fb1Bd35B3F501c5460C0392964D63E",
"pauseAdmin": "0x96B5CA2575393eBc1F534d808d86E602a2318d30",
"delayedAdmin": "0xc89c96956202798310502aE5C03bE6B11A2b0cd6",
"messages": "0xd6c9f5204037a054a1BB3768195bD52A38E84ccD"
"root": "0xd9789E8cd7aC7b2D05CF51f52A9C64541f411d97",
"investmentManager": "0xe4Ae602E4D488a6bb16e5d8A44C8184928C3E4B4",
"centrifugeRouter": "0xFd2bd7e938C461A208740507362d43E36021AF65",
"poolManager": "0xd5F5Bb94dCC8bD894C0A66C0a5Fe3d2503a3D013",
"gateway": "0xc002c4437e05E41B746e5F840041275dEed912ba",
"gasService": "0x3CEc80ba243C5627300E90FD611e17207CbBD206",
"escrow": "0x961Ea4bEED78F8460125b2EB4bD76760b39a93e8",
"routerEscrow": "0x679c1DdAD3DDE8a2e80cC87Fc7123090C1dB137f",
"adapter": "0x7857E1c9e02dE72ce6CD582A88e2e1d92c9Cf2E7",
"trancheFactory": "0xaA141F0E0e408f75CB706d51F1a7811c13E00CED",
"erc7540VaultFactory": "0xa329bf0A2286B3f5631b6d5679a52911681FF84F",
"transferProxyFactory": "0x7EE1B98b0D53D175b74799b41757BD589B766Dd4",
"restrictionManagerFactory": "0x3293C3Aa8C3dC892d035b4101175141Ed2C00f8A",
"guardian": "0x0Be897D63eC22E020B7eA05A606e9e9614768B22"
},
"deploymentBlock": 4922687,
"deploymentBlock": 6379316,
"isTestnet": true
}
9 changes: 7 additions & 2 deletions test/integration/LocalAdapter.s.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.26;

import {Deployer} from "script/Deployer.sol";
import {LocalAdapter} from "test/integration/LocalAdapter.sol";
import {Deployer} from "../../script/Deployer.sol";
import {LocalAdapter} from "./LocalAdapter.sol";

// Script to deploy Liquidity Pools with an Axelar adapter.
contract LocalAdapterScript is Deployer {
function setUp() public {}

function run() public {
vm.startBroadcast();

// NOTE: 0x361c43cd5Fd700923Aae9dED678851a201839fc6 is the H160 of Keyring::Admin in the Centrifuge Chain
// repository
adminSafe = address(0x361c43cd5Fd700923Aae9dED678851a201839fc6);

deploy(msg.sender);
LocalAdapter adapter = new LocalAdapter();
wire(address(adapter));

adapter.file("gateway", address(gateway));
adapter.file("sourceChain", "TestDomain");
adapter.file("sourceAddress", "0x1111111111111111111111111111111111111111");

removeDeployerAccess(address(adapter), msg.sender);

vm.stopBroadcast();
}
}
12 changes: 10 additions & 2 deletions test/integration/LocalAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ contract LocalAdapter is Auth, IAdapter {
event File(bytes32 indexed what, address addr);
event File(bytes32 indexed what, string data);

constructor() {
wards[msg.sender] = 1;
emit Rely(msg.sender);
}

// --- Administrative ---
function file(bytes32 what, address data) external {
if (what == "gateway") {
Expand Down Expand Up @@ -79,12 +84,15 @@ contract LocalAdapter is Auth, IAdapter {
}

/// @inheritdoc IAdapter
function estimate(bytes calldata payload, uint256 baseCost) external view returns (uint256) {
function estimate(bytes calldata, uint256) external pure returns (uint256) {
return 0;
}

/// @inheritdoc IAdapter
function pay(bytes calldata payload, address refund) public payable {
function pay(bytes calldata, address) public payable {
return;
}

// Added to be ignored in coverage report
function test() public {}
}
34 changes: 31 additions & 3 deletions test/integration/PassthroughAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,37 @@ contract PassthroughAdapterScript is Deployer {
function setUp() public {}

function run() public {
vm.startBroadcast();

adminSafe = vm.envAddress("ADMIN");

deploy(msg.sender);
PassthroughAdapter adapter = new PassthroughAdapter();
wire(address(adapter));
adapter.file("gateway", address(gateway));
PassthroughAdapter router = new PassthroughAdapter();
wire(address(router));

router.file("gateway", address(gateway));
router.file("sourceChain", vm.envString("SOURCE_CHAIN"));
router.file("sourceAddress", toString(address(router)));

removeDeployerAccess(address(router), msg.sender);

vm.stopBroadcast();
}

function toString(address account) public pure returns (string memory) {
return toString(abi.encodePacked(account));
}

function toString(bytes memory data) public pure returns (string memory) {
bytes memory alphabet = "0123456789abcdef";

bytes memory str = new bytes(2 + data.length * 2);
str[0] = "0";
str[1] = "x";
for (uint256 i = 0; i < data.length; i++) {
str[2 + i * 2] = alphabet[uint256(uint8(data[i] >> 4))];
str[3 + i * 2] = alphabet[uint256(uint8(data[i] & 0x0f))];
}
return string(str);
}
}
66 changes: 48 additions & 18 deletions test/integration/PassthroughAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.26;

import {Auth} from "./../../src/Auth.sol";
import {IAdapter} from "src/interfaces/gateway/IAdapter.sol";

interface PrecompileLike {
function execute(
Expand All @@ -19,20 +19,27 @@ interface GatewayLike {
/// @title PassthroughAdapter
/// @notice Routing contract that accepts any incomming messages and forwards them
/// to the gateway and solely emits an event for outgoing messages.
contract PassthroughAdapter is Auth {
contract PassthroughAdapter is Auth, IAdapter {
address internal constant PRECOMPILE = 0x0000000000000000000000000000000000000800;
bytes32 internal constant FAKE_COMMAND_ID = keccak256("FAKE_COMMAND_ID");

GatewayLike public gateway;
string public sourceChain;
string public sourceAddress;

event RouteToDomain(string destinationChain, string destinationContractAddress, bytes payload);
event RouteToCentrifuge(string sourceChain, string sourceAddress, bytes payload);
event ExecuteOnDomain(string destinationChain, string destinationContractAddress, bytes payload);
event Route(string destinationChain, string destinationContractAddress, bytes payload);
event ExecuteOnDomain(string sourceChain, string sourceAddress, bytes payload);
event ExecuteOnCentrifuge(string sourceChain, string sourceAddress, bytes payload);

event File(bytes32 indexed what, address addr);
event File(bytes32 indexed what, string data);

constructor() {
wards[msg.sender] = 1;
emit Rely(msg.sender);
}

function file(bytes32 what, address addr) external {
// --- Administrative ---
function file(bytes32 what, address addr) external auth {
if (what == "gateway") {
gateway = GatewayLike(addr);
} else {
Expand All @@ -42,40 +49,63 @@ contract PassthroughAdapter is Auth {
emit File(what, addr);
}

function file(bytes32 what, string calldata data) external auth {
if (what == "sourceChain") {
sourceChain = data;
} else if (what == "sourceAddress") {
sourceAddress = data;
} else {
revert("PassthroughAdapter/file-unrecognized-param");
}

emit File(what, data);
}

/// --- Incoming ---
/// @notice From Centrifuge to LP on other domain. Just emits an event.
/// Just used on Centrifuge.
function callContract(
string calldata destinationChain,
string calldata destinationContractAddress,
bytes calldata payload
) public {
emit RouteToDomain(destinationChain, destinationContractAddress, payload);
emit Route(destinationChain, destinationContractAddress, payload);
}

/// --- Outgoing ---
/// @inheritdoc IAdapter
/// @notice From other domain to Centrifuge. Just emits an event.
/// Just used on EVM domains.
function send(bytes calldata message) public {
emit RouteToCentrifuge("LP-EVM-Domain", "Passthrough-Contract", message);
emit Route(sourceChain, sourceAddress, message);
}

/// @notice Execute message on centrifuge
function executeOnCentrifuge(string calldata sourceChain, string calldata sourceAddress, bytes calldata payload)
function executeOnCentrifuge(string calldata _sourceChain, string calldata _sourceAddress, bytes calldata payload)
external
{
PrecompileLike precompile = PrecompileLike(PRECOMPILE);
precompile.execute(FAKE_COMMAND_ID, sourceChain, sourceAddress, payload);
precompile.execute(FAKE_COMMAND_ID, _sourceChain, _sourceAddress, payload);

emit ExecuteOnCentrifuge(sourceChain, sourceAddress, payload);
emit ExecuteOnCentrifuge(_sourceChain, _sourceAddress, payload);
}

/// @notice Execute message on other domain
function executeOnOtherDomain(
string calldata destinationChain,
string calldata destinationContractAddress,
bytes calldata payload
) external {
function executeOnDomain(string calldata _sourceChain, string calldata _sourceAddress, bytes calldata payload)
external
{
gateway.handle(payload);
emit ExecuteOnDomain(destinationChain, destinationContractAddress, payload);
emit ExecuteOnDomain(_sourceChain, _sourceAddress, payload);
}

/// @inheritdoc IAdapter
function estimate(bytes calldata, uint256) external pure returns (uint256) {
return 0;
}

/// @inheritdoc IAdapter
function pay(bytes calldata, address) public payable {
return;
}

// Added to be ignored in coverage report
Expand Down

0 comments on commit 1f92ebd

Please sign in to comment.