|
2 | 2 | import "FungibleToken" |
3 | 3 | import "Burner" |
4 | 4 | import "ViewResolver" |
| 5 | +import "MetadataViews" |
5 | 6 | // DeFiActions |
6 | 7 | import "DeFiActions" |
7 | 8 | import "FlowYieldVaultsClosedBeta" |
@@ -63,6 +64,53 @@ access(all) contract FlowYieldVaults { |
63 | 64 | owner: Address? |
64 | 65 | ) |
65 | 66 |
|
| 67 | + /* --- VIEWS --- */ |
| 68 | + |
| 69 | + /// YieldVaultInfo |
| 70 | + /// |
| 71 | + /// Minimal view struct providing basic identification and configuration details for a YieldVault |
| 72 | + access(all) struct YieldVaultInfo { |
| 73 | + /// The YieldVault's ID (DeFiActions.UniqueIdentifier.id) |
| 74 | + access(all) let id: UInt64 |
| 75 | + /// The YieldVault resource uuid |
| 76 | + access(all) let uuid: UInt64 |
| 77 | + /// The type identifier of the Vault this YieldVault operates on |
| 78 | + access(all) let vaultTypeIdentifier: String |
| 79 | + /// The strategy type identifier for this YieldVault |
| 80 | + access(all) let strategyTypeIdentifier: String |
| 81 | + /// The YieldVault owner's address if available |
| 82 | + access(all) let owner: Address? |
| 83 | + |
| 84 | + init( |
| 85 | + id: UInt64, |
| 86 | + uuid: UInt64, |
| 87 | + vaultTypeIdentifier: String, |
| 88 | + strategyTypeIdentifier: String, |
| 89 | + owner: Address? |
| 90 | + ) { |
| 91 | + self.id = id |
| 92 | + self.uuid = uuid |
| 93 | + self.vaultTypeIdentifier = vaultTypeIdentifier |
| 94 | + self.strategyTypeIdentifier = strategyTypeIdentifier |
| 95 | + self.owner = owner |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + /// YieldVaultBalance |
| 100 | + /// |
| 101 | + /// Minimal view struct providing the YieldVault's current available balance for the vault's denomination. |
| 102 | + access(all) struct YieldVaultBalance { |
| 103 | + /// The type identifier of the Vault this YieldVault operates on |
| 104 | + access(all) let tokenTypeIdentifier: String |
| 105 | + /// The current available balance for withdrawal |
| 106 | + access(all) let availableBalance: UFix64 |
| 107 | + |
| 108 | + init(tokenTypeIdentifier: String, availableBalance: UFix64) { |
| 109 | + self.tokenTypeIdentifier = tokenTypeIdentifier |
| 110 | + self.availableBalance = availableBalance |
| 111 | + } |
| 112 | + } |
| 113 | + |
66 | 114 | /* --- CONSTRUCTS --- */ |
67 | 115 |
|
68 | 116 | /// Strategy |
@@ -272,12 +320,38 @@ access(all) contract FlowYieldVaults { |
272 | 320 | // Force unwrap to ensure burnCallback is called on the Strategy |
273 | 321 | Burner.burn(<-_strategy!) |
274 | 322 | } |
275 | | - /// TODO: FlowYieldVaults specific views |
276 | 323 | access(all) view fun getViews(): [Type] { |
277 | | - return [] |
| 324 | + return [ |
| 325 | + Type<MetadataViews.Display>(), |
| 326 | + Type<YieldVaultInfo>(), |
| 327 | + Type<YieldVaultBalance>() |
| 328 | + ] |
278 | 329 | } |
279 | | - /// TODO: FlowYieldVaults specific view resolution |
280 | 330 | access(all) fun resolveView(_ view: Type): AnyStruct? { |
| 331 | + switch view { |
| 332 | + case Type<MetadataViews.Display>(): |
| 333 | + return MetadataViews.Display( |
| 334 | + name: "Yield Vault #\(self.id())", |
| 335 | + description: "Yield vault for strategy \(self.getStrategyType()) and vault type \(self.getVaultTypeIdentifier())", |
| 336 | + // Temporary placeholder thumbnail; replace with the final hosted URL when available. |
| 337 | + thumbnail: MetadataViews.HTTPFile( |
| 338 | + url: "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'/>" |
| 339 | + ) |
| 340 | + ) |
| 341 | + case Type<YieldVaultInfo>(): |
| 342 | + return YieldVaultInfo( |
| 343 | + id: self.id(), |
| 344 | + uuid: self.uuid, |
| 345 | + vaultTypeIdentifier: self.vaultType.identifier, |
| 346 | + strategyTypeIdentifier: self.getStrategyType(), |
| 347 | + owner: self.owner?.address |
| 348 | + ) |
| 349 | + case Type<YieldVaultBalance>(): |
| 350 | + return YieldVaultBalance( |
| 351 | + tokenTypeIdentifier: self.vaultType.identifier, |
| 352 | + availableBalance: self.getYieldVaultBalance() |
| 353 | + ) |
| 354 | + } |
281 | 355 | return nil |
282 | 356 | } |
283 | 357 | /// Deposits the provided Vault to the Strategy |
@@ -312,7 +386,7 @@ access(all) contract FlowYieldVaults { |
312 | 386 | } |
313 | 387 | /// Returns the strategy type identifier for this YieldVault |
314 | 388 | access(all) view fun getStrategyType(): String { |
315 | | - return self.strategy.getType().identifier |
| 389 | + return self._borrowStrategy().getType().identifier |
316 | 390 | } |
317 | 391 | /// Withdraws the requested amount from the Strategy |
318 | 392 | access(FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} { |
|
0 commit comments