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

[VEN-1462]: Risk Fund and XVS Converter #9

Merged
merged 213 commits into from
Jan 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
213 commits
Select commit Hold shift + click to select a range
f473ffc
refactor: removed duplicate folders and files
Debugger022 Jul 17, 2023
89138f0
upgrade: oracle dependency verion
Debugger022 Jul 18, 2023
848271f
feat: absract token transformer
Debugger022 Jul 18, 2023
08d449b
feat: risk fund contract
Debugger022 Jul 18, 2023
89c4bf8
feat: ven-1471 risk fund transformer
Debugger022 Jul 18, 2023
6a90a8a
tests: ven-1471 risk fund transformer
Debugger022 Jul 18, 2023
78c27c7
refactor: upgrade oracle dependency version
Debugger022 Jul 18, 2023
b380587
refactor: risk fund storage layout
Debugger022 Jul 19, 2023
443eedb
refactor: folder and files structure
Debugger022 Jul 19, 2023
57a465e
refactor: changes name from swap to transform
Debugger022 Jul 19, 2023
23b6698
refactor: files names
Debugger022 Jul 19, 2023
f18c2a0
refactor: ven-1748 risk fund V2
Debugger022 Jul 19, 2023
a2ddf1e
tests: ven-1748 riskfund unit tests
Debugger022 Jul 20, 2023
8319971
feat: ven-1472 xvs vault transformer
Debugger022 Jul 21, 2023
cf8f101
feat: ven-1473 xvs vault treasury
Debugger022 Jul 21, 2023
66b33fe
refactor: added preSweepToken and updateAssetsPrice
Debugger022 Jul 24, 2023
ecbb1ab
fix: pr comments
Debugger022 Jul 25, 2023
c3f500e
refactor: abstract transformer
Debugger022 Jul 26, 2023
1f7fa40
refactor: RiskFund and AbstractTransformer
Debugger022 Jul 26, 2023
6622481
refactor: remove redundant reading of assetsReserves storage
Debugger022 Jul 26, 2023
3b21bc7
fix: get amount method
Debugger022 Jul 26, 2023
f64f521
tests: fixed transformer tests
Debugger022 Jul 27, 2023
759887a
wip
Debugger022 Jul 27, 2023
a348fc0
tests: ven-1785 getAmount() risk fund transformer
Debugger022 Jul 31, 2023
631c1a9
tests: ven-1785 risk fund transformer
Debugger022 Aug 1, 2023
e80fbf4
refactor: abstract transformer tests
Debugger022 Aug 2, 2023
e45db93
refactor: added reserve helpers methods
Debugger022 Aug 3, 2023
3743f49
fix: lint issues
Debugger022 Aug 3, 2023
20ccc98
refactor: ven-1790 transformer to converter
Debugger022 Aug 3, 2023
caf7c41
fix: updatedsolidity-coverage depedency package
Debugger022 Aug 4, 2023
628a46c
Merge branch 'develop' into feat/passive-swap
Debugger022 Aug 4, 2023
b6ba439
update: yarn.lock
Debugger022 Aug 4, 2023
cbb1651
fix: gas optimization for riskfundv2
Debugger022 Aug 16, 2023
81bfa06
fix: pr comments
Debugger022 Aug 16, 2023
1d037fd
merge branch 'develop' into feat/passive-swap
Debugger022 Aug 16, 2023
57dceb0
feat: ven-1827 added core pool in risk fund converter
Debugger022 Aug 16, 2023
91bbfbb
feat: ven-1828 added sweep token in risk fund
Debugger022 Aug 16, 2023
a8068a7
tests: ven-1827 added core pool in the risk fund
Debugger022 Aug 16, 2023
64218e3
tests: ven-1828 added sweepToken method for risk fund v2
Debugger022 Aug 16, 2023
bbaf19a
feat: ven-1834 functionality for multiple assets in risk fund
Debugger022 Aug 17, 2023
e9a5c0f
refactor: undo base asset changes
Debugger022 Aug 18, 2023
46cd2cb
feat: added setter for the direct transfer assets for riskfund
Debugger022 Aug 18, 2023
e1bd562
refactor: ensure market listed in any pool
Debugger022 Aug 18, 2023
5cc6107
refactor: risk fund storage
Debugger022 Aug 18, 2023
0fb7f1d
Merge pull request #12 from VenusProtocol/VEN-1827/1828
Debugger022 Aug 20, 2023
d4240a0
refactor: is market listed for core pool logic
Debugger022 Aug 21, 2023
e766511
refactor: added functionality to set false in pool assets direct tran…
Debugger022 Aug 23, 2023
3d64345
fix: pr comments
Debugger022 Aug 24, 2023
3ca655c
Merge pull request #13 from VenusProtocol/fix/ven-1827
Debugger022 Aug 25, 2023
d099e97
tests: refactor converter fork tests
Debugger022 Aug 25, 2023
255e01a
fix: fork tests for risk fund converter
Debugger022 Aug 28, 2023
6871238
fix: make comptroller and vBNB immutable
Debugger022 Aug 29, 2023
1a41ef5
feat: support for native wrapped token
Debugger022 Aug 29, 2023
571b3bb
Merge pull request #15 from VenusProtocol/fix/ven-1827
chechu Aug 29, 2023
a314d49
Merge branch 'develop' into feat/passive-swap
chechu Aug 29, 2023
cc3d674
refactor: fixing the order of functions following linter
chechu Aug 29, 2023
f05bba5
refactor: isMarketListed method
Debugger022 Sep 1, 2023
a45d994
tests: fork tests for resume/pause and set oracle in conversion
Debugger022 Sep 1, 2023
aee3c6c
feat: ven-1883 deployment script for riskFundConverter
Debugger022 Sep 1, 2023
cdf4466
fix: resolved merge conflicts
Debugger022 Sep 3, 2023
14d56fb
fix: postConversionHook error
Debugger022 Sep 3, 2023
22865a0
tests: fork tests for native wrapped tokens
Debugger022 Sep 3, 2023
15c252d
fix: post conversion hook bug
Debugger022 Sep 4, 2023
26e3828
feat: add getters for getAmountIn and getAmountOut
Debugger022 Sep 8, 2023
7fd547e
fix: n1
Debugger022 Sep 9, 2023
2d18458
fix: n2
Debugger022 Sep 9, 2023
624b0f1
fix: n3
Debugger022 Sep 9, 2023
a1e6697
fix: pve-001
Debugger022 Sep 9, 2023
fd20124
fix: pve-002
Debugger022 Sep 9, 2023
74f9cb2
fix: pve-005
Debugger022 Sep 9, 2023
92342eb
fix: pve-003
Debugger022 Sep 9, 2023
057dcee
fix: pve-003-2
Debugger022 Sep 9, 2023
3de3561
Merge pull request #17 from VenusProtocol/VEN-1911
Debugger022 Sep 11, 2023
5d1c6b3
fix: added miannet addresses in the convertor script
Debugger022 Sep 11, 2023
0e46af5
Merge pull request #16 from VenusProtocol/VEN-1882/1883
Debugger022 Sep 11, 2023
87f0532
merge branch 'feat/passive-swap' into feat/abstract-token-converter-g…
Debugger022 Sep 11, 2023
a0d3f2a
fix: pr comments
Debugger022 Sep 11, 2023
ca8f8ba
Merge pull request #19 from VenusProtocol/feat/abstract-token-convert…
Debugger022 Sep 11, 2023
b467b46
fix:ven-2007 l-01
Debugger022 Sep 26, 2023
0f58716
fix: ven-2007 l-02
Debugger022 Sep 26, 2023
a555053
fix: ven-2007 l-04
Debugger022 Sep 26, 2023
e558b15
fix: ven-2007 l-06
Debugger022 Sep 26, 2023
5d0f03b
fix: ven-2007 n-01
Debugger022 Sep 26, 2023
91eb7a6
fix: ven-2007 n-02
Debugger022 Sep 26, 2023
1e367e1
fix: ven-2007 n-03
Debugger022 Sep 26, 2023
8d6389c
fix: ven-2007 n-04
Debugger022 Sep 26, 2023
8227f4b
fix: ven-2007 n-06
Debugger022 Sep 26, 2023
78150be
fix: ven-2007 n-09
Debugger022 Sep 27, 2023
bda9bea
fix: ven-2007 n-08
Debugger022 Sep 27, 2023
3876d3b
fix: ven-2007 n-10
Debugger022 Sep 27, 2023
2be108d
fix: ven-2007 l-08
Debugger022 Sep 27, 2023
35dc0a1
fix: ven-2007 l-05
Debugger022 Sep 27, 2023
4025db0
fix: ven-2007 m-01
Debugger022 Sep 27, 2023
939da0a
fix: ven-2007 m-02
Debugger022 Sep 27, 2023
a842667
fix: ven-2007 l-03
Debugger022 Sep 27, 2023
7c18feb
fix: minor fixes
Debugger022 Sep 28, 2023
39eea6f
refactor: used unchecked for variables and added netspec for events
Debugger022 Oct 3, 2023
08bacb3
fix: ven-2007 n-07
Debugger022 Oct 3, 2023
9c2d122
Merge pull request #24 from VenusProtocol/VEN-2007
Debugger022 Oct 3, 2023
e5ad0df
fix: resolved conflicts
Debugger022 Oct 4, 2023
a71fe6f
fix: ATC-05
Debugger022 Oct 11, 2023
ecc0c21
fix: VPB-04
Debugger022 Oct 11, 2023
2848374
fix: VPB-05
Debugger022 Oct 11, 2023
20cd1b1
fix: VPB-12
Debugger022 Oct 11, 2023
83e5e1b
fix: RFC-04
Debugger022 Oct 11, 2023
42e67b7
fix: RFV-06
Debugger022 Oct 11, 2023
17a377c
fix: VPB-03
Debugger022 Oct 11, 2023
f76345d
fix: ATC-01
Debugger022 Oct 11, 2023
9f579b1
fix: TCV-01
Debugger022 Oct 11, 2023
06914bd
fix: RFC-02
Debugger022 Oct 11, 2023
df2eeb4
fix: VPB-10
Debugger022 Oct 11, 2023
e991342
fix: VPB-14
Debugger022 Oct 12, 2023
ade9bda
fix: VPB-01
Debugger022 Oct 12, 2023
cf5e371
fix: RFV-03
Debugger022 Oct 12, 2023
e37341c
fix: ATC-04
Debugger022 Oct 12, 2023
b04357d
fix: VPB-06
Debugger022 Oct 16, 2023
1c558e8
fix: ATC-04
Debugger022 Oct 16, 2023
9145119
fix: VPB-09
Debugger022 Oct 16, 2023
dc70688
fix: pr comments
Debugger022 Oct 16, 2023
6205aac
refactor: updated deployment script for riskFundConverter
Debugger022 Oct 16, 2023
a5caf65
fix: ATC-03
Debugger022 Oct 18, 2023
b8e3e7b
fix: VPB-13
Debugger022 Oct 18, 2023
91402dc
refactor: VEN-2064
Debugger022 Oct 18, 2023
7f289d0
refactor: added some checks for the non supporting fee tokens
Debugger022 Oct 20, 2023
df13780
refactor: updated function names and getters for token amount to not …
Debugger022 Oct 23, 2023
98779f0
refactor: updated deployment script to add poolLiquidStakedBNB
Debugger022 Oct 23, 2023
bcf659b
chore: updated natspec comments for AbstractTokenConverter
Debugger022 Oct 25, 2023
188562d
feat: added ConverterNetwork contract and tests
Debugger022 Oct 26, 2023
268a107
feat: added private conversion functionality
Debugger022 Oct 26, 2023
fa43b9a
refactor: added checks for private conversion
Debugger022 Oct 27, 2023
e139c4b
refactor: added or updated some checks for the token converter
Debugger022 Oct 27, 2023
2d3c3f8
tests: added integration tests for converter and converterNetwork
Debugger022 Oct 27, 2023
108897b
tests: added tests for checks in token converter
Debugger022 Oct 30, 2023
7458733
fixup: VPB-03
Debugger022 Oct 31, 2023
b483870
fixup: VPB-06
Debugger022 Oct 31, 2023
d0c5d17
fixup: VPU-01
Debugger022 Oct 31, 2023
f2021e5
fixup: ATC-06
Debugger022 Oct 31, 2023
24aa165
tests: added ut for private conversions
Debugger022 Nov 1, 2023
cd353bd
fix: resolved merge conflicts
Debugger022 Nov 1, 2023
edd7361
fixup: undo ATC-06
Debugger022 Nov 1, 2023
3e60089
fix: resolve comments
Debugger022 Nov 1, 2023
5e6aa8b
fix: merge conflicts
Debugger022 Nov 2, 2023
176a6f5
fix: pr comments
Debugger022 Nov 2, 2023
921b5d8
refactor: added states for conversion accessibility
Debugger022 Nov 5, 2023
3aebab5
Merge pull request #29 from VenusProtocol/VEN-2043
Debugger022 Nov 6, 2023
23d4e99
fix: pr comments
Debugger022 Nov 6, 2023
f8a8179
fix: TCP-04
Debugger022 Nov 9, 2023
cdd9e14
fix: TCP-05
Debugger022 Nov 9, 2023
11352cd
fix: ATT-02
Debugger022 Nov 9, 2023
abe7ead
fix: ATT-01
Debugger022 Nov 9, 2023
f52d56a
fix: CNC-02
Debugger022 Nov 9, 2023
2ba7503
fix: CNC-04
chechu Nov 20, 2023
73bc544
fix: TCP-06
Debugger022 Nov 21, 2023
f4c8d1e
fix: TCP-03
Debugger022 Nov 21, 2023
72e1b37
fix: add reentrancy guard to getPoolAssetReserve function
Debugger022 Nov 22, 2023
8467d36
Merge pull request #38 from VenusProtocol/VEN-2140
Debugger022 Nov 22, 2023
3a6c78e
refactor: gas optimizations
Debugger022 Nov 23, 2023
c8588a0
fix: ATT-02
Debugger022 Nov 23, 2023
8b8c5a1
tests: added tests for quicksort
Debugger022 Nov 24, 2023
dd07dae
Merge pull request #40 from VenusProtocol/fix/VEN-2140
chechu Nov 27, 2023
23662c0
fix: resolved merge conflicts
Debugger022 Nov 29, 2023
b9c63a8
Merge branch 'develop' into feat/passive-swap
Debugger022 Nov 29, 2023
b176ddb
fix: pr comments
Debugger022 Dec 4, 2023
8d8f8c7
fix: pr comments
Debugger022 Dec 4, 2023
9a915e7
Merge branch 'develop' into feat/passive-swap
Debugger022 Dec 4, 2023
4d93597
Merge branch 'feat/passive-swap' into feat/private-conversions
Debugger022 Dec 5, 2023
5088e0f
fix: convertForExactTokens bug regarding deflationary token
Debugger022 Dec 5, 2023
e6578b3
test: added commented tests for convertForExactTokensSupportingFeeOnT…
Debugger022 Dec 5, 2023
d550be6
Merge branch 'feat/passive-swap' into feat/private-conversions
Debugger022 Dec 5, 2023
1af57c2
fix: N-01
Debugger022 Dec 6, 2023
b1244b3
fix: N-02
Debugger022 Dec 6, 2023
9994f12
fix: N-03
Debugger022 Dec 6, 2023
a265d02
fix: N-07
Debugger022 Dec 7, 2023
af3d4fc
fix: N-04
Debugger022 Dec 7, 2023
ae9e07b
fix: N-05
Debugger022 Dec 7, 2023
84cbf18
fix: N-06
Debugger022 Dec 7, 2023
52eb722
fix: L-01
Debugger022 Dec 7, 2023
6b6e9e4
fix: L-02
Debugger022 Dec 7, 2023
6bd7f9a
fix: L-03
Debugger022 Dec 7, 2023
f7dd3a2
refactor: remove immutability from baseAsset
Debugger022 Dec 7, 2023
f3e40c3
fix: L-04
Debugger022 Dec 7, 2023
166d40b
fix: minor fixes
Debugger022 Dec 7, 2023
554d804
fix: pr comments
Debugger022 Dec 7, 2023
6286a0a
feat: add deployment scripts for converters, ConverterNetwork and XVS…
Debugger022 Dec 8, 2023
baf6dfb
feat: add conversion config method for setting configs in batch
Debugger022 Dec 11, 2023
8ef869a
fix: pr comments
Debugger022 Dec 13, 2023
66d11be
Merge branch 'develop' into feat/passive-swap
Debugger022 Dec 13, 2023
136714d
Merge branch 'feat/passive-swap' into feat/private-conversions
Debugger022 Dec 13, 2023
1b16c45
Merge branch 'feat/private-conversions' into VEN-2226
Debugger022 Dec 13, 2023
511c89d
refactor: variable name in singleTokenConverter deployment script and…
Debugger022 Dec 13, 2023
fc27510
Merge pull request #48 from VenusProtocol/VEN-2226
Debugger022 Dec 18, 2023
27569a3
Merge pull request #35 from VenusProtocol/feat/private-conversions
Debugger022 Dec 18, 2023
34ca45a
feat: updating deployment files
Debugger022 Dec 18, 2023
5468dc9
fix: deployment scripts and updated deployment files
Debugger022 Dec 19, 2023
13813be
feat: updating deployment files
Debugger022 Dec 19, 2023
22a231a
fix: N-05
Debugger022 Dec 22, 2023
605f5b6
refactor: replace conditional check with ensureNonzeroAddress function
Debugger022 Dec 22, 2023
2339328
fix: pr comments
Debugger022 Jan 9, 2024
7b31bf4
Merge branch 'develop' into feat/passive-swap
Debugger022 Jan 9, 2024
2ba62d3
refactor: deployment scripts to be compatible for non-live networks
Debugger022 Jan 9, 2024
781890c
refactor: replace local file validators with solidity-utilities function
Debugger022 Jan 10, 2024
343dd16
Merge pull request #52 from VenusProtocol/fix/oz-audit-private-conver…
Debugger022 Jan 10, 2024
2abea71
feat: add deployment files for bsc mainnet
Debugger022 Jan 11, 2024
45481a3
feat: updating deployment files
Debugger022 Jan 11, 2024
bbb9661
refactor: updated addresses in deployment files for bsc testnet
Debugger022 Jan 11, 2024
7f148a9
feat: updating deployment files
Debugger022 Jan 11, 2024
72ebb08
refactor: add comment in hardhat config about preventing deployment e…
Debugger022 Jan 12, 2024
768a392
feat: sweep token for pools
Debugger022 Jan 22, 2024
f31dc8b
docs: add audit reports for token converter and private conversions
chechu Jan 22, 2024
f11b8e9
fixup! : update method name SweepTokenToPool to SweepTokenFromPool
Debugger022 Jan 23, 2024
6be027e
fixup! : riskFundV2 natspec
Debugger022 Jan 24, 2024
7bd2a5e
Merge pull request #58 from VenusProtocol/refactor/sweep-token
Debugger022 Jan 24, 2024
e5b95c4
Merge branch 'develop' into feat/passive-swap
Debugger022 Jan 24, 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
Prev Previous commit
Next Next commit
fix: ven-2007 l-03
  • Loading branch information
