Skip to content

Commit

Permalink
feat: update pool collateral configuration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickk137 committed Aug 15, 2023
1 parent 14f0ca8 commit 7f36cf0
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 67 deletions.
22 changes: 12 additions & 10 deletions protocol/synthetix/contracts/interfaces/IPoolModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ interface IPoolModule {
PoolCollateralConfiguration.Data memory newConfig
) external;

/**
* @notice Allows collaterals accepeted by the system will be accpeted by the pool by default
* @param poolId The id of the pool.
*/
function enablePoolCollateralByDefault(uint128 poolId) external;

/**
* @notice Prevents collaterals accepeted by the system will not be accpeted by the pool by default
* @param poolId The id of the pool.
*/
function disablePoolCollateralByDefault(uint128 poolId) external;

/**
* @notice Retrieves the MarketConfiguration of the specified pool.
* @param poolId The id of the pool whose configuration is being queried.
Expand Down Expand Up @@ -186,16 +198,6 @@ interface IPoolModule {
*/
function setMinLiquidityRatio(uint256 minLiquidityRatio) external;

/**
@notice Shows if a given collateral type is enabled for deposits and delegation in a given pool.
* @param poolId The id of the pool for to check the collateral for.
* @param collateral The address of the collateral.
*/
function isDelegationEnabledByPool(
uint128 poolId,
address collateral
) external view returns (bool enabled);

/**
@notice returns a pool minimum issuance ratio
* @param poolId The id of the pool for to check the collateral for.
Expand Down
29 changes: 18 additions & 11 deletions protocol/synthetix/contracts/modules/core/PoolModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ contract PoolModule is IPoolModule {
emit PoolConfigurationSet(poolId, newMarketConfigurations, msg.sender);
}

/**
* @inheritdoc IPoolModule
*/
function disablePoolCollateralByDefault(uint128 poolId) external override {
Pool.Data storage pool = Pool.loadExisting(poolId);

pool.collateralDisabledByDefault = true;
}

/**
* @inheritdoc IPoolModule
*/
function enablePoolCollateralByDefault(uint128 poolId) external override {
Pool.Data storage pool = Pool.loadExisting(poolId);

pool.collateralDisabledByDefault = false;
}

/**
* @inheritdoc IPoolModule
*/
Expand Down Expand Up @@ -228,17 +246,6 @@ contract PoolModule is IPoolModule {
emit PoolNameUpdated(poolId, name, msg.sender);
}

/**
* @inheritdoc IPoolModule
*/
function isDelegationEnabledByPool(
uint128 poolId,
address collateral
) external view override returns (bool) {
return
!Pool.loadExisting(poolId).collateralConfigurations[collateral].collateralTypeDisabled;
}

