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

Sip 366 implementation #2145

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2209136
wip sip366
leomassazza May 8, 2024
45dfd41
wip 366
leomassazza May 9, 2024
cebc9c4
wip 366 start fixing tests
leomassazza May 9, 2024
f41d109
fix, wrong params for pair
leomassazza May 9, 2024
e3ab470
wip: add per collateral accounting
leomassazza May 13, 2024
18de031
Test MarketManagerModule
leomassazza May 13, 2024
de561f0
Fix LiquidationModule test
leomassazza May 13, 2024
1f49264
wip: fix tests
leomassazza May 13, 2024
5a28067
checkpoint: fixing vault module test (wip)
leomassazza May 13, 2024
13a5120
checkpoint: use delta for intent declarations
leomassazza May 13, 2024
b2cb01c
checkpoint: added some events
leomassazza May 13, 2024
7280c58
Link to liquidation
leomassazza May 13, 2024
64030e3
checkpoint: more tests fixed and bugs smashed
leomassazza May 14, 2024
3f68d81
Fix tests
leomassazza May 15, 2024
c60b1c4
fix other project tests
leomassazza May 16, 2024
6ae5345
fix another tests on bfp
leomassazza May 16, 2024
8289f11
Only owner can delete all intents
leomassazza May 17, 2024
c6b5332
Make window time flexible with configuration changes
leomassazza May 20, 2024
55cf924
wip: timing tests
leomassazza May 20, 2024
383d27e
test edge cases
leomassazza May 20, 2024
18a4308
Reduce AccountDelegationIntents footprint
leomassazza May 21, 2024
a47d06c
Cleanup and comments
leomassazza May 21, 2024
12db077
update storage.dump
leomassazza May 22, 2024
1027f7f
add skipped test - multiple markets with diff timing
leomassazza May 22, 2024
3a4ac69
deps fix
leomassazza May 22, 2024
ed9d256
undo deps fix
leomassazza May 22, 2024
fc9cf62
Merge branch 'SIP-366-implementation' of https://github.com/Synthetix…
leomassazza May 22, 2024
f0531e2
fix deps
leomassazza May 22, 2024
d03d3ca
typos + remove account owner check on delete expired intents
leomassazza May 22, 2024
0cf5549
PR review fixes (partial)
leomassazza May 27, 2024
6c54a5d
fix: ensure intentId to process is still valid for the account (not r…
leomassazza May 27, 2024
3c9f5be
fix pair using wrong key
leomassazza May 27, 2024
50b6b61
fix tests
leomassazza May 27, 2024
f62dad5
propagate storage change
leomassazza May 27, 2024
901f542
rename function (wip)
leomassazza May 27, 2024
30953ee
add two new views
leomassazza May 28, 2024
05cd81f
some fixes
leomassazza May 30, 2024
2e5ddcd
add views test + small fix
leomassazza Jun 4, 2024
9e836d5
PR Fixes -> SIP 366 (#2171)
leomassazza Jun 26, 2024
cb02ac7
Merge branch 'main' into SIP-366-implementation
leomassazza Jun 26, 2024
4061dec
fix bfp tests
leomassazza Jun 26, 2024
f9ba8da
more fixes on bfp (roll back changes)
leomassazza Jun 26, 2024
cc0bd12
add missing empty line
leomassazza Jun 27, 2024
62de774
add more info to view
leomassazza Jun 27, 2024
9a44955
fix wrong sign + a small refactor
leomassazza Jun 27, 2024
6272a49
fix test
leomassazza Jun 27, 2024
ac3ad55
rename FFs
leomassazza Jul 1, 2024
c11d354
fix tests
leomassazza Jul 1, 2024
c4fa5d3
Merge branch 'main' into SIP-366-implementation
leomassazza Jul 2, 2024
0a2d08e
push storage dump
leomassazza Jul 3, 2024
b190bfc
Merge branch 'main' into SIP-366-implementation
leomassazza Jul 15, 2024
dde2c7d
Merge branch 'main' into SIP-366-implementation
leomassazza Jul 18, 2024
4ff64db
Reduce delegationIntent footprint
leomassazza Jul 19, 2024
cd8a7f9
fix missing references to intent.id
leomassazza Jul 19, 2024
eb05eba
Merge branch 'main' into SIP-366-implementation
leomassazza Jul 27, 2024
1f46654
Merge branch 'main' into SIP-366-implementation
leomassazza Aug 13, 2024
f960f81
fix test
leomassazza Aug 13, 2024
712921c
Merge branch 'main' into SIP-366-implementation
leomassazza Aug 27, 2024
dcb9ea4
Merge branch 'main' into SIP-366-implementation
leomassazza Aug 30, 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
Link to liquidation
  • Loading branch information
leomassazza committed May 13, 2024
commit 7280c5802e2fb4eaad4eac6b36cb0855b8380d75
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import "@synthetixio/core-contracts/contracts/utils/ERC2771Context.sol";

import "@synthetixio/core-modules/contracts/storage/FeatureFlag.sol";

import "../../storage/AccountDelegationIntents.sol";

/**
* @title Module for liquidated positions and vaults that are below the liquidation ratio.
* @dev See ILiquidationModule.
Expand All @@ -33,6 +35,7 @@ contract LiquidationModule is ILiquidationModule {
using VaultEpoch for VaultEpoch.Data;
using Distribution for Distribution.Data;
using ScalableMapping for ScalableMapping.Data;
using AccountDelegationIntents for AccountDelegationIntents.Data;

bytes32 private constant _USD_TOKEN = "USDToken";

Expand Down Expand Up @@ -114,6 +117,9 @@ contract LiquidationModule is ILiquidationModule {
liquidationData.amountRewarded
);

// Clean any outstanding intents to delegate collateral
AccountDelegationIntents.getValid(accountId).cleanAllIntents();
kaleb-keny marked this conversation as resolved.
Show resolved Hide resolved

emit Liquidation(
accountId,
poolId,
Expand Down
123 changes: 0 additions & 123 deletions protocol/synthetix/contracts/modules/core/VaultModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,129 +40,6 @@ contract VaultModule is IVaultModule {

bytes32 private constant _DELEGATE_FEATURE_FLAG = "delegateCollateral";

// function delegateCollateral(
// uint128 accountId,
// uint128 poolId,
// address collateralType,
// uint256 newCollateralAmountD18,
// uint256 leverage
// ) external override {
// FeatureFlag.ensureAccessToFeature(_DELEGATE_FEATURE_FLAG);
// Account.loadAccountAndValidatePermission(accountId, AccountRBAC._DELEGATE_PERMISSION);

// // Each collateral type may specify a minimum collateral amount that can be delegated.
// // See CollateralConfiguration.minDelegationD18.
// if (newCollateralAmountD18 > 0) {
// CollateralConfiguration.requireSufficientDelegation(
// collateralType,
// newCollateralAmountD18
// );
// }

// // System only supports leverage of 1.0 for now.
// if (leverage != DecimalMath.UNIT) revert InvalidLeverage(leverage);

// // Identify the vault that corresponds to this collateral type and pool id.
// Vault.Data storage vault = Pool.loadExisting(poolId).vaults[collateralType];

// // Use account interaction to update its rewards.
// uint256 totalSharesD18 = vault.currentEpoch().accountsDebtDistribution.totalSharesD18;
// uint256 actorSharesD18 = vault.currentEpoch().accountsDebtDistribution.getActorShares(
// accountId.toBytes32()
// );

// uint256 currentCollateralAmount = vault.currentAccountCollateral(accountId);

// // Conditions for collateral amount

// // Ensure current collateral amount differs from the new collateral amount.
// if (newCollateralAmountD18 == currentCollateralAmount) revert InvalidCollateralAmount();
// // If increasing delegated collateral amount,
// // Check that the account has sufficient collateral.
// else if (newCollateralAmountD18 > currentCollateralAmount) {
// // Check if the collateral is enabled here because we still want to allow reducing delegation for disabled collaterals.
// CollateralConfiguration.collateralEnabled(collateralType);

// Account.requireSufficientCollateral(
// accountId,
// collateralType,
// newCollateralAmountD18 - currentCollateralAmount
// );

// Pool.loadExisting(poolId).checkPoolCollateralLimit(
// collateralType,
// newCollateralAmountD18 - currentCollateralAmount
// );

// // if decreasing delegation amount, ensure min time has elapsed
// } else {
// // TODO LJM
// // Pool.loadExisting(poolId).requireMinDelegationTimeElapsed(
// // vault.currentEpoch().lastDelegationTime[accountId]
// // );
// }

// // Update the account's position for the given pool and collateral type,
// // Note: This will trigger an update in the entire debt distribution chain.
// uint256 collateralPrice = _updatePosition(
// accountId,
// poolId,
// collateralType,
// newCollateralAmountD18,
// currentCollateralAmount,
// leverage
// );

// _updateAccountCollateralPools(
// accountId,
// poolId,
// collateralType,
// newCollateralAmountD18 > 0
// );

// // If decreasing the delegated collateral amount,
// // check the account's collateralization ratio.
// // Note: This is the best time to do so since the user's debt and the collateral's price have both been updated.
// if (newCollateralAmountD18 < currentCollateralAmount) {
// int256 debt = vault.currentEpoch().consolidatedDebtAmountsD18[accountId];

// uint256 minIssuanceRatioD18 = Pool
// .loadExisting(poolId)
// .collateralConfigurations[collateralType]
// .issuanceRatioD18;

// // Minimum collateralization ratios are configured in the system per collateral type.abi
// // Ensure that the account's updated position satisfies this requirement.
// CollateralConfiguration.load(collateralType).verifyIssuanceRatio(
// debt < 0 ? 0 : debt.toUint(),
// newCollateralAmountD18.mulDecimal(collateralPrice),
// minIssuanceRatioD18
// );

// // Accounts cannot reduce collateral if any of the pool's
// // connected market has its capacity locked.
// _verifyNotCapacityLocked(poolId);
// }

// // solhint-disable-next-line numcast/safe-cast
// vault.currentEpoch().lastDelegationTime[accountId] = uint64(block.timestamp);

// emit DelegationUpdated(
// accountId,
// poolId,
// collateralType,
// newCollateralAmountD18,
// leverage,
// ERC2771Context._msgSender()
// );

// vault.updateRewards(
// Vault.PositionSelector(accountId, poolId, collateralType),
// totalSharesD18,
// actorSharesD18
// );
// }

/**
* @inheritdoc IVaultModule
*/
Expand Down