-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add Shift Protocol TVL adapter #16717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
caa5b43
166d654
133add4
f6b12b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| [ | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "_accessControlContract", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "nonpayable", | ||
| "type": "constructor" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "AlreadyInitialized", | ||
| "type": "error" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "CountMustBePositive", | ||
| "type": "error" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "IndexOutOfBounds", | ||
| "type": "error" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "NotInitialized", | ||
| "type": "error" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "string", | ||
| "name": "_role", | ||
| "type": "string" | ||
| } | ||
| ], | ||
| "name": "Unauthorized", | ||
| "type": "error" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "ZeroAddress", | ||
| "type": "error" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "newValue", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "timestamp", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "TvlUpdated", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "accessControlContract", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "contract IAccessControl", | ||
| "name": "", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "decimals", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "uint8", | ||
| "name": "", | ||
| "type": "uint8" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "getLastTvl", | ||
| "outputs": [ | ||
| { | ||
| "components": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "value", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "timestamp", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "supplySnapshot", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "internalType": "struct ShiftTvlFeed.TvlData", | ||
| "name": "", | ||
| "type": "tuple" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "_count", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "getLastTvlEntries", | ||
| "outputs": [ | ||
| { | ||
| "components": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "value", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "timestamp", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "supplySnapshot", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "internalType": "struct ShiftTvlFeed.TvlData[]", | ||
| "name": "", | ||
| "type": "tuple[]" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "_index", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "getTvlEntry", | ||
| "outputs": [ | ||
| { | ||
| "components": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "value", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "timestamp", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "supplySnapshot", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "internalType": "struct ShiftTvlFeed.TvlData", | ||
| "name": "", | ||
| "type": "tuple" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "init", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "bool", | ||
| "name": "", | ||
| "type": "bool" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "_shiftVaultContract", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "name": "initialize", | ||
| "outputs": [], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "shiftVault", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "contract IShiftVault", | ||
| "name": "", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "_value", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "updateTvl", | ||
| "outputs": [], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "_user", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "_value", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "updateTvlForDeposit", | ||
| "outputs": [], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function" | ||
| } | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module.exports = { | ||
| base: [ | ||
| "0x6196810Be8e6a1D0fB0Ec10c789966c88340F19b", | ||
| ], | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const { getProvider } = require("@defillama/sdk/build/general"); | ||
| const { Contract, formatUnits } = require("ethers"); | ||
| const abi = require("./ShiftTvlFeed.json"); | ||
| const contractsByChain = require("./config"); | ||
|
|
||
| function getChainTvlFunction(chain) { | ||
| return async function tvl(_, _block, _chainBlocks) { | ||
| const provider = getProvider(chain); | ||
| let totalTvl = 0; | ||
|
|
||
| for (const address of contractsByChain[chain]) { | ||
| const contract = new Contract(address, abi, provider); | ||
|
||
| const [tvlData, decimals] = await Promise.all([ | ||
| contract.getLastTvl(), | ||
| contract.decimals() | ||
| ]); | ||
|
|
||
| const tvlValue = parseFloat(formatUnits(tvlData.value, decimals)); | ||
| totalTvl += tvlValue; | ||
|
||
| } | ||
|
|
||
| return { | ||
| usd: totalTvl | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| const adapter = { | ||
| methodology: "TVL is calculated as the aggregated amount of USDC deposited across all of Shift's vault, inclusive of losses or gains." | ||
| }; | ||
|
|
||
| for (const chain of Object.keys(contractsByChain)) { | ||
| adapter[chain] = { | ||
| tvl: getChainTvlFunction(chain) | ||
| }; | ||
| } | ||
|
|
||
| module.exports = adapter; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use string form ABI instead - try searching the repo for
"functionUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our TVL (currently) is defined as circulating liquid receipt tokens (ltPARA) * share price.
We emit ltPARA which is an ERC20 token on Base, against USDC deposits. The deposits then get transferred to Paradex and deposited in the Gigavault (which is their LP/MM vault).
Therefore, for the circulating of supply this is fairly easy, as it corresponds to https://basescan.org/token/0xaf69bf9ea9e0166498c0502af5b5945980ed1e0e
The price is calculated as a fundamental value via: underlying backing / number of circulating shares.
Therefore, as you see, our TVL is essentially calculated as the underlying backing.
The underlying backing is calculated via several steps:
The dust/inactive deposits on base at our wallet: https://basescan.org/address/0x2f8b5f84032c7ffea5a5dc990ce5eb7167d596ed
And the active deposits on Paradex.
Through Paradex APIs we get: