Skip to content

Commit

Permalink
Merge pull request connext#5655 from connext/5654-relayer-whitelisting
Browse files Browse the repository at this point in the history
feat: update gelato addresses
  • Loading branch information
preethamr authored Feb 7, 2024
2 parents 412283b + ed340e9 commit 7a1b0fb
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 76 deletions.
5 changes: 3 additions & 2 deletions packages/adapters/relayer/src/gelato/gelato.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
RelayRequestOptions,
NATIVE_TOKEN,
RelayerRequest,
GELATO_RELAYER_ADDRESS,
getGelatoRelayerAddress,
chainIdToDomain,
} from "@connext/nxtp-utils";
import interval from "interval-promise";

Expand Down Expand Up @@ -192,7 +193,7 @@ const GAS_LIMIT_FOR_RELAYER = (chainId: number): string => {
};

export const getRelayerAddress = async (_chainId: number): Promise<string> => {
return Promise.resolve(GELATO_RELAYER_ADDRESS);
return Promise.resolve(getGelatoRelayerAddress(chainIdToDomain(_chainId).toString()));
};

export const send = async (
Expand Down
17 changes: 9 additions & 8 deletions packages/adapters/relayer/test/gelato/gelato.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
expect,
mock,
Logger,
GELATO_RELAYER_ADDRESS,
getGelatoRelayerAddress,
RelayerTaskStatus,
mkBytes32,
createRequestContext,
chainIdToDomain,
} from "@connext/nxtp-utils";
import { ChainReader } from "@connext/nxtp-txservice";
import { mockChainReader } from "@connext/nxtp-txservice/test/mock";
Expand Down Expand Up @@ -42,7 +42,6 @@ const logger = new Logger({ name: "test", level: process.env.LOG_LEVEL || "silen
describe("Adapters: Gelato", () => {
let isChainSupportedByGelatoStub: SinonStub<[chainId: number], Promise<boolean>>;
let chainReaderMock: SinonStubbedInstance<ChainReader>;
let axiosPostStub: SinonStub;
let axiosGetStub: SinonStub;
let gelatoRelayMock;

Expand Down Expand Up @@ -77,7 +76,7 @@ describe("Adapters: Gelato", () => {

describe("#getRelayerAddress", () => {
it("happy: should return address", async () => {
expect(await getRelayerAddress(1337)).to.be.eq(GELATO_RELAYER_ADDRESS);
expect(await getRelayerAddress(1337)).to.be.eq(getGelatoRelayerAddress(chainIdToDomain(1337).toString()));
});
});

Expand Down Expand Up @@ -233,20 +232,22 @@ describe("Adapters: Gelato", () => {

describe("#getRelayerAddress", () => {
beforeEach(() => {
axiosGetStub.resolves({ data: { address: GELATO_RELAYER_ADDRESS } });
axiosGetStub.resolves({
data: { address: getGelatoRelayerAddress(chainIdToDomain(1337).toString()) },
});
});

it("should work", async () => {
const relayerAddress = await getRelayerAddress(1234);
expect(relayerAddress).to.eq(GELATO_RELAYER_ADDRESS);
const relayerAddress = await getRelayerAddress(1337);
expect(relayerAddress).to.eq(getGelatoRelayerAddress(chainIdToDomain(1337).toString()));
});
});

describe("#send", () => {
let gelatoSDKSendStub;
beforeEach(() => {
isChainSupportedByGelatoStub = stub(GelatoFns, "isChainSupportedByGelato").resolves(true);
stub(GelatoFns, "getRelayerAddress").resolves(GELATO_RELAYER_ADDRESS);
stub(GelatoFns, "getRelayerAddress").resolves(getGelatoRelayerAddress(chainIdToDomain(1337).toString()));
chainReaderMock = mockChainReader() as any;
stub(RelayerIndexFns, "url").value("http://example.com");
gelatoSDKSendStub = stub(GelatoFns, "gelatoSDKSend").resolves(mockGelatoSDKSuccessResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
jsonifyError,
NxtpError,
SparseMerkleTree,
GELATO_RELAYER_ADDRESS,
getGelatoRelayerAddress,
RequestContext,
XMessage,
ExecStatus,
Expand Down Expand Up @@ -272,7 +272,7 @@ export const processMessages = async (brokerMessage: BrokerMessage, _requestCont

/// Temp: Using relayer proxy
const domain = +destinationDomain;
const relayerAddress = GELATO_RELAYER_ADDRESS; // hardcoded gelato address will always be whitelisted
const relayerAddress = getGelatoRelayerAddress(destinationDomain); // hardcoded gelato address will always be whitelisted

logger.info("Sending tx to relayer", requestContext, methodContext, {
relayer: relayerAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const sendExecuteSlowToSequencer = async (
// Validate the bid's fulfill call will succeed on chain.
// note: using gelato's relayer address since it will be whitelisted everywhere
// another note: we are using the old system, but new system will have this relayer whitelisted still
// const relayerAddress = GELATO_RELAYER_ADDRESS;
// const relayerAddress = getGelatoRelayerAddress(args.params.destinationDomain);

// TEMP: Relayer proxy
const relayerProxyAddress = config.chains[args.params.destinationDomain].deployments.relayerProxy;
Expand Down
10 changes: 8 additions & 2 deletions packages/agents/sequencer/src/lib/operations/relayer/fastpath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { RequestContext, createLoggingContext, Bid, OriginTransfer, GELATO_RELAYER_ADDRESS } from "@connext/nxtp-utils";
import {
RequestContext,
createLoggingContext,
Bid,
OriginTransfer,
getGelatoRelayerAddress,
} from "@connext/nxtp-utils";

import { sendWithRelayerWithBackup } from "../../../mockable";
import { getContext } from "../../../sequencer";
Expand Down Expand Up @@ -31,7 +37,7 @@ export const sendExecuteFastToRelayer = async (
const executeEncodedData = await encodeExecuteFromBids(round, bids, transfer, requestContext);

// Simulation data for Execute transfer
const relayerFrom = GELATO_RELAYER_ADDRESS;
const relayerFrom = getGelatoRelayerAddress(transfer.xparams.destinationDomain);

try {
await database.updateExecuteSimulationData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
RequestContext,
ExecutorData,
createLoggingContext,
GELATO_RELAYER_ADDRESS,
getGelatoRelayerAddress,
domainToChainId,
} from "@connext/nxtp-utils";

Expand Down Expand Up @@ -33,7 +33,7 @@ export const sendExecuteSlowToRelayer = async (
const destinationConnextAddress = config.chains[transfer.xparams.destinationDomain].deployments.connext;

// Simulation data for Execute transfer
const relayerFrom = GELATO_RELAYER_ADDRESS;
const relayerFrom = getGelatoRelayerAddress(transfer.xparams.destinationDomain);

try {
await database.updateExecuteSimulationData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,8 @@ export const MAINNET_PRODUCTION_INIT_CONFIG: InitConfig = {
},
relayers: {
allowlist: [
"0x75bA5Af8EFFDCFca32E1e288806d54277D1fde99", // gelato 1balance
// NOTE: gelato whitelisted in `init` script
"0x935AaAe0f5b02007c08512F0629a9d37Af2E1A47", // connext relayer
// "0x99a039d4F0e734aA8CcBE74C0FF9780BccD79f1d", // gelato 1balance zksync era
],
},
proposers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ export const MAINNET_STAGING_INIT_CONFIG: InitConfig = {
},
relayers: {
allowlist: [
"0x75bA5Af8EFFDCFca32E1e288806d54277D1fde99", // gelato 1balance
// NOTE: gelato whitelisted in `init` script
"0x935AaAe0f5b02007c08512F0629a9d37Af2E1A47", // connext relayer
//"0x99a039d4F0e734aA8CcBE74C0FF9780BccD79f1d", // gelato 1balance zksync era
],
},
proposers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,14 @@ export const TESTNET_PRODUCTION_INIT_CONFIG: InitConfig = {
},
relayers: {
allowlist: [
"0x99a039d4F0e734aA8CcBE74C0FF9780BccD79f1d", // gelato (zksync)
"0x75bA5Af8EFFDCFca32E1e288806d54277D1fde99", // gelato (new)
// NOTE: gelato whitelisted in `init` script
"0x7198C77022566F8F1f8A9A41C7B9C084bD18F934", // connext relayer
"0xa2Ee8DCd2A8A3A54Cf37F6590E5108BbE502B006",
],
blacklist: [
"0x99a039d4F0e734aA8CcBE74C0FF9780BccD79f1d", // gelato (zksync - old)
"0x75bA5Af8EFFDCFca32E1e288806d54277D1fde99", // gelato (old)
],
},
proposers: {
allowlist: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ export const TESTNET_STAGING_INIT_CONFIG: InitConfig = {
},
relayers: {
allowlist: [
"0x75bA5Af8EFFDCFca32E1e288806d54277D1fde99", // gelato (new)
"0xf6d4f65325b258b2d70797CA7576CF8CD03Ed7b8",
"0xaBcC9b596420A9E9172FD5938620E265a0f9Df92", // gelato
// NOTE: gelato whitelisted in `init` script
"0xED6fbBB952F5dA88bE9B507A9b2289B1ec07d494",
"0x24d677f8a59a486bfc6d87e9453c4f1fefcb0958",
"0xaB0A8DCb1590C4565C35cC785dc25A0590398054",
"0xCDdE9992Fb66038Dd8419b56149a75CC79Df133C",
"0xf6d4f65325b258b2d70797CA7576CF8CD03Ed7b8",
"0x8cFAcF1d7f052faA1aED6e793f0C451b5dEA8c1E",
],
blacklist: [
"0x99a039d4F0e734aA8CcBE74C0FF9780BccD79f1d", // gelato (zksync - old)
"0x75bA5Af8EFFDCFca32E1e288806d54277D1fde99", // gelato (old)
],
},
proposers: {
allowlist: ["0xa2Ee8DCd2A8A3A54Cf37F6590E5108BbE502B006", "0xD29f9168004a13e2266eFE450D2d60eBEE8adAA1"],
Expand Down
144 changes: 102 additions & 42 deletions packages/deployments/contracts/src/cli/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from "fs";
import { providers, Wallet, utils, constants } from "ethers";
import * as zk from "zksync-ethers";
import commandLineArgs from "command-line-args";
import { ajv, domainToChainId, GELATO_RELAYER_ADDRESS, getChainData } from "@connext/nxtp-utils";
import { ajv, domainToChainId, getGelatoRelayerAddress, getChainData } from "@connext/nxtp-utils";
import { HttpNetworkUserConfig } from "hardhat/types";

import { canonizeId } from "../../domain";
Expand Down Expand Up @@ -548,47 +548,77 @@ export const initProtocol = async (protocol: ProtocolStack, apply: boolean, stag

/// MARK - Relayers
if (protocol.agents.relayers) {
if (protocol.agents.relayers.allowlist) {
console.log("\n\nWHITELIST RELAYERS");

for (const network of protocol.networks) {
const relayerProxyAddress = network.deployments.messaging.RelayerProxy.address;
await updateIfNeeded({
apply,
deployment: network.deployments.Connext,
desired: true,
read: { method: "approvedRelayers", args: [relayerProxyAddress] },
write: { method: "addRelayer", args: [relayerProxyAddress] },
auth: [
{ method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
{ method: "queryRole", args: [network.signerAddress], eval: (ret) => ret === 3 },
],
chainData,
});

await updateIfNeeded({
apply,
deployment: network.deployments.messaging.RelayerProxy,
desired: GELATO_RELAYER_ADDRESS,
read: { method: "gelatoRelayer" },
write: { method: "setGelatoRelayer", args: [GELATO_RELAYER_ADDRESS] },
chainData,
auth: { method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
});

const feeCollector = network.relayerFeeVault;
await updateIfNeeded({
apply,
deployment: network.deployments.messaging.RelayerProxy,
desired: feeCollector,
read: { method: "feeCollector" },
write: { method: "setFeeCollector", args: [feeCollector] },
chainData,
auth: { method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
});
}
console.log("\n\nWHITELIST RELAYERS");

console.log("\tVerifying RelayerProxy setup.");
for (const network of protocol.networks) {
// whitelist relayer proxy as relayer on connext
const relayerProxyAddress = network.deployments.messaging.RelayerProxy.address;
await updateIfNeeded({
apply,
deployment: network.deployments.Connext,
desired: true,
read: { method: "approvedRelayers", args: [relayerProxyAddress] },
write: { method: "addRelayer", args: [relayerProxyAddress] },
auth: [
{ method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
{ method: "queryRole", args: [network.signerAddress], eval: (ret) => ret === 3 },
],
chainData,
});

// set gelato relayer address on relayer proxy
await updateIfNeeded({
apply,
deployment: network.deployments.messaging.RelayerProxy,
desired: getGelatoRelayerAddress(network.domain),
read: { method: "gelatoRelayer" },
write: { method: "setGelatoRelayer", args: [getGelatoRelayerAddress(network.domain)] },
chainData,
auth: { method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
});

// set fee collector on relayer proxy
const feeCollector = network.relayerFeeVault;
await updateIfNeeded({
apply,
deployment: network.deployments.messaging.RelayerProxy,
desired: feeCollector,
read: { method: "feeCollector" },
write: { method: "setFeeCollector", args: [feeCollector] },
chainData,
auth: { method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
});

// Whitelist gelato relayer on the Relayer Proxy + Connext
await updateIfNeeded({
apply,
deployment: network.deployments.messaging.RelayerProxy,
desired: true,
read: { method: "allowedRelayer", args: [getGelatoRelayerAddress(network.domain)] },
write: { method: "addRelayer", args: [getGelatoRelayerAddress(network.domain)] },
chainData,
auth: { method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
});

// also add gelato to the base connext contract
await updateIfNeeded({
apply,
deployment: network.deployments.Connext,
desired: true,
read: { method: "approvedRelayers", args: [getGelatoRelayerAddress(network.domain)] },
write: { method: "addRelayer", args: [getGelatoRelayerAddress(network.domain)] },
auth: [
{ method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
{ method: "queryRole", args: [network.signerAddress], eval: (ret) => ret === 3 },
],
chainData,
});
}

if (protocol.agents.relayers.allowlist) {
// Whitelist named relayers for the Relayer Proxy, in order to call `execute`.
console.log("\tWhitelisting named relayers on RelayerProxy + Connext");
for (const relayer of protocol.agents.relayers.allowlist) {
for (const network of protocol.networks) {
await updateIfNeeded({
Expand Down Expand Up @@ -616,9 +646,39 @@ export const initProtocol = async (protocol: ProtocolStack, apply: boolean, stag
});
}
}
// Additionally, approve relayers as callers for connectors and root manager.
}
// TODO: Blacklist/remove relayers.

if (protocol.agents.relayers.blacklist) {
// Blacklist named relayers for the relayer proxy / connext
console.log("\tBlacklisting named relayers on RelayerProxy + Connext");
for (const relayer of protocol.agents.relayers.blacklist) {
for (const network of protocol.networks) {
await updateIfNeeded({
apply,
deployment: network.deployments.messaging.RelayerProxy,
desired: false,
read: { method: "allowedRelayer", args: [relayer] },
write: { method: "removeRelayer", args: [relayer] },
chainData,
auth: { method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
});

// also add relayers to the base connext contract
await updateIfNeeded({
apply,
deployment: network.deployments.Connext,
desired: false,
read: { method: "approvedRelayers", args: [relayer] },
write: { method: "removeRelayer", args: [relayer] },
auth: [
{ method: "owner", eval: (ret: string) => ret.toLowerCase() === network.signerAddress },
{ method: "queryRole", args: [network.signerAddress], eval: (ret) => ret === 3 },
],
chainData,
});
}
}
}
}

/// MARK - Sequencers
Expand Down
Loading

0 comments on commit 7a1b0fb

Please sign in to comment.