Skip to content
Merged
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

- changed: Replace wallet denomination methods with synchronous utils
- changed: Use tokenIds in invalid currency objects

## 2.40.0 (2025-12-04)

- added: (Maya) Zcash support
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"chai": "^4.2.0",
"cleaner-config": "^0.1.10",
"crypto-browserify": "^3.12.0",
"edge-core-js": "^2.34.0",
"edge-core-js": "^2.37.0",
"edge-currency-accountbased": "^2.9.0",
"edge-currency-plugins": "^2.4.1",
"esbuild-loader": "^2.20.0",
Expand Down
58 changes: 36 additions & 22 deletions src/swap/central/changehero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ import {

import {
ChainCodeTickerMap,
checkInvalidCodes,
checkInvalidTokenIds,
checkWhitelistedMainnetCodes,
CurrencyPluginIdSwapChainCodeMap,
getChainAndTokenCodes,
getMaxSwappable,
InvalidCurrencyCodes,
InvalidTokenIds,
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import {
convertRequest,
denominationToNative,
getAddress,
memoType,
nativeToDenomination
} from '../../util/utils'
import { EdgeSwapRequestPlugin } from '../types'

const pluginId = 'changehero'
Expand Down Expand Up @@ -117,10 +123,10 @@ export const MAINNET_CODE_TRANSCRIPTION: CurrencyPluginIdSwapChainCodeMap = {

// See https://changehero.io/currencies for list of supported currencies
// Or `curl -X POST 'https://api.changehero.io/v2' -H 'api-key: <your-api-key>' -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"one","method":"getCurrenciesFull","params":{}}'`
const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
const INVALID_TOKEN_IDS: InvalidTokenIds = {
from: {},
to: {
zcash: ['ZEC'] // ChangeHero doesn't support sending to shielded addresses
zcash: [null] // ChangeHero doesn't support sending to shielded addresses
}
}

Expand Down Expand Up @@ -255,13 +261,15 @@ export function makeChangeHeroPlugin(

const quoteAmount =
request.quoteFor === 'from'
? await request.fromWallet.nativeToDenomination(
? nativeToDenomination(
request.fromWallet,
request.nativeAmount,
request.fromCurrencyCode
request.fromTokenId
)
: await request.toWallet.nativeToDenomination(
: nativeToDenomination(
request.toWallet,
request.nativeAmount,
request.toCurrencyCode
request.toTokenId
)

const fixRate = {
Expand All @@ -282,21 +290,25 @@ export function makeChangeHeroPlugin(
const [
{ id: responseId, maxFrom, maxTo, minFrom, minTo }
] = asGetFixRateReply(fixedRateQuote).result
const maxFromNative = await request.fromWallet.denominationToNative(
const maxFromNative = denominationToNative(
request.fromWallet,
maxFrom,
request.fromCurrencyCode
request.fromTokenId
)
const maxToNative = await request.toWallet.denominationToNative(
const maxToNative = denominationToNative(
request.toWallet,
maxTo,
request.toCurrencyCode
request.toTokenId
)
const minFromNative = await request.fromWallet.denominationToNative(
const minFromNative = denominationToNative(
request.fromWallet,
minFrom,
request.fromCurrencyCode
request.fromTokenId
)
const minToNative = await request.toWallet.denominationToNative(
const minToNative = denominationToNative(
request.toWallet,
minTo,
request.toCurrencyCode
request.toTokenId
)

if (request.quoteFor === 'from') {
Expand Down Expand Up @@ -356,13 +368,15 @@ export function makeChangeHeroPlugin(
checkReply(sendReply, request)

const quoteInfo = asCreateFixTransactionReply(sendReply).result
const amountExpectedFromNative = await request.fromWallet.denominationToNative(
const amountExpectedFromNative = denominationToNative(
request.fromWallet,
`${quoteInfo.amountExpectedFrom.toString()}`,
request.fromCurrencyCode
request.fromTokenId
)
const amountExpectedToNative = await request.toWallet.denominationToNative(
const amountExpectedToNative = denominationToNative(
request.toWallet,
`${quoteInfo.amountExpectedTo.toString()}`,
request.toCurrencyCode
request.toTokenId
)

const memos: EdgeMemo[] =
Expand Down Expand Up @@ -427,7 +441,7 @@ export function makeChangeHeroPlugin(
// Fetch and persist chaincode/tokencode maps from provider
await fetchSupportedAssets()

checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
checkInvalidTokenIds(INVALID_TOKEN_IDS, request, swapInfo)
checkWhitelistedMainnetCodes(
MAINNET_CODE_TRANSCRIPTION,
request,
Expand Down
46 changes: 29 additions & 17 deletions src/swap/central/changenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ import {

import {
ChainCodeTickerMap,
checkInvalidCodes,
checkInvalidTokenIds,
checkWhitelistedMainnetCodes,
CurrencyPluginIdSwapChainCodeMap,
EdgeIdSwapIdMap,
ensureInFuture,
getChainAndTokenCodes,
getMaxSwappable,
InvalidCurrencyCodes,
InvalidTokenIds,
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import {
convertRequest,
denominationToNative,
getAddress,
memoType,
nativeToDenomination
} from '../../util/utils'
import { EdgeSwapRequestPlugin, StringMap } from '../types'

const pluginId = 'changenow'
Expand All @@ -56,7 +62,7 @@ const asInitOptions = asObject({
const orderUri = 'https://changenow.io/exchange/txs/'
const uri = 'https://api.changenow.io/v2/'

const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
const INVALID_TOKEN_IDS: InvalidTokenIds = {
from: {},
to: {}
}
Expand Down Expand Up @@ -282,9 +288,10 @@ export function makeChangeNowPlugin(
async function swapSell(
flow: 'fixed-rate' | 'standard'
): Promise<SwapOrder> {
const largeDenomAmount = await request.fromWallet.nativeToDenomination(
const largeDenomAmount = nativeToDenomination(
request.fromWallet,
nativeAmount,
request.fromCurrencyCode
request.fromTokenId
)

// Get min and max
Expand All @@ -300,17 +307,19 @@ export function makeChangeNowPlugin(
const { minAmount, maxAmount } = asMarketRange(marketRangeResponseJson)

if (lt(largeDenomAmount, minAmount.toString())) {
const minNativeAmount = await request.fromWallet.denominationToNative(
const minNativeAmount = denominationToNative(
request.fromWallet,
minAmount.toString(),
request.fromCurrencyCode
request.fromTokenId
)
throw new SwapBelowLimitError(swapInfo, minNativeAmount)
}

if (maxAmount != null && gt(largeDenomAmount, maxAmount.toString())) {
const maxNativeAmount = await request.fromWallet.denominationToNative(
const maxNativeAmount = denominationToNative(
request.fromWallet,
maxAmount.toString(),
request.fromCurrencyCode
request.fromTokenId
)
throw new SwapAboveLimitError(swapInfo, maxNativeAmount)
}
Expand All @@ -323,9 +332,10 @@ export function makeChangeNowPlugin(
validUntil
} = await createOrder(flow, true, largeDenomAmount)

const toNativeAmount = await request.toWallet.denominationToNative(
const toNativeAmount = denominationToNative(
request.toWallet,
toAmount.toString(),
request.toCurrencyCode
request.toTokenId
)

const memos: EdgeMemo[] =
Expand Down Expand Up @@ -387,9 +397,10 @@ export function makeChangeNowPlugin(

async function swapBuy(flow: 'fixed-rate'): Promise<SwapOrder> {
// Skip min/max check when requesting a purchase amount
const largeDenomAmount = await request.toWallet.nativeToDenomination(
const largeDenomAmount = nativeToDenomination(
request.toWallet,
nativeAmount,
request.toCurrencyCode
request.toTokenId
)

const {
Expand All @@ -400,9 +411,10 @@ export function makeChangeNowPlugin(
validUntil
} = await createOrder(flow, false, largeDenomAmount)

const fromNativeAmount = await request.fromWallet.denominationToNative(
const fromNativeAmount = denominationToNative(
request.fromWallet,
fromAmount.toString(),
request.fromCurrencyCode
request.fromTokenId
)

const memos: EdgeMemo[] =
Expand Down Expand Up @@ -494,7 +506,7 @@ export function makeChangeNowPlugin(
// Fetch and persist chaincode/tokencode maps from provider
await fetchSupportedAssets()

checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
checkInvalidTokenIds(INVALID_TOKEN_IDS, request, swapInfo)
checkWhitelistedMainnetCodes(
MAINNET_CODE_TRANSCRIPTION,
request,
Expand Down
Loading
Loading