Skip to content

Commit

Permalink
feat: show incoming
Browse files Browse the repository at this point in the history
  • Loading branch information
noyyyy committed Apr 13, 2024
1 parent 7b4acec commit 4359457
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 52 deletions.
27 changes: 27 additions & 0 deletions packages/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,41 @@ import { DeploymentLocation } from "./component/DeploymentLocation";
import { StatusBar } from "./component/StatusBar";
import { Title } from "./component/Title";
import "./index.css";
import { Rules } from "./component/Rules";
import { March } from "./component/March";

function App() {
return (
<Web3Provider>
<div className="flex relative h-screen w-screen">
<Rules />
<StatusBar />
<Title />
<Champion />
<March
className="w-80 left-1/4 top-[40%] rotate-[18deg]"
chainId={baseSepolia.id}
/>
<March
className="w-80 left-1/4 bottom-[45%] rotate-[-18deg]"
chainId={arbitrumSepolia.id}
/>

<March
className="w-80 right-1/4 top-[40%] rotate-[-18deg]"
chainId={avalancheFuji.id}
/>

<March
className="w-80 right-1/4 bottom-[45%] rotate-[18deg]"
chainId={bscTestnet.id}
/>

<March
className="w-40 left-1/2 -translate-x-1/2 bottom-[30%] rotate-[90deg]"
chainId={optimismSepolia.id}
/>

{/* op sepolia */}
<DeploymentLocation
className="left-1/2 -translate-x-1/2 bottom-[4rem] "
Expand Down
12 changes: 10 additions & 2 deletions packages/client/src/Web3Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WagmiProvider, createConfig } from "wagmi";
import { WagmiProvider, createConfig, http } from "wagmi";
import {
arbitrumSepolia,
avalancheFuji,
Expand All @@ -21,7 +21,15 @@ const config = createConfig(
bscTestnet,
baseSepolia,
],
// transports: {},
transports: {
[avalancheFuji.id]: http(
"https://avalanche-fuji-c-chain-rpc.publicnode.com"
),
[optimismSepolia.id]: http("https://optimism-sepolia-rpc.publicnode.com"),
[arbitrumSepolia.id]: http("https://arbitrum-sepolia-rpc.publicnode.com"),
[bscTestnet.id]: http("https://bsc-testnet-rpc.publicnode.com"),
[baseSepolia.id]: http("https://base-sepolia-rpc.publicnode.com"),
},

// Required API Keys
walletConnectProjectId: "",
Expand Down
3 changes: 0 additions & 3 deletions packages/client/src/component/Line.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions packages/client/src/component/March.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useWatchContractEvent } from "wagmi";
import { TrojanHorseAddress } from "../constant";
import { TrojanHorseAbi } from "../abis/TrojanHorse";
import { useState } from "react";

export function March({
chainId,
className,
}: {
chainId: number;
className: string;
}) {
const [inComing, setInComing] = useState<
{
messageId: string;
soldiers: number;
}[]
>([]);
useWatchContractEvent({
address: TrojanHorseAddress[chainId],
abi: TrojanHorseAbi,
eventName: "HorseSent",
onLogs(logs) {
logs.forEach((log) => {
setInComing([
...inComing,
{
messageId: log.args.messageId!,
soldiers: Number(log.args.soldierAmount!),
},
]);
});
},
chainId: chainId,
poll: true,
pollingInterval: 10000,
});

return (
<div
className={`absolute bg-black h-1 transform flex flex-row ${className}`}
>
{inComing.map((i) => (
<a id={i.messageId} href={`https://ccip.chain.link/msg/${i.messageId}`}>
{i.soldiers}
</a>
))}
</div>
);
}
10 changes: 10 additions & 0 deletions packages/client/src/component/Rules.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function Rules() {
return (
<div className="m-2">
<div className=" text-2xl font-bold">Rules:</div>
<div >
Fund your favorite layer to capture the treasure on ethereum sepolia
</div>
</div>
);
}
40 changes: 16 additions & 24 deletions packages/contracts/deployments/sepolia/Troy.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "bytes32",
"name": "messageId",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "uint256",
Expand Down Expand Up @@ -386,21 +392,14 @@
"name": "readStorageValue",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "championChainId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "soldierAmount",
"type": "uint256"
}
],
"internalType": "struct Troy.TroyStorage",
"name": "",
"type": "tuple"
"internalType": "uint256",
"name": "championChainId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "soldierAmount",
"type": "uint256"
}
],
"stateMutability": "view",
Expand Down Expand Up @@ -540,15 +539,8 @@
"0x2B4899c7316cc7d15301dbD0A5D7204456D3B441",
"0x485cc955000000000000000000000000ba45b3d7a42c3554fa98bdc3f790da2676cb05600000000000000000000000000bf3de8c5d3e8a2b34d2beeb17abfcebaf363a59"
],
"numDeployments": 1,
"numDeployments": 2,
"bytecode": "0x60806040526040516107353803806107358339810160408190526100229161031e565b61002e82826000610035565b505061043b565b61003e8361006b565b60008251118061004b5750805b156100665761006483836100ab60201b6100291760201c565b505b505050565b610074816100d7565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60606100d0838360405180606001604052806027815260200161070e602791396101a9565b9392505050565b6100ea8161022260201b6100551760201c565b6101515760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084015b60405180910390fd5b806101887f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc60001b61023160201b6100641760201c565b80546001600160a01b0319166001600160a01b039290921691909117905550565b6060600080856001600160a01b0316856040516101c691906103ec565b600060405180830381855af49150503d8060008114610201576040519150601f19603f3d011682016040523d82523d6000602084013e610206565b606091505b50909250905061021886838387610234565b9695505050505050565b6001600160a01b03163b151590565b90565b606083156102a0578251610299576001600160a01b0385163b6102995760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610148565b50816102aa565b6102aa83836102b2565b949350505050565b8151156102c25781518083602001fd5b8060405162461bcd60e51b81526004016101489190610408565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561030d5781810151838201526020016102f5565b838111156100645750506000910152565b6000806040838503121561033157600080fd5b82516001600160a01b038116811461034857600080fd5b60208401519092506001600160401b038082111561036557600080fd5b818501915085601f83011261037957600080fd5b81518181111561038b5761038b6102dc565b604051601f8201601f19908116603f011681019083821181831017156103b3576103b36102dc565b816040528281528860208487010111156103cc57600080fd5b6103dd8360208301602088016102f2565b80955050505050509250929050565b600082516103fe8184602087016102f2565b9190910192915050565b60208152600082518060208401526104278160408501602087016102f2565b601f01601f19169190910160400192915050565b6102c48061044a6000396000f3fe60806040523661001357610011610017565b005b6100115b610027610022610067565b61009f565b565b606061004e8383604051806060016040528060278152602001610268602791396100c3565b9392505050565b6001600160a01b03163b151590565b90565b600061009a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b3660008037600080366000845af43d6000803e8080156100be573d6000f35b3d6000fd5b6060600080856001600160a01b0316856040516100e09190610218565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b50915091506101318683838761013b565b9695505050505050565b606083156101ac5782516101a5576001600160a01b0385163b6101a55760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064015b60405180910390fd5b50816101b6565b6101b683836101be565b949350505050565b8151156101ce5781518083602001fd5b8060405162461bcd60e51b815260040161019c9190610234565b60005b838110156102035781810151838201526020016101eb565b83811115610212576000848401525b50505050565b6000825161022a8184602087016101e8565b9190910192915050565b60208152600082518060208401526102538160408501602087016101e8565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220ff8e6f2d761d58b3bd984933269e01a7ff1f70a460b808056daa4cff1ee8ab6964736f6c63430008090033416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564",
"deployedBytecode": "0x60806040523661001357610011610017565b005b6100115b610027610022610067565b61009f565b565b606061004e8383604051806060016040528060278152602001610268602791396100c3565b9392505050565b6001600160a01b03163b151590565b90565b600061009a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b3660008037600080366000845af43d6000803e8080156100be573d6000f35b3d6000fd5b6060600080856001600160a01b0316856040516100e09190610218565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b50915091506101318683838761013b565b9695505050505050565b606083156101ac5782516101a5576001600160a01b0385163b6101a55760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064015b60405180910390fd5b50816101b6565b6101b683836101be565b949350505050565b8151156101ce5781518083602001fd5b8060405162461bcd60e51b815260040161019c9190610234565b60005b838110156102035781810151838201526020016101eb565b83811115610212576000848401525b50505050565b6000825161022a8184602087016101e8565b9190910192915050565b60208152600082518060208401526102538160408501602087016101e8565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220ff8e6f2d761d58b3bd984933269e01a7ff1f70a460b808056daa4cff1ee8ab6964736f6c63430008090033",
"execute": {
"methodName": "initialize",
"args": [
"0xba45b3d7A42c3554fa98bDC3F790da2676Cb0560",
"0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59"
]
},
"implementation": "0x2B4899c7316cc7d15301dbD0A5D7204456D3B441"
"implementation": "0x324E0F328747fDe1c85ae4ab3e6be41d2199b531"
}
57 changes: 36 additions & 21 deletions packages/contracts/deployments/sepolia/Troy_Implementation.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions packages/contracts/src/Troy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ contract Troy is UUPSUpgradeable, Ownable2StepUpgradeable, CCIPReceiverUpgradeab
struct TroyStorage {
uint256 championChainId;
uint256 soldierAmount;
mapping(bytes32 => bool) messageIdArrived;
}

event SoldiersArrive(
bytes32 indexed messageId,
uint256 indexed chainId,
uint256 amount,
uint256 initChampion,
Expand Down Expand Up @@ -59,7 +61,13 @@ contract Troy is UUPSUpgradeable, Ownable2StepUpgradeable, CCIPReceiverUpgradeab
}
}

bytes32 messageId = any2EvmMessage.messageId;

// mark message as arrived
_getTroyStorage().messageIdArrived[messageId] = true;

emit SoldiersArrive(
messageId,
srcChainId,
incommingSoldierAmount,
championChainId,
Expand All @@ -69,7 +77,8 @@ contract Troy is UUPSUpgradeable, Ownable2StepUpgradeable, CCIPReceiverUpgradeab
);
}

function readStorageValue() public view returns (TroyStorage memory) {
return _getTroyStorage();
function readStorageValue() public view returns (uint256 championChainId, uint256 soldierAmount) {
TroyStorage storage $ = _getTroyStorage();
return ($.championChainId, $.soldierAmount);
}
}

0 comments on commit 4359457

Please sign in to comment.