Skip to content

Commit 0b997db

Browse files
authored
Merge pull request #118 from Alien-Worlds/DEMZNE-1303_Bug-fixes-on-referendum-and-Dacproposals-for-main-net-operation
Fixes to the proposals and referendum contracts based on main net int…
2 parents cba7c4b + 13683f3 commit 0b997db

6 files changed

Lines changed: 464 additions & 280 deletions

File tree

contracts/TestHelpers.ts

Lines changed: 88 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { rename, stat } from 'node:fs/promises';
2929

3030
export var NUMBER_OF_CANDIDATES = 7;
3131

32+
type config_type = Partial<{ planet: Account; vote_weight_account: Account }>;
33+
3234
export class SharedTestObjects {
3335
// Shared Instances to use between tests.
3436
private static instance: SharedTestObjects;
@@ -169,7 +171,7 @@ export class SharedTestObjects {
169171
dacId: string,
170172
symbol: string,
171173
initialAsset: string,
172-
config?: any
174+
config?: config_type
173175
) {
174176
await this.setup_new_auth_account();
175177
// Further setup after the inital singleton object have been created.
@@ -305,7 +307,7 @@ export class SharedTestObjects {
305307
private async register_dac_with_directory(
306308
dacId: string,
307309
tokenSymbol: string,
308-
config?: any
310+
config?: config_type
309311
) {
310312
const accounts = [
311313
{
@@ -325,18 +327,87 @@ export class SharedTestObjects {
325327
value: this.referendum_contract.account.name,
326328
},
327329
];
328-
if (config && config.planet) {
329-
accounts.push({
330-
key: Account_type.MSIGOWNED,
331-
value: config.planet.name,
332-
});
333-
}
334-
if (config && config.vote_weight_account) {
335-
console.log('adding ', config.vote_weight_account.name);
336-
accounts.push({
337-
key: Account_type.VOTING,
338-
value: config.vote_weight_account.name,
339-
});
330+
if (config) {
331+
if (config.planet) {
332+
accounts.push({
333+
key: Account_type.MSIGOWNED,
334+
value: config.planet.name,
335+
});
336+
accounts.push({
337+
key: Account_type.SPENDINGS,
338+
value: config.planet.name,
339+
});
340+
await debugPromise(
341+
UpdateAuth.execUpdateAuth(
342+
[{ actor: config.planet.name, permission: 'active' }],
343+
config.planet.name,
344+
'escrow',
345+
'active',
346+
UpdateAuth.AuthorityToSet.forContractCode(
347+
this.dacproposals_contract.account
348+
)
349+
),
350+
'add escrow auth'
351+
);
352+
353+
await debugPromise(
354+
UpdateAuth.execUpdateAuth(
355+
[{ actor: config.planet.name, permission: 'active' }],
356+
config.planet.name,
357+
'xfer',
358+
'active',
359+
UpdateAuth.AuthorityToSet.forContractCode(
360+
this.dacproposals_contract.account
361+
)
362+
),
363+
'add xfer to SPENDINGS'
364+
);
365+
await UpdateAuth.execLinkAuth(
366+
[{ actor: config.planet.name, permission: 'active' }],
367+
config.planet.name,
368+
this.dacescrow_contract.account.name,
369+
'init',
370+
'escrow'
371+
);
372+
373+
await debugPromise(
374+
UpdateAuth.execLinkAuth(
375+
[{ actor: config.planet.name, permission: 'active' }],
376+
config.planet.name,
377+
this.dacescrow_contract.account.name,
378+
'approve',
379+
'escrow'
380+
),
381+
'linking escrow perm to planet spendings'
382+
);
383+
await debugPromise(
384+
UpdateAuth.execLinkAuth(
385+
[{ actor: config.planet.name, permission: 'active' }],
386+
config.planet.name,
387+
this.dac_token_contract.account.name,
388+
'transfer',
389+
'xfer'
390+
),
391+
'linking xfer perm to transfer tokens'
392+
);
393+
await debugPromise(
394+
UpdateAuth.execLinkAuth(
395+
[{ actor: config.planet.name, permission: 'active' }],
396+
config.planet.name,
397+
'eosio.token',
398+
'transfer',
399+
'xfer'
400+
),
401+
'linking xfer perm to transfer tokens'
402+
);
403+
}
404+
if (config.vote_weight_account) {
405+
console.log('adding ', config.vote_weight_account.name);
406+
accounts.push({
407+
key: Account_type.VOTING,
408+
value: config.vote_weight_account.name,
409+
});
410+
}
340411
}
341412

342413
await this.dacdirectory_contract.regdac(
@@ -411,45 +482,14 @@ export class SharedTestObjects {
411482
'add xfer auth to eosdactoken'
412483
);
413484

414-
await debugPromise(
415-
UpdateAuth.execUpdateAuth(
416-
this.treasury_account.active,
417-
this.treasury_account.name,
418-
'escrow',
419-
'active',
420-
UpdateAuth.AuthorityToSet.forContractCode(
421-
this.dacproposals_contract.account
422-
)
423-
),
424-
'add escrow auth'
425-
);
426-
427485
await debugPromise(
428486
UpdateAuth.execUpdateAuth(
429487
this.treasury_account.active,
430488
this.treasury_account.name,
431489
'xfer',
432490
'active',
433-
UpdateAuth.AuthorityToSet.explicitAuthorities(
434-
1,
435-
[
436-
{
437-
permission: {
438-
actor: this.daccustodian_contract.account.name,
439-
permission: 'eosio.code',
440-
},
441-
weight: 1,
442-
},
443-
{
444-
permission: {
445-
actor: this.dacproposals_contract.account.name,
446-
permission: 'eosio.code',
447-
},
448-
weight: 1,
449-
},
450-
],
451-
[],
452-
[]
491+
UpdateAuth.AuthorityToSet.forContractCode(
492+
this.daccustodian_contract.account
453493
)
454494
),
455495
'add xfer to treasury'
@@ -536,25 +576,6 @@ export class SharedTestObjects {
536576
'notify'
537577
);
538578

539-
await UpdateAuth.execLinkAuth(
540-
this.treasury_account.active,
541-
this.treasury_account.name,
542-
this.dacescrow_contract.account.name,
543-
'init',
544-
'escrow'
545-
);
546-
547-
await debugPromise(
548-
UpdateAuth.execLinkAuth(
549-
this.treasury_account.active,
550-
this.treasury_account.name,
551-
this.dacescrow_contract.account.name,
552-
'approve',
553-
'escrow'
554-
),
555-
'linking escrow perm to treasury'
556-
);
557-
558579
await UpdateAuth.execLinkAuth(
559580
this.treasury_account.active,
560581
this.treasury_account.name,
@@ -976,6 +997,7 @@ export enum Account_type {
976997
VOTING = 8,
977998
ACTIVATION = 9,
978999
REFERENDUM = 10,
1000+
SPENDINGS = 11,
9791001
EXTERNAL = 254,
9801002
OTHER = 255,
9811003
}

contracts/dacproposals/dacproposals.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ namespace eosdac {
3131
"ERR::CREATEPROP_INVALID_proposal_pay::Invalid pay amount. Must be greater than 0.");
3232
check(is_account(arbitrator), "ERR::CREATEPROP_INVALID_ARBITRATOR::Invalid arbitrator.");
3333

34-
auto dac = dacdir::dac_for_id(dac_id);
35-
auto treasury = dac.account_for_type(dacdir::TREASURY);
36-
auto auth = dac.owner;
37-
check(arbitrator != auth && arbitrator != treasury, "Arbitrator must be a third party");
34+
auto dac = dacdir::dac_for_id(dac_id);
35+
auto funding_source = dac.account_for_type(dacdir::SPENDINGS);
36+
auto auth = dac.owner;
37+
check(arbitrator != auth && arbitrator != funding_source, "Arbitrator must be a third party");
3838
auto current_configs = configs{get_self(), dac_id};
3939

4040
uint32_t approval_duration = current_configs.get_approval_duration();
@@ -228,31 +228,31 @@ namespace eosdac {
228228

229229
assertValidMember(prop.proposer, dac_id);
230230

231-
// print("Transfer funds to escrow account");
232231
string memo = prop.proposer.to_string() + ":" + proposal_id.to_string() + ":" + prop.content_hash;
233232

234233
time_point_sec time_now = time_point_sec(current_time_point().sec_since_epoch());
235234

236-
const auto treasury = dacdir::dac_for_id(dac_id).account_for_type(dacdir::TREASURY);
237-
const auto escrow = dacdir::dac_for_id(dac_id).account_for_type(dacdir::ESCROW);
235+
const auto funding_source = dacdir::dac_for_id(dac_id).account_for_type(dacdir::SPENDINGS);
236+
const auto escrow = dacdir::dac_for_id(dac_id).account_for_type(dacdir::ESCROW);
238237

239-
check(is_account(treasury), "ERR::TREASURY_ACCOUNT_NOT_FOUND::Treasury account not found");
238+
check(is_account(funding_source), "ERR::FUNDING_SOURCE_ACCOUNT_NOT_FOUND::Funding account not found");
240239
check(is_account(escrow), "ERR::ESCROW_ACCOUNT_NOT_FOUND::Escrow account not found");
241240

242241
proposals.modify(prop, same_payer, [&](auto &p) {
243242
p.state = ProposalStateWork_in_progress;
244243
});
245244

246-
dacescrow::init_action{escrow, {treasury, "escrow"_n}}
247-
.to_action(treasury, prop.proposer, prop.arbitrator, time_now + (prop.job_duration * 2), memo, proposal_id)
245+
dacescrow::init_action{escrow, {funding_source, "escrow"_n}}
246+
.to_action(
247+
funding_source, prop.proposer, prop.arbitrator, time_now + (prop.job_duration * 2), memo, proposal_id)
248248
.send();
249249

250-
action(eosio::permission_level{treasury, "xfer"_n}, prop.proposal_pay.contract, "transfer"_n,
251-
make_tuple(treasury, escrow, prop.proposal_pay.quantity, "rec:" + proposal_id.to_string()))
250+
action(eosio::permission_level{funding_source, "xfer"_n}, prop.proposal_pay.contract, "transfer"_n,
251+
make_tuple(funding_source, escrow, prop.proposal_pay.quantity, "rec:" + proposal_id.to_string()))
252252
.send();
253253

254-
action(eosio::permission_level{treasury, "xfer"_n}, prop.arbitrator_pay.contract, "transfer"_n,
255-
make_tuple(treasury, escrow, prop.arbitrator_pay.quantity, "arb:" + proposal_id.to_string()))
254+
action(eosio::permission_level{funding_source, "xfer"_n}, prop.arbitrator_pay.contract, "transfer"_n,
255+
make_tuple(funding_source, escrow, prop.arbitrator_pay.quantity, "arb:" + proposal_id.to_string()))
256256
.send();
257257
}
258258

@@ -436,12 +436,11 @@ namespace eosdac {
436436

437437
void dacproposals::transferfunds(const proposal &prop, name dac_id) {
438438
proposal_table proposals(_self, dac_id.value);
439-
// auto current_configs = configs(get_self(), dac_id);
440-
auto treasury = dacdir::dac_for_id(dac_id).account_for_type(dacdir::TREASURY);
441-
auto escrow = dacdir::dac_for_id(dac_id).account_for_type(dacdir::ESCROW);
439+
auto funding_source = dacdir::dac_for_id(dac_id).account_for_type(dacdir::SPENDINGS);
440+
auto escrow = dacdir::dac_for_id(dac_id).account_for_type(dacdir::ESCROW);
442441

443-
eosio::action(eosio::permission_level{treasury, "escrow"_n}, escrow, "approve"_n,
444-
make_tuple(prop.proposal_id.value, treasury))
442+
eosio::action(eosio::permission_level{funding_source, "escrow"_n}, escrow, "approve"_n,
443+
make_tuple(prop.proposal_id.value, funding_source))
445444
.send();
446445

447446
clearprop(prop, dac_id);
@@ -523,7 +522,7 @@ namespace eosdac {
523522
// Find the difference between current custodians and the ones that have already voted to avoid double votes.
524523
std::vector<name> nonvoting_custodians(current_custodians.size());
525524
auto end_itr = std::set_difference(current_custodians.begin(), current_custodians.end(),
526-
voted_custodians.begin(), voted_custodians.end(), nonvoting_custodians.begin());
525+
voted_custodians.begin(), voted_custodians.end(), nonvoting_custodians.begin());
527526

528527
nonvoting_custodians.resize(end_itr - nonvoting_custodians.begin());
529528

0 commit comments

Comments
 (0)