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

chore: release v1.724.0 #8406

Merged
merged 17 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import {
ASSET_NAMESPACE,
CHAIN_NAMESPACE,
CHAIN_REFERENCE,
fromAssetId,
solAssetId,
toAssetId,
wrappedSolAssetId,
@@ -12,6 +13,7 @@ import type { KnownChainIds } from '@shapeshiftoss/types'
import { bn, bnOrZero, convertDecimalPercentageToBasisPoints } from '@shapeshiftoss/utils'
import type { Result } from '@sniptt/monads'
import { Err, Ok } from '@sniptt/monads'
import { PublicKey } from '@solana/web3.js'
import { v4 as uuid } from 'uuid'

import type {
@@ -23,7 +25,7 @@ import type {
} from '../../../types'
import { SwapperName, TradeQuoteError } from '../../../types'
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils'
import { JUPITER_COMPUTE_UNIT_MARGIN_MULTIPLIER } from '../utils/constants'
import { JUPITER_COMPUTE_UNIT_MARGIN_MULTIPLIER, TOKEN_2022_PROGRAM_ID } from '../utils/constants'
import {
calculateAccountCreationCosts,
createSwapInstructions,
@@ -38,7 +40,7 @@ export const getTradeQuote = async (
const {
sellAsset,
buyAsset,
affiliateBps,
affiliateBps: _affiliateBps,
receiveAddress,
accountNumber,
sendAddress,
@@ -99,10 +101,31 @@ export const getTradeQuote = async (
)
}

const adapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId)

const buyAssetAddress =
buyAsset.assetId === solAssetId
? fromAssetId(wrappedSolAssetId).assetReference
: fromAssetId(buyAsset.assetId).assetReference

const sellAssetAddress =
sellAsset.assetId === solAssetId
? fromAssetId(wrappedSolAssetId).assetReference
: fromAssetId(sellAsset.assetId).assetReference

const sellTokenInfo = await adapter
.getConnection()
.getAccountInfo(new PublicKey(sellAssetAddress))
const buyTokenInfo = await adapter.getConnection().getAccountInfo(new PublicKey(buyAssetAddress))
const isSellTokenToken2022 = sellTokenInfo?.owner.toString() === TOKEN_2022_PROGRAM_ID.toString()
const isBuyTokenToken2022 = buyTokenInfo?.owner.toString() === TOKEN_2022_PROGRAM_ID.toString()

const affiliateBps = isSellTokenToken2022 && isBuyTokenToken2022 ? '0' : _affiliateBps

const maybePriceResponse = await getJupiterPrice({
apiUrl: jupiterUrl,
sourceAsset: sellAsset.assetId === solAssetId ? wrappedSolAssetId : sellAsset.assetId,
destinationAsset: buyAsset.assetId === solAssetId ? wrappedSolAssetId : buyAsset.assetId,
sourceAssetAddress: sellAssetAddress,
destinationAssetAddress: buyAssetAddress,
commissionBps: affiliateBps,
amount: sellAmount,
slippageBps: _slippageTolerancePercentageDecimal
@@ -126,8 +149,6 @@ export const getTradeQuote = async (
// e.g for 0.5% bps, Jupiter represents this as 50. 50/100 = 0.5, then we div by 100 again to honour our decimal format e.g 0.5/100 = 0.005
bn(priceResponse.slippageBps).div(100).div(100).toString()

const adapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId)

const { instructions, addressLookupTableAddresses } = await createSwapInstructions({
priceResponse,
sendAddress,
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import type { KnownChainIds } from '@shapeshiftoss/types'
import { bn, bnOrZero, convertDecimalPercentageToBasisPoints } from '@shapeshiftoss/utils'
import type { Result } from '@sniptt/monads'
import { Err, Ok } from '@sniptt/monads'
import { PublicKey } from '@solana/web3.js'
import { v4 as uuid } from 'uuid'

import type {
@@ -24,7 +25,7 @@ import type {
} from '../../../types'
import { SwapperName, TradeQuoteError } from '../../../types'
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils'
import { SOLANA_RANDOM_ADDRESS } from '../utils/constants'
import { SOLANA_RANDOM_ADDRESS, TOKEN_2022_PROGRAM_ID } from '../utils/constants'
import {
calculateAccountCreationCosts,
createSwapInstructions,
@@ -40,7 +41,7 @@ export const getTradeRate = async (
sellAsset,
buyAsset,
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount,
affiliateBps,
affiliateBps: _affiliateBps,
receiveAddress,
accountNumber,
slippageTolerancePercentageDecimal: _slippageTolerancePercentageDecimal,
@@ -90,10 +91,31 @@ export const getTradeRate = async (
)
}

const adapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId)

const buyAssetAddress =
buyAsset.assetId === solAssetId
? fromAssetId(wrappedSolAssetId).assetReference
: fromAssetId(buyAsset.assetId).assetReference

const sellAssetAddress =
sellAsset.assetId === solAssetId
? fromAssetId(wrappedSolAssetId).assetReference
: fromAssetId(sellAsset.assetId).assetReference

const sellTokenInfo = await adapter
.getConnection()
.getAccountInfo(new PublicKey(sellAssetAddress))
const buyTokenInfo = await adapter.getConnection().getAccountInfo(new PublicKey(buyAssetAddress))
const isSellTokenToken2022 = sellTokenInfo?.owner.toString() === TOKEN_2022_PROGRAM_ID.toString()
const isBuyTokenToken2022 = buyTokenInfo?.owner.toString() === TOKEN_2022_PROGRAM_ID.toString()

const affiliateBps = isSellTokenToken2022 && isBuyTokenToken2022 ? '0' : _affiliateBps

const maybePriceResponse = await getJupiterPrice({
apiUrl: jupiterUrl,
sourceAsset: sellAsset.assetId === solAssetId ? wrappedSolAssetId : sellAsset.assetId,
destinationAsset: buyAsset.assetId === solAssetId ? wrappedSolAssetId : buyAsset.assetId,
sourceAssetAddress: sellAssetAddress,
destinationAssetAddress: buyAssetAddress,
commissionBps: affiliateBps,
amount: sellAmount,
slippageBps: _slippageTolerancePercentageDecimal
@@ -130,8 +152,6 @@ export const getTradeRate = async (
return { networkFeeCryptoBaseUnit: fast.txFee }
}

const adapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId)

const protocolFees: Record<AssetId, ProtocolFee> = priceResponse.routePlan.reduce(
(acc, route) => {
const feeAssetId = toAssetId({
12 changes: 6 additions & 6 deletions packages/swapper/src/swappers/JupiterSwapper/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@ const JUPITER_TRANSACTION_MAX_ACCOUNTS = 54

type GetJupiterQuoteArgs = {
apiUrl: string
sourceAsset: string
destinationAsset: string
sourceAssetAddress: string
destinationAssetAddress: string
commissionBps: string
amount: string
slippageBps: string | undefined
@@ -60,16 +60,16 @@ type CreateInstructionsParams = {

export const getJupiterPrice = ({
apiUrl,
sourceAsset,
destinationAsset,
sourceAssetAddress,
destinationAssetAddress,
commissionBps,
amount,
slippageBps,
}: GetJupiterQuoteArgs): Promise<Result<AxiosResponse<QuoteResponse, any>, SwapErrorRight>> =>
jupiterService.get<QuoteResponse>(
`${apiUrl}/quote` +
`?inputMint=${fromAssetId(sourceAsset).assetReference}` +
`&outputMint=${fromAssetId(destinationAsset).assetReference}` +
`?inputMint=${sourceAssetAddress}` +
`&outputMint=${destinationAssetAddress}` +
`&amount=${amount}` +
(slippageBps ? `&slippageBps=${slippageBps}` : `&autoSlippage=true`) +
`&maxAccounts=${JUPITER_TRANSACTION_MAX_ACCOUNTS}` +
2 changes: 2 additions & 0 deletions src/state/slices/tradeQuoteSlice/selectors.ts
Original file line number Diff line number Diff line change
@@ -566,6 +566,8 @@ export const selectTradeQuoteAffiliateFeeAfterDiscountUsd = createSelector(
selectActiveQuoteAffiliateBps,
(calculatedFees, affiliateBps) => {
if (!affiliateBps) return
if (affiliateBps === '0') return bn(0)

return calculatedFees.feeUsd
},
)