@@ -20,9 +20,10 @@ contract LiquidityDepositContract(
2020 rightVault : Address ,
2121 leftSideAmount : Int as coins ,
2222 rightSideAmount : Int as coins ,
23- depositor : Address , // This and the next field are kind of salt, so several similar contracts can exist
23+ lpTokensReceiver : Address , // This and the next field are kind of salt, so several similar contracts can exist
2424 contractId : Int as uint64 ,
25- status : Int as uint3 , // Should be deployed with 0.
25+ leftSideFilled : Bool ,
26+ rightSideFilled : Bool ,
2627 // 0 - not started
2728 // 1 - left side is filled
2829 // 2 - right side is filled
@@ -33,46 +34,20 @@ contract LiquidityDepositContract(
3334) {
3435 receive (msg : PartHasBeenDeposited ) {
3536 let sender = sender ();
37+ // If corresponding side is already filled - we don't care.
38+ // User shouldn't top up the same side again.
3639 if (sender == self .leftVault ) {
37- require (msg .depositor == self .depositor , " LP Deposit: Depositor must be the same" );
38- if ((self .status & 1 ) != 0 || msg .amount != self .leftSideAmount ) {
39- message (MessageParameters {
40- mode : SendRemainingValue ,
41- body : RejectLiquidityPart {
42- depositor : msg .depositor ,
43- amountToReturn : msg .amount ,
44- }.toCell (),
45- value : 0 ,
46- to : sender (),
47- bounce : false ,
48- });
49- commit ();
50- require (false , " LP Deposit: Left side cannot be filled again or with different amount" );
51- }
40+ require (msg .amount == self .leftSideAmount , " LP Deposit: Left side cannot be filled with different amount" );
5241 self .leftAdditionalParams = msg .additionalParams ;
53- self .status |= 1 ;
42+ self .leftSideFilled = true ;
5443 } else if (sender == self .rightVault ) {
55- require (msg .depositor == self .depositor , " LP Deposit: Depositor must be the same" );
56- if ((self .status & 2 ) != 0 || msg .amount != self .rightSideAmount ) {
57- message (MessageParameters {
58- mode : SendRemainingValue ,
59- body : RejectLiquidityPart {
60- depositor : msg .depositor ,
61- amountToReturn : msg .amount ,
62- }.toCell (),
63- value : 0 ,
64- to : sender (),
65- bounce : false ,
66- });
67- commit ();
68- require (false , " LP Deposit: Right side cannot be filled again or with different amount" );
69- }
44+ require (msg .amount == self .rightSideAmount , " LP Deposit: Right side cannot be filled with different amount" );
7045 self .rightAdditionalParams = msg .additionalParams ;
71- self .status |= 2 ;
46+ self .rightSideFilled = true ;
7247 }
7348 require (self .leftVault != self .rightVault , " LP Deposit: Vaults must be different" );
7449 // Both sides are filled, we can deposit now.
75- if (self .status == 3 ) {
50+ if (self .leftSideFilled && self . rightSideFilled ) {
7651 // We must check, that this account was deployed with sorted vault, otherwise it could be a security issue
7752 let sortedAddresses = sortAddresses (self .leftVault , self .rightVault );
7853 require (sortedAddresses .lower == self .leftVault , " LP Deposit: Vaults MUST be sorted, to not break invariant" );
@@ -92,7 +67,7 @@ contract LiquidityDepositContract(
9267 }.toCell (),
9368 },
9469 body : LiquidityDeposit {
95- depositor : self .depositor ,
70+ lpTokensReceiver : self .lpTokensReceiver ,
9671 contractId : self .contractId ,
9772 leftAmount : self .leftSideAmount ,
9873 rightAmount : self .rightSideAmount ,
@@ -107,7 +82,15 @@ contract LiquidityDepositContract(
10782 cashback (sender ());
10883 }
10984
110- get fun status (): Int {
111- return self .status ;
85+ get fun status (): Status {
86+ return Status {
87+ leftSideFilled : self .leftSideFilled ,
88+ rightSideFilled : self .rightSideFilled ,
89+ };
11290 }
11391}
92+
93+ struct Status {
94+ leftSideFilled : Bool ;
95+ rightSideFilled : Bool ;
96+ }
0 commit comments