Skip to content

Commit

Permalink
update metadata views and test on testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Aug 9, 2024
1 parent 4ae6f83 commit f148c4b
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ so they can build a basic understanding of the programming language.
| ------------- | -------------------- |
| Previewnet | Coming Soon |
| Testnet | [`0x4516677f8083d680`](https://contractbrowser.com/A.4516677f8083d680.USDCFlow) |
| Mainnet | Coming Soon |
| Mainnet | [`0xf1ab99c82dee3526`]() |

This is the contract that defines the Cadence version of Flow USDC.
Before the Sept 4th Crescendo migration, users can send
Expand Down
28 changes: 23 additions & 5 deletions contracts/USDCFlow.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ pub contract USDCFlow: FungibleToken {
return FungibleTokenMetadataViews.FTDisplay(
name: "USDC (Flow)",
symbol: "USDCf",
description: "This fungible token representation of USDC is bridged from Flow EVM.",
externalURL: MetadataViews.ExternalURL("https://www.circle.com/en/usdc"),
description: "This fungible token representation of Axelar USDC is bridged from Flow EVM.",
externalURL: MetadataViews.ExternalURL("https://docs.axelar.dev/learn/axlusdc"),
logos: medias,
socials: {
"x": MetadataViews.ExternalURL("https://x.com/circle")
}
socials: {},
)
case Type<FungibleTokenMetadataViews.FTVaultData>():
return FungibleTokenMetadataViews.FTVaultData(
Expand Down Expand Up @@ -179,6 +177,26 @@ pub contract USDCFlow: FungibleToken {
self.VaultPublicPath = /public/usdcFlowMetadata
self.ReceiverPublicPath = /public/usdcFlowReceiver

// Create a new FiatToken Vault and put it in storage
self.account.save(
<-FiatToken.createEmptyVault(),
to: FiatToken.VaultStoragePath
)

// Create FiatToken Vault Capabilities
self.account.link<&FiatToken.Vault{FungibleToken.Receiver}>(
FiatToken.VaultReceiverPubPath,
target: FiatToken.VaultStoragePath
)
self.account.link<&FiatToken.Vault{FiatToken.ResourceId}>(
FiatToken.VaultUUIDPubPath,
target: FiatToken.VaultStoragePath
)
self.account.link<&FiatToken.Vault{FungibleToken.Balance}>(
FiatToken.VaultBalancePubPath,
target: FiatToken.VaultStoragePath
)

// Create the Vault with the total supply of tokens and save it in storage.
let vault <- create Vault(balance: self.totalSupply)
self.account.save(<-vault, to: self.VaultStoragePath)
Expand Down
13 changes: 12 additions & 1 deletion contracts/utility/FiatToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub contract FiatToken: FungibleToken {
pub let VaultStoragePath: StoragePath
pub let VaultBalancePubPath: PublicPath
pub let VaultReceiverPubPath: PublicPath
pub let VaultUUIDPubPath: PublicPath
pub let MinterStoragePath: StoragePath

pub var totalSupply: UFix64
Expand All @@ -24,12 +25,20 @@ pub contract FiatToken: FungibleToken {

/// ------- FiatToken Resources -------
pub resource Vault: FungibleToken.Provider,
pub resource interface ResourceId {
pub fun UUID(): UInt64
}

pub resource Vault: ResourceId, FungibleToken.Provider,
FungibleToken.Receiver,
FungibleToken.Balance {

pub var balance: UFix64

pub fun UUID(): UInt64 {
return self.uuid
}

/// getSupportedVaultTypes optionally returns a list of vault types that this receiver accepts
pub fun getSupportedVaultTypes(): {Type: Bool} {
let supportedTypes: {Type: Bool} = {}
Expand Down Expand Up @@ -78,6 +87,7 @@ pub contract FiatToken: FungibleToken {
VaultStoragePath: StoragePath,
VaultBalancePubPath: PublicPath,
VaultReceiverPubPath: PublicPath,
VaultUUIDPubPath: PublicPath,
MinterStoragePath: StoragePath,
initTotalSupply: UFix64,
) {
Expand All @@ -87,6 +97,7 @@ pub contract FiatToken: FungibleToken {
self.VaultStoragePath = VaultStoragePath
self.VaultBalancePubPath = VaultBalancePubPath
self.VaultReceiverPubPath = VaultReceiverPubPath
self.VaultUUIDPubPath = VaultUUIDPubPath

self.MinterStoragePath = MinterStoragePath

Expand Down
27 changes: 25 additions & 2 deletions flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@
"USDCFlow": {
"source": "./contracts/USDCFlow.cdc",
"aliases": {
"testing": "0000000000000007",
"testnet": "4516677f8083d680"
"mainnet": "f1ab99c82dee3526",
"testing": "0000000000000008",
"testnet": "4516677f8083d680"
}
},
"USDCFlowMinterToBridge": {
Expand All @@ -118,6 +119,28 @@
"address": "f8d6e0586b0a20c7",
"key": "758abfd76ad82071cbeeb309f251eeefbe9bb8442557de745769a6ff0a912636"
},
"mainnet-test": {
"address": "93a83fa73bc253ce",
"key": {
"type": "file",
"location": "./mainnet-test.pkey"
}
},
"mainnet-usdc-josh": {
"address": "f1ab99c82dee3526",
"key": {
"type": "google-kms",
"hashAlgorithm": "SHA2_256",
"resourceID": "projects/dl-flow-admin/locations/global/keyRings/flow-usdc/cryptoKeys/flow-usdc-mainnet/cryptoKeyVersions/1"
}
},
"testnet-test": {
"address": "85639e2129d50be5",
"key": {
"type": "file",
"location": "testnet-test.pkey"
}
},
"testnet-usdc": {
"address": "4516677f8083d680",
"key": {
Expand Down
42 changes: 42 additions & 0 deletions tests/transactions/create_fiattoken_vault.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

import "FungibleToken"
import "FiatToken"

transaction() {

prepare(signer: AuthAccount) {

// Return early if the account already stores a FiatToken Vault
if signer.borrow<&FiatToken.Vault>(from: FiatToken.VaultStoragePath) != nil {
return
}

// Create a new ExampleToken Vault and put it in storage
signer.save(
<-FiatToken.createEmptyVault(),
to: FiatToken.VaultStoragePath
)

// Create a public capability to the Vault that only exposes
// the deposit function through the Receiver interface
signer.link<&FiatToken.Vault{FungibleToken.Receiver}>(
FiatToken.VaultReceiverPubPath,
target: FiatToken.VaultStoragePath
)

// Create a public capability to the Vault that only exposes
// the UUID() function through the VaultUUID interface
signer.link<&FiatToken.Vault{FiatToken.ResourceId}>(
FiatToken.VaultUUIDPubPath,
target: FiatToken.VaultStoragePath
)

// Create a public capability to the Vault that only exposes
// the balance field through the Balance interface
signer.link<&FiatToken.Vault{FungibleToken.Balance}>(
FiatToken.VaultBalancePubPath,
target: FiatToken.VaultStoragePath
)

}
}
20 changes: 17 additions & 3 deletions tests/wrapped_fiattoken_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import "USDCFlow"
import "FiatToken"

access(all) let admin = Test.getAccount(0x0000000000000007)
access(all) let usdcFlowContractAccount = Test.getAccount(0x0000000000000008)
access(all) let recipient = Test.createAccount()

access(all) let VaultStoragePath = StoragePath(identifier: "USDCVault")!
access(all) let VaultBalancePubPath = PublicPath(identifier: "USDCVaultBalance")!
access(all) let VaultReceiverPubPath = PublicPath(identifier: "USDCVaultReceiver")!
access(all) let VaultUUIDPubPath = PublicPath(identifier: "USDCVaultUUID")!
access(all) let MinterStoragePath = StoragePath(identifier: "USDCMinter")!
access(all) let initTotalSupply = 1000.0

Expand Down Expand Up @@ -42,6 +44,7 @@ fun setup() {
VaultStoragePath,
VaultBalancePubPath,
VaultReceiverPubPath,
VaultUUIDPubPath,
MinterStoragePath,
initTotalSupply
]
Expand Down Expand Up @@ -101,6 +104,8 @@ fun testWrapTokens() {
[]
)
Test.expect(scriptResult, Test.beSucceeded())
var totalSupply = scriptResult.returnValue! as! UFix64
Test.assertEqual(250.0, totalSupply)

// FiatToken supply should not have decreased
scriptResult = _executeScript(
Expand All @@ -109,17 +114,26 @@ fun testWrapTokens() {
)
Test.expect(scriptResult, Test.beSucceeded())

let totalSupply = scriptResult.returnValue! as! UFix64
totalSupply = scriptResult.returnValue! as! UFix64
Test.assertEqual(1000.0, totalSupply)

// Verify the senders old FiatToken balance
// Verify the senders old FiatToken balance was decreased by the amount wrapped
scriptResult = _executeScript(
"scripts/get_fiattoken_balance.cdc",
[admin.address]
)
Test.expect(scriptResult, Test.beSucceeded())
var balance = scriptResult.returnValue! as! UFix64
Test.assertEqual(1000.0, balance)
Test.assertEqual(750.0, balance)

// Verify the USDCFlow old FiatToken balance was increased by the amount minted
scriptResult = _executeScript(
"scripts/get_fiattoken_balance.cdc",
[usdcFlowContractAccount.address]
)
Test.expect(scriptResult, Test.beSucceeded())
balance = scriptResult.returnValue! as! UFix64
Test.assertEqual(250.0, balance)
}

access(all)
Expand Down

0 comments on commit f148c4b

Please sign in to comment.