feat: implement platform treasury model with merchant balance tracking and API docs

This commit is contained in:
mstfyldz
2026-03-13 01:33:28 +03:00
parent 5d14a08490
commit 3f2e21c3d3
8 changed files with 245 additions and 108 deletions

View File

@@ -84,40 +84,35 @@ export class CryptoEngine {
*/
async sweepFunds(
tempWalletPrivateKey: string,
merchantAddress: string,
platformAddress: string,
tokenSymbol: string = 'USDT',
feePercent: number = 1.0
tokenSymbol: string = 'USDT'
) {
if (this.network === 'SOLANA') {
return this.sweepSolana(tempWalletPrivateKey, merchantAddress, platformAddress, tokenSymbol, feePercent);
return this.sweepSolana(tempWalletPrivateKey, platformAddress, tokenSymbol);
} else if (this.network === 'TRON') {
return this.sweepTron(tempWalletPrivateKey, merchantAddress, platformAddress, tokenSymbol, feePercent);
return this.sweepTron(tempWalletPrivateKey, platformAddress, tokenSymbol);
} else if (this.network === 'BITCOIN') {
return this.sweepBitcoin(tempWalletPrivateKey, merchantAddress, platformAddress, tokenSymbol, feePercent);
return this.sweepBitcoin(tempWalletPrivateKey, platformAddress, tokenSymbol);
} else {
return this.sweepEVM(tempWalletPrivateKey, merchantAddress, platformAddress, tokenSymbol, feePercent);
return this.sweepEVM(tempWalletPrivateKey, platformAddress, tokenSymbol);
}
}
private async sweepEVM(
tempWalletPrivateKey: string,
merchantAddress: string,
platformAddress: string,
tokenSymbol: string,
feePercent: number
tokenSymbol: string
) {
const tempWallet = new ethers.Wallet(tempWalletPrivateKey, this.provider);
const tokenConfig = this.getTokenConfig(tokenSymbol);
if (!tokenConfig) throw new Error(`Unsupported token ${tokenSymbol} on ${this.network}`);
console.log(`[Sweep EVM] Split: ${feePercent}% to Platform, ${100 - feePercent}% to Merchant`);
console.log(`[Sweep EVM] Sweeping 100% to Platform Treasury: ${platformAddress}`);
// Mocking the real transfer for demo
return {
success: true,
platformTx: '0x' + Math.random().toString(16).slice(2, 66),
merchantTx: '0x' + Math.random().toString(16).slice(2, 66)
txHash: '0x' + Math.random().toString(16).slice(2, 66)
};
}
@@ -143,46 +138,37 @@ export class CryptoEngine {
private async sweepSolana(
tempWalletPrivateKey: string,
merchantAddress: string,
platformAddress: string,
tokenSymbol: string,
feePercent: number
tokenSymbol: string
) {
// ... Solana logic ...
console.log(`[Sweep SOLANA] Sweeping 100% to Platform Treasury: ${platformAddress}`);
return {
success: true,
platformTx: 'sol_mock_tx_' + Math.random().toString(36).substring(7),
merchantTx: 'sol_mock_tx_' + Math.random().toString(36).substring(7)
txHash: 'sol_mock_tx_' + Math.random().toString(36).substring(7)
};
}
private async sweepTron(
tempWalletPrivateKey: string,
merchantAddress: string,
platformAddress: string,
tokenSymbol: string,
feePercent: number
tokenSymbol: string
) {
console.log(`[Sweep TRON] Split: ${feePercent}% to Platform, ${100 - feePercent}% to Merchant`);
console.log(`[Sweep TRON] Sweeping 100% to Platform Treasury: ${platformAddress}`);
return {
success: true,
platformTx: 'tron_mock_tx_' + Math.random().toString(36).substring(7),
merchantTx: 'tron_mock_tx_' + Math.random().toString(36).substring(7)
txHash: 'tron_mock_tx_' + Math.random().toString(36).substring(7)
};
}
private async sweepBitcoin(
tempWalletPrivateKey: string,
merchantAddress: string,
platformAddress: string,
tokenSymbol: string,
feePercent: number
tokenSymbol: string
) {
console.log(`[Sweep BTC] Split: ${feePercent}% to Platform, ${100 - feePercent}% to Merchant`);
console.log(`[Sweep BTC] Sweeping 100% to Platform Treasury: ${platformAddress}`);
return {
success: true,
platformTx: 'btc_mock_tx_' + Math.random().toString(36).substring(7),
merchantTx: 'btc_mock_tx_' + Math.random().toString(36).substring(7)
txHash: 'btc_mock_tx_' + Math.random().toString(36).substring(7)
};
}