Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Support for erc1155 #272

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 12 additions & 0 deletions modules/client/src/internal/graphql-queries/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
`;
7 changes: 7 additions & 0 deletions modules/client/src/internal/graphql-queries/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ query TokenTransfers($where: TokenTransfer_filter!, $limit:Int!, $skip: Int!, $d
... on NativeTransfer {
amount
}
...on ERC1155Transfer{
amount
tokenId
token {
id
}
}
}
}
`;
91 changes: 78 additions & 13 deletions modules/client/src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type SubgraphPluginListItem = {
} | null;
appliedPluginRepo: {
subdomain: string;
} | null;
} | null;
appliedVersion: {
build: number;
release: {
Expand All @@ -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;
Expand All @@ -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
Expand Down
Loading