Skip to content

Commit

Permalink
Add allowance for consumer host and state channel (#408)
Browse files Browse the repository at this point in the history
* Add allowance for consumer host and state channel

* Rename

* fix typo
  • Loading branch information
nz-neooo authored May 27, 2024
1 parent 15d95d7 commit 8b62e52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contracts/ConsumerHost.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,15 @@ contract ConsumerHost is Initializable, OwnableUpgradeable, IConsumer, ERC165, S

// Approve Token to State Channel.
IERC20 sqt = IERC20(_sqt);
sqt.approve(_channel, sqt.totalSupply());
sqt.approve(_channel, type(uint256).max);
}

/**
* @notice approve enough token to state channel.
*/
function resetAllowance() external onlyOwner {
IERC20 sqt = IERC20(settings.getContractAddress(SQContracts.SQToken));
sqt.approve(settings.getContractAddress(SQContracts.StateChannel), type(uint256).max);
}

/**
Expand Down Expand Up @@ -247,7 +255,6 @@ contract ConsumerHost is Initializable, OwnableUpgradeable, IConsumer, ERC165, S
// transfer the balance to contract
IERC20 sqt = IERC20(settings.getContractAddress(SQContracts.SQToken));
sqt.safeTransferFrom(msg.sender, address(this), amount);
sqt.safeIncreaseAllowance(settings.getContractAddress(SQContracts.StateChannel), amount);

Consumer storage consumer = consumers[msg.sender];
consumer.balance += amount;
Expand Down
7 changes: 7 additions & 0 deletions publish/ABI/ConsumerHost.json
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,13 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "resetAllowance",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down

0 comments on commit 8b62e52

Please sign in to comment.