Skip to content

Commit

Permalink
Merge branch 'main' into update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Sep 4, 2024
2 parents eb95108 + 47a1a06 commit c57c7b6
Show file tree
Hide file tree
Showing 34 changed files with 189 additions and 208 deletions.
45 changes: 45 additions & 0 deletions .github/actions/cache-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: cache-node
description: install and Cache Node Modules
runs:
using: composite
steps:
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: |
yarn.lock
ui/yarn.lock
- name: Cache top-level node modules
id: top-node-modules
uses: actions/cache@v4
with:
key: node_modules-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
path: node_modules

- name: Cache ui node modules
id: ui-node-modules
uses: actions/cache@v4
with:
key: node_modules-${{ runner.os }}-${{ hashFiles('ui/yarn.lock') }}
path: ui/node_modules

- name: Cache nextjs build cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/ui/.next/cache
# Generate a new cache whenever packages or source files change.
key: nextjs-${{ runner.os }}-${{ hashFiles('ui/src/yarn.lock') }}-${{ hashFiles('ui/src/**/*.ts', 'ui/src/**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
nextjs-${{ runner.os }}-${{ hashFiles('ui/src/yarn.lock') }}-
- name: Install dependencies
shell: bash
run: |
echo "Before installing dependencies" $(date "+%F %T.%3N")
yarn --frozen-lockfile --network-concurrency 2
(cd ui && yarn --frozen-lockfile --network-concurrency 2)
echo "After installing dependencies" $(date "+%F %T.%3N")
56 changes: 21 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request]

env:
FOUNDRY_PROFILE: ci
FOUNDRY_FORK_BLOCK_NUMBER: 61373304

jobs:
common:
Expand All @@ -12,34 +13,26 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Cache solana
- name: Install and cache solana
uses: ./.github/actions/cache-solana

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: |
yarn.lock
ui/yarn.lock
- name: Install dependencies
run: |
yarn --frozen-lockfile --network-concurrency 2
(cd ui && yarn --frozen-lockfile --network-concurrency 2)
- name: Install and cache node modules
uses: ./.github/actions/cache-node

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Cache rust
uses: Swatinem/rust-cache@v2
with:
workspaces: solana-contract

- name: install essentials
run: |
sudo apt-get update
sudo apt-get install -y pkg-config build-essential libudev-dev
- name: Install essentials
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: pkg-config build-essential libudev-dev
version: 1.0

evm:
runs-on: ubuntu-latest
Expand All @@ -62,8 +55,10 @@ jobs:
forge build --sizes
- name: Run Forge tests
env:
RPC: ${{ secrets.POLYGON_RPC }}
working-directory: evm-contract
run: forge test -vvv
run: forge test -vvv --fork-url $RPC --fork-block-number $FOUNDRY_FORK_BLOCK_NUMBER

solana:
needs: common
Expand All @@ -77,6 +72,11 @@ jobs:

- name: Cache rust
uses: Swatinem/rust-cache@v2
with:
workspaces: solana-contract

- name: Install and cache solana
uses: ./.github/actions/cache-solana

- name: Run fmt
working-directory: solana-contract
Expand All @@ -86,14 +86,6 @@ jobs:
working-directory: solana-contract
run: cargo clippy -- --deny=warnings

- name: Cache build artifact
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
solana-contract/target
key: cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('rust-toolchain.toml') }}
- name: Build
working-directory: solana-contract
run: cargo build-sbf
Expand All @@ -117,14 +109,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: |
yarn.lock
ui/yarn.lock
- name: Install and cache node modules
uses: ./.github/actions/cache-node

- name: Check that all deps are restored
run: |
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "evm-contract/lib/forge-std"]
path = evm-contract/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "evm-contract/lib/contracts"]
path = evm-contract/lib/contracts
url = https://github.com/ToucanProtocol/contracts
[submodule "evm-contract/lib/OffsetHelper"]
path = evm-contract/lib/OffsetHelper
url = https://github.com/ToucanProtocol/OffsetHelper
Expand All @@ -15,3 +12,6 @@
path = evm-contract/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
branch = release-v4.9
[submodule "evm-contract/lib/ToucanProtocol"]
path = evm-contract/lib/ToucanProtocol
url = https://github.com/ToucanProtocol/contracts
15 changes: 0 additions & 15 deletions docs/Solana Carbon Retirement.puml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ TX 3 - Redeem bridged tokens
end note

