Skip to content

Commit

Permalink
fix: updated to sync create vault and deposit nfts
Browse files Browse the repository at this point in the history
  • Loading branch information
mishuagopian committed Jan 13, 2024
1 parent 26d8e03 commit ec38b14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
14 changes: 6 additions & 8 deletions examples/userVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ const userVaults = async () => {
await approveNFT(gondi, USER_VAULT_CONTRACT_V5, ANOTHER_COLLECTION);

console.log('Creating vault with nfts...');
const createTxn = await gondi.createUserVault({
const { vaultId, receipts } = await gondi.createUserVault({
nfts: [
// Assuming user has same tokenId for collections
{ collection: ANOTHER_COLLECTION, tokenIds: [testTokenId] },
{ collection: testCollection.contractAddress, tokenIds: [testTokenId] },
],
});
const vaultId = createTxn.vaultId;
console.log(`successfully created vaultId ${vaultId}.`);
console.log(`
Successfully created vaultId ${vaultId}.
Successfully deposited ${receipts.length} nfts to 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];
for (let i = 0; i < receipts.length; i++) {
const element = receipts[i];
const owner = await gondi.getOwner({
nftAddress: element.collection,
tokenId: element.tokenId,
Expand Down
19 changes: 8 additions & 11 deletions src/contracts/UserVaultV5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,16 @@ export class UserVaultV5 extends Contract<typeof userVaultABIV5> {

async createVault(nfts: { collection: Address; tokenIds: bigint[] }[]) {
const { id: vaultId } = await this.#mintVault();
const receipts = [];

const deposits = await Promise.all(
nfts.map(async ({ collection, tokenIds }) =>
this.depositERC721s({ vaultId, collection, tokenIds }),
),
);
for (let i = 0; i < nfts.length; i++) {
const { collection, tokenIds } = nfts[i];
const deposit = await this.depositERC721s({ vaultId, collection, tokenIds });
const receipt = await deposit.waitTxInBlock();
receipts.push(receipt);
}

return {
vaultId,
txHash: deposits.map(({ txHash }) => txHash),
waitTxInBlock: async () =>
await Promise.all(deposits.map(({ waitTxInBlock }) => waitTxInBlock())),
};
return { vaultId, receipts };
}

async depositERC721s({
Expand Down

0 comments on commit ec38b14

Please sign in to comment.