11// SPDX-License-Identifier: MIT
22// Copyright © 2025 TON Studio
33
4- import " ./amm-pool" ;
54import " ../utils/math" ;
65import " ./messages" ;
6+ import " ../vaults/vault-interface" ;
7+
8+ // TODO This is here until Tact will have something like `dataOf Contract()`
9+ struct AmmPoolData {
10+ leftVault : Address ;
11+ rightVault : Address ; // To be deterministic, rightVault address must be greater than leftVault address
12+ leftSideReserve : Int as coins ;
13+ rightSideReserve : Int as coins ;
14+ totalSupply : Int as coins ;
15+ jettonContent : Cell ? ;
16+ }
717
818contract LiquidityDepositContract (
919 leftVault : Address , // To be deterministic, leftVault address must be less than rightVault address
@@ -24,19 +34,43 @@ contract LiquidityDepositContract(
2434 receive (msg : PartHasBeenDeposited ) {
2535 let sender = sender ();
2636 if (sender == self .leftVault ) {
27- // TODO maybe here we should check that it is not already filled and revert on errors.
28- require (msg .amount == self .leftSideAmount , " LP Deposit: Amount must be equal to leftSide" );
2937 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+ }
3052 self .leftAdditionalParams = msg .additionalParams ;
3153 self .status |= 1 ;
32- }
33- if (sender == self .rightVault ) {
34- // TODO maybe here we should check that it is not already filled and revert on errors.
35- require (msg .amount == self .rightSideAmount , " LP Deposit: Amount must be equal to rightSide" );
54+ } else if (sender == self .rightVault ) {
3655 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+ }
3770 self .rightAdditionalParams = msg .additionalParams ;
3871 self .status |= 2 ;
3972 }
73+ require (self .leftVault != self .rightVault , " LP Deposit: Vaults must be different" );
4074 // Both sides are filled, we can deposit now.
4175 if (self .status == 3 ) {
4276 // We must check, that this account was deployed with sorted vault, otherwise it could be a security issue
@@ -46,7 +80,17 @@ contract LiquidityDepositContract(
4680 value : 0 ,
4781 bounce : false , // 1. To pay storage fees of AmmPool. 2. We will destroy this contract, so bounce does not have sense.
4882 mode : SendRemainingBalance + SendDestroyIfZero , // We don't need to keep this contract alive
49- init : initOf AmmPool (self .leftVault , self .rightVault , 0 , 0 , 0 , null ),
83+ init : StateInit {
84+ code : msg .ammPoolCode ,
85+ data : AmmPoolData {
86+ leftVault : self .leftVault ,
87+ rightVault : self .rightVault ,
88+ leftSideReserve : 0 ,
89+ rightSideReserve : 0 ,
90+ totalSupply : 0 ,
91+ jettonContent : null ,
92+ }.toCell (),
93+ },
5094 body : LiquidityDeposit {
5195 depositor : self .depositor ,
5296 contractId : self .contractId ,
0 commit comments