-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff789eb
commit 825f592
Showing
2 changed files
with
194 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: Unlicensed | ||
pragma solidity >=0.8.10; | ||
|
||
import { DSTestPlus } from "solmate/test/utils/DSTestPlus.sol"; | ||
import { stdStorage, StdStorage } from "lib/forge-std/src/Test.sol"; | ||
|
||
// DSTestPlus with some other nice functions from the forge-std/Test library. | ||
contract SuperDSTestPlus is DSTestPlus { | ||
using stdStorage for StdStorage; | ||
|
||
uint256 internal constant MAX_UINT = 115792089237316195423570985008687907853269984665640564039457584007913129639935; | ||
|
||
StdStorage internal stdstore; | ||
|
||
// Set the balance of an account for any ERC20 token | ||
// Use the alternative signature to update `totalSupply` | ||
function deal(address token, address to, uint256 give) internal { | ||
deal(token, to, give, false); | ||
} | ||
|
||
function deal(address token, address to, uint256 give, bool adjust) internal { | ||
// get current balance | ||
(, bytes memory balData) = token.call(abi.encodeWithSelector(0x70a08231, to)); | ||
uint256 prevBal = abi.decode(balData, (uint256)); | ||
|
||
// update balance | ||
stdstore | ||
.target(token) | ||
.sig(0x70a08231) | ||
.with_key(to) | ||
.checked_write(give); | ||
|
||
// update total supply | ||
if(adjust){ | ||
(, bytes memory totSupData) = token.call(abi.encodeWithSelector(0x18160ddd)); | ||
uint256 totSup = abi.decode(totSupData, (uint256)); | ||
if(give < prevBal) { | ||
totSup -= (prevBal - give); | ||
} else { | ||
totSup += (give - prevBal); | ||
} | ||
stdstore | ||
.target(token) | ||
.sig(0x18160ddd) | ||
.checked_write(totSup); | ||
} | ||
} | ||
} |