Comments (3)
import TokenForwarding from "../contracts/standard/TokenForwarding.cdc"
import FungibleToken from "../contracts/standard/FungibleToken.cdc"
import DapperUtilityCoin from "../contracts/standard/DapperUtilityCoin.cdc"
import FlowUtilityToken from "../contracts/standard/FlowUtilityToken.cdc"
import FungibleTokenSwitchboard from "../contracts/standard/FungibleTokenSwitchboard.cdc"
import FiatToken from "../contracts/standard/FiatToken.cdc"
import FUSD from "../contracts/standard/FUSD.cdc"
import FlowToken from "../contracts/standard/FlowToken.cdc"
/**
This is a transaction to set up an merchant account
It has to be a blocto account since dapper will not allow us to run this account on a merchan account
The only input parameter to this is your merchant account at dapper
// 1. run this transaction in a lilico/blocto account your "credit account"
// 2. use the path = /public/fungibleTokenSwitchboardPublic on this account as royalty receiver, it will be able to handle all the common FT
**/
transaction(dapperMerchantAccountAddress: Address) {
prepare(acct: AuthAccount) {
// Get a Receiver reference for the Dapper account that will be the recipient of the forwarded DUC and FUT
let dapper = getAccount(dapperMerchantAccountAddress)
//FUSD
let fusdReceiver = acct.getCapability<&{FungibleToken.Receiver}>(/public/fusdReceiver)
if !fusdReceiver.check() {
let fusd <- FUSD.createEmptyVault()
acct.save(<- fusd, to: /storage/fusdVault)
acct.link<&FUSD.Vault{FungibleToken.Receiver}>( /public/fusdReceiver, target: /storage/fusdVault)
acct.link<&FUSD.Vault{FungibleToken.Balance}>( /public/fusdBalance, target: /storage/fusdVault)
}
//USDC
let usdcCap = acct.getCapability<&FiatToken.Vault{FungibleToken.Receiver}>(FiatToken.VaultReceiverPubPath)
if !usdcCap.check() {
acct.save( <-FiatToken.createEmptyVault(), to: FiatToken.VaultStoragePath)
acct.link<&FiatToken.Vault{FungibleToken.Receiver}>( FiatToken.VaultReceiverPubPath, target: FiatToken.VaultStoragePath)
acct.link<&FiatToken.Vault{FiatToken.ResourceId}>( FiatToken.VaultUUIDPubPath, target: FiatToken.VaultStoragePath)
acct.link<&FiatToken.Vault{FungibleToken.Balance}>( FiatToken.VaultBalancePubPath, target:FiatToken.VaultStoragePath)
}
//Dapper utility token
let ducReceiver = acct.getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
let dapperDUCReceiver = dapper.getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
if !ducReceiver.check(){
let ducForwarder <- TokenForwarding.createNewForwarder(recipient: dapperDUCReceiver)
acct.save(<-ducForwarder, to: /storage/dapperUtilityCoinReceiver)
acct.link<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver, target: /storage/dapperUtilityCoinReceiver)
}
//FlowUtility token
let futReceiver = acct.getCapability<&{FungibleToken.Receiver}>(/public/flowUtilityTokenReceiver)
let dapperFUTReceiver = dapper.getCapability<&{FungibleToken.Receiver}>(/public/flowUtilityTokenReceiver)
if !futReceiver.check(){
let futForwarder <- TokenForwarding.createNewForwarder(recipient: dapperFUTReceiver)
acct.save(<-futForwarder, to: /storage/flowUtilityTokenReceiver)
acct.link<&{FungibleToken.Receiver}>(/public/flowUtilityTokenReceiver, target: /storage/flowUtilityTokenReceiver)
}
let switchboard <- FungibleTokenSwitchboard.createSwitchboard()
//We add the direct forwarder to the merchant account to the switchboard so that the chain will be
//switchboard --> merchant account forwarder --> dapper
//the alternative would be
//switchboard --> our forwarder --> merchant account forwarder --> dapper
switchboard.addNewVaultWrapper(capability: dapperDUCReceiver, type: Type<@DapperUtilityCoin.Vault>())
switchboard.addNewVaultWrapper(capability: dapperFUTReceiver, type: Type<@FlowUtilityToken.Vault>())
switchboard.addNewVault(capability: usdcCap)
switchboard.addNewVault(capability: fusdReceiver)
switchboard.addNewVault(capability: acct.getCapability<&{FungibleToken.Receiver}>(/public/flowTokenReceiver))
acct.save(<- switchboard, to: FungibleTokenSwitchboard.StoragePath)
acct.link<&FungibleTokenSwitchboard.Switchboard{FungibleToken.Receiver}>( FungibleTokenSwitchboard.ReceiverPublicPath, target: FungibleTokenSwitchboard.StoragePath)
acct.link<&FungibleTokenSwitchboard.Switchboard{FungibleTokenSwitchboard.SwitchboardPublic, FungibleToken.Receiver}>(
FungibleTokenSwitchboard.PublicPath,
target: FungibleTokenSwitchboard.StoragePath
)
}
}
from flow-ft.
I think that transaction looks pretty good. Though we should create another one that links everything besides the dapper coins that others can use for their wallets.
cc @alilloig
from flow-ft.
borrow with type or maybe borrow and type check not better?
let fusdReceiver = acct.getCapability<&FUSD.Vault{FungibleToken.Receiver}>(/public/fusdReceiver)
from flow-ft.
Related Issues (20)
- Adequate comments to docgen tool and include generated docs in repo
- Problems with Switchboard HOT 6
- feat: Allow public Switchboard to be used as FT Receiver HOT 2
- FungibleTokenSwitchboard is not interoperable with TokenForwarding HOT 3
- Check PrivateForwarder transactions and tests HOT 1
- error: cannot deploy invalid contract HOT 4
- safeDeposit and addNewVaultsByPath methods on switchboard are not entirely panic free HOT 6
- Make TokenForwarder and Switchboard target capabilities retrievable
- Update contract import schema HOT 1
- [DOCS] Add documentation for FungibleTokenMetadataViews HOT 2
- Flow CLI: Transaction Error [Error Code: 1101] pre-condition failed: Cannot deposit an incompatible token type HOT 2
- Build FT Metadata Views features
- Add FT Metadata Views to Example Token contract
- DOCS: Update FT documentation to include Metadata Views including examples
- Incorrect attribute when emitting `VaultCapabilityAdded` in FungibleTokenSwitchboard
- Update flow-ft contracts to comply with Stable Cadence changes
- cannot borrowViewResolver for some NFT HOT 2
- Normalize flow.json
- Refactor utilityContracts folder into utility folder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flow-ft.