Skip to content

Commit

Permalink
Merge pull request #149 from onflow/sisyphusSmiling/v2-standard-update
Browse files Browse the repository at this point in the history
Update repo contents for Cadence 1.0
  • Loading branch information
sisyphusSmiling authored Nov 7, 2023
2 parents c1363b4 + b2edf2f commit a2f4f3b
Show file tree
Hide file tree
Showing 63 changed files with 4,242 additions and 2,061 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI

on: [push]
on:
- push
- pull_request

jobs:
build:
Expand All @@ -9,15 +11,15 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.18.x'
go-version: '1.19.x'
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.3.1
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.5.0-stable-cadence.3
- name: Flow CLI Version
run: flow version
- name: Update PATH
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
lib/js/test/node_modules/*
node_modules/*
.env
.env
coverage.lcov
coverage.json
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
test:
$(MAKE) generate -C lib/go
$(MAKE) test -C lib/go
flow test --cover tests/*.cdc
flow test --cover --covercode="contracts" tests/*.cdc

.PHONY: ci
ci:
$(MAKE) ci -C lib/go
flow test --cover tests/*.cdc
flow test --cover --covercode="contracts" tests/*.cdc
47 changes: 38 additions & 9 deletions contracts/ExampleToken-v2.cdc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import FungibleToken from "FungibleToken"
import MetadataViews from "MetadataViews"
import FungibleTokenMetadataViews from "FungibleTokenMetadataViews"
import MultipleVaults from "MultipleVaults"
import ViewResolver from "ViewResolver"

access(all) contract ExampleToken: ViewResolver {
Expand All @@ -18,6 +17,7 @@ access(all) contract ExampleToken: ViewResolver {
/// User Paths
access(all) let VaultStoragePath: StoragePath
access(all) let VaultPublicPath: PublicPath
access(all) let ReceiverPublicPath: PublicPath

/// Function to return the types that the contract implements
access(all) view fun getVaultTypes(): [Type] {
Expand Down Expand Up @@ -58,6 +58,7 @@ access(all) contract ExampleToken: ViewResolver {

access(self) var storagePath: StoragePath
access(self) var publicPath: PublicPath
access(self) var receiverPath: PublicPath

/// Returns the storage path where the vault should typically be stored
access(all) view fun getDefaultStoragePath(): StoragePath? {
Expand All @@ -69,11 +70,18 @@ access(all) contract ExampleToken: ViewResolver {
return self.publicPath
}

/// Returns the public path where this vault's Receiver should have a public capability
access(all) view fun getDefaultReceiverPath(): PublicPath? {
return self.receiverPath
}

access(all) view fun getViews(): [Type] {
return [Type<FungibleTokenMetadataViews.FTView>(),
Type<FungibleTokenMetadataViews.FTDisplay>(),
Type<FungibleTokenMetadataViews.FTVaultData>(),
Type<FungibleTokenMetadataViews.TotalSupply>()]
return [
Type<FungibleTokenMetadataViews.FTView>(),
Type<FungibleTokenMetadataViews.FTDisplay>(),
Type<FungibleTokenMetadataViews.FTVaultData>(),
Type<FungibleTokenMetadataViews.TotalSupply>()
]
}

access(all) fun resolveView(_ view: Type): AnyStruct? {
Expand Down Expand Up @@ -106,16 +114,20 @@ access(all) contract ExampleToken: ViewResolver {
?? panic("Could not borrow a reference to the stored vault")
return FungibleTokenMetadataViews.FTVaultData(
storagePath: self.storagePath,
receiverPath: self.publicPath,
receiverPath: self.receiverPath,
metadataPath: self.publicPath,
providerPath: /private/exampleTokenVault,
receiverLinkedType: Type<&ExampleToken.Vault>(),
receiverLinkedType: Type<&{FungibleToken.Receiver}>(),
metadataLinkedType: Type<&ExampleToken.Vault>(),
providerLinkedType: Type<&ExampleToken.Vault>(),
createEmptyVaultFunction: (fun(): @{FungibleToken.Vault} {
return <-vaultRef.createEmptyVault()
})
)
case Type<FungibleTokenMetadataViews.TotalSupply>():
return FungibleTokenMetadataViews.TotalSupply(
totalSupply: ExampleToken.totalSupply
)
}
return nil
}
Expand All @@ -137,6 +149,7 @@ access(all) contract ExampleToken: ViewResolver {
let identifier = "exampleTokenVault"
self.storagePath = StoragePath(identifier: identifier)!
self.publicPath = PublicPath(identifier: identifier)!
self.receiverPath = PublicPath(identifier: "exampleTokenReceiver")!
}

/// Get the balance of the vault
Expand Down Expand Up @@ -197,6 +210,8 @@ access(all) contract ExampleToken: ViewResolver {
return <-create Vault(balance: 0.0)
}

// TODO: Revisit if removal of custom destructors passes
// See https://github.com/onflow/flips/pull/131
destroy() {
if self.balance > 0.0 {
ExampleToken.totalSupply = ExampleToken.totalSupply - self.balance
Expand Down Expand Up @@ -232,6 +247,17 @@ access(all) contract ExampleToken: ViewResolver {
return <- create Vault(balance: 0.0)
}

/// Function that destroys a Vault instance, effectively burning the tokens.
///
/// @param from: The Vault resource containing the tokens to burn
///
// TODO: Revisit if removal of custom destructors passes
// Will need to add an update to total supply
// See https://github.com/onflow/flips/pull/131
access(all) fun burnTokens(from: @ExampleToken.Vault) {
destroy from
}

init() {
self.totalSupply = 1000.0

Expand All @@ -242,17 +268,20 @@ access(all) contract ExampleToken: ViewResolver {
let vault <- create Vault(balance: self.totalSupply)
self.VaultStoragePath = vault.getDefaultStoragePath()!
self.VaultPublicPath = vault.getDefaultPublicPath()!
self.ReceiverPublicPath = vault.getDefaultReceiverPath()!

self.account.storage.save(<-vault, to: self.VaultStoragePath)

// Create a public capability to the stored Vault that exposes
// the `deposit` method and getAcceptedTypes method through the `Receiver` interface
// and the `getBalance()` method through the `Balance` interface
//
let exampleTokenCap = self.account.capabilities.storage.issue<&ExampleToken>(self.VaultStoragePath)
let exampleTokenCap = self.account.capabilities.storage.issue<&Vault>(self.VaultStoragePath)
self.account.capabilities.publish(exampleTokenCap, at: self.VaultPublicPath)
let receiverCap = self.account.capabilities.storage.issue<&{FungibleToken.Receiver}>(self.VaultStoragePath)
self.account.capabilities.publish(receiverCap, at: self.ReceiverPublicPath)

let admin <- create Minter()
self.account.storage.save(<-admin, to: self.AdminStoragePath)
}
}

6 changes: 3 additions & 3 deletions contracts/ExampleToken.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FungibleToken from "FungibleToken"
import MetadataViews from "MetadataViews"
import FungibleTokenMetadataViews from "FungibleTokenMetadataViews"
import "FungibleToken"
import "MetadataViews"
import "FungibleTokenMetadataViews"

access(all) contract ExampleToken: FungibleToken {

Expand Down
25 changes: 16 additions & 9 deletions contracts/FungibleToken-v2.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ access(all) contract FungibleToken {
///
access(all) fun deposit(from: @{Vault})

// /// getSupportedVaultTypes optionally returns a list of vault types that this receiver accepts
// access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
// pre { true: "dummy" }
// }
/// getSupportedVaultTypes optionally returns a list of vault types that this receiver accepts
access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
pre { true: "dummy" }
}

// /// Returns whether or not the given type is accepted by the Receiver
// /// A vault that can accept any type should just return true by default
// access(all) view fun isSupportedVaultType(type: Type): Bool {
// pre { true: "dummy" }
// }
/// Returns whether or not the given type is accepted by the Receiver
/// A vault that can accept any type should just return true by default
access(all) view fun isSupportedVaultType(type: Type): Bool {
pre { true: "dummy" }
}
}

access(all) resource interface Transferor {
Expand Down Expand Up @@ -187,6 +187,13 @@ access(all) contract FungibleToken {
return nil
}

/// Returns the public path where this vault's Receiver should have a public capability
/// Publishing a Receiver Capability at a different path enables alternate Receiver implementations to be used
/// in the same canonical namespace as the underlying Vault.
access(all) view fun getDefaultReceiverPath(): PublicPath? {
return nil
}

// access(all) view fun getViews(): [Type] {
// pre { true: "dummy" }
// }
Expand Down
Loading

0 comments on commit a2f4f3b

Please sign in to comment.