Skip to content

Commit

Permalink
Fix: Support for erc1155 (#272)
Browse files Browse the repository at this point in the history
* fix support for erc1155

* update changelog
  • Loading branch information
josemarinas authored Aug 17, 2023
1 parent 4cb651c commit b6a27a6
Show file tree
Hide file tree
Showing 8 changed files with 472 additions and 136 deletions.
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

0 comments on commit b6a27a6

Please sign in to comment.