Skip to content

Commit

Permalink
instant mint burn
Browse files Browse the repository at this point in the history
  • Loading branch information
saadtroon committed Jan 31, 2022
2 parents 32c4b7d + 128f438 commit 9103b57
Show file tree
Hide file tree
Showing 23 changed files with 112 additions and 117 deletions.
13 changes: 6 additions & 7 deletions Cadence/contracts/Controller.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import FungibleToken from 0xee82856bf20e2aa6

pub contract Controller {

pub var allSocialTokens : {String:TokenStructure}
pub var allArtist : {Address:Artist}
pub var allSocialTokens : {String: TokenStructure}
pub var allArtist : {Address: Artist}

pub event TokenRegistered(_ tokenId:String, _ maxSupply: UFix64, _ artist: Address)
pub event TokenRegistered(_ tokenId: String, _ maxSupply: UFix64, _ artist: Address)

pub var AdminResourceStoragePath: StoragePath

Expand Down Expand Up @@ -36,13 +36,13 @@ pub contract Controller {
self.tokenResourcePublicPath = tokenPublicPath
}

pub fun incrementIssuedSupply(_ amount: UFix64){
access(account) fun incrementIssuedSupply(_ amount: UFix64){
pre{
self.issuedSupply + amount <= self.maxSupply : "max supply reached"
}
self.issuedSupply = self.issuedSupply + amount
}
pub fun setFeeSpliterDetail(_ feeSplitterDetail:{Address: FeeStructure}){
access(account) fun setFeeSpliterDetail(_ feeSplitterDetail:{Address: FeeStructure}){
pre {
}
self.feeSplitterDetail = feeSplitterDetail
Expand All @@ -57,7 +57,7 @@ pub contract Controller {
self.address = address
self.tokenIds = []
}
pub fun addToken(_ tokenId: String){
access(account) fun addToken(_ tokenId: String){
pre {
self.tokenIds.contains(tokenId)==false:"Token already added"
}
Expand Down Expand Up @@ -92,7 +92,6 @@ pub contract Controller {
}
let artistAddress = artist

//let tokenId = (artistAddress.toString().concat("_")).concat(symbol)
let tokenId = (symbol.concat("_")).concat(artistAddress.toString())
assert(Controller.allSocialTokens[tokenId]==nil, message: "token already registered")
Controller.allSocialTokens[tokenId] = Controller.TokenStructure(tokenId, symbol, maxSupply, artistAddress, tokenStoragePath, tokenPublicPath)
Expand Down
5 changes: 3 additions & 2 deletions Cadence/contracts/SocialToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub contract SocialToken : FungibleToken{
pub event TokensInitialized(initialSupply: UFix64)
pub event TokensWithdrawn(amount: UFix64, from: Address?)
pub event TokensDeposited(amount: UFix64, to: Address?)
pub event TokenIdSeted(_ tokenId: String)

pub var collateralPool: FUSDPool
pub resource interface SocialTokenPublic{
Expand All @@ -31,6 +32,7 @@ pub contract SocialToken : FungibleToken{
tokenId !=nil: "token id must not be nil"
}
self.tokenId = tokenId
emit TokenIdSeted(tokenId)
}
pub fun getTokenId(): String{
return self.tokenId
Expand Down Expand Up @@ -90,7 +92,6 @@ pub contract SocialToken : FungibleToken{
access(contract) fun distributeFee(_ tokenId : String, _ fusdPayment: @FungibleToken.Vault): @FungibleToken.Vault{
let amount = fusdPayment.balance
for address in Controller.allSocialTokens[tokenId]!.feeSplitterDetail.keys {
log(address)
let feeStructer = Controller.allSocialTokens[tokenId]!.feeSplitterDetail[address]

let tempAmmount = amount * feeStructer!.percentage
Expand All @@ -101,7 +102,7 @@ pub contract SocialToken : FungibleToken{
let depositSigner= account.getCapability<&FUSD.Vault{FungibleToken.Receiver}>(/public/fusdReceiver)
.borrow()
??panic("could not borrow")

depositSigner.deposit(from:<- tempraryVault)
}
return <- fusdPayment
Expand Down
23 changes: 13 additions & 10 deletions Cadence/tasks/mint_burn_instant/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ func main() {

//Setup FUSD Vaults for all accounts
log.Printf(" ------")
flow.TransactionFromFile("setup_fusd_vault").SignProposeAndPayAs("first").RunPrintEventsFull()
flow.TransactionFromFile("fusd/setup_fusd_vault").SignProposeAndPayAs("account").RunPrintEventsFull()
flow.TransactionFromFile("fusd/setup_fusd_vault").SignProposeAndPayAs("second").RunPrintEventsFull() // Artist Vault
flow.TransactionFromFile("setupFusdVault").SignProposeAndPayAs("first").RunPrintEventsFull()
log.Printf(" ---")

flow.TransactionFromFile("setupFusdVault").SignProposeAndPayAs("account").RunPrintEventsFull()
log.Printf(" ---")

flow.TransactionFromFile("setupFusdVault").SignProposeAndPayAs("second").RunPrintEventsFull() // Artist Vault

//First Account sets up FUSD Minter
flow.TransactionFromFile("fusd/setup_fusd_minter").SignProposeAndPayAs("first").RunPrintEventsFull()
flow.TransactionFromFile("setup_fusd_minter").SignProposeAndPayAs("first").RunPrintEventsFull()

//Admin Account deposits minter into first account
flow.TransactionFromFile("fusd/deposit_fusd_minter").SignProposeAndPayAs("account").AccountArgument("first").RunPrintEventsFull()
flow.TransactionFromFile("setMinterProxy").SignProposeAndPayAs("account").AccountArgument("first").RunPrintEventsFull()

// First Account Mints and deposits in one transaction
flow.TransactionFromFile("fusd/mint_fusd").SignProposeAndPayAs("first").UFix64Argument("10000000.00").AccountArgument("first").RunPrintEventsFull()
flow.TransactionFromFile("mint_fusd").SignProposeAndPayAs("first").UFix64Argument("10000000.00").AccountArgument("first").RunPrintEventsFull()

//Log balance
fusdFirstAccountBalance := flow.ScriptFromFile("get_fusd_balance").AccountArgument("first").RunFailOnError()
Expand All @@ -42,26 +45,26 @@ func main() {
//-------------------------------------------------//

//Register Token for a new account
flow.TransactionFromFile("controller/registerToken").SignProposeAndPayAs("account").UFix64Argument("10000000.00").AccountArgument("first").StringArgument("TestSymbol").RunPrintEventsFull()
flow.TransactionFromFile("registerToken").SignProposeAndPayAs("account").StringArgument("TestSymbol").UFix64Argument("10000000.00").AccountArgument("first").RunPrintEventsFull()

//-------------------------------------------------//
//--------- SETUP AND MINT SOCIAL TOKEN -----------//
//-------------------------------------------------//

//Setup SocialToken Vaults for both accounts
flow.TransactionFromFile("social_token/setup_social_vault").SignProposeAndPayAs("first").RunPrintEventsFull()
flow.TransactionFromFile("setup_social_vault").SignProposeAndPayAs("first").RunPrintEventsFull()
//flow.TransactionFromFile("social_token/setup_social_vault").SignProposeAndPayAs("account").RunPrintEventsFull()

//First Account sets up Social Minter
flow.TransactionFromFile("social_token/setup_social_minter").StringArgument("TestSymbol_0x1cf0e2f2f715450").SignProposeAndPayAs("first").RunPrintEventsFull()
flow.TransactionFromFile("setup_social_minter").StringArgument("TestSymbol_0x1cf0e2f2f715450").SignProposeAndPayAs("first").RunPrintEventsFull()

//Admin Account deposits minter into first account
// flow.TransactionFromFile("social_token/deposit_social_minter").SignProposeAndPayAs("account").AccountArgument("first").RunPrintEventsFull()
mintQuote := flow.ScriptFromFile("getTokenDetails").StringArgument("TestSymbol_0x1cf0e2f2f715450").RunFailOnError()
log.Printf(" ------ Social Token Details ----- %s", mintQuote)

// mint social Tokens
flow.TransactionFromFile("social_token/mint_social_token").SignProposeAndPayAs("first").UFix64Argument("10000000.00").UFix64Argument("10000000.00").RunPrintEventsFull()
flow.TransactionFromFile("mint_social_token").SignProposeAndPayAs("first").UFix64Argument("10000000.00").UFix64Argument("10000000.00").RunPrintEventsFull()

//Log balance
fusdFirstAccountBalance = flow.ScriptFromFile("get_fusd_balance").AccountArgument("first").RunFailOnError()
Expand Down
160 changes: 77 additions & 83 deletions flow.json
Original file line number Diff line number Diff line change
@@ -1,89 +1,83 @@
{
"emulators": {
"default": {
"port": 3569,
"serviceAccount": "emulator-account"
}
},
"contracts": {
"Debug": "./Cadence/contracts/Debug.cdc",
"FungibleToken": {
"source": "./Cadence/contracts/FungibleToken.cdc",
"aliases": {
"emulator": "0xee82856bf20e2aa6"
}
},
"FUSD": {
"source": "./Cadence/contracts/FUSD.cdc",
"aliases": {
"emulator": "0x179b6b1cb6755e31"
}
},

"emulators": {
"default": {
"port": 3569,
"serviceAccount": "emulator-account"
}
},
"contracts": {
"Debug": "./Cadence/contracts/Debug.cdc",
"SocialToken": {
"source": "./Cadence/contracts/SocialToken.cdc",
"aliases": {
"emulator": "0x0ae53cb6e3f42a79",
"testnet": "0x7e60df042a9c0868"
}
},
"FungibleToken": {
"source": "./Cadence/contracts/FungibleToken.cdc",
"aliases": {
"emulator": "0xee82856bf20e2aa6",
"testnet": "0x9a0766d93b6608b7"
}
},
"FUSD": {
"source": "./Cadence/contracts/FUSD.cdc",
"aliases": {
"emulator": "0x0ae53cb6e3f42a79",
"testnet": "0x7e60df042a9c0868"
}
},
"Controller": {
"source": "./Cadence/contracts/Controller.cdc",
"aliases": {
"emulator": "0xf3fcd2c1a78f5eee"
}
},
"SocialToken": {
"source": "./Cadence/contracts/SocialToken.cdc",
"aliases": {
"emulator": "0xe03daebed8ca0615"
}
}
},
"networks": {
"emulator": "127.0.0.1:3569",
"mainnet": "access.mainnet.nodes.onflow.org:9000",
"testnet": "access.devnet.nodes.onflow.org:9000"
},
"accounts": {
"emulator-account": {
"address": "f8d6e0586b0a20c7",
"key": "dc0097a6b58533e56af78c955e7b0c0f386b5f44f22b75c390beab7fcb1af13f"
},
"emulator-first": {
"address": "0x01cf0e2f2f715450",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
},
"emulator-second": {
"address": "0x179b6b1cb6755e31",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
},
"emulator-third": {
"address": "0xf3fcd2c1a78f5eee",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
},
"0x04": {
"address": "0xe03daebed8ca0615",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
},
"0x05": {
"address": "0x045a1763c93006ca",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
},
"0x06": {
"address": "0x120e725050340cab",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
},
"0x07": {
"address": "0xf669cb8d41ce0c74",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
},
"0x08": {
"address": "0x192440c99cb17282",
"key": "fd4dbe7da1b2c53c3b81785dbb1911e4fb04815e2154713e04ea6eb47a97c651"
}
},
"deployments": {
"emulator": {
"emulator-account": [
"source": "./Cadence/contracts/Controller.cdc",
"aliases": {
"emulator": "0x0ae53cb6e3f42a79",
"testnet": "0x7e60df042a9c0868"
}
}
},
"networks": {
"emulator": "127.0.0.1:3569",
"mainnet": "access.mainnet.nodes.onflow.org:9000",
"testnet": "access.devnet.nodes.onflow.org:9000"
},
"accounts": {
"emulator-account": {
"address": "f8d6e0586b0a20c7",
"key": "dc0097a6b58533e56af78c955e7b0c0f386b5f44f22b75c390beab7fcb1af13f"
},
"emulator-first": {
"address": "01cf0e2f2f715450",
"key": "d5457a187e9642a8e49d4032b3b4f85c92da7202c79681d9302c6e444e7033a8"
},
"emulator-second": {
"address": "179b6b1cb6755e31",
"key": "d5457a187e9642a8e49d4032b3b4f85c92da7202c79681d9302c6e444e7033a8"
},
"emulator-3": {
"address": "f3fcd2c1a78f5eee",
"key": "d5457a187e9642a8e49d4032b3b4f85c92da7202c79681d9302c6e444e7033a8"
},
"emulator-4": {
"address": "e03daebed8ca0615",
"key": "d5457a187e9642a8e49d4032b3b4f85c92da7202c79681d9302c6e444e7033a8"
},
"emulator-5": {
"address": "045a1763c93006ca",
"key": "d5457a187e9642a8e49d4032b3b4f85c92da7202c79681d9302c6e444e7033a8"
}
},
"deployments": {
"emulator": {
"emulator-account": [
"FungibleToken",
"FUSD",
"Controller",
"SocialToken"

]
}
}
}
],
"emulator-first": [],
"emulator-second": []
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// To check if an account has a vault or initialize a new vault,
// use check_fusd_vault_setup.cdc and setup_fusd_vault.cdc respectively.
import FungibleToken from 0xee82856bf20e2aa6
import FUSD from "../contracts/FUSD.cdc"
import FUSD from 0xf8d6e0586b0a20c7
pub fun main(address: Address): UFix64 {
let account = getAccount(address)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion transactions/mint_fusd.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// or initialize a new vault, use check_fusd_vault_setup.cdc and setup_fusd_vault.cdc
// respectively.
import FungibleToken from 0xee82856bf20e2aa6
import FUSD from "../contracts/FUSD.cdc"
import FUSD from 0xf8d6e0586b0a20c7

transaction(amount: UFix64, to: Address) {

Expand Down
9 changes: 4 additions & 5 deletions transactions/registerToken.cdc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import FungibleToken from "../contracts/FungibleToken.cdc"
import SocialToken from "../contracts/SocialToken.cdc"
import Controller from "../contracts/Controller.cdc"
import FUSD from "../contracts/FUSD.cdc"

import FUSD from 0xf8d6e0586b0a20c7
import SocialToken from 0xf8d6e0586b0a20c7
import FungibleToken from 0xee82856bf20e2aa6
import Controller from 0xf8d6e0586b0a20c7

transaction (symbol: String, maxSupply: UFix64, artistAddress: Address){
prepare(acct: AuthAccount) {
Expand Down
3 changes: 1 addition & 2 deletions transactions/setMinterProxy.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
// an FUSD.MinterProxy resource. Use the setup_fusd_minter.cdc transaction to
// create a minter proxy in the minter account.
import FUSD from "../contracts/FUSD.cdc"

import FUSD from 0xf8d6e0586b0a20c7

transaction(minterAddress: Address) {

Expand Down
2 changes: 1 addition & 1 deletion transactions/setupFusdVault.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// - FungibleToken.Receiver: this capability allows this account to accept FUSD deposits.
// - FungibleToken.Balance: this capability allows anybody to inspect the FUSD balance of this account.
import FungibleToken from 0xee82856bf20e2aa6
import FUSD from "./../contracts/FUSD.cdc"
import FUSD from 0xf8d6e0586b0a20c7


transaction {
Expand Down
2 changes: 1 addition & 1 deletion transactions/setup_fusd_minter.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// must run deposit_fusd_minter.cdc to deposit a minter resource
// inside the minter proxy.
import FUSD from "../contracts/FUSD.cdc"
import FUSD from 0xf8d6e0586b0a20c7


transaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ transaction () {
prepare(acct: AuthAccount) {

acct.save(<- SocialToken.createEmptyVault(), to: /storage/S_0x5)
acct.save(<- SocialToken.createNewMinter(), to: /storage/SMinter)
acct.save(<- SocialToken.createNewBurner(), to: /storage/SBurner)
acct.link<&SocialToken.Burner{SocialToken.BurnerPublic}>(/public/SBurner, target: /storage/SBurner)
acct.link<& SocialToken.Minter{SocialToken.MinterPublic}>(/public/SMinter, target: /storage/SMinter)
acct.save(<- SocialToken.createNewMinter(), to: /storage/Minter)
acct.save(<- SocialToken.createNewBurner(), to: /storage/RBurner)
acct.link<&SocialToken.Burner{SocialToken.BurnerPublic}>(/public/RBurner, target: /storage/RBurner)
acct.link<& SocialToken.Minter{SocialToken.MinterPublic}>(/public/Minter, target: /storage/Minter)
acct.link<&SocialToken.Vault{FungibleToken.Balance,SocialToken.SocialTokenPublic, FungibleToken.Receiver}>
(/public/S_0x5,
target: /storage/S_0x5)
Expand Down

0 comments on commit 9103b57

Please sign in to comment.