diff --git a/apps/namadillo/package.json b/apps/namadillo/package.json index 978efe681e..4e1e808b8d 100644 --- a/apps/namadillo/package.json +++ b/apps/namadillo/package.json @@ -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", diff --git a/apps/namadillo/public/config.toml b/apps/namadillo/public/config.toml index 9e4e902e0a..d3e067c86a 100644 --- a/apps/namadillo/public/config.toml +++ b/apps/namadillo/public/config.toml @@ -4,3 +4,8 @@ #masp_indexer_url = "" #localnet_enabled = false #fathom_site_id = "" + +[server_fee] +target = "znam175uaqlukleyjjyfcccehp2pw3g696a57skewlv0fenldlw702gtjd6qkpjs09zxl6jafsz3e73h" +percentage = 0.05 +max_value = 100 diff --git a/apps/namadillo/src/atoms/settings/atoms.ts b/apps/namadillo/src/atoms/settings/atoms.ts index e223bfc194..bfb310623b 100644 --- a/apps/namadillo/src/atoms/settings/atoms.ts +++ b/apps/namadillo/src/atoms/settings/atoms.ts @@ -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"], diff --git a/apps/namadillo/src/atoms/transfer/atoms.ts b/apps/namadillo/src/atoms/transfer/atoms.ts index ba5162b5a8..4d90e4aec0 100644 --- a/apps/namadillo/src/atoms/transfer/atoms.ts +++ b/apps/namadillo/src/atoms/transfer/atoms.ts @@ -103,6 +103,7 @@ export const createShieldingTransferAtom = atomWithMutation((get) => { gasConfig, account, memo, + frontendFeeConfig, }: BuildTxAtomParams) => createShieldingTransferTx( chain.data!, @@ -110,7 +111,8 @@ export const createShieldingTransferAtom = atomWithMutation((get) => { params, gasConfig, rpcUrl, - memo + memo, + frontendFeeConfig ), }; }); diff --git a/apps/namadillo/src/atoms/transfer/services.ts b/apps/namadillo/src/atoms/transfer/services.ts index 9e7ba4e91f..994ca00cb6 100644 --- a/apps/namadillo/src/atoms/transfer/services.ts +++ b/apps/namadillo/src/atoms/transfer/services.ts @@ -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, @@ -168,7 +168,8 @@ export const createShieldingTransferTx = async ( props: ShieldingTransferProps[], gasConfig: GasConfig, rpcUrl: string, - memo?: string + memo?: string, + frontendFeeConfig?: FrontendFeeConfig ): Promise | undefined> => { const source = props[0]?.data[0]?.source; const destination = props[0]?.target; @@ -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, @@ -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", diff --git a/apps/namadillo/src/hooks/useTransaction.tsx b/apps/namadillo/src/hooks/useTransaction.tsx index ca9409c950..67ba7518c7 100644 --- a/apps/namadillo/src/hooks/useTransaction.tsx +++ b/apps/namadillo/src/hooks/useTransaction.tsx @@ -147,6 +147,7 @@ export const useTransaction = ({ params, gasConfig: feeProps.gasConfig, account, + frontendFeeConfig: feeProps.frontendFeeConfig, ...txAdditionalParams, }; const encodedTxData = await performBuildTx(variables); diff --git a/apps/namadillo/src/hooks/useTransactionFee/useTransactionFee.ts b/apps/namadillo/src/hooks/useTransactionFee/useTransactionFee.ts index c2814193f7..a700083e96 100644 --- a/apps/namadillo/src/hooks/useTransactionFee/useTransactionFee.ts +++ b/apps/namadillo/src/hooks/useTransactionFee/useTransactionFee.ts @@ -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"; @@ -24,6 +25,7 @@ export type TransactionFeeProps = { gasPriceTable: GasPriceTable | undefined; onChangeGasLimit: (value: BigNumber) => void; onChangeGasToken: (value: string) => void; + frontendFeeConfig?: FrontendFeeConfig; }; export const useTransactionFee = ( @@ -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 @@ -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 || @@ -145,6 +154,7 @@ export const useTransactionFee = ( return { gasConfig, + frontendFeeConfig, isLoading, gasEstimate, gasPriceTable, diff --git a/apps/namadillo/src/types.ts b/apps/namadillo/src/types.ts index b02739eee2..8c1ac58891 100644 --- a/apps/namadillo/src/types.ts +++ b/apps/namadillo/src/types.ts @@ -26,6 +26,7 @@ type Unique = { export type PublicKey = string; export type Address = string; +export type PaymentAddress = string; export type BaseDenom = string; @@ -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; @@ -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 = { @@ -184,6 +196,7 @@ export type BuildTxAtomParams = { gasConfig: GasConfig; memo?: string; signer?: Signer; + frontendFeeConfig?: FrontendFeeConfig; }; export type SortOptions = "asc" | "desc" | undefined; diff --git a/yarn.lock b/yarn.lock index d643dcfe3c..310e7c7df9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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