**What it is:** DeFiKit's embedded trading widget is a lightweight, plug-and-play iframe component that any third-party platform — Discord bots, Telegram groups, crypto websites, community dashboards — can drop into their UI in under 60 seconds. **Why it matters:** Instead of spending millions on paid acquisition, DeFiKit converts every partner's existing user base into a revenue-share distribution channel, turning community platforms into sales pipelines with zero upfront cost to the partner.
The Problem
Traditional DeFi distribution is broken. Projects burn through ad budgets on CPM campaigns that convert at 0.02%, sponsor Twitter influencers who churn followers monthly, and run airdrop campaigns that attract sybil farmers instead of real traders. Centralized exchanges charge $500K-$2M listing fees plus market-making deposits before a single user can trade.
For crypto-native platforms — Discord servers with 50K members, Telegram groups of 10K degens, or niche DeFi dashboards — there's no good way to monetize their audience beyond donations, NFT mints, or ads. They have the traffic. They have the trust. But they lack a trading product to offer their users.
An embedded widget solves both problems simultaneously: the partner monetizes without building a product, and DeFiKit acquires customers at near-zero CAC.
The Solution
DeFiKit's Embedded Trading Widget wraps the full trading engine — spot swaps, limit orders, portfolio tracking — into a single `<iframe>` snippet. Partners paste one line of HTML, and their users get the full DeFiKit experience without ever leaving the partner's platform.
Revenue-sharing is the key incentive. Partners receive a configurable percentage (default 30%) of all trading fees generated by users they refer. This is tracked on-chain via Solana for transparency, with settlement every epoch. No spreadsheets, no manual payouts, no trust issues.
Architecture Overview
System Components
| Component | Technology | Role |
|---|---|---|
| Embed SDK | Cloudflare Workers | Serves the widget JS/CSS edge-cached, routes partner origin validation |
| Partner Tracking | Cloudflare D1 (SQLite) | Maps partner IDs to revenue splits, aggregates referral data |
| Settlement Engine | Solana Program (Rust) | On-chain revenue distribution, epoch-based payouts |
| Widget UI | React + Tailwind | Injected into partner `<iframe>`, communicates via `postMessage` |
| Auth Bridge | SIWE (Sign-In with Ethereum) | User authentication inside the iframe, wallet connection passthrough |
Data Flow
```
User clicks "Trade" in partner platform (e.g., Discord bot)
│
▼
Partner app opens iframe with ?partner_id=abc
│
▼
Cloudflare Worker validates origin against whitelist
│
▼
Worker serves embed HTML from edge cache (25ms TTFB)
│
▼
Widget loads in iframe — user connects wallet (SIWE)
│
▼
Trade executed via Solana — fee recorded with partner_id attached
│
▼
D1 table fees_log updated: {trade_id, partner_id, fee_amount, timestamp}
│
▼
Epoch boundary — Solana program calculates partner share
│
▼
Revenue split sent to partner wallet (USDC or SOL)
```
Implementation
Step 1: Generate Embed Snippet
Partners receive a unique snippet from the DeFiKit Partner Dashboard. Each snippet contains a signed `partner_id` and optional `config` overrides (theme colors, allowed tokens, revenue split).
```html
<!-- DeFiKit Embed Snippet -->
<iframe
src="https://embed.defikit.com/widget?partner_id=abc123&theme=dark&split=30"
width="100%"
height="600px"
frameborder="0"
allow="clipboard-read; clipboard-write"
title="DeFiKit Trading"
></iframe>
```
Step 2: iframe + postMessage API
To support deep integration — like Discord bots that respond to `/trade SOL-USDC` with an embedded widget — the widget exposes a `postMessage` API. Partners can programmatically trigger trades, check balances, or listen for events.
```javascript
// Partner-side: communicate with DeFiKit widget
const iframe = document.querySelector('iframe[src*="embed.defikit.com"]');
// Send a trade command to the widget
function sendTrade(pair, amount, side) {
iframe.contentWindow.postMessage({
type: 'DEFIKIT_TRADE',
payload: {
pair: pair, // e.g., 'SOL-USDC'
amount: amount, // in base token
side: side // 'buy' or 'sell'
}
}, 'https://embed.defikit.com');
}
// Listen for trade confirmations
window.addEventListener('message', (event) => {
if (event.origin !== 'https://embed.defikit.com') return;
const { type, payload } = event.data;
if (type === 'DEFIKIT_TRADE_COMPLETE') {
console.log(`Trade executed: ${payload.signature}`);
// Update partner UI — show confirmation, update leaderboard, etc.
}
if (type === 'DEFIKIT_ERROR') {
console.error(`Trade failed: ${payload.reason}`);
}
});
```
Step 3: Cloudflare Worker Route
The embed server runs on Cloudflare Workers, providing global edge distribution (sub-50ms latency worldwide) and automatic origin validation. The worker checks the `Origin` header against a whitelist of registered partner domains before serving the widget.
```javascript
// Cloudflare Worker — embed.defikit.com router
export default {
async fetch(request, env) {
const url = new URL(request.url);
const origin = request.headers.get('Origin') || 'direct';
// Validate partner origin
if (origin !== 'direct') {
const allowed = await env.DB.prepare(
'SELECT 1 FROM partners WHERE allowed_origin = ?',
).bind(origin).first();
if (!allowed) {
return new Response('Unauthorized origin', { status: 403 });
}
}
// Serve the widget HTML from KV or static asset
if (url.pathname === '/widget' || url.pathname === '/') {
const partnerId = url.searchParams.get('partner_id');
if (!partnerId) {
return new Response('Missing partner_id', { status: 400 });
}
const html = await env.ASSETS.fetch(request);
return new Response(html.body, {
headers: {
'Content-Type': 'text/html',
'X-Frame-Options': 'ALLOW-FROM ' + origin,
}
});
}
return new Response('Not found', { status: 404 });
}
};
```
Step 4: Revenue Share Tracking
Each trade records the `partner_id` in Cloudflare D1. At epoch boundaries (every 24 hours or on-demand), the Solana settlement program processes the aggregated fees and distributes the partner's share.
```sql
-- D1: Calculate revenue share for a partner epoch
WITH partner_fees AS (
SELECT
partner_id,
SUM(fee_amount) AS total_fees,
COUNT(*) AS trade_count
FROM fees_log
WHERE
partner_id = ?
AND timestamp >= ? -- epoch start
AND timestamp < ? -- epoch end
AND settled = 0
GROUP BY partner_id
),
partner_config AS (
SELECT revenue_split_pct
FROM partners
WHERE partner_id = ?
)
SELECT
pf.partner_id,
pf.total_fees,
pf.trade_count,
pc.revenue_split_pct,
(pf.total_fees * pc.revenue_split_pct / 100) AS partner_payout
FROM partner_fees pf
JOIN partner_config pc ON 1=1;
```
```javascript
// Settlement Script — runs on epoch boundary
async function settlePartner(env, partnerId, epochStart, epochEnd) {
const stmt = env.DB.prepare(`
WITH fees AS (
SELECT SUM(fee_amount) as total, COUNT(*) as trades
FROM fees_log
WHERE partner_id = ? AND timestamp >= ? AND timestamp < ? AND settled = 0
)
SELECT total, trades FROM fees
`).bind(partnerId, epochStart, epochEnd);
const { total, trades } = await stmt.first();
if (!total || total === 0) return;
const partner = await env.DB.prepare(
'SELECT revenue_split_pct, wallet_address FROM partners WHERE partner_id = ?'
).bind(partnerId).first();
const payout = total * (partner.revenue_split_pct / 100);
// Submit Solana instruction for USDC transfer
const tx = await env.SOLANA.transfer({
from: env.FEE_WALLET,
to: partner.wallet_address,
amount: payout,
token: 'USDC',
});
// Mark fees as settled
await env.DB.prepare(
'UPDATE fees_log SET settled = 1, settlement_tx = ? WHERE partner_id = ? AND timestamp >= ? AND timestamp < ?'
).bind(tx.signature, partnerId, epochStart, epochEnd).run();
return { payout, trades, tx: tx.signature };
}
```
Results
Since launching the embedded widget program, DeFiKit has onboarded 47 partners across Discord, Telegram, and web platforms. Key metrics:
| Metric | Value |
|---|---|
| Average partner onboarding time | 8 minutes (from signup to live widget) |
| Partner revenue split (default) | 30% of trading fees |
| Widget adoption rate | 68% of invited partners go live within 48 hours |
| Average partner revenue (monthly) | $1,420 USDC per partner |
| Top partner revenue (monthly) | $8,700 USDC (a DeFi dashboard with 120K MAU) |
| User conversion rate (partner → trader) | 4.7% (versus 0.02% for paid ads) |
| Widget page load (P95) | 320ms from Cloudflare edge |
| Customer acquisition cost (via widget) | $1.12 per active trader |
| CAC for traditional paid acquisition | $47.80 per active trader |
| Partner churn (quarterly) | 4.3% |
| Total fees generated through widget channel | $187,000 (first 6 months) |
Partners report that the widget increases their user engagement by 22% on average — users who trade stay longer and return more frequently to the host platform. The revenue-share model has proven to be a powerful retention mechanism: partners actively promote DeFiKit to their communities because their own income scales with usage.
Key Takeaways
1. **Embedded distribution is DeFi's most capital-efficient growth channel.** DeFiKit's widget converts partner audiences at 235x the efficiency of paid ads ($1.12 CAC vs $47.80).
2. **Revenue-share aligns incentives perfectly.** When partners earn a percentage of every trade their users make, they become a motivated sales force promoting DeFiKit organically.
3. **Edge architecture (Cloudflare Workers + D1) makes the widget globally fast.** Partners paste an iframe — the worker validates origins, serves the widget, and logs fees in <50ms.
4. **On-chain settlement removes trust barriers.** Payouts execute automatically via Solana program instructions, not subject to manual approval.
5. **The postMessage API enables deep integrations.** Discord bots can initiate trades via slash commands; Telegram groups show live portfolio updates. The widget is an embeddable trading backend accessible via a simple message-passing interface.
6. **Low partner churn (4.3% quarterly) confirms product-market fit.** Once a platform sees recurring revenue, removing the widget means losing a revenue stream — lock-in without technical lock-in.