Skip to content

Commit

Permalink
Add Zcash buys to Exolix
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Nov 15, 2024
1 parent c6745e8 commit bee788d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- added: (Exolix) Support Zcash buys
- changed: Upgrade edge-core-js

## 2.14.0 (2024-11-11)

- changed: Rename Thorchain DEX Aggregator to SwapKit
Expand Down
27 changes: 20 additions & 7 deletions src/swap/central/exolix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ import {
getAddress,
memoType
} from '../../util/utils'
import { asRatesResponse, EdgeSwapRequestPlugin, RatesRespose } from '../types'
import {
asRatesResponse,
EdgeSwapRequestPlugin,
RatesRespose,
StringMap
} from '../types'

const pluginId = 'exolix'

Expand All @@ -56,9 +61,11 @@ const asInitOptions = asObject({
const MAX_USD_VALUE = '70000'
const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
from: {},
to: {
zcash: ['ZEC']
}
to: {}
}

const addressTypeMap: StringMap = {
zcash: 'transparentAddress'
}

// See https://exolix.com/currencies for list of supported currencies
Expand Down Expand Up @@ -203,10 +210,16 @@ export function makeExolixPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
}

const [fromAddress, toAddress] = await Promise.all([
getAddress(request.fromWallet),
getAddress(request.toWallet)
getAddress(
request.fromWallet,
addressTypeMap[request.fromWallet.currencyInfo.pluginId]
),
getAddress(
request.toWallet,
addressTypeMap[request.toWallet.currencyInfo.pluginId]
)
])

log.warn('in exolix address:', fromAddress, toAddress)
const exchangeQuoteAmount =
request.quoteFor === 'from'
? await request.fromWallet.nativeToDenomination(
Expand Down
22 changes: 19 additions & 3 deletions src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,27 @@ export const convertRequest = (
return out
}

export async function getAddress(wallet: EdgeCurrencyWallet): Promise<string> {
const { publicAddress, segwitAddress } = await wallet.getReceiveAddress({
export async function getAddress(
wallet: EdgeCurrencyWallet,
requiredAddressType?: string
): Promise<string> {
const allAddresses = await wallet.getAddresses({
tokenId: null
})
return segwitAddress ?? publicAddress

if (requiredAddressType != null) {
const address = allAddresses.find(
address => address.addressType === requiredAddressType
)
if (address != null) return address.publicAddress
else throw new Error(`No address of type ${requiredAddressType}`)
}

const segwitAddress = allAddresses.find(
address => address.addressType === 'segwitAddress'
)

return (segwitAddress ?? allAddresses[0]).publicAddress
}

export const hexToDecimal = (hex: string): string => {
Expand Down

0 comments on commit bee788d

Please sign in to comment.