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 token Management controller #536

Merged
merged 7 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from "./relayedTransactionV1Builder";
export * from "./relayedTransactionV2Builder";
export * from "./signableMessage";
export * from "./smartContractQueriesController";
export * from "./tokenManagement";
export * from "./tokenOperations";
export * from "./tokens";
export * from "./transaction";
Expand Down
4 changes: 2 additions & 2 deletions src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import BigNumber from "bignumber.js";
import { ITransactionOnNetwork } from "./interfaceOfNetwork";
import { TransactionOnNetwork } from "./networkProviders";

export interface ITransactionFetcher {
/**
* Fetches the state of a {@link Transaction}.
*/
getTransaction(txHash: string): Promise<ITransactionOnNetwork>;
getTransaction(txHash: string): Promise<TransactionOnNetwork>;
}

export interface IPlainTransactionObject {
Expand Down
12 changes: 6 additions & 6 deletions src/testutils/mockNetworkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export class MockNetworkProvider {
static AddressOfBob = new Address("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx");
static AddressOfCarol = new Address("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8");

private readonly transactions: Map<string, ITransactionOnNetwork>;
private readonly transactions: Map<string, TransactionOnNetwork>;
private nextTransactionTimelinePoints: any[] = [];
private readonly accounts: Map<string, IAccountOnNetwork>;
private readonly queryContractResponders: QueryContractResponder[] = [];
private readonly getTransactionResponders: GetTransactionResponder[] = [];

constructor() {
this.transactions = new Map<string, ITransactionOnNetwork>();
this.transactions = new Map<string, TransactionOnNetwork>();
this.accounts = new Map<string, IAccountOnNetwork>();

this.accounts.set(MockNetworkProvider.AddressOfAlice.bech32(), {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class MockNetworkProvider {
}
}

mockPutTransaction(hash: TransactionHash, item: ITransactionOnNetwork) {
mockPutTransaction(hash: TransactionHash, item: TransactionOnNetwork) {
item.isCompleted = false;
this.transactions.set(hash.toString(), item);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ export class MockNetworkProvider {
return {};
}

async getTransaction(txHash: string): Promise<ITransactionOnNetwork> {
async getTransaction(txHash: string): Promise<TransactionOnNetwork> {
// At first, try to use a mock responder
for (const responder of this.getTransactionResponders) {
if (responder.matches(txHash)) {
Expand Down Expand Up @@ -193,9 +193,9 @@ class QueryContractResponder {

class GetTransactionResponder {
readonly matches: (hash: string) => boolean;
readonly response: ITransactionOnNetwork;
readonly response: TransactionOnNetwork;

constructor(matches: (hash: string) => boolean, response: ITransactionOnNetwork) {
constructor(matches: (hash: string) => boolean, response: TransactionOnNetwork) {
this.matches = matches;
this.response = response;
}
Expand Down
12 changes: 3 additions & 9 deletions src/testutils/networkProviders.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { Query } from "../abi";
import { IAddress } from "../interface";
import {
IAccountOnNetwork,
IContractQueryResponse,
INetworkConfig,
ITransactionOnNetwork,
ITransactionStatus,
} from "../interfaceOfNetwork";
import { ApiNetworkProvider, ProxyNetworkProvider } from "../networkProviders";
import { IAccountOnNetwork, IContractQueryResponse, INetworkConfig, ITransactionStatus } from "../interfaceOfNetwork";
import { ApiNetworkProvider, ProxyNetworkProvider, TransactionOnNetwork } from "../networkProviders";

import { Transaction } from "../transaction";

Expand Down Expand Up @@ -39,7 +33,7 @@ export function createMainnetProvider(): INetworkProvider {
export interface INetworkProvider {
getNetworkConfig(): Promise<INetworkConfig>;
getAccount(address: IAddress): Promise<IAccountOnNetwork>;
getTransaction(txHash: string, withProcessStatus?: boolean): Promise<ITransactionOnNetwork>;
getTransaction(txHash: string, withProcessStatus?: boolean): Promise<TransactionOnNetwork>;
popenta marked this conversation as resolved.
Show resolved Hide resolved
getTransactionStatus(txHash: string): Promise<ITransactionStatus>;
sendTransaction(tx: Transaction): Promise<string>;
simulateTransaction(tx: Transaction): Promise<any>;
Expand Down
3 changes: 3 additions & 0 deletions src/tokenManagement/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./tokenManagementController";
export * from "./tokenManagementTransactionsFactory";
export * from "./tokenManagementTransactionsOutcomeParser";
113 changes: 113 additions & 0 deletions src/tokenManagement/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { IAddress } from "../interface";

export type IssueFungibleInput = IssueInput & { initialSupply: bigint; numDecimals: bigint };

export type IssueSemiFungibleInput = IssueNonFungibleInput;

export type IssueNonFungibleInput = IssueInput & { canTransferNFTCreateRole: boolean };

export type IssueInput = {
tokenName: string;
tokenTicker: string;
canFreeze: boolean;
canWipe: boolean;
canPause: boolean;
canChangeOwner: boolean;
canUpgrade: boolean;
canAddSpecialRoles: boolean;
};

export type FungibleSpecialRoleInput = {
user: IAddress;
tokenIdentifier: string;
addRoleLocalMint: boolean;
addRoleLocalBurn: boolean;
addRoleESDTTransferRole: boolean;
};
export type SemiFungibleSpecialRoleInput = SpecialRoleInput & { addRoleNFTAddQuantity: boolean };

export type SpecialRoleInput = {
user: IAddress;
tokenIdentifier: string;
addRoleNFTCreate: boolean;
addRoleNFTBurn: boolean;
addRoleNFTUpdateAttributes: boolean;
addRoleNFTAddURI: boolean;
addRoleESDTTransferRole: boolean;
addRoleESDTModifyCreator?: boolean;
addRoleNFTRecreate?: boolean;
addRoleESDTSetNewURI?: boolean;
addRoleESDTModifyRoyalties?: boolean;
};

export type MintInput = {
tokenIdentifier: string;
initialQuantity: bigint;
name: string;
royalties: number;
hash: string;
attributes: Uint8Array;
uris: string[];
};
export type ManagementInput = { user: IAddress; tokenIdentifier: string };
export type LocalBurnInput = { tokenIdentifier: string; supplyToBurn: bigint };
export type LocalMintInput = { tokenIdentifier: string; supplyToMint: bigint };

export type UpdateAttributesInput = UpdateInput & { attributes: Uint8Array };

export type UpdateQuantityInput = UpdateInput & { quantity: bigint };

export type UpdateInput = { tokenIdentifier: string; tokenNonce: bigint };
export type BurnRoleGloballyInput = { tokenIdentifier: string };

export type RegisterRolesInput = {
tokenName: string;
tokenTicker: string;
tokenType: TokenType;
numDecimals: bigint;
};

export type RegisterMetaESDTInput = {
tokenName: string;
tokenTicker: string;
numDecimals: bigint;
canFreeze: boolean;
canWipe: boolean;
canPause: boolean;
canTransferNFTCreateRole: boolean;
canChangeOwner: boolean;
canUpgrade: boolean;
canAddSpecialRoles: boolean;
};

export type ModifyRoyaltiesInput = BaseInput & { newRoyalties: bigint };

export type BaseInput = { tokenIdentifier: string; tokenNonce: bigint };

export type SetNewUriInput = BaseInput & { newUris: string[] };

export type UpdateMetadataInput = {
tokenIdentifier: string;
tokenNonce: bigint;
newTokenName?: string;
newRoyalties?: bigint;
newHash?: string;
newAttributes?: Uint8Array;
newUris?: string[];
};

export type RegisteringDynamicTokenInput = { tokenName: string; tokenTicker: string; tokenType: TokenType };

type TokenType = "NFT" | "SFT" | "META" | "FNG";

export type SpecialRoleOutput = {
userAddress: string;
tokenIdentifier: string;
roles: string[];
};

export type MintNftOutput = {
tokenIdentifier: string;
nonce: bigint;
initialQuantity: bigint;
};
Loading
Loading