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

Add unassigned deposits #13

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
181 changes: 181 additions & 0 deletions abis/Escrow.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"name": "EscrowStillThawing",
"type": "error"
},
{
"inputs": [],
"name": "InputsLengthMismatch",
"type": "error"
},
{
"inputs": [
{
Expand All @@ -77,6 +82,22 @@
"name": "InsufficientThawAmount",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "available",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "required",
"type": "uint256"
}
],
"name": "InsufficientUnassignedEscrow",
"type": "error"
},
{
"inputs": [],
"name": "InvalidRAVSigner",
Expand Down Expand Up @@ -233,6 +254,31 @@
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "DepositAssigned",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -351,6 +397,31 @@
"name": "ThawSigner",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "depositor",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "UnassignedDeposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -396,6 +467,42 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "assignDeposit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "receivers",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "amounts",
"type": "uint256[]"
}
],
"name": "assignDepositMany",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -474,6 +581,42 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "receivers",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "amounts",
"type": "uint256[]"
}
],
"name": "depositMany",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "depositUnassigned",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -586,6 +729,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
}
],
"name": "getUnassignedEscrowAmount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -716,6 +878,25 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
}
],
"name": "unassignedAccounts",
"outputs": [
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
7 changes: 7 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ type Transaction @entity{
escrowAccount: EscrowAccount!
}

type UnnasignedTransaction @entity{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than creating this new entity, would it be simpler if you just add an unassignedBalance field in the Sender entity? Or is there a reason why you'd prefer this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that does make sense, didnt thought of that thanks!

id: ID!
transactionGroupID: String!
type: String!
balance: BigInt!
}

type AuthorizedSigner @entity{
id: ID!
isAuthorized: Boolean!
Expand Down
43 changes: 41 additions & 2 deletions src/mappings/escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
Sender,
Receiver,
EscrowAccount,
AuthorizedSigner
AuthorizedSigner,
UnnasignedTransaction
} from '../types/schema'
import { Deposit, Withdraw, Redeem, Thaw, AuthorizeSigner, RevokeAuthorizedSigner, CancelThaw, CancelThawSigner} from '../types/Escrow/Escrow'
import { Deposit, Withdraw, Redeem, Thaw, AuthorizeSigner, RevokeAuthorizedSigner, CancelThaw, CancelThawSigner, UnassignedDeposit, DepositAssigned} from '../types/Escrow/Escrow'
let ZERO_BI = BigInt.fromI32(0)
let ZERO_AD = '0x0000000000000000000000000000000000000000'

Expand All @@ -31,6 +32,33 @@ export function handleCancelThaw(event: CancelThaw): void {
escrow.save()
}

export function handleUnassignedDeposit(event: UnassignedDeposit): void{
let unnasignedTransaction = createOrLoadUnassignedTransaction(event.params.sender.toHexString())
unnasignedTransaction.type = 'deposit'
unnasignedTransaction.balance.plus(event.params.amount)
unnasignedTransaction.save()
}

export function handleDepositAssigned(event: DepositAssigned): void{
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())
let unnasignedTransaction = createOrLoadUnassignedTransaction(event.params.sender.toHexString())

transaction.type = "deposit"
transaction.sender = sender.id
transaction.receiver = receiver.id
transaction.amount = event.params.amount
transaction.escrowAccount = escrow.id
transaction.transactionGroupID = event.transaction.hash.toHexString()

unnasignedTransaction.balance.minus(event.params.amount)

transaction.save()
escrow.save()
}

export function handleDeposit(event: Deposit): void {
let transaction = new Transaction(event.transaction.hash.toHexString() + '-' + event.logIndex.toString())
let sender = createOrLoadSender(event.params.sender.toHexString())
Expand Down Expand Up @@ -168,4 +196,15 @@ export function createOrLoadEscrowAccount(sender: string, receiver: string): Esc
escrowAccount.save()
}
return escrowAccount as EscrowAccount
}
// ID: would be the depositer
export function createOrLoadUnassignedTransaction(id: string): UnnasignedTransaction{
let unassignedTransaction = UnnasignedTransaction.load(id)
if(unassignedTransaction == null){
unassignedTransaction = new UnnasignedTransaction(id)
unassignedTransaction.balance = ZERO_BI
unassignedTransaction.type = ''
unassignedTransaction.save()
}
return unassignedTransaction as UnnasignedTransaction
}
10 changes: 7 additions & 3 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ schema:
dataSources:
- kind: ethereum
name: Escrow
network: mainnet
network: goerli
source:
address: '0xe2e5421247C9aac3eee8417900138aB741b9f990'
address: '0xD46c60558F7960407F4D00098145D77Fd061aD90'
abi: Escrow
startBlock: 0
startBlock: 9765074
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand Down Expand Up @@ -40,3 +40,7 @@ dataSources:
handler: handleThawSigner
- event: CancelThawSigner(indexed address,indexed address,uint256)
handler: handleCancelThawSigner
- event: UnassignedDeposit(indexed address,indexed address,uint256)
handler: handleUnassignedDeposit
- event: DepositAssigned(indexed address,indexed address,uint256)
handler: handleDepositAssigned
Loading