Skip to content

Commit

Permalink
Merge branch 'beta' into docs/checkpoint-entity
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Jan 16, 2020
2 parents 0084f3e + 326ff97 commit 7e4b195
Show file tree
Hide file tree
Showing 32 changed files with 855 additions and 81 deletions.
5 changes: 3 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@polymathnetwork/sdk",
"version": "2.0.1-beta.93",
"version": "2.0.1-beta.98",
"description": "A Javascript SDK for interacting with the Polymath network for the browser and Node.js",
"bugs": {
"url": "https://github.com/PolymathNetwork/polymath-sdk/issues"
Expand All @@ -25,7 +25,7 @@
"semantic-release": "semantic-release",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
"lint": "eslint src --ext .ts",
"postinstall": "rm -rf ./node_modules/typedoc/node_modules/typescript"
"postinstall": "rimraf ./node_modules/typedoc/node_modules/typescript"
},
"jest": {
"moduleFileExtensions": [
Expand Down Expand Up @@ -107,6 +107,7 @@
"prettier-eslint-cli": "^4.7.1",
"reflect-metadata": "^0.1.12",
"regenerator-runtime": "^0.13.1",
"rimraf": "^3.0.0",
"semantic-release": "^16.0.0-beta.18",
"sinon": "^7.5.0",
"ts-loader": "^5.3.3",
Expand Down
3 changes: 3 additions & 0 deletions src/entities/Entity.ts
@@ -1,3 +1,6 @@
/**
* Represents an object or resource in the Polymath Ecosystem with its own set of properties and functionality
*/
export abstract class Entity<Params> {
public abstract uid: string;

Expand Down
35 changes: 35 additions & 0 deletions src/entities/Erc20TokenBalance.ts
Expand Up @@ -4,6 +4,9 @@ import { serialize, unserialize } from '../utils';
import { PolymathError } from '../PolymathError';
import { ErrorCode } from '../types';

/**
* Properties that uniquely identify an ERC20 token balance
*/
export interface UniqueIdentifiers {
tokenAddress: string;
walletAddress: string;
Expand All @@ -15,11 +18,17 @@ function isUniqueIdentifiers(identifiers: any): identifiers is UniqueIdentifiers
return typeof tokenAddress === 'string' && typeof walletAddress === 'string';
}

/**
* Constructor parameters
*/
export interface Params {
tokenSymbol: string | null;
balance: BigNumber;
}

/**
* Used to manage a ERC20 token balance
*/
export class Erc20TokenBalance extends Entity<Params> {
public static generateId({ tokenAddress, walletAddress }: UniqueIdentifiers) {
return serialize('erc20TokenBalance', {
Expand All @@ -28,6 +37,11 @@ export class Erc20TokenBalance extends Entity<Params> {
});
}

/**
* Unserialize a serialized erc20 token balance
*
* @param serialized - string with erc20 token balance entity information
*/
public static unserialize(serialized: any) {
const unserialized = unserialize(serialized);

Expand All @@ -41,16 +55,31 @@ export class Erc20TokenBalance extends Entity<Params> {
return unserialized;
}

/**
* unique generated identifier for an ERC20 token balance
*/
public uid: string;

public tokenSymbol: string | null;

/**
* address of the ERC20 token
*/
public tokenAddress: string;

/**
* wallet address of the token holder
*/
public walletAddress: string;

/**
* total number of tokens belonging to token holder
*/
public balance: BigNumber;

/**
* Create an ERC20 Token balance instance
*/
constructor(params: Params & UniqueIdentifiers) {
super();

Expand All @@ -66,6 +95,9 @@ export class Erc20TokenBalance extends Entity<Params> {
});
}

/**
* Convert entity to a POJO (Plain Old Javascript Object)
*/
public toPojo() {
const { uid, tokenSymbol, tokenAddress, balance, walletAddress } = this;

Expand All @@ -78,6 +110,9 @@ export class Erc20TokenBalance extends Entity<Params> {
};
}

/**
* Hydrate the entity
*/
public _refresh(params: Partial<Params>) {
const { tokenSymbol, balance } = params;

Expand Down
41 changes: 41 additions & 0 deletions src/entities/Investment.ts
Expand Up @@ -4,6 +4,9 @@ import { serialize, unserialize } from '../utils';
import { PolymathError } from '../PolymathError';
import { ErrorCode } from '../types';

/**
* Properties that uniquely identify an Investment
*/
export interface UniqueIdentifiers {
securityTokenId: string;
stoId: string;
Expand All @@ -18,13 +21,19 @@ function isUniqueIdentifiers(identifiers: any): identifiers is UniqueIdentifiers
);
}

/**
* Constructor parameters
*/
export interface Params {
securityTokenSymbol: string;
address: string;
tokenAmount: BigNumber;
investedFunds: BigNumber;
}

/**
* Used to manage an Investment in a Security Token Offering
*/
export class Investment extends Entity<Params> {
public static generateId({ securityTokenId, stoId, index }: UniqueIdentifiers) {
return serialize('investment', {
Expand All @@ -34,6 +43,11 @@ export class Investment extends Entity<Params> {
});
}

/**
* Unserialize a serialized Investment entity
*
* @param serialized - string with Investment entity information
*/
public static unserialize(serialized: string) {
const unserialized = unserialize(serialized);

Expand All @@ -47,22 +61,43 @@ export class Investment extends Entity<Params> {
return unserialized;
}

/**
* unique generated identifier for an Investment
*/
public uid: string;

public securityTokenId: string;

/**
* unique ID for the Investment
*/
public stoId: string;

public securityTokenSymbol: string;

/**
* wallet address of token holder
*/
public address: string;

/**
* index of the Investment
*/
public index: number;

/**
* total amount of tokens involved in the Investment
*/
public tokenAmount: BigNumber;

/**
* amount of funds used to make Investment
*/
public investedFunds: BigNumber;

/**
* Create an Investment instance
*/
constructor(params: Params & UniqueIdentifiers) {
super();

Expand Down Expand Up @@ -90,6 +125,9 @@ export class Investment extends Entity<Params> {
});
}

/**
* Convert entity to a POJO (Plain Old Javascript Object)
*/
public toPojo() {
const {
uid,
Expand All @@ -114,6 +152,9 @@ export class Investment extends Entity<Params> {
};
}

/**
* Hydrate the entity
*/
public _refresh(params: Partial<Params>) {
const { securityTokenSymbol, address, investedFunds, tokenAmount } = params;

Expand Down

0 comments on commit 7e4b195

Please sign in to comment.