From 7e585d83b1d220d3cd856011522e6d49b8437623 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 24 Jun 2020 11:55:36 +1000 Subject: [PATCH 1/2] fix: remove undefined extension opts --- src/services/swap_service.ts | 51 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/services/swap_service.ts b/src/services/swap_service.ts index c2d6166ee..a4ee9e856 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, @@ -388,8 +387,7 @@ export class SwapService { takerAddress = await this._getExchangeProxyFlashWalletAsync(); break; default: - takerAddress = from || ''; - break; + throw new Error(`Unsupported Swap version: ${swapVersion}`); } _rfqt = { ...rfqt, @@ -432,29 +430,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 { From 2eedfd3cb681cc025768bfcd758e4c5ca7dc6b03 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 24 Jun 2020 12:33:43 +1000 Subject: [PATCH 2/2] github workflow --- .github/workflows/ci-build.yml | 80 +++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 36 deletions(-) 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