* `@0x/contract-artifacts`: Update artifacts. * `@0x/contract-wrappers`: Regenerate wrappers. * `@0x/migrations`: Update Forwarder migration. * `@0x/asset-swapper`: Update forwarder fees for new forwarder contract. * `@0x/dev-utils`: Make `"istanbul"` the default `hardfork` when creating a ganache provider. * `@0x/asset-swapper`: Remove debug code. * `@0x/asset-swapper`: Remove `getSmartContractParamsOrThrowAsync()` because why does it even exist? `@0x/asset-swapper`: Fix broken tests. `@0x/asset-swapper`: Correctly handle affiliate fees in `getCalldataOrThrow()`. * `@0x/contract-wrappers`: Export `ExchangeOwnershipTransferredEventArgs`. `@0x/0x.js`: Export `ExchangeOwnershipTransferredEventArgs`. `@0x/asset-swapper`: Unexport `MethodAbi`, `ConstructorStateMutability`, and `StateMutability`. * Update changelogs * Update packages/migrations/CHANGELOG.json Co-Authored-By: Jacob Evans <jacob@dekz.net> * Update packages/asset-swapper/CHANGELOG.json Co-Authored-By: Jacob Evans <jacob@dekz.net> Co-authored-by: Lawrence Forman <me@merklejerk.com> Co-authored-by: Jacob Evans <dekz@dekz.net>
30 lines
1.5 KiB
TypeScript
30 lines
1.5 KiB
TypeScript
import { BigNumber } from '@0x/utils';
|
|
|
|
import { SwapQuoteInfo } from '../types';
|
|
|
|
import { assert } from './assert';
|
|
|
|
export const affiliateFeeUtils = {
|
|
/**
|
|
* Get the amount of eth to send for a forwarder contract call (includes takerAssetAmount, protocol fees, and specified affiliate fee amount)
|
|
* @param swapQuoteInfo SwapQuoteInfo to generate total eth amount from
|
|
* @param feePercentage Percentage of additive fees to apply to totalTakerAssetAmount + protocol fee.
|
|
*/
|
|
getTotalEthAmountWithAffiliateFee(swapQuoteInfo: SwapQuoteInfo, feePercentage: number): BigNumber {
|
|
const ethAmount = swapQuoteInfo.protocolFeeInWeiAmount.plus(swapQuoteInfo.totalTakerAssetAmount);
|
|
const ethAmountWithFees = ethAmount.plus(affiliateFeeUtils.getFeeAmount(swapQuoteInfo, feePercentage));
|
|
return ethAmountWithFees;
|
|
},
|
|
/**
|
|
* Get the affiliate fee owed to the forwarder fee recipient.
|
|
* @param swapQuoteInfo SwapQuoteInfo to generate total eth amount from
|
|
* @param feePercentage Percentage of additive fees to apply to totalTakerAssetAmount + protocol fee.
|
|
*/
|
|
getFeeAmount(swapQuoteInfo: SwapQuoteInfo, feePercentage: number): BigNumber {
|
|
assert.assert(feePercentage >= 0, 'feePercentage must be >= 0');
|
|
const ethAmount = swapQuoteInfo.protocolFeeInWeiAmount.plus(swapQuoteInfo.totalTakerAssetAmount);
|
|
// HACK(dekz): This is actually in WEI amount not ETH
|
|
return ethAmount.times(feePercentage).integerValue(BigNumber.ROUND_UP);
|
|
},
|
|
};
|