From b6a27a6aaf7cb6f4d3515e34de0075baa4f8d7b1 Mon Sep 17 00:00:00 2001 From: josemarinas <36479864+josemarinas@users.noreply.github.com> Date: Thu, 17 Aug 2023 18:03:46 +0200 Subject: [PATCH] Fix: Support for erc1155 (#272) * fix support for erc1155 * update changelog --- modules/client/CHANGELOG.md | 4 + modules/client/package.json | 2 +- .../src/internal/graphql-queries/balances.ts | 12 + .../src/internal/graphql-queries/transfer.ts | 7 + modules/client/src/internal/types.ts | 91 +++++- modules/client/src/internal/utils.ts | 280 ++++++++++++------ modules/client/src/types.ts | 45 ++- .../test/integration/client/methods.test.ts | 167 +++++++++-- 8 files changed, 472 insertions(+), 136 deletions(-) diff --git a/modules/client/CHANGELOG.md b/modules/client/CHANGELOG.md index c5d2de411..f08e3ddba 100644 --- a/modules/client/CHANGELOG.md +++ b/modules/client/CHANGELOG.md @@ -17,6 +17,10 @@ TEMPLATE: --> ## [UPCOMING] +### Fixes +- Support for ERC115Transfers and balances +## [1.13.0-rc1] + ### Added - Block param on `getVotingSettings` and `getMembers` functions to allow for historical data - Support for local chains diff --git a/modules/client/package.json b/modules/client/package.json index 937ef01b9..daaccf2cd 100644 --- a/modules/client/package.json +++ b/modules/client/package.json @@ -1,7 +1,7 @@ { "name": "@aragon/sdk-client", "author": "Aragon Association", - "version": "1.13.0-rc1", + "version": "1.13.1-rc1", "license": "MIT", "main": "dist/index.js", "module": "dist/sdk-client.esm.js", diff --git a/modules/client/src/internal/graphql-queries/balances.ts b/modules/client/src/internal/graphql-queries/balances.ts index d750dc13f..8625e565a 100644 --- a/modules/client/src/internal/graphql-queries/balances.ts +++ b/modules/client/src/internal/graphql-queries/balances.ts @@ -20,10 +20,22 @@ query TokenBalances($where: TokenBalance_filter!, $limit:Int!, $skip: Int!, $dir symbol id } + tokenIds } ... on NativeBalance { balance } + ... on ERC1155Balance { + metadataUri + token { + id + } + balances { + amount + id + tokenId + } + } } } `; diff --git a/modules/client/src/internal/graphql-queries/transfer.ts b/modules/client/src/internal/graphql-queries/transfer.ts index c67c4fa95..34b135352 100644 --- a/modules/client/src/internal/graphql-queries/transfer.ts +++ b/modules/client/src/internal/graphql-queries/transfer.ts @@ -32,6 +32,13 @@ query TokenTransfers($where: TokenTransfer_filter!, $limit:Int!, $skip: Int!, $d ... on NativeTransfer { amount } + ...on ERC1155Transfer{ + amount + tokenId + token { + id + } + } } } `; diff --git a/modules/client/src/internal/types.ts b/modules/client/src/internal/types.ts index f93b597fe..077700483 100644 --- a/modules/client/src/internal/types.ts +++ b/modules/client/src/internal/types.ts @@ -7,7 +7,7 @@ export type SubgraphPluginListItem = { } | null; appliedPluginRepo: { subdomain: string; - } | null; + } | null; appliedVersion: { build: number; release: { @@ -29,24 +29,52 @@ export type SubgraphDao = SubgraphDaoBase & { export type SubgraphDaoListItem = SubgraphDaoBase; -export type SubgraphBalance = { +type SubgraphBalanceBase = { + id: string; + lastUpdated: string; __typename: string; - token: { - id: string; - name: string; - symbol: string; - decimals: number; - }; +}; + +export type SubgraphErc20Balance = SubgraphBalanceBase & { + __typename: "ERC20Balance"; balance: string; - lastUpdated: string; + token: SubgraphErc20Token; +}; + +export type SubgraphErc721Balance = SubgraphBalanceBase & { + __typename: "ERC721Balance"; + token: SubgraphErc721Token; + tokenIds: string[]; }; +export type SubgraphNativeBalance = SubgraphBalanceBase & { + __typename: "NativeBalance"; + balance: string; +}; + +export type SubgraphErc1155Balance = SubgraphBalanceBase & { + __typename: "ERC1155Balance"; + metadataUri: string; + token: SubgraphErc1155Token; + balances: { + amount: string; + id: string; + tokenId: string; + }[]; +}; + +export type SubgraphBalance = + | SubgraphErc20Balance + | SubgraphErc721Balance + | SubgraphNativeBalance + | SubgraphErc1155Balance; + export enum SubgraphTransferType { DEPOSIT = "Deposit", WITHDRAW = "Withdraw", } -export type SubgraphTransferListItem = { +type SubgraphTransferListItemBase = { from: string; to: string; type: SubgraphTransferType; @@ -55,17 +83,54 @@ export type SubgraphTransferListItem = { proposal: { id: string | null; }; +}; + +export type SubgraphErc20TransferListItem = SubgraphTransferListItemBase & { + __typename: "ERC20Transfer"; amount: string; - token: SubgraphToken; - __typename: string; + token: SubgraphErc20Token; +}; + +export type SubgraphErc721TransferListItem = SubgraphTransferListItemBase & { + __typename: "ERC721Transfer"; + token: SubgraphErc721Token; +}; + +export type SubgraphNativeTransferListItem = SubgraphTransferListItemBase & { + __typename: "NativeTransfer"; + amount: string; +}; + +export type SubgraphErc1155TransferListItem = SubgraphTransferListItemBase & { + __typename: "ERC1155Transfer"; + amount: string; + tokenId: string; + token: SubgraphErc1155Token; }; -export type SubgraphToken = { +export type SubgraphTransferListItem = + | SubgraphErc20TransferListItem + | SubgraphErc721TransferListItem + | SubgraphNativeTransferListItem + | SubgraphErc1155TransferListItem; + +type SubgraphTokenBase = { id: string; +}; + +export type SubgraphErc20Token = SubgraphTokenBase & { name: string; symbol: string; decimals: number; }; + +export type SubgraphErc721Token = SubgraphTokenBase & { + name: string; + symbol: string; +}; + +export type SubgraphErc1155Token = SubgraphTokenBase; + export const SubgraphTransferTypeMap: Map< TransferType, SubgraphTransferType diff --git a/modules/client/src/internal/utils.ts b/modules/client/src/internal/utils.ts index 9f35e601b..4f9e9d7ee 100644 --- a/modules/client/src/internal/utils.ts +++ b/modules/client/src/internal/utils.ts @@ -30,6 +30,14 @@ import { SubgraphBalance, SubgraphDao, SubgraphDaoListItem, + SubgraphErc1155Balance, + SubgraphErc1155TransferListItem, + SubgraphErc20Balance, + SubgraphErc20TransferListItem, + SubgraphErc721Balance, + SubgraphErc721TransferListItem, + SubgraphNativeBalance, + SubgraphNativeTransferListItem, SubgraphPluginListItem, SubgraphPluginRepo, SubgraphPluginRepoListItem, @@ -48,7 +56,11 @@ import { DecodedApplyInstallationParams, TokenType, } from "@aragon/sdk-client-common"; -import { InvalidParameter, NotImplementedError, SizeMismatchError } from "@aragon/sdk-common"; +import { + InvalidParameter, + NotImplementedError, + SizeMismatchError, +} from "@aragon/sdk-common"; import { Signer } from "@ethersproject/abstract-signer"; import { Contract } from "@ethersproject/contracts"; import { BigNumber } from "@ethersproject/bignumber"; @@ -136,77 +148,115 @@ export function toDaoListItem( }; } +function toNativeBalance(balance: SubgraphNativeBalance): AssetBalance { + return { + id: balance.id, + type: TokenType.NATIVE, + balance: BigInt(balance.balance), + updateDate: new Date(parseInt(balance.lastUpdated) * 1000), + }; +} + +function toErc20Balance(balance: SubgraphErc20Balance): AssetBalance { + return { + id: balance.id, + type: TokenType.ERC20, + address: balance.token.id, + name: balance.token.name, + symbol: balance.token.symbol, + decimals: balance.token.decimals, + balance: BigInt(balance.balance), + updateDate: new Date(parseInt(balance.lastUpdated) * 1000), + }; +} + +function toErc721Balance(balance: SubgraphErc721Balance): AssetBalance { + return { + id: balance.id, + type: TokenType.ERC721, + address: balance.token.id, + name: balance.token.name, + symbol: balance.token.symbol, + updateDate: new Date(parseInt(balance.lastUpdated) * 1000), + tokenIds: balance.tokenIds.map((id) => BigInt(id)), + }; +} +function toErc1155Balance(balance: SubgraphErc1155Balance): AssetBalance { + return { + id: balance.id, + type: TokenType.ERC1155, + address: balance.token.id, + metadataUri: balance.metadataUri, + updateDate: new Date(parseInt(balance.lastUpdated) * 1000), + balances: balance.balances.map((balance) => ({ + tokenId: BigInt(balance.tokenId), + amount: BigInt(balance.amount), + id: balance.id, + })), + }; +} + export function toAssetBalance(balance: SubgraphBalance): AssetBalance { - const updateDate = new Date(parseInt(balance.lastUpdated) * 1000); - if (balance.__typename === "NativeBalance") { - return { - type: TokenType.NATIVE, - balance: BigInt(balance.balance), - updateDate, - }; - } else if (balance.__typename === "ERC721Balance") { - return { - type: TokenType.ERC721, - name: balance.token.name, - symbol: balance.token.symbol, - updateDate, - address: balance.token.id, - }; - } else { - return { - type: TokenType.ERC20, - address: balance.token.id, - name: balance.token.name, - symbol: balance.token.symbol, - decimals: balance.token.decimals, - balance: BigInt(balance.balance), - updateDate, - }; + switch (balance.__typename) { + case "NativeBalance": + return toNativeBalance(balance); + case "ERC20Balance": + return toErc20Balance(balance); + case "ERC721Balance": + return toErc721Balance(balance); + case "ERC1155Balance": + return toErc1155Balance(balance); + default: + throw new InvalidParameter("Token type not supported"); } } -export function toTokenTransfer(transfer: SubgraphTransferListItem): Transfer { +function toErc20Transfer( + transfer: SubgraphErc20TransferListItem, +): Transfer { const creationDate = new Date(parseInt(transfer.createdAt) * 1000); - if (transfer.__typename === "NativeTransfer") { - if (transfer.type === SubgraphTransferType.DEPOSIT) { - return { - type: TransferType.DEPOSIT, - tokenType: TokenType.NATIVE, - amount: BigInt(transfer.amount), - creationDate, - transactionId: transfer.txHash, - from: transfer.from, - to: transfer.to, - }; - } + if (transfer.type === SubgraphTransferType.DEPOSIT) { return { - type: TransferType.WITHDRAW, - tokenType: TokenType.NATIVE, + type: TransferType.DEPOSIT, + tokenType: TokenType.ERC20, + token: { + address: transfer.token.id, + name: transfer.token.name, + symbol: transfer.token.symbol, + decimals: transfer.token.decimals, + }, amount: BigInt(transfer.amount), creationDate, transactionId: transfer.txHash, - proposalId: transfer.proposal?.id || "", - to: transfer.to, from: transfer.from, + to: transfer.to, }; - } else if (transfer.__typename === "ERC721Transfer") { - if (transfer.type === SubgraphTransferType.DEPOSIT) { - return { - type: TransferType.DEPOSIT, - tokenType: TokenType.ERC721, - token: { - address: transfer.token.id, - name: transfer.token.name, - symbol: transfer.token.symbol, - }, - creationDate, - transactionId: transfer.txHash, - from: transfer.from, - to: transfer.to, - }; - } + } + return { + type: TransferType.WITHDRAW, + tokenType: TokenType.ERC20, + token: { + address: transfer.token.id, + name: transfer.token.name, + symbol: transfer.token.symbol, + decimals: transfer.token.decimals, + }, + amount: BigInt(transfer.amount), + creationDate, + transactionId: transfer.txHash, + to: transfer.to, + from: transfer.from, + proposalId: transfer.proposal?.id || "", + }; +} + +function toErc721Transfer( + transfer: SubgraphErc721TransferListItem, +): Transfer { + const creationDate = new Date(parseInt(transfer.createdAt) * 1000); + if (transfer.type === SubgraphTransferType.DEPOSIT) { return { - type: TransferType.WITHDRAW, + type: TransferType.DEPOSIT, tokenType: TokenType.ERC721, token: { address: transfer.token.id, @@ -215,45 +265,101 @@ export function toTokenTransfer(transfer: SubgraphTransferListItem): Transfer { }, creationDate, transactionId: transfer.txHash, - to: transfer.to, from: transfer.from, - proposalId: transfer.proposal?.id || "", + to: transfer.to, }; - } else { - if (transfer.type === SubgraphTransferType.DEPOSIT) { - return { - type: TransferType.DEPOSIT, - tokenType: TokenType.ERC20, - token: { - address: transfer.token.id, - name: transfer.token.name, - symbol: transfer.token.symbol, - decimals: transfer.token.decimals, - }, - amount: BigInt(transfer.amount), - creationDate, - transactionId: transfer.txHash, - from: transfer.from, - to: transfer.to, - }; - } + } + return { + type: TransferType.WITHDRAW, + tokenType: TokenType.ERC721, + token: { + address: transfer.token.id, + name: transfer.token.name, + symbol: transfer.token.symbol, + }, + creationDate, + transactionId: transfer.txHash, + to: transfer.to, + from: transfer.from, + proposalId: transfer.proposal?.id || "", + }; +} + +function toErc1155Transfer( + transfer: SubgraphErc1155TransferListItem, +): Transfer { + const creationDate = new Date(parseInt(transfer.createdAt) * 1000); + if (transfer.type === SubgraphTransferType.DEPOSIT) { return { - type: TransferType.WITHDRAW, - tokenType: TokenType.ERC20, + type: TransferType.DEPOSIT, + tokenType: TokenType.ERC1155, + amount: BigInt(transfer.amount), + tokenId: BigInt(transfer.tokenId), token: { address: transfer.token.id, - name: transfer.token.name, - symbol: transfer.token.symbol, - decimals: transfer.token.decimals, }, - amount: BigInt(transfer.amount), creationDate, transactionId: transfer.txHash, + from: transfer.from, to: transfer.to, + }; + } + return { + type: TransferType.WITHDRAW, + tokenType: TokenType.ERC1155, + amount: BigInt(transfer.amount), + tokenId: BigInt(transfer.tokenId), + token: { + address: transfer.token.id, + }, + creationDate, + transactionId: transfer.txHash, + proposalId: transfer.proposal?.id || "", + to: transfer.to, + from: transfer.from, + }; +} + +function toNativeTransfer( + transfer: SubgraphNativeTransferListItem, +): Transfer { + const creationDate = new Date(parseInt(transfer.createdAt) * 1000); + if (transfer.type === SubgraphTransferType.DEPOSIT) { + return { + type: TransferType.DEPOSIT, + tokenType: TokenType.NATIVE, + amount: BigInt(transfer.amount), + creationDate, + transactionId: transfer.txHash, from: transfer.from, - proposalId: transfer.proposal?.id || "", + to: transfer.to, }; } + return { + type: TransferType.WITHDRAW, + tokenType: TokenType.NATIVE, + amount: BigInt(transfer.amount), + creationDate, + transactionId: transfer.txHash, + proposalId: transfer.proposal?.id || "", + to: transfer.to, + from: transfer.from, + }; +} + +export function toTokenTransfer(transfer: SubgraphTransferListItem): Transfer { + switch (transfer.__typename) { + case "ERC20Transfer": + return toErc20Transfer(transfer); + case "ERC721Transfer": + return toErc721Transfer(transfer); + case "NativeTransfer": + return toNativeTransfer(transfer); + case "ERC1155Transfer": + return toErc1155Transfer(transfer); + default: + throw new InvalidParameter("Token type not supported"); + } } export function toPluginRepoRelease( diff --git a/modules/client/src/types.ts b/modules/client/src/types.ts index 6c6d51e48..ab33f0e9e 100644 --- a/modules/client/src/types.ts +++ b/modules/client/src/types.ts @@ -213,13 +213,13 @@ export type WithdrawParams = /* Balances */ type AssetBalanceBase = { + id: string; address: string; - name: string; - symbol: string; updateDate: Date; }; type NativeAssetBalance = { + id: string; type: TokenType.NATIVE; balance: bigint; updateDate: Date; @@ -228,9 +228,24 @@ type Erc20AssetBalance = AssetBalanceBase & { type: TokenType.ERC20; balance: bigint; decimals: number; + name: string; + symbol: string; }; type Erc721AssetBalance = AssetBalanceBase & { type: TokenType.ERC721; + tokenIds: bigint[]; + name: string; + symbol: string; +}; + +type Erc1155AssetBalance = AssetBalanceBase & { + type: TokenType.ERC1155; + balances: { + id: string; + tokenId: bigint; + amount: bigint; + }[]; + metadataUri: string; }; export type DaoBalancesQueryParams = Pagination & { @@ -244,7 +259,8 @@ export enum AssetBalanceSortBy { export type AssetBalance = | NativeAssetBalance | Erc20AssetBalance - | Erc721AssetBalance; + | Erc721AssetBalance + | Erc1155AssetBalance; /* Transfers */ @@ -279,19 +295,38 @@ type Erc20TokenTransfer = TokenTransferBase & { }; }; +type Erc1155TokenTransfer = TokenTransferBase & { + tokenType: TokenType.ERC1155; + tokenId: bigint; + token: { + address: string; + } + amount: bigint; +}; + export enum TransferType { DEPOSIT = "deposit", WITHDRAW = "withdraw", } export type Deposit = - & (NativeTokenTransfer | Erc20TokenTransfer | Erc721TokenTransfer) + & ( + | NativeTokenTransfer + | Erc20TokenTransfer + | Erc721TokenTransfer + | Erc1155TokenTransfer + ) & { type: TransferType.DEPOSIT; }; export type Withdraw = - & (NativeTokenTransfer | Erc20TokenTransfer | Erc721TokenTransfer) + & ( + | NativeTokenTransfer + | Erc20TokenTransfer + | Erc721TokenTransfer + | Erc1155TokenTransfer + ) & { type: TransferType.WITHDRAW; proposalId: string; diff --git a/modules/client/test/integration/client/methods.test.ts b/modules/client/test/integration/client/methods.test.ts index aec2f80d0..4d8c9429e 100644 --- a/modules/client/test/integration/client/methods.test.ts +++ b/modules/client/test/integration/client/methods.test.ts @@ -107,7 +107,7 @@ describe("Client", () => { contextParamsLocalChain.ensRegistryAddress = deployment.ensRegistry.address; - const daoCreation = await deployContracts.createTokenVotingDAO( + const daoCreation = await deployContracts.createTokenVotingDAO( deployment, "test-tokenvoting-dao", VotingMode.STANDARD, @@ -535,7 +535,6 @@ describe("Client", () => { expect( daoBalance.toString(), ).toBe(amount.toString()); - }); it("Check if dao factory has register dao permission in the dao registry", async () => { @@ -864,18 +863,15 @@ describe("Client", () => { const mockedClient = mockedGraphqlRequest.getMockedInstance( client.graphql.getClient(), ); + const lastUpdated = Math.round(Date.now() / 1000).toString(); const subgraphBalanceNative: SubgraphBalance = { + id: ADDRESS_ONE, __typename: "NativeBalance", - token: { - id: ADDRESS_ONE, - name: "TestToken", - symbol: "TST", - decimals: 18, - }, balance: "50", - lastUpdated: Math.round(Date.now() / 1000).toString(), + lastUpdated, }; const subgraphBalanceERC20: SubgraphBalance = { + id: ADDRESS_ONE, __typename: "ERC20Balance", token: { id: ADDRESS_TWO, @@ -887,28 +883,50 @@ describe("Client", () => { lastUpdated: Math.round(Date.now() / 1000).toString(), }; const subgraphBalanceERC721: SubgraphBalance = { + id: ADDRESS_ONE, __typename: "ERC721Balance", token: { - id: ADDRESS_THREE, + id: ADDRESS_TWO, name: "TestToken", symbol: "TST", - decimals: 18, }, - balance: "50", - lastUpdated: Math.round(Date.now() / 1000).toString(), + tokenIds: ["20", "30"], + lastUpdated, + }; + const subgraphBalanceERC1155: SubgraphBalance = { + id: ADDRESS_ONE, + __typename: "ERC1155Balance", + metadataUri: "https://example.org/{id}.json", + lastUpdated, + token: { + id: ADDRESS_TWO, + }, + balances: [ + { + id: ADDRESS_THREE, + amount: "10", + tokenId: "20", + }, + { + id: ADDRESS_THREE, + amount: "10", + tokenId: "30", + }, + ], }; mockedClient.request.mockResolvedValueOnce({ tokenBalances: [ subgraphBalanceNative, subgraphBalanceERC721, subgraphBalanceERC20, + subgraphBalanceERC1155, ], }); const balances = await client.methods.getDaoBalances({ daoAddressOrEns: daoAddress, }); - expect(balances!.length).toBe(3); + expect(balances!.length).toBe(4); if (balances && balances.length > 0) { expect(balances[0].type).toBe(TokenType.NATIVE); if (balances[0].type === TokenType.NATIVE) { @@ -957,6 +975,24 @@ describe("Client", () => { new Date(parseInt(subgraphBalanceERC20.lastUpdated) * 1000), ); } + + expect(balances[3].type).toBe(TokenType.ERC1155); + if (balances[3].type === TokenType.ERC1155) { + expect(balances[3].address).toBe( + subgraphBalanceERC1155.token.id, + ); + expect(balances[3].balances.length).toBe(2); + for (const index in balances[3].balances) { + const balance = balances[3].balances[index]; + const subgraphBalance = subgraphBalanceERC1155.balances[index]; + expect(balance.id).toBe(subgraphBalance.id); + expect(balance.tokenId).toBe(BigInt(subgraphBalance.tokenId)); + expect(balance.amount).toBe(BigInt(subgraphBalance.amount)); + } + expect(balances[3].updateDate).toMatchObject( + new Date(parseInt(subgraphBalanceERC1155.lastUpdated) * 1000), + ); + } } expect(mockedClient.request).toHaveBeenCalledWith(QueryTokenBalances, { @@ -1038,12 +1074,6 @@ describe("Client", () => { proposal: { id: TEST_MULTISIG_PROPOSAL_ID, }, - token: { - id: AddressZero, - name: "TestToken", - symbol: "TST", - decimals: 18, - }, }; mockedClient.request.mockResolvedValueOnce({ tokenTransfers: [subgraphTransfer], @@ -1074,7 +1104,6 @@ describe("Client", () => { const subgraphTransfer: SubgraphTransferListItem = { __typename: "ERC721Transfer", type: SubgraphTransferType.DEPOSIT, - amount: "50", createdAt: Math.round(Date.now() / 1000).toString(), txHash: TEST_TX_HASH, from: ADDRESS_ONE, @@ -1086,7 +1115,6 @@ describe("Client", () => { id: AddressZero, name: "TestToken", symbol: "TST", - decimals: 18, }, }; mockedClient.request.mockResolvedValueOnce({ @@ -1162,11 +1190,12 @@ describe("Client", () => { } } }); - it("withdraw native transfer", async () => { + it("deposit erc1155 transfer", async () => { const subgraphTransfer: SubgraphTransferListItem = { - __typename: "NativeTransfer", - type: SubgraphTransferType.WITHDRAW, + __typename: "ERC1155Transfer", + type: SubgraphTransferType.DEPOSIT, amount: "50", + tokenId: "20", createdAt: Math.round(Date.now() / 1000).toString(), txHash: TEST_TX_HASH, from: ADDRESS_ONE, @@ -1176,9 +1205,45 @@ describe("Client", () => { }, token: { id: AddressZero, - name: "TestToken", - symbol: "TST", - decimals: 18, + }, + }; + mockedClient.request.mockResolvedValueOnce({ + tokenTransfers: [subgraphTransfer], + }); + + const transfers = await client.methods.getDaoTransfers(params); + expect(transfers?.length).toBe(1); + if (transfers && transfers.length > 0) { + const transfer = transfers[0]; + expect(transfer.type).toBe(TransferType.DEPOSIT); + expect(transfer.tokenType).toBe(TokenType.ERC1155); + if ( + transfer.type === TransferType.DEPOSIT && + transfer.tokenType === TokenType.ERC1155 + ) { + expect(transfer.creationDate).toMatchObject( + new Date(parseInt(subgraphTransfer.createdAt) * 1000), + ); + expect(transfer.transactionId).toBe(subgraphTransfer.txHash); + expect(transfer.from).toBe(subgraphTransfer.from); + expect(transfer.to).toBe(subgraphTransfer.to); + expect(transfer.token.address).toBe(subgraphTransfer.token.id); + expect(transfer.tokenId).toBe(BigInt(subgraphTransfer.tokenId)); + expect(transfer.amount).toBe(BigInt(subgraphTransfer.amount)); + } + } + }); + it("withdraw native transfer", async () => { + const subgraphTransfer: SubgraphTransferListItem = { + __typename: "NativeTransfer", + type: SubgraphTransferType.WITHDRAW, + amount: "50", + createdAt: Math.round(Date.now() / 1000).toString(), + txHash: TEST_TX_HASH, + from: ADDRESS_ONE, + to: ADDRESS_TWO, + proposal: { + id: TEST_MULTISIG_PROPOSAL_ID, }, }; mockedClient.request.mockResolvedValueOnce({ @@ -1211,7 +1276,6 @@ describe("Client", () => { const subgraphTransfer: SubgraphTransferListItem = { __typename: "ERC721Transfer", type: SubgraphTransferType.WITHDRAW, - amount: "50", createdAt: Math.round(Date.now() / 1000).toString(), txHash: TEST_TX_HASH, from: ADDRESS_ONE, @@ -1223,7 +1287,6 @@ describe("Client", () => { id: AddressZero, name: "TestToken", symbol: "TST", - decimals: 18, }, }; mockedClient.request.mockResolvedValueOnce({ @@ -1301,6 +1364,50 @@ describe("Client", () => { } } }); + it("withdraw erc1155 transfer", async () => { + const subgraphTransfer: SubgraphTransferListItem = { + __typename: "ERC1155Transfer", + type: SubgraphTransferType.WITHDRAW, + amount: "50", + createdAt: Math.round(Date.now() / 1000).toString(), + txHash: TEST_TX_HASH, + from: ADDRESS_ONE, + to: ADDRESS_TWO, + proposal: { + id: TEST_MULTISIG_PROPOSAL_ID, + }, + token: { + id: AddressZero, + }, + tokenId: "20", + }; + mockedClient.request.mockResolvedValueOnce({ + tokenTransfers: [subgraphTransfer], + }); + + const transfers = await client.methods.getDaoTransfers(params); + expect(transfers?.length).toBe(1); + if (transfers && transfers.length > 0) { + const transfer = transfers[0]; + expect(transfer.type).toBe(TransferType.WITHDRAW); + expect(transfer.tokenType).toBe(TokenType.ERC1155); + if ( + transfer.type === TransferType.WITHDRAW && + transfer.tokenType === TokenType.ERC1155 + ) { + expect(transfer.creationDate).toMatchObject( + new Date(parseInt(subgraphTransfer.createdAt) * 1000), + ); + expect(transfer.transactionId).toBe(subgraphTransfer.txHash); + expect(transfer.from).toBe(subgraphTransfer.from); + expect(transfer.to).toBe(subgraphTransfer.to); + expect(transfer.proposalId).toBe(subgraphTransfer.proposal.id); + expect(transfer.token.address).toBe(subgraphTransfer.token.id); + expect(transfer.tokenId).toBe(BigInt(subgraphTransfer.tokenId)); + expect(transfer.amount).toBe(BigInt(subgraphTransfer.amount)); + } + } + }); }); it("Should get a list plugin details", async () => {