Skip to content

Commit

Permalink
Merge branch 'master' into guaranteed_options
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Myers authored May 9, 2020
2 parents 02e1660 + a5ed296 commit 863984e
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 129 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules/
*-error.log
.idea/
yarn.lock
package-lock.json
9 changes: 7 additions & 2 deletions contracts/MyCollectible.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import "./ERC1155Tradable.sol";
* MyCollectible - a contract for my semi-fungible tokens.
*/
contract MyCollectible is ERC1155Tradable {
constructor(address _proxyRegistryAddress) ERC1155Tradable(
constructor(address _proxyRegistryAddress)
ERC1155Tradable(
"MyCollectible",
"MCB",
_proxyRegistryAddress
) public {
_setBaseMetadataURI("https://opensea-creatures-api.herokuapp.com/api/creature/");
_setBaseMetadataURI("https://creatures-api.opensea.io/api/creature/");
}

function contractURI() public view returns (string memory) {
return "https://creatures-api.opensea.io/contract/opensea-erc1155";
}
}
2 changes: 1 addition & 1 deletion contracts/MyLootBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ contract MyLootBox is ILootBox, Ownable, Pausable, ReentrancyGuard, MyFactory {
uint256 _optionId,
address _toAddress,
uint256 _amount
) external {
) external onlyOwner {
_mint(Option(_optionId), _toAddress, _amount, "");
}

Expand Down
2 changes: 1 addition & 1 deletion migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(deployer, network) {
}

if (!ENABLE_LOOTBOX) {
deployer.deploy(MyCollectible, proxyRegistryAddress, {gas: 5000000});
deployer.deploy(MyCollectible, proxyRegistryAddress, {gas: 5000000});
} else if (NFT_ADDRESS_TO_USE) {
deployer.deploy(MyLootBox, proxyRegistryAddress, NFT_ADDRESS_TO_USE, {gas: 5000000})
.then(setupLootbox);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@0x/subproviders": "^2.1.4",
"multi-token-standard": "github:ProjectOpenSea/multi-token-standard",
"opensea-js": "latest",
"opensea-js": "^1.1.5",
"openzeppelin-solidity": "^2.1.3",
"truffle": "^5.1.12",
"truffle-assertions": "^0.9.2",
Expand Down
79 changes: 27 additions & 52 deletions scripts/advanced/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,57 @@ const web3 = require('web3')
const MNEMONIC = process.env.MNEMONIC
const INFURA_KEY = process.env.INFURA_KEY
const FACTORY_CONTRACT_ADDRESS = process.env.FACTORY_CONTRACT_ADDRESS
const NFT_CONTRACT_ADDRESS = process.env.NFT_CONTRACT_ADDRESS
const OWNER_ADDRESS = process.env.OWNER_ADDRESS
const NETWORK = process.env.NETWORK
const NUM_CREATURES = 12
const NUM_LOOTBOXES = 4
const DEFAULT_OPTION_ID = 0
const LOOTBOX_OPTION_ID = 2

if (!MNEMONIC || !INFURA_KEY || !OWNER_ADDRESS || !NETWORK) {
console.error("Please set a mnemonic, infura key, owner, network, and contract address.")
return
}

const NFT_ABI = [{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
}
],
"name": "mintTo",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}]

