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

fix: osmosis multi-account swaps #3901

Merged
merged 20 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
17e895a
fix: osmosis multi-account swaps
pastaghost Feb 23, 2023
f93f038
Merge branch 'develop' into fix-osmosis-cross-account-swaps
gomesalexandre Feb 23, 2023
874d9df
feat: bump swapper to latest
gomesalexandre Feb 23, 2023
9c8f16e
fix: types
gomesalexandre Feb 23, 2023
5cd5ba7
Merge branch 'develop' into fix-osmosis-cross-account-swaps
gomesalexandre Feb 23, 2023
ebbc755
feat: bump swapper to latest
gomesalexandre Feb 23, 2023
ca22f94
Merge remote-tracking branch 'origin/develop' into fix-osmosis-cross-…
gomesalexandre Feb 23, 2023
8e12f09
Merge branch 'develop' of https://github.com/shapeshift/web into fix-…
pastaghost Feb 23, 2023
2e1cefe
chore: update dependencies
pastaghost Feb 23, 2023
e8ee55c
Merge branch 'fix-osmosis-cross-account-swaps' of https://github.com/…
pastaghost Feb 23, 2023
9428e4f
Merge branch 'develop' of https://github.com/shapeshift/web into fix-…
pastaghost Feb 23, 2023
89981c9
Merge branch 'develop' into fix-osmosis-cross-account-swaps
gomesalexandre Feb 24, 2023
9614690
feat: regenerate yarn.lock
gomesalexandre Feb 24, 2023
79aec4e
feat: bump chain-adapters to latest
gomesalexandre Feb 24, 2023
3d7f05d
feat: bump hdwallet packages to latest
gomesalexandre Feb 24, 2023
dd44479
feat: bump caip to latest
gomesalexandre Feb 24, 2023
ea1f72b
feat: run git checkout origin/develop -- yarn.lock && yarn
gomesalexandre Feb 24, 2023
bfd8005
Revert "feat: bump caip to latest"
gomesalexandre Feb 24, 2023
3f7a93c
fix: update deps. add os, fs polyfills
pastaghost Feb 24, 2023
f53d97b
feat: bump swapper
gomesalexandre Feb 24, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"@shapeshiftoss/investor-yearn": "^6.4.0",
"@shapeshiftoss/logger": "^1.1.3",
"@shapeshiftoss/market-service": "^7.7.0",
"@shapeshiftoss/swapper": "^17.3.0",
"@shapeshiftoss/swapper": "^17.3.1",
"@shapeshiftoss/types": "8.5.0",
"@shapeshiftoss/unchained-client": "^10.12.1",
"@uniswap/sdk": "^3.0.3",
Expand Down
6 changes: 6 additions & 0 deletions src/components/Trade/hooks/useSwapper/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ export const isSupportedNonUtxoSwappingChain = (
chainId === KnownChainIds.ThorchainMainnet
)
}

