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

Fast Break #229

Merged
merged 43 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6d6b21f
initial fast break contract implementation
HouseOfHufflepuff Dec 10, 2023
5d94239
dynamic nft
HouseOfHufflepuff Dec 10, 2023
ef5be2c
Merge branch 'master' into jer/fast-break
HouseOfHufflepuff Dec 10, 2023
848338e
renamed resources
HouseOfHufflepuff Dec 11, 2023
d1ec7c1
Merge branch 'jer/fast-break' of github.com:dapperlabs/nba-smart-cont…
HouseOfHufflepuff Dec 11, 2023
74605a5
serial numbers will be individually incremented. ie every player star…
HouseOfHufflepuff Dec 11, 2023
9fe976e
game validation
HouseOfHufflepuff Dec 11, 2023
ab76169
tests
HouseOfHufflepuff Dec 11, 2023
9f1c4c7
wired game play to submission map
HouseOfHufflepuff Dec 16, 2023
946ff3d
added oracle functions to update score
HouseOfHufflepuff Dec 17, 2023
4c9c17c
fatigue mode and hydrated events
HouseOfHufflepuff Dec 17, 2023
623ac64
isPublic & event hydration
HouseOfHufflepuff Dec 17, 2023
587fa81
fast break stats
HouseOfHufflepuff Dec 17, 2023
9044c03
top shot contract integration
HouseOfHufflepuff Dec 17, 2023
0df5c52
test framework and create run test
HouseOfHufflepuff Dec 17, 2023
b3f5485
moved out stats function and added tests
HouseOfHufflepuff Dec 17, 2023
2bf3d86
tests for play use cases
HouseOfHufflepuff Dec 18, 2023
f8e0ef9
prevent re-submission to fast break
HouseOfHufflepuff Dec 18, 2023
5829a65
added tests for fail play cases
HouseOfHufflepuff Dec 18, 2023
6983c4d
added comments per pr comment
HouseOfHufflepuff Dec 19, 2023
f9ce2fe
added oracle test coverage, comments
HouseOfHufflepuff Dec 19, 2023
ace348a
pushing up assets.go
HouseOfHufflepuff Dec 19, 2023
ba9bcb7
handled errors in tests
HouseOfHufflepuff Dec 27, 2023
052395b
resolving pr comments & introduced enum game states
HouseOfHufflepuff Dec 28, 2023
2498246
Update contracts/FastBreak.cdc
HouseOfHufflepuff Dec 28, 2023
26c92a4
Update contracts/FastBreak.cdc
HouseOfHufflepuff Dec 28, 2023
f2abe5e
resolving pr feedback
HouseOfHufflepuff Dec 28, 2023
b612c27
rename wallet to account
HouseOfHufflepuff Dec 28, 2023
ef90443
added depth to comments especially around game rules and field defini…
HouseOfHufflepuff Dec 28, 2023
119f87a
added comments
HouseOfHufflepuff Dec 29, 2023
d381920
merge conflict
HouseOfHufflepuff Dec 29, 2023
57e3ee4
removed isPublic & renamed leaderboard winCount
HouseOfHufflepuff Jan 2, 2024
cd205ae
pr feedback if... let
HouseOfHufflepuff Jan 2, 2024
2032b4f
Merge branch 'master' into jer/fast-break
HouseOfHufflepuff Jan 2, 2024
3277df3
more efficient validation of top shots
HouseOfHufflepuff Jan 2, 2024
020cd79
regenerated assets go
HouseOfHufflepuff Jan 2, 2024
37d3956
Update contracts/FastBreak.cdc
HouseOfHufflepuff Jan 3, 2024
30d6524
player resource
HouseOfHufflepuff Jan 8, 2024
10b6903
Merge branch 'jer/fast-break' of github.com:dapperlabs/nba-smart-cont…
HouseOfHufflepuff Jan 8, 2024
12e0faa
recompiled assets
HouseOfHufflepuff Jan 8, 2024
72bacd0
Make player a NFT
HouseOfHufflepuff Jan 9, 2024
5771878
player account mapping
HouseOfHufflepuff Jan 9, 2024
0aae769
recompile assets
HouseOfHufflepuff Jan 9, 2024
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
815 changes: 815 additions & 0 deletions contracts/FastBreak.cdc

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions lib/go/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
defaultTopShotLockingAddress = "TOPSHOTLOCKINGADDRESS"
defaultTopShotRoyaltyAddress = "TOPSHOTROYALTYADDRESS"
defaultNetwork = "${NETWORK}"
fastBreakFile = "FastBreak.cdc"
HouseOfHufflepuff marked this conversation as resolved.
Show resolved Hide resolved
)

// GenerateTopShotContract returns a copy
Expand Down Expand Up @@ -120,3 +121,13 @@ func GenerateTopShotLockingContractWithTopShotRuntimeAddr(nftAddr string, topsho

return []byte(codeWithTopShotAddr)
}

// GenerateFastBreakContract returns a copy
// of the FastBreakContract with the import addresses updated
func GenerateFastBreakContract(nftAddr string, topshotAddr string) []byte {
fastBreakCode := assets.MustAssetString(fastBreakFile)
codeWithNFTAddr := strings.ReplaceAll(fastBreakCode, defaultNonFungibleTokenAddress, nftAddr)
codeWithTopShotAddr := strings.ReplaceAll(codeWithNFTAddr, defaultTopshotAddress, topshotAddr)

return []byte(codeWithTopShotAddr)
}
7 changes: 7 additions & 0 deletions lib/go/contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ func TestTopShotMarketV3Contract(t *testing.T) {
assert.NotNil(t, contract)
assert.Contains(t, string(contract), addrA)
}

