generated from ScopeLift/foundry-template
-
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.
* forge install: solmate * forge install: perp-curie-contract v2.4.5 * forge install: openzeppelin-contracts v4.8.2 * Working example * Cleanup * Update to pass linting * Update to pass linting * Add Optimism rpc url * Make changes based on feedback * Fix formatting * Remove SARIF * Add permalinks for interfaces * Fix toml * Add some natspec * Scopelint format * Convert to fallback function * Fix format * Remove unused import * Fix scopelint * Change comment * Changes based on feedback * Add receive to remove warning * Working closePosition * Update deposit * Add benchmarks * Some changes based on comments * More changes based on comments * Remove comment * style: fmt new statements * style: forge fmt * Add comments * Fix formatting * Change to internal * Change wording of comments --------- Co-authored-by: Matt Solomon <[email protected]>
- Loading branch information
1 parent
b66daf2
commit 16d48eb
Showing
27 changed files
with
4,144 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ on: | |
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
OPTIMISM_RPC_URL: ${{ secrets.OPTIMISM_RPC_URL }} | ||
|
||
jobs: | ||
build: | ||
|
@@ -75,7 +76,7 @@ jobs: | |
uses: zgosalvez/github-actions-report-lcov@v2 | ||
with: | ||
coverage-files: ./lcov.info | ||
minimum-coverage: 100 # Set coverage threshold. | ||
minimum-coverage: 80 # Set coverage threshold. | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
|
@@ -100,23 +101,3 @@ jobs: | |
run: | | ||
scopelint --version | ||
scopelint check | ||
slither-analyze: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
security-events: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Run Slither | ||
uses: crytic/[email protected] | ||
id: slither # Required to reference this step in the next step. | ||
with: | ||
fail-on: none # Required to avoid failing the CI run regardless of findings. | ||
sarif: results.sarif | ||
slither-args: --filter-paths "./lib|./test" --exclude naming-convention | ||
|
||
- name: Upload SARIF file | ||
uses: github/codeql-action/upload-sarif@v2 | ||
with: | ||
sarif_file: ${{ steps.slither.outputs.sarif }} |
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,3 +1,12 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/solmate"] | ||
path = lib/solmate | ||
url = https://github.com/transmissions11/solmate | ||
[submodule "lib/perp-curie-contract"] | ||
path = lib/perp-curie-contract | ||
url = https://github.com/perpetual-protocol/perp-curie-contract | ||
[submodule "lib/openzeppelin-contracts"] | ||
path = lib/openzeppelin-contracts | ||
url = https://github.com//OpenZeppelin/openzeppelin-contracts |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Submodule openzeppelin-contracts
added at
d00ace
Submodule perp-curie-contract
added at
4e187e
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,87 @@ | ||
import {Script, stdJson} from "forge-std/Script.sol"; | ||
import {DepositRouter} from "src/DepositRouter.sol"; | ||
import {PerpetualRouterFactory} from "src/PerpetualRouterFactory.sol"; | ||
import {ERC20} from "solmate/tokens/ERC20.sol"; | ||
import {IVault} from "src/interface/IVault.sol"; | ||
import {IClearingHouse} from "src/interface/IClearingHouse.sol"; | ||
import {IDelegateApproval} from "test/interface/IDelegateApproval.sol"; | ||
|
||
contract Benchmark is Script { | ||
using stdJson for string; | ||
|
||
IVault vault = IVault(0xAD7b4C162707E0B2b5f6fdDbD3f8538A5fbA0d60); | ||
IClearingHouse clearingHouse = IClearingHouse(0x82ac2CE43e33683c58BE4cDc40975E73aA50f459); | ||
|
||
IDelegateApproval delegateApproval = IDelegateApproval(0xfd7bB5F6844a43c5469c972640Eddfa99597a547); | ||
address public immutable VETH = 0x8C835DFaA34e2AE61775e80EE29E2c724c6AE2BB; | ||
address public immutable USDC = 0x7F5c764cBc14f9669B88837ca1490cCa17c31607; | ||
|
||
function run() public { | ||
require(block.chainid == 10, "script can only be run on optimism"); | ||
string memory file = "broadcast/Deploy.s.sol/10/run-latest.json"; | ||
string memory json = vm.readFile(file); | ||
|
||
address depositRtr = json.readAddress(".transactions[1].additionalContracts[0].address"); | ||
|
||
address positionRtr = json.readAddress(".transactions[2].additionalContracts[0].address"); | ||
|
||
// =========================== | ||
// ======== Execution ======== | ||
// =========================== | ||
|
||
vm.startBroadcast(); | ||
// Default ETH deposit in perpetual vault | ||
vault.depositEther{value: 0.00002 ether}(); | ||
|
||
// Optimized ETH deposit in perpetual vault | ||
(bool ok,) = payable(depositRtr).call{value: 0.00002 ether}(""); | ||
require(ok, "Optimized ETH deposit"); | ||
|
||
// Default ERC20 deposit in perpetual vault | ||
ERC20(USDC).approve(address(vault), 250_000); | ||
vault.deposit(USDC, 250_000); | ||
|
||
// Optimized ERC20 deposit in perpetual vault | ||
ERC20(USDC).approve(depositRtr, 250_000); | ||
(bool okDepositUSDC,) = payable(depositRtr).call(abi.encode(250_000)); | ||
require(okDepositUSDC, "Optimized ETH deposit"); | ||
|
||
uint256 amount = 0.000000025 ether; | ||
delegateApproval.approve(positionRtr, 1); | ||
|
||
// Default open exact output short VETH position | ||
clearingHouse.openPosition( | ||
IClearingHouse.OpenPositionParams({ | ||
baseToken: VETH, | ||
isBaseToQuote: true, | ||
isExactInput: false, | ||
amount: amount, | ||
oppositeAmountBound: 0, | ||
deadline: type(uint256).max, | ||
sqrtPriceLimitX96: 0, | ||
referralCode: 0 | ||
}) | ||
); | ||
|
||
// Default close VETH positions | ||
clearingHouse.closePosition( | ||
IClearingHouse.ClosePositionParams({ | ||
baseToken: VETH, | ||
oppositeAmountBound: 0, | ||
deadline: type(uint256).max, | ||
sqrtPriceLimitX96: 0, | ||
referralCode: 0 | ||
}) | ||
); | ||
|
||
// Optimized open exact output short VETH position | ||
(bool okPosition,) = payable(positionRtr).call(abi.encode(1, amount, 0, 0)); | ||
require(okPosition, "Optimized VETH close position"); | ||
|
||
// Optimized close VETH positions | ||
(bool okClose,) = payable(positionRtr).call(abi.encode(5, 0, 0, 0)); | ||
require(okClose, "Optimized VETH close position"); | ||
|
||
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
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,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import {ERC20} from "solmate/tokens/ERC20.sol"; | ||
import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; | ||
|
||
import {IVault} from "src/interface/IVault.sol"; | ||
|
||
/// @notice A router for depositing funds into the perpetual vault | ||
contract DepositRouter { | ||
/// @notice The token used for the router's deposits | ||
address public immutable TOKEN; | ||
|
||
/// @notice The contract for the perpetual vault to accept deposits | ||
IVault public immutable PERPETUAL_VAULT; | ||
|
||
constructor(address token, IVault vault) { | ||
TOKEN = token; | ||
PERPETUAL_VAULT = vault; | ||
} | ||
|
||
function _deposit(uint256 amount) private { | ||
SafeTransferLib.safeTransferFrom(ERC20(TOKEN), msg.sender, address(this), amount); | ||
ERC20(TOKEN).approve(address(PERPETUAL_VAULT), amount); | ||
PERPETUAL_VAULT.depositFor(msg.sender, TOKEN, amount); | ||
} | ||
|
||
// TODO: integer optimization after talking to the protocol | ||
fallback() external payable { | ||
uint256 amount = abi.decode(msg.data, (uint256)); | ||
_deposit(amount); | ||
} | ||
|
||
receive() external payable { | ||
PERPETUAL_VAULT.depositEtherFor{value: msg.value}(msg.sender); | ||
} | ||
} |
Oops, something went wrong.