Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Add get wrapped tokens functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeto committed May 26, 2022
1 parent c32632e commit 8e87a96
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
6 changes: 3 additions & 3 deletions etc/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5425,9 +5425,9 @@ export class WrongListingTypeError extends Error {

// Warnings were encountered during analysis:
//
// dist/src/contracts/multiwrap.d.ts:160:9 - (ae-forgotten-export) The symbol "ERC20Wrappable" needs to be exported by the entry point index.d.ts
// dist/src/contracts/multiwrap.d.ts:161:9 - (ae-forgotten-export) The symbol "ERC721Wrappable" needs to be exported by the entry point index.d.ts
// dist/src/contracts/multiwrap.d.ts:162:9 - (ae-forgotten-export) The symbol "ERC1155Wrappable" needs to be exported by the entry point index.d.ts
// dist/src/contracts/multiwrap.d.ts:150:9 - (ae-forgotten-export) The symbol "ERC20Wrappable" needs to be exported by the entry point index.d.ts
// dist/src/contracts/multiwrap.d.ts:151:9 - (ae-forgotten-export) The symbol "ERC721Wrappable" needs to be exported by the entry point index.d.ts
// dist/src/contracts/multiwrap.d.ts:152:9 - (ae-forgotten-export) The symbol "ERC1155Wrappable" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
55 changes: 50 additions & 5 deletions src/contracts/multiwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {
ERC721Wrappable,
} from "../types/multiwrap";
import { normalizePriceValue } from "../common/currency";
import TokenStruct = ITokenBundle.TokenStruct;
import { ITokenBundle } from "contracts/Multiwrap";
import { MultiwrapContractSchema } from "../schema/contracts/multiwrap";
import { BigNumber, BigNumberish, ethers } from "ethers";
import TokenStruct = ITokenBundle.TokenStruct;

/**
* Multiwrap lets you wrap arbitrary ERC20, ERC721 and ERC1155 tokens you own into a single wrapped token / NFT.
Expand Down Expand Up @@ -120,10 +121,6 @@ export class Multiwrap extends Erc721<MultiwrapContract> {
? recipientAddress
: await this.contractWrapper.getSignerAddress();

// tokenStructs = []
// contents[1].each do token
// TransformtoTokenStruct(token)
//
const tokens: TokenStruct[] = [];

const provider = this.contractWrapper.getProvider();
Expand Down Expand Up @@ -175,4 +172,52 @@ export class Multiwrap extends Erc721<MultiwrapContract> {
receipt,
};
}

public async getWrappedContents(wrappedTokenId: BigNumberish = 0) {
const wrappedTokens =
await this.contractWrapper.readContract.getWrappedContents(
wrappedTokenId,
);

// console.log(wrappedTokens[0].totalAmount);

const erc20Tokens: ERC20Wrappable[] = [];
const erc721Tokens: ERC721Wrappable[] = [];
const erc1155Tokens: ERC1155Wrappable[] = [];

for (const token of wrappedTokens) {
switch (token.tokenType) {
case 0: {
erc20Tokens.push({
contractAddress: token.assetContract,
tokenAmount: ethers.utils.formatEther(token.totalAmount),
});
break;
}
case 1: {
erc721Tokens.push({
contractAddress: token.assetContract,
tokenId: token.tokenId,
});
break;
}
case 2: {
erc1155Tokens.push({
contractAddress: token.assetContract,
tokenId: token.tokenId,
tokenAmount: token.totalAmount.toString(),
});
break;
}
}
}

return {
erc20Tokens,
erc721Tokens,
erc1155Tokens,
};
}

// public async unwrap(wrappedTokenId: BigNumber): Promise<TransactionResult> {}
}
40 changes: 40 additions & 0 deletions test/multiwrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { sdk, signers } from "./before-setup";
import { Edition, Multiwrap, NFTCollection, Token } from "../src/contracts";
import { expect } from "chai";
import { BigNumber } from "ethers";

describe("Multiwrap Contract", async () => {
let multiwrapContract: Multiwrap;
Expand Down Expand Up @@ -237,4 +238,43 @@ describe("Multiwrap Contract", async () => {
const balanceE = await editionContract.balanceOf(adminWallet.address, 0);
expect(balanceE.toNumber()).to.eq(90);
});

it("get wrapped contents", async () => {
await multiwrapContract.wrap(
{
erc20tokens: [
{
contractAddress: tokenContract.getAddress(),
tokenAmount: 100.5,
},
{
contractAddress: tokenContract2.getAddress(),
tokenAmount: 19.5,
},
],
erc721tokens: [
{
contractAddress: nftContract.getAddress(),
tokenId: "0",
},
],
erc1155tokens: [
{
contractAddress: editionContract.getAddress(),
tokenId: "0",
tokenAmount: 10,
},
],
},
{
name: "Wrapped token",
},
);
const wrappedTokens = await multiwrapContract.getWrappedContents();
expect(wrappedTokens.erc20Tokens.length).to.eq(2);
expect(wrappedTokens.erc20Tokens[0].contractAddress).to.eq(
tokenContract.getAddress(),
);
expect(wrappedTokens.erc1155Tokens[0].tokenAmount).to.eq("10");
});
});

0 comments on commit 8e87a96

Please sign in to comment.