Skip to content
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

fea: add psm #104

Merged
merged 67 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
aa7ad49
fea: add psm
ricklista Oct 9, 2024
df7523c
fea: add testnet deploy scripts
ricklista Nov 4, 2024
a785d88
fix: PSM VaultManager VenusAdapter issues
ricklista Nov 4, 2024
b236fe9
VenusAdapter quota to delta
ricklista Nov 4, 2024
8460e5f
fix: remove totalAssetEmissionWeights
ricklista Nov 4, 2024
d728c1e
fea: dev deploy scripts optimize
ricklista Nov 4, 2024
bade256
fix: review issues
ricklista Nov 5, 2024
2577b41
fix: add MIT licence and some issues
ricklista Nov 5, 2024
3bb3f3a
docs: add diagrams for psm
qingyang-lista Nov 5, 2024
6effd8f
Merge branch 'psm' of github.com:lista-dao/lista-dao-contracts into psm
qingyang-lista Nov 5, 2024
f4692bc
docs: update diagram of PSM
qingyang-lista Nov 5, 2024
16414fd
docs: correct diagram of PSM
qingyang-lista Nov 5, 2024
969755b
fix: vault manager precision
ricklista Nov 6, 2024
df51422
Merge branch 'psm' of github.com:lista-dao/lista-dao-contracts into psm
ricklista Nov 6, 2024
2316367
fix: add MIT License
ricklista Nov 6, 2024
b180a1a
Merge branch 'master' into psm
ricklista Nov 6, 2024
46d9150
fix: withdraw remain
ricklista Nov 6, 2024
3f05527
fix: netDeposit is zero issue
ricklista Nov 6, 2024
5f8b9e4
Merge branch 'master' into psm
ricklista Nov 6, 2024
24cee45
fix: remove test/psm/Atest.t.sol
ricklista Nov 6, 2024
ebeaf39
fix: add ReentrancyGuardUpgradeable to VaultManager
ricklista Nov 6, 2024
3b0685a
fix: add events
ricklista Nov 6, 2024
3057231
fix: unit test
ricklista Nov 6, 2024
70d03a7
fix: harvest and withdraw delta
ricklista Nov 6, 2024
d1dcaad
Merge pull request #111 from lista-dao/code-standard
qingyang-lista Nov 6, 2024
475a52f
Merge pull request #112 from lista-dao/code-standard
qingyang-lista Nov 6, 2024
eb690c5
chore: force code style for psm
qingyang-lista Nov 6, 2024
8a5588b
Merge branch 'psm' into code-standard-new
qingyang-lista Nov 6, 2024
b660a53
Merge pull request #114 from lista-dao/code-standard-new
qingyang-lista Nov 6, 2024
efea041
fix: code format
ricklista Nov 6, 2024
c5bd92d
fix: VenusAdapter redeem to redeemUnderlying
ricklista Nov 6, 2024
796cd42
fix: withdraw rand index
ricklista Nov 7, 2024
cdcd88c
fix: remove emergencyWithdraw from VenusAdapter
ricklista Nov 8, 2024
f96b6ad
fea: add contracts/mock/psm/MockVenus.sol and scripts/dev/psm/deploy_…
ricklista Nov 11, 2024
03426b3
fix: psm unit test
ricklista Nov 11, 2024
7a098f9
fix: add vault manager unit test
ricklista Nov 11, 2024
51cae58
fix: venusAdapter unit test
ricklista Nov 11, 2024
f9c4ee1
fix: vaultManager active withdraw
ricklista Nov 12, 2024
7e36b05
fix: psm fees harvest
ricklista Nov 12, 2024
c41aacd
fix: getTotalSellLimit
ricklista Nov 12, 2024
e409ceb
fix: vault manager withdraw
ricklista Nov 12, 2024
15b0fd4
fix: vault manager withdraw
ricklista Nov 12, 2024
6d91b04
Merge branch 'psm-fix-1.0' of https://github.com/lista-dao/lista-dao-…
paddy20210802 Nov 12, 2024
fd1cf25
psm audit fix
ricklista Nov 13, 2024
608b2e2
Merge branch 'psm-fix-1.0' of github.com:lista-dao/lista-dao-contract…
ricklista Nov 13, 2024
016ede4
fix: add scripts/dev/psm/deploy_venusAdapter.js
ricklista Nov 13, 2024
bc4a54a
Merge pull request #118 from lista-dao/psm-audit-fix-1.0
ricklista Nov 13, 2024
a15bdf1
Merge branch 'master' into psm
ricklista Nov 13, 2024
34d738a
fix: lisUSD upgrade unit test
ricklista Nov 13, 2024
4b786cf
fea: add psm prod deploy scripts
ricklista Nov 20, 2024
141be08
! fix workflow error
tedw-lista Nov 21, 2024
a3c57eb
fix: blocksec and salus audit fix
ricklista Nov 21, 2024
21cc0bf
Merge remote-tracking branch 'origin/241121_workflow_fix' into psm-au…
ricklista Nov 21, 2024
3d037b9
fea: LisUSDPoolSet bot call setDuty
ricklista Nov 21, 2024
fca5f0c
fix: add bot in contructor
ricklista Nov 21, 2024
31d1216
fix: psm deploy scripts
ricklista Nov 22, 2024
c4d1008
Merge pull request #119 from lista-dao/psm-audit-fix-2.0
ricklista Nov 22, 2024
9913306
add audit report
ricklista Nov 22, 2024
b7c8e00
Merge branch 'psm' of github.com:lista-dao/lista-dao-contracts into psm
ricklista Nov 22, 2024
7655ff0
chore: update psm deploy scripts
qingyang-lista Nov 22, 2024
dd14f75
Merge pull request #122 from lista-dao/deploy-psm
qingyang-lista Nov 22, 2024
74dc3d8
fea: add scripts/prod/psm/transfer_role.js
ricklista Nov 22, 2024
aacc308
Merge branch 'psm' of github.com:lista-dao/lista-dao-contracts into psm
ricklista Nov 22, 2024
46fbc57
chore: update psm deploy scripts
qingyang-lista Nov 22, 2024
a5fccc0
Merge branch 'psm' of github.com:lista-dao/lista-dao-contracts into psm
ricklista Nov 22, 2024
f3711f0
fix: transfer role address
ricklista Nov 22, 2024
a20e67f
fix: blocksec psm audit report
ricklista Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ coverage*
gasReporterOutput.json
lib/
contracts/*
!contracts/psm/
scripts/*
test/*
!test/psm/
Binary file added audits/blocksec_psm_241122.pdf
Binary file not shown.
Binary file added audits/salus_PSM_241122.pdf
Binary file not shown.
8 changes: 8 additions & 0 deletions contracts/hMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ library hMath {
}
}
}

function rmul(uint x, uint y) internal pure returns (uint z) {
unchecked {
z = x * y;
require(y == 0 || z / y == x);
z = z / hMath.ONE;
}
}
}
4 changes: 4 additions & 0 deletions contracts/interfaces/HayLike.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ interface HayLike is IERC20{
function transferFrom(address, address, uint256) external returns (bool);

function approve(address, uint256) external returns (bool);

function mint(address, uint256) external;

function burn(address, uint256) external;
}
14 changes: 14 additions & 0 deletions contracts/interfaces/IAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IAdapter {
function deposit(uint256 amount) external;

function withdraw(address account, uint256 amount) external;

function totalAvailableAmount() external returns (uint256);

function withdrawAll() external returns (uint256);

function netDepositAmount() external view returns (uint256);
}
6 changes: 6 additions & 0 deletions contracts/interfaces/IEarnPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IEarnPool {
function deposit(address account, uint256 gemAmount, uint256 lisUSDAmount) external;
}
6 changes: 6 additions & 0 deletions contracts/interfaces/ILisUSDPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface ILisUSDPool {
function depositFor(address pool, address account, uint256 amount) external;
}
10 changes: 10 additions & 0 deletions contracts/interfaces/IPSM.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IPSM {
function buy(uint256 amount) external;

function sell(uint256 amount) external;

function token() external view returns (address);
}
12 changes: 12 additions & 0 deletions contracts/interfaces/IVBep20Delegate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IVBep20Delegate {
ricklista marked this conversation as resolved.
Show resolved Hide resolved
function mint(uint256 mintAmount) external returns (uint256);

function redeem(uint256 redeemTokens) external returns (uint256);

function redeemUnderlying(uint256 redeemAmount) external returns (uint256);

function balanceOfUnderlying(address owner) external returns (uint256);
}
10 changes: 10 additions & 0 deletions contracts/interfaces/IVaultManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IVaultManager {
function deposit(uint256 amount) external;

function withdraw(address receiver, uint256 amount) external;

function getTotalNetDepositAmount() external view returns (uint256);
}
2 changes: 2 additions & 0 deletions contracts/interfaces/VatLike.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ interface VatLike {
function cage() external;

function uncage() external;

function debt() external view returns (uint256);
}
11 changes: 11 additions & 0 deletions contracts/mock/MockUSDC.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockUSDC is ERC20 {
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {
uint256 initialSupply = 1e18 * 1e9;
_mint(msg.sender, initialSupply);
}
}
39 changes: 39 additions & 0 deletions contracts/mock/psm/MockVenus.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract MockVenus is ERC20 {
using SafeERC20 for IERC20;
address public underlying;

constructor(address _underlying) ERC20("MockVenus", "MockVenus") {
underlying = _underlying;
}

function mint(uint256 amount) external returns (uint256) {
IERC20(underlying).safeTransferFrom(msg.sender, address(this), amount);

_mint(msg.sender, amount);
return amount;
}

function redeem(uint256 amount) external returns (uint256) {
IERC20(underlying).safeTransfer(msg.sender, amount);

_burn(msg.sender, amount);
return amount;
}

function redeemUnderlying(uint256 amount) external returns (uint256) {
IERC20(underlying).safeTransfer(msg.sender, amount);

_burn(msg.sender, amount);
return amount;
}

function balanceOfUnderlying(address owner) external view returns (uint256) {
return balanceOf(owner);
}
}
132 changes: 132 additions & 0 deletions contracts/psm/EarnPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "../interfaces/ILisUSDPool.sol";
import "../interfaces/IPSM.sol";

contract EarnPool is AccessControlUpgradeable, PausableUpgradeable, UUPSUpgradeable {
using SafeERC20 for IERC20;

// token => psm
mapping(address => address) public psm;

address public lisUSDPool; // lisUSD pool address

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are not to be updated, then you can make them immutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be updated

address public lisUSD; // lisUSD address

bytes32 public constant MANAGER = keccak256("MANAGER"); // manager role
bytes32 public constant PAUSER = keccak256("PAUSER"); // pause role

event SetLisUSDPool(address lisUSDPool);
event SetLisUSD(address lisUSD);
event SetPSM(address token, address psm);
event RemovePSM(address token);

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

/**
* @dev initialize contract
* @param _admin admin address
* @param _manager manager address
* @param _lisUSDPool lisUSD pool address
* @param _lisUSD lisUSD address
*/
function initialize(
address _admin,
address _manager,
address _pauser,
address _lisUSDPool,
address _lisUSD
) public initializer {
require(_admin != address(0), "admin cannot be zero address");
require(_manager != address(0), "manager cannot be zero address");
require(_pauser != address(0), "pauser cannot be zero address");
require(_lisUSDPool != address(0), "lisUSDPool cannot be zero address");
require(_lisUSD != address(0), "lisUSD cannot be zero address");
__AccessControl_init();
__Pausable_init();
__UUPSUpgradeable_init();

_setupRole(DEFAULT_ADMIN_ROLE, _admin);
_setupRole(MANAGER, _manager);
_setupRole(PAUSER, _pauser);

lisUSDPool = _lisUSDPool;
lisUSD = _lisUSD;

emit SetLisUSDPool(_lisUSDPool);
emit SetLisUSD(_lisUSD);
}

