From bca03f630050a79a3437d8db524a9b75128faa43 Mon Sep 17 00:00:00 2001
From: BenRey
Date: Thu, 16 May 2024 15:51:28 +0200
Subject: [PATCH 1/3] Optional deploy options and gas estimation fix
---
.../src/experimental/smartContract.ts | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/packages/massa-web3/src/experimental/smartContract.ts b/packages/massa-web3/src/experimental/smartContract.ts
index 0b64f1fb..03df0191 100644
--- a/packages/massa-web3/src/experimental/smartContract.ts
+++ b/packages/massa-web3/src/experimental/smartContract.ts
@@ -87,7 +87,13 @@ export class SmartContract {
* @param client - The client to connect to the desired blockchain.
* @param account - The account that will deploy the smart contract.
* @param contract - The contract to deploy.
- * @param opts - Optional deployment details.
+ * @param opts - Optional deployment details. Default to
+ * - fee: auto-estimated fee,
+ * - maxCoins: auto-estimated cost,
+ * - maxGas: auto-estimated gas,
+ * - periodToLive: 10,
+ * - waitFinalExecution: true.
+ *
*
* @returns The deployed smart contract.
*
@@ -98,7 +104,9 @@ export class SmartContract {
account: Account,
// TODO: Handle multiple contracts
contract: DeployContract,
- opts: DeployOptions
+ opts: DeployOptions = {
+ waitFinalExecution: true,
+ }
): Promise {
const totalCost =
StorageCost.smartContract(contract.byteCode.length) + contract.coins
@@ -254,6 +262,8 @@ export class SmartContract {
/**
* Returns the gas estimation for a given function.
*
+ * @remarks To avoid running out of gas, the gas estimation is increased by 20%.
+ *
* @param func - The function to estimate the gas cost.
* @param parameter - The parameter for the function call in Uint8Array format.
* @param callerAddress - The address of the caller.
@@ -278,6 +288,7 @@ export class SmartContract {
throw new Error(result.info.error)
}
- return BigInt(result.info.gasCost)
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
+ return (BigInt(result.info.gasCost) * 120n) / 100n
}
}
From fbe8ed7b2d8b37bf08b2624d72ff767623351c38 Mon Sep 17 00:00:00 2001
From: BenRey <44082144+Ben-Rey@users.noreply.github.com>
Date: Thu, 16 May 2024 18:10:59 +0200
Subject: [PATCH 2/3] Update
packages/massa-web3/src/experimental/smartContract.ts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Grégory Libert
---
.../massa-web3/src/experimental/smartContract.ts | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/packages/massa-web3/src/experimental/smartContract.ts b/packages/massa-web3/src/experimental/smartContract.ts
index 03df0191..52130903 100644
--- a/packages/massa-web3/src/experimental/smartContract.ts
+++ b/packages/massa-web3/src/experimental/smartContract.ts
@@ -87,12 +87,12 @@ export class SmartContract {
* @param client - The client to connect to the desired blockchain.
* @param account - The account that will deploy the smart contract.
* @param contract - The contract to deploy.
- * @param opts - Optional deployment details. Default to
- * - fee: auto-estimated fee,
- * - maxCoins: auto-estimated cost,
- * - maxGas: auto-estimated gas,
- * - periodToLive: 10,
- * - waitFinalExecution: true.
+ * @param opts - Optional deployment details with defaults as follows:
+ * @param opts.fee - Execution fee, auto-estimated if absent.
+ * @param opts.maxCoins - Maximum number of coins to use, auto-estimated if absent.
+ * @param opts.maxGas - Maximum executino gas, auto-estimated if absent.
+ * @param opts.periodToLive - Duration in blocks before the transaction expires, defaults to 10.
+ * @param opts.waitFinalExecution - Whether to wait for the transaction to be finalized, defaults to true.
*
*
* @returns The deployed smart contract.
From 1a8f7c5d5d96b0f360ba2d7823783c52fdb770fd Mon Sep 17 00:00:00 2001
From: BenRey <44082144+Ben-Rey@users.noreply.github.com>
Date: Thu, 16 May 2024 18:11:19 +0200
Subject: [PATCH 3/3] Update
packages/massa-web3/src/experimental/smartContract.ts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Grégory Libert
---
packages/massa-web3/src/experimental/smartContract.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/massa-web3/src/experimental/smartContract.ts b/packages/massa-web3/src/experimental/smartContract.ts
index 52130903..17569c9b 100644
--- a/packages/massa-web3/src/experimental/smartContract.ts
+++ b/packages/massa-web3/src/experimental/smartContract.ts
@@ -289,6 +289,6 @@ export class SmartContract {
}
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
- return (BigInt(result.info.gasCost) * 120n) / 100n
+ return BigInt(result.info.gasCost * 1.2)
}
}