Skip to content

Commit 0e7750c

Browse files
rvaggZenGround0
authored andcommitted
chore: update to synapse@next tag, fix test failures & update more lockup mismatches
1 parent 607a992 commit 0e7750c

File tree

7 files changed

+30
-28
lines changed

7 files changed

+30
-28
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@
9797
"homepage": "https://github.com/filecoin-project/filecoin-pin#readme",
9898
"dependencies": {
9999
"@clack/prompts": "^0.11.0",
100-
"@filoz/synapse-sdk": "^0.34.0",
100+
"@filoz/synapse-sdk": "^0.35.0-dev.1",
101101
"@helia/unixfs": "^6.0.1",
102102
"@ipld/car": "^5.4.2",
103103
"commander": "^14.0.1",
104-
"ethers": "^6.15.0",
105104
"fastify": "^5.6.0",
106105
"helia": "^6.0.1",
107106
"it-to-buffer": "^4.0.10",

src/common/upload-flow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Synapse } from '@filoz/synapse-sdk'
99
import type { CID } from 'multiformats/cid'
1010
import pc from 'picocolors'
1111
import type { Logger } from 'pino'
12-
import type { PaymentCapacityCheck } from '../core/payments/index.js'
12+
import { DEFAULT_LOCKUP_DAYS, type PaymentCapacityCheck } from '../core/payments/index.js'
1313
import { cleanupSynapseService, type SynapseService } from '../core/synapse/index.js'
1414
import { checkUploadReadiness, executeUpload, getDownloadURL, type SynapseUploadResult } from '../core/upload/index.js'
1515
import { formatUSDFC } from '../core/utils/format.js'
@@ -207,7 +207,7 @@ function displayPaymentIssues(capacityCheck: PaymentCapacityCheck, fileSize: num
207207
log.indent(
208208
`Required deposit: ${formatUSDFC(capacityCheck.required.lockupAllowance + capacityCheck.required.lockupAllowance / 10n)} USDFC`
209209
)
210-
log.indent(pc.gray('(includes 10-day safety reserve)'))
210+
log.indent(pc.gray(`(includes ${DEFAULT_LOCKUP_DAYS}-day safety reserve)`))
211211
log.line('')
212212

213213
log.line(pc.bold('Suggested actions:'))

src/core/payments/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ export function calculateStorageAllowances(storageTiB: number, pricePerTiBPerEpo
539539
// Calculate rate allowance (per epoch payment)
540540
const rateAllowance = (pricePerTiBPerEpoch * BigInt(scaledStorage)) / BigInt(scale)
541541

542-
// Calculate lockup allowance (30 days worth)
543-
const epochsIn10Days = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
544-
const lockupAllowance = rateAllowance * epochsIn10Days
542+
// Calculate lockup allowance
543+
const epochsInLockupDays = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
544+
const lockupAllowance = rateAllowance * epochsInLockupDays
545545

546546
return {
547547
rateAllowance,
@@ -582,7 +582,7 @@ export function calculateActualCapacity(rateAllowance: bigint, pricePerTiBPerEpo
582582
* Calculate storage capacity from USDFC amount
583583
*
584584
* Determines how much storage can be purchased with a given USDFC amount,
585-
* accounting for the 10-day lockup period.
585+
* accounting for the 30-day lockup period.
586586
*
587587
* @param usdfcAmount - Amount of USDFC in its smallest unit
588588
* @param pricePerTiBPerEpoch - Current pricing from storage service
@@ -591,9 +591,9 @@ export function calculateActualCapacity(rateAllowance: bigint, pricePerTiBPerEpo
591591
export function calculateStorageFromUSDFC(usdfcAmount: bigint, pricePerTiBPerEpoch: bigint): number {
592592
if (pricePerTiBPerEpoch === 0n) return 0
593593

594-
// Calculate how much this covers for 30 days
595-
const epochsIn10Days = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
596-
const ratePerEpoch = usdfcAmount / epochsIn10Days
594+
// Calculate how much this covers for lockup
595+
const epochsInLockupDays = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
596+
const ratePerEpoch = usdfcAmount / epochsInLockupDays
597597

598598
return calculateActualCapacity(ratePerEpoch, pricePerTiBPerEpoch)
599599
}
@@ -810,7 +810,7 @@ export function computeAdjustmentForExactDaysWithPiece(
810810
* treating WarmStorage as fully trusted with max allowances, i.e. not
811811
* accounting for allowance limits. If usage limits need to be accounted for
812812
* then the capacity can be capped by either deposit or allowances.
813-
* This function accounts for the 10-day lockup requirement.
813+
* This function accounts for the 30-day lockup requirement.
814814
*
815815
* @param depositAmount - Amount deposited in USDFC
816816
* @param pricePerTiBPerEpoch - Current pricing from storage service
@@ -840,21 +840,21 @@ export function calculateDepositCapacity(
840840

841841
// With infinite allowances, deposit is the only limiting factor
842842
// Deposit needs to cover: lockup (30 days) + at least some buffer
843-
const epochsIn10Days = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
843+
const epochsInLockupDays = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
844844
const epochsPerMonth = TIME_CONSTANTS.EPOCHS_PER_MONTH
845845

846846
// Maximum storage we can support with this deposit
847847
// Reserve 10% for buffer beyond the lockup
848848
// Calculate max rate per epoch we can afford with deposit
849-
const maxRatePerEpoch = (depositAmount * BUFFER_DENOMINATOR) / (epochsIn10Days * BUFFER_NUMERATOR)
849+
const maxRatePerEpoch = (depositAmount * BUFFER_DENOMINATOR) / (epochsInLockupDays * BUFFER_NUMERATOR)
850850

851851
// Convert to storage capacity
852852
const tibPerMonth = calculateActualCapacity(maxRatePerEpoch, pricePerTiBPerEpoch)
853853
const gibPerMonth = tibPerMonth * 1024
854854

855855
// Calculate the actual costs for this capacity
856856
const monthlyPayment = maxRatePerEpoch * epochsPerMonth
857-
const requiredLockup = maxRatePerEpoch * epochsIn10Days
857+
const requiredLockup = maxRatePerEpoch * epochsInLockupDays
858858
const totalRequired = withBuffer(requiredLockup)
859859

860860
return {

src/payments/fund.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
computeAdjustmentForExactDays,
1818
computeAdjustmentForExactDaysWithPiece,
1919
computeAdjustmentForExactDeposit,
20+
DEFAULT_LOCKUP_DAYS,
2021
depositUSDFC,
2122
getPaymentStatus,
2223
validatePaymentRequirements,
@@ -31,7 +32,7 @@ import { cancel, createSpinner, intro, isInteractive, outro } from '../utils/cli
3132
import { isTTY, log } from '../utils/cli-logger.js'
3233
import type { AutoFundOptions, FundingAdjustmentResult, FundOptions } from './types.js'
3334

34-
// Helper: confirm/warn or bail when target implies < 10-day runway
35+
// Helper: confirm/warn or bail when target implies < lockup-days runway
3536
async function ensureBelowThirtyDaysAllowed(opts: {
3637
spinner: Spinner
3738
warningLine1: string
@@ -43,7 +44,7 @@ async function ensureBelowThirtyDaysAllowed(opts: {
4344
console.error(pc.red(warningLine1))
4445
console.error(pc.red(warningLine2))
4546
cancel('Fund adjustment aborted')
46-
throw new Error('Unsafe target below 10-day baseline')
47+
throw new Error(`Unsafe target below ${DEFAULT_LOCKUP_DAYS}-day baseline`)
4748
}
4849

4950
log.line(pc.yellow('⚠ Warning'))

src/payments/interactive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
checkAllowances,
1616
checkFILBalance,
1717
checkUSDFCBalance,
18+
DEFAULT_LOCKUP_DAYS,
1819
depositUSDFC,
1920
getPaymentStatus,
2021
setMaxAllowances,
@@ -227,7 +228,7 @@ export async function runInteractiveSetup(options: PaymentSetupOptions): Promise
227228
log.indent(`100 GiB capacity: ~${formatUSDFC((pricePerGiBPerMonth * 100n * 11n) / 10n)} USDFC`)
228229
log.indent(`1 TiB capacity: ~${formatUSDFC((pricePerTiBPerMonth * 11n) / 10n)} USDFC`)
229230
log.indent(`10 TiB capacity: ~${formatUSDFC((pricePerTiBPerMonth * 10n * 11n) / 10n)} USDFC`)
230-
log.indent(pc.gray('(deposit covers 1 month + 10-day safety reserve)'))
231+
log.indent(pc.gray(`(deposit covers 1 month + ${DEFAULT_LOCKUP_DAYS}-day safety reserve)`))
231232
log.flush()
232233

233234
const amountStr = await text({
@@ -299,7 +300,7 @@ export async function runInteractiveSetup(options: PaymentSetupOptions): Promise
299300
? `${(finalCapacity.gibPerMonth / 1024).toFixed(1)} TiB`
300301
: `${finalCapacity.gibPerMonth.toFixed(1)} GiB`
301302
log.indent(`Capacity: ~${capacityStr} for 1 month`)
302-
log.indent(pc.gray('(includes 10-day safety reserve)'))
303+
log.indent(pc.gray(`(includes ${DEFAULT_LOCKUP_DAYS}-day safety reserve)`))
303304
}
304305
log.flush()
305306

src/test/unit/payments-setup.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ describe('Payment Setup Tests', () => {
110110
getStorageInfo: vi.fn().mockResolvedValue({
111111
pricing: {
112112
noCDN: {
113-
perTiBPerEpoch: ethers.parseUnits('0.0000565', 18),
114-
perTiBPerDay: ethers.parseUnits('0.16272', 18),
115-
perTiBPerMonth: ethers.parseUnits('4.8816', 18),
113+
perTiBPerEpoch: ethers.parseUnits('0.00002893519', 18), // 2.5 USDFC/TiB/month
114+
perTiBPerDay: ethers.parseUnits('0.08333333', 18),
115+
perTiBPerMonth: ethers.parseUnits('2.5', 18),
116116
},
117117
},
118118
}),
@@ -196,7 +196,7 @@ describe('Payment Setup Tests', () => {
196196
'0xwarmstorage',
197197
rateAllowance,
198198
lockupAllowance,
199-
86400, // 30 days * 2880 epochs/day
199+
86400n, // 30 days * 2880 epochs/day (bigint)
200200
'USDFC'
201201
)
202202
})
@@ -387,11 +387,12 @@ describe('Payment Setup Tests', () => {
387387
expect(capacityTiB).toBe(0)
388388
})
389389

390-
// simple testcase to show what the pricePerTibPerEpoch would need to be to get 1TiB/month with 1USDFC
391-
// feel free to skip/delete this testcase if it becomes irrelevant
390+
// Verify pricePerTibPerEpoch needed to get 1TiB/month with 1USDFC given 30-day lockup
391+
// With 30-day lockup: 1 USDFC / (30 days * 2880 epochs/day) = 1 USDFC / 86400 epochs
392+
// For 1 TiB capacity: pricePerTiBPerEpoch = 1 / 86400 = 0.000011574074 USDFC
392393
it('should return capacity of 1 when pricePerTibPerEpoch is low', () => {
393394
const usdfcAmount = ethers.parseUnits('1', 18)
394-
const pricePerTiBPerEpoch = ethers.parseUnits('0.000034722219', 18)
395+
const pricePerTiBPerEpoch = ethers.parseUnits('0.000011574074', 18)
395396
const capacityTiB = calculateStorageFromUSDFC(usdfcAmount, pricePerTiBPerEpoch)
396397
// within 10 decimal places accuracy of 1
397398
expect(capacityTiB).toBeCloseTo(1, 10)

src/test/unit/payments.compute.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ describe('computeAdjustmentForExactDays', () => {
8585
it('returns positive delta when more deposit needed (includes 1-hour safety)', () => {
8686
const rateUsed = 1_000_000_000_000_000_000n // 1 USDFC/epoch
8787
const perDay = rateUsed * TIME_CONSTANTS.EPOCHS_PER_DAY
88-
const days = 10
88+
const days = 30
8989
const available = perDay * 30n // exactly 30 days
9090
const status = makeStatus({ filecoinPayBalance: available, lockupUsed: 0n, rateUsed })
9191
const res = computeAdjustmentForExactDays(status, days)
9292
const perHour = perDay / 24n
9393
const safety = perHour > 0n ? perHour : 1n
9494
expect(res.delta).toBe(safety)
95-
expect(res.targetAvailable).toBe(perDay * 10n + safety)
95+
expect(res.targetAvailable).toBe(perDay * 30n + safety)
9696
})
9797

9898
it('returns negative delta when withdrawal possible', () => {

0 commit comments

Comments
 (0)