Skip to content

Commit

Permalink
🌭 fail only when getSGDRate is called but CMC_API_KEY is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiashu committed Aug 8, 2024
1 parent c8afc2f commit a73549c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions scripts/util/cmc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import axios from 'axios'
const CMC_API_KEY = process.env.CMC_API_KEY || ''

if (!CMC_API_KEY) {
// fail early
throw new Error('CMC_API_KEY is not set')
}

interface QuoteData {
data: {
[key: string]: {
Expand All @@ -19,6 +14,11 @@ interface QuoteData {
}

export const getSGDRate = async (): Promise<number> => {
if (!CMC_API_KEY) {
// fail early
throw new Error('CMC_API_KEY is not set')
}

try {
const response = await axios.get<QuoteData>(
'https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?id=2808',
Expand Down
3 changes: 2 additions & 1 deletion scripts/xsgd-rewards-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const snapshotXSGDRewards = async (
hre: HardhatRuntimeEnvironment,
epochDate: string // YYYY-MM format, e.g. 2023-03 for March 2023
) => {
// Get the current XSGD rate
const rate = await getSGDRate()
const [deployer] = await hre.ethers.getSigners()
const FXPoolContract = new hre.ethers.Contract(
POOL_ADDRESS,
Expand Down Expand Up @@ -119,7 +121,6 @@ export const snapshotXSGDRewards = async (
reward: string
}[] = []

const rate = await getSGDRate()
const xsgdRate = parseEther(`${rate}`)
console.log(`RATE: 1 XSGD = ${formatEther(xsgdRate)} USD`)

Expand Down

0 comments on commit a73549c

Please sign in to comment.