Skip to content

Commit

Permalink
[KRYS-1496] NFT contracts support (#33)
Browse files Browse the repository at this point in the history
* 1st draft of NFT contracts

* use upgradable

* upgradable NFT contract and added proxy multisig

* add staging nft contract

* minor

* redeploy to ropsten
  • Loading branch information
Jarvis authored Sep 13, 2021
1 parent 1230b35 commit c8be582
Show file tree
Hide file tree
Showing 12 changed files with 452 additions and 168 deletions.
4 changes: 2 additions & 2 deletions cmd.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

usage="yarn <deploy,test> [-h] [-c <eth,bsc,polygon>] [-n <mainnet,testnet,ropsten,rinkeby>] -- to run test on specific chain and network
usage="yarn <deploy,test> [-h] [-c <eth,bsc,polygon>] [-n <mainnet,testnet,ropsten,rinkeby,staging>] -- to run test on specific chain and network
where:
-h show this help text
Expand All @@ -27,7 +27,7 @@ while getopts ":hc:n:f:x:" option; do
fi
CHAIN=$OPTARG;;
n)
if [[ ! "$OPTARG" =~ ^(mainnet|ropsten|rinkeby|testnet|mumbai)$ ]]; then
if [[ ! "$OPTARG" =~ ^(mainnet|ropsten|rinkeby|testnet|mumbai|staging)$ ]]; then
printf "invalid value for -%s\n" "$option" >&2
echo "$usage" >&2
exit 1
Expand Down
16 changes: 13 additions & 3 deletions contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
},
"lendingContracts": {
"compoundLending": "0x6deaAe9d76991db2943064Bca84e00f63c46C0A3"
}
},
"nft": "0x9e81428F5672EDCea83F5bf58b6B2cD968df8EE6",
"nftImplementation": "0x029B41cD39Ccb4131807AaB24C2ae5c948Da56f9"
},
"bsc_staging": {
"nft": "0x0993A84E5bdad44f2Cb49C8eB8CEC81Bc8791d6B",
"nftImplementation": "0xfd5904626c103A9bE91635DF823B442f0b77EC88"
},
"bsc_testnet": {
"smartWalletImplementation": "0xe66cc698a26a943A6152040662e88b254f9afcAa",
Expand All @@ -33,7 +39,9 @@
},
"lendingContracts": {
"compoundLending": "0xb455810945407Ad3146B74Aa3773df1cDaD61b11"
}
},
"nft": "0x3209286B92060D2f5e88565E7194ccB5aA831606",
"nftImplementation": "0xF7f2964E08A2a2aFA43c70D176b08Af52a75A8A3"
},
"eth_mainnet": {
"smartWalletImplementation": "0x95ceC39Aa053C62d1A49D88B60620a489C241F53",
Expand Down Expand Up @@ -75,7 +83,9 @@
},
"lendingContracts": {
"compoundLending": "0x60fc810EA972809d729FCE0043B82a58766596ee"
}
},
"nft": "0x3209286B92060D2f5e88565E7194ccB5aA831606",
"nftImplementation": "0xF7f2964E08A2a2aFA43c70D176b08Af52a75A8A3"
},
"polygon_mainnet": {
"smartWalletImplementation": "0x867eB83fEe136Be5b35d3554C89eC75D79737368",
Expand Down
13 changes: 13 additions & 0 deletions contracts/nft/KrystalCollectibles.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "./KrystalCollectiblesStorage.sol";
import "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol";

contract KrystalCollectibles is TransparentUpgradeableProxy {
constructor(
address _logic,
address _admin,
bytes memory _data
) TransparentUpgradeableProxy(_logic, _admin, _data) {}
}
36 changes: 36 additions & 0 deletions contracts/nft/KrystalCollectiblesImpl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "./KrystalCollectiblesStorage.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract KrystalCollectiblesImpl is KrystalCollectiblesStorage {
using Strings for uint256;

function initialize(
string memory _name,
string memory _symbol,
string memory _uri
) public initializer {
super.initialize(_uri);
name = _name;
symbol = _symbol;
tokenUriPrefix = _uri;
}

// Overriding original ERC-1155 format
function uri(uint256 tokenId) external view override returns (string memory) {
return string(abi.encodePacked(tokenUriPrefix, tokenId.toString()));
}

// ERC-721 Compatible
function tokenUri(uint256 tokenId) external view returns (string memory) {
return string(abi.encodePacked(tokenUriPrefix, tokenId.toString()));
}

function setURI(string memory newuri) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "setURI: admin required");
super._setURI(newuri);
tokenUriPrefix = newuri;
}
}
11 changes: 11 additions & 0 deletions contracts/nft/KrystalCollectiblesStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts-upgradeable/presets/ERC1155PresetMinterPauserUpgradeable.sol";

contract KrystalCollectiblesStorage is ERC1155PresetMinterPauserUpgradeable, ReentrancyGuard {
string public name;
string public symbol;
string public tokenUriPrefix;
}
10 changes: 9 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ if (PRIVATE_KEY) {
timeout: 20000,
gasPrice: 5 * 1e9,
};

