Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getMakerFeeAmount(order: Order, makerFillAmount: BigNumber): BigNumber {
// Round down because Maker fee rate favors Maker
const makerFeeAmount = makerFillAmount
.multipliedBy(order.makerFee)
.div(order.makerAssetAmount)
.integerValue(BigNumber.ROUND_FLOOR);
return makerFeeAmount;
},
/**
getRemainingMakerAmount(order: SignedOrder, remainingTakerAmount: BigNumber): BigNumber {
const remainingMakerAmount = remainingTakerAmount
.times(order.makerAssetAmount)
.div(order.takerAssetAmount)
.integerValue(BigNumber.ROUND_FLOOR);
return remainingMakerAmount;
},
// given a desired amount of makerAsset, calculate how much takerAsset is required to fill that amount
getMakerFillAmount(order: SignedOrder, takerFillAmount: BigNumber): BigNumber {
// Round down because exchange rate favors Maker
const makerFillAmount = takerFillAmount
.multipliedBy(order.makerAssetAmount)
.div(order.takerAssetAmount)
.integerValue(BigNumber.ROUND_FLOOR);
return makerFillAmount;
},
// given a desired amount of makerAsset, calculate how much fee is required by the maker to fill that amount
getMakerFillAmount(order: Order, takerFillAmount: BigNumber): BigNumber {
// Round down because exchange rate favors Maker
const makerFillAmount = takerFillAmount
.multipliedBy(order.makerAssetAmount)
.div(order.takerAssetAmount)
.integerValue(BigNumber.ROUND_FLOOR);
return makerFillAmount;
},
/**
// Calculate min of balance & allowance of maker's makerAsset -> translate into takerAsset amount
const maxMakerAssetFillAmount = BigNumber.min(traderInfo.makerBalance, traderInfo.makerAllowance);
const maxTakerAssetFillAmountGivenMakerConstraints = orderCalculationUtils.getTakerFillAmount(
signedOrder,
maxMakerAssetFillAmount,
);
minSet.push(maxTakerAssetFillAmountGivenMakerConstraints);
// Calculate min of balance & allowance of taker's Fee -> translate into takerAsset amount
if (!signedOrder.takerFee.eq(0)) {
const takerFeeAvailable = BigNumber.min(traderInfo.takerFeeBalance, traderInfo.takerFeeAllowance);
const maxTakerAssetFillAmountGivenTakerFeeConstraints = takerFeeAvailable
.multipliedBy(signedOrder.takerAssetAmount)
.div(signedOrder.takerFee)
.integerValue(BigNumber.ROUND_FLOOR);
minSet.push(maxTakerAssetFillAmountGivenTakerFeeConstraints);
}
// Calculate min of balance & allowance of maker's Fee -> translate into takerAsset amount
if (!signedOrder.makerFee.eq(0)) {
const makerFeeAvailable = BigNumber.min(traderInfo.makerFeeBalance, traderInfo.makerFeeAllowance);
const maxTakerAssetFillAmountGivenMakerFeeConstraints = makerFeeAvailable
.multipliedBy(signedOrder.takerAssetAmount)
.div(signedOrder.makerFee)
.integerValue(BigNumber.ROUND_FLOOR);
minSet.push(maxTakerAssetFillAmountGivenMakerFeeConstraints);
}
const remainingTakerAssetFillAmount = signedOrder.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount);
minSet.push(remainingTakerAssetFillAmount);
getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
const partialAmount = numerator
.multipliedBy(target)
.div(denominator)
.integerValue(BigNumber.ROUND_FLOOR);
return partialAmount;
},
createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => {
export const getTotalBalancesString = (tally: TallyInterface = ZERO_TALLY): string => {
const bigNumberFormat = {
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: ' ',
fractionGroupSize: 0,
};
const { yes, no } = tally;
const totalBalance = yes.plus(no);
const totalBalanceString = Web3Wrapper.toUnitAmount(totalBalance, constants.DECIMAL_PLACES_ETH).toFormat(
0,
BigNumber.ROUND_FLOOR,
bigNumberFormat,
);
return totalBalanceString;
};
public render(): React.ReactNode {
const { isOpen, onDismiss, zeipId } = this.props;
const { isSuccessful, selectedAddress, currentBalance, isErrorModalOpen, errorMessage } = this.state;
const bigNumberFormat = {
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: ' ',
fractionGroupSize: 0,
};
const formattedBalance = Web3Wrapper.toUnitAmount(currentBalance, constants.DECIMAL_PLACES_ETH).toFormat(
0,
BigNumber.ROUND_FLOOR,
bigNumberFormat,
);
return (
<>
{this._renderFormContent()}
Vote Received!
public render(): React.ReactNode {
const { votePreference, errors, isSuccessful, isAwaitingLedgerSignature } = this.state;
const { currentBalance, selectedAddress, zeipId } = this.props;
const bigNumberFormat = {
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: ' ',
fractionGroupSize: 0,
};
const formattedBalance = Web3Wrapper.toUnitAmount(currentBalance, constants.DECIMAL_PLACES_ETH).toFormat(
0,
BigNumber.ROUND_FLOOR,
bigNumberFormat,
);
return (
<form>
ZEIP-{zeipId} Vote
Make sure you are informed to the best of your ability before casting your vote. It will have
lasting implications for the 0x ecosystem.
</form>
const takerToken = this.props.tokenByAddress[takerTokenAddress];
const orderTakerAmount = this.state.parsedOrder.signedOrder.takerAssetAmount;
const orderMakerAmount = this.state.parsedOrder.signedOrder.makerAssetAmount;
const takerAssetToken = {
amount: orderTakerAmount.minus(this.state.unavailableTakerAmount),
symbol: takerToken.symbol,
};
const fillToken = this.props.tokenByAddress[takerTokenAddress];
const makerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.makerAssetData)
.tokenAddress;
const makerToken = this.props.tokenByAddress[makerTokenAddress];
const makerAssetToken = {
amount: orderMakerAmount
.times(takerAssetToken.amount)
.div(orderTakerAmount)
.integerValue(BigNumber.ROUND_FLOOR),
symbol: makerToken.symbol,
};
const fillAssetToken = {
amount: this.props.orderFillAmount,
symbol: takerToken.symbol,
};
const parsedOrderExpiration = this.state.parsedOrder.signedOrder.expirationTimeSeconds;
let orderReceiveAmount = 0;
if (this.props.orderFillAmount !== undefined) {
const orderReceiveAmountBigNumber = orderMakerAmount
.times(this.props.orderFillAmount)
.dividedBy(orderTakerAmount)
.integerValue(BigNumber.ROUND_FLOOR);
orderReceiveAmount = this._formatCurrencyAmount(orderReceiveAmountBigNumber, makerToken.decimals);
}