Skip to content

Commit

Permalink
update Issuer and DynamicSynthRedeemer
Browse files Browse the repository at this point in the history
  • Loading branch information
barrasso committed Mar 28, 2024
1 parent f5ac62e commit 5bcb639
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
29 changes: 12 additions & 17 deletions contracts/DynamicSynthRedeemer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "./interfaces/IDynamicSynthRedeemer.sol";
import "./SafeDecimalMath.sol";

// Internal references
import "./interfaces/IERC20.sol";
import "./interfaces/IIssuer.sol";
import "./interfaces/IExchangeRates.sol";

Expand All @@ -18,32 +17,27 @@ contract DynamicSynthRedeemer is Owned, IDynamicSynthRedeemer, MixinResolver {

bytes32 public constant CONTRACT_NAME = "DynamicSynthRedeemer";

uint public discountRate;

bytes32 internal constant sUSD = "sUSD";

bytes32 private constant CONTRACT_ISSUER = "Issuer";
bytes32 private constant CONTRACT_SYNTHSUSD = "SynthsUSD";
bytes32 private constant CONTRACT_EXRATES = "ExchangeRates";

// Rate applied to chainlink price for redemptions
uint public discountRate;

constructor(address _owner, address _resolver) public Owned(_owner) MixinResolver(_resolver) {
discountRate = SafeDecimalMath.unit();
}

function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
addresses = new bytes32[](3);
addresses = new bytes32[](2);
addresses[0] = CONTRACT_ISSUER;
addresses[1] = CONTRACT_SYNTHSUSD;
addresses[2] = CONTRACT_EXRATES;
addresses[1] = CONTRACT_EXRATES;
}

function issuer() internal view returns (IIssuer) {
return IIssuer(requireAndGetAddress(CONTRACT_ISSUER));
}

function sUSD() internal view returns (IERC20) {
return IERC20(requireAndGetAddress(CONTRACT_SYNTHSUSD));
}

function exchangeRates() internal view returns (IExchangeRates) {
return IExchangeRates(requireAndGetAddress(CONTRACT_EXRATES));
}
Expand All @@ -52,10 +46,10 @@ contract DynamicSynthRedeemer is Owned, IDynamicSynthRedeemer, MixinResolver {
return discountRate;
}

