Skip to content

Commit fef668b

Browse files
committed
feat: add all missing TieredSto properties and some for CappedSto
1 parent 06e719f commit fef668b

File tree

4 files changed

+183
-13
lines changed

4 files changed

+183
-13
lines changed

src/entities/Sto.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ export interface Params {
2424
startTime: Date;
2525
endTime: Date;
2626
fundraiseTypes: Currency[];
27+
raisedFundsWallet: string;
28+
unsoldTokensWallet: string;
2729
raisedAmount: BigNumber;
2830
soldTokensAmount: BigNumber;
2931
investorAmount: number;
3032
investments: Investment[];
3133
paused: boolean;
3234
capReached: boolean;
35+
isFinalized: boolean;
36+
preMintAllowed: boolean;
37+
beneficialInvestmentsAllowed: boolean;
3338
}
3439

3540
export abstract class Sto<P> extends Entity<P> {
@@ -47,6 +52,10 @@ export abstract class Sto<P> extends Entity<P> {
4752

4853
public endTime: Date;
4954

55+
public raisedFundsWallet: string;
56+
57+
public unsoldTokensWallet: string;
58+
5059
public raisedAmount: BigNumber;
5160

5261
public soldTokensAmount: BigNumber;
@@ -61,6 +70,12 @@ export abstract class Sto<P> extends Entity<P> {
6170

6271
public capReached: boolean;
6372

73+
public isFinalized: boolean;
74+
75+
public preMintAllowed: boolean;
76+
77+
public beneficialInvestmentsAllowed: boolean;
78+
6479
protected context: Context;
6580

6681
public static unserialize(serialized: string) {
@@ -87,12 +102,17 @@ export abstract class Sto<P> extends Entity<P> {
87102
fundraiseTypes,
88103
startTime,
89104
endTime,
105+
raisedFundsWallet,
106+
unsoldTokensWallet,
90107
raisedAmount,
91108
soldTokensAmount,
92109
investorAmount,
93110
investments,
94111
paused,
95112
capReached,
113+
isFinalized,
114+
preMintAllowed,
115+
beneficialInvestmentsAllowed,
96116
} = params;
97117

98118
this.address = address;
@@ -101,13 +121,18 @@ export abstract class Sto<P> extends Entity<P> {
101121
this.stoType = stoType;
102122
this.startTime = startTime;
103123
this.endTime = endTime;
124+
this.raisedFundsWallet = raisedFundsWallet;
125+
this.unsoldTokensWallet = unsoldTokensWallet;
104126
this.raisedAmount = raisedAmount;
105127
this.soldTokensAmount = soldTokensAmount;
106128
this.investorAmount = investorAmount;
107129
this.investments = investments;
108130
this.fundraiseTypes = fundraiseTypes;
109131
this.paused = paused;
110132
this.capReached = capReached;
133+
this.isFinalized = isFinalized;
134+
this.preMintAllowed = preMintAllowed;
135+
this.beneficialInvestmentsAllowed = beneficialInvestmentsAllowed;
111136
this.context = context;
112137
}
113138

@@ -175,26 +200,42 @@ export abstract class Sto<P> extends Entity<P> {
175200
const {
176201
uid,
177202
securityTokenId,
203+
address,
178204
securityTokenSymbol,
179205
fundraiseTypes,
206+
raisedFundsWallet,
207+
unsoldTokensWallet,
180208
raisedAmount,
181209
soldTokensAmount,
182210
investorAmount,
183211
investments,
184212
startTime,
185213
endTime,
214+
capReached,
215+
isFinalized,
216+
paused,
217+
preMintAllowed,
218+
beneficialInvestmentsAllowed,
186219
} = this;
187220

188221
return {
189222
uid,
190223
securityTokenId,
224+
address,
191225
securityTokenSymbol,
192226
fundraiseTypes,
227+
raisedFundsWallet,
228+
unsoldTokensWallet,
193229
raisedAmount,
194230
soldTokensAmount,
195231
investorAmount,
196232
startTime,
197233
endTime,
234+
capReached,
235+
isFinalized,
236+
paused,
237+
preMintAllowed,
238+
beneficialInvestmentsAllowed,
198239
investments: investments.map(investment => investment.toPojo()),
199240
};
200241
}
@@ -205,12 +246,17 @@ export abstract class Sto<P> extends Entity<P> {
205246
startTime,
206247
endTime,
207248
fundraiseTypes,
249+
raisedFundsWallet,
250+
unsoldTokensWallet,
208251
raisedAmount,
209252
soldTokensAmount,
210253
investorAmount,
211254
investments,
212255
paused,
213256
capReached,
257+
isFinalized,
258+
preMintAllowed,
259+
beneficialInvestmentsAllowed,
214260
} = params;
215261

216262
if (securityTokenSymbol) {
@@ -229,6 +275,14 @@ export abstract class Sto<P> extends Entity<P> {
229275
this.fundraiseTypes = fundraiseTypes;
230276
}
231277

278+
if (raisedFundsWallet) {
279+
this.raisedFundsWallet = raisedFundsWallet;
280+
}
281+
282+
if (unsoldTokensWallet) {
283+
this.unsoldTokensWallet = unsoldTokensWallet;
284+
}
285+
232286
if (raisedAmount) {
233287
this.raisedAmount = raisedAmount;
234288
}
@@ -252,5 +306,17 @@ export abstract class Sto<P> extends Entity<P> {
252306
if (capReached !== undefined) {
253307
this.capReached = capReached;
254308
}
309+
310+
if (isFinalized !== undefined) {
311+
this.isFinalized = isFinalized;
312+
}
313+
314+
if (preMintAllowed !== undefined) {
315+
this.preMintAllowed = preMintAllowed;
316+
}
317+
318+
if (beneficialInvestmentsAllowed !== undefined) {
319+
this.beneficialInvestmentsAllowed = beneficialInvestmentsAllowed;
320+
}
255321
}
256322
}

src/entities/TieredSto.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { Context } from '../Context';
66
export { UniqueIdentifiers };
77

88
export interface Tier {
9-
cap: BigNumber;
10-
rate: BigNumber;
9+
tokensOnSale: BigNumber;
10+
tokensSold: BigNumber;
11+
price: BigNumber;
12+
tokensWithDiscount: BigNumber;
13+
tokensSoldAtDiscount: BigNumber;
14+
discountedPrice: BigNumber;
1115
}
1216

1317
export interface Params extends StoParams {

src/entities/factories/CappedStoFactory.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
conversionUtils,
55
FULL_DECIMALS,
66
CappedSTOEvents,
7+
isCappedSTO_3_1_0,
78
} from '@polymathnetwork/contract-wrappers';
89
import { Factory } from './Factory';
910
import { Context } from '../../Context';
@@ -19,8 +20,11 @@ export class CappedStoFactory extends Factory<CappedSto, Params, UniqueIdentifie
1920
const { securityTokenId, stoType, address } = CappedSto.unserialize(uid);
2021

2122
const { symbol } = SecurityToken.unserialize(securityTokenId);
23+
const {
24+
context: { contractWrappers, factories },
25+
} = this;
2226

23-
const module = await this.context.contractWrappers.moduleFactory.getModuleInstance({
27+
const module = await contractWrappers.moduleFactory.getModuleInstance({
2428
name: ModuleName.CappedSTO,
2529
address,
2630
});
@@ -43,8 +47,33 @@ export class CappedStoFactory extends Factory<CappedSto, Params, UniqueIdentifie
4347
const [
4448
paused,
4549
capReached,
50+
beneficialInvestmentsAllowed,
51+
raisedFundsWallet,
4652
{ fundsRaised, investorCount, totalTokensSold, isRaisedInPoly, ...details },
47-
] = await Promise.all([module.paused(), module.capReached(), module.getSTODetails()]);
53+
] = await Promise.all([
54+
module.paused(),
55+
module.capReached(),
56+
module.allowBeneficialInvestments(),
57+
module.wallet(),
58+
module.getSTODetails(),
59+
]);
60+
61+
let preMintAllowed = false;
62+
let isFinalized = capReached || details.endTime <= new Date();
63+
let unsoldTokensWallet: string;
64+
65+
if (isCappedSTO_3_1_0(module)) {
66+
[preMintAllowed, unsoldTokensWallet, isFinalized] = await Promise.all([
67+
module.preMintAllowed(),
68+
module.getTreasuryWallet(),
69+
module.isFinalized(),
70+
]);
71+
} else {
72+
const securityToken = await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker(
73+
symbol
74+
);
75+
unsoldTokensWallet = await securityToken.owner();
76+
}
4877

4978
const stoId = CappedSto.generateId({
5079
securityTokenId,
@@ -53,14 +82,16 @@ export class CappedStoFactory extends Factory<CappedSto, Params, UniqueIdentifie
5382
});
5483

5584
const investmentEntities = investments.map(({ index, ...investment }) =>
56-
this.context.factories.investmentFactory.create(
57-
Investment.generateId({ securityTokenId, stoId, index }),
58-
{ securityTokenSymbol: symbol, ...investment }
59-
)
85+
factories.investmentFactory.create(Investment.generateId({ securityTokenId, stoId, index }), {
86+
securityTokenSymbol: symbol,
87+
...investment,
88+
})
6089
);
6190

6291
return {
6392
fundraiseTypes: isRaisedInPoly ? [Currency.POLY] : [Currency.ETH],
93+
raisedFundsWallet,
94+
unsoldTokensWallet,
6495
raisedAmount: fundsRaised,
6596
soldTokensAmount: totalTokensSold,
6697
investorAmount: investorCount,
@@ -72,6 +103,9 @@ export class CappedStoFactory extends Factory<CappedSto, Params, UniqueIdentifie
72103
address,
73104
paused,
74105
capReached,
106+
isFinalized,
107+
preMintAllowed,
108+
beneficialInvestmentsAllowed,
75109
};
76110
};
77111

src/entities/factories/TieredStoFactory.ts

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import {
44
BlockParamLiteral,
55
conversionUtils,
66
FULL_DECIMALS,
7+
isUSDTieredSTO_3_1_0,
78
} from '@polymathnetwork/contract-wrappers';
8-
import { zipWith } from 'lodash';
9+
import { range } from 'lodash';
910
import { Factory } from './Factory';
1011
import { Context } from '../../Context';
1112
import { Currency } from '../../types';
1213
import { SecurityToken } from '../SecurityToken';
1314
import { Investment } from '../Investment';
14-
import { TieredSto, Params, UniqueIdentifiers } from '../TieredSto';
15+
import { TieredSto, Params, UniqueIdentifiers, Tier } from '../TieredSto';
1516

1617
const { weiToValue } = conversionUtils;
1718

@@ -46,6 +47,10 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
4647
const [
4748
paused,
4849
capReached,
50+
isFinalized,
51+
beneficialInvestmentsAllowed,
52+
raisedFundsWallet,
53+
numberOfTiers,
4954
{
5055
tokensSold,
5156
capPerTier,
@@ -57,7 +62,65 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
5762
isRaisedInSC,
5863
...details
5964
},
60-
] = await Promise.all([module.paused(), module.capReached(), module.getSTODetails()]);
65+
] = await Promise.all([
66+
module.paused(),
67+
module.capReached(),
68+
module.isFinalized(),
69+
module.allowBeneficialInvestments(),
70+
module.wallet(),
71+
module.getNumberOfTiers(),
72+
module.getSTODetails(),
73+
]);
74+
75+
let preMintAllowed = false;
76+
let unsoldTokensWallet: string;
77+
let tiers: Tier[];
78+
let rawTiers;
79+
80+
if (isUSDTieredSTO_3_1_0(module)) {
81+
[preMintAllowed, unsoldTokensWallet, rawTiers] = await Promise.all([
82+
module.preMintAllowed(),
83+
module.getTreasuryWallet(),
84+
Promise.all(range(numberOfTiers).map(tier => module.tiers({ tier }))),
85+
]);
86+
tiers = rawTiers.map(
87+
({
88+
tokenTotal,
89+
totalTokensSoldInTier,
90+
rate,
91+
soldDiscountPoly,
92+
tokensDiscountPoly,
93+
rateDiscountPoly,
94+
}) => ({
95+
tokensOnSale: tokenTotal,
96+
tokensSold: totalTokensSoldInTier,
97+
price: rate,
98+
tokensWithDiscount: tokensDiscountPoly,
99+
tokensSoldAtDiscount: soldDiscountPoly,
100+
discountedPrice: rateDiscountPoly,
101+
})
102+
);
103+
} else {
104+
unsoldTokensWallet = await module.treasuryWallet();
105+
rawTiers = await Promise.all(range(numberOfTiers).map(tier => module.tiers({ tier })));
106+
tiers = rawTiers.map(
107+
({
108+
tokenTotal,
109+
mintedTotal,
110+
rate,
111+
tokensDiscountPoly,
112+
mintedDiscountPoly,
113+
rateDiscountPoly,
114+
}) => ({
115+
tokensOnSale: tokenTotal,
116+
tokensSold: mintedTotal,
117+
price: rate,
118+
tokensWithDiscount: tokensDiscountPoly,
119+
tokensSoldAtDiscount: mintedDiscountPoly,
120+
discountedPrice: rateDiscountPoly,
121+
})
122+
);
123+
}
61124

62125
const stoId = TieredSto.generateId({
63126
securityTokenId,
@@ -72,8 +135,6 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
72135
)
73136
);
74137

75-
const tiers = zipWith(capPerTier, ratePerTier, (cap, rate) => ({ cap, rate }));
76-
77138
const fundraiseTypes = [];
78139

79140
if (isRaisedInETH) {
@@ -90,6 +151,8 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
90151

91152
return {
92153
fundraiseTypes,
154+
raisedFundsWallet,
155+
unsoldTokensWallet,
93156
raisedAmount: fundsRaised,
94157
investorAmount: investorCount,
95158
soldTokensAmount: tokensSold,
@@ -102,6 +165,9 @@ export class TieredStoFactory extends Factory<TieredSto, Params, UniqueIdentifie
102165
address,
103166
paused,
104167
capReached,
168+
isFinalized,
169+
preMintAllowed,
170+
beneficialInvestmentsAllowed,
105171
};
106172
};
107173

0 commit comments

Comments
 (0)