This guide walks through the technical steps for integrating Leviathan Embedded Lending into your protocol. The integration is SDK-driven — your frontend calls the @leviathan/sdk/embedded package, which handles all communication with Leviathan’s on-chain programs.
PrerequisitesBefore starting integration, your protocol must complete the onboarding process. Onboarding establishes your protocol’s whitelist, approved functions, and revenue split configuration on-chain.
Before offering lending features, check whether a user qualifies:
const userWallet = new PublicKey("user-wallet-address");const eligibility = await client.checkEligibility(userWallet);if (eligibility.eligible) { // User qualifies — show lending UI console.log(`Credit limit: \${eligibility.creditLimit}`); console.log(`Rate tier: \${eligibility.rateTier}`);} else { // User does not qualify — hide or disable lending features console.log(`Reason: \${eligibility.reason}`);}
Eligibility is determined by the user’s on-chain credit score from leviathan-score. Users with insufficient history or low scores may not qualify.
The agreement links the legal terms (hashed) with the on-chain credit line parameters. Both parties can verify that the on-chain state matches the signed document.
const loan = await client.originateLoan({ borrower: userWallet, amount: 10_000_000, // in smallest units purpose: "margin-trade", // protocol-defined purpose tag});// User signs the loan origination transactionconst signedTx = await walletAdapter.signTransaction(loan.transaction);await connection.sendRawTransaction(signedTx.serialize());console.log(`Loan PDA: \${loan.loanPda}`);console.log(`Capital available for use within protocol`);
Once originated, capital is deployed into a policy-gated environment scoped to your protocol’s approved function set.
Before executing an action with borrowed capital, validate that it conforms to the protocol’s function gate:
const validation = await client.validateAction({ loanPda: loan.loanPda, targetProgram: new PublicKey("target-contract"), functionSelector: "swap", amount: 5_000_000,});if (validation.permitted) { // Proceed with the action} else { // Action would be rejected — do not submit console.log(`Blocked: \${validation.reason}`);}
This client-side check mirrors the on-chain enforcement — use it to prevent users from submitting transactions that would be rejected, improving UX.