Skip to content

Commit 020697c

Browse files
Brechtpddong77
authored andcommitted
[Protocol3] Misc small improvements + More tests (#241)
* [Protocol3] WIP: maintenance mode changes * [Protocol3] WIP: maintenance mode improvements * [Protocol3] Fixed issue * [Protocol3] Improved docs * [Protocol3] Fixed doc * Update ExchangeMode.sol * Update ExchangeAdmins.sol * [Protocol3] Tests + fixes for improved maintenance mode * [Protocol3] Fixed misc tests * [Protocol3] Added block version * [Protocol3] Added support for data compression * [Protocol3] Removed protocol2-js dependency * [Protocol3] Fixed misc tests * [Protocol3] Renamed numElements to blockSize for consistency * [Protocol3] Optimized onchain decompression * [Protocol3] Improved LZ compressor + ring data transformation * [Protocol3] Misc small improvements * [Protocol3] Improved LZ compressor performance * [Protocol3] Fixed offchain withdrawal message signing * [Protocol3] Update ABI * [Protocol3] Updated generate_keys script for parameter rename * [Protocol3] Break long lines * [Protocol3] Misc small improvements + added misc tests * [Protocol3] Misc improvements/tests for same accounts in requests * [Protocol3] Fixed test * [Protocol3] Added reentrancy tests * [Protocol3] Small refactor * [Protocol3] Added misc ring settlement/block fee tests * [Protocol3] Removed 'only' from tests * [Protocol3] Added transfer tests * [Protocol3] Fixed testing check * [Protocol3] Small refactor (burn -> protocol fees) * [Protocol3] Cleaned up logging * [Protocol3] Fixed precission error in test check * [Protocol3] Added some more misc tests * [Protocol3] Fixed test check for shutdown mode * [Protocol3] Update backend doc * [Protocol3] Small refactoring * [Protocol3] Allow withdrawing the protocol fees directly to pfm * [Protocol3] Changed createOrUpdateAccount to update the Merkle tree * [Protocol3] Fixed compile warning * [Protocol3] Fixed test with AccountContract
1 parent f84d92b commit 020697c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2253
-700
lines changed

packages/loopring_v3/ABI/version30/AddressUtil.abi

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/loopring_v3/ABI/version30/IExchange.abi

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/loopring_v3/ABI/version30/ILoopringV3.abi

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/loopring_v3/BACKEND.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,30 +232,24 @@ Order
232232
validUntil: number,
233233
maxFeeBips: number,
234234
buy: number,
235-
235+
236236
feeBips: number,
237237
rebateBips: number,
238238
239239
signature: Signature,
240-
241-
# The data in the trade history of tokenS before they are updated
242-
tradeHistoryFilled: string,
243-
tradeHistoryCancelled: number,
244-
tradeHistoryOrderID: number,
245240
}
246241
247242
class Ring
248243
{
249244
orderA: Order,
250245
orderB: Order,
251246
252-
minerAccountID: number,
253-
feeRecipientAccountID: number,
247+
ringMatcherAccountID: number,
254248
tokenID: number,
255249
fee: string,
256250
nonce: number,
257251
258-
minerSignature: Signature,
252+
ringMatcherSignature: Signature,
259253
dualAuthASignature: Signature,
260254
dualAuthBSignature: Signature,
261255
}
@@ -293,7 +287,7 @@ RingSettlement
293287
balanceUpdateB_M: BalanceUpdate,
294288
balanceUpdateO_M: BalanceUpdate,
295289
accountUpdate_M: AccountUpdate,
296-
290+
297291
# Balance update data for protocol fee payments
298292
balanceUpdateA_P: BalanceUpdate,
299293
balanceUpdateB_P: BalanceUpdate,
@@ -311,11 +305,11 @@ RingSettlementBlock
311305
312306
# Timestamp used in this block
313307
timestamp: number,
314-
308+
315309
# Protocol fees used in this block
316310
protocolTakerFeeBips: number;
317311
protocolMakerFeeBips: number;
318-
312+
319313
# Protocol fee account update data (account 0)
320314
accountUpdate_P: AccountUpdate,
321315
@@ -594,8 +588,7 @@ Order
594588
595589
Ring
596590
{
597-
minerAccountID: number,
598-
feeRecipientAccountID: number,
591+
ringMatcherAccountID: number,
599592
tokenID: number,
600593
fee: string,
601594
orderA: Order,

packages/loopring_v3/contracts/iface/IExchange.sol

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,25 @@ contract IExchange
177177

178178
/// @dev Submit an onchain request to create a new account for msg.sender or
179179
/// update its existing account by replacing its trading public key.
180+
/// The total fee in ETH that the user needs to pay is:
181+
/// depositFee +
182+
/// (isAccountNew ? accountCreationFee : 0) +
183+
/// (isAccountUpdated ? accountUpdateFee : 0)
184+
/// If the user sends too much ETH the surplus is immediatly sent back.
185+
///
186+
/// Note that after such an operation, it will take the operator some
187+
/// time (no more than MAX_AGE_REQUEST_UNTIL_FORCED) to process the request
188+
/// and create or update the offchain account.
189+
///
190+
/// Calling this method with a different trading public key will effectively
191+
/// cancel all existing orders within MAX_AGE_REQUEST_UNTIL_FORCED.
192+
///
180193
/// @param pubKeyX The first part of the account's trading EdDSA public key
181194
/// @param pubKeyY The second part of the account's trading EdDSA public key.
182195
/// Note that pubkeyX and pubKeyY cannot be both `1`.
183196
/// @return accountID The account's ID
184197
/// @return isAccountNew True if this account is newly created, false if the account existed
198+
/// @return isAccountUpdated True if this account was updated, false otherwise
185199
function createOrUpdateAccount(
186200
uint pubKeyX,
187201
uint pubKeyY
@@ -190,7 +204,8 @@ contract IExchange
190204
payable
191205
returns (
192206
uint24 accountID,
193-
bool isAccountNew
207+
bool isAccountNew,
208+
bool isAccountUpdated
194209
);
195210

196211
// -- Balances --
@@ -560,10 +575,16 @@ contract IExchange
560575
);
561576

562577
/// @dev Deposit Ether or ERC20 tokens to the sender's account.
563-
/// This function will create a new account if such no account exists
578+
/// This function will create a new account if no account exists
564579
/// for msg.sender, or update the existing account with the given trading
565580
/// public key when the account exists.
566581
///
582+
/// The total fee in ETH that the user needs to pay is:
583+
/// depositFee +
584+
/// (isAccountNew ? accountCreationFee : 0) +
585+
/// (isAccountUpdated ? accountUpdateFee : 0)
586+
/// If the user sends too much ETH the surplus is immediatly sent back.
587+
///
567588
/// Note that after such an operation, it will take the operator some
568589
/// time (no more than MAX_AGE_REQUEST_UNTIL_FORCED) to process the request
569590
/// and create the deposit to the offchain account.
@@ -577,6 +598,7 @@ contract IExchange
577598
/// @param amount The amount of tokens to deposit
578599
/// @return accountID The id of the account
579600
/// @return isAccountNew True if this account is newly created, false if the account existed
601+
/// @return isAccountUpdated True if this account was updated, false otherwise
580602
function updateAccountAndDeposit(
581603
uint pubKeyX,
582604
uint pubKeyY,
@@ -587,15 +609,19 @@ contract IExchange
587609
payable
588610
returns (
589611
uint24 accountID,
590-
bool isAccountNew
612+
bool isAccountNew,
613+
bool isAccountUpdated
591614
);
592615

593616
/// @dev Deposit Ether or ERC20 tokens to the sender's account.
594617
///
618+
/// The total fee in ETH that the user needs to pay is 'depositFee'.
619+
/// If the user sends too much ETH the surplus is immediatly sent back.
620+
///
595621
/// Note that after such an operation, it will take the operator some
596622
/// time (no more than MAX_AGE_REQUEST_UNTIL_FORCED) to process the request
597623
/// and create the deposit to the offchain account.
598-
////
624+
///
599625
/// Warning: the DEX UI should warn their users not to deposit more than 2^96 - 1
600626
/// tokens in total. If that happens, the user may lose token.
601627
/// This token balance upper limit, however, is large enought for most scenarios.
@@ -611,6 +637,9 @@ contract IExchange
611637

612638
/// @dev Deposit Ether or ERC20 tokens to a recipient account.
613639
///
640+
/// The total fee in ETH that the user needs to pay is 'depositFee'.
641+
/// If the user sends too much ETH the surplus is immediatly sent back.
642+
///
614643
/// Note that after such an operation, it will take the operator some
615644
/// time (no more than MAX_AGE_REQUEST_UNTIL_FORCED) to process the request
616645
/// and create the deposit to the offchain account.
@@ -664,15 +693,19 @@ contract IExchange
664693
uint32 timestamp
665694
);
666695

667-
// Set the large value for amount to withdraw the complete balance
668696
/// @dev Submit an onchain request to withdraw Ether or ERC20 tokens. To withdraw
669697
/// all the balance, use a very large number for `amount`.
670698
///
699+
/// Only the owner of the account can request a withdrawal.
700+
///
701+
/// The total fee in ETH that the user needs to pay is 'withdrawalFee'.
702+
/// If the user sends too much ETH the surplus is immediatly sent back.
703+
///
671704
/// Note that after such an operation, it will take the operator some
672705
/// time (no more than MAX_AGE_REQUEST_UNTIL_FORCED) to process the request
673706
/// and create the deposit to the offchain account.
674707
///
675-
/// @param tokenAddress The adderss of the token, use `0x0` for Ether.
708+
/// @param tokenAddress The address of the token, use `0x0` for Ether.
676709
/// @param amount The amount of tokens to deposit
677710
function withdraw(
678711
address tokenAddress,
@@ -681,6 +714,22 @@ contract IExchange
681714
external
682715
payable;
683716

717+
/// @dev Submit an onchain request to withdraw Ether or ERC20 tokens from the
718+
/// protocol fees account. The complete balance is always withdrawn.
719+
///
720+
/// Anyone can request a withdrawal of the protocol fees.
721+
///
722+
/// Note that after such an operation, it will take the operator some
723+
/// time (no more than MAX_AGE_REQUEST_UNTIL_FORCED) to process the request
724+
/// and create the deposit to the offchain account.
725+
///
726+
/// @param tokenAddress The address of the token, use `0x0` for Ether.
727+
function withdrawProtocolFees(
728+
address tokenAddress
729+
)
730+
external
731+
payable;
732+
684733
/// @dev Allows an account owner to withdraw his funds using the balances stored
685734
/// in the merkle tree. The funds will be sent to the owner of the acount.
686735
///

packages/loopring_v3/contracts/iface/ILoopringV3.sol

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ contract ILoopringV3
6060
uint time
6161
);
6262

63+
event ProtocolFeeManagerUpdated(
64+
address payable pfm
65+
);
66+
6367
// == Public Variables ==
6468
struct Exchange
6569
{
@@ -91,6 +95,8 @@ contract ILoopringV3
9195
uint public targetProtocolTakerFeeStake;
9296
uint public targetProtocolMakerFeeStake;
9397

98+
address payable public pfm;
99+
94100
// == Public Functions ==
95101
/// @dev Update the global exchange settings.
96102
/// This function can only be called by the owner of this contract.
@@ -126,6 +132,16 @@ contract ILoopringV3
126132
)
127133
external;
128134

135+
/// @dev Update the protocol fee manager.
136+
/// This function can only be called by the owner of this contract.
137+
///
138+
/// Warning: this new address will be used by existing and
139+
/// new Loopring exchanges.
140+
function setProtocolFeeManager(
141+
address payable _pfm
142+
)
143+
external;
144+
129145
/// @dev Create a new exchange. msg.sender will become the owner of the new exchange.
130146
/// @param operator The operator address of the exchange who will be responsible for
131147
/// submitting blocks and proofs.
@@ -230,16 +246,6 @@ contract ILoopringV3
230246
)
231247
external;
232248

