Skip to content

Commit

Permalink
Merge branch 'main' of github.com:butaneprotocol/translucent-core
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkendall committed Sep 21, 2024
2 parents 802b6ac + 27d4aa0 commit 5a4ecf2
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/blaze-core/src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const hardCodedProtocolParams: ProtocolParameters = {
minPoolCost: 170000000, // The minimum pool cost.
protocolVersion: { major: 9, minor: 0 }, // The protocol version.
maxValueSize: 5000, // The maximum value size.
collateralPercentage: 150 / 100, // The collateral percentage.
collateralPercentage: 150, // The collateral percentage.
maxCollateralInputs: 3, // The maximum collateral inputs.
costModels: new Map() // The cost models.
.set(
Expand Down
18 changes: 18 additions & 0 deletions packages/blaze-emulator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @blaze-cardano/emulator

## 0.1.76

### Patch Changes

- Updated dependencies [88ee831]
- @blaze-cardano/tx@0.6.1
- @blaze-cardano/wallet@0.1.56

## 0.1.75

### Patch Changes

- Updated dependencies [c924f95]
- Updated dependencies [471d47d]
- Updated dependencies [c951eec]
- @blaze-cardano/tx@0.6.0
- @blaze-cardano/wallet@0.1.55

## 0.1.74

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-emulator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blaze-cardano/emulator",
"version": "0.1.74",
"version": "0.1.76",
"description": "Blaze cardano emulator library",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-emulator/src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export class Emulator {

// Minimum collateral amount included
const minCollateral = BigInt(
Math.ceil(this.params.collateralPercentage * Number(body.fee())),
Math.ceil((this.params.collateralPercentage * Number(body.fee())) / 100),
);

// If any scripts have been invoked, minimum collateral must be included
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-query/src/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Blockfrost implements Provider {
minor: response.protocol_minor_ver,
},
maxValueSize: response.max_val_size,
collateralPercentage: response.collateral_percent / 100,
collateralPercentage: response.collateral_percent,
maxCollateralInputs: response.max_collateral_inputs,
costModels: costModels,
prices: {
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-query/src/maestro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Maestro implements Provider {
minPoolCost: params.min_stake_pool_cost.ada.lovelace,
protocolVersion: params.version,
maxValueSize: params.max_value_size.bytes,
collateralPercentage: params.collateral_percentage / 100,
collateralPercentage: params.collateral_percentage,
maxCollateralInputs: params.max_collateral_inputs,
costModels: costModels,
prices: {
Expand Down
25 changes: 25 additions & 0 deletions packages/blaze-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# @blaze-cardano/sdk

## 0.2.1

### Patch Changes

- Updated dependencies [88ee831]
- @blaze-cardano/tx@0.6.1
- @blaze-cardano/uplc@0.1.30
- @blaze-cardano/wallet@0.1.56

## 0.2.0

### Minor Changes

- 471d47d: Submit built transactions through the wallet by default, while allowing a provider option.

### Patch Changes

- c951eec: avoid preCompleteHook overriding user selections
- Updated dependencies [c924f95]
- Updated dependencies [471d47d]
- Updated dependencies [c951eec]
- @blaze-cardano/tx@0.6.0
- @blaze-cardano/uplc@0.1.29
- @blaze-cardano/wallet@0.1.55

## 0.1.35

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blaze-cardano/sdk",
"version": "0.1.35",
"version": "0.2.1",
"description": "Blaze cardano sdk library",
"exports": {
".": {
Expand Down
16 changes: 11 additions & 5 deletions packages/blaze-sdk/src/blaze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export class Blaze<ProviderType extends Provider, WalletType extends Wallet> {
const changeAddress = await this.wallet.getChangeAddress();
tx.setNetworkId(await this.wallet.getNetworkId())
.addUnspentOutputs(myUtxos)
.setChangeAddress(changeAddress)
.useEvaluator((x, y) => this.provider.evaluateTransaction(x, y));
// We do not want to override the change address if it was already set
.setChangeAddress(changeAddress, false)
.useEvaluator((x, y) => this.provider.evaluateTransaction(x, y), false);
});
}

Expand Down Expand Up @@ -95,9 +96,14 @@ export class Blaze<ProviderType extends Provider, WalletType extends Wallet> {
* @returns {Promise<TransactionId>} - The transaction ID.
* @throws {Error} If the transaction submission fails.
* @description This method sends the provided transaction to the blockchain network
* using the configured provider.
* using the configured wallet, or the configured provider if set.
*/
async submitTransaction(tx: Transaction): Promise<TransactionId> {
return this.provider.postTransactionToChain(tx);
async submitTransaction(
tx: Transaction,
useProvider?: boolean,
): Promise<TransactionId> {
return useProvider
? this.provider.postTransactionToChain(tx)
: this.wallet.postTransaction(tx);
}
}
17 changes: 17 additions & 0 deletions packages/blaze-tx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @blaze-cardano/tx

## 0.6.1

### Patch Changes

- 88ee831: Small fee calculation fix

## 0.6.0

### Minor Changes

- 471d47d: Submit built transactions through the wallet by default, while allowing a provider option.

### Patch Changes

- c924f95: Fix fee calculation before evaluation
- c951eec: avoid preCompleteHook overriding user selections

## 0.5.17

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-tx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blaze-cardano/tx",
"version": "0.5.17",
"version": "0.6.1",
"description": "Blaze cardano transaction building library",
"exports": {
".": {
Expand Down
41 changes: 32 additions & 9 deletions packages/blaze-tx/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class TxBuilder {
private scriptScope: Set<Script> = new Set(); // A set of scripts included in the transaction.
private scriptSeen: Set<ScriptHash> = new Set(); // A set of script hashes that have been processed.
private changeAddress?: Address; // The address to send change to, if any.
private collateralChangeAddress?: Address; // The address to send collateral change to, if any.
private rewardAddress?: Address; // The reward address to delegate from, if any.
private networkId?: NetworkId; // The network ID for the transaction.
private changeOutputIndex?: number; // The index of the change output in the transaction.
Expand Down Expand Up @@ -165,10 +166,25 @@ export class TxBuilder {
* This address will receive any remaining funds not allocated to outputs or fees.
*
* @param {Address} address - The address to receive the change.
* @param {boolean} [override=true] - Whether to override the change address if one is already set.
* @returns {TxBuilder} The same transaction builder
*/
setChangeAddress(address: Address): TxBuilder {
this.changeAddress = address;
setChangeAddress(address: Address, override = true): TxBuilder {
if (override || !this.changeAddress) {
this.changeAddress = address;
}
return this;
}

/**
* Sets the collateral change address for the transaction.
* This address will receive the collateral change if there is any.
*
* @param {Address} address - The address to receive the collateral change.
* @returns {TxBuilder} The same transaction builder
*/
setCollateralChangeAddress(address: Address): TxBuilder {
this.collateralChangeAddress = address;
return this;
}

Expand All @@ -189,10 +205,13 @@ export class TxBuilder {
* The evaluator is used to execute Plutus scripts during transaction building.
*
* @param {Evaluator} evaluator - The evaluator to be used for script execution.
* @param {boolean} [override=true] - Whether to override the evaluator if one is already set.
* @returns {TxBuilder} The same transaction builder
*/
useEvaluator(evaluator: Evaluator): TxBuilder {
this.evaluator = evaluator;
useEvaluator(evaluator: Evaluator, override = true): TxBuilder {
if (override || !this.evaluator) {
this.evaluator = evaluator;
}
return this;
}

Expand Down Expand Up @@ -1316,7 +1335,7 @@ export class TxBuilder {
}
// Also set the collateral return to the output of the selected UTXO.
const ret = new TransactionOutput(
this.changeAddress!,
this.collateralChangeAddress ?? this.changeAddress!,
best.reduce(
(acc, x) => value.merge(acc, x.output().amount()),
value.zero(),
Expand Down Expand Up @@ -1394,8 +1413,9 @@ export class TxBuilder {
// Calculate the total collateral based on the transaction fee and collateral percentage.
const totalCollateral = BigInt(
Math.ceil(
this.params.collateralPercentage *
Number(bigintMax(this.fee, this.minimumFee) + this.feePadding),
(this.params.collateralPercentage *
Number(bigintMax(this.fee, this.minimumFee) + this.feePadding)) /
100,
),
);
// Calculate the collateral value by summing up the amounts from collateral inputs.
Expand Down Expand Up @@ -1558,7 +1578,10 @@ export class TxBuilder {
this.calculateFees(draft_tx);
excessValue = value.merge(
excessValue,
new Value(-(bigintMax(this.fee, this.minimumFee) + this.feePadding)),
new Value(
-(bigintMax(this.fee, this.minimumFee) + this.feePadding) +
BigInt(preliminaryFee),
),
);
this.balanceChange(excessValue);
let evaluationFee: bigint = 0n;
Expand Down Expand Up @@ -1598,7 +1621,7 @@ export class TxBuilder {
"A transaction was built using fee padding. This is useful for working around changes to fee calculation, but ultimately is a bandaid. If you find yourself needing this, please open a ticket at https://github.com/butaneprotocol/blaze-cardano so we can fix the underlying inaccuracy!",
);
}
let final_size = draft_tx.toCbor().length / 2;
let final_size = draft_size;
do {
const oldEvaluationFee = evaluationFee;
this.fee += BigInt(
Expand Down
16 changes: 16 additions & 0 deletions packages/blaze-uplc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @blaze-cardano/uplc

## 0.1.30

### Patch Changes

- Updated dependencies [88ee831]
- @blaze-cardano/tx@0.6.1

## 0.1.29

### Patch Changes

- Updated dependencies [c924f95]
- Updated dependencies [471d47d]
- Updated dependencies [c951eec]
- @blaze-cardano/tx@0.6.0

## 0.1.28

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-uplc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blaze-cardano/uplc",
"version": "0.1.28",
"version": "0.1.30",
"description": "Blaze untyped plutus core library",
"exports": {
".": {
Expand Down
3 changes: 2 additions & 1 deletion packages/blaze-uplc/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CborReader,
CborWriter,
CborReaderState,
PlutusV3Script,
} from "@blaze-cardano/core";
import { HexBlob } from "@blaze-cardano/core";
import { UPLCDecoder } from "./decoder";
Expand Down Expand Up @@ -123,7 +124,7 @@ export function cborToScript(cbor: string, type: ScriptType): Script {
} else if (type === "PlutusV2") {
return Script.newPlutusV2Script(new PlutusV2Script(cborHex));
} else {
throw new Error("Unsupported script type");
return Script.newPlutusV3Script(new PlutusV3Script(cborHex));
}
}
}
16 changes: 16 additions & 0 deletions packages/blaze-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @blaze-cardano/wallet

## 0.1.56

### Patch Changes

- Updated dependencies [88ee831]
- @blaze-cardano/tx@0.6.1

## 0.1.55

### Patch Changes

- Updated dependencies [c924f95]
- Updated dependencies [471d47d]
- Updated dependencies [c951eec]
- @blaze-cardano/tx@0.6.0

## 0.1.54

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blaze-cardano/wallet",
"version": "0.1.54",
"version": "0.1.56",
"description": "Blaze cardano wallet library",
"exports": {
".": {
Expand Down

0 comments on commit 5a4ecf2

Please sign in to comment.