@@ -3,51 +3,57 @@ package models
3
3
import (
4
4
"math/big"
5
5
6
- "github.com/ethereum/go-ethereum/common"
6
+ gethCommon "github.com/ethereum/go-ethereum/common"
7
7
"github.com/onflow/cadence"
8
8
)
9
9
10
- // Flex is an account inside FVM with special access to the underlying infrasturcture which
11
- // allows to run a virtual evm-based blockchain on top of FVM. There are two ways to interact with this
12
- // blockchain (flex env), first by passing signed transactions (EOA accounts) through Flex.Run method and each transaction
13
- // would be considered as a block, updating the internal merkle tree of the Flex env and emitting a new root hash.
14
- // The second way is through a new form of accounts called (FOA) which acts as a resource that any account on Flow environment
15
- // could own and it has a collision-proof allocated flex address and any one who owns the resource, would be able to
16
- // interact with the Flex environment on behalf of the flex address.
17
-
18
- // The Flex enviornment shares the same native token as Flow, there is no new tokens minted and tokens could be bridged between
19
- // FOA resources and Flow accounts. Then it could be circulated to any address space in the Flex (EOA, smart contracts), etc.
20
-
21
- // Flex addresses are evm-compatible addresses
22
- type FlexAddress common.Address
23
-
24
- func (fa FlexAddress ) ToCommon () common.Address {
25
- return common .Address (fa )
10
+ // Flex is an account inside FVM with special access to the underlying infrastructure
11
+ // which allows to run a virtual EVM-based blockchain inside FVM.
12
+ //
13
+ // There are two ways to interact with this environment:
14
+ //
15
+ // First, passing a signed transaction (EOA account) to the `Flex.run` Cadence function
16
+ // creates a new block, updates the internal merkle tree, and emits a new root hash.
17
+ //
18
+ // The Second way is through a new form of account called Flow-owned account (FOA),
19
+ // which is represented and controlled through a resource, owned by a Flow account.
20
+ // The FOA has a collision-proof allocated address.
21
+ /// The owner of the FOA resource can interact with the Flex environment on behalf of the Flex address.
22
+ //
23
+ // The Flex environment shares the same native token as Flow, there are no new tokens minted.
24
+ // Other ERC-20 fungible tokens can be bridged between FOA resources and Flow accounts.
25
+
26
+ // FlexAddress is an EVM-compatible address
27
+ type FlexAddress gethCommon.Address
28
+
29
+ func (fa FlexAddress ) ToCommon () gethCommon.Address {
30
+ return gethCommon .Address (fa )
26
31
}
27
32
28
33
func NewFlexAddressFromString (str string ) FlexAddress {
29
- return FlexAddress (common .BytesToAddress ([]byte (str )))
34
+ return FlexAddress (gethCommon .BytesToAddress ([]byte (str )))
30
35
}
31
36
32
- // FlexBlock captures block info such as height and state
37
+ // FlexBlock represents an EVM block.
38
+ // It captures block info such as height and state
33
39
type FlexBlock interface {
34
- // returns the height of this block (autoincrement number)
40
+ // Height returns the height of this EVM block (auto-incremented number)
35
41
Height () uint64
36
- // returns the root hash of the state after executing this block
37
- StateRoot () common .Hash
38
- // returns the root hash of the events emited during execution of this block
39
- EventRoot () common .Hash
42
+ // StateRoot returns the EVM root hash of the state after executing this EVM block
43
+ StateRoot () gethCommon .Hash
44
+ // EventRoot returns the EVM root hash of the events emitted during execution of this EVM block
45
+ EventRoot () gethCommon .Hash
40
46
}
41
47
42
- // Balance of a flex account
48
+ // Balance represents the balance of a Flex account
43
49
// a separate type has been considered here to prevent
44
50
// accidental dev mistakes when dealing with the conversion
45
51
type Balance interface {
46
52
InAttoFlow () * big.Int
47
53
InFlow () cadence.UFix64
48
54
}
49
55
50
- type Gaslimit uint64
56
+ type GasLimit uint64
51
57
52
58
type Code []byte
53
59
@@ -59,51 +65,59 @@ type FlexAccount interface {
59
65
Balance () Balance
60
66
}
61
67
62
- type FlowTokenVault interface {
68
+ // FLOWTokenVault represents a FLOW Vault
69
+ type FLOWTokenVault interface {
63
70
Balance () Balance
64
- Withdraw (Balance ) FlowTokenVault
65
- Deposit (FlowTokenVault )
71
+ Withdraw (Balance ) FLOWTokenVault
72
+ Deposit (FLOWTokenVault )
66
73
}
67
74
68
- // FlowOwnedAccount is a new type of accounts on the Flex environment
69
- // that instead of being managed by public key inside the Flex, it would be managed
70
- // as a resource inside the FVM accounts. in other words, the FVM account who holds
71
- // a owns the FOA resource, could bridge native token from and to flex account associated with the FOA
72
- // and deploys contracts or calls method on contracts without the need to sign a transaction.
75
+ // FlowOwnedAccount is a new type of account in the Flex environment,
76
+ // that instead of being managed by public key inside the Flex,
77
+ // is managed by a resource owned by a Flow account.
78
+ //
79
+ // In other words, the FVM account who owns the FOA resource
80
+ // can bridge native tokens to and from the Flex account associated with the FOA,
81
+ // deploy contracts to the Flex environment,
82
+ // or call methods on contracts without the need to sign a transaction.
73
83
type FlowOwnedAccount interface {
74
84
// Address returns the flex address associated with the FOA account
75
85
Address () * FlexAddress
76
86
77
87
// Deposit deposits the token from the given vault into the Flex main vault
78
88
// and update the FOA balance with the new amount
79
- Deposit (FlowTokenVault )
89
+ // TODO: move to FlexAccount
90
+ Deposit (FLOWTokenVault )
80
91
81
92
// Withdraw deducts the balance from the FOA account and
82
93
// withdraw and return flow token from the Flex main vault.
83
- Withdraw (Balance ) FlowTokenVault
94
+ Withdraw (Balance ) FLOWTokenVault
84
95
85
96
// Deploy deploys a contract to the Flex environment
86
97
// the new deployed contract would be at the returned address and
87
98
// the contract data is not controlled by the FOA accounts
88
- Deploy (Code , Gaslimit , Balance ) FlexAddress
89
-
90
- // Call calls a smart contract function with the given data
91
- // it would limit the gas used according to the limit provided
92
- // given it doesn't goes beyond what Flow transaction allows.
93
- // the balance would be deducted from the OFA account and would be transferred to the target address
94
- // contract data is not controlled by the FOA accounts
95
- Call (FlexAddress , Data , Gaslimit , Balance ) Data
99
+ Deploy (Code , GasLimit , Balance ) FlexAddress
100
+
101
+ // Call calls a smart contract function with the given data.
102
+ // The gas usage is limited by the given gas limit,
103
+ // and the Flow transaction's computation limit.
104
+ // The fees are deducted from the FOA
105
+ // and are transferred to the target address.
106
+ // TODO: clarify
107
+ // Contract data is not controlled by the FOA account
108
+ Call (FlexAddress , Data , GasLimit , Balance ) Data
96
109
}
97
110
98
- // Flex contract handles operations on the flex environment
111
+ // FlexContractHandler handles operations on the Flex environment
99
112
type FlexContractHandler interface {
100
- // constructs a new flow owned account
113
+ // NewFlowOwnedAccount constructs a new FOA
101
114
NewFlowOwnedAccount () FlowOwnedAccount
102
115
103
- // returns the last executed block info
116
+ // LastExecutedBlock returns information about the last executed block
104
117
LastExecutedBlock () FlexBlock
105
118
106
- // runs a transaction in the Flex environment and collect
107
- // the flex gas fees under coinbase account, if tx is success full it returns true
108
- Run (bytes []byte , coinbase FlexAddress ) bool
119
+ // Run runs a transaction in the Flex environment,
120
+ // collects the gas fees, and transfers the gas fees to the given coinbase account.
121
+ // Returns true if the transaction was successfully executed
122
+ Run (tx []byte , coinbase FlexAddress ) bool
109
123
}
0 commit comments