2

Below is the Scenario of the problem: I made some changes in the real concept because it will hard to understand the problem so I try to make it real simple.

I make a contract to facilitate some buying and selling of goods. A user (Alice) will create the smart contract(say goods contract) to sell its goods by using some factory contract and initialize the goods contract with some variables, then Alice will call a function to set the properties of the goods where Alice need to transfer Y amount of token as a security of successful transfer of good. for doing so a token proxy contract get also created in the same functions and transfer all those Y tokens to that token proxy contract.

Another user(bob) will buy the good. and after buying bid he did not want any product or there may be many reasons and needs settlement. For settlement, Bob called some function called settlement of goods contract and then the number of tokens will get back to bob from the token proxy contract.

Here in settlement() there is an internal call to distributeStakes() function of tokenProxy contract which calls a transfer function of the token and transfers the stakes to respective account.

Below is the goods contract

function issueGoods(uint256 _assetsOffered, uint256 _premium, uint256 _expiry) public {
   require(createProxy(_expiry));
   uint256 assets = _assetsOffered * strikePrice * 10 ** uint256(DECIMAL_FACTOR);
   require(QT.transferFrom(buyer, tokenProxy, assets));
   balances[this] = _assetsOffered;
   assetsOffered = _assetsOffered;
   premium = _premium;
   expiry = _expiry;
   Transfer(0x0, this, _assetsOffered);

}

function createProxy(uint256 _expiry) internal returns(bool) {
   tokenProxy = new Proxy(baseToken, quoteToken, _expiry, price, buyer);
   require(addressHasCode(tokenProxy));
   proxy = IProxy(tokenProxy);
   return true;

}

function settlement(uint256 _amount) external returns (bool) {
   uint256 amount = _amount * 10 ** uint256(DECIMAL_FACTOR);
   require(proxy.distributeStakes(msg.sender, amount));
   // Provide allowance to this by the trader
   require(this.transferFrom(msg.sender, 0x0, _amount));
   return true;

Below is tokenProxy contract

contract Proxy is IProxy {
  IERC20 public BT;
  IERC20 public QT;
  address public option;
  address public buyer;
  uint256 public dealExpiry;
  uint256 public price;
   function Proxy(address _baseToken, address _quoteToken, uint256 _expiry, uint256 _strikePrice, address _buyer) public {
      BT = IERC20(_baseToken);
      QT = IERC20(_quoteToken);
      dealExpiry = _expiry;
      price = _price;
      buyer = _buyer;
 }

   function distributeStakes(address _to, uint256 _amount) public returns (bool success) {
        require(QT.transfer(to, amount)); 
        require(BT.transferFrom(_to, buyer, _amount));
     }
     return true;
 }

}

For some reason settlement call doesn't get executed successfully. When I debug the tx it went down at the distributeStakes() function line require(QT.transfer(to, amount)) by giving the revert error. I don't understand the reason. and at truffle debugging it me this.

debug(develop:0x9757d361...)>

(596) PUSH1 0x60 No data on stack.

? | 0x9efec315e368e8812025b85b399a69513cd0e716:

1: // No source code found.

Any help is very much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.