function setDiscountRate(uint newRate) external onlyOwner {
require(newRate >= 0, "Invalid rate");
discountRate = newRate;
emit DiscountRateUpdated(discountRate);
function setDiscountRate(uint _newRate) external onlyOwner {
require(_newRate >= 0, "Invalid rate");
discountRate = _newRate;
emit DiscountRateUpdated(_newRate);
}

function redeemAll(IERC20[] calldata synthProxies, bytes32[] calldata currencyKeys) external {
Expand Down Expand Up @@ -84,12 +78,13 @@ contract DynamicSynthRedeemer is Owned, IDynamicSynthRedeemer, MixinResolver {
uint amountOfSynth,
bytes32 currencyKey
) internal {
// Discount rate applied to chainlink price for dynamic redemptions
uint rateToRedeem = exchangeRates().rateForCurrency(currencyKey).multiplyDecimalRound(discountRate);
require(rateToRedeem > 0, "Synth not redeemable");
require(amountOfSynth > 0, "No balance of synth to redeem");
issuer().burnForRedemption(address(synthProxy), msg.sender, amountOfSynth);
uint amountInsUSD = amountOfSynth.multiplyDecimal(rateToRedeem);
sUSD().transfer(msg.sender, amountInsUSD);
issuer().issueSynthsWithoutDebt(sUSD, msg.sender, amountInsUSD);
emit SynthRedeemed(address(synthProxy), msg.sender, amountOfSynth, amountInsUSD);
}

Expand Down
33 changes: 11 additions & 22 deletions contracts/Issuer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ contract Issuer is Owned, MixinSystemSettings, IIssuer {
bytes32 private constant CONTRACT_LIQUIDATOR = "Liquidator";
bytes32 private constant CONTRACT_LIQUIDATOR_REWARDS = "LiquidatorRewards";
bytes32 private constant CONTRACT_DEBTCACHE = "DebtCache";
bytes32 private constant CONTRACT_DYNAMICSYNTHREDEEMER = "DynamicSynthRedeemer";
bytes32 private constant CONTRACT_SYNTHREDEEMER = "SynthRedeemer";
bytes32 private constant CONTRACT_SYNTHETIXBRIDGETOOPTIMISM = "SynthetixBridgeToOptimism";
bytes32 private constant CONTRACT_SYNTHETIXBRIDGETOBASE = "SynthetixBridgeToBase";
Expand All @@ -101,7 +102,7 @@ contract Issuer is Owned, MixinSystemSettings, IIssuer {
/* ========== VIEWS ========== */
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
bytes32[] memory existingAddresses = MixinSystemSettings.resolverAddressesRequired();
bytes32[] memory newAddresses = new bytes32[](14);
bytes32[] memory newAddresses = new bytes32[](15);
newAddresses[0] = CONTRACT_SYNTHETIX;
newAddresses[1] = CONTRACT_EXCHANGER;
newAddresses[2] = CONTRACT_EXRATES;
Expand All @@ -114,8 +115,9 @@ contract Issuer is Owned, MixinSystemSettings, IIssuer {
newAddresses[9] = CONTRACT_LIQUIDATOR_REWARDS;
newAddresses[10] = CONTRACT_DEBTCACHE;
newAddresses[11] = CONTRACT_SYNTHREDEEMER;
newAddresses[12] = CONTRACT_EXT_AGGREGATOR_ISSUED_SYNTHS;
newAddresses[13] = CONTRACT_EXT_AGGREGATOR_DEBT_RATIO;
newAddresses[12] = CONTRACT_DYNAMICSYNTHREDEEMER;
newAddresses[13] = CONTRACT_EXT_AGGREGATOR_ISSUED_SYNTHS;
newAddresses[14] = CONTRACT_EXT_AGGREGATOR_DEBT_RATIO;
return combineArrays(existingAddresses, newAddresses);
}

Expand Down Expand Up @@ -649,20 +651,6 @@ contract Issuer is Owned, MixinSystemSettings, IIssuer {
}
}

/**
* Function used to migrate balances from the CollateralShort contract
* @param short The address of the CollateralShort contract to be upgraded
* @param amount The amount of sUSD collateral to be burnt
*/
function upgradeCollateralShort(address short, uint amount) external onlyOwner {
require(short == resolver.getAddress("CollateralShortLegacy"), "wrong address");
require(amount > 0, "cannot burn 0 synths");

exchanger().settle(short, sUSD);

synths[sUSD].burn(short, amount);
}

function issueSynths(address from, uint amount) external onlySynthetix {
require(amount > 0, "cannot issue 0 synths");

Expand Down Expand Up @@ -1034,7 +1022,11 @@ contract Issuer is Owned, MixinSystemSettings, IIssuer {
address bridgeL1 = resolver.getAddress(CONTRACT_SYNTHETIXBRIDGETOOPTIMISM);
address bridgeL2 = resolver.getAddress(CONTRACT_SYNTHETIXBRIDGETOBASE);
address feePool = resolver.getAddress(CONTRACT_FEEPOOL);
require(msg.sender == bridgeL1 || msg.sender == bridgeL2 || msg.sender == feePool, "only trusted minters");
address dynamicSynthRedeemer = resolver.getAddress(CONTRACT_DYNAMICSYNTHREDEEMER);
require(
msg.sender == bridgeL1 || msg.sender == bridgeL2 || msg.sender == feePool || msg.sender == dynamicSynthRedeemer,
"only trusted minters"
);
_;
}

Expand All @@ -1047,10 +1039,7 @@ contract Issuer is Owned, MixinSystemSettings, IIssuer {
}

function _onlySynthRedeemer() internal view {
require(
msg.sender == address(synthRedeemer()) || msg.sender == resolver.getAddress("DynamicSynthRedeemer"),
"Only Synth Redeemers"
);
require(msg.sender == address(synthRedeemer()), "Only SynthRedeemer");
}

modifier onlySynthRedeemer() {
Expand Down

0 comments on commit 5bcb639

Please sign in to comment.