generated from defi-wonderland/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: batchRequest initial contract setup
- Loading branch information
1 parent
5155e86
commit ffd73fd
Showing
10 changed files
with
215 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity 0.8.23; | ||
|
||
import {Greeter} from 'contracts/Greeter.sol'; | ||
import {Script} from 'forge-std/Script.sol'; | ||
import {IERC20} from 'forge-std/interfaces/IERC20.sol'; | ||
// import {Script} from "forge-std/Script.sol"; | ||
// import {IERC20} from "forge-std/interfaces/IERC20.sol"; | ||
|
||
contract Deploy is Script { | ||
struct DeploymentParams { | ||
string greeting; | ||
IERC20 token; | ||
} | ||
// contract Deploy is Script { | ||
// struct DeploymentParams { | ||
// string greeting; | ||
// IERC20 token; | ||
// } | ||
|
||
/// @notice Deployment parameters for each chain | ||
mapping(uint256 _chainId => DeploymentParams _params) internal _deploymentParams; | ||
// /// @notice Deployment parameters for each chain | ||
// mapping(uint256 _chainId => DeploymentParams _params) | ||
// internal _deploymentParams; | ||
|
||
function setUp() public { | ||
// Mainnet | ||
_deploymentParams[1] = DeploymentParams('Hello, Mainnet!', IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)); | ||
// function setUp() public { | ||
// // Mainnet | ||
// _deploymentParams[1] = DeploymentParams( | ||
// "Hello, Mainnet!", | ||
// IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) | ||
// ); | ||
|
||
// Sepolia | ||
_deploymentParams[11_155_111] = | ||
DeploymentParams('Hello, Sepolia!', IERC20(0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6)); | ||
} | ||
// // Sepolia | ||
// _deploymentParams[11_155_111] = DeploymentParams( | ||
// "Hello, Sepolia!", | ||
// IERC20(0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6) | ||
// ); | ||
// } | ||
|
||
function run() public { | ||
DeploymentParams memory _params = _deploymentParams[block.chainid]; | ||
// function run() public { | ||
// DeploymentParams memory _params = _deploymentParams[block.chainid]; | ||
|
||
vm.startBroadcast(); | ||
new Greeter(_params.greeting, _params.token); | ||
vm.stopBroadcast(); | ||
} | ||
} | ||
// vm.startBroadcast(); | ||
// new Greeter(_params.greeting, _params.token); | ||
// vm.stopBroadcast(); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {Data, IPoolManager} from '../interfaces/IPoolManager.sol'; | ||
|
||
contract BatchPoolManagerData { | ||
// This contract is used to fetch multiple pools from the PoolManager contract | ||
constructor(IPoolManager _poolManager) { | ||
// create an array to store return data | ||
uint256 _poolsToFetch = _poolManager.numPools(); | ||
Data[] memory _returnData = new Data[](_poolsToFetch); | ||
|
||
// fetch pools | ||
for (uint256 _i = 0; _i < _poolsToFetch; _i++) { | ||
_returnData[_i] = _poolManager.queryPool(_i); | ||
} | ||
|
||
// encode return data | ||
bytes memory _data = abi.encode(_returnData); | ||
|
||
// force constructor to return data via assembly | ||
assembly { | ||
// abi.encode adds an additional offset (32 bytes) that we need to skip | ||
let _dataStart := add(_data, 32) | ||
// msize() gets the size of active memory in bytes. | ||
// if we subtract msize() from _dataStart, the output will be | ||
// the amount of bytes from _dataStart to the end of memory | ||
// which due to how the data has been laid out in memory, will coincide with | ||
// where our desired data ends. | ||
let _dataEnd := sub(msize(), _dataStart) | ||
// starting from _dataStart, get all the data in memory. | ||
return(_dataStart, _dataEnd) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {Data, IPoolManager} from '../interfaces/IPoolManager.sol'; | ||
|
||
contract PoolManager is IPoolManager { | ||
uint256 private constant _FAKE_LIQUIDITY = 10_000; | ||
uint256 private constant _FAKE_NUM_POOLS = 50; | ||
|
||
/// @inheritdoc IPoolManager | ||
function queryPool(uint256 _poolId) public pure returns (Data memory _pool) { | ||
return Data({id: _poolId, liquidity: _FAKE_LIQUIDITY}); | ||
} | ||
|
||
/// @inheritdoc IPoolManager | ||
function numPools() external pure returns (uint256 _numPools) { | ||
return _FAKE_NUM_POOLS; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
struct Data { | ||
uint256 id; | ||
uint256 liquidity; | ||
} | ||
|
||
interface IPoolManager { | ||
/** | ||
* @notice Query a pool | ||
* @param _poolId The pool ID | ||
* @return _pool The pool data | ||
*/ | ||
function queryPool(uint256 _poolId) external returns (Data memory _pool); | ||
|
||
/** | ||
* @notice Get the number of pools | ||
* @return _numPools The number of pools | ||
*/ | ||
function numPools() external returns (uint256 _numPools); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity 0.8.23; | ||
|
||
import {IntegrationBase} from 'test/integration/IntegrationBase.sol'; | ||
// import {IntegrationBase} from 'test/integration/IntegrationBase.sol'; | ||
|
||
contract IntegrationGreeter is IntegrationBase { | ||
function test_Greet() public { | ||
uint256 _whaleBalance = _dai.balanceOf(_daiWhale); | ||
// contract IntegrationGreeter is IntegrationBase { | ||
// function test_Greet() public { | ||
// uint256 _whaleBalance = _dai.balanceOf(_daiWhale); | ||
|
||
vm.prank(_daiWhale); | ||
(string memory _greeting, uint256 _balance) = _greeter.greet(); | ||
// vm.prank(_daiWhale); | ||
// (string memory _greeting, uint256 _balance) = _greeter.greet(); | ||
|
||
assertEq(_whaleBalance, _balance); | ||
assertEq(_initialGreeting, _greeting); | ||
} | ||
} | ||
// assertEq(_whaleBalance, _balance); | ||
// assertEq(_initialGreeting, _greeting); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity 0.8.23; | ||
|
||
import {Greeter, IGreeter} from 'contracts/Greeter.sol'; | ||
import {Test} from 'forge-std/Test.sol'; | ||
import {IERC20} from 'forge-std/interfaces/IERC20.sol'; | ||
// import {Greeter, IGreeter} from 'contracts/Greeter.sol'; | ||
// import {Test} from 'forge-std/Test.sol'; | ||
// import {IERC20} from 'forge-std/interfaces/IERC20.sol'; | ||
|
||
contract IntegrationBase is Test { | ||
uint256 internal constant _FORK_BLOCK = 18_920_905; | ||
// contract IntegrationBase is Test { | ||
// uint256 internal constant _FORK_BLOCK = 18_920_905; | ||
|
||
string internal _initialGreeting = 'hola'; | ||
address internal _user = makeAddr('user'); | ||
address internal _owner = makeAddr('owner'); | ||
address internal _daiWhale = 0x42f8CA49E88A8fd8F0bfA2C739e648468b8f9dec; | ||
IERC20 internal _dai = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); | ||
IGreeter internal _greeter; | ||
// string internal _initialGreeting = 'hola'; | ||
// address internal _user = makeAddr('user'); | ||
// address internal _owner = makeAddr('owner'); | ||
// address internal _daiWhale = 0x42f8CA49E88A8fd8F0bfA2C739e648468b8f9dec; | ||
// IERC20 internal _dai = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); | ||
// IGreeter internal _greeter; | ||
|
||
function setUp() public { | ||
vm.createSelectFork(vm.rpcUrl('mainnet'), _FORK_BLOCK); | ||
vm.prank(_owner); | ||
_greeter = new Greeter(_initialGreeting, _dai); | ||
} | ||
} | ||
// function setUp() public { | ||
// vm.createSelectFork(vm.rpcUrl('mainnet'), _FORK_BLOCK); | ||
// vm.prank(_owner); | ||
// _greeter = new Greeter(_initialGreeting, _dai); | ||
// } | ||
// } |
Oops, something went wrong.