Skip to content

Commit 9f60dd1

Browse files
authored
Merge pull request #1007 from oceanprotocol/feature/escrow_with_permit
add permit to escrow contracts
2 parents cfb6abb + 5bd73d5 commit 9f60dd1

8 files changed

Lines changed: 510 additions & 27 deletions

File tree

addresses/address.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@
145145
"VestingWalletC": "0x29F74B853C4B8D36273666FB63a3b71c754424Ed",
146146
"OceanNodesBooster": "0x73558Ef3bb6543A8107ac032C5a98Da03ceb0eEf",
147147
"OPFCommunityFeeCollectorCompute": "0x1705CaF86B86e85804e20FE342f39B17322Ff592",
148-
"Escrow": "0x225Fd0CfA1200F1e42c6C54071B646738A1d81bb",
148+
"Escrow": "0xC98C71A9efeF2a940c73B7986f1D8469f1815F94",
149149
"AccessListFactory": "0x7ed6ac4243472adA55408fEE45c5Dff379f7aBE0",
150150
"EnterpriseFeeCollector": "0x254302d1Ae1e1200319c885D93D40a8927ACFcD7",
151-
"EnterpriseEscrow": "0x7F773EE2B8AFE158FA03B72fC20672B408Cd9818",
151+
"EnterpriseEscrow": "0x2213FeBd4E681633bE255AfceFbd233EbcFc33c9",
152152
"FixedPriceEnterprise": "0x6C97D128f7E7D21ac3C722458Dc5d71f7e1bBa6e"
153153
},
154154
"goerli": {
@@ -305,14 +305,14 @@
305305
"Dispenser": "0x2720d405ef7cDC8a2E2e5AeBC8883C99611d893C",
306306
"ERC721Factory": "0xEF62FB495266C72a5212A11Dce8baa79Ec0ABeB1",
307307
"OPFCommunityFeeCollectorCompute": "0x0Ee8b03Dafc868a0899ebE1c12d734D53A957250",
308-
"Escrow": "0x8149276f275EEFAc110D74AFE8AFECEaeC7d1593",
308+
"Escrow": "0xd09789Ce05aa0f6feFc18315de4964Db07Cc0618",
309309
"EnterpriseFeeCollector": "0x8c98ea273bA22327F896Aa1a1a46E1BFf56e9b1D",
310310
"FixedPriceEnterprise": "0xfa48673a7C36A2A768f89AC1ee8C355D5c367B02",
311311
"AccessListFactory": "0x43eC0a34E1b70C7f8E579ab866F37642777727E7",
312-
"EnterpriseEscrow": "0x49E35cd2bAE043Abd9074B6e5a649a5AdEB05C33",
313-
"COMPY":"0x973e69303259B0c2543a38665122b773D28405fB",
314-
"COMPYFaucet":"0x3EFDD8f728c8e774aB81D14d0B2F07a8238960f4",
315-
"COMPYSwap":"0x8B8E187CF9c551e63f54AA04E21F48CDAF2296aE"
312+
"EnterpriseEscrow": "0x6fd867E5AEE6D62a24f97939db90C4e67A73A651",
313+
"COMPY": "0x973e69303259B0c2543a38665122b773D28405fB",
314+
"COMPYFaucet": "0x3EFDD8f728c8e774aB81D14d0B2F07a8238960f4",
315+
"COMPYSwap": "0x8B8E187CF9c551e63f54AA04E21F48CDAF2296aE"
316316
},
317317
"oasis_sapphire": {
318318
"chainId": 23294,
@@ -339,7 +339,7 @@
339339
"AccessListFactory": "0x12bB8D85a091A69A07E22E52d4567dBB91568f52",
340340
"BatchPayments": "0x9497d1d64F2aFeBcd4f9916Eef3d9094E5Df962f",
341341
"OPFCommunityFeeCollectorCompute": "0xE5aa2C9B551aFcA4C0A98BB3B37D7A43084d0a66",
342-
"Escrow": "0xA0329eFFa1370eAb1DC5998Db4292ae0F535a282"
342+
"Escrow": "0x0Ee8b03Dafc868a0899ebE1c12d734D53A957250"
343343
},
344344
"optimism_sepolia": {
345345
"chainId": 11155420,
@@ -358,7 +358,7 @@
358358
"Dispenser": "0x30E4CC2C7A9c6aA2b2Ce93586E3Df24a3A00bcDD",
359359
"ERC721Factory": "0xDEfD0018969cd2d4E648209F876ADe184815f038",
360360
"OPFCommunityFeeCollectorCompute": "0xe47991939632757DEe324E8ec9A3268c62C0DB76",
361-
"Escrow": "0xD3173c3E3d9ea662E914C30Bcd647eF573AcE405",
361+
"Escrow": "0x23A8b2D7176485a6349e4830605F323f31019333",
362362
"AccessListFactory": "0xEcD0C3519a081e3924D6F3197f86980eA7dfCf71"
363363
},
364364
"optimism": {
@@ -378,10 +378,10 @@
378378
"Dispenser": "0x2112Eb973af1DBf83a4f11eda82f7a7527D7Fde5",
379379
"ERC721Factory": "0x80E63f73cAc60c1662f27D2DFd2EA834acddBaa8",
380380
"OPFCommunityFeeCollectorCompute": "0xc37F8341Ac6e4a94538302bCd4d49Cf0852D30C0",
381-
"Escrow": "0x98679D582AB3398C03D3308dEB9c7AeC50B52ded",
381+
"Escrow": "0x4dD281EB67DED07E76E413Df16176D66ae69e240",
382382
"AccessListFactory": "0x4E6058dC00e90C0DCA47A5d0D3346F409939A5ab",
383383
"EnterpriseFeeCollector": "0xE9397625Df9B63f0C152f975234b7988b54710B8",
384-
"EnterpriseEscrow": "0xc313e19146Fc9a04470689C9d41a4D3054693531",
384+
"EnterpriseEscrow": "0xFe7967A5176fDAFa8DE109b3507016B885a82D6e",
385385
"FixedPriceEnterprise": "0x1d535147a97bd87c8443125376E6671B60556E07"
386386
},
387387
"pontus-x-devnet": {
@@ -418,10 +418,10 @@
418418
"ERC721Factory": "0x159924ca0F47D6F704B97E29099b89e518A17B5E",
419419
"BatchPayments": "0xFe7967A5176fDAFa8DE109b3507016B885a82D6e",
420420
"OPFCommunityFeeCollectorCompute": "0x7b0576CF01E868bce46cca91b2a8E674141b0355",
421-
"Escrow": "0xf0c7A31D7Ee26bEBfb4BAD8e37490bEadE3F846f",
421+
"Escrow": "0x43eC0a34E1b70C7f8E579ab866F37642777727E7",
422422
"AccessListFactory": "0xE5aa2C9B551aFcA4C0A98BB3B37D7A43084d0a66",
423-
"COMPY":"0x298f163244e0c8cc9316D6E97162e5792ac5d410",
424-
"COMPYFaucet":"0x23A8b2D7176485a6349e4830605F323f31019333",
425-
"COMPYSwap":"0xb65F19225fEBb650Fcc211dC9F18FEC6f4a328D5"
423+
"COMPY": "0x298f163244e0c8cc9316D6E97162e5792ac5d410",
424+
"COMPYFaucet": "0x23A8b2D7176485a6349e4830605F323f31019333",
425+
"COMPYSwap": "0xb65F19225fEBb650Fcc211dC9F18FEC6f4a328D5"
426426
}
427427
}