const FACTORY_ABI = [{
"constant": false,
"inputs": [
{
"name": "_optionId",
"type": "uint256"
},
{
"name": "_toAddress",
"type": "address"
}
{
"internalType": "uint256",
"name": "_optionId",
"type": "uint256"
},
{
"internalType": "address",
"name": "_toAddress",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "mint",
"name": "open",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}]

/**
* For now, this script just opens a lootbox.
*/
async function main() {
const provider = new HDWalletProvider(MNEMONIC, `https://${NETWORK}.infura.io/v3/${INFURA_KEY}`)
const web3Instance = new web3(
provider
)

if (NFT_CONTRACT_ADDRESS) {
const nftContract = new web3Instance.eth.Contract(NFT_ABI, NFT_CONTRACT_ADDRESS, { gasLimit: "1000000" })

// Creatures issued directly to the owner.
for (var i = 0; i < NUM_CREATURES; i++) {
const result = await nftContract.methods.mintTo(OWNER_ADDRESS).send({ from: OWNER_ADDRESS });
console.log("Minted creature. Transaction: " + result.transactionHash)
}
} else if (FACTORY_CONTRACT_ADDRESS) {
const factoryContract = new web3Instance.eth.Contract(FACTORY_ABI, FACTORY_CONTRACT_ADDRESS, { gasLimit: "1000000" })

// Creatures issued directly to the owner.
for (var i = 0; i < NUM_CREATURES; i++) {
const result = await factoryContract.methods.mint(DEFAULT_OPTION_ID, OWNER_ADDRESS).send({ from: OWNER_ADDRESS });
console.log("Minted creature. Transaction: " + result.transactionHash)
}

// Lootboxes issued directly to the owner.
for (var i = 0; i < NUM_LOOTBOXES; i++) {
const result = await factoryContract.methods.mint(LOOTBOX_OPTION_ID, OWNER_ADDRESS).send({ from: OWNER_ADDRESS });
console.log("Minted lootbox. Transaction: " + result.transactionHash)
}
if (!FACTORY_CONTRACT_ADDRESS) {
console.error("Please set an NFT contract address.")
return
}

const factoryContract = new web3Instance.eth.Contract(FACTORY_ABI, FACTORY_CONTRACT_ADDRESS, { gasLimit: "1000000" })
const result = await factoryContract.methods.open(0, OWNER_ADDRESS, 1).send({ from: OWNER_ADDRESS });
console.log("Created. Transaction: " + result.transactionHash)
}

main()
main()
41 changes: 9 additions & 32 deletions scripts/initial_sale.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,44 +50,21 @@ async function main() {
const optionId = FIXED_PRICE_OPTION_IDS[i];
console.log(`Creating fixed price auctions for ${optionId}...`)
const numOrders = await seaport.createFactorySellOrders({
assetId: optionId,
factoryAddress: FACTORY_CONTRACT_ADDRESS,
assets: [{
tokenId: optionId,
tokenAddress: FACTORY_CONTRACT_ADDRESS,
// Comment the next line if this is an ERC-721 asset (defaults to ERC721):
schemaName: WyvernSchemaName.ERC1155
}],
// Quantity of each asset to issue
quantity: 1,
accountAddress: OWNER_ADDRESS,
startAmount: FIXED_PRICES_ETH[i],
numberOfOrders: NUM_FIXED_PRICE_AUCTIONS[i],
schemaName: WyvernSchemaName.ERC1155
// Number of times to repeat creating the same order for each asset. If greater than 5, creates them in batches of 5. Requires an `apiKey` to be set during seaport initialization:
numberOfOrders: NUM_FIXED_PRICE_AUCTIONS[i]
})
console.log(`Successfully made ${numOrders} fixed-price sell orders!\n`)
}
/*
// Example: many fixed price auctions for multiple factory options.
console.log("Creating fixed price auctions...")
const fixedSellOrders = await seaport.createFactorySellOrders({
assetIds: FIXED_PRICE_OPTION_IDS,
factoryAddress: FACTORY_CONTRACT_ADDRESS,
accountAddress: OWNER_ADDRESS,
startAmount: FIXED_PRICE,
numberOfOrders: NUM_FIXED_PRICE_AUCTIONS
})
console.log(`Successfully made ${fixedSellOrders.length} fixed-price sell orders for multiple assets at once! ${fixedSellOrders[0].asset.openseaLink}\n`)
// Example: many declining Dutch auction for a factory.
console.log("Creating dutch auctions...")
// Expire one day from now
const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24)
const dutchSellOrders = await seaport.createFactorySellOrders({
assetId: DUTCH_AUCTION_OPTION_ID,
factoryAddress: FACTORY_CONTRACT_ADDRESS,
accountAddress: OWNER_ADDRESS,
startAmount: DUTCH_AUCTION_START_AMOUNT,
endAmount: DUTCH_AUCTION_END_AMOUNT,
expirationTime: expirationTime,
numberOfOrders: NUM_DUTCH_AUCTIONS
})
console.log(`Successfully made ${dutchSellOrders.length} Dutch-auction sell orders! ${dutchSellOrders[0].asset.openseaLink}\n`)
*/
}

main().catch(e => console.error(e))
23 changes: 15 additions & 8 deletions scripts/sell.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ async function main() {
// Example: simple fixed-price sale of an item owned by a user.
console.log("Auctioning an item for a fixed price...")
const fixedPriceSellOrder = await seaport.createSellOrder({
tokenId: "1",
tokenAddress: NFT_CONTRACT_ADDRESS,
asset: {
tokenId: "1",
tokenAddress: NFT_CONTRACT_ADDRESS,
schemaName: WyvernSchemaName.ERC1155
},
startAmount: .05,
expirationTime: 0,
accountAddress: OWNER_ADDRESS,
schemaName: WyvernSchemaName.ERC1155,
})
console.log(`Successfully created a fixed-price sell order! ${fixedPriceSellOrder.asset.openseaLink}\n`)

// // Example: Dutch auction.
console.log("Dutch auctioning an item...")
const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24)
const dutchAuctionSellOrder = await seaport.createSellOrder({
tokenId: "2",
tokenAddress: NFT_CONTRACT_ADDRESS,
asset: {
tokenId: "2",
tokenAddress: NFT_CONTRACT_ADDRESS,
schemaName: WyvernSchemaName.ERC1155
},
startAmount: .05,
endAmount: .01,
expirationTime: expirationTime,
Expand All @@ -72,14 +77,16 @@ async function main() {
console.log("Selling multiple items for an ERC20 token (WETH)")
const wethAddress = NETWORK == 'mainnet' ? '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' : "0xc778417e063141139fce010982780140aa0cd5ab"
const englishAuctionSellOrder = await seaport.createSellOrder({
tokenId: "3",
tokenAddress: NFT_CONTRACT_ADDRESS,
asset: {
tokenId: "3",
tokenAddress: NFT_CONTRACT_ADDRESS,
schemaName: WyvernSchemaName.ERC1155
},
startAmount: .03,
quantity: 2,
expirationTime: expirationTime,
paymentTokenAddress: wethAddress,
accountAddress: OWNER_ADDRESS,
schemaName: WyvernSchemaName.ERC1155,
})
console.log(`Successfully created bulk-item sell order! ${englishAuctionSellOrder.asset.openseaLink}\n`)

Expand Down
2 changes: 2 additions & 0 deletions test/ERC1155Tradable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const truffleAssert = require('truffle-assertions');


const vals = require('../lib/testValuesCommon.js');


Expand Down Expand Up @@ -194,6 +195,7 @@ contract("ERC1155Tradable - ERC 1155", (accounts) => {
// Use the hand-crafted accessor
const supplyAccessorValue = await instance.totalSupply(tokenId);
assert.ok(supplyAccessorValue.eq(MINT_AMOUNT));

// Make explicitly sure everything mateches
assert.ok(supplyGetterValue.eq(balance));
assert.ok(supplyAccessorValue.eq(balance));
Expand Down
24 changes: 24 additions & 0 deletions test/MyCollectible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Contracts in this test */

const MyCollectible = artifacts.require("../contracts/MyCollectible.sol");


contract("MyCollectible", (accounts) => {
const URI_BASE = 'https://creatures-api.opensea.io';
const CONTRACT_URI = `${URI_BASE}/contract/opensea-erc1155`;
let myCollectible;

before(async () => {
myCollectible = await MyCollectible.deployed();
});

// This is all we test for now

// This also tests contractURI()

describe('#constructor()', () => {
it('should set the contractURI to the supplied value', async () => {
assert.equal(await myCollectible.contractURI(), CONTRACT_URI);
});
});
});
Loading

0 comments on commit 863984e

Please sign in to comment.