Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement hybrid custody #44

Merged
merged 47 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a27a75c
add hybrid custody contracts
sisyphusSmiling Jul 12, 2023
f5e9b82
add hybrid custody & dependencies + flow.json & setup script
sisyphusSmiling Jul 13, 2023
8f2e2bc
remove AccountCreator & implementations
sisyphusSmiling Jul 13, 2023
52130b8
add Filter & Manager setup transaction
sisyphusSmiling Jul 13, 2023
b302fdd
init Cadence test framework & update import format
sisyphusSmiling Jul 13, 2023
beca751
update GamePieceNFT to impl ViewResolver
sisyphusSmiling Jul 13, 2023
ef5b350
add filter & factory coverage + setup txns
sisyphusSmiling Jul 13, 2023
edc34fb
test case for self-custody onboarding
sisyphusSmiling Jul 14, 2023
8ea7e1d
add transfer_flow txn & test helper method
sisyphusSmiling Jul 14, 2023
fc01034
replace child publishing txn
sisyphusSmiling Jul 14, 2023
7232967
update GH CI action
sisyphusSmiling Jul 14, 2023
1caa3f2
add HC redeem transaction & test coverage
sisyphusSmiling Jul 14, 2023
62d9d05
refactor blockchain-native onboarding + tests
sisyphusSmiling Jul 14, 2023
ed8a9f2
replace remove child txn
sisyphusSmiling Jul 14, 2023
999810e
replace child account management setup txn
sisyphusSmiling Jul 14, 2023
7ffe4a7
replace add as child multi-sign txn + tests
sisyphusSmiling Jul 14, 2023
fc6e446
rm remaining linked-accounts txns
sisyphusSmiling Jul 14, 2023
f87a500
replace global accounts balance query
sisyphusSmiling Jul 14, 2023
674f264
replace child account metadata scripts
sisyphusSmiling Jul 14, 2023
dd515b7
replace remaining linked-accounts scripts
sisyphusSmiling Jul 14, 2023
f86a4c0
add hybrid custody queries
sisyphusSmiling Jul 14, 2023
a01fc3f
replace HybridCustody in TicketToken balance script
sisyphusSmiling Jul 14, 2023
4f09c11
update arcade prize cross account mint txn
sisyphusSmiling Jul 17, 2023
b819e76
rm LinkedAccounts & LinkedAccountsMetadataViews
sisyphusSmiling Jul 17, 2023
fccfcfe
update flow.json
sisyphusSmiling Jul 17, 2023
a7400c4
update txn comments
sisyphusSmiling Jul 17, 2023
5b1cd54
rm walletless onboarding js tests
sisyphusSmiling Jul 17, 2023
65ed332
impl ViewResolver in TicketToken
sisyphusSmiling Jul 18, 2023
a22948b
add hybrid custody cross-account transaction test coverage
sisyphusSmiling Jul 18, 2023
46c21b2
update import syntax
sisyphusSmiling Jul 18, 2023
5c4a491
update flow cli version in ci action
sisyphusSmiling Jul 18, 2023
a5cd3c3
add singleplayer match test coverage
sisyphusSmiling Jul 18, 2023
7d8cb00
fix add_account_multi_sign txn
sisyphusSmiling Jul 19, 2023
5f7e963
add basic setup test cases
sisyphusSmiling Jul 19, 2023
18b8466
add multiplayer test coverage
sisyphusSmiling Jul 19, 2023
a6eb265
add cheating test case coverage
sisyphusSmiling Jul 19, 2023
301e2ad
rm js test framework
sisyphusSmiling Jul 19, 2023
98ac434
update ci workflow
sisyphusSmiling Jul 19, 2023
fa2f57f
re-include AccountCreator + coverage in onboarding txns
sisyphusSmiling Jul 20, 2023
aaf14cc
add AccountCreator queries & txns + test coverage
sisyphusSmiling Jul 20, 2023
b2e19fc
update setup & flow config
sisyphusSmiling Jul 24, 2023
c8608c6
add testnet deployment in flow config
sisyphusSmiling Jul 24, 2023
26c05fc
fix ticket token balance query
sisyphusSmiling Jul 26, 2023
0583387
add metadata setter to add_account_multi_sign
sisyphusSmiling Jul 26, 2023
473399f
add metadata setter txns
sisyphusSmiling Jul 26, 2023
f21e053
metadata updates to contracts
sisyphusSmiling Jul 26, 2023
137e1f0
update .gitignore
sisyphusSmiling Jul 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/ci.yml

