Skip to content

Commit

Permalink
wiotx unwrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderZhi committed Nov 20, 2024
1 parent de54ee9 commit 75ba1af
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
27 changes: 27 additions & 0 deletions contracts/WIOTXUnwrapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity >= 0.8.0;

interface IWIOTX {
function withdraw(uint256) external;
}

contract WIOTXUnwrapper {
address public wiotx;

constructor(address _wiotx) {
wiotx = _wiotx;
}

receive() external payable {
}

function onReceive(address _sender, IWIOTX _token, uint256 _amount, bytes calldata _payload) external {
require(address(_token) == wiotx, "WIOTXUnwrapper: invalid token");
address recipient = _sender;
if (_payload.length == 32) {
(recipient) = abi.decode(_payload, (address));
}
_token.withdraw(_amount);
payable(recipient).transfer(_amount);
}
}
3 changes: 3 additions & 0 deletions witness-service/configs/witness-config-ethereum-payload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ cashiers:
# USDa
- token2: "0xeaa38983d3370e35fb42229f89e816e28035a74b"
token1: "0xBB76063476A79F73624386795f4CcA855954C891"
# W-IOTX
- token2: "io15qr5fzpxsnp7garl4m7k355rafzqn8grrm0grz"
token1: "0x6fB3e0A217407EFFf7Ca062D46c26E5d60a14d69"
2 changes: 1 addition & 1 deletion witness-service/relayer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func (s *Service) submitTransfers() error {
if err := s.submitTransfer(transfer, validator); err != nil {
util.Alert("failed to submit transfer" + err.Error())
}
time.Sleep(2 * time.Second)
time.Sleep(5 * time.Second)
}
}
return nil
Expand Down
8 changes: 6 additions & 2 deletions witness-service/relayer/transfervalidatoronethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"crypto/ecdsa"
"log"
"math/big"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -382,7 +383,7 @@ func (tv *transferValidatorOnEthereum) Check(transfer *Transfer) (StatusOnChainT
switch errors.Cause(err) {
case ethereum.NotFound:
if transfer.nonce <= nonce {
if transfer.updateTime.Add(5 * time.Minute).Before(time.Now()) {
if transfer.updateTime.Add(10 * time.Minute).Before(time.Now()) {
return StatusOnChainNonceOverwritten, nil
}
return StatusOnChainNotConfirmed, nil
Expand All @@ -397,7 +398,7 @@ func (tv *transferValidatorOnEthereum) Check(transfer *Transfer) (StatusOnChainT
default:
return StatusOnChainUnknown, err
}
if transfer.updateTime.After(time.Now().Add(-10 * time.Minute)) {
if transfer.updateTime.After(time.Now().Add(-20 * time.Minute)) {
return StatusOnChainNotConfirmed, nil
}
// no matter what the receipt status is, mark the validation as failure
Expand Down Expand Up @@ -465,6 +466,9 @@ func (tv *transferValidatorOnEthereum) submit(transfer *Transfer, witnesses []*W
case ethereum.NotFound:
return common.Hash{}, common.Address{}, 0, nil, errors.Wrap(errNoncritical, err.Error())
default:
if strings.Contains(err.Error(), "could not replace existing tx") {
return common.Hash{}, common.Address{}, 0, nil, errors.Wrap(errNoncritical, err.Error())
}
return common.Hash{}, common.Address{}, 0, nil, err
}
}
Expand Down

0 comments on commit 75ba1af

Please sign in to comment.