Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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 src/contracts/AssetLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {SharesMath} from 'src/contracts/SharesMath.sol';
import {PercentageMath} from 'src/contracts/PercentageMath.sol';
import {WadRayMath} from 'src/contracts/WadRayMath.sol';

import 'forge-std/console2.sol';
Comment thread
yan-man marked this conversation as resolved.
Outdated

library AssetLogic {
using AssetLogic for Asset;
using PercentageMath for uint256;
Expand Down
12 changes: 7 additions & 5 deletions src/contracts/LiquidityHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {SharesMath} from 'src/contracts/SharesMath.sol';
import {MathUtils} from 'src/contracts/MathUtils.sol';
import {PercentageMath} from 'src/contracts/PercentageMath.sol';

import 'forge-std/console2.sol';
Comment thread
yan-man marked this conversation as resolved.
Outdated

struct SpokeData {
uint256 suppliedShares; // share
uint256 baseDebt; // asset
Expand Down Expand Up @@ -172,12 +174,11 @@ contract LiquidityHub is ILiquidityHub {
baseDebtChange: 0
});

asset.availableLiquidity += amount;

// todo: Mitigate inflation attack (burn some amount if first supply)
uint256 sharesAmount = asset.convertToSharesDown(amount);
require(sharesAmount > 0, 'INVALID_AMOUNT');
require(sharesAmount > 0, 'INVALID_SHARES_AMOUNT');

asset.availableLiquidity += amount;
Comment thread
yan-man marked this conversation as resolved.
asset.suppliedShares += sharesAmount;
spoke.suppliedShares += sharesAmount; // todo: mint 4626 shares to abstract this accounting

Expand Down Expand Up @@ -333,6 +334,7 @@ contract LiquidityHub is ILiquidityHub {
SpokeData storage spoke,
uint256 amount
) internal view {
require(amount > 0, 'INVALID_AMOUNT');
require(assetsList[asset.id] != IERC20(address(0)), 'ASSET_NOT_LISTED');
// TODO: Different states e.g. frozen, paused
require(asset.config.active, 'ASSET_NOT_ACTIVE');
Expand Down Expand Up @@ -413,8 +415,8 @@ contract LiquidityHub is ILiquidityHub {

uint256 newSpokeDebt = baseDebtChange > 0
? existingSpokeDebt + uint256(baseDebtChange) // debt added
// force underflow: only possible when spoke takes repays amount more than net drawn
: existingSpokeDebt - uint256(-baseDebtChange); // debt restored
: // force underflow: only possible when spoke takes repays amount more than net drawn
existingSpokeDebt - uint256(-baseDebtChange); // debt restored

(uint256 newAssetRiskPremium, uint256 newAssetDebt) = MathUtils.addToWeightedAverage(
assetRiskPremiumWithoutCurrent,
Expand Down
1 change: 1 addition & 0 deletions tests/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ library TestErrors {
bytes constant INVALID_SPOKE = 'INVALID_SPOKE';
bytes constant RESERVE_NOT_COLLATERAL = 'RESERVE_NOT_COLLATERAL';
bytes constant INVALID_RESTORE_AMOUNT = 'INVALID_RESTORE_AMOUNT';
bytes constant INVALID_SHARES_AMOUNT = 'INVALID_SHARES_AMOUNT';
// Spoke
bytes constant NO_SUPPLY = 'NO_SUPPLY';
bytes constant REPAY_EXCEEDS_DEBT = 'REPAY_EXCEEDS_DEBT';
Expand Down
6 changes: 5 additions & 1 deletion tests/Utils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {Vm} from 'forge-std/Vm.sol';
import {LiquidityHub, DataTypes} from 'src/contracts/LiquidityHub.sol';
import {Spoke, ISpoke} from 'src/contracts/Spoke.sol';

import 'forge-std/console2.sol';

library Utils {
// hub
function addAssetAndSpokes(
Expand Down Expand Up @@ -32,8 +34,10 @@ library Utils {
address user,
address onBehalfOf
) internal {
vm.prank(user);
vm.startPrank(user);
Comment thread
DhairyaSethi marked this conversation as resolved.
hub.assetsList(assetId).approve(address(hub), amount);
vm.stopPrank();

vm.startPrank(spoke);
hub.supply({assetId: assetId, amount: amount, riskPremium: 0, supplier: user});
vm.stopPrank();
Expand Down
Loading