Skip to content

Commit 2cb79c8

Browse files
authored
Cancellation & Requested changes from PR 29 (#44)
* requested changes made * RPC API Refs update * Cancellation implemented * Fixed fee share test and claim functions * added some new tests * revoke subscription tests added * cancel subscription tests added * renamed some methods and added claimRegistryFee tests * optmized/simplified existing tests * added some missing tests * updated RPC API refs in README.md and updated an inconsistent return value * readme updated * Readme edits * new deployments
1 parent fec35da commit 2cb79c8

10 files changed

Lines changed: 1155 additions & 181 deletions

README.md

Lines changed: 337 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the initial [MVP Architecture and Design](docs/mvp-design-and-architecture.m
1313
### Prerequisites
1414

1515
- [Foundry](https://book.getfoundry.sh/getting-started/installation) (forge, cast, anvil)
16-
- [jq](https://jqlang.org/) (optional) — for script usage (e.g. `get_address` in `script/utils.sh` reads `deployments.json` via jq)
16+
- [jq](https://jqlang.org/) (optional) — for script usage (e.g. `get_address` in `script/utils.sh` reads `registries_<chain_id>.json` via jq)
1717

1818
### Setup
1919

@@ -149,37 +149,344 @@ All external functions for the registry and asset contracts, for use with JSON-R
149149
150150
### IAssetRegistry
151151
152-
| Function | Type | Permissions | Description | Parameters |
153-
|----------|------|-------------|-------------|------------|
154-
| `createAsset(bytes32 _assetId, uint256 _subscriptionPrice, address _tokenAddress, address _owner)(address)` | write | onlyOwner | Deploys a new Asset contract and registers it under the given id. | `_assetId` — Unique identifier for the asset.<br>`_subscriptionPrice` — Price per subscription unit for the asset.<br>`_tokenAddress` — ERC20 (with permit) used for subscription payments.<br>`_owner` — Creator/owner of the new asset. |
155-
| `viewAsset(bytes32 _assetId)(bool)` | read | anyone | Checks whether an asset is registered for the given id. | `_assetId` — Asset identifier to check. |
156-
| `getAsset(bytes32 _assetId)(address)` | read | anyone | Returns the contract address of the asset for the given id. Throws if not found. | `_assetId` — Asset identifier to look up. |
157-
| `viewSubscription(bytes32 _assetId)(bool)` | read | anyone | Checks whether the caller has an active subscription for the given asset. | `_assetId` — Asset identifier. |
158-
| `viewSubscription(bytes32 _assetId, address _user)(bool)` | read | onlyOwner | Checks whether a user has an active subscription for the given asset. | `_assetId` — Asset identifier.<br>`_user` — User address. |
159-
| `getSubscription(bytes32 _assetId)(uint256)` | read | anyone | Returns the caller's subscription expiry timestamp for the given asset. | `_assetId` — Asset identifier. |
160-
| `getSubscription(bytes32 _assetId, address _user)(uint256)` | read | onlyOwner | Returns the subscription expiry timestamp for the given user for the given asset. | `_assetId` — Asset identifier.<br>`_user` — User address. |
161-
| `getSubscriptionPrice(bytes32 _assetId, uint256 _duration)(uint256)` | read | anyone | Returns the subscription price for the given asset and duration. | `_assetId` — Asset identifier.<br>`_duration` — Subscription duration in seconds. |
162-
| `subscribe(bytes32 _assetId, address _owner, address _spender, uint256 _value, uint256 _deadline, uint8 _v, bytes32 _r, bytes32 _s)(uint256)` | write | anyone | Subscribes the given owner to the asset using ERC-2612 permit; forwards to the asset contract. Returns subscription expiry in Unix timestamp. | `_assetId` — Asset identifier.<br>`_owner` — Token owner and subscription beneficiary.<br>`_spender` — Must be the asset contract address for the permit.<br>`_value` — Permit allowance / payment amount.<br>`_deadline` — Permit signature expiry.<br>`_v` — Signature v.<br>`_r` — Signature r.<br>`_s` — Signature s. |
163-
| `updateCreatorFeeShare(uint256 _creatorFeeShare)()` | write | onlyOwner | Updates the creator's share of subscription fees. | `_creatorFeeShare` — New creator fee share (used with totalFeeShare for percentage). |
164-
| `updateRegistryFeeShare(uint256 _registryFeeShare)()` | write | onlyOwner | Updates the registry's share of subscription fees. | `_registryFeeShare` — New registry fee share (used with totalFeeShare for percentage). |
165-
| `getCreatorFee(uint256 _value)(uint256)` | read | anyone | Computes the creator portion of a payment value based on current fee shares. | `_value` — Total payment value. |
166-
| `getRegistryFee(uint256 _value)(uint256)` | read | anyone | Computes the registry portion of a payment value based on current fee shares. | `_value` — Total payment value. |
167-
| `getOwner()(address)` | read | anyone | Returns the owner of the registry (e.g. for receiving registry fees). ||
152+
---
153+
154+
**createAsset** : Deploys a new Asset contract and registers it under the given id.
155+
- Type: write
156+
- Permission: `onlyOwner`
157+
- Parameters:
158+
- `bytes32 _assetId` : Unique identifier for the asset.
159+
- `uint256 _subscriptionPrice` : Price per subscription unit for the asset.
160+
- `address _tokenAddress` : ERC20 (with permit) used for subscription payments.
161+
- `address _owner` : Creator/owner of the new asset.
162+
- Returns:
163+
- `address` : Address of the newly deployed Asset contract.
164+
165+
166+
---
167+
168+
**viewAsset** : Checks whether an asset is registered for the given id.
169+
- Type: read
170+
- Permission: none
171+
- Parameters:
172+
- `bytes32 _assetId` : Asset identifier to check.
173+
- Returns:
174+
- `bool` : True if an asset exists for the id.
175+
176+
177+
---
178+
179+
**getAsset** : Returns the contract address of the asset for the given id. Throws if not found.
180+
- Type: read
181+
- Permission: none
182+
- Parameters:
183+
- `bytes32 _assetId` : Asset identifier to look up.
184+
- Returns:
185+
- `address` : Address of the Asset contract.
186+
187+
188+
---
189+
190+
**viewMySubscription** : Checks whether the caller has an active subscription for the given asset.
191+
- Type: read
192+
- Permission: none
193+
- Parameters:
194+
- `bytes32 _assetId` : Asset identifier.
195+
- Returns:
196+
- `bool` : True if the caller's subscription is active.
197+
198+
199+
---
200+
201+
**viewSubscription** : Checks whether a user has an active subscription for the given asset.
202+
- Type: read
203+
- Permission: `onlyOwner`
204+
- Parameters:
205+
- `bytes32 _assetId` : Asset identifier.
206+
- `address _user` : User address.
207+
- Returns:
208+
- `bool` : True if the user's subscription is active.
209+
210+
211+
---
212+
213+
**getMySubscription** : Returns the caller's subscription expiry timestamp for the given asset.
214+
- Type: read
215+
- Permission: none
216+
- Parameters:
217+
- `bytes32 _assetId` : Asset identifier.
218+
- Returns:
219+
- `uint256` : Expiry timestamp; 0 if no subscription.
220+
221+
222+
---
223+
224+
**getSubscription** : Returns the subscription expiry timestamp for the given user for the given asset.
225+
- Type: read
226+
- Permission: `onlyOwner`
227+
- Parameters:
228+
- `bytes32 _assetId` : Asset identifier.
229+
- `address _user` : User address.
230+
- Returns:
231+
- `uint256` : Expiry timestamp in seconds; 0 if no subscription.
232+
233+
234+
---
235+
236+
**getSubscriptionPrice** : Returns the subscription price for the given asset and duration.
237+
- Type: read
238+
- Permission: none
239+
- Parameters:
240+
- `bytes32 _assetId` : Asset identifier.
241+
- `uint256 _duration` : Subscription duration in seconds.
242+
- Returns:
243+
- `uint256` : Total price for the duration.
244+
245+
246+
---
247+
248+
**subscribe** : Subscribes the given owner to the asset using ERC-2612 permit; forwards to the asset contract.
249+
- Type: write
250+
- Permission: none
251+
- Parameters:
252+
- `bytes32 _assetId` : Asset identifier.
253+
- `address _owner` : Token owner and subscription beneficiary.
254+
- `address _spender` : Must be the asset contract address for the permit.
255+
- `uint256 _value` : Permit allowance / payment amount.
256+
- `uint256 _deadline` : Permit signature expiry.
257+
- `uint8 _v` : Signature v.
258+
- `bytes32 _r` : Signature r.
259+
- `bytes32 _s` : Signature s.
260+
- Returns:
261+
- `uint256` : Subscription expiry in Unix timestamp.
262+
263+
264+
---
265+
266+
**updateCreatorFeeShare** : Updates the creator's share of subscription fees.
267+
- Type: write
268+
- Permission: `onlyOwner`
269+
- Parameters:
270+
- `uint256 _creatorFeeShare` : New creator fee share (used with totalFeeShare for percentage).
271+
- Returns: void
272+
273+
274+
---
275+
276+
**updateRegistryFeeShare** : Updates the registry's share of subscription fees.
277+
- Type: write
278+
- Permission: `onlyOwner`
279+
- Parameters:
280+
- `uint256 _registryFeeShare` : New registry fee share (used with totalFeeShare for percentage).
281+
- Returns: void
282+
283+
284+
---
285+
286+
**getCreatorFee** : Returns the creator fee for a given payment value.
287+
- Type: read
288+
- Permission: none
289+
- Parameters:
290+
- `uint256 _value` : Total payment value.
291+
- Returns:
292+
- `uint256` : Creator fee amount.
293+
294+
295+
---
296+
297+
**getRegistryFee** : Returns the registry fee for a given payment value.
298+
- Type: read
299+
- Permission: none
300+
- Parameters:
301+
- `uint256 _value` : Total payment value.
302+
- Returns:
303+
- `uint256` : Registry fee amount.
304+
305+
306+
---
307+
308+
**getFees** : Returns the creator and registry fees for a given payment value.
309+
- Type: read
310+
- Permission: none
311+
- Parameters:
312+
- `uint256 _value` : Total payment value.
313+
- Returns:
314+
- `uint256 creatorFee` : Creator portion.
315+
- `uint256 registryFee` : Registry portion.
316+
317+
318+
---
319+
320+
**claimRegistryFee** : Claims the registry fee for a subscriber.
321+
- Type: write
322+
- Permission: `onlyOwner`
323+
- Parameters:
324+
- `bytes32 _assetId` : Asset identifier.
325+
- `address _subscriber` : Address whose registry fee to claim.
326+
- Returns:
327+
- `uint256` : Amount of registry fee claimed.
328+
329+
330+
---
331+
332+
**getOwner** : Returns the owner of the registry (e.g. for receiving registry fees).
333+
- Type: read
334+
- Permission: none
335+
- Parameters: none
336+
- Returns:
337+
- `address` : Registry owner address.
338+
168339
169340
---
170341
171342
### IAsset
172343
173-
| Function | Type | Permissions | Description | Parameters |
174-
|----------|------|-------------|-------------|------------|
175-
| `getAssetId()(bytes32)` | read | anyone | Returns the unique identifier for this asset. ||
176-
| `getRegistryAddress()(address)` | read | anyone | Returns the address of the registry that deployed this asset. ||
177-
| `getTokenAddress()(address)` | read | anyone | Returns the address of the token contract used for subscription payments. Must be an ERC20 with permit. ||
178-
| `getSubscriptionPrice(uint256 duration)(uint256)` | read | anyone | Returns the total price for a subscription of the given duration. | `duration` — Length of the subscription in seconds. |
179-
| `setSubscriptionPrice(uint256 newSubscriptionPrice)()` | write | onlyOwner | Sets the subscription price for the asset. | `newSubscriptionPrice` — New subscription price. |
180-
| `getMySubscription()(uint256)` | read | anyone | Returns the caller's current subscription expiry timestamp. | — |
181-
| `getSubscription(address user)(uint256)` | read | onlyRegistryOrOwner | Returns a user's subscription expiry timestamp. | `user` — Address to query. |
182-
| `viewMySubscription()(bool)` | read | anyone | Checks whether the caller has an active subscription (expiry > block.timestamp). ||
183-
| `viewSubscription(address user)(bool)` | read | onlyRegistryOrOwner | Checks whether a user has an active subscription. | `user` — Address to check. |
184-
| `subscribe(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)(uint256)` | write | anyone | Subscribes an owner using ERC-2612 permit: owner signs permit, then payment is pulled and subscription extended. Returns subscription expiry in Unix timestamp. | `owner` — Token owner and subscription beneficiary.<br>`spender` — Must be this asset contract for the permit to be accepted.<br>`value` — Permit allowance / payment amount (will be rounded down to subscription price units).<br>`deadline` — Permit signature expiry.<br>`v` — Signature recovery id.<br>`r` — Signature r.<br>`s` — Signature s. |
185-
| `revokeSubscription(address user)(bool)` | write | onlyOwner | Revokes a user's subscription. | `user` — Address whose subscription to revoke. |
344+
---
345+
346+
**getAssetId** : Returns the unique identifier for this asset.
347+
- Type: read
348+
- Permission: none
349+
- Parameters: none
350+
- Returns:
351+
- `bytes32` : Asset id.
352+
353+
354+
---
355+
356+
**getRegistryAddress** : Returns the address of the registry that deployed this asset.
357+
- Type: read
358+
- Permission: none
359+
- Parameters: none
360+
- Returns:
361+
- `address` : Registry address.
362+
363+
364+
---
365+
366+
**getTokenAddress** : Returns the address of the token contract used for subscription payments.
367+
- Type: read
368+
- Permission: none
369+
- Parameters: none
370+
- Returns:
371+
- `address` : Token contract address (ERC20 with permit).
372+
373+
374+
---
375+
376+
**getSubscriptionPrice** : Returns the total price for a subscription of the given duration.
377+
- Type: read
378+
- Permission: none
379+
- Parameters:
380+
- `uint256 duration` : Length of the subscription in seconds.
381+
- Returns:
382+
- `uint256` : Total price for the duration.
383+
384+
385+
---
386+
387+
**setSubscriptionPrice** : Sets the subscription price for the asset.
388+
- Type: write
389+
- Permission: `onlyOwner`
390+
- Parameters:
391+
- `uint256 newSubscriptionPrice` : New subscription price.
392+
- Returns: void
393+
394+
395+
---
396+
397+
**getMySubscription** : Returns the caller's current subscription expiry timestamp.
398+
- Type: read
399+
- Permission: none
400+
- Parameters: none
401+
- Returns:
402+
- `uint256` : Expiry timestamp in seconds; 0 if no active subscription.
403+
404+
405+
---
406+
407+
**getSubscription** : Returns a user's subscription expiry timestamp.
408+
- Type: read
409+
- Permission: `onlyRegistryOrOwner`
410+
- Parameters:
411+
- `address user` : Address to query.
412+
- Returns:
413+
- `uint256` : Expiry timestamp; 0 if no subscription.
414+
415+
416+
---
417+
418+
**viewMySubscription** : Checks whether the caller has an active subscription (expiry > block.timestamp).
419+
- Type: read
420+
- Permission: none
421+
- Parameters: none
422+
- Returns:
423+
- `bool` : True if the caller's subscription is active.
424+
425+
426+
---
427+
428+
**viewSubscription** : Checks whether a user has an active subscription.
429+
- Type: read
430+
- Permission: `onlyRegistryOrOwner`
431+
- Parameters:
432+
- `address user` : Address to check.
433+
- Returns:
434+
- `bool` : True if the user's subscription is active.
435+
436+
437+
---
438+
439+
**subscribe** : Subscribes an owner using ERC-2612 permit: owner signs permit, then payment is pulled and subscription extended.
440+
- Type: write
441+
- Permission: none
442+
- Parameters:
443+
- `address owner` : Token owner and subscription beneficiary.
444+
- `address spender` : Must be this asset contract for the permit to be accepted.
445+
- `uint256 value` : Permit allowance / payment amount (will be rounded down to subscription price units).
446+
- `uint256 deadline` : Permit signature expiry.
447+
- `uint8 v` : Signature recovery id.
448+
- `bytes32 r` : Signature r.
449+
- `bytes32 s` : Signature s.
450+
- Returns:
451+
- `uint256` : Subscription expiry in Unix timestamp.
452+
453+
454+
---
455+
456+
**claimCreatorFee** : Claims the creator fee for a user.
457+
- Type: write
458+
- Permission: `onlyOwner`
459+
- Parameters:
460+
- `address user` : Address whose creator fee to claim.
461+
- Returns:
462+
- `uint256` : Amount of creator fee claimed.
463+
464+
465+
---
466+
467+
**claimRegistryFee** : Claims the registry fee for a user.
468+
- Type: write
469+
- Permission: `onlyRegistryOwner`
470+
- Parameters:
471+
- `address user` : Address whose registry fee to claim.
472+
- Returns:
473+
- `uint256` : Amount of registry fee claimed.
474+
475+
476+
---
477+
478+
**revokeSubscription** : Revokes a user's subscription.
479+
- Type: write
480+
- Permission: `onlyOwner`
481+
- Parameters:
482+
- `address user` : Address whose subscription to revoke.
483+
- Returns: void
484+
485+
486+
---
487+
488+
**cancelSubscription** : Cancels the caller's subscription.
489+
- Type: write
490+
- Permission: none
491+
- Parameters: none
492+
- Returns: void

0 commit comments

Comments
 (0)