-
Notifications
You must be signed in to change notification settings - Fork 5
/
EnableDividendManager.ts
57 lines (50 loc) · 1.7 KB
/
EnableDividendManager.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
import { ModuleName, SecurityToken, TransactionParams } from '@polymathnetwork/contract-wrappers';
import { Procedure } from './Procedure';
import {
EnableDividendManagerProcedureArgs,
ProcedureType,
PolyTransactionTag,
ErrorCode,
} from '../types';
import { PolymathError } from '../PolymathError';
/**
* Procedure that enables Dividends on a Security Token
*/
export class EnableDividendManager extends Procedure<EnableDividendManagerProcedureArgs> {
public type = ProcedureType.EnableDividendManager;
/**
* Enable Dividends on the Security Token and set a wallet address where reclaimed dividends and withheld tax will be stored
*/
public async prepareTransactions() {
const { symbol, storageWalletAddress } = this.args;
const { contractWrappers } = this.context;
let securityToken: SecurityToken;
try {
securityToken = await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker(
symbol
);
} catch (err) {
throw new PolymathError({
code: ErrorCode.ProcedureValidationError,
message: `There is no Security Token with symbol ${symbol}`,
});
}
const tokenAddress = await securityToken.address();
const moduleName = ModuleName.ERC20DividendCheckpoint;
const moduleFactoryAddress = await contractWrappers.getModuleFactoryAddress({
tokenAddress,
moduleName,
});
await this.addTransaction<TransactionParams.SecurityToken.AddDividendCheckpoint>(
securityToken.addModuleWithLabel,
{
tag: PolyTransactionTag.EnableDividends,
}
)({
moduleName,
address: moduleFactoryAddress,
data: { wallet: storageWalletAddress },
archived: false,
});
}
}