From 4845d363696e3c7c1f28837b38d202da8e97d34c Mon Sep 17 00:00:00 2001 From: Dmytro Tolok Date: Fri, 8 Sep 2023 12:54:08 +0200 Subject: [PATCH] feat(proposal-update): add ability to update proposal --- package.json | 2 +- src/schemas/index.ts | 2 ++ src/schemas/update-proposal.json | 58 ++++++++++++++++++++++++++++++++ src/sign/index.ts | 10 ++++++ src/sign/types.json | 1 + src/sign/types.ts | 28 +++++++++++++++ 6 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/schemas/update-proposal.json diff --git a/package.json b/package.json index 695856927..3563321ea 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/schemas/index.ts b/src/schemas/index.ts index a0aa6972f..4ae34e679 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -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'; @@ -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, diff --git a/src/schemas/update-proposal.json b/src/schemas/update-proposal.json new file mode 100644 index 000000000..84569b23e --- /dev/null +++ b/src/schemas/update-proposal.json @@ -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 + } + } +} diff --git a/src/sign/index.ts b/src/sign/index.ts index 791517de5..6c703a61d 100644 --- a/src/sign/index.ts +++ b/src/sign/index.ts @@ -5,6 +5,7 @@ import { getAddress } from '@ethersproject/address'; import { Space, Proposal, + UpdateProposal, CancelProposal, Vote, Follow, @@ -17,6 +18,7 @@ import { Statement, spaceTypes, proposalTypes, + updateProposalTypes, cancelProposalTypes, cancelProposal2Types, voteTypes, @@ -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, diff --git a/src/sign/types.json b/src/sign/types.json index 11ab9c310..dd2c708a7 100644 --- a/src/sign/types.json +++ b/src/sign/types.json @@ -4,6 +4,7 @@ "6fee59b7db10fabbb0c6420c0a18c9d2c36306e342042826a355bfc7fe733870": "proposal", "9ff8af4cfb586e2c7962d792b99328fb47e8a4e73cc89873c0980484bc1063a5": "delete-proposal", "734df82cdad586386defa4cb55adda7cb1b2a56929c4e6c3dc676f9901947288": "delete-proposal", + "f258e1a6831b6b675dbe78572048b5d1714370be29cde5e67771d43238aabada": "update-proposal", "50084aae0fe117c83ddf855557dde35ae2872e9045443a15f72aa6c68ea3943b": "vote", "1dfe3863f6333a85581fb150d4ee77c95a6d026c518ca1b11c08ae1d98acd598": "vote-array", "1814c3dd303c5919ce488b924f92b9a42a0834972f514e55b1879fda48e67736": "vote-string", diff --git a/src/sign/types.ts b/src/sign/types.ts index df4fc6d3d..f45b8757a 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -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; @@ -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' },