-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat: margin zero #12971
feat: margin zero #12971
Conversation
The adapter at projects/margin-zero exports TVL:
|
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.
.
projects/margin-zero/index.js
Outdated
const chainConfig = { | ||
146: { | ||
chainName: "sonic", | ||
subgraph: "https://api.goldsky.com/api/public/project_cm58q8wq01kbk01ts09lc52kp/subgraphs/mz-subgraph/main/gn" |
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.
is there any way to get tokenIds of the uni v3 positions? we have helper code to unwrap and pull tvl from it, would simplify this adapter code
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 contracts do not deposit through Nft position manager contract but rather directly into the pool, so we don't have the v3 tokenIds
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.
not uni v3, but your position manager does?
https://sonicscan.org/tx/0x1ad74b93afde626b5c49174949efdc5e1cec8d5740e2fc27db9a0b19128c318e#eventlog
then, we can fetch value onchain using WagmiV3Handler ?
https://sonicscan.org/address/0xe7e225194e81729b27e8fa5c1ebd801d502c016b#readContract
projects/margin-zero/index.js
Outdated
} | ||
|
||
function LiquidityRangesQuery(first, skip) { | ||
return `{ liquidityRanges(first: ${first}, skip: ${skip}) {pool liquidity tickLower tickUpper }}` |
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.
I think you should add a liquidity_gt: 100
to filter out expired positions
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.
I'm sorry, what do you mean by expired positions?
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.
@0xradishmz when liquidity is withdrawn, I saw a few positions with 0 liquidity
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.
@0xradishmz when liquidity is withdrawn, I saw a few positions with 0 liquidity
sounds good, thanks for clarification
projects/margin-zero/index.js
Outdated
|
||
|
||
async function tvl(sdk) { | ||
if (sdk.api.chainId && chainConfig[sdk.api.chainId]) { |
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.
dont think this check is needed
projects/margin-zero/index.js
Outdated
} | ||
|
||
|
||
async function tvl(sdk) { |
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.
change sdk -> api
projects/margin-zero/index.js
Outdated
|
||
let counter = 0; | ||
while (true) { | ||
const { liquidityRanges } = await cachedGraphQuery('marign-zero/tvl', subgraphUrl, LiquidityRangesQuery(1000, 1000 * counter)) |
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.
you should use fetchById
here (also, update the query), like https://github.com/0xradishmz/DefiLlama-Adapters/blob/pr/0xradishmz/12971/projects/panoptic/index.js#L63
noticed that panoptic & this adapter have the same bug, if we use cached graph data, we will end up with incorrect liquidity data & wrong tvl, but using tokenIds fixing it (so we fetch liquidity on chain)
The adapter at projects/margin-zero exports TVL:
|
The adapter at projects/margin-zero exports TVL:
|
The adapter at projects/margin-zero exports TVL:
|
The adapter at projects/margin-zero exports TVL:
|
The adapter at projects/margin-zero exports TVL:
|
The adapter at projects/margin-zero exports TVL:
|
@0xradishmz thanks for the PR |
The adapter at projects/margin-zero exports TVL:
|
NOTE
Please enable "Allow edits by maintainers" while putting up the PR.
package-lock.json
file as part of your changes, we use lockfileVersion 2, and most use v1 and using that messes up our CIName (to be shown on DefiLlama):
Margin Zero
Twitter Link:
https://x.com/marginzero_xyz
List of audit links if any:
https://github.com/marginzero-xyz/contracts/blob/main/audits/yAudits/MarginZero_yAudits_December2024_OptionsOTM.pdf
Website Link:
https://www.marginzero.xyz/
Logo (High resolution, will be shown with rounded borders):
Current TVL:
Treasury Addresses (if the protocol has treasury)
Chain:
Sonic (cross chain soon)
Coingecko ID (so your TVL can appear on Coingecko, leave empty if not listed): (https://api.coingecko.com/api/v3/coins/list)
Coinmarketcap ID (so your TVL can appear on Coinmarketcap, leave empty if not listed): (https://api.coinmarketcap.com/data-api/v3/map/all?listing_status=active,inactive,untracked&start=1&limit=10000)
Short Description (to be shown on DefiLlama):
MarginZero is an omni-chain, oracle-less and permission-less options & protected perpetual protocol
Token address and ticker if any:
Category (full list at https://defillama.com/categories) *Please choose only one:
Options
Oracle Provider(s): Specify the oracle(s) used (e.g., Chainlink, Band, API3, TWAP, etc.):
Implementation Details: Briefly describe how the oracle is integrated into your project:
Documentation/Proof: Provide links to documentation or any other resources that verify the oracle's usage:
forkedFrom (Does your project originate from another project):
methodology (what is being counted as tvl, how is tvl being calculated):
TVL is the total amount of tokens deposited in DEX's through Margin Zero's handler contracts.
Github org/user (Optional, if your code is open source, we can track activity):
https://github.com/marginzero-xyz