diff --git a/.changeset/few-horses-push.md b/.changeset/few-horses-push.md new file mode 100644 index 000000000..59a37a836 --- /dev/null +++ b/.changeset/few-horses-push.md @@ -0,0 +1,5 @@ +--- +"@nocturne-xyz/frontend-sdk": patch +--- + +Adds Protocol TVL diff --git a/actors/deposit-screener/src/screening/checks/RuleSet.ts b/actors/deposit-screener/src/screening/checks/RuleSet.ts index f854ec55e..f69993da0 100644 --- a/actors/deposit-screener/src/screening/checks/RuleSet.ts +++ b/actors/deposit-screener/src/screening/checks/RuleSet.ts @@ -1,13 +1,13 @@ import { CachedFetchOptions } from "@nocturne-xyz/offchain-utils"; +import IORedis from "ioredis"; +import { Logger } from "winston"; import { ScreeningDepositRequest } from ".."; import { API_CALL_MAP, ApiCallNames, - ApiCallToReturnType, ApiCallReturnData, + ApiCallToReturnType, } from "./apiCalls"; -import IORedis from "ioredis"; -import { Logger } from "winston"; export interface Rejection { type: "Rejection"; @@ -224,9 +224,11 @@ export class RuleSet { }); if (result.type === "Rejection") { this.logger.info( - `Screener execution for deposit:`, - deposit, - rulesLogList + `Screener execution on deposit for addr ${deposit.spender}`, + { + deposit: { ...deposit }, + results: { ...toLoggable(rulesLogList) }, + } ); return result; } else if (result.type === "Delay") { @@ -237,15 +239,25 @@ export class RuleSet { } currRule = currRule.next; } - - const ruleResults = rulesLogList.reduce((acc, { ruleName, result }) => { - acc[ruleName] = result; - return acc; - }, {} as Record>>); - this.logger.info(`Screener execution for deposit:`, { - ...deposit, - ...ruleResults, - }); + this.logger.info( + `Screener execution for deposit for addr ${deposit.spender}`, + { + deposit: { ...deposit }, + results: { ...toLoggable(rulesLogList) }, + } + ); return { type: "Delay", timeSeconds: delaySeconds }; } } + +const toLoggable = ( + rulesLogList: { + ruleName: string; + result: Awaited>; + }[] +): Record => { + return rulesLogList.reduce((acc, { ruleName, result }) => { + acc[ruleName] = result; + return acc; + }, {} as Record>>); +}; diff --git a/packages/frontend-sdk/src/sdk.ts b/packages/frontend-sdk/src/sdk.ts index 74b93ac55..a4f8cedf4 100644 --- a/packages/frontend-sdk/src/sdk.ts +++ b/packages/frontend-sdk/src/sdk.ts @@ -78,6 +78,7 @@ import { E_ALREADY_LOCKED, Mutex, tryAcquire } from "async-mutex"; import retry from "async-retry"; import * as JSON from "bigint-json-serialization"; import { BigNumber, ContractTransaction, ethers } from "ethers"; +import ERC20_ABI from "./abis/ERC20.json"; import { DepositAdapter, SubgraphDepositAdapter } from "./depositFetching"; import { SnapStateSdk, getSigner } from "./metamask"; import { GetSnapOptions } from "./metamask/types"; @@ -288,6 +289,21 @@ export class NocturneSdk { return newOpRequestBuilder(this.provider, this.chainId); } + async getProtocolTvl(): Promise> { + const tellerAddress = this.sdkConfig.config.tellerAddress; + const tvlByAsset = new Map(); + for (const [assetName, { address }] of this.sdkConfig.config.erc20s) { + const erc20Contract = new ethers.Contract( + address, + ERC20_ABI, + this.provider, + ); + const balance = await erc20Contract.balanceOf(tellerAddress); + tvlByAsset.set(assetName, balance.toBigInt()); + } + return tvlByAsset; + } + /** * Call `depositManager.instantiateErc20MultiDeposit` given the provided * `erc20Address`, `valuse`, and `gasCompPerDeposit`.