Skip to content

Commit

Permalink
generic AssetHub naming
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljaegerde committed Apr 27, 2024
1 parent 7dff020 commit a7d860d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 57 deletions.
21 changes: 10 additions & 11 deletions app/[chain]/referendum-rewards/components/form-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ export default function FormActions({

let amountOfTxs: number;

if (!rewardSendoutData?.kusamaAssetHubTxs) {
if (!rewardSendoutData?.assetHubTxs) {
// It's better to handle this condition differently or ensure the layout still renders without functional impact.
amountOfTxs = 0;
}
else {
amountOfTxs = Math.ceil(rewardSendoutData?.kusamaAssetHubTxs?.length / rewardsConfig.NFT_BATCH_SIZE_MAX);
amountOfTxs = Math.ceil(rewardSendoutData?.assetHubTxs?.length / rewardsConfig.NFT_BATCH_SIZE_MAX);
}

function onReset() {
Expand Down Expand Up @@ -196,12 +196,12 @@ export default function FormActions({
rewardsConfig.NFT_BATCH_SIZE_MAX / responseData?.txsCount?.txsPerVote
) * responseData?.txsCount?.txsPerVote;

let kusamaAssetHubTxsBatches: TxTypes[] | undefined =
responseData?.kusamaAssetHubTxs;
let assetHubTxsBatches: TxTypes[] | undefined =
responseData?.assetHubTxs;

if (kusamaAssetHubTxsBatches && Array.isArray(kusamaAssetHubTxsBatches)) {
// group the kusamaAssetHubTxs in batches of max size maxTxsPerbatch making sure that txs belonging together (multiples of 13) are never split to different batches
const batches = kusamaAssetHubTxsBatches.reduce((acc, tx, index) => {
if (assetHubTxsBatches && Array.isArray(assetHubTxsBatches)) {
// group the assetHubTxs in batches of max size maxTxsPerbatch making sure that txs belonging together (multiples of 13) are never split to different batches
const batches = assetHubTxsBatches.reduce((acc, tx, index) => {
const batchIndex: number = Math.floor(index / maxTxsPerBatch);
if (!acc[batchIndex]) {
acc[batchIndex] = [];
Expand All @@ -212,7 +212,7 @@ export default function FormActions({

setRewardSendoutData({
...responseData,
kusamaAssetHubTxsBatches: batches,
assetHubTxsBatches: batches,
});
} else {
setRewardSendoutData({
Expand Down Expand Up @@ -358,9 +358,8 @@ export default function FormActions({
<p>
Start the sendout process. You will be asked to sign
<span className="text-warning px-4">
{amountOfTxs === 1 ? "1 transaction" : `${amountOfTxs ?? "multiple"} transactions`}
{amountOfTxs === 1 ? "1 transaction" : `${amountOfTxs ?? "multiple"} transactions in sequence.`}
</span>
in sequence.
{amountOfTxs > 1 && "Complete all for a full sendout."}
</p>
</div>
Expand All @@ -376,7 +375,7 @@ export default function FormActions({
</Button>
)}
<TxButton
extrinsic={rewardSendoutData?.kusamaAssetHubTxsBatches}
extrinsic={rewardSendoutData?.assetHubTxsBatches}
requiredBalance={totalFees}
variant="shadow"
isDisabled={isSubmitting || step !== 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default function ModalAnalyzeSendout({
const { isOpen, onOpenChange } = props;

const displayedData = pick(sendoutData, [
// "kusamaAssetHubTxsBatches",
"kusamaAssetHubTxsHuman",
// "assetHubTxsBatches",
"assetHubTxsHuman",
"distribution",
"voters",
"config",
Expand Down
14 changes: 7 additions & 7 deletions app/[chain]/referendum-rewards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export type GenerateRewardsResult =
| {
call?: string;
config?: RewardConfiguration;
kusamaCall?: string;
kusamaAssetHubCall?: string;
kusamaAssetHubTxs?: string[];
kusamaAssetHubTxsBatches?: string[];
kusamaAssetHubTxsHuman?: any[];
// kusamaCall?: string;
assetHubCall?: string;
assetHubTxs?: string[];
assetHubTxsBatches?: string[];
assetHubTxsHuman?: any[];
distribution?: RarityDistribution;
voters?: string[];
fees?: {
Expand All @@ -29,8 +29,8 @@ export type GenerateRewardsResult =

export type CreateCollectionResult = {
call: string | undefined;
kusamaAssetHubCall: string | undefined;
kusamaAssetHubTxs: string[] | undefined;
assetHubCall: string | undefined;
assetHubTxs: string[] | undefined;
fees: string | undefined;
txsCount: number | undefined;
};
Expand Down
18 changes: 9 additions & 9 deletions app/api/rewards/get-reward-txs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export const getTxsReferendumRewards = async (
rarityDistribution: RarityDistribution,
rng: RNG
): Promise<{
txsKusamaAssetHub: any[];
txsAssetHub: any[];
txsKusama: any[];
txsPerVote: number;
}> => {
if (!apiAssetHub || !apiRelay || !apiPinata)
throw "getTxsReferendumRewards needs defined apis";

let txsKusamaAssetHub: TxTypes[] = [];
let txsAssetHub: TxTypes[] = [];
let txsKusama: TxTypes[] = [];

const { refIndex: referendumIndex } = config;
Expand All @@ -40,9 +40,9 @@ export const getTxsReferendumRewards = async (
apiPinata,
config
);
txsKusamaAssetHub = [
...txsKusamaAssetHub,
...txsCollectionSetMetadata.txsKusamaAssetHub,
txsAssetHub = [
...txsAssetHub,
...txsCollectionSetMetadata.txsAssetHub,
];
}
//todo lock collection after mint if new collection
Expand Down Expand Up @@ -85,9 +85,9 @@ export const getTxsReferendumRewards = async (

const txsPerVote = txsVotes.length / decoratedVotes.length;

txsKusamaAssetHub = [...txsKusamaAssetHub, ...txsVotes];
txsAssetHub = [...txsAssetHub, ...txsVotes];

// txsKusamaAssetHub = [
// txsAssetHub = [
// apiAssetHub.tx.system.remark(
// "Created with https://www.proofofchaos.app/referendum-rewards/"
// ),
Expand All @@ -96,10 +96,10 @@ export const getTxsReferendumRewards = async (
// const txsKusamaXCM = await getTxsKusamaXCM(
// apiRelay,
// apiAssetHub,
// txsKusamaAssetHub
// txsAssetHub
// );

// txsKusama = [...txsKusama, ...txsKusamaXCM];

return { txsKusamaAssetHub, txsKusama, txsPerVote };
return { txsAssetHub, txsKusama, txsPerVote };
};
18 changes: 9 additions & 9 deletions app/api/rewards/get-txs-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { ApiCache } from "@/config/chains/ApiCache";
import { SubstrateChain } from "@/types";

export const getUserLatestCollectionId = async (
apiKusamaAssetHub: ApiPromise,
apiAssetHub: ApiPromise,
address: string
): Promise<string> => {
const allUserCollections =
await apiKusamaAssetHub.query.nfts.collectionAccount.keys(address);
await apiAssetHub.query.nfts.collectionAccount.keys(address);
const collectionIds: BN[] = allUserCollections.map(
({ args: [, collectionId] }) => new BN(collectionId.toString())
);
Expand All @@ -25,19 +25,19 @@ export const getUserLatestCollectionId = async (

/**
* Get the txs for setting the metadata for a collection
* @param apiKusamaAssetHub
* @param apiAssetHub
* @param apiPinata
* @param config
* @returns
*/
export const getTxsCollectionSetMetadata = async (
apiKusamaAssetHub: ApiPromise,
apiAssetHub: ApiPromise,
apiPinata: PinataClient,
config: RewardConfiguration
): Promise<{
txsKusamaAssetHub: TxTypes[];
txsAssetHub: TxTypes[];
}> => {
let txsKusamaAssetHub = [];
let txsAssetHub = [];

if (!config.collectionConfig.id)
throw "getTxsCollectionSetMetadata needs a collection config id";
Expand All @@ -48,11 +48,11 @@ export const getTxsCollectionSetMetadata = async (

const ipfsIdentifier = `ipfs://ipfs/${config.collectionConfig.metadataCid}`;

txsKusamaAssetHub.push(
apiKusamaAssetHub.tx.nfts.setCollectionMetadata(
txsAssetHub.push(
apiAssetHub.tx.nfts.setCollectionMetadata(
config.collectionConfig.id,
ipfsIdentifier
)
);
return { txsKusamaAssetHub };
return { txsAssetHub };
};
12 changes: 6 additions & 6 deletions app/api/rewards/get-txs-vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ApiPromise } from "@polkadot/api";
import crypto from "crypto";

export const getTxsForVotes = (
apiKusamaAssetHub: ApiPromise,
apiAssetHub: ApiPromise,
config: RewardConfiguration,
fileAndMetadataCids: PinImageAndMetadataForOptionsResult,
attributes: any,
Expand Down Expand Up @@ -69,7 +69,7 @@ export const getTxsForVotes = (
}

txs.push(
apiKusamaAssetHub.tx.nfts.mint(
apiAssetHub.tx.nfts.mint(
config.collectionConfig.id,
nftId,
vote.address.toString(),
Expand All @@ -79,7 +79,7 @@ export const getTxsForVotes = (

// txs.push(
// ...getAllSetAttributeTxs(
// apiKusamaAssetHub,
// apiAssetHub,
// config,
// fileAndMetadataCids,
// attributes,
Expand All @@ -93,7 +93,7 @@ export const getTxsForVotes = (
const ipfsIdentifier = `ipfs://ipfs/${metadataCid}`;

txs.push(
apiKusamaAssetHub.tx.nfts.setMetadata(
apiAssetHub.tx.nfts.setMetadata(
config.collectionConfig.id,
nftId,
ipfsIdentifier
Expand All @@ -102,7 +102,7 @@ export const getTxsForVotes = (

if (config.isMetadataLocked || config.isAttributesLocked) {
txs.push(
apiKusamaAssetHub.tx.nfts.lockItemProperties(
apiAssetHub.tx.nfts.lockItemProperties(
config.collectionConfig.id,
nftId,
config.isMetadataLocked,
Expand All @@ -111,7 +111,7 @@ export const getTxsForVotes = (
);
}
// txs.push(
// apiKusamaAssetHub.tx.nfts.transfer(
// apiAssetHub.tx.nfts.transfer(
// config.collectionConfig.id,
// nftId,
// vote.address.toString()
Expand Down
22 changes: 11 additions & 11 deletions app/api/rewards/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const generateCalls = async (

// get all transactions that are needed for the distribution of the rewards
// ipfs pinning, metadata, also happens here
let { txsKusamaAssetHub, txsPerVote } = await getTxsReferendumRewards(
let { txsAssetHub, txsPerVote } = await getTxsReferendumRewards(
nftPalletApi,
referendaPalletApi,
apiPinata,
Expand All @@ -226,13 +226,13 @@ const generateCalls = async (
);

// const nftCalls = nftPalletApi?.tx.utility
// .batchAll(txsKusamaAssetHub)
// .batchAll(txsAssetHub)
// .method.toHex();

// // const kusamaCalls = referendaPalletApi.tx.utility.batchAll(txsKusama).method.toHex();

console.info(
`📊 Generated ${txsKusamaAssetHub.length} txs for minting NFTs on Asset Hub (Kusama)`
`📊 Generated ${txsAssetHub.length} txs for minting NFTs on Asset Hub (Kusama)`
// ,` and ${txsKusama.length} txs for Kusama XCM calls`
);

Expand All @@ -244,15 +244,15 @@ const generateCalls = async (
`💵 Calculating fees for sender ${sender} on chain address ${encodedAddress}`
);

const amountOfTxs = txsKusamaAssetHub.length;
const amountOfTxs = txsAssetHub.length;
const amountOfNFTs = decoratedVotes.length;
const txsPerNFT = amountOfTxs / amountOfNFTs;

console.info(`📊 Generated ${amountOfTxs} txs for ${amountOfNFTs} NFTs`);
console.info(`📊 Generated ${txsPerNFT} txs per NFT`);

infoNftCalls = await nftPalletApi?.tx.utility
.batchAll(txsKusamaAssetHub)
.batchAll(txsAssetHub)
.paymentInfo(encodedAddress);

console.info("successfully calculated fees");
Expand Down Expand Up @@ -290,10 +290,10 @@ const generateCalls = async (
call: "omitted",
config,
// kusamaCall: JSON.stringify(kusamaCalls),
kusamaCall: "",
kusamaAssetHubCall: "", // JSON.stringify(nftCalls),
kusamaAssetHubTxs: txsKusamaAssetHub,
kusamaAssetHubTxsHuman: txsKusamaAssetHub.map((tx) => tx.method.toHuman()),
// kusamaCall: "",
assetHubCall: "", // JSON.stringify(nftCalls),
assetHubTxs: txsAssetHub,
assetHubTxsHuman: txsAssetHub.map((tx) => tx.method.toHuman()),
voters,
distribution: rarityDistribution,
fees: {
Expand All @@ -306,8 +306,8 @@ const generateCalls = async (
deposit: totalDeposit?.toString(),
},
txsCount: {
kusama: txsKusamaAssetHub.length,
nfts: txsKusamaAssetHub.length,
kusama: txsAssetHub.length,
nfts: txsAssetHub.length,
txsPerVote,
},
};
Expand Down
2 changes: 1 addition & 1 deletion app/api/test/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function* getTxsReferendumRewards({
await sleep(500);
yield "some other action is done";
await sleep(500);
yield { txsPerVote: 2, txsKusamaAssetHub: ["0x123", "0x456"] };
yield { txsPerVote: 2, txsAssetHub: ["0x123", "0x456"] };
}

async function* generator2(data: any) {
Expand Down
2 changes: 1 addition & 1 deletion config/txs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SubstrateChain } from "@/types";

/**
* Will get the txs for creating a collection but NOT adding the metadata
* @param apiKusamaAssetHub
* @param apiAssetHub
* @param rewardConfig
* @returns
*/
Expand Down

0 comments on commit a7d860d

Please sign in to comment.