Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Jan 29, 2025
1 parent 5546b5f commit b68558f
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 375 deletions.
21 changes: 9 additions & 12 deletions contracts/ICS20Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,19 @@ contract ICS20Transfer is
erc20Address = ICS20Lib.mustHexStringToAddress(token.denom.base);
} else {
// we are not origin source, i.e. sender chain is the origin source: add denom trace and mint vouchers
ICS20Lib.Denom memory newDenom = ICS20Lib.Denom({
base: token.denom.base,
trace: new ICS20Lib.Hop[](token.denom.trace.length + 1)
});
newDenom.trace[0] = ICS20Lib.Hop({
portId: msg_.payload.destPort,
channelId: msg_.destinationClient
});
ICS20Lib.Denom memory newDenom =
ICS20Lib.Denom({ base: token.denom.base, trace: new ICS20Lib.Hop[](token.denom.trace.length + 1) });
newDenom.trace[0] = ICS20Lib.Hop({ portId: msg_.payload.destPort, channelId: msg_.destinationClient });
for (uint256 j = 0; j < token.denom.trace.length; j++) {
newDenom.trace[j+1] = token.denom.trace[j];
newDenom.trace[j + 1] = token.denom.trace[j];
}

erc20Address = findOrCreateERC20Address(newDenom);
IBCERC20(erc20Address).mint(token.amount);
}

// transfer the tokens to the receiver
// solhint-disable-next-line multiple-sends
_getEscrow().send(IERC20(erc20Address), receiver, token.amount);
}

Expand Down Expand Up @@ -236,11 +232,11 @@ contract ICS20Transfer is
string calldata sourceClient,
ICS20Lib.FungibleTokenPacketData memory packetData
)
private
private
{
// TODO: How similar is this to the logic in onSendPacket?
address refundee = ICS20Lib.mustHexStringToAddress(packetData.sender);

for (uint256 i = 0; i < packetData.tokens.length; i++) {
ICS20Lib.Token memory token = packetData.tokens[i];

Expand All @@ -253,7 +249,7 @@ contract ICS20Transfer is

IBCERC20(erc20Address).mint(token.amount);
} else {
// the token is either a native token (in which case the base denom is an address),
// the token is either a native token (in which case the base denom is an address),
// or we are a middle chain and the token was minted (and mapped) here
bool isERC20Address;
(erc20Address, isERC20Address) = ICS20Lib.hexStringToAddress(token.denom.base);
Expand All @@ -265,6 +261,7 @@ contract ICS20Transfer is

require(erc20Address != address(0), ICS20DenomNotFound(token.denom));

// solhint-disable-next-line multiple-sends
_getEscrow().send(IERC20(erc20Address), refundee, token.amount);
}
}
Expand Down
32 changes: 13 additions & 19 deletions contracts/utils/ICS20Lib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.28;
// solhint-disable no-inline-assembly

import { Strings } from "@openzeppelin-contracts/utils/Strings.sol";
import { Bytes } from "@openzeppelin-contracts/utils/Bytes.sol";
import { IICS20Errors } from "../errors/IICS20Errors.sol";
import { IICS26RouterMsgs } from "../msgs/IICS26RouterMsgs.sol";
import { IICS20TransferMsgs } from "../msgs/IICS20TransferMsgs.sol";
Expand Down Expand Up @@ -56,7 +55,7 @@ library ICS20Lib {
struct Denom {
string base;
Hop[] trace;
}
}

/// @notice Hop defines a port ID, channel ID pair specifying where tokens must be forwarded
/// next in a multihop transfer, or the trace of an existing token.
Expand Down Expand Up @@ -121,24 +120,17 @@ library ICS20Lib {
fullDenom = fullDenomFromContract;
} catch {
// otherwise this is just an ERC20 address, so we use it as the denom
fullDenom = ICS20Lib.Denom({
base: Strings.toHexString(msg_.tokens[i].contractAddress),
trace: new Hop[](0)
});
fullDenom =
ICS20Lib.Denom({ base: Strings.toHexString(msg_.tokens[i].contractAddress), trace: new Hop[](0) });
}

tokens[i] = Token({
denom: fullDenom,
amount: msg_.tokens[i].amount
});
tokens[i] = Token({ denom: fullDenom, amount: msg_.tokens[i].amount });
}

