Skip to content

Commit cb713ab

Browse files
authored
GSMC new closing at (#641)
* GSMC new closing at * fix * move consts to utils
1 parent 78ee8f5 commit cb713ab

File tree

6 files changed

+83
-9
lines changed

6 files changed

+83
-9
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/subgraph",
3-
"version": "0.0.41-8",
3+
"version": "0.0.41-9",
44
"author": "DAOstack (https://www.daostack.io)",
55
"license": "GPL-3.0",
66
"description": "A caching layer for daostack using The Graph",

src/domain/proposal.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Address,
1212
store } from '@graphprotocol/graph-ts';
1313
import { GenesisProtocol } from '../types/GenesisProtocol/GenesisProtocol';
1414
import { ControllerScheme, DAO, GenesisProtocolParam, Proposal, Tag } from '../types/schema';
15-
import { concat, equalsBytes, equalStrings } from '../utils';
15+
import { CLOSING_AT_TIME_DECREASE_GSMC, CLOSING_AT_TIME_INCREASE, concat, equalsBytes, equalStrings } from '../utils';
1616
import { getDAO, saveDAO } from './dao';
1717
import { addNewProposalEvent, addVoteFlipEvent } from './event';
1818
import { updateThreshold } from './gpqueue';
@@ -434,8 +434,11 @@ export function updateProposalExecution(
434434
proposal.executedAt = timestamp;
435435
// Setting the closingAt field to a far away point in the future so it will be easy to
436436
// sort all proposal(open and executed) in ascending order by the closingAt field
437-
const CLOSING_AT_TIME_INCREASE = 2147483647;
438-
proposal.closingAt = (BigInt.fromI32(CLOSING_AT_TIME_INCREASE).minus(timestamp)).times(BigInt.fromI32(100));
437+
if (proposal.genericSchemeMultiCall) {
438+
proposal.closingAt = timestamp.minus(BigInt.fromI32(CLOSING_AT_TIME_DECREASE_GSMC));
439+
} else {
440+
proposal.closingAt = (BigInt.fromI32(CLOSING_AT_TIME_INCREASE).minus(timestamp)).times(BigInt.fromI32(100));
441+
}
439442
if (totalReputation != null) {
440443
proposal.totalRepWhenExecuted = totalReputation;
441444
}

src/mappings/GenericSchemeMultiCall/mapping.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bytes, store } from '@graphprotocol/graph-ts';
1+
import { BigInt, Bytes, store } from '@graphprotocol/graph-ts';
22

33
// Import event types from the Reputation contract ABI
44
import {
@@ -10,10 +10,12 @@ import {
1010
import * as domain from '../../domain';
1111

1212
// Import entity types generated from the GraphQL schema
13+
import { getProposal } from '../../domain/proposal';
1314
import {
1415
GenericSchemeMultiCallProposal,
1516
GenericSchemeParam,
1617
} from '../../types/schema';
18+
import { CLOSING_AT_TIME_DECREASE_GSMC, CLOSING_AT_TIME_INCREASE } from '../../utils';
1719

1820
function insertNewProposal(event: NewMultiCallProposal): void {
1921
let ent = new GenericSchemeMultiCallProposal(event.params._proposalId.toHex());
@@ -65,6 +67,13 @@ export function handleProposalExecuted(
6567
) as GenericSchemeMultiCallProposal;
6668
if (ent != null) {
6769
ent.executed = true;
70+
let proposal = getProposal(event.params._proposalId.toHex());
71+
proposal.closingAt = (
72+
BigInt.fromI32(CLOSING_AT_TIME_INCREASE).minus(
73+
proposal.closingAt.plus(BigInt.fromI32(CLOSING_AT_TIME_DECREASE_GSMC)),
74+
)
75+
).times(BigInt.fromI32(100));
76+
proposal.save();
6877
}
6978

7079
store.set('GenericSchemeMultiCallProposal', event.params._proposalId.toHex(), ent);

src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export function concat(a: ByteArray, b: ByteArray): ByteArray {
2929
return out as ByteArray;
3030
}
3131

32+
export const CLOSING_AT_TIME_DECREASE_GSMC = 32000000;
33+
export const CLOSING_AT_TIME_INCREASE = 2147483647;
34+
3235
export function eventId(event: ethereum.Event): string {
3336
return crypto
3437
.keccak256(

test/0.0.1-rc.55/GenericSchemeMultiCall.spec.ts

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,43 @@ describe('GenericSchemeMultiCall', () => {
172172
voter: accounts[3].address,
173173
});
174174

175-
await genericSchemeMultiCall.methods.execute(p1).send();
176-
177175
const executedIsIndexed = async () => {
178176
return (await sendQuery(getProposal)).proposal.executedAt != null;
179177
};
180178

181179
await waitUntilTrue(executedIsIndexed);
182180

183-
proposal = (await sendQuery(getProposal)).proposal;
181+
const getProposalWithClosingAt = `{
182+
proposal(id: "${p1}") {
183+
id
184+
descriptionHash
185+
stage
186+
createdAt
187+
executedAt
188+
proposer
189+
votingMachine
190+
closingAt
191+
genericSchemeMultiCall {
192+
id
193+
dao {
194+
id
195+
}
196+
contractsToCall
197+
callsData
198+
values
199+
executed
200+
returnValues
201+
}
202+
scheme {
203+
genericSchemeMultiCallParams {
204+
contractsWhiteList
205+
schemeConstraints
206+
}
207+
}
208+
}
209+
}`;
210+
211+
proposal = (await sendQuery(getProposalWithClosingAt)).proposal;
184212
expect(proposal).toMatchObject({
185213
id: p1,
186214
descriptionHash,
@@ -189,7 +217,38 @@ describe('GenericSchemeMultiCall', () => {
189217
executedAt: executedAt + '',
190218
proposer: web3.eth.defaultAccount.toLowerCase(),
191219
votingMachine: genesisProtocol.options.address.toLowerCase(),
220+
closingAt: (parseInt(executedAt, 10) - 32000000).toString(),
221+
genericSchemeMultiCall: {
222+
id: p1,
223+
dao: {
224+
id: addresses.Avatar.toLowerCase(),
225+
},
226+
contractsToCall,
227+
callsData,
228+
values,
229+
executed: false,
230+
returnValues: null,
231+
},
232+
});
192233

234+
await genericSchemeMultiCall.methods.execute(p1).send();
235+
236+
const executedGSMCIsIndexed = async () => {
237+
return (await sendQuery(getProposalWithClosingAt)).proposal.genericSchemeMultiCall.executed == true;
238+
};
239+
240+
await waitUntilTrue(executedGSMCIsIndexed);
241+
242+
proposal = (await sendQuery(getProposalWithClosingAt)).proposal;
243+
expect(proposal).toMatchObject({
244+
id: p1,
245+
descriptionHash,
246+
stage: 'Executed',
247+
createdAt: p1Creation.toString(),
248+
executedAt: executedAt + '',
249+
proposer: web3.eth.defaultAccount.toLowerCase(),
250+
votingMachine: genesisProtocol.options.address.toLowerCase(),
251+
closingAt: ((2147483647 - parseInt(executedAt, 10)) * 100).toString(),
193252
genericSchemeMultiCall: {
194253
id: p1,
195254
dao: {

0 commit comments

Comments
 (0)