Skip to content

Commit

Permalink
Merge pull request #53 from PolymeshAssociation/feat/DA-833
Browse files Browse the repository at this point in the history
feat: update sdk and add CustomClaim example
  • Loading branch information
VictorVicente authored Jan 9, 2024
2 parents e459501 + 28e36cb commit 41f7646
Show file tree
Hide file tree
Showing 23 changed files with 4,869 additions and 5,849 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
}
],
"simple-import-sort/sort": "error",
"simple-import-sort/imports": "error",
"sort-imports": "off",
"import/order": "off"
},
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '16.x'
- name: install dependencies
run: yarn --frozen-lockfile
- name: lint
Expand All @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '16.x'
- name: install dependencies
run: yarn --frozen-lockfile
- name: test
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '18.x'
- name: install dependencies
run: yarn --frozen-lockfile
- name: build
Expand Down
87 changes: 34 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,48 @@
"semantic-release": "semantic-release",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"run-example": "npx [email protected] -r tsconfig-paths/register -r dotenv/config",
"format": "cross-env prettier-eslint $PWD\"/src/**/*.{ts,tsx,js,jsx,json,css,md}\" --write"
"format": "cross-env prettier-eslint $PWD\"/src/**/*.{ts,tsx,js,jsx,json,css,md}\" --write",
"prepare": "is-ci || husky install"
},
"devDependencies": {
"@commitlint/cli": "^7.6.1",
"@commitlint/config-conventional": "^7.6.0",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@ovos-media/ts-transform-paths": "^1.7.18-1",
"@semantic-release/git": "^8.0.0",
"@types/bluebird": "^3.5.33",
"@types/jest": "^23.3.10",
"@types/node": "^13.1.8",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"@zerollup/ts-transform-paths": "^1.7.11",
"cross-env": "^7.0.0",
"@types/bluebird": "^3.5.38",
"@types/jest": "29.5.4",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "6.5.0",
"@typescript-eslint/parser": "6.5.0",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-config-semistandard": "^15.0.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-simple-import-sort": "^5.0.1",
"eslint-plugin-standard": "^4.0.1",
"husky": "^4.1.0",
"jest": "^24.1.0",
"lint-staged": "^8.1.5",
"prettier": "^1.19.1",
"prettier-eslint": "^9.0.1",
"prettier-eslint-cli": "^5.0.0",
"semantic-release": "^17.2.3",
"ts-jest": "^24.3.0",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-semistandard": "17.0.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.0.2",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "8.0.3",
"is-ci": "3.0.1",
"jest": "29.6.4",
"lint-staged": "14.0.1",
"prettier": "2.8.8",
"prettier-eslint": "15.0.1",
"prettier-eslint-cli": "7.1.0",
"semantic-release": "^19.0.2",
"ts-jest": "^29.1.1",
"tsconfig-paths": "^3.9.0",
"ttypescript": "^1.5.12",
"typedoc": "^0.16.8",
"typescript": "4.4.4"
"ttypescript": "^1.5.15",
"typedoc": "^0.23.5",
"typescript": "4.6.2"
},
"dependencies": {
"@polymeshassociation/local-signing-manager": "2.1.0",
"@polymeshassociation/polymesh-sdk": "20.1.0",
"@polymeshassociation/local-signing-manager": "^3.1.0",
"@polymeshassociation/polymesh-sdk": "23.0.0",
"bluebird": "^3.7.2",
"dotenv": "^8.2.0"
},
"resolutions": {
"@polkadot/keyring": "10.4.2",
"@polkadot/util": "10.4.2",
"@polkadot/networks": "10.4.2",
"@polkadot/util-crypto": "10.4.2"
},
"overrides": {
"@polkadot/keyring": "10.4.2",
"@polkadot/util": "10.4.2",
"@polkadot/networks": "10.4.2",
"@polkadot/util-crypto": "10.4.2"
},
"pnpm": {
"overrides": {
"@polkadot/keyring": "10.4.2",
"@polkadot/util": "10.4.2",
"@polkadot/networks": "10.4.2",
"@polkadot/util-crypto": "10.4.2"
}
"dotenv": "^16.0.3"
},
"config": {
"commitizen": {
Expand Down
2 changes: 1 addition & 1 deletion src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getClient(mnemonic?: string): Promise<Polymesh> {
api = await Polymesh.connect({
/* eslint-disable @typescript-eslint/no-non-null-assertion */
nodeUrl: process.env.POLYMESH_NODE_URL!,
middleware: {
middlewareV2: {
link: process.env.MIDDLEWARE_LINK!,
key: process.env.MIDDLEWARE_KEY!,
/* eslint-enable @typescript-eslint/no-non-null-assertion */
Expand Down
33 changes: 33 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { ClaimData, FungibleLeg, Leg, NftLeg } from '@polymeshassociation/polymesh-sdk/types';
import { isEntity } from '@polymeshassociation/polymesh-sdk/utils';

/**
Expand Down Expand Up @@ -42,3 +43,35 @@ export function parseArgs<T>(args: string[]): T {

return parsedArgs as T;
}

/**
* @hidden
*/
export const renderClaim = (
{ target, issuer, issuedAt, expiry, claim }: ClaimData,
pos: number
): void => {
const issuedAtText = issuedAt ? `issued at ${issuedAt}` : '';
console.log(`Claim #${pos} ${issuedAtText}`);
console.log(`Target: ${target.did}`);
console.log(`Issuer: ${issuer.did}`);
if (expiry) {
console.log(`Expiry date: ${expiry}`);
}
console.log(`Claim: ${claim.type}`);
console.log('\n');
};

/**
* @hidden
*/
export const isFungibleLeg = (leg: Leg): leg is FungibleLeg => {
return (leg as FungibleLeg).amount !== undefined;
};

/**
* @hidden
*/
export const isNftLeg = (leg: Leg): leg is NftLeg => {
return (leg as NftLeg).nfts !== undefined;
};
9 changes: 5 additions & 4 deletions src/examples/assets/getHolders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { getClient } from '~/common/client';
import { parseArgs } from '~/common/utils';

type ScriptArgs = {
ticker?: string;
};

/*
This script showcases how get list of Asset holders.
Expand All @@ -21,7 +25,7 @@ import { parseArgs } from '~/common/utils';
const identity = (await api.getSigningIdentity())!;
console.log(`Connected! Signing Identity ID: ${identity.did}`);

const asset = await api.assets.getAsset({ ticker });
const asset = await api.assets.getFungibleAsset({ ticker });

console.log(`Preparing to list token holders for ${ticker}`);

Expand All @@ -38,6 +42,3 @@ import { parseArgs } from '~/common/utils';
await api.disconnect();
})();

type ScriptArgs = {
ticker?: string;
};
12 changes: 6 additions & 6 deletions src/examples/assets/issueTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { getClient } from '~/common/client';
import { parseArgs } from '~/common/utils';

type ScriptArgs = {
amount?: number;
ticker?: string;
};

/*
This script showcases how to issue tokens for an Asset.
Expand All @@ -27,7 +32,7 @@ import { parseArgs } from '~/common/utils';
const identity = (await api.getSigningIdentity())!;
console.log(`Connected! Signing Identity ID: ${identity.did}`);

const asset = await api.assets.getAsset({ ticker });
const asset = await api.assets.getFungibleAsset({ ticker });

console.log(`Preparing to issue ${amount} of tokens for ${ticker}`);

Expand All @@ -42,8 +47,3 @@ import { parseArgs } from '~/common/utils';

await api.disconnect();
})();

type ScriptArgs = {
amount?: number;
ticker?: string;
};
12 changes: 6 additions & 6 deletions src/examples/assets/redeemTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { getClient } from '~/common/client';
import { parseArgs } from '~/common/utils';

type ScriptArgs = {
amount?: number;
ticker?: string;
};

/*
This script showcases how to redeem tokens for an Asset.
Expand All @@ -27,7 +32,7 @@ import { parseArgs } from '~/common/utils';
const identity = (await api.getSigningIdentity())!;
console.log(`Connected! Signing Identity ID: ${identity.did}`);

const asset = await api.assets.getAsset({ ticker });
const asset = await api.assets.getFungibleAsset({ ticker });

console.log(`Preparing to redeem ${amount} of tokens for ${ticker}`);

Expand All @@ -42,8 +47,3 @@ import { parseArgs } from '~/common/utils';

await api.disconnect();
})();

type ScriptArgs = {
amount?: number;
ticker?: string;
};
12 changes: 8 additions & 4 deletions src/examples/batchTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { Asset, KnownAssetType } from '@polymeshassociation/polymesh-sdk/types';
import { isAsset, isPolymeshTransactionBatch } from '@polymeshassociation/polymesh-sdk/utils';
import { FungibleAsset } from '@polymeshassociation/polymesh-sdk/internal';
import { KnownAssetType } from '@polymeshassociation/polymesh-sdk/types';
import {
isFungibleAsset,
isPolymeshTransactionBatch,
} from '@polymeshassociation/polymesh-sdk/utils';
import P from 'bluebird';

import { getClient } from '~/common/client';
Expand Down Expand Up @@ -62,15 +66,15 @@ import { getClient } from '~/common/client';
assetType: KnownAssetType.EquityCommon,
});

if (isPolymeshTransactionBatch<Asset>(batchTx3)) {
if (isPolymeshTransactionBatch<FungibleAsset>(batchTx3)) {
const transactions = batchTx3.splitTransactions();

// Transactions MUST be run in strict order, waiting for one to finalize before running the next.
await P.mapSeries(transactions, async tx => {
const result = await tx.run();

// The original result of the batch is returned only by the last transaction in the split array
if (isAsset(result)) {
if (result && isFungibleAsset(result)) {
console.log(`Asset with ticker ${result.ticker} created`);
}
});
Expand Down
13 changes: 3 additions & 10 deletions src/examples/checkpoints.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { CalendarUnit } from '@polymeshassociation/polymesh-sdk/types';

import { getClient } from '~/common/client';

/*
Expand Down Expand Up @@ -28,7 +25,7 @@ import { getClient } from '~/common/client';
throw new Error('Please supply a ticker as an argument to the script');
}

const asset = await api.assets.getAsset({ ticker });
const asset = await api.assets.getFungibleAsset({ ticker });
console.log(`Asset found! Current asset name is: ${(await asset.details()).name}`);

const createQ = await asset.checkpoints.create();
Expand Down Expand Up @@ -59,17 +56,13 @@ import { getClient } from '~/common/client';
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const createScheduleQ = await asset.checkpoints.schedules.create({
start: tomorrow,
period: { unit: CalendarUnit.Week, amount: new BigNumber(1) },
repetitions: new BigNumber(5),
points: [tomorrow],
});
const newSchedule = await createScheduleQ.run();
console.log('New schedule has been created:');

console.log('New schedule has been created:');
console.log(`- Id: ${newSchedule.id}`);
console.log(`- Ticker: ${newSchedule.asset.ticker}`);
console.log(`- Start: ${newSchedule.start}`);
console.log(`- Period: ${newSchedule.period}`);
console.log(`- Expiry date: ${newSchedule.expiryDate}`);

const { nextCheckpointDate, remainingCheckpoints } = await newSchedule.details();
Expand Down
25 changes: 2 additions & 23 deletions src/examples/claims.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
import { ClaimData, ClaimType, ScopeType } from '@polymeshassociation/polymesh-sdk/types';
import { ClaimType, ScopeType } from '@polymeshassociation/polymesh-sdk/types';

import { getClient } from '~/common/client';

/**
* @hidden
*/
const renderClaim = ({ target, issuer, issuedAt, expiry, claim }: ClaimData, pos: number): void => {
console.log(`Claim #${pos} ${issuedAt ? `issued at ${issuedAt}` : ``}`);
console.log(`Target: ${target.did}`);
console.log(`Issuer: ${issuer.did}`);
if (expiry) {
console.log(`Expiry date: ${expiry}`);
}
console.log(`Claim: ${claim.type}`);
console.log('\n');
};
import { renderClaim } from '~/common/utils';

/*
This script showcases Claim related functionality. It:
- Add a claim
- Revoke a claim
- Get CDD claims
- Get uniqueness investor claims
- Get claims targeting a given Identity
- Get claims issued by given Identity
*/
Expand Down Expand Up @@ -81,13 +67,6 @@ const renderClaim = ({ target, issuer, issuedAt, expiry, claim }: ClaimData, pos
renderClaim(claim, i + 1);
});

const investorUniquenessClaims = await api.claims.getInvestorUniquenessClaims();

console.log('List of InvestorUniqueness claims for the signing Identity:\n');
investorUniquenessClaims.forEach((claim, i) => {
renderClaim(claim, i + 1);
});

const targetingClaims = await api.claims.getTargetingClaims({ target: bobDid });

console.log(`List of claims targeting to ${bobDid}\n`);
Expand Down
Loading

0 comments on commit 41f7646

Please sign in to comment.