Skip to content

Commit 0037173

Browse files
committed
feat: add test contracts
1 parent 293849a commit 0037173

11 files changed

+5307
-2
lines changed

bun.lockb

458 Bytes
Binary file not shown.

contracts/test/ERC20Mock.sol

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5+
6+
contract ERC20Mock is ERC20 {
7+
event Mint(address to, uint256 amount);
8+
event Burn(address to, uint256 amount);
9+
10+
constructor(string memory name, string memory symbol, uint256 initialSupply, uint8) ERC20(name, symbol) {
11+
_mint(msg.sender, initialSupply);
12+
}
13+
14+
function mint(address account, uint256 _amount) public {
15+
_mint(account, _amount);
16+
}
17+
18+
function burn(address account, uint256 _amount) public {
19+
_burn(account, _amount);
20+
}
21+
}

contracts/test/SwapRouter.sol

Lines changed: 1825 additions & 0 deletions
Large diffs are not rendered by default.

contracts/test/Test0x.sol

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import { IRegistry } from "../interfaces/IRegistry.sol";
5+
import { ITestERC20Decimals } from "./interfaces/ITestERC20Decimals.sol";
6+
7+
contract Test0x {
8+
IRegistry public registry;
9+
uint256 public baseTokenAmount;
10+
11+
constructor(address _registry, uint256 _baseTokenAmount) {
12+
registry = IRegistry(_registry);
13+
baseTokenAmount = _baseTokenAmount * 1e6;
14+
}
15+
16+
// solhint-disable-next-line no-complex-fallback
17+
fallback() external payable {
18+
uint256 price = registry.priceOracle().price(); // normalised to 18dp
19+
uint256 baseTokenPrecision = 18 - (registry.topUp().baseToken().decimals());
20+
uint256 fuelTokenAmount = ((baseTokenAmount * 10 ** baseTokenPrecision) * 1 ether) / price;
21+
22+
registry.topUp().baseToken().transferFrom(msg.sender, address(this), baseTokenAmount);
23+
ITestERC20Decimals(address(registry.economicsFactory().fuelToken())).mint(msg.sender, fuelTokenAmount);
24+
25+
(bool success, ) = payable(msg.sender).call{ value: address(this).balance }("");
26+
require(success, "Transfer failed");
27+
}
28+
29+
receive() external payable {
30+
(bool success, ) = payable(msg.sender).call{ value: msg.value }("");
31+
require(success, "Transfer failed");
32+
}
33+
}

contracts/test/TestERC20Decimals.sol

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
5+
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
import { ITestERC20Decimals } from "./interfaces/ITestERC20Decimals.sol";
7+
8+
// prettier-ignore
9+
contract TestERC20Decimals is ITestERC20Decimals, Context, ERC20 {
10+
uint8 private _decimals;
11+
12+
/**
13+
* @dev Initializes ERC20 token
14+
*/
15+
constructor(string memory name, string memory symbol, uint256 decimal) ERC20(name, symbol) {
16+
_decimals = uint8(decimal);
17+
}
18+
19+
/**
20+
* @dev Creates `amount` new tokens for `to`. Public for any test to call.
21+
*
22+
* See {ERC20-_mint}.
23+
*/
24+
function mint(address to, uint256 amount) public virtual override {
25+
// Not expected to be true protection, but we don't ever mint more than 3.4M tokens at a given time within test
26+
// and pre-prod environments. Makes it economically unviable to mint the max uint256 to break the environment.
27+
// 100M (times 1000 because of the migration of GET to OPN) chosen to add a bit of breathing room.
28+
require(amount <= 100_000_000_000 * 10 ** _decimals, "TestERC20Decimals: above maximum allowed mint");
29+
_mint(to, amount);
30+
}
31+
32+
function burn(uint256 amount) public {
33+
_burn(_msgSender(), amount);
34+
}
35+
36+
function decimals() public view virtual override(ERC20, ITestERC20Decimals) returns (uint8) {
37+
return _decimals;
38+
}
39+
}

contracts/test/UniswapV3Factory.sol

