Skip to content

Commit

Permalink
Ran new build and squashed commits
Browse files Browse the repository at this point in the history
  • Loading branch information
mvpoyatt authored and mvpoyatt committed Sep 24, 2024
1 parent 514d0ea commit e4f5184
Show file tree
Hide file tree
Showing 42 changed files with 435 additions and 112 deletions.
8 changes: 4 additions & 4 deletions bindings/go/earth/Earth.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions bindings/go/mars/Mars.go

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions bindings/go/mars/PanickingMars.go

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions bindings/go/mars/RevertingBytesMars.go

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions bindings/go/mars/RevertingEmptyMars.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions bindings/go/mars/RevertingStringCloseChannelMars.go

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions bindings/go/mars/RevertingStringMars.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions bindings/go/moon/Moon.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contracts/base/GeneralMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract GeneralMiddleware is IbcMwUser, IbcMiddleware, IbcMwEventsEmitter, IbcM
uint256 mwIndex,
// bytes calldata appData,
address[] calldata mwAddrs
) external onlyIbcMw returns (AckPacket memory ackPacket) {
) external onlyIbcMw returns (AckPacket memory ackPacket, bool skipAck) {
// extra MW custom logic here to process packet, eg. emit MW events, mutate state, etc.
// implementer can emit custom data fields suitable for their use cases.
// Here we use MW_ID as the custom MW data field.
Expand Down Expand Up @@ -180,7 +180,7 @@ contract GeneralMiddleware is IbcMwUser, IbcMiddleware, IbcMwEventsEmitter, IbcM
external
override
onlyIbcMw
returns (AckPacket memory ackPacket)
returns (AckPacket memory ackPacket, bool skipAck)
{}

function onUniversalAcknowledgement(bytes32 channelId, UniversalPacket memory packet, AckPacket calldata ack)
Expand Down
6 changes: 5 additions & 1 deletion contracts/core/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,15 @@ contract Dispatcher is Ownable2StepUpgradeable, UUPSUpgradeable, ReentrancyGuard
}

