Skip to content

Commit

Permalink
apply prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Feb 5, 2024
1 parent 91ab3a2 commit 5239cba
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 132 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@
]
},
"engines": {
"node": "^20"
"node": "^19"
}
}
4 changes: 3 additions & 1 deletion src/common/models/AmmPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export abstract class AmmPool {
): Currency;

get poolFee(): number {
return evaluate(`(1 - ${this.feeNum} / ${this.feeDenom}) * ${this.feeDenom / 10n}`).toFixed(1);
return evaluate(
`(1 - ${this.feeNum} / ${this.feeDenom}) * ${this.feeDenom / 10n}`,
).toFixed(1);
}

get xRatio(): Ratio {
Expand Down
15 changes: 9 additions & 6 deletions src/network/cardano/api/ammPools/ammPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { cardanoWasm$ } from '../common/cardanoWasm';
import { defaultTokenList$ } from '../common/defaultTokenList';
import { networkContext$ } from '../networkContext/networkContext';
import { AnalyticPoolNetwork } from './analyticPoolNetwork';
import { AnalyticPoolNetworkV3 } from './analyticPoolNetworkV3.ts';
import { CardanoAmmPool } from './CardanoAmmPool';
import { AnalyticPoolNetworkV3 } from "./analyticPoolNetworkV3.ts";

export const showUnverifiedPools$ = new BehaviorSubject(false);

Expand Down Expand Up @@ -59,7 +59,8 @@ const getPoolsV2 = () =>
map(() =>
mkNetworkPoolsV1(cardanoNetwork, mkPoolsParser(RustModule.CardanoWasm), {
...ScriptCredsV1,
ammPoolDefault: '6b9c456aa650cb808a9ab54326e039d5235ed69f069c9664a8fe5b69',
ammPoolDefault:
'6b9c456aa650cb808a9ab54326e039d5235ed69f069c9664a8fe5b69',
}),
),
switchMap((poolsRepository) =>
Expand Down Expand Up @@ -109,10 +110,12 @@ export const unverifiedAmmPools$ = networkContext$.pipe(
);

const rawAmmPools$: Observable<AmmPool[]> = networkContext$.pipe(
exhaustMap(() => combineLatest([
analyticAmmPoolsNetwork.getAll().then((data) => data[0]),
analyticAmmPoolsNetworkV3.getAll().then((data) => data[0])
])),
exhaustMap(() =>
combineLatest([
analyticAmmPoolsNetwork.getAll().then((data) => data[0]),
analyticAmmPoolsNetworkV3.getAll().then((data) => data[0]),
]),
),
map(([v2Pools, v3Pools]) => v2Pools.concat(v3Pools)),
catchError(() => of(undefined)),
filter(Boolean),
Expand Down
204 changes: 103 additions & 101 deletions src/network/cardano/api/ammPools/analyticPoolNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,163 +3,163 @@ import {
AssetAmount,
EmissionLP,
HexString,
PoolId
} from "@spectrumlabs/cardano-dex-sdk";
import { Pools } from "@spectrumlabs/cardano-dex-sdk/build/main/amm/services/pools";
import { AssetClass } from "@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/assetClass";
import { encodeHex } from "@spectrumlabs/cardano-dex-sdk/build/main/utils/hex";
import { RustModule } from "@spectrumlabs/cardano-dex-sdk/build/main/utils/rustLoader";
import axios from "axios";
PoolId,
} from '@spectrumlabs/cardano-dex-sdk';
import { Pools } from '@spectrumlabs/cardano-dex-sdk/build/main/amm/services/pools';
import { AssetClass } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/assetClass';
import { encodeHex } from '@spectrumlabs/cardano-dex-sdk/build/main/utils/hex';
import { RustModule } from '@spectrumlabs/cardano-dex-sdk/build/main/utils/rustLoader';
import axios from 'axios';

import { Dictionary } from "../../../../common/utils/Dictionary";
import { cardanoNetworkData } from "../../utils/cardanoNetworkData";
import { AmmPoolAnalytics } from "../ammPoolsStats/ammPoolsStats";
import { Dictionary } from '../../../../common/utils/Dictionary';
import { cardanoNetworkData } from '../../utils/cardanoNetworkData';
import { AmmPoolAnalytics } from '../ammPoolsStats/ammPoolsStats';

const mapPoolIdToLqBound = new Map<string, string>([
[
"c0df17aae50c8644d438d1c0f1e876a897febb49fb1c959c8487f996.446a65644d6963726f5553445f4144415f4e4654",
"20000000000"
'c0df17aae50c8644d438d1c0f1e876a897febb49fb1c959c8487f996.446a65644d6963726f5553445f4144415f4e4654',
'20000000000',
],
[
"5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.4144415f53554e4441455f4e4654",
"5000000"
'5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.4144415f53554e4441455f4e4654',
'5000000',
],
[
"def400a2deaa534e5a73ee15d31b15e77dba28e6859c6c86cf712a57.4144415f534f43494554595f4e4654",
"10000000000"
'def400a2deaa534e5a73ee15d31b15e77dba28e6859c6c86cf712a57.4144415f534f43494554595f4e4654',
'10000000000',
],
[
"72f2990e8f906b589926b4290dd511bc846f0ac727c26fd7542f9db2.574d545f4144415f4e4654",
"20000000000"
'72f2990e8f906b589926b4290dd511bc846f0ac727c26fd7542f9db2.574d545f4144415f4e4654',
'20000000000',
],
[
"7e573afb96607a14b237574efb251d337f321c7436ab79051064925a.50415649415f4144415f4e4654",
"20000000000"
'7e573afb96607a14b237574efb251d337f321c7436ab79051064925a.50415649415f4144415f4e4654',
'20000000000',
],
[
"167e27a610f7786055995c6f425935cd05f5e195c776f1d9be009c57.4d454c445f4144415f4e4654",
"20000000000"
'167e27a610f7786055995c6f425935cd05f5e195c776f1d9be009c57.4d454c445f4144415f4e4654',
'20000000000',
],
[
"544ab8ca262e397d1dce7750742c56f934af83591362fe5b52e29d2b.5368656e4d6963726f5553445f4144415f4e4654",
"20000000000"
'544ab8ca262e397d1dce7750742c56f934af83591362fe5b52e29d2b.5368656e4d6963726f5553445f4144415f4e4654',
'20000000000',
],
[
"f781a51a2da081369b8295e03815877a8d64145512c1eea51f08297c.694254435f4144415f4e4654",
"10000000000"
'f781a51a2da081369b8295e03815877a8d64145512c1eea51f08297c.694254435f4144415f4e4654',
'10000000000',
],
[
"538736444e795327bb0a66dd8b2bca0a6a4fffd72052cacf66ed40c7.636861726c69335f6164615f6e6674",
"10000000000"
'538736444e795327bb0a66dd8b2bca0a6a4fffd72052cacf66ed40c7.636861726c69335f6164615f6e6674',
'10000000000',
],
[
"fd011feb9dc34f85e58e56838989816343f5c62619a82f6a089f0548.414749585f4144415f4e4654",
"20000000000"
'fd011feb9dc34f85e58e56838989816343f5c62619a82f6a089f0548.414749585f4144415f4e4654',
'20000000000',
],
[
"1c23a9875ca001fb5262366e61b7bd976d5fcf63fc515836eca04aaf.636e6574615f6164615f6e6674",
"10000000000"
'1c23a9875ca001fb5262366e61b7bd976d5fcf63fc515836eca04aaf.636e6574615f6164615f6e6674',
'10000000000',
],
[
"d8beceb1ac736c92df8e1210fb39803508533ae9573cffeb2b24a839.696274635f4144415f4e4654",
"20000000000"
'd8beceb1ac736c92df8e1210fb39803508533ae9573cffeb2b24a839.696274635f4144415f4e4654',
'20000000000',
],
[
"c2ea7b366349afda7bab0fbdb712d1e6cec1c91c1cfda21a43998e38.436f726e75636f706961735f4144415f4e4654",
"20000000000"
'c2ea7b366349afda7bab0fbdb712d1e6cec1c91c1cfda21a43998e38.436f726e75636f706961735f4144415f4e4654',
'20000000000',
],
[
"689b05e40d9b2b7c213aa70be06df1a9c9c4318791b834eb2973c4b7.414749585f4144415f4e4654",
"10000000000"
'689b05e40d9b2b7c213aa70be06df1a9c9c4318791b834eb2973c4b7.414749585f4144415f4e4654',
'10000000000',
],
[
"99f53c6447b7e07f20852bc38e7040efe83deff794d42183a9eba093.484f534b595f4144415f4e4654",
"20000000000"
'99f53c6447b7e07f20852bc38e7040efe83deff794d42183a9eba093.484f534b595f4144415f4e4654',
'20000000000',
],
[
"9985928ac3a33e05e884d5cac04c338036b8a35ea9198ffa9c01894e.696574685f4144415f4e4654",
"20000000000"
'9985928ac3a33e05e884d5cac04c338036b8a35ea9198ffa9c01894e.696574685f4144415f4e4654',
'20000000000',
],
[
"a6379c282c824035b99725fc1d476b0087aeb8c510fd28c06a2fde44.434c41595f4144415f4e4654",
"20000000000"
'a6379c282c824035b99725fc1d476b0087aeb8c510fd28c06a2fde44.434c41595f4144415f4e4654',
'20000000000',
],
[
"5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.706f6f6c5f6e6674",
"10"
'5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.706f6f6c5f6e6674',
'10',
],
[
"8110fec4abdd3912a07683a776e2936323089745f472152fedded11e.697573645f4144415f4e4654",
"20000000000"
'8110fec4abdd3912a07683a776e2936323089745f472152fedded11e.697573645f4144415f4e4654',
'20000000000',
],
[
"e36480a99003832c2a4dd7b9919915e5c9b5b00244117e5f5ece009d.697573645f4144415f4e4654",
"20000000000"
'e36480a99003832c2a4dd7b9919915e5c9b5b00244117e5f5ece009d.697573645f4144415f4e4654',
'20000000000',
],
[
"5f4c10f0603a0106d3625922bd97e37e756657b7f253ca9b93fa6110.4e54585f4144415f4e4654",
"10000000000"
'5f4c10f0603a0106d3625922bd97e37e756657b7f253ca9b93fa6110.4e54585f4144415f4e4654',
'10000000000',
],
[
"4a27465112a39464e6dd5ee470c552ebb3cb42925d5ec04014967908.534e454b5f4144415f4e4654",
"20000000000"
'4a27465112a39464e6dd5ee470c552ebb3cb42925d5ec04014967908.534e454b5f4144415f4e4654',
'20000000000',
],
[
"5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.4144415f20534e454b5f4e4654",
"1000"
'5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.4144415f20534e454b5f4e4654',
'1000',
],
[
"93a109d2328a00bb9eef3c71c1a1de5172338adc7d70fc8cf97aaef8.636e6574615f6164615f6e6674",
"10000000000"
'93a109d2328a00bb9eef3c71c1a1de5172338adc7d70fc8cf97aaef8.636e6574615f6164615f6e6674',
'10000000000',
],
[
"aee90e8aae33944110d8b807d7564537400f7f646ca507cd26795ff1.634254435f4144415f4e4654",
"10000000000"
'aee90e8aae33944110d8b807d7564537400f7f646ca507cd26795ff1.634254435f4144415f4e4654',
'10000000000',
],
[
"a22ebe57c45d0be3ba4bebca5a9d4877b42d7fd872f3d740414fa124.414144415f4144415f4e4654",
"20000000000"
'a22ebe57c45d0be3ba4bebca5a9d4877b42d7fd872f3d740414fa124.414144415f4144415f4e4654',
'20000000000',
],
[
"2e11e7313e00ccd086cfc4f1c3ebed4962d31b481b6a153c23601c0f.636861726c69335f6164615f6e6674",
"10000000000"
'2e11e7313e00ccd086cfc4f1c3ebed4962d31b481b6a153c23601c0f.636861726c69335f6164615f6e6674',
'10000000000',
],
[
"5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.6e65775f6e6674",
"100000000"
'5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.6e65775f6e6674',
'100000000',
],
[
"4871a6b35de12a92b519fa048b8378b87f159b1725700d3f69c035aa.4d454c445f4144415f4e4654",
"10000000000"
'4871a6b35de12a92b519fa048b8378b87f159b1725700d3f69c035aa.4d454c445f4144415f4e4654',
'10000000000',
],
[
"2ddd621a1658e031c0ef3421bb60a3350b5bc0d062a7e8f94a7f109b.4c515f4144415f4e4654",
"20000000000"
'2ddd621a1658e031c0ef3421bb60a3350b5bc0d062a7e8f94a7f109b.4c515f4144415f4e4654',
'20000000000',
],
[
"bca5f2951474244a220f7336f5789fbf9cfbb7fe62bf225a9c99fcae.636e6574615f6164615f6e6674",
"10000000000"
'bca5f2951474244a220f7336f5789fbf9cfbb7fe62bf225a9c99fcae.636e6574615f6164615f6e6674',
'10000000000',
],
[
"e6f445feb406f4151b5e69f51115a42027d2e8f0dc2a7d84c2f03a01.4e54585f4144415f4e4654",
"20000000000"
'e6f445feb406f4151b5e69f51115a42027d2e8f0dc2a7d84c2f03a01.4e54585f4144415f4e4654',
'20000000000',
],
[
"b992582b95a3ee20cb4025699808c83caaefa7bae9387b72ba2c57c3.4941475f4144415f4e4654",
"20000000000"
'b992582b95a3ee20cb4025699808c83caaefa7bae9387b72ba2c57c3.4941475f4144415f4e4654',
'20000000000',
],
[
"cb15b0ae5322d0b5ec3c91398da464505084daab7e0e419fd59d63fb.636861726c69335f6164615f6e6674",
"10000000000"
'cb15b0ae5322d0b5ec3c91398da464505084daab7e0e419fd59d63fb.636861726c69335f6164615f6e6674',
'10000000000',
],
[
"d0861c6a8e913001a9ceaca2c8f3d403c7ed541e27fab570c0d17a32.494e44495f4144415f4e4654",
"20000000000"
'd0861c6a8e913001a9ceaca2c8f3d403c7ed541e27fab570c0d17a32.494e44495f4144415f4e4654',
'20000000000',
],
[
"5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.534e454b5f53554e4441455f4e4654",
"5000000"
]
'5ac3d4bdca238105a040a565e5d7e734b7c9e1630aec7650e809e34a.534e454b5f53554e4441455f4e4654',
'5000000',
],
]);

export class AnalyticPoolNetwork implements Pools {
Expand All @@ -179,70 +179,72 @@ export class AnalyticPoolNetwork implements Pools {
}

getAll(): Promise<[AmmPool[], number]> {
return cardanoNetworkData.name === "cardano" ?
this.request()
.then((rawAmmPools) => Object.values(rawAmmPools).map(this.createAmmPool))
.then((ammPools) => [ammPools, ammPools.length]) :
Promise.resolve([[], 0]);
return cardanoNetworkData.name === 'cardano'
? this.request()
.then((rawAmmPools) =>
Object.values(rawAmmPools).map(this.createAmmPool),
)
.then((ammPools) => [ammPools, ammPools.length])
: Promise.resolve([[], 0]);
}

getByTokens(): Promise<[AmmPool[], number]> {
throw new Error("not implemented");
throw new Error('not implemented');
}

getByTokensUnion(): Promise<[AmmPool[], number]> {
throw new Error("not implemented");
throw new Error('not implemented');
}

private request() {
return axios
.get<Dictionary<AmmPoolAnalytics>>(
`${cardanoNetworkData.analyticUrl}front/pools`,
{ params: { after: 0 } }
{ params: { after: 0 } },
)
.then((res) => res.data as Dictionary<AmmPoolAnalytics>);
}

private createAmmPool(rawAmmPool: AmmPoolAnalytics): AmmPool {
const [nftPolicyId, nftName] = rawAmmPool.id.split(".");
const [nftPolicyId, nftName] = rawAmmPool.id.split('.');
const nftAsset: AssetClass = {
policyId: nftPolicyId,
name: nftName,
nameHex: this.assetNameToHex(nftName)
nameHex: this.assetNameToHex(nftName),
};
const lqAsset: AssetClass = {
policyId: rawAmmPool.lockedLQ.asset.currencySymbol,
name: rawAmmPool.lockedLQ.asset.tokenName,
nameHex: this.assetNameToHex(rawAmmPool.lockedLQ.asset.tokenName)
nameHex: this.assetNameToHex(rawAmmPool.lockedLQ.asset.tokenName),
};
const xAsset: AssetClass = {
policyId: rawAmmPool.lockedX.asset.currencySymbol,
name: rawAmmPool.lockedX.asset.tokenName,
nameHex: this.assetNameToHex(rawAmmPool.lockedX.asset.tokenName)
nameHex: this.assetNameToHex(rawAmmPool.lockedX.asset.tokenName),
};
const yAsset: AssetClass = {
policyId: rawAmmPool.lockedY.asset.currencySymbol,
name: rawAmmPool.lockedY.asset.tokenName,
nameHex: this.assetNameToHex(rawAmmPool.lockedY.asset.tokenName)
nameHex: this.assetNameToHex(rawAmmPool.lockedY.asset.tokenName),
};

return new AmmPool(
nftAsset,
new AssetAmount(lqAsset, EmissionLP-BigInt(rawAmmPool.lockedLQ.amount)),
new AssetAmount(lqAsset, EmissionLP - BigInt(rawAmmPool.lockedLQ.amount)),
new AssetAmount(xAsset, BigInt(rawAmmPool.lockedX.amount)),
new AssetAmount(yAsset, BigInt(rawAmmPool.lockedY.amount)),
rawAmmPool.poolFeeNum,
BigInt(
mapPoolIdToLqBound.get(
`${nftPolicyId}.${encodeHex(new TextEncoder().encode(nftName))}`
) || "0"
)
`${nftPolicyId}.${encodeHex(new TextEncoder().encode(nftName))}`,
) || '0',
),
);
}

private assetNameToHex(name: string): HexString {
return RustModule.CardanoWasm.AssetName.from_json(
`"${encodeHex(new TextEncoder().encode(name))}"`
`"${encodeHex(new TextEncoder().encode(name))}"`,
).to_hex();
}
}
Loading

0 comments on commit 5239cba

Please sign in to comment.