Skip to content

Commit

Permalink
Require solidity version, add NFT contract versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Jul 3, 2023
1 parent fd61e0e commit 1d70b58
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 7 deletions.
10 changes: 8 additions & 2 deletions solidity/contracts/LiquidInfrastructureNFT.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
//SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.12; // Force solidity compliance

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand Down Expand Up @@ -38,6 +38,12 @@ contract LiquidInfrastructureNFT is ERC721, OwnableApprovableERC721 {
address[] private thresholdErc20s;
uint256[] private thresholdAmounts;

/**
* @notice This is the current version of the contract. Every update to the contract will introduce a new
* version, regardless of anticipated compatibility.
*/
uint256 public constant Version = 1;

/**
* @notice This NFT holds only 1 token in it, which is the Account token. Its Id is `1`.
* This Id is used for access control via the onlyOwner/onlyOwnerOrApproved modifiers.
Expand Down
3 changes: 2 additions & 1 deletion solidity/contracts/OwnableApprovableERC721.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.8.10;
//SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.12; // Force solidity compliance

import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/TestERC20A.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.10;
pragma solidity 0.8.12; // Force solidity compliance
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// One of three testing coins
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/TestERC20B.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.10;
pragma solidity 0.8.12; // Force solidity compliance
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// One of three testing coins
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/TestERC20C.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.10;
pragma solidity 0.8.12; // Force solidity compliance
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// One of three testing coins
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/TestERC721A.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.10;
pragma solidity 0.8.12; // Force solidity compliance
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

// Generate NFTs with token ids 1-10 and 190-195
Expand Down
21 changes: 21 additions & 0 deletions x/microtx/keeper/liquid_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var DefaultGasLimit uint64 = 30000000
// type will cause execution failure
var AccountId *big.Int = big.NewInt(1)

var CurrentNFTVersion *big.Int = big.NewInt(1)

// DoLiquify will deploy a LiquidInfrastructureNFT smart contract for the given account.
// The token will then be transferred to the given account and live under its control.
// Transfer to another owner requires interacting with the EVM
Expand Down Expand Up @@ -58,6 +60,14 @@ func (k Keeper) deployLiquidInfrastructureNFTContract(ctx sdk.Context, account s
return common.Address{}, sdkerrors.Wrap(err, "liquid infrastructure account contract deployment failed")
}

version, err := k.queryLiquidInfrastructureContractVersion(ctx, contract)
if err != nil {
return common.Address{}, sdkerrors.Wrap(err, "could not query NFT version")
}
if version.Cmp(CurrentNFTVersion) != 0 {
return common.Address{}, sdkerrors.Wrapf(err, "expected contract with version %v, got %v", CurrentNFTVersion, version)
}

_, err = k.transferLiquidInfrastructureNFTFromModuleToAddress(ctx, contract, account)
if err != nil {
return common.Address{}, sdkerrors.Wrapf(err, "could not transfer nft from %v to %v", types.ModuleEVMAddress.Hex(), SDKToEVMAddress(account).Hex())
Expand Down Expand Up @@ -103,6 +113,17 @@ func (k Keeper) queryLiquidInfrastructureOwner(ctx sdk.Context, nftAddress commo
return &owner, nil
}

// queryLiquidInfrastructureContractVersion fetches the `Version()` of the LiquidInfrastructureNFT deployed at `nftAddress`
func (k Keeper) queryLiquidInfrastructureContractVersion(ctx sdk.Context, nftAddress common.Address) (*big.Int, error) {
// ABI: uint256 public constant Version
res, err := k.QueryEVM(ctx, "Version", types.LiquidInfrastructureNFT, types.ModuleEVMAddress, &nftAddress)
if err != nil {
return nil, sdkerrors.Wrap(err, "unable to call Versionw with no args")
}
version := big.NewInt(0).SetBytes(res.Ret)
return version, nil
}

// queryLiquidInfrastructureThresholds is used by the module to control liquid infrastructure account balances, it calls the
// LiquidInfrastructureNFT getThresholds() function and formats the output into a useable type
func (k Keeper) queryLiquidInfrastructureThresholds(ctx sdk.Context, nftAddress common.Address) ([]types.LiquidAccountThreshold, error) {
Expand Down
1 change: 1 addition & 0 deletions x/microtx/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ var (
ErrNoLiquidAccount = sdkerrors.Register(ModuleName, 3, "account is not a liquid infrastructure account")
ErrInvalidThresholds = sdkerrors.Register(ModuleName, 4, "invalid liquid infrastructure account thresholds")
ErrInvalidMicrotx = sdkerrors.Register(ModuleName, 5, "invalid microtx")
ErrInvalidContract = sdkerrors.Register(ModuleName, 6, "invalid contract")
)

0 comments on commit 1d70b58

Please sign in to comment.