Skip to content

Commit

Permalink
Refactor transactions (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xGabi authored Jun 26, 2020
1 parent b1edace commit cf1db94
Show file tree
Hide file tree
Showing 16 changed files with 761 additions and 989 deletions.
27 changes: 13 additions & 14 deletions SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# Table of contents

* [⚡ Aragon Connect](README.md)
- [⚡ Aragon Connect](README.md)

## GUIDES

* [Getting started](guides/getting-started.md)
* [Aragon app subgraph](guides/subgraph-template.md)
- [Getting started](guides/getting-started.md)
- [Aragon app subgraph](guides/subgraph-template.md)

## API REFERENCE

* [connect\(\)](api-reference/connect.md)
* [App](api-reference/app.md)
* [Connectors](api-reference/connectors.md)
* [Intent](api-reference/transaction-intent.md)
* [Organization](api-reference/organization.md)
* [Permission](api-reference/permission.md)
* [Repo](api-reference/repo.md)
* [Role](api-reference/role.md)
* [TransactionPath](api-reference/transaction-path.md)
* [TransactionRequest](api-reference/transaction-request.md)

- [connect\(\)](api-reference/connect.md)
- [App](api-reference/app.md)
- [Connectors](api-reference/connectors.md)
- [Intent](api-reference/transaction-intent.md)
- [Organization](api-reference/organization.md)
- [Permission](api-reference/permission.md)
- [Repo](api-reference/repo.md)
- [Role](api-reference/role.md)
- [TransactionPath](api-reference/transaction-path.md)
- [TransactionRequest](api-reference/transaction-request.md)
29 changes: 14 additions & 15 deletions api-reference/transaction-intent.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ An TransactionIntent to create an Ethereum transaction on, or through, an Aragon

Get all the possible transaction paths for a given address. This can be useful to let users pick the one they want. Otherwise, `TransactionIntent#transactions()` can get called directly.

| Name | Type | Description |
| :--- | :--- | :--- |
| `account` | `String` | The account that will sign the transaction. |
| `options` | `Object` | Options object. |
| `options.as` | `String` | Address of an Aragon organization, or its agent app, through which the paths should get created. |
| `options.path` | `String[]` | An array of address that conform a transaction path, it will be verified without calculating other paths. |
| returns | `TransactionPath[]` | Array of all the possible transaction paths. |
| Name | Type | Description |
| :------------- | :--------------------------- | :-------------------------------------------------------------------------------------------------------- |
| `account` | `String` | The account that will sign the transaction. |
| `options` | `Object` | Options object. |
| `options.as` | `String` | Address of an Aragon organization, or its agent app, through which the paths should get created. |
| `options.path` | `String[]` | An array of address that conform a transaction path, it will be verified without calculating other paths. |
| returns | `Promise<TransactionPath[]>` | Array of all the possible transaction paths. |

### TransactionIntent\#transactions\(account, options\)

Get the transactions to execute for the shortest transaction path.

This is an easier way to do `TransactionIntent.paths(account, options)[0].transactions`

| Name | Type | Description |
| :--- | :--- | :--- |
| `account` | `String` | The account that will sign the transaction. |
| `options` | `Object` | Options object. |
| `options.as` | `String` | Address of an Aragon organization, or its agent app, through which the paths should get created. |
| `options.path` | `String[]` | An array of address that conform a transaction path, it will be verified without calculating other paths. |
| returns | `TransactionRequest[]` | The transactions corresponding to the shortest transaction path. |

| Name | Type | Description |
| :------------- | :------------------------------ | :-------------------------------------------------------------------------------------------------------- |
| `account` | `String` | The account that will sign the transaction. |
| `options` | `Object` | Options object. |
| `options.as` | `String` | Address of an Aragon organization, or its agent app, through which the paths should get created. |
| `options.path` | `String[]` | An array of address that conform a transaction path, it will be verified without calculating other paths. |
| returns | `Promise<TransactionRequest[]>` | The transactions corresponding to the shortest transaction path. |
13 changes: 7 additions & 6 deletions api-reference/transaction-path.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Represents a single transaction path.

## Properties

| Name | Type | Description |
| :--- | :--- | :--- |
| `apps` | `App[]` | Get all the apps for the path. |
| `destination` | `App` | Get the destination of the transactions path. |
| `transactions` | `TransactionRequest[]` | Transaction request objects, ready to be sent to an Ethereum library. |

| Name | Type | Description |
| :---------------------------- | :----------------------- | :----------------------------------------------------------------------------- |
| `apps` | `App[]` | Get all the apps for the path. |
| `transactionsDescribed` | `TransactionDescribed[]` | List of transactions in the path with their corresponding radspec description. |
| `destination` | `App` | Get the destination of the transactions path. |
| `forwardingFeePretransaction` | `TransactionRequest[]` | Optional pre-transaction, needed with the forwarder fee interface. |
| `transactions` | `TransactionRequest[]` | List of transations in the path, ready to be sent to an Ethereum library. |
18 changes: 7 additions & 11 deletions api-reference/transaction-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ An object describing a transaction that can get signed by a library like ethers.

## Properties

| Name | Type | Description |
| :--- | :--- | :--- |
| `chainId` | `Number` | Chain ID of the network. |
| `data` | `String` | Transaction data. |
| `from` | `String` | Address to use as default sender. |
| `gas` | `String` | Price \(in wei\) per unit of gas. Duplicate of `gasPrice`. |
| `gasLimit` | `Number` | Maximum gas this transaction may spend. |
| `gasPrice` | `String` | Price \(in wei\) per unit of gas. |
| `to` | `String` | Target address or ENS name. |
| `value` | `String` | Amount \(in wei\) this transaction is sending. |

| Name | Type | Description |
| :--------------------- | :------------- | :------------------------------------------------------------------------------------------- |
| `descriptionAnnotated` | `Annotation[]` | List of the Radspec description bindings with the properties `{ type: string, value: any }`. |
| `description` | `string` | Radspec description for the transaction. |
| `data` | `String` | Transaction data. |
| `from` | `String` | Address to use as default sender. |
| `to` | `String` | Target address or ENS name. |
2 changes: 1 addition & 1 deletion examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@aragon/connect-thegraph": "*",
"@aragon/connect-thegraph-tokens": "*",
"@aragon/connect-thegraph-voting": "*",
"ethers": "^5.0.0-beta.188",
"ethers": "^5.0.0",
"graphql-tag": "^2.10.3"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion examples/nodejs/src/transaction-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ async function main() {

console.log('\nTransactions on the path:')
txPath.transactions.map((tx: any) => console.log(tx))
txPath.transactionsDescribed.map((tx: any) => console.log(tx))
}

main()
.then(() => process.exit(0))
.catch((err) => {
.catch(err => {
console.log(`Error: `, err)
console.log(
'\nPlease report any problem to https://github.com/aragon/connect/issues'
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"typescript": "^3.8.3"
},
"dependencies": {
"ethers": "^5.0.0-beta.188",
"ethers": "^5.0.0",
"radspec": "^2.0.0-rc.1"
},
"description": "Access and interact with Aragon Organizations and their apps.",
Expand Down
34 changes: 15 additions & 19 deletions packages/connect-core/src/transactions/TransactionIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default class TransactionIntent {
this.#org = org
this.#provider = provider

Object.assign(this, data)
this.contractAddress = data.contractAddress
this.functionArgs = data.functionArgs
this.functionName = data.functionName
}

async paths(
Expand All @@ -38,42 +40,36 @@ export default class TransactionIntent {
options?: { as?: string; path?: string[] }
): Promise<TransactionPath> {
const apps = await this.#org.apps()
const destination = this.contractAddress

const transactions = await calculateTransactionPath(
const {
forwardingFeePretransaction,
transactions,
} = await calculateTransactionPath(
account,
destination,
this.contractAddress,
this.functionName,
this.functionArgs,
apps,
this.#provider
)

const describedTransactions = await describeTransactionPath(
const transactionsDescribed = await describeTransactionPath(
transactions,
apps,
this.#provider
)

// Include chainId and create Transaction Request objects
const chainId = (await this.#provider.getNetwork()).chainId
const transactionsRequests = describedTransactions.map((transaction) => {
return new TransactionRequest({
...transaction,
chainId,
})
})

const appsOnPath = transactions.map((transaction) => transaction.to)
const appsOnPath = transactions.map(transaction => transaction.to)

return new TransactionPath({
apps: apps.filter((app) =>
appsOnPath.some((address) => address === app.address)
apps: apps.filter(app =>
appsOnPath.some(address => address === app.address)
),
destination: apps.find(
(app) => app.address == destination
app => app.address == this.contractAddress
) as Application,
transactions: transactionsRequests,
forwardingFeePretransaction,
transactions: transactionsDescribed.map(tx => new TransactionRequest(tx)),
})
}

Expand Down
7 changes: 6 additions & 1 deletion packages/connect-core/src/transactions/TransactionPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import Application from '../entities/Application'
export interface TransactionPathData {
apps: Application[]
destination: Application
forwardingFeePretransaction?: TransactionRequest
transactions: TransactionRequest[]
}

export default class TransactionPath {
readonly apps!: Application[]
readonly destination!: Application
readonly forwardingFeePretransaction?: TransactionRequest
readonly transactions!: TransactionRequest[]

constructor(data: TransactionPathData) {
Object.assign(this, data)
this.apps = data.apps
this.destination = data.destination
this.forwardingFeePretransaction = data.forwardingFeePretransaction
this.transactions = data.transactions
}
}
40 changes: 13 additions & 27 deletions packages/connect-core/src/transactions/TransactionRequest.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
export interface TransactionRequestData {
to: string
from: string
data: string
pretransaction?: {
to: string
from: string
data: string
}
description?: string
annotatedDescription?: Annotation[]
chainId?: number
gas?: string
gasPrice?: string
gasLimit?: string
descriptionAnnotated?: Annotation[]
data: string
from: string
to: string
}

export interface Annotation {
Expand All @@ -21,22 +12,17 @@ export interface Annotation {
}

export default class TransactionRequest {
readonly to!: string
readonly from!: string
readonly data!: string
readonly pretransaction?: {
to: string
from: string
data: string
}
readonly description?: string
readonly annotatedDescription?: Annotation[]
readonly gas?: string
readonly gasPrice?: string
readonly gasLimit?: string
readonly chainId?: number
readonly descriptionAnnotated?: Annotation[]
readonly data!: string
readonly from!: string
readonly to!: string

constructor(data: TransactionRequestData) {
Object.assign(this, data)
this.description = data.description
this.descriptionAnnotated = data.descriptionAnnotated
this.data = data.data
this.from = data.from
this.to = data.to
}
}
Loading

0 comments on commit cf1db94

Please sign in to comment.