Skip to content

Commit

Permalink
Merge pull request #35 from etherisc/bugfix/price-feed-integration
Browse files Browse the repository at this point in the history
Bugfix/price feed integration
  • Loading branch information
matthiaszimmermann authored Aug 17, 2023
2 parents 6af51f4 + eb9022e commit 5a09305
Show file tree
Hide file tree
Showing 27 changed files with 920 additions and 1,849 deletions.
17 changes: 17 additions & 0 deletions .devcontainer/Dockerfile.anvil
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:lts-bookworm

EXPOSE 7545

# install foundry
RUN curl -L https://foundry.paradigm.xyz | bash
# RUN echo 'export PATH="$PATH:/root/.foundry/bin"' >> ~/.zshrc
RUN /root/.foundry/bin/foundryup

CMD /root/.foundry/bin/anvil \
--mnemonic "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat" \
--chain-id 1337 \
--port 7545 \
--accounts 20 \
--state /anvil \
--host "0.0.0.0"

14 changes: 0 additions & 14 deletions .devcontainer/Dockerfile.ganache

This file was deleted.

2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": ["ganache:7545",8000],
"forwardPorts": ["anvil:7545",8000],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/scripts/post-create.sh",
Expand Down
8 changes: 4 additions & 4 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ version: '3'


services:
ganache:
anvil:
build:
context: ..
dockerfile: .devcontainer/Dockerfile.ganache
dockerfile: .devcontainer/Dockerfile.anvil
volumes:
- ganache-db:/ganache
- anvil-state:/anvil
# ports:
# - "7545:7545"
brownie:
Expand All @@ -29,4 +29,4 @@ services:
command: sleep infinity

volumes:
ganache-db:
anvil-state:
4 changes: 2 additions & 2 deletions .devcontainer/scripts/deploy-gif.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ fi


# deploy gif and save registry address
echo "Deploying GIF contracts to ganache ..."
brownie console --network=ganache <<EOF
echo "Deploying GIF contracts to devchain ..."
brownie console --network=devchain <<EOF
from scripts.instance import GifInstance
instance = GifInstance(accounts[0], accounts[1])
f = open("/workspace/gif_instance_address.txt", "w")
Expand Down
6 changes: 3 additions & 3 deletions .devcontainer/scripts/post-create.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
brownie networks add Local ganache host=http://ganache:7545 chainid=1234
brownie networks add Local devchain host=http://anvil:7545 chainid=1337

.devcontainer/scripts/deploy-gif.sh

Expand All @@ -14,8 +14,8 @@ if grep -q "usd1=" "/workspace/gif_instance_address.txt"; then
fi

# deploy USD1, USD2, USD3, DIP and save addresses
echo "Deploying the USD contracts to ganache ..."
brownie console --network=ganache <<EOF
echo "Deploying the USD contracts to devchain ..."
brownie console --network=devchain <<EOF
from brownie import USD1, USD2, USD3, DIP
usd1 = USD1.deploy({'from': accounts[0]})
usd2 = USD2.deploy({'from': accounts[0]})
Expand Down
20 changes: 10 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
"@etherisc/gif-interface/=/home/vscode/.brownie/packages/etherisc/gif-interface@a8c9822",
],
"solidity.compileUsingRemoteVersion": "v0.8.2+commit.661d1103",
"peacock.remoteColor": "#4f3cbe",
"peacock.remoteColor": "002366",
"solidity.defaultCompiler": "remote",
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#7060cd",
"activityBar.background": "#7060cd",
"activityBar.activeBackground": "#003599",
"activityBar.background": "#003599",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#61281f",
"activityBarBadge.background": "#df004d",
"activityBarBadge.foreground": "#e7e7e7",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#7060cd",
"statusBar.background": "#4f3cbe",
"sash.hoverBorder": "#003599",
"statusBar.background": "#002366",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#7060cd",
"statusBarItem.remoteBackground": "#4f3cbe",
"statusBarItem.hoverBackground": "#003599",
"statusBarItem.remoteBackground": "#002366",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#4f3cbe",
"titleBar.activeBackground": "#002366",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#4f3cbe99",
"titleBar.inactiveBackground": "#00236699",
"titleBar.inactiveForeground": "#e7e7e799"
},
}
2 changes: 1 addition & 1 deletion check.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

GITHUB_USER = 'etherisc'
GITHUB_REPO = 'registry-contracts'
GITHUB_BRANCH = 'develop'
GITHUB_BRANCH = 'experiment/upgradable-struct' # 'develop'
REPO_BASE = '{}/{}/{}'.format(GITHUB_USER, GITHUB_REPO, GITHUB_BRANCH)
GITHUB_BASE = 'https://raw.githubusercontent.com/{}'.format(REPO_BASE)

Expand Down
100 changes: 100 additions & 0 deletions contracts/DepegMessageHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.2;

import "./EIP712.sol";


contract DepegMessageHelper is
EIP712
{
// EIP-712 Depeg specifics
string public constant EIP712_DOMAIN_NAME = "EtheriscDepeg";
string public constant EIP712_DOMAIN_VERSION = "1";

string public constant EIP712_POLICY_TYPE = "Policy(address wallet,uint256 protectedBalance,uint256 duration,uint256 bundleId,bytes32 signatureId)";
bytes32 private constant EIP712_POLICY_TYPE_HASH = keccak256(abi.encodePacked(EIP712_POLICY_TYPE));

// tracking of signatures
mapping(bytes32 /* signature hash */ => bool /* used */) private _signatureIsUsed;


constructor()
EIP712(EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION)
{ }

function checkAndRegisterSignature (
address policyHolder,
address protectedWallet,
uint256 protectedBalance,
uint256 duration,
uint256 bundleId,
bytes32 signatureId,
bytes calldata signature
)
external
{
bytes32 signatureHash = keccak256(abi.encode(signature));
require(!_signatureIsUsed[signatureHash], "ERROR:DMH-001:SIGNATURE_USED");

address signer = getSignerFromDigestAndSignature(
protectedWallet,
protectedBalance,
duration,
bundleId,
signatureId,
signature);

require(policyHolder == signer, "ERROR:DMH-002:SIGNATURE_INVALID");

_signatureIsUsed[signatureHash] = true;
}

function getSignerFromDigestAndSignature(
address protectedWallet,
uint256 protectedBalance,
uint256 duration,
uint256 bundleId,
bytes32 signatureId,
bytes calldata signature
)
public
view
returns(address)
{
bytes32 digest = getDigest(
protectedWallet,
protectedBalance,
duration,
bundleId,
signatureId
);

return getSigner(digest, signature);
}


function getDigest(
address protectedWallet,
uint256 protectedBalance,
uint256 duration,
uint256 bundleId,
bytes32 signatureId
)
internal
view
returns(bytes32)
{
bytes32 structHash = keccak256(
abi.encode(
EIP712_POLICY_TYPE_HASH,
protectedWallet,
protectedBalance,
duration,
bundleId,
signatureId
)
);

return getTypedDataV4Hash(structHash);
}
}
Loading

0 comments on commit 5a09305

Please sign in to comment.