Skip to content

Commit

Permalink
Intract mints feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Apratim Gupta authored and Apratim Gupta committed Dec 22, 2024
1 parent 082ecd3 commit 10788b7
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 3 deletions.
14 changes: 14 additions & 0 deletions libs/mint-intract/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "mint-intract",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"ethers": "^6.13.2"
}
}
2 changes: 2 additions & 0 deletions libs/mint-intract/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './mint-intract.module';
export * from './mint-intract.service';
11 changes: 11 additions & 0 deletions libs/mint-intract/src/mint-intract.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SharedModule } from '@core/shared';
import { Module } from '@nestjs/common';

import { MintIntractService } from './mint-intract.service';

@Module({
imports: [SharedModule],
providers: [MintIntractService],
exports: [MintIntractService],
})
export class MintIntractModule {}
159 changes: 159 additions & 0 deletions libs/mint-intract/src/mint-intract.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { RegistryPlug } from '@action/registry';
import { ChainService } from '@core/shared';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Contract, Interface, ethers } from 'ethers';
import {
Action as ActionDto,
ActionMetadata,
GenerateTransactionParams,
GenerateTransactionResponse,
TransactionInfo,
} from 'src/common/dto';
import { Chains } from 'src/constants';

import { FieldTypes } from './types';