User->Wormhole_P: Poll for VAA
note left
TODO is this correct?
end note
Wormhole_P-->User: <<VAA available>>
User->HoldingContract_P: Redeem from Bridge
HoldingContract_P->Wormhole_P:Redeem VAA
Wormhole_P-->HoldingContract_P: <<USDC>>
note left
TODO can we store the originator
of the bridge here, ie the solana address?
end note
HoldingContract_P-->User: <<OK>>

note left of User
Expand All @@ -78,11 +71,6 @@ CarbonOffsetSettler_P->TCO2Contract_P:retireAndMintCertificate
TCO2Contract_P-->CarbonOffsetSettler_P:<<retirement certificate>>
CarbonOffsetSettler_P-->HoldingContract_P: <<OK>>
HoldingContract_P-->User: <<OK>>

note left
TODO any work required here to convert it to an ERC721?
end note

note left of User
TX 5 - Bridge Retirement Certificate
end note
Expand All @@ -97,9 +85,6 @@ TX 6 - Redeem Retirement Certificate
end note

User->Wormhole_S: Poll for VAA
note left
TODO is this correct?
end note
Wormhole_S-->User: <<VAA available>>
User->RetirementProgram_S: Redeem ticket (pass VAA)
RetirementProgram_S->Wormhole_S: Redeem VAA
Expand Down
2 changes: 1 addition & 1 deletion evm-contract/lib/forge-std
Submodule forge-std updated 2 files
+7 −1 src/Vm.sol
+2 −2 test/Vm.t.sol
2 changes: 1 addition & 1 deletion evm-contract/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
forge-std/=lib/forge-std/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
toucan/=lib/contracts/contracts
toucan/=lib/ToucanProtocol/contracts
@OffsetHelper/=lib/OffsetHelper/contracts
2 changes: 0 additions & 2 deletions evm-contract/src/CarbonOffsetSettler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import "lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeab
import "lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol";
import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/IERC721Upgradeable.sol";
import "forge-std/console.sol";
import "toucan/RetirementCertificates.sol";
import "forge-std/console.sol";

