Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added streaming to maya #306

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# 1.22.0 (2024-07-tbh)
# 1.22.0 (2024-07-29)

## Updates/Fixes

- Fix addresss indexing issue with ledger [#300](https://github.com/asgardex/asgardex-desktop/pull/300)
- Fix BSC.USDT not showing [#303](https://github.com/asgardex/asgardex-desktop/pull/304)
- Fix white screen on bondtab [#301] (https://github.com/asgardex/asgardex-desktop/pull/306)
- Fix bsc usdt not showing [#304] (https://github.com/asgardex/asgardex-desktop/pull/305)
- Fix usdt usdt crash [#305] (https://github.com/asgardex/asgardex-desktop/pull/306)
- Fix white screen on bondtab [#301] (https://github.com/asgardex/asgardex-desktop/pull/307)

## Add

- Streaming added to MayaChain swaps [#305] (https://github.com/asgardex/asgardex-desktop/pull/306)

# 1.21.9 (2024-06-15)

Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
"@xchainjs/xchain-bitcoin": "0.23.18",
"@xchainjs/xchain-bitcoincash": "0.17.16",
"@xchainjs/xchain-bsc": "0.5.0",
"@xchainjs/xchain-client": "0.16.7",
"@xchainjs/xchain-client": "0.16.8",
"@xchainjs/xchain-cosmos": "1.1.5",
"@xchainjs/xchain-cosmos-sdk": "^0.2.12",
"@xchainjs/xchain-cosmos-sdk": "^0.2.13",
"@xchainjs/xchain-crypto": "0.3.4",
"@xchainjs/xchain-dash": "0.3.5",
"@xchainjs/xchain-doge": "0.7.19",
Expand All @@ -100,16 +100,16 @@
"@xchainjs/xchain-kujira": "0.1.20",
"@xchainjs/xchain-litecoin": "0.14.5",
"@xchainjs/xchain-mayachain": "1.0.10",
"@xchainjs/xchain-mayachain-query": "0.1.15",
"@xchainjs/xchain-mayamidgard": "0.1.4",
"@xchainjs/xchain-mayamidgard-query": "0.1.13",
"@xchainjs/xchain-mayanode": "0.1.6",
"@xchainjs/xchain-midgard": "0.5.7",
"@xchainjs/xchain-midgard-query": "0.1.18",
"@xchainjs/xchain-mayachain-query": "0.1.20",
"@xchainjs/xchain-mayamidgard": "0.1.5",
"@xchainjs/xchain-mayamidgard-query": "0.1.15",
"@xchainjs/xchain-mayanode": "0.1.8",
"@xchainjs/xchain-midgard": "0.5.8",
"@xchainjs/xchain-midgard-query": "0.1.20",
"@xchainjs/xchain-thorchain": "1.1.0",
"@xchainjs/xchain-thorchain-query": "0.7.13",
"@xchainjs/xchain-thornode": "0.3.15",
"@xchainjs/xchain-util": "0.13.6",
"@xchainjs/xchain-thorchain-query": "0.7.17",
"@xchainjs/xchain-thornode": "0.3.17",
"@xchainjs/xchain-util": "0.13.7",
"@xchainjs/xchain-utxo": "0.1.9",
"@xchainjs/xchain-utxo-providers": "0.2.17",
"antd": "^4.20.7",
Expand Down
127 changes: 55 additions & 72 deletions src/renderer/components/swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,20 @@ export const Swap = ({
)
// For normal quotes
const [oQuote, setQuote] = useState<O.Option<TxDetails>>(O.none)

// For maya quotes
const [oQuoteMaya, setQuoteMaya] = useState<O.Option<QuoteSwap>>(O.none)

// Default Streaming interval set to 1 blocks
const [streamingInterval, setStreamingInterval] = useState<number>(dex.chain === THORChain ? 1 : 0)
const [streamingInterval, setStreamingInterval] = useState<number>(dex.chain === THORChain ? 1 : 3)
// Default Streaming quantity set to 0 network computes the optimum
const [streamingQuantity, setStreamingQuantity] = useState<number>(0)
// Slide use state
const [slider, setSlider] = useState<number>(dex.chain === THORChain ? 26 : 0)
const [slider, setSlider] = useState<number>(dex.chain === THORChain ? 26 : 76)

const [oTargetWalletType, setTargetWalletType] = useState<O.Option<WalletType>>(oInitialTargetWalletType)

const [isStreaming, setIsStreaming] = useState<Boolean>(dex.chain === THORChain ? true : false)
const [isStreaming, setIsStreaming] = useState<Boolean>(true)

// Update state needed - initial target walletAddress is loaded async and can be different at first run
useEffect(() => {
Expand Down Expand Up @@ -788,7 +789,7 @@ export const Swap = ({

//Helper Affiliate function, swaps where tx is greater than affiliate aff is free
const applyBps = useMemo(() => {
const aff = ASGARDEX_AFFILIATE_FEE === 10 ? ASGARDEX_AFFILIATE_FEE : 10
const aff = ASGARDEX_AFFILIATE_FEE
let applyBps: number
const txFeeCovered = priceAmountToSwapMax1e8.assetAmount.gt(ASGARDEX_AFFILIATE_FEE_MIN)
applyBps = network === Network.Stagenet ? 0 : aff
Expand Down Expand Up @@ -878,13 +879,17 @@ export const Swap = ({
const amount = new CryptoAmount(convertBaseAmountDecimal(amountToSwapMax1e8, sourceAssetDecimal), sourceAsset)
const address = destinationAddress
const fromAdd = sourceWalletAddress
const streamingInt = isStreaming ? streamingInterval : 0
const streaminQuant = isStreaming ? streamingQuantity : 0
const toleranceBps = isStreaming ? 10000 : slipTolerance * 100 // convert to basis points
return {
fromAsset: fromAsset,
destinationAsset: destinationAsset,
amount: amount,
destinationAddress: address,
fromAddress: fromAdd,
streamingInterval: streamingInt,
streamingQuantity: streaminQuant,
toleranceBps: toleranceBps,
affiliateAddress: ASGARDEX_THORNAME,
affiliateBps: applyBps
Expand All @@ -899,6 +904,8 @@ export const Swap = ({
amountToSwapMax1e8,
sourceAssetDecimal,
isStreaming,
streamingInterval,
streamingQuantity,
slipTolerance,
applyBps
]
Expand Down Expand Up @@ -950,7 +957,9 @@ export const Swap = ({
destinationAsset: targetAsset,
fromAddress: sourceWalletAddress,
amount: new CryptoAmount(convertBaseAmountDecimal(amountToSwapMax1e8, sourceAssetDecimal), sourceAsset),
toleranceBps: slipTolerance * 100,
streamingInterval: isStreaming ? streamingInterval : 0,
streamingQuantity: isStreaming ? streamingQuantity : 0,
toleranceBps: isStreaming || network === Network.Stagenet ? 10000 : slipTolerance * 100, // convert to basis points,
affiliateAddress: ASGARDEX_THORNAME,
affiliateBps: applyBps
}
Expand Down Expand Up @@ -1053,17 +1062,27 @@ export const Swap = ({
}, [dex, oQuote, oQuoteMaya])

// Quote slippage returned as a percent
const swapStreamingSlippage: number = useMemo(
() =>
FP.pipe(
oQuote,
O.fold(
() => 0, // default affiliate fee asset amount return as number not as BP
(txDetails) => txDetails.txEstimate.streamingSlipBasisPoints / 100
)
),
[oQuote]
)
const swapStreamingSlippage: number = useMemo(() => {
// Handle each Option individually
const slipFromTxDetails = FP.pipe(
oQuote,
O.fold(
() => 0,
(txDetails) => txDetails.txEstimate.streamingSlipBasisPoints / 100
)
)
const slipFromQuoteSwap = FP.pipe(
oQuoteMaya,
O.fold(
() => 0,
(quoteSwap) => {
return quoteSwap.slipBasisPoints / 100
}
)
)
return dex.chain === THORChain ? slipFromTxDetails : slipFromQuoteSwap
}, [dex, oQuote, oQuoteMaya])

// Quote expiry returned as a date
const swapExpiry: Date = useMemo(() => {
const swapExpiryThor = FP.pipe(
Expand Down Expand Up @@ -1100,24 +1119,14 @@ export const Swap = ({
oQuoteMaya,
O.fold(
() => new CryptoAmount(baseAmount(0), targetAsset),
(quoteSwap) => quoteSwap.expectedAmount
(quoteSwap) => {
return quoteSwap.expectedAmount
}
)
)
return dex.chain === THORChain ? swapResultAmountMaxThor : swapResultAmountMaxMaya
}, [dex, oQuote, oQuoteMaya, targetAsset])

// Swap streaming result from thornode
const swapStreamingNetOutput: CryptoAmount = useMemo(
() =>
FP.pipe(
sequenceTOption(oQuote),
O.fold(
() => new CryptoAmount(baseAmount(0), targetAsset),
([txDetails]) => txDetails.txEstimate.netOutputStreaming
)
),
[oQuote, targetAsset]
)
// Swap streaming result from thornode
const maxStreamingQuantity: number = useMemo(
() =>
Expand Down Expand Up @@ -1174,7 +1183,7 @@ export const Swap = ({
? PoolHelpers.getPoolPriceValue({
balance: {
asset: swapResultAmountMax.asset,
amount: isStreaming ? swapStreamingNetOutput.baseAmount : swapResultAmountMax.baseAmount
amount: swapResultAmountMax.baseAmount
},
poolDetails,
pricePool
Expand All @@ -1187,7 +1196,7 @@ export const Swap = ({
getPoolPriceValueM({
balance: {
asset: swapResultAmountMax.asset,
amount: isStreaming ? swapStreamingNetOutput.baseAmount : swapResultAmountMax.baseAmount
amount: swapResultAmountMax.baseAmount
},
poolDetails,
pricePool
Expand All @@ -1196,15 +1205,7 @@ export const Swap = ({
O.getOrElse(() => baseAmount(0, THORCHAIN_DECIMAL)), // default decimal
(amount) => ({ asset: pricePool.asset, amount })
)
}, [
dex,
swapResultAmountMax.asset,
swapResultAmountMax.baseAmount,
isStreaming,
swapStreamingNetOutput.baseAmount,
poolDetails,
pricePool
])
}, [dex, swapResultAmountMax.asset, swapResultAmountMax.baseAmount, poolDetails, pricePool])

/**
* Price sum of swap fees (IN + OUT) and affiliate
Expand Down Expand Up @@ -1731,10 +1732,10 @@ export const Swap = ({

// Function to reset the slider to default position
const resetToDefault = () => {
setStreamingInterval(dex.chain === THORChain ? 1 : 0) // Default position
setStreamingQuantity(0) // thornode decides the swap quantity
setSlider(dex.chain === THORChain ? 26 : 0)
setIsStreaming(dex.chain === THORChain ? true : false)
setStreamingInterval(dex.chain === THORChain ? 1 : 3) // Default position
setStreamingQuantity(0) // thornode | mayanode decides the swap quantity
setSlider(26)
setIsStreaming(true)
}
const quoteOnlyButton = () => {
setQuoteOnly(!quoteOnly)
Expand All @@ -1759,11 +1760,8 @@ export const Swap = ({
setIsStreaming(streamingIntervalValue !== 0)
}
const tipFormatter =
dex.chain === THORChain
? slider === 0
? 'Caution tx could be refunded'
: `${streamingIntervalValue} Block interval between swaps`
: `Mayachain does not support streaming yet`
slider === 0 ? 'Caution tx could be refunded' : `${streamingIntervalValue} Block interval between swaps`

const labelMin = slider <= 0 ? `Limit Swap` : `` || slider < 50 ? 'Time Optimised' : `Price Optimised`

return (
Expand All @@ -1778,12 +1776,10 @@ export const Swap = ({
tipFormatter={() => `${tipFormatter} `}
labels={[`${labelMin}`, `${streamingInterval}`]}
tooltipPlacement={'top'}
error={dex.chain === 'MAYA'}
disabled={dex.chain === 'MAYA'}
/>
</div>
)
}, [dex, slider, streamingInterval])
}, [slider, streamingInterval])

// Streaming Quantity slider
const renderStreamerQuantity = useMemo(() => {
Expand All @@ -1795,12 +1791,12 @@ export const Swap = ({
let toolTip: string
if (streamingInterval === 0) {
quantityLabel = [`Limit swap`]
toolTip = dex.chain === THORChain ? `No Streaming interval set` : `Mayachain does not support streaming yet`
toolTip = `No Streaming interval set`
} else {
quantityLabel = quantity === 0 ? [`Auto swap count`] : [`Sub swaps`, `${quantity}`]
toolTip =
quantity === 0
? `Thornode decides the swap count`
? `${dex.chain === THORChain ? 'Thornode' : 'Mayanode'} decides the swap count`
: `` || quantity === maxStreamingQuantity
? `Max sub swaps ${maxStreamingQuantity}`
: ''
Expand All @@ -1817,12 +1813,10 @@ export const Swap = ({
included={false}
labels={quantityLabel}
tooltipPlacement={'top'}
error={dex.chain === 'MAYA'}
disabled={dex.chain === 'MAYA'}
/>
</div>
)
}, [streamingQuantity, streamingInterval, maxStreamingQuantity, dex])
}, [streamingQuantity, streamingInterval, maxStreamingQuantity, dex.chain])

// swap expiry progress bar
useEffect(() => {
Expand Down Expand Up @@ -1958,23 +1952,13 @@ export const Swap = ({
source={{ asset: sourceAsset, amount: amountToSwapMax1e8 }}
target={{
asset: targetAsset,
amount: isStreaming ? swapStreamingNetOutput.baseAmount : swapResultAmountMax.baseAmount
amount: swapResultAmountMax.baseAmount
}}
stepDescription={stepLabel}
network={network}
/>
)
}, [
swapState,
sourceAsset,
amountToSwapMax1e8,
targetAsset,
isStreaming,
swapStreamingNetOutput.baseAmount,
swapResultAmountMax.baseAmount,
network,
intl
])
}, [swapState, sourceAsset, amountToSwapMax1e8, targetAsset, swapResultAmountMax.baseAmount, network, intl])
// assuming on a unsucessful tx that the swap state should remain the same
const onCloseTxModal = useCallback(() => {
resetSwapState()
Expand Down Expand Up @@ -2176,9 +2160,8 @@ export const Swap = ({
if (lockedWallet || quoteOnly) {
return <></>
}

const error = quoteErrors[0].split(':')
const assetPart = error[2].split('(')[1]?.split(')')[0]
const assetPart = error.length === 3 ? error[2].split('(')[1]?.split(')')[0] : undefined
if (!lockedWallet && assetPart === `${targetAsset.chain}.${targetAsset.symbol}`) {
return <ErrorLabel>{intl.formatMessage({ id: 'swap.errors.pool.notAvailable' }, { pool: assetPart })}</ErrorLabel>
}
Expand Down Expand Up @@ -2795,7 +2778,7 @@ export const Swap = ({
title={intl.formatMessage({ id: 'swap.output' })}
// Show swap result <= 1e8
amount={{
amount: isStreaming ? swapStreamingNetOutput.baseAmount : swapResultAmountMax.baseAmount,
amount: swapResultAmountMax.baseAmount,
asset: targetAsset
}}
priceAmount={priceSwapResultAmountMax1e8}
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/components/wallet/txs/interact/InteractFormThor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MagnifyingGlassMinusIcon, MagnifyingGlassPlusIcon } from '@heroicons/re
import { Network } from '@xchainjs/xchain-client'
import { PoolDetails } from '@xchainjs/xchain-midgard'
import { THORChain } from '@xchainjs/xchain-thorchain'
import { QuoteThornameParams, ThorchainQuery, ThornameDetails } from '@xchainjs/xchain-thorchain-query'
import { QuoteTHORNameParams, ThorchainQuery, ThornameDetails } from '@xchainjs/xchain-thorchain-query'
import {
Asset,
assetAmount,
Expand Down Expand Up @@ -331,25 +331,25 @@ export const InteractFormThor: React.FC<Props> = (props) => {
const currentDate = new Date()

form.validateFields()
const thorname = form.getFieldValue('thorname')
const name = form.getFieldValue('thorname')
const chain = thornameRegister ? form.getFieldValue('chain') : form.getFieldValue('aliasChain')
const yearsToAdd = form.getFieldValue('expiry')
const expirity =
const expiry =
yearsToAdd === 1
? undefined
: new Date(currentDate.getFullYear() + yearsToAdd, currentDate.getMonth(), currentDate.getDate())
const chainAddress = thornameRegister ? form.getFieldValue('chainAddress') : form.getFieldValue('aliasAddress')
const owner = balance.walletAddress
if (thorname !== undefined && chain !== undefined && chainAddress !== undefined) {
if (name !== undefined && chain !== undefined && chainAddress !== undefined) {
const fetchThornameQuote = async () => {
try {
const params: QuoteThornameParams = {
thorname,
const params: QuoteTHORNameParams = {
name,
chain,
chainAddress,
owner,
preferredAsset,
expirity: expirity,
expiry,
isUpdate: thornameUpdate || isOwner
}

Expand Down
Loading