Address Contract Verified
Address
0xe2dDb832c0ed81b7ec097E9c9d3b20CEbbe01407
Balance
0.004359 ETH
Nonce
1
Code Size
5075 bytes
Creator
0x0D424e1a...41D1 at tx 0x625e6827...252514
Indexed Transactions
0
Contract Bytecode
5075 bytes
0x6080604052600436101561001257600080fd5b60003560e01c806335be7d8b14610d0f578063599ca04814610ca3578063673da15414610a675780637249fbb6146108ff5780638928777e14610804578063a9e0c1a514610775578063daebb789146103e25763f30ce07a1461007457600080fd5b6101403660031901126103dd5767ffffffffffffffff6004358181116103dd576100a2903690600401610dc3565b916024358181116103dd576100bb903690600401610dc3565b91906044358281116103dd576100d5903690600401610dc3565b9290916064358281116103dd576100f0903690600401610d95565b6084358481116103dd57610108903690600401610d95565b95909660a4358681116103dd57610123903690600401610d95565b95909660c4359081116103dd5761013e903690600401610d95565b909b909a90610104356001600160a01b03811690036103dd5765ffffffffffff610124351661012435036103dd57610384420142116103c75765ffffffffffff61012435166103844201116103b557610195611265565b60e4356000908152600160205260409020600301546001600160a01b03166103a3573415610391576040516101c981611055565b348152600160f81b6020808301918252600160408085018281523360608701908152610104356001600160a01b039081166080890190815265ffffffffffff610124351660a0808b0191825260c08b0188815260e4356000908152998990529690982099518a5597519589019590955591516002880155516003870180546001600160a01b03191691831691909117905591516004909501805494516001600160d01b031990951695909216949094179290911b65ffffffffffff60a01b169190911781559051815460ff60d01b191660d09190911b60ff60d01b161790556040519d8e6101209081815201906102bf926111da565b908d80830390602001526102d2926111da565b908b820360408d01526102e4926111da565b9089820360608b01526102f6926111b9565b908782036080890152610308926111b9565b9085820360a087015261031a926111b9565b9083820360c085015261032c926111b9565b3460e083015265ffffffffffff6101243516610100830152610104356001600160a01b031691339160e435917f48d52ce986069817751aa9893c41f6743eef33f5468ba8d638818a793fec500e9181900390a4600160005560405160e4358152602090f35b604051636f8ab38d60e11b8152600490fd5b604051630ed8e66b60e21b8152600490fd5b604051637c68874160e11b8152600490fd5b634e487b7160e01b600052601160045260246000fd5b600080fd5b6101403660031901126103dd5760643565ffffffffffff811681036103dd576084359065ffffffffffff821682036103dd5760a4356001600160a01b03811681036103dd5767ffffffffffffffff9260c4358481116103dd57610449903690600401610d95565b939060e4358681116103dd57610463903690600401610d95565b959096610104358181116103dd5761047f903690600401610d95565b91610124359081116103dd57610499903690600401610d95565b91909261038442018042116103c75765ffffffffffff8916106103b5576104be611265565b6004356000908152600160205260409020600301546001600160a01b03166103a357604435341180159061076d575b6103915765ffffffffffff881665ffffffffffff881611801561075c575b61074a5761062161051e604435346111ac565b6040519061052b82611055565b815260243560208201526001604082015233606082015260018060a01b038b16608082015260ff60a0820165ffffffffffff8c16815261060765ffffffffffff60c085019260018452600435600052600160205260406000208651815560208701516001820155604087015160028201556004600382019160018060a01b0360608a015116926bffffffffffffffffffffffff60a01b93848254161790550196608060018060a01b0391015116908754161786555116849081549065ffffffffffff60a01b9060a01b169065ffffffffffff60a01b1916179055565b51825460ff60d01b1916911660d01b60ff60d01b16179055565b6044356106fb575b610635604435346111ac565b9a6040519a610120808d6024358152602001528c0190610654926111b9565b908a820360408c0152610666926111b9565b9088820360608a0152610678926111b9565b90868203608088015261068a926111b9565b9460a085015260443560c085015265ffffffffffff1660e084015265ffffffffffff16610100830152600160a01b60019003169133918060043592037fd9bb64008dc2709fe211e8b5bbcf1671389cc4f5a4ffd295891f17c759a1817a91a460016000556040516004358152602090f35b60405161070781611023565b604435815265ffffffffffff60016020830192828b16845260043560005260026020526040600020905181550191511665ffffffffffff19825416179055610629565b6040516364df023960e01b8152600490fd5b504265ffffffffffff88161061050b565b5034156104ed565b346103dd5760603660031901126103dd5760443560043565ffffffffffff82168083036103dd576000828152600160205260409020600301546001600160a01b0316156107f25761038442018042116103c757116103b5576020916107e5916107dc611265565b602435906110bc565b6001600055604051908152f35b6040516368cadcd560e01b8152600490fd5b346103dd5760203660031901126103dd57600060c060405161082581611055565b8281528260208201528260408201528260608201528260808201528260a08201520152600435600052600160205260e0604060002060ff6040519161086983611055565b8054928381526001820154906020810191825260028301546040820190815260018060a01b03908160048160038801541696606086019788520154956080850192828816845265ffffffffffff968960c060a08901988a8c60a01c168a52019960d01c1689526040519a8b525160208b01525160408a01525116606088015251166080860152511660a0840152511660c0820152f35b346103dd5760203660031901126103dd576004356000818152600160205260409020600301546001600160a01b0316156107f25761093b611265565b806000526001602052604060002090600482019182549060ff8260d01c1660028114908115610a5c575b50610a4a574265ffffffffffff8360a01c1611610a385760ff60d01b19909116600160d11b179092556000818152600260209081526040822054909382918291829115610a14576109d060018060a01b03600383015416915487845260028952604084205490610df4565b90612710f1506109de611071565b505b604051907f92b8d387b3b4732fb701784c5e553091c36997ec127e0865a7c990bc62cc7382600080a2600160005560018152f35b60038101549054906001600160a01b0316612710f150610a32611071565b506109e0565b60405163b3f711f760e01b8152600490fd5b604051630c8d9eab60e31b8152600490fd5b600391501485610965565b346103dd5760403660031901126103dd5760043560008181526001602052604090206003015460243591906001600160a01b0316156107f257610aa8611265565b8060005260209160018352604060002060018101918254856040518382820152818152610ad481611023565b604051908051908360005b838110610c915750505090806000928101838152039060025afa15610c855760005103610c73576004820192835460ff8160d01c1660038114908115610c68575b50610a4a57600080807f7cbd5a76f728157ea921886950b9fb8dbf8f7c21b4d81b7ad97dd405e07a77a3976060978295600360d01b60ff60d01b1982161783558860028301558b845260028d5260408420908154158514610bba57505090549054906001600160a01b0316612710f150610b98611071565b505b5460405191338352868301526040820152a2600160005560405160018152f35b65ffffffffffff60018301541642108514610c0c57509091600360018060a01b038092541693858080808454612710998af150610bf5611071565b50015416905491f150610c06611071565b50610b9a565b6001600160a01b03908116933385148614610c4157610c3393945054169254905490610df4565b90612710f150610c06611071565b5050908380808093546127109687f150610c59611071565b5054903390f150610c06611071565b600291501488610b20565b60405163e73bcb3560e01b8152600490fd5b6040513d6000823e3d90fd5b81818401015181860152018490610adf565b346103dd5760203660031901126103dd5760006020604051610cc481611023565b8281520152600435600052600260205260408060002060018251610ce781611023565b602083549384835265ffffffffffff9384910154169101908152835192835251166020820152f35b346103dd57366003190160c081126103dd576060136103dd5760a43560ff811681036103dd576004356000908152600160205260409020600301546001600160a01b0316156107f25760443565ffffffffffff81168091036103dd5761038442018042116103c757116103b5576107e5602091610d8a611265565b608435606435610e01565b9181601f840112156103dd5782359167ffffffffffffffff83116103dd57602083818601950101116103dd57565b9181601f840112156103dd5782359167ffffffffffffffff83116103dd576020808501948460051b0101116103dd57565b919082018092116103c757565b6004803593604435936024359365ffffffffffff861693928487036103dd5760409485519060208201907fde6780c140fbc4ab251ad9d48d26e1652301c0f664623a09aeb6c54131b0fe5382528a8884015288606084015260808301526080825260a082019067ffffffffffffffff908383108284111761100e578289528351902061190160f01b60c085019081527f496d2cce309cea5c73e0de0eb84f4025129a5ade238b82f6c6a271d19e720dbb60c286015260e285019190915260428352926101200190811182821017610ff95791610ef296959391610ee995938952519020611288565b90939193611318565b600086815260016020528381206003015490926001600160a01b03908116911603610feb578582526001602052828220908082019160ff835460d01c1660028114908115610fe0575b50610fd1576001018054909190600160f81b03610fc35750849055805465ffffffffffff60a01b191660a086901b65ffffffffffff60a01b1617905580610fc057505190815265ffffffffffff909116602082015281907f4ceab1c2914b95780a2f8f611de30f855494a303ba92b618f434814a617637c79080604081015b0390a290565b80fd5b8451636e6870d560e01b8152fd5b508351630c8d9eab60e31b8152fd5b600391501438610f3b565b8251638baa579f60e01b8152fd5b604187634e487b7160e01b6000525260246000fd5b604188634e487b7160e01b6000525260246000fd5b6040810190811067ffffffffffffffff82111761103f57604052565b634e487b7160e01b600052604160045260246000fd5b60e0810190811067ffffffffffffffff82111761103f57604052565b3d156110b75767ffffffffffffffff903d82811161103f5760405192601f8201601f19908116603f011684019081118482101761103f5760405282523d6000602084013e565b606090565b9190826000526001602052604060002091600483019260ff845460d01c16600281149081156111a1575b50610a4a576003810154336001600160a01b039091160361118f576001018054909290600160f81b0361117d5791829055825465ffffffffffff60a01b191660a082901b65ffffffffffff60a01b161790925582917f4ceab1c2914b95780a2f8f611de30f855494a303ba92b618f434814a617637c7916040805191825265ffffffffffff90921660208201529081908101610fba565b604051636e6870d560e01b8152600490fd5b604051631d7eb35960e31b8152600490fd5b6003915014386110e6565b919082039182116103c757565b908060209392818452848401376000828201840152601f01601f1916010190565b908281815260208091019360208360051b82010194846000925b858410611205575050505050505090565b90919293949596601f198282030184528735601e19843603018112156103dd57830186810191903567ffffffffffffffff81116103dd5780360383136103dd57611254889283926001956111b9565b9901940194019295949391906111f4565b600260005414611276576002600055565b604051633ee5aeb560e01b8152600490fd5b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841161130c57926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa156113005780516001600160a01b038116156112f757918190565b50809160019190565b604051903d90823e3d90fd5b50505060009160039190565b6004811015611387578061132a575050565b600181036113445760405163f645eedf60e01b8152600490fd5b600281036113655760405163fce698f760e01b815260048101839052602490fd5b60031461136f5750565b602490604051906335e2f38360e21b82526004820152fd5b634e487b7160e01b600052602160045260246000fdfea2646970667358221220d59522ebeb31fe4dd69a718b16d3003a37af0a34474f4f3c8a94cef9a8e2fce864736f6c63430008170033
Verified Source Code Full Match
Compiler: v0.8.23+commit.f704f362
EVM: paris
Optimization: Yes (200 runs)
ECDSA.sol 180 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(
bytes32 hash,
bytes memory signature
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly ("memory-safe") {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}
ReentrancyGuard.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
HashedTimeLockEther.sol 463 lines
/*
_ __ _____
| | __ _ _ _ ___ _ __ _____ ____ _ _ __ \ \ / ( _ )
| | / _` | | | |/ _ \ '__/ __\ \ /\ / / _` | '_ \ \ \ / // _ \
| |__| (_| | |_| | __/ | \__ \\ V V / (_| | |_) | \ V /| (_) |
|_____\__,_|\__, |\___|_| |___/ \_/\_/ \__,_| .__/ \_/ \___/
|___/ |_|
*/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';
/// @title LayerswapV8 Contract
/// @notice Implements the Layerswap V8 PreHTLC protocol, enabling secure and atomic cross-chain swaps.
/// @dev Manages HTLCs for trustless cross-chain transactions with event-based updates.
/// @dev Represents the EIP-712 domain for signature verification.
struct EIP712Domain {
string name;
string version;
uint256 chainId;
address verifyingContract;
bytes32 salt;
}
contract LayerswapV8 is ReentrancyGuard {
using ECDSA for bytes32;
bytes32 private immutable DOMAIN_SEPARATOR;
/// @dev Sets up the EIP-712 domain details used for verifying signed messages.
constructor() {
DOMAIN_SEPARATOR = hashDomain(
EIP712Domain({
name: 'LayerswapV8',
version: '1',
chainId: block.chainid,
verifyingContract: address(this),
salt: 0x2e4ff7169d640efc0d28f2e302a56f1cf54aff7e127eededda94b3df0946f5c0
})
);
}
/// @dev Custom errors to simplify failure handling in the contract.
error FundsNotSent();
error NotPassedTimelock();
error HTLCAlreadyExists();
error HTLCNotExists();
error HashlockNotMatch();
error AlreadyClaimed();
error NoAllowance();
error InvalidSignature();
error HashlockAlreadySet();
error InvalidTimelock();
error InvaliRewardTimelock();
/// @dev Represents a hashed time-locked contract (HTLC) used in the Layerswap V8 protocol.
struct HTLC {
/// @notice The amount of funds locked in the HTLC.
uint256 amount;
/// @notice The hash of the secret required for redeem.
bytes32 hashlock;
/// @notice The secret required to redeem.
uint256 secret;
/// @notice The creator of the HTLC.
address payable sender;
/// @notice The recipient of the funds if conditions are met.
address payable srcReceiver;
/// @notice The timestamp after which the funds can be refunded.
uint48 timelock;
/// @notice Indicates whether the funds were claimed (redeemed(3) or refunded (2)).
uint8 claimed;
}
/// @dev Represents the details required to add a lock, used as part of the `addLockSig` parameters.
struct addLockMsg {
/// @notice The identifier of the HTLC to which the hashlock should be added and the timelock updated.
bytes32 Id;
/// @notice The hashlock to be added to the HTLC.
bytes32 hashlock;
/// @notice The new timelock to be set for the HTLC.
uint48 timelock;
}
/// @dev Represents the reward details including the amount and the timelock for claiming the reward.
struct Reward {
/// @notice The amount of the reward in wei to be claimed.
uint256 amount;
/// @notice The timelock (timestamp) after which the reward can be claimed.
uint48 timelock;
}
/// @dev Emitted when an HTLC is created and funds are committed.
/// @param Id The unique identifier of the HTLC.
/// @param hopChains The sequence of chains forming the path from the source to the destination chain.
/// @param hopAssets The sequence of assets being swapped along the path.
/// @param hopAddresses The sequence of addresses involved along the path.
/// @param dstChain The destination blockchain.
/// @param dstAddress The recipient address on the destination chain.
/// @param dstAsset The asset on the destination chain.
/// @param sender The creator of the HTLC.
/// @param srcReceiver The recipient of the funds if conditions are met.
/// @param srcAsset The asset being locked.
/// @param amount The amount of funds locked in the HTLC.
/// @param timelock The timestamp after which the funds can be refunded.
event TokenCommitted(
bytes32 indexed Id,
string[] hopChains,
string[] hopAssets,
string[] hopAddresses,
string dstChain,
string dstAddress,
string dstAsset,
address indexed sender,
address indexed srcReceiver,
string srcAsset,
uint256 amount,
uint48 timelock
);
/// @dev Emitted when an HTLC is locked with a hashlock and timelock.
/// @param reward The reward amount (in wei) associated with the HTLC.
/// @param rewardTimelock The timelock (timestamp) after which the reward can be claimed.
event TokenLocked(
bytes32 indexed Id,
bytes32 hashlock,
string dstChain,
string dstAddress,
string dstAsset,
address indexed sender,
address indexed srcReceiver,
string srcAsset,
uint256 amount,
uint256 reward,
uint48 rewardTimelock,
uint48 timelock
);
/// @dev Emitted when a hashlock and timelock are added to an existing HTLC.
event TokenLockAdded(bytes32 indexed Id, bytes32 hashlock, uint48 timelock);
/// @dev Emitted when funds are refunded from an HTLC after the timelock expires.
event TokenRefunded(bytes32 indexed Id);
/// @dev Emitted when funds are redeemed from an HTLC using the correct secret.
event TokenRedeemed(bytes32 indexed Id, address redeemAddress, uint256 secret, bytes32 hashlock);
/// @dev Modifier to ensure HTLC exists before proceeding.
modifier _exists(bytes32 Id) {
if (!hasHTLC(Id)) revert HTLCNotExists();
_;
}
/// @dev Modifier to ensure the provided timelock is at least 15 minutes in the future.
modifier _validTimelock(uint48 timelock) {
if (block.timestamp + 900 > timelock) revert InvalidTimelock();
_;
}
/// @dev Storage for HTLCs
mapping(bytes32 => HTLC) private contracts;
/// @dev Storage for rewards on unclaimed HTLCs
mapping(bytes32 => Reward) private rewards;
/// @notice Creates and commits a new hashed time-locked contract (HTLC).
/// @dev Locks funds in the contract and emits a `TokenCommitted` event.
/// @param hopChains The sequence of chains forming the path from the source to the destination chain.
/// @param hopAssets The sequence of assets being swapped along the path.
/// @param hopAddresses The sequence of addresses involved along the path.
/// @param dstChain The destination blockchain.
/// @param dstAsset The asset on the destination chain.
/// @param dstAddress The recipient address on the destination chain.
/// @param srcAsset The asset being locked.
/// @param Id The unique identifier of the created HTLC.
/// @param srcReceiver The recipient of the funds if conditions are met.
/// @param timelock The timestamp after which the funds can be refunded.
/// @return bytes32 The unique identifier of the created HTLC.
function commit(
string[] calldata hopChains,
string[] calldata hopAssets,
string[] calldata hopAddresses,
string calldata dstChain,
string calldata dstAsset,
string calldata dstAddress,
string calldata srcAsset,
bytes32 Id,
address srcReceiver,
uint48 timelock
) external payable _validTimelock(timelock) nonReentrant returns (bytes32) {
// Ensure the generated ID does not already exist to prevent overwriting.
if (hasHTLC(Id)) revert HTLCAlreadyExists();
if (msg.value == 0) revert FundsNotSent(); // Ensure funds are sent.
// Store HTLC details.
contracts[Id] = HTLC(
msg.value,
bytes32(bytes1(0x01)),
uint256(1),
payable(msg.sender),
payable(srcReceiver),
timelock,
uint8(1)
);
// Emit the commit event.
emit TokenCommitted(
Id,
hopChains,
hopAssets,
hopAddresses,
dstChain,
dstAddress,
dstAsset,
msg.sender,
srcReceiver,
srcAsset,
msg.value,
timelock
);
return Id;
}
/// @notice Refunds the locked funds from an HTLC after the timelock expires.
/// @dev Can only be called if the HTLC exists and the timelock has passed. Emits a `TokenRefunded` event.
/// @param Id The unique identifier of the HTLC to be refunded.
/// @return bool Returns `true` if the refund is successful.
function refund(bytes32 Id) external _exists(Id) nonReentrant returns (bool) {
HTLC storage htlc = contracts[Id];
if (htlc.claimed == 2 || htlc.claimed == 3) revert AlreadyClaimed(); // Prevent refund if already redeemed or refunded.
if (htlc.timelock > block.timestamp) revert NotPassedTimelock(); // Ensure timelock has passed.
htlc.claimed = 2;
if (rewards[Id].amount != 0) {
htlc.sender.call{ value: htlc.amount + rewards[Id].amount, gas: 10000 }('');
} else {
htlc.sender.call{ value: htlc.amount, gas: 10000 }('');
}
emit TokenRefunded(Id);
return true;
}
/// @notice Adds a hashlock and updates the timelock for an existing HTLC.
/// @dev Can only be called by the HTLC's creator if the HTLC exists and has not been claimed. Emits a `TokenLockAdded` event.
/// @param Id The unique identifier of the HTLC to update.
/// @param hashlock The hashlock to be added.
/// @param timelock The new timelock to be set.
/// @return bytes32 The updated HTLC identifier.
function addLock(
bytes32 Id,
bytes32 hashlock,
uint48 timelock
) external _exists(Id) _validTimelock(timelock) nonReentrant returns (bytes32) {
HTLC storage htlc = contracts[Id];
if (htlc.claimed == 2 || htlc.claimed == 3) revert AlreadyClaimed();
if (msg.sender == htlc.sender) {
if (htlc.hashlock == bytes32(bytes1(0x01))) {
htlc.hashlock = hashlock;
htlc.timelock = timelock;
} else {
revert HashlockAlreadySet(); // Prevent overwriting hashlock.
}
emit TokenLockAdded(Id, hashlock, timelock);
return Id;
} else {
revert NoAllowance(); // Ensure only allowed accounts can add a lock.
}
}
/// @notice Adds a hashlock and updates the timelock for an existing HTLC using a signed message.
/// @dev Verifies the provided signature and updates the HTLC if valid. Emits a `TokenLockAdded` event.
/// @param message The details of the lock to be added, including the HTLC ID, hashlock, and timelock.
/// @param r The `r` value of the ECDSA signature.
/// @param s The `s` value of the ECDSA signature.
/// @param v The `v` value of the ECDSA signature.
/// @return bytes32 The updated HTLC identifier.
function addLockSig(
addLockMsg calldata message,
bytes32 r,
bytes32 s,
uint8 v
) external _exists(message.Id) _validTimelock(message.timelock) nonReentrant returns (bytes32) {
if (verifyMessage(message, r, s, v)) {
HTLC storage htlc = contracts[message.Id];
if (htlc.claimed == 2 || htlc.claimed == 3) revert AlreadyClaimed();
if (htlc.hashlock == bytes32(bytes1(0x01))) {
htlc.hashlock = message.hashlock;
htlc.timelock = message.timelock;
} else {
revert HashlockAlreadySet();
}
emit TokenLockAdded(message.Id, message.hashlock, message.timelock);
return message.Id;
} else {
revert InvalidSignature(); // Ensure valid signature.
}
}
/// @notice Locks funds in a new hashed time-locked contract (HTLC).
/// @dev Creates an HTLC with the specified details and emits a `TokenLocked` event.
/// @param Id The unique identifier for the new HTLC.
/// @param hashlock The hash of the secret required for redeeming the HTLC.
/// @param reward The reward amount in wei granted to the caller of redeem.
/// @param rewardTimelock The timelock (timestamp) after which the reward can be claimed.
/// @param timelock The timestamp after which the funds can be refunded if not claimed.
/// @param srcReceiver The recipient of the funds if the HTLC is successfully redeemed.
/// @param srcAsset The asset being locked in the HTLC.
/// @param dstChain The destination blockchain for the swap.
/// @param dstAddress The recipient address on the destination chain.
/// @param dstAsset The asset on the destination chain.
/// @return bytes32 The unique identifier of the created HTLC.
function lock(
bytes32 Id,
bytes32 hashlock,
uint256 reward,
uint48 rewardTimelock,
uint48 timelock,
address payable srcReceiver,
string calldata srcAsset,
string calldata dstChain,
string calldata dstAddress,
string calldata dstAsset
) external payable _validTimelock(timelock) nonReentrant returns (bytes32) {
if (hasHTLC(Id)) revert HTLCAlreadyExists();
if (msg.value <= reward || msg.value == 0) revert FundsNotSent();
if (rewardTimelock > timelock || rewardTimelock < block.timestamp) revert InvaliRewardTimelock();
contracts[Id] = HTLC(
msg.value - reward,
hashlock,
uint256(1),
payable(msg.sender),
srcReceiver,
timelock,
uint8(1)
);
if (reward != 0) {
rewards[Id] = Reward(reward, rewardTimelock);
}
emit TokenLocked(
Id,
hashlock,
dstChain,
dstAddress,
dstAsset,
msg.sender,
srcReceiver,
srcAsset,
msg.value - reward,
reward,
rewardTimelock,
timelock
);
return Id;
}
/// @notice Redeems funds from an HTLC using the correct secret.
/// @dev Verifies the provided secret against the hashlock and transfers the funds to the recipient. Emits a `TokenRedeemed` event.
/// @param Id The unique identifier of the HTLC to be redeemed.
/// @param secret The secret value used to unlock the HTLC.
/// @return bool Returns `true` if the redemption is successful.
function redeem(bytes32 Id, uint256 secret) external _exists(Id) nonReentrant returns (bool) {
HTLC storage htlc = contracts[Id];
if (htlc.hashlock != sha256(abi.encodePacked(secret))) revert HashlockNotMatch(); // Ensure secret matches hashlock.
if (htlc.claimed == 3 || htlc.claimed == 2) revert AlreadyClaimed();
htlc.claimed = 3;
htlc.secret = secret;
Reward storage reward = rewards[Id];
if (reward.amount == 0) {
htlc.srcReceiver.call{ value: htlc.amount, gas: 10000 }('');
} else if (reward.timelock > block.timestamp) {
htlc.srcReceiver.call{ value: htlc.amount, gas: 10000 }('');
htlc.sender.call{ value: reward.amount, gas: 10000 }('');
} else {
if (msg.sender == htlc.srcReceiver) {
htlc.srcReceiver.call{ value: htlc.amount + reward.amount, gas: 10000 }('');
} else {
htlc.srcReceiver.call{ value: htlc.amount, gas: 10000 }('');
msg.sender.call{ value: reward.amount, gas: 10000 }('');
}
}
emit TokenRedeemed(Id, msg.sender, secret, htlc.hashlock);
return true;
}
/// @notice Retrieves the details of a specific HTLC.
/// @dev Returns the HTLC structure associated with the given identifier.
/// @param Id The unique identifier of the HTLC.
/// @return HTLC The details of the specified HTLC.
function getHTLCDetails(bytes32 Id) public view returns (HTLC memory) {
return contracts[Id];
}
/// @notice Fetches the reward details for a specific HTLC.
/// @dev Returns the reward amount (in wei) and the timelock after which it can be claimed.
/// @param Id The unique identifier of the HTLC.
/// @return Reward A struct with the reward amount and claimable timelock.
function getRewardDetails(bytes32 Id) public view returns (Reward memory) {
return rewards[Id];
}
/// @notice Generates a hash of the EIP-712 domain.
/// @dev Encodes and hashes the EIP-712 domain fields according to the specification.
/// @param domain The EIP-712 domain structure containing the domain details.
/// @return bytes32 The hashed representation of the EIP-712 domain.
function hashDomain(EIP712Domain memory domain) private pure returns (bytes32) {
return
keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)'),
keccak256(bytes(domain.name)),
keccak256(bytes(domain.version)),
domain.chainId,
domain.verifyingContract,
domain.salt
)
);
}
/// @notice Generates a hash of the `addLockMsg` structure.
/// @dev Encodes and hashes the `addLockMsg` fields for use in EIP-712 signature verification.
/// @param message The `addLockMsg` structure containing the HTLC details to be hashed.
/// @return bytes32 The hashed representation of the `addLockMsg` structure.
function hashMessage(addLockMsg calldata message) private pure returns (bytes32) {
return
keccak256(
abi.encode(
keccak256('addLockMsg(bytes32 Id,bytes32 hashlock,uint48 timelock)'),
message.Id,
message.hashlock,
message.timelock
)
);
}
/// @notice Verifies that an EIP-712 message signature matches the sender of the specified HTLC.
/// @dev Combines the domain separator and the hashed message to create the digest, then verifies the signature.
/// @param message The `addLockMsg` structure containing the HTLC details.
/// @param r The `r` value of the ECDSA signature.
/// @param s The `s` value of the ECDSA signature.
/// @param v The `v` value of the ECDSA signature.
/// @return bool Returns `true` if the signature is valid and matches the sender of the HTLC.
function verifyMessage(addLockMsg calldata message, bytes32 r, bytes32 s, uint8 v) private view returns (bool) {
bytes32 digest = keccak256(abi.encodePacked('\x19\x01', DOMAIN_SEPARATOR, hashMessage(message)));
return (ECDSA.recover(digest, v, r, s) == contracts[message.Id].sender);
}
/// @notice Checks whether an HTLC with the given Id exists.
/// @dev An HTLC exists if the sender address in its details is non-zero.
/// @param Id The unique identifier of the HTLC to check.
/// @return bool Returns `true` if the HTLC exists, otherwise `false`.
function hasHTLC(bytes32 Id) private view returns (bool) {
return (contracts[Id].sender != address(0));
}
}
Read Contract
getHTLCDetails 0x8928777e → tuple
getRewardDetails 0x599ca048 → tuple
Write Contract 6 functions
These functions modify contract state and require a wallet transaction to execute.
addLock 0xa9e0c1a5
bytes32 Id
bytes32 hashlock
uint48 timelock
returns: bytes32
addLockSig 0x68eb8f25
tuple message
bytes32 r
bytes32 s
uint8 v
returns: bytes32
commit 0xf30ce07a
string[] hopChains
string[] hopAssets
string[] hopAddresses
string dstChain
string dstAsset
string dstAddress
string srcAsset
bytes32 Id
address srcReceiver
uint48 timelock
returns: bytes32
lock 0xdaebb789
bytes32 Id
bytes32 hashlock
uint256 reward
uint48 rewardTimelock
uint48 timelock
address srcReceiver
string srcAsset
string dstChain
string dstAddress
string dstAsset
returns: bytes32
redeem 0x673da154
bytes32 Id
uint256 secret
returns: bool
refund 0x7249fbb6
bytes32 Id
returns: bool
Recent Transactions
No transactions found for this address