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

Add Lens contract to Optimism #171

Merged
merged 83 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
278faab
chg: Test aaveadapter with full path.
twygod Sep 6, 2022
84eb4cd
fix: remove call claimRewards result judgment, Because there is no re…
twygod Sep 8, 2022
f120915
new: add int tests for pure token adapter.
maxweng Sep 9, 2022
edafbb1
Merge remote-tracking branch 'origin/develop' into feature/uni-920-in…
maxweng Sep 9, 2022
94859d4
fix: add non null assertion.
twygod Sep 9, 2022
d200428
new: add slither analyzer.
maxweng Sep 9, 2022
ac14899
fix: compile errors.
maxweng Sep 12, 2022
b70ac98
fix: reentrancy warnings.
maxweng Sep 12, 2022
257d8b8
fix: uninitialized var warnings.
maxweng Sep 12, 2022
e96d876
fix: tautology warnings.
maxweng Sep 12, 2022
648ab87
fix: disable unused return warnings.
maxweng Sep 12, 2022
30e0f66
fix: Slither warning.
twygod Sep 12, 2022
585d13d
chg: check if the adapter is valid.
maxweng Sep 12, 2022
2a51c9b
fix: pureAdapter foundry test.
twygod Sep 12, 2022
c49b2e9
Merge pull request #34 from unioncredit/feature/uni-920-int-test-for-…
GeraldHost Sep 12, 2022
727a502
chg: mute false positive slither warnings.
maxweng Sep 15, 2022
a4b726b
chg: update gas-snapshot
maxweng Sep 15, 2022
f61cf1e
Merge remote-tracking branch 'origin/develop' into feature/uni-929-ru…
maxweng Sep 15, 2022
3ccf4a2
chg: gas optimization.
maxweng Sep 15, 2022
81d3069
chg: revert to previous version.
maxweng Sep 24, 2022
933ff4b
chg: check if the token address is a contract.
maxweng Sep 30, 2022
30706ce
feat: remove contract check
GeraldHost Oct 4, 2022
2b78d0f
feat: public to external
GeraldHost Oct 4, 2022
49fdb32
fix: remove old test
GeraldHost Oct 4, 2022
951c4c5
Merge pull request #35 from unioncredit/feature/uni-929-run-through-s…
GeraldHost Oct 4, 2022
cab3ec3
feat: added getBorrowerAddresses and getStakerAddresses functions
0xbarbs Sep 17, 2023
7399a0d
new: add unionLens test.
twygod Oct 12, 2023
ebc0365
Merge branch 'feature/uni-1316-data-columns-missing-from-optimism-and…
twygod Oct 20, 2023
ad83e0a
new: deploy lens on op-goerli.
twygod Oct 20, 2023
af8688c
chg: update hardhat to 2.21.0
maxweng Mar 14, 2024
c94c453
chg: update deploy script to support USDC and Base network
maxweng Mar 15, 2024
68c84ad
chg: update github actions
maxweng Mar 15, 2024
a7092fe
chg: update hardhat version
maxweng Mar 15, 2024
eca9109
chg: remove gov actions
maxweng Mar 15, 2024
cf7330d
chg: update dependencies
maxweng Mar 15, 2024
76c1e05
chg: update github actions
maxweng Mar 16, 2024
96144bc
chg: add base-sepolia deployment
maxweng Mar 16, 2024
a0235ae
chg: update eth-optimism/sdk to support base network
maxweng Mar 18, 2024
58df6dd
new: deploy lens
twygod Mar 18, 2024
7758295
fix: unit error
twygod Mar 21, 2024
a4a5f81
chg: update contract and test
twygod Mar 26, 2024
cf09374
chg: update contract and test
twygod Mar 26, 2024
b31a98d
chg: update deploy script and deploy contract
twygod Mar 26, 2024
36f7883
chg: deploy and set aaveadapter on base sepolia
twygod Jun 13, 2024
de2b1c3
new: add testing
twygod Jun 20, 2024
38fc165
chg: add ScaledDecimalBase contract
maxweng Jun 20, 2024
b3ca13e
fix: compiler warnings
maxweng Jun 20, 2024
feabaf2
chg: add env var DECIMALS for various tokens decimals testing
maxweng Jun 20, 2024
5b204ba
fix: update erc20 mock contract to fix permit func error
twygod Jun 24, 2024
c61b149
chg: add new test
twygod Jun 24, 2024
7b00ef5
chg: update UNIT setting on foundry test
twygod Jun 24, 2024
58a40b5
chg: set DECIMAL's default value if not set
maxweng Jul 1, 2024
8003e7d
chg: add base-sepolia testnet
maxweng Jul 1, 2024
9fe5a80
Merge remote-tracking branch 'origin/develop' into feature/uni-1825-d…
maxweng Jul 1, 2024
353db2e
chg: fix test errors after merging the dev branch
maxweng Jul 1, 2024
0ce7036
fix: slither warnings
maxweng Jul 1, 2024
1e6c540
chg: add extra check on the withdrawal amount from the assetManager
maxweng Jul 24, 2024
84eb9d7
chg: update to use the correct OZ lib
maxweng Jul 24, 2024
9f1c1ea
fix: calculate the global total stake after total frozen is updated
maxweng Jul 22, 2024
7c39016
fix: coverage report error
maxweng Jul 29, 2024
bb7454f
fix: rounding up the utoken amount when redeeming
maxweng Jul 23, 2024
b1786d2
Merge remote-tracking branch 'origin/feature/uni-1825-deploy-to-base-…
maxweng Aug 30, 2024
10e974b
Merge pull request #175 from unioncredit/finding/uni-1992-repaying-a-…
maxweng Aug 30, 2024
da5c99d
chg: consider introducing an option for rounding the decimalReducing(…
twygod Jul 25, 2024
be12536
chg: add test
twygod Jul 25, 2024
3ad06dc
chg: modify coverage configuration
twygod Jul 26, 2024
2cc2c60
chg: add scaledDecimal test
twygod Jul 26, 2024
2027dec
chg: update scaledDecimal test
twygod Jul 26, 2024
d5d4996
chg: update scaledDecimal test
twygod Jul 26, 2024
9425e85
fix: repayBorrowWithERC20Permit functions use incorrectly scaled accu…
twygod Jul 25, 2024
037dbea
chg: update test
twygod Jul 30, 2024
1dd601d
fix: exchangeRateStored decimals are incorrect and misaligned with ex…
twygod Jul 25, 2024
b47c6b8
chg: update test
twygod Jul 25, 2024
295042b
fix: the amount of _totalStaked added when writeOffDebt is not scaled
twygod Jul 25, 2024
3d6da9a
chg: add test
twygod Jul 25, 2024
93934fa
chg: max_borrow_rate to 100% apr
maxweng Jul 30, 2024
d3197fc
Merge branch 'feature/uni-1825-deploy-to-base-sepolia-testnet' into f…
maxweng Aug 31, 2024
ef7e42d
Merge pull request #180 from unioncredit/finding/uni-1989-wrong-calcu…
maxweng Aug 31, 2024
2216798
fix: slither warnings
maxweng Aug 31, 2024
65007a0
new: deploye contract when fixed
twygod Sep 19, 2024
0626512
chg: update contract address
twygod Sep 19, 2024
a753bd6
Merge pull request #172 from unioncredit/feature/uni-1825-deploy-to-b…
maxweng Dec 6, 2024
e9b293d
Merge remote-tracking branch 'origin/master' into develop
maxweng Dec 6, 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
6 changes: 3 additions & 3 deletions .github/workflows/ci_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
name: Build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20

- name: Install dependencies
run: yarn install
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
name: Build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- name: Install dependencies
run: yarn install
Expand Down Expand Up @@ -45,14 +45,14 @@ jobs:
run: yarn hh:test

- name: Run Slither
uses: crytic/[email protected].0
uses: crytic/[email protected].1
id: slither
with:
node-version: 16
node-version: 20
sarif: results.sarif
fail-on: none

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
7 changes: 3 additions & 4 deletions .github/workflows/ci_slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ jobs:
name: Run slither
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: crytic/[email protected].0
- uses: actions/checkout@v4
- uses: crytic/[email protected].1
with:
node-version: 16
node-version: 20
target: "."
slither-args: '--filter-path "test|node_modules|contracts/mocks"'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ docs
.envrc
dist
report
arguments.js
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Built using [foundry](https://book.getfoundry.sh/) and [hardhat](https://hardhat
- [contract addresses](https://github.com/unioncredit/union-v2-contracts/blob/master/deployments/optimism-goerli/deployment.json)
- [deployment config](https://github.com/unioncredit/union-v2-contracts/blob/master/deployments/optimism-goerli/config.json)

- Base Sepolia

- [contract addresses](https://github.com/unioncredit/union-v2-contracts/blob/master/deployments/optimism-goerli/deployment.json)
- [deployment config](https://github.com/unioncredit/union-v2-contracts/blob/master/deployments/optimism-goerli/config.json)

## Install

To install dependencies:
Expand Down Expand Up @@ -113,3 +118,9 @@ CONFIG=arbitrum FORK_NODE_URL=<URL> FORK_BLOCK=<NUMBER> yarn hh:test
```
yarn format
```

## Other Scripts

Deposit to L2

yarn hardhat --network sepolia --config hardhat-task.config.ts op:deposit --pk <private_key> --l1-rpc-url https://eth-sepolia.public.blastapi.io --l2-rpc-url https://sepolia.base.org --l1-union 0xE4ADdfdf5641EB4e15F60a81F63CEd4884B49823 --l2-union 0xB025ee78b54B5348BD638Fe4a6D77Ec2F813f4f9 --amount 10000
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ ignore:
- "contracts/mocks/"
- "test/foundry/"
- "contracts/peripheral"
coverage:
status:
project:
default:
threshold: 1%
8 changes: 4 additions & 4 deletions contracts/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ abstract contract Controller is Initializable, UUPSUpgradeable {
* @dev Check if the address provided is the admin
* @param account Account address
*/
function isAdmin(address account) public view returns (bool) {
function isAdmin(address account) external view returns (bool) {
return account == admin;
}

/**
* @dev set new admin account
* @param account Account address
*/
function setPendingAdmin(address account) public onlyAdmin {
function setPendingAdmin(address account) external onlyAdmin {
pendingAdmin = account;
}

function acceptAdmin() public {
function acceptAdmin() external {
if (pendingAdmin != msg.sender) revert SenderNotPendingAdmin();
admin = pendingAdmin;
}
Expand All @@ -137,7 +137,7 @@ abstract contract Controller is Initializable, UUPSUpgradeable {
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view returns (bool) {
function paused() external view returns (bool) {
return _paused;
}

Expand Down
39 changes: 39 additions & 0 deletions contracts/ScaledDecimalBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

/**
* @title ScaledDecimalBase
* @dev For easy access to the utility functions of scaling decimals
*/
abstract contract ScaledDecimalBase {
function decimalScaling(uint256 amount, uint8 decimal) internal pure returns (uint256) {
if (decimal > 18) {
uint8 diff = decimal - 18;
return amount / 10 ** diff;
} else {
uint8 diff = 18 - decimal;
return amount * 10 ** diff;
}
}

function decimalReducing(uint256 actualAmount, uint8 decimal) internal pure returns (uint256) {
if (decimal > 18) {
uint8 diff = decimal - 18;
return actualAmount * 10 ** diff;
} else {
uint8 diff = 18 - decimal;
return actualAmount / 10 ** diff;
}
}

function decimalReducing(uint256 actualAmount, uint8 decimal, bool roundUp) internal pure returns (uint256) {
if (decimal > 18) {
uint8 diff = decimal - 18;
return actualAmount * 10 ** diff;
} else {
uint8 diff = 18 - decimal;
uint256 rounding = roundUp ? 10 ** diff - 1 : 0;
return (actualAmount + rounding) / 10 ** diff;
}
}
}
76 changes: 47 additions & 29 deletions contracts/UnionLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,59 @@
IUserManager userManager = IUserManager(marketRegistry.userManagers(underlying));
IUToken uToken = IUToken(marketRegistry.uTokens(underlying));

(bool isMember, uint96 stakedAmount, uint96 locked, , , ) = userManager.stakers(user);
bool isMember = userManager.checkIsMember(user);
uint256 stakedAmount = userManager.getStakerBalance(user);
uint256 locked = userManager.getTotalLockedStake(user);

Check warning on line 64 in contracts/UnionLens.sol

View check run for this annotation

Codecov / codecov/patch

contracts/UnionLens.sol#L62-L64

Added lines #L62 - L64 were not covered by tests

userInfo.isOverdue = uToken.checkIsOverdue(user);
userInfo.memberFrozen = userManager.memberFrozen(user);

userInfo.isMember = isMember;
userInfo.locked = uint256(locked);
userInfo.stakedAmount = uint256(stakedAmount);
userInfo.locked = locked;
userInfo.stakedAmount = stakedAmount;

Check warning on line 71 in contracts/UnionLens.sol

View check run for this annotation

Codecov / codecov/patch

contracts/UnionLens.sol#L70-L71

Added lines #L70 - L71 were not covered by tests

userInfo.voucherCount = userManager.getVoucherCount(user);
userInfo.voucheeCount = userManager.getVoucheeCount(user);

userInfo.accountBorrow = uToken.getBorrowed(user);
}

function getBorrowerAddresses(address underlying, address account) public view returns (address[] memory) {
IUserManager userManager = IUserManager(marketRegistry.userManagers(underlying));

uint256 voucheeCount = userManager.getVoucheeCount(account);
address[] memory addresses = new address[](voucheeCount);

for (uint256 i = 0; i < voucheeCount; i++) {
(address borrower, ) = userManager.vouchees(account, i);
addresses[i] = borrower;
}

return addresses;
}

function getStakerAddresses(address underlying, address account) public view returns (address[] memory) {
IUserManager userManager = IUserManager(marketRegistry.userManagers(underlying));

uint256 voucherCount = userManager.getVoucherCount(account);
address[] memory addresses = new address[](voucherCount);

for (uint256 i = 0; i < voucherCount; i++) {
(address staker, , ,) = userManager.vouchers(account, i);
addresses[i] = staker;
}

return addresses;
}

function getVouchInfo(
address underlying,
address staker,
address borrower
) public view returns (uint256, uint256, uint256, uint256) {
IUserManager userManager = IUserManager(marketRegistry.userManagers(underlying));

(, uint96 stakerStakedAmount, , , , ) = userManager.stakers(staker);
uint256 stakerStakedAmount = userManager.getStakerBalance(staker);

Check warning on line 114 in contracts/UnionLens.sol

View check run for this annotation

Codecov / codecov/patch

contracts/UnionLens.sol#L114

Added line #L114 was not covered by tests

bool isSet;
uint256 idx;
Expand All @@ -95,7 +125,7 @@

return (
uint256(trust),
trust > stakerStakedAmount ? stakerStakedAmount : trust, // vouch
uint256(trust) > stakerStakedAmount ? stakerStakedAmount : uint256(trust), // vouch
uint256(locked),
uint256(lastUpdated)
);
Expand All @@ -106,32 +136,20 @@
address staker,
address borrower
) public view returns (RelatedInfo memory related) {
(
uint256 voucherTrust,
uint256 voucherVouch,
uint256 voucherLocked,
uint256 voucherLastUpdated
) = getVouchInfo(underlying, staker, borrower);

(
uint256 voucheeTrust,
uint256 voucheeVouch,
uint256 voucheeLocked,
uint256 voucheeLastUpdated
) = getVouchInfo(underlying, borrower, staker);

related.voucher = VouchInfo(
voucherTrust,
voucherVouch,
voucherLocked,
voucherLastUpdated
(uint256 voucherTrust, uint256 voucherVouch, uint256 voucherLocked, uint256 voucherLastUpdated) = getVouchInfo(

Check warning on line 139 in contracts/UnionLens.sol

View check run for this annotation

Codecov / codecov/patch

contracts/UnionLens.sol#L139

Added line #L139 was not covered by tests
underlying,
staker,
borrower
);

related.vouchee = VouchInfo(
voucheeTrust,
voucheeVouch,
voucheeLocked,
voucheeLastUpdated
(uint256 voucheeTrust, uint256 voucheeVouch, uint256 voucheeLocked, uint256 voucheeLastUpdated) = getVouchInfo(

Check warning on line 145 in contracts/UnionLens.sol

View check run for this annotation

Codecov / codecov/patch

contracts/UnionLens.sol#L145

Added line #L145 was not covered by tests
underlying,
borrower,
staker
);

related.voucher = VouchInfo(voucherTrust, voucherVouch, voucherLocked, voucherLastUpdated);

Check warning on line 151 in contracts/UnionLens.sol

View check run for this annotation

Codecov / codecov/patch

contracts/UnionLens.sol#L151

Added line #L151 was not covered by tests

related.vouchee = VouchInfo(voucheeTrust, voucheeVouch, voucheeLocked, voucheeLastUpdated);

Check warning on line 153 in contracts/UnionLens.sol

View check run for this annotation

Codecov / codecov/patch

contracts/UnionLens.sol#L153

Added line #L153 was not covered by tests
}
}
2 changes: 1 addition & 1 deletion contracts/asset/AssetManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ contract AssetManager is Controller, ReentrancyGuardUpgradeable, IAssetManager {
* @param token ERC20 token address
* @param account User address
* @param amount ERC20 token address
* @return Withdraw amount
* @return The difference between the amount withdrawn and the amount transferred to the caller
*/
function withdraw(
address token,
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IDai.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ interface IDai is IERC20 {
bytes32 r,
bytes32 s
) external;

function decimals() external view returns (uint8);
}
2 changes: 2 additions & 0 deletions contracts/interfaces/IUserManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ interface IUserManager {
*/
function getStakeInfo(address staker) external view returns (bool, uint256, uint256, uint256);

function getStakeInfoMantissa(address staker) external view returns (bool, uint256, uint256, uint256);

/**
* @dev Update the frozen info by the comptroller
* @param staker Staker address
Expand Down
4 changes: 2 additions & 2 deletions contracts/market/FixedInterestRateModel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ contract FixedInterestRateModel is Ownable, IInterestRateModel {
Storage
------------------------------------------------------------------- */
/**
* @dev Maximum borrow rate that can ever be applied (0.005% / 12 second)
* @dev Maximum borrow rate that can ever be applied (100%, 1e18 / 3600 / 24 / 365)
*/
uint256 public constant BORROW_RATE_MAX_MANTISSA = 4_166_666_666_667; // 0.005e16 / 12
uint256 public constant BORROW_RATE_MAX_MANTISSA = 31_709_791_983;

/**
* @dev IInterest rate per second
Expand Down
4 changes: 2 additions & 2 deletions contracts/market/UDai.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract UDai is UToken, IUDai {
erc20Token.permit(msg.sender, address(this), nonce, expiry, true, v, r, s);

if (!accrueInterest()) revert AccrueInterestFailed();
uint256 interest = calculatingInterest(borrower);
_repayBorrowFresh(msg.sender, borrower, amount, interest);
uint256 interest = _calculatingInterest(borrower);
_repayBorrowFresh(msg.sender, borrower, decimalScaling(amount, underlyingDecimal), interest);
}
}
4 changes: 2 additions & 2 deletions contracts/market/UErc20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract UErc20 is UToken {
erc20Token.permit(msg.sender, address(this), amount, deadline, v, r, s);

if (!accrueInterest()) revert AccrueInterestFailed();
uint256 interest = calculatingInterest(borrower);
_repayBorrowFresh(msg.sender, borrower, amount, interest);
uint256 interest = _calculatingInterest(borrower);
_repayBorrowFresh(msg.sender, borrower, decimalScaling(amount, underlyingDecimal), interest);
}
}
Loading
Loading