/
Controller.ts
102 lines (90 loc) · 3.43 KB
/
Controller.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { BigNumber } from '@polymathnetwork/contract-wrappers';
import { SubModule } from './SubModule';
import {
ControllerTransfer,
SetController,
ControllerRedeem,
DisableController,
SignDisableControllerAck,
} from '../../procedures';
/**
* Namespace that handles all Controller related functionality
*/
export class Controller extends SubModule {
/**
* Set the address of the Security Token's Controller. The controller may perform forced transfers
*
* @param args.controller - security token's controller address
*/
public modifyController = async (args: { controller: string }) => {
const { controller } = args;
const { symbol } = this.securityToken;
const procedure = new SetController({ symbol, controller }, this.context);
return procedure.prepare();
};
/**
* Permanently disable controller functionality
*
* @param args.signature - optional signed data. If not passed, signing will be requested when the transaction queue is run. The data can be generated beforehand by the token owner calling `signDisableAck`
*/
public disable = async (args?: { signature?: string }) => {
const { symbol } = this.securityToken;
const procedure = new DisableController({ ...args, symbol }, this.context);
return procedure.prepare();
};
/**
* Perform a forced transfer of tokens from one address to another. You must be the
* Security Token's controller to do this
*
* @param args.amount - amount of tokens to be transferred
* @param args.from - address from which to transfer tokens
* @param args.to - address that will receive the tokens
* @param args.reason - optional message to describe why the transfer occurred
* @param args.data - optional data used to validate the transfer
*/
public transfer = async (args: {
amount: BigNumber;
from: string;
to: string;
reason?: string;
data?: string;
}) => {
const { amount, from, to, reason = '', data = '' } = args;
const { symbol } = this.securityToken;
const procedure = new ControllerTransfer(
{ symbol, amount, from, to, log: reason, data },
this.context
);
return procedure.prepare();
};
/**
* Redeem (burn) an amount of tokens from a token holder. Only the Security Token's controller can call this
* This operation is subject to transfer restrictions and the amount is limited by the token holder's balance.
* `balanceOf(tokenHolder)` tokens) and potentially also need to respect other transfer restrictions.
*
* @param args.amount - amount of tokens to be redeemed
* @param args.address - address of the token holder
* @param args.reason - optional message to describe why the redemption occurred
* @param args.data - optional data used to validate the transfer
*/
public redeem = async (args: {
amount: BigNumber;
from: string;
reason?: string;
data?: string;
}) => {
const { symbol } = this.securityToken;
const procedure = new ControllerRedeem({ symbol, ...args }, this.context);
return procedure.prepare();
};
/**
* Generate a signature string that can be used to permanently disable the Security Token's controller functionality
*
* **Note that only the owner's signature is valid for this operation**
*/
public signDisableAck = async () => {
const { symbol } = this.securityToken;
const procedure = new SignDisableControllerAck({ symbol }, this.context);
return procedure.prepare();
};
}