@@ -2,12 +2,16 @@ import * as anchor from '@project-serum/anchor';
22import { isSome , publicKey , sol , Umi } from '@metaplex-foundation/umi' ;
33import {
44 airdrop ,
5+ assertIsBetween ,
56 createPool ,
67 createUmi ,
78 DEFAULT_TEST_SETUP_TREE_PARAMS ,
89 getCreatorRoyaltiesArgs ,
910 getPubKey ,
11+ getSellStatePDARent ,
12+ PRICE_ERROR_RANGE ,
1013 setupTree ,
14+ SIGNATURE_FEE_LAMPORTS ,
1115 verifyOwnership ,
1216} from './utils' ;
1317import {
@@ -44,6 +48,7 @@ import {
4448} from '@metaplex-foundation/mpl-bubblegum' ;
4549import { BN } from '@project-serum/anchor' ;
4650import { ConcurrentMerkleTreeAccount } from '@solana/spl-account-compression' ;
51+ import { assert } from 'chai' ;
4752
4853async function createCNftCollectionOffer (
4954 program : anchor . Program < Mmm > ,
@@ -54,6 +59,7 @@ async function createCNftCollectionOffer(
5459 const poolData = await createPool ( program , {
5560 ...poolArgs ,
5661 reinvestFulfillBuy : false ,
62+ buysideCreatorRoyaltyBp : 10_000 ,
5763 } ) ;
5864
5965 const poolKey = poolData . poolKey ;
@@ -103,7 +109,7 @@ describe('cnft tests', () => {
103109 const buyer = new anchor . Wallet ( Keypair . generate ( ) ) ;
104110 const seller = new anchor . Wallet ( Keypair . generate ( ) ) ;
105111 const connection = new anchor . web3 . Connection ( endpoint , 'confirmed' ) ;
106- const provider = new anchor . AnchorProvider ( connection , buyer , {
112+ let provider = new anchor . AnchorProvider ( connection , buyer , {
107113 commitment : 'confirmed' ,
108114 } ) ;
109115
@@ -176,7 +182,7 @@ describe('cnft tests', () => {
176182 const spotPrice = 1 ;
177183 const expectedBuyPrices = getSolFulfillBuyPrices ( {
178184 totalPriceLamports : spotPrice * LAMPORTS_PER_SOL ,
179- lpFeeBp : 200 ,
185+ lpFeeBp : 0 ,
180186 takerFeeBp : 100 ,
181187 metadataRoyaltyBp : 500 ,
182188 buysideCreatorRoyaltyBp : 10_000 ,
@@ -209,6 +215,29 @@ describe('cnft tests', () => {
209215 } = getCreatorRoyaltiesArgs ( creatorRoyalties ) ;
210216 console . log ( `got creator royalties` ) ;
211217
218+ // get balances before fulfill buy
219+ const [
220+ buyerBefore ,
221+ sellerBefore ,
222+ buyerSolEscrowAccountBalanceBefore ,
223+ creator1Before ,
224+ creator2Before ,
225+ ] = await Promise . all ( [
226+ connection . getBalance ( buyer . publicKey ) ,
227+ connection . getBalance ( seller . publicKey ) ,
228+ connection . getBalance ( buysideSolEscrowAccount ) ,
229+ connection . getBalance ( creatorAccounts [ 0 ] . pubkey ) ,
230+ connection . getBalance ( creatorAccounts [ 1 ] . pubkey ) ,
231+ ] ) ;
232+
233+ console . log ( `buyerBefore: ${ buyerBefore } ` ) ;
234+ console . log ( `sellerBefore: ${ sellerBefore } ` ) ;
235+ console . log (
236+ `buyerSolEscrowAccountBalanceBefore: ${ buyerSolEscrowAccountBalanceBefore } ` ,
237+ ) ;
238+ console . log ( `creator1Before: ${ creator1Before } ` ) ;
239+ console . log ( `creator2Before: ${ creator2Before } ` ) ;
240+
212241 try {
213242 const metadataSerializer = getMetadataArgsSerializer ( ) ;
214243 const metadataArgs : MetadataArgs = metadataSerializer . deserialize (
@@ -334,5 +363,65 @@ describe('cnft tests', () => {
334363 metadata ,
335364 [ ] ,
336365 ) ;
366+
367+ // Get balances after fulfill buy
368+ const [
369+ buyerAfter ,
370+ sellerAfter ,
371+ buyerSolEscrowAccountBalanceAfter ,
372+ creator1After ,
373+ creator2After ,
374+ ] = await Promise . all ( [
375+ connection . getBalance ( buyer . publicKey ) ,
376+ connection . getBalance ( seller . publicKey ) ,
377+ connection . getBalance ( buysideSolEscrowAccount ) ,
378+ connection . getBalance ( creatorAccounts [ 0 ] . pubkey ) ,
379+ connection . getBalance ( creatorAccounts [ 1 ] . pubkey ) ,
380+ ] ) ;
381+
382+ console . log ( `buyerAfter: ${ buyerAfter } ` ) ;
383+ console . log ( `sellerAfter: ${ sellerAfter } ` ) ;
384+ console . log (
385+ `buyerSolEscrowAccountBalanceAfter: ${ buyerSolEscrowAccountBalanceAfter } ` ,
386+ ) ;
387+ console . log ( `creator1After: ${ creator1After } ` ) ;
388+ console . log ( `creator2After: ${ creator2After } ` ) ;
389+
390+ const expectedTxFees = SIGNATURE_FEE_LAMPORTS * 3 ; // cosigner + seller + payer (due to provider is under buyer)
391+
392+ assert . equal ( buyerBefore , buyerAfter + expectedTxFees ) ;
393+
394+ assert . equal (
395+ buyerSolEscrowAccountBalanceBefore ,
396+ buyerSolEscrowAccountBalanceAfter + spotPrice * LAMPORTS_PER_SOL ,
397+ ) ;
398+
399+ // In production it should be seller buy tx fee, but with this test set up, buyer pays
400+ // tx fee due to provider is initiated under buyer.
401+ assert . equal (
402+ sellerAfter ,
403+ sellerBefore +
404+ spotPrice * LAMPORTS_PER_SOL -
405+ expectedBuyPrices . takerFeePaid . toNumber ( ) -
406+ expectedBuyPrices . royaltyPaid . toNumber ( ) ,
407+ ) ;
408+
409+ assertIsBetween (
410+ creator1After ,
411+ creator1Before +
412+ ( expectedBuyPrices . royaltyPaid . toNumber ( ) *
413+ metadata . creators [ 0 ] . share ) /
414+ 100 ,
415+ PRICE_ERROR_RANGE ,
416+ ) ;
417+
418+ assertIsBetween (
419+ creator2After ,
420+ creator2Before +
421+ ( expectedBuyPrices . royaltyPaid . toNumber ( ) *
422+ metadata . creators [ 1 ] . share ) /
423+ 100 ,
424+ PRICE_ERROR_RANGE ,
425+ ) ;
337426 } ) ;
338427} ) ;
0 commit comments