Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/sample.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
INFURA_API_KEY=
PINATA_JWT=
PINATA_GATEWAY_URL=
PINATA_GATEWAY_API_KEY=
PINATA_GATEWAY_API_KEY=
THORNODE_URL=https://daemon.thorchain.shapeshift.com
UNCHAINED_URL=https://api.thorchain.shapeshift.com
22 changes: 16 additions & 6 deletions cli/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ import { error, info, warn } from './logging'
import { CalculateRewardsArgs, RewardDistribution } from './types'

const INFURA_API_KEY = process.env['INFURA_API_KEY']

if (!INFURA_API_KEY) {
error('INFURA_API_KEY not set. Please make sure you copied the sample.env and filled out your .env file.')
process.exit(1)
}

const THORNODE_URL = process.env['THORNODE_URL']
if (!THORNODE_URL) {
error('THORNODE_URL not set. Please make sure you copied the sample.env and filled out your .env file.')
process.exit(1)
}

const UNCHAINED_URL = process.env['UNCHAINED_URL']
if (!UNCHAINED_URL) {
error('UNCHAINED_URL not set. Please make sure you copied the sample.env and filled out your .env file.')
process.exit(1)
}

const AVERAGE_BLOCK_TIME_BLOCKS = 1000
const THORCHAIN_PRECISION = 8
const TOKEN_PRECISION = 18
Expand All @@ -32,6 +43,7 @@ export const stakingContracts = [
type Revenue = {
addresses: string[]
amount: string
revenue: Record<string, string>
}

type Pool = {
Expand Down Expand Up @@ -145,7 +157,7 @@ export class Client {
async getRevenue(startTimestamp: number, endTimestamp: number): Promise<Revenue> {
try {
const { data } = await axios.get<Revenue>(
`https://api.thorchain.shapeshift.com/api/v1/affiliate/revenue?start=${startTimestamp}&end=${endTimestamp}`,
`${UNCHAINED_URL}/api/v1/affiliate/revenue?start=${startTimestamp}&end=${endTimestamp}`,
)
return data
} catch (err) {
Expand All @@ -163,12 +175,10 @@ export class Client {

async getPrice(): Promise<Price> {
try {
const { data: ethPool } = await axios.get<Pool>(
'https://daemon.thorchain.shapeshift.com/lcd/thorchain/pool/ETH.ETH',
)
const { data: ethPool } = await axios.get<Pool>(`${THORNODE_URL}/lcd/thorchain/pool/ETH.ETH`)

const { data: foxPool } = await axios.get<Pool>(
'https://daemon.thorchain.shapeshift.com/lcd/thorchain/pool/ETH.FOX-0XC770EEFAD204B5180DF6A14EE197D99D808EE52D',
`${THORNODE_URL}/lcd/thorchain/pool/ETH.FOX-0XC770EEFAD204B5180DF6A14EE197D99D808EE52D`,
)

const ethPriceUsd = toPrecision(ethPool.asset_tor_price, THORCHAIN_PRECISION).toFixed(THORCHAIN_PRECISION)
Expand Down
13 changes: 10 additions & 3 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ const processEpoch = async () => {

const revenue = await client.getRevenue(metadata.epochStartTimestamp, metadata.epochEndTimestamp)

info(
`Total ${month} revenue earned by ${revenue.addresses}: ${BigNumber(revenue.amount).div(100000000).toFixed(8)} RUNE`,
)
info(`Affilate addresses:`)
revenue.addresses.forEach(address => info(`\t- ${address}`))

info(`Total revenue earned by denom:`)
Object.entries(revenue.revenue).forEach(([denom, amount]) => {
info(`\t- ${BigNumber(amount).div(100000000).toFixed(8)} ${denom}`)
})

info(`Total revenue in RUNE: ${BigNumber(revenue.amount).div(100000000).toFixed(8)}`)

const totalDistributionRate = Object.entries(metadata.distributionRateByStakingContract).reduce(
(prev, [stakingContract, distributionRate]) => {
Expand Down Expand Up @@ -119,6 +125,7 @@ const processEpoch = async () => {
endBlock: Number(endBlock),
treasuryAddress: metadata.treasuryAddress,
totalRevenue: revenue.amount,
revenue: revenue.revenue,
burnRate: metadata.burnRate,
runePriceUsd,
distributionStatus: 'pending',
Expand Down
2 changes: 1 addition & 1 deletion cli/src/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prompts from '@inquirer/prompts'
import { PinataSDK } from 'pinata'
import axios, { isAxiosError } from 'axios'
import { isAxiosError } from 'axios'
import BigNumber from 'bignumber.js'
import { error, info } from './logging'
import { Epoch, EpochDetails, RFOXMetadata, RewardDistribution } from './types'
Expand Down
2 changes: 2 additions & 0 deletions cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export type Epoch = {
treasuryAddress: string
/** The total revenue (RUNE) earned by the treasury for this epoch */
totalRevenue: string
/** The revenue earned (by denom) by the treasury for this epoch */
revenue: Record<string, string>
/** The percentage of revenue (RUNE) accumulated by the treasury to be used to buy FOX from the open market and subsequently burned for this epoch */
burnRate: number
/** The spot price of rune in USD */
Expand Down
7 changes: 6 additions & 1 deletion cli/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import { error, info, success } from './logging'
import { Epoch } from './types'
import { RFOX_DIR } from '.'

const THORNODE_URL = process.env['THORNODE_URL']
if (!THORNODE_URL) {
error('THORNODE_URL not set. Please make sure you copied the sample.env and filled out your .env file.')
process.exit(1)
}

const BIP32_PATH = `m/44'/931'/0'/0/0`
const SHAPESHIFT_MULTISIG_ADDRESS = 'thor122h9hlrugzdny9ct95z6g7afvpzu34s73uklju'
const THORNODE_URL = 'https://daemon.thorchain.shapeshift.com'

const addressNList = bip32ToAddressNList(BIP32_PATH)

Expand Down
Loading