Skip to content

Commit a3fb475

Browse files
committed
chore: update to synapse@next tag, fix test failures & update more lockup mismatches
1 parent 2456d17 commit a3fb475

File tree

7 files changed

+31
-29
lines changed

7 files changed

+31
-29
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@
9595
"homepage": "https://github.com/FilOzone/filecoin-pin#readme",
9696
"dependencies": {
9797
"@clack/prompts": "^0.11.0",
98-
"@filoz/synapse-sdk": "^0.34.0",
98+
"@filoz/synapse-sdk": "^0.35.0-dev.1",
9999
"@helia/unixfs": "^6.0.1",
100100
"@ipld/car": "^5.4.2",
101101
"commander": "^14.0.1",
102-
"ethers": "^6.15.0",
103102
"fastify": "^5.6.0",
104103
"helia": "^6.0.1",
105104
"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
@@ -537,9 +537,9 @@ export function calculateStorageAllowances(storageTiB: number, pricePerTiBPerEpo
537537
// Calculate rate allowance (per epoch payment)
538538
const rateAllowance = (pricePerTiBPerEpoch * BigInt(scaledStorage)) / BigInt(scale)
539539

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

544544
return {
545545
rateAllowance,
@@ -580,7 +580,7 @@ export function calculateActualCapacity(rateAllowance: bigint, pricePerTiBPerEpo
580580
* Calculate storage capacity from USDFC amount
581581
*
582582
* Determines how much storage can be purchased with a given USDFC amount,
583-
* accounting for the 10-day lockup period.
583+
* accounting for the 30-day lockup period.
584584
*
585585
* @param usdfcAmount - Amount of USDFC in its smallest unit
586586
* @param pricePerTiBPerEpoch - Current pricing from storage service
@@ -589,9 +589,9 @@ export function calculateActualCapacity(rateAllowance: bigint, pricePerTiBPerEpo
589589
export function calculateStorageFromUSDFC(usdfcAmount: bigint, pricePerTiBPerEpoch: bigint): number {
590590
if (pricePerTiBPerEpoch === 0n) return 0
591591

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

596596
return calculateActualCapacity(ratePerEpoch, pricePerTiBPerEpoch)
597597
}
@@ -808,7 +808,7 @@ export function computeAdjustmentForExactDaysWithFile(
808808
* treating WarmStorage as fully trusted with max allowances, i.e. not
809809
* accounting for allowance limits. If usage limits need to be accounted for
810810
* then the capacity can be capped by either deposit or allowances.
811-
* This function accounts for the 10-day lockup requirement.
811+
* This function accounts for the 30-day lockup requirement.
812812
*
813813
* @param depositAmount - Amount deposited in USDFC
814814
* @param pricePerTiBPerEpoch - Current pricing from storage service
@@ -838,21 +838,21 @@ export function calculateDepositCapacity(
838838

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

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

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

853853
// Calculate the actual costs for this capacity
854854
const monthlyPayment = maxRatePerEpoch * epochsPerMonth
855-
const requiredLockup = maxRatePerEpoch * epochsIn10Days
855+
const requiredLockup = maxRatePerEpoch * epochsInLockupDays
856856
const totalRequired = withBuffer(requiredLockup)
857857

858858
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
computeAdjustmentForExactDaysWithFile,
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({
@@ -298,7 +299,7 @@ export async function runInteractiveSetup(options: PaymentSetupOptions): Promise
298299
? `${(finalCapacity.gibPerMonth / 1024).toFixed(1)} TiB`
299300
: `${finalCapacity.gibPerMonth.toFixed(1)} GiB`
300301
log.indent(`Capacity: ~${capacityStr} for 1 month`)
301-
log.indent(pc.gray('(includes 10-day safety reserve)'))
302+
log.indent(pc.gray(`(includes ${DEFAULT_LOCKUP_DAYS}-day safety reserve)`))
302303
}
303304
log.flush()
304305

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: 3 additions & 3 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
89-
const available = perDay * 30n // exactly 30 days
88+
const days = 30
89+
const available = perDay * 30n // exactly 30 days (no safety buffer)
9090
const status = makeStatus({ depositedAmount: 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)