Skip to content

Commit

Permalink
Merge pull request #108 from blocto/feat/update-scripts
Browse files Browse the repository at this point in the history
feat: update flow scripts for Crescendo
  • Loading branch information
mordochi authored Sep 3, 2024
2 parents 2c58856 + 7b376e6 commit 8ecb73c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 73 deletions.
8 changes: 4 additions & 4 deletions src/components/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ReactJSXElement } from "@emotion/react/types/jsx-namespace";
import { ec as EC } from "elliptic";
import { SHA3 } from "sha3";
import * as types from "@onflow/types";
import * as Campaign from "../scripts/flow/Campaign";
import * as BloctoDAOTemplates from "../scripts/flow/DAO";
// import * as Campaign from "../scripts/flow/Campaign";
// import * as BloctoDAOTemplates from "../scripts/flow/DAO";
import * as SignMessageTemplates from "../scripts/flow/SignMessage";
import * as TransactionsTemplates from "../scripts/flow/Transactions";
import ScriptTypes, { Arg } from "../types/ScriptTypes";
Expand Down Expand Up @@ -107,8 +107,8 @@ function parseFclArgs(args: Arg[] = []) {
}

const MenuGroups = [
{ title: "Campaign", templates: Campaign },
{ title: "DAO", templates: BloctoDAOTemplates },
// { title: "Campaign", templates: Campaign },
// { title: "DAO", templates: BloctoDAOTemplates },
{ title: "Transactions", templates: TransactionsTemplates },
{ title: "Sign Message", templates: SignMessageTemplates },
];
Expand Down
83 changes: 20 additions & 63 deletions src/scripts/flow/Transactions.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import ScriptTypes from "../../types/ScriptTypes";
import getAddress from "../../utils/getAddress";

export const getFUSDBalance = {
type: ScriptTypes.SCRIPT,
script: `
import FungibleToken from ${getAddress("FungibleToken")}
import FUSD from ${getAddress("FUSD")}
pub fun main (address: Address): UFix64 {
let vaultRef = getAccount(address).getCapability(/public/fusdBalance)!.borrow<&AnyResource{FungibleToken.Balance}>()
?? panic("Could not borrow reference to the owner's Vault!")
return vaultRef.balance
}
`,
args: [{ type: "Address", comment: "address" }],
};

export const getBLTBalance = {
type: ScriptTypes.SCRIPT,
script: `
import FungibleToken from ${getAddress("FungibleToken")}
import BloctoToken from ${getAddress("BloctoToken")}
pub fun main (address: Address): UFix64 {
let vaultRef = getAccount(address).getCapability(/public/bloctoTokenBalance)!.borrow<&AnyResource{FungibleToken.Balance}>()
access(all) fun main (address: Address): UFix64 {
let vaultRef = getAccount(address).capabilities.borrow<&{FungibleToken.Balance}>(/public/bloctoTokenBalance)
?? panic("Could not borrow reference to the owner's Vault!")
return vaultRef.balance
}
Expand All @@ -37,8 +22,8 @@ export const getTUSDTBalance = {
import FungibleToken from ${getAddress("FungibleToken")}
import TeleportedTetherToken from ${getAddress("TeleportedTetherToken")}
pub fun main (address: Address): UFix64 {
let vaultRef = getAccount(address).getCapability(TeleportedTetherToken.TokenPublicBalancePath)!.borrow<&AnyResource{FungibleToken.Balance}>()
access(all) fun main (address: Address): UFix64 {
let vaultRef = getAccount(address).capabilities.borrow<&{FungibleToken.Balance}>(TeleportedTetherToken.TokenPublicBalancePath)
?? panic("Could not borrow reference to the owner's Vault!")
return vaultRef.balance
}
Expand All @@ -52,60 +37,32 @@ export const getFlowBalance = {
import FungibleToken from ${getAddress("FungibleToken")}
import FlowToken from ${getAddress("FlowToken")}
pub fun main (address: Address): UFix64 {
let vaultRef = getAccount(address).getCapability(/public/flowTokenBalance)!.borrow<&AnyResource{FungibleToken.Balance}>()
access(all) fun main (address: Address): UFix64 {
let vaultRef = getAccount(address).capabilities.borrow<&{FungibleToken.Balance}>(/public/flowTokenBalance)
?? panic("Could not borrow reference to the owner's Vault!")
return vaultRef.balance
}
`,
args: [{ type: "Address", comment: "address" }],
};

export const sendFUSD = {
type: ScriptTypes.TX,
script: `\
import FungibleToken from ${getAddress("FungibleToken")}
import FUSD from ${getAddress("FUSD")}
transaction(amount: UFix64, to: Address) {
let sentVault: @FungibleToken.Vault
prepare(signer: AuthAccount) {
let vaultRef = signer.borrow<&FUSD.Vault>(from: /storage/fusdVault)
?? panic("Could not borrow reference to the owner's Vault!")
self.sentVault <- vaultRef.withdraw(amount: amount)
}
execute {
let recipient = getAccount(to)
let receiverRef = recipient.getCapability(/public/fusdReceiver)!.borrow<&{FungibleToken.Receiver}>()
?? panic("Could not borrow receiver reference to the recipient's Vault")
receiverRef.deposit(from: <-self.sentVault)
}
}`,
args: [
{ type: "UFix64", comment: "amount" },
{ type: "Address", comment: "recipient" },
],
shouldSign: true,
};