AckPacket memory ack;
bool skipAck;
// Not timeout yet, then do normal handling
(bool success, bytes memory data) =
_callIfContract(receiver, abi.encodeWithSelector(IbcPacketReceiver.onRecvPacket.selector, packet));
if (success) {
(ack) = abi.decode(data, (AckPacket));
(ack, skipAck) = abi.decode(data, (AckPacket, bool));
if (skipAck) {
return;
}
} else {
ack = AckPacket(false, data);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/UniversalChannelHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ contract UniversalChannelHandler is IbcReceiverBaseUpgradeable, FeeSender, UUPSU
external
override
onlyIbcDispatcher
returns (AckPacket memory ackPacket)
returns (AckPacket memory ackPacket, bool skipAck)
{
UniversalPacket memory ucPacket = IbcUtils.fromUniversalPacketBytes(packet.data);
// no other middleware stack registered for this packet. Deliver packet to dApp directly.
Expand Down
5 changes: 3 additions & 2 deletions contracts/examples/Earth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,18 @@ contract Earth is IbcUniversalPacketReceiverBase {
* @param channelId The channel ID.
* @param packet The universal packet.
* @return ackPacket The acknowledgement packet.
* @return skipAck Whether to skip the writeAck event.
* @dev It's recommended to always validate the authorized channel of any packet or channel using the
* onlyAuthorizedChannel modifier.
*/
function onRecvUniversalPacket(bytes32 channelId, UniversalPacket calldata packet)
external
onlyUCH
onlyAuthorizedChannel(channelId)
returns (AckPacket memory ackPacket)
returns (AckPacket memory ackPacket, bool skipAck)
{
recvedPackets.push(UcPacketWithChannel(channelId, packet));
return this.generateAckPacket(channelId, IbcUtils.toAddress(packet.srcPortAddr), packet.appData);
return (this.generateAckPacket(channelId, IbcUtils.toAddress(packet.srcPortAddr), packet.appData), false);
}

/**
Expand Down
42 changes: 36 additions & 6 deletions contracts/examples/Mars.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ contract Mars is IbcReceiverBase, IbcReceiver, FeeSender {
* @notice Callback for receiving a packet; triggered when a counterparty sends an an IBC packet
* @param packet The IBC packet received
* @return ackPacket The acknowledgement packet generated in response
* @return skipAck Whether to skip the writeAck event.
* @dev Make sure to validate packet's source and destiation channels and ports.
*/
function onRecvPacket(IbcPacket memory packet)
external
virtual
onlyIbcDispatcher
returns (AckPacket memory ackPacket)
returns (AckPacket memory ackPacket, bool skipAck)
{
recvedPackets.push(packet);

// solhint-disable-next-line quotes
return AckPacket(true, abi.encodePacked('{ "account": "account", "reply": "got the message" }'));
return (AckPacket(true, abi.encodePacked('{ "account": "account", "reply": "got the message" }')), false);
}

/**
Expand Down Expand Up @@ -243,10 +244,17 @@ contract RevertingStringMars is Mars {
constructor(IbcDispatcher _dispatcher) Mars(_dispatcher) {}

// solhint-disable-next-line
function onRecvPacket(IbcPacket memory) external view override onlyIbcDispatcher returns (AckPacket memory ack) {
function onRecvPacket(IbcPacket memory)
external
view
override
onlyIbcDispatcher
returns (AckPacket memory ack, bool skipAck)
{
// solhint-disable-next-line
require(false, "on recv packet is reverting");
ack = AckPacket(false, "");
skipAck = false;
}

// solhint-disable-next-line
Expand Down Expand Up @@ -280,8 +288,15 @@ contract RevertingBytesMars is Mars {

constructor(IbcDispatcher _dispatcher) Mars(_dispatcher) {}

function onRecvPacket(IbcPacket memory) external view override onlyIbcDispatcher returns (AckPacket memory ack) {
function onRecvPacket(IbcPacket memory)
external
view
override
onlyIbcDispatcher
returns (AckPacket memory ack, bool skipAck)
{
ack = AckPacket(false, "");
skipAck = false;
revert OnRecvPacketRevert();
}

Expand All @@ -294,18 +309,33 @@ contract RevertingBytesMars is Mars {
contract RevertingEmptyMars is Mars {
constructor(IbcDispatcher _dispatcher) Mars(_dispatcher) {}

function onRecvPacket(IbcPacket memory) external view override onlyIbcDispatcher returns (AckPacket memory ack) {
function onRecvPacket(IbcPacket memory)
external
view
override
onlyIbcDispatcher
returns (AckPacket memory ack, bool skipAck)
{
// solhint-disable-next-line
require(false);
// Set values to avoid compiler warning
ack = AckPacket(false, "");
skipAck = false;
}
}

contract PanickingMars is Mars {
constructor(IbcDispatcher _dispatcher) Mars(_dispatcher) {}

function onRecvPacket(IbcPacket memory) external view override onlyIbcDispatcher returns (AckPacket memory ack) {
function onRecvPacket(IbcPacket memory)
external
view
override
onlyIbcDispatcher
returns (AckPacket memory ack, bool skipAck)
{
assert(false);
ack = AckPacket(false, "");
skipAck = false;
}
}
51 changes: 51 additions & 0 deletions contracts/examples/Pluto.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright 2024, Polymer Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pragma solidity ^0.8.9;

import {AckPacket} from "../libs/Ibc.sol";
import {Mars} from "./Mars.sol";
import {IbcPacket} from "../interfaces/IbcReceiver.sol";
import {IbcDispatcher} from "../interfaces/IbcDispatcher.sol";

/**
* @title Pluto
* @notice Pluto is a simple IBC receiver contract that receives packets without sending acks.
* @dev This contract is used for only testing IBC functionality and as an example for dapp developers
* on how to integrate with the vibc protocol.
*/
contract Pluto is Mars {
constructor(IbcDispatcher _dispatcher) Mars(_dispatcher) {}

/**
* @notice Callback for receiving a packet; triggered when a counterparty sends an an IBC packet
* @param packet The IBC packet received
* @return ackPacket The acknowledgement packet generated in response
* @dev Make sure to validate packet's source and destiation channels and ports.
*/
function onRecvPacket(IbcPacket memory packet)
external
override
onlyIbcDispatcher
returns (AckPacket memory ackPacket, bool skipAck)
{
recvedPackets.push(packet);

// solhint-disable-next-line quotes
return (AckPacket(true, abi.encodePacked('{ "account": "account", "reply": "got the message" }')), true);
}
}
4 changes: 2 additions & 2 deletions contracts/interfaces/IbcMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface IbcMwPacketReceiver {
// Each mw in the stack must increment mwIndex by 1 before calling the next MW.
uint256 mwIndex,
address[] calldata mwAddrs
) external returns (AckPacket memory ackPacket);
) external returns (AckPacket memory ackPacket, bool skipAck);

function onRecvMWAck(
bytes32 channelId,
Expand Down Expand Up @@ -103,7 +103,7 @@ interface IbcUniversalPacketReceiver {

function onRecvUniversalPacket(bytes32 channelId, UniversalPacket calldata ucPacket)
external
returns (AckPacket memory ackPacket);
returns (AckPacket memory ackPacket, bool skipAck);

function onUniversalAcknowledgement(bytes32 channelId, UniversalPacket memory packet, AckPacket calldata ack)
external;
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/IbcReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ interface IbcPacketReceiver {
* @notice Callback for receiving a packet; triggered when a counterparty sends an an IBC packet
* @param packet The IBC packet received
* @return ackPacket The acknowledgement packet generated in response
* @return skipAck Whether to skip sending an acknowledgement packet
* @dev Make sure to validate packet's source and destiation channels and ports.
*/
function onRecvPacket(IbcPacket calldata packet) external returns (AckPacket memory ackPacket);
function onRecvPacket(IbcPacket calldata packet) external returns (AckPacket memory ackPacket, bool skipAck);

/**
* @notice Callback for acknowledging a packet; triggered on reciept of an IBC packet by the counterparty
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-ibc/vibc-core-smart-contracts",
"version": "3.1.0",
"version": "4.0.0",
"main": "dist/index.js",
"bin": {
"verify-vibc-core-smart-contracts": "./dist/scripts/verify-contract-script.js",
Expand Down
14 changes: 12 additions & 2 deletions src/evm/contracts/Earth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ export interface Earth extends BaseContract {

onRecvUniversalPacket: TypedContractMethod<
[channelId: BytesLike, packet: UniversalPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ackPacket: AckPacketStructOutput;
skipAck: boolean;
}
],
"nonpayable"
>;

Expand Down Expand Up @@ -413,7 +418,12 @@ export interface Earth extends BaseContract {
nameOrSignature: "onRecvUniversalPacket"
): TypedContractMethod<
[channelId: BytesLike, packet: UniversalPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ackPacket: AckPacketStructOutput;
skipAck: boolean;
}
],
"nonpayable"
>;
getFunction(
Expand Down
14 changes: 12 additions & 2 deletions src/evm/contracts/IUniversalChannelHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ export interface IUniversalChannelHandler extends BaseContract {

onRecvPacket: TypedContractMethod<
[packet: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ackPacket: AckPacketStructOutput;
skipAck: boolean;
}
],
"nonpayable"
>;

Expand Down Expand Up @@ -450,7 +455,12 @@ export interface IUniversalChannelHandler extends BaseContract {
nameOrSignature: "onRecvPacket"
): TypedContractMethod<
[packet: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ackPacket: AckPacketStructOutput;
skipAck: boolean;
}
],
"nonpayable"
>;
getFunction(
Expand Down
14 changes: 12 additions & 2 deletions src/evm/contracts/Mars.sol/Mars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ export interface Mars extends BaseContract {

onRecvPacket: TypedContractMethod<
[packet: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ackPacket: AckPacketStructOutput;
skipAck: boolean;
}
],
"nonpayable"
>;

Expand Down Expand Up @@ -590,7 +595,12 @@ export interface Mars extends BaseContract {
nameOrSignature: "onRecvPacket"
): TypedContractMethod<
[packet: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ackPacket: AckPacketStructOutput;
skipAck: boolean;
}
],
"nonpayable"
>;
getFunction(
Expand Down
14 changes: 12 additions & 2 deletions src/evm/contracts/Mars.sol/PanickingMars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ export interface PanickingMars extends BaseContract {

onRecvPacket: TypedContractMethod<
[arg0: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ack: AckPacketStructOutput;
skipAck: boolean;
}
],
"view"
>;

Expand Down Expand Up @@ -590,7 +595,12 @@ export interface PanickingMars extends BaseContract {
nameOrSignature: "onRecvPacket"
): TypedContractMethod<
[arg0: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ack: AckPacketStructOutput;
skipAck: boolean;
}
],
"view"
>;
getFunction(
Expand Down
14 changes: 12 additions & 2 deletions src/evm/contracts/Mars.sol/RevertingBytesMars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ export interface RevertingBytesMars extends BaseContract {

onRecvPacket: TypedContractMethod<
[arg0: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ack: AckPacketStructOutput;
skipAck: boolean;
}
],
"view"
>;

Expand Down Expand Up @@ -586,7 +591,12 @@ export interface RevertingBytesMars extends BaseContract {
nameOrSignature: "onRecvPacket"
): TypedContractMethod<
[arg0: IbcPacketStruct],
[AckPacketStructOutput],
[
[AckPacketStructOutput, boolean] & {
ack: AckPacketStructOutput;
skipAck: boolean;
}
],
"view"
>;
getFunction(
Expand Down
Loading

0 comments on commit e4f5184

Please sign in to comment.