From c785490fc428221cfe8a84326a9385c3d23cd03b Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 15 Nov 2024 15:16:24 -0800 Subject: [PATCH] Add Zcash buys to Exolix --- CHANGELOG.md | 3 +++ src/swap/central/exolix.ts | 25 +++++++++++++++++++------ src/util/utils.ts | 22 +++++++++++++++++++--- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aa0c4ad..b764112c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/swap/central/exolix.ts b/src/swap/central/exolix.ts index 8092b41c..66cdf717 100644 --- a/src/swap/central/exolix.ts +++ b/src/swap/central/exolix.ts @@ -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' @@ -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 @@ -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 = diff --git a/src/util/utils.ts b/src/util/utils.ts index a0b8d21d..1bbcac67 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -179,11 +179,27 @@ export const convertRequest = ( return out } -export async function getAddress(wallet: EdgeCurrencyWallet): Promise { - const { publicAddress, segwitAddress } = await wallet.getReceiveAddress({ +export async function getAddress( + wallet: EdgeCurrencyWallet, + requiredAddressType?: string +): Promise { + 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 => {