Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e2567f4
feat: develop for native currencies
aimensahnoun Sep 12, 2024
c624474
feat: develop for ERC20 currencies
aimensahnoun Sep 12, 2024
917d472
feat: create `EthereumSingleRequestProxy` factory contract
aimensahnoun Sep 12, 2024
d5e4728
feat: create `ERC20SingleRequestProxy` factory contract
aimensahnoun Sep 12, 2024
0543092
refactor: merge the single request proxy factories into one factory
aimensahnoun Sep 13, 2024
2bd3495
fix: infinite loop between `EthSingleRequestProxy` and `EthFeeProxy`
aimensahnoun Sep 13, 2024
19b5e40
refactor: refactor `nonReentrant` to match openzeppelin implementation
aimensahnoun Sep 16, 2024
c1d3a77
fix: update `ERC20SingleRequestProxy` to use `balance`
aimensahnoun Sep 16, 2024
1376582
fix: update `SingleRequestProxyFactory` to call Ownable constructor
aimensahnoun Sep 16, 2024
c2f55ee
chore: update contracts to use `0.8.9` solidity version
aimensahnoun Sep 17, 2024
bc922e8
test: add test for `EthereumSingleRequestProxy`
aimensahnoun Sep 18, 2024
8aef234
fix: `ERC20SingleRequestProxy` to factor in fee amount
aimensahnoun Sep 18, 2024
0769aa7
test: `ERC20SingleRequestProxy` functionality
aimensahnoun Sep 18, 2024
3bd9e38
test: `SingleRequestProxyFactory` functionality
aimensahnoun Sep 18, 2024
ed429ae
chore: update `EthereumSingleRequestProxy` tests
aimensahnoun Sep 18, 2024
d9a4484
Merge branch 'master' into 1394-develop-smart-contracts-nativesingler…
aimensahnoun Sep 18, 2024
a341ce1
feat: write deployment script for `SingleRequestProxyFactory`
aimensahnoun Sep 23, 2024
10974b5
Merge branch '1394-develop-smart-contracts-nativesinglerequestproxy-e…
aimensahnoun Sep 23, 2024
2cc82a0
refactor: rewrite deployment to use `CREATE2` schema
aimensahnoun Sep 23, 2024
bee1f58
fix: add SingleRequestProxyFactory `create2ContractDeploymentList`
aimensahnoun Sep 23, 2024
aab6711
chore: include SingleRequestProxyFactory in transfer ownership cases …
aimensahnoun Sep 23, 2024
0c68eba
refactor: rename updateEthereumFeeProxy to setEthereumFeeProxy for cl…
aimensahnoun Sep 23, 2024
796f2b9
Merge branch 'master' into 1394-develop-smart-contracts-nativesingler…
aimensahnoun Sep 23, 2024
0482f6d
fix: type and add new events
aimensahnoun Sep 26, 2024
b8183f3
Merge branch '1394-develop-smart-contracts-nativesinglerequestproxy-e…
aimensahnoun Sep 26, 2024
85fdc13
Merge branch 'master' of github.com:RequestNetwork/requestNetwork int…
aimensahnoun Oct 16, 2024
9033066
docs: add more documentation to nonReentrant modifier
aimensahnoun Oct 16, 2024
cd91ec2
feat: add `rescueFunds` to `EthereumSingleRequestProxy`
aimensahnoun Oct 16, 2024
f944199
docs: add more documentation to `SingleRequestProxyFactory`
aimensahnoun Oct 16, 2024
c77c1eb
fix: use `safeApprove` instead of `approve`
aimensahnoun Oct 16, 2024
41e43b5
feat: add rescue funds method
aimensahnoun Oct 17, 2024
01c28d2
test: add more ownership tests
aimensahnoun Oct 17, 2024
cfba1b9
test: add partial payment and non-standard ERC20 tests
aimensahnoun Oct 17, 2024
7241e0c
test: add rescue-funds tests
aimensahnoun Oct 17, 2024
4abe9e9
test: refactor tests
aimensahnoun Oct 17, 2024
90b413f
test: add await back
aimensahnoun Oct 17, 2024
c493758
feat: add triggerERC20Payment
aimensahnoun Oct 17, 2024
06e015a
chore: add require for zero address
aimensahnoun Oct 17, 2024
c778b17
feat: add rescue methods for ERC20 and native tokens
aimensahnoun Oct 17, 2024
b45607a
test: add tests for both rescue methods
aimensahnoun Oct 17, 2024
c58dfc0
fix: rename rescueFunds to rescueERC20Funds
aimensahnoun Oct 17, 2024
9ee661a
fix: typo in "receive"
aimensahnoun Oct 18, 2024
0141d22
Merge branch 'master' of github.com:RequestNetwork/requestNetwork int…
aimensahnoun Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add triggerERC20Payment
  • Loading branch information
