Skip to content
Open
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
60 changes: 54 additions & 6 deletions src/swap/defi/rango.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
SwapBelowLimitError,
SwapCurrencyError
} from 'edge-core-js/types'
import { base64 } from 'rfc4648'

import { rango as rangoMapping } from '../../mappings/rango'
import { div18 } from '../../util/biggystringplus'
Expand Down Expand Up @@ -210,6 +211,11 @@ const asCosmosTransaction = asObject({
// expectedOutput: asOptional(asString) // Unused
})

const asSuiTransaction = asObject({
type: asValue('SUI'),
unsignedPtbBase64: asString
})

const asSwapResponse = asObject({
resultType: asRoutingResultType,
route: asEither(asSwapSimulationResult, asNull),
Expand All @@ -218,6 +224,7 @@ const asSwapResponse = asObject({
asEvmTransaction,
asSolanaTransaction,
asCosmosTransaction,
asSuiTransaction,
asNull
),
// Common tracking fields that might be in the response
Expand Down Expand Up @@ -552,6 +559,9 @@ export function makeRangoPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {

const preTxs: EdgeTransaction[] = []
let spendInfo: EdgeSpendInfo

const providersStr = providers?.join(' -> ')
const metadataNotes = `DEX Providers: ${providersStr}`

switch (tx.type) {
case 'SOLANA': {
Expand Down Expand Up @@ -656,9 +666,6 @@ export function makeRangoPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
txData: JSON.stringify(cosmosTransaction.data)
}

const providersStr = providers?.join(' -> ')
const metadataNotes = `DEX Providers: ${providersStr}`

// Return SwapOrder with makeTxParams directly (not spendInfo)
return {
expirationDate: new Date(Date.now() + EXPIRATION_MS),
Expand All @@ -672,6 +679,50 @@ export function makeRangoPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
}
}

case 'SUI': {
const { unsignedPtbBase64 } = asSuiTransaction(tx)
const unsignedTx = base64.parse(unsignedPtbBase64)

const makeTxParams: MakeTxParams = {
type: 'MakeTx',
unsignedTx,
metadata: {
assetAction: {
assetActionType: 'swap'
},
savedAction: {
actionType: 'swap',
swapInfo,
isEstimate: true,
toAsset: {
pluginId: toWallet.currencyInfo.pluginId,
tokenId: toTokenId,
nativeAmount: route.outputAmount
},
fromAsset: {
pluginId: fromWallet.currencyInfo.pluginId,
tokenId: fromTokenId,
nativeAmount
},
payoutAddress: toAddress,
payoutWalletId: toWallet.id,
refundAddress: fromAddress
}
}
}

return {
expirationDate: new Date(Date.now() + EXPIRATION_MS),
fromNativeAmount: nativeAmount,
metadataNotes,
minReceiveAmount: route.outputAmountMin,
preTxs,
request,
makeTxParams,
swapInfo
}
}

default: {
const evmTransaction = asEvmTransaction(tx)
if (evmTransaction.txData == null) {
Expand Down Expand Up @@ -745,9 +796,6 @@ export function makeRangoPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
}
}

const providersStr = providers?.join(' -> ')
const metadataNotes = `DEX Providers: ${providersStr}`

return {
expirationDate: new Date(Date.now() + EXPIRATION_MS),
fromNativeAmount: nativeAmount,
Expand Down