Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/synapse-sdk/src/abis/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,7 @@ export const paymentsAbi = [
{ name: 'finalSettledEpoch', internalType: 'uint256', type: 'uint256' },
{ name: 'note', internalType: 'string', type: 'string' },
],
stateMutability: 'nonpayable',
stateMutability: 'payable',
},
{
type: 'function',
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
})
})
})
14 changes: 14 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,17 @@ export class WarmStorageService {
const window = await viewContract.challengeWindow()
return Number(window)
}

// ========== CDN Operations ==========

async topUpCDNPaymentRails(
signer: ethers.Signer,
dataSetId: number,
cdnAmountToAdd: bigint,
cacheMissAmountToAdd: bigint
): Promise<ethers.TransactionResponse> {
const contract = this._getWarmStorageContract()
const contractWithSigner = contract.connect(signer) as ethers.Contract
return await contractWithSigner.topUpCDNPaymentRails(dataSetId, cdnAmountToAdd, cacheMissAmountToAdd)
}
}
Loading