Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Fluid-Dex #877

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/abi/fluid-dex/resolver.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
"name": "fee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "centerPrice",
"type": "uint256"
},
{
"components": [
{
Expand Down Expand Up @@ -395,6 +400,11 @@
"name": "fee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "centerPrice",
"type": "uint256"
},
{
"components": [
{
Expand Down Expand Up @@ -1192,6 +1202,11 @@
"name": "fee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "centerPrice",
"type": "uint256"
},
{
"components": [
{
Expand Down Expand Up @@ -1392,6 +1407,11 @@
"name": "fee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "centerPrice",
"type": "uint256"
},
{
"components": [
{
Expand Down Expand Up @@ -1616,6 +1636,11 @@
"name": "fee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "centerPrice",
"type": "uint256"
},
{
"components": [
{
Expand Down Expand Up @@ -1816,6 +1841,11 @@
"name": "fee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "centerPrice",
"type": "uint256"
},
{
"components": [
{
Expand Down
4 changes: 2 additions & 2 deletions src/dex/fluid-dex/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export const FluidDexConfig: DexConfigMap<DexParams> = {
[Network.MAINNET]: {
commonAddresses: {
liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497',
resolver: '0x45f4ad57e300da55c33dea579a40fcee000d7b94',
resolver: '0xb387f9C2092cF7c4943F97842887eBff7AE96EB3',
dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
},
},
[Network.ARBITRUM]: {
commonAddresses: {
liquidityProxy: '0x52Aa899454998Be5b000Ad077a46Bbe360F4e497',
resolver: '0xb8f526718FF58758E256D9aD86bC194a9ff5986D',
resolver: '0xCe6F4E40152a1DF97ae95a7e4F60D944871A4060',
dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/dex/fluid-dex/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const MIN_SWAP_LIQUIDITY = 10n ** 4n;
export const MIN_SWAP_LIQUIDITY = 20n ** 4n;
37 changes: 13 additions & 24 deletions src/dex/fluid-dex/fluid-dex-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,12 @@ describe('FluidDex E2E', () => {
describe('Mainnet', () => {
const network = Network.MAINNET;

// TODO: Uncomment & test when the issue is resolved. Currently no price as expected.
// describe.only('FLUID -> ETH', () => {
// const tokenASymbol: string = 'FLUID';
// const tokenBSymbol: string = 'ETH';
//
// const tokenAAmount: string = '160097047322810379';
// const tokenBAmount: string = '79923068733005505624';
//
// testForNetwork(
// network,
// dexKey,
// tokenASymbol,
// tokenBSymbol,
// tokenAAmount,
// tokenBAmount,
// );
// });

describe('ETH -> INST', () => {
const tokenASymbol: string = 'ETH';
const tokenBSymbol: string = 'INST';
describe('FLUID -> ETH', () => {
const tokenASymbol: string = 'FLUID';
const tokenBSymbol: string = 'ETH';

const tokenAAmount: string = '100000000000000';
const tokenBAmount: string = '100000000000000';
const tokenAAmount: string = '16009704732';
const tokenBAmount: string = '7992306000001';

testForNetwork(
network,
Expand Down Expand Up @@ -247,6 +229,9 @@ function NewDebtReservesOne(): DebtReserves {
};
}

const centerPriceTight: bigint = 3401944443797854601871360n;
const centerPriceWide: bigint = 1190081051944310368000000000n;

const limitsTight: DexLimits = {
withdrawableToken0: {
available: 456740438880263n,
Expand Down Expand Up @@ -314,6 +299,7 @@ describe('TestPoolSimulator_SwapInLimits', () => {
100n,
18,
limitsTight,
BigInt(centerPriceTight),
Math.floor(Date.now() / 1000) - 10,
);
expect(outAmt).toEqual(0n);
Expand All @@ -331,10 +317,11 @@ describe('TestPoolSimulator_SwapInLimits', () => {
100n,
18,
limitsTight,
BigInt(centerPriceTight),
Math.floor(Date.now() / 1000) - 6000,
);
console.log('outAmt: ', outAmt);
expect(outAmt?.toString()).toEqual('998262697204710');
expect(outAmt?.toString()).toEqual('998163044346107');
});

it('when price diff hit', () => {
Expand All @@ -348,6 +335,7 @@ describe('TestPoolSimulator_SwapInLimits', () => {
100n,
18,
limitsWide,
BigInt(centerPriceWide),
Math.floor(Date.now() / 1000) - 10,
);
expect(outAmt).toEqual(0n);
Expand All @@ -367,6 +355,7 @@ describe('TestPoolSimulator_SwapInLimits', () => {
100n,
18,
limitsWide,
BigInt(centerPriceWide),
Math.floor(Date.now() / 1000) - 10,
);
expect(outAmt).toEqual(0n);
Expand Down
3 changes: 3 additions & 0 deletions src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
token0,
token1,
feeHex,
centerPriceHex,
collateralReservesHex,
debtReservesHex,
dexLimitsHex,
] = poolReserve;

const fee = Number(feeHex.toString());
const centerPrice = Number(centerPriceHex.toString());

const collateralReserves = {
token0RealReserves: bigIntify(collateralReservesHex[0]),
Expand Down Expand Up @@ -196,6 +198,7 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
token0,
token1,
fee,
centerPrice,
collateralReserves,
debtReserves,
dexLimits,
Expand Down
Loading