This file was deleted.

27 changes: 12 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ on:

jobs:
build:
name: Flow CLI Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
cache-dependency-path: lib/js/test/package-lock.json
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"
- name: Flow cli Version
run: flow version
- name: Update PATH
run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: cd lib/js/test && npm ci
- run: make ci
- uses: actions/checkout@v3
with:
submodules: "true"
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Install Flow CLI
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.3.2
- name: Run tests
run: make ci

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.DS_Store
flowdb/
lib/js/test/node_modules
.vscode/
.env
coverage.json
*.pkey
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: test
test:
$(MAKE) test -C lib/js/test
set -e
flow test --cover ./test/*_tests.cdc

.PHONY: ci
ci:
$(MAKE) ci -C lib/js/test
ci: test
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,19 @@ To demo the functionality of this repo, clone it and follow the steps below by e

- In one terminal window, run:
```sh
flow emulator start
flow emulator
```

- In another terminal window deploy the contracts with:
- In another terminal window, run the setup script creating our accounts & deploying contracts:
```sh
flow deploy
sh setup.sh
```

- Lastly, a HybridCustody pre-requisite includes setting up a Capability `Filter` and Capability Factory `Manager`. These ensure that parent account access is scoped to just the Capabilities they need to interact with the assets we as the developer want them to access. For more info on `CapabilityFilter` & `CapabilityFactory`, read [these docs](https://developers.flow.com/concepts/hybrid-custody/guides/linking-accounts#pre-requisites).

```sh
flow transactions send ./transactions/hybrid-custody/dev-setup/setup_filter_and_factory_manager.cdc \
f8d6e0586b0a20c7 GamePieceNFT f8d6e0586b0a20c7 TicketToken
```

## Walletless Demo Walkthrough
Expand Down
8 changes: 4 additions & 4 deletions contracts/ArcadePrize.cdc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import NonFungibleToken from "./utility/NonFungibleToken.cdc"
import FungibleToken from "./utility/FungibleToken.cdc"
import MetadataViews from "./utility/MetadataViews.cdc"
import TicketToken from "./TicketToken.cdc"
import "NonFungibleToken"
import "FungibleToken"
import "MetadataViews"
import "TicketToken"

pub contract ArcadePrize: NonFungibleToken {

Expand Down
2 changes: 1 addition & 1 deletion contracts/DynamicNFT.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MetadataViews from "./utility/MetadataViews.cdc"
import "MetadataViews"

/// DynamicNFT
///
Expand Down
109 changes: 68 additions & 41 deletions contracts/GamePieceNFT.cdc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import FungibleToken from "./utility/FungibleToken.cdc"
import NonFungibleToken from "./utility/NonFungibleToken.cdc"
import MetadataViews from "./utility/MetadataViews.cdc"
import GamingMetadataViews from "./GamingMetadataViews.cdc"
import DynamicNFT from "./DynamicNFT.cdc"
import "FungibleToken"
import "NonFungibleToken"
import "MetadataViews"
import "ViewResolver"

import "GamingMetadataViews"
import "DynamicNFT"

/// GamePieceNFT
///
Expand All @@ -11,7 +13,7 @@ import DynamicNFT from "./DynamicNFT.cdc"
/// heavily modeled on MonsterMaker, using images from that NFT collection
/// as well as many values & methods from that collection.
///
pub contract GamePieceNFT: NonFungibleToken {
pub contract GamePieceNFT: NonFungibleToken, ViewResolver {

/// Counter to track total circulating supply
pub var totalSupply: UInt64
Expand Down Expand Up @@ -217,45 +219,13 @@ pub contract GamePieceNFT: NonFungibleToken {
self.id
)
case Type<MetadataViews.ExternalURL>():
return MetadataViews.ExternalURL("https://walletless-arcade-game.vercel.app/".concat(self.id.toString()))
// TODO: Confirm returned types
return MetadataViews.ExternalURL("https://walletless-arcade-game.vercel.app/")
case Type<MetadataViews.NFTCollectionData>():
return MetadataViews.NFTCollectionData(
storagePath: GamePieceNFT.CollectionStoragePath,
publicPath: GamePieceNFT.CollectionPublicPath,
providerPath: GamePieceNFT.ProviderPrivatePath,
publicCollection: Type<&GamePieceNFT.Collection{GamePieceNFT.GamePieceNFTCollectionPublic}>(),
publicLinkedType: Type<&GamePieceNFT.Collection{GamePieceNFT.GamePieceNFTCollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(),
providerLinkedType: Type<&GamePieceNFT.Collection{GamePieceNFT.GamePieceNFTCollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Provider, MetadataViews.ResolverCollection}>(),
createEmptyCollectionFunction: (fun (): @NonFungibleToken.Collection {
return <-GamePieceNFT.createEmptyCollection()
})
)
return GamePieceNFT.resolveView(view)
case Type<MetadataViews.NFTCollectionDisplay>():
let media = MetadataViews.Media(
file: MetadataViews.HTTPFile(
url: "https://i.imgur.com/UMXsEjt.png"
),
mediaType: "image/png"
)

let bannerMedia = MetadataViews.Media(
file: MetadataViews.HTTPFile(
url: "https://i.imgur.com/NzV9cyo.png"
),
mediaType: "image/png"
)
return MetadataViews.NFTCollectionDisplay(
name: "The MonsterMaker GamePieceNFT Collection",
description: "This collection is used as an example to help you develop your next Flow NFT.",
externalURL: MetadataViews.ExternalURL("https://walletless-arcade-game.vercel.app/"),
squareImage: media,
bannerImage: bannerMedia,
socials: {}
)
return GamePieceNFT.resolveView(view)
case Type<MetadataViews.Traits>():
let traitsView = MetadataViews.dictToTraits(dict: self.metadata, excludedNames: [])

return traitsView
default:
return nil
Expand Down Expand Up @@ -559,6 +529,63 @@ pub contract GamePieceNFT: NonFungibleToken {
)
}

/// Function that resolves a metadata view for this contract.
///
/// @param view: The Type of the desired view.
/// @return A structure representing the requested view.
///
pub fun resolveView(_ view: Type): AnyStruct? {
switch view {
case Type<MetadataViews.NFTCollectionData>():
return MetadataViews.NFTCollectionData(
storagePath: GamePieceNFT.CollectionStoragePath,
publicPath: GamePieceNFT.CollectionPublicPath,
providerPath: GamePieceNFT.ProviderPrivatePath,
publicCollection: Type<&GamePieceNFT.Collection{GamePieceNFT.GamePieceNFTCollectionPublic}>(),
publicLinkedType: Type<&GamePieceNFT.Collection{GamePieceNFT.GamePieceNFTCollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(),
providerLinkedType: Type<&GamePieceNFT.Collection{GamePieceNFT.GamePieceNFTCollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Provider, MetadataViews.ResolverCollection}>(),
createEmptyCollectionFunction: (fun (): @NonFungibleToken.Collection {
return <-GamePieceNFT.createEmptyCollection()
})
)
case Type<MetadataViews.NFTCollectionDisplay>():
let media = MetadataViews.Media(
file: MetadataViews.HTTPFile(
url: "https://i.imgur.com/UMXsEjt.png"
),
mediaType: "image/png"
)

let bannerMedia = MetadataViews.Media(
file: MetadataViews.HTTPFile(
url: "https://i.imgur.com/NzV9cyo.png"
),
mediaType: "image/png"
)
return MetadataViews.NFTCollectionDisplay(
name: "The MonsterMaker GamePieceNFT Collection",
description: "This collection is used as an example to help you develop your next Flow NFT.",
externalURL: MetadataViews.ExternalURL("https://walletless-arcade-game.vercel.app/"),
squareImage: media,
bannerImage: bannerMedia,
socials: {}
)
}
return nil
}

/// Function that returns all the Metadata Views implemented by a Non Fungible Token
///
/// @return An array of Types defining the implemented views. This value will be used by
/// developers to know which parameter to pass to the resolveView() method.
///
pub fun getViews(): [Type] {
return [
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>()
]
}

init() {

self.totalSupply = 0
Expand Down
2 changes: 1 addition & 1 deletion contracts/GamingMetadataViews.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MetadataViews from "./utility/MetadataViews.cdc"
import "MetadataViews"

/// GamingMetadataViews
///
Expand Down
50 changes: 0 additions & 50 deletions contracts/LinkedAccountMetadataViews.cdc

This file was deleted.

Loading