contracts/escrow/EnterpriseEscrow.sol

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pragma solidity 0.8.12;
66
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
77
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
88
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
9+
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
910
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
1011
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
1112
import "../interfaces/IEnterpriseFeeCollector.sol";
@@ -111,6 +112,40 @@ contract EnterpriseEscrow is
111112
_deposit(token[i],amount[i]);
112113
}
113114
}
115+
116+
/**
117+
* @dev depositWithPermit
118+
* Called by payer to deposit funds in the contract using ERC20Permit
119+
* This function allows users to deposit without a separate approval transaction
120+
*
121+
* @param token token to deposit
122+
* @param amount amount in wei to deposit
123+
* @param deadline The time at which the permit expires (unix timestamp)
124+
* @param v The recovery byte of the signature
125+
* @param r Half of the ECDSA signature pair
126+
* @param s Half of the ECDSA signature pair
127+
*/
128+
function depositWithPermit(
129+
address token,
130+
uint256 amount,
131+
uint256 deadline,
132+
uint8 v,
133+
bytes32 r,
134+
bytes32 s
135+
) external nonReentrant {
136+
// Use permit to approve this contract to spend user's tokens
137+
IERC20Permit(token).permit(
138+
msg.sender,
139+
address(this),
140+
amount,
141+
deadline,
142+
v,
143+
r,
144+
s
145+
);
146+
// Deposit the tokens
147+
_deposit(token, amount);
148+
}
114149
function _deposit(address token,uint256 amount) internal{
115150
require(token!=address(0),"Invalid token address");
116151
funds[msg.sender][token].available+=amount;

contracts/escrow/Escrow.sol

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pragma solidity 0.8.12;
66
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
77
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
88
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
9+
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
910
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
1011
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
1112
import "../interfaces/IFactoryRouter.sol";
@@ -115,6 +116,40 @@ contract Escrow is
115116
_deposit(token[i],amount[i]);
116117
}
117118
}
119+
120+
/**
121+
* @dev depositWithPermit
122+
* Called by payer to deposit funds in the contract using ERC20Permit
123+
* This function allows users to deposit without a separate approval transaction
124+
*
125+
* @param token token to deposit
126+
* @param amount amount in wei to deposit
127+
* @param deadline The time at which the permit expires (unix timestamp)
128+
* @param v The recovery byte of the signature
129+
* @param r Half of the ECDSA signature pair
130+
* @param s Half of the ECDSA signature pair
131+
*/
132+
function depositWithPermit(
133+
address token,
134+
uint256 amount,
135+
uint256 deadline,
136+
uint8 v,
137+
bytes32 r,
138+
bytes32 s
139+
) external nonReentrant {
140+
// Use permit to approve this contract to spend user's tokens
141+
IERC20Permit(token).permit(
142+
msg.sender,
143+
address(this),
144+
amount,
145+
deadline,
146+
v,
147+
r,
148+
s
149+
);
150+
// Deposit the tokens
151+
_deposit(token, amount);
152+
}
118153
function _deposit(address token,uint256 amount) internal{
119154
require(token!=address(0),"Invalid token address");
120155
funds[msg.sender][token].available+=amount;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
pragma solidity 0.8.12;
2+
// Copyright BigchainDB GmbH and Ocean Protocol contributors
3+
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4+
// Code is Apache-2.0 and docs are CC-BY-4.0
5+
6+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
7+
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
8+
9+
/**
10+
* @dev Mock ERC20 token with configurable decimals and ERC20Permit support.
11+
* This is a test utility contract that implements ERC20Permit for testing permit functionality.
12+
*/
13+
contract MockERC20Permit is ERC20, ERC20Permit {
14+
uint8 private _decimals;
15+
16+
/**
17+
* @dev Sets the values for {name}, {symbol}, and {decimals}.
18+
* @param name_ Token name
19+
* @param symbol_ Token symbol
20+
* @param decimals_ Number of decimals
21+
*/
22+
constructor(
23+
string memory name_,
24+
string memory symbol_,
25+
uint8 decimals_
26+
) ERC20(name_, symbol_) ERC20Permit(name_) {
27+
_decimals = decimals_;
28+
_mint(msg.sender, 10e25);
29+
}
30+
31+
/**
32+
* @dev Returns the number of decimals used to get its user representation.
33+
*/
34+
function decimals() public view virtual override returns (uint8) {
35+
return _decimals;
36+
}
37+
}

scripts/deploy_enterpriseescrow.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function main() {
4949
case 1:
5050
networkName = "mainnet";
5151
gasLimit = 6500000;
52-
gasPrice = ethers.utils.parseUnits("1.15", "gwei");
52+
gasPrice = ethers.utils.parseUnits("0.08", "gwei");
5353
break;
5454
case 10:
5555
networkName = "optimism";
@@ -58,7 +58,7 @@ async function main() {
5858
break;
5959
case 11155111:
6060
networkName = "sepolia";
61-
gasPrice = ethers.utils.parseUnits("0.001000011", "gwei");
61+
gasPrice = ethers.utils.parseUnits("5", "gwei");
6262
gasLimit = 6500000;
6363
break;
6464
}
@@ -99,7 +99,7 @@ async function main() {
9999
addresses.EnterpriseFeeCollector,
100100
options
101101
);
102-
await deployEscrow.deployTransaction.wait();
102+
await deployEscrow.deployTransaction.wait(1);
103103
if (show_verify) {
104104
console.log("\tRun the following to verify on etherscan");
105105
console.log(
@@ -116,13 +116,6 @@ async function main() {
116116
if (addressFile) {
117117
// write address.json if needed
118118
oldAddresses[networkName] = addresses;
119-
if (logging)
120-
console.info(
121-
"writing to " +
122-
addressFile +
123-
"\r\n" +
124-
JSON.stringify(oldAddresses, null, 2)
125-
);
126119
try {
127120
fs.writeFileSync(addressFile, JSON.stringify(oldAddresses, null, 2));
128121
} catch (e) {

scripts/deploy_escrow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async function main() {
9292
networkName = "sepolia";
9393
OPFOwner = '0xC7EC1970B09224B317c52d92f37F5e1E4fF6B687';
9494
RouterAddress = "0x2112Eb973af1DBf83a4f11eda82f7a7527D7Fde5";
95-
gasPrice = ethers.utils.parseUnits('0.001000011', 'gwei')
95+
gasPrice = ethers.utils.parseUnits('5', 'gwei')
9696
gasLimit = 5000000
9797
break;
9898
case 11155420:
@@ -167,7 +167,7 @@ async function main() {
167167
);
168168

169169
const deployEscrow = await Escrow.connect(owner).deploy(RouterAddress,addresses.OPFCommunityFeeCollectorCompute,options)
170-
await deployEscrow.deployTransaction.wait();
170+
await deployEscrow.deployTransaction.wait(1);
171171
if (show_verify) {
172172
console.log("\tRun the following to verify on etherscan");
173173
console.log("\tnpx hardhat verify --network " + networkName + " " + deployEscrow.address+ " " + RouterAddress + " " + addresses.OPFCommunityFeeCollectorCompute)

0 commit comments

Comments
 (0)