11import React , { useState , useEffect } from 'react' ;
22import { useNetwork } from '../../context/NetworkContext' ;
33import { useSwap } from '../../context/SwapContext' ;
4- import { to } from 'dero-xswd-api' ;
5- import { DERO_SCID , GHOST_EXCHANGE_SCID } from '../../constants/addresses' ;
4+ import { gasEstimateSCArgs , to } from 'dero-xswd-api' ;
5+ import { GHOST_EXCHANGE_SCID } from '../../constants/addresses' ;
66import PrimaryButton from '../PrimaryButton' ;
77import InputField from '../InputField' ;
88
@@ -37,7 +37,7 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
3737 const assetValue = trimToFiveDecimals ( e . target . value ) ;
3838 setAssetAmount ( assetValue ) ;
3939 if ( currentRatio && assetValue ) {
40- setDeroAmount ( ( parseFloat ( assetValue ) * currentRatio ) . toFixed ( 5 ) ) ;
40+ setDeroAmount ( ( parseFloat ( assetValue ) * currentRatio - 0.00001 ) . toFixed ( 5 ) ) ;
4141 } else {
4242 setDeroAmount ( '' ) ;
4343 }
@@ -47,7 +47,7 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
4747 const deroValue = trimToFiveDecimals ( e . target . value ) ;
4848 setDeroAmount ( deroValue ) ;
4949 if ( currentRatio && deroValue ) {
50- setAssetAmount ( ( parseFloat ( deroValue ) / currentRatio ) . toFixed ( 5 ) ) ;
50+ setAssetAmount ( ( parseFloat ( deroValue ) / currentRatio + 0.00001 ) . toFixed ( 5 ) ) ;
5151 } else {
5252 setAssetAmount ( '' ) ;
5353 }
@@ -62,20 +62,26 @@ const AddLiquiditySection: React.FC<AddLiquiditySectionProps> = ({ pair, setStat
6262 setButtonDisabled ( true ) ;
6363 setStatusMessage ( 'Processing transaction...' ) ;
6464
65- const assetAmountNum = Math . round ( parseFloat ( assetAmount ) * 1e5 ) ;
65+ const assetAmountNum = Math . round ( parseFloat ( assetAmount ) * 1e5 ) ;
6666 const deroAmountNum = Math . round ( parseFloat ( deroAmount ) * 1e5 ) ;
6767
6868 const response = await xswd . wallet . transfer ( {
6969 scid : GHOST_EXCHANGE_SCID ,
7070 transfers : [
71- { scid : pair , burn : assetAmountNum } ,
72- { scid : DERO_SCID , burn : deroAmountNum } ,
73- ] ,
74- sc_rpc : [
75- { name : 'entrypoint' , datatype : 'S' , value : 'AddLiquidity' } ,
76- { name : 't' , datatype : 'S' , value : pair } ,
77- { name : 'u' , datatype : 'U' , value : 1 } ,
71+ // The "destination" parameter requires a valid DERO address DIFFERENT FROM THE SENDER'S but, in this context, it serves solely
72+ // to satisfy the RPC syntax. Rest assured, the DERO specified will be transferred to the Smart Contract, not the random address provided.
73+ // In this case, the random address used is Captain's address, as disclosed in the genesis block:
74+ // https://github.com/deroproject/derohe/blob/e9df1205b6603c62f0651d0e18e5e77a2584b15e/config/config.go#L103C28-L103C94
75+ { burn : deroAmountNum , destination : "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270" } ,
76+ { scid : pair , burn : assetAmountNum }
7877 ] ,
78+ sc_rpc : gasEstimateSCArgs (
79+ GHOST_EXCHANGE_SCID ,
80+ "AddLiquidity" , [
81+ { name : "u" , value : 1 } ,
82+ { name : "t" , value : pair } ,
83+
84+ ] ) ,
7985 ringsize : 2 ,
8086 } ) ;
8187
0 commit comments