Skip to content

Commit

Permalink
feat: rename treasuryIdentity to primaryIssuanceAgent. MSDK-289
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Sep 23, 2020
1 parent eae437b commit 8d19fdb
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/Polymesh.ts
Expand Up @@ -762,7 +762,7 @@ describe('Polymesh Class', () => {
name: dsMockUtils.createMockAssetName(),
asset_type: dsMockUtils.createMockAssetType(),
divisible: dsMockUtils.createMockBool(),
treasury_did: dsMockUtils.createMockOption(),
primary_issuance_agent: dsMockUtils.createMockOption(),
total_supply: dsMockUtils.createMockBalance(),
/* eslint-enable @typescript-eslint/camelcase */
}),
Expand All @@ -787,7 +787,7 @@ describe('Polymesh Class', () => {
name: dsMockUtils.createMockAssetName(),
asset_type: dsMockUtils.createMockAssetType(),
divisible: dsMockUtils.createMockBool(),
treasury_did: dsMockUtils.createMockOption(),
primary_issuance_agent: dsMockUtils.createMockOption(),
total_supply: dsMockUtils.createMockBalance(),
/* eslint-enable @typescript-eslint/camelcase */
}),
Expand Down
2 changes: 1 addition & 1 deletion src/api/entities/Identity/__tests__/index.ts
Expand Up @@ -217,7 +217,7 @@ describe('Identity class', () => {
total_supply: dsMockUtils.createMockBalance(3000),
divisible: dsMockUtils.createMockBool(true),
asset_type: dsMockUtils.createMockAssetType('EquityCommon'),
treasury_did: dsMockUtils.createMockOption(),
primary_issuance_agent: dsMockUtils.createMockOption(),
name: dsMockUtils.createMockAssetName('someToken'),
})
);
Expand Down
10 changes: 5 additions & 5 deletions src/api/entities/SecurityToken/__tests__/index.ts
Expand Up @@ -63,7 +63,7 @@ describe('SecurityToken class', () => {
let isDivisible: boolean;
let owner: string;
let assetType: 'EquityCommon';
let treasuryIdentity: string;
let primaryIssuanceAgent: string;

let rawToken: MeshSecurityToken;

Expand All @@ -76,7 +76,7 @@ describe('SecurityToken class', () => {
isDivisible = true;
owner = '0x0wn3r';
assetType = 'EquityCommon';
treasuryIdentity = '0xtr34sury';
primaryIssuanceAgent = '0xtr34sury';
});

beforeEach(() => {
Expand All @@ -88,7 +88,7 @@ describe('SecurityToken class', () => {
divisible: dsMockUtils.createMockBool(isDivisible),
total_supply: dsMockUtils.createMockBalance(totalSupply),
primary_issuance_agent: dsMockUtils.createMockOption(
dsMockUtils.createMockIdentityId(treasuryIdentity)
dsMockUtils.createMockIdentityId(primaryIssuanceAgent)
),
/* eslint-enable @typescript-eslint/camelcase */
});
Expand All @@ -109,7 +109,7 @@ describe('SecurityToken class', () => {
expect(details.isDivisible).toBe(isDivisible);
expect(details.owner.did).toBe(owner);
expect(details.assetType).toBe(assetType);
expect(details.treasuryIdentity?.did).toBe(treasuryIdentity);
expect(details.primaryIssuanceAgent?.did).toBe(primaryIssuanceAgent);
});

test('should allow subscription', async () => {
Expand All @@ -133,7 +133,7 @@ describe('SecurityToken class', () => {
name: ticker,
owner: new Identity({ did: owner }, context),
totalSupply: new BigNumber(totalSupply).div(Math.pow(10, 6)),
treasuryIdentity: null,
primaryIssuanceAgent: null,
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/entities/SecurityToken/index.ts
Expand Up @@ -162,7 +162,7 @@ export class SecurityToken extends Entity<UniqueIdentifiers> {
name: assetNameToString(name),
owner: new Identity({ did: identityIdToString(owner_did) }, context),
totalSupply: balanceToBigNumber(total_supply),
treasuryIdentity: primary_issuance_agent.isSome
primaryIssuanceAgent: primary_issuance_agent.isSome
? new Identity({ did: identityIdToString(primary_issuance_agent.unwrap()) }, context)
: null,
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/entities/SecurityToken/types.ts
Expand Up @@ -8,7 +8,7 @@ export interface SecurityTokenDetails {
name: string;
owner: Identity;
totalSupply: BigNumber;
treasuryIdentity: Identity | null;
primaryIssuanceAgent: Identity | null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/entities/TickerReservation/__tests__/index.ts
Expand Up @@ -160,7 +160,7 @@ describe('TickerReservation class', () => {
name: dsMockUtils.createMockAssetName('someToken'),
asset_type: dsMockUtils.createMockAssetType('EquityCommon'),
divisible: dsMockUtils.createMockBool(true),
treasury_did: dsMockUtils.createMockOption(),
primary_issuance_agent: dsMockUtils.createMockOption(),
total_supply: dsMockUtils.createMockBalance(1000),
/* eslint-enable @typescript-eslint/camelcase */
}),
Expand Down
2 changes: 2 additions & 0 deletions src/api/entities/TickerReservation/index.ts
Expand Up @@ -150,6 +150,8 @@ export class TickerReservation extends Entity<UniqueIdentifiers> {
/**
* Create a Security Token using the reserved ticker
*
* @note the primary issuance agent will be the issuer did
*
* @param args.totalSupply - amount of tokens that will be minted on creation
* @param args.isDivisible - whether a single token can be divided into decimal parts
* @param args.tokenType - type of security that the token represents (i.e. Equity, Debt, Commodity, etc)
Expand Down
13 changes: 1 addition & 12 deletions src/api/procedures/__tests__/createSecurityToken.ts
Expand Up @@ -10,7 +10,6 @@ import {
DocumentName,
FundingRoundName,
IdentifierType,
IdentityId,
Ticker,
} from 'polymesh-types/types';
import sinon from 'sinon';
Expand Down Expand Up @@ -57,7 +56,6 @@ describe('createSecurityToken procedure', () => {
>;
let stringToAssetIdentifierStub: sinon.SinonStub<[string, Context], AssetIdentifier>;
let stringToFundingRoundNameStub: sinon.SinonStub<[string, Context], FundingRoundName>;
let stringToIdentityIdStub: sinon.SinonStub<[string, Context], IdentityId>;
let stringToDocumentNameStub: sinon.SinonStub<[string, Context], DocumentName>;
let tokenDocumentDataToDocumentStub: sinon.SinonStub<[TokenDocumentData, Context], Document>;
let ticker: string;
Expand All @@ -67,7 +65,6 @@ describe('createSecurityToken procedure', () => {
let tokenType: TokenType;
let tokenIdentifiers: TokenIdentifier[];
let fundingRound: string;
let treasury: string;
let documents: TokenDocument[];
let rawTicker: Ticker;
let rawName: AssetName;
Expand All @@ -76,7 +73,6 @@ describe('createSecurityToken procedure', () => {
let rawType: AssetType;
let rawIdentifiers: [IdentifierType, AssetIdentifier][];
let rawFundingRound: FundingRoundName;
let rawTreasury: IdentityId;
let rawDocuments: Document[];
let rawDocumentTuples: [DocumentName, Document][];
let args: Params;
Expand All @@ -98,7 +94,6 @@ describe('createSecurityToken procedure', () => {
);
stringToAssetIdentifierStub = sinon.stub(utilsModule, 'stringToAssetIdentifier');
stringToFundingRoundNameStub = sinon.stub(utilsModule, 'stringToFundingRoundName');
stringToIdentityIdStub = sinon.stub(utilsModule, 'stringToIdentityId');
stringToDocumentNameStub = sinon.stub(utilsModule, 'stringToDocumentName');
tokenDocumentDataToDocumentStub = sinon.stub(utilsModule, 'tokenDocumentDataToDocument');
ticker = 'someTicker';
Expand All @@ -113,7 +108,6 @@ describe('createSecurityToken procedure', () => {
},
];
fundingRound = 'Series A';
treasury = 'someDid';
documents = [
{
name: 'someDocument',
Expand Down Expand Up @@ -143,7 +137,6 @@ describe('createSecurityToken procedure', () => {
tuple(dsMockUtils.createMockDocumentName(documentName), rawDocuments[index])
);
rawFundingRound = dsMockUtils.createMockFundingRoundName(fundingRound);
rawTreasury = dsMockUtils.createMockIdentityId(treasury);
args = {
ticker,
name,
Expand All @@ -152,7 +145,6 @@ describe('createSecurityToken procedure', () => {
tokenType,
tokenIdentifiers,
fundingRound,
treasury,
};
});

Expand Down Expand Up @@ -193,7 +185,6 @@ describe('createSecurityToken procedure', () => {
.withArgs(tokenIdentifiers[0].value, mockContext)
.returns(rawIdentifiers[0][1]);
stringToFundingRoundNameStub.withArgs(fundingRound, mockContext).returns(rawFundingRound);
stringToIdentityIdStub.withArgs(treasury, mockContext).returns(rawTreasury);
stringToDocumentNameStub
.withArgs(documents[0].name, mockContext)
.returns(rawDocumentTuples[0][0]);
Expand Down Expand Up @@ -255,16 +246,14 @@ describe('createSecurityToken procedure', () => {
rawIsDivisible,
rawType,
rawIdentifiers,
rawFundingRound,
rawTreasury
rawFundingRound
);
expect(result).toMatchObject(new SecurityToken({ ticker }, mockContext));

await prepareCreateSecurityToken.call(proc, {
...args,
tokenIdentifiers: undefined,
fundingRound: undefined,
treasury: undefined,
});

sinon.assert.calledWith(
Expand Down
10 changes: 5 additions & 5 deletions src/api/procedures/__tests__/issueTokens.ts
Expand Up @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js';
import { Ticker } from 'polymesh-types/types';
import sinon from 'sinon';

import { SecurityToken } from '~/api/entities';
import { Identity, SecurityToken } from '~/api/entities';
import { getRequiredRoles, Params, prepareIssueTokens } from '~/api/procedures/issueTokens';
import { Context } from '~/base';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
Expand Down Expand Up @@ -101,7 +101,6 @@ describe('issueTokens procedure', () => {
issuanceAmount: {
amount,
},

ticker,
};

Expand Down Expand Up @@ -134,18 +133,20 @@ describe('issueTokens procedure', () => {
});
});

test('should throw an error if canMint returns a status different from Success', async () => {
test('should throw an error if canMint returns a different status from Success', async () => {
const transferStatus = TransferStatus.Failure;
const args = {
issuanceAmount: {
amount,
},

ticker,
};

entityMockUtils.configureMocks({
securityTokenOptions: {
details: {
primaryIssuanceAgent: new Identity({ did: 'someDid' }, mockContext),
},
transfersCanMint: transferStatus,
},
});
Expand All @@ -171,7 +172,6 @@ describe('issueTokens procedure', () => {
issuanceAmount: {
amount,
},

ticker,
};

Expand Down
9 changes: 1 addition & 8 deletions src/api/procedures/createSecurityToken.ts
Expand Up @@ -5,7 +5,6 @@ import { SecurityToken, TickerReservation } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
import {
ErrorCode,
Identity,
Role,
RoleType,
TickerReservationStatus,
Expand All @@ -18,12 +17,10 @@ import {
batchArguments,
booleanToBool,
numberToBalance,
signerToString,
stringToAssetIdentifier,
stringToAssetName,
stringToDocumentName,
stringToFundingRoundName,
stringToIdentityId,
stringToTicker,
tokenDocumentDataToDocument,
tokenIdentifierTypeToIdentifierType,
Expand All @@ -37,7 +34,6 @@ export interface CreateSecurityTokenParams {
tokenType: TokenType;
tokenIdentifiers?: TokenIdentifier[];
fundingRound?: string;
treasury?: string | Identity;
documents?: TokenDocument[];
}

Expand Down Expand Up @@ -69,7 +65,6 @@ export async function prepareCreateSecurityToken(
tokenType,
tokenIdentifiers = [],
fundingRound,
treasury,
documents,
} = args;

Expand Down Expand Up @@ -105,7 +100,6 @@ export async function prepareCreateSecurityToken(
}
);
const rawFundingRound = fundingRound ? stringToFundingRoundName(fundingRound, context) : null;
const rawTreasury = treasury ? stringToIdentityId(signerToString(treasury), context) : null;

this.addTransaction(
tx.asset.createAsset,
Expand All @@ -116,8 +110,7 @@ export async function prepareCreateSecurityToken(
rawIsDivisible,
rawType,
rawIdentifiers,
rawFundingRound,
rawTreasury
rawFundingRound
);

if (documents) {
Expand Down
6 changes: 3 additions & 3 deletions src/api/procedures/issueTokens.ts
Expand Up @@ -34,7 +34,7 @@ export async function prepareIssueTokens(

const securityToken = new SecurityToken({ ticker }, context);

const { isDivisible, totalSupply, treasuryIdentity } = await securityToken.details();
const { isDivisible, totalSupply, primaryIssuanceAgent } = await securityToken.details();
const { amount } = issuanceAmount;

if (isDivisible) {
Expand Down Expand Up @@ -68,8 +68,8 @@ export async function prepareIssueTokens(

let canTransfer = TransferStatus.InvalidSenderIdentity;

if (treasuryIdentity) {
canTransfer = await securityToken.transfers.canMint({ to: treasuryIdentity, amount });
if (primaryIssuanceAgent) {
canTransfer = await securityToken.transfers.canMint({ to: primaryIssuanceAgent, amount });
}

if (canTransfer !== TransferStatus.Success) {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/types.ts
Expand Up @@ -779,7 +779,7 @@ export enum CallIdEnum {
AddExtension = 'add_extension',
ArchiveExtension = 'archive_extension',
UnarchiveExtension = 'unarchive_extension',
SetTreasuryDid = 'set_treasury_did',
SetPrimaryIssuanceagent = 'set_primary_issuance_agent',
New = 'new',
Cancel = 'cancel',
ClaimUnclaimed = 'claim_unclaimed',
Expand Down

0 comments on commit 8d19fdb

Please sign in to comment.