four-flap-meme-sdk
Version:
SDK for Flap bonding curve and four.meme TokenManager
428 lines (427 loc) • 14.3 kB
TypeScript
export type FourSignConfig = {
rpcUrl: string;
fourApiUrl?: string;
club48Endpoint?: string;
club48ExplorerEndpoint?: string;
txType?: 0 | 2;
gasLimit?: number | bigint;
gasLimitMultiplier?: number;
gasPriceMultiplierPercent?: number;
minGasPriceGwei?: number;
chainId?: number;
prefer21000ForNative?: boolean;
checkBnbForErc20NoHop?: boolean;
estimateGas?: boolean;
customSubmitFn?: (signedTxs: string[]) => Promise<string>;
spPrivateKey?: string;
spMode?: 'none' | 'timestampPersonalSign' | 'concatTxHash' | 'rawTimestamp';
spVMode?: '27_28' | '0_1';
bribeAmount?: number;
};
export type FourBundleMerkleConfig = {
apiKey: string;
customRpcUrl?: string;
fourApiUrl?: string;
bundleBlockOffset?: number;
minBlockOffset?: number;
autoRetryBundle?: boolean;
maxBundleRetries?: number;
txType?: 0 | 2;
gasLimit?: number | bigint;
gasLimitMultiplier?: number;
gasPriceMultiplierPercent?: number;
minGasPriceGwei?: number;
waitForConfirmation?: boolean;
waitTimeoutMs?: number;
chainId?: number;
prefer21000ForNative?: boolean;
checkBnbForErc20NoHop?: boolean;
skipSubmit?: boolean;
};
export type AmountLike = string | number | bigint;
export type MerkleTransactionStatus = {
index: number;
hash: string;
success: boolean;
blockNumber?: number;
gasUsed?: string;
effectiveGasPrice?: string;
gasCost?: string;
error?: string;
};
export type MerkleBundleStatus = {
bundleHash: string;
txHashes: string[];
results: MerkleTransactionStatus[];
successCount: number;
totalGasUsed: bigint;
targetBlock: number;
};
/**
* 统一的 Merkle 方法返回类型
* SDK 不再内部提交,只返回签名交易和元数据
*/
export type MerkleSignedResult = {
/** 已签名的交易数组(发送到服务器进行提交) */
signedTransactions: string[];
/** 创建代币时返回的代币地址(仅 create 方法使用) */
tokenAddress?: string;
/** 多跳钱包的私钥(仅 disperse/sweep 使用,按接收者分组) */
hopWallets?: string[][];
/** 元数据(如利润信息等) */
metadata?: {
[key: string]: any;
};
/** 交易哈希数组(内部提交时返回) */
txHashes?: string[];
};
/** ✅ 创建代币 + 购买参数(Merkle 版本 - 完整) */
export type FourCreateWithBundleBuyMerkleParams = {
privateKeys: string[];
buyAmounts: string[];
b0Amount?: string;
tokenInfo: {
name: string;
symbol: string;
description: string;
imageUrl?: string;
imageFile?: Blob;
label?: 'Meme' | 'AI' | 'Defi' | 'Games' | 'Infra' | 'De-Sci' | 'Social' | 'Depin' | 'Charity' | 'Others';
preSale?: string;
webUrl?: string;
twitterUrl?: string;
telegramUrl?: string;
};
config: FourBundleMerkleConfig;
};
/** ✅ 创建代币 + 购买参数(仅签名版本 - 精简) */
export type FourCreateWithBundleBuySignParams = {
privateKeys: string[];
buyAmounts: string[];
b0Amount?: string;
tokenInfo: {
name: string;
symbol: string;
description: string;
imageUrl?: string;
imageFile?: Blob;
label?: 'Meme' | 'AI' | 'Defi' | 'Games' | 'Infra' | 'De-Sci' | 'Social' | 'Depin' | 'Charity' | 'Others';
preSale?: string;
webUrl?: string;
twitterUrl?: string;
telegramUrl?: string;
};
config: FourSignConfig;
};
/**
* ✅ 创建代币 + 购买结果(简化版)
* 包含 tokenAddress 用于返回创建的代币地址
*/
export type FourCreateWithBundleBuyMerkleResult = MerkleSignedResult;
/** ✅ 批量购买参数(Merkle 版本 - 完整) */
export type FourBatchBuyMerkleParams = {
privateKeys: string[];
buyAmounts: string[];
tokenAddress: string;
config: FourBundleMerkleConfig;
};
/** ✅ 批量购买参数(仅签名版本 - 精简) */
export type FourBatchBuySignParams = {
privateKeys: string[];
buyAmounts: string[];
tokenAddress: string;
config: FourSignConfig;
};
/** ✅ 批量购买结果(简化版) */
export type FourBatchBuyMerkleResult = MerkleSignedResult;
/** ✅ 批量卖出参数(Merkle 版本 - 完整) */
export type FourBatchSellMerkleParams = {
privateKeys: string[];
sellAmounts: string[];
tokenAddress: string;
minOutputAmounts?: (string | bigint)[];
config: FourBundleMerkleConfig;
};
/** ✅ 批量卖出参数(仅签名版本 - 精简) */
export type FourBatchSellSignParams = {
privateKeys: string[];
sellAmounts: string[];
tokenAddress: string;
minOutputAmounts?: (string | bigint)[];
config: FourSignConfig;
};
/** ✅ 批量卖出结果(简化版) */
export type FourBatchSellMerkleResult = MerkleSignedResult;
/** ✅ 私有交易基础配置(Merkle 版本 - 完整) */
export type FourPrivateMerkleBase = {
config: FourBundleMerkleConfig;
};
/** ✅ 私有交易基础配置(仅签名版本 - 精简) */
export type FourPrivateSignBase = {
config: FourSignConfig;
};
/** ✅ 私有购买参数(Merkle 版本 - 完整) */
export type FourPrivateBuyMerkleParams = FourPrivateMerkleBase & {
privateKey: string;
tokenAddress: string;
funds: string;
to?: string;
};
/** ✅ 私有购买参数(仅签名版本 - 精简) */
export type FourPrivateBuySignParams = FourPrivateSignBase & {
privateKey: string;
tokenAddress: string;
funds: string;
to?: string;
};
/** ✅ 私有卖出参数(Merkle 版本 - 完整) */
export type FourPrivateSellMerkleParams = FourPrivateMerkleBase & {
privateKey: string;
tokenAddress: string;
amount: string;
minFunds?: bigint;
};
/** ✅ 私有卖出参数(仅签名版本 - 精简) */
export type FourPrivateSellSignParams = FourPrivateSignBase & {
privateKey: string;
tokenAddress: string;
amount: string;
minFunds?: bigint;
};
/** ✅ 私有交易结果(简化版) */
export type FourPrivateTransactionResult = MerkleSignedResult;
/** ✅ 批量私有购买参数(Merkle 版本 - 完整) */
export type FourBatchPrivateBuyMerkleParams = FourPrivateMerkleBase & {
privateKeys: string[];
fundsList: string[];
tokenAddress: string;
};
/** ✅ 批量私有购买参数(仅签名版本 - 精简) */
export type FourBatchPrivateBuySignParams = FourPrivateSignBase & {
privateKeys: string[];
fundsList: string[];
tokenAddress: string;
};
/** ✅ 批量私有卖出参数(Merkle 版本 - 完整) */
export type FourBatchPrivateSellMerkleParams = FourPrivateMerkleBase & {
privateKeys: string[];
amounts: string[];
tokenAddress: string;
minFundsEach?: bigint;
};
/** ✅ 批量私有卖出参数(仅签名版本 - 精简) */
export type FourBatchPrivateSellSignParams = FourPrivateSignBase & {
privateKeys: string[];
amounts: string[];
tokenAddress: string;
minFundsEach?: bigint;
};
/** ✅ 批量私有交易结果(简化版) */
export type FourBatchPrivateMerkleResult = MerkleSignedResult;
/** ✅ 分发参数(Merkle 版本 - 完整) */
export type DisperseMerkleParams = {
fromPrivateKey: string;
recipients: string[];
amount?: AmountLike;
amounts?: AmountLike[];
tokenAddress?: string;
tokenDecimals?: number;
hopCount?: number | number[];
hopPrivateKeys?: string[][];
items?: Array<{
to: string;
amount: AmountLike;
hopCount?: number;
hopPrivateKeys?: string[];
}>;
config: FourBundleMerkleConfig;
};
/** ✅ 分发参数(仅签名版本 - 精简) */
/** 代币池子类型 */
export type TokenPoolType = 'flap' | 'four' | 'v2' | 'v3';
/** 报价代币类型(池子的计价代币) */
export type QuoteTokenType = 'native' | 'usdt' | 'usdc';
export type DisperseSignParams = {
fromPrivateKey: string;
recipients: string[];
amount?: AmountLike;
amounts?: AmountLike[];
tokenAddress?: string;
tokenDecimals?: number;
hopCount?: number | number[];
hopPrivateKeys?: string[][];
items?: Array<{
to: string;
amount: AmountLike;
hopCount?: number;
hopPrivateKeys?: string[];
}>;
config: FourSignConfig;
/** ✅ 新增:起始 nonce(用于并行调用时避免 nonce 冲突) */
startNonce?: number;
/** ✅ 新增:代币池子类型(用于利润报价),默认 'v2' */
tokenPoolType?: TokenPoolType;
/** ✅ 新增:报价代币类型(池子的计价代币),默认 'native'(BNB/MON) */
quoteToken?: QuoteTokenType;
};
/**
* ✅ 分发结果(简化版)
* 包含 hopWallets 用于返回生成的多跳钱包私钥
*/
export type DisperseMerkleResult = MerkleSignedResult;
/** ✅ 归集参数(Merkle 版本 - 完整) */
export type SweepMerkleParams = {
sourcePrivateKeys: string[];
target: string;
ratioPct?: number;
ratios?: number[];
amount?: AmountLike;
amounts?: AmountLike[];
tokenAddress?: string;
tokenDecimals?: number;
skipIfInsufficient?: boolean;
hopCount?: number | number[];
hopPrivateKeys?: string[][];
sources?: Array<{
privateKey: string;
ratioPct?: number;
amount?: AmountLike;
hopCount?: number;
hopPrivateKeys?: string[];
}>;
config: FourBundleMerkleConfig;
};
/** ✅ 归集参数(仅签名版本 - 精简) */
export type SweepSignParams = {
sourcePrivateKeys: string[];
target: string;
ratioPct?: number;
ratios?: number[];
amount?: AmountLike;
amounts?: AmountLike[];
tokenAddress?: string;
tokenDecimals?: number;
skipIfInsufficient?: boolean;
hopCount?: number | number[];
hopPrivateKeys?: string[][];
sources?: Array<{
privateKey: string;
ratioPct?: number;
amount?: AmountLike;
hopCount?: number;
hopPrivateKeys?: string[];
}>;
config: FourSignConfig;
/** ✅ 新增:起始 nonce(用于并行调用时避免 nonce 冲突,仅对第一个源钱包生效) */
startNonce?: number;
/** ✅ 新增:代币池子类型(用于利润报价),默认 'v2' */
tokenPoolType?: TokenPoolType;
/** ✅ 新增:报价代币类型(池子的计价代币),默认 'native'(BNB/MON) */
quoteToken?: QuoteTokenType;
};
/**
* ✅ 归集结果(简化版)
* 包含 hopWallets 用于返回生成的多跳钱包私钥
*/
export type SweepMerkleResult = MerkleSignedResult;
/** ✅ PancakeProxy 批量购买参数(Merkle 版本 - 完整) */
export type FourPancakeProxyBatchBuyParams = {
privateKeys: string[];
buyAmounts: string[];
tokenAddress: string;
routeType: 'v2' | 'v3-single' | 'v3-multi';
v2Path?: string[];
v3TokenIn?: string;
v3Fee?: number;
v3LpAddresses?: string[];
v3ExactTokenIn?: string;
/** V3 多跳:代币路径 [tokenIn, tokenMid1, ..., tokenOut] */
v3Tokens?: string[];
/** V3 多跳:费率路径 [fee0, fee1, ...] - 长度 = v3Tokens.length - 1 */
v3Fees?: number[];
minOutputAmounts?: (string | bigint)[];
config: FourBundleMerkleConfig;
};
/** ✅ PancakeProxy 批量购买参数(仅签名版本 - 精简) */
export type FourPancakeProxyBatchBuySignParams = {
privateKeys: string[];
buyAmounts: string[];
tokenAddress: string;
routeType: 'v2' | 'v3-single' | 'v3-multi';
v2Path?: string[];
v3TokenIn?: string;
v3Fee?: number;
v3LpAddresses?: string[];
v3ExactTokenIn?: string;
/** V3 多跳:代币路径 [tokenIn, tokenMid1, ..., tokenOut] */
v3Tokens?: string[];
/** V3 多跳:费率路径 [fee0, fee1, ...] - 长度 = v3Tokens.length - 1 */
v3Fees?: number[];
minOutputAmounts?: (string | bigint)[];
config: FourSignConfig;
};
/** ✅ PancakeProxy 批量购买结果(简化版) */
export type FourPancakeProxyBatchBuyResult = MerkleSignedResult;
/** ✅ PancakeProxy 批量卖出参数(Merkle 版本 - 完整) */
export type FourPancakeProxyBatchSellParams = {
privateKeys: string[];
sellAmounts: string[];
tokenAddress: string;
routeType: 'v2' | 'v3-single' | 'v3-multi';
v2Path?: string[];
v3TokenOut?: string;
v3Fee?: number;
v3LpAddresses?: string[];
v3ExactTokenIn?: string;
/** V3 多跳:代币路径 [tokenIn, tokenMid1, ..., tokenOut] */
v3Tokens?: string[];
/** V3 多跳:费率路径 [fee0, fee1, ...] - 长度 = v3Tokens.length - 1 */
v3Fees?: number[];
minOutputAmounts?: (string | bigint)[];
config: FourBundleMerkleConfig;
};
/** ✅ PancakeProxy 批量卖出参数(仅签名版本 - 精简) */
export type FourPancakeProxyBatchSellSignParams = {
privateKeys: string[];
sellAmounts: string[];
tokenAddress: string;
routeType: 'v2' | 'v3-single' | 'v3-multi';
v2Path?: string[];
v3TokenOut?: string;
v3Fee?: number;
v3LpAddresses?: string[];
v3ExactTokenIn?: string;
/** V3 多跳:代币路径 [tokenIn, tokenMid1, ..., tokenOut] */
v3Tokens?: string[];
/** V3 多跳:费率路径 [fee0, fee1, ...] - 长度 = v3Tokens.length - 1 */
v3Fees?: number[];
minOutputAmounts?: (string | bigint)[];
config: FourSignConfig;
};
/** ✅ PancakeProxy 批量卖出结果(简化版) */
export type FourPancakeProxyBatchSellResult = MerkleSignedResult;
export type FourPancakeProxyApprovalParams = {
privateKey: string;
tokenAddress: string;
amount: string | 'max';
rpcUrl: string;
/** 路由类型,用于确定授权目标(V2 或 V3 Router) */
routeType?: 'v2' | 'v3-single' | 'v3-multi';
};
export type FourPancakeProxyApprovalBatchParams = {
privateKeys: string[];
tokenAddress: string;
amounts: (string | 'max')[];
config: FourSignConfig;
/** 路由类型,用于确定授权目标(V2 或 V3 Router) */
routeType?: 'v2' | 'v3-single' | 'v3-multi';
};
/** ✅ PancakeProxy 批量授权结果 */
export type FourPancakeProxyApprovalBatchResult = {
success: boolean;
approvedCount: number;
signedTransactions: string[];
txHashes?: string[];
bundleHash?: string;
message: string;
};