From cbdc763fc4f151706083eddc9b6493ca969e64c9 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 30 Apr 2024 19:00:26 -0300 Subject: [PATCH] Scripts --- .../02-create-rental-offer.ts | 9 +++-- .../03-accept-rental-offer.ts | 36 +++++++++++++++++++ .../04-cancel-rental-offer.ts | 35 ++++++++++++++++++ utils/roles.ts | 1 + 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 scripts/nft-rental-marketplace/03-accept-rental-offer.ts create mode 100644 scripts/nft-rental-marketplace/04-cancel-rental-offer.ts diff --git a/scripts/nft-rental-marketplace/02-create-rental-offer.ts b/scripts/nft-rental-marketplace/02-create-rental-offer.ts index 736a742..74dd74c 100644 --- a/scripts/nft-rental-marketplace/02-create-rental-offer.ts +++ b/scripts/nft-rental-marketplace/02-create-rental-offer.ts @@ -1,10 +1,9 @@ -import { ZeroAddress } from 'ethers' import { print, colors } from '../../utils/misc' import { callContractFunction } from '../../utils/write-contract' import { randomBytes } from 'crypto' import { etherPerDayToWeiPerSecond } from '../../utils/bignumber' import { EMPTY_BYTES, ONE_DAY } from '../../utils/constants' -import { USER_ROLE } from '../../utils/roles' +import { USER_ROLE_MOONBEAM } from '../../utils/roles' import { ethers } from 'hardhat' import { RentalOffer } from '../../utils/types' @@ -16,14 +15,14 @@ async function main() { const RENTAL_OFFER: RentalOffer = { nonce: `0x${randomBytes(32).toString('hex')}`, lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', - borrower: ZeroAddress, + borrower: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', tokenId: 1994, tokenAddress: '0xcb13945ca8104f813992e4315f8ffefe64ac49ca', // GLMR jungle address feeTokenAddress: '0xd10078fdbc835726c79533a4a19db40cfad69d7f', // GLMB address - feeAmountPerSecond: etherPerDayToWeiPerSecond('0.01'), + feeAmountPerSecond: etherPerDayToWeiPerSecond('0'), deadline: blockTimestamp + ONE_DAY, minDuration: 0, - roles: [USER_ROLE], + roles: [USER_ROLE_MOONBEAM], rolesData: [EMPTY_BYTES], } await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, [RENTAL_OFFER]) diff --git a/scripts/nft-rental-marketplace/03-accept-rental-offer.ts b/scripts/nft-rental-marketplace/03-accept-rental-offer.ts new file mode 100644 index 0000000..7997a54 --- /dev/null +++ b/scripts/nft-rental-marketplace/03-accept-rental-offer.ts @@ -0,0 +1,36 @@ +import { print, colors } from '../../utils/misc' +import { callContractFunction } from '../../utils/write-contract' +import { etherPerDayToWeiPerSecond } from '../../utils/bignumber' +import { EMPTY_BYTES, ONE_DAY } from '../../utils/constants' +import { USER_ROLE_MOONBEAM } from '../../utils/roles' +import { RentalOffer } from '../../utils/types' + +const CONTRACT_NAME = 'NftRentalMarketplace' +const CONTRACT_FUNCTION = 'acceptRentalOffer' + +async function main() { + const RENTAL_OFFER: RentalOffer = { + nonce: '115457453593754985652281111685552019968813348573560119211069111442109350087626', + lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', + borrower: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', + tokenId: 1994, + tokenAddress: '0xcb13945ca8104f813992e4315f8ffefe64ac49ca', // GLMR jungle address + feeTokenAddress: '0xd10078fdbc835726c79533a4a19db40cfad69d7f', // GLMB address + feeAmountPerSecond: etherPerDayToWeiPerSecond('0'), + deadline: 1714599894, + minDuration: 0, + roles: [USER_ROLE_MOONBEAM], + rolesData: [EMPTY_BYTES], + } + const DURATION = ONE_DAY / 2 + await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, [RENTAL_OFFER, DURATION]) +} + +main() + .then(() => { + print(colors.bigSuccess, 'All done!') + }) + .catch(error => { + console.error(error) + process.exitCode = 1 + }) diff --git a/scripts/nft-rental-marketplace/04-cancel-rental-offer.ts b/scripts/nft-rental-marketplace/04-cancel-rental-offer.ts new file mode 100644 index 0000000..d0a3896 --- /dev/null +++ b/scripts/nft-rental-marketplace/04-cancel-rental-offer.ts @@ -0,0 +1,35 @@ +import { print, colors } from '../../utils/misc' +import { callContractFunction } from '../../utils/write-contract' +import { etherPerDayToWeiPerSecond } from '../../utils/bignumber' +import { EMPTY_BYTES } from '../../utils/constants' +import { USER_ROLE_MOONBEAM } from '../../utils/roles' +import { RentalOffer } from '../../utils/types' + +const CONTRACT_NAME = 'NftRentalMarketplace' +const CONTRACT_FUNCTION = 'cancelRentalOffer' + +async function main() { + const RENTAL_OFFER: RentalOffer = { + nonce: '41073076454465649804684789998370311225937584494094599799884085085462612297440', + lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', + borrower: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', + tokenId: 1994, + tokenAddress: '0xcb13945ca8104f813992e4315f8ffefe64ac49ca', // GLMR jungle address + feeTokenAddress: '0xd10078fdbc835726c79533a4a19db40cfad69d7f', // GLMB address + feeAmountPerSecond: etherPerDayToWeiPerSecond('0'), + deadline: 1714599360, + minDuration: 0, + roles: [USER_ROLE_MOONBEAM], + rolesData: [EMPTY_BYTES], + } + await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, [RENTAL_OFFER]) +} + +main() + .then(() => { + print(colors.bigSuccess, 'All done!') + }) + .catch(error => { + console.error(error) + process.exitCode = 1 + }) diff --git a/utils/roles.ts b/utils/roles.ts index 711a0a4..97a53e9 100644 --- a/utils/roles.ts +++ b/utils/roles.ts @@ -3,5 +3,6 @@ import { ethers } from 'hardhat' export const abi = AbiCoder.defaultAbiCoder() export const USER_ROLE = ethers.keccak256(ethers.toUtf8Bytes('USER_ROLE')) +export const USER_ROLE_MOONBEAM = ethers.keccak256(ethers.toUtf8Bytes('User()')) export const UNIQUE_ROLE = ethers.keccak256(ethers.toUtf8Bytes('UNIQUE_ROLE')) export const PLAYER_ROLE = ethers.keccak256(ethers.toUtf8Bytes('Player()'))