Skip to content

Commit

Permalink
fix: gather fuel issue when consuming all of the fuel (#103)
Browse files Browse the repository at this point in the history
Co-authored-by: Rico Miles Quiblat <[email protected]>
  • Loading branch information
ricomiles and Rico Miles Quiblat authored Nov 28, 2024
1 parent f91c0a8 commit c6652f9
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions sdk/blaze/src/asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ async function moveShip(
(value: bigint, asset: AssetId, map: Map<AssetId, bigint>) => {
if (
AssetId.getPolicyId(asset).toLowerCase() ==
shipyard_policy.toLowerCase() &&
shipyard_policy.toLowerCase() &&
AssetId.getAssetName(asset).toLowerCase() ==
old_ship_datum.pilot_token_name.toLowerCase()
old_ship_datum.pilot_token_name.toLowerCase()
) {
pilot_utxo = utxo;
}
Expand Down Expand Up @@ -387,9 +387,9 @@ async function gatherFuel(
(value: bigint, asset: AssetId) => {
if (
AssetId.getPolicyId(asset).toLowerCase() ==
shipyard_policy &&
shipyard_policy &&
AssetId.getAssetName(asset).toLowerCase() ==
old_ship_datum.pilot_token_name
old_ship_datum.pilot_token_name
) {
pilot_utxo = utxo;
}
Expand Down Expand Up @@ -450,7 +450,16 @@ async function gatherFuel(
);

const pellet_change = pellet_fuel - amount_to_gather;

let value_to_lock = makeValue(0n, [
admin_token,
1n,
])
if(pellet_change > 0) {
value_to_lock = makeValue(0n, [fuel_token, pellet_change], [
admin_token,
1n,
]);
}
const tx = blaze
.newTransaction()
.setValidFrom(Slot(lower_bound_slot))
Expand All @@ -469,10 +478,7 @@ async function gatherFuel(
)
.lockAssets(
pellet_validator_address,
makeValue(0n, [fuel_token, pellet_fuel - amount_to_gather], [
admin_token,
1n,
]),
value_to_lock,
new_pellet_datum,
)
.payAssets(blaze.wallet.address, makeValue(0n, [pilot_token, 1n]))
Expand Down Expand Up @@ -657,9 +663,9 @@ async function quit(
(value: bigint, asset: AssetId) => {
if (
AssetId.getPolicyId(asset).toLowerCase() ==
shipyard_policy &&
shipyard_policy &&
AssetId.getAssetName(asset).toLowerCase() ==
old_ship_datum.pilot_token_name
old_ship_datum.pilot_token_name
) {
pilot_utxo = utxo;
}
Expand Down

0 comments on commit c6652f9

Please sign in to comment.