Skip to content

Instantly share code, notes, and snippets.

@visvirial
Created January 22, 2022 01:53
Show Gist options
  • Save visvirial/9c3da950a517f08a20a178457faf7f45 to your computer and use it in GitHub Desktop.
Save visvirial/9c3da950a517f08a20a178457faf7f45 to your computer and use it in GitHub Desktop.
import fetch from 'cross-fetch';
import { PublicKey, Connection, Keypair, Transaction } from '@solana/web3.js';
import * as anchor from '@project-serum/anchor';
import { QuarrySDK } from '@quarryprotocol/quarry-sdk';
import { SolanaProvider } from "@saberhq/solana-contrib";
import { Token } from '@saberhq/token-utils';
export default class Wallet {
constructor(readonly payer: Keypair) {}
async signTransaction(tx: Transaction): Promise<Transaction> {
tx.partialSign(this.payer);
return tx;
}
async signAllTransactions(txs: Transaction[]): Promise<Transaction[]> {
return txs.map((t) => {
t.partialSign(this.payer);
return t;
});
}
get publicKey(): PublicKey {
return this.payer.publicKey;
}
}
export const makeSDK = (): QuarrySDK => {
const options = anchor.Provider.defaultOptions();
const connection = new Connection('https://solana-api.projectserum.com', options.commitment);
const wallet = new Wallet(Keypair.generate());
const anchorProvider = new anchor.Provider(connection, wallet, options);
anchor.setProvider(anchorProvider);
const provider = SolanaProvider.load({
connection: anchorProvider.connection,
sendConnection: anchorProvider.connection,
wallet: anchorProvider.wallet,
opts: anchorProvider.opts,
});
return QuarrySDK.load({
provider,
});
};
(async () => {
const sdk = makeSDK();
const mine = sdk.mine;
const rewarderKey = new PublicKey('rXhAofQCT7NN9TUqigyEAUzV1uLL4boeD8CRkNBSkYk');
const rewarderWrapper = await mine.loadRewarderWrapper(rewarderKey);
const tokenInfo = await (await fetch('https://raw.githubusercontent.com/saber-hq/saber-lp-token-list/master/lists/saber-lp.mainnet-beta.json')).json();
for(const token of tokenInfo.tokens) {
try {
const stakeToken = new Token(token);
const quarryWrapper = await rewarderWrapper.getQuarry(stakeToken);
const annualRewardsRate = Number.parseFloat(quarryWrapper.quarryData.annualRewardsRate.toString()) * 1e-6;
const dailyRewardsRate = annualRewardsRate / 365;
console.log(token.symbol, `${dailyRewardsRate.toFixed(0)} SBR/day`);
} catch(e) {
console.error(`E: Failed to fetch for ${token.symbol}`, (e as Error).toString());
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment