Skip to content

Commit 1cd2f3e

Browse files
committed
feat: wip tx lvl fees
1 parent 3d13273 commit 1cd2f3e

File tree

9 files changed

+60
-9
lines changed

9 files changed

+60
-9
lines changed

apps/namadillo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@keplr-wallet/types": "^0.12.136",
1313
"@namada/chain-registry": "^1.5.2",
1414
"@namada/indexer-client": "4.0.5",
15-
"@namada/sdk-multicore": "0.23.0",
15+
"@namada/sdk-multicore": "file:.yalc/@namada/sdk-multicore",
1616
"@tailwindcss/container-queries": "^0.1.1",
1717
"@tanstack/query-core": "^5.40.0",
1818
"@tanstack/react-query": "^5.40.0",

apps/namadillo/public/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
#masp_indexer_url = ""
55
#localnet_enabled = false
66
#fathom_site_id = ""
7+
8+
[server_fee]
9+
target = "znam175uaqlukleyjjyfcccehp2pw3g696a57skewlv0fenldlw702gtjd6qkpjs09zxl6jafsz3e73h"
10+
percentage = 0.05
11+
max_value = 100

apps/namadillo/src/atoms/settings/atoms.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ export const maspIndexerUrlAtom = atom((get) => {
175175
return "";
176176
});
177177

178+
// TODO: figure out where to have this atom
179+
export const serverFeeAtom = atom((get) => {
180+
const serverFee = get(defaultServerConfigAtom).data?.server_fee;
181+
return (
182+
serverFee && {
183+
target: serverFee.target,
184+
percentage: serverFee.percentage,
185+
maxValue: serverFee.max_value,
186+
}
187+
);
188+
});
189+
178190
export const updateIndexerUrlAtom = atomWithMutation(() => {
179191
return {
180192
mutationKey: ["update-indexer-url"],

apps/namadillo/src/atoms/transfer/atoms.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ export const createShieldingTransferAtom = atomWithMutation((get) => {
103103
gasConfig,
104104
account,
105105
memo,
106+
frontendFeeConfig,
106107
}: BuildTxAtomParams<ShieldingTransferProps>) =>
107108
createShieldingTransferTx(
108109
chain.data!,
109110
account,
110111
params,
111112
gasConfig,
112113
rpcUrl,
113-
memo
114+
memo,
115+
frontendFeeConfig
114116
),
115117
};
116118
});

