Skip to content

Commit

Permalink
Merge pull request #3 from gardenfi/fix/tob-garden-6
Browse files Browse the repository at this point in the history
TOB-GARDEN-6 resolution
  • Loading branch information
r4reetik authored Jun 18, 2024
2 parents 1b0fec2 + 593223f commit eeebb03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions contracts/fee/GardenFEEAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract GardenFEEAccount is EIP712Upgradeable {

struct HTLC {
bytes32 secretHash;
uint256 timeLock;
uint256 expiry;
uint256 sendAmount;
uint256 recieveAmount;
}
Expand All @@ -37,12 +37,12 @@ contract GardenFEEAccount is EIP712Upgradeable {
keccak256(
abi.encodePacked(
"Claim(uint256 nonce,uint256 amount,HTLC[] htlcs)",
"HTLC(bytes32 secretHash,uint256 timeLock,uint256 sendAmount,uint256 recieveAmount)"
"HTLC(bytes32 secretHash,uint256 expiry,uint256 sendAmount,uint256 recieveAmount)"
)
);

bytes32 private constant HTLC_TYPEHASH =
keccak256("HTLC(bytes32 secretHash,uint256 timeLock,uint256 sendAmount,uint256 recieveAmount)");
keccak256("HTLC(bytes32 secretHash,uint256 expiry,uint256 sendAmount,uint256 recieveAmount)");

// Are set when the channel is created
IERC20Upgradeable public token;
Expand Down Expand Up @@ -134,7 +134,7 @@ contract GardenFEEAccount is EIP712Upgradeable {

uint256 localSecretsProvided = 0;
for (uint256 i = 0; i < htlcs.length; i++) {
if (htlcs[i].timeLock > block.number && sha256(secrets[i]) == htlcs[i].secretHash) {
if (htlcs[i].expiry > block.number && sha256(secrets[i]) == htlcs[i].secretHash) {
localSecretsProvided++;
amount_ += htlcs[i].sendAmount;
amount_ -= htlcs[i].recieveAmount;
Expand Down Expand Up @@ -200,7 +200,7 @@ contract GardenFEEAccount is EIP712Upgradeable {
abi.encode(
HTLC_TYPEHASH,
htlcs[i].secretHash,
htlcs[i].timeLock,
htlcs[i].expiry,
htlcs[i].sendAmount,
htlcs[i].recieveAmount
)
Expand Down
40 changes: 20 additions & 20 deletions contracts/htlc/GardenHTLC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract GardenHTLC is EIP712 {
address initiator;
address redeemer;
uint256 initiatedAt;
uint256 expiry;
uint256 timelock;
uint256 amount;
}

Expand All @@ -33,7 +33,7 @@ contract GardenHTLC is EIP712 {
mapping(bytes32 => Order) public orders;

bytes32 private constant _INITIATE_TYPEHASH =
keccak256("Initiate(address redeemer,uint256 expiry,uint256 amount,bytes32 secretHash)");
keccak256("Initiate(address redeemer,uint256 timelock,uint256 amount,bytes32 secretHash)");

bytes32 private constant _REFUND_TYPEHASH = keccak256("Refund(bytes32 orderId)");

Expand All @@ -45,19 +45,19 @@ contract GardenHTLC is EIP712 {
* @notice .
* @dev provides checks to ensure
* 1. redeemer is not null address
* 3. expiry is greater than current block number
* 3. timelock is greater than 0
* 4. amount is not zero
* @param redeemer public address of the reedeem
* @param expiry expiry in period for the htlc order
* @param timelock timelock in period for the htlc order
* @param amount amount of tokens to trade
*/
modifier safeParams(
address redeemer,
uint256 expiry,
uint256 timelock,
uint256 amount
) {
require(redeemer != address(0), "GardenHTLC: zero address redeemer");
require(expiry > 0, "GardenHTLC: zero expiry");
require(timelock > 0, "GardenHTLC: zero timelock");
require(amount > 0, "GardenHTLC: zero amount");
_;
}
Expand All @@ -72,17 +72,17 @@ contract GardenHTLC is EIP712 {
* and sha256 hash should be used to support hashing methods on other non-evm chains.
* Signers cannot generate orders with same secret hash or override an existing order.
* @param redeemer public address of the redeemer
* @param expiry expiry in period for the htlc order
* @param timelock timelock in period for the htlc order
* @param amount amount of tokens to trade
* @param secretHash sha256 hash of the secret used for redemtion
**/
function initiate(
address redeemer,
uint256 expiry,
uint256 timelock,
uint256 amount,
bytes32 secretHash
) external safeParams(redeemer, expiry, amount) {
_initiate(msg.sender, redeemer, expiry, amount, secretHash);
) external safeParams(redeemer, timelock, amount) {
_initiate(msg.sender, redeemer, timelock, amount, secretHash);
}

/**
Expand All @@ -91,23 +91,23 @@ contract GardenHTLC is EIP712 {
* and sha256 hash should be used to support hashing methods on other non-evm chains.
* Signers cannot generate orders with same secret hash or override an existing order.
* @param redeemer public address of the redeemer
* @param expiry expiry in period for the htlc order
* @param timelock timelock in period for the htlc order
* @param amount amount of tokens to trade
* @param secretHash sha256 hash of the secret used for redemtion
* @param signature EIP712 signature provided by authorized user for iniatiation. user will be assigned as initiator
**/
function initiateWithSignature(
address redeemer,
uint256 expiry,
uint256 timelock,
uint256 amount,
bytes32 secretHash,
bytes calldata signature
) external safeParams(redeemer, expiry, amount) {
) external safeParams(redeemer, timelock, amount) {
address initiator = _hashTypedDataV4(
keccak256(abi.encode(_INITIATE_TYPEHASH, redeemer, expiry, amount, secretHash))
keccak256(abi.encode(_INITIATE_TYPEHASH, redeemer, timelock, amount, secretHash))
).recover(signature);

_initiate(initiator, redeemer, expiry, amount, secretHash);
_initiate(initiator, redeemer, timelock, amount, secretHash);
}

/**
Expand Down Expand Up @@ -136,7 +136,7 @@ contract GardenHTLC is EIP712 {
}

/**
* @notice Signers can refund the locked assets after expiry block number
* @notice Signers can refund the locked assets after timelock block number
* @dev Signers cannot refund the an order before epiry block number or refund the same order
* multiple times.
* Funds will be SafeTransferred to the initiator.
Expand All @@ -147,7 +147,7 @@ contract GardenHTLC is EIP712 {

require(order.redeemer != address(0), "GardenHTLC: order not initiated");
require(!order.isFulfilled, "GardenHTLC: order fulfilled");
require(order.initiatedAt + order.expiry < block.number, "GardenHTLC: order not expired");
require(order.initiatedAt + order.timelock < block.number, "GardenHTLC: order not expired");

order.isFulfilled = true;

Expand All @@ -166,13 +166,13 @@ contract GardenHTLC is EIP712 {
* @param initiator_ The address of the initiator of the atomic swap
* @param redeemer_ The address of the redeemer of the atomic swap
* @param secretHash_ The hash of the secret used for redemption
* @param expiry_ The expiry block number for the atomic swap
* @param timelock_ The timelock block number for the atomic swap
* @param amount_ The amount of tokens to be traded in the atomic swap
*/
function _initiate(
address initiator_,
address redeemer_,
uint256 expiry_,
uint256 timelock_,
uint256 amount_,
bytes32 secretHash_
) internal {
Expand All @@ -188,7 +188,7 @@ contract GardenHTLC is EIP712 {
initiator: initiator_,
redeemer: redeemer_,
initiatedAt: block.number,
expiry: expiry_,
timelock: timelock_,
amount: amount_
});
orders[orderID] = newOrder;
Expand Down

0 comments on commit eeebb03

Please sign in to comment.