Skip to content

Commit

Permalink
updates to subgraph and sdk for v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Nov 9, 2023
1 parent 75cd5f5 commit 2309adc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 34 deletions.
18 changes: 9 additions & 9 deletions packages/docs/pages/allowances.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ Each allowance is stored as a tuple of the following shape:

```solidity
struct Allowance {
uint128 refillAmount;
uint128 maxBalance;
uint64 refillInterval;
uint128 refill;
uint128 maxRefill;
uint64 period;
uint128 balance;
uint64 refillTimestamp;
uint64 timestamp;
}
```

`refillInterval` – Duration of the period in seconds, 0 for one-time allowance
`period` – Duration of the refill interval in seconds, 0 for one-time allowance

`refillAmount` – Amount that will be replenished per period
`refill` – Amount that will be refilled per interval

`refillTimestamp` – Timestamp of the last interval refilled for
`timestamp` – Timestamp of the last interval refilled for

`maxBalance` – Max accrual amount, replenishing stops once the unused allowance hits this value
`maxRefill` – Max accrual amount, refilling stops once the unused allowance balance hits this value

`balance` – Unused allowance that can be spent

All fields can be manually updated.
Upon consumption of an allowance, the `balance` and `refillTimestamp` fields will be updated automatically:
Upon consumption of an allowance, the `balance` and `timestamp` fields will be updated automatically:

- Update the balance to reflect the accrual since the last refill
- Update the refill timestamp to the current interval's timestamp
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ export interface Condition {

export interface Allowance {
key: `0x${string}`
refillInterval: number
refillAmount: BigNumber
refillTimestamp: number
maxBalance: BigNumber
period: number
refill: BigNumber
timestamp: number
maxRefill: BigNumber
balance: BigNumber
}

Expand Down
8 changes: 4 additions & 4 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ type Allowance @entity {
id: ID! # Global unique id
key: Bytes! # Unique within the Roles modifier instance (bytes32)
rolesModifier: RolesModifier!
refillInterval: Int! # duration of the period in seconds, 0 for one-time allowance
refillAmount: BigInt! # amount that will be replenished "at the start of every period" (replace with: per period)
refillTimestamp: Int! # timestamp of the last interval refilled for;
maxBalance: BigInt! # max accrual amount, replenishing stops once the unused allowance hits this value
period: Int! # duration of the period in seconds, 0 for one-time allowance
refill: BigInt! # amount that will be replenished "at the start of every period" (replace with: per period)
timestamp: Int! # timestamp of the last interval refilled for;
maxRefill: BigInt! # max accrual amount, replenishing stops once the unused allowance hits this value
balance: BigInt! # unused allowance;
}

Expand Down
16 changes: 8 additions & 8 deletions packages/subgraph/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ export const getRolesModifier = (rolesModifierId: string): RolesModifier | null
/**
* For created Allowance:
* - balance is 0
* - maxBalance is 0
* - refillAmount is 0
* - refillInterval is 0
* - refillTimestamp is 0
* - maxRefill is 0
* - refill is 0
* - period is 0
* - timestamp is 0
*/
export const getOrCreateAllowance = (allowanceKey: Bytes, rolesModifierId: string): Allowance => {
const id = getAllowanceId(allowanceKey, rolesModifierId)
Expand All @@ -126,10 +126,10 @@ export const getOrCreateAllowance = (allowanceKey: Bytes, rolesModifierId: strin
allowance.key = allowanceKey
allowance.rolesModifier = rolesModifierId
allowance.balance = BigInt.fromU32(0)
allowance.maxBalance = BigInt.fromU32(0)
allowance.refillAmount = BigInt.fromU32(0)
allowance.refillInterval = 0
allowance.refillTimestamp = 0
allowance.maxRefill = BigInt.fromU32(0)
allowance.refill = BigInt.fromU32(0)
allowance.period = 0
allowance.timestamp = 0
allowance.save()
}
return allowance
Expand Down
8 changes: 4 additions & 4 deletions packages/subgraph/src/permissions.mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ export function handleSetAllowance(event: SetAllowance): void {

const allowance = getOrCreateAllowance(event.params.allowanceKey, rolesModifierId)
allowance.balance = event.params.balance
allowance.maxBalance = event.params.balance
allowance.refillAmount = event.params.refillAmount
allowance.refillInterval = event.params.refillInterval.toU32()
allowance.refillTimestamp = event.params.refillTimestamp.toU32()
allowance.refill = event.params.refill
allowance.maxRefill = event.params.maxRefill
allowance.period = event.params.period.toU32()
allowance.timestamp = event.params.timestamp.toU32()
allowance.save()

log.info("Allowance {} has been set", [allowance.id])
Expand Down
3 changes: 0 additions & 3 deletions packages/subgraph/src/roles.mapping.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
AssignRoles,
AvatarSet,
ChangedGuard,
DisabledModule,
EnabledModule,
RolesModSetup,
Expand Down Expand Up @@ -66,8 +65,6 @@ export function handleAssignRoles(event: AssignRoles): void {

export function handleAvatarSet(event: AvatarSet): void {}

export function handleChangedGuard(event: ChangedGuard): void {}

export function handleDisabledModule(event: DisabledModule): void {
const rolesModifierAddress = event.address
const rolesModifierId = getRolesModifierId(rolesModifierAddress)
Expand Down
2 changes: 0 additions & 2 deletions packages/subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ dataSources:
handler: handleAssignRoles
- event: AvatarSet(indexed address,indexed address)
handler: handleAvatarSet
- event: ChangedGuard(address)
handler: handleChangedGuard
- event: DisabledModule(address)
handler: handleDisabledModule
- event: EnabledModule(address)
Expand Down

0 comments on commit 2309adc

Please sign in to comment.