Skip to content

Commit

Permalink
closes #211
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeard002 committed May 13, 2024
1 parent e1832ed commit bb4b941
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
19 changes: 17 additions & 2 deletions scripts/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ async function main() {
/// @dev This is the list of mock deployments addresses that were stored in the `.env` file.
const ERC20_ADDRESS = process.env.ERC20_ADDRESS || 0x0;
const ERC721_ADDRESS = process.env.ERC721_ADDRESS || 0x0;
const ERC1155_ADDRESS = process.env.ERC1155_ADDRESS || 0x0;
/// @dev The Swaplace address also needs to be instance to receive the approvals.
const SWAPLACE_ADDRESS = process.env.SWAPLACE_ADDRESS || 0x0;
/// @dev Will throw an error if any of the addresses were not set in the `.env` file.
if (!ERC20_ADDRESS || !ERC721_ADDRESS || !SWAPLACE_ADDRESS) {
if (
!ERC20_ADDRESS ||
!ERC721_ADDRESS ||
!SWAPLACE_ADDRESS ||
!ERC1155_ADDRESS
) {
throw new Error(
"Invalid ERC20, ERC721 or Swaplace address, please check if the addresse in the `.env` file is set up correctly.",
"Invalid ERC20, ERC721, ERC1155 or Swaplace address, please check if the addresse in the `.env` file is set up correctly.",
);
}

Expand All @@ -39,6 +45,7 @@ async function main() {
/// @dev The returned contract instance that will be deployed via the deploy function in utils.
let MockERC20: Contract;
let MockERC721: Contract;
let MockERC1155: Contract;

/// @dev will throw an error if any of the accounts was not set up correctly.
try {
Expand All @@ -63,6 +70,11 @@ async function main() {
ERC721_ADDRESS,
signers[0],
);
MockERC1155 = await ethers.getContractAt(
"MockERC1155",
ERC1155_ADDRESS,
signers[0],
);
} catch (error) {
throw new Error(
`Error deploying one of the Mock Contracts.
Expand All @@ -76,11 +88,13 @@ async function main() {
/// @dev Responses from the minting transactions.
let txErc20;
let txErc721;
let txErc1155;

/// @dev We are approving the signer address to spend the amount of tokens.
try {
txErc20 = await MockERC20.approve(SWAPLACE_ADDRESS, amount);
txErc721 = await MockERC721.approve(SWAPLACE_ADDRESS, tokenId);
txErc1155 = await MockERC1155.setApprovalForAll(SWAPLACE_ADDRESS, true);
} catch (error) {
throw new Error(
`Error while approving the tokens. Make sure that the approve function is
Expand All @@ -97,6 +111,7 @@ async function main() {
tokenId,
txErc721.hash,
);
console.log("\nERC1155 Approved all tokens \nAt Tx %s", txErc1155.hash);
}

main().catch((error) => {
Expand Down
20 changes: 18 additions & 2 deletions scripts/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ async function main() {
/// @dev This is the list of mock deployments addresses that were stored in the `.env` file.
const ERC20_ADDRESS = process.env.ERC20_ADDRESS || 0x0;
const ERC721_ADDRESS = process.env.ERC721_ADDRESS || 0x0;
const ERC1155_ADDRESS = process.env.ERC1155_ADDRESS || 0x0;
/// @dev Will throw an error if any of the addresses were not set in the `.env` file.
if (!ERC20_ADDRESS || !ERC721_ADDRESS) {
if (!ERC20_ADDRESS || !ERC721_ADDRESS || !ERC1155_ADDRESS) {
throw new Error(
"Invalid ERC20 or ERC721 address, please check if the addresse in the `.env` file is set up correctly.",
"Invalid ERC20 or ERC721 or ERC1155 address, please check if the addresses in the `.env` file are set up correctly.",
);
}

Expand All @@ -25,6 +26,7 @@ async function main() {
/// @dev The returned contract instance that will be deployed via the deploy function in utils.
let MockERC20: Contract;
let MockERC721: Contract;
let MockERC1155: Contract;

/// @dev will throw an error if any of the accounts was not set up correctly.
try {
Expand All @@ -49,6 +51,11 @@ async function main() {
ERC721_ADDRESS,
signers[0],
);
MockERC1155 = await ethers.getContractAt(
"MockERC1155",
ERC1155_ADDRESS,
signers[0],
);
} catch (error) {
throw new Error(
`Error deploying one of the Mock Contracts.
Expand All @@ -69,6 +76,7 @@ async function main() {
/// @dev Responses from the minting transactions.
let txErc20;
let txErc721;
let txErc1155;

/// @dev Minting function will throw an error if the minting fails.
/// We are minting for the first signer of `hardhat.config.ts` 1000
Expand All @@ -77,6 +85,7 @@ async function main() {
try {
txErc20 = await MockERC20.mint(signers[0].address, amount);
txErc721 = await MockERC721.mint(signers[0].address, tokenId);
txErc1155 = await MockERC1155.mint(signers[0].address, tokenId, amount);
} catch (error) {
throw new Error(
`Error while minting tokens. Make sure that the minting function is
Expand All @@ -93,12 +102,19 @@ async function main() {
tokenId,
txErc721.hash,
);
console.log(
"\nERC1155 Minted %s tokens with ID #%s \nAt Tx %s",
amount,
tokenId,
txErc1155.hash,
);

await storeEnv(tokenId, "TOKEN_ID", false);

/// @dev Awaits for the transaction to be mined.
await txErc20.wait();
await txErc721.wait();
await txErc1155.wait();
}

main().catch((error) => {
Expand Down

0 comments on commit bb4b941

Please sign in to comment.