-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
479372f
commit dc76680
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Address } from 'viem'; | ||
|
||
import { approveNFT, testCollection, testTokenId, users } from './common'; | ||
|
||
const userVaults = async () => { | ||
const gondi = users[1]; | ||
|
||
const anotherCollectionAddress = process.env.TEST_COLLECTION_2 as Address; | ||
if (!anotherCollectionAddress) { | ||
throw new Error( | ||
'TEST_COLLECTION_2 not provided, please provide address to run user vaults example', | ||
); | ||
} | ||
await approveNFT(gondi, anotherCollectionAddress); | ||
|
||
console.log('Creating vault with nfts...'); | ||
const createTxn = await gondi.createUserVault({ | ||
nfts: [ | ||
// Assuming users[0] has same tokenId for collections | ||
{ collection: anotherCollectionAddress, tokenIds: [testTokenId] }, | ||
{ collection: testCollection.contractAddress, tokenIds: [testTokenId] }, | ||
], | ||
}); | ||
const vaultId = createTxn.vaultId; | ||
console.log(`successfully created vaultId ${vaultId}.`); | ||
|
||
const createResult = await createTxn.waitTxInBlock(); | ||
console.log(`successfully deposited ${createResult.length} nfts to vaultId ${vaultId}.`); | ||
|
||
for (let i = 0; i < createResult.length; i++) { | ||
const element = createResult[i]; | ||
const owner = await gondi.getOwner({ | ||
nftAddress: element.collection, | ||
tokenId: element.tokenId, | ||
}); | ||
console.log(`-- ${i + 1}: ${element.collection} ${element.tokenId} - owner: ${owner}`); | ||
} | ||
|
||
console.log('Burning and withdrawing nfts...'); | ||
|
||
const burnTxn = await gondi.burnUserVaultAndWithdraw({ | ||
vaultId, | ||
collections: [anotherCollectionAddress, testCollection.contractAddress], | ||
tokenIds: [testTokenId, testTokenId], | ||
}); | ||
|
||
const burnResult = await burnTxn.waitTxInBlock(); | ||
console.log(`successfully burned vaultId ${vaultId}.`); | ||
|
||
const withdrawEvents = burnResult.events; | ||
console.log(`successfully withdrawn ${withdrawEvents.length} nfts from vaultId ${vaultId}.`); | ||
|
||
for (let j = 0; j < withdrawEvents.length; j++) { | ||
const event = withdrawEvents[j]; | ||
const owner = await gondi.getOwner({ nftAddress: event.collection, tokenId: event.tokenId }); | ||
console.log(`-- ${j + 1}: ${event.collection} ${event.tokenId} - owner: ${owner}`); | ||
} | ||
}; | ||
|
||
async function main() { | ||
try { | ||
await userVaults(); | ||
} catch (e) { | ||
console.log('Error:'); | ||
console.log(e); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters