Skip to content

Commit

Permalink
Feature: Add voteReplacemeent flag and fix transfers and balances que…
Browse files Browse the repository at this point in the history
…ries (#155)

* fix subgraph transfers and balances

* add vote replacement flag

* update changelog

* update dao balances

* fix comments

* fix tests

* fix build

* update changelog, examples and docs, fix comments

* fix comments

* update examples

* update examples
  • Loading branch information
josemarinas authored Feb 16, 2023
1 parent 3cece27 commit 6b9c859
Show file tree
Hide file tree
Showing 28 changed files with 398 additions and 278 deletions.
10 changes: 5 additions & 5 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ This does not estimate the gas cost of updating the allowance of an ERC20 token<
* [.hasPermission(params)](#ClientMethods+hasPermission) ⇒ <code>\*</code>
* [.getDao(daoAddressOrEns)](#ClientMethods+getDao) ⇒ <code>\*</code>
* [.getDaos({)](#ClientMethods+getDaos) ⇒ <code>\*</code>
* [.getDaoBalances(daoAddressorEns)](#ClientMethods+getDaoBalances) ⇒ <code>\*</code>
* [.getDaoBalances({)](#ClientMethods+getDaoBalances) ⇒ <code>\*</code>
* [.getDaoTransfers({)](#ClientMethods+getDaoTransfers) ⇒ <code>\*</code>

<a name="ClientMethods+createDao"></a>
Expand Down Expand Up @@ -324,15 +324,15 @@ This does not estimate the gas cost of updating the allowance of an ERC20 token<

<a name="ClientMethods+getDaoBalances"></a>

### clientMethods.getDaoBalances(daoAddressorEns) ⇒ <code>\*</code>
### clientMethods.getDaoBalances({) ⇒ <code>\*</code>
<p>Retrieves the asset balances of the given DAO, by default, ETH, DAI, USDC and USDT on Mainnet</p>

**Kind**: instance method of [<code>ClientMethods</code>](#ClientMethods)
**Returns**: <code>\*</code> - <p>{(Promise&lt;AssetBalance[] | null&gt;)}</p>

| Param | Type |
| --- | --- |
| daoAddressorEns | <code>string</code> |
| Param | Type | Description |
| --- | --- | --- |
| { | <code>DaoBalancesQueryParams</code> | <p>daoAddressOrEns, limit = 10, skip = 0, direction = SortDirection.ASC, sortBy = AssetBalanceSortBy.LAST_UPDATED, }</p> |

<a name="ClientMethods+getDaoTransfers"></a>

Expand Down
10 changes: 10 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ TEMPLATE:
-->

## [0.20.0-beta]
### Changed
- Update `getDaoBalances` parameters from `daoAddressOrEns` to `DaoBalancesQueryParams`

### Added
- Add support for Subgraph version `0.7.2-alpha`
- Add Vote Replacement flag in MajorityVoting clients
## [0.20.0-beta]
### Changed
- Updates to contracts-ethers v0.7.1
Expand Down Expand Up @@ -50,6 +57,9 @@ TEMPLATE:

## [0.19.0-alpha]

### Fixed
- Transfer and Balances queries

## [0.18.0-alpha]
### Added
- Add `pinMetadata` examples
Expand Down
20 changes: 15 additions & 5 deletions modules/client/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ import { contextParams } from "./00-context";
const context: Context = new Context(contextParams);
const client: Client = new Client(context);
const daoAddressOrEns = "0x12345...";
const balances: AssetBalance[] | null = await client.methods.getDaoBalances(daoAddressOrEns);
const balances: AssetBalance[] | null = await client.methods.getDaoBalances({
daoAddressOrEns: daoAddressOrEns,
});
console.log(balances);
/*
[
Expand Down Expand Up @@ -2365,14 +2367,22 @@ import { Client, Context, WithdrawParams } from "@aragon/sdk-client";
import { contextParams } from "../00-client/00-context";
const context: Context = new Context(contextParams);
const client: Client = new Client(context);
const data: Uint8Array = new Uint8Array([12, 56]);

const params: WithdrawParams = client.decoding.withdrawAction(data);
const action = {
to: "0x<token-contract>",
value: BigInt(0),
data: new Uint8Array([12, 56]),
};
const params: WithdrawParams = client.decoding.withdrawAction(
action.to,
action.value,
action.data,
);

console.log(params);
/*
{
type: "Erc20",
type: "erc20",
recipientAddress: "0x1234567890123456789012345678901234567890",
amount: 10n,
tokenAddress: "0x1234567890123456789012345678901234567890",
Expand Down Expand Up @@ -2875,7 +2885,7 @@ import {
TokenType,
WithdrawParams,
} from "@aragon/sdk-client";
import {} from "../../src/interfaces";

import { contextParams } from "../00-client/00-context";

// Create a simple context
Expand Down
4 changes: 3 additions & 1 deletion modules/client/examples/00-client/08-get-balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { contextParams } from "./00-context";
const context: Context = new Context(contextParams);
const client: Client = new Client(context);
const daoAddressOrEns = "0x12345...";
const balances: AssetBalance[] | null = await client.methods.getDaoBalances(daoAddressOrEns);
const balances: AssetBalance[] | null = await client.methods.getDaoBalances({
daoAddressOrEns: daoAddressOrEns,
});
console.log(balances);
/*
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TokenType,
WithdrawParams,
} from "@aragon/sdk-client";
import {} from "../../src/interfaces";

import { contextParams } from "../00-client/00-context";

// Create a simple context
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": "0.20.0-beta",
"version": "0.21.0-beta",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion modules/client/src/addresslistVoting/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface IAddresslistVotingClient {
export type AddresslistVotingProposal = ProposalBase & {
result: AddresslistVotingProposalResult;
settings: IProposalSettings;
votes: Array<{ address: string; vote: VoteValues }>;
votes: Array<{ address: string; vote: VoteValues, voteReplaced: boolean }>;
totalVotingWeight: number;
creationBlockNumber: number;
executionDate: Date;
Expand Down
12 changes: 7 additions & 5 deletions modules/client/src/addresslistVoting/internal/client/methods.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
boolArrayToBitmap,
decodeRatio,
GraphQLError,
InvalidAddressError,
InvalidAddressOrEnsError,
Expand Down Expand Up @@ -32,7 +33,6 @@ import {
IExecuteProposalParams,
IProposalQueryParams,
IVoteProposalParams,
parseEtherRatio,
ProposalCreationSteps,
ProposalCreationStepValue,
ProposalMetadata,
Expand Down Expand Up @@ -481,11 +481,13 @@ export class AddresslistVotingClientMethods extends ClientCore
}
return {
minDuration: parseInt(addresslistVotingPlugin.minDuration),
supportThreshold: parseEtherRatio(
addresslistVotingPlugin.supportThreshold,
supportThreshold: decodeRatio(
BigInt(addresslistVotingPlugin.supportThreshold),
6,
),
minParticipation: parseEtherRatio(
addresslistVotingPlugin.minParticipation,
minParticipation: decodeRatio(
BigInt(addresslistVotingPlugin.minParticipation),
6,
),
minProposerVotingPower: BigInt(
addresslistVotingPlugin.minProposerVotingPower,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ query AddresslistVotingProposal($proposalId: ID!) {
value
data
}
yes,
no,
yes
no
abstain
votingMode
supportThreshold
Expand All @@ -33,6 +33,7 @@ query AddresslistVotingProposal($proposalId: ID!) {
address
}
voteOption
voteReplaced
}
totalVotingPower
minVotingPower
Expand Down
1 change: 1 addition & 0 deletions modules/client/src/addresslistVoting/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function toAddresslistVotingProposal(
votes: proposal.voters.map(
(voter: SubgraphAddresslistVotingVoterListItem) => {
return {
voteReplaced: voter.voteReplaced,
address: voter.voter.address,
vote: SubgraphVoteValuesMap.get(voter.voteOption) as VoteValues,
};
Expand Down
6 changes: 6 additions & 0 deletions modules/client/src/client-common/interfaces/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export interface IPagination {
direction?: SortDirection;
}

export type Pagination = {
skip?: number;
limit?: number;
direction?: SortDirection;
};

export enum SortDirection {
ASC = "asc",
DESC = "desc",
Expand Down
1 change: 1 addition & 0 deletions modules/client/src/client-common/interfaces/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export type SubgraphVoterListItemBase = {
voter: {
address: string;
};
voteReplaced: boolean
voteOption: SubgraphVoteValues;
};

Expand Down
14 changes: 0 additions & 14 deletions modules/client/src/client-common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { Interface } from "@ethersproject/abi";
import { id } from "@ethersproject/hash";
import { Log } from "@ethersproject/providers";
import { InvalidVotingModeError } from "@aragon/sdk-common";
import { formatEther } from "@ethersproject/units";
import { InvalidPrecisionError } from "@aragon/sdk-common";

export function unwrapProposalParams(
params: ICreateProposalParams,
Expand Down Expand Up @@ -125,15 +123,3 @@ export function votingModeFromContracts(votingMode: number): VotingMode {
}
}

// TODO
// delete me
export function parseEtherRatio(ether: string, precision: number = 2): number {
if (precision <= 0 || !Number.isInteger(precision)) {
throw new InvalidPrecisionError();
}
return parseFloat(
parseFloat(
formatEther(ether),
).toFixed(precision),
);
}
Loading

0 comments on commit 6b9c859

Please sign in to comment.