Skip to content

Commit f9cd34b

Browse files
committed
add referrer address to config
1 parent d6d7d20 commit f9cd34b

5 files changed

Lines changed: 38 additions & 37 deletions

File tree

evm/ts/src/nttWithExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class EvmNttWithExecutor<N extends Network, C extends EvmChains>
167167
};
168168
const feeArgs = {
169169
dbps: quote.referrerFeeDbps,
170-
payee: quote.referrer.address.toString(),
170+
payee: quote.referrer ? quote.referrer.address.toString() : senderAddress,
171171
};
172172

173173
const data = iface.encodeFunctionData("transfer", [

sdk/definitions/src/nttWithExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export namespace NttWithExecutor {
1313
relayInstructions: Uint8Array; // The relay instructions for the transfer
1414
estimatedCost: bigint; // The estimated cost of the transfer in native token base units
1515
payeeAddress: Uint8Array; // The wallet address on the source chain, designated by the Quoter, to receive funds when requesting an execution
16-
referrer: ChainAddress; // The referrer address (to whom the referrer fee should be paid)
16+
referrer?: ChainAddress; // The referrer address (to whom the referrer fee should be paid, undefined when fee is 0)
1717
referrerFee: bigint; // The referrer fee in NTT token base units
1818
remainingAmount: bigint; // The remaining amount after the referrer fee in NTT token base units
1919
referrerFeeDbps: bigint; // The referrer fee in *tenths* of basis points

sdk/route/src/executor/consts.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
import {
2-
Chain,
3-
chainToPlatform,
4-
Network,
5-
} from "@wormhole-foundation/sdk-connect";
1+
import { Network } from "@wormhole-foundation/sdk-connect";
62

73
export const apiBaseUrl: Partial<Record<Network, string>> = {
84
Mainnet: "https://executor.labsapis.com",
95
Testnet: "https://executor-testnet.labsapis.com",
106
};
11-
12-
// Referrer addresses (to whom the referrer fee should be paid)
13-
export const getReferrerAddress = (chain: Chain): string | undefined => {
14-
if (chainToPlatform(chain) === "Evm") {
15-
return "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E";
16-
}
17-
if (chain === "Solana") {
18-
return "JB3rmygUVuVZzgkxvMdV8mSKLJeQAkSXEK284Dqsziah";
19-
}
20-
};

sdk/route/src/executor/executor.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ import {
3232
serializeLayout,
3333
signSendWait,
3434
toChainId,
35+
Platform,
36+
chainToPlatform,
3537
} from "@wormhole-foundation/sdk-connect";
3638
import "@wormhole-foundation/sdk-definitions-ntt";
3739
import { NttRoute } from "../types.js";
38-
import { getReferrerAddress } from "./consts.js";
3940
import {
4041
calculateReferrerFee,
4142
fetchCapabilities,
@@ -53,13 +54,17 @@ import {
5354
export namespace NttExecutorRoute {
5455
export type Config = {
5556
ntt: NttRoute.Config;
57+
referrerFee?: ReferrerFeeConfig;
58+
};
59+
60+
export type ReferrerFeeConfig = {
5661
// Referrer Fee in *tenths* of basis points - e.g. 10 = 1 basis point (0.01%)
57-
referrerFeeDbps?: bigint;
58-
perTokenOverrides?: {
59-
chain: Chain;
60-
address: string;
61-
referrerFeeDbps: bigint;
62-
}[];
62+
feeDbps: bigint;
63+
// The address to which the referrer fee will be sent
64+
referrerAddresses: Partial<Record<Platform, string>>;
65+
perTokenOverrides?: Partial<
66+
Record<Chain, Record<string, { referrerFeeDbps: bigint }>>
67+
>;
6368
};
6469

6570
export type Options = {
@@ -191,15 +196,18 @@ export class NttExecutorRoute<N extends Network>
191196
request.destination.id
192197
);
193198

194-
let referrerFeeDbps = this.staticConfig.referrerFeeDbps ?? 0n;
195-
if (this.staticConfig.perTokenOverrides) {
196-
const srcTokenAddress = canonicalAddress(request.source.id);
197-
const override = this.staticConfig.perTokenOverrides.find(
198-
(o) =>
199-
o.chain === request.source.id.chain && o.address === srcTokenAddress
200-
);
201-
if (override) {
202-
referrerFeeDbps = override.referrerFeeDbps;
199+
let referrerFeeDbps = 0n;
200+
if (this.staticConfig.referrerFee) {
201+
referrerFeeDbps = this.staticConfig.referrerFee.feeDbps;
202+
if (this.staticConfig.referrerFee.perTokenOverrides) {
203+
const srcTokenAddress = canonicalAddress(request.source.id);
204+
const override =
205+
this.staticConfig.referrerFee.perTokenOverrides[
206+
request.source.id.chain
207+
]?.[srcTokenAddress];
208+
if (override) {
209+
referrerFeeDbps = override.referrerFeeDbps;
210+
}
203211
}
204212
}
205213

@@ -302,11 +310,17 @@ export class NttExecutorRoute<N extends Network>
302310
): Promise<NttWithExecutor.Quote> {
303311
const { fromChain, toChain } = request;
304312

305-
const referrerAddress = getReferrerAddress(fromChain.chain);
306-
if (!referrerAddress) {
307-
throw new Error("No referrer address found");
313+
let referrer: ChainAddress | undefined = undefined;
314+
const referrerFeeConfig = this.staticConfig.referrerFee;
315+
if (referrerFeeConfig && referrerFeeConfig.feeDbps > 0n) {
316+
const platform = chainToPlatform(fromChain.chain);
317+
const referrerAddress =
318+
referrerFeeConfig.referrerAddresses?.[platform] ?? "";
319+
if (!referrerAddress) {
320+
throw new Error("No referrer address found");
321+
}
322+
referrer = Wormhole.chainAddress(fromChain.chain, referrerAddress);
308323
}
309-
const referrer = Wormhole.chainAddress(fromChain.chain, referrerAddress);
310324

311325
const { referrerFee, remainingAmount, referrerFeeDbps } =
312326
calculateReferrerFee(

solana/ts/sdk/nttWithExecutor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class SolanaNttWithExecutor<N extends Network, C extends SolanaChains>
119119
);
120120

121121
if (quote.referrerFee > 0n) {
122+
if (!quote.referrer) throw new Error("referrer is required");
122123
const referrer = new PublicKey(quote.referrer.address.toString());
123124
const { mint } = await ntt.getConfig();
124125
const referrerAta = getAssociatedTokenAddressSync(

0 commit comments

Comments
 (0)