Skip to content

Commit b128a91

Browse files
juliangruberpyropy
authored andcommitted
feat: add WarmStorageService#topUpCDNPaymentRails (#332)
Co-authored-by: Srdjan <[email protected]>
1 parent d245ba9 commit b128a91

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

docs/src/content/docs/intro/components.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ if (verification.dataSetLive) {
139139
// Service provider operations
140140
const isApproved = await warmStorageService.isProviderApproved(providerAddress)
141141
const providers = await warmStorageService.getAllApprovedProviders()
142+
143+
// Top up CDN payment rails
144+
await wamStorageService.topUpCDNPaymentRails(signer, dataSetId, cdnAmountToAdd, cacheMissAmountToAdd)
142145
```
143146

144147
### Subgraph Service

packages/synapse-sdk/src/test/warm-storage-service.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,4 +2035,30 @@ describe('WarmStorageService', () => {
20352035
mockProvider.call = originalCall
20362036
})
20372037
})
2038+
2039+
describe('CDN Operations', () => {
2040+
it('should top up CDN payment rails (mock transaction)', async () => {
2041+
const dataSetId = 49
2042+
const warmStorageService = await createWarmStorageService()
2043+
const mockSigner = {
2044+
getAddress: async () => '0x1234567890123456789012345678901234567890',
2045+
} as any
2046+
2047+
// Mock the contract connection
2048+
const originalGetWarmStorageContract = (warmStorageService as any)._getWarmStorageContract
2049+
;(warmStorageService as any)._getWarmStorageContract = () => ({
2050+
connect: () => ({
2051+
topUpCDNPaymentRails: async () => ({
2052+
hash: '0xmocktxhash',
2053+
wait: async () => ({ status: 1 }),
2054+
}),
2055+
}),
2056+
})
2057+
2058+
const tx = await warmStorageService.topUpCDNPaymentRails(mockSigner, dataSetId, 1n, 1n)
2059+
assert.equal(tx.hash, '0xmocktxhash')
2060+
2061+
;(warmStorageService as any)._getWarmStorageContract = originalGetWarmStorageContract
2062+
})
2063+
})
20382064
})

packages/synapse-sdk/src/warm-storage/service.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* - Service provider registration and management
77
* - Client dataset ID tracking
88
* - Data set creation verification
9+
* - CDN service management
910
*
1011
* @example
1112
* ```typescript
@@ -1081,4 +1082,32 @@ export class WarmStorageService {
10811082
const window = await viewContract.challengeWindow()
10821083
return Number(window)
10831084
}
1085+
/**
1086+
* Increments the fixed locked-up amounts for CDN payment rails.
1087+
*
1088+
* This method tops up the prepaid balance for CDN services by adding to the existing
1089+
* lockup amounts. Both CDN and cache miss rails can be incremented independently.
1090+
*
1091+
* @param dataSetId - The ID of the data set
1092+
* @param cdnAmountToAdd - Amount to add to the CDN rail lockup
1093+
* @param cacheMissAmountToAdd - Amount to add to the cache miss rail lockup
1094+
* @returns Transaction response
1095+
*/
1096+
async topUpCDNPaymentRails(
1097+
signer: ethers.Signer,
1098+
dataSetId: number,
1099+
cdnAmountToAdd: bigint,
1100+
cacheMissAmountToAdd: bigint
1101+
): Promise<ethers.TransactionResponse> {
1102+
if (cdnAmountToAdd < 0n || cacheMissAmountToAdd < 0n) {
1103+
throw new Error('Top up amounts must be positive')
1104+
}
1105+
if (cdnAmountToAdd === 0n && cacheMissAmountToAdd === 0n) {
1106+
throw new Error('At least one top up amount must be >0')
1107+
}
1108+
1109+
const contract = this._getWarmStorageContract()
1110+
const contractWithSigner = contract.connect(signer) as ethers.Contract
1111+
return await contractWithSigner.topUpCDNPaymentRails(dataSetId, cdnAmountToAdd, cacheMissAmountToAdd)
1112+
}
10841113
}

0 commit comments

Comments
 (0)