Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new events for 7.x chain and some other fixes #259

Merged
merged 7 commits into from
Oct 17, 2024
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polymesh-subquery",
"version": "16.0.1",
"version": "16.1.0",
"author": "Polymesh Association",
"license": "Apache-2.0",
"description": "A Polymesh Chain Indexer, providing a GraphQL interface",
Expand Down Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"@polkadot/api": "^11.2.1",
"@polkadot/types-support": "^11.2.1",
"@polymeshassociation/polymesh-types": "^5.9.0",
"@polymeshassociation/polymesh-types": "^5.14.0",
"@subql/cli": "4.14.0",
"@subql/types": "3.6.1",
"@subql/types-core": "^0.7.0",
Expand Down
1 change: 1 addition & 0 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const filters = {
AssetMediatorsAdded: ['handleAssetMediatorsAdded'],
AssetMediatorsRemoved: ['handleAssetMediatorsRemoved'],
TickerLinkedToAsset: ['handleTickerLinkedToAsset'],
TickerUnlinkedFromAsset: ['handleTickerUnlinkedFromAsset'],
},
balances: {
AccountBalanceBurned: ['handleBalanceBurned'],
Expand Down
3 changes: 3 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ enum EventIdEnum {
AssetMediatorsAdded
SetAssetMediators # This can be removed, `AssetMediatorsAdded` is emitted instead
AssetMediatorsRemoved
TickerUnlinkedFromAsset

## capitaldistribution ##
Created
Expand Down Expand Up @@ -869,6 +870,7 @@ enum CallIdEnum {
join_identity
reject
remove_admin_via_admin
remove_admin
remove_multisig_signers_via_admin
remove_multisig_signers
remove_payer
Expand Down Expand Up @@ -1027,6 +1029,7 @@ enum CallIdEnum {
add_mandatory_mediators
remove_mandatory_mediators
link_ticker_to_asset_id
unlink_ticker_from_asset_id

## capitaldistribution ##
distribute
Expand Down
53 changes: 34 additions & 19 deletions src/mappings/entities/assets/mapAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const handleAssetCreated = async (event: SubstrateEvent): Promise<void> =
}

await Asset.create({
id: getAssetId(rawAssetId, block),
id: await getAssetId(rawAssetId, block),
ticker,
name,
type: assetType,
Expand All @@ -212,7 +212,7 @@ export const handleAssetRenamed = async (event: SubstrateEvent): Promise<void> =
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId, rawName] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.name = bytesToString(rawName);
Expand All @@ -225,7 +225,7 @@ export const handleFundingRoundSet = async (event: SubstrateEvent): Promise<void
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId, rawFundingRound] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);

Expand All @@ -239,7 +239,7 @@ export const handleDocumentAdded = async (event: SubstrateEvent): Promise<void>
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId, rawDocId, rawDoc] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const documentId = getNumberValue(rawDocId);
const docDetails = getDocValue(rawDoc);

Expand All @@ -259,7 +259,7 @@ export const handleDocumentRemoved = async (event: SubstrateEvent): Promise<void
const { params, block } = extractArgs(event);
const [, rawAssetId, rawDocId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const documentId = getNumberValue(rawDocId);

await AssetDocument.remove(`${assetId}/${documentId}`);
Expand All @@ -269,7 +269,7 @@ export const handleIdentifiersUpdated = async (event: SubstrateEvent): Promise<v
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId, rawIdentifiers] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.identifiers = getSecurityIdentifiers(rawIdentifiers);
Expand All @@ -282,7 +282,7 @@ export const handleDivisibilityChanged = async (event: SubstrateEvent): Promise<
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.isDivisible = true;
Expand All @@ -297,7 +297,7 @@ export const handleIssued = async (event: SubstrateEvent): Promise<void> => {
params;

const issuerDid = getTextValue(rawBeneficiaryDid);
const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const issuedAmount = getBigIntValue(rawAmount);
const fundingRound = bytesToString(rawFundingRound);
const totalFundingAmount = getBigIntValue(rawTotalFundingAmount);
Expand Down Expand Up @@ -347,7 +347,7 @@ export const handleRedeemed = async (event: SubstrateEvent): Promise<void> => {
const [, rawAssetId, rawBeneficiaryDid, rawAmount] = params;

const issuerDid = getTextValue(rawBeneficiaryDid);
const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const issuedAmount = getBigIntValue(rawAmount);

const asset = await getAsset(assetId);
Expand All @@ -367,7 +367,7 @@ export const handleFrozen = async (event: SubstrateEvent): Promise<void> => {
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.isFrozen = true;
Expand All @@ -380,7 +380,7 @@ export const handleUnfrozen = async (event: SubstrateEvent): Promise<void> => {
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.isFrozen = false;
Expand All @@ -394,7 +394,7 @@ export const handleAssetOwnershipTransferred = async (event: SubstrateEvent): Pr

const [to, rawAssetId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.ownerId = getTextValue(to);
Expand All @@ -408,7 +408,7 @@ export const handleAssetTransfer = async (event: SubstrateEvent): Promise<void>
const [, rawAssetId, rawFromPortfolio, rawToPortfolio, rawAmount] = params;
const { identityId: fromDid, number: fromPortfolioNumber } = getPortfolioValue(rawFromPortfolio);
const { identityId: toDid, number: toPortfolioNumber } = getPortfolioValue(rawToPortfolio);
const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const transferAmount = getBigIntValue(rawAmount);

let fromPortfolioId = `${fromDid}/${fromPortfolioNumber}`;
Expand Down Expand Up @@ -483,7 +483,7 @@ export const handleAssetBalanceUpdated = async (event: SubstrateEvent): Promise<

let fromPortfolioNumber: number, toPortfolioNumber: number;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const asset = await getAsset(assetId);

let fromPortfolioId: string;
Expand Down Expand Up @@ -593,7 +593,7 @@ export const handleAssetBalanceUpdated = async (event: SubstrateEvent): Promise<
export const handleAssetMediatorsAdded = async (event: SubstrateEvent): Promise<void> => {
const { params, blockId, block } = extractArgs(event);
const addedById = getTextValue(params[0]);
const assetId = getAssetId(params[1], block);
const assetId = await getAssetId(params[1], block);
const mediators = getStringArrayValue(params[2]);

const createPromises = mediators.map(mediator =>
Expand All @@ -612,7 +612,7 @@ export const handleAssetMediatorsAdded = async (event: SubstrateEvent): Promise<

export const handleAssetMediatorsRemoved = async (event: SubstrateEvent): Promise<void> => {
const { params, block } = extractArgs(event);
const assetId = getAssetId(params[1], block);
const assetId = await getAssetId(params[1], block);
const mediators = getStringArrayValue(params[2]);

await Promise.all(
Expand All @@ -623,7 +623,7 @@ export const handleAssetMediatorsRemoved = async (event: SubstrateEvent): Promis
export const handlePreApprovedAsset = async (event: SubstrateEvent): Promise<void> => {
const { params, blockId, block } = extractArgs(event);
const identityId = getTextValue(params[0]);
const assetId = getAssetId(params[1], block);
const assetId = await getAssetId(params[1], block);

await AssetPreApproval.create({
id: `${assetId}/${identityId}`,
Expand All @@ -638,7 +638,7 @@ export const handleRemovePreApprovedAsset = async (event: SubstrateEvent): Promi
const { params, block } = extractArgs(event);

const identityId = getTextValue(params[0]);
const assetId = getAssetId(params[1], block);
const assetId = await getAssetId(params[1], block);

await AssetPreApproval.remove(`${assetId}/${identityId}`);
};
Expand All @@ -648,11 +648,26 @@ export const handleTickerLinkedToAsset = async (event: SubstrateEvent): Promise<

const [, rawTicker, rawAssetId] = params;
const ticker = serializeTicker(rawTicker);
const assetId = rawAssetId.toString();
const assetId = getTextValue(rawAssetId);
const asset = await getAsset(assetId);

asset.ticker = ticker;
asset.updatedBlockId = blockId;

await asset.save();
};

export const handleTickerUnlinkedFromAsset = async (event: SubstrateEvent): Promise<void> => {
const { params, blockId } = extractArgs(event);

const [, rawTicker, rawAssetId] = params;
const ticker = serializeTicker(rawTicker);
const assetId = getTextValue(rawAssetId);
const asset = await getAsset(assetId);

if (asset.ticker === ticker) {
asset.ticker = undefined;
asset.updatedBlockId = blockId;
await asset.save();
}
};
16 changes: 8 additions & 8 deletions src/mappings/entities/assets/mapCompliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const handleAssetCompliancePaused = async (event: SubstrateEvent): Promis
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.isCompliancePaused = true;
Expand All @@ -27,7 +27,7 @@ export const handleAssetComplianceResumed = async (event: SubstrateEvent): Promi
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const asset = await getAsset(assetId);
asset.isCompliancePaused = false;
Expand All @@ -40,7 +40,7 @@ export const handleComplianceReset = async (event: SubstrateEvent): Promise<void
const { params, block } = extractArgs(event);
const [, rawAssetId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const complianceRequirements = await Compliance.getByAssetId(assetId);

Expand All @@ -61,7 +61,7 @@ export const handleComplianceCreated = async (event: SubstrateEvent): Promise<vo
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId, rawCompliance] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const { complianceId, data } = getComplianceValue(rawCompliance);

await createCompliance(assetId, complianceId, data, blockId);
Expand All @@ -71,7 +71,7 @@ export const handleComplianceReplaced = async (event: SubstrateEvent): Promise<v
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId, rawCompliances] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);

const existingCompliances = await Compliance.getByAssetId(assetId);

Expand All @@ -89,7 +89,7 @@ export const handleComplianceRemoved = async (event: SubstrateEvent): Promise<vo
const { params, block } = extractArgs(event);
const [, rawAssetId, rawId] = params;

const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const complianceId = getNumberValue(rawId);

await Compliance.remove(`${assetId}/${complianceId}`);
Expand All @@ -101,7 +101,7 @@ export const handleTrustedDefaultClaimIssuerAdded = async (
const { params, eventIdx, blockId, block } = extractArgs(event);

const [, rawAssetId, rawIssuer] = params;
const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const issuer = (rawIssuer as unknown as { issuer: Codec }).issuer.toString();

await TrustedClaimIssuer.create({
Expand All @@ -120,7 +120,7 @@ export const handleTrustedDefaultClaimIssuerRemoved = async (
const { params, block } = extractArgs(event);

const [, rawAssetId, rawIdentity] = params;
const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const issuer = getTextValue(rawIdentity);
await TrustedClaimIssuer.remove(`${assetId}/${issuer}`);
};
8 changes: 4 additions & 4 deletions src/mappings/entities/assets/mapCorporateActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const handleDistributionCreated = async (event: SubstrateEvent): Promise<
const { params, blockId, block } = extractArgs(event);
const [rawDid, rawCaId, rawDistribution] = params;

const { localId, assetId } = getCaIdValue(rawCaId, block);
const { localId, assetId } = await getCaIdValue(rawCaId, block);
const distributionDetails = getDistributionValue(rawDistribution);

await Distribution.create({
Expand All @@ -26,7 +26,7 @@ export const handleDistributionRemoved = async (event: SubstrateEvent): Promise<
const { params, block } = extractArgs(event);
const [, rawCaId] = params;

const { localId, assetId } = getCaIdValue(rawCaId, block);
const { localId, assetId } = await getCaIdValue(rawCaId, block);

await Distribution.remove(`${assetId}/${localId}`);
};
Expand All @@ -36,7 +36,7 @@ export const handleBenefitClaimed = async (event: SubstrateEvent): Promise<void>
const [, rawClaimantDid, rawCaId, , rawAmount, rawTax] = params;

const targetId = getTextValue(rawClaimantDid);
const { localId, assetId } = getCaIdValue(rawCaId, block);
const { localId, assetId } = await getCaIdValue(rawCaId, block);
const amount = getBigIntValue(rawAmount);
const tax = getBigIntValue(rawTax);

Expand Down Expand Up @@ -67,7 +67,7 @@ export const handleReclaimed = async (event: SubstrateEvent): Promise<void> => {
const [rawEventDid, rawCaId, rawAmount] = params;

const targetId = getTextValue(rawEventDid);
const { localId, assetId } = getCaIdValue(rawCaId, block);
const { localId, assetId } = await getCaIdValue(rawCaId, block);
const amount = getBigIntValue(rawAmount);

await DistributionPayment.create({
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/entities/assets/mapNfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getNftHolder = async (
export const handleNftCollectionCreated = async (event: SubstrateEvent): Promise<void> => {
const { params, blockId, block } = extractArgs(event);
const [, rawAssetId] = params;
const assetId = getAssetId(rawAssetId, block);
const assetId = await getAssetId(rawAssetId, block);
const asset = await getAsset(assetId);

asset.isNftCollection = true;
Expand Down Expand Up @@ -71,7 +71,7 @@ export const handleNftPortfolioUpdates = async (event: SubstrateEvent): Promise<
const reason = getFirstKeyFromJson(rawUpdateReason);
const value = getFirstValueFromJson(rawUpdateReason);

const { assetId, ids } = getNftId(rawNftId, block);
const { assetId, ids } = await getNftId(rawNftId, block);

const asset = await getAsset(assetId);
asset.updatedBlockId = blockId;
Expand Down
Loading
Loading