config.networks!.bsc_staging = {
url: 'https://bsc-dataseed.binance.org/',
chainId: 56,
accounts: [PRIVATE_KEY],
timeout: 20000,
gasPrice: 5 * 1e9,
};
}

if (PRIVATE_KEY && INFURA_API_KEY) {
Expand Down Expand Up @@ -155,7 +163,7 @@ if (PRIVATE_KEY && INFURA_API_KEY) {
chainId: 3,
accounts: [PRIVATE_KEY],
timeout: 20000,
gasPrice: 80 * 1e9,
gasPrice: 15 * 1e9,
};

config.networks!.eth_mainnet = {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
"dependencies": {
"@kyber.network/utils-sc": "^2.2.1",
"@openzeppelin/contracts": "^3.4.1",
"@openzeppelin/contracts-upgradeable": "^3.4.1",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"@uniswap/v3-periphery": "^1.1.0",
"dotenv": "^10.0.0",
"solc": "0.7.6"
},
"devDependencies": {
"@gnosis.pm/safe-core-sdk": "^0.2.0",
"@gnosis.pm/safe-core-sdk": "^0.3.1",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
Expand Down
40 changes: 39 additions & 1 deletion scripts/config_bsc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {commonPlatformWallets, IConfig} from './config_utils';
import {commonNftConfig, commonPlatformWallets, IConfig} from './config_utils';

export const BscConfig: Record<string, IConfig> = {
bsc_mainnet: {
Expand Down Expand Up @@ -35,6 +35,35 @@ export const BscConfig: Record<string, IConfig> = {

supportedWallets: commonPlatformWallets,
fundedAmount: 10, // swap 10 bnb each for every token

nft: {
...commonNftConfig,
uri: 'https://api.krystal.app/bsc/nft/',
name: 'Krystal Collectibles',
},

proxyAdminMultisig: '0xD84f47F60F518C37a07FC7371aC1438F989aE7dc',
maintainerMultisig: '0x5dCB1EFD48AB4927EA9F801bdC0848bE72d23082',
},

bsc_staging: {
disableProxy: true,
autoVerifyContract: true,
tokens: [
{symbol: 'busd', address: '0xe9e7cea3dedca5984780bafc599bd69add087d56'},
{symbol: 'dai', address: '0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3'},
],
wNative: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',

supportedWallets: commonPlatformWallets,

nft: {
...commonNftConfig,
uri: 'https://dev-krystal-api.knstats.com/bsc/nft/',
name: 'Krystal Collectibles Staging',
},

proxyAdminMultisig: '0xD84f47F60F518C37a07FC7371aC1438F989aE7dc',
},

bsc_testnet: {
Expand All @@ -61,5 +90,14 @@ export const BscConfig: Record<string, IConfig> = {
cTokens: [],
},
supportedWallets: commonPlatformWallets,

nft: {
...commonNftConfig,
uri: 'https://staging-krystal-api.knstats.com/bsc/nft/',
name: 'Krystal Collectibles Test',
},

// This is the mainnet one as gnosis doesnt support bsc-testnet, but it doesnt matter on testnet anw
proxyAdminMultisig: '0xD84f47F60F518C37a07FC7371aC1438F989aE7dc',
},
};
14 changes: 13 additions & 1 deletion scripts/config_eth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {commonPlatformWallets, IConfig} from './config_utils';
import {commonNftConfig, commonPlatformWallets, IConfig} from './config_utils';

export const EthConfig: Record<string, IConfig> = {
eth_mainnet: {
Expand Down Expand Up @@ -299,6 +299,14 @@ export const EthConfig: Record<string, IConfig> = {

supportedWallets: commonPlatformWallets,
fundedAmount: 5, // swap 5 eth each for every token

nft: {
...commonNftConfig,
uri: 'https://dev-krystal-api.knstats.com/ropsten/nft/',
name: 'Krystal Collectibles Test',
},

proxyAdminMultisig: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
},

eth_rinkeby: {
Expand All @@ -317,5 +325,9 @@ export const EthConfig: Record<string, IConfig> = {

supportedWallets: commonPlatformWallets,
fundedAmount: 5, // swap 5 eth each for every token

nft: {
...commonNftConfig,
},
},
};
24 changes: 24 additions & 0 deletions scripts/config_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,34 @@ export interface IConfig {

supportedWallets: string[];
fundedAmount?: number;

nft?: {
enabled?: boolean;
name: string;
symbol: string;
uri: string;
};

// For proxy admin
proxyAdminMultisig?: string;
// For managing the config and admin jobs
adminMultisig?: string;
// For maintaining, minting and some executing jobs
maintainerMultisig?: string;

// For staging contracts, which doesn't need a full settings
disableProxy?: boolean;
}

export const commonPlatformWallets = [
'0xa1738F8DD7c42cd4175CcdCa79Af89b3EC7b68E9', // android
'0x5250b8202AEBca35328E2c217C687E894d70Cd31', // ios
'0x168E4c3AC8d89B00958B6bE6400B066f0347DDc9', // web
];

export const commonNftConfig = {
enabled: true,
name: 'Krystal Collectibles',
symbol: 'KRYS',
uri: 'https://api.krystal.app/ethereum/nft/',
};
Loading

0 comments on commit c8be582

Please sign in to comment.