Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 4538 wormhole connector #4623

Merged
merged 39 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d951be5
feat: wormhole connector draft
liu-zhipeng Jun 28, 2023
1be9c5e
chore: contract build
liu-zhipeng Jun 28, 2023
9216f57
fix: wormhole connector deploy script
liu-zhipeng Jun 29, 2023
dc65666
chore: rebuild contracts
liu-zhipeng Jun 29, 2023
51cda18
fix: deploy wormhole connectors
liu-zhipeng Jun 29, 2023
f537a54
fix: wormhole base connector
liu-zhipeng Jun 29, 2023
5f7a977
doc: add comments
liu-zhipeng Jun 30, 2023
0ea4b80
test: forge tests for wormhole connectors
liu-zhipeng Jun 30, 2023
69ce4d6
fix: build
LayneHaber Jul 1, 2023
b3f1b12
chore: rebuild
LayneHaber Jul 1, 2023
d439161
refactor: rename the mirror chain variable
LayneHaber Jul 1, 2023
fa29ab8
fix: don't store amb twice
LayneHaber Jul 1, 2023
e6d242a
fix: minor review updates
LayneHaber Jul 1, 2023
4d63a2d
feat: add configurable refund address for fees
LayneHaber Jul 1, 2023
7c9510f
feat: use owner as the first relayer
LayneHaber Jul 1, 2023
ea8deeb
fix: forge tests for wormhole spoke connector
liu-zhipeng Jul 2, 2023
50ef681
fix: update IWormholeReceiver interface
liu-zhipeng Jul 6, 2023
8bbd58f
fix: capping gasLimit in the `quoteEvmDeliveryPrice`
liu-zhipeng Jul 6, 2023
ec9d93a
fix: renounceOwnership logic
liu-zhipeng Jul 6, 2023
396a0a8
Merge pull request #4650 from connext/macro-wormhole-q3
LayneHaber Jul 7, 2023
26591a4
Merge pull request #4648 from connext/macro-wormhole-q1
LayneHaber Jul 7, 2023
f447982
Merge pull request #4649 from connext/macro-wormhole-q2
LayneHaber Jul 7, 2023
0240f48
feat: 4545 offchainlighthouse subtasks for bnb amb (#4659)
liu-zhipeng Jul 7, 2023
f941684
feat: wormhole connector deployed
liu-zhipeng Jul 7, 2023
02288d0
Merge branch 'main' into 4538-wormhole-connector
liu-zhipeng Jul 7, 2023
73a3edf
feat: 4544 wormhole connector subgraph (#4661)
sanchaymittal Jul 7, 2023
f7a751b
fix: return init script messaging functionality
LayneHaber Jul 7, 2023
5dd193c
chore: fresh install
LayneHaber Jul 7, 2023
111383e
feat: per-chain configurable relayer fee vault
LayneHaber Jul 7, 2023
68d0ddc
feat: respect names configured if properly prefixed
LayneHaber Jul 7, 2023
6490421
refactor: only fork creation logic not execution upgrade in base
LayneHaber Jul 8, 2023
c38f077
feat: add ability to create forks from env vars
LayneHaber Jul 8, 2023
a7739fe
chore: rename helper lib to RpcLookup
LayneHaber Jul 8, 2023
a92e1ac
feat: add deployment lookup contract helper
LayneHaber Jul 8, 2023
ba9337c
feat: wormhole connectors upgrading on fork
LayneHaber Jul 8, 2023
1433659
feat: add replay test for old transfers
LayneHaber Jul 8, 2023
cf08b6f
fix: remove unused transfer examples
LayneHaber Jul 10, 2023
c6d6ca6
Merge pull request #4668 from connext/init-script-fixes
LayneHaber Jul 10, 2023
a3c11ab
Merge pull request #4671 from connext/4641-bnb-fork-tests
LayneHaber Jul 11, 2023
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
102,006 changes: 51,003 additions & 51,003 deletions packages/adapters/subgraph/.graphclient/index.ts

Large diffs are not rendered by default.

81,284 changes: 40,642 additions & 40,642 deletions packages/adapters/subgraph/.graphclient/schema.graphql

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions packages/agents/lighthouse/src/tasks/propagate/helpers/bnb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContractInterface } from "ethers";
import { ContractInterface, utils } from "ethers";
import { createLoggingContext, RequestContext } from "@connext/nxtp-utils";

import { NoHubConnector, NoProviderForDomain, NoSpokeConnector } from "../errors";
Expand All @@ -15,7 +15,7 @@ export const getPropagateParams = async (
const {
config,
logger,
adapters: { deployments, ambs },
adapters: { deployments },
} = getContext();
const { methodContext, requestContext } = createLoggingContext(getPropagateParams.name, _requestContext);
logger.info("Getting propagate params for BNB", requestContext, methodContext, { l2domain });
Expand Down Expand Up @@ -51,8 +51,12 @@ export const getPropagateParams = async (
);
const ambAddress = await l1HubConnectorContract.AMB();

const ambContract = getContract(ambAddress as string, ambs.bnb as ContractInterface, l1Provider);
const fee = await ambContract.calcSrcFees("", l2ChainId, 32);
// gasLimit on spoke side = 200_000
// actually it required about 60_000 gas on bnb chain to call `receiveWormholeMessages`
// remain gas will be refunded on bnb chain to refund address (default: deployer address)
const gasLimit = "200000";
const fee = await l1HubConnectorContract.quoteEVMDeliveryPrice(gasLimit, ambAddress);
const encodedData = utils.defaultAbiCoder.encode(["uint256"], [gasLimit]);

return { _connector: "", _fee: fee, _encodedData: "0x" };
return { _connector: "", _fee: fee, _encodedData: encodedData };
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { createLoggingContext, domainToChainId } from "@connext/nxtp-utils";
import { ContractInterface, utils } from "ethers";

import { getContext } from "../sendOutboundRoot";
import { ExtraSendOutboundRootParam } from "../operations/sendOutboundRoot";
import { NoProviderForDomain, NoSpokeConnector } from "../../propagate/errors";
import { getInterface, getBestProvider } from "../../../mockable";
import { getBestProvider, getJsonRpcProvider, getContract } from "../../../mockable";

export const getSendOutboundRootParams = async (l2domain: string): Promise<ExtraSendOutboundRootParam> => {
const {
config,
adapters: { deployments, contracts, chainreader, ambs },
adapters: { deployments },
} = getContext();
const { requestContext, methodContext } = createLoggingContext(getSendOutboundRootParams.name);
const l2RpcUrl = await getBestProvider(config.chains[l2domain]?.providers ?? []);
Expand All @@ -22,7 +23,6 @@ export const getSendOutboundRootParams = async (l2domain: string): Promise<Extra
}

const l2ChainId = domainToChainId(+l2domain);
const hubChainId = domainToChainId(+config.hubDomain);

const l2SpokeConnector = deployments.spokeConnector(
l2ChainId,
Expand All @@ -33,14 +33,20 @@ export const getSendOutboundRootParams = async (l2domain: string): Promise<Extra
throw new NoSpokeConnector(l2ChainId, requestContext, methodContext);
}

let encodedData = contracts.spokeConnector.encodeFunctionData("AMB");
let encoded = await chainreader.readTx({ data: encodedData, domain: Number(l2domain), to: l2SpokeConnector.address });
const [ambAddress] = contracts.spokeConnector.decodeFunctionResult("AMB", encoded);
const l2Provider = getJsonRpcProvider(l2RpcUrl);
const l2SpokeConnectorContract = getContract(
l2SpokeConnector.address,
l2SpokeConnector.abi as ContractInterface,
l2Provider,
);
const ambAddress = await l2SpokeConnectorContract.AMB();
liu-zhipeng marked this conversation as resolved.
Show resolved Hide resolved

const ambInterface = getInterface(ambs.bnb);
encodedData = ambInterface.encodeFunctionData("calcSrcFees", ["", hubChainId, 32]);
encoded = await chainreader.readTx({ data: encodedData, domain: Number(l2domain), to: ambAddress });
const [_fee] = ambInterface.decodeFunctionResult("calcSrcFees", encoded);
// gasLimit on hub side = 200_000
// actually it required about 100_000 gas on mainnet to call `receiveWormholeMessages`
// remain gas will be refunded on mainnetto refund address (default: deployer address)
const gasLimit = "200000";
const fee = await l2SpokeConnectorContract.quoteEVMDeliveryPrice(gasLimit, ambAddress);
liu-zhipeng marked this conversation as resolved.
Show resolved Hide resolved
const encodedData = utils.defaultAbiCoder.encode(["uint256"], [gasLimit]);

return { _fee: _fee.toString(), _encodedData: "0x" };
return { _fee: fee.toString(), _encodedData: encodedData };
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getPropagateParams } from "../../../../src/tasks/propagate/helpers/bnb"
import * as Mockable from "../../../../src/mockable";
import { getBestProviderMock, propagateCtxMock } from "../../../globalTestHook";
import { mock } from "../../../mock";
import { constants, Contract } from "ethers";
import { constants, Contract, utils } from "ethers";

const requestContext = createRequestContext("test");

Expand All @@ -15,7 +15,7 @@ describe("Helpers: Bnb", () => {
beforeEach(() => {
stub(Mockable, "getContract").returns({
AMB: stub().resolves(mkAddress("0x123")),
calcSrcFees: stub().resolves(constants.One),
quoteEVMDeliveryPrice: stub().resolves(constants.One),
} as any);
});

Expand Down Expand Up @@ -54,7 +54,7 @@ describe("Helpers: Bnb", () => {
expect(data).to.deep.eq({
_connector: "",
_fee: constants.One,
_encodedData: "0x",
_encodedData: utils.defaultAbiCoder.encode(["uint256"], [200000]),
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { expect, mock } from "@connext/nxtp-utils";
import { BigNumber } from "ethers";
import { SinonStub, stub, createStubInstance } from "sinon";
import { expect, mkAddress, mock } from "@connext/nxtp-utils";
import { BigNumber, constants, utils } from "ethers";

import * as Mockable from "../../../../src/mockable";
import { getSendOutboundRootParams } from "../../../../src/tasks/sendOutboundRoot/helpers/bnb";

describe("Helpers: BNB", () => {
describe("#getSendOutboundRootParams", () => {
beforeEach(() => {
stub(Mockable, "getContract").returns({
AMB: stub().resolves(mkAddress("0x123")),
quoteEVMDeliveryPrice: stub().resolves(constants.One),
} as any);
});

it("should get params", async () => {
const res = await getSendOutboundRootParams(mock.domain.A);
expect(res).to.deep.eq({
_fee: "42",
_encodedData: "0x",
_fee: constants.One.toString(),
_encodedData: utils.defaultAbiCoder.encode(["uint256"], [200000]),
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
"error ProposedOwnable__onlyOwner_notOwner()",
"error ProposedOwnable__onlyProposed_notProposedOwner()",
"error ProposedOwnable__ownershipDelayElapsed_delayNotElapsed()",
"error ProposedOwnable__proposeNewOwner_invalidProposal()",
"error ProposedOwnable__proposeNewOwner_noOwnershipChange()",
"error ProposedOwnable__renounceOwnership_invalidProposal()",
"error ProposedOwnable__renounceOwnership_noProposal()",
"event GasCapUpdated(uint256 _previous, uint256 _updated)",
"event OwnershipProposed(address indexed proposedOwner)",
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
"event RefundAddressUpdated(address indexed previous, address indexed updated)",
"function MIRROR_WORMHOLE_ID() view returns (uint16)",
"function acceptProposedOwner()",
"function delay() view returns (uint256)",
"function owner() view returns (address)",
"function processedWhMessages(bytes32) view returns (bool)",
"function proposeNewOwner(address newlyProposed)",
"function proposed() view returns (address)",
"function proposedTimestamp() view returns (uint256)",
"function quoteEVMDeliveryPrice(uint256 _gasLimit, address _amb) view returns (uint256 _cost)",
"function refundAddress() view returns (address)",
"function renounceOwnership()",
"function renounced() view returns (bool)",
"function setGasCap(uint256 _gasCap)",
"function setRefundAddress(address _updated)"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
"constructor(uint32 _domain, uint32 _mirrorDomain, address _amb, address _rootManager, address _mirrorConnector, uint256 _gasCap, uint16 _mirrorWormholeChainId)",
"error Connector__processMessage_notUsed()",
"error ProposedOwnable__onlyOwner_notOwner()",
"error ProposedOwnable__onlyProposed_notProposedOwner()",
"error ProposedOwnable__ownershipDelayElapsed_delayNotElapsed()",
"error ProposedOwnable__proposeNewOwner_invalidProposal()",
"error ProposedOwnable__proposeNewOwner_noOwnershipChange()",
"error ProposedOwnable__renounceOwnership_invalidProposal()",
"error ProposedOwnable__renounceOwnership_noProposal()",
"event GasCapUpdated(uint256 _previous, uint256 _updated)",
"event MessageProcessed(bytes data, address caller)",
"event MessageSent(bytes data, bytes encodedData, address caller)",
"event MirrorConnectorUpdated(address previous, address current)",
"event NewConnector(uint32 indexed domain, uint32 indexed mirrorDomain, address amb, address rootManager, address mirrorConnector)",
"event OwnershipProposed(address indexed proposedOwner)",
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
"event RefundAddressUpdated(address indexed previous, address indexed updated)",
"function AMB() view returns (address)",
"function DOMAIN() view returns (uint32)",
"function MIRROR_DOMAIN() view returns (uint32)",
"function MIRROR_WORMHOLE_ID() view returns (uint16)",
"function ROOT_MANAGER() view returns (address)",
"function acceptProposedOwner()",
"function delay() view returns (uint256)",
"function mirrorConnector() view returns (address)",
"function owner() view returns (address)",
"function processMessage(bytes _data)",
"function processedWhMessages(bytes32) view returns (bool)",
"function proposeNewOwner(address newlyProposed)",
"function proposed() view returns (address)",
"function proposedTimestamp() view returns (uint256)",
"function quoteEVMDeliveryPrice(uint256 _gasLimit, address _amb) view returns (uint256 _cost)",
"function receiveWormholeMessages(bytes _payload, bytes[], bytes32 _sourceAddress, uint16 _sourceChain, bytes32 _deliveryHash) payable",
"function refundAddress() view returns (address)",
"function renounceOwnership()",
"function renounced() view returns (bool)",
"function sendMessage(bytes _data, bytes _encodedData) payable",
"function setGasCap(uint256 _gasCap)",
"function setMirrorConnector(address _mirrorConnector)",
"function setRefundAddress(address _updated)",
"function verifySender(address _expected) returns (bool)"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[
"constructor(uint32 _domain, uint32 _mirrorDomain, address _amb, address _rootManager, address _mirrorConnector, uint256 _processGas, uint256 _reserveGas, uint256 _delayBlocks, address _merkle, address _watcherManager, uint256 _gasCap, uint16 _mirrorWormholeChainId)",
"error Connector__processMessage_notUsed()",
"error ProposedOwnable__onlyOwner_notOwner()",
"error ProposedOwnable__onlyProposed_notProposedOwner()",
"error ProposedOwnable__ownershipDelayElapsed_delayNotElapsed()",
"error ProposedOwnable__proposeNewOwner_invalidProposal()",
"error ProposedOwnable__proposeNewOwner_noOwnershipChange()",
"error ProposedOwnable__renounceOwnership_invalidProposal()",
"error ProposedOwnable__renounceOwnership_noProposal()",
"error RateLimited__rateLimited_messageSendRateExceeded()",
"error TypedMemView__index_indexMoreThan32Bytes()",
"error TypedMemView__index_overrun(uint256 loc, uint256 len, uint256 index, uint256 slice)",
"error TypedMemView__unsafeCopyTo_identityOOG()",
"error TypedMemView__unsafeCopyTo_invalidPointer()",
"error TypedMemView__unsafeCopyTo_nullPointer()",
"event AggregateRootReceived(bytes32 root)",
"event AggregateRootRemoved(bytes32 root)",
"event AggregateRootVerified(bytes32 indexed root)",
"event DelayBlocksUpdated(uint256 indexed updated, address caller)",
"event Dispatch(bytes32 leaf, uint256 index, bytes32 root, bytes message)",
"event FundsWithdrawn(address indexed to, uint256 amount)",
"event GasCapUpdated(uint256 _previous, uint256 _updated)",
"event MessageProcessed(bytes data, address caller)",
"event MessageProven(bytes32 indexed leaf, bytes32 indexed aggregateRoot, uint256 aggregateIndex)",
"event MessageSent(bytes data, bytes encodedData, address caller)",
"event MirrorConnectorUpdated(address previous, address current)",
"event NewConnector(uint32 indexed domain, uint32 indexed mirrorDomain, address amb, address rootManager, address mirrorConnector)",
"event OwnershipProposed(address indexed proposedOwner)",
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
"event Paused(address account)",
"event Process(bytes32 leaf, bool success, bytes returnData)",
"event RefundAddressUpdated(address indexed previous, address indexed updated)",
"event SendRateLimitUpdated(address updater, uint256 newRateLimit)",
"event SenderAdded(address sender)",
"event SenderRemoved(address sender)",
"event Unpaused(address account)",
"event WatcherManagerChanged(address watcherManager)",
"function AMB() view returns (address)",
"function DOMAIN() view returns (uint32)",
"function MERKLE() view returns (address)",
"function MIRROR_DOMAIN() view returns (uint32)",
"function MIRROR_WORMHOLE_ID() view returns (uint16)",
"function PROCESS_GAS() view returns (uint256)",
"function RESERVE_GAS() view returns (uint256)",
"function ROOT_MANAGER() view returns (address)",
"function acceptProposedOwner()",
"function addSender(address _sender)",
"function allowlistedSenders(address) view returns (bool)",
"function delay() view returns (uint256)",
"function delayBlocks() view returns (uint256)",
"function dispatch(uint32 _destinationDomain, bytes32 _recipientAddress, bytes _messageBody) returns (bytes32, bytes)",
"function home() view returns (address)",
"function isReplica(address _potentialReplica) view returns (bool)",
"function lastSentBlock() view returns (uint256)",
"function localDomain() view returns (uint32)",
"function messages(bytes32) view returns (uint8)",
"function mirrorConnector() view returns (address)",
"function nonces(uint32) view returns (uint32)",
"function outboundRoot() view returns (bytes32)",
"function owner() view returns (address)",
"function pause()",
"function paused() view returns (bool)",
"function pendingAggregateRoots(bytes32) view returns (uint256)",
"function processMessage(bytes _data)",
"function processedWhMessages(bytes32) view returns (bool)",
"function proposeNewOwner(address newlyProposed)",
"function proposed() view returns (address)",
"function proposedTimestamp() view returns (uint256)",
"function proveAndProcess(tuple(bytes message, bytes32[32] path, uint256 index)[] _proofs, bytes32 _aggregateRoot, bytes32[32] _aggregatePath, uint256 _aggregateIndex)",
"function provenAggregateRoots(bytes32) view returns (bool)",
"function provenMessageRoots(bytes32) view returns (bool)",
"function quoteEVMDeliveryPrice(uint256 _gasLimit, address _amb) view returns (uint256 _cost)",
"function rateLimitBlocks() view returns (uint256)",
"function receiveWormholeMessages(bytes _payload, bytes[], bytes32 _sourceAddress, uint16 _sourceChain, bytes32 _deliveryHash) payable",
"function refundAddress() view returns (address)",
"function removePendingAggregateRoot(bytes32 _fraudulentRoot)",
"function removeSender(address _sender)",
"function renounceOwnership()",
"function renounced() view returns (bool)",
"function send(bytes _encodedData) payable",
"function sentMessageRoots(bytes32) view returns (bool)",
"function setDelayBlocks(uint256 _delayBlocks)",
"function setGasCap(uint256 _gasCap)",
"function setMirrorConnector(address _mirrorConnector)",
"function setRateLimitBlocks(uint256 _rateLimit)",
"function setRefundAddress(address _updated)",
"function setWatcherManager(address _watcherManager)",
"function unpause()",
"function verifySender(address _expected) returns (bool)",
"function watcherManager() view returns (address)",
"function withdrawFunds(address _to)"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"function receiveWormholeMessages(bytes payload, bytes[] additionalVaas, bytes32 sourceAddress, uint16 sourceChain, bytes32 deliveryHash) payable"
]
Loading