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 namespace token mint method #8724

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const NamespaceAbi = [
{
type: 'function',
name: 'balanceOf',
inputs: [
{ name: 'account', type: 'address', internalType: 'address' },
{ name: 'id', type: 'uint256', internalType: 'uint256' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'mintId',
inputs: [
{ name: 'assignee', type: 'address', internalType: 'address' },
{ name: 'id', type: 'uint256', internalType: 'uint256' },
{ name: 'amount', type: 'uint256', internalType: 'uint256' },
{ name: 'data', type: 'bytes', internalType: 'bytes' },
],
outputs: [],
stateMutability: 'nonpayable',
},
];
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ZERO_ADDRESS } from '@hicommonwealth/shared';
import { TransactionReceipt } from 'web3';
import { AbiItem } from 'web3-utils';
import { NamespaceAbi } from './Abi/NamespaceAbi';
import { namespaceFactoryAbi } from './Abi/NamespaceFactoryAbi';
import { reservationHookAbi } from './Abi/ReservationHookAbi';
import ContractBase from './ContractBase';
Expand Down Expand Up @@ -262,6 +263,44 @@ class NamespaceFactory extends ContractBase {
return String(balance / (10 ^ (decimals ?? 18)));
}
}
/**
* mints namespace tokens to assignee on id with desired balance
* @param namespace the namespace name
* @param id the id on the namespace to mint(admin = 0)
* @param desiredBalance the total desired balance(admin = 1)
* @param assigneeAddress the address to assign the token to
* @param chainId the current chainId
* @param walletAddress The senders wallet address
* @returns txReceipt
* NOTE: If address already has > balance no tokens will be minted
*/
async mintNamespaceTokens(
namespace: string,
id: number,
desiredBalance: number,
assigneeAddress: string,
chainId: string,
walletAddress: string,
) {
if (!this.initialized || !this.walletEnabled) {
await this.initialize(true, chainId);
}
const namespaceAddr = await this.getNamespaceAddress(namespace);
const namespaceContract = new this.web3.eth.Contract(
NamespaceAbi,
namespaceAddr,
);
const balance = await namespaceContract.methods
.balanceOf(assigneeAddress, id)
.call();
const balanceDiff = desiredBalance - Number(balance);
if (balanceDiff > 0) {
jnaviask marked this conversation as resolved.
Show resolved Hide resolved
const txReceipt = await namespaceContract.methods
.mintId(assigneeAddress, id, balanceDiff, '0x')
.send({ from: walletAddress });
return txReceipt;
}
}
}

export default NamespaceFactory;
Loading