Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes committed Mar 9, 2025
1 parent 2de242c commit 1e50e04
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 98 deletions.
8 changes: 4 additions & 4 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ contract Gateway is IGatewayBase, IGatewayV1, IGatewayV2, IInitializable, IUpgra
// Makes functions nonreentrant
modifier nonreentrant() {
assembly {
if tload(0) {
revert(0, 0)
}
if tload(0) { revert(0, 0) }
tstore(0, 1)
}
_;
Expand Down Expand Up @@ -439,7 +437,9 @@ contract Gateway is IGatewayBase, IGatewayV1, IGatewayV2, IInitializable, IUpgra
// Dispatch the message payload
bool success = v2_dispatch(message);

emit IGatewayV2.InboundMessageDispatched(message.nonce, message.topic, success, rewardAddress);
emit IGatewayV2.InboundMessageDispatched(
message.nonce, message.topic, success, rewardAddress
);
}

// Dispatch all the commands within a message payload
Expand Down
17 changes: 13 additions & 4 deletions contracts/src/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ contract Token is IERC20, IERC20Metadata, IERC20Permit {
return token.approve(spender, amount);
}

function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) {
function transferFrom(address sender, address recipient, uint256 amount)
external
returns (bool)
{
return token.transferFrom(sender, recipient, amount);
}

Expand All @@ -79,9 +82,15 @@ contract Token is IERC20, IERC20Metadata, IERC20Permit {
return TokenLib.domainSeparator(name);
}

function permit(address issuer, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
{
function permit(
address issuer,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external {
token.permit(name, issuer, spender, value, deadline, v, r, s);
}

Expand Down
38 changes: 25 additions & 13 deletions contracts/src/TokenLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import {IERC20Permit} from "./interfaces/IERC20Permit.sol";
import {ECDSA} from "openzeppelin/utils/cryptography/ECDSA.sol";

library TokenLib {

/// The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
bytes32 public constant DOMAIN_TYPEHASH = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);

/// The EIP-712 typehash for the permit struct used by the contract
bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);

struct Token {
mapping(address account => uint256) balance;
Expand All @@ -32,12 +35,18 @@ library TokenLib {
_update(token, account, address(0), amount);
}

function approve(Token storage token, address spender, uint256 amount) external returns (bool) {
function approve(Token storage token, address spender, uint256 amount)
external
returns (bool)
{
_approve(token, msg.sender, spender, amount, true);
return true;
}

function transfer(Token storage token, address recipient, uint256 amount) external returns (bool) {
function transfer(Token storage token, address recipient, uint256 amount)
external
returns (bool)
{
_transfer(token, msg.sender, recipient, amount);
return true;
}
Expand Down Expand Up @@ -70,12 +79,7 @@ library TokenLib {
_domainSeparator(tokenName),
keccak256(
abi.encode(
PERMIT_TYPEHASH,
issuer,
spender,
value,
token.nonces[issuer]++,
deadline
PERMIT_TYPEHASH, issuer, spender, value, token.nonces[issuer]++, deadline
)
)
)
Expand Down Expand Up @@ -103,7 +107,9 @@ library TokenLib {
);
}

function _transfer(Token storage token, address sender, address recipient, uint256 amount) internal {
function _transfer(Token storage token, address sender, address recipient, uint256 amount)
internal
{
require(sender != address(0), IERC20.InvalidSender(address(0)));
require(recipient != address(0), IERC20.InvalidReceiver(address(0)));
_update(token, sender, recipient, amount);
Expand All @@ -123,7 +129,13 @@ library TokenLib {
return true;
}

function _approve(Token storage token, address owner, address spender, uint256 amount, bool emitEvent) internal {
function _approve(
Token storage token,
address owner,
address spender,
uint256 amount,
bool emitEvent
) internal {
require(owner != address(0), IERC20.InvalidApprover(address(0)));
require(spender != address(0), IERC20.InvalidSpender(address(0)));

Expand Down
13 changes: 7 additions & 6 deletions contracts/src/Verification.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ library Verification {
}

// Verify that a message commitment is in the header digest
function isCommitmentInHeaderDigest(bytes32 commitment, ParachainHeader calldata header, bool isV2)
internal
pure
returns (bool)
{
function isCommitmentInHeaderDigest(
bytes32 commitment,
ParachainHeader calldata header,
bool isV2
) internal pure returns (bool) {
for (uint256 i = 0; i < header.digestItems.length; i++) {
if (
header.digestItems[i].kind == DIGEST_ITEM_OTHER
Expand All @@ -151,7 +151,8 @@ library Verification {
return true;
}
if (
isV2 && header.digestItems[i].kind == DIGEST_ITEM_OTHER && header.digestItems[i].data.length == 33
isV2 && header.digestItems[i].kind == DIGEST_ITEM_OTHER
&& header.digestItems[i].data.length == 33
&& header.digestItems[i].data[0] == DIGEST_ITEM_OTHER_SNOWBRIDGE_V2
&& commitment == bytes32(header.digestItems[i].data[1:])
) {
Expand Down
4 changes: 3 additions & 1 deletion contracts/src/v2/IGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ interface IGatewayV2 {
*/

// V2: Emitted when inbound message has been dispatched
event InboundMessageDispatched(uint64 indexed nonce, bytes32 topic, bool success, bytes32 rewardAddress);
event InboundMessageDispatched(
uint64 indexed nonce, bytes32 topic, bool success, bytes32 rewardAddress
);

// v2 Emitted when an outbound message has been accepted for delivery to a Polkadot parachain
event OutboundMessageAccepted(uint64 nonce, Payload payload);
Expand Down
1 change: 0 additions & 1 deletion contracts/test/GatewayV1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ contract GatewayV1Test is Test {
/**
* Message Verification
*/

function testLegacyUnlockWethHappyPath() public {
address recipient = makeAddr("test_recipeint");
uint128 amount = 1;
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ScaleCodec.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ contract ScaleCodecTest is Test {
}

function testEncodeCompactU128() public {
assertEq(ScaleCodec.encodeCompactU128(9000000000000), hex"0b0090cd792f08");
assertEq(ScaleCodec.encodeCompactU128(9_000_000_000_000), hex"0b0090cd792f08");
}
}
Loading

0 comments on commit 1e50e04

Please sign in to comment.