Skip to content

Commit cce4789

Browse files
committed
fix: add missing procedure arguments to the ProcedureArguments interface
also renamed the Approve procedure to ApproveErc20 and created a TransferErc20 procedure BREAKING CHANGE: rename `ProcedureType` enum's member `Approve` to `ApproveErc20`, rename the `ApproveProcedureArgs` interface to `ApproveErc20ProcedureArgs`. This affects the `ProcedureArguments` interface
1 parent c3ae890 commit cce4789

16 files changed

Lines changed: 155 additions & 56 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@0x/subproviders": "^3.0.2",
4949
"@babel/polyfill": "^7.0.0",
5050
"@babel/runtime": "^7.2.0",
51-
"@polymathnetwork/contract-wrappers": "2.0.0-beta.6",
51+
"@polymathnetwork/contract-wrappers": "2.0.0-beta.7",
5252
"ethereum-address": "^0.0.4",
5353
"json-stable-stringify": "^1.0.1",
5454
"lodash": "^4.17.13",
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { BigNumber } from '@polymathnetwork/contract-wrappers';
22
import { Procedure } from './Procedure';
3-
import { ApproveProcedureArgs, ErrorCode, ProcedureType, PolyTransactionTag } from '../types';
3+
import { ApproveErc20ProcedureArgs, ErrorCode, ProcedureType, PolyTransactionTag } from '../types';
44
import { PolymathError } from '../PolymathError';
55

