Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/src/content/docs/intro/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ if (verification.dataSetLive) {
// Service provider operations
const isApproved = await warmStorageService.isProviderApproved(providerAddress)
const providers = await warmStorageService.getAllApprovedProviders()

// Top up CDN payment rails
await wamStorageService.topUpCDNPaymentRails(signer, dataSetId, cdnAmountToAdd, cacheMissAmountToAdd)
```

### Subgraph Service
Expand Down
26 changes: 26 additions & 0 deletions packages/synapse-sdk/src/test/warm-storage-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2035,4 +2035,30 @@ describe('WarmStorageService', () => {
mockProvider.call = originalCall
})
})

describe('CDN Operations', () => {
it('should top up CDN payment rails (mock transaction)', async () => {
const dataSetId = 49
const warmStorageService = await createWarmStorageService()
const mockSigner = {
getAddress: async () => '0x1234567890123456789012345678901234567890',
} as any

// Mock the contract connection
const originalGetWarmStorageContract = (warmStorageService as any)._getWarmStorageContract
;(warmStorageService as any)._getWarmStorageContract = () => ({
connect: () => ({
topUpCDNPaymentRails: async () => ({
hash: '0xmocktxhash',
wait: async () => ({ status: 1 }),
}),
}),
})

const tx = await warmStorageService.topUpCDNPaymentRails(mockSigner, dataSetId, 1n, 1n)
assert.equal(tx.hash, '0xmocktxhash')

;(warmStorageService as any)._getWarmStorageContract = originalGetWarmStorageContract
})
})
})
29 changes: 29 additions & 0 deletions packages/synapse-sdk/src/warm-storage/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* - Service provider registration and management
* - Client dataset ID tracking
* - Data set creation verification
* - CDN service management
*
* @example
* ```typescript
Expand Down Expand Up @@ -1081,4 +1082,32 @@ export class WarmStorageService {
const window = await viewContract.challengeWindow()
return Number(window)
}
/**
* Increments the fixed locked-up amounts for CDN payment rails.
*
* This method tops up the prepaid balance for CDN services by adding to the existing
* lockup amounts. Both CDN and cache miss rails can be incremented independently.
*
* @param dataSetId - The ID of the data set
* @param cdnAmountToAdd - Amount to add to the CDN rail lockup
* @param cacheMissAmountToAdd - Amount to add to the cache miss rail lockup
* @returns Transaction response
*/
async topUpCDNPaymentRails(
signer: ethers.Signer,
dataSetId: number,
cdnAmountToAdd: bigint,
cacheMissAmountToAdd: bigint
): Promise<ethers.TransactionResponse> {
if (cdnAmountToAdd < 0n || cacheMissAmountToAdd < 0n) {
throw new Error('Top up amounts must be positive')
}
if (cdnAmountToAdd === 0n && cacheMissAmountToAdd === 0n) {
throw new Error('At least one top up amount must be >0')
}

const contract = this._getWarmStorageContract()
const contractWithSigner = contract.connect(signer) as ethers.Contract
return await contractWithSigner.topUpCDNPaymentRails(dataSetId, cdnAmountToAdd, cacheMissAmountToAdd)
}
}
Loading