Skip to content

Commit 4f80c10

Browse files
authored
Merge pull request #59 from onflow/nialexsan/usdc
usdc contract
2 parents 939a521 + 1e680a2 commit 4f80c10

4 files changed

Lines changed: 160 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import "FungibleToken"
2+
import "USDCFlow"
3+
import "FungibleTokenMetadataViews"
4+
5+
import "FlowEVMBridgeHandlerInterfaces"
6+
7+
/// This transaction is what the minter Account uses to mint new ExampleTokens
8+
/// They provide the recipient address and amount to mint, and the tokens
9+
/// are transferred to the address after minting
10+
11+
transaction(recipient: Address, amount: UFix64) {
12+
13+
/// Reference to the Example Token Minter Resource object
14+
let tokenMinter: auth(FlowEVMBridgeHandlerInterfaces.Mint) &USDCFlow.Minter
15+
16+
/// Reference to the Fungible Token Receiver of the recipient
17+
let tokenReceiver: &{FungibleToken.Receiver}
18+
19+
/// The total supply of tokens before the burn
20+
let supplyBefore: UFix64
21+
22+
prepare(signer: auth(BorrowValue) &Account) {
23+
self.supplyBefore = USDCFlow.totalSupply
24+
25+
// Borrow a reference to the admin object
26+
self.tokenMinter = signer.storage.borrow<auth(FlowEVMBridgeHandlerInterfaces.Mint) &USDCFlow.Minter>(
27+
from: /storage/usdcFlowMinter
28+
) ?? panic("Signer is not the token admin")
29+
30+
let vaultData = USDCFlow.resolveContractView(
31+
resourceType: nil,
32+
viewType: Type<FungibleTokenMetadataViews.FTVaultData>()
33+
) as! FungibleTokenMetadataViews.FTVaultData?
34+
?? panic("Could not get vault data view for the contract")
35+
36+
self.tokenReceiver = getAccount(recipient).capabilities.borrow<&{FungibleToken.Receiver}>(vaultData.receiverPath)
37+
?? panic("Could not borrow receiver reference to the Vault")
38+
}
39+
40+
execute {
41+
42+
// Create mint tokens
43+
let mintedVault <- self.tokenMinter.mint(amount: amount)
44+
45+
// Deposit them to the receiever
46+
self.tokenReceiver.deposit(from: <-mintedVault)
47+
}
48+
49+
post {
50+
USDCFlow.totalSupply == self.supplyBefore + amount: "The total supply must be increased by the amount"
51+
}
52+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This transaction is a template for a transaction to allow
2+
// anyone to add a Vault resource to their account so that
3+
// they can use the exampleToken
4+
5+
import "FungibleToken"
6+
import "USDCFlow"
7+
import "ViewResolver"
8+
import "FungibleTokenMetadataViews"
9+
10+
transaction () {
11+
12+
prepare(signer: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) {
13+
14+
let vaultData = USDCFlow.resolveContractView(
15+
resourceType: nil,
16+
viewType: Type<FungibleTokenMetadataViews.FTVaultData>()
17+
) as! FungibleTokenMetadataViews.FTVaultData?
18+
?? panic("ViewResolver does not resolve FTVaultData view")
19+
20+
// Return early if the account already stores a ExampleToken Vault
21+
if signer.storage.borrow<&USDCFlow.Vault>(from: vaultData.storagePath) != nil {
22+
return
23+
}
24+
25+
let vault <- USDCFlow.createEmptyVault(vaultType: Type<@USDCFlow.Vault>())
26+
27+
// Create a new ExampleToken Vault and put it in storage
28+
signer.storage.save(<-vault, to: vaultData.storagePath)
29+
30+
// Create a public capability to the Vault that exposes the Vault interfaces
31+
let vaultCap = signer.capabilities.storage.issue<&USDCFlow.Vault>(
32+
vaultData.storagePath
33+
)
34+
signer.capabilities.publish(vaultCap, at: vaultData.metadataPath)
35+
36+
// Create a public Capability to the Vault's Receiver functionality
37+
let receiverCap = signer.capabilities.storage.issue<&USDCFlow.Vault>(
38+
vaultData.storagePath
39+
)
40+
signer.capabilities.publish(receiverCap, at: vaultData.receiverPath)
41+
}
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This transaction is a template for a transaction that
2+
// could be used by anyone to send USDCFlows to another
3+
// account that has been set up to receive tokens.
4+
//
5+
// The withdraw amount and the account from getAccount
6+
// would be the parameters to the transaction
7+
8+
import "FungibleToken"
9+
import "USDCFlow"
10+
import "FungibleTokenMetadataViews"
11+
12+
transaction(amount: UFix64, to: Address) {
13+
14+
/// FTVaultData metadata view for the token being used
15+
let vaultData: FungibleTokenMetadataViews.FTVaultData
16+
17+
// The Vault resource that holds the tokens that are being transferred
18+
let sentVault: @{FungibleToken.Vault}
19+
20+
prepare(signer: auth(BorrowValue) &Account) {
21+
22+
self.vaultData = USDCFlow.resolveContractView(
23+
resourceType: nil,
24+
viewType: Type<FungibleTokenMetadataViews.FTVaultData>()
25+
) as! FungibleTokenMetadataViews.FTVaultData?
26+
?? panic("ViewResolver does not resolve FTVaultData view")
27+
28+
// Get a reference to the signer's stored vault
29+
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &USDCFlow.Vault>(from: self.vaultData.storagePath)
30+
?? panic("Could not borrow reference to the owner's Vault!")
31+
32+
// Withdraw tokens from the signer's stored vault
33+
self.sentVault <- vaultRef.withdraw(amount: amount)
34+
}
35+
36+
execute {
37+
38+
// Get the recipient's public account object
39+
let recipient = getAccount(to)
40+
41+
// Get a reference to the recipient's Receiver
42+
let receiverRef = recipient.capabilities.borrow<&{FungibleToken.Receiver}>(self.vaultData.receiverPath)
43+
?? panic("Could not borrow receiver reference to the recipient's Vault")
44+
45+
// Deposit the withdrawn tokens in the recipient's receiver
46+
receiverRef.deposit(from: <-self.sentVault)
47+
}
48+
}

flow.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@
156156
"testnet": "8c5303eaa26202d6"
157157
}
158158
},
159+
"FlowEVMBridgeHandlerInterfaces": {
160+
"source": "mainnet://1e4aa0b87d10b141.FlowEVMBridgeHandlerInterfaces",
161+
"hash": "7e0e28eb8fb30595249384cb8c7a44eae3884700d0a6c3139240c0d19e4dc173",
162+
"aliases": {
163+
"emulator": "f8d6e0586b0a20c7",
164+
"mainnet": "1e4aa0b87d10b141"
165+
}
166+
},
159167
"FlowStorageFees": {
160168
"source": "mainnet://e467b9dd11fa00df.FlowStorageFees",
161169
"hash": "e38d8a95f6518b8ff46ce57dfa37b4b850b3638f33d16333096bc625b6d9b51a",
@@ -258,6 +266,14 @@
258266
"mainnet": "a6850776a94e6551"
259267
}
260268
},
269+
"USDCFlow": {
270+
"source": "mainnet://f1ab99c82dee3526.USDCFlow",
271+
"hash": "221e4f6b0d3cfc61d6baab6c968d962ff019a58e1eff43835daa7e62258c8fc5",
272+
"aliases": {
273+
"emulator": "f8d6e0586b0a20c7",
274+
"mainnet": "f1ab99c82dee3526"
275+
}
276+
},
261277
"ViewResolver": {
262278
"source": "mainnet://1d7e57aa55817448.ViewResolver",
263279
"hash": "374a1994046bac9f6228b4843cb32393ef40554df9bd9907a702d098a2987bde",
@@ -315,6 +331,8 @@
315331
"deployments": {
316332
"emulator": {
317333
"emulator-account": [
334+
"FlowEVMBridgeHandlerInterfaces",
335+
"USDCFlow",
318336
"DeFiActionsMathUtils",
319337
"DeFiActionsUtils",
320338
"DeFiActions",

0 commit comments

Comments
 (0)