Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update subgraph for escrow #253

Merged
merged 14 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/core/contracts/Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ contract Escrow is IEscrow, ReentrancyGuard {
event TrustedHandlerAdded(address _handler);
event IntermediateStorage(string _url, string _hash);
event Pending(string manifest, string hash);
event BulkTransfer(uint256 indexed _txId, uint256 _bulkCount);
event BulkTransfer(
uint256 indexed _txId,
uint256 _bulkCount,
uint256 _amountPaid,
bool _isPartial
);
event Cancelled();
event Completed();

Expand Down Expand Up @@ -230,13 +235,15 @@ contract Escrow is IEscrow, ReentrancyGuard {
uint256 recordingOracleFee
) = finalizePayouts(_amounts);

uint256 _amountPaid = 0;
for (uint256 i = 0; i < _recipients.length; ++i) {
uint256 amount = finalAmounts[i];
if (amount == 0) {
continue;
}
finalAmounts[i] = 0;
_safeTransfer(_recipients[i], amount);
_amountPaid += amount;
}

delete finalAmounts;
Expand All @@ -263,7 +270,12 @@ contract Escrow is IEscrow, ReentrancyGuard {
status = EscrowStatuses.Paid;
}
}
emit BulkTransfer(_txId, _recipients.length);
emit BulkTransfer(
_txId,
_recipients.length,
_amountPaid,
status == EscrowStatuses.Partial
);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@human-protocol/core",
"description": "Human Protocol Core Smart Contracts",
"version": "1.0.39",
"version": "1.0.40",
"files": [
"contracts/**/*.sol",
"abis/**/*.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/Escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ describe('Escrow', function () {
.bulkPayOut(recepients, amounts, MOCK_URL, MOCK_HASH, '000')
)
.to.emit(escrow, 'BulkTransfer')
.withArgs(anyValue, recepients.length);
.withArgs(anyValue, recepients.length, 8, true);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/eth-kvstore-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@mui/icons-material": "^5.10.6",
"@mui/material": "^5.10.7",
"@mui/x-data-grid": "^5.17.4",
"@rainbow-me/rainbowkit": "^0.7.0",
"@rainbow-me/rainbowkit": "^0.8.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/examples/eth-kvstore-gui/src/components/Decrypt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
export default function ColorTextFields() {
const [open, setOpen] = useState(false);


const { address } = useAccount();
const [key, setKey] = useState<string>("");
const [value, setValue] = useState<string>("");
Expand All @@ -32,8 +32,8 @@ export default function ColorTextFields() {
const [password, setPassword] = useState<string>("");
const [error, setError] = useState<string>("");
const { refetch } = useContractRead({
addressOrName: process.env.REACT_APP_CONTRACT as string,
contractInterface: KVStore,
address: process.env.REACT_APP_CONTRACT as `0x${string}`,
abi: KVStore,
functionName: "get",
args: [address, key],
});
Expand All @@ -45,7 +45,7 @@ export default function ColorTextFields() {
try {
const { data } = await refetch();
setValue(await showIPFS(data!.toString()));

} catch (e) {
if(e instanceof Error){
setError(e.message)
Expand All @@ -69,7 +69,7 @@ export default function ColorTextFields() {
privateKey: await openpgp.readPrivateKey({ armoredKey: privkey }),
passphrase: password,
});

const message = await openpgp.readMessage({
armoredMessage: value, // parse armored message
});
Expand All @@ -85,9 +85,9 @@ export default function ColorTextFields() {
setDecrypted("");
setOpen(true);
setError(e.message)

}

}
}
return (
Expand Down
18 changes: 9 additions & 9 deletions packages/examples/eth-kvstore-gui/src/components/GeneratePGP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default function GeneratePGP() {
setOpen(false);
};
const { config } = usePrepareContractWrite({
addressOrName: process.env.REACT_APP_CONTRACT as string,
contractInterface: KVStore,
address: process.env.REACT_APP_CONTRACT as `0x${string}`,
abi: KVStore,
functionName: "set",
args: ["public_key", cid],
});
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function GeneratePGP() {
setPublicKey("");
setError(e.message);
}

}
}

Expand All @@ -115,7 +115,7 @@ export default function GeneratePGP() {
if(e instanceof Error){
setError(e.message);
}

}
}
async function storeKV() {
Expand All @@ -125,7 +125,7 @@ export default function GeneratePGP() {
if(e instanceof Error){
setError(e.message);
}

}
}

