Skip to content

Commit

Permalink
feat: 🎸 Add support for latest SQ
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantasdeveloper authored and polymath-eric committed Aug 30, 2024
1 parent 2975bc5 commit 752fe88
Show file tree
Hide file tree
Showing 35 changed files with 4,732 additions and 980 deletions.
4 changes: 2 additions & 2 deletions src/api/client/Claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class Claims {
let targetIssuers;

const filters = {
scope: scope ? scopeToMiddlewareScope(scope, false) : undefined,
scope: scope ? await scopeToMiddlewareScope(scope, context) : undefined,
trustedClaimIssuers: trustedClaimIssuers?.map(trustedClaimIssuer =>
signerToString(trustedClaimIssuer)
),
Expand Down Expand Up @@ -443,7 +443,7 @@ export class Claims {
if (isMiddlewareAvailable) {
const filters = {
dids: [did],
scope: scope ? scopeToMiddlewareScope(scope, false) : undefined,
scope: scope ? await scopeToMiddlewareScope(scope, context) : undefined,
includeExpired,
};

Expand Down
3 changes: 3 additions & 0 deletions src/api/client/__tests__/Claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ describe('Claims Class', () => {
const targetDid = 'someTargetDid';
const issuerDid = 'someIssuerDid';
const scope: Scope = { type: ScopeType.Ticker, value: 'someValue' };
jest
.spyOn(utilsConversionModule, 'scopeToMiddlewareScope')
.mockResolvedValue({ type: 'Ticker', value: 'someValue' });
const date = 1589816265000;
const accreditedType = ClaimTypeEnum.Accredited;
const claimData = {
Expand Down
20 changes: 16 additions & 4 deletions src/api/entities/Asset/Fungible/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import {
stringToTicker,
tickerToDid,
} from '~/utils/conversion';
import { calculateNextKey, createProcedureMethod, optionize } from '~/utils/internal';
import {
calculateNextKey,
createProcedureMethod,
getAssetIdForMiddleware,
getAssetIdFromMiddleware,
optionize,
} from '~/utils/internal';

import { FungibleSettlements } from '../Base/Settlements';
import { UniqueIdentifiers } from '../types';
Expand Down Expand Up @@ -147,13 +153,15 @@ export class FungibleAsset extends BaseAsset {
public async getOperationHistory(): Promise<HistoricAgentOperation[]> {
const { context, ticker: assetId } = this;

const middlewareAssetId = await getAssetIdForMiddleware(assetId, context);

const {
data: {
tickerExternalAgentHistories: { nodes },
},
} = await context.queryMiddleware<Ensured<Query, 'tickerExternalAgentHistories'>>(
tickerExternalAgentHistoryQuery({
assetId,
assetId: middlewareAssetId,
})
);

Expand All @@ -180,14 +188,16 @@ export class FungibleAsset extends BaseAsset {
const { context, ticker } = this;
const { size, start } = opts;

const middlewareAssetId = await getAssetIdForMiddleware(ticker, context);

const {
data: {
assetTransactions: { nodes, totalCount },
},
} = await context.queryMiddleware<Ensured<Query, 'assetTransactions'>>(
assetTransactionQuery(
{
assetId: ticker,
assetId: middlewareAssetId,
},
size,
start
Expand All @@ -196,7 +206,7 @@ export class FungibleAsset extends BaseAsset {

const data: HistoricAssetTransaction[] = nodes.map(
({
assetId,
asset,
amount,
fromPortfolioId,
toPortfolioId,
Expand All @@ -211,6 +221,8 @@ export class FungibleAsset extends BaseAsset {
const fromPortfolio = optionize(portfolioIdStringToPortfolio)(fromPortfolioId);
const toPortfolio = optionize(portfolioIdStringToPortfolio)(toPortfolioId);

const assetId = getAssetIdFromMiddleware(asset);

return {
asset: new FungibleAsset({ ticker: assetId }, context),
amount: new BigNumber(amount).shiftedBy(-6),
Expand Down
6 changes: 4 additions & 2 deletions src/api/entities/Asset/NonFungible/AssetHolders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { nftCollectionHolders } from '~/middleware/queries/assets';
import { Query } from '~/middleware/types';
import { IdentityHeldNfts, NftCollection, ResultSet } from '~/types';
import { Ensured } from '~/types/utils';
import { calculateNextKey } from '~/utils/internal';
import { calculateNextKey, getAssetIdForMiddleware } from '~/utils/internal';

/**
* Handles all NFT Holders related functionality
Expand All @@ -27,12 +27,14 @@ export class AssetHolders extends Namespace<NftCollection> {

const { size, start } = opts;

const middlewareAssetId = await getAssetIdForMiddleware(ticker, context);

const {
data: {
nftHolders: { totalCount, nodes },
},
} = await context.queryMiddleware<Ensured<Query, 'nftHolders'>>(
nftCollectionHolders(ticker, size, start)
nftCollectionHolders(middlewareAssetId, size, start)
);

const data = nodes.map(({ nftIds, identityId }) => ({
Expand Down
14 changes: 11 additions & 3 deletions src/api/entities/Asset/NonFungible/NftCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ import {
stringToTicker,
u64ToBigNumber,
} from '~/utils/conversion';
import { calculateNextKey, createProcedureMethod, optionize } from '~/utils/internal';
import {
calculateNextKey,
createProcedureMethod,
getAssetIdFromMiddleware,
optionize,
} from '~/utils/internal';

const sumNftIssuance = (
numberOfNfts: [StorageKey<[PolymeshPrimitivesTicker, PolymeshPrimitivesIdentityId]>, u64][]
Expand Down Expand Up @@ -336,7 +341,7 @@ export class NftCollection extends BaseAsset {

const data: HistoricNftTransaction[] = nodes.map(
({
assetId,
asset,
nftIds,
fromPortfolioId,
toPortfolioId,
Expand All @@ -351,8 +356,11 @@ export class NftCollection extends BaseAsset {
const fromPortfolio = optionize(portfolioIdStringToPortfolio)(fromPortfolioId);
const toPortfolio = optionize(portfolioIdStringToPortfolio)(toPortfolioId);

const assetId = getAssetIdFromMiddleware(asset);
const collection = new NftCollection({ ticker: assetId }, context);

return {
asset: new NftCollection({ ticker: assetId }, context),
asset: collection,
nfts: nftIds.map(
(id: string) => new Nft({ ticker: assetId, id: new BigNumber(id) }, context)
),
Expand Down
21 changes: 17 additions & 4 deletions src/api/entities/Asset/__tests__/Fungible/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mo
import { ErrorCode, SecurityIdentifier, SecurityIdentifierType } from '~/types';
import { tuple } from '~/types/utils';
import * as utilsConversionModule from '~/utils/conversion';
import * as utilsInternalModule from '~/utils/internal';

jest.mock(
'~/api/entities/Identity',
Expand All @@ -34,7 +35,7 @@ jest.mock(
require('~/testUtils/mocks/procedure').mockProcedureModule('~/base/Procedure')
);

describe('Asset class', () => {
describe('Fungible class', () => {
let bytesToStringSpy: jest.SpyInstance;
beforeAll(() => {
dsMockUtils.initMocks();
Expand Down Expand Up @@ -709,6 +710,7 @@ describe('Asset class', () => {
describe('method: getOperationHistory', () => {
it('should return a list of agent operations', async () => {
const ticker = 'TICKER';
jest.spyOn(utilsInternalModule, 'getAssetIdForMiddleware').mockResolvedValue(ticker);
const context = dsMockUtils.getContextInstance();
const asset = new FungibleAsset({ ticker }, context);

Expand Down Expand Up @@ -771,13 +773,18 @@ describe('Asset class', () => {
describe('method: getTransactionHistory', () => {
it('should return the list of asset transactions', async () => {
const ticker = 'TICKER';
const assetId = '0x1234';
const context = dsMockUtils.getContextInstance();
jest.spyOn(utilsInternalModule, 'getAssetIdForMiddleware').mockResolvedValue(ticker);
const asset = new FungibleAsset({ ticker }, context);
const transactionResponse = {
totalCount: new BigNumber(5),
nodes: [
{
assetId: ticker,
asset: {
id: assetId,
ticker,
},
amount: new BigNumber(100).shiftedBy(6),
eventId: EventIdEnum.Issued,
toPortfolioId: 'SOME_DID/0',
Expand All @@ -791,7 +798,10 @@ describe('Asset class', () => {
},
},
{
assetId: ticker,
asset: {
id: assetId,
ticker,
},
amount: new BigNumber(1).shiftedBy(6),
eventId: EventIdEnum.Redeemed,
fromPortfolioId: 'SOME_DID/0',
Expand All @@ -805,7 +815,10 @@ describe('Asset class', () => {
},
},
{
assetId: ticker,
asset: {
id: assetId,
ticker,
},
amount: new BigNumber(10).shiftedBy(6),
eventId: EventIdEnum.Transfer,
fromPortfolioId: 'SOME_DID/0',
Expand Down
2 changes: 2 additions & 0 deletions src/api/entities/Asset/__tests__/NonFungible/AssetHolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Context, Namespace } from '~/internal';
import { nftCollectionHolders } from '~/middleware/queries/assets';
import { dsMockUtils, entityMockUtils } from '~/testUtils/mocks';
import { NftCollection } from '~/types';
import * as utilsInternalModule from '~/utils/internal';

jest.mock(
'~/api/entities/Asset/NonFungible',
Expand Down Expand Up @@ -47,6 +48,7 @@ describe('AssetHolder class', () => {
beforeEach(() => {
context = dsMockUtils.getContextInstance();
collection = entityMockUtils.getNftCollectionInstance({ ticker });
jest.spyOn(utilsInternalModule, 'getAssetIdForMiddleware').mockResolvedValue(ticker);
assetHolders = new AssetHolders(collection, context);

const nftHoldersResponse = {
Expand Down
13 changes: 11 additions & 2 deletions src/api/entities/Asset/__tests__/NonFungible/NftCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '~/types';
import { tuple } from '~/types/utils';
import * as utilsConversionModule from '~/utils/conversion';
import * as utilsInternalModule from '~/utils/internal';

jest.mock(
'~/api/entities/Identity',
Expand Down Expand Up @@ -570,12 +571,17 @@ describe('NftCollection class', () => {
it('should return the list of the collection transactions', async () => {
const ticker = 'TICKER';
const context = dsMockUtils.getContextInstance();
jest.spyOn(utilsInternalModule, 'getAssetIdForMiddleware').mockResolvedValue(ticker);
const asset = new NftCollection({ ticker }, context);
const assetId = '0x1234';
const transactionResponse = {
totalCount: new BigNumber(5),
nodes: [
{
assetId: ticker,
asset: {
id: assetId,
ticker,
},
nftIds: ['1'],
eventId: EventIdEnum.Issued,
toPortfolioId: 'SOME_DID/0',
Expand All @@ -589,7 +595,10 @@ describe('NftCollection class', () => {
},
},
{
assetId: ticker,
asset: {
id: assetId,
ticker,
},
nftIds: ['1'],
eventId: EventIdEnum.Transfer,
toPortfolioId: 'OTHER_DID/0',
Expand Down
5 changes: 3 additions & 2 deletions src/api/entities/DefaultTrustedClaimIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
stringToTicker,
trustedIssuerToTrustedClaimIssuer,
} from '~/utils/conversion';
import { optionize } from '~/utils/internal';
import { getAssetIdForMiddleware, optionize } from '~/utils/internal';

export interface UniqueIdentifiers {
did: string;
Expand Down Expand Up @@ -58,6 +58,7 @@ export class DefaultTrustedClaimIssuer extends Identity {
context,
} = this;

const middlewareAssetId = await getAssetIdForMiddleware(assetId, context);
const {
data: {
trustedClaimIssuers: {
Expand All @@ -66,7 +67,7 @@ export class DefaultTrustedClaimIssuer extends Identity {
},
} = await context.queryMiddleware<Ensured<Query, 'trustedClaimIssuers'>>(
trustedClaimIssuerQuery({
assetId,
assetId: middlewareAssetId,
issuer,
})
);
Expand Down
9 changes: 9 additions & 0 deletions src/api/entities/DividendDistribution/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '~/types';
import { MAX_DECIMALS } from '~/utils/constants';
import * as utilsConversionModule from '~/utils/conversion';
import * as utilsInternalModule from '~/utils/internal';

jest.mock(
'~/api/entities/Identity',
Expand Down Expand Up @@ -276,6 +277,10 @@ describe('DividendDistribution class', () => {
});

describe('method: getWithheldTax', () => {
beforeEach(() => {
jest.spyOn(utilsInternalModule, 'getAssetIdForMiddleware').mockResolvedValue(ticker);
});

it('should return the amount of the withheld tax', async () => {
const fakeTax = new BigNumber(1000000);

Expand Down Expand Up @@ -547,6 +552,10 @@ describe('DividendDistribution class', () => {
});

describe('method: getPaymentHistory', () => {
beforeEach(() => {
jest.spyOn(utilsInternalModule, 'getAssetIdForMiddleware').mockResolvedValue(ticker);
});

it('should return the amount of the withheld tax', async () => {
const blockId = new BigNumber(1);
const blockHash = 'someHash';
Expand Down
9 changes: 7 additions & 2 deletions src/api/entities/DividendDistribution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
import {
calculateNextKey,
createProcedureMethod,
getAssetIdForMiddleware,
getIdentity,
toHumanReadable,
xor,
Expand Down Expand Up @@ -449,9 +450,11 @@ export class DividendDistribution extends CorporateActionBase {
context,
} = this;

const middlewareAssetId = await getAssetIdForMiddleware(ticker, context);

const taxPromise = context.queryMiddleware<Ensured<Query, 'distributions'>>(
distributionQuery({
assetId: ticker,
assetId: middlewareAssetId,
localId: id.toNumber(),
})
);
Expand Down Expand Up @@ -491,10 +494,12 @@ export class DividendDistribution extends CorporateActionBase {
} = this;
const { size, start } = opts;

const middlewareAssetId = await getAssetIdForMiddleware(ticker, context);

const paymentsPromise = context.queryMiddleware<Ensured<Query, 'distributionPayments'>>(
distributionPaymentsQuery(
{
distributionId: `${ticker}/${id.toString()}`,
distributionId: `${middlewareAssetId}/${id.toString()}`,
},
size,
start
Expand Down
Loading

0 comments on commit 752fe88

Please sign in to comment.