apps/namadillo/src/atoms/transfer/services.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import BigNumber from "bignumber.js";
1717
import * as Comlink from "comlink";
1818
import { NamadaKeychain } from "hooks/useNamadaKeychain";
1919
import { buildTx, EncodedTxData, isPublicKeyRevealed } from "lib/query";
20-
import { Address, ChainSettings, GasConfig } from "types";
20+
import { Address, ChainSettings, FrontendFeeConfig, GasConfig } from "types";
2121
import { getSdkInstance } from "utils/sdk";
2222
import {
2323
IbcTransfer,
@@ -168,7 +168,8 @@ export const createShieldingTransferTx = async (
168168
props: ShieldingTransferProps[],
169169
gasConfig: GasConfig,
170170
rpcUrl: string,
171-
memo?: string
171+
memo?: string,
172+
frontendFeeConfig?: FrontendFeeConfig
172173
): Promise<EncodedTxData<ShieldingTransferProps> | undefined> => {
173174
const source = props[0]?.data[0]?.source;
174175
const destination = props[0]?.target;
@@ -184,6 +185,9 @@ export const createShieldingTransferTx = async (
184185
ledger.closeTransport();
185186
}
186187

188+
const susFeeAmount = frontendFeeConfig?.percentage.times(amount);
189+
// console.log("susFeeAmount", susFeeAmount?.toString(), frontendFeeConfig);
190+
187191
return await workerBuildTxPair({
188192
rpcUrl,
189193
nativeToken: chain.nativeTokenAddress,
@@ -193,6 +197,10 @@ export const createShieldingTransferTx = async (
193197
target: destination,
194198
data: [{ source, token, amount }],
195199
bparams,
200+
frontendSusFee: frontendFeeConfig && {
201+
address: frontendFeeConfig.target,
202+
amount: BigInt(susFeeAmount!.toNumber()),
203+
},
196204
};
197205
const msg: Shield = {
198206
type: "shield",

apps/namadillo/src/hooks/useTransaction.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export const useTransaction = <T,>({
147147
params,
148148
gasConfig: feeProps.gasConfig,
149149
account,
150+
frontendFeeConfig: feeProps.frontendFeeConfig,
150151
...txAdditionalParams,
151152
};
152153
const encodedTxData = await performBuildTx(variables);

apps/namadillo/src/hooks/useTransactionFee/useTransactionFee.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
isPublicKeyRevealedAtom,
1010
} from "atoms/fees";
1111
import { tokenPricesFamily } from "atoms/prices/atoms";
12+
import { serverFeeAtom } from "atoms/settings";
1213
import BigNumber from "bignumber.js";
1314
import invariant from "invariant";
1415
import { useAtomValue } from "jotai";
1516
import { useMemo, useState } from "react";
16-
import { GasConfig } from "types";
17+
import { FrontendFeeConfig, GasConfig } from "types";
1718
import { TxKind } from "types/txKind";
1819
import { findCheapestToken } from "./internal";
1920

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

2931
export const useTransactionFee = (
@@ -35,6 +37,7 @@ export const useTransactionFee = (
3537
const userTransparentBalances = useAtomValue(transparentBalanceAtom);
3638
const userShieldedBalances = useAtomValue(shieldedBalanceAtom);
3739
const isPublicKeyRevealed = useAtomValue(isPublicKeyRevealedAtom);
40+
const serverFee = useAtomValue(serverFeeAtom);
3841

3942
const { data: nativeToken, isLoading: isLoadingNativeToken } = useAtomValue(
4043
nativeTokenAddressAtom
@@ -137,6 +140,12 @@ export const useTransactionFee = (
137140
gasToken,
138141
};
139142

143+
const frontendFeeConfig = serverFee && {
144+
target: serverFee.target,
145+
percentage: BigNumber(serverFee.percentage),
146+
maxFeeInMinDenom: serverFee.maxValue && BigNumber(serverFee.maxValue),
147+
};
148+
140149
const isLoading =
141150
userTransparentBalances.isLoading ||
142151
isLoadingNativeToken ||
@@ -145,6 +154,7 @@ export const useTransactionFee = (
145154

146155
return {
147156
gasConfig,
157+
frontendFeeConfig,
148158
isLoading,
149159
gasEstimate,
150160
gasPriceTable,

apps/namadillo/src/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Unique = {
2626
export type PublicKey = string;
2727

2828
export type Address = string;
29+
export type PaymentAddress = string;
2930

3031
export type BaseDenom = string;
3132

@@ -46,6 +47,12 @@ export type GasConfig = {
4647
gasToken: GasToken;
4748
};
4849

50+
export type FrontendFeeConfig = {
51+
target: Address | PaymentAddress;
52+
percentage: BigNumber;
53+
maxValue?: BigNumber;
54+
};
55+
4956
export type GasConfigToDisplay = {
5057
totalDisplayAmount: BigNumber;
5158
asset: Asset;
@@ -71,6 +78,11 @@ export type SettingsTomlOptions = {
7178
rpc_url?: string;
7279
localnet_enabled?: boolean;
7380
fathom_site_id?: string;
81+
server_fee?: {
82+
target: string;
83+
percentage: number;
84+
max_value?: number;
85+
};
7486
};
7587

7688
export type ChainParameters = {
@@ -184,6 +196,7 @@ export type BuildTxAtomParams<T> = {
184196
gasConfig: GasConfig;
185197
memo?: string;
186198
signer?: Signer;
199+
frontendFeeConfig?: FrontendFeeConfig;
187200
};
188201

189202
export type SortOptions = "asc" | "desc" | undefined;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ __metadata:
37723772
"@keplr-wallet/types": "npm:^0.12.136"
37733773
"@namada/chain-registry": "npm:^1.5.2"
37743774
"@namada/indexer-client": "npm:4.0.5"
3775-
"@namada/sdk-multicore": "npm:0.23.0"
3775+
"@namada/sdk-multicore": "file:.yalc/@namada/sdk-multicore"
37763776
"@namada/sdk-node": "npm:0.23.0"
37773777
"@namada/vite-esbuild-plugin": "npm:^1.0.1"
37783778
"@playwright/test": "npm:^1.24.1"
@@ -3858,9 +3858,9 @@ __metadata:
38583858
languageName: unknown
38593859
linkType: soft
38603860

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

0 commit comments

Comments
 (0)