Skip to content

Commit

Permalink
feat: refactor createST procedure to make totalSupply as option
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Jul 5, 2021
1 parent 555119e commit e595e6f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
20 changes: 18 additions & 2 deletions src/api/procedures/__tests__/createSecurityToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ describe('createSecurityToken procedure', () => {
args = {
ticker,
name,
totalSupply,
isDivisible,
tokenType,
tokenIdentifiers,
Expand Down Expand Up @@ -231,7 +230,7 @@ describe('createSecurityToken procedure', () => {
test('should add a token creation transaction to the queue', async () => {
const proc = procedureMockUtils.getInstance<Params, SecurityToken>(mockContext);

const result = await prepareCreateSecurityToken.call(proc, args);
let result = await prepareCreateSecurityToken.call(proc, args);

sinon.assert.calledWith(
addTransactionStub.firstCall,
Expand All @@ -248,6 +247,7 @@ describe('createSecurityToken procedure', () => {

await prepareCreateSecurityToken.call(proc, {
...args,
totalSupply: new BigNumber(0),
tokenIdentifiers: undefined,
fundingRound: undefined,
});
Expand All @@ -263,6 +263,22 @@ describe('createSecurityToken procedure', () => {
[],
null
);

const addBatchTransactionStub = procedureMockUtils.getAddBatchTransactionStub();

result = await prepareCreateSecurityToken.call(proc, { ...args, totalSupply });

sinon.assert.calledWith(addBatchTransactionStub, transaction, { fee: undefined }, [
[rawName, rawTicker, rawIsDivisible, rawType, rawIdentifiers, rawFundingRound],
]);

const assetIssueTransaction = dsMockUtils.createTxStub('asset', 'issue');

result = await prepareCreateSecurityToken.call(proc, { ...args, totalSupply });

sinon.assert.calledWith(addBatchTransactionStub, assetIssueTransaction, {}, [
[rawTicker, rawTotalSupply],
]);
});

test('should waive protocol fees if the token was created in Ethereum', async () => {
Expand Down
37 changes: 25 additions & 12 deletions src/api/procedures/createSecurityToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {
TokenType,
} from '~/types';
import { ProcedureAuthorization } from '~/types/internal';
import { tuple } from '~/types/utils';
import {
booleanToBool,
boolToBoolean,
numberToBalance,
stringToAssetName,
stringToFundingRoundName,
stringToTicker,
Expand All @@ -26,9 +28,9 @@ import { batchArguments } from '~/utils/internal';
export interface CreateSecurityTokenParams {
name: string;
/**
* amount of tokens that will be minted on creation
* amount of tokens that will be minted on creation (optional, default doesn't mint)
*/
totalSupply: BigNumber;
totalSupply?: BigNumber;
/**
* whether a single token can be divided into decimal parts
*/
Expand Down Expand Up @@ -71,6 +73,7 @@ export async function prepareCreateSecurityToken(
const {
ticker,
name,
totalSupply,
isDivisible,
tokenType,
tokenIdentifiers = [],
Expand Down Expand Up @@ -118,16 +121,26 @@ export async function prepareCreateSecurityToken(
fee = new BigNumber(0);
}

this.addTransaction(
tx.asset.createAsset,
{ fee },
rawName,
rawTicker,
rawIsDivisible,
rawType,
rawIdentifiers,
rawFundingRound
);
if (!totalSupply || (totalSupply && totalSupply.eq(0))) {
this.addTransaction(
tx.asset.createAsset,
{ fee },
rawName,
rawTicker,
rawIsDivisible,
rawType,
rawIdentifiers,
rawFundingRound
);
} else {
this.addBatchTransaction(tx.asset.createAsset, { fee }, [
tuple(rawName, rawTicker, rawIsDivisible, rawType, rawIdentifiers, rawFundingRound),
]);

const rawTotalSupply = numberToBalance(totalSupply, context, isDivisible);

this.addBatchTransaction(tx.asset.issue, {}, [tuple(rawTicker, rawTotalSupply)]);
}

if (documents) {
const rawDocuments = documents.map(doc => tokenDocumentToDocument(doc, context));
Expand Down

0 comments on commit e595e6f

Please sign in to comment.