Skip to content
Draft
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
2 changes: 1 addition & 1 deletion apps/namadillo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@keplr-wallet/types": "^0.12.136",
"@namada/chain-registry": "^1.5.2",
"@namada/indexer-client": "4.0.5",
"@namada/sdk-multicore": "0.23.0",
"@namada/sdk-multicore": "file:.yalc/@namada/sdk-multicore",
"@tailwindcss/container-queries": "^0.1.1",
"@tanstack/query-core": "^5.40.0",
"@tanstack/react-query": "^5.40.0",
Expand Down
5 changes: 5 additions & 0 deletions apps/namadillo/public/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
#masp_indexer_url = ""
#localnet_enabled = false
#fathom_site_id = ""

[server_fee]
target = "znam175uaqlukleyjjyfcccehp2pw3g696a57skewlv0fenldlw702gtjd6qkpjs09zxl6jafsz3e73h"
percentage = 0.05
max_value = 100
12 changes: 12 additions & 0 deletions apps/namadillo/src/atoms/settings/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ export const maspIndexerUrlAtom = atom((get) => {
return "";
});

// TODO: figure out where to have this atom
export const serverFeeAtom = atom((get) => {
const serverFee = get(defaultServerConfigAtom).data?.server_fee;
return (
serverFee && {
target: serverFee.target,
percentage: serverFee.percentage,
maxValue: serverFee.max_value,
}
);
});

