Skip to content
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
9 changes: 7 additions & 2 deletions src/accountManagement/accountController.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { IAccount } from "../accounts/interfaces";
import { Address } from "../core";
import { Address, BaseController } from "../core";
import { Transaction } from "../core/transaction";
import { TransactionComputer } from "../core/transactionComputer";
import { TransactionsFactoryConfig } from "../core/transactionsFactoryConfig";
import { AccountTransactionsFactory } from "./accountTransactionsFactory";
import { SaveKeyValueInput, SetGuardianInput } from "./resources";

export class AccountController {
export class AccountController extends BaseController {
private factory: AccountTransactionsFactory;
private txComputer: TransactionComputer;

constructor(options: { chainID: string }) {
super();
this.factory = new AccountTransactionsFactory({
config: new TransactionsFactoryConfig(options),
});
Expand All @@ -27,6 +28,7 @@ export class AccountController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -42,6 +44,7 @@ export class AccountController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -55,6 +58,7 @@ export class AccountController {
const transaction = this.factory.createTransactionForGuardingAccount(sender.address);
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -70,6 +74,7 @@ export class AccountController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand Down
14 changes: 14 additions & 0 deletions src/core/baseController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Transaction } from "../core/transaction";
import { EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS, EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS } from "./constants";

export class BaseController {
addExtraGasLimitIfRequired(transaction: Transaction): void {
if (transaction.guardian && !transaction.guardian.isEmpty()) {
transaction.gasLimit += BigInt(EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS);
}

if (transaction.relayer && !transaction.relayer.isEmpty()) {
transaction.gasLimit += BigInt(EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS);
}
}
}
2 changes: 2 additions & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export const SDK_JS_SIGNER = "sdk-js";
export const UNKNOWN_SIGNER = "unknown";

export const EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER = "EGLD-000000";
export const EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS = 50_000;
export const EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS = 50_000;
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require("./globals");

export * from "./address";
export * from "./asyncTimer";
export * from "./baseController";
export * from "./config";
export * from "./errors";
export * from "./interface";
Expand Down
24 changes: 22 additions & 2 deletions src/delegation/delegationController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IAccount } from "../accounts/interfaces";
import { Address } from "../core";
import { Address, BaseController } from "../core";
import { Transaction } from "../core/transaction";
import { TransactionComputer } from "../core/transactionComputer";
import { TransactionOnNetwork } from "../core/transactionOnNetwork";
Expand All @@ -10,13 +10,14 @@ import { DelegationTransactionsFactory } from "./delegationTransactionsFactory";
import { DelegationTransactionsOutcomeParser } from "./delegationTransactionsOutcomeParser";
import * as resources from "./resources";

export class DelegationController {
export class DelegationController extends BaseController {
private transactionAwaiter: TransactionWatcher;
private factory: DelegationTransactionsFactory;
private parser: DelegationTransactionsOutcomeParser;
private txComputer: TransactionComputer;

constructor(options: { chainID: string; networkProvider: INetworkProvider }) {
super();
this.transactionAwaiter = new TransactionWatcher(options.networkProvider);
this.factory = new DelegationTransactionsFactory({
config: new TransactionsFactoryConfig({ chainID: options.chainID }),
Expand All @@ -35,6 +36,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -59,6 +61,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -74,6 +77,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -89,6 +93,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -104,6 +109,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -119,6 +125,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -134,6 +141,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -149,6 +157,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -164,6 +173,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -179,6 +189,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -194,6 +205,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -212,6 +224,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -230,6 +243,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -245,6 +259,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -260,6 +275,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -275,6 +291,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -290,6 +307,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -305,6 +323,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -321,6 +340,7 @@ export class DelegationController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();

this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand Down
8 changes: 6 additions & 2 deletions src/smartContracts/smartContractController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Abi, ArgSerializer, isTyped, NativeSerializer } from "../abi";
import { IAccount } from "../accounts/interfaces";
import { Address } from "../core";
import { Address, BaseController } from "../core";
import { Err, ErrSmartContractQuery } from "../core/errors";
import { SmartContractQuery, SmartContractQueryInput, SmartContractQueryResponse } from "../core/smartContractQuery";
import { Transaction } from "../core/transaction";
Expand All @@ -13,7 +13,7 @@ import { SmartContractTransactionsOutcomeParser } from "../transactionsOutcomePa
import * as resources from "./resources";
import { SmartContractTransactionsFactory } from "./smartContractTransactionsFactory";

export class SmartContractController {
export class SmartContractController extends BaseController {
private factory: SmartContractTransactionsFactory;
private parser: SmartContractTransactionsOutcomeParser;
private transactionWatcher: TransactionWatcher;
Expand All @@ -22,6 +22,7 @@ export class SmartContractController {
private abi?: Abi;

constructor(options: { chainID: string; networkProvider: INetworkProvider; abi?: Abi }) {
super();
this.factory = new SmartContractTransactionsFactory({
config: new TransactionsFactoryConfig({ chainID: options.chainID }),
abi: options.abi,
Expand All @@ -43,6 +44,7 @@ export class SmartContractController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -67,6 +69,7 @@ export class SmartContractController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand All @@ -82,6 +85,7 @@ export class SmartContractController {
transaction.guardian = options.guardian ?? Address.empty();
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.addExtraGasLimitIfRequired(transaction);
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction));

return transaction;
Expand Down
Loading
Loading