Skip to content

Commit 39765c3

Browse files
Merge pull request #1007 from ProvableHQ/feat/fee-calculation
[Feature] Automatic fee calculation
2 parents c8d914d + 75635bf commit 39765c3

24 files changed

+1031
-452
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
**/tmp
99
storage*/
1010
**/.next
11+
*.zip
1112

1213
## OS Files
1314
**.DS_Store

docs/api_reference/sdk-src_program-manager.md

Lines changed: 57 additions & 46 deletions
Large diffs are not rendered by default.

docs/examples/01_transfer_public.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const transaction = await programManager
2929
recipient // The address of the recipient.
3030
.address()
3131
.to_string(),
32-
0.1 // The fee amount.
32+
0.0 // The optional priority fee amount.
3333
);
3434

3535
// Broadcast the transaction to the Aleo network.

docs/examples/02_transfer_private.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const transaction = await programManager
2727
.address()
2828
.to_string(),
2929
"publicToPrivate", // The transfer type.
30-
0.1, // The fee amount.
30+
0.0, // The optional priority fee amount.
3131
false, // Indicates whether or not the fee will be private.
3232
);
3333
// Broadcast the transaction to the Aleo network.
@@ -62,7 +62,7 @@ const transaction2 = await programManager
6262
.address()
6363
.to_string(),
6464
"private", // The transfer type.
65-
0.1, // The fee amount.
65+
0.0, // The optional priority fee amount.
6666
false, // Indicates whether or not the fee will be private.
6767
);
6868
// Broadcast the transaction to the Aleo network.

docs/examples/03_deploy_program.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function addition:
3030
`;
3131

3232
// Create a deployment transaction using the declared source code.
33-
const transaction = await programManager.buildDeploymentTransaction(program, 3, false);
33+
const transaction = await programManager.buildDeploymentTransaction(program, 0.0, false);
3434
// Broadcast the transaction to the Aleo network.
3535
const result = await programManager.networkClient.submitTransaction(transaction);
3636
```

docs/examples/04_execute_program.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const input2 = 28;
2727
const transaction = await programManager.buildExecutionTransaction({
2828
programName: "addition_demo.aleo",
2929
functionName: "addition",
30-
fee: 0.020,
30+
priorityFee: 0.0,
3131
privateFee: false,
3232
inputs: [`${input1}u32`, `${input2}u32`],
3333
keySearchParams: { "cacheKey": "addition_demo:addition" },

docs/guide/06_executing_programs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ try {
132132
const tx = await programManager.buildExecutionTransaction({
133133
programName: "betastaking.aleo",
134134
functionName: "stake_public",
135-
fee: 0.10,
135+
priorityFee: 0.0,
136136
privateFee: false, // Assuming a value for privateFee
137137
inputs: ["aleo17x23al8k9scqe0qqdppzcehlu8vm0ap0j5mukskdq56lsa25lv8qz5cz3g", "50000000u64"], // Example inputs matching the function definition
138138
keySearchParams: keySearchParams,

docs/guide/07_deploying_programs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ programManager.setAccount(account)
6363
// Define an Aleo program to deploy
6464
const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
6565

66-
// Define a fee to pay to deploy the program
67-
const fee = 3.8; // 3.8 Aleo credits
66+
// Set the priority fee to pay to deploy the program
67+
const priorityFee = 0.0;
6868

6969
// Build a deployment transaction for the program.
70-
const tx = await programManager.buildDeploymentTransaction(program, fee, false);
70+
const tx = await programManager.buildDeploymentTransaction(program, priorityFee, false);
7171

7272
// Send the transaction to the network.
7373
const tx_id = await programManager.networkClient.submitTransaction(tx);

sdk/src/network-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,10 @@ class AleoNetworkClient {
752752
* const account = new Account();
753753
* const publicBalance = networkClient.getPublicBalance(account.address());
754754
*/
755-
async getPublicBalance(address: Address): Promise<number> {
755+
async getPublicBalance(address: Address | string): Promise<number> {
756756
try {
757-
const balanceStr = await this.getProgramMappingValue('credits.aleo', 'account', address.to_string());
757+
const addressString = address instanceof Address ? address.to_string() : address;
758+
const balanceStr = await this.getProgramMappingValue('credits.aleo', 'account', addressString);
758759
return balanceStr ? parseInt(balanceStr) : 0;
759760
} catch (error) {
760761
throw new Error(`Error fetching public balance for ${address}: ${error}`);

0 commit comments

Comments
 (0)