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

Added functionality for manyDeposits change in the escrow #11

Merged
merged 1 commit into from
Nov 8, 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
167 changes: 111 additions & 56 deletions abis/MockStaking.abi.json
Original file line number Diff line number Diff line change
@@ -1,75 +1,130 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_token",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "address",
"name": "_allocationID",
"type": "address"
},
{
"internalType": "address",
"name": "_indexer",
"type": "address"
}
{
"internalType": "bytes32",
"name": "_subgraphDeploymentID",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "_tokens",
"type": "uint256"
},
{
"internalType": "address",
"name": "_allocationID",
"type": "address"
},
{
"internalType": "bytes32",
"name": "_metadata",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "_proof",
"type": "bytes"
}
],
"name": "allocate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_tokens",
"type": "uint256"
},
{
"internalType": "address",
"name": "_allocationID",
"type": "address"
}
],
"name": "collect",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
"inputs": [
{
"internalType": "uint256",
"name": "_tokens",
"type": "uint256"
},
{
"internalType": "address",
"name": "_allocationID",
"type": "address"
}
],
"name": "collect",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"internalType": "address",
"name": "_allocationID",
"type": "address"
}
],
"name": "getAllocation",
"outputs": [
"inputs": [
{
"internalType": "address",
"name": "_allocationID",
"type": "address"
}
],
"name": "getAllocation",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "indexer",
"type": "address"
},
{
"internalType": "bytes32",
"name": "_subgraphDeploymentID",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "_tokens",
"type": "uint256"
},
{
"internalType": "address",
"name": "_allocationID",
"type": "address"
},
{
"internalType": "bytes32",
"name": "_metadata",
"type": "bytes32"
}
],
"internalType": "struct IStaking.Allocation",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"components": [
"inputs": [
{
"internalType": "address",
"name": "indexer",
"name": "_assetHolder",
"type": "address"
},
{
"internalType": "bool",
"name": "_allowed",
"type": "bool"
}
],
"internalType": "struct IStaking.Allocation",
"name": "",
"type": "tuple"
"name": "setAssetHolder",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_tokens",
"type": "uint256"
}
],
"name": "stake",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"stateMutability": "view",
"type": "function"
}
]
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Receiver @entity {

type Transaction @entity{
id: ID!
transactionGroupID: String!
type: String!
sender: Sender!
receiver: Receiver!
Expand Down
11 changes: 7 additions & 4 deletions src/mappings/escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function handleCancelThaw(event: CancelThaw): void {
}

export function handleDeposit(event: Deposit): void {
let transaction = new Transaction(event.transaction.hash.toHexString())
let transaction = new Transaction(event.transaction.hash.toHexString() + '-' + event.logIndex.toString())
aasseman marked this conversation as resolved.
Show resolved Hide resolved
let sender = createOrLoadSender(event.params.sender.toHexString())
let receiver = createOrLoadReceiver(event.params.receiver.toHexString())
let escrow = createOrLoadEscrowAccount(event.params.sender.toHexString(), event.params.receiver.toHexString())
Expand All @@ -44,13 +44,14 @@ export function handleDeposit(event: Deposit): void {
transaction.receiver = receiver.id
transaction.amount = event.params.amount
transaction.escrowAccount = escrow.id
transaction.transactionGroupID = event.transaction.hash.toHexString()

transaction.save()
escrow.save()
}

export function handleWidthrawals(event: Withdraw): void {
let transaction = new Transaction(event.transaction.hash.toHexString())
let transaction = new Transaction(event.transaction.hash.toHexString() + '-' + event.logIndex.toString())
let sender = createOrLoadSender(event.params.sender.toHexString())
let receiver = createOrLoadReceiver(event.params.receiver.toHexString())
let escrow = createOrLoadEscrowAccount(event.params.sender.toHexString(), event.params.receiver.toHexString())
Expand All @@ -64,14 +65,15 @@ export function handleWidthrawals(event: Withdraw): void {
transaction.receiver = receiver.id
transaction.amount = event.params.amount
transaction.escrowAccount = escrow.id
transaction.transactionGroupID = event.transaction.hash.toHexString()

transaction.save()
escrow.save()

}

export function handleRedeems(event: Redeem): void {
let transaction = new Transaction(event.transaction.hash.toHexString())
let transaction = new Transaction(event.transaction.hash.toHexString() + '-' + event.logIndex.toString())
let sender = createOrLoadSender(event.params.sender.toHexString())
let receiver = createOrLoadReceiver(event.params.receiver.toHexString())
let escrow = createOrLoadEscrowAccount(event.params.sender.toHexString(), event.params.receiver.toHexString())
Expand All @@ -84,7 +86,8 @@ export function handleRedeems(event: Redeem): void {
transaction.expectedAmount = event.params.expectedAmount
transaction.allocationID = event.params.allocationID.toHexString()
transaction.escrowAccount = escrow.id

transaction.transactionGroupID = event.transaction.hash.toHexString()

transaction.save()
escrow.save()

Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def check_subgraph_transaction(
):
graphql_query = """
query($id: String!){
transactions(where: {id: $id}) {
transactions(where: {transactionGroupID: $id}) {
amount
}
}
Expand Down
30 changes: 25 additions & 5 deletions tests/local_contract_calls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import json
import sys
import time
import os

from eip712.messages import EIP712Message
from eth_account.messages import encode_defunct
from web3 import Web3
from web3.exceptions import ContractCustomError, ContractLogicError

from helpers import (ALLOCATION_ID, ALLOCATIONID_PK, GATEWAY, RECEIVER, SIGNER,
SIGNER_PK, check_subgraph_escrow_account,
check_subgraph_signer, check_subgraph_transaction,
decode_custom_error, time_remaining)
from helpers import (
ALLOCATION_ID,
ALLOCATIONID_PK,
GATEWAY,
RECEIVER,
SIGNER,
SIGNER_PK,
check_subgraph_escrow_account,
check_subgraph_signer,
check_subgraph_transaction,
decode_custom_error,
time_remaining,
)

# This script will help test that the subgraph is actually catching the required information
ESCROW_ADDRESS = sys.argv[1]
Expand Down Expand Up @@ -95,8 +105,18 @@ class ReceiptAggregateVoucher(EIP712Message):

# MOCK STAKING CONTRACT CALLS
try:
message_hash = Web3.solidity_keccak(
["address", "address"], [GATEWAY, ALLOCATION_ID]
)

# Convert the hash to the Ethereum specific signature format
eth_signed_message = encode_defunct(hexstr=message_hash.hex())

# Sign the message with the private key
signature = w3.eth.account.sign_message(eth_signed_message, private_key=ALLOCATIONID_PK)
arbitraryBytes32 = os.urandom(32)
print("Allocate receiver with allocationid")
mockStaking.functions.allocate(ALLOCATION_ID, RECEIVER).transact({"from": GATEWAY})
mockStaking.functions.allocate(arbitraryBytes32, 1000, ALLOCATION_ID, arbitraryBytes32, RECEIVER).transact({"from": RECEIVER})
aasseman marked this conversation as resolved.
Show resolved Hide resolved
except ContractCustomError as e:
raise ContractCustomError(decode_custom_error(mockStaking_abi_json, str(e), w3))
except ContractLogicError as e:
Expand Down
Loading