From a31337bf080f468656a326d0f09aed1d5bb2d37a Mon Sep 17 00:00:00 2001 From: scx1332 Date: Mon, 11 Mar 2024 17:24:02 +0100 Subject: [PATCH] fixing contract --- crates/erc20_payment_lib/config-payments.toml | 2 +- yatestnet/contracts/contracts/LockPayment.sol | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/erc20_payment_lib/config-payments.toml b/crates/erc20_payment_lib/config-payments.toml index 48c1d60f..8cf8c34f 100644 --- a/crates/erc20_payment_lib/config-payments.toml +++ b/crates/erc20_payment_lib/config-payments.toml @@ -142,7 +142,7 @@ transaction-timeout = 100 token = { address = "0x8888888815bf4DB87e57B609A50f938311EEd068", symbol = "tGLM" } multi-contract = { address = "0xAaAAAaA00E1841A63342db7188abA84BDeE236c7", max-at-once = 10 } mint-contract = { address = "0xFACe100969FF47EB58d2CF603321B581A84bcEaC", max-glm-allowed = 400 } -lock-contract = { address = "0xD8b2D4e53350075333c2f6B90314518e01F42b2f" } +lock-contract = { address = "0xfe1B27Bac0e3Ad39d55C9459ae59894De847dcbf" } faucet-client = { max-eth-allowed = 0.009, faucet-srv = "_holesky-faucet._tcp", faucet-host = "faucet.testnet.golem.network", faucet-lookup-domain = "dev.golem.network", faucet-srv-port = 4002 } confirmation-blocks = 0 block-explorer-url = "https://holesky.etherscan.io" diff --git a/yatestnet/contracts/contracts/LockPayment.sol b/yatestnet/contracts/contracts/LockPayment.sol index c62c028c..dad6c6f7 100644 --- a/yatestnet/contracts/contracts/LockPayment.sol +++ b/yatestnet/contracts/contracts/LockPayment.sol @@ -133,13 +133,14 @@ contract LockPayment { deposits[id].feeAmount = 0; } - // funder can terminate deposit after validTo date elapses + // Funder can terminate deposit after validTo date elapses function terminateDeposit(uint64 nonce) public { uint256 id = idFromNonce(nonce); Deposit memory deposit = deposits[id]; - // customer cannot return funds before block_no - // sender can return funds at any time - require(deposit.validTo < block.timestamp); + //The following check is not needed (Funder is in id), but added for clarity + require(funderFromId(id) == msg.sender, "funderFromId(id) == msg.sender"); + // Check for time condition + require(deposit.validTo < block.timestamp, "deposit.validTo < block.timestamp"); require(GLM.transfer(msg.sender, deposit.amount + deposit.feeAmount), "transfer failed"); deposits[id].amount = 0; deposits[id].feeAmount = 0; @@ -149,7 +150,7 @@ contract LockPayment { Deposit memory deposit = deposits[id]; require(msg.sender == deposit.spender, "msg.sender == deposit.spender"); require(addr != deposit.spender, "cannot transfer to spender"); - require(GLM.transferFrom(address(this), addr, amount), "transferFrom failed"); + require(GLM.transfer(addr, amount), "transferFrom failed"); require(deposit.amount >= amount, "deposit.amount >= amount"); deposit.amount -= amount; deposits[id].amount = deposit.amount; @@ -167,7 +168,7 @@ contract LockPayment { address addr = address(bytes20(payment)); uint128 amount = uint128(uint256(payment) % 2 ** 96); require(addr != deposit.spender, "cannot transfer to spender"); - require(GLM.transferFrom(address(this), addr, amount), "transferFrom failed"); + require(GLM.transfer(addr, amount), "transferFrom failed"); require(deposit.amount >= amount, "deposit.amount >= amount"); deposit.amount -= amount; }