export const isSupportedCosmosSdkSwappingChain = (
chainId: ChainId,
): chainId is SupportedSwappingChain => {
return chainId === KnownChainIds.OsmosisMainnet || chainId === KnownChainIds.CosmosMainnet
}
39 changes: 32 additions & 7 deletions src/components/Trade/hooks/useSwapper/useSwapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useAvailableSwappers } from 'components/Trade/hooks/useAvailableSwapper
import { useReceiveAddress } from 'components/Trade/hooks/useReceiveAddress'
import { getSwapperManager } from 'components/Trade/hooks/useSwapper/swapperManager'
import {
isSupportedCosmosSdkSwappingChain,
isSupportedNonUtxoSwappingChain,
isSupportedUtxoSwappingChain,
} from 'components/Trade/hooks/useSwapper/typeGuards'
Expand Down Expand Up @@ -39,6 +40,7 @@ export const useSwapper = () => {
const buyTradeAsset = useWatch({ control, name: 'buyTradeAsset' })
const quote = useWatch({ control, name: 'quote' })
const sellAssetAccountId = useWatch({ control, name: 'sellAssetAccountId' })
const buyAssetAccountId = useWatch({ control, name: 'buyAssetAccountId' })
const isSendMax = useWatch({ control, name: 'isSendMax' })
const isExactAllowance = useWatch({ control, name: 'isExactAllowance' })
const slippage = useWatch({ control, name: 'slippage' })
Expand Down Expand Up @@ -94,6 +96,18 @@ export const useSwapper = () => {
selectBIP44ParamsByAccountId(state, sellAccountFilter),
)

const buyAssetAccountIds = useAppSelector(state =>
selectPortfolioAccountIdsByAssetId(state, { assetId: buyAsset?.assetId ?? '' }),
)
const buyAccountFilter = useMemo(
() => ({ accountId: buyAssetAccountId ?? buyAssetAccountIds[0] }),
[buyAssetAccountId, buyAssetAccountIds],
)

const buyAccountBip44Params = useAppSelector(state =>
selectBIP44ParamsByAccountId(state, buyAccountFilter),
)

/*
Cross-account trading means trades that are either:
- Trades between assets on the same chain but different accounts
Expand Down Expand Up @@ -161,6 +175,7 @@ export const useSwapper = () => {
if (!receiveAddress) throw new Error('Missing receiveAddress')
if (!sellAssetAccountId) throw new Error('Missing sellAssetAccountId')
if (!sellAccountBip44Params) throw new Error('Missing sellAccountBip44Params')
if (!buyAccountBip44Params) throw new Error('Missing buyAccountBip44Params')
if (!sellAccountMetadata) throw new Error('Missing sellAccountMetadata')

const buildTradeCommonArgs: BuildTradeInputCommonArgs = {
Expand All @@ -176,7 +191,16 @@ export const useSwapper = () => {
slippage,
}
const sellAssetChainId = sellAsset.chainId
if (isSupportedNonUtxoSwappingChain(sellAssetChainId)) {
if (isSupportedCosmosSdkSwappingChain(sellAssetChainId)) {
const { accountNumber } = sellAccountBip44Params
const { accountNumber: receiveAccountNumber } = buyAccountBip44Params
return bestTradeSwapper.buildTrade({
...buildTradeCommonArgs,
chainId: sellAssetChainId,
accountNumber,
receiveAccountNumber,
})
} else if (isSupportedNonUtxoSwappingChain(sellAssetChainId)) {
const { accountNumber } = sellAccountBip44Params
return bestTradeSwapper.buildTrade({
...buildTradeCommonArgs,
Expand All @@ -201,18 +225,19 @@ export const useSwapper = () => {
})
}
}, [
sellAsset,
bestTradeSwapper,
sellTradeAsset?.amountCryptoPrecision,
sellTradeAsset?.asset,
buyTradeAsset?.asset,
isSendMax,
wallet,
receiveAddress,
sellAccountBip44Params,
sellAsset,
sellAssetAccountId,
sellAccountBip44Params,
buyAccountBip44Params,
sellAccountMetadata,
sellTradeAsset?.amountCryptoPrecision,
sellTradeAsset?.asset,
isSendMax,
slippage,
wallet,
])

// useEffects
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4196,10 +4196,10 @@
google-protobuf "^3.17.0"
long "^4.0.0"

"@shapeshiftoss/swapper@^17.3.0":
version "17.3.0"
resolved "https://registry.yarnpkg.com/@shapeshiftoss/swapper/-/swapper-17.3.0.tgz#d248f4f0d3436143effda1d187e38ff89f5b7062"
integrity sha512-GJvxts6N5RcSl7+hjanPiQ4AGbdrNqQ0zN/n6DvIeS8C/HJ8ogCWO8+ssxt14FJHj7y1rJtdv976Wu99H9Tszg==
"@shapeshiftoss/swapper@^17.3.1":
version "17.3.1"
resolved "https://registry.yarnpkg.com/@shapeshiftoss/swapper/-/swapper-17.3.1.tgz#97b4c94644b9c46eb031539dd9d6b9cf0eebef02"
integrity sha512-kWF4/hXPmiaozqT7vsZQIhKSvoeh2vuNvsUSpkVpcUHSE/TKYxdOso1Iy7bW8S6IWDUO1/2Wu7BqxNrA+V84bA==
dependencies:
axios "^0.26.1"
axios-cache-adapter "^2.7.3"
Expand Down