Expand All @@ -140,7 +140,7 @@ export default function GeneratePGP() {
{ open && <Grid
container
justifyContent="center"

>
<Alert onClose={handleClose} severity="success" className="alertWidth">
Transaction success
Expand All @@ -150,7 +150,7 @@ export default function GeneratePGP() {
{error.length > 0 && <Grid
container
justifyContent="center"

>
<Alert onClose={handleClose} severity="error" className="alertWidth">
{error}
Expand Down Expand Up @@ -212,7 +212,7 @@ export default function GeneratePGP() {
disabled={loading}
variant="contained"
onClick={downloadKey}

>
Download Key
</Button>}
Expand All @@ -221,7 +221,7 @@ export default function GeneratePGP() {
{(loading || publicKey) && <Button
disabled={loading || !write}
className="marginBottom10"

variant="contained"
onClick={storeKV}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ export default function ImportButton({
loading:boolean;
}) {
const { config } = usePrepareContractWrite({
addressOrName: process.env.REACT_APP_CONTRACT as string,
contractInterface: KVStore,
address: process.env.REACT_APP_CONTRACT as `0x${string}`,
abi: KVStore,
functionName: "set",
args: ["", ""],
});
const { writeAsync } = useContractWrite({
...config,
mode: 'recklesslyUnprepared',
onSuccess() {
setOpen(true);
setLoading(false);
Expand All @@ -55,7 +56,7 @@ export default function ImportButton({
await writeAsync?.({
recklesslySetUnpreparedArgs: ["public_key", cid2],
});

} catch (e) {
if (e instanceof Error) {
setError(e.message);
Expand Down
19 changes: 10 additions & 9 deletions packages/examples/eth-kvstore-gui/src/components/KeyValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ export default function KeyValue() {
setError("")
};


const { config } = usePrepareContractWrite({
addressOrName: process.env.REACT_APP_CONTRACT as string,
contractInterface: KVStore,
address: process.env.REACT_APP_CONTRACT as `0x${string}`,
abi: KVStore,
functionName: "set",
args: [key, value],
});
const { writeAsync } = useContractWrite({
...config,
mode: 'recklesslyUnprepared',
onSuccess() {
setOpen(true);
setLoading(false);
Expand Down Expand Up @@ -74,7 +75,7 @@ export default function KeyValue() {
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
const message=await openpgp.createMessage({ text: value });
const encrypted = await openpgp.encrypt({
message,
message,
encryptionKeys: publicKey,
config: {
preferredCompressionAlgorithm: openpgp.enums.compression.zlib,
Expand All @@ -86,20 +87,20 @@ export default function KeyValue() {
recklesslySetUnpreparedArgs: [key, cid]
});


} catch (e) {
if (e instanceof Error) {
setOpen(false);
setLoading(false);
setError(e.message)
}

}
}
const {address} = useAccount();
const { refetch } = useContractRead({
addressOrName: process.env.REACT_APP_CONTRACT as string,
contractInterface: KVStore,
address: process.env.REACT_APP_CONTRACT as `0x${string}`,
abi: KVStore,
functionName: "get",
args: [address, "public_key"],
});
Expand All @@ -120,7 +121,7 @@ export default function KeyValue() {
Transaction success
</Alert>
</Grid>}

{error.length>0 && <Grid container justifyContent="center" className="marginBottom2">
<Alert onClose={handleClose} severity="error" className="alertWidth">
{error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default function YourPublicKey() {
const [error, setError] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
const { refetch } = useContractRead({
addressOrName: process.env.REACT_APP_CONTRACT as string,
contractInterface: KVStore,
address: process.env.REACT_APP_CONTRACT as `0x${string}`,
abi: KVStore,
functionName: "get",
args: [address, "public_key"],
async onSuccess(data: Result) {
Expand Down
5 changes: 3 additions & 2 deletions packages/examples/eth-kvstore-gui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
} from "@rainbow-me/rainbowkit";
import "./styles/globals.css";
import "@rainbow-me/rainbowkit/styles.css";
import { chain, configureChains, createClient, WagmiConfig } from "wagmi";
import { configureChains, createClient, WagmiConfig } from "wagmi";
import * as chain from "wagmi/chains";
import { alchemyProvider } from "wagmi/providers/alchemy";
import { publicProvider } from "wagmi/providers/public";

const { chains, provider } = configureChains(
[chain.polygonMumbai, chain.localhost, chain.mainnet, chain.ropsten, chain.rinkeby],
[chain.polygonMumbai, chain.localhost, chain.mainnet],
[
alchemyProvider({ apiKey: process.env.REACT_APP_ALCHEMY_ID as string }),
publicProvider(),
Expand Down
9 changes: 7 additions & 2 deletions packages/sdk/typescript/subgraph/config/bsc-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
"abi": "./node_modules/@human-protocol/core/abis/Escrow.json"
},
"Staking": {
"address": "0xC2163A0928034e020f0d31e1171Ba0D6d9AfFB6c",
"startBlock": 25486216,
"address": "0x05398211bA2046E296fBc9a9D3EB49e3F15C3123",
"startBlock": 25486218,
"abi": "./node_modules/@human-protocol/core/abis/Staking.json"
},
"KVStore": {
"address": "0x70671167176C4934204B1C7e97F5e86695857ef2",
"startBlock": 25486223,
"abi": "./node_modules/@human-protocol/core/abis/KVStore.json"
},
"RewardPool": {
"address": "0x4A5963Dd6792692e9147EdC7659936b96251917a",
"startBlock": 25486227,
"abi": "./node_modules/@human-protocol/core/abis/RewardPool.json"
}
}
10 changes: 10 additions & 0 deletions packages/sdk/typescript/subgraph/config/bsctest-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@
"address": "0x3aD4B091E054f192a822D1406f4535eAd38580e4",
"startBlock": 26716360,
"abi": "./node_modules/@human-protocol/core/abis/KVStore.json"
},
"RewardPool": {
"address": "0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29",
"startBlock": 26716365,
"abi": "./node_modules/@human-protocol/core/abis/RewardPool.json"
},
"Reputation": {
"address": "0xb8F62639aA3DD51A39d6AACD969363e7F87dcc98",
"startBlock": 26716369,
"abi": "./node_modules/@human-protocol/core/abis/Reputation.json"
}
}
10 changes: 10 additions & 0 deletions packages/sdk/typescript/subgraph/config/goerli-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@
"address": "0xc9Fe39c4b6e1d7A2991355Af159956982DADf842",
"startBlock": 8403040,
"abi": "./node_modules/@human-protocol/core/abis/KVStore.json"
},
"RewardPool": {
"address": "0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4",
"startBlock": 8403042,
"abi": "./node_modules/@human-protocol/core/abis/RewardPool.json"
},
"Reputation": {
"address": "0x6B220A6306D8D86C9878A1FBb3F49707b3E2b405",
"startBlock": 8403044,
"abi": "./node_modules/@human-protocol/core/abis/Reputation.json"
}
}
10 changes: 10 additions & 0 deletions packages/sdk/typescript/subgraph/config/moonbase-alpha-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@
"address": "0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d",
"startBlock": 3648030,
"abi": "./node_modules/@human-protocol/core/abis/KVStore.json"
},
"RewardPool": {
"address": "0x2bfA592DBDaF434DDcbb893B1916120d181DAD18",
"startBlock": 3648034,
"abi": "./node_modules/@human-protocol/core/abis/RewardPool.json"
},
"Reputation": {
"address": "0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29",
"startBlock": 3648038,
"abi": "./node_modules/@human-protocol/core/abis/Reputation.json"
}
}
5 changes: 5 additions & 0 deletions packages/sdk/typescript/subgraph/config/moonbeam-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
"address": "0x70671167176C4934204B1C7e97F5e86695857ef2",
"startBlock": 2904821,
"abi": "./node_modules/@human-protocol/core/abis/KVStore.json"
},
"RewardPool": {
"address": "0x4A5963Dd6792692e9147EdC7659936b96251917a",
"startBlock": 2904825,
"abi": "./node_modules/@human-protocol/core/abis/RewardPool.json"
}
}
Loading