Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/src/__tests__/rest/checkpoints/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Checkpoints Controller', () => {
},
{
name: 'Test Checkpoint Asset',
initialSupply: '1000000', // 1M tokens
initialSupply: '100', // 1M tokens
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
initialSupply: '100', // 1M tokens
initialSupply: '100',

}
);

Expand Down
86 changes: 86 additions & 0 deletions tests/src/__tests__/rest/corporate-actions/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { TargetTreatment } from '@polymeshassociation/polymesh-sdk/types';
import { TestFactory } from '~/helpers';
import { RestClient } from '~/rest';
import { createAssetParams } from '~/rest/assets/params';
import { ProcessMode } from '~/rest/common';
import { Identity } from '~/rest/identities/interfaces';

const handles = ['issuer', 'recipient'];
let factory: TestFactory;

describe('Corporate Actions', () => {
let restClient: RestClient;
let signer: string;
let issuer: Identity;
let assetParams: ReturnType<typeof createAssetParams>;
let assetId: string;

beforeAll(async () => {
factory = await TestFactory.create({ handles });
({ restClient } = factory);
issuer = factory.getSignerIdentity(handles[0]);

signer = issuer.signer;

assetParams = createAssetParams({
options: { processMode: ProcessMode.Submit, signer },
});
});

afterAll(async () => {
await factory.close();
});

it('should create and fetch the Asset', async () => {
assetId = await restClient.assets.createAndGetAssetId(assetParams);

const asset = await restClient.assets.getAsset(assetId);

expect(asset).toMatchObject({
name: assetParams.name,
assetType: assetParams.assetType,
});

await restClient.compliance.pauseRequirements(assetId, {
options: { processMode: ProcessMode.Submit, signer },
});
});

it('should get the corporate actions default config', async () => {
const result = await restClient.corporateActions.getCorporateActionsDefaultConfig(assetId);

expect(result).toEqual(
expect.objectContaining({
targets: {
identities: [],
treatment: TargetTreatment.Exclude,
},
defaultTaxWithholding: '0',
taxWithholdings: [],
})
);
});

it('should modify the corporate actions default config', async () => {
await restClient.corporateActions.modifyCorporateActionsDefaultConfig(assetId, {
options: { processMode: ProcessMode.Submit, signer },
defaultTaxWithholding: new BigNumber(100),
targets: undefined,
taxWithholdings: undefined,
});

const result = await restClient.corporateActions.getCorporateActionsDefaultConfig(assetId);

expect(result).toEqual(
expect.objectContaining({
targets: {
identities: [],
treatment: TargetTreatment.Exclude,
},
defaultTaxWithholding: '100',
taxWithholdings: [],
})
);
});
});
43 changes: 42 additions & 1 deletion tests/src/rest/corporate-actions/client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { BigNumber } from '@polymeshassociation/polymesh-sdk';

import { RestClient } from '~/rest/client';
import { TxBase } from '~/rest/common';
import { PostResult, RestSuccessResult, ResultSet } from '~/rest/interfaces';

import { setAssetDocumentParams } from '../assets';
import {
claimDividendDistributionParams,
corporateActionDefaultConfigParams,
CorporateActionTargets,
CorporateActionTaxWithHoldings,
createDividendDistributionParams,
payDividendDistributionParams,
reclaimDividendDistributionParams,
} from './params';

export class CorporateActions {
constructor(private client: RestClient) {}
constructor(private readonly client: RestClient) {}

// NOTE: Only endpoints verified against docs should live here

Expand Down Expand Up @@ -92,4 +99,38 @@ export class CorporateActions {
`/assets/${asset}/corporate-actions/dividend-distributions/${id}/payment-history`
);
}

public async getCorporateActionsDefaultConfig(
ticker: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<{
targets: CorporateActionTargets;
defaultTaxWithholding: string;
taxWithholdings: CorporateActionTaxWithHoldings[];
}> {
return this.client.get(`/assets/${ticker}/corporate-actions/default-config`);
}

public async modifyCorporateActionsDefaultConfig(
ticker: string,
params: ReturnType<typeof corporateActionDefaultConfigParams>
): Promise<PostResult> {
return this.client.post(`/assets/${ticker}/corporate-actions/default-config/modify`, params);
}

public async deleteCorporateActions(
ticker: string,
id: BigNumber,
txBase: TxBase
): Promise<PostResult> {
return this.client.post(`/assets/${ticker}/corporate-actions/${id}/delete`, { ...txBase });
}

public async linkDocuments(
asset: string,
id: BigNumber,
params: ReturnType<typeof setAssetDocumentParams>
): Promise<PostResult> {
return this.client.post(`assets/${asset}/corporate-actions/${id}/documents/link`, params);
}
}
25 changes: 25 additions & 0 deletions tests/src/rest/corporate-actions/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ export const modifyDistributionCheckpointParams = (
...base,
checkpoint,
} as const);

export type CorporateActionTargets = {
identities: string[];
treatment: TargetTreatment;
};

export type CorporateActionTaxWithHoldings = {
identity: string;
percentage: BigNumber;
};

export const corporateActionDefaultConfigParams = (
base: TxBase,
defaultTaxWithholding?: BigNumber | undefined,
targets?: CorporateActionTargets | undefined,
taxWithholdings?: CorporateActionTaxWithHoldings[] | undefined,
extras: TxExtras = {}
) =>
({
targets,
defaultTaxWithholding,
taxWithholdings,
...extras,
...base,
} as const);