Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

fix: remove undefined extension opts #268

Merged
merged 2 commits into from
Jun 24, 2020
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
80 changes: 44 additions & 36 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 24 additions & 27 deletions src/services/swap_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ProtocolFeeUtils,
SwapQuote,
SwapQuoteConsumer,
SwapQuoteGetOutputOpts,
SwapQuoter,
SwapQuoterOpts,
} from '@0x/asset-swapper';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -432,29 +430,28 @@ export class SwapService {
affiliateAddress: string,
swapVersion: SwapVersion,
): Promise<SwapQuoteResponsePartialTransaction> {
let extensionContractType;
let opts: Partial<SwapQuoteGetOutputOpts> = { 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 {
Expand Down