Skip to content

Commit

Permalink
feat: batchRequest initial contract setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchaymittal committed May 13, 2024
1 parent 5155e86 commit ffd73fd
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# 1. Build the contracts
# 2. Stage build output
# 2. Lint and stage style improvements
yarn build && npx lint-staged
npx lint-staged
57 changes: 31 additions & 26 deletions script/Deploy.sol
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();
// }
// }
35 changes: 35 additions & 0 deletions src/contracts/BatchRequest.sol
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)
}
}
}
59 changes: 0 additions & 59 deletions src/contracts/Greeter.sol

This file was deleted.

19 changes: 19 additions & 0 deletions src/contracts/PoolManager.sol
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) {

Check warning on line 16 in src/contracts/PoolManager.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, external pure function can not go after public pure function (line 11)
return _FAKE_NUM_POOLS;
}
}
74 changes: 0 additions & 74 deletions src/interfaces/IGreeter.sol

This file was deleted.

22 changes: 22 additions & 0 deletions src/interfaces/IPoolManager.sol
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);
}
24 changes: 12 additions & 12 deletions test/integration/Greeter.t.sol
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);
// }
// }
38 changes: 19 additions & 19 deletions test/integration/IntegrationBase.sol
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);
// }
// }
Loading

0 comments on commit ffd73fd

Please sign in to comment.