export const sendBLT = {
type: ScriptTypes.TX,
script: `\
import FungibleToken from ${getAddress("FungibleToken")}
import BloctoToken from ${getAddress("BloctoToken")}
transaction(amount: UFix64, to: Address) {
let sentVault: @FungibleToken.Vault
prepare(signer: AuthAccount) {
let vaultRef = signer.borrow<&BloctoToken.Vault>(from: /storage/bloctoTokenVault)
let sentVault: @{FungibleToken.Vault}
prepare(signer: auth(BorrowValue) &Account) {
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &BloctoToken.Vault>(from: /storage/bloctoTokenVault)
?? panic("Could not borrow reference to the owner's Vault!")
self.sentVault <- vaultRef.withdraw(amount: amount)
}
execute {
let recipient = getAccount(to)
let receiverRef = recipient.getCapability(/public/bloctoTokenReceiver)!.borrow<&{FungibleToken.Receiver}>()
let receiverRef = recipient.capabilities.borrow<&{FungibleToken.Receiver}>(/public/bloctoTokenReceiver)
?? panic("Could not borrow receiver reference to the recipient's Vault")
receiverRef.deposit(from: <-self.sentVault)
}
Expand All @@ -126,12 +83,12 @@ import TeleportedTetherToken from ${getAddress("TeleportedTetherToken")}
transaction(amount: UFix64, to: Address) {
// The Vault resource that holds the tokens that are being transferred
let sentVault: @FungibleToken.Vault
let sentVault: @{FungibleToken.Vault}
prepare(signer: AuthAccount) {
prepare(signer: auth(BorrowValue) &Account) {
// Get a reference to the signer's stored vault
let vaultRef = signer.borrow<&TeleportedTetherToken.Vault>(from: TeleportedTetherToken.TokenStoragePath)
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &TeleportedTetherToken.Vault>(from: TeleportedTetherToken.TokenStoragePath)
?? panic("Could not borrow reference to the owner's Vault!")
// Withdraw tokens from the signer's stored vault
Expand All @@ -144,8 +101,8 @@ transaction(amount: UFix64, to: Address) {
let recipient = getAccount(to)
// Get a reference to the recipient's Receiver
let receiverRef = recipient.getCapability(TeleportedTetherToken.TokenPublicReceiverPath)
.borrow<&{FungibleToken.Receiver}>()
let receiverRef = recipient.capabilities
.borrow<&{FungibleToken.Receiver}>(TeleportedTetherToken.TokenPublicReceiverPath)
?? panic("Could not borrow receiver reference to the recipient's Vault")
// Deposit the withdrawn tokens in the recipient's receiver
Expand All @@ -168,12 +125,12 @@ import FlowToken from ${getAddress("FlowToken")}
transaction(amount: UFix64, to: Address) {
// The Vault resource that holds the tokens that are being transferred
let sentVault: @FungibleToken.Vault
let sentVault: @{FungibleToken.Vault}
prepare(signer: AuthAccount) {
prepare(signer: auth(BorrowValue) &Account) {
// Get a reference to the signer's stored vault
let vaultRef = signer.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow reference to the owner's Vault!")
// Withdraw tokens from the signer's stored vault
Expand All @@ -186,8 +143,8 @@ transaction(amount: UFix64, to: Address) {
let recipient = getAccount(to)
// Get a reference to the recipient's Receiver
let receiverRef = recipient.getCapability(/public/flowTokenReceiver)
.borrow<&{FungibleToken.Receiver}>()
let receiverRef = recipient.capabilities
.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
?? panic("Could not borrow receiver reference to the recipient's Vault")
// Deposit the withdrawn tokens in the recipient's receiver
Expand Down
8 changes: 2 additions & 6 deletions src/utils/getAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export default function getAddress(key: string): string {
return "0xe0f601b5afd47581";
case "FungibleToken":
return "0xf233dcee88fe0abe";
case "FUSD":
return "0x3c5959b568896393";
case "BloctoToken":
return "0x0f9df91c9121c460";
case "TeleportedTetherToken":
Expand All @@ -26,12 +24,10 @@ export default function getAddress(key: string): string {
return "0x7deafdfc288e422d";
case "FungibleToken":
return "0x9a0766d93b6608b7";
case "FUSD":
return "0xe223d8a629e49c68";
case "BloctoToken":
return "0x6e0797ac987005f5";
return "0x653cfe36d146e7be";
case "TeleportedTetherToken":
return "0xab26e0a07d770ec1";
return "0x2d270db9ac8c7fef";
case "BloctoPrize":
return "0xc52330593c1d935f";
default:
Expand Down

0 comments on commit 8ecb73c

Please sign in to comment.