Skip to content

Commit 02ac093

Browse files
committed
address comments
1 parent a2e9fa6 commit 02ac093

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

cadence/contracts/TidalYield.cdc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ access(all) contract TidalYield {
320320
}
321321
/// Creates a new Tide executing the specified Strategy with the provided funds
322322
access(all) fun createTide(betaRef: auth(TidalYieldClosedBeta.Beta) &TidalYieldClosedBeta.BetaBadge, strategyType: Type, withVault: @{FungibleToken.Vault}) {
323+
pre {
324+
TidalYieldClosedBeta.validateBeta(self.owner?.address!, betaRef):
325+
"Invalid Beta Ref"
326+
}
323327
let balance = withVault.balance
324328
let type = withVault.getType()
325329
let tide <-create Tide(strategyType: strategyType, withVault: <-withVault)
@@ -341,6 +345,9 @@ access(all) contract TidalYield {
341345
pre {
342346
self.tides[tide.uniqueID.id] == nil:
343347
"Collision with Tide ID \(tide.uniqueID.id) - a Tide with this ID already exists"
348+
349+
TidalYieldClosedBeta.validateBeta(self.owner?.address!, betaRef):
350+
"Invalid Beta Ref"
344351
}
345352
emit AddedToManager(id: tide.uniqueID.id, owner: self.owner?.address, managerUUID: self.uuid, tokenType: tide.getType().identifier)
346353
self.tides[tide.uniqueID.id] <-! tide
@@ -350,6 +357,9 @@ access(all) contract TidalYield {
350357
pre {
351358
self.tides[id] != nil:
352359
"No Tide with ID \(id) found"
360+
361+
TidalYieldClosedBeta.validateBeta(self.owner?.address!, betaRef):
362+
"Invalid Beta Ref"
353363
}
354364
let tide = (&self.tides[id] as &Tide?)!
355365
tide.deposit(from: <-from)
@@ -366,6 +376,9 @@ access(all) contract TidalYield {
366376
pre {
367377
self.tides[id] != nil:
368378
"No Tide with ID \(id) found"
379+
380+
TidalYieldClosedBeta.validateBeta(self.owner?.address!, betaRef):
381+
"Invalid Beta Ref"
369382
}
370383
return <- self._withdrawTide(id: id)!
371384
}

cadence/contracts/TidalYieldClosedBeta.cdc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ access(all) contract TidalYieldClosedBeta {
44
access(all) entitlement Beta
55

66
access(all) resource BetaBadge {
7-
access(all) let _owner: Address
8-
init(_ o: Address) {
9-
self._owner = o
7+
access(all) let assignedTo: Address
8+
init(_ addr: Address) {
9+
self.assignedTo = addr
1010
}
1111
access(all) view fun getOwner(): Address {
12-
return self._owner
12+
return self.assignedTo
1313
}
1414
}
1515

@@ -103,6 +103,27 @@ access(all) contract TidalYieldClosedBeta {
103103
return nil
104104
}
105105

106+
access(all) view fun validateBeta(_ addr: Address?, _ betaRef: auth(Beta) &BetaBadge): Bool {
107+
if (addr == nil) {
108+
return false
109+
}
110+
// Must have a live, non-revoked record for this address
111+
let recordedID: UInt64? = self.getBetaCapID(addr!);
112+
if recordedID == nil {
113+
return false
114+
}
115+
116+
if self.issuedCapIDs[addr!]?.isRevoked == true {
117+
return false
118+
}
119+
120+
if betaRef.getOwner() != addr {
121+
return false
122+
}
123+
124+
return true
125+
}
126+
106127
init() {
107128
self.AdminHandleStoragePath = StoragePath(
108129
identifier: "TidalYieldClosedBetaAdmin_\(self.account.address)"

cadence/transactions/tidal-yield/admin/grant_beta.cdc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ transaction() {
88
admin: auth(Capabilities) &Account,
99
user: auth(Storage, Capabilities) &Account
1010
) {
11-
let adminCap: Capability<auth(TidalYieldClosedBeta.Admin) &TidalYieldClosedBeta.AdminHandle> =
12-
admin.capabilities.storage.issue<auth(TidalYieldClosedBeta.Admin) &TidalYieldClosedBeta.AdminHandle>(
13-
TidalYieldClosedBeta.AdminHandleStoragePath
14-
)
15-
let handle: auth(TidalYieldClosedBeta.Admin) &TidalYieldClosedBeta.AdminHandle =
16-
adminCap.borrow() ?? panic("Missing AdminHandle")
11+
let handle = admin.storage.borrow<auth(TidalYieldClosedBeta.Admin) &TidalYieldClosedBeta.AdminHandle>(
12+
from: TidalYieldClosedBeta.AdminHandleStoragePath
13+
) ?? panic("Missing AdminHandle")
1714

1815
let cap: Capability<auth(TidalYieldClosedBeta.Beta) &TidalYieldClosedBeta.BetaBadge> =
1916
handle.grantBeta(addr: user.address)

0 commit comments

Comments
 (0)