Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Integrate diamond #266

Merged
merged 19 commits into from
Jul 27, 2023
34,943 changes: 0 additions & 34,943 deletions contracts/Gateway.json

This file was deleted.

11,900 changes: 11,900 additions & 0 deletions contracts/GatewayGetterFacet.json

Large diffs are not rendered by default.

7,933 changes: 7,933 additions & 0 deletions contracts/GatewayManagerFacet.json

Large diffs are not rendered by default.

14,291 changes: 14,291 additions & 0 deletions contracts/GatewayRouterFacet.json

Large diffs are not rendered by default.

17,869 changes: 0 additions & 17,869 deletions contracts/SubnetActor.json

This file was deleted.

6,168 changes: 6,168 additions & 0 deletions contracts/SubnetActorGetterFacet.json

Large diffs are not rendered by default.

12,629 changes: 12,629 additions & 0 deletions contracts/SubnetActorManagerFacet.json

Large diffs are not rendered by default.

1,073 changes: 544 additions & 529 deletions contracts/SubnetRegistry.json

Large diffs are not rendered by default.

589 changes: 0 additions & 589 deletions src/manager/evm/conversion.rs

This file was deleted.

151 changes: 151 additions & 0 deletions src/manager/evm/convert/checkpoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT

use crate::checkpoint::{NativeBottomUpCheckpoint, NativeChildCheck};
use crate::manager::evm::convert::{eth_to_fil_amount, fil_to_eth_amount};
use crate::manager::evm::manager::{gateway_router_facet, subnet_actor_manager_facet};
use anyhow::anyhow;
use fvm_shared::clock::ChainEpoch;
use ipc_gateway::checkpoint::BatchCrossMsgs;
use ipc_gateway::{CrossMsg, TopDownCheckpoint};
use ipc_sdk::subnet_id::SubnetID;

impl TryFrom<TopDownCheckpoint> for gateway_router_facet::TopDownCheckpoint {
type Error = anyhow::Error;

fn try_from(value: TopDownCheckpoint) -> Result<Self, Self::Error> {
Ok(Self {
epoch: value.epoch as u64,
top_down_msgs: value
.top_down_msgs
.into_iter()
.map(gateway_router_facet::CrossMsg::try_from)
.collect::<anyhow::Result<Vec<_>>>()?,
})
}
}

// Native child check
impl TryFrom<NativeChildCheck> for subnet_actor_manager_facet::ChildCheck {
type Error = anyhow::Error;

fn try_from(value: NativeChildCheck) -> Result<Self, Self::Error> {
let vec_to_array = |v: Vec<u8>| {
let bytes = if v.len() > 32 {
log::warn!("child check more than 32 bytes, taking only first 32 bytes");
&v[0..32]
} else {
&v
};

let mut array = [0u8; 32];
array.copy_from_slice(bytes);

array
};
let checks: Vec<[u8; 32]> = value
.checks
.into_iter()
.map(vec_to_array)
.collect::<Vec<_>>();
Ok(Self {
source: subnet_actor_manager_facet::SubnetID::try_from(&value.source)?,
checks,
})
}
}

impl TryFrom<subnet_actor_manager_facet::ChildCheck> for NativeChildCheck {
type Error = anyhow::Error;

fn try_from(value: subnet_actor_manager_facet::ChildCheck) -> Result<Self, Self::Error> {
let checks = value.checks.into_iter().map(|v| v.to_vec()).collect();
Ok(Self {
source: SubnetID::try_from(value.source)?,
checks,
})
}
}

impl TryFrom<subnet_actor_manager_facet::BottomUpCheckpoint> for NativeBottomUpCheckpoint {
type Error = anyhow::Error;

fn try_from(
value: subnet_actor_manager_facet::BottomUpCheckpoint,
) -> Result<Self, Self::Error> {
let children = value
.children
.into_iter()
.map(NativeChildCheck::try_from)
.collect::<anyhow::Result<_>>()?;

let cross_msgs = value
.cross_msgs
.into_iter()
.map(|i| {
CrossMsg::try_from(i).map_err(|e| anyhow!("cannot convert cross msg due to: {e:}"))
})
.collect::<Result<Vec<_>, _>>()?;

let b = NativeBottomUpCheckpoint {
source: SubnetID::try_from(value.source)?,
proof: Some(value.proof.to_vec()),
epoch: value.epoch as ChainEpoch,
prev_check: Some(value.prev_hash.to_vec()),
children,
cross_msgs: BatchCrossMsgs {
cross_msgs: Some(cross_msgs),
fee: eth_to_fil_amount(&value.fee)?,
},
sig: vec![],
};
Ok(b)
}
}

impl TryFrom<NativeBottomUpCheckpoint> for subnet_actor_manager_facet::BottomUpCheckpoint {
type Error = anyhow::Error;

fn try_from(value: NativeBottomUpCheckpoint) -> Result<Self, Self::Error> {
let cross_msgs = value
.cross_msgs
.cross_msgs
.unwrap_or_default()
.into_iter()
.map(|i| {
subnet_actor_manager_facet::CrossMsg::try_from(i)
.map_err(|e| anyhow!("cannot convert cross msg due to: {e:}"))
})
.collect::<Result<Vec<_>, _>>()?;
let children = value
.children
.into_iter()
.map(|i| {
subnet_actor_manager_facet::ChildCheck::try_from(i)
.map_err(|e| anyhow!("cannot convert child check due to: {e:}"))
})
.collect::<Result<Vec<_>, _>>()?;

let mut prev_hash = [0u8; 32];
if let Some(v) = &value.prev_check {
prev_hash.copy_from_slice(v);
}

let proof = if let Some(v) = value.proof {
ethers::core::types::Bytes::from(v)
} else {
ethers::core::types::Bytes::default()
};

let b = subnet_actor_manager_facet::BottomUpCheckpoint {
source: subnet_actor_manager_facet::SubnetID::try_from(&value.source)?,
epoch: value.epoch as u64,
fee: fil_to_eth_amount(&value.cross_msgs.fee)?,
cross_msgs,
children,
prev_hash,
proof,
};
Ok(b)
}
}
Loading