forked from aragon/osx-plugin-template-hardhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: emmdim <[email protected]>
- Loading branch information
Showing
9 changed files
with
970 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,110 @@ | ||
export const DEFAULT_OFFCHAIN_VOTING_REPO_ADDRESS = "0x0000000000000000000000000000000000000000"; | ||
// import { MetadataAbiInput } from './types'; | ||
import { IERC20MintableUpgradeable__factory } from '@aragon/osx-ethers'; | ||
import { MetadataAbiInput } from '@aragon/sdk-client-common'; | ||
import { VocdoniVoting__factory } from '@vocdoni/offhcain-voting-ethers'; | ||
|
||
export const DEFAULT_OFFCHAIN_VOTING_REPO_ADDRESS = | ||
'0x0000000000000000000000000000000000000000'; | ||
|
||
export const DEFAULT_OFFCHAIN_VOTING_BACKEND_URL = | ||
"https://example.otg/offchain-voting/rpc"; | ||
'https://example.otg/offchain-voting/rpc'; | ||
|
||
const majorityVotingInterface = VocdoniVoting__factory.createInterface(); | ||
|
||
export const AVAILABLE_FUNCTION_SIGNATURES: string[] = [ | ||
VocdoniVoting__factory.createInterface() | ||
.getFunction('updatePluginSettings') | ||
.format('minimal'), | ||
IERC20MintableUpgradeable__factory.createInterface() | ||
.getFunction('mint') | ||
.format('minimal'), | ||
]; | ||
|
||
export const FAILING_PROPOSAL_AVAILABLE_FUNCTION_SIGNATURES = [ | ||
majorityVotingInterface.getFunction('updatePluginSettings').format('minimal'), | ||
]; | ||
|
||
export const INSTALLATION_ABI: MetadataAbiInput[] = [ | ||
{ | ||
components: [ | ||
{ | ||
internalType: 'bool', | ||
name: 'onlyCommitteeProposalCreation', | ||
type: 'bool', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'uint16', | ||
name: 'minTallyApprovals', | ||
type: 'uint16', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'uint32', | ||
name: 'minParticipation', | ||
type: 'uint32', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'uint32', | ||
name: 'supportThreshold', | ||
type: 'uint32', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'uint64', | ||
name: 'minDuration', | ||
type: 'uint64', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: 'daoTokenAddress', | ||
type: 'address', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'uint256', | ||
name: 'minProposerVotingPower', | ||
type: 'uint256', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'string', | ||
name: 'censusStrategy', | ||
type: 'string', | ||
description: '', | ||
}, | ||
], | ||
internalType: 'struct VocdoniVoting.PluginSettings', | ||
name: 'pluginSettings', | ||
type: 'tuple', | ||
description: '', | ||
}, | ||
{ | ||
components: [ | ||
{ | ||
internalType: 'address', | ||
name: 'to', | ||
type: 'address', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'uint256', | ||
name: 'value', | ||
type: 'uint256', | ||
description: '', | ||
}, | ||
{ | ||
internalType: 'bytes', | ||
name: 'data', | ||
type: 'bytes', | ||
description: '', | ||
}, | ||
], | ||
internalType: 'struct IDAO.Action[]', | ||
name: 'actions', | ||
type: 'tuple[]', | ||
description: '', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,126 @@ | ||
import { OffchainVotingClientCore } from "../core"; | ||
import { IOffchainVotingClientEncoding } from "../interfaces"; | ||
import metadata from '../../../../contracts/src/build-metadata.json'; | ||
import { INSTALLATION_ABI } from '../constants'; | ||
import { ITokenVotingClientEncoding } from '../interfaces'; | ||
import { OffchainVotingPluginInstall } from '../types'; | ||
import { | ||
mintTokenParamsToContract, | ||
tokenVotingInitParamsToContract, | ||
} from '../utils'; | ||
import { IERC20MintableUpgradeable__factory } from '@aragon/osx-ethers'; | ||
import { | ||
MintTokenParams, | ||
TokenVotingPluginInstall, | ||
encodeUpdateVotingSettingsAction, | ||
VotingSettings, | ||
} from '@aragon/sdk-client'; | ||
import { | ||
ClientCore, | ||
DaoAction, | ||
getNamedTypesFromMetadata, | ||
LIVE_CONTRACTS, | ||
PluginInstallItem, | ||
SupportedNetwork, | ||
SupportedNetworksArray, | ||
} from '@aragon/sdk-client-common'; | ||
import { | ||
hexToBytes, | ||
InvalidAddressError, | ||
UnsupportedNetworkError, | ||
} from '@aragon/sdk-common'; | ||
import { defaultAbiCoder } from '@ethersproject/abi'; | ||
import { isAddress } from '@ethersproject/address'; | ||
import { Networkish, getNetwork } from '@ethersproject/providers'; | ||
|
||
export class OffchainVotingClientEncoding extends OffchainVotingClientCore | ||
implements IOffchainVotingClientEncoding { | ||
// add your action encoders here | ||
const prepareInstallationDataTypes = getNamedTypesFromMetadata( | ||
metadata.pluginSetup.prepareInstallation.inputs | ||
); | ||
|
||
/** | ||
* Encoding module the SDK TokenVoting Client | ||
*/ | ||
export class OffchainVotingClientEncoding | ||
extends ClientCore | ||
implements ITokenVotingClientEncoding | ||
{ | ||
/** | ||
* Computes the parameters to be given when creating the DAO, | ||
* so that the plugin is configured | ||
* | ||
* @param {TokenVotingPluginInstall} params | ||
* @param {Networkish} network | ||
* @return {*} {PluginInstallItem} | ||
* @memberof TokenVotingClientEncoding | ||
*/ | ||
static getPluginInstallItem( | ||
params: OffchainVotingPluginInstall, | ||
network: Networkish | ||
): PluginInstallItem { | ||
const networkName = getNetwork(network).name as SupportedNetwork; | ||
if (!SupportedNetworksArray.includes(networkName)) { | ||
throw new UnsupportedNetworkError(networkName); | ||
} | ||
const args = tokenVotingInitParamsToContract(params); | ||
const hexBytes = defaultAbiCoder.encode(prepareInstallationDataTypes, | ||
args | ||
//[ | ||
// Object.values([params.daoAddress]), | ||
// Object.values(params.votingSettings), | ||
// [params.useToken?.tokenAddress, '', ''], | ||
// Object.values(params.newToken?.), | ||
] | ||
//); | ||
return { | ||
id: LIVE_CONTRACTS[networkName].tokenVotingRepo, | ||
data: hexToBytes(hexBytes), | ||
}; | ||
} | ||
/** | ||
* Computes the parameters to be given when creating a proposal that updates the governance configuration | ||
* | ||
* @param {string} pluginAddress | ||
* @param {VotingSettings} params | ||
* @return {*} {DaoAction} | ||
* @memberof TokenVotingClientEncoding | ||
*/ | ||
public updatePluginSettingsAction( | ||
pluginAddress: string, | ||
params: VotingSettings | ||
): DaoAction { | ||
if (!isAddress(pluginAddress)) { | ||
throw new InvalidAddressError(); | ||
} | ||
// TODO: check if to and value are correct | ||
return { | ||
to: pluginAddress, | ||
value: BigInt(0), | ||
data: encodeUpdateVotingSettingsAction(params), | ||
}; | ||
} | ||
|
||
/** | ||
* Computes the parameters to be given when creating a proposal that mints an amount of ERC-20 tokens to an address | ||
* | ||
* @param {string} minterAddress | ||
* @param {MintTokenParams} params | ||
* @return {*} {DaoAction} | ||
* @memberof TokenVotingClientEncoding | ||
*/ | ||
public mintTokenAction( | ||
minterAddress: string, | ||
params: MintTokenParams | ||
): DaoAction { | ||
if (!isAddress(minterAddress) || !isAddress(params.address)) { | ||
throw new InvalidAddressError(); | ||
} | ||
const votingInterface = | ||
IERC20MintableUpgradeable__factory.createInterface(); | ||
const args = mintTokenParamsToContract(params); | ||
// get hex bytes | ||
const hexBytes = votingInterface.encodeFunctionData('mint', args); | ||
return { | ||
to: minterAddress, | ||
value: BigInt(0), | ||
data: hexToBytes(hexBytes), | ||
}; | ||
} | ||
} |
Oops, something went wrong.