contract CarbonOffsetSettler is OwnableUpgradeable, IERC721Receiver {
address public constant NCT = 0xD838290e877E0188a4A44700463419ED96c16107;
Expand Down
43 changes: 32 additions & 11 deletions evm-contract/src/test/HoldingContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ import "src/CarbonOffsetSettler.sol";
import "src/HoldingContractFactory.sol";
import "forge-std/console.sol";
import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/IERC721Upgradeable.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

contract HoldingContractTest is Test {
HoldingContract holdingImplementation;
CarbonOffsetSettler carbonOffsetSettler;
HoldingContractFactory factory;
address proxy;
address usdc = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;
// address usdc = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;
address public constant CERT = 0x5e377f16E4ec6001652befD737341a28889Af002;

IERC20 public constant usdc = IERC20(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174);

address user = address(1234);
address tco2 = 0x463de2a5c6E8Bb0c87F4Aa80a02689e6680F72C7;

// TCO2 contract address for carbon credit project
// https://registry.verra.org/app/projectDetail/VCS/875
// 208k supply remaining at polygon block # 61373304
address tco2 = 0x0BCCAB36F518f55E00f3efe2e828aE63cd2ac1B9;
string beneficiaryName = "0x0";
bytes32 SolanaAccountAddress = "";

Expand Down Expand Up @@ -110,12 +117,12 @@ contract HoldingContractTest is Test {
assertEq(HoldingContract(proxy).beneficiary(), address(146));
IERC721Upgradeable cert = IERC721Upgradeable(CERT);

deal(usdc, proxy, 100 * 1e6);
deal(address(usdc), proxy, 100 * 1e6);

HoldingContract(proxy).offset("entity", "msg");
assertEq(IERC20(usdc).balanceOf(proxy), 0);
assertEq(cert.balanceOf(proxy), 1);
// deal(usdc, proxy, 100 * 1e6);
// deal(address(usdc), proxy, 100 * 1e6);
// HoldingContract(proxy).offset("2nd entity", "msg");
// assertEq(cert.balanceOf(proxy), 2);

Expand All @@ -132,7 +139,7 @@ contract HoldingContractTest is Test {
);
HoldingContract(proxy).setBeneficiary(address(6143), "Solana");
assertEq(HoldingContract(proxy).beneficiary(), address(6143));
deal(usdc, proxy, 100 * 1e6);
deal(address(usdc), proxy, 100 * 1e6);

HoldingContract(proxy).offset("entity", "msg");
assertEq(IERC20(usdc).balanceOf(proxy), 0);
Expand All @@ -148,7 +155,7 @@ contract HoldingContractTest is Test {
function test_Offset() public {
// fund holding contract with USDC
uint amount = 100 * 1e6;
deal(usdc, proxy, amount);
deal(address(usdc), proxy, amount);
// vm.prank(0x19aB546E77d0cD3245B2AAD46bd80dc4707d6307);
// usdc.call(
// abi.encodeWithSignature(
Expand All @@ -161,7 +168,6 @@ contract HoldingContractTest is Test {
IERC721Upgradeable cert = IERC721Upgradeable(CERT);
assertEq(cert.balanceOf(proxy), 0);
assertEq(IERC20(usdc).balanceOf(proxy), 100 * 1e6);

// Call offset and emit event

vm.expectEmit(true, true, true, true);
Expand Down Expand Up @@ -201,7 +207,7 @@ contract HoldingContractTest is Test {

// Fund holding contract with USDC
uint amount = 100 * 1e6;
deal(usdc, proxy, amount);
deal(address(usdc), proxy, amount);
// vm.prank(0x19aB546E77d0cD3245B2AAD46bd80dc4707d6307);
// usdc.call(
// abi.encodeWithSignature(
Expand Down Expand Up @@ -236,12 +242,27 @@ contract HoldingContractTest is Test {

function test_bridge() public {
uint amount = 100 * 1e6;
deal(usdc, proxy, amount);
deal(address(usdc), proxy, amount);
vm.startPrank(user);

vm.recordLogs();
HoldingContract(proxy).offset("entity", "msg");
HoldingContract(proxy).bridgeToAddress(4054, SolanaAccountAddress);
IERC721Upgradeable cert = IERC721Upgradeable(CERT);

bytes32 topic = keccak256("Transfer(address,address,uint256)");
uint256 tokenId;
Vm.Log[] memory logs = vm.getRecordedLogs();
for (uint i = 0; i < logs.length; i++) {
if (logs[i].topics[0] == topic && logs[i].topics.length > 3) {
// from address (0) is topic 1
// to address (holding contract) is topic 2
// tokenId is topic 3
tokenId = uint256(logs[i].topics[3]);
}
}

HoldingContract(proxy).bridgeToAddress(tokenId, SolanaAccountAddress);

IERC721Upgradeable cert = IERC721Upgradeable(CERT);
assertEq(cert.balanceOf(proxy), 0);
}
}
16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
"@jup-ag/api": "^6.0.10",
"@solana/spl-token": "0.4.6",
"@solana/web3.js": "^1.76.0",
"@solana/web3.js": "^1.95.3",
"bs58": "^5.0.0",
"ethers": "^5.7.2",
"jsbi": "^4.3.0",
Expand All @@ -34,15 +34,11 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "tsc",
"initialize": "ts-node scripts/initialize.ts",
"wrap-sol": "ts-node scripts/wrapSOL.ts",
"deposit-usdc": "ts-node scripts/depositUSDC.ts",
"swap": "ts-node scripts/swap.ts",
"bridge": "ts-node scripts/bridge.ts",
"redeem": "ts-node scripts/redeemPolygonVAA.ts",
"retire": "ts-node scripts/retireFunds.ts",
"bridge-nft": "ts-node scripts/bridgeNFT.ts"
"install:all": "yarn install && (cd ui && yarn install)",
"build:ui": "cd ui && yarn build",
"start:ui": "cd ui && yarn dev",
"build:evm": "cd evm-contract && forge build",
"build:solana": "cd solana-contract && anchor build"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit c57c7b6

Please sign in to comment.