Skip to content

Commit 3a755df

Browse files
committed
feat: change Sto interface
Removed `investments` in favor of a `getInvestments` function. Changed `investorAmount` to `investorCount` BREAKING CHANGE: Removed `investments` in favor of a `getInvestments` function. Changed `investorAmount` to `investorCount`
1 parent 07e5d92 commit 3a755df

File tree

6 files changed

+127
-100
lines changed

6 files changed

+127
-100
lines changed

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"typescript.tsdk": "node_modules/typescript/lib",
33
"editor.tabSize": 2,
4-
"editor.formatOnSave": true,
5-
"prettier.eslintIntegration": true
4+
"editor.formatOnSave": true
65
}

src/entities/CappedSto.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
import { BigNumber } from '@polymathnetwork/contract-wrappers';
1+
import {
2+
BigNumber,
3+
ModuleName,
4+
CappedSTOEvents,
5+
BlockParamLiteral,
6+
conversionUtils,
7+
FULL_DECIMALS,
8+
} from '@polymathnetwork/contract-wrappers';
29
import { serialize } from '../utils';
310
import { Sto, UniqueIdentifiers, Params as StoParams } from './Sto';
411
import { Context } from '../Context';
512
import { InvestInCappedStoProcedureArgs, Currency } from '../types';
613
import { TransactionQueue } from './TransactionQueue';
714
import { InvestInCappedSto } from '../procedures';
15+
import { Investment } from './Investment';
16+
17+
const { weiToValue } = conversionUtils;
818

