Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename executeQuote to ZrxExecuteQuote
Browse files Browse the repository at this point in the history
DaoDev44 committed Nov 23, 2021

Verified

This commit was signed with the committer’s verified signature.
vbudhram Vijay Budhram
1 parent 8131746 commit c330a6a
Showing 4 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ import { ChainTypes, ExecQuoteInput, SwapperType } from '@shapeshiftoss/types'

import { setupQuote } from '../utils/test-data/setupSwapQuote'
import { ZrxSwapperDeps } from '../ZrxSwapper'
import { executeQuote } from './executeQuote'
import { ZrxExecuteQuote } from './ZrxExecuteQuote'

describe('executeQuote', () => {
describe('ZrxExecuteQuote', () => {
const { quoteInput, sellAsset } = setupQuote()
const txid = '0xffaac3dd529171e8a9a2adaf36b0344877c4894720d65dfd86e4b3a56c5a857e'
let wallet = ({
@@ -27,8 +27,8 @@ describe('executeQuote', () => {
quote: { ...quoteInput, success: false },
wallet
}
await expect(executeQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:executeQuote Cannot execute a failed quote'
await expect(ZrxExecuteQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:ZrxExecuteQuote Cannot execute a failed quote'
)
})

@@ -37,8 +37,8 @@ describe('executeQuote', () => {
quote: { ...quoteInput, sellAsset: { ...sellAsset, network: '' } },
wallet
} as unknown) as ExecQuoteInput<ChainTypes, SwapperType>
await expect(executeQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:executeQuote sellAssetNetwork and sellAssetSymbol are required'
await expect(ZrxExecuteQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:ZrxExecuteQuote sellAssetNetwork and sellAssetSymbol are required'
)
})

@@ -47,8 +47,8 @@ describe('executeQuote', () => {
quote: { ...quoteInput, sellAsset: { ...sellAsset, symbol: '' } },
wallet
}
await expect(executeQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:executeQuote sellAssetNetwork and sellAssetSymbol are required'
await expect(ZrxExecuteQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:ZrxExecuteQuote sellAssetNetwork and sellAssetSymbol are required'
)
})

@@ -57,8 +57,8 @@ describe('executeQuote', () => {
quote: { ...quoteInput, sellAssetAccountId: '' },
wallet
}
await expect(executeQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:executeQuote sellAssetAccountId is required'
await expect(ZrxExecuteQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:ZrxExecuteQuote sellAssetAccountId is required'
)
})

@@ -67,8 +67,8 @@ describe('executeQuote', () => {
quote: { ...quoteInput, sellAmount: '' },
wallet
}
await expect(executeQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:executeQuote sellAmount is required'
await expect(ZrxExecuteQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:ZrxExecuteQuote sellAmount is required'
)
})

@@ -77,8 +77,8 @@ describe('executeQuote', () => {
quote: { ...quoteInput, depositAddress: '' },
wallet
}
await expect(executeQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:executeQuote depositAddress is required'
await expect(ZrxExecuteQuote(deps, args)).rejects.toThrow(
'ZrxSwapper:ZrxExecuteQuote depositAddress is required'
)
})

@@ -88,7 +88,7 @@ describe('executeQuote', () => {
wallet
}

expect(await executeQuote(deps, args)).toEqual({ txid })
expect(await ZrxExecuteQuote(deps, args)).toEqual({ txid })
})

it('returns txid if offline signing is unsupported', async () => {
@@ -101,6 +101,6 @@ describe('executeQuote', () => {
wallet
}

expect(await executeQuote(deps, args)).toEqual({ txid })
expect(await ZrxExecuteQuote(deps, args)).toEqual({ txid })
})
})
Original file line number Diff line number Diff line change
@@ -4,30 +4,30 @@ import { numberToHex } from 'web3-utils'
import { SwapError } from '../../../api'
import { ZrxSwapperDeps } from '../ZrxSwapper'

export async function executeQuote(
export async function ZrxExecuteQuote(
{ adapterManager }: ZrxSwapperDeps,
{ quote, wallet }: ExecQuoteInput<ChainTypes.Ethereum, SwapperType>
): Promise<ExecQuoteOutput> {
const { sellAsset } = quote

if (!quote.success) {
throw new SwapError('ZrxSwapper:executeQuote Cannot execute a failed quote')
throw new SwapError('ZrxSwapper:ZrxExecuteQuote Cannot execute a failed quote')
}

if (!sellAsset.network || !sellAsset.symbol) {
throw new SwapError('ZrxSwapper:executeQuote sellAssetNetwork and sellAssetSymbol are required')
throw new SwapError('ZrxSwapper:ZrxExecuteQuote sellAssetNetwork and sellAssetSymbol are required')
}

if (!quote.sellAssetAccountId) {
throw new SwapError('ZrxSwapper:executeQuote sellAssetAccountId is required')
throw new SwapError('ZrxSwapper:ZrxExecuteQuote sellAssetAccountId is required')
}

if (!quote.sellAmount) {
throw new SwapError('ZrxSwapper:executeQuote sellAmount is required')
throw new SwapError('ZrxSwapper:ZrxExecuteQuote sellAmount is required')
}

if (!quote.depositAddress) {
throw new SwapError('ZrxSwapper:executeQuote depositAddress is required')
throw new SwapError('ZrxSwapper:ZrxExecuteQuote depositAddress is required')
}

// value is 0 for erc20s
@@ -50,7 +50,7 @@ export async function executeQuote(
bip32Params
})
} catch (error) {
throw new SwapError(`executeQuote - buildSendTransaction error: ${error}`)
throw new SwapError(`ZrxExecuteQuote - buildSendTransaction error: ${error}`)
}

const { txToSign } = buildTxResponse
@@ -61,29 +61,29 @@ export async function executeQuote(
try {
signedTx = await adapter.signTransaction({ txToSign: txWithQuoteData, wallet })
} catch (error) {
throw new SwapError(`executeQuote - signTransaction error: ${error}`)
throw new SwapError(`ZrxExecuteQuote - signTransaction error: ${error}`)
}

if (!signedTx) {
throw new SwapError(`executeQuote - Signed transaction is required: ${signedTx}`)
throw new SwapError(`ZrxExecuteQuote - Signed transaction is required: ${signedTx}`)
}

try {
txid = await adapter.broadcastTransaction(signedTx)
} catch (error) {
throw new SwapError(`executeQuote - broadcastTransaction error: ${error}`)
throw new SwapError(`ZrxExecuteQuote - broadcastTransaction error: ${error}`)
}

return { txid }
} else if (wallet.supportsBroadcast() && adapter.signAndBroadcastTransaction) {
try {
txid = await adapter.signAndBroadcastTransaction?.({ txToSign: txWithQuoteData, wallet })
} catch (error) {
throw new SwapError(`executeQuote - signAndBroadcastTransaction error: ${error}`)
throw new SwapError(`ZrxExecuteQuote - signAndBroadcastTransaction error: ${error}`)
}

return { txid }
} else {
throw new SwapError('executeQuote - invalid HDWallet config')
throw new SwapError('ZrxExecuteQuote - invalid HDWallet config')
}
}
10 changes: 5 additions & 5 deletions packages/swapper/src/swappers/zrx/ZrxSwapper.test.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import Web3 from 'web3'
import { ZrxError } from '../..'
import { ZrxSwapper } from '..'
import { ZrxBuildQuoteTx } from '../zrx/ZrxBuildQuoteTx/ZrxBuildQuoteTx'
import { executeQuote } from '../zrx/executeQuote/executeQuote'
import { ZrxExecuteQuote } from './ZrxExecuteQuote/ZrxExecuteQuote'
import { ZrxApprovalNeeded } from './ZrxApprovalNeeded/ZrxApprovalNeeded'
import { ZrxApproveInfinite } from './ZrxApproveInfinite/ZrxApproveInfinite'
import { getMinMax } from './getMinMax/getMinMax'
@@ -17,8 +17,8 @@ import { BTC, FOX, WETH } from './utils/test-data/assets'
import { setupQuote } from './utils/test-data/setupSwapQuote'

jest.mock('./utils/helpers/helpers')
jest.mock('../zrx/executeQuote/executeQuote', () => ({
executeQuote: jest.fn()
jest.mock('../zrx/ZrxExecuteQuote/ZrxExecuteQuote', () => ({
ZrxExecuteQuote: jest.fn()
}))

jest.mock('../zrx/ZrxBuildQuoteTx/ZrxBuildQuoteTx', () => ({
@@ -90,11 +90,11 @@ describe('ZrxSwapper', () => {
await swapper.buildQuoteTx(args)
expect(ZrxBuildQuoteTx).toHaveBeenCalled()
})
it('calls executeQuote on swapper.executeQuote', async () => {
it('calls ZrxExecuteQuote on swapper.executeQuote', async () => {
const swapper = new ZrxSwapper(zrxSwapperDeps)
const args = { quote, wallet }
await swapper.executeQuote(args)
expect(executeQuote).toHaveBeenCalled()
expect(ZrxExecuteQuote).toHaveBeenCalled()
})
it('gets default pair', () => {
const swapper = new ZrxSwapper(zrxSwapperDeps)
4 changes: 2 additions & 2 deletions packages/swapper/src/swappers/zrx/ZrxSwapper.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import { Swapper } from '../../api'
import { ZrxApprovalNeeded } from './ZrxApprovalNeeded/ZrxApprovalNeeded'
import { ZrxApproveInfinite } from './ZrxApproveInfinite/ZrxApproveInfinite'
import { ZrxBuildQuoteTx } from './ZrxBuildQuoteTx/ZrxBuildQuoteTx'
import { executeQuote } from './executeQuote/executeQuote'
import { ZrxExecuteQuote } from './ZrxExecuteQuote/ZrxExecuteQuote'
import { getMinMax } from './getMinMax/getMinMax'
import { getZrxQuote } from './getZrxQuote/getZrxQuote'
import { getSendMaxAmount } from './getSendMaxAmount/getSendMaxAmount'
@@ -81,7 +81,7 @@ export class ZrxSwapper implements Swapper {
}

async executeQuote(args: ExecQuoteInput<ChainTypes, SwapperType>): Promise<ExecQuoteOutput> {
return executeQuote(this.deps, args)
return ZrxExecuteQuote(this.deps, args)
}

async approvalNeeded(

0 comments on commit c330a6a

Please sign in to comment.