Skip to content

Commit

Permalink
refactor(wasm): fix fee balancing bug for swap claims (#1095)
Browse files Browse the repository at this point in the history
* update rust deps to v0.74

* initial planner port

* modified to use same ActionList impl

* update rust deps to v0.75

* fix memo

* formatting and clippy

* minor organization

* spelling

* manually set gas prices in indexdb

* add prepaid fee logic to planner

* linting

* fmt and clippy

* removed extra types

* remove log

* address comments

* address comments
  • Loading branch information
TalDerei authored May 13, 2024
1 parent adb8644 commit 02eae9b
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 301 deletions.
9 changes: 0 additions & 9 deletions apps/minifront/src/state/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,6 @@ const assembleSwapRequest = async ({ assetIn, amount, assetOut }: SwapSlice) =>
assetId: getAssetIdFromValueView(assetIn.balanceView),
},
claimAddress: await getAddressByIndex(addressIndex.account),
// TODO: Calculate this properly in subsequent PR
// Asset Id should almost certainly be upenumbra,
// may need to indicate native denom in registry
fee: {
amount: {
hi: 0n,
lo: 0n,
},
},
},
],
source: getAddressIndex(assetIn.accountAddress),
Expand Down
19 changes: 19 additions & 0 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export class IndexedDb implements IndexedDbInterface {
const existing0thEpoch = await instance.getEpochByHeight(0n);
if (!existing0thEpoch) await instance.addEpoch(0n); // Create first epoch

// set non-zero gas prices in indexDB since the testnet has not yet enabled gas fees.
await instance.initGasPrices();

return instance;
}

Expand Down Expand Up @@ -279,6 +282,22 @@ export class IndexedDb implements IndexedDbInterface {
);
}

async initGasPrices() {
const savedGasPrices = await this.getGasPrices();
// These are arbitrarily set, but can take on any value.
// The gas prices set here will determine the fees to use Penumbra.
if (!savedGasPrices) {
await this.saveGasPrices(
new GasPrices({
verificationPrice: 1n,
executionPrice: 1n,
blockSpacePrice: 1n,
compactBlockSpacePrice: 1n,
}),
);
}
}

async *iterateTransactions() {
yield* new ReadableStream(
new IdbCursorSource(this.db.transaction('TRANSACTIONS').store.openCursor(), TransactionInfo),
Expand Down
88 changes: 44 additions & 44 deletions packages/wasm/crate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 15 additions & 16 deletions packages/wasm/crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[package]
name = "penumbra-wasm"
version = "2.0.0"
Expand All @@ -17,20 +16,20 @@ mock-database = []
[dependencies]
# TODO: Use `tag` instead of `rev` once auctions land in a tagged release of
# core.
penumbra-auction = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-auction", default-features = false }
penumbra-asset = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-asset" }
penumbra-compact-block = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-compact-block", default-features = false }
penumbra-dex = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-dex", default-features = false }
penumbra-fee = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-fee", default-features = false }
penumbra-keys = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-keys" }
penumbra-num = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-num" }
penumbra-proof-params = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-proof-params", default-features = false }
penumbra-proto = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-proto", default-features = false }
penumbra-sct = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-sct", default-features = false }
penumbra-shielded-pool = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-shielded-pool", default-features = false }
penumbra-stake = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-stake", default-features = false }
penumbra-tct = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-tct" }
penumbra-transaction = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "519f0f023", package = "penumbra-transaction", default-features = false }
penumbra-auction = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-auction", default-features = false }
penumbra-asset = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-asset" }
penumbra-compact-block = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-compact-block", default-features = false }
penumbra-dex = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-dex", default-features = false }
penumbra-fee = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-fee", default-features = false }
penumbra-keys = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-keys" }
penumbra-num = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-num" }
penumbra-proof-params = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-proof-params", default-features = false }
penumbra-proto = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-proto", default-features = false }
penumbra-sct = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-sct", default-features = false }
penumbra-shielded-pool = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-shielded-pool", default-features = false }
penumbra-stake = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-stake", default-features = false }
penumbra-tct = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-tct" }
penumbra-transaction = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.75.0", package = "penumbra-transaction", default-features = false }

anyhow = "1.0.80"
ark-ff = { version = "0.4.2", features = ["std"] }
Expand All @@ -51,4 +50,4 @@ web-sys = { version = "0.3.69", features = ["console"] }

[dev-dependencies]
wasm-bindgen-test = "0.3.42"
serde_json = "1.0.114"
serde_json = "1.0.114"
Loading

0 comments on commit 02eae9b

Please sign in to comment.