Skip to content

Commit

Permalink
Merge branch 'develop' into fix-order-list-sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Jan 7, 2025
2 parents 79b1b16 + 1b2fac1 commit 67605cb
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 64 deletions.
32 changes: 22 additions & 10 deletions packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ export const thorchainApi: SwapperApi = {
case TradeType.LongTailToL1: {
assert(aggregator, 'aggregator required for thorchain longtail to l1 swaps')

const expectedAmountOut = longtailData?.longtailToL1ExpectedAmountOut ?? 0n
const expectedAmountOut = longtailData?.longtailToL1ExpectedAmountOut ?? '0'
// Paranoia assertion - expectedAmountOut should never be 0 as it would likely lead to a loss of funds.
assert(expectedAmountOut > 0n, 'expected expectedAmountOut to be a positive amount')
assert(
bnOrZero(expectedAmountOut).gt(0),
'expected expectedAmountOut to be a positive amount',
)

const amountOutMin = BigInt(
bnOrZero(expectedAmountOut.toString())
bnOrZero(expectedAmountOut)
.times(bn(1).minus(slippageTolerancePercentageDecimal ?? 0))
.toFixed(0, BigNumber.ROUND_UP),
)
Expand Down Expand Up @@ -198,9 +201,12 @@ export const thorchainApi: SwapperApi = {
}
}
case TradeType.L1ToLongTail:
const expectedAmountOut = longtailData?.L1ToLongtailExpectedAmountOut ?? 0n
const expectedAmountOut = longtailData?.L1ToLongtailExpectedAmountOut ?? '0'
// Paranoia assertion - expectedAmountOut should never be 0 as it would likely lead to a loss of funds.
assert(expectedAmountOut > 0n, 'expected expectedAmountOut to be a positive amount')
assert(
bnOrZero(expectedAmountOut).gt(0),
'expected expectedAmountOut to be a positive amount',
)

const { router: updatedRouter } = await getEvmThorTxInfo({
sellAsset,
Expand Down Expand Up @@ -308,12 +314,15 @@ export const thorchainApi: SwapperApi = {
case TradeType.LongTailToL1: {
assert(aggregator, 'aggregator required for thorchain longtail to l1 swaps')

const expectedAmountOut = longtailData?.longtailToL1ExpectedAmountOut ?? 0n
const expectedAmountOut = longtailData?.longtailToL1ExpectedAmountOut ?? '0'
// Paranoia assertion - expectedAmountOut should never be 0 as it would likely lead to a loss of funds.
assert(expectedAmountOut > 0n, 'expected expectedAmountOut to be a positive amount')
assert(
bnOrZero(expectedAmountOut).gt(0),
'expected expectedAmountOut to be a positive amount',
)

const amountOutMin = BigInt(
bnOrZero(expectedAmountOut.toString())
bnOrZero(expectedAmountOut)
.times(bn(1).minus(slippageTolerancePercentageDecimal ?? 0))
.toFixed(0, BigNumber.ROUND_UP),
)
Expand Down Expand Up @@ -349,9 +358,12 @@ export const thorchainApi: SwapperApi = {
return networkFeeCryptoBaseUnit
}
case TradeType.L1ToLongTail:
const expectedAmountOut = longtailData?.L1ToLongtailExpectedAmountOut ?? 0n
const expectedAmountOut = longtailData?.L1ToLongtailExpectedAmountOut
// Paranoia assertion - expectedAmountOut should never be 0 as it would likely lead to a loss of funds.
assert(expectedAmountOut > 0n, 'expected expectedAmountOut to be a positive amount')
assert(
bnOrZero(expectedAmountOut).gt(0),
'expected expectedAmountOut to be a positive amount',
)

const { router: updatedRouter } = await getEvmThorTxInfo({
sellAsset,
Expand Down
4 changes: 2 additions & 2 deletions packages/swapper/src/swappers/ThorchainSwapper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ type ThorTradeQuoteSpecificMetadata = {
tradeType: TradeType
expiry: number
longtailData?: {
longtailToL1ExpectedAmountOut?: bigint
L1ToLongtailExpectedAmountOut?: bigint
longtailToL1ExpectedAmountOut?: string
L1ToLongtailExpectedAmountOut?: string
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export const getCallDataFromQuote = async ({
return data
}
case TradeType.LongTailToL1: {
const expectedAmountOut = longtailData?.longtailToL1ExpectedAmountOut ?? 0n
const expectedAmountOut = longtailData?.longtailToL1ExpectedAmountOut ?? '0'
const amountOutMin = BigInt(
bnOrZero(expectedAmountOut.toString())
bnOrZero(expectedAmountOut)
.times(bn(1).minus(slippageTolerancePercentageDecimal ?? 0))
.toFixed(0, BigNumber.ROUND_UP),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const getL1ToLongtailQuote = async (
})) as MultiHopTradeQuoteSteps, // assuming multi-hop quote steps here since we're mapping over quote steps,
isLongtail: true,
longtailData: {
L1ToLongtailExpectedAmountOut: quotedAmountOut,
L1ToLongtailExpectedAmountOut: quotedAmountOut.toString(),
},
})
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const getL1ToLongtailRate = async (
})) as MultiHopTradeRateSteps, // assuming multi-hop rate steps here since we're mapping over quote steps,
isLongtail: true,
longtailData: {
L1ToLongtailExpectedAmountOut: quotedAmountOut,
L1ToLongtailExpectedAmountOut: quotedAmountOut.toString(),
},
})
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,24 @@ export const getLongtailToL1Quote = async (
)

return thorchainQuotes.andThen(quotes => {
const updatedQuotes: ThorTradeQuote[] = quotes.map(q => ({
...q,
aggregator: bestAggregator,
// This logic will need to be updated to support multi-hop, if that's ever implemented for THORChain
steps: q.steps.map(s => ({
...s,
sellAmountIncludingProtocolFeesCryptoBaseUnit,
sellAsset,
allowanceContract: TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET,
})) as MultiHopTradeQuoteSteps, // assuming multi-hop quote steps here since we're mapping over quote steps
isLongtail: true,
longtailData: {
longtailToL1ExpectedAmountOut: quotedAmountOut,
},
}))
const updatedQuotes = quotes.map(
q =>
({
...q,
aggregator: bestAggregator,
// This logic will need to be updated to support multi-hop, if that's ever implemented for THORChain
steps: q.steps.map(s => ({
...s,
sellAmountIncludingProtocolFeesCryptoBaseUnit,
sellAsset,
allowanceContract: TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET,
})) as MultiHopTradeQuoteSteps, // assuming multi-hop quote steps here since we're mapping over quote steps
isLongtail: true,
longtailData: {
longtailToL1ExpectedAmountOut: quotedAmountOut.toString(),
},
}) satisfies ThorTradeQuote,
)

return Ok(updatedQuotes)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const getLongtailToL1Rate = async (
})) as MultiHopTradeRateSteps, // assuming multi-hop quote steps here since we're mapping over quote steps
isLongtail: true,
longtailData: {
longtailToL1ExpectedAmountOut: quotedAmountOut,
longtailToL1ExpectedAmountOut: quotedAmountOut.toString(),
},
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type ExpandableStepperStepsProps = {
isExpanded?: boolean
}

export const ExpandableStepperSteps = (props: ExpandableStepperStepsProps) => {
const [isExpanded, setIsExpanded] = useState(false)
export const ExpandableStepperSteps = ({
isExpanded: initialIsExpanded = false,
}: ExpandableStepperStepsProps) => {
const [isExpanded, setIsExpanded] = useState(initialIsExpanded)
const confirmedTradeExecutionState = useAppSelector(selectConfirmedTradeExecutionState)
const summaryStepProps = useMemo(
() => ({
Expand Down Expand Up @@ -104,7 +106,7 @@ export const ExpandableStepperSteps = (props: ExpandableStepperStepsProps) => {
stepProps={summaryStepProps}
useSpacer={false}
/>
<Collapse in={props.isExpanded ?? isExpanded} style={collapseStyle}>
<Collapse in={isExpanded} style={collapseStyle}>
<Box py={4} pl={0}>
{activeTradeQuote && <ExpandedStepperSteps activeTradeQuote={activeTradeQuote} />}
</Box>
Expand Down
Loading

0 comments on commit 67605cb

Please sign in to comment.