-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NES-255] make pUSD a ComponentToken #97
Open
ungaro
wants to merge
35
commits into
main
Choose a base branch
from
alp/NES-255
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2131910
[NES-254] add adapter contract for pUSD
eyqs e415bc9
add vault for pUSD
ungaro 51e5d53
remove incorrect include
ungaro 9656816
keep pUSD as ERC20 and remove unnecessary functions
ungaro 69467dd
remove comment
ungaro 35ca154
fmt
ungaro c613ac9
remove hook
ungaro 697c4f9
make pUSD a ComponentToken
ungaro 03dcdd1
make pUSD a ComponentToken and update Deployment Script
ungaro 2452ef9
change storage location
ungaro 9fc98c6
remove erc4626
ungaro 1636d22
update pUSD storage slot
ungaro 300f1b4
pUSD is Initializable, ERC20Upgradeable, AccessControlUpgradeable, UU…
ungaro 9e4f883
merge main
ungaro 00cd67b
fix overrides
ungaro 270dd48
update description
ungaro 5bc1b2f
add test for pUSD - WIP
ungaro 1ce0e5a
add mockvault for pUSD
ungaro 47cb601
change initialization modifier to onlyInitializing
ungaro f5773db
remove pausable
ungaro b00649d
finish preliminary tests, fix some bugs with MockVault and pUSD
ungaro 013f0eb
93.9% coverage for pUSD - rest is just assembly
ungaro f034359
remove comments
ungaro 5521e69
add IVault interface
ungaro 2ab5bb8
forge fmt
ungaro 4fdd93f
better handling of convertToShares, convertToAssets, make tests 100% …
ungaro 030869c
forge fmt
ungaro ff2f659
add extra comment
ungaro 93a2f34
add reentrancy check
ungaro 269841d
implementing some audit findings & ComponentToken precision test checks
ungaro 396cff3
leave conversion functions unimplemented and force integrators to imp…
ungaro d6537de
add NatSpec comments for functions
ungaro d5d2a61
remove componenttoken comments
ungaro 999adcb
deployment script for pUSD
ungaro 114516a
add pUSD contract update
ungaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import { Script } from "forge-std/Script.sol"; | ||
import { console2 } from "forge-std/console2.sol"; | ||
|
||
import { pUSD } from "../src/token/pUSD.sol"; | ||
|
||
contract DeploypUSD is Script { | ||
|
||
address private constant NEST_ADMIN_ADDRESS = 0xb015762405De8fD24d29A6e0799c12e0Ea81c1Ff; | ||
address private constant USDC_ADDRESS = 0x401eCb1D350407f13ba348573E5630B83638E30D; | ||
address private constant VAULT_TOKEN = 0xe644F07B1316f28a7F134998e021eA9f7135F351; | ||
|
||
function run() external { | ||
vm.startBroadcast(NEST_ADMIN_ADDRESS); | ||
|
||
// Deploy pUSD implementation | ||
pUSD pUSDToken = new pUSD(); | ||
console2.log("pUSD implementation deployed to:", address(pUSDToken)); | ||
|
||
// Deploy pUSD proxy | ||
ERC1967Proxy pUSDProxy = new ERC1967Proxy( | ||
address(pUSDToken), | ||
abi.encodeCall( | ||
pUSD.initialize, | ||
( | ||
NEST_ADMIN_ADDRESS, // owner | ||
IERC20(USDC_ADDRESS), // asset token (USDC) | ||
VAULT_TOKEN // vault token address | ||
) | ||
) | ||
); | ||
console2.log("pUSD proxy deployed to:", address(pUSDProxy)); | ||
|
||
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 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,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
interface IVault { | ||
|
||
/** | ||
* @notice Deposits assets into the vault in exchange for shares | ||
* @param from Address providing the assets | ||
* @param asset Token address being deposited | ||
* @param assetAmount Amount of assets to deposit | ||
* @param to Address receiving the vault shares | ||
* @param shareAmount Amount of shares to mint | ||
*/ | ||
function enter(address from, address asset, uint256 assetAmount, address to, uint256 shareAmount) external; | ||
|
||
/** | ||
* @notice Withdraws assets from the vault by burning shares | ||
* @param to Address receiving the withdrawn assets | ||
* @param asset Token address being withdrawn | ||
* @param assetAmount Amount of assets to withdraw | ||
* @param from Address providing the shares to burn | ||
* @param shareAmount Amount of shares to burn | ||
*/ | ||
function exit(address to, address asset, uint256 assetAmount, address from, uint256 shareAmount) external; | ||
|
||
/** | ||
* @notice Transfers vault shares from one address to another | ||
* @param from Address sending the shares | ||
* @param to Address receiving the shares | ||
* @param amount Number of shares to transfer | ||
* @return bool Success of the transfer operation | ||
*/ | ||
function transferFrom(address from, address to, uint256 amount) external returns (bool); | ||
|
||
/** | ||
* @notice Approves another address to spend vault shares | ||
* @param spender Address authorized to spend shares | ||
* @param amount Number of shares approved to spend | ||
* @return bool Success of the approval operation | ||
*/ | ||
function approve(address spender, uint256 amount) external returns (bool); | ||
|
||
/** | ||
* @notice Returns the number of vault shares owned by an account | ||
* @param account Address to check balance for | ||
* @return uint256 Number of shares owned by the account | ||
*/ | ||
function balanceOf( | ||
address account | ||
) external view returns (uint256); | ||
|
||
} |
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,78 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
contract MockVault { | ||
|
||
using SafeERC20 for IERC20; | ||
|
||
mapping(address => uint256) private _balances; | ||
mapping(address => mapping(address => uint256)) private _allowances; | ||
IERC20 public asset; | ||
|
||
function enter(address from, address asset_, uint256 assetAmount, address to, uint256 shareAmount) external { | ||
if (assetAmount > 0) { | ||
IERC20(asset_).safeTransferFrom(from, address(this), assetAmount); | ||
} | ||
_balances[to] = _balances[to] + shareAmount; | ||
_allowances[to][msg.sender] = type(uint256).max; | ||
} | ||
|
||
function exit(address to, address asset_, uint256 assetAmount, address from, uint256 shareAmount) external { | ||
// Change from checking 'from' balance to checking the actual owner's balance | ||
address owner = from == msg.sender ? to : from; | ||
require(_balances[owner] >= shareAmount, "MockVault: insufficient balance"); | ||
|
||
uint256 allowed = _allowances[owner][msg.sender]; | ||
if (allowed != type(uint256).max) { | ||
require(allowed >= shareAmount, "MockVault: insufficient allowance"); | ||
_allowances[owner][msg.sender] = allowed - shareAmount; | ||
} | ||
|
||
_balances[owner] = _balances[owner] - shareAmount; | ||
|
||
// Changed: Transfer to 'to' instead of msg.sender, and always transfer if we have shares | ||
if (shareAmount > 0) { | ||
IERC20(asset_).safeTransfer(to, shareAmount); | ||
} | ||
} | ||
|
||
function transferFrom(address from, address to, uint256 amount) external returns (bool) { | ||
require(_balances[from] >= amount, "MockVault: insufficient balance"); | ||
|
||
uint256 allowed = _allowances[from][msg.sender]; | ||
if (allowed != type(uint256).max) { | ||
require(allowed >= amount, "MockVault: insufficient allowance"); | ||
_allowances[from][msg.sender] = allowed - amount; | ||
} | ||
|
||
_balances[from] = _balances[from] - amount; | ||
_balances[to] = _balances[to] + amount; | ||
return true; | ||
} | ||
|
||
function approve(address spender, uint256 amount) external returns (bool) { | ||
_allowances[msg.sender][spender] = amount; | ||
return true; | ||
} | ||
|
||
function balanceOf( | ||
address account | ||
) external view returns (uint256) { | ||
return _balances[account]; | ||
} | ||
|
||
function setBeforeTransferHook( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need |
||
address | ||
) external { | ||
// Mock implementation | ||
} | ||
|
||
function allowance(address owner, address spender) external view returns (uint256) { | ||
return _allowances[owner][spender]; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove deploying pUSD here since we have a different script to deploy pUSD