-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcontributionRewardExt.ts
71 lines (66 loc) · 2.11 KB
/
contributionRewardExt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import BN = require('bn.js')
import { Arc } from '../arc'
import { IProposalBaseCreateOptions, Proposal } from '../proposal'
import { Address } from '../types'
import { NULL_ADDRESS } from '../utils'
export interface IContributionRewardExt {
beneficiary: Address
externalTokenReward: BN
externalToken: Address
ethReward: BN
nativeTokenReward: BN
periods: number
periodLength: number
reputationReward: BN
alreadyRedeemedNativeTokenPeriods: number
alreadyRedeemedReputationPeriods: number
alreadyRedeemedExternalTokenPeriods: number
alreadyRedeemedEthPeriods: number
}
export interface IProposalCreateOptionsContributionRewardExt extends IProposalBaseCreateOptions {
beneficiary: Address
nativeTokenReward?: BN
reputationReward?: BN
ethReward?: BN
externalTokenReward?: BN
externalTokenAddress?: Address
proposer: Address
}
export enum IProposalType {
ContributionReward = 'ContributionRewardExt' // propose a contributionReward
}
/**
*
* @param options
* @param context
*/
export function createProposal(options: any, context: Arc) {
const contract = context.getContract(options.scheme)
if (!options.proposer) {
options.proposer = NULL_ADDRESS
}
return async () => {
options.descriptionHash = await context.saveIPFSData(options)
const transaction = contract.methods.proposeContributionReward(
options.descriptionHash || '',
options.reputationReward && options.reputationReward.toString() || 0,
[
options.nativeTokenReward && options.nativeTokenReward.toString() || 0,
options.ethReward && options.ethReward.toString() || 0,
options.externalTokenReward && options.externalTokenReward.toString() || 0
],
options.externalTokenAddress || NULL_ADDRESS,
options.beneficiary,
options.proposer
)
return transaction
}
}
export function createTransactionMap(options: any, context: Arc) {
const eventName = 'NewContributionProposal'
const map = (receipt: any) => {
const proposalId = receipt.events[eventName].returnValues._proposalId
return new Proposal(proposalId, context)
}
return map
}