Skip to content

Commit 86cc6d0

Browse files
committed
Minswap v2
1 parent b23e31f commit 86cc6d0

File tree

9 files changed

+961
-2
lines changed

9 files changed

+961
-2
lines changed

src/IndexerApplication.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class IndexerApplication {
5353
new VyFiAnalyzer(this),
5454
]),
5555
new OrderBookDexTransactionIndexer([
56-
new GeniusYieldAnalyzer(this),
56+
// new GeniusYieldAnalyzer(this),
5757
// new AxoAnalyzer(this),
5858
]),
5959
new HybridDexTransactionIndexer([
@@ -176,6 +176,7 @@ export class IndexerApplication {
176176
* Spectrum - 98301694, d0d2abcaf741be13d353ac80b0f9001d7b323a2b5827ff2dce6480bf032dd3db
177177
* TeddySwap - 109078697, 8494922f6266885a671408055d7123e1c7bdf78b9cd86720680c55c1f94e839e
178178
* GeniusYield - 110315300, d7281a52d68eef89a7472860fdece323ecc39d3054cdd1fa0825afe56b942a86
179+
* Minswap v2 - 128247239, d7edc62dcfeb8e809f4a8584354b9bf0df640d365ff47cb26a0f9e972ba1dca4
179180
*/
180181
return lastSync
181182
? this.chainSyncClient.startSync([{ slot: lastSync.slot, hash: lastSync.blockHash }])

src/api/controllers/AssetController.ts

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { BaseApiController } from './BaseApiController';
22
import express from 'express';
33
import { dbApiService } from '../../apiServices';
4-
import { Brackets, EntityManager } from 'typeorm';
4+
import { Brackets, EntityManager, SelectQueryBuilder } from 'typeorm';
55
import { Asset } from '../../db/entities/Asset';
66
import { AssetResource } from '../resources/AssetResource';
77
import { LiquidityPoolState } from '../../db/entities/LiquidityPoolState';
88
import { LiquidityPoolResource } from '../resources/LiquidityPoolResource';
99
import { LiquidityPool } from '../../db/entities/LiquidityPool';
10+
import { TickInterval } from '../../constants';
11+
import { LiquidityPoolTick } from '../../db/entities/LiquidityPoolTick';
12+
import { LiquidityPoolTickResource } from '../resources/LiquidityPoolTickResource';
1013

1114
const MAX_PER_PAGE: number = 100;
1215

@@ -16,6 +19,7 @@ export class AssetController extends BaseApiController {
1619
this.router.get(`${this.basePath}`, this.assets);
1720
this.router.post(`${this.basePath}`, this.assets);
1821
this.router.get(`${this.basePath}/search`, this.search);
22+
this.router.post(`${this.basePath}/ticks`, this.ticks);
1923
this.router.get(`${this.basePath}/:lpToken/pool`, this.lpTokenPool);
2024
this.router.get(`${this.basePath}/:asset`, this.asset);
2125
this.router.get(`${this.basePath}/:asset/price`, this.assetPrice);
@@ -217,4 +221,74 @@ export class AssetController extends BaseApiController {
217221
}).catch(() => response.send(super.failResponse('Unable to retrieve asset price')));
218222
}
219223

224+
private ticks(request: express.Request, response: express.Response) {
225+
const {
226+
forAssets,
227+
} = request.body;
228+
const {
229+
resolution,
230+
fromTime,
231+
toTime,
232+
orderBy,
233+
} = request.query;
234+
235+
if (forAssets && ! (forAssets instanceof Array)) {
236+
return response.send(super.failResponse('Assets must be an array'));
237+
}
238+
if (! (Object.values(TickInterval) as string[]).includes(resolution as string)) {
239+
return response.send(super.failResponse(`Must supply 'resolution' as ${Object.values(TickInterval).join(',')}`));
240+
}
241+
if (orderBy && ! ['ASC', 'DESC'].includes(orderBy as string)) {
242+
return response.send(super.failResponse("orderBy must be 'ASC' or 'DESC'"));
243+
}
244+
245+
const assets: Asset[] = ((forAssets ?? []) as string[]).map((identifier: string) => Asset.fromId(identifier));
246+
const policyIds: string[] = assets.map((asset: Asset) => asset.policyId);
247+
const nameHexs: string[] = assets.map((asset: Asset) => asset.nameHex);
248+
249+
const fetchTicks: any = (manager: EntityManager) => {
250+
return manager.createQueryBuilder(LiquidityPoolTick, 'ticks')
251+
.leftJoinAndSelect('ticks.liquidityPool', 'liquidityPool')
252+
.leftJoinAndMapOne(
253+
'liquidityPool.latestState',
254+
LiquidityPoolState,
255+
'states',
256+
'states.liquidityPoolId = liquidityPool.id AND states.id = (SELECT MAX(id) FROM liquidity_pool_states WHERE liquidity_pool_states.slot + 1596491091 - 4924800 <= ticks.time AND liquidity_pool_states.liquidityPoolId = liquidityPool.id)'
257+
)
258+
.leftJoinAndSelect('liquidityPool.tokenB', 'tokenB')
259+
.andWhere('liquidityPool.tokenA IS NULL')
260+
.andWhere(
261+
new Brackets((query) => {
262+
query.andWhere('tokenB.policyId IN(:policyIds) AND tokenB.nameHex IN(:nameHexs)', {
263+
policyIds,
264+
nameHexs,
265+
});
266+
267+
if (fromTime && ! isNaN(parseInt(fromTime as string))) {
268+
query.andWhere('ticks.time >= :fromTime', {
269+
fromTime: parseInt(fromTime as string),
270+
});
271+
}
272+
273+
if (toTime && ! isNaN(parseInt(toTime as string))) {
274+
query.andWhere('ticks.time < :toTime', {
275+
toTime: parseInt(toTime as string),
276+
});
277+
}
278+
279+
return query;
280+
}),
281+
)
282+
.orderBy('time', orderBy ? (orderBy as 'ASC' | 'DESC') : 'ASC')
283+
.getMany();
284+
};
285+
286+
return dbApiService.transaction(fetchTicks)
287+
.then((ticks: LiquidityPoolTick[]) => {
288+
const resource: LiquidityPoolTickResource = new LiquidityPoolTickResource();
289+
290+
response.send(resource.manyToJson(ticks));
291+
}).catch((e) => response.send(super.failResponse(e)));
292+
}
293+
220294
}

src/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export enum DatumParameterKey {
3636
OpeningFee = 'OpeningFee',
3737
FinalFee = 'FinalFee',
3838
ProtocolFee = 'ProtocolFee',
39+
BaseFee = 'BaseFee',
40+
FeeSharingNumerator = 'FeeSharingNumerator',
41+
ReserveA = 'ReserveA',
42+
ReserveB = 'ReserveB',
43+
Direction = 'Direction',
3944

4045
TokenPolicyId = 'TokenPolicyId',
4146
TokenAssetName = 'TokenAssetName',
@@ -68,6 +73,7 @@ export enum DatumParameterKey {
6873

6974
export enum Dex {
7075
Minswap = 'Minswap',
76+
MinswapV2 = 'MinswapV2',
7177
SundaeSwap = 'SundaeSwap',
7278
SundaeSwapV3 = 'SundaeSwapV3',
7379
WingRiders = 'WingRiders',

0 commit comments

Comments
 (0)