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-194 Fix Liquidations on L2 #1621

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 35 additions & 4 deletions contracts/BaseSynthetix.sol
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ contract BaseSynthetix is IERC20, ExternStateToken, MixinResolver, ISynthetix {
return issuer().burnSynthsToTargetOnBehalf(burnForAddress, messageSender);
}

function liquidateDelinquentAccount(address account, uint susdAmount)
external
systemActive
optionalProxy
returns (bool)
{
(uint totalRedeemed, uint amountLiquidated) =
issuer().liquidateDelinquentAccount(account, susdAmount, messageSender);

emitAccountLiquidated(account, totalRedeemed, amountLiquidated, messageSender);

// Transfer SNX redeemed to messageSender
// Reverts if amount to redeem is more than balanceOf account, ie due to escrowed balance
return _transferByProxy(account, messageSender, totalRedeemed);
}

function exchangeWithTrackingForInitiator(
bytes32,
uint,
Expand Down Expand Up @@ -337,10 +353,6 @@ contract BaseSynthetix is IERC20, ExternStateToken, MixinResolver, ISynthetix {
_notImplemented();
}

function liquidateDelinquentAccount(address, uint) external returns (bool) {
_notImplemented();
}

function mintSecondary(address, uint) external {
_notImplemented();
}
Expand Down Expand Up @@ -396,6 +408,25 @@ contract BaseSynthetix is IERC20, ExternStateToken, MixinResolver, ISynthetix {
}

// ========== EVENTS ==========
event AccountLiquidated(address indexed account, uint snxRedeemed, uint amountLiquidated, address liquidator);
bytes32 internal constant ACCOUNTLIQUIDATED_SIG = keccak256("AccountLiquidated(address,uint256,uint256,address)");

function emitAccountLiquidated(
address account,
uint256 snxRedeemed,
uint256 amountLiquidated,
address liquidator
) internal {
proxy._emit(
abi.encode(snxRedeemed, amountLiquidated, liquidator),
2,
ACCOUNTLIQUIDATED_SIG,
addressToBytes32(account),
0,
0
);
}

event SynthExchange(
address indexed account,
bytes32 fromCurrencyKey,
Expand Down
34 changes: 0 additions & 34 deletions contracts/Synthetix.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,6 @@ contract Synthetix is BaseSynthetix {
return true;
}

function liquidateDelinquentAccount(address account, uint susdAmount)
external
systemActive
optionalProxy
returns (bool)
{
(uint totalRedeemed, uint amountLiquidated) =
issuer().liquidateDelinquentAccount(account, susdAmount, messageSender);

emitAccountLiquidated(account, totalRedeemed, amountLiquidated, messageSender);

// Transfer SNX redeemed to messageSender
// Reverts if amount to redeem is more than balanceOf account, ie due to escrowed balance
return _transferByProxy(account, messageSender, totalRedeemed);
}

/* Once off function for SIP-60 to migrate SNX balances in the RewardEscrow contract
* To the new RewardEscrowV2 contract
*/
Expand All @@ -196,24 +180,6 @@ contract Synthetix is BaseSynthetix {
}

// ========== EVENTS ==========
event AccountLiquidated(address indexed account, uint snxRedeemed, uint amountLiquidated, address liquidator);
bytes32 internal constant ACCOUNTLIQUIDATED_SIG = keccak256("AccountLiquidated(address,uint256,uint256,address)");

function emitAccountLiquidated(
address account,
uint256 snxRedeemed,
uint256 amountLiquidated,
address liquidator
) internal {
proxy._emit(
abi.encode(snxRedeemed, amountLiquidated, liquidator),
2,
ACCOUNTLIQUIDATED_SIG,
addressToBytes32(account),
0,
0
);
}

event AtomicSynthExchange(
address indexed account,
Expand Down
5 changes: 5 additions & 0 deletions publish/releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@
"layer": "both",
"sources": ["WrapperFactory"],
"released": "both"
},
{
"sip": 194,
"layer": "ovm",
"sources": ["Synthetix"]
}
],
"releases": [
Expand Down