@@ -23,24 +23,26 @@ export const useEditPosition = (props: Props) => {
2323 const slippage = useStore ( ( s ) => s . slippage )
2424
2525 const [ editPosition , coinsAfterSwap ] = useMemo < [ Position , Coin [ ] ] > ( ( ) => {
26- const primaryAmount =
27- props . position . amounts . primary - ( props . prevPosition ?. amounts . primary || 0 )
28- const secondaryAmount =
29- props . position . amounts . secondary - ( props . prevPosition ?. amounts . secondary || 0 )
30- const borrowedPrimaryAmount =
31- props . position . amounts . borrowedPrimary - ( props . prevPosition ?. amounts . borrowedPrimary || 0 )
32-
33- const borrowedSecondaryAmount =
34- props . position . amounts . borrowedSecondary -
35- ( props . prevPosition ?. amounts . borrowedSecondary || 0 )
26+ const primaryAmount = new BigNumber ( props . position . amounts . primary )
27+ . minus ( props . prevPosition ?. amounts . primary || 0 )
28+ . integerValue ( BigNumber . ROUND_CEIL )
29+ const secondaryAmount = new BigNumber ( props . position . amounts . secondary )
30+ . minus ( props . prevPosition ?. amounts . secondary || 0 )
31+ . integerValue ( BigNumber . ROUND_CEIL )
32+ const borrowedPrimaryAmount = new BigNumber ( props . position . amounts . borrowedPrimary )
33+ . minus ( props . prevPosition ?. amounts . borrowedPrimary || 0 )
34+ . integerValue ( BigNumber . ROUND_CEIL )
35+ const borrowedSecondaryAmount = new BigNumber ( props . position . amounts . borrowedSecondary )
36+ . minus ( props . prevPosition ?. amounts . borrowedSecondary || 0 )
37+ . integerValue ( BigNumber . ROUND_CEIL )
3638
3739 const editPosition = {
3840 ...props . position ,
3941 amounts : {
40- primary : primaryAmount ,
41- secondary : secondaryAmount ,
42- borrowedPrimary : borrowedPrimaryAmount ,
43- borrowedSecondary : borrowedSecondaryAmount ,
42+ primary : primaryAmount . toNumber ( ) ,
43+ secondary : secondaryAmount . toNumber ( ) ,
44+ borrowedPrimary : borrowedPrimaryAmount . toNumber ( ) ,
45+ borrowedSecondary : borrowedSecondaryAmount . toNumber ( ) ,
4446 lp : {
4547 amount : '0' ,
4648 primary : 0 ,
@@ -52,11 +54,11 @@ export const useEditPosition = (props: Props) => {
5254
5355 const primaryBaseAmount = convertToBaseCurrency ( {
5456 denom : props . vault . denoms . primary ,
55- amount : ( primaryAmount + borrowedPrimaryAmount ) . toString ( ) ,
57+ amount : primaryAmount . plus ( borrowedPrimaryAmount ) . toString ( ) ,
5658 } )
5759 const secondaryBaseAmount = convertToBaseCurrency ( {
5860 denom : props . vault . denoms . secondary ,
59- amount : ( secondaryAmount + borrowedSecondaryAmount ) . toString ( ) ,
61+ amount : secondaryAmount . plus ( borrowedSecondaryAmount ) . toString ( ) ,
6062 } )
6163
6264 let primaryAfterSwap = new BigNumber ( primaryAmount ) . plus ( borrowedPrimaryAmount )
@@ -71,7 +73,7 @@ export const useEditPosition = (props: Props) => {
7173 const amount = Math . floor (
7274 convertValueToAmount ( {
7375 denom : props . vault . denoms [ swapTarget ] ,
74- amount : inputAmount . toString ( ) ,
76+ amount : new BigNumber ( inputAmount ) . toString ( ) ,
7577 } ) ,
7678 )
7779
@@ -126,12 +128,12 @@ export const useEditPosition = (props: Props) => {
126128
127129 const primary = editPosition . amounts . primary && {
128130 denom : props . vault . denoms . primary ,
129- amount : editPosition . amounts . primary . toString ( ) ,
131+ amount : new BigNumber ( editPosition . amounts . primary ) . toString ( ) ,
130132 }
131133
132134 const secondary = editPosition . amounts . secondary && {
133135 denom : props . vault . denoms . secondary ,
134- amount : editPosition . amounts . secondary . toString ( ) ,
136+ amount : new BigNumber ( editPosition . amounts . secondary ) . toString ( ) ,
135137 }
136138
137139 const borrow = editPosition . borrowDenom && {
@@ -148,12 +150,16 @@ export const useEditPosition = (props: Props) => {
148150
149151 const primaryBaseAmount = convertToBaseCurrency ( {
150152 denom : props . vault . denoms . primary ,
151- amount : ( editPosition . amounts . primary + editPosition . amounts . borrowedPrimary ) . toString ( ) ,
153+ amount : new BigNumber ( editPosition . amounts . primary )
154+ . plus ( editPosition . amounts . borrowedPrimary )
155+ . toString ( ) ,
152156 } )
153157
154158 const secondaryBaseAmount = convertToBaseCurrency ( {
155159 denom : props . vault . denoms . secondary ,
156- amount : ( editPosition . amounts . secondary + editPosition . amounts . borrowedSecondary ) . toString ( ) ,
160+ amount : new BigNumber ( editPosition . amounts . secondary )
161+ . plus ( editPosition . amounts . borrowedSecondary )
162+ . toString ( ) ,
157163 } )
158164
159165 const swapMessage : Action [ ] = [ ]
@@ -164,15 +170,21 @@ export const useEditPosition = (props: Props) => {
164170 if ( Math . abs ( difference ) > SWAP_THRESHOLD ) {
165171 const inputDenom = difference > 0 ? props . vault . denoms . primary : props . vault . denoms . secondary
166172 const outputDenom = difference < 0 ? props . vault . denoms . primary : props . vault . denoms . secondary
167- const amount = new BigNumber ( difference ) . abs ( ) . div ( 2 ) . toString ( )
168- const swapAmount = Math . ceil ( convertValueToAmount ( { denom : inputDenom , amount : amount } ) )
173+ const amount = new BigNumber ( difference )
174+ . abs ( )
175+ . div ( 2 )
176+ . integerValue ( BigNumber . ROUND_CEIL )
177+ . toString ( )
178+ const swapAmount = new BigNumber (
179+ Math . ceil ( convertValueToAmount ( { denom : inputDenom , amount : amount } ) ) ,
180+ ) . toString ( )
169181
170182 swapMessage . push ( {
171183 swap_exact_in : {
172184 coin_in : {
173185 denom : inputDenom ,
174186 amount : {
175- exact : swapAmount . toString ( ) ,
187+ exact : swapAmount ,
176188 } ,
177189 } ,
178190 denom_out : outputDenom ,
@@ -184,7 +196,7 @@ export const useEditPosition = (props: Props) => {
184196 BigNumber . config ( { EXPONENTIAL_AT : [ - 7 , 30 ] } )
185197 const minimumReceive = new BigNumber ( minLpToReceive )
186198 . times ( 1 - slippage )
187- . dp ( 0 )
199+ . integerValue ( BigNumber . ROUND_CEIL )
188200 . toString ( )
189201
190202 const actions : Action [ ] = [
0 commit comments