233-
/// @dev Withdraw
234-
/// @param exchangeId The id of the exchange to withdraw the fees from
235-
/// @param tokenAddress The token to withdraw the fees for
236-
function withdrawProtocolFees(
237-
uint exchangeId,
238-
address tokenAddress
239-
)
240-
external
241-
payable;
242-
243249
/// @dev Get the protocol fee values for an exchange.
244250
/// @param exchangeId The id of the exchange
245251
/// @param onchainDataAvailability True if the exchange has on-chain
@@ -254,25 +260,7 @@ contract ILoopringV3
254260
view
255261
returns (uint8 takerFeeBips, uint8 makerFeeBips);
256262

257-
/// @dev Withdraw all non-LRC fees (called the Burn) to the designated address.
258-
/// LRC fees have been burned already thanks to the new LRC contract's burn function;
259-
/// All non-LRC fees will be auctioned off for LRC by the Looprong Foundation, the
260-
/// purchased LRC will also be publicly burned.
261-
///
262-
/// In the future, all non-LRC fees will be auctioned off in a fully decentralized
263-
/// fashion using Loopring's Oedax (Open-Ended Dutch Auction eXchange) protocol.
264-
/// For more details, please see:
265-
/// https://medium.com/loopring-protocol/oedax-looprings-open-ended-dutch-auction-exchange-model-d92cebbd3667
266-
///
267-
/// @param token The address of the token. Use 0x0 for Ether.
268-
/// @param recipient The address to receive the tokens.
269-
function withdrawTheBurn(
270-
address token,
271-
address payable recipient
272-
)
273-
external;
274-
275-
/// @dev Allow ETH to be sent directly to this contract (for burning)
263+
/// @dev Allow ETH to be sent directly to this contract (to collect the protocol fees)
276264
function()
277265
external
278266
payable;

0 commit comments

Comments
 (0)