/**
* @inheritdoc IPoolModule
*/
Expand Down
3 changes: 0 additions & 3 deletions protocol/synthetix/contracts/modules/core/VaultModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ contract VaultModule is IVaultModule {
// Check if the collateral is enabled here because we still want to allow reducing delegation for disabled collaterals.
CollateralConfiguration.collateralEnabled(collateralType);

// Check if delegation is enabled for the pool
Pool.load(poolId).checkDelegationEnabled(collateralType);

Account.requireSufficientCollateral(
accountId,
collateralType,
Expand Down
28 changes: 11 additions & 17 deletions protocol/synthetix/contracts/storage/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ library Pool {
uint256 maxCollateral
);

/**
* @notice Thrown when attempting delegate a pool disabled collateral
*/
error PoolCollateralIsDisabled(address collateral, uint128 poolId);

bytes32 private constant _CONFIG_SET_MARKET_MIN_DELEGATE_MAX = "setMarketMinDelegateTime_max";

struct Data {
Expand Down Expand Up @@ -131,6 +126,14 @@ library Pool {
uint64 __reserved2;
uint64 __reserved3;
mapping(address => PoolCollateralConfiguration.Data) collateralConfigurations;
/**
* @dev A switch to make the pool opt-in for new collateral
*
* By default it's set to false, which means any new collateral accepeted by the system will be accpeted by the pool.
*
* If the pool owner sets this value to true, then new collaterals will be disabled for the pool unless a maxDeposit is set for a that collateral.
*/
bool collateralDisabledByDefault;
}

/**
Expand Down Expand Up @@ -534,8 +537,9 @@ library Pool {
uint256 maxDeposit = self.collateralConfigurations[collateralType].maxDepositD18;

if (
maxDeposit > 0 &&
self.vaults[collateralType].currentCollateral() + collateralAmountD18 > maxDeposit
(self.collateralDisabledByDefault && maxDeposit == 0) ||
(maxDeposit > 0 &&
self.vaults[collateralType].currentCollateral() + collateralAmountD18 > maxDeposit)
) {
revert PoolCollateralLimitExceeded(
self.id,
Expand All @@ -545,14 +549,4 @@ library Pool {
);
}
}

/**
* @notice Shows if a given collateral type is enabled for deposits and delegation in given pool.
* @param collateralType The address of the collateral.
*/
function checkDelegationEnabled(Data storage self, address collateralType) internal view {
if (self.collateralConfigurations[collateralType].collateralTypeDisabled) {
revert PoolCollateralIsDisabled(collateralType, self.id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ library PoolCollateralConfiguration {

struct Data {
uint256 maxDepositD18;
bool collateralTypeDisabled;
uint256 issuanceRatioD18;
}
}
1 change: 0 additions & 1 deletion protocol/synthetix/test/integration/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export function bootstrapWithMockMarketAndPool() {
.Core.connect(owner)
.setPoolCollateralConfiguration(r.poolId, r.collateralAddress(), {
maxDepositD18: bn(1000000000),
collateralTypeDisabled: false,
issuanceRatioD18: bn(1),
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ describe('IssueUSDModule', function () {
await systems()
.Core.connect(owner)
.setPoolCollateralConfiguration(poolId, collateralAddress(), {
collateralTypeDisabled: false,
maxDepositD18: bn(10),
issuanceRatioD18: bn(6),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,37 +714,21 @@ describe('PoolModule Admin', function () {
.Core.connect(user2)
.setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), {
maxDepositD18: bn(10),
collateralTypeDisabled: false,
issuanceRatioD18: bn(0),
}),
`Unauthorized("${await user2.getAddress()}")`,
systems().Core
);
});

it('collateral is enabled by default for the pool', async () => {
await assert.equal(
await systems().Core.isDelegationEnabledByPool(thirdPoolId, collateralAddress()),
true
);
});

it('disable the collateral by pool owner', async () => {
await systems()
.Core.connect(user1)
.setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), {
maxDepositD18: bn(10),
collateralTypeDisabled: true,
issuanceRatioD18: bn(2),
});
});

it('collateral is disabled for the pool', async () => {
await assert.equal(
await systems().Core.isDelegationEnabledByPool(thirdPoolId, collateralAddress()),
false
);
});
});

describe('set pool collateral issuance ratio', async () => {
Expand Down Expand Up @@ -773,7 +757,6 @@ describe('PoolModule Admin', function () {
.Core.connect(user2)
.setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), {
maxDepositD18: bn(10),
collateralTypeDisabled: false,
issuanceRatioD18: bn(2),
}),
`Unauthorized("${await user2.getAddress()}")`,
Expand All @@ -793,7 +776,6 @@ describe('PoolModule Admin', function () {
.Core.connect(user1)
.setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), {
maxDepositD18: bn(10),
collateralTypeDisabled: false,
issuanceRatioD18: bn(2),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ describe('VaultModule', function () {
.Core.connect(user1)
.setPoolCollateralConfiguration(fakeVaultId, collateralAddress(), {
maxDepositD18: bn(10),
collateralTypeDisabled: true,
issuanceRatioD18: bn(0),
});
});
Expand All @@ -357,7 +356,9 @@ describe('VaultModule', function () {
depositAmount.div(50),
ethers.utils.parseEther('1')
),
`PoolCollateralIsDisabled("${collateralAddress()}", "${fakeVaultId}")`,
`PoolCollateralLimitExceeded("${fakeVaultId}", "${collateralAddress()}", "${depositAmount
.div(50)
.toString()}", "${bn(10).toString()}")`,
systems().Core
);
});
Expand All @@ -367,7 +368,6 @@ describe('VaultModule', function () {
.Core.connect(user1)
.setPoolCollateralConfiguration(fakeVaultId, collateralAddress(), {
maxDepositD18: bn(1000000),
collateralTypeDisabled: false,
issuanceRatioD18: bn(0),
});
});
Expand All @@ -391,7 +391,6 @@ describe('VaultModule', function () {
.Core.connect(owner)
.setPoolCollateralConfiguration(poolId, collateralAddress(), {
maxDepositD18: depositAmount.div(2),
collateralTypeDisabled: false,
issuanceRatioD18: bn(0),
});
});
Expand Down Expand Up @@ -454,7 +453,6 @@ describe('VaultModule', function () {
.Core.connect(owner)
.setPoolCollateralConfiguration(poolId, collateralAddress(), {
maxDepositD18: depositAmount.mul(10),
collateralTypeDisabled: false,
issuanceRatioD18: bn(0),
});
});
Expand Down

0 comments on commit 7f36cf0

Please sign in to comment.