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 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
6 changes: 3 additions & 3 deletions src/abi/interaction.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe("test smart contract interactor", function () {

const transactionCompletionAwaiter = new TransactionWatcher({
getTransaction: async (hash: string) => {
return await provider.getTransaction(hash, true);
return await provider.getTransaction(hash);
},
});

Expand Down Expand Up @@ -406,7 +406,7 @@ describe("test smart contract interactor", function () {

const transactionCompletionAwaiter = new TransactionWatcher({
getTransaction: async (hash: string) => {
return await provider.getTransaction(hash, true);
return await provider.getTransaction(hash);
},
});

Expand Down Expand Up @@ -600,7 +600,7 @@ describe("test smart contract interactor", function () {

const transactionCompletionAwaiter = new TransactionWatcher({
getTransaction: async (hash: string) => {
return await provider.getTransaction(hash, true);
return await provider.getTransaction(hash);
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/abi/smartContract.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("test on local testnet", function () {

watcher = new TransactionWatcher({
getTransaction: async (hash: string) => {
return await provider.getTransaction(hash, true);
return await provider.getTransaction(hash);
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/abi/smartContractResults.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("fetch transactions from local testnet", function () {
({ alice } = await loadTestWallets());
watcher = new TransactionWatcher({
getTransaction: async (hash: string) => {
return await provider.getTransaction(hash, true);
return await provider.getTransaction(hash);
},
});
});
Expand Down
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
2 changes: 1 addition & 1 deletion src/testutils/contractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ContractController {
this.provider = provider;
this.transactionCompletionAwaiter = new TransactionWatcher({
getTransaction: async (hash: string) => {
return await provider.getTransaction(hash, true);
return await provider.getTransaction(hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass the network provider directly?

},
});
}
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): Promise<TransactionOnNetwork>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, good to drop this flag.

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";
117 changes: 117 additions & 0 deletions src/tokenManagement/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
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 PausingInput = { 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 UpdateTokenIDInput = { tokenIdentifier: string };
export type ChangeTokenToDynamicInput = { 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 ModifyCreatorInput = BaseInput;

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

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

export type ManageMetadataInput = {
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