func TestFastBreakContract(t *testing.T) {
contract := contracts.GenerateFastBreakContract(addrA, addrB)
assert.NotNil(t, contract)
assert.Contains(t, string(contract), addrA)
assert.Contains(t, string(contract), addrB)
}
23 changes: 23 additions & 0 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions lib/go/templates/fastbreak_oracle_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package templates

import (
"github.com/dapperlabs/nba-smart-contracts/lib/go/templates/internal/assets"
)

const (
createFastBreakRunFilename = "fastbreak/oracle/create_run.cdc"
createFastBreakGameFilename = "fastbreak/oracle/create_game.cdc"
addStatToFastBreakGameFilename = "fastbreak/oracle/add_stat_to_game.cdc"
updateFastBreakGameFilename = "fastbreak/oracle/update_fast_break_game.cdc"
scoreFastBreakSubmissionFilename = "fastbreak/oracle/score_fast_break_submission.cdc"
)

func GenerateCreateRunScript(env Environment) []byte {
code := assets.MustAssetString(transactionsPath + createFastBreakRunFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateCreateGameScript(env Environment) []byte {
code := assets.MustAssetString(transactionsPath + createFastBreakGameFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateAddStatToGameScript(env Environment) []byte {
code := assets.MustAssetString(transactionsPath + addStatToFastBreakGameFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateUpdateFastBreakGameScript(env Environment) []byte {
code := assets.MustAssetString(transactionsPath + updateFastBreakGameFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateScoreFastBreakSubmissionScript(env Environment) []byte {
code := assets.MustAssetString(transactionsPath + scoreFastBreakSubmissionFilename)

return []byte(replaceAddresses(code, env))
}
45 changes: 45 additions & 0 deletions lib/go/templates/fastbreak_script_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package templates

import (
"github.com/dapperlabs/nba-smart-contracts/lib/go/templates/internal/assets"
)

const (
fastBreakScriptsPath = "../../../transactions/fastbreak/scripts/"

getFastBreakByIdFilename = "get_fast_break.cdc"
getFastBreakTokenCountFilename = "get_token_count.cdc"
getScoreByPlayerFilename = "get_player_score.cdc"
getFastBreakStatsFilename = "get_fast_break_stats.cdc"
fastBreakCurrentPlayer = "get_current_player.cdc"
)

func GenerateGetFastBreakScript(env Environment) []byte {
code := assets.MustAssetString(fastBreakScriptsPath + getFastBreakByIdFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateGetFastBreakTokenCountScript(env Environment) []byte {
code := assets.MustAssetString(fastBreakScriptsPath + getFastBreakTokenCountFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateGetPlayerScoreScript(env Environment) []byte {
code := assets.MustAssetString(fastBreakScriptsPath + getScoreByPlayerFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateGetFastBreakStatsScript(env Environment) []byte {
code := assets.MustAssetString(fastBreakScriptsPath + getFastBreakStatsFilename)

return []byte(replaceAddresses(code, env))
}

func GenerateCurrentPlayerScript(env Environment) []byte {
code := assets.MustAssetString(fastBreakScriptsPath + fastBreakCurrentPlayer)

return []byte(replaceAddresses(code, env))
}
22 changes: 22 additions & 0 deletions lib/go/templates/fastbreak_user_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package templates

import (
"github.com/dapperlabs/nba-smart-contracts/lib/go/templates/internal/assets"
)

const (
fastBreakSetupGameFilename = "fastbreak/player/create_player.cdc"
fastBreakPlayFilename = "fastbreak/player/play.cdc"
)

func GenerateFastBreakCreateAccountScript(env Environment) []byte {
code := assets.MustAssetString(transactionsPath + fastBreakSetupGameFilename)

return []byte(replaceAddresses(code, env))
}

func GeneratePlayFastBreakScript(env Environment) []byte {
code := assets.MustAssetString(transactionsPath + fastBreakPlayFilename)

return []byte(replaceAddresses(code, env))
}
490 changes: 387 additions & 103 deletions lib/go/templates/internal/assets/assets.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions lib/go/templates/template_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
placeholderForwardingAddress = "0xFORWARDINGADDRESS"
placeholderMetadataViewsAddress = "0xMETADATAVIEWSADDRESS"
placeholderTopShotLockingAddress = "0xTOPSHOTLOCKINGADDRESS"
placeholderFastBreakAddress = "0xFASTBREAKADDRESS"
)

type Environment struct {
Expand All @@ -33,6 +34,7 @@ type Environment struct {
TopShotMarketAddress string
TopShotMarketV3Address string
ShardedAddress string
FastBreakAddress string
AdminReceiverAddress string
DUCAddress string
ForwardingAddress string
Expand Down Expand Up @@ -135,5 +137,11 @@ func replaceAddresses(code string, env Environment) string {
withHexPrefix(env.TopShotLockingAddress),
)

code = strings.ReplaceAll(
code,
placeholderFastBreakAddress,
withHexPrefix(env.FastBreakAddress),
)

return code
}
Loading
Loading