Skip to content

Commit

Permalink
feat(proposal-update): add ability to update proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
Todmy committed Sep 8, 2023
1 parent 3210ffc commit 4845d36
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/snapshot.js",
"version": "0.5.8",
"version": "0.5.9",
"repository": "snapshot-labs/snapshot.js",
"license": "MIT",
"main": "dist/snapshot.cjs.js",
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import space from './space.json';
import proposal from './proposal.json';
import updateProposal from './update-proposal.json';
import vote from './vote.json';
import profile from './profile.json';
import statement from './statement.json';
Expand All @@ -8,6 +9,7 @@ import zodiac from './zodiac.json';
export default {
space: space.definitions.Space,
proposal: proposal.definitions.Proposal,
updateProposal: updateProposal.definitions.UpdateProposal,
vote: vote.definitions.Vote,
profile: profile.definitions.Profile,
statement: statement.definitions.Statement,
Expand Down
58 changes: 58 additions & 0 deletions src/schemas/update-proposal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/UpdateProposal",
"definitions": {
"UpdateProposal": {
"title": "Update Proposal",
"type": "object",
"properties": {
"proposal": {
"type": "string",
"title": "proposal id"
},
"name": {
"type": "string",
"title": "name",
"minLength": 1,
"maxLength": 256
},
"body": {
"type": "string",
"title": "body",
"minLength": 0,
"maxLength": 20000
},
"discussion": {
"type": "string",
"format": "customUrl",
"title": "discussion",
"maxLength": 256
},
"choices": {
"type": "array",
"title": "choices",
"minItems": 1,
"maxItems": 500
},
"type": {
"type": "string",
"enum": [
"single-choice",
"approval",
"ranked-choice",
"quadratic",
"weighted",
"custom",
"basic"
]
},
"metadata": {
"type": "object",
"title": "metadata"
}
},
"required": ["proposal"],
"additionalProperties": false
}
}
}
10 changes: 10 additions & 0 deletions src/sign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getAddress } from '@ethersproject/address';
import {
Space,
Proposal,
UpdateProposal,
CancelProposal,
Vote,
Follow,
Expand All @@ -17,6 +18,7 @@ import {
Statement,
spaceTypes,
proposalTypes,
updateProposalTypes,
cancelProposalTypes,
cancelProposal2Types,
voteTypes,
Expand Down Expand Up @@ -111,6 +113,14 @@ export default class Client {
return await this.sign(web3, address, message, proposalTypes);
}

async updateProposal(
web3: Web3Provider | Wallet,
address: string,
message: UpdateProposal
) {
return await this.sign(web3, address, message, updateProposalTypes);
}

async cancelProposal(
web3: Web3Provider | Wallet,
address: string,
Expand Down
1 change: 1 addition & 0 deletions src/sign/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"6fee59b7db10fabbb0c6420c0a18c9d2c36306e342042826a355bfc7fe733870": "proposal",
"9ff8af4cfb586e2c7962d792b99328fb47e8a4e73cc89873c0980484bc1063a5": "delete-proposal",
"734df82cdad586386defa4cb55adda7cb1b2a56929c4e6c3dc676f9901947288": "delete-proposal",
"f258e1a6831b6b675dbe78572048b5d1714370be29cde5e67771d43238aabada": "update-proposal",
"50084aae0fe117c83ddf855557dde35ae2872e9045443a15f72aa6c68ea3943b": "vote",
"1dfe3863f6333a85581fb150d4ee77c95a6d026c518ca1b11c08ae1d98acd598": "vote-array",
"1814c3dd303c5919ce488b924f92b9a42a0834972f514e55b1879fda48e67736": "vote-string",
Expand Down
28 changes: 28 additions & 0 deletions src/sign/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export interface Proposal {
app?: string;
}

export interface UpdateProposal {
proposal: string;
from: string;
space: string;
timestamp: number;
type?: ProposalType;
title?: string;
body?: string;
discussion?: string;
choices?: string[];
plugins?: string;
}

export interface CancelProposal {
from?: string;
space: string;
Expand Down Expand Up @@ -126,6 +139,21 @@ export const proposalTypes = {
]
};

export const updateProposalTypes = {
updateProposal: [
{ name: 'proposal', type: 'string' },
{ name: 'from', type: 'address' },
{ name: 'space', type: 'string' },
{ name: 'timestamp', type: 'uint64' },
{ name: 'type', type: 'string' },
{ name: 'title', type: 'string' },
{ name: 'body', type: 'string' },
{ name: 'discussion', type: 'string' },
{ name: 'choices', type: 'string[]' },
{ name: 'plugins', type: 'string' }
]
};

export const cancelProposalTypes = {
CancelProposal: [
{ name: 'from', type: 'address' },
Expand Down

0 comments on commit 4845d36

Please sign in to comment.