Skip to content

Commit

Permalink
Merge pull request paraswap#488 from paraswap/aburkut/back-1263-equal…
Browse files Browse the repository at this point in the history
…izer

BACK-1263: Integrate Equalizer on Fantom
  • Loading branch information
Verisana authored Sep 1, 2023
2 parents e6662d2 + 9bf6de4 commit f47e269
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "2.33.1",
"version": "2.33.2",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
2 changes: 2 additions & 0 deletions src/dex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { SpiritSwapV2 } from './solidly/forks-override/spiritSwapV2';
import { Synthetix } from './synthetix/synthetix';
import { Cone } from './solidly/forks-override/cone';
import { SoliSnek } from './solidly/forks-override/solisnek';
import { Equalizer } from './solidly/forks-override/equalizer';
import { BalancerV1 } from './balancer-v1/balancer-v1';
import { balancerV1Merge } from './balancer-v1/optimizer';
import { CurveV1 } from './curve-v1/curve-v1';
Expand Down Expand Up @@ -133,6 +134,7 @@ const Dexes = [
VelodromeV2,
Cone,
SoliSnek,
Equalizer,
Synthetix,
CurveV1Factory,
SwaapV1,
Expand Down
12 changes: 11 additions & 1 deletion src/dex/solidly/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,24 @@ export const SolidlyConfig: DexConfigMap<DexParams> = {
feeCode: 0,
},
},
Equalizer: {
[Network.FANTOM]: {
factoryAddress: '0xc6366EFD0AF1d09171fe0EBF32c7943BB310832a',
router: '0x93d2611EB8b85bE4FDEa9D94Ce9913D90072eC0f',
initCode:
'0x02ada2a0163cd4f7e0f0c9805f5230716a95b174140e4c84c14883de216cc6a3',
feeCode: 0,
poolGasCost: 180 * 1000,
},
},
};

export const Adapters: Record<number, AdapterMappings> = {
[Network.POLYGON]: {
[SwapSide.SELL]: [{ name: 'PolygonAdapter02', index: 3 }], // dystopia
},
[Network.FANTOM]: {
[SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 10 }], // solidly + spiritSwapV2
[SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 10 }], // solidly + spiritSwapV2 + Equalizer
},
[Network.OPTIMISM]: {
[SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 8 }], // velodrome
Expand Down
58 changes: 58 additions & 0 deletions src/dex/solidly/forks-override/equalizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Solidly } from '../solidly';
import { SolidlyPair } from '../types';
import { Network } from '../../../constants';
import { IDexHelper } from '../../../dex-helper';
import { Interface } from '@ethersproject/abi';
import { getDexKeysWithNetwork } from '../../../utils';
import { SolidlyConfig } from '../config';
import _ from 'lodash';

const EqualizerFactoryABI = [
{
inputs: [{ internalType: 'address', name: '_pair', type: 'address' }],
name: 'getRealFee',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
];

const equalizerFactoryIface = new Interface(EqualizerFactoryABI);

export class Equalizer extends Solidly {
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Equalizer']));

constructor(
protected network: Network,
dexKey: string,
protected dexHelper: IDexHelper,
) {
super(
network,
dexKey,
dexHelper,
true, // dynamic fees
);
}

protected getFeesMultiCallData(pair: SolidlyPair) {
const callEntry = {
target: this.factoryAddress,
callData: equalizerFactoryIface.encodeFunctionData('getRealFee', [
pair.exchange,
]),
};
const callDecoder = (values: any[]) =>
parseInt(
equalizerFactoryIface
.decodeFunctionResult('getRealFee', values)[0]
.toString(),
);

return {
callEntry,
callDecoder,
};
}
}
23 changes: 23 additions & 0 deletions src/dex/solidly/solidly-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,29 @@ describe('Solidly E2E', () => {
});
});
});

describe('Equalizer', () => {
const dexKey = 'Equalizer';
const network = Network.FANTOM;

const tokenASymbol: string = 'FUSDT';
const tokenBSymbol: string = 'USDC';

const tokenAAmount: string = '111110';
const tokenBAmount: string = '100000';
const nativeTokenAmount = '11000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);

});
});

describe('Mainnet', () => {
Expand Down
Loading

0 comments on commit f47e269

Please sign in to comment.