Skip to content

Commit

Permalink
Split apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Tsymbal authored and tsmbl committed May 25, 2022
1 parent e6cbb52 commit b15422a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
35 changes: 8 additions & 27 deletions src/saber-wars-api/quarry-sdk-factory.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { GaugeSDK } from '@quarryprotocol/gauge';
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import { Connection, Keypair } from '@solana/web3.js';
import * as anchor from '@project-serum/anchor';
import { Provider } from '@project-serum/anchor';
import NodeWallet from '@project-serum/anchor/dist/cjs/nodewallet';
import { makeSaberProvider } from '@saberhq/anchor-contrib';
import { QuarrySDK } from '@quarryprotocol/quarry-sdk';

const connection = new Connection(
process.env.QUARRY_RPC_URL ?? process.env.RPC_URL!,
{
commitment: 'recent',
},
);
const connection = new Connection(process.env.MAINNET_RPC_URL, 'recent');

const keypair = new Keypair();
const wallet = new NodeWallet(keypair);
const provider1 = new Provider(connection, wallet, Provider.defaultOptions());
const provider1 = new Provider(
connection,
wallet,
anchor.Provider.defaultOptions(),
);
const provider = makeSaberProvider(provider1);
export const gaugeSdk = GaugeSDK.load({
provider,
Expand All @@ -23,22 +23,3 @@ export const gaugeSdk = GaugeSDK.load({
export const quarrySDK = QuarrySDK.load({
provider,
});

const mmPkToOwnerPk: Map<string, PublicKey> = new Map<string, PublicKey>();

export async function getOwner(authority: PublicKey): Promise<PublicKey> {
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);
}
2 changes: 1 addition & 1 deletion src/saber-wars-api/token-info-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export async function getTokenInfo(address: string | PublicKey) {
.then((it) => it.data);
cache.set(tokenMintAddress, tokenMintInfo);
}
return cache.get(tokenMintAddress)!;
return cache.get(tokenMintAddress);
}

0 comments on commit b15422a

Please sign in to comment.