@RegistryPlug('mint-intract', 'v1')
@Injectable()
export class MintIntractService extends ActionDto<FieldTypes> {
private readonly isDev: boolean;
constructor(
private readonly chainService: ChainService,
private readonly configService: ConfigService,
) {
super();
this.isDev = this.configService.get('env')! === 'dev';
}

async getMetadata(): Promise<ActionMetadata<FieldTypes>> {
const supportedNetwork = [
Chains.ZkLinkNova,
Chains.ArbitrumOne,
Chains.EthereumMainnet,
Chains.Base,
Chains.Linea,
Chains.MantaPacificMainnet,
Chains.OpMainnet,
Chains.ScrollMainnet,
Chains.BSCMainnet,
];
if (this.isDev) {
supportedNetwork.push(
Chains.ZkLinkNovaSepolia,
Chains.ArbitrumSepolia,
Chains.BaseSepolia,
Chains.BSCTestnet,
);
}
return {
title: 'Mint Intract NFT',
description: '<div>This action allows you to mint Intract NFTs</div>',
networks: this.chainService.buildSupportedNetworks(supportedNetwork),
author: {
name: 'Intract',
github: 'https://quest.intract.io/',
},
magicLinkMetadata: {
title: 'Mint Intract NFT',
description: 'Mint Intract NFTs',
},
intent: {
binding: true,
components: [
{
name: 'contract',
label: 'NFT Contract Address',
desc: 'Enter the NFT contract address',
type: 'input',
regex: '^0x[a-fA-F0-9]{40}$',
regexDesc: 'Invalid Address',
},
{
name: 'price',
label: 'NFT Price',
desc: 'The NFT mint fee, leave it to 0 for free mint NFT',
type: 'input',
regex: '^\\d+\\.?\\d*$|^\\d*\\.\\d+$',
regexDesc: 'Must be a number',
defaultValue: '0',
},
],
},
};
}

async generateTransaction(
data: GenerateTransactionParams<FieldTypes>,
): Promise<GenerateTransactionResponse> {
const { additionalData, formData } = data;
const { chainId } = additionalData;
const provider = this.chainService.getProvider(chainId);

const payable = ' payable';
const abiParams = [];
const funcParams = [];
const txParams = [];
const recipient = additionalData.account;
abiParams.push('address _receiver');
funcParams.push('address');
txParams.push(recipient);
abiParams.push('uint256 _quantity');
funcParams.push('uint256');
txParams.push(1);
abiParams.push('address _currency');
funcParams.push('address');
txParams.push('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE');
abiParams.push('uint256 _pricePerToken');
funcParams.push('uint256');
txParams.push(Number(formData.price));
abiParams.push('tuple _allowlistProof');
funcParams.push('tuple');
txParams.push([
[],
1,
Number(formData.price),
'0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
]);
abiParams.push('bytes _data');
funcParams.push('bytes');
txParams.push([]);

// if (formData.recipient != 'none') {
// abiParams.push('address recipient');
// funcParams.push('address');
// if (formData.recipient == 'sender') {
// txParams.push(additionalData.account);
// } else {
// txParams.push(formData.recipient);
// }
// }
// if (Number(formData.quantity) > 0) {
// abiParams.push('uint quantity');
// funcParams.push('uint');
// txParams.push(Number(formData.quantity));
// }
// if (formData.ext != 'none') {
// abiParams.push('string ext');
// funcParams.push('string');
// txParams.push(formData.ext);
// }
const entrypoint = 'claim';
const abi = new Interface([
`function ${entrypoint}(${abiParams.join(',')})${payable}`,
]);

const contract = new Contract(formData.contract.toString(), abi, provider);
const mintTx = await contract[
`${entrypoint}(${funcParams.join(',')})`
].populateTransaction.apply(this, txParams);
const tx: TransactionInfo = {
chainId: chainId,
to: mintTx.to,
value: ethers.parseEther(formData.price).toString(),
data: mintTx.data,
shouldPublishToChain: true,
};
return { transactions: [tx] };
}
}
4 changes: 4 additions & 0 deletions libs/mint-intract/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type FieldTypes = {
contract: string;
price: string;
};
9 changes: 9 additions & 0 deletions libs/mint-intract/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "../../dist/libs/mint-intract"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
2 changes: 2 additions & 0 deletions libs/registry/src/registry.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BuyNftOKXModule } from '@action/buy-nft-okx';
import { CrossChainSwapModule } from '@action/cross-chain-swap';
import { DxFunModule } from '@action/dx-fun';
import { MagicSwapModule } from '@action/magic-swap';
import { MintIntractModule } from '@action/mint-intract';
import { MintNftModule } from '@action/mint-nft';
import { MintNovaNftModule } from '@action/mint-nova-nft';
import { NewsModule } from '@action/news';
Expand Down Expand Up @@ -39,6 +40,7 @@ import { RegistryService } from './registry.service';
PreSaleModule,
MagicSwapModule,
AgxModule,
MintIntractModule,
],
providers: [RegistryService],
exports: [RegistryService],
Expand Down
9 changes: 9 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@
"compilerOptions": {
"tsConfigPath": "libs/agx/tsconfig.lib.json"
}
},
"mint-intract": {
"type": "library",
"root": "libs/mint-intract",
"entryFile": "index",
"sourceRoot": "libs/mint-intract/src",
"compilerOptions": {
"tsConfigPath": "libs/mint-intract/tsconfig.lib.json"
}
}
}
}
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
"^@action/magic-swap(|/.*)$": "<rootDir>/libs/magic-swap/src/$1",
"^@action/agx(|/.*)$": "<rootDir>/libs/agx/src/$1",
"^@action/okx-bridge(|/.*)$": "<rootDir>/libs/okx-bridge/src/$1",
"^@action/dx-fun(|/.*)$": "<rootDir>/libs/dx-fun/src/$1"
"^@action/dx-fun(|/.*)$": "<rootDir>/libs/dx-fun/src/$1",
"^@action/mint-intract(|/.*)$": "<rootDir>/libs/mint-intract/src/$1"
}
}
}
}
4 changes: 3 additions & 1 deletion test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"@action/magic-swap/(.*)": "<rootDir>/../libs/magic-swap/src/$1",
"@action/magic-swap": "<rootDir>/../libs/magic-swap/src",
"@action/agx/(.*)": "<rootDir>/../libs/agx/src/$1",
"@action/agx": "<rootDir>/../libs/agx/src"
"@action/agx": "<rootDir>/../libs/agx/src",
"@action/mint-intract/(.*)": "<rootDir>/../libs/mint-intract/src/$1",
"@action/mint-intract": "<rootDir>/../libs/mint-intract/src"
}
}
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
],
"@action/agx/*": [
"libs/agx/src/*"
],
"@action/mint-intract": [
"libs/mint-intract/src"
],
"@action/mint-intract/*": [
"libs/mint-intract/src/*"
]
}
}
Expand Down

0 comments on commit 10788b7

Please sign in to comment.