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

Upgrade to edge-core-js v0.19.33 #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"buffer": "^6.0.3",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"edge-core-js": "^0.19.29",
"edge-core-js": "^0.19.33",
"eslint": "^7.14.0",
"eslint-config-standard-kit": "0.15.1",
"eslint-plugin-flowtype": "^5.2.0",
Expand Down
21 changes: 14 additions & 7 deletions src/swap-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
SwapCurrencyError
} from 'edge-core-js/types'

import { fixRequest } from './util/utils'

const likeKindAssets = [
['BTC', 'WBTC', 'SBTC', 'RBTC'],
['ETH', 'WETH'],
Expand Down Expand Up @@ -53,6 +55,7 @@ export function makeSwapPluginQuote(
)

const out: EdgeSwapQuote = {
request,
fromNativeAmount,
toNativeAmount,
networkFee: {
Expand Down Expand Up @@ -100,12 +103,15 @@ interface AllCodes {
toCurrencyCode: string
}

export const getCodes = (request: EdgeSwapRequest): AllCodes => ({
fromMainnetCode: request.fromWallet.currencyInfo.currencyCode,
toMainnetCode: request.toWallet.currencyInfo.currencyCode,
fromCurrencyCode: request.fromCurrencyCode,
toCurrencyCode: request.toCurrencyCode
})
export const getCodes = (rawRequest: EdgeSwapRequest): AllCodes => {
const request = fixRequest(rawRequest)
return {
fromMainnetCode: request.fromWallet.currencyInfo.currencyCode,
toMainnetCode: request.toWallet.currencyInfo.currencyCode,
fromCurrencyCode: request.fromCurrencyCode,
toCurrencyCode: request.toCurrencyCode
}
}

const getPluginIds = (
request: EdgeSwapRequest
Expand All @@ -129,9 +135,10 @@ const defaultInvalidCodes: InvalidCurrencyCodes = {
*/
export function checkInvalidCodes(
invalidCodes: InvalidCurrencyCodes,
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
swapInfo: EdgeSwapInfo
): void {
const request = fixRequest(rawRequest)
const { fromPluginId, toPluginId } = getPluginIds(request)
const {
fromMainnetCode,
Expand Down
10 changes: 7 additions & 3 deletions src/swap/changehero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
InvalidCurrencyCodes,
makeSwapPluginQuote
} from '../swap-helpers'
import { fixRequest } from '../util/utils'

const pluginId = 'changehero'

Expand Down Expand Up @@ -96,8 +97,9 @@ async function getAddress(

function checkReply(
reply: { error?: { code?: number; message?: string } },
request: EdgeSwapRequest
rawRequest: EdgeSwapRequest
): void {
const request = fixRequest(rawRequest)
if (reply.error != null) {
if (
reply.error.code === -32602 ||
Expand Down Expand Up @@ -135,8 +137,9 @@ export function makeChangeHeroPlugin(
}

async function getFixedQuote(
request: EdgeSwapRequest
rawRequest: EdgeSwapRequest
): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
const [fromAddress, toAddress] = await Promise.all([
getAddress(request.fromWallet, request.fromCurrencyCode),
getAddress(request.toWallet, request.toCurrencyCode)
Expand Down Expand Up @@ -299,7 +302,8 @@ export function makeChangeHeroPlugin(

const out: EdgeSwapPlugin = {
swapInfo,
async fetchSwapQuote(request: EdgeSwapRequest): Promise<EdgeSwapQuote> {
async fetchSwapQuote(rawRequest: EdgeSwapRequest): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
return await getFixedQuote(request)
}
Expand Down
4 changes: 3 additions & 1 deletion src/swap/changenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
InvalidCurrencyCodes,
makeSwapPluginQuote
} from '../swap-helpers'
import { fixRequest } from '../util/utils'
const pluginId = 'changenow'

const swapInfo: EdgeSwapInfo = {
Expand Down Expand Up @@ -87,10 +88,11 @@ export function makeChangeNowPlugin(
swapInfo,

async fetchSwapQuote(
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
userSettings: Object | undefined,
opts: { promoCode?: string }
): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
const { promoCode } = opts

checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
Expand Down
10 changes: 8 additions & 2 deletions src/swap/defi/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import {
isLikeKind,
makeSwapPluginQuote
} from '../../swap-helpers'
import { fetchInfo, fetchWaterfall, promiseWithTimeout } from '../../util/utils'
import {
fetchInfo,
fetchWaterfall,
fixRequest,
promiseWithTimeout
} from '../../util/utils'
import abi from './abi/THORCHAIN_SWAP_ABI'
import erc20Abi from './abi/UNISWAP_V2_ERC20_ABI'

Expand Down Expand Up @@ -149,7 +154,8 @@ export function makeThorchainPlugin(
const out: EdgeSwapPlugin = {
swapInfo,

async fetchSwapQuote(request: EdgeSwapRequest): Promise<EdgeSwapQuote> {
async fetchSwapQuote(rawRequest: EdgeSwapRequest): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
const {
fromCurrencyCode,
toCurrencyCode,
Expand Down
4 changes: 3 additions & 1 deletion src/swap/defi/thorchainDa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import {
fetchInfo,
fetchWaterfall,
fixRequest,
makeQueryParams,
promiseWithTimeout
} from '../../util/utils'
Expand Down Expand Up @@ -130,7 +131,8 @@ export function makeThorchainDaPlugin(
const out: EdgeSwapPlugin = {
swapInfo,

async fetchSwapQuote(request: EdgeSwapRequest): Promise<EdgeSwapQuote> {
async fetchSwapQuote(rawRequest: EdgeSwapRequest): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
const {
fromCurrencyCode,
toCurrencyCode,
Expand Down
4 changes: 3 additions & 1 deletion src/swap/defi/uni-v2-based/plugins/spookySwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'edge-core-js/types'
import { ethers } from 'ethers'

import { fixRequest } from '../../../../util/utils'
import { getInOutTokenAddresses } from '../../defiUtils'
import { getFtmProvider, makeSpookySwapRouterContract } from '../uniV2Contracts'
import {
Expand Down Expand Up @@ -39,7 +40,8 @@ export function makeSpookySwapPlugin(

const out: EdgeSwapPlugin = {
swapInfo,
async fetchSwapQuote(request: EdgeSwapRequest): Promise<EdgeSwapQuote> {
async fetchSwapQuote(rawRequest: EdgeSwapRequest): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
const {
fromWallet,
toWallet,
Expand Down
4 changes: 3 additions & 1 deletion src/swap/defi/uni-v2-based/plugins/tombSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'edge-core-js/types'
import { ethers } from 'ethers'

import { fixRequest } from '../../../../util/utils'
import { getInOutTokenAddresses } from '../../defiUtils'
import { getFtmProvider, makeTombSwapRouterContract } from '../uniV2Contracts'
import {
Expand Down Expand Up @@ -39,7 +40,8 @@ export function makeTombSwapPlugin(

const out: EdgeSwapPlugin = {
swapInfo,
async fetchSwapQuote(request: EdgeSwapRequest): Promise<EdgeSwapQuote> {
async fetchSwapQuote(rawRequest: EdgeSwapRequest): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
const {
fromWallet,
toWallet,
Expand Down
5 changes: 4 additions & 1 deletion src/swap/defi/uni-v2-based/uniV2Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { BigNumber, Contract, ethers, PopulatedTransaction } from 'ethers'

import { round } from '../../../util/biggystringplus'
import { fixRequest } from '../../../util/utils'
import { getMetaTokenAddress } from '../defiUtils'
import { makeErc20Contract, makeWrappedFtmContract } from './uniV2Contracts'
/**
Expand Down Expand Up @@ -44,14 +45,15 @@ export const getSwapAmounts = async (
*/
export const getSwapTransactions = async (
provider: ethers.providers.Provider,
swapRequest: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
router: Contract,
amountToSwap: string,
expectedAmountOut: string,
toAddress: string,
slippage: string,
deadline: number
): Promise<PopulatedTransaction[]> => {
const swapRequest = fixRequest(rawRequest)
const { fromWallet, fromCurrencyCode, toCurrencyCode } = swapRequest
const {
currencyCode: nativeCurrencyCode,
Expand Down Expand Up @@ -192,6 +194,7 @@ export function makeUniV2EdgeSwapQuote(
const swapTx = txs[txs.length - 1]

const out: EdgeSwapQuote = {
request,
fromNativeAmount,
toNativeAmount,
networkFee: {
Expand Down
7 changes: 5 additions & 2 deletions src/swap/exolix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
InvalidCurrencyCodes,
makeSwapPluginQuote
} from '../swap-helpers'
import { fixRequest } from '../util/utils'

const pluginId = 'exolix'

Expand Down Expand Up @@ -113,9 +114,10 @@ export function makeExolixPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const out: EdgeSwapPlugin = {
swapInfo,
async fetchSwapQuote(
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
userSettings: Object | undefined
): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)

const fixedPromise = getFixedQuote(request, userSettings)
Expand All @@ -126,9 +128,10 @@ export function makeExolixPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
}

const getFixedQuote = async (
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
_userSettings: Object | undefined
): Promise<EdgeSwapQuote> => {
const request = fixRequest(rawRequest)
const [fromAddress, toAddress] = await Promise.all([
getAddress(request.fromWallet, request.fromCurrencyCode),
getAddress(request.toWallet, request.toCurrencyCode)
Expand Down
7 changes: 5 additions & 2 deletions src/swap/godex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
InvalidCurrencyCodes,
makeSwapPluginQuote
} from '../swap-helpers'
import { fixRequest } from '../util/utils'

const pluginId = 'godex'

Expand Down Expand Up @@ -113,9 +114,10 @@ export function makeGodexPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {

async function call(
url: string,
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
data: { params: JsonObject }
): Promise<JsonObject> {
const request = fixRequest(rawRequest)
const body = JSON.stringify(data.params)

const headers = {
Expand All @@ -140,10 +142,11 @@ export function makeGodexPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
swapInfo,

async fetchSwapQuote(
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
userSettings: Object | undefined,
opts: { promoCode?: string }
): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
const reverseQuote = request.quoteFor === 'to'

Expand Down
7 changes: 5 additions & 2 deletions src/swap/letsexchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
InvalidCurrencyCodes,
makeSwapPluginQuote
} from '../swap-helpers'
import { fixRequest } from '../util/utils'
import { asOptionalBlank } from './changenow'

const pluginId = 'letsexchange'
Expand Down Expand Up @@ -93,9 +94,10 @@ export function makeLetsExchangePlugin(

async function call(
url: string,
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
data: { params: Object }
): Promise<Object> {
const request = fixRequest(rawRequest)
const body = JSON.stringify(data.params)

const headers = {
Expand All @@ -121,10 +123,11 @@ export function makeLetsExchangePlugin(
swapInfo,

async fetchSwapQuote(
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
userSettings: Object | undefined,
opts: { promoCode?: string }
): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
const reverseQuote = request.quoteFor === 'to'

Expand Down
7 changes: 5 additions & 2 deletions src/swap/sideshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getCodesWithTranscription,
makeSwapPluginQuote
} from '../swap-helpers'
import { fixRequest } from '../util/utils'

const MAINNET_CODE_TRANSCRIPTION = {
zcash: 'shielded',
Expand All @@ -45,9 +46,10 @@ async function getAddress(

async function checkQuoteError(
rate: Rate,
request: EdgeSwapRequest,
rawRequest: EdgeSwapRequest,
quoteErrorMessage: string
): Promise<void> {
const request = fixRequest(rawRequest)
const { fromCurrencyCode, fromWallet, toCurrencyCode } = request

if (quoteErrorMessage === 'Amount too low') {
Expand Down Expand Up @@ -121,8 +123,9 @@ const createSideshiftApi = (

const createFetchSwapQuote = (api: SideshiftApi, affiliateId: string) =>
async function fetchSwapQuote(
request: EdgeSwapRequest
rawRequest: EdgeSwapRequest
): Promise<EdgeSwapQuote> {
const request = fixRequest(rawRequest)
const [refundAddress, settleAddress] = await Promise.all([
getAddress(request.fromWallet, request.fromCurrencyCode),
getAddress(request.toWallet, request.toCurrencyCode)
Expand Down
7 changes: 5 additions & 2 deletions src/swap/swapuz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
makeSwapPluginQuote
} from '../swap-helpers'
import { div18 } from '../util/biggystringplus'
import { fixRequest } from '../util/utils'

const pluginId = 'swapuz'

Expand Down Expand Up @@ -82,8 +83,9 @@ export function makeSwapuzPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
}

const fetchSwapQuoteInner = async (
request: EdgeSwapRequest
rawRequest: EdgeSwapRequest
): Promise<EdgeSwapQuote> => {
const request = fixRequest(rawRequest)
const { fromWallet, toWallet, nativeAmount } = request

checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
Expand Down Expand Up @@ -232,7 +234,8 @@ export function makeSwapuzPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const out: EdgeSwapPlugin = {
swapInfo,

async fetchSwapQuote(requestTop: EdgeSwapRequest): Promise<EdgeSwapQuote> {
async fetchSwapQuote(request: EdgeSwapRequest): Promise<EdgeSwapQuote> {
const requestTop = fixRequest(request)
const {
fromCurrencyCode,
toWallet,
Expand Down
Loading