Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zcash buys to Exolix #352

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
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
Loading