-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBankReserve.sol
60 lines (52 loc) · 2 KB
/
BankReserve.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "https://raw.githubusercontent.com/chiru-labs/ERC721A/main/contracts/ERC721A.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./LiquidityPool.sol";
contract BankReserve is ERC721A, Ownable {
struct BullionData {
string assetId;
string purity;
uint256 weight;
uint256 dateOfIntake;
}
mapping(uint256 => BullionData) public bullionData;
uint256[] private allBullionIds;
LiquidityPool private liquidityPool;
constructor(string memory _name, string memory _symbol, address _liquidityPool) ERC721A(_name, _symbol) {
liquidityPool = LiquidityPool(_liquidityPool);
}
function mintBullionNFT(
address _to,
uint256 _tokenId,
string memory _assetId,
string memory _purity,
uint256 _weight,
uint256 _dateOfIntake
) external onlyOwner {
_mint(_to, _tokenId);
bullionData[_tokenId] = BullionData(_assetId, _purity, _weight, _dateOfIntake);
allBullionIds.push(_tokenId);
liquidityPool.depositNFT(_tokenId); // Deposit the weight of the bullion into the liquidity pool
}
function burnBullionNFT(uint256 _tokenId) external onlyOwner {
require(_exists(_tokenId), "BullionNFT: Token ID does not exist");
liquidityPool.withdrawNFT(_tokenId); // Withdraw the weight of the burnt bullion from the liquidity pool
_burn(_tokenId);
delete bullionData[_tokenId];
uint256[] storage allBullion = allBullionIds;
for (uint256 i = 0; i < allBullion.length; i++) {
if (allBullion[i] == _tokenId) {
allBullion[i] = allBullion[allBullion.length - 1];
allBullion.pop();
break;
}
}
}
function getAllBullion() external view returns (uint256[] memory) {
return allBullionIds;
}
function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}
}