Skip to content

Commit

Permalink
fix: proper offset
Browse files Browse the repository at this point in the history
fix: reuse function for offset

fix: remove import
  • Loading branch information
sakulstra committed Apr 2, 2021
1 parent 8ac02a1 commit a80ba7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
14 changes: 12 additions & 2 deletions src/tx-builder/services/LiquiditySwapAdapterParaswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import { LiquiditySwapValidator } from '../validators/methodValidators';
import { IsEthAddress, IsPositiveAmount } from '../validators/paramValidators';
import BaseService from './BaseService';

export function augustusFromAmountOffsetFromCalldata(calldata: string) {
switch (calldata.slice(0, 10)) {
case '0xda8567c8': // Augustus V3 multiSwap
return 4 + 32 + 2 * 32;
default:
throw new Error('Unrecognized function selector for Augustus');
}
}

export default class LiquiditySwapAdapterService
extends BaseService<IParaSwapLiquiditySwapAdapter>
implements LiquiditySwapAdapterInterface {
Expand All @@ -23,7 +32,6 @@ export default class LiquiditySwapAdapterService
constructor(config: Configuration) {
super(config, IParaSwapLiquiditySwapAdapter__factory);

console.log('nw', this.config.network);
const { SWAP_COLLATERAL_ADAPTER } = commonContractAddressBetweenMarketsV2[
this.config.network
];
Expand Down Expand Up @@ -61,7 +69,9 @@ export default class LiquiditySwapAdapterService
assetToSwapTo,
amountToSwap,
minAmountToReceive,
swapAll ? 4 + 2 * 32 : 0,
swapAll
? augustusFromAmountOffsetFromCalldata(swapCallData as string)
: 0,
swapCallData,
augustus,
permitParams
Expand Down
21 changes: 4 additions & 17 deletions src/tx-builder/services/v2/LendingPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import LiquiditySwapAdapterInterface from '../../interfaces/LiquiditySwapAdapterParaswap';
import RepayWithCollateralAdapterInterface from '../../interfaces/RepayWithCollateralAdapter';
import BaseService from '../BaseService';
import { augustusFromAmountOffsetFromCalldata } from '../LiquiditySwapAdapterParaswap';

const buildParaSwapLiquiditySwapParams = (
assetToSwapTo: tEthereumAddress,
Expand Down Expand Up @@ -584,22 +585,6 @@ export default class LendingPool
swapCallData,
}: LPSwapCollateral
): Promise<EthereumTransactionTypeExtended[]> {
console.log('inParams', {
user,
flash,
fromAsset,
fromAToken,
toAsset,
fromAmount,
toAmount,
maxSlippage,
permitSignature,
swapAll,
onBehalfOf,
referralCode,
augustus,
swapCallData,
});
const txs: EthereumTransactionTypeExtended[] = [];

const permitParams = permitSignature || {
Expand Down Expand Up @@ -655,7 +640,9 @@ export default class LendingPool
const params = buildParaSwapLiquiditySwapParams(
toAsset,
amountSlippageConverted,
swapAll ? 4 + 2 * 32 : 0,
swapAll
? augustusFromAmountOffsetFromCalldata(swapCallData as string)
: 0,
swapCallData,
augustus,
permitParams.amount,
Expand Down

0 comments on commit a80ba7f

Please sign in to comment.