Skip to content

Commit

Permalink
Add manual insertFromAmountPos and sendEthButSupportsInsertFromAmount…
Browse files Browse the repository at this point in the history
… for Bebop and Cables
  • Loading branch information
aburkut committed Dec 26, 2024
1 parent fb04915 commit a4e4d2d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
66 changes: 39 additions & 27 deletions src/dex/bebop/bebop-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function testForNetwork(
const nativeTokenSymbol = NativeTokenSymbols[network];

const sideToContractMethods = new Map([
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
// [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
[SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
]);

Expand All @@ -50,34 +50,46 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
100,
);
});
it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[nativeTokenSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[tokenBSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
// it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
// await testE2E(
// tokens[tokenASymbol],
// tokens[nativeTokenSymbol],
// holders[tokenASymbol],
// side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
// side,
// dexKey,
// contractMethod,
// network,
// provider,
// undefined,
// undefined,
// undefined,
// 100,
// );
// });
// it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
// await testE2E(
// tokens[tokenASymbol],
// tokens[tokenBSymbol],
// holders[tokenASymbol],
// side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
// side,
// dexKey,
// contractMethod,
// network,
// provider,
// undefined,
// undefined,
// undefined,
// 100,
// );
// });
});
});
}),
Expand Down
18 changes: 17 additions & 1 deletion src/dex/bebop/bebop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
} from './constants';
import BigNumber from 'bignumber.js';
import { getBigNumberPow } from '../../bignumber-constants';
import { utils } from 'ethers';
import { ethers, utils } from 'ethers';
import qs from 'qs';
import { isEqual } from 'lodash';

Expand Down Expand Up @@ -656,12 +656,28 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
srcAmount, // modify filledTakerAmount to make insertFromAmount work
]);

const fromAmount = ethers.utils.defaultAbiCoder.encode(
['uint256'],
[srcAmount],
);

const filledTakerAmountIndex = exchangeData
.replace('0x', '')
.lastIndexOf(fromAmount.replace('0x', ''));

const filledTakerAmountPos =
(filledTakerAmountIndex !== -1
? filledTakerAmountIndex
: exchangeData.length) / 2;

return {
exchangeData: exchangeData,
needWrapNative: this.needWrapNative,
dexFuncHasRecipient: true,
targetExchange: this.settlementAddress,
returnAmountPos: undefined,
sendEthButSupportsInsertFromAmount: true,
insertFromAmountPos: filledTakerAmountPos,
};
} else {
throw new Error('Not supported method');
Expand Down
1 change: 1 addition & 0 deletions src/dex/cables/cables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export class Cables extends SimpleExchange implements IDex<any> {
targetExchange: this.mainnetRFQAddress,
returnAmountPos: undefined,
insertFromAmountPos: filledAmountPos,
sendEthButSupportsInsertFromAmount: true,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/executor/Executor03BytecodeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ExecutorBytecodeBuilder,
SingleSwapCallDataParams,
} from './ExecutorBytecodeBuilder';
import { assert } from 'ts-essentials';

const {
utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack },
Expand Down Expand Up @@ -330,6 +329,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<

let fromAmountPos = 0;
let toAmountPos = 0;

if (insertAmount) {
if (exchangeParam.insertFromAmountPos) {
fromAmountPos = exchangeParam.insertFromAmountPos;
Expand Down

0 comments on commit a4e4d2d

Please sign in to comment.