@@ -248,7 +248,7 @@ export class SdkPool extends SdkShared {
248
248
}
249
249
250
250
/**
251
- * Calculates the amounts of underlying tokens returned.
251
+ * Calculates the amounts of underlying tokens returned.
252
252
*
253
253
* @param domainId - The domain ID of the pool.
254
254
* @param tokenAddress - The address of local or adopted token.
@@ -268,6 +268,33 @@ export class SdkPool extends SdkShared {
268
268
return amounts ;
269
269
}
270
270
271
+ /**
272
+ * Calculate the dy, the amount of selected token that user receives
273
+ *
274
+ * @param domainId - The domain ID of the pool.
275
+ * @param tokenAddress - The address of local or adopted token.
276
+ * @param amount - The amount of the LP token to burn on withdrawal.
277
+ * @param index - The index of the token to withdraw.
278
+ * @returns availableTokenAmount calculated amount of underlying token
279
+ */
280
+ async calculateRemoveSwapLiquidityOneToken (
281
+ domainId : string ,
282
+ tokenAddress : string ,
283
+ amount : string ,
284
+ index : number ,
285
+ ) : Promise < BigNumber > {
286
+ const _tokenAddress = utils . getAddress ( tokenAddress ) ;
287
+
288
+ const [ connextContract , [ canonicalDomain , canonicalId ] ] = await Promise . all ( [
289
+ this . getConnext ( domainId ) ,
290
+ this . getCanonicalTokenId ( domainId , _tokenAddress ) ,
291
+ ] ) ;
292
+ const key = this . calculateCanonicalKey ( canonicalDomain , canonicalId ) ;
293
+ const available = await connextContract . calculateRemoveSwapLiquidityOneToken ( key , amount , index ) ;
294
+
295
+ return available ;
296
+ }
297
+
271
298
/**
272
299
* Calculates the price impact depending on whether liquidity is being deposited or withdrawn.
273
300
*
@@ -845,8 +872,8 @@ export class SdkPool extends SdkShared {
845
872
*
846
873
* @param domainId - The domain ID of the pool.
847
874
* @param tokenAddress - The address of local or adopted token.
848
- * @param amount - The amount of the token to swap .
849
- * @param minAmounts - (optional) The minimum acceptable amounts of each token to withdraw.
875
+ * @param amount - The amount of the LP token to remove .
876
+ * @param minAmounts - (optional) The minimum amounts of each token in the pool
850
877
* @param deadline - (optional) The deadline for the swap.
851
878
* @returns providers.TransactionRequest object.
852
879
*/
@@ -879,6 +906,61 @@ export class SdkPool extends SdkShared {
879
906
return txRequest ;
880
907
}
881
908
909
+ /**
910
+ * Returns the transaction request for removing liquidity from the pool, weighted differently than the
911
+ * pool's current balances.
912
+ *
913
+ * @param domainId - The domain ID of the pool.
914
+ * @param tokenAddress - The address of local or adopted token.
915
+ * @param amounts - The amounts of the each token to remove.
916
+ * @param maxBurnAmount - (optional) The max LP token provider is willing to pay to
917
+ * @param deadline - (optional) The deadline for the swap.
918
+ * @returns providers.TransactionRequest object.
919
+ */
920
+ async removeLiquidityImbalance (
921
+ domainId : string ,
922
+ tokenAddress : string ,
923
+ amounts : string [ ] ,
924
+ maxBurnAmount = "0" ,
925
+ deadline = this . getDefaultDeadline ( ) ,
926
+ ) : Promise < providers . TransactionRequest > {
927
+ const { requestContext, methodContext } = createLoggingContext ( this . removeLiquidityImbalance . name ) ;
928
+ this . logger . info ( "Method start" , requestContext , methodContext , { domainId, amounts, maxBurnAmount, deadline } ) ;
929
+
930
+ const _tokenAddress = utils . getAddress ( tokenAddress ) ;
931
+
932
+ const signerAddress = this . config . signerAddress ;
933
+ if ( ! signerAddress ) {
934
+ throw new SignerAddressMissing ( ) ;
935
+ }
936
+
937
+ const [ connextContract , [ canonicalDomain , canonicalId ] ] = await Promise . all ( [
938
+ this . getConnext ( domainId ) ,
939
+ this . getCanonicalTokenId ( domainId , _tokenAddress ) ,
940
+ ] ) ;
941
+ const key = this . calculateCanonicalKey ( canonicalDomain , canonicalId ) ;
942
+
943
+ if ( maxBurnAmount === "0" || ! maxBurnAmount ) {
944
+ const poolDataResults = await this . getPoolData ( { key : key , domainId : domainId } ) ;
945
+ if ( ! poolDataResults || poolDataResults . length == 0 ) {
946
+ this . logger . debug ( `No Pool for token ${ _tokenAddress } on domain ${ domainId } ` ) ;
947
+ }
948
+ const poolData = poolDataResults [ 0 ] ; // there should only be one pool
949
+ maxBurnAmount = ( await this . getTokenUserBalance ( domainId , String ( poolData . lp_token ) , signerAddress ) ) . toString ( ) ;
950
+ }
951
+
952
+ const txRequest = await connextContract . populateTransaction . removeSwapLiquidityImbalance (
953
+ key ,
954
+ amounts ,
955
+ maxBurnAmount ,
956
+ deadline ,
957
+ ) ;
958
+
959
+ this . logger . info ( `${ this . removeLiquidityImbalance . name } transaction created ` , requestContext , methodContext ) ;
960
+
961
+ return txRequest ;
962
+ }
963
+
882
964
/**
883
965
* Returns the transaction request for performing a swap in a pool.
884
966
*
0 commit comments