Skip to content

Commit 3859f81

Browse files
authored
Merge pull request #38 from bitcoin-verse/purchase-router
Purchase router
2 parents e07061b + 89fdeed commit 3859f81

33 files changed

+11360
-112
lines changed

.github/workflows/foundry-gas-diff.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ jobs:
3131

3232
# Add any step generating a gas report to a temporary file named gasreport.ansi. For example:
3333
- name: Run tests
34-
run: forge test --gas-report > gasreport.ansi -vvv # <- this file name should be unique in your repository!
34+
run: forge test --gas-report > gasreport.ansi -vvvv # <- this file name should be unique in your repository!
3535
env:
3636
# make fuzzing semi-deterministic to avoid noisy gas cost estimation
3737
# due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
3838
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}
3939

4040
- name: Compare gas reports
41-
uses: Rubilmax/foundry-gas-diff@v3.16
41+
uses: Rubilmax/foundry-gas-diff@v3.21
4242
with:
43+
name: gas-report
4344
summaryQuantile: 0.9 # only display the 10% most significant gas diffs in the summary (defaults to 20%)
4445
sortCriteria: avg,max # sort diff rows by criteria
4546
sortOrders: desc,asc # and directions

contracts/BasketHelper.sol

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
/**
5+
* @title IERC20
6+
* @dev Interface of the ERC20 standard as defined in the EIP.
7+
*/
8+
interface IERC20 {
9+
function totalSupply() external view returns (uint256);
10+
function balanceOf(address account) external view returns (uint256);
11+
function transfer(address recipient, uint256 amount) external returns (bool);
12+
function allowance(address owner, address spender) external view returns (uint256);
13+
function approve(address spender, uint256 amount) external returns (bool);
14+
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
15+
event Transfer(address indexed from, address indexed to, uint256 value);
16+
event Approval(address indexed owner, address indexed spender, uint256 value);
17+
}
18+
19+
/**
20+
* @title IWETH
21+
* @dev Interface for WETH (Wrapped Ether) or similar wrapped native currency tokens.
22+
*/
23+
interface IWETH is IERC20 {
24+
function deposit() external payable;
25+
function withdraw(uint wad) external;
26+
}
27+
28+
/**
29+
* @title IUniswapV2Router02
30+
* @dev Interface for Uniswap V2 Router.
31+
*/
32+
interface IUniswapV2Router02 {
33+
function factory() external pure returns (address);
34+
function WETH() external pure returns (address);
35+
36+
function swapExactTokensForTokens(
37+
uint amountIn,
38+
uint amountOutMin,
39+
address[] calldata path,
40+
address to,
41+
uint deadline
42+
) external returns (uint[] memory amounts);
43+
44+
function swapExactETHForTokens(
45+
uint amountOutMin,
46+
address[] calldata path,
47+
address to,
48+
uint deadline
49+
) external payable returns (uint[] memory amounts);
50+
}
51+
52+
/**
53+
* @title ISwapRouter (Uniswap V3)
54+
* @dev Interface for Uniswap V3 Swap Router.
55+
*/
56+
interface ISwapRouter {
57+
struct ExactInputSingleParams {
58+
address tokenIn;
59+
address tokenOut;
60+
uint24 fee;
61+
address recipient;
62+
uint256 deadline;
63+
uint256 amountIn;
64+
uint256 amountOutMinimum;
65+
uint160 sqrtPriceLimitX96;
66+
}
67+
68+
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
69+
}
70+
71+
/**
72+
* @title Ownable
73+
* @dev Contract module which provides a basic access control mechanism.
74+
*/
75+
abstract contract Ownable {
76+
address public owner;
77+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
78+
79+
constructor() {
80+
owner = msg.sender;
81+
emit OwnershipTransferred(address(0), msg.sender);
82+
}
83+
84+
modifier onlyOwner() {
85+
require(owner == msg.sender, "Ownable: caller is not the owner");
86+
_;
87+
}
88+
89+
function transferOwnership(address newOwner) public virtual onlyOwner {
90+
require(newOwner != address(0), "Ownable: new owner is the zero address");
91+
emit OwnershipTransferred(owner, newOwner);
92+
owner = newOwner;
93+
}
94+
}
95+
96+
/**
97+
* @title ReentrancyGuard
98+
* @dev Contract module that helps prevent reentrant calls to a function.
99+
*/
100+
abstract contract ReentrancyGuard {
101+
uint256 private constant _NOT_ENTERED = 1;
102+
uint256 private constant _ENTERED = 2;
103+
uint256 private _status;
104+
105+
constructor() {
106+
_status = _NOT_ENTERED;
107+
}
108+
109+
modifier nonReentrant() {
110+
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
111+
_status = _ENTERED;
112+
_;
113+
_status = _NOT_ENTERED;
114+
}
115+
}

0 commit comments

Comments
 (0)