6-
export class Approve extends Procedure<ApproveProcedureArgs> {
7-
public type = ProcedureType.Approve;
6+
/**
7+
* Procedure to approve spending funds on an ERC20 token. If no token address is specified, it defaults to POLY
8+
*/
9+
export class ApproveErc20 extends Procedure<ApproveErc20ProcedureArgs> {
10+
public type = ProcedureType.ApproveErc20;
811

912
public async prepareTransactions() {
1013
const { amount, spender, tokenAddress, owner } = this.args;
@@ -48,15 +51,13 @@ export class Approve extends Procedure<ApproveProcedureArgs> {
4851
const isTestnet = await contractWrappers.isTestnet();
4952

5053
if (balance.lt(amount)) {
51-
if (isTestnet) {
52-
if (address.toUpperCase() === polyTokenAddress.toUpperCase()) {
53-
await this.addTransaction(contractWrappers.getPolyTokens, {
54-
tag: PolyTransactionTag.GetTokens,
55-
})({
56-
amount: amount.minus(balance).decimalPlaces(0, BigNumber.ROUND_HALF_UP),
57-
address: ownerAddress,
58-
});
59-
}
54+
if (isTestnet && address.toUpperCase() === polyTokenAddress.toUpperCase()) {
55+
await this.addTransaction(contractWrappers.getPolyTokens, {
56+
tag: PolyTransactionTag.GetTokens,
57+
})({
58+
amount: amount.minus(balance).decimalPlaces(0, BigNumber.ROUND_HALF_UP),
59+
address: ownerAddress,
60+
});
6061
} else {
6162
throw new PolymathError({
6263
code: ErrorCode.ProcedureValidationError,
@@ -76,7 +77,7 @@ export class Approve extends Procedure<ApproveProcedureArgs> {
7677
}
7778

7879
await this.addTransaction(token.approve, {
79-
tag: PolyTransactionTag.ApprovePoly,
80+
tag: PolyTransactionTag.ApproveErc20,
8081
})({ spender, value: amount });
8182
}
8283
}

src/procedures/ChangeDelegatePermission.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Procedure } from './Procedure';
33
import {
44
ProcedureType,
55
PolyTransactionTag,
6-
ChangeDelegatePermissionArgs,
6+
ChangeDelegatePermissionProcedureArgs,
77
ErrorCode,
88
ModuleOperation,
99
} from '../types';
1010
import { PolymathError } from '../PolymathError';
1111

12-
export class ChangeDelegatePermission extends Procedure<ChangeDelegatePermissionArgs> {
12+
export class ChangeDelegatePermission extends Procedure<ChangeDelegatePermissionProcedureArgs> {
1313
public type = ProcedureType.ChangeDelegatePermission;
1414

1515
public async prepareTransactions() {

src/procedures/ControllerTransfer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { Procedure } from './Procedure';
2-
import { ProcedureType, PolyTransactionTag, ControllerTransferArgs, ErrorCode } from '../types';
2+
import {
3+
ProcedureType,
4+
PolyTransactionTag,
5+
ControllerTransferProcedureArgs,
6+
ErrorCode,
7+
} from '../types';
38
import { PolymathError } from '../PolymathError';
49
import { isValidAddress } from '../utils';
510

6-
export class ControllerTransfer extends Procedure<ControllerTransferArgs> {
11+
export class ControllerTransfer extends Procedure<ControllerTransferProcedureArgs> {
712
public type = ProcedureType.ControllerTransfer;
813

914
public async prepareTransactions() {

src/procedures/CreateErc20DividendDistribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
PolyTransactionTag,
1111
ErrorCode,
1212
} from '../types';
13-
import { Approve } from '../procedures/Approve';
13+
import { ApproveErc20 } from './ApproveErc20';
1414
import { PolymathError } from '../PolymathError';
1515
import { findEvent } from '../utils';
1616

@@ -54,7 +54,7 @@ export class CreateErc20DividendDistribution extends Procedure<
5454
);
5555
}
5656

57-
await this.addProcedure(Approve)({
57+
await this.addProcedure(ApproveErc20)({
5858
amount,
5959
spender: await erc20Module.address(),
6060
tokenAddress: erc20Address,

src/procedures/CreateSecurityToken.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Procedure } from './Procedure';
2-
import { Approve } from '../procedures/Approve';
2+
import { ApproveErc20 } from './ApproveErc20';
33
import { CreateSecurityTokenProcedureArgs, ProcedureType, PolyTransactionTag } from '../types';
44

55
export class CreateSecurityToken extends Procedure<CreateSecurityTokenProcedureArgs> {
@@ -12,7 +12,7 @@ export class CreateSecurityToken extends Procedure<CreateSecurityTokenProcedureA
1212
} = this.context;
1313
const fee = await securityTokenRegistry.getSecurityTokenLaunchFee();
1414

15-
await this.addProcedure(Approve)({
15+
await this.addProcedure(ApproveErc20)({
1616
amount: fee,
1717
spender: await securityTokenRegistry.address(),
1818
});

src/procedures/LaunchCappedSto.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
LaunchCappedStoProcedureArgs,
88
} from '../types';
99
import { PolymathError } from '../PolymathError';
10+
import { TransferErc20 } from './TransferErc20';
1011

1112
interface AddCappedSTOParams {
1213
moduleName: ModuleName.CappedSTO;
@@ -43,22 +44,20 @@ export class LaunchCappedSto extends Procedure<LaunchCappedStoProcedureArgs> {
4344
});
4445
}
4546

46-
const tokenAddress = await securityToken.address();
47+
const securityTokenAddress = await securityToken.address();
4748
const moduleName = ModuleName.CappedSTO;
4849

4950
const factoryAddress = await contractWrappers.getModuleFactoryAddress({
50-
tokenAddress,
51+
tokenAddress: securityTokenAddress,
5152
moduleName,
5253
});
5354

5455
const moduleFactory = await contractWrappers.moduleFactory.getModuleFactory(factoryAddress);
5556
const cost = await moduleFactory.setupCostInPoly();
5657

57-
await this.addTransaction(contractWrappers.polyToken.transfer, {
58-
tag: PolyTransactionTag.TransferPoly,
59-
})({
60-
to: tokenAddress,
61-
value: cost,
58+
await this.addProcedure(TransferErc20)({
59+
receiver: securityTokenAddress,
60+
amount: cost,
6261
});
6362

6463
await this.addTransaction<AddCappedSTOParams>(securityToken.addModuleWithLabel, {

src/procedures/LaunchUsdTieredSto.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
LaunchUsdTieredStoProcedureArgs,
88
} from '../types';
99
import { PolymathError } from '../PolymathError';
10+
import { TransferErc20 } from './TransferErc20';
1011

1112
interface AddUSDTieredSTOParams {
1213
moduleName: ModuleName.UsdTieredSTO;
@@ -60,22 +61,20 @@ export class LaunchUsdTieredSto extends Procedure<LaunchUsdTieredStoProcedureArg
6061
});
6162
}
6263

63-
const tokenAddress = await securityToken.address();
64+
const securityTokenAddress = await securityToken.address();
6465
const moduleName = ModuleName.UsdTieredSTO;
6566

6667
const factoryAddress = await contractWrappers.getModuleFactoryAddress({
67-
tokenAddress,
68+
tokenAddress: securityTokenAddress,
6869
moduleName,
6970
});
7071

7172
const moduleFactory = await contractWrappers.moduleFactory.getModuleFactory(factoryAddress);
7273
const cost = await moduleFactory.setupCostInPoly();
7374

74-
await this.addTransaction(contractWrappers.polyToken.transfer, {
75-
tag: PolyTransactionTag.TransferPoly,
76-
})({
77-
to: tokenAddress,
78-
value: cost,
75+
await this.addProcedure(TransferErc20)({
76+
receiver: securityTokenAddress,
77+
amount: cost,
7978
});
8079

8180
const ratePerTier: BigNumber[] = [];

src/procedures/ModifyWhitelist.ts

Whitespace-only changes.

src/procedures/PauseSto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ModuleName } from '@polymathnetwork/contract-wrappers';
22
import { Procedure } from './Procedure';
3-
import { ProcedureType, PolyTransactionTag, PauseStoArgs, ErrorCode } from '../types';
3+
import { ProcedureType, PolyTransactionTag, PauseStoProcedureArgs, ErrorCode } from '../types';
44
import { PolymathError } from '../PolymathError';
55
import { isValidAddress } from '../utils';
66

7-
export class PauseSto extends Procedure<PauseStoArgs> {
7+
export class PauseSto extends Procedure<PauseStoProcedureArgs> {
88
public type = ProcedureType.PauseSto;
99

1010
public async prepareTransactions() {

0 commit comments

Comments
 (0)