Skip to content

Commit

Permalink
feat: setIssuanceData structure
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Apr 13, 2020
1 parent 390aa05 commit edff37f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/api/entities/SecurityToken/Issuance.ts
@@ -0,0 +1,23 @@
import { setIssuanceData } from '~/api/procedures';
import { Namespace, TransactionQueue } from '~/base';
import { IssuanceData } from '~/types';

import { SecurityToken } from './';

/**
* Handles all Security Token Issuance related functionality
*/
export class Issuance extends Namespace<SecurityToken> {
/**
* Issue a certain amount of tokens to a one or multiple DIDs. The investor must be an acredited client.
*
* @param args.issuances - array that specifies who to issue tokens to and which amounts
*/
public issue(args: { issuances: IssuanceData[] }): Promise<TransactionQueue<SecurityToken>> {
const {
parent: { ticker },
context,
} = this;
return setIssuanceData.prepare({ ticker, ...args }, context);
}
}
3 changes: 3 additions & 0 deletions src/api/entities/SecurityToken/index.ts
Expand Up @@ -23,6 +23,7 @@ import {
} from '~/utils';

import { Documents } from './Documents';
import { Issuance } from './Issuance';
import { Transfers } from './Transfers';
import { SecurityTokenDetails } from './types';

Expand Down Expand Up @@ -63,6 +64,7 @@ export class SecurityToken extends Entity<UniqueIdentifiers> {
// Namespaces
public documents: Documents;
public transfers: Transfers;
public issuance: Issuance;

/**
* @hidden
Expand All @@ -77,6 +79,7 @@ export class SecurityToken extends Entity<UniqueIdentifiers> {

this.documents = new Documents(this, context);
this.transfers = new Transfers(this, context);
this.issuance = new Issuance(this, context);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/api/procedures/index.ts
Expand Up @@ -5,3 +5,4 @@ export { createSecurityToken, CreateSecurityTokenParams } from './createSecurity
export { setTokenDocuments, SetTokenDocumentsParams } from './setTokenDocuments';
export { transferTokenOwnership, TransferTokenOwnershipParams } from './transferTokenOwnership';
export { consumeAuthorizationRequests, ConsumeParams } from './consumeAuthorizationRequests';
export { setIssuanceData, SetIssuanceDataParams } from './setIssuanceData';
41 changes: 41 additions & 0 deletions src/api/procedures/setIssuanceData.ts
@@ -0,0 +1,41 @@
import { SecurityToken } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
import { ErrorCode, IssuanceData, Role, RoleType } from '~/types';
import { stringToTicker } from '~/utils';

export interface SetIssuanceDataParams {
issuances: IssuanceData[];
}

export type Params = SetIssuanceDataParams & {
ticker: string;
};

/**
* @hidden
*/
export async function prepareSetIssuanceData(
this: Procedure<Params, SecurityToken>,
args: Params
): Promise<SecurityToken> {
const {
context: {
polymeshApi: { query, tx },
},
context,
} = this;
const { ticker, issuances } = args;

const rawTicker = stringToTicker(ticker, context);

return new SecurityToken({ ticker }, context);
}

/**
* @hidden
*/
export function getRequiredRoles({ ticker }: Params): Role[] {
return [{ type: RoleType.TokenOwner, ticker }];
}

export const setIssuanceData = new Procedure(prepareSetIssuanceData, getRequiredRoles);
10 changes: 10 additions & 0 deletions src/types/index.ts
@@ -1,3 +1,5 @@
import BigNumber from 'bignumber.js';

export enum TransactionStatus {
/**
* the transaction is prepped to run
Expand Down Expand Up @@ -162,4 +164,12 @@ export enum ErrorCode {
NotAuthorized = 'NotAuthorized',
}

/**
* Issuer representation
*/
export interface IssuanceData {
did: string;
balance: BigNumber;
}

export * from '~/api/entities/types';

0 comments on commit edff37f

Please sign in to comment.