Debugger022 committed Sep 27, 2023
commit a8426677df622b6c59b62196eecf8d168f0ff2f8
2 changes: 2 additions & 0 deletions contracts/Interfaces/IRiskFundConverter.sol
Original file line number Diff line number Diff line change
@@ -3,4 +3,6 @@ pragma solidity 0.8.13;

interface IRiskFundConverter {
function updateAssetsState(address comptroller, address asset) external;

function getPools(address asset) external view returns (address[] memory);
}
67 changes: 52 additions & 15 deletions contracts/ProtocolReserve/RiskFundV2.sol
Debugger022 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -6,7 +6,11 @@ import { AccessControlledV8 } from "@venusprotocol/governance-contracts/contract
import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";

import { IRiskFund } from "../Interfaces/IRiskFund.sol";
import { IRiskFundConverter } from "../Interfaces/IRiskFundConverter.sol";

import { ensureNonzeroAddress } from "../Utils/Validators.sol";
import { EXP_SCALE } from "../Utils/Constants.sol";

import { RiskFundV2Storage } from "./RiskFundStorage.sol";

/// @title RiskFundV2
@@ -32,7 +36,7 @@ contract RiskFundV2 is AccessControlledV8, RiskFundV2Storage, IRiskFund {
event PoolStateUpdated(address indexed comptroller, address indexed asset, uint256 amount);

/// @notice Event emitted when tokens are swept
event SweepToken(address indexed comptroller, address indexed asset, uint256 amount);
event SweepToken(address indexed asset);

/// @notice Error is thrown when updatePoolState is not called by riskFundConverter
error InvalidRiskFundConverter();
@@ -104,26 +108,21 @@ contract RiskFundV2 is AccessControlledV8, RiskFundV2Storage, IRiskFund {
}

/// @notice Function to sweep baseAsset for pool, Tokens are sent to admin (timelock)
/// @param comptroller The address of the pool for the amount need to be sweeped
/// @param asset Address of the asset(token)
/// @param tokenAddress Address of the asset(token)
/// @param to Address to which assets will be transferred
/// @param amount Amount need to sweep for the pool
/// @custom:event Emits SweepToken event on success
/// @custom:error ZeroAddressNotAllowed is thrown when tokenAddress/to address is zero
kkirka marked this conversation as resolved.
Show resolved Hide resolved
/// @custom:error InsufficientPoolReserve is thrown when pool reserve is less than the amount needed
/// @custom:access Only Governance
function sweepToken(address comptroller, address asset, uint256 amount) external onlyOwner nonReentrant {
ensureNonzeroAddress(comptroller);
function sweepToken(address tokenAddress, address to, uint256 amount) external onlyOwner nonReentrant {
ensureNonzeroAddress(tokenAddress);
ensureNonzeroAddress(to);

uint256 poolReserve = poolAssetsFunds[comptroller][asset];
if (amount > poolReserve) {
revert InsufficientPoolReserve(comptroller, amount, poolReserve);
}
poolAssetsFunds[comptroller][asset] = poolReserve - amount;
IERC20Upgradeable token = IERC20Upgradeable(tokenAddress);
postSweepToken(tokenAddress, amount);
token.safeTransfer(to, amount);

IERC20Upgradeable token = IERC20Upgradeable(asset);
token.safeTransfer(owner(), amount);

emit SweepToken(comptroller, asset, amount);
emit SweepToken(tokenAddress);
}

/// @dev Update the reserve of the asset for the specific pool after transferring to risk fund
@@ -138,4 +137,42 @@ contract RiskFundV2 is AccessControlledV8, RiskFundV2Storage, IRiskFund {
poolAssetsFunds[comptroller][asset] += amount;
emit PoolStateUpdated(comptroller, asset, amount);
}

/// @notice Operations to perform after sweepToken
/// @param tokenAddress Address of the token
/// @param amount Amount transferred to address(to)
function postSweepToken(address tokenAddress, uint256 amount) internal {
uint256 balance = IERC20Upgradeable(tokenAddress).balanceOf(address(this));
require(balance >= amount, "Insufficient Balance");

address[] memory pools = IRiskFundConverter(riskFundConverter).getPools(tokenAddress);

uint256 assetReserves;
uint256 poolsLength = pools.length;
for (uint256 i; i < poolsLength; ++i) {
assetReserves += poolAssetsFunds[pools[i]][tokenAddress];
}

uint256 balanceDiff = balance - assetReserves;

if (balanceDiff < amount) {
uint256 amountDiff = amount - balanceDiff;
for (uint256 i; i < poolsLength; ++i) {
uint256 poolShare = (poolAssetsFunds[pools[i]][tokenAddress] * EXP_SCALE) / assetReserves;
if (poolShare == 0) continue;
updatePoolAssetsReserve(pools[i], tokenAddress, amountDiff, poolShare);
}
}
}

/// @notice Update the poolAssetsReserves upon transferring the tokens
/// @param pool Address of the pool
/// @param tokenAddress Address of the token
/// @param amount Amount transferred to address(to)
/// @param poolShare share for corresponding pool
function updatePoolAssetsReserve(address pool, address tokenAddress, uint256 amount, uint256 poolShare) internal {
uint256 poolAmountShare = (poolShare * amount) / EXP_SCALE;
poolAssetsFunds[pool][tokenAddress] -= poolAmountShare;
emit PoolStateUpdated(pool, tokenAddress, poolAmountShare);
}
}
38 changes: 19 additions & 19 deletions contracts/TokenConverter/RiskFundConverter.sol
Original file line number Diff line number Diff line change
@@ -197,6 +197,25 @@ contract RiskFundConverter is AbstractTokenConverter {
return assetsReserves[tokenAddress];
}

/// @notice Get the array of all pools addresses
/// @param tokenAddress Address of the token
function getPools(address tokenAddress) public view returns (address[] memory) {
address[] memory pools = IPoolRegistry(poolRegistry).getPoolsSupportedByAsset(tokenAddress);

if (isAssetListedInCore(tokenAddress)) {
uint256 poolsLength = pools.length;
address[] memory poolsWithCore = new address[](poolsLength + 1);

for (uint256 i; i < poolsLength; ++i) {
poolsWithCore[i] = pools[i];
}
poolsWithCore[poolsLength] = CORE_POOL_COMPTROLLER;
return poolsWithCore;
}

return pools;
}

/// @notice Hook to perform after converting tokens
/// @dev After transformation poolsAssetsReserves are settled by pool's reserves fraction
/// @param tokenInAddress Address of the tokenIn
@@ -255,25 +274,6 @@ contract RiskFundConverter is AbstractTokenConverter {
emit AssetsReservesUpdated(pool, tokenAddress, poolAmountShare);
}

/// @notice Get the array of all pools addresses
/// @param tokenAddress Address of the token
function getPools(address tokenAddress) internal view returns (address[] memory) {
address[] memory pools = IPoolRegistry(poolRegistry).getPoolsSupportedByAsset(tokenAddress);

if (isAssetListedInCore(tokenAddress)) {
uint256 poolsLength = pools.length;
address[] memory poolsWithCore = new address[](poolsLength + 1);

for (uint256 i; i < poolsLength; ++i) {
poolsWithCore[i] = pools[i];
}
poolsWithCore[poolsLength] = CORE_POOL_COMPTROLLER;
return poolsWithCore;
}

return pools;
}

function isAssetListedInCore(address tokenAddress) internal view returns (bool isAssetListed) {
kkirka marked this conversation as resolved.
Show resolved Hide resolved
address[] memory coreMarkets = IComptroller(CORE_POOL_COMPTROLLER).getAllMarkets();

30 changes: 24 additions & 6 deletions tests/ProtocolReserve/RiskFundV2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FakeContract, MockContract, smock } from "@defi-wonderland/smock";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { impersonateAccount, loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { expect } from "chai";
import { Signer, constants } from "ethers";
import { parseUnits } from "ethers/lib/utils.js";
@@ -172,15 +172,33 @@ describe("Risk Fund: Tests", function () {
});

describe("SweepTokens", () => {
it("Transfer sweep tokens to owner", async () => {
let riskFundConverterSigner: Signer;
const COMPTROLLER_A_AMOUNT: string = convertToUnit(10, 18);

beforeEach(async () => {
await riskFund.connect(admin).setConvertibleBaseAsset(tokenA.address);
const COMPTROLLER_A_AMOUNT = convertToUnit(10, 18);

await tokenA.transfer(riskFund.address, COMPTROLLER_A_AMOUNT);
await riskFund.setVariable("riskFundConverter", await admin.getAddress());
await riskFund.connect(admin).updatePoolState(comptrollerA.address, tokenA.address, COMPTROLLER_A_AMOUNT);
});

it("Transfer sweep tokens to (to) address", async () => {
await impersonateAccount(riskFundConverter.address);
riskFundConverterSigner = await ethers.getSigner(riskFundConverter.address);
await admin.sendTransaction({ to: riskFundConverter.address, value: ethers.utils.parseEther("10") });

await riskFund
.connect(riskFundConverterSigner)
.updatePoolState(comptrollerA.address, tokenA.address, COMPTROLLER_A_AMOUNT);

await expect(riskFund.sweepToken(tokenA.address, await admin.getAddress(), 1000)).to.changeTokenBalances(
tokenA,
[await riskFund.owner(), riskFund.address],
[1000, -1000],
);
});

await expect(riskFund.sweepToken(comptrollerA.address, tokenA.address, 1000)).to.changeTokenBalances(
it("Transfer untracked token to (to) address", async () => {
await expect(riskFund.sweepToken(tokenA.address, await admin.getAddress(), 1000)).to.changeTokenBalances(
tokenA,
[await riskFund.owner(), riskFund.address],
[1000, -1000],