@pear-protocol/exchanges-sdk
Advanced tools
| import { submitReferralCode, fetchUserReferrals } from '../../client/lighter/rest'; | ||
| import { retrieveLighterAuthToken } from './auth-token.helper'; | ||
| var __defProp = Object.defineProperty; | ||
| var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
| async function applyReferralCode(sdk, params, demo) { | ||
| const authToken = await retrieveLighterAuthToken(sdk, params.credentials, demo); | ||
| await submitReferralCode({ | ||
| l1Address: params.l1Address, | ||
| referralCode: params.referralCode, | ||
| authToken, | ||
| discord: params.discord, | ||
| telegram: params.telegram, | ||
| x: params.x, | ||
| signature: params.signature | ||
| }, demo); | ||
| } | ||
| __name(applyReferralCode, "applyReferralCode"); | ||
| async function readUserReferrals(sdk, params, demo) { | ||
| const authToken = await retrieveLighterAuthToken(sdk, params.credentials, demo); | ||
| return fetchUserReferrals({ | ||
| l1Address: params.l1Address, | ||
| authToken, | ||
| cursor: params.cursor, | ||
| statsStartTimestamp: params.statsStartTimestamp, | ||
| statsEndTimestamp: params.statsEndTimestamp, | ||
| limit: params.limit, | ||
| eligibleOnly: params.eligibleOnly | ||
| }, demo); | ||
| } | ||
| __name(readUserReferrals, "readUserReferrals"); | ||
| export { applyReferralCode, readUserReferrals }; |
@@ -303,2 +303,76 @@ import { proxyFetch } from '@pear-protocol/utils'; | ||
| __name(fetchPositionFundingSince, "fetchPositionFundingSince"); | ||
| async function submitReferralCode(params, demo = false) { | ||
| const body = new URLSearchParams({ | ||
| l1_address: params.l1Address, | ||
| referral_code: params.referralCode | ||
| }); | ||
| if (params.discord) { | ||
| body.set("discord", params.discord); | ||
| } | ||
| if (params.telegram) { | ||
| body.set("telegram", params.telegram); | ||
| } | ||
| if (params.x) { | ||
| body.set("x", params.x); | ||
| } | ||
| if (params.signature) { | ||
| body.set("signature", params.signature); | ||
| } | ||
| const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/referral/use`, params.authToken, { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/x-www-form-urlencoded" | ||
| }, | ||
| body | ||
| }); | ||
| await readLighterResponse(response, "/referral/use"); | ||
| } | ||
| __name(submitReferralCode, "submitReferralCode"); | ||
| async function fetchUserReferrals(params, demo = false) { | ||
| const query = new URLSearchParams({ | ||
| l1_address: params.l1Address | ||
| }); | ||
| if (params.cursor) { | ||
| query.set("cursor", params.cursor); | ||
| } | ||
| if (params.statsStartTimestamp !== void 0) { | ||
| query.set("stats_start_timestamp", params.statsStartTimestamp.toString()); | ||
| } | ||
| if (params.statsEndTimestamp !== void 0) { | ||
| query.set("stats_end_timestamp", params.statsEndTimestamp.toString()); | ||
| } | ||
| if (params.limit !== void 0) { | ||
| query.set("limit", params.limit.toString()); | ||
| } | ||
| if (params.eligibleOnly) { | ||
| query.set("is_eligible", "true"); | ||
| } | ||
| const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/referral/userReferrals?${query.toString()}`, params.authToken); | ||
| const data = await readLighterResponse(response, "/referral/userReferrals"); | ||
| const referrals = []; | ||
| for (const referral of data.referrals ?? []) { | ||
| if (typeof referral !== "object" || referral === null) { | ||
| continue; | ||
| } | ||
| if (typeof referral.l1_address !== "string") { | ||
| continue; | ||
| } | ||
| referrals.push({ | ||
| l1Address: referral.l1_address, | ||
| referralCode: typeof referral.referral_code === "string" ? referral.referral_code : "", | ||
| usedAt: readReferralCount(referral.used_at), | ||
| tier: typeof referral.tier === "string" ? referral.tier : "", | ||
| tradeStats: readReferralTradeStats(referral.trade_stats) | ||
| }); | ||
| } | ||
| return { | ||
| usedCode: typeof data.used_code === "string" && data.used_code.length > 0 ? data.used_code : null, | ||
| referrals, | ||
| totals: readReferralTotals(data.totals), | ||
| // Reuse the funding-history reading: it treats an unparseable cursor as live, so the worst an | ||
| // encoding mismatch costs here is one extra empty page rather than a dropped one. | ||
| nextCursor: readHistoryCursor(data.cursor) | ||
| }; | ||
| } | ||
| __name(fetchUserReferrals, "fetchUserReferrals"); | ||
| async function authenticatedLighterFetch(url, authToken, init) { | ||
@@ -378,3 +452,47 @@ const headers = new Headers(init?.headers); | ||
| __name(readLighterResponse, "readLighterResponse"); | ||
| function readReferralTradeStats(stats) { | ||
| const raw = typeof stats === "object" && stats !== null ? stats : {}; | ||
| return { | ||
| count: readReferralCount(raw.count), | ||
| volume: readReferralAmount(raw.volume), | ||
| webCount: readReferralCount(raw.web_count), | ||
| webVolume: readReferralAmount(raw.web_volume), | ||
| mobileAppCount: readReferralCount(raw.mobile_app_count), | ||
| mobileAppVolume: readReferralAmount(raw.mobile_app_volume), | ||
| mobileBrowserCount: readReferralCount(raw.mobile_browser_count), | ||
| mobileBrowserVolume: readReferralAmount(raw.mobile_browser_volume), | ||
| freeMakerVolume: readReferralAmount(raw.free_maker_volume), | ||
| freeTakerVolume: readReferralAmount(raw.free_taker_volume), | ||
| nonFreeMakerVolume: readReferralAmount(raw.non_free_maker_volume), | ||
| nonFreeTakerVolume: readReferralAmount(raw.non_free_taker_volume), | ||
| makerFeesPaid: readReferralAmount(raw.maker_fees_paid), | ||
| takerFeesPaid: readReferralAmount(raw.taker_fees_paid) | ||
| }; | ||
| } | ||
| __name(readReferralTradeStats, "readReferralTradeStats"); | ||
| function readReferralTotals(totals) { | ||
| const raw = typeof totals === "object" && totals !== null ? totals : {}; | ||
| return { | ||
| count: readReferralCount(raw.count), | ||
| volume: readReferralAmount(raw.volume), | ||
| freeMakerVolume: readReferralAmount(raw.free_maker_volume), | ||
| freeTakerVolume: readReferralAmount(raw.free_taker_volume), | ||
| nonFreeMakerVolume: readReferralAmount(raw.non_free_maker_volume), | ||
| nonFreeTakerVolume: readReferralAmount(raw.non_free_taker_volume), | ||
| makerFeesPaid: readReferralAmount(raw.maker_fees_paid), | ||
| takerFeesPaid: readReferralAmount(raw.taker_fees_paid), | ||
| totalReferrals: readReferralCount(raw.total_referrals), | ||
| totalPremiumReferrals: readReferralCount(raw.total_premium_referrals) | ||
| }; | ||
| } | ||
| __name(readReferralTotals, "readReferralTotals"); | ||
| function readReferralCount(value) { | ||
| return typeof value === "number" && Number.isFinite(value) ? value : 0; | ||
| } | ||
| __name(readReferralCount, "readReferralCount"); | ||
| function readReferralAmount(value) { | ||
| return typeof value === "string" && value.length > 0 ? value : "0"; | ||
| } | ||
| __name(readReferralAmount, "readReferralAmount"); | ||
| export { createCctpDepositIntentAddress, fetchAccount, fetchAccountLimits, fetchAccountMetadata, fetchAccountsByL1Address, fetchApiKeys, fetchAssetDetails, fetchDepositHistory, fetchDepositNetworks, fetchOrderBookDetails, fetchPositionFundingSince, fetchPublicAccount, fetchPublicOrderBookDetails, fetchTradesSince, fetchWithdrawHistory }; | ||
| export { createCctpDepositIntentAddress, fetchAccount, fetchAccountLimits, fetchAccountMetadata, fetchAccountsByL1Address, fetchApiKeys, fetchAssetDetails, fetchDepositHistory, fetchDepositNetworks, fetchOrderBookDetails, fetchPositionFundingSince, fetchPublicAccount, fetchPublicOrderBookDetails, fetchTradesSince, fetchUserReferrals, fetchWithdrawHistory, submitReferralCode }; |
@@ -10,2 +10,3 @@ import { parseUnits, isAddress } from 'viem'; | ||
| import { LIGHTER_ACCOUNT_NOT_REGISTERED_CODE, readOnboardingStatus } from './onboarding.helper'; | ||
| import { readUserReferrals, applyReferralCode } from './referral.helper'; | ||
| import { MIN_LIGHTER_FAST_WITHDRAW_USDC } from './types'; | ||
@@ -202,2 +203,14 @@ | ||
| return readWithdrawHistory(sdk, params, demo); | ||
| }, | ||
| /** Reads the Fun.xyz bridge deposits Lighter has seen for a wallet. */ | ||
| async listUdaDeposits(walletAddress) { | ||
| return sdk.core.misc.lighter.listUdaDeposits(walletAddress); | ||
| }, | ||
| /** Applies a referrer's code to the owner. Lighter accepts this at most once per owner. */ | ||
| async applyReferralCode(params) { | ||
| return applyReferralCode(sdk, params, demo); | ||
| }, | ||
| /** Reads one page of the owner's referral record, including the code that referred them. */ | ||
| async getUserReferrals(params) { | ||
| return readUserReferrals(sdk, params, demo); | ||
| } | ||
@@ -204,0 +217,0 @@ }; |
+2
-2
| { | ||
| "name": "@pear-protocol/exchanges-sdk", | ||
| "version": "0.10.0", | ||
| "version": "0.11.0", | ||
| "description": "Pear Protocol Exchanges SDK", | ||
@@ -31,3 +31,3 @@ "private": false, | ||
| "@pear-protocol/core-sdk": "^1.19.0", | ||
| "@pear-protocol/types": "^1.30.0", | ||
| "@pear-protocol/types": "^1.30.1", | ||
| "@pear-protocol/utils": "^0.5.3", | ||
@@ -34,0 +34,0 @@ "bignumber.js": "^11.1.1", |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
471657
2.42%110
0.92%11892
2.2%Updated