From 7b376e6fdba37ebd4956873edd84297ff943804a Mon Sep 17 00:00:00 2001 From: mordochi Date: Mon, 2 Sep 2024 18:07:49 +0800 Subject: [PATCH] feat: update flow scripts for Crescendo --- src/components/FlowEditor.tsx | 8 +-- src/scripts/flow/Transactions.ts | 83 ++++++++------------------------ src/utils/getAddress.ts | 8 +-- 3 files changed, 26 insertions(+), 73 deletions(-) diff --git a/src/components/FlowEditor.tsx b/src/components/FlowEditor.tsx index 81d40aa..cab9172 100644 --- a/src/components/FlowEditor.tsx +++ b/src/components/FlowEditor.tsx @@ -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"; @@ -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 }, ]; diff --git a/src/scripts/flow/Transactions.ts b/src/scripts/flow/Transactions.ts index cad87c8..e4bf771 100644 --- a/src/scripts/flow/Transactions.ts +++ b/src/scripts/flow/Transactions.ts @@ -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 } @@ -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 } @@ -52,8 +37,8 @@ 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 } @@ -61,34 +46,6 @@ pub fun main (address: Address): UFix64 { 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: `\ @@ -96,16 +53,16 @@ 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(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) } @@ -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(from: TeleportedTetherToken.TokenStoragePath) ?? panic("Could not borrow reference to the owner's Vault!") // Withdraw tokens from the signer's stored vault @@ -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 @@ -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(from: /storage/flowTokenVault) ?? panic("Could not borrow reference to the owner's Vault!") // Withdraw tokens from the signer's stored vault @@ -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 diff --git a/src/utils/getAddress.ts b/src/utils/getAddress.ts index 03bae0b..ad0b2f0 100644 --- a/src/utils/getAddress.ts +++ b/src/utils/getAddress.ts @@ -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": @@ -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: