@flowtyio/flow-contracts 0.1.0-beta.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/contracts/FungibleTokenSwitchboard.cdc +360 -0
- package/contracts/MetadataViews.cdc +79 -6
- package/contracts/NonFungibleToken.cdc +17 -10
- package/contracts/capability-cache/CapabilityCache.cdc +97 -0
- package/contracts/dapper/TopShot.cdc +323 -259
- package/contracts/dapper/TopShotLocking.cdc +41 -15
- package/contracts/dapper/offers/DapperOffersV2.cdc +46 -43
- package/contracts/dapper/offers/OffersV2.cdc +40 -56
- package/contracts/dapper/offers/Resolver.cdc +20 -13
- package/contracts/emerald-city/FLOAT.cdc +259 -254
- package/contracts/evm/CrossVMNFT.cdc +50 -0
- package/contracts/evm/EVM.cdc +851 -0
- package/contracts/evm/FlowEVMBridgeConfig.cdc +454 -0
- package/contracts/evm/FlowEVMBridgeHandlerInterfaces.cdc +163 -0
- package/contracts/evm/FlowEVMBridgeHandlers.cdc +230 -0
- package/contracts/evm/FlowEVMBridgeUtils.cdc +1303 -0
- package/contracts/evm/IBridgePermissions.cdc +19 -0
- package/contracts/evm/ICrossVM.cdc +12 -0
- package/contracts/evm/ICrossVMAsset.cdc +19 -0
- package/contracts/evm/Serialize.cdc +141 -0
- package/contracts/evm/SerializeMetadata.cdc +221 -0
- package/contracts/example/ExampleNFT.cdc +2 -2
- package/contracts/find/FindViews.cdc +357 -353
- package/contracts/flow-utils/ScopedFTProviders.cdc +5 -2
- package/contracts/flow-utils/ScopedNFTProviders.cdc +6 -2
- package/contracts/flowty-drops/ContractManager.cdc +73 -0
- package/contracts/flowty-drops/DropFactory.cdc +75 -0
- package/contracts/flowty-drops/DropTypes.cdc +282 -0
- package/contracts/flowty-drops/FlowtyActiveCheckers.cdc +113 -0
- package/contracts/flowty-drops/FlowtyAddressVerifiers.cdc +64 -0
- package/contracts/flowty-drops/FlowtyDrops.cdc +461 -0
- package/contracts/flowty-drops/FlowtyPricers.cdc +48 -0
- package/contracts/flowty-drops/initializers/ContractBorrower.cdc +14 -0
- package/contracts/flowty-drops/initializers/ContractInitializer.cdc +7 -0
- package/contracts/flowty-drops/initializers/OpenEditionInitializer.cdc +57 -0
- package/contracts/flowty-drops/nft/BaseCollection.cdc +97 -0
- package/contracts/flowty-drops/nft/BaseNFT.cdc +107 -0
- package/contracts/flowty-drops/nft/ContractFactory.cdc +13 -0
- package/contracts/flowty-drops/nft/ContractFactoryTemplate.cdc +48 -0
- package/contracts/flowty-drops/nft/NFTMetadata.cdc +140 -0
- package/contracts/flowty-drops/nft/OpenEditionNFT.cdc +42 -0
- package/contracts/flowty-drops/nft/OpenEditionTemplate.cdc +54 -0
- package/contracts/flowty-drops/nft/UniversalCollection.cdc +29 -0
- package/contracts/fungible-token-router/FungibleTokenRouter.cdc +103 -0
- package/contracts/hybrid-custody/CapabilityDelegator.cdc +28 -26
- package/contracts/hybrid-custody/CapabilityFactory.cdc +20 -18
- package/contracts/hybrid-custody/CapabilityFilter.cdc +41 -24
- package/contracts/hybrid-custody/HybridCustody.cdc +303 -242
- package/contracts/hybrid-custody/factories/FTAllFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTProviderFactory.cdc +17 -5
- package/contracts/hybrid-custody/factories/FTReceiverBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTReceiverFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +46 -0
- package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
- package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionFactory.cdc +22 -0
- package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
- package/contracts/lost-and-found/LostAndFound.cdc +21 -17
- package/contracts/tokens/USDCFlow.cdc +232 -0
- package/flow.json +278 -7
- package/package.json +1 -1
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +0 -10
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import "Burner"
|
|
2
|
+
import "FungibleToken"
|
|
3
|
+
import "NonFungibleToken"
|
|
4
|
+
|
|
5
|
+
import "EVM"
|
|
6
|
+
|
|
7
|
+
import "FlowEVMBridgeHandlerInterfaces"
|
|
8
|
+
import "FlowEVMBridgeConfig"
|
|
9
|
+
import "FlowEVMBridgeUtils"
|
|
10
|
+
|
|
11
|
+
/// FlowEVMBridgeHandlers
|
|
12
|
+
///
|
|
13
|
+
/// This contract is responsible for defining and configuring bridge handlers for special cased assets.
|
|
14
|
+
///
|
|
15
|
+
access(all) contract FlowEVMBridgeHandlers {
|
|
16
|
+
|
|
17
|
+
/**********************
|
|
18
|
+
Contract Fields
|
|
19
|
+
***********************/
|
|
20
|
+
|
|
21
|
+
/// The storage path for the HandlerConfigurator resource
|
|
22
|
+
access(all) let ConfiguratorStoragePath: StoragePath
|
|
23
|
+
|
|
24
|
+
/****************
|
|
25
|
+
Constructs
|
|
26
|
+
*****************/
|
|
27
|
+
|
|
28
|
+
/// Handler for bridging Cadence native fungible tokens to EVM. In the event a Cadence project migrates native
|
|
29
|
+
/// support to EVM, this Hander can be configured to facilitate bridging the Cadence tokens to EVM. This Handler
|
|
30
|
+
/// then effectively allows the bridge to treat such tokens as bridge-defined on the Cadence side and EVM-native on
|
|
31
|
+
/// the EVM side minting/burning in Cadence and escrowing in EVM.
|
|
32
|
+
/// In order for this to occur, neither the Cadence token nor the EVM contract can be onboarded to the bridge - in
|
|
33
|
+
/// essence, neither side of the asset can be onboarded to the bridge.
|
|
34
|
+
/// The Handler must be configured in the bridge via the HandlerConfigurator. Once added, the bridge will filter
|
|
35
|
+
/// requests to bridge the token Vault to EVM through this Handler which cannot be enabled until a target EVM
|
|
36
|
+
/// address is set. Once the corresponding EVM contract address is known, it can be set and the Handler. It's also
|
|
37
|
+
/// suggested that the Handler only be enabled once sufficient liquidity has been arranged in bridge escrow on the
|
|
38
|
+
/// EVM side.
|
|
39
|
+
///
|
|
40
|
+
access(all) resource CadenceNativeTokenHandler : FlowEVMBridgeHandlerInterfaces.TokenHandler {
|
|
41
|
+
/// Flag determining if request handling is enabled
|
|
42
|
+
access(self) var enabled: Bool
|
|
43
|
+
/// The Cadence Type this handler fulfills requests for
|
|
44
|
+
access(self) var targetType: Type
|
|
45
|
+
/// The EVM contract address this handler fulfills requests for. This field is optional in the event the EVM
|
|
46
|
+
/// contract address is not yet known but the Cadence type must still be filtered via Handler to prevent the
|
|
47
|
+
/// type from being onboarded otherwise.
|
|
48
|
+
access(self) var targetEVMAddress: EVM.EVMAddress?
|
|
49
|
+
/// The expected minter type for minting tokens on fulfillment
|
|
50
|
+
access(self) let expectedMinterType: Type
|
|
51
|
+
/// The Minter enabling minting of Cadence tokens on fulfillment from EVM
|
|
52
|
+
access(self) var minter: @{FlowEVMBridgeHandlerInterfaces.TokenMinter}?
|
|
53
|
+
|
|
54
|
+
init(targetType: Type, targetEVMAddress: EVM.EVMAddress?, expectedMinterType: Type) {
|
|
55
|
+
pre {
|
|
56
|
+
expectedMinterType.isSubtype(of: Type<@{FlowEVMBridgeHandlerInterfaces.TokenMinter}>()):
|
|
57
|
+
"Invalid minter type"
|
|
58
|
+
}
|
|
59
|
+
self.enabled = false
|
|
60
|
+
self.targetType = targetType
|
|
61
|
+
self.targetEVMAddress = targetEVMAddress
|
|
62
|
+
self.expectedMinterType = expectedMinterType
|
|
63
|
+
self.minter <- nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* --- HandlerInfo --- */
|
|
67
|
+
|
|
68
|
+
/// Returns the enabled status of the handler
|
|
69
|
+
access(all) view fun isEnabled(): Bool {
|
|
70
|
+
return self.enabled
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Returns the type of the asset the handler is configured to handle
|
|
74
|
+
access(all) view fun getTargetType(): Type? {
|
|
75
|
+
return self.targetType
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// Returns the EVM contract address the handler is configured to handle
|
|
79
|
+
access(all) view fun getTargetEVMAddress(): EVM.EVMAddress? {
|
|
80
|
+
return self.targetEVMAddress
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// Returns the expected minter type for the handler
|
|
84
|
+
access(all) view fun getExpectedMinterType(): Type? {
|
|
85
|
+
return self.expectedMinterType
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* --- TokenHandler --- */
|
|
89
|
+
|
|
90
|
+
/// Fulfill a request to bridge tokens from Cadence to EVM, burning the provided Vault and transferring from
|
|
91
|
+
/// EVM escrow to the named recipient. Assumes any fees are handled by the caller within the bridge contracts
|
|
92
|
+
///
|
|
93
|
+
/// @param tokens: The Vault containing the tokens to bridge
|
|
94
|
+
/// @param to: The EVM address to transfer the tokens to
|
|
95
|
+
///
|
|
96
|
+
access(account)
|
|
97
|
+
fun fulfillTokensToEVM(
|
|
98
|
+
tokens: @{FungibleToken.Vault},
|
|
99
|
+
to: EVM.EVMAddress
|
|
100
|
+
) {
|
|
101
|
+
let evmAddress = self.getTargetEVMAddress()!
|
|
102
|
+
|
|
103
|
+
// Get values from vault and burn
|
|
104
|
+
let amount = tokens.balance
|
|
105
|
+
let uintAmount = FlowEVMBridgeUtils.convertCadenceAmountToERC20Amount(amount, erc20Address: evmAddress)
|
|
106
|
+
|
|
107
|
+
assert(uintAmount > UInt256(0), message: "Amount to bridge must be greater than 0")
|
|
108
|
+
|
|
109
|
+
Burner.burn(<-tokens)
|
|
110
|
+
|
|
111
|
+
FlowEVMBridgeUtils.mustTransferERC20(to: to, amount: uintAmount, erc20Address: evmAddress)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// Fulfill a request to bridge tokens from EVM to Cadence, minting the provided amount of tokens in Cadence
|
|
115
|
+
/// and transferring from the named owner to bridge escrow in EVM.
|
|
116
|
+
///
|
|
117
|
+
/// @param owner: The EVM address of the owner of the tokens. Should also be the caller executing the protected
|
|
118
|
+
/// transfer call.
|
|
119
|
+
/// @param type: The type of the asset being bridged
|
|
120
|
+
/// @param amount: The amount of tokens to bridge
|
|
121
|
+
///
|
|
122
|
+
/// @return The minted Vault containing the the requested amount of Cadence tokens
|
|
123
|
+
///
|
|
124
|
+
access(account)
|
|
125
|
+
fun fulfillTokensFromEVM(
|
|
126
|
+
owner: EVM.EVMAddress,
|
|
127
|
+
type: Type,
|
|
128
|
+
amount: UInt256,
|
|
129
|
+
protectedTransferCall: fun (): EVM.Result
|
|
130
|
+
): @{FungibleToken.Vault} {
|
|
131
|
+
let evmAddress = self.getTargetEVMAddress()!
|
|
132
|
+
|
|
133
|
+
// Convert the amount to a UFix64
|
|
134
|
+
let ufixAmount = FlowEVMBridgeUtils.convertERC20AmountToCadenceAmount(
|
|
135
|
+
amount,
|
|
136
|
+
erc20Address: evmAddress
|
|
137
|
+
)
|
|
138
|
+
assert(ufixAmount > 0.0, message: "Amount to bridge must be greater than 0")
|
|
139
|
+
|
|
140
|
+
FlowEVMBridgeUtils.mustEscrowERC20(
|
|
141
|
+
owner: owner,
|
|
142
|
+
amount: amount,
|
|
143
|
+
erc20Address: evmAddress,
|
|
144
|
+
protectedTransferCall: protectedTransferCall
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
// After state confirmation, mint the tokens and return
|
|
148
|
+
let minter = self.borrowMinter() ?? panic("Minter not set")
|
|
149
|
+
let minted <- minter.mint(amount: ufixAmount)
|
|
150
|
+
return <-minted
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* --- Admin --- */
|
|
154
|
+
|
|
155
|
+
/// Sets the target type for the handler
|
|
156
|
+
access(FlowEVMBridgeHandlerInterfaces.Admin)
|
|
157
|
+
fun setTargetType(_ type: Type) {
|
|
158
|
+
self.targetType = type
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// Sets the target EVM address for the handler
|
|
162
|
+
access(FlowEVMBridgeHandlerInterfaces.Admin)
|
|
163
|
+
fun setTargetEVMAddress(_ address: EVM.EVMAddress) {
|
|
164
|
+
self.targetEVMAddress = address
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// Sets the target type for the handler
|
|
168
|
+
access(FlowEVMBridgeHandlerInterfaces.Admin)
|
|
169
|
+
fun setMinter(_ minter: @{FlowEVMBridgeHandlerInterfaces.TokenMinter}) {
|
|
170
|
+
pre {
|
|
171
|
+
self.minter == nil: "Minter has already been set"
|
|
172
|
+
}
|
|
173
|
+
self.minter <-! minter
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/// Enables the handler for request handling. The
|
|
177
|
+
access(FlowEVMBridgeHandlerInterfaces.Admin)
|
|
178
|
+
fun enableBridging() {
|
|
179
|
+
pre {
|
|
180
|
+
self.minter != nil: "Cannot enable handler without a minter"
|
|
181
|
+
}
|
|
182
|
+
self.enabled = true
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* --- Internal --- */
|
|
186
|
+
|
|
187
|
+
/// Returns an entitled reference to the encapsulated minter resource
|
|
188
|
+
access(self)
|
|
189
|
+
view fun borrowMinter(): auth(FlowEVMBridgeHandlerInterfaces.Mint) &{FlowEVMBridgeHandlerInterfaces.TokenMinter}? {
|
|
190
|
+
return &self.minter
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// This resource enables the configuration of Handlers. These Handlers are stored in FlowEVMBridgeConfig from which
|
|
195
|
+
/// further setting and getting can be executed.
|
|
196
|
+
///
|
|
197
|
+
access(all) resource HandlerConfigurator {
|
|
198
|
+
/// Creates a new Handler and adds it to the bridge configuration
|
|
199
|
+
///
|
|
200
|
+
/// @param handlerType: The type of handler to create as defined in this contract
|
|
201
|
+
/// @param targetType: The type of the asset the handler will handle.
|
|
202
|
+
/// @param targetEVMAddress: The EVM contract address the handler will handle, can be nil if still unknown
|
|
203
|
+
/// @param expectedMinterType: The Type of the expected minter to be set for the created TokenHandler
|
|
204
|
+
///
|
|
205
|
+
access(FlowEVMBridgeHandlerInterfaces.Admin)
|
|
206
|
+
fun createTokenHandler(
|
|
207
|
+
handlerType: Type,
|
|
208
|
+
targetType: Type,
|
|
209
|
+
targetEVMAddress: EVM.EVMAddress?,
|
|
210
|
+
expectedMinterType: Type
|
|
211
|
+
) {
|
|
212
|
+
switch handlerType {
|
|
213
|
+
case Type<@CadenceNativeTokenHandler>():
|
|
214
|
+
let handler <-create CadenceNativeTokenHandler(
|
|
215
|
+
targetType: targetType,
|
|
216
|
+
targetEVMAddress: targetEVMAddress,
|
|
217
|
+
expectedMinterType: expectedMinterType
|
|
218
|
+
)
|
|
219
|
+
FlowEVMBridgeConfig.addTokenHandler(<-handler)
|
|
220
|
+
default:
|
|
221
|
+
panic("Invalid Handler type requested")
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
init() {
|
|
227
|
+
self.ConfiguratorStoragePath = /storage/BridgeHandlerConfigurator
|
|
228
|
+
self.account.storage.save(<-create HandlerConfigurator(), to: self.ConfiguratorStoragePath)
|
|
229
|
+
}
|
|
230
|
+
}
|