Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for olympus swaps #1193

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.mutinywallet.mutinywallet"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 66
versionName "1.7.5"
versionCode 68
versionName "1.7.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
4 changes: 2 additions & 2 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.7.5;
MARKETING_VERSION = 1.7.7;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = "com.mutinywallet.mutiny-test";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -387,7 +387,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.7.5;
MARKETING_VERSION = 1.7.7;
PRODUCT_BUNDLE_IDENTIFIER = com.mutinywallet.mutiny;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mutiny-wallet",
"version": "1.7.5",
"version": "1.7.7",
"license": "MIT",
"packageManager": "[email protected]",
"scripts": {
Expand Down Expand Up @@ -56,7 +56,7 @@
"@kobalte/core": "^0.12.6",
"@kobalte/tailwindcss": "^0.9.0",
"@modular-forms/solid": "^0.20.0",
"@mutinywallet/mutiny-wasm": "1.7.5",
"@mutinywallet/mutiny-wasm": "1.7.7",
"@sentry/browser": "^8.7.0",
"@sentry/vite-plugin": "^2.18.0",
"@solid-primitives/upload": "^0.0.117",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

29 changes: 17 additions & 12 deletions src/routes/SwapLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function SwapLightning() {
);

const [amountSats, setAmountSats] = createSignal(0n);
const [invoice, setInvoice] = createSignal("");
const [feeSats, setFeeSats] = createSignal(0n);
const [maxFederationBalanceBeforeSwap, setMaxFederationBalanceBeforeSwap] =
createSignal(0n);
Expand All @@ -69,15 +70,11 @@ export function SwapLightning() {
setLoading(true);
setFeeEstimateWarning(undefined);

if (isMax()) {
const result = await sw.sweep_federation_balance(undefined);

setSweepResult({ result: result });
} else {
const result = await sw.sweep_federation_balance(amountSats());

setSweepResult({ result: result });
}
const result = await sw.sweep_federation_balance_to_invoice(
undefined,
invoice()
);
setSweepResult({ result: result });

await vibrateSuccess();
} catch (e) {
Expand Down Expand Up @@ -129,12 +126,20 @@ export function SwapLightning() {
setLoading(true);
setFeeEstimateWarning(undefined);

const fee = await sw.estimate_sweep_federation_fee(
const mutinyInvoice = await sw.create_sweep_federation_invoice(
isMax() ? undefined : amountSats()
);

if (fee) {
setFeeSats(fee);
if (mutinyInvoice.bolt11) {
setInvoice(mutinyInvoice.bolt11);
} else {
console.error("No invoice created");
// this should never happen
throw new Error("No invoice created");
}

if (mutinyInvoice.fees_paid) {
setFeeSats(mutinyInvoice.fees_paid);
}
setMaxFederationBalanceBeforeSwap(calculateMaxFederation());

Expand Down
32 changes: 16 additions & 16 deletions src/routes/Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ export function Transfer() {
if (!fromFed()) throw new Error("No from federation");
if (!toFed()) throw new Error("No to federation");

if (isMax()) {
const result = await sw.sweep_federation_balance(
undefined,
fromFed()?.federation_id,
toFed()?.federation_id
);

setTransferResult({ result: result });
} else {
const result = await sw.sweep_federation_balance(
amountSats(),
fromFed()?.federation_id,
toFed()?.federation_id
);

setTransferResult({ result: result });
const mutinyInvoice = await sw.create_sweep_federation_invoice(
isMax() ? undefined : amountSats(),
fromFed()?.federation_id,
toFed()?.federation_id
);

if (!mutinyInvoice.bolt11) {
// this should never happen
throw new Error("No invoice created");
}

const result = await sw.sweep_federation_balance_to_invoice(
fromFed()?.federation_id,
mutinyInvoice.bolt11
);

setTransferResult({ result: result });

await vibrateSuccess();
} catch (e) {
const error = eify(e);
Expand Down
34 changes: 21 additions & 13 deletions src/workers/walletWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1588,31 +1588,39 @@ export async function estimate_sweep_channel_open_fee(

/**
* Sweep the federation balance into a lightning channel
* @param {bigint | undefined} [amount]
* @param {string | undefined} [from_federation_id]
* @param {string} [invoice]
* @returns {Promise<FedimintSweepResult>}
*/
export async function sweep_federation_balance(
amount?: bigint,
from_federation_id?: string,
to_federation_id?: string
export async function sweep_federation_balance_to_invoice(
from_federation_id: string | undefined,
invoice: string
): Promise<FedimintSweepResult> {
const result = await wallet!.sweep_federation_balance(
amount,
const result = await wallet!.sweep_federation_balance_to_invoice(
from_federation_id,
to_federation_id
invoice
);
return { ...result.value } as FedimintSweepResult;
}

/**
* Estimate the fee before trying to sweep from federation
* @param {bigint | undefined} [amount]
* @returns {Promise<bigint | undefined>}
* @param {string | undefined} [from_federation_id]
* @param {string | undefined} [to_federation_id]
* @returns {Promise<MutinyInvoice>}
*/
export async function estimate_sweep_federation_fee(
amount?: bigint
): Promise<bigint | undefined> {
return await wallet!.estimate_sweep_federation_fee(amount);
export async function create_sweep_federation_invoice(
amount?: bigint,
from_federation_id?: string,
to_federation_id?: string
): Promise<MutinyInvoice> {
const invoice = await wallet!.create_sweep_federation_invoice(
amount,
from_federation_id,
to_federation_id
);
return destructureInvoice(invoice);
}

export async function parse_params(params: string): Promise<PaymentParams> {
Expand Down
Loading