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 20, 2024
1 parent c6745e8 commit c785490
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 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
25 changes: 19 additions & 6 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,8 +210,14 @@ 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]
)
])

const exchangeQuoteAmount =
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 c785490

Please sign in to comment.