diff --git a/examples/quarry-events-example.ts b/examples/quarry-events-example.ts index 7621c88..6449862 100644 --- a/examples/quarry-events-example.ts +++ b/examples/quarry-events-example.ts @@ -1,19 +1,22 @@ -import { ClaimEvent, StakeEvent } from '@quarryprotocol/quarry-sdk'; -import { getTokenInfo } from '../src/saber-wars-api/token-info-api'; import { QuarryEventSubscription } from '../src/saber-wars-api/quarry-event-api'; -import { quarrySDK } from '../src/saber-wars-api/quarry-sdk-factory'; +import { getOwner, quarrySDK } from '../src/saber-wars-api/quarry-sdk-factory'; +import { getTokenInfo } from '../src/saber-wars-api/token-info-api'; +import { ClaimEvent, StakeEvent } from '@quarryprotocol/quarry-sdk'; async function main() { const defaultSubscription = new QuarryEventSubscription( quarrySDK.programs.Mine, async (it) => { + const owner = await getOwner(it.data.authority); switch (it.name) { case 'StakeEvent': { const stakeEvent = it as StakeEvent; const optionalParams = await getTokenInfo( stakeEvent.data.token.toBase58(), ); - console.log(stakeEvent, optionalParams); + console.log( + `Stake event from ${owner.toBase58()}, ${stakeEvent.data.amount.toNumber()}`, + ); break; } case 'ClaimEvent': { @@ -21,7 +24,9 @@ async function main() { const optionalParams = await getTokenInfo( claimEvent.data.rewardsToken.toBase58(), ); - console.log(claimEvent, optionalParams); + console.log( + `Claim event from ${owner.toBase58()}, ${claimEvent.data.amount.toNumber()}`, + ); break; } } diff --git a/package.json b/package.json index ea337d7..5393a27 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@nestjs/schedule": "^1.0.2", "@project-serum/anchor": "0.23.0", "@quarryprotocol/gauge": "^0.2.2", - "@quarryprotocol/quarry-sdk": "^2.0.1", + "@quarryprotocol/quarry-sdk": "^5.0.2", "@saberhq/anchor-contrib": "^1.12.61", "@saberhq/solana-contrib": "^1.12.61", "@saberhq/token-utils": "^1.12.61", diff --git a/src/monitor/saber-monitoring-service.ts b/src/monitor/saber-monitoring-service.ts index fb0e288..48b362d 100644 --- a/src/monitor/saber-monitoring-service.ts +++ b/src/monitor/saber-monitoring-service.ts @@ -24,7 +24,7 @@ import { Cron } from '@nestjs/schedule'; import { DialectConnection } from './dialect-connection'; import { Subject } from 'rxjs'; import { QuarryEventSubscription } from '../saber-wars-api/quarry-event-api'; -import { quarrySDK } from '../saber-wars-api/quarry-sdk-factory'; +import { getOwner, quarrySDK } from '../saber-wars-api/quarry-sdk-factory'; import { getTokenInfo } from '../saber-wars-api/token-info-api'; import { TwitterNotificationSink } from './twitter-notification-sink'; import { OnChainSubscriberRepository } from '@dialectlabs/monitor/lib/cjs/internal/on-chain-subscriber.repository'; @@ -108,7 +108,7 @@ Time remaining in epoch: ${epochInfo.currentEpochRemainingTime.toFormat( } const resourceId = process.env.TEST_MODE ? (await subscriberRepository.findAll())[0] - : evt.data.authority; + : await getOwner(evt.data.authority); if (evt.name === 'StakeEvent') { const tokenInfo = await getTokenInfo(evt.data.token); quarryEvents.next({ diff --git a/src/saber-wars-api/quarry-sdk-factory.ts b/src/saber-wars-api/quarry-sdk-factory.ts index f5b23e6..4c397bd 100644 --- a/src/saber-wars-api/quarry-sdk-factory.ts +++ b/src/saber-wars-api/quarry-sdk-factory.ts @@ -1,5 +1,5 @@ import { GaugeSDK } from '@quarryprotocol/gauge'; -import { Connection, Keypair } from '@solana/web3.js'; +import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import { Provider } from '@project-serum/anchor'; import NodeWallet from '@project-serum/anchor/dist/cjs/nodewallet'; import { makeSaberProvider } from '@saberhq/anchor-contrib'; @@ -23,3 +23,22 @@ export const gaugeSdk = GaugeSDK.load({ export const quarrySDK = QuarrySDK.load({ provider, }); + +const mmPkToOwnerPk: Map = new Map(); + +export async function getOwner(authority: PublicKey): Promise { + const cacheKey = authority.toBase58(); + if (!mmPkToOwnerPk.has(cacheKey)) { + try { + const mm = await quarrySDK.mergeMine.fetchMergeMinerData( + new PublicKey(authority), + ); + mmPkToOwnerPk.set(cacheKey, mm.data.owner); + } catch (e) { + mmPkToOwnerPk.set(cacheKey, authority); + // console.error(e); + } + } + const ownerPkBase58 = mmPkToOwnerPk.get(cacheKey)!; + return ownerPkBase58 && new PublicKey(ownerPkBase58); +}