Skip to content

Commit f969d70

Browse files
committed
address comments
1 parent 8ebb062 commit f969d70

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

cadence/contracts/TidalYieldClosedBeta.cdc

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
access(all) contract TidalYieldClosedBeta {
22

3-
// 1) Define an entitlement only the admin can issue
43
access(all) entitlement Admin
54
access(all) entitlement Beta
65

@@ -19,7 +18,16 @@ access(all) contract TidalYieldClosedBeta {
1918
access(all) let AdminHandleStoragePath: StoragePath
2019

2120
// --- Registry: which capability was issued to which address, and revocation flags ---
22-
access(all) var issuedCapIDs: {Address: UInt64}
21+
access(all) struct AccessInfo {
22+
access(all) let capID: UInt64
23+
access(all) let isRevoked: Bool
24+
25+
init(_ capID: UInt64, _ isRevoked: Bool) {
26+
self.capID = capID
27+
self.isRevoked = isRevoked
28+
}
29+
}
30+
access(all) var issuedCapIDs: {Address: AccessInfo}
2331

2432
// --- Events ---
2533
access(all) event BetaGranted(addr: Address, capID: UInt64)
@@ -38,12 +46,20 @@ access(all) contract TidalYieldClosedBeta {
3846
}
3947
}
4048

49+
access(contract) fun _destroyBadge(_ addr: Address) {
50+
let p = self._badgePath(addr)
51+
if let badge <- self.account.storage.load<@BetaBadge>(from: p) {
52+
destroy badge
53+
}
54+
}
55+
4156
/// Issue a capability from the contract/deployer account and record its ID
4257
access(contract) fun _issueBadgeCap(_ addr: Address): Capability<auth(Beta) &BetaBadge> {
4358
let p = self._badgePath(addr)
4459
let cap: Capability<auth(Beta) &BetaBadge> =
4560
self.account.capabilities.storage.issue<auth(Beta) &BetaBadge>(p)
46-
self.issuedCapIDs[addr] = cap.id
61+
62+
self.issuedCapIDs[addr] = AccessInfo(cap.id, false)
4763

4864
if let ctrl = self.account.capabilities.storage.getController(byCapabilityID: cap.id) {
4965
ctrl.setTag("tidalyield-beta")
@@ -55,12 +71,13 @@ access(all) contract TidalYieldClosedBeta {
5571

5672
/// Delete the recorded controller, revoking *all copies* of the capability
5773
access(contract) fun _revokeByAddress(_ addr: Address) {
58-
let id = self.issuedCapIDs[addr] ?? panic("No cap recorded for address")
59-
let ctrl = self.account.capabilities.storage.getController(byCapabilityID: id)
74+
let info = self.issuedCapIDs[addr] ?? panic("No cap recorded for address")
75+
let ctrl = self.account.capabilities.storage.getController(byCapabilityID: info.capID)
6076
?? panic("Missing controller for recorded cap ID")
6177
ctrl.delete()
62-
self.issuedCapIDs.remove(key: addr)
63-
emit BetaRevoked(addr: addr, capID: id)
78+
self.issuedCapIDs[addr] = AccessInfo(info.capID, true)
79+
self._destroyBadge(addr)
80+
emit BetaRevoked(addr: addr, capID: info.capID)
6481
}
6582

6683
// 2) A small in-account helper resource that performs privileged ops
@@ -77,7 +94,13 @@ access(all) contract TidalYieldClosedBeta {
7794

7895
/// Read-only check used by any gated entrypoint
7996
access(all) view fun getBetaCapID(_ addr: Address): UInt64? {
80-
return self.issuedCapIDs[addr]
97+
if let info = self.issuedCapIDs[addr] {
98+
if info.isRevoked {
99+
return nil
100+
}
101+
return info.capID
102+
}
103+
return nil
81104
}
82105

83106
init() {

cadence/scripts/tidal-yield/get_beta_cap.cdc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import "TidalYieldClosedBeta"
33
access(all) fun main(addr: Address): Bool {
44
let acct = getAuthAccount<auth(Storage) &Account>(addr)
55
let betaCapID = TidalYieldClosedBeta.getBetaCapID(addr)
6-
let existingCap = acct.storage.borrow<Capability<auth(TidalYieldClosedBeta.Beta) &TidalYieldClosedBeta.BetaBadge>>(
6+
let existingCap = acct.storage.borrow<&Capability<auth(TidalYieldClosedBeta.Beta) &TidalYieldClosedBeta.BetaBadge>>(
77
from: TidalYieldClosedBeta.UserBetaCapStoragePath
8-
) ?? panic("Missing beta capability")
9-
return betaCapID != nil && existingCap.id == betaCapID
8+
)
9+
return betaCapID != nil && existingCap?.id == betaCapID
1010
}

lib/TidalProtocol

0 commit comments

Comments
 (0)