Skip to content

Commit

Permalink
Merge pull request #832 from oceanprotocol/feature/check_fre_basetoke…
Browse files Browse the repository at this point in the history
…n_for_eoa

check if basetoken is contract
  • Loading branch information
alexcos20 authored Oct 26, 2023
2 parents fa8abae + 3f6697c commit 1a2cad4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion contracts/pools/fixedRate/FixedRateExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,18 @@ contract FixedRateExchange is ReentrancyGuard, IFixedRateExchange {
return IFactoryRouter(router).getOPCFee(baseTokenAddress);
}


/**
* @dev isContract
* checks if address is a contract
* addr - address to be checked
*/
function isContract(address addr) public view returns(bool){
uint32 size;
assembly {
size := extcodesize(addr)
}
return (size > 0);
}
/**
* @dev create
* creates new exchange pairs between a baseToken
Expand Down Expand Up @@ -209,6 +220,10 @@ contract FixedRateExchange is ReentrancyGuard, IFixedRateExchange {
addresses[0] != address(0),
"FixedRateExchange: Invalid baseToken, zero address"
);
require(
isContract(addresses[0]),
"FixedRateExchange: Invalid baseToken, looks EOA"
);
require(
datatoken != address(0),
"FixedRateExchange: Invalid datatoken, zero address"
Expand Down
9 changes: 9 additions & 0 deletions test/flow/FixedRateExchange.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ describe("FixedRateExchange", () => {
mockDT18 = erc20Token;
});

it("should fail if basetoken is EOA", async () => {
await expectRevert(mockDT18.connect(alice)
.createFixedRate(
fixedRateExchange.address,
[bob.address, alice.address, marketFeeCollector.address, ZERO_ADDRESS],
[18, 18, rate, marketFee, 0])
,"FixedRateExchange: Invalid baseToken, looks EOA" )

});
it("#2 - create exchange", async () => {
marketFee = 1e15;

Expand Down

0 comments on commit 1a2cad4

Please sign in to comment.