Skip to content

Commit

Permalink
fix: zeroExV4Adapter minIncomingAmount validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau authored May 9, 2023
1 parent cea915a commit da8ed1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ contract ZeroExV4Adapter is AdapterBase, MathHelpers, ZeroExV4ActionsMixin {
spendAssetAmounts_ = new uint256[](1);

address maker;
uint256 makerAmount;
uint256 takerAmount;
uint256 takerTokenFeeAmount;

Expand All @@ -133,6 +134,7 @@ contract ZeroExV4Adapter is AdapterBase, MathHelpers, ZeroExV4ActionsMixin {
);

maker = order.maker;
makerAmount = order.makerAmount;
incomingAssets_[0] = order.makerToken;
spendAssets_[0] = order.takerToken;
takerAmount = order.takerAmount;
Expand All @@ -142,6 +144,7 @@ contract ZeroExV4Adapter is AdapterBase, MathHelpers, ZeroExV4ActionsMixin {
encodedZeroExOrderArgs
);
maker = order.maker;
makerAmount = order.makerAmount;
incomingAssets_[0] = order.makerToken;
spendAssets_[0] = order.takerToken;
takerAmount = order.takerAmount;
Expand All @@ -163,6 +166,12 @@ contract ZeroExV4Adapter is AdapterBase, MathHelpers, ZeroExV4ActionsMixin {
spendAssetAmounts_[0] = takerAssetFillAmount;
}

minIncomingAssetAmounts_[0] = __calcRelativeQuantity({
_quantity1: takerAmount,
_quantity2: makerAmount,
_relativeQuantity1: takerAssetFillAmount
});

return (
IIntegrationManager.SpendAssetsHandleType.Transfer,
spendAssets_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('parseAssetsForAction', () => {

expect(result).toMatchFunctionOutput(zeroExV4AdapterWithWhitelist.parseAssetsForAction, {
incomingAssets_: [incomingAsset],
minIncomingAssetAmounts_: [0],
minIncomingAssetAmounts_: [makerAmount.mul(takerAssetFillAmount).div(takerAmount)],
spendAssetAmounts_: [takerAssetFillAmount],
spendAssetsHandleType_: SpendAssetsHandleType.Transfer,
spendAssets_: [outgoingAsset],
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('parseAssetsForAction', () => {

expect(result).toMatchFunctionOutput(zeroExV4Adapter.parseAssetsForAction, {
incomingAssets_: [incomingAsset],
minIncomingAssetAmounts_: [0],
minIncomingAssetAmounts_: [makerAmount.mul(takerAssetFillAmount).div(takerAmount)],
spendAssetAmounts_: [takerAssetFillAmount],
spendAssetsHandleType_: SpendAssetsHandleType.Transfer,
spendAssets_: [outgoingAsset],
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('parseAssetsForAction', () => {

expect(result).toMatchFunctionOutput(zeroExV4Adapter.parseAssetsForAction, {
incomingAssets_: [incomingAsset],
minIncomingAssetAmounts_: [0],
minIncomingAssetAmounts_: [makerAmount.mul(takerAssetFillAmount).div(takerAmount)],
spendAssetAmounts_: [takerAssetFillAmount.add(expectedTakerFee)],
spendAssetsHandleType_: SpendAssetsHandleType.Transfer,
spendAssets_: [outgoingAsset],
Expand Down

0 comments on commit da8ed1e

Please sign in to comment.