@brahmafi/cards-sdk
Version:
Official SDK for integrating Swype payment and credit services
372 lines (355 loc) • 11.7 kB
TypeScript
import { JSX } from 'react';
import * as react_jsx_runtime from 'react/jsx-runtime';
import * as zustand from 'zustand';
interface KycModalProps {
eoaAddress: string;
onClose?: () => void;
onComplete?: () => void;
}
declare function KycModal({ eoaAddress, onClose, onComplete, }: KycModalProps): JSX.Element | null;
interface CreditDelegationRequest {
creditType: "aave-v3" | "euler" | "hypurrFi";
from: string;
creditLimit: number;
userParams?: {
vaults: string[];
borrowVaultAddress: string;
} | {
borrowTokenAddress: string;
};
}
type CardStatus = "initiated" | "pending" | "approved" | "userNotExisting" | "review" | "rejected" | "feePending";
interface UserCard {
cardID: string;
creditProviderAddress: string;
type: "virtual" | "physical";
status: "active" | "inactive" | "pending" | "locked";
last4: string;
solverType: "aave-v3" | "euler" | "hypurrFi";
expirationMonth: string;
expirationYear: string;
}
interface SuppliedAsset {
UsageAsCollateralEnabledOnUser: boolean;
amount: number;
amountUSD: number;
collateralAmountBase: string;
collateralAmountBig: number;
supplyRate: number;
underlyingAsset: string;
}
interface BorrowedAsset {
amount: number;
amountUSD: number;
borrowRate: number;
debtAmountBase: string;
debtAmountBig: number;
underlyingAsset: string;
}
interface AaveCreditMetadata {
availableBorrowsBase: number;
borrowPower: number;
borrowValue: number;
eModeCategory: number;
healthFactor: number;
liquidationThreshold: number;
ltv: number;
netAPY: number;
stableBorrowAPY: number;
stableBorrowedAssets: any[];
suppliedAssets: SuppliedAsset[];
suppliedValue: number;
supplyAPY: number;
totalCollateralBase: number;
totalDebtBase: number;
variableBorrowAPY: number;
variableBorrowedAssets: BorrowedAsset[];
maxDelegateAmount: number;
}
interface EulerPosition {
vault: {
address: string;
name: string;
symbol: string;
token: string;
};
collateralValue: string;
}
interface EulerCreditMetadata {
userPosition: EulerPosition[];
undelegatedPositions: EulerPosition[];
debt: string;
subAccount: string;
}
interface CreditInformationResponse {
data: {
metadata: AaveCreditMetadata | EulerCreditMetadata;
availableLimit: number;
amountDelegated: number;
SupportedChainIDs: number[];
} | null;
}
interface SwypeSDKConfig {
apiKey: string;
baseUrl?: string;
apiPath?: string;
eoaAddress: string;
chainID: number;
signature: string;
deadline: number;
}
type TransactionType = "spend";
type TransactionStatus = "pending" | "declined" | "reversed" | "completed";
type OnchainDirection = "credit" | "debit";
type OnchainStatus = "pending" | "processing" | "completed" | "failed";
type OnchainPurpose = "authorization" | "increment" | "settlement" | "reversal" | "refund" | "recovery";
interface OnchainTransaction {
transaction_hash: string;
chain_id: string;
amount: number;
direction: OnchainDirection;
status: OnchainStatus;
purpose: OnchainPurpose;
created_at: string;
}
interface Merchant {
name: string;
city: string;
country: string;
icon: string;
category: string;
}
interface Transaction {
id: string;
type: TransactionType;
status: TransactionStatus;
amount: number;
currency: string;
local_amount?: number;
local_currency: string;
merchant: Merchant;
declined_reason?: string;
created_at: string;
authorized_at?: string;
posted_at?: string | null;
onchain_transactions?: OnchainTransaction[];
}
interface OnchainTransactionDetail {
id: string;
transaction_id: string;
direction: OnchainDirection;
chain_id: string;
from_address: string;
to_address: string;
transaction_hash: string;
amount: number;
amount_raw: string;
fee_raw: string;
token: string;
status: OnchainStatus;
purpose: OnchainPurpose;
error_details?: string;
created_at: string;
completed_at?: string;
}
interface OnchainTransactionDetailsResponse {
data: OnchainTransactionDetail[];
}
type CreditType = "aave-v3" | "euler" | "hypurrFi" | string;
interface EulerTotalAssetResponse {
data: {
totalAssetsUSD: number;
};
}
declare global {
interface Window {
rain?: {
generateSessionId: (pemKey: string) => Promise<{
secretKey: string;
sessionId: string;
}>;
decryptSecret: (data: string, iv: string, secretKey: string) => Promise<string>;
};
}
}
interface CardDetailsCallbacks {
onToast: (message: {
title: string;
description: string;
icon: string;
}) => void;
signTypedData: (params: any) => Promise<string>;
}
interface ManageCardModalProps {
title: string;
onClose: () => void;
callbacks: CardDetailsCallbacks;
address: string;
chainId: number;
}
declare function ManageCardModal({ title, onClose, callbacks, address, chainId, }: ManageCardModalProps): react_jsx_runtime.JSX.Element;
interface DelegateCardParams$1 {
chainID: number;
creditType: "aave-v3" | "euler" | "hypurrFi";
creditLimit: number;
sendTransactionAsync: (params: {
to: string;
value: bigint;
data: string;
}) => Promise<string>;
signTypedData: (typedData: any) => Promise<string>;
userParams?: {
vaults: string[];
borrowVaultAddress: string;
} | {
borrowTokenAddress: string;
};
}
declare function delegateCard({ chainID, creditLimit, creditType, sendTransactionAsync, signTypedData, userParams, }: DelegateCardParams$1): Promise<{
success: boolean;
message: string;
}>;
interface createCardActionParams {
chainID: number;
creditType: CreditType;
signTypedData: (typedData: any) => Promise<string>;
}
/**
* Creates a new user card if one does not already exist, signs the operation,
* and updates the local card store with the created card.
*
* This function performs the following steps:
* 1. Fetches existing user cards and updates the card store.
* 2. If no card exists, signs a typed message and creates a new card.
* 3. Verifies the card creation by fetching updated cards.
* 4. Ensures that the newly created card belongs to the user (EOA).
* 5. Updates the store with the new card if creation was successful.
*
* @param {createCardActionParams} params - Parameters for creating the card.
* @param {number} params.chainID - The blockchain network ID.
* @param {CreditType} params.creditType - Type of credit to be associated with the card.
* @param {(typedData: any) => Promise<string>} params.signTypedData - Function to sign the typed data.
*
* @returns {Promise<{ success: boolean; message: string }>} - Result indicating success or failure and a message.
*/
declare function createCardAction({ chainID, creditType, signTypedData, }: createCardActionParams): Promise<{
success: boolean;
message: string;
}>;
interface DelegateCardParams {
creditType: "aave-v3" | "euler" | any;
creditLimit: number;
sendTransactionAsync: (params: {
to: string;
value: bigint;
data: string;
}) => Promise<string>;
userParams?: {
vaults: string[];
borrowVaultAddress: string;
} | {
borrowTokenAddress: string;
};
}
declare function delegateAmount({ creditLimit, creditType, sendTransactionAsync, userParams, }: DelegateCardParams): Promise<{
success: boolean;
message: string;
transactionHash?: string;
}>;
interface UpdateCardProviderParams {
creditType: CreditType;
signTypedData: (typedData: any) => Promise<string>;
chainId?: number;
}
declare function updateCardProvider({ creditType, signTypedData, chainId, }: UpdateCardProviderParams): Promise<{
success: boolean;
message: string;
}>;
declare function initializeSwypeSDK(config: SwypeSDKConfig): Promise<void>;
declare const generateAuthSign: (eoaAddress: string, chainId: number, signTypedData: (typedData: any) => Promise<string>) => Promise<{
signature: string;
deadline: number;
}>;
/**
* Fetches a preview of the Euler credit limits based on the provided vaults.
* @param vaults Array of vault addresses to be used for the preview.
* @returns An object containing credit and collateral amounts as strings.
*/
declare const getEulerCardPreview: (vaults: string[], creditType?: CreditType) => Promise<{
data: {
credit: string;
collateral: string;
};
}>;
/**
* Fetches the Euler health factor for the user.
* @returns An object containing the health factor as a string.
*/
declare const getEulerHealthFactor: () => Promise<{
data: {
healthFactor: string;
};
}>;
/**
* Fetches the pending transaction balances for a specific card.
* @param cardID The UUID of the card for which to fetch pending transaction balances.
* @returns An object containing the status and balances of pending transactions.
*/
declare const getPendingTransactionBalance: (cardID: string) => Promise<{
data: {
status: string;
balances: {
usd: number;
};
};
}>;
/**
* Get Euler total assets for a specific chain ID
* @param chainID - The chain ID to get assets for
* @returns Promise with total assets in USD
*/
declare const getEulerTotalAsset: (chainID: number) => Promise<EulerTotalAssetResponse>;
interface KycStoreState {
acceptedRainTerms: boolean;
isKycModalOpen: boolean;
isSumsubProfileVerified: boolean;
setAcceptedRainTerms: (accepted: boolean) => void;
setKycModalOpen: (open: boolean) => void;
setIsSumsubProfileVerified: (verified: boolean) => void;
}
declare const useKycStore: zustand.UseBoundStore<zustand.StoreApi<KycStoreState>>;
interface UseCardDataReturn {
status: CardStatus | null;
userCard: UserCard | null;
isUserCardDelegated: boolean;
isLoading: boolean;
error: string | null;
refreshCardStatus: () => Promise<void>;
}
declare const useCardData: () => UseCardDataReturn;
interface UseCreditDataReturn {
creditInfo: Record<CreditType, CreditInformationResponse | null>;
isLoading: boolean;
error: string | null;
refreshPositions: (creditTypes: CreditType[]) => Promise<void>;
}
declare function useCreditData(): UseCreditDataReturn;
interface UseGetTransactionsReturn {
transactions: Transaction[];
isLoading: boolean;
loadingNextPage: boolean;
error: string | null;
hasNext: boolean;
pendingTxnAmount: number;
loadMore: () => Promise<void>;
refetch: () => Promise<void>;
resetError: () => void;
fetchOnchainDetails: (transactionID: string) => Promise<OnchainTransactionDetailsResponse>;
}
/**
* Hook for managing transactions
* Automatically fetches transactions on mount using SDK internal state
* Provides pagination and onchain details functionality
*/
declare const useGetTransactions: () => UseGetTransactionsReturn;
export { type CardDetailsCallbacks, type CardStatus, type CreditDelegationRequest, type EulerTotalAssetResponse, KycModal, ManageCardModal, type OnchainTransactionDetail, type Transaction, type UpdateCardProviderParams, type UserCard, createCardAction, delegateAmount, delegateCard, generateAuthSign, getEulerCardPreview, getEulerHealthFactor, getEulerTotalAsset, getPendingTransactionBalance, initializeSwypeSDK, updateCardProvider, useCardData, useCreditData, useGetTransactions, useKycStore };