forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env node | ||
const path = require("path"); | ||
require('dotenv').config(); | ||
const {default: computeTVL} = require("@defillama/sdk/build/computeTVL"); | ||
const { getCurrentBlocks } = require("@defillama/sdk/build//computeTVL/blocks"); | ||
const { humanizeNumber } = require("@defillama/sdk/build//computeTVL/humanizeNumber"); | ||
|
||
|
||
if (process.argv.length < 3) { | ||
console.error(`Missing argument, you need to provide the filename of the adapter to test. | ||
Eg: npx @defillama/sdk projects/myadapter.js`); | ||
process.exit(1); | ||
} | ||
const passedFile = path.resolve(process.cwd(), process.argv[2]); | ||
|
||
(async () => { | ||
const moduleToTest = (await import(passedFile)).default; | ||
let usdTvl; | ||
if (moduleToTest.fetch) { | ||
usdTvl = await moduleToTest.fetch(); | ||
} else if (moduleToTest.tvl) { | ||
const { timestamp, ethereumBlock, chainBlocks } = await getCurrentBlocks(); | ||
|
||
let tvl = await moduleToTest.tvl(timestamp, ethereumBlock, chainBlocks); | ||
if (typeof tvl !== "object") { | ||
throw new Error("TVL returned is not a balances object"); | ||
} | ||
|
||
usdTvl = (await computeTVL(tvl, "now", true)).usdTvl; | ||
} else { | ||
throw new Error("File must export either a property called tvl or one called fetch") | ||
} | ||
console.log("Total:", humanizeNumber(usdTvl)); | ||
process.exit(0); | ||
})(); |