diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index e233fcc1d..7514ae0c5 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -6,39 +6,47 @@ name: Build and Test on: [push] jobs: - build_and_test: - name: Build and Test - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [11.x] - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Cache node modules - uses: actions/cache@v1 - env: - cache-name: cached-node-modules - with: - path: ~/work/0x-api/0x-api/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('yarn.lock') }} - - - run: yarn install --frozen-lockfile - - run: yarn build - # Pull the docker images so that they don't need to be pulled in the tests. - - run: docker-compose pull - - run: yarn lint - - run: yarn test - - name: Save build artifacts - uses: actions/upload-artifact@v1 - with: - name: lib - path: lib + build_and_test: + name: Build and Test + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [11.x] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + # Get the yarn cache directory and store it for cache hits + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache node modules + uses: actions/cache@v2 + id: yarn-cache + env: + cache-name: cached-node-modules + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-build-${{ hashFiles('yarn.lock') }} + restore-keys: | + ${{ runner.os }}-build- + + - run: yarn install --frozen-lockfile + - run: yarn build + # Pull the docker images so that they don't need to be pulled in the tests. + - run: docker-compose pull + - run: yarn lint + - run: yarn test + - name: Save build artifacts + uses: actions/upload-artifact@v1 + with: + name: lib + path: lib diff --git a/src/services/swap_service.ts b/src/services/swap_service.ts index 612db85b0..2c0821545 100644 --- a/src/services/swap_service.ts +++ b/src/services/swap_service.ts @@ -4,6 +4,7 @@ import { ProtocolFeeUtils, SwapQuote, SwapQuoteConsumer, + SwapQuoteGetOutputOpts, SwapQuoter, SwapQuoterOpts, } from '@0x/asset-swapper'; @@ -160,21 +161,19 @@ export class SwapService { attributedSwapQuote, ); - // set the allowance target based on version. V0 is legacy param to support Nuo integrator - let allowanceTarget = NULL_ADDRESS; - if (isETHSell) { - switch (swapVersion) { - case SwapVersion.V0: - allowanceTarget = this._contractAddresses.erc20Proxy; - break; - case SwapVersion.V1: - allowanceTarget = this._contractAddresses.exchangeProxyAllowanceTarget; - break; - default: - allowanceTarget = NULL_ADDRESS; - break; - } + // set the allowance target based on version. V0 is legacy param to support transition to v1 + let erc20AllowanceTarget = NULL_ADDRESS; + switch (swapVersion) { + case SwapVersion.V0: + erc20AllowanceTarget = this._contractAddresses.erc20Proxy; + break; + case SwapVersion.V1: + erc20AllowanceTarget = this._contractAddresses.exchangeProxyAllowanceTarget; + break; + default: + throw new Error(`Unsupported Swap version: ${swapVersion}`); } + const allowanceTarget = isETHSell ? NULL_ADDRESS : erc20AllowanceTarget; const apiSwapQuote: GetSwapQuoteResponse = { price, @@ -390,8 +389,7 @@ export class SwapService { takerAddress = await this._getExchangeProxyFlashWalletAsync(); break; default: - takerAddress = from || ''; - break; + throw new Error(`Unsupported Swap version: ${swapVersion}`); } _rfqt = { ...rfqt, @@ -434,29 +432,28 @@ export class SwapService { affiliateAddress: string, swapVersion: SwapVersion, ): Promise { - let extensionContractType; + let opts: Partial = { useExtensionContract: ExtensionContractType.None }; switch (swapVersion) { case SwapVersion.V0: - extensionContractType = isFromETH ? ExtensionContractType.Forwarder : ExtensionContractType.None; + if (isFromETH) { + opts = { useExtensionContract: ExtensionContractType.Forwarder }; + } break; case SwapVersion.V1: - extensionContractType = ExtensionContractType.ExchangeProxy; + opts = { + useExtensionContract: ExtensionContractType.ExchangeProxy, + extensionContractOpts: { isFromETH, isToETH }, + }; break; default: - break; + throw new Error(`Unsupported Swap version: ${swapVersion}`); } - const extensionContractOpts = - extensionContractType === ExtensionContractType.ExchangeProxy ? { isFromETH, isToETH } : undefined; - const { calldataHexString: data, ethAmount: value, toAddress: to, - } = await this._swapQuoteConsumer.getCalldataOrThrowAsync(swapQuote, { - useExtensionContract: extensionContractType, - extensionContractOpts, - }); + } = await this._swapQuoteConsumer.getCalldataOrThrowAsync(swapQuote, opts); const affiliatedData = serviceUtils.attributeCallData(data, affiliateAddress); return {