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

Refactor API: ForwardingPath descriptions + App intent actions #256

Merged
merged 85 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
5c4b021
Types: Update types definition
0xGabi Aug 20, 2020
e36825a
Types: Fix imports
0xGabi Aug 20, 2020
e3fb789
Refactor: update imports and definitions for Transction entity
0xGabi Aug 20, 2020
453b4ef
Refactor: Create Transaction entity & update how handle transactions
0xGabi Aug 20, 2020
163166a
Comment logic related to forwarding path description
0xGabi Aug 20, 2020
4c0890b
Comment logic related to forwarding path description
0xGabi Aug 20, 2020
552bda1
Merge branch 'refactor-transaction' of github.com:aragon/connect into…
0xGabi Aug 20, 2020
c6f1740
Refactor: Add Intent entity + refactor calculate path logic
0xGabi Aug 20, 2020
9456cbe
Refactor: Remove TransactionIntent entity + update logic
0xGabi Aug 20, 2020
d84e4b1
Fix import
0xGabi Aug 20, 2020
097325a
Refactor: Add ForwardingPath entity + update logic to describe a Forw…
0xGabi Aug 20, 2020
0d4bd4a
Merge
0xGabi Aug 26, 2020
867d0b3
Types: update types definition
0xGabi Aug 31, 2020
9f574f9
Core: Update Organization API
0xGabi Aug 31, 2020
8b28d2d
Core: Remove Intent entity + update App API
0xGabi Aug 31, 2020
81e4b28
Core: Calculate path logic + refactor utilities
0xGabi Aug 31, 2020
144bf47
Connector: fetch Repo latestsVersion
0xGabi Aug 31, 2020
fa6150b
Core: ForwardingPath descriptor logic
0xGabi Aug 31, 2020
d4c6cbf
Merge remote-tracking branch 'origin/master' into refactor-api
0xGabi Aug 31, 2020
c1afe43
Chore: Code cleanup
0xGabi Sep 1, 2020
613c7cc
Fix build
0xGabi Sep 1, 2020
2214b0a
Fix tests
0xGabi Sep 1, 2020
111305b
Merge branch 'refactor-api' of github.com:aragon/connect into refacto…
0xGabi Sep 1, 2020
a401390
Chore: clean code
0xGabi Sep 2, 2020
06b67f8
Chore: More code cleanups
0xGabi Sep 3, 2020
55eb610
Chore: fix typos
0xGabi Sep 3, 2020
d0d75ca
Add a few tests + clean code
0xGabi Sep 3, 2020
ad86cd1
Core: Add pre-transaction logic
0xGabi Sep 3, 2020
d69546a
Core: Fix radspec postprocess + findAppMethodFromData
0xGabi Sep 3, 2020
c385c6a
Core: remove side effects from postprocess function
0xGabi Sep 3, 2020
f3f5ae2
Core: Have a path object on the ForwardingPath
0xGabi Sep 4, 2020
40e596b
Tests: Fix disputable subgraph test
0xGabi Sep 8, 2020
e49264d
v0.8.0-alpha.1
0xGabi Sep 8, 2020
e7adcbb
Merge branch 'master' of github.com:aragon/connect into refactor-api
facuspagnuolo Sep 8, 2020
3d719b0
agreement: implement sign action
facuspagnuolo Sep 4, 2020
7315e10
agreement: implement close action
facuspagnuolo Sep 6, 2020
1b70b23
agreement: implement settle action
facuspagnuolo Sep 6, 2020
2781b43
core: support resetting erc20 approvals
facuspagnuolo Sep 7, 2020
b702303
agreement: implement challenge action
facuspagnuolo Sep 7, 2020
43e1f72
agreement: implement dispute action
facuspagnuolo Sep 7, 2020
ea96663
agreement: fail on not-found actions
facuspagnuolo Sep 8, 2020
4e6447b
Merge branch 'master' of github.com:aragon/connect into refactor-api
facuspagnuolo Sep 8, 2020
dd4c389
Merge branch 'refactor-api' of github.com:aragon/connect into agreeme…
facuspagnuolo Sep 8, 2020
8a73601
Core: use artifact roles data to postprocess description
0xGabi Sep 9, 2020
dcffe03
Merge remote-tracking branch 'origin/master' into refactor-api
0xGabi Sep 9, 2020
58e4757
Merge branch 'refactor-api' of github.com:aragon/connect into refacto…
0xGabi Sep 9, 2020
a1b1442
DisputableVoting: Implement new vote action
facuspagnuolo Sep 9, 2020
c283572
DisputableVoting: Implement cast vote action
facuspagnuolo Sep 9, 2020
aa99f9a
DisputableVoting: Remove vote unused internal method
facuspagnuolo Sep 9, 2020
c45b5ad
Agreement: Implement actions (#264)
facuspagnuolo Sep 9, 2020
6f82660
Merge branch 'refactor-api' into disputable_voting/implement_actions
0xGabi Sep 9, 2020
b900bd0
Update packages/connect-disputable-voting/subgraph/package.json
0xGabi Sep 9, 2020
49eee2d
Core: fix postprocess roles parsing
0xGabi Sep 9, 2020
f881b25
Merge remote-tracking branch 'origin/disputable_voting/implement_acti…
0xGabi Sep 9, 2020
3bb5f0e
Merge remote-tracking branch 'origin/disputable_voting/implement_acti…
0xGabi Sep 9, 2020
8da25a5
v0.8.0-alpha.2
0xGabi Sep 9, 2020
177b041
DisputableVoting: Compute actual quiet ending extension (#279)
facuspagnuolo Sep 9, 2020
721454a
DisputableVoting: Handle no settlement answer (#280)
facuspagnuolo Sep 10, 2020
50065ae
DisputableVoting: Fix has ended for implicit settlements (#282)
facuspagnuolo Sep 10, 2020
1c1508e
Agreement: Handle null signers (#281)
facuspagnuolo Sep 10, 2020
74d40bf
Merge branch 'refactor-api' of github.com:aragon/connect into refacto…
0xGabi Sep 10, 2020
45909c3
DisputableVoting: Fix collateral requirement parsing (#283)
facuspagnuolo Sep 11, 2020
8d6e154
Agreement: Update staking ABI (#284)
facuspagnuolo Sep 11, 2020
39b18b8
Core: fix abi overload case
0xGabi Sep 11, 2020
859ab3b
Merge branch 'refactor-api' of github.com:aragon/connect into refacto…
0xGabi Sep 11, 2020
4298d0f
v0.8.0-alpha.3
0xGabi Sep 11, 2020
8d66307
Core: Fix pre-approvals (#285)
facuspagnuolo Sep 11, 2020
a68783e
v0.8.0-alpha.4
facuspagnuolo Sep 11, 2020
b5b35f2
Agreement: Reduce staking movements complexity (#286)
facuspagnuolo Sep 14, 2020
1340963
DisputableVoting: Implement voting checks (#287)
facuspagnuolo Sep 14, 2020
1cbc0f6
v0.8.0-alpha.5
0xGabi Sep 14, 2020
7570926
Agreement: Allow nullable staking info (#293)
facuspagnuolo Sep 17, 2020
fc9c500
DisputableVoting: Implement settlement offer (#291)
facuspagnuolo Sep 17, 2020
47045de
Cache token symbols
facuspagnuolo Sep 17, 2020
5e762f5
Update agreement and disputable voting subraphs for rinkeby-staging
facuspagnuolo Sep 17, 2020
326357b
Agreement: Fix staking movement mapping
facuspagnuolo Sep 17, 2020
8184697
DisputableVoting: Implement has voted subscription
facuspagnuolo Sep 17, 2020
7208276
Examples: add forwarding-path (#290)
bpierre Sep 25, 2020
eca5746
Core: prefer generating signature from ABI (#292)
0xGabi Sep 25, 2020
085547e
Merge remote-tracking branch 'origin/master' into refactor-api
0xGabi Sep 25, 2020
62e622f
Chore: arrange imports
0xGabi Sep 25, 2020
081751a
Chore: fix type
0xGabi Sep 25, 2020
40288dd
Core: add changes from review comments
0xGabi Sep 26, 2020
6f063bf
Merge remote-tracking branch 'origin/master' into refactor-api
0xGabi Dec 30, 2020
1731eba
Core: add missing imports + update lock
0xGabi Dec 30, 2020
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
11 changes: 11 additions & 0 deletions packages/connect-core/src/entities/App.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ethers } from 'ethers'
0xGabi marked this conversation as resolved.
Show resolved Hide resolved

import Organization from './Organization'
import Repo from './Repo'
import Role from './Role'
Expand Down Expand Up @@ -59,6 +61,15 @@ export default class App {
return this.organization.connection.orgConnector
}

interface(): ethers.utils.Interface {
if (!this.abi) {
throw new Error(
`No ABI specified in app for ${this.address}. Make sure the metada for the app is available`
)
}
return new ethers.utils.Interface(this.abi)
}

async repo(): Promise<Repo> {
return this.orgConnector().repoForApp(this.organization, this.address)
}
Expand Down
15 changes: 15 additions & 0 deletions packages/connect-core/src/entities/Transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Address } from '@aragon/connect-types'

import { TransactionData } from '../types'

export default class Transaction {
readonly data: string
readonly from: Address
readonly to: Address

constructor(data: TransactionData) {
this.data = data.data
this.from = data.from
this.to = data.to
}
}
132 changes: 32 additions & 100 deletions packages/connect-core/src/utils/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
import { ethers } from 'ethers'

import { erc20ABI, forwarderAbi, forwarderFeeAbi } from './abis'
import { isFullMethodSignature } from './app'
import App from '../entities/App'
import Transaction from '../entities/Transaction'

export interface Transaction {
data: string
from?: string
to: string
}

export interface TransactionWithTokenData extends Transaction {
token: {
address: string
value: string
spender: string
}
}

export async function createDirectTransaction(
sender: string,
destination: string,
methodAbiFragment: ethers.utils.FunctionFragment,
params: any[]
): Promise<Transaction> {
let transactionOptions = {}

// If an extra parameter has been provided, it is the transaction options if it is an object
Copy link
Contributor Author

@0xGabi 0xGabi Sep 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To provide overrides is no longer relevant to the context of Connect as we just return a raw transaction object.

if (
methodAbiFragment.inputs.length + 1 === params.length &&
typeof params[params.length - 1] === 'object'
) {
const options = params.pop()
transactionOptions = { ...transactionOptions, ...options }
}

const ethersInterface = new ethers.utils.Interface([methodAbiFragment])

// The direct transaction we eventually want to perform
return {
...transactionOptions, // Options are overwriten by the values below
from: sender,
to: destination,
data: ethersInterface.encodeFunctionData(
ethers.utils.FunctionFragment.from(methodAbiFragment),
params
),
}
interface TokenData {
address: string
value: string
spender: string
}

export async function createDirectTransactionForApp(
Expand All @@ -55,42 +16,17 @@ export async function createDirectTransactionForApp(
methodSignature: string,
params: any[]
): Promise<Transaction> {
if (!app) {
throw new Error(`Could not create transaction due to missing app artifact`)
}
const appInterface = app.interface()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the app Ethers Interface helper directly 🙌

const functionFragment = appInterface.getFunction(methodSignature)

const destination = app.address

if (!app.abi) {
throw new Error(`No ABI specified in artifact for ${destination}`)
}

const methodAbiFragment = app.abi.find((method) => {
// If the full signature isn't given, just find the first overload declared
if (!isFullMethodSignature(methodSignature)) {
return method.name === methodSignature
}

// Fallback functions don't have inputs in the ABI
const currentParameterTypes = Array.isArray(method.inputs)
? method.inputs.map(({ type }) => type)
: []
const currentMethodSignature = `${method.name}(${currentParameterTypes.join(
','
)})`
return currentMethodSignature === methodSignature
return new Transaction({
from: sender,
to: app.address,
data: appInterface.encodeFunctionData(
ethers.utils.FunctionFragment.from(functionFragment),
params
),
})

if (!methodAbiFragment) {
throw new Error(`${methodSignature} not found on ABI for ${destination}`)
}

return createDirectTransaction(
sender,
destination,
methodAbiFragment as ethers.utils.FunctionFragment,
params
)
}

export function createForwarderTransactionBuilder(
Expand All @@ -99,24 +35,23 @@ export function createForwarderTransactionBuilder(
): Function {
const forwarder = new ethers.utils.Interface(forwarderAbi)

return (forwarderAddress: string, script: string): Transaction => ({
...directTransaction, // Options are overwriten by the values below
from: sender,
to: forwarderAddress,
data: forwarder.encodeFunctionData('forward', [script]),
})
return (forwarderAddress: string, script: string): Transaction =>
new Transaction({
...directTransaction, // Options are overwriten by the values below
from: sender,
to: forwarderAddress,
data: forwarder.encodeFunctionData('forward', [script]),
})
}

export async function buildPretransaction(
transaction: TransactionWithTokenData,
transaction: Transaction,
tokenData: TokenData,
provider: ethers.providers.Provider
): Promise<Transaction | undefined> {
// Token allowance pretransactionn
const {
from,
to,
token: { address: tokenAddress, value: tokenValue, spender },
} = transaction
const { from, to } = transaction
const { address: tokenAddress, value: tokenValue, spender } = tokenData

// Approve the transaction destination unless an spender is passed to approve a different contract
const approveSpender = spender || to
Expand Down Expand Up @@ -144,11 +79,11 @@ export async function buildPretransaction(

const erc20 = new ethers.utils.Interface(erc20ABI)

return {
return new Transaction({
from,
to: tokenAddress,
data: erc20.encodeFunctionData('approve', [approveSpender, tokenValue]),
}
})
}

return undefined
Expand Down Expand Up @@ -181,16 +116,13 @@ export async function buildForwardingFeePretransaction(

if (feeDetails.tokenAddress && feeDetails.amount > BigInt(0)) {
// Needs a token approval pretransaction
const forwardingTxWithTokenData: TransactionWithTokenData = {
...forwardingTransaction,
token: {
address: feeDetails.tokenAddress,
spender: forwarderAddress, // since it's a forwarding transaction, always show the real spender
value: feeDetails.amount.toString(),
},
const tokenData: TokenData = {
address: feeDetails.tokenAddress,
spender: forwarderAddress, // since it's a forwarding transaction, always show the real spender
value: feeDetails.amount.toString(),
}

return buildPretransaction(forwardingTxWithTokenData, provider)
return buildPretransaction(forwardingTransaction, tokenData, provider)
}
return undefined
}