Skip to content

Commit 1035fc3

Browse files
committed
Merge branch 'docs/security-token-entity' of github.com:PolymathNetwork/polymath-sdk into docs/security-token-entity
2 parents eaeb476 + e4e330f commit 1035fc3

File tree

14 files changed

+1027
-129
lines changed

14 files changed

+1027
-129
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polymathnetwork/sdk",
3-
"version": "2.0.1-beta.90",
3+
"version": "2.0.1-beta.93",
44
"description": "A Javascript SDK for interacting with the Polymath network for the browser and Node.js",
55
"bugs": {
66
"url": "https://github.com/PolymathNetwork/polymath-sdk/issues"

src/entities/SecurityToken/Issuance/Offerings.ts

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,27 @@ interface LaunchTieredStoParams {
2424
currencies: Currency[];
2525
raisedFundsWallet: string;
2626
unsoldTokensWallet: string;
27-
stableCoinAddresses: string[];
27+
stableCoinAddresses?: string[];
2828
customCurrency?: Partial<CustomCurrency>;
2929
allowPreIssuance?: boolean;
3030
}
3131

32-
type OnlyEth =
33-
| [Currency.ETH]
34-
| [Currency.StableCoin, Currency.ETH]
35-
| [Currency.ETH, Currency.StableCoin];
36-
type OnlyPoly =
37-
| [Currency.POLY]
32+
type OnlyEth = [Currency.ETH];
33+
type EthAndStableCoin = [Currency.StableCoin, Currency.ETH] | [Currency.ETH, Currency.StableCoin];
34+
type OnlyPoly = [Currency.POLY];
35+
type PolyAndStableCoin =
3836
| [Currency.StableCoin, Currency.POLY]
3937
| [Currency.POLY, Currency.StableCoin];
40-
type EthAndPoly =
41-
| [Currency.ETH, Currency.POLY]
42-
| [Currency.POLY, Currency.ETH]
38+
type EthAndPoly = [Currency.ETH, Currency.POLY] | [Currency.POLY, Currency.ETH];
39+
type AllCurrencies =
4340
| [Currency.StableCoin, Currency.ETH, Currency.POLY]
4441
| [Currency.ETH, Currency.StableCoin, Currency.POLY]
4542
| [Currency.ETH, Currency.POLY, Currency.StableCoin]
4643
| [Currency.StableCoin, Currency.POLY, Currency.ETH]
4744
| [Currency.POLY, Currency.StableCoin, Currency.ETH]
4845
| [Currency.POLY, Currency.ETH, Currency.StableCoin];
4946

47+
5048
/**
5149
* Params for [[getSto]]
5250
*/
@@ -60,7 +58,23 @@ interface LaunchTieredStoNoCustomCurrencyParams
6058
currencies: OnlyEth | OnlyPoly | EthAndPoly;
6159
}
6260