919
export interface Params extends StoParams {
1020
cap: BigNumber;
@@ -40,6 +50,48 @@ export class CappedSto extends Sto<Params> {
4050
this.uid = CappedSto.generateId({ address, stoType, securityTokenId });
4151
}
4252

53+
/**
54+
* Retrieve all investments that have been made on this STO
55+
*/
56+
public async getInvestments(): Promise<Investment[]> {
57+
const {
58+
context: { contractWrappers, factories },
59+
address,
60+
securityTokenSymbol: symbol,
61+
securityTokenId,
62+
uid: stoId,
63+
} = this;
64+
65+
const module = await contractWrappers.moduleFactory.getModuleInstance({
66+
name: ModuleName.CappedSTO,
67+
address,
68+
});
69+
70+
const tokenPurchases = await module.getLogsAsync({
71+
eventName: CappedSTOEvents.TokenPurchase,
72+
blockRange: {
73+
fromBlock: BlockParamLiteral.Earliest,
74+
toBlock: BlockParamLiteral.Latest,
75+
},
76+
indexFilterValues: {},
77+
});
78+
const investments = tokenPurchases.map(({ args: { beneficiary, amount, value } }, index) => ({
79+
address: beneficiary,
80+
tokenAmount: weiToValue(amount, FULL_DECIMALS),
81+
investedFunds: weiToValue(value, FULL_DECIMALS),
82+
index,
83+
}));
84+
85+
const investmentEntities = investments.map(({ index, ...investment }) =>
86+
factories.investmentFactory.create(Investment.generateId({ securityTokenId, stoId, index }), {
87+
securityTokenSymbol: symbol,
88+
...investment,
89+
})
90+
);
91+
92+
return investmentEntities;
93+
}
94+
4395
/**
4496
* Invests in the STO
4597
*

src/entities/Sto.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigNumber } from '@polymathnetwork/contract-wrappers';
1+
import { BigNumber, CappedSTOEvents } from '@polymathnetwork/contract-wrappers';
22
import { Entity } from './Entity';
33
import { unserialize } from '../utils';
44
import { StoType, isStoType, Currency, ErrorCode, StoRole } from '../types';
@@ -7,6 +7,8 @@ import { PolymathError } from '../PolymathError';
77
import { Context } from '../Context';
88
import { PauseSto, AssignStoRole, FinalizeSto, ModifyBeneficialInvestments } from '../procedures';
99
import { ModifyPreMinting } from '../procedures/ModifyPreMinting';
10+
import { CappedSto } from './CappedSto';
11+
import { TieredSto } from './TieredSto';
1012

1113
export interface UniqueIdentifiers {
1214
securityTokenId: string;
@@ -29,8 +31,7 @@ export interface Params {
2931
unsoldTokensWallet: string;
3032
raisedAmount: BigNumber;
3133
soldTokensAmount: BigNumber;
32-
investorAmount: number;
33-
investments: Investment[];
34+
investorCount: number;
3435
isPaused: boolean;
3536
capReached: boolean;
3637
isFinalized: boolean;
@@ -61,9 +62,7 @@ export abstract class Sto<P> extends Entity<P> {
6162

6263
public soldTokensAmount: BigNumber;
6364

64-
public investorAmount: number;
65-
66-
public investments: Investment[];
65+
public investorCount: number;
6766

6867
public currencies: Currency[];
6968

@@ -107,8 +106,7 @@ export abstract class Sto<P> extends Entity<P> {
107106
unsoldTokensWallet,
108107
raisedAmount,
109108
soldTokensAmount,
110-
investorAmount,
111-
investments,
109+
investorCount,
112110
isPaused,
113111
capReached,
114112
isFinalized,
@@ -126,8 +124,7 @@ export abstract class Sto<P> extends Entity<P> {
126124
this.unsoldTokensWallet = unsoldTokensWallet;
127125
this.raisedAmount = raisedAmount;
128126
this.soldTokensAmount = soldTokensAmount;
129-
this.investorAmount = investorAmount;
130-
this.investments = investments;
127+
this.investorCount = investorCount;
131128
this.currencies = currencies;
132129
this.isPaused = isPaused;
133130
this.capReached = capReached;
@@ -278,8 +275,7 @@ export abstract class Sto<P> extends Entity<P> {
278275
unsoldTokensWallet,
279276
raisedAmount,
280277
soldTokensAmount,
281-
investorAmount,
282-
investments,
278+
investorCount,
283279
startDate,
284280
endDate,
285281
capReached,
@@ -299,15 +295,14 @@ export abstract class Sto<P> extends Entity<P> {
299295
unsoldTokensWallet,
300296
raisedAmount,
301297
soldTokensAmount,
302-
investorAmount,
298+
investorCount,
303299
startDate,
304300
endDate,
305301
capReached,
306302
isFinalized,
307303
isPaused,
308304
preMintAllowed,
309305
beneficialInvestmentsAllowed,
310-
investments: investments.map(investment => investment.toPojo()),
311306
};
312307
}
313308

@@ -321,8 +316,7 @@ export abstract class Sto<P> extends Entity<P> {
321316
unsoldTokensWallet,
322317
raisedAmount,
323318
soldTokensAmount,
324-
investorAmount,
325-
investments,
319+
investorCount,
326320
isPaused,
327321
capReached,
328322
isFinalized,
@@ -362,12 +356,8 @@ export abstract class Sto<P> extends Entity<P> {
362356
this.soldTokensAmount = soldTokensAmount;
363357
}
364358

365-
if (investorAmount) {
366-
this.investorAmount = investorAmount;
367-
}
368-
369-
if (investments) {
370-
this.investments = investments;
359+
if (investorCount) {
360+
this.investorCount = investorCount;
371361
}
372362

373363
if (isPaused !== undefined) {

src/entities/TieredSto.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
import { BigNumber } from '@polymathnetwork/contract-wrappers';
1+
import {
2+
BigNumber,
3+
ModuleName,
4+
USDTieredSTOEvents,
5+
BlockParamLiteral,
6+
FULL_DECIMALS,
7+
conversionUtils,
8+
} from '@polymathnetwork/contract-wrappers';
29
import { serialize } from '../utils';
310
import { Sto, UniqueIdentifiers, Params as StoParams } from './Sto';
411
import { Context } from '../Context';
512
import { StoTier, Currency, InvestInTieredStoProcedureArgs } from '../types';
613
import { ModifyTieredStoData, InvestInTieredSto } from '../procedures';
714
import { TransactionQueue } from './TransactionQueue';
15+
import { Investment } from './Investment';
16+
17+
const { weiToValue } = conversionUtils;
818

919
export { UniqueIdentifiers };
1020

@@ -66,6 +76,50 @@ export class TieredSto extends Sto<Params> {
6676
this.uid = TieredSto.generateId({ address, stoType, securityTokenId });
6777
}
6878

79+
/**
80+
* Retrieve all investments that have been made on this STO
81+
*/
82+
public async getInvestments(): Promise<Investment[]> {
83+
const {
84+
context: { contractWrappers, factories },
85+
address,
86+
securityTokenSymbol: symbol,
87+
securityTokenId,
88+
uid: stoId,
89+
} = this;
90+
91+
const module = await contractWrappers.moduleFactory.getModuleInstance({
92+
name: ModuleName.UsdTieredSTO,
93+
address,
94+
});
95+
96+
const tokenPurchases = await module.getLogsAsync({
97+
eventName: USDTieredSTOEvents.TokenPurchase,
98+
blockRange: {
99+
fromBlock: BlockParamLiteral.Earliest,
100+
toBlock: BlockParamLiteral.Latest,
101+
},
102+
indexFilterValues: {},
103+
});
104+
const investments = tokenPurchases.map(
105+
({ args: { _beneficiary, _usdAmount, _tokens } }, index) => ({
106+
address: _beneficiary,
107+
tokenAmount: weiToValue(_tokens, FULL_DECIMALS),
108+
investedFunds: weiToValue(_usdAmount, FULL_DECIMALS),
109+
index,
110+
})
111+
);
112+
113+
const investmentEntities = investments.map(({ index, ...investment }) =>
114+
factories.investmentFactory.create(Investment.generateId({ securityTokenId, stoId, index }), {
115+
securityTokenSymbol: symbol,
116+
...investment,
117+
})
118+
);
119+
120+
return investmentEntities;
121+
}
122+
69123
/**
70124
* Modifies STO parameters. Must be done before the STO starts
71125
*

src/entities/factories/CappedStoFactory.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,24 @@
1-
import {
2-
ModuleName,
3-
BlockParamLiteral,
4-
conversionUtils,
5-
FULL_DECIMALS,
6-
CappedSTOEvents,
7-
isCappedSTO_3_1_0,
8-
} from '@polymathnetwork/contract-wrappers';
1+
import { ModuleName, isCappedSTO_3_1_0 } from '@polymathnetwork/contract-wrappers';
92
import { Factory } from './Factory';
103
import { Context } from '../../Context';
114
import { Currency } from '../../types';
125
import { CappedSto, Params, UniqueIdentifiers } from '../CappedSto';
136
import { SecurityToken } from '../SecurityToken';
14-
import { Investment } from '../Investment';
15-
16-
const { weiToValue } = conversionUtils;
177

188
export class CappedStoFactory extends Factory<CappedSto, Params, UniqueIdentifiers> {
199
protected generateProperties = async (uid: string) => {
2010
const { securityTokenId, stoType, address } = CappedSto.unserialize(uid);
2111

2212
const { symbol } = SecurityToken.unserialize(securityTokenId);
2313
const {
24-
context: { contractWrappers, factories },
14+
context: { contractWrappers },
2515
} = this;
2616

2717
const module = await contractWrappers.moduleFactory.getModuleInstance({
2818
name: ModuleName.CappedSTO,
2919
address,
3020
});
3121

32-
const tokenPurchases = await module.getLogsAsync({
33-
eventName: CappedSTOEvents.TokenPurchase,
34-
blockRange: {
35-
fromBlock: BlockParamLiteral.Earliest,
36-
toBlock: BlockParamLiteral.Latest,
37-
},
38-
indexFilterValues: {},
39-
});
40-
const investments = tokenPurchases.map(({ args: { beneficiary, amount, value } }, index) => ({
41-
address: beneficiary,
42-
tokenAmount: weiToValue(amount, FULL_DECIMALS),
43-
investedFunds: weiToValue(value, FULL_DECIMALS),
44-
index,
45-
}));
46-
4722
const [
4823
isPaused,
4924
capReached,
@@ -84,26 +59,18 @@ export class CappedStoFactory extends Factory<CappedSto, Params, UniqueIdentifie
8459
address,
8560
});
8661

87-
const investmentEntities = investments.map(({ index, ...investment }) =>
88-
factories.investmentFactory.create(Investment.generateId({ securityTokenId, stoId, index }), {
89-
securityTokenSymbol: symbol,
90-
...investment,
91-
})
92-
);
93-
9462
return {
9563
currencies: isRaisedInPoly ? [Currency.POLY] : [Currency.ETH],
9664
raisedFundsWallet,
9765
unsoldTokensWallet,
9866
raisedAmount: fundsRaised,
9967
soldTokensAmount: totalTokensSold,
100-
investorAmount: investorCount,
68+
investorCount,
10169
startDate: startTime,
10270
endDate: endTime,
10371
...details,
10472
securityTokenId,
10573
securityTokenSymbol: symbol,
106-
investments: investmentEntities,
10774
stoType,
10875
address,
10976
isPaused,

0 commit comments

Comments
 (0)