Skip to content

Commit bab6c1c

Browse files
committed
feat: add protocolFee to getJoinSpacePriceDetails response (#4269)
### Description Added protocol fee to the `getJoinSpacePriceDetails` method to properly account for the total cost when joining a space. ### Changes - Added `protocolFee` property to the return type of `getJoinSpacePriceDetails` - Updated the method to fetch protocol fee data via multicall - Modified the method to decode and return the protocol fee value - Updated tests to verify that the price includes the protocol fee ### Checklist - [x] Tests added where required - [x] Documentation updated where applicable - [x] Changes adhere to the repository's contribution guidelines
1 parent 8b93c7b commit bab6c1c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/sdk/src/tests/multi/spaceWithVariousPriceConfigurations.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,12 @@ describe('spaceWithVariousPriceConfigurations', () => {
155155
membershipRequirements,
156156
)
157157

158-
const { price: joinPrice } = await bobSpaceDapp.getJoinSpacePriceDetails(spaceId)
158+
const { price: joinPrice, protocolFee } =
159+
await bobSpaceDapp.getJoinSpacePriceDetails(spaceId)
159160

160-
expect(joinPrice.toBigInt()).toBe(ethers.utils.parseEther('1').toBigInt())
161+
expect(joinPrice.toBigInt()).toBe(
162+
ethers.utils.parseEther('1').toBigInt() + protocolFee.toBigInt(),
163+
)
161164

162165
log('Alice should be able to join space')
163166

packages/web3/src/space-dapp/SpaceDapp.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ export class SpaceDapp<TProvider extends ethers.providers.Provider = ethers.prov
15251525
price: ethers.BigNumber
15261526
prepaidSupply: ethers.BigNumber
15271527
remainingFreeSupply: ethers.BigNumber
1528+
protocolFee: ethers.BigNumber
15281529
}> {
15291530
const space = this.getSpace(spaceId)
15301531
if (!space) {
@@ -1548,16 +1549,20 @@ export class SpaceDapp<TProvider extends ethers.providers.Provider = ethers.prov
15481549
const prepaidSupplyEncoded =
15491550
space.Prepay.interface.encodeFunctionData('prepaidMembershipSupply')
15501551

1552+
const protocolFeeEncoded = space.Membership.interface.encodeFunctionData('getProtocolFee')
1553+
15511554
const [
15521555
membershipPriceResult,
15531556
totalSupplyResult,
15541557
freeAllocationResult,
15551558
prepaidSupplyResult,
1559+
protocolFeeResult,
15561560
] = await space.Multicall.read.callStatic.multicall([
15571561
membershipPriceEncoded,
15581562
totalSupplyEncoded,
15591563
freeAllocationEncoded,
15601564
prepaidSupplyEncoded,
1565+
protocolFeeEncoded,
15611566
])
15621567

15631568
try {
@@ -1577,7 +1582,10 @@ export class SpaceDapp<TProvider extends ethers.providers.Provider = ethers.prov
15771582
'prepaidMembershipSupply',
15781583
prepaidSupplyResult,
15791584
)[0] as BigNumber
1580-
1585+
const protocolFee = space.Membership.interface.decodeFunctionResult(
1586+
'getProtocolFee',
1587+
protocolFeeResult,
1588+
)[0] as BigNumber
15811589
// remainingFreeSupply
15821590
// if totalSupply < freeAllocation, freeAllocation + prepaid - minted memberships
15831591
// else the remaining prepaidSupply if any
@@ -1589,6 +1597,7 @@ export class SpaceDapp<TProvider extends ethers.providers.Provider = ethers.prov
15891597
price: remainingFreeSupply.gt(0) ? ethers.BigNumber.from(0) : membershipPrice,
15901598
prepaidSupply,
15911599
remainingFreeSupply,
1600+
protocolFee,
15921601
}
15931602
} catch (error) {
15941603
logger.error('getJoinSpacePriceDetails: Error decoding membership price', error)

packages/web3/tests/getJoinSpacePriceDetails.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ describe('getJoinSpacePriceDetails', () => {
7070
const spaceId = SpaceIdFromSpaceAddress(spaceAddress)
7171

7272
const priceDetails = await spaceDapp.getJoinSpacePriceDetails(spaceAddress)
73+
const protocolFee = priceDetails.protocolFee
74+
const totalPrice = price.add(protocolFee)
7375

74-
expect(priceDetails.price.toBigInt()).toBe(price.toBigInt())
76+
expect(priceDetails.price.toBigInt()).toBe(totalPrice.toBigInt())
7577
expect(priceDetails.prepaidSupply.toBigInt()).toBe(0n)
7678
expect(priceDetails.remainingFreeSupply.toBigInt()).toBe(0n)
7779

0 commit comments

Comments
 (0)