61+
interface LaunchTieredStoNoCustomCurrencyParams
62+
extends Omit<LaunchTieredStoParams, 'customCurrency'> {
63+
currencies: EthAndStableCoin | PolyAndStableCoin | AllCurrencies;
64+
stableCoinAddresses: string[];
65+
}
66+
6367
interface LaunchTieredStoCustomCurrencyEthParams extends LaunchTieredStoParams {
68+
currencies: OnlyEth | EthAndStableCoin;
69+
customCurrency: {
70+
currencySymbol?: string;
71+
ethOracleAddress: string;
72+
};
73+
stableCoinAddresses: string[];
74+
}
75+
76+
interface LaunchTieredStoCustomCurrencyEthNoStableCoinParams
77+
extends Omit<LaunchTieredStoParams, 'stableCoinAddresses'> {
6478
currencies: OnlyEth;
6579
customCurrency: {
6680
currencySymbol?: string;
@@ -69,6 +83,16 @@ interface LaunchTieredStoCustomCurrencyEthParams extends LaunchTieredStoParams {
6983
}
7084

7185
interface LaunchTieredStoCustomCurrencyPolyParams extends LaunchTieredStoParams {
86+
currencies: OnlyPoly | PolyAndStableCoin;
87+
customCurrency: {
88+
currencySymbol?: string;
89+
polyOracleAddress: string;
90+
};
91+
stableCoinAddresses: string[];
92+
}
93+
94+
interface LaunchTieredStoCustomCurrencyPolyNoStableCoinParams
95+
extends Omit<LaunchTieredStoParams, 'stableCoinAddresses'> {
7296
currencies: OnlyPoly;
7397
customCurrency: {
7498
currencySymbol?: string;
@@ -77,6 +101,17 @@ interface LaunchTieredStoCustomCurrencyPolyParams extends LaunchTieredStoParams
77101
}
78102

79103
interface LaunchTieredStoCustomCurrencyBothParams extends LaunchTieredStoParams {
104+
currencies: AllCurrencies;
105+
customCurrency: {
106+
currencySymbol?: string;
107+
ethOracleAddress: string;
108+
polyOracleAddress: string;
109+
};
110+
stableCoinAddresses: string[];
111+
}
112+
113+
interface LaunchTieredStoCustomCurrencyBothNoStableCoinParams
114+
extends Omit<LaunchTieredStoParams, 'stableCoinAddresses'> {
80115
currencies: EthAndPoly;
81116
customCurrency: {
82117
currencySymbol?: string;
@@ -87,16 +122,28 @@ interface LaunchTieredStoCustomCurrencyBothParams extends LaunchTieredStoParams
87122

88123
interface LaunchTieredStoMethod {
89124
(args: LaunchTieredStoNoCustomCurrencyParams): Promise<
90-
TransactionQueue<LaunchTieredStoProcedureArgs>
125+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
126+
>;
127+
(args: LaunchTieredStoNoCustomCurrencyNoStableCoinParams): Promise<
128+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
91129
>;
92130
(args: LaunchTieredStoCustomCurrencyEthParams): Promise<
93-
TransactionQueue<LaunchTieredStoProcedureArgs>
131+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
132+
>;
133+
(args: LaunchTieredStoCustomCurrencyEthNoStableCoinParams): Promise<
134+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
94135
>;
95136
(args: LaunchTieredStoCustomCurrencyPolyParams): Promise<
96-
TransactionQueue<LaunchTieredStoProcedureArgs>
137+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
138+
>;
139+
(args: LaunchTieredStoCustomCurrencyPolyNoStableCoinParams): Promise<
140+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
97141
>;
98142
(args: LaunchTieredStoCustomCurrencyBothParams): Promise<
99-
TransactionQueue<LaunchTieredStoProcedureArgs>
143+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
144+
>;
145+
(args: LaunchTieredStoCustomCurrencyBothNoStableCoinParams): Promise<
146+
TransactionQueue<LaunchTieredStoProcedureArgs, TieredSto>
100147
>;
101148
}
102149

src/entities/TieredSto.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export interface Tier {
3232
export interface Params extends StoParams {
3333
currentTier: number;
3434
tiers: Tier[];
35+
nonAccreditedInvestmentLimit: BigNumber;
36+
minimumInvestment: BigNumber;
37+
stableCoinAddresses: string[];
3538
}
3639

3740
interface BaseParams {
@@ -64,15 +67,31 @@ export class TieredSto extends Sto<Params> {
6467

6568
public currentTier: number;
6669

70+
public nonAccreditedInvestmentLimit: BigNumber;
71+
72+
public minimumInvestment: BigNumber;
73+
74+
public stableCoinAddresses: string[];
75+
6776
public tiers: Tier[];
6877

6978
constructor(params: Params & UniqueIdentifiers, context: Context) {
70-
const { currentTier, tiers, ...rest } = params;
79+
const {
80+
currentTier,
81+
tiers,
82+
nonAccreditedInvestmentLimit,
83+
minimumInvestment,
84+
stableCoinAddresses,
85+
...rest
86+
} = params;
7187

7288
super(rest, context);
7389

7490
const { securityTokenId, address, stoType } = rest;
7591

92+
this.nonAccreditedInvestmentLimit = nonAccreditedInvestmentLimit;
93+
this.minimumInvestment = minimumInvestment;
94+
this.stableCoinAddresses = stableCoinAddresses;
7695
this.currentTier = currentTier;
7796
this.tiers = tiers;
7897
this.uid = TieredSto.generateId({ address, stoType, securityTokenId });

src/entities/factories/TieredStoFactory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
2828
raisedFundsWallet,
2929
unsoldTokensWallet,
3030
numberOfTiers,
31+
minimumInvestment,
32+
nonAccreditedInvestmentLimit,
3133
{
3234
tokensSold,
3335
capPerTier,
@@ -49,8 +51,11 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
4951
module.wallet(),
5052
contractWrappers.getTreasuryWallet({ module }),
5153
module.getNumberOfTiers(),
54+
module.minimumInvestmentUSD(),
55+
module.nonAccreditedLimitUSD(),
5256
module.getSTODetails(),
5357
]);
58+
const stableCoinAddresses = await module.getUsdTokens();
5459

5560
let preIssueAllowed = false;
5661
let tiers: Tier[];
@@ -133,6 +138,9 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
133138
isFinalized,
134139
preIssueAllowed,
135140
beneficialInvestmentsAllowed,
141+
minimumInvestment,
142+
nonAccreditedInvestmentLimit,
143+
stableCoinAddresses,
136144
};
137145
};
138146

src/procedures/LaunchSimpleSto.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ export class LaunchSimpleSto extends Procedure<LaunchSimpleStoProcedureArgs, Sim
7474
usdCost = cost;
7575
}
7676

77-
await this.addProcedure(TransferErc20)({
78-
receiver: securityTokenAddress,
79-
amount: polyCost,
80-
});
77+
const balance = await contractWrappers.polyToken.balanceOf({ owner: securityTokenAddress });
78+
const difference = polyCost.minus(balance);
79+
80+
// only transfer the required amount of POLY
81+
if (difference.gt(new BigNumber(0))) {
82+
await this.addProcedure(TransferErc20)({
83+
receiver: securityTokenAddress,
84+
amount: difference,
85+
});
86+
}
8187

8288
const fundRaiseType =
8389
currency === Currency.ETH ? CappedSTOFundRaiseType.ETH : CappedSTOFundRaiseType.POLY;

src/procedures/LaunchTieredSto.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class LaunchTieredSto extends Procedure<LaunchTieredStoProcedureArgs, Tie
3535
currencies,
3636
raisedFundsWallet,
3737
unsoldTokensWallet,
38-
stableCoinAddresses,
38+
stableCoinAddresses = [],
3939
customCurrency,
4040
allowPreIssuing = false,
4141
} = args;
@@ -57,6 +57,13 @@ export class LaunchTieredSto extends Procedure<LaunchTieredStoProcedureArgs, Tie
5757
});
5858
}
5959

60+
if (currencies.includes(FundRaiseType.StableCoin) && stableCoinAddresses.length === 0) {
61+
throw new PolymathError({
62+
code: ErrorCode.ProcedureValidationError,
63+
message: 'Stable Coin address array cannot be empty if raising in Stable Coin',
64+
});
65+
}
66+
6067
const customOracleAddresses: string[] = [];
6168
let denominatedCurrency = '';
6269

@@ -116,10 +123,16 @@ export class LaunchTieredSto extends Procedure<LaunchTieredStoProcedureArgs, Tie
116123
usdCost = cost;
117124
}
118125

119-
await this.addProcedure(TransferErc20)({
120-
receiver: securityTokenAddress,
121-
amount: polyCost,
122-
});
126+
const balance = await contractWrappers.polyToken.balanceOf({ owner: securityTokenAddress });
127+
const difference = polyCost.minus(balance);
128+
129+
// only transfer the required amount of POLY
130+
if (difference.gt(new BigNumber(0))) {
131+
await this.addProcedure(TransferErc20)({
132+
receiver: securityTokenAddress,
133+
amount: difference,
134+
});
135+
}
123136

124137
const ratePerTier: BigNumber[] = [];
125138
const ratePerTierDiscountPoly: BigNumber[] = [];

0 commit comments

Comments
 (0)