@zebec-network/solana-payroll-sdk 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/services.js +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +8 -6
- package/package.json +1 -1
package/dist/services.js
CHANGED
|
@@ -1298,7 +1298,7 @@ export async function withdrawPayrollAndYieldDeposit(payrollProgram, configsProg
|
|
|
1298
1298
|
return blocktime;
|
|
1299
1299
|
}));
|
|
1300
1300
|
}
|
|
1301
|
-
const withdrawableAmount = calculateTotalWithdrawableAmount(BigNumber(payrollMetadataAccount.schedule.startTime.toString()), BigNumber(payrollMetadataAccount.financials.fullAmount.toString()), BigNumber(payrollMetadataAccount.schedule.duration.toString()), effectiveTime, BigNumber(payrollMetadataAccount.schedule.pausedInterval.toString())).shiftedBy(payrollTokenDecimals * -1);
|
|
1301
|
+
const withdrawableAmount = calculateTotalWithdrawableAmount(BigNumber(payrollMetadataAccount.schedule.startTime.toString()), BigNumber(payrollMetadataAccount.financials.fullAmount.toString()), BigNumber(payrollMetadataAccount.financials.withdrawnAmount.toString()), BigNumber(payrollMetadataAccount.schedule.duration.toString()), effectiveTime, BigNumber(payrollMetadataAccount.schedule.pausedInterval.toString())).shiftedBy(payrollTokenDecimals * -1);
|
|
1302
1302
|
if (withdrawableAmount.lt(params.depositAmount)) {
|
|
1303
1303
|
throw new Error("Withdrawable payroll amount is less than asked Yield deposit amount");
|
|
1304
1304
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -14,4 +14,4 @@ export type ParsedTokenFeeItem = {
|
|
|
14
14
|
};
|
|
15
15
|
export declare function getFeeRateForMint(feeRateList: ParsedTokenFeeItem[], mint: PublicKey): number;
|
|
16
16
|
export declare function deductFeeFromAmount(rawAmount: BigNumber.Value, feeRateInBps: BigNumber.Value): string;
|
|
17
|
-
export declare function calculateTotalWithdrawableAmount(
|
|
17
|
+
export declare function calculateTotalWithdrawableAmount(startTime: BigNumber, fullAmount: BigNumber, withdrawnAmount: BigNumber, duration: BigNumber, now: BigNumber, pausedInterval: BigNumber): BigNumber;
|
package/dist/utils.js
CHANGED
|
@@ -99,14 +99,16 @@ export function deductFeeFromAmount(rawAmount, feeRateInBps) {
|
|
|
99
99
|
const fee = amount.times(feeRateInBps).div(BPS_DENOMINATOR);
|
|
100
100
|
return amount.minus(fee).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
101
101
|
}
|
|
102
|
-
export function calculateTotalWithdrawableAmount(
|
|
103
|
-
if (now.lte(
|
|
102
|
+
export function calculateTotalWithdrawableAmount(startTime, fullAmount, withdrawnAmount, duration, now, pausedInterval) {
|
|
103
|
+
if (now.lte(startTime)) {
|
|
104
104
|
return BigNumber(0);
|
|
105
105
|
}
|
|
106
|
-
const elapsed = BigNumber.max(0, now.minus(
|
|
106
|
+
const elapsed = BigNumber.max(0, now.minus(startTime).minus(pausedInterval));
|
|
107
107
|
const totalDuration = BigNumber.max(1, duration);
|
|
108
|
-
|
|
109
|
-
.times(
|
|
108
|
+
const totalStreamed = BigNumber.min(elapsed
|
|
109
|
+
.times(fullAmount)
|
|
110
110
|
.div(totalDuration)
|
|
111
|
-
.decimalPlaces(0, BigNumber.ROUND_FLOOR),
|
|
111
|
+
.decimalPlaces(0, BigNumber.ROUND_FLOOR), fullAmount);
|
|
112
|
+
const withdrawable = totalStreamed.minus(withdrawnAmount);
|
|
113
|
+
return withdrawable.isNegative() ? BigNumber(0) : withdrawable;
|
|
112
114
|
}
|
package/package.json
CHANGED