33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
/**
|
|
* Ramp Network on-ramp adapter — URL-based widget, no server-side session needed.
|
|
*
|
|
* Docs: https://docs.ramp.network/
|
|
*/
|
|
|
|
import type { OnrampProvider, OnrampSessionRequest, OnrampSessionResult } from './onramp-provider';
|
|
|
|
export class RampOnrampAdapter implements OnrampProvider {
|
|
id = 'ramp' as const;
|
|
name = 'Ramp Network';
|
|
|
|
isAvailable(): boolean {
|
|
return !!process.env.RAMP_API_KEY;
|
|
}
|
|
|
|
async createSession(req: OnrampSessionRequest): Promise<OnrampSessionResult> {
|
|
const hostApiKey = process.env.RAMP_API_KEY;
|
|
if (!hostApiKey) throw new Error('Ramp Network not configured');
|
|
|
|
const url = new URL('https://app.ramp.network/');
|
|
url.searchParams.set('hostApiKey', hostApiKey);
|
|
url.searchParams.set('userAddress', req.walletAddress);
|
|
url.searchParams.set('swapAsset', 'BASE_USDC');
|
|
url.searchParams.set('fiatValue', req.fiatAmount.toString());
|
|
url.searchParams.set('fiatCurrency', req.fiatCurrency.toUpperCase());
|
|
if (req.email) url.searchParams.set('userEmailAddress', req.email);
|
|
if (req.returnUrl) url.searchParams.set('finalUrl', req.returnUrl);
|
|
|
|
return { widgetUrl: url.toString(), provider: 'ramp' };
|
|
}
|
|
}
|