aimensahnoun committed Oct 17, 2024
commit c4937584d7836acf49f323e9c587d8d10319b765
12 changes: 10 additions & 2 deletions packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ contract ERC20SingleRequestProxy {

receive() external payable {
require(msg.value == 0, 'This function is only for triggering the transfer');
_processPayment();
}

function triggerERC20Payment() external {
_processPayment();
}

function _processPayment() internal {
IERC20 token = IERC20(tokenAddress);
uint256 balance = token.balanceOf(address(this));
uint256 paymentAmount = balance;
Expand All @@ -60,8 +68,8 @@ contract ERC20SingleRequestProxy {
* @notice Rescues any trapped funds by sending them to the payee
* @dev Can be called by anyone, but funds are always sent to the payee
*/
function rescueFunds() external {
IERC20 token = IERC20(tokenAddress);
function rescueFunds(address _tokenAddress) external {
IERC20 token = IERC20(_tokenAddress);
uint256 balance = token.balanceOf(address(this));
require(balance > 0, 'No funds to rescue');
bool success = SafeERC20.safeTransfer(token, payee, balance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('contract: ERC20SingleRequestProxy', () => {
expect(await erc20SingleRequestProxy.erc20FeeProxy()).to.equal(erc20FeeProxy.address);
});

it('should process a payment correctly', async () => {
it('should process a payment correctly via recieve', async () => {
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Typo in test description: 'recieve' should be 'receive'

The test description on line 79 contains a typo. It should read 'should process a payment correctly via receive'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true 👍 There's a typo - receive is mispelled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MantisClone, glad we caught that typo! 😄

(_/)
(='.'=)
(")
(")


🧠 Learnings used
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts:0-0
Timestamp: 2024-10-17T16:01:47.326Z
Learning: The `rescueFunds` function in `EthereumSingleRequestProxy` does not emit any events.

const paymentAmount = BN.from(100).mul(BASE_DECIMAL);
const totalAmount = paymentAmount.add(feeAmount);

Expand Down Expand Up @@ -114,9 +114,8 @@ describe('contract: ERC20SingleRequestProxy', () => {
expect(feeRecipientBalanceAfter).to.equal(feeAmount);
});

it('should process a partial payment correctly', async () => {
// Pay 10 tokens instead of 100
const paymentAmount = BN.from(10).mul(BASE_DECIMAL);
it('should process a payment correctly via triggerERC20Payment', async () => {
const paymentAmount = BN.from(100).mul(BASE_DECIMAL);
const totalAmount = paymentAmount.add(feeAmount);

await testToken.connect(user1).transfer(erc20SingleRequestProxy.address, totalAmount);
Expand All @@ -126,12 +125,7 @@ describe('contract: ERC20SingleRequestProxy', () => {
);
expect(erc20SingleRequestProxyBalanceBefore).to.equal(totalAmount);

await expect(
user1.sendTransaction({
to: erc20SingleRequestProxy.address,
value: 0,
}),
)
await expect(erc20SingleRequestProxy.triggerERC20Payment())
.to.emit(erc20FeeProxy, 'TransferWithReferenceAndFee')
.withArgs(
testToken.address,
Expand All @@ -153,6 +147,10 @@ describe('contract: ERC20SingleRequestProxy', () => {
expect(feeRecipientBalanceAfter).to.equal(feeAmount);
});

it.skip('should process a partial payment correctly', async () => {
// Smart contract does not keep track of the payment amount, it accepts any amount of tokens
});

it('should process a payment with a non-standard ERC20', async () => {
const usdtFeeAmount = BN.from(10).mul(USDT_DECIMAL);
const usdtProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy(
Expand Down Expand Up @@ -265,7 +263,7 @@ describe('contract: ERC20SingleRequestProxy', () => {

const payeeBalanceBefore = await testToken.balanceOf(user2Addr);

await erc20SingleRequestProxy.rescueFunds();
await erc20SingleRequestProxy.rescueFunds(testToken.address);

const contractBalanceAfter = await testToken.balanceOf(erc20SingleRequestProxy.address);
expect(contractBalanceAfter).to.equal(0);
Expand Down