From 602e6bbc196f22b2d16be611669543eea21c0a48 Mon Sep 17 00:00:00 2001 From: Austin Kline Date: Tue, 21 May 2024 07:54:34 -0700 Subject: [PATCH] adjust entitlements, address feedback --- contracts/LostAndFound.cdc | 26 +++++++++++-------- contracts/standard/ExampleNFT.cdc | 4 +-- package-lock.json | 14 +++++----- package.json | 2 +- transactions/depositor/setup_depositor.cdc | 1 - .../depositor/withdraw_below_threshold.cdc | 2 +- .../depositor/withdraw_to_threshold.cdc | 2 +- transactions/example-nft/mint_example_nft.cdc | 1 - 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/contracts/LostAndFound.cdc b/contracts/LostAndFound.cdc index 16ec2e5..713b957 100644 --- a/contracts/LostAndFound.cdc +++ b/contracts/LostAndFound.cdc @@ -45,8 +45,12 @@ access(all) contract LostAndFound { access(all) event DepositorTokensAdded(uuid: UInt64, tokens: UFix64, balance: UFix64) access(all) event DepositorTokensWithdrawn(uuid: UInt64, tokens: UFix64, balance: UFix64) + // Used by the @Depositor resource and controls whether the depositor can be used + // or not to send resources to the LostAndFound access(all) entitlement Deposit - access(all) entitlement Withdraw + + // Used by the @Depositor resource to manage settings such as low token threshold + access(all) entitlement Owner // Placeholder receiver so that any resource can be supported, not just FT and NFT Receivers access(all) resource interface AnyResourceReceiver { @@ -54,7 +58,7 @@ access(all) contract LostAndFound { } access(all) resource DepositEstimate { - access(Withdraw) var item: @AnyResource? + access(self) var item: @AnyResource? access(all) let storageFee: UFix64 init(item: @AnyResource, storageFee: UFix64) { @@ -62,7 +66,7 @@ access(all) contract LostAndFound { self.storageFee = storageFee } - access(Withdraw) fun withdraw(): @AnyResource { + access(all) fun withdraw(): @AnyResource { let item <- self.item <- nil return <-item! } @@ -140,7 +144,7 @@ access(all) contract LostAndFound { return nil } - access(Withdraw) fun withdraw(receiver: Capability) { + access(contract) fun withdraw(receiver: Capability) { pre { receiver.address == self.redeemer: "receiver address and redeemer must match" !self.redeemed: "already redeemed" @@ -344,7 +348,7 @@ access(all) contract LostAndFound { } // Redeem a specific ticket instead of all of a certain type. - access(Withdraw) fun redeem(type: Type, ticketID: UInt64, receiver: Capability) { + access(all) fun redeem(type: Type, ticketID: UInt64, receiver: Capability) { pre { receiver.address == self.redeemer: "receiver must match the redeemer of this shelf" self.bins.containsKey(type.identifier): "no bin for provided type" @@ -430,7 +434,7 @@ access(all) contract LostAndFound { storagePayment.getType() == Type<@FlowToken.Vault>(): "storage payment must be in flow tokens" } let receiver = LostAndFound.account - .capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)! + .capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver) .borrow()! @@ -513,11 +517,11 @@ access(all) contract LostAndFound { return false } - access(Mutate) fun setLowBalanceThreshold(threshold: UFix64?) { + access(Owner) fun setLowBalanceThreshold(threshold: UFix64?) { self.lowBalanceThreshold = threshold } - access(Mutate) fun getLowBalanceThreshold(): UFix64? { + access(Owner) fun getLowBalanceThreshold(): UFix64? { return self.lowBalanceThreshold } @@ -528,7 +532,7 @@ access(all) contract LostAndFound { display: MetadataViews.Display? ) : UInt64 { let receiver = LostAndFound.account - .capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)! + .capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver) .borrow()! let storageBeforeShelf = LostAndFound.account.storage.used @@ -577,7 +581,7 @@ access(all) contract LostAndFound { } } - access(Mutate) fun withdrawTokens(amount: UFix64): @{FungibleToken.Vault} { + access(Owner) fun withdrawTokens(amount: UFix64): @{FungibleToken.Vault} { let tokens <-self.flowTokenVault.withdraw(amount: amount) emit DepositorTokensWithdrawn(uuid: self.uuid, tokens: amount, balance: self.flowTokenVault.balance) self.checkForLowBalance() @@ -617,7 +621,7 @@ access(all) contract LostAndFound { } access(all) fun borrowShelfManager(): &LostAndFound.ShelfManager { - return self.account.capabilities.get<&LostAndFound.ShelfManager>(LostAndFound.LostAndFoundPublicPath)!.borrow()! + return self.account.capabilities.get<&LostAndFound.ShelfManager>(LostAndFound.LostAndFoundPublicPath).borrow()! } access(all) fun borrowAllTicketsByType(addr: Address, type: Type): [&LostAndFound.Ticket] { diff --git a/contracts/standard/ExampleNFT.cdc b/contracts/standard/ExampleNFT.cdc index d2da748..45e74a1 100644 --- a/contracts/standard/ExampleNFT.cdc +++ b/contracts/standard/ExampleNFT.cdc @@ -163,7 +163,7 @@ access(all) contract ExampleNFT: ViewResolver { // dictionary of NFT conforming tokens // NFT is a resource type with an `UInt64` ID field - access(self) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}} + access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}} init () { self.ownedNFTs <- {} @@ -197,7 +197,7 @@ access(all) contract ExampleNFT: ViewResolver { } // withdraw removes an NFT from the collection and moves it to the caller - access(NonFungibleToken.Withdraw | NonFungibleToken.Owner) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} { + access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} { let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT") emit Withdraw(id: token.id, from: self.owner?.address) diff --git a/package-lock.json b/package-lock.json index 911cf83..fbbd407 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,13 +9,13 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@flowtyio/flow-contracts": "^0.1.0-beta.6" + "@flowtyio/flow-contracts": "^0.1.0-beta.21" } }, "node_modules/@flowtyio/flow-contracts": { - "version": "0.1.0-beta.6", - "resolved": "https://registry.npmjs.org/@flowtyio/flow-contracts/-/flow-contracts-0.1.0-beta.6.tgz", - "integrity": "sha512-TmGuEdK8DKxop2tgpgFMcX91cT6KOWqRsAmoseECLnRC7/+vZZASQiun1i0e83EABmGgFP3x5ULtQ/WizSSuQQ==", + "version": "0.1.0-beta.21", + "resolved": "https://registry.npmjs.org/@flowtyio/flow-contracts/-/flow-contracts-0.1.0-beta.21.tgz", + "integrity": "sha512-VHmwlxvjoJw/mNnmg2/BzndngkiIF8LsFNqR2CJh1Zoo5OVII+FqUoZkyOFmZ9ZiB7g9bWH9CCMelNxFhGnLWw==", "dependencies": { "commander": "^11.0.0" }, @@ -34,9 +34,9 @@ }, "dependencies": { "@flowtyio/flow-contracts": { - "version": "0.1.0-beta.6", - "resolved": "https://registry.npmjs.org/@flowtyio/flow-contracts/-/flow-contracts-0.1.0-beta.6.tgz", - "integrity": "sha512-TmGuEdK8DKxop2tgpgFMcX91cT6KOWqRsAmoseECLnRC7/+vZZASQiun1i0e83EABmGgFP3x5ULtQ/WizSSuQQ==", + "version": "0.1.0-beta.21", + "resolved": "https://registry.npmjs.org/@flowtyio/flow-contracts/-/flow-contracts-0.1.0-beta.21.tgz", + "integrity": "sha512-VHmwlxvjoJw/mNnmg2/BzndngkiIF8LsFNqR2CJh1Zoo5OVII+FqUoZkyOFmZ9ZiB7g9bWH9CCMelNxFhGnLWw==", "requires": { "commander": "^11.0.0" } diff --git a/package.json b/package.json index dc62227..88af175 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,6 @@ }, "homepage": "https://github.com/Flowtyio/lost-and-found#readme", "dependencies": { - "@flowtyio/flow-contracts": "^0.1.0-beta.6" + "@flowtyio/flow-contracts": "^0.1.0-beta.21" } } diff --git a/transactions/depositor/setup_depositor.cdc b/transactions/depositor/setup_depositor.cdc index 2e40c05..fe1b068 100644 --- a/transactions/depositor/setup_depositor.cdc +++ b/transactions/depositor/setup_depositor.cdc @@ -7,7 +7,6 @@ transaction(lowBalanceThreshold: UFix64?) { prepare(acct: auth(Storage, Capabilities) &Account) { if acct.storage.borrow<&LostAndFound.Depositor>(from: LostAndFound.DepositorStoragePath) == nil { let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver) - ?? panic("flow token repayment capability not found") let depositor <- LostAndFound.createDepositor(flowTokenRepayment, lowBalanceThreshold: lowBalanceThreshold) acct.storage.save(<-depositor, to: LostAndFound.DepositorStoragePath) diff --git a/transactions/depositor/withdraw_below_threshold.cdc b/transactions/depositor/withdraw_below_threshold.cdc index d6ea81a..a267471 100644 --- a/transactions/depositor/withdraw_below_threshold.cdc +++ b/transactions/depositor/withdraw_below_threshold.cdc @@ -6,7 +6,7 @@ import "FlowToken" transaction(lowBalanceThreshold: UFix64) { prepare(acct: auth(Storage, Capabilities) &Account) { if acct.storage.borrow<&LostAndFound.Depositor>(from: LostAndFound.DepositorStoragePath) == nil { - let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)! + let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver) let depositor <- LostAndFound.createDepositor(flowTokenRepayment, lowBalanceThreshold: lowBalanceThreshold) acct.storage.save(<-depositor, to: LostAndFound.DepositorStoragePath) diff --git a/transactions/depositor/withdraw_to_threshold.cdc b/transactions/depositor/withdraw_to_threshold.cdc index 44ae513..6414211 100644 --- a/transactions/depositor/withdraw_to_threshold.cdc +++ b/transactions/depositor/withdraw_to_threshold.cdc @@ -6,7 +6,7 @@ import "FlowToken" transaction(lowBalanceThreshold: UFix64) { prepare(acct: auth(Storage, Capabilities) &Account) { if acct.storage.borrow<&LostAndFound.Depositor>(from: LostAndFound.DepositorStoragePath) == nil { - let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)! + let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver) let depositor <- LostAndFound.createDepositor(flowTokenRepayment, lowBalanceThreshold: lowBalanceThreshold) acct.storage.save(<-depositor, to: LostAndFound.DepositorStoragePath) diff --git a/transactions/example-nft/mint_example_nft.cdc b/transactions/example-nft/mint_example_nft.cdc index fcea942..ae9f053 100644 --- a/transactions/example-nft/mint_example_nft.cdc +++ b/transactions/example-nft/mint_example_nft.cdc @@ -15,7 +15,6 @@ transaction(recipient: Address, num: Int) { execute { let cap = getAccount(recipient).capabilities.get<&{NonFungibleToken.Collection}>(ExampleNFT.CollectionPublicPath) - ?? panic("receiver not found") let receiver = cap.borrow() ?? panic("unable to borrow collection") var count = 0