Lines changed: 3116 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5+
import { IEventImplementation } from "../../interfaces/IEventImplementation.sol";
6+
7+
interface IEconomics {
8+
// Data structure containing all the different rates for a particular relayer.
9+
// 100% (1) 1_000_000,
10+
// 10% (0.1) = 100_000,
11+
// 1% (0.01) = 10_000,
12+
// 0.1% (0.001) = 1_000,
13+
// 0.01% (0.0001) = 100,
14+
// 0.001% (0,00001) = 10,
15+
// 0.0001% = (0.000001) = 1
16+
// All scaled by 1_000_000.
17+
//
18+
// USD values (e.g. minFee, maxFee) are scaled by 1_000 (tenth of a cent).
19+
struct DynamicRates {
20+
uint24 minFeePrimary;
21+
uint24 maxFeePrimary;
22+
uint24 primaryRate;
23+
uint24 minFeeSecondary;
24+
uint24 maxFeeSecondary;
25+
uint24 secondaryRate;
26+
uint24 salesTaxRate;
27+
}
28+
29+
// Largely unnecesary to define separately but helps avoid stack too deep errors within reserved fuel calculations.
30+
struct Rate {
31+
uint24 minFee;
32+
uint24 maxFee;
33+
uint24 rate;
34+
}
35+
36+
struct IntegratorData {
37+
uint32 index;
38+
uint32 activeTicketCount;
39+
bool isBillingEnabled;
40+
bool isConfigured;
41+
uint256 price;
42+
uint256 availableFuel;
43+
uint256 reservedFuel;
44+
uint256 reservedFuelProtocol;
45+
string name;
46+
bool onCredit;
47+
}
48+
49+
struct RelayerData {
50+
uint32 integratorIndex;
51+
}
52+
53+
struct SpentFuel {
54+
uint256 total;
55+
uint256 protocol;
56+
uint32 ticketCount;
57+
}
58+
59+
event IntegratorToppedUp(
60+
uint32 indexed integratorIndex,
61+
uint256 indexed total,
62+
uint256 price,
63+
uint256 indexed newAveragePrice,
64+
uint256 salesTax
65+
);
66+
event FuelReservedPrimary(uint32 integratorIndex, uint32 ticketCount, uint256 fuel, uint256 fuelProtocol);
67+
event FuelReservedSecondary(uint32 integratorIndex, uint32 ticketCount, uint256 fuel, uint256 fuelProtocol);
68+
event BasicTaxCharged(uint32 integratorIndex, uint32 actionCount, uint256 fuel, uint256 fuelProtocol);
69+
event TicketFuelEmptied(uint32 integratorIndex, uint32 ticketCount, uint256 fuel, uint256 fuelProtocol);
70+
event SalesTaxFuelCollected(address salesTaxFuelDesintation, uint256 salesTaxFuel);
71+
event AccountBalanceCorrected(
72+
uint32 integratorIndex,
73+
uint256 oldAvailableFuel,
74+
uint256 newAvailableFuel,
75+
uint256 oldReservedBalance,
76+
uint256 newReservedBalance,
77+
uint256 oldReservedBalanceProtocol,
78+
uint256 newReservedBalanceProtocol
79+
);
80+
event UpdateBasicTaxRate(uint24 old, uint24 updated);
81+
event UpdateFuelToken(address old, address updated);
82+
event UpdateSpentFuel(SpentFuel spentFuel);
83+
event UpdateSpentFuelOnCredit(uint256 spentFuelOnCredit);
84+
event UpdateDynamicRates(uint32 integratorIndex, DynamicRates dynamicRates);
85+
event UpdateProtocolRates(DynamicRates protocolRates);
86+
event UpdateSalesTaxFuelDestination(address salesTaxFuelDestination);
87+
event IntegratorConfigured(uint32 integratorIndex, string name, address relayerAddress, DynamicRates dynamicRates);
88+
event IntegratorActivated(uint32 integratorIndex);
89+
event IntegratorDisabled(uint32 integratorIndex);
90+
event RelayerAdded(address relayerAddress, uint32 integratorIndex);
91+
event RelayerRemoved(address relayerAddress, uint32 integratorIndex);
92+
event BillingStatusUpdated(uint32 integeratorIndex, bool status);
93+
event ConfigurationStatusUpdated(uint32 integratorIndex, bool status);
94+
event EnableIntegratorBilling(uint32 integratorIndex);
95+
event DisableIntegratorBilling(uint32 integratorIndex);
96+
event UpdateIntegratorTicketCount(uint32 integratorIndex, uint256 activeTicketCount);
97+
event UpdateIntegratorPrice(uint32 integratorIndex, uint256 price);
98+
event UpdateIntegratorName(uint32 integratorIndex, string name);
99+
event UpdateIntegratorOnCredit(uint32 integratorIndex, bool onCredit);
100+
101+
function fuelToken() external returns (IERC20);
102+
103+
function basicTaxRate() external returns (uint24);
104+
105+
function spentFuel() external returns (uint256, uint256, uint32);
106+
107+
function integratorCount() external returns (uint32);
108+
109+
function topUpIntegrator(
110+
uint32 _integratorIndex,
111+
address _sender,
112+
uint256 _amount,
113+
uint256 _price
114+
) external returns (uint256);
115+
116+
function reserveFuelPrimarySale(
117+
address _relayerAddress,
118+
IEventImplementation.TicketAction[] memory _ticketActions
119+
) external returns (uint256, uint256);
120+
121+
function reserveFuelSecondarySale(
122+
address _relayerAddress,
123+
IEventImplementation.TicketAction[] memory _ticketActions
124+
) external returns (uint256, uint256);
125+
126+
function spendBasicAction(address _relayerAddress, uint32 _actionCount) external returns (uint256, uint256);
127+
128+
function spendTicketReserved(address _relayerAddress, uint32 _ticketCount) external returns (uint256, uint256);
129+
130+
function collectSalesTaxFuel() external;
131+
132+
function correctAccountBalance(
133+
uint32 _integratorIndex,
134+
uint256 _newAvailableFuel,
135+
uint256 _newReservedFuel
136+
) external;
137+
138+
function setupIntegrator(
139+
string calldata _name,
140+
address _relayerAddress,
141+
DynamicRates calldata _dynamicRates,
142+
uint256 _price
143+
) external;
144+
145+
function activateIntegrator(uint32 _integratorIndex) external;
146+
147+
function disableIntegrator(uint32 _integratorIndex) external;
148+
149+
function addRelayer(address _relayerAddress, uint32 _integratorIndex) external;
150+
151+
function removeRelayer(address _relayerAddress) external;
152+
153+
function setDynamicRates(uint32 _integratorIndex, DynamicRates memory dynamicRates) external;
154+
155+
function setProtocolRates(DynamicRates memory dynamicRates) external;
156+
157+
function setSalesTaxFuelDestination(address _salesTaxFuelDestination) external;
158+
159+
function enableIntegratorBilling(uint32 _integratorIndex) external;
160+
161+
function disableIntegratorBilling(uint32 _integratorIndex) external;
162+
163+
function setBasicTaxRate(uint24 _basicTaxRate) external;
164+
165+
function setSpentFuel(SpentFuel calldata _spentFuel, uint256 _spentFuelOnCredit) external;
166+
167+
function migrateEconomicsData() external returns (IntegratorData[] memory, DynamicRates[] memory);
168+
169+
function emergencyWithdraw(address _asset, address _to, uint256 _amount) external;
170+
171+
function setBillingStatus(uint32 _integratorIndex, bool status) external;
172+
173+
function setConfigurationStatus(uint32 _integratorIndex, bool status) external;
174+
175+
function setIntegratorPrice(uint32 _integratorIndex, uint256 _price) external;
176+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
interface ITestERC20Decimals {
5+
function mint(address to, uint256 amount) external;
6+
7+
function decimals() external view returns (uint8);
8+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-License-Identifier: MIT
2+
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
3+
4+
pragma solidity ^0.8.4;
5+
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
6+
7+
/**
8+
* @dev Provides information about the current execution context, including the
9+
* sender of the transaction and its data. While these are generally available
10+
* via msg.sender and msg.data, they should not be accessed in such a direct
11+
* manner, since when dealing with meta-transactions the account sending and
12+
* paying for execution may not be the actual sender (as far as an application
13+
* is concerned).
14+
*
15+
* This contract is only required for intermediate, library-like contracts.
16+
*/
17+
abstract contract ContextUpgradeableGapless is Initializable {
18+
// solhint-disable-next-line func-name-mixedcase
19+
function __Context_init() internal onlyInitializing {}
20+
21+
// solhint-disable-next-line func-name-mixedcase
22+
function __Context_init_unchained() internal onlyInitializing {}
23+
24+
function _msgSender() internal view virtual returns (address) {
25+
return msg.sender;
26+
}
27+
28+
function _msgData() internal view virtual returns (bytes calldata) {
29+
return msg.data;
30+
}
31+
32+
function _contextSuffixLength() internal view virtual returns (uint256) {
33+
return 0;
34+
}
35+
36+
/**
37+
* @dev This empty reserved space is put in place to allow future versions to add new
38+
* variables without shifting down storage in the inheritance chain.
39+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
40+
*
41+
* @dev (!!) Note that due to the change of inheritance chain of EventImplementation
42+
* we have had to remove the storage gap from ContextUpgradeable. ERC2981Upgradeable has
43+
* been added which introduces a gap of 50 and the safest place to remove this is from
44+
* ContextUpgradeable as this is unlikely to ever receive a local varaible. As a result
45+
* we must always use this version of ContextUpgradeable for the ERC721 inheritance and
46+
* never the one directly from OpenZeppelin.
47+
*/
48+
// uint256[50] private __gap;
49+
}

hardhat.config.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,44 @@ const config: HardhatUserConfig = {
5656
},
5757
},
5858
solidity: {
59-
version: "0.8.24",
59+
compilers: [
60+
{
61+
version: "0.8.27",
62+
settings: {
63+
optimizer: {
64+
enabled: true,
65+
runs: 800,
66+
},
67+
},
68+
},
69+
{
70+
version: "0.8.12",
71+
settings: {
72+
optimizer: {
73+
enabled: true,
74+
runs: 800,
75+
},
76+
},
77+
},
78+
{
79+
version: "0.7.6",
80+
settings: {
81+
optimizer: {
82+
enabled: true,
83+
runs: 800,
84+
},
85+
},
86+
},
87+
{
88+
version: "0.8.17",
89+
settings: {
90+
optimizer: {
91+
enabled: true,
92+
runs: 800,
93+
},
94+
},
95+
},
96+
],
6097
},
6198
};
6299

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"test": "hardhat test --network hardhat"
1616
},
1717
"devDependencies": {
18-
"@matterlabs/hardhat-zksync": "^1.3.0",
18+
"@matterlabs/hardhat-zksync": "^1.4.0",
19+
"@matterlabs/hardhat-zksync-solc": "^1.2.6",
1920
"@matterlabs/zksync-contracts": "^0.6.1",
2021
"@nomicfoundation/hardhat-verify": "^2.0.9",
2122
"@openzeppelin/contracts": "^5.2.0",

0 commit comments

Comments
 (0)