// TODO: Make sure to have a test that covers this properly
string memory memo = msg_.memo;
ForwardingPacketData memory forwarding = ForwardingPacketData({
destinationMemo: "",
hops: msg_.forwarding.hops
});
ForwardingPacketData memory forwarding =
ForwardingPacketData({ destinationMemo: "", hops: msg_.forwarding.hops });
if (msg_.forwarding.hops.length > 0) {
memo = "";
forwarding.destinationMemo = msg_.memo;
Expand Down Expand Up @@ -210,17 +202,19 @@ library ICS20Lib {
/// @param client Client ID for the prefix
function hasPrefix(Denom memory denom, string calldata port, string calldata client) internal pure returns (bool) {
// if the denom is native, then it is not prefixed by any port/channel pair
if (denom.trace.length == 0) {
return false;
}
if (denom.trace.length == 0) {
return false;
}

return denom.trace[0].portId.equal(port) && denom.trace[0].channelId.equal(client);
return denom.trace[0].portId.equal(port) && denom.trace[0].channelId.equal(client);
}

function getDenomIdentifier(Denom memory denom) internal pure returns (bytes32) {
bytes memory traceBytes = "";
for (uint256 i = 0; i < denom.trace.length; i++) {
traceBytes = abi.encodePacked(traceBytes, keccak256(abi.encodePacked(denom.trace[i].portId, denom.trace[i].channelId)));
traceBytes = abi.encodePacked(
traceBytes, keccak256(abi.encodePacked(denom.trace[i].portId, denom.trace[i].channelId))
);
}

return keccak256(abi.encodePacked(denom.base, traceBytes));
Expand Down
1 change: 0 additions & 1 deletion test/solidity-ibc/BenchmarkTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pragma solidity ^0.8.28;
// solhint-disable-next-line no-global-import
import "forge-std/console.sol";
import { TestERC20 } from "./mocks/TestERC20.sol";
import { IICS20TransferMsgs } from "../../contracts/msgs/IICS20TransferMsgs.sol";
import { ICS20Lib } from "../../contracts/utils/ICS20Lib.sol";
import { ICS24Host } from "../../contracts/utils/ICS24Host.sol";
import { FixtureTest } from "./FixtureTest.t.sol";
Expand Down
11 changes: 2 additions & 9 deletions test/solidity-ibc/IBCERC20Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ contract IBCERC20Test is Test, IICS20Transfer {
function setUp() public {
_escrow = new Escrow(address(this));
ICS20Lib.Hop[] memory hops = new ICS20Lib.Hop[](1);
hops[0] = ICS20Lib.Hop({
portId: "testport",
channelId: "channel-42"
});
denom = ICS20Lib.Denom({
base: "test",
trace: hops
});
hops[0] = ICS20Lib.Hop({ portId: "testport", channelId: "channel-42" });
denom = ICS20Lib.Denom({ base: "test", trace: hops });
bytes32 denomID = ICS20Lib.getDenomIdentifier(denom);
ibcERC20 = new IBCERC20(IICS20Transfer(this), _escrow, denomID, denom);
}
Expand Down Expand Up @@ -138,7 +132,6 @@ contract IBCERC20Test is Test, IICS20Transfer {
function ibcERC20Contract(ICS20Lib.Denom calldata) external pure override returns (address) {
return address(0);
}


// Dummy implementation of IICS20Transfer
function newMsgSendPacketV2(
Expand Down
45 changes: 9 additions & 36 deletions test/solidity-ibc/ICS20LibTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
// // SPDX-License-Identifier: UNLICENSED
// pragma solidity ^0.8.28;
//
// // solhint-disable custom-errors,max-line-length
//
// import { Test } from "forge-std/Test.sol";
// import { ICS20Lib } from "../../contracts/utils/ICS20Lib.sol";
//
// contract ICS20LibTest is Test {
// struct IBCDenomTestCase {
// string denom;
// string expected;
// }
//
// function test_toIBCDenom() public pure {
// // Test cases against the ibc-go implementations output
// IBCDenomTestCase[3] memory testCases = [
// IBCDenomTestCase(
// "transfer/channel-0/uatom", "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
// ),
// IBCDenomTestCase(
// "transfer/channel-0/transfer/channel-52/uatom",
// "ibc/869A01B76A1E87154A4253B3493A2CDD106F4AE6E8F4800C252006C13B20C226"
// ),
// IBCDenomTestCase(
// "transfer/07-tendermint-0/stake", "ibc/D33713CAB4FB7F6E46CDB160183F558E99AFDA3C3A0F22B358273D374BECAA18"
// )
// ];
//
// for (uint256 i = 0; i < testCases.length; i++) {
// IBCDenomTestCase memory testCase = testCases[i];
// string memory actual = ICS20Lib.toIBCDenom(testCase.denom);
// assertEq(actual, testCase.expected);
// }
// }
// }
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

// solhint-disable custom-errors,max-line-length

import { Test } from "forge-std/Test.sol";

// solhint-disable-next-line no-empty-blocks
contract ICS20LibTest is Test { }
Loading

0 comments on commit b68558f

Please sign in to comment.