Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpaceDapp: getJoinPriceDetails, add prepaidSupply and remainingFreeSu… #1069

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/web3/src/ContractTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ export type MembershipInfo = Pick<
MembershipInfoStruct,
'maxSupply' | 'currency' | 'feeRecipient' | 'price' | 'duration' | 'pricingModule'
> &
TotalSupplyInfo
TotalSupplyInfo & {
prepaidSupply: number
remainingFreeSupply: number
}

export type TotalSupplyInfo = Pick<TotalSupplyOutputStruct, 'totalSupply'>

Expand Down
7 changes: 6 additions & 1 deletion packages/web3/src/ISpaceDapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ export interface ISpaceDapp {
) => Promise<TransactionType>
getSpace(spaceId: string): Space | undefined
getSpaceMembershipTokenAddress: (spaceId: string) => Promise<string>
getJoinSpacePrice: (spaceId: string) => Promise<BigNumber>
getJoinSpacePriceDetails: (spaceId: string) => Promise<{
price: ethers.BigNumber
prepaidSupply: ethers.BigNumber
remainingFreeSupply: ethers.BigNumber
}>
joinSpace: (
spaceId: string,
recipient: string,
Expand Down Expand Up @@ -312,4 +316,5 @@ export interface ISpaceDapp {
receiver: string,
abortController?: AbortController,
) => Promise<{ issued: true; tokenId: string } | { issued: false; tokenId: undefined }>
getMembershipFreeAllocation: (spaceId: string) => Promise<BigNumber>
}
4 changes: 4 additions & 0 deletions packages/web3/src/v3/PlatformRequirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export class PlatformRequirements extends BaseContractShim<LocalhostContract, Lo
super(address, provider, LocalhostAbi)
}

public getMembershipMintLimit() {
return this.read.getMembershipMintLimit()
}

public getMembershipFee() {
return this.read.getMembershipFee()
}
Expand Down
60 changes: 44 additions & 16 deletions packages/web3/src/v3/SpaceDapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChannelMetadata,
EntitlementModuleType,
isPermission,
MembershipInfo,
Permission,
PricingModuleStruct,
RoleDetails,
Expand Down Expand Up @@ -1277,17 +1278,34 @@ export class SpaceDapp implements ISpaceDapp {
return space.Membership.address
}

public async getJoinSpacePrice(spaceId: string): Promise<ethers.BigNumber> {
public async getJoinSpacePriceDetails(spaceId: string): Promise<{
price: ethers.BigNumber
prepaidSupply: ethers.BigNumber
remainingFreeSupply: ethers.BigNumber
}> {
const space = this.getSpace(spaceId)
if (!space) {
throw new Error(`Space with spaceId "${spaceId}" is not found.`)
}
const prepaidSupply = await space.Prepay.read.prepaidMembershipSupply()
const membershipPrice = await space.Membership.read.getMembershipPrice()
const freeAllocation = await this.getMembershipFreeAllocation(spaceId)
const totalSupply = await space.ERC721A.read.totalSupply()
const remainingFreeSupply = freeAllocation.add(prepaidSupply).sub(totalSupply)

return {
price: prepaidSupply.gt(0) ? ethers.BigNumber.from(0) : membershipPrice,
prepaidSupply,
remainingFreeSupply,
}
}

if (prepaidSupply.gt(0)) {
return ethers.BigNumber.from(0)
public async getMembershipFreeAllocation(spaceId: string) {
const space = this.getSpace(spaceId)
if (!space) {
throw new Error(`Space with spaceId "${spaceId}" is not found.`)
}
return space.Membership.read.getMembershipPrice()
return space.Membership.read.getMembershipFreeAllocation()
}

public async joinSpace(
Expand Down Expand Up @@ -1365,26 +1383,36 @@ export class SpaceDapp implements ISpaceDapp {
if (!space) {
throw new Error(`Space with spaceId "${spaceId}" is not found.`)
}
const [price, limit, currency, feeRecipient, duration, totalSupply, pricingModule] =
await Promise.all([
this.getJoinSpacePrice(spaceId),
space.Membership.read.getMembershipLimit(),
space.Membership.read.getMembershipCurrency(),
space.Ownable.read.owner(),
space.Membership.read.getMembershipDuration(),
space.ERC721A.read.totalSupply(),
space.Membership.read.getMembershipPricingModule(),
])
const [
joinSpacePriceDetails,
limit,
currency,
feeRecipient,
duration,
totalSupply,
pricingModule,
] = await Promise.all([
this.getJoinSpacePriceDetails(spaceId),
space.Membership.read.getMembershipLimit(),
space.Membership.read.getMembershipCurrency(),
space.Ownable.read.owner(),
space.Membership.read.getMembershipDuration(),
space.ERC721A.read.totalSupply(),
space.Membership.read.getMembershipPricingModule(),
])
const { price, prepaidSupply, remainingFreeSupply } = joinSpacePriceDetails

return {
price: price, // keep as BigNumber (wei)
price, // keep as BigNumber (wei)
maxSupply: limit.toNumber(),
currency: currency,
feeRecipient: feeRecipient,
duration: duration.toNumber(),
totalSupply: totalSupply.toNumber(),
pricingModule: pricingModule,
}
prepaidSupply: prepaidSupply.toNumber(),
remainingFreeSupply: remainingFreeSupply.toNumber(),
} satisfies MembershipInfo
}

public getWalletLink(): WalletLink {
Expand Down
Loading