export const updateIndexerUrlAtom = atomWithMutation(() => {
return {
mutationKey: ["update-indexer-url"],
Expand Down
4 changes: 3 additions & 1 deletion apps/namadillo/src/atoms/transfer/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ export const createShieldingTransferAtom = atomWithMutation((get) => {
gasConfig,
account,
memo,
frontendFeeConfig,
}: BuildTxAtomParams<ShieldingTransferProps>) =>
createShieldingTransferTx(
chain.data!,
account,
params,
gasConfig,
rpcUrl,
memo
memo,
frontendFeeConfig
),
};
});
Expand Down
12 changes: 10 additions & 2 deletions apps/namadillo/src/atoms/transfer/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import BigNumber from "bignumber.js";
import * as Comlink from "comlink";
import { NamadaKeychain } from "hooks/useNamadaKeychain";
import { buildTx, EncodedTxData, isPublicKeyRevealed } from "lib/query";
import { Address, ChainSettings, GasConfig } from "types";
import { Address, ChainSettings, FrontendFeeConfig, GasConfig } from "types";
import { getSdkInstance } from "utils/sdk";
import {
IbcTransfer,
Expand Down Expand Up @@ -168,7 +168,8 @@ export const createShieldingTransferTx = async (
props: ShieldingTransferProps[],
gasConfig: GasConfig,
rpcUrl: string,
memo?: string
memo?: string,
frontendFeeConfig?: FrontendFeeConfig
): Promise<EncodedTxData<ShieldingTransferProps> | undefined> => {
const source = props[0]?.data[0]?.source;
const destination = props[0]?.target;
Expand All @@ -184,6 +185,9 @@ export const createShieldingTransferTx = async (
ledger.closeTransport();
}

const susFeeAmount = frontendFeeConfig?.percentage.times(amount);
// console.log("susFeeAmount", susFeeAmount?.toString(), frontendFeeConfig);

return await workerBuildTxPair({
rpcUrl,
nativeToken: chain.nativeTokenAddress,
Expand All @@ -193,6 +197,10 @@ export const createShieldingTransferTx = async (
target: destination,
data: [{ source, token, amount }],
bparams,
frontendSusFee: frontendFeeConfig && {
address: frontendFeeConfig.target,
amount: BigInt(susFeeAmount!.toNumber()),
},
};
const msg: Shield = {
type: "shield",
Expand Down
1 change: 1 addition & 0 deletions apps/namadillo/src/hooks/useTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const useTransaction = <T,>({
params,
gasConfig: feeProps.gasConfig,
account,
frontendFeeConfig: feeProps.frontendFeeConfig,
...txAdditionalParams,
};
const encodedTxData = await performBuildTx(variables);
Expand Down
12 changes: 11 additions & 1 deletion apps/namadillo/src/hooks/useTransactionFee/useTransactionFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {
isPublicKeyRevealedAtom,
} from "atoms/fees";
import { tokenPricesFamily } from "atoms/prices/atoms";
import { serverFeeAtom } from "atoms/settings";
import BigNumber from "bignumber.js";
import invariant from "invariant";
import { useAtomValue } from "jotai";
import { useMemo, useState } from "react";
import { GasConfig } from "types";
import { FrontendFeeConfig, GasConfig } from "types";
import { TxKind } from "types/txKind";
import { findCheapestToken } from "./internal";

Expand All @@ -24,6 +25,7 @@ export type TransactionFeeProps = {
gasPriceTable: GasPriceTable | undefined;
onChangeGasLimit: (value: BigNumber) => void;
onChangeGasToken: (value: string) => void;
frontendFeeConfig?: FrontendFeeConfig;
};

export const useTransactionFee = (
Expand All @@ -35,6 +37,7 @@ export const useTransactionFee = (
const userTransparentBalances = useAtomValue(transparentBalanceAtom);
const userShieldedBalances = useAtomValue(shieldedBalanceAtom);
const isPublicKeyRevealed = useAtomValue(isPublicKeyRevealedAtom);
const serverFee = useAtomValue(serverFeeAtom);

const { data: nativeToken, isLoading: isLoadingNativeToken } = useAtomValue(
nativeTokenAddressAtom
Expand Down Expand Up @@ -137,6 +140,12 @@ export const useTransactionFee = (
gasToken,
};

const frontendFeeConfig = serverFee && {
target: serverFee.target,
percentage: BigNumber(serverFee.percentage),
maxFeeInMinDenom: serverFee.maxValue && BigNumber(serverFee.maxValue),
};

const isLoading =
userTransparentBalances.isLoading ||
isLoadingNativeToken ||
Expand All @@ -145,6 +154,7 @@ export const useTransactionFee = (

return {
gasConfig,
frontendFeeConfig,
isLoading,
gasEstimate,
gasPriceTable,
Expand Down
13 changes: 13 additions & 0 deletions apps/namadillo/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Unique = {
export type PublicKey = string;

export type Address = string;
export type PaymentAddress = string;

export type BaseDenom = string;

Expand All @@ -46,6 +47,12 @@ export type GasConfig = {
gasToken: GasToken;
};

export type FrontendFeeConfig = {
target: Address | PaymentAddress;
percentage: BigNumber;
maxValue?: BigNumber;
};

export type GasConfigToDisplay = {
totalDisplayAmount: BigNumber;
asset: Asset;
Expand All @@ -71,6 +78,11 @@ export type SettingsTomlOptions = {
rpc_url?: string;
localnet_enabled?: boolean;
fathom_site_id?: string;
server_fee?: {
target: string;
percentage: number;
max_value?: number;
};
};

export type ChainParameters = {
Expand Down Expand Up @@ -184,6 +196,7 @@ export type BuildTxAtomParams<T> = {
gasConfig: GasConfig;
memo?: string;
signer?: Signer;
frontendFeeConfig?: FrontendFeeConfig;
};

export type SortOptions = "asc" | "desc" | undefined;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3772,7 +3772,7 @@ __metadata:
"@keplr-wallet/types": "npm:^0.12.136"
"@namada/chain-registry": "npm:^1.5.2"
"@namada/indexer-client": "npm:4.0.5"
"@namada/sdk-multicore": "npm:0.23.0"
"@namada/sdk-multicore": "file:.yalc/@namada/sdk-multicore"
"@namada/sdk-node": "npm:0.23.0"
"@namada/vite-esbuild-plugin": "npm:^1.0.1"
"@playwright/test": "npm:^1.24.1"
Expand Down Expand Up @@ -3858,9 +3858,9 @@ __metadata:
languageName: unknown
linkType: soft

"@namada/sdk-multicore@npm:0.23.0":
"@namada/sdk-multicore@file:.yalc/@namada/sdk-multicore::locator=%40namada%2Fnamadillo%40workspace%3Aapps%2Fnamadillo":
version: 0.23.0
resolution: "@namada/sdk-multicore@npm:0.23.0"
resolution: "@namada/sdk-multicore@file:.yalc/@namada/sdk-multicore#.yalc/@namada/sdk-multicore::hash=33de7f&locator=%40namada%2Fnamadillo%40workspace%3Aapps%2Fnamadillo"
dependencies:
"@cosmjs/encoding": "npm:^0.29.0"
"@dao-xyz/borsh": "npm:^5.1.5"
Expand All @@ -3871,7 +3871,7 @@ __metadata:
buffer: "npm:^6.0.3"
semver: "npm:^7.7.2"
slip44: "npm:^3.0.18"
checksum: 10c0/435a2a08f4abbffbc62ad1f164f8ca5d9700eec53a4930508f73dff09ddcfc06081f6bad1fe6811d18d5ad9695ed2237a559b395eed907327c9a7f955a454723
checksum: 10c0/5b644a9afdbccba851a40678c171fb66d3efb0091b691b189807c45459e9cd98460f167081a1402d4b665a422e0d1a022ab12f4cb48f4d20eb0c3103500f18ed
languageName: node
linkType: hard

Expand Down
Loading