-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from zikriya/feature/feeManagement
Fee management with new flow
- Loading branch information
Showing
10 changed files
with
335 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 90 additions & 22 deletions
112
app/lib/middlewares/helpers/feeDistribution/feeDistributionHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,113 @@ | ||
var { Big } = require("big.js"); | ||
import { FeeDistribution } from "../../../../interfaces/feeDistributionInterface"; | ||
import { | ||
getFeeDistributionSignature, | ||
getSaltAndExpiryData, | ||
} from "../feeDistribution/feeDistributionSignatureHelper"; | ||
import { getFeeDistributionDataByReferralCode } from "../../../httpCalls/multiSwapAxiosHelper"; | ||
|
||
export async function getFeeDistributionData( | ||
referralCode: string, | ||
network: any | ||
export async function getFeeDistributionObject( | ||
feeDistribution: FeeDistribution, | ||
network: any, | ||
sourceAmountIn: string, | ||
sourceAmountOut: string, | ||
destinationAmountIn: string, | ||
destinationAmountOut: string | ||
): Promise<FeeDistribution> { | ||
let data: FeeDistribution = { | ||
feeAllocations: [], | ||
salt: "", | ||
expiry: 0, | ||
signature: "", | ||
}; | ||
try { | ||
const feeDistribution = await getFeeDistributionDataByReferralCode( | ||
referralCode | ||
); | ||
const feeAllocations = feeDistribution ? [feeDistribution] : []; | ||
const { salt, expiry } = await getSaltAndExpiryData(); | ||
const { salt, expiry } = getSaltAndExpiryData(); | ||
console.log({ salt, expiry }); | ||
const signature = await getFeeDistributionSignature( | ||
network.foundryTokenAddress, | ||
network, | ||
network.fiberRouter, | ||
feeAllocations, | ||
feeDistribution, | ||
salt, | ||
expiry | ||
expiry, | ||
sourceAmountIn, | ||
sourceAmountOut, | ||
destinationAmountIn, | ||
destinationAmountOut | ||
); | ||
console.log("feeDistribution signature", signature); | ||
feeDistribution.salt = salt; | ||
feeDistribution.expiry = expiry; | ||
feeDistribution.signature = signature; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
console.log("getFeeDistributionObject", feeDistribution); | ||
return feeDistribution; | ||
} | ||
|
||
export async function getDataAfterCutDistributionFee( | ||
referralCode: string, | ||
decimalAmount: any | ||
): Promise<any> { | ||
let amountAfterCut = decimalAmount; | ||
let totalPlatformFee = "0"; | ||
let feeAllocations: any = []; | ||
let data: FeeDistribution = { | ||
feeAllocations: [], | ||
totalPlatformFee: "", | ||
sourceAmountIn: "", | ||
sourceAmountOut: "", | ||
destinationAmountIn: "", | ||
destinationAmountOut: "", | ||
salt: "", | ||
expiry: 0, | ||
signature: "", | ||
}; | ||
try { | ||
const response = await getFeeDistributionDataByReferralCode(referralCode); | ||
if (response?.rateInBps && response?.recipient) { | ||
const rateInBps = response?.rateInBps; | ||
const rate = Number(rateInBps) / 100; | ||
console.log("rate", rate); | ||
amountAfterCut = await ( | ||
global as any | ||
).commonFunctions.addSlippageInDecimal(decimalAmount, rate); | ||
totalPlatformFee = Big(decimalAmount) | ||
.minus(Big(amountAfterCut)) | ||
.toString(); | ||
feeAllocations.push({ | ||
recipient: response?.recipient, | ||
platformFee: totalPlatformFee?.toString(), | ||
}); | ||
} | ||
data = { | ||
feeAllocations: feeAllocations, | ||
salt: salt, | ||
expiry: expiry, | ||
signature: signature, | ||
totalPlatformFee: totalPlatformFee, | ||
sourceAmountIn: "", | ||
sourceAmountOut: "", | ||
destinationAmountIn: "", | ||
destinationAmountOut: "", | ||
salt: "", | ||
expiry: 0, | ||
signature: "", | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
console.log("getFeeDistributionData", data); | ||
return data; | ||
return { | ||
amountAfterCut: amountAfterCut, | ||
data: data, | ||
}; | ||
} | ||
|
||
export function convertIntoFeeDistributionObject( | ||
feeDistribution: FeeDistribution, | ||
sourceAmountIn: string, | ||
sourceAmountOut: string, | ||
destinationAmountIn: string, | ||
destinationAmountOut: string | ||
): FeeDistribution { | ||
try { | ||
feeDistribution.sourceAmountIn = sourceAmountIn; | ||
feeDistribution.sourceAmountOut = sourceAmountOut; | ||
feeDistribution.destinationAmountIn = destinationAmountIn; | ||
feeDistribution.destinationAmountOut = destinationAmountOut; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
return feeDistribution; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.