Skip to content
Open
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
5 changes: 5 additions & 0 deletions projects/shift-protocol/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
base: [
"0xaf69Bf9ea9E0166498c0502aF5B5945980Ed1E0E",
],
};
79 changes: 79 additions & 0 deletions projects/shift-protocol/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const sdk = require('@defillama/sdk');
const { formatUnits } = require('ethers');
const contractsByChain = require('./config');

function getChainTvlFunction(chain) {
return async (_timestamp, _ethBlock, chainBlocks) => {
const block = chainBlocks[chain];
let totalTvl = 0;

const addresses = contractsByChain[chain] || [];
for (const address of addresses) {
// totalSupply using standard ERC20 short ABI
let totalSupply;
try {
totalSupply = await sdk.api.abi.call({
target: address,
abi: 'erc20:totalSupply',
block,
chain,
});
} catch (e) {
// no totalSupply -> skip this contract
console.warn(`totalSupply() missing for ${address} on ${chain}: ${e.message || e}`);
continue;
}

// decimals using standard ERC20 short ABI (fallback to 18 if fails)
let decimals = 18;
try {
const decRes = await sdk.api.abi.call({
target: address,
abi: 'erc20:decimals',
block,
chain,
});
decimals = Number(decRes.output);
} catch (e) {
console.warn(`decimals() missing for ${address} on ${chain}, defaulting to 18: ${e.message || e}`);
decimals = 18;
}

// getSharePrice() - custom function, format with 6 decimals
let sharePrice = 0;
try {
const spRes = await sdk.api.abi.call({
target: address,
abi: 'function getSharePrice() view returns (uint256)',
block,
chain,
});
// format with 6 decimals as requested
sharePrice = Number(formatUnits(spRes.output, 6));
} catch (e) {
// If contract doesn't expose getSharePrice, log and treat as 0
console.warn(`getSharePrice() missing for ${address} on ${chain}, using 0: ${e.message || e}`);
sharePrice = 0;
}

const supplyHuman = Number(formatUnits(totalSupply.output, decimals));
const tvlForAddress = supplyHuman * sharePrice;
totalTvl += tvlForAddress;
}

return {
usd: totalTvl,
};
};
}

const adapter = {
methodology:
'TVL is calculated by summing total supply of shares distributed to depositors and multiplied by their share price (comprehensive of profit and loss). Aggregated across configured contracts.',
};

for (const chain of Object.keys(contractsByChain)) {
adapter[chain] = { tvl: getChainTvlFunction(chain) };
}

module.exports = adapter;
Loading