Skip to content

Commit bd72e14

Browse files
committed
WR v2 & Sundae fixes
1 parent df260e5 commit bd72e14

File tree

11 files changed

+154
-54
lines changed

11 files changed

+154
-54
lines changed

src/IndexerApplication.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class IndexerApplication {
5050
new SundaeSwapAnalyzer(this),
5151
new SundaeSwapV3Analyzer(this),
5252
new WingRidersAnalyzer(this),
53-
// new WingRidersV2Analyzer(this),
53+
new WingRidersV2Analyzer(this),
5454
new SpectrumAnalyzer(this),
5555
new TeddySwapAnalyzer(this),
5656
new VyFiAnalyzer(this),
@@ -189,7 +189,7 @@ export class IndexerApplication {
189189
* TeddySwap - 109078697, 8494922f6266885a671408055d7123e1c7bdf78b9cd86720680c55c1f94e839e
190190
* GeniusYield - 110315300, d7281a52d68eef89a7472860fdece323ecc39d3054cdd1fa0825afe56b942a86
191191
* Minswap v2 - 128247239, d7edc62dcfeb8e809f4a8584354b9bf0df640d365ff47cb26a0f9e972ba1dca4
192-
* WingRiders v2 - 133796834, 4525344131bc0f7a85b375d8bab72ac17518038f29ed613e4bbaae8e9757dca4
192+
* WingRiders v2 - 133880255, 5cab603d6ca6f5dd5bc0ae92cbe7f4b796f330004ca64b5ad74c2e27577fb539
193193
*/
194194
return lastSync
195195
? this._chainSyncClient?.resume([{ slot: lastSync.slot, id: lastSync.blockHash }])

src/api/controllers/LiquidityPoolController.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,15 +804,13 @@ export class LiquidityPoolController extends BaseApiController {
804804
}).then((results: any) => {
805805
response.send(
806806
results.reduce((prices: Object[], entry: any) => {
807+
if (! entry.latestState) return prices;
808+
807809
const tokenADecimals: number = entry.tokenA ? entry.tokenA.decimals : 6;
808810
const tokenBDecimals: number = entry.tokenB.decimals ?? 0;
809811

810812
const price: number = (entry.latestState.reserveA / 10**tokenADecimals) / (entry.latestState.reserveB / 10**tokenBDecimals);
811813

812-
if (entry.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
813-
console.log(entry.hour_tick, price)
814-
}
815-
816814
prices.push({
817815
identifier: entry.identifier,
818816
price: price,

src/api/controllers/OrdersController.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class OrdersController extends BaseApiController {
2828
private swaps(request: express.Request, response: express.Response) {
2929
const {
3030
pubKeyHashes,
31+
stakeKeyHashes,
3132
} = request.body;
3233
const {
3334
poolIdentifier,
@@ -44,7 +45,7 @@ export class OrdersController extends BaseApiController {
4445
? (token as string).split('.')
4546
: [null, null];
4647

47-
if (pubKeyHashes.length === 0) {
48+
if (! pubKeyHashes && ! stakeKeyHashes) {
4849
response.send(super.formatPaginatedResponse(
4950
Number(page ?? 1),
5051
Number(limit ?? MAX_PER_PAGE),
@@ -69,9 +70,24 @@ export class OrdersController extends BaseApiController {
6970
operationType: LiquidityPoolSwap.name,
7071
}
7172
)
72-
.where('swaps.senderPubKeyHash IN(:...hashes)', { hashes: pubKeyHashes })
7373
.andWhere(
7474
new Brackets((query) => {
75+
query.andWhere(
76+
new Brackets((query1) => {
77+
if (pubKeyHashes && pubKeyHashes.length > 0) {
78+
query1.orWhere('swaps.senderPubKeyHash IN(:...pkHashes)', {
79+
pkHashes: pubKeyHashes,
80+
});
81+
}
82+
83+
if (stakeKeyHashes && stakeKeyHashes.length > 0) {
84+
query1.orWhere('swaps.senderStakeKeyHash IN(:...skHashes)', {
85+
skHashes: stakeKeyHashes,
86+
});
87+
}
88+
})
89+
);
90+
7591
if (poolIdentifier) {
7692
query.andWhere('liquidityPool.identifier = :identifier', {
7793
identifier: poolIdentifier,
@@ -131,6 +147,7 @@ export class OrdersController extends BaseApiController {
131147
private deposits(request: express.Request, response: express.Response) {
132148
const {
133149
pubKeyHashes,
150+
stakeKeyHashes,
134151
} = request.body;
135152
const {
136153
poolIdentifier,
@@ -146,7 +163,7 @@ export class OrdersController extends BaseApiController {
146163
? (token as string).split('.')
147164
: [null, null];
148165

149-
if (pubKeyHashes.length === 0) {
166+
if (! pubKeyHashes && ! stakeKeyHashes) {
150167
response.send(super.formatPaginatedResponse(
151168
Number(page ?? 1),
152169
Number(limit ?? MAX_PER_PAGE),
@@ -171,7 +188,6 @@ export class OrdersController extends BaseApiController {
171188
operationType: LiquidityPoolDeposit.name,
172189
}
173190
)
174-
.where('deposits.senderPubKeyHash IN(:...hashes)', { hashes: pubKeyHashes })
175191
.andWhere(
176192
new Brackets((query) => {
177193
if (poolIdentifier) {
@@ -180,6 +196,18 @@ export class OrdersController extends BaseApiController {
180196
});
181197
}
182198

199+
if (pubKeyHashes && pubKeyHashes.length > 0) {
200+
query.andWhere('deposits.senderPubKeyHash IN(:...pkHashes)', {
201+
pkHashes: pubKeyHashes,
202+
});
203+
}
204+
205+
if (stakeKeyHashes && stakeKeyHashes.length > 0) {
206+
query.andWhere('deposits.senderStakeKeyHash IN(:...skHashes)', {
207+
skHashes: stakeKeyHashes,
208+
});
209+
}
210+
183211
if (policyId && nameHex) {
184212
query.andWhere(new Brackets((query1) => {
185213
query1.where('depositAToken.policyId = :policyId', {
@@ -218,6 +246,7 @@ export class OrdersController extends BaseApiController {
218246
private withdraws(request: express.Request, response: express.Response) {
219247
const {
220248
pubKeyHashes,
249+
stakeKeyHashes,
221250
} = request.body;
222251
const {
223252
poolIdentifier,
@@ -228,7 +257,7 @@ export class OrdersController extends BaseApiController {
228257
const take: number = Math.min(Number((limit ? +limit : undefined) || MAX_PER_PAGE), MAX_PER_PAGE);
229258
const skip: number = (Math.max(Number((page ? +page : undefined) || 1), 1) - 1) * take;
230259

231-
if (pubKeyHashes.length === 0) {
260+
if (! pubKeyHashes && ! stakeKeyHashes) {
232261
response.send(super.formatPaginatedResponse(
233262
Number(page ?? 1),
234263
Number(limit ?? MAX_PER_PAGE),
@@ -252,7 +281,6 @@ export class OrdersController extends BaseApiController {
252281
operationType: LiquidityPoolWithdraw.name,
253282
}
254283
)
255-
.where('withdraws.senderPubKeyHash IN(:...hashes)', { hashes: pubKeyHashes })
256284
.andWhere(
257285
new Brackets((query) => {
258286
if (poolIdentifier) {
@@ -261,6 +289,18 @@ export class OrdersController extends BaseApiController {
261289
});
262290
}
263291

292+
if (pubKeyHashes && pubKeyHashes.length > 0) {
293+
query.andWhere('withdraws.senderPubKeyHash IN(:...pkHashes)', {
294+
pkHashes: pubKeyHashes,
295+
});
296+
}
297+
298+
if (stakeKeyHashes && stakeKeyHashes.length > 0) {
299+
query.andWhere('withdraws.senderStakeKeyHash IN(:...skHashes)', {
300+
skHashes: stakeKeyHashes,
301+
});
302+
}
303+
264304
return query;
265305
}),
266306
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { MigrationInterface, QueryRunner, TableIndex } from 'typeorm';
2+
3+
export class CreateStakeKeyHashIndexes1731944573000 implements MigrationInterface {
4+
5+
public async up(queryRunner: QueryRunner): Promise<void> {
6+
await queryRunner.createIndices('liquidity_pool_swaps', [
7+
new TableIndex({
8+
columnNames: ['senderStakeKeyHash'],
9+
isUnique: false,
10+
}),
11+
]);
12+
await queryRunner.createIndices('liquidity_pool_deposits', [
13+
new TableIndex({
14+
columnNames: ['senderStakeKeyHash'],
15+
isUnique: false,
16+
}),
17+
]);
18+
await queryRunner.createIndices('liquidity_pool_withdraws', [
19+
new TableIndex({
20+
columnNames: ['senderStakeKeyHash'],
21+
isUnique: false,
22+
}),
23+
]);
24+
await queryRunner.createIndices('liquidity_pool_zaps', [
25+
new TableIndex({
26+
columnNames: ['senderStakeKeyHash'],
27+
isUnique: false,
28+
}),
29+
]);
30+
}
31+
32+
public async down(queryRunner: QueryRunner): Promise<void> {
33+
await queryRunner.dropIndices('liquidity_pool_swaps', [
34+
new TableIndex({
35+
columnNames: ['senderStakeKeyHash'],
36+
isUnique: false,
37+
}),
38+
]);
39+
await queryRunner.dropIndices('liquidity_pool_deposits', [
40+
new TableIndex({
41+
columnNames: ['senderStakeKeyHash'],
42+
isUnique: false,
43+
}),
44+
]);
45+
await queryRunner.dropIndices('liquidity_pool_withdraws', [
46+
new TableIndex({
47+
columnNames: ['senderStakeKeyHash'],
48+
isUnique: false,
49+
}),
50+
]);
51+
await queryRunner.dropIndices('liquidity_pool_zaps', [
52+
new TableIndex({
53+
columnNames: ['senderStakeKeyHash'],
54+
isUnique: false,
55+
}),
56+
]);
57+
}
58+
59+
}

src/dex/WingRidersAnalyzer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { OperationStatus } from '../db/entities/OperationStatus';
2727
* WingRiders constants.
2828
*/
2929
const ORDER_CONTRACT_ADDRESS: string = 'addr1wxr2a8htmzuhj39y2gq7ftkpxv98y2g67tg8zezthgq4jkg0a4ul4';
30-
const POOL_NFT_POLICY_ID: string = '6fdc63a1d71dc2c65502b79baae7fb543185702b12c3c5fb639ed737';
30+
const POOL_NFT_POLICY_ID: string = '026a18d04a0c642759bb3d83b12e3344894e5c1c7b2aeb1a2113a570';
3131
const MIN_POOL_ADA: bigint = 3_000_000n;
3232
const MAX_INT: bigint = 9_223_372_036_854_775_807n;
3333
const BATCHER_FEE: bigint = 2000000n;

src/dex/WingRidersV2Analyzer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { OperationStatus } from '../db/entities/OperationStatus';
2727
* WingRiders constants.
2828
*/
2929
const ORDER_CONTRACT_ADDRESS: string = 'addr1w8qnfkpe5e99m7umz4vxnmelxs5qw5dxytmfjk964rla98q605wte';
30-
const POOL_NFT_POLICY_ID: string = '026a18d04a0c642759bb3d83b12e3344894e5c1c7b2aeb1a2113a570';
30+
const POOL_NFT_POLICY_ID: string = '6fdc63a1d71dc2c65502b79baae7fb543185702b12c3c5fb639ed737';
3131
const MIN_POOL_ADA: bigint = 3_000_000n;
3232
const MAX_INT: bigint = 9_223_372_036_854_775_807n;
3333
const BATCHER_FEE: bigint = 2000000n;
@@ -36,7 +36,7 @@ const CANCEL_ORDER_DATUM: string = 'd87a80';
3636

3737
export class WingRidersV2Analyzer extends BaseAmmDexAnalyzer {
3838

39-
public startSlot: number = 133796834;
39+
public startSlot: number = 133880255;
4040

4141
/**
4242
* Analyze transaction for possible DEX operations.
@@ -83,7 +83,7 @@ export class WingRidersV2Analyzer extends BaseAmmDexAnalyzer {
8383
swapInAmount = output.assetBalances[0].quantity;
8484
} else {
8585
swapInToken = 'lovelace';
86-
swapInAmount = output.lovelaceBalance - BATCHER_FEE - BigInt(datumParameters.PoolAssetBAssetName as string);
86+
swapInAmount = output.lovelaceBalance - BATCHER_FEE - BigInt(datumParameters.Deposit as string);
8787
}
8888

8989
swapOutToken = tokensMatch(poolTokenA, swapInToken)
@@ -245,7 +245,7 @@ export class WingRidersV2Analyzer extends BaseAmmDexAnalyzer {
245245
depositAToken,
246246
depositBToken,
247247
Number(depositAToken === 'lovelace'
248-
? output.lovelaceBalance - BATCHER_FEE - BigInt(datumParameters.PoolAssetBAssetName as string)
248+
? output.lovelaceBalance - BATCHER_FEE - BigInt(datumParameters.Deposit as string)
249249
: output.assetBalances[0].quantity),
250250
Number(depositAToken === 'lovelace'
251251
? output.assetBalances[0].quantity

src/dex/definitions/sundaeswap-v3/swap.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DatumParameterKey } from '../../../constants';
2+
import { DatumParameters, DefinitionField } from '../../../types';
23

34
export default {
45
constructor: 0,
@@ -12,10 +13,10 @@ export default {
1213
],
1314
},
1415
{
15-
constructor: 0,
16+
constructor: DatumParameterKey.Unknown,
1617
fields: [
1718
{
18-
bytes: DatumParameterKey.SenderStakingKeyHash,
19+
bytes: DatumParameterKey.Unknown,
1920
},
2021
],
2122
},
@@ -29,36 +30,35 @@ export default {
2930
constructor: 0,
3031
fields: [
3132
{
32-
constructor: 0,
33+
constructor: DatumParameterKey.Unknown,
3334
fields: [
3435
{
3536
bytes: DatumParameterKey.SenderPubKeyHash,
3637
},
3738
],
3839
},
39-
{
40-
constructor: 0,
41-
fields: [
42-
{
43-
constructor: 0,
44-
fields: [
45-
{
46-
constructor: 0,
47-
fields: [
48-
{
49-
bytes: DatumParameterKey.SenderStakingKeyHash,
50-
},
51-
],
52-
},
53-
],
54-
},
55-
],
56-
},
40+
(field: DefinitionField, foundParameters: DatumParameters) => {
41+
if ('fields' in field) {
42+
if (field.constructor === 1) {
43+
return;
44+
}
45+
46+
const constr: DefinitionField = field.fields[0];
47+
48+
if ('fields' in constr && 'fields' in constr.fields[0] && 'bytes' in constr.fields[0].fields[0]) {
49+
const field: DefinitionField = constr.fields[0].fields[0];
50+
foundParameters[DatumParameterKey.SenderStakingKeyHash] = field.bytes;
51+
52+
return;
53+
}
54+
}
55+
56+
throw new Error("Template definition does not match with 'bytes'");
57+
}
5758
],
5859
},
59-
{
60-
constructor: 0,
61-
fields: [],
60+
(field: DefinitionField, parameters: DatumParameters, shouldExtract: boolean = true) => {
61+
return;
6262
},
6363
],
6464
},
@@ -89,8 +89,8 @@ export default {
8989
],
9090
],
9191
},
92-
{
93-
bytes: DatumParameterKey.CancelDatum,
92+
(field: DefinitionField, parameters: DatumParameters, shouldExtract: boolean = true) => {
93+
return;
9494
},
9595
],
9696
}

0 commit comments

Comments
 (0)