/**
* @dev deposit token to earn pool
* @param token token address
* @param amount token amount
*/
function deposit(address token, uint256 amount) external whenNotPaused {
require(amount > 0, "amount must be greater than zero");
require(psm[token] != address(0), "psm not set");

address account = msg.sender;
// transfer token to earn pool
IERC20(token).safeTransferFrom(account, address(this), amount);

// convert token to lisUSD by psm
IERC20(token).safeIncreaseAllowance(psm[token], amount);
uint256 before = IERC20(lisUSD).balanceOf(address(this));
IPSM(psm[token]).sell(amount);
uint256 lisUSDAmount = IERC20(lisUSD).balanceOf(address(this)) - before;

// deposit lisUSD to lisUSD pool
IERC20(lisUSD).safeIncreaseAllowance(lisUSDPool, lisUSDAmount);
ILisUSDPool(lisUSDPool).depositFor(token, account, lisUSDAmount);
}

/**
* @dev pause contract
*/
function pause() external onlyRole(PAUSER) {
_pause();
}

/**
* @dev unpause contract
*/
function unpause() external onlyRole(MANAGER) {
_unpause();
}

/**
* @dev set psm
* @param _token token address
* @param _psm psm address
*/
function setPSM(address _token, address _psm) external onlyRole(MANAGER) {
require(_token != address(0), "token cannot be zero address");
require(_psm != address(0), "psm cannot be zero address");
require(psm[_token] == address(0), "psm already set");
require(IPSM(_psm).token() == _token, "psm token not match");
psm[_token] = _psm;

emit SetPSM(_token, _psm);
}

/**
* @dev remove psm
* @param _token token address
*/
function removePSM(address _token) external onlyRole(MANAGER) {
require(psm[_token] != address(0), "psm is not set");
delete psm[_token];

emit RemovePSM(_token);
}

function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}
}
Loading
Loading