Phase 3 - Rent Pallet #91
Replies: 1 comment
-
Rent Pallet v2.0.0Second version of the Rent Pallet : Global changes :
Events2 Updated :/// Contract Created.
ContractCreated {
nft_id: NFTId,
renter: T::AccountId,
duration: Duration<T::BlockNumber>,
acceptance_type: AcceptanceType<AccountList<T::AccountId, T::AccountSizeLimit>>,
renter_can_revoke: bool,
rent_fee: RentFee<BalanceOf<T>>,
renter_cancellation_fee: Option<CancellationFee<BalanceOf<T>>>,
rentee_cancellation_fee: Option<CancellationFee<BalanceOf<T>>>,
},
/// A contract subscription's terms were changed by renter.
ContractSubscriptionTermsChanged {
nft_id: NFTId,
period: T::BlockNumber,
max_duration: Option<T::BlockNumber>,
rent_fee: BalanceOf<T>,
}, 1 Added/// Contract was canceled.
ContractCanceled { nft_id: NFTId }, Impact on SDK eventsAdditional events will be added to the EventType enum in src > events.ts in the SDK: export enum EventType {
...
// Rent
// Updated :
ContractCreated = "rent.ContractCreated",
ContractSubscriptionTermsChanged = "rent.ContractSubscriptionTermsChanged",
// New :
ContractCanceled = "rent.ContractCanceled",
}
static fromEvent(event: Event): BlockchainEvent {
...
switch (name) {
...
// Rent
// Updated :
case EventType.ContractCreated:
return new ContractCreatedEvent(event)
case EventType.ContractSubscriptionTermsChanged:
return new ContractSubscriptionTermsChangedEvent(event)
//New :
case EventType.ContractCanceled:
return new ContractCanceledEvent(event)
}
...
}
}
/**
* This class represents the on-chain ContractCreatedEvent event.
*/
export class ContractCreatedEvent extends BlockchainEvent {
nftId: number
renter: string
durationType?: string
blockDuration?: number | null
blockSubscriptionRenewal?: number | null
acceptanceType?: string
acceptanceList?: string[]
renterCanRevoke?: boolean
rentFeeType?: string
rentFee?: string | number
rentFeeRounded?: number
renterCancellationFeeType?: string | null
renterCancellationFee?: string | number | null
renterCancellationFeeRounded?: number | null
renteeCancellationFeeType?: string | null
renteeCancellationFee?: string | number | null
renteeCancellationFeeRounded?: number | null
/**
* Construct the data object from the ContractCreatedEvent event
* @param event The ContractCreatedEvent event
*/
constructor(event: Event) {
super(event, EventType.ContractCreated)
const [
nftId,
renter,
duration,
acceptanceType,
renterCanRevoke,
rentFee,
renterCancellationFee,
renteeCancellationFee,
] = event.data
const parsedDuration = JSON.parse(duration.toString())
const isDurationFixed = parsedDuration.Fixed
const isDurationSubscription = parsedDuration.Subscription
const parsedAcceptance = JSON.parse(acceptanceType.toString())
const isAutoAcceptance = parsedAcceptance.AutoAcceptance
// const isrevocationTypeNoRevocation = revocationType.toString() === RevocationAction.NoRevocation
// const isrevocationTypeOnSubscriptionChange = revocationType.toString() === RevocationAction.OnSubscriptionChange
const parsedRentFee = JSON.parse(rentFee.toString())
const isRentFeeToken = parsedRentFee.Token
const parsedRenterCancellationFee = renterCancellationFee && JSON.parse(renterCancellationFee.toString())
const isRenterCancellationFeeFixed = parsedRenterCancellationFee.FixedTokens
const isRenterCancellationFeeFlexible = parsedRenterCancellationFee.FlexibleTokens
const parsedRenteeCancellationFee = renteeCancellationFee && JSON.parse(renteeCancellationFee.toString())
const isRenteeCancellationFeeFixed = parsedRenteeCancellationFee.FixedTokens
const isRenteeCancellationFeeFlexible = parsedRenteeCancellationFee.FlexibleTokens
this.nftId = Number.parseInt(nftId.toString())
this.renter = renter.toString()
this.durationType = undefined
this.blockDuration = undefined
this.blockSubscriptionRenewal = undefined
this.acceptanceType = undefined
this.acceptanceList = undefined
this.renterCanRevoke = renterCanRevoke
//this.revocationType = undefined
this.rentFeeType = undefined
this.rentFee = undefined
this.rentFeeRounded = undefined
this.renterCancellationFeeType = undefined
this.renterCancellationFee = undefined
this.renterCancellationFeeRounded = undefined
this.renteeCancellationFeeType = undefined
this.renteeCancellationFee = undefined
this.renteeCancellationFeeRounded = undefined
if (isDurationFixed) {
this.durationType = DurationAction.Fixed
this.blockDuration = Number.parseInt(parsedDuration.Fixed.toString())
} else if (isDurationSubscription) {
this.durationType = DurationAction.Subscription
this.blockDuration = Number.parseInt(parsedDuration.Subscription[0].toString())
this.blockSubscriptionRenewal = Number.parseInt(parsedDuration.Subscription[1].toString())
} else {
this.durationType = DurationAction.Infinite
}
if (isAutoAcceptance) {
this.acceptanceType = AcceptanceAction.AutoAcceptance
this.acceptanceList = []
parsedAcceptance.AutoAcceptance.map((account: string) => this.acceptanceList?.push(account.toString()))
} else {
this.acceptanceType = AcceptanceAction.ManualAcceptance
this.acceptanceList = []
parsedAcceptance.ManualAcceptance.map((account: string) => this.acceptanceList?.push(account.toString()))
}
// if (isrevocationTypeNoRevocation) {
// this.revocationType = RevocationAction.NoRevocation
// } else if (isrevocationTypeOnSubscriptionChange) {
// this.revocationType = RevocationAction.OnSubscriptionChange
// } else {
// this.revocationType = RevocationAction.Anytime
// }
if (isRentFeeToken) {
this.rentFeeType = RentFeeAction.Tokens
this.rentFee = bnToBn(isRentFeeToken).toString()
this.rentFeeRounded = roundBalance(this.rentFee)
} else {
this.rentFeeType = RentFeeAction.NFT
this.rentFee = Number.parseInt(parsedRentFee.NFT.toString())
this.rentFeeRounded = this.rentFee
}
if (isRenterCancellationFeeFixed) {
this.renterCancellationFeeType = CancellationFeeAction.FixedTokens
this.renterCancellationFee = bnToBn(parsedRenterCancellationFee.FixedTokens).toString()
this.renterCancellationFeeRounded = roundBalance(this.renterCancellationFee)
} else if (isRenterCancellationFeeFlexible) {
this.renterCancellationFeeType = CancellationFeeAction.FlexibleTokens
this.renterCancellationFee = bnToBn(parsedRenterCancellationFee.FlexibleTokens).toString()
this.renterCancellationFeeRounded = roundBalance(this.renterCancellationFee)
} else {
this.renterCancellationFeeType = CancellationFeeAction.NFT
this.renterCancellationFee = Number.parseInt(parsedRenterCancellationFee.NFT.toString())
this.renterCancellationFeeRounded = this.renterCancellationFee
}
if (isRenteeCancellationFeeFixed) {
this.renteeCancellationFeeType = CancellationFeeAction.FixedTokens
this.renteeCancellationFee = bnToBn(parsedRenteeCancellationFee.FixedTokens).toString()
this.renteeCancellationFeeRounded = roundBalance(this.renteeCancellationFee)
} else if (isRenteeCancellationFeeFlexible) {
this.renteeCancellationFeeType = CancellationFeeAction.FlexibleTokens
this.renteeCancellationFee = bnToBn(parsedRenteeCancellationFee.FlexibleTokens).toString()
this.renteeCancellationFeeRounded = roundBalance(this.renteeCancellationFee)
} else {
this.renteeCancellationFeeType = CancellationFeeAction.NFT
this.renteeCancellationFee = Number.parseInt(parsedRenteeCancellationFee.NFT.toString())
this.renteeCancellationFeeRounded = this.renteeCancellationFee
}
}
}
/**
* This class represents the on-chain ContractSubscriptionTermsChangedEvent event.
*/
export class ContractSubscriptionTermsChangedEvent extends BlockchainEvent {
nftId: number
durationType?: string
blockDuration?: number | null
blockSubscriptionRenewal?: number | null
rentFeeType?: string
rentFee?: string | number
rentFeeRounded?: number
/**
* Construct the data object from the ContractSubscriptionTermsChangedEvent event
* @param event The ContractSubscriptionTermsChangedEvent event
*/
constructor(event: Event) {
super(event, EventType.ContractSubscriptionTermsChanged)
const [nftId, duration, rentFee] = event.data
// Received from the chain. Need to log format
// nft_id: number
// period: T::BlockNumber,
// max_duration: Option<T::BlockNumber>,
// rent_fee: BalanceOf<T>,
const parsedDuration = JSON.parse(duration.toString())
const parsedRentFee = JSON.parse(rentFee.toString())
this.nftId = Number.parseInt(nftId.toString())
this.durationType = DurationAction.Subscription
this.blockDuration = Number.parseInt(parsedDuration.subscription[0].toString())
this.blockSubscriptionRenewal =
parsedDuration.subscription[1] && Number.parseInt(parsedDuration.subscription[1].toString())
this.rentFeeType = RentFeeAction.Tokens
this.rentFee = bnToBn(parsedRentFee.tokens).toString()
this.rentFeeRounded = roundBalance(this.rentFee)
}
}
Added :/**
* This class represents the on-chain ContractCanceledEvent event.
*/
export class ContractCanceledEvent extends BlockchainEvent {
nftId: number
/**
* Construct the data object from the ContractCanceledEvent event
* @param event The ContractCanceledEvent event
*/
constructor(event: Event) {
super(event, EventType.ContractCanceled)
const [nftId] = event.data
this.nftId = Number.parseInt(nftId.toString())
}
} Extrinsics3 Updated tx/**
* @name createContractTx
* @summary Creates an unsigned unsubmitted Create-Rent-Contract Transaction Hash for an NFT.
* @param nftId The NFT Id of the contract.
* @param duration The contract duration : Fixed, Subscription
* @param acceptanceType The type of acceptance: automatic or manuall
* @param renterRevoke Set to true if renter can revoke the running contract, and false if he can't.
* @param rentFee The fee to rent the contract: a token amount or an NFT
* @param renterCancellationFee The fee to cancel the contract (due by the renter): FixedTokens amount, FlexibleTokens amount or an NFT
* @param renteeCancellationFee The fee to cancel the contract (due by the rentee): FixedTokens amount, FlexibleTokens amount or an NFT
* @returns Unsigned unsubmitted Create-Rent-Contract Transaction Hash. The Hash is only valid for 5 minutes.
*/
createContractTx(
nftId: number,
duration: DurationType
acceptanceType: AcceptanceType
renterCanRevoke:boolean
rentFee: RentFeeType
renterCancellationFee: CancellationFeeType | null = null
renteeCancellationFee: CancellationFeeType | null = null
)
/**
* @name changeSubscriptionTermsTx
* @summary Creates an unsigned unsubmitted Change-Contract-Subscription-Terms Transaction Hash for an NFT.
* @param nftId The NFT Id of the contract to change the subscription terms.
* @param period tbc
* @param maxDuration tbc
* @param rentFee tbc
* @param changeable tbc
* @returns Unsigned unsubmitted Change-Contract-Subscription-Terms Transaction Hash. The Hash is only valid for 5 minutes.
*/
changeSubscriptionTermsTx(
nft_id: number
period: tbc
maxDuration: tbc
rentFee: tbc
changeable: boolean
)
// Need to update rent tx description as offer are not anymore made from this extrinsic 2 Added tx/**
* @name cancelContractTx
* @summary Creates an unsigned unsubmitted Cancel-Contract Transaction Hash for an NFT.
* @param nftId The NFT Id of the contract to cancel.
* @returns Unsigned unsubmitted Cancel-Contract Transaction Hash. The Hash is only valid for 5 minutes.
*/
cancelContract(nftId: number) => Event : ContractCanceled
/**
* @name makeRentOfferTx
* @summary Creates an unsigned unsubmitted MakeRentOffer-Contract Transaction Hash for an NFT.
* @param nftId The NFT Id of the contract to make an offer on.
* @returns Unsigned unsubmitted MakeRentOffer-Contract Transaction Hash. The Hash is only valid for 5 minutes.
*/
makeRentOffer(nftId: number) => Event : ContractOfferCreated ConstantsNo changes Storage3 remaining storages export enum chainQuery {
...
// rent
contracts = "contracts"
offers = "offers"
// add
queues = "queues"
//Remove :
numberOfCurrentContracts = "numberOfCurrentContracts"
availableQueue = "availableQueue"
fixedQueue = "fixedQueue"
subscriptionQueue = "subscriptionQueue"
}
type RentalContractDataType = {
hasStarted: boolean
startBlockId: number | null
startBlockDate: Date | null
renter: string
rentee: string | null
durationType: DurationAction
blockDuration: number | null
blockSubscriptionRenewal: number | null
acceptanceType: AcceptanceAction
acceptanceList: string[]
renterCanRevoke: boolean // ??
//revocationType: RevocationAction
rentFeeType: RentFeeAction
rentFee: BalanceType | number
rentFeeRounded: number
renterCancellationFeeType: CancellationFeeAction | null
renterCancellationFee: BalanceType | number | null
renterCancellationFeeRounded: number | null
renteeCancellationFeeType: CancellationFeeAction | null
renteeCancellationFee: BalanceType | number | null
renteeCancellationFeeRounded: number | null
termsAccepted: boolean
}
// Must be removed
type AvailableRentalContractType = {
nftId: number
contractExpirationBlockId: number
contractExpirationDate: Date
}
// Must be removed
type ActiveFixedContractType = {
nftId: number
contractEndingBlockId: number
contractEndingDate: Date
}
// Must be removed
type ActiveSubscribedContractType = {
nftId: number
contractRenewalOrEndBlockId: number
contractRenewalOrEndDate: Date
}
/**
* @name getRentalContractData
* @summary Provides the data related to a rent contract.
* @param nftId The ID of the contracted NFT.
* @returns A JSON object with the rental contract data.
*/
getRentalContractData(
nftId: number,
): Promise<RentalContractDataType | null> => query(txPallets.rent, chainQuery.contracts, [nftId])
/**
* @name getRentalOffers
* @summary Provides the data related to rent contracts offers.
* @param nftId The ID of the contracted NFT.
* @returns Number.
*/
getRentalOffers(
nftId: number,
): Promise<string[]> => query(txPallets.rent, chainQuery.offers, [nftId])
/**
* @name getQueues
* @summary Data related to contracts queues.
* @returns Number.
*/
getQueues(): Promise<number> => query(txPallets.rent, chainQuery.queues)
// Must be removed
/**
* @name getAvailableRentalContracts
* @summary Provides the data related to fixed contract deadlines.
* @returns Number.
*/
getAvailableRentalContracts(): Promise<AvailableRentalContractType[]> => query(txPallets.rent, chainQuery.availableQueue)
// Must be removed
/**
* @name getActiveFixedRentalContracts
* @summary Provides the data related to fixed contract deadlines.
* @returns Number.
*/
getActiveFixedRentalContracts(): Promise<ActiveFixedContractType[]> => query(txPallets.rent, chainQuery.fixedQueue)
// Must be removed
/**
* @name getActiveSubscribedRentalContracts
* @summary Provides the data related to subscription contract deadlines.
* @returns Number.
*/
getActiveSubscribedRentalContracts(): Promise<ActiveSubscribedContractType[]> => query(txPallets.rent, chainQuery.subscriptionQueue) SchemaThe Indexer schema for the new type RentEntity @entity {
id: ID!
nftId: String!
hasStarted: Boolean!
hasEnded: Boolean!
isExpired: Boolean!
renter: String! @index
rentee: String @index
startBlockId: String
durationType: String!
blockDuration: Int
blockSubscriptionRenewal: Int
nbSubscriptionRenewal: Int
acceptanceType: String!
acceptanceList: [String]
renterCanrevoke: Boolean
#revocationType: String!
revokedBy: String
rentFeeType: String!
rentFee: String!
rentFeeRounded: Float!
rentOffers: [String]
nbRentOffers: Int
areTermsAccepted: Boolean
nbTermsUpdate: Int
renterCancellationFeeType: String
renterCancellationFee: String
renterCancellationFeeRounded: Float
renteeCancellationFeeType: String
renteeCancellationFee: String
renterCancellationFeeRounded: Float
timestampCreate: Date! @index
timestampStart: Date @index
timestampLastSubscriptionRenewal: Date
timestampNextSubscriptionRenewal: Date
timestampLastTermsUpdate: Date
timestampLastOffer: Date
timestampEnd: Date
timestampRevoke: Date
timestampExpire: Date
} New NFT operations
|
Beta Was this translation helpful? Give feedback.
-
Rent Pallet
This document specifies the design choices took for the Rent pallet implementation in the Indexer and SDK.
Feel free to comment on certain misunderstandings and new suggestions are warm welcomed.
Sections:
Events
In order to make the returned events datas usefull, we provide both the native format and a friendly ready to use format design format :
10 events are triggered by the chain in the module Rent.
SDK events
Additional events will be added to the EventType enum in src > events.ts in the SDK:
Extrinsics
7 extrinsics will be implemented from the Rent pallet.
Each helperTx will be duplicated by another helper version with 2 additional parameters: the keyring that will be used to sign and submit the transaction, and a waitUntil callback parameter, to define at which point we want to get the results of the transaction execution.
Constants
4 constants getters will be implemented from the rent pallet.
Storage
6 storage getters will be implemented for the rent pallet.
Schema
The Indexer schema for the new
RentEntity
is detailed here below.Linking upgrades
The integration of the rent pallet introduces new links to existing entities: the
NftEntity
.New NFT operations
The rent pallet introduces 6 new NFT operations. The
NftOperationEntity
remains the same and the fulfilled fields for each new operation are listed below.createRent
typeOfTransaction
='createRentContract'renewContract // TBC ?? => ContractSubscriptionPeriodStarted
startingRent
typeOfTransaction
='rentContractStarted,from
,to
,price
(price, priceRounded if renteFeeType = RentFeeAction.Tokens)endingRent = ContractRevoked ?? or ContractEnded?? or ContractAvailableExpired ??
typeOfTransaction
='unrent',from
,to
addRentalOffer => TBC ??
typeOfTransaction
='addRentalOffer',from
(price, priceRounded if renteFeeType = RentFeeAction.Tokens)removeRentalOffer => TBC ??
typeOfTransaction
='removeRentalOffer',from
(price, priceRounded if renteFeeType = RentFeeAction.Tokens)Beta Was this translation helpful? Give feedback.
All reactions