|
@@ -152,12 +152,12 @@ export class SniperEngine {
|
|
|
parentPositionAddress,
|
|
parentPositionAddress,
|
|
|
copyUsdValue
|
|
copyUsdValue
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (success) {
|
|
if (success) {
|
|
|
this.copiedCache.add(parentPositionAddress, {
|
|
this.copiedCache.add(parentPositionAddress, {
|
|
|
poolAddress,
|
|
poolAddress,
|
|
|
targetUsdValue: copyBaseValue,
|
|
targetUsdValue: copyBaseValue,
|
|
|
- copiedAt: new Date().toISOString(),
|
|
|
|
|
|
|
+ copiedAt: new Date().toISOString(), // 关仓时用 copiedAt 与 positionAgeMs 匹配「我的」子仓位
|
|
|
targetPositionAddress: targetPositionAddress,
|
|
targetPositionAddress: targetPositionAddress,
|
|
|
calculation: calculation, // Store calculation details
|
|
calculation: calculation, // Store calculation details
|
|
|
});
|
|
});
|
|
@@ -429,12 +429,23 @@ export class SniperEngine {
|
|
|
this.copiedCache.has(parentPositionAddress)) {
|
|
this.copiedCache.has(parentPositionAddress)) {
|
|
|
|
|
|
|
|
logger.warn(`Target closed their copied position: ${targetPositionAddress}`);
|
|
logger.warn(`Target closed their copied position: ${targetPositionAddress}`);
|
|
|
- logger.info(`Closing our copy of parent position: ${parentPositionAddress}`);
|
|
|
|
|
|
|
+ const copiedData = this.copiedCache.get(parentPositionAddress);
|
|
|
|
|
+ logger.info('Resolving our position address by parent (and copy time if multiple)...');
|
|
|
|
|
+ const myPositionAddress = await ByrealAPI.getMyPositionAddressForParent(
|
|
|
|
|
+ parentPositionAddress,
|
|
|
|
|
+ this.myWallet,
|
|
|
|
|
+ copiedData?.poolAddress,
|
|
|
|
|
+ copiedData?.copiedAt
|
|
|
|
|
+ );
|
|
|
|
|
+ if (!myPositionAddress) {
|
|
|
|
|
+ logger.error(`Could not resolve our position for parent ${parentPositionAddress}, skip close`);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ logger.info(`Closing our position: ${myPositionAddress} (parent was ${parentPositionAddress})`);
|
|
|
|
|
|
|
|
- const success = await ByrealAPI.closePosition(parentPositionAddress);
|
|
|
|
|
|
|
+ const success = await ByrealAPI.closePosition(myPositionAddress);
|
|
|
|
|
|
|
|
if (success) {
|
|
if (success) {
|
|
|
- const copiedData = this.copiedCache.get(parentPositionAddress);
|
|
|
|
|
this.closedCache.add(parentPositionAddress, {
|
|
this.closedCache.add(parentPositionAddress, {
|
|
|
closedAt: new Date().toISOString(),
|
|
closedAt: new Date().toISOString(),
|
|
|
reason: `Target closed their position ${targetPositionAddress}`,
|
|
reason: `Target closed their position ${targetPositionAddress}`,
|
|
@@ -444,7 +455,7 @@ export class SniperEngine {
|
|
|
|
|
|
|
|
// Send Discord notification
|
|
// Send Discord notification
|
|
|
this.discord.notifyCloseSuccess({
|
|
this.discord.notifyCloseSuccess({
|
|
|
- positionAddress: parentPositionAddress,
|
|
|
|
|
|
|
+ positionAddress: myPositionAddress,
|
|
|
poolName: copiedData?.calculation?.tokenA?.symbol && copiedData?.calculation?.tokenB?.symbol
|
|
poolName: copiedData?.calculation?.tokenA?.symbol && copiedData?.calculation?.tokenB?.symbol
|
|
|
? `${copiedData.calculation.tokenA.symbol}/${copiedData.calculation.tokenB.symbol}`
|
|
? `${copiedData.calculation.tokenA.symbol}/${copiedData.calculation.tokenB.symbol}`
|
|
|
: 'Unknown Pool',
|
|
: 'Unknown Pool',
|