Skip to content

Commit

Permalink
update ts formatting & add ci EVM contract env alias
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Feb 15, 2024
1 parent 399f0d5 commit d94652a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
NEXT_PUBLIC_CONTRACT_FUNGIBLE_TOKEN: "0xee82856bf20e2aa6"
NEXT_PUBLIC_CONTRACT_FLOW_TOKEN: "0x0ae53cb6e3f42a79"
NEXT_PUBLIC_CONTRACT_FUSD: "0xf8d6e0586b0a20c7"
NEXT_PUBLIC_CONTRACT_EVM: "0xf8d6e0586b0a20c7"
NEXT_PUBLIC_NETWORK: "testnet"

strategy:
Expand Down
66 changes: 33 additions & 33 deletions lib/flow/account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fcl from "@onflow/fcl"
import * as t from "@onflow/types"
import publicConfig from "../publicConfig"
import { sendTransaction } from "./send"
import {sendTransaction} from "./send"

const accountCreatedEventType = "flow.AccountCreated"

Expand Down Expand Up @@ -50,37 +50,37 @@ transaction(publicKey: String, flowTokenAmount: UFix64, sigAlgorithm: UInt8, has
`

export async function createAccount(
publicKey: string,
sigAlgo: number,
hashAlgo: number,
authorization: fcl.Authorization
publicKey: string,
sigAlgo: number,
hashAlgo: number,
authorization: fcl.Authorization
) {
const result = await sendTransaction({
transaction: txCreateAccount,
args: [
fcl.arg(publicKey, t.String),
fcl.arg(publicConfig.tokenAmountFlow, t.UFix64),
fcl.arg(sigAlgo.toString(), t.UInt8),
fcl.arg(hashAlgo.toString(), t.UInt8),
],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})

const accountCreatedEvent = result.events.find(
(event: fcl.Event) => event.type === accountCreatedEventType
)

if (!accountCreatedEvent) {
throw "Transaction did not emit account creation event"
}

const address = accountCreatedEvent.data.address
const transactionId = accountCreatedEvent.transactionId

return {
address,
transactionId,
}
const result = await sendTransaction({
transaction: txCreateAccount,
args: [
fcl.arg(publicKey, t.String),
fcl.arg(publicConfig.tokenAmountFlow, t.UFix64),
fcl.arg(sigAlgo.toString(), t.UInt8),
fcl.arg(hashAlgo.toString(), t.UInt8),
],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})

const accountCreatedEvent = result.events.find(
(event: fcl.Event) => event.type === accountCreatedEventType
)

if (!accountCreatedEvent) {
throw "Transaction did not emit account creation event"
}

const address = accountCreatedEvent.data.address
const transactionId = accountCreatedEvent.transactionId

return {
address,
transactionId,
}
}
32 changes: 16 additions & 16 deletions lib/flow/fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ transaction(address: Address, amount: UFix64) {

type TokenType = "FLOW" | "FUSD"
type Token = {
tx: string
amount: string
tx: string
amount: string
}
type Tokens = Record<TokenType, Token>

export const tokens: Tokens = {
FLOW: {tx: txFundAccountFLOW, amount: TOKEN_FUNDING_AMOUNTS[FLOW_TYPE]},
FUSD: {tx: txFundAccountFUSD, amount: TOKEN_FUNDING_AMOUNTS[FUSD_TYPE]},
FLOW: {tx: txFundAccountFLOW, amount: TOKEN_FUNDING_AMOUNTS[FLOW_TYPE]},
FUSD: {tx: txFundAccountFUSD, amount: TOKEN_FUNDING_AMOUNTS[FUSD_TYPE]},
}

export async function fundAccount(
address: string,
token: TokenType,
authorization: fcl.Authorization
address: string,
token: TokenType,
authorization: fcl.Authorization
) {
const {tx, amount} = tokens[token]
const {tx, amount} = tokens[token]

await sendTransaction({
transaction: tx,
args: [fcl.arg(address, t.Address), fcl.arg(amount, t.UFix64)],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})
await sendTransaction({
transaction: tx,
args: [fcl.arg(address, t.Address), fcl.arg(amount, t.UFix64)],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})

return amount
return amount
}

0 comments on commit d94652a

Please sign in to comment.