-
Notifications
You must be signed in to change notification settings - Fork 3
feat: blog route and launch notification #438
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,43 @@ | ||
| import path from 'node:path'; | ||
|
|
||
| const deployUrl = process.env.BOAT_DEPLOY_URL ?? process.env.VERCEL_URL; | ||
|
|
||
| export const POSTS_DIRECTORY = path.join(process.cwd(), 'src/content/posts'); | ||
| export const POSTS_SITE_ORIGIN = deployUrl ? `https://${deployUrl}` : 'https://monarchlend.xyz'; | ||
|
|
||
| export type PostListItem = { | ||
| slug: string; | ||
| title: string; | ||
| publishedDate: string | null; | ||
| excerpt: string; | ||
| sortTime: number; | ||
| }; | ||
|
|
||
| export const formatSlugTitle = (slug: string): string => | ||
| slug | ||
| .replace(/^\d{4}-\d{2}-\d{2}-/, '') | ||
| .replace(/-/g, ' ') | ||
| .replace(/\b\w/g, (character) => character.toUpperCase()); | ||
|
|
||
| export const parseDateFromSlug = (slug: string): { label: string | null; time: number } => { | ||
| const match = slug.match(/^(\d{4})-(\d{2})-(\d{2})-/); | ||
| if (!match) { | ||
| return { label: null, time: 0 }; | ||
| } | ||
|
|
||
| const [_, year, month, day] = match; | ||
| const date = new Date(`${year}-${month}-${day}T00:00:00Z`); | ||
| if (Number.isNaN(date.getTime())) { | ||
| return { label: null, time: 0 }; | ||
| } | ||
|
|
||
| return { | ||
| label: date.toLocaleDateString('en-US', { | ||
| year: 'numeric', | ||
| month: 'long', | ||
| day: 'numeric', | ||
| timeZone: 'UTC', | ||
| }), | ||
| time: date.getTime(), | ||
| }; | ||
| }; |
This file contains hidden or 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,141 @@ | ||
| import { promises as fs, type Dirent } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import Link from 'next/link'; | ||
| import Header from '@/components/layout/header/Header'; | ||
| import { Breadcrumbs } from '@/components/shared/breadcrumbs'; | ||
| import { generateMetadata } from '@/utils/generateMetadata'; | ||
| import { POSTS_DIRECTORY, POSTS_SITE_ORIGIN, formatSlugTitle, parseDateFromSlug, type PostListItem } from './helpers'; | ||
|
|
||
| const getPostPreview = (markdown: string, fallbackTitle: string): { title: string; excerpt: string } => { | ||
| const lines = markdown.replaceAll('\r\n', '\n').split('\n'); | ||
| let title = fallbackTitle; | ||
| let excerpt = 'Product update and announcement.'; | ||
|
|
||
| for (const line of lines) { | ||
| const trimmed = line.trim(); | ||
| if (!trimmed) { | ||
| continue; | ||
| } | ||
|
|
||
| const headingMatch = trimmed.match(/^#\s+(.+)$/); | ||
| if (headingMatch && title === fallbackTitle) { | ||
| title = headingMatch[1]; | ||
| continue; | ||
| } | ||
|
|
||
| if ( | ||
| !trimmed.startsWith('#') && | ||
| !trimmed.startsWith('![') && | ||
| !trimmed.startsWith('```') && | ||
| !trimmed.startsWith('---') && | ||
| !trimmed.match(/^[-*]\s+/) && | ||
| !trimmed.match(/^\d+\.\s+/) | ||
| ) { | ||
| excerpt = trimmed.replace(/^>\s*/, ''); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return { title, excerpt }; | ||
| }; | ||
|
|
||
| const getAllPosts = async (): Promise<PostListItem[]> => { | ||
| let entries: Dirent[]; | ||
| try { | ||
| entries = await fs.readdir(POSTS_DIRECTORY, { withFileTypes: true }); | ||
| } catch (error: unknown) { | ||
| const fsError = error as NodeJS.ErrnoException; | ||
| if (fsError.code === 'ENOENT') { | ||
| return []; | ||
| } | ||
|
|
||
| throw error; | ||
| } | ||
|
|
||
| const markdownFiles = entries.filter((entry) => entry.isFile() && entry.name.endsWith('.md')); | ||
|
|
||
| const posts = await Promise.all( | ||
| markdownFiles.map(async (entry) => { | ||
| const slug = entry.name.replace(/\.md$/, ''); | ||
| const fallbackTitle = formatSlugTitle(slug); | ||
| const filePath = path.join(POSTS_DIRECTORY, entry.name); | ||
| const markdown = await fs.readFile(filePath, 'utf8'); | ||
| const { title, excerpt } = getPostPreview(markdown, fallbackTitle); | ||
| const { label, time } = parseDateFromSlug(slug); | ||
|
|
||
| return { | ||
| slug, | ||
| title, | ||
| excerpt, | ||
| publishedDate: label, | ||
| sortTime: time, | ||
| }; | ||
| }), | ||
| ); | ||
|
|
||
| return posts.sort((first, second) => { | ||
| if (first.sortTime !== second.sortTime) { | ||
| return second.sortTime - first.sortTime; | ||
| } | ||
|
|
||
| return second.slug.localeCompare(first.slug); | ||
| }); | ||
| }; | ||
|
|
||
| export const metadata = generateMetadata({ | ||
| title: 'Posts | Monarch', | ||
| description: 'Monarch announcements and product updates', | ||
| images: 'themes.png', | ||
| url: POSTS_SITE_ORIGIN, | ||
| pathname: '/posts', | ||
| }); | ||
|
|
||
| export default async function PostsPage() { | ||
| const posts = await getAllPosts(); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col justify-between font-zen"> | ||
| <Header /> | ||
| <div className="container h-full gap-8 pb-12"> | ||
| <div className="mt-10 min-h-10 flex items-center md:mt-12"> | ||
| <Breadcrumbs | ||
| items={[ | ||
| { label: 'Home', href: '/' }, | ||
| { label: 'Posts', isCurrent: true }, | ||
| ]} | ||
| /> | ||
| </div> | ||
|
|
||
| <section className="mt-4 w-full pb-4"> | ||
| <header className="pb-2"> | ||
| <p className="text-xs uppercase tracking-[0.12em] text-secondary">Announcements</p> | ||
| <h1 className="!pb-0 !pt-2 text-2xl font-normal sm:text-3xl">Posts</h1> | ||
| </header> | ||
|
|
||
| <div className="mt-3 flex flex-col gap-3"> | ||
| {posts.length === 0 ? ( | ||
| <p className="py-4 text-sm text-secondary">No posts published yet.</p> | ||
| ) : ( | ||
| posts.map((post) => ( | ||
| <Link | ||
| key={post.slug} | ||
| href={`/posts/${post.slug}`} | ||
| className="no-underline rounded-lg px-4 py-4 transition-colors hover:bg-hovered" | ||
| > | ||
| <div className="mb-2 flex flex-wrap items-center gap-2"> | ||
| <span className="inline-flex rounded border border-primary/20 px-2 py-1 text-[10px] uppercase tracking-[0.18em] text-primary/80"> | ||
| Product Update | ||
| </span> | ||
| {post.publishedDate && <span className="text-xs text-secondary">{post.publishedDate}</span>} | ||
| </div> | ||
| <h2 className="text-lg font-normal text-primary">{post.title}</h2> | ||
| <p className="mt-1 text-sm text-secondary">{post.excerpt}</p> | ||
| </Link> | ||
| )) | ||
| )} | ||
| </div> | ||
| </section> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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 @@ | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| # Leverage Is Live on Monarch | ||
|
|
||
| Leverage is now available in Monarch for all markets. | ||
|
|
||
| This launch includes two execution paths: | ||
| - Swap-based leverage for general collateral/loan pairs | ||
| - ERC4626 vault-token leverage when the collateral vault underlying matches the market loan asset | ||
|
|
||
|
|
||
| ## What this release enables | ||
|
|
||
| You can open leveraged positions in one bundled transaction flow, start from supported collateral or loan-asset input (depending on route), review projected collateral, borrow amount, and fee before confirming, and use the same interface for leverage and deleverage. | ||
|
|
||
| - Click the market action dropdown from any table, or go to a specific market page and click the Borrow dropdown. | ||
|
|
||
| ## How routing works | ||
|
|
||
| When you open leverage, Monarch picks the available route for that market and chain. | ||
|
|
||
| 1. ERC4626 deterministic route: If the collateral token is a vault share token whose underlying is the loan asset, Monarch uses the ERC4626 route. | ||
| 2. Swap-backed route: If that ERC4626 route is not available, Monarch uses a swap route powered by Velora (ParaSwap). | ||
|
|
||
| ## Swap-based leverage (Velora + Bundler3) | ||
|
|
||
| For swap routes, the action is executed as one bundled transaction. (You need to sign a one-time authorization for Morpho's [official Bundler3 contract](https://morpho.org/blog/introducing-bundler3/) if you haven't used it before.) | ||
|
|
||
| If you inspect the transaction flow, the core steps are: | ||
| - Move your input into the leverage flow | ||
| - Take a flash loan in the market loan asset | ||
| - Swap loan asset to collateral through Velora | ||
| - Supply collateral to Morpho | ||
| - Borrow loan asset to close the loop and settle the flash loan | ||
| - Apply the displayed fee | ||
|
|
||
| All of that happens in one transaction path so you do not have to manually chain steps. | ||
|
|
||
|
|
||
|  | ||
|
|
||
|
|
||
| ## ERC4626 vault-token leverage | ||
|
|
||
| For vault-share collateral where the vault underlying equals the market loan asset, Monarch switches to ERC4626 mode automatically. This route use the existing BundlerV2, so no extra authorization is needed for existing users. | ||
|
|
||
| That path avoids a DEX swap leg in the leverage loop and uses vault conversion steps instead. In practice, this is the clean route for vault-token-to-underlying pairs. For example, markets like USDC/yoUSD below. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix subject-verb agreement. "Route" is singular and needs "uses" instead of "use". 📝 Proposed fix-For vault-share collateral where the vault underlying equals the market loan asset, Monarch switches to ERC4626 mode automatically. This route use the existing BundlerV2, so no extra authorization is needed for existing users.
+For vault-share collateral where the vault underlying equals the market loan asset, Monarch switches to ERC4626 mode automatically. This route uses the existing BundlerV2, so no extra authorization is needed for existing users.🤖 Prompt for AI Agents |
||
|
|
||
|  | ||
|
|
||
| P.S. If you know any active incentive campaign on a vault token like yoUSD above, get in touch so we can support showing this APY on the leverage preview. | ||
|
|
||
| ## Fee model | ||
|
|
||
| Current leverage fee is 0.0075% (0.75 bps) of added collateral, capped at $5 per transaction. Fee is shown in preview before execution. | ||
|
|
||
| ## Risk note | ||
|
|
||
| Leverage increases liquidation risk as effective LTV rises. Use conservative multipliers and review projected post-action metrics before signing. | ||
|
|
||
| Happy looping. | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Don’t turn unexpected read failures into “no posts”.
This
catchalso swallowsreadFilefailures inside thePromise.all, so one bad markdown file makes the route render an empty state with a 200 instead of surfacing the error. Only the missing-directory case should fall back to[].💡 Narrow the fallback
🤖 Prompt for AI Agents