From 3090fa7a914c1c6852577dcdeaa72ee95d3c60a0 Mon Sep 17 00:00:00 2001 From: CronosLabsDev Date: Wed, 1 May 2024 14:01:57 -0400 Subject: [PATCH 1/4] add orby network liquidation adapter --- liquidations/orby-network/index.ts | 120 +++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 liquidations/orby-network/index.ts diff --git a/liquidations/orby-network/index.ts b/liquidations/orby-network/index.ts new file mode 100644 index 000000000000..fa6babc5ad9f --- /dev/null +++ b/liquidations/orby-network/index.ts @@ -0,0 +1,120 @@ +import { gql, request } from "graphql-request"; +import BigNumber from "bignumber.js"; +import { getPagedGql } from "../utils/gql"; +import { Liq } from "../utils/types"; + +const subgraphUrl = "https://graph.cronoslabs.com/subgraphs/name/orby/orby"; + +const globalQuery = gql` + { + global(id: "only") { + currentSystemState { + price + totalCollateral + totalDebt + totalCollateralRatio + } + } + _meta { + block { + number + } + } + } +`; + +type SystemState = { + price: string; + totalCollateral: string; + totalDebt: string; + totalCollateralRatio: string; +}; + +const trovesQuery = gql` + query troves($lastId: String, $pageSize: Int) { + troves(first: $pageSize, where: { status: open, id_gt: $lastId }) { + id + collateral + rawCollateral + debt + owner { + id + } + } + _meta { + block { + number + } + } + } +`; + +type Trove = { + id: string; + collateral: string; + rawCollateral: string; + debt: string; + owner: { + id: string; + }; +}; + +const isRecoveryMode = (totalCollateralRatio: string) => { + return Number(totalCollateralRatio) < 1.5; +}; + +const getSystemState = async () => { + const systemState = (await request(subgraphUrl, globalQuery)).global + .currentSystemState as SystemState; + return systemState; +}; + +// 1.35 * debt / collateral = price +const calculateLiquidationPrice = ( + debt: string, + collateral: string, + isRecoveryMode: boolean +) => { + const collateralRatioThreshold = isRecoveryMode ? 1.5 : 1.35; + const price = new BigNumber(collateralRatioThreshold) + .times(debt) + .div(collateral) + .toString(); + return price; +}; + +const EXPLORER_BASE_URL = "https://explorer.cronos.org/address/"; + +const positions = async () => { + const { totalCollateralRatio } = await getSystemState(); + const _isRecoveryMode = isRecoveryMode(totalCollateralRatio); + + const troves = (await getPagedGql( + subgraphUrl, + trovesQuery, + "troves" + )) as Trove[]; + const _troves = troves.map( + ({ collateral: _collateral, debt, owner, rawCollateral }) => { + return { + owner: owner.id, + liqPrice: Number( + calculateLiquidationPrice(debt, _collateral, _isRecoveryMode) + ), + collateral: "cronos:" + "0x7a7c9db510aB29A2FC362a4c34260BEcB5cE3446", // cdcETH + collateralAmount: rawCollateral, + extra: { + url: EXPLORER_BASE_URL + owner.id, + }, + } as Liq; + } + ); + + return _troves; +}; + +module.exports = { + cronos: { + liquidations: positions, + }, +}; From 7d86f75ef24ee3ce134ef73e2b3e3ab166af5eba Mon Sep 17 00:00:00 2001 From: CronosLabsDev <106642922+CronosLabsDev@users.noreply.github.com> Date: Wed, 28 Aug 2024 11:20:03 +1000 Subject: [PATCH 2/4] feat: fulcrom-cronos-zkevm-tvl --- projects/fulcrom/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/fulcrom/index.js b/projects/fulcrom/index.js index b31fd2f4870e..9f53c9cc65ea 100644 --- a/projects/fulcrom/index.js +++ b/projects/fulcrom/index.js @@ -2,6 +2,7 @@ const { sumTokens2 } = require('../helper/unwrapLPs') const CRO_VAULT_ADDR = '0x8C7Ef34aa54210c76D6d5E475f43e0c11f876098'; const ZKSYNC_VAULT_ADDR = '0x7d5b0215EF203D0660BC37d5D09d964fd6b55a1E'; +const CRO_ZKEVM_VAULT_ADDR = '0xdDDf221d5293619572616574Ff46a2760f162075'; function fulExports({ vault, }) { return async (api) => { @@ -27,4 +28,7 @@ module.exports = { era: { tvl: fulExports({ vault: ZKSYNC_VAULT_ADDR, }), }, + cronos_zkevm: { + tvl: fulExports({ vault: CRO_ZKEVM_VAULT_ADDR, }), + }, } From e311a17f96d6b3799493525b2e756ca63aa1e171 Mon Sep 17 00:00:00 2001 From: CronosLabsDev <106642922+CronosLabsDev@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:29:03 +1000 Subject: [PATCH 3/4] chore: revert unapproved change --- liquidations/orby-network/index.ts | 120 ----------------------------- 1 file changed, 120 deletions(-) delete mode 100644 liquidations/orby-network/index.ts diff --git a/liquidations/orby-network/index.ts b/liquidations/orby-network/index.ts deleted file mode 100644 index fa6babc5ad9f..000000000000 --- a/liquidations/orby-network/index.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { gql, request } from "graphql-request"; -import BigNumber from "bignumber.js"; -import { getPagedGql } from "../utils/gql"; -import { Liq } from "../utils/types"; - -const subgraphUrl = "https://graph.cronoslabs.com/subgraphs/name/orby/orby"; - -const globalQuery = gql` - { - global(id: "only") { - currentSystemState { - price - totalCollateral - totalDebt - totalCollateralRatio - } - } - _meta { - block { - number - } - } - } -`; - -type SystemState = { - price: string; - totalCollateral: string; - totalDebt: string; - totalCollateralRatio: string; -}; - -const trovesQuery = gql` - query troves($lastId: String, $pageSize: Int) { - troves(first: $pageSize, where: { status: open, id_gt: $lastId }) { - id - collateral - rawCollateral - debt - owner { - id - } - } - _meta { - block { - number - } - } - } -`; - -type Trove = { - id: string; - collateral: string; - rawCollateral: string; - debt: string; - owner: { - id: string; - }; -}; - -const isRecoveryMode = (totalCollateralRatio: string) => { - return Number(totalCollateralRatio) < 1.5; -}; - -const getSystemState = async () => { - const systemState = (await request(subgraphUrl, globalQuery)).global - .currentSystemState as SystemState; - return systemState; -}; - -// 1.35 * debt / collateral = price -const calculateLiquidationPrice = ( - debt: string, - collateral: string, - isRecoveryMode: boolean -) => { - const collateralRatioThreshold = isRecoveryMode ? 1.5 : 1.35; - const price = new BigNumber(collateralRatioThreshold) - .times(debt) - .div(collateral) - .toString(); - return price; -}; - -const EXPLORER_BASE_URL = "https://explorer.cronos.org/address/"; - -const positions = async () => { - const { totalCollateralRatio } = await getSystemState(); - const _isRecoveryMode = isRecoveryMode(totalCollateralRatio); - - const troves = (await getPagedGql( - subgraphUrl, - trovesQuery, - "troves" - )) as Trove[]; - const _troves = troves.map( - ({ collateral: _collateral, debt, owner, rawCollateral }) => { - return { - owner: owner.id, - liqPrice: Number( - calculateLiquidationPrice(debt, _collateral, _isRecoveryMode) - ), - collateral: "cronos:" + "0x7a7c9db510aB29A2FC362a4c34260BEcB5cE3446", // cdcETH - collateralAmount: rawCollateral, - extra: { - url: EXPLORER_BASE_URL + owner.id, - }, - } as Liq; - } - ); - - return _troves; -}; - -module.exports = { - cronos: { - liquidations: positions, - }, -}; From 14ed4733279576c8576d7f03c44659ed5402dc62 Mon Sep 17 00:00:00 2001 From: CronosLabsDev Date: Fri, 27 Dec 2024 10:30:29 +0800 Subject: [PATCH 4/4] feat: with sumTokens2 function --- projects/moonlander/index.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 projects/moonlander/index.js diff --git a/projects/moonlander/index.js b/projects/moonlander/index.js new file mode 100644 index 000000000000..cf9a03163be0 --- /dev/null +++ b/projects/moonlander/index.js @@ -0,0 +1,32 @@ +const { sumTokens2 } = require("../helper/unwrapLPs"); + +const CRO_ZKEVM_MOONLANDER_ADDR = '0x02ae2e56bfDF1ee4667405eE7e959CD3fE717A05'; + +function tvl({moonlander,}) { + return async (api) => { + const poolTokens = await api.call({ + abi: abis.totalValue, + target: moonlander, + }) + + const addresses = []; + const valuesUsd = []; + + poolTokens.forEach((poolToken) => { + addresses.push(poolToken.tokenAddress); + valuesUsd.push(poolToken.valueUsd); + }); + + return sumTokens2({ api, owner: moonlander, tokens: addresses, balances: valuesUsd}) + } +} + +const abis = { + totalValue: 'function totalValue() view returns (tuple(address tokenAddress, int256 value, uint8 decimals, int256 valueUsd, uint16 targetWeight, uint16 feeBasisPoints, uint16 taxBasisPoints, bool dynamicFee)[])' +} + +module.exports = { + cronos_zkevm: { + tvl: tvl({ moonlander: CRO_ZKEVM_MOONLANDER_ADDR, }), + }, + } \ No newline at end of file