/
ModifyDividendsDefaultExclusionList.ts
63 lines (55 loc) · 1.91 KB
/
ModifyDividendsDefaultExclusionList.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
import { chunk } from 'lodash';
import { ModuleName } from '@polymathnetwork/contract-wrappers';
import P from 'bluebird';
import { Procedure } from './Procedure';
import {
ModifyDividendsDefaultExclusionListProcedureArgs,
ProcedureType,
PolyTransactionTag,
ErrorCode,
} from '../types';
import { PolymathError } from '../PolymathError';
const CHUNK_SIZE = 200;
/**
* Procedure that modifies the list of shareholders which are excluded from receiving dividend payments
*/
export class ModifyDividendsDefaultExclusionList extends Procedure<
ModifyDividendsDefaultExclusionListProcedureArgs
> {
public type = ProcedureType.ModifyDividendsDefaultExclusionList;
/**
* Set the default exclusion list for dividend distributions
*
* Note that this procedure will fail if the Dividends Feature is not enabled
*/
public async prepareTransactions() {
const { symbol, shareholderAddresses: investors } = this.args;
const { contractWrappers } = this.context;
try {
await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker(symbol);
} catch (err) {
throw new PolymathError({
code: ErrorCode.ProcedureValidationError,
message: `There is no Security Token with symbol ${symbol}`,
});
}
const [dividendsModule] = await contractWrappers.getAttachedModules(
{ moduleName: ModuleName.ERC20DividendCheckpoint, symbol },
{ unarchived: true }
);
if (!dividendsModule) {
throw new PolymathError({
code: ErrorCode.ProcedureValidationError,
message: "The Dividends Feature hasn't been enabled",
});
}
const shareholderAddressChunks = chunk(investors, CHUNK_SIZE);
await P.each(shareholderAddressChunks, async addresses => {
await this.addTransaction(dividendsModule!.setDefaultExcluded, {
tag: PolyTransactionTag.SetDefaultExcluded,
})({
excluded: addresses,
});
});
}
}