Skip to content

Commit

Permalink
cloud_functions: convert env var NETWORK to sdk Network
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <[email protected]>
  • Loading branch information
bingyuyap committed Jun 6, 2024
1 parent fd37c95 commit c1499ae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cloud_functions/src/computeNTTRateLimits.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
assertEnvironmentVariable,
NTT_MANAGER_CONTRACT,
NTT_TOKENS,
NTT_TRANSCEIVER_CONTRACT,
NTT_SUPPORTED_CHAINS,
getEvmTokenDecimals,
getSolanaTokenDecimals,
NTTRateLimit,
getNetwork,
} from '@wormhole-foundation/wormhole-monitor-common';
import { EvmPlatform, EvmChains } from '@wormhole-foundation/sdk-evm';
import { SolanaPlatform } from '@wormhole-foundation/sdk-solana';
Expand All @@ -17,7 +17,8 @@ import { Storage } from '@google-cloud/storage';

const storage = new Storage();
let bucketName: string = 'wormhole-ntt-cache';
if (assertEnvironmentVariable('NETWORK') === 'Testnet') {
const network = getNetwork();
if (network === 'Testnet') {
bucketName = 'wormhole-ntt-cache-testnet';
}

Expand Down Expand Up @@ -115,7 +116,6 @@ export async function computeNTTRateLimits(req: any, res: any) {
}

try {
const network = assertEnvironmentVariable('NETWORK') as Network;
const managerContracts = NTT_MANAGER_CONTRACT[network];

const rateLimits = await Promise.all(
Expand Down
14 changes: 6 additions & 8 deletions cloud_functions/src/computeTotalSupplyAndLocked.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {
NTT_MANAGER_CONTRACT,
NTT_TOKENS,
assertEnvironmentVariable,
NTTTotalSupplyAndLockedData,
derivePda,
getCustody,
getCustodyAmount,
getEvmTokenDecimals,
getEvmTotalSupply,
getNetwork,
normalizeToDecimals,
} from '@wormhole-foundation/wormhole-monitor-common';
import { PublicKey } from '@solana/web3.js';
import {
getCustody,
getCustodyAmount,
NTTTotalSupplyAndLockedData,
} from '@wormhole-foundation/wormhole-monitor-common';
import { Network, rpc, Chain, chainToChainId } from '@wormhole-foundation/sdk-base';
import { Storage } from '@google-cloud/storage';

const storage = new Storage();
let bucketName: string = 'wormhole-ntt-cache';
if (assertEnvironmentVariable('NETWORK') === 'Testnet') {
const network = getNetwork();
if (network === 'Testnet') {
bucketName = 'wormhole-ntt-cache-testnet';
}

Expand Down Expand Up @@ -96,7 +95,6 @@ export async function computeTotalSupplyAndLocked(req: any, res: any) {
}

try {
const network = assertEnvironmentVariable('NETWORK') as Network;
const totalSupplyAndLocked = await fetchTotalSupplyAndLocked(network);
await cloudStorageCache.save(JSON.stringify(totalSupplyAndLocked));
res.status(200).send('Total supply and locked saved');
Expand Down
4 changes: 2 additions & 2 deletions cloud_functions/src/getNTTRateLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Storage } from '@google-cloud/storage';
import { chainIdToChain } from '@wormhole-foundation/sdk-base';
import {
NTTRateLimit,
assertEnvironmentVariable,
getNetwork,
normalizeToDecimals,
} from '@wormhole-foundation/wormhole-monitor-common';
import { Gauge, register } from 'prom-client';
Expand Down Expand Up @@ -33,7 +33,7 @@ async function setCapacityGauge(
const storage = new Storage();

let bucketName: string = 'wormhole-ntt-cache';
const network = assertEnvironmentVariable('NETWORK');
const network = getNetwork();
if (network === 'Testnet') {
bucketName = 'wormhole-ntt-cache-testnet';
}
Expand Down
7 changes: 2 additions & 5 deletions cloud_functions/src/getTotalSupplyAndLocked.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Storage } from '@google-cloud/storage';
import {
NTTRateLimit,
assertEnvironmentVariable,
} from '@wormhole-foundation/wormhole-monitor-common';
import { NTTRateLimit, getNetwork } from '@wormhole-foundation/wormhole-monitor-common';

const storage = new Storage();
const network = assertEnvironmentVariable('NETWORK');
const network = getNetwork();
let bucketName: string = 'wormhole-ntt-cache';
if (network === 'Testnet') {
bucketName = 'wormhole-ntt-cache-testnet';
Expand Down

0 comments on commit c1499ae

Please sign in to comment.