Loanyee / app

Interface for Loanyee
https://app.loanyee.xyz
0 stars 0 forks source link

Get Salary History #15

Closed yukiwaki closed 1 year ago

yukiwaki commented 1 year ago

[Overview] When they borrow money, we should check their salary history based on the employer address and employee address (connected address).

We should get ・how long the stream runs ・Current monthly amount ・Total amount received

Use the FlowUpdated events and StreamPeriods

how long the stream runs Please use "streams" to get the active stream and check the timestamp. (original implementation with Flowupdatedevent cannot work since we don't know which one is closed) https://thegraph.com/hosted-service/subgraph/superfluid-finance/protocol-v1-goerli

{
  streams(where:{
          sender: "0x02b5525fd3bd29dbfae8f8e453fe3b7e85d7d470"
          receiver: "0x84a432a45b54725e0f8fd2015a074ca507bdd7dc"
        }
       ) {
    id
    currentFlowRate
    createdAtTimestamp
    updatedAtTimestamp
    streamPeriods {
      id
    }
  }
}

Current monthly amount =Current flow rate/(10^18)60602430

Total amount received This page in our docs has a formula + query you can use to get the total amount streamed from one account to another: https://docs.superfluid.finance/superfluid/developers/subgraph#getting-stream-data-between-2-parties

*we need to make the wallet address lowercased with The Graph limitation

Note: to get the current (dynamic) total amount streamed, you can use the following formula: streamedUntilUpdatedAt + ((current time in seconds) - updatedAtTimestamp) * currentFlowRate


{
    streams(where:{
          sender: "0xdcb45e4f6762c3d7c61a00e96fb94adb7cf27721"
          receiver: "0x568b9bfff4a3a7c7351db84ec2f4ad4ca147a1d0"
        }
       ) {
        token {
        id
        symbol
      }
        createdAtTimestamp
        updatedAtTimestamp
        currentFlowRate
        streamedUntilUpdatedAt
        }
}
yukiwaki commented 1 year ago

Duration if there is only type 0, check how long from the timestamp to current time if there is both type 0 and 2, we should show the duration by deducting from 2-0. (but we should say (terminated))

yukiwaki commented 1 year ago

Type 0 Sender 0x54DC214722bB592e0f46a9a4a724Eb464AeA6b62 Receiver 0x6f40B3E8000693929464D14AB05f38037F8EDff2

Type 0 and 2 sender 0x02b5525Fd3bd29dBFaE8f8e453FE3B7e85D7D470 Receiver 0x237CE8AbaED724970C17Afd1ff82B191CC3759Bc

yukiwaki commented 1 year ago

this is the old implementation

And for stream duration, you can get when the stream starts by filtering flowUpdated events for type of 0 (which represents a creation event), and 2 (which represents a deletion event)

{
  flowUpdatedEvents(where:{
          sender: "0x02b5525fd3bd29dbfae8f8e453fe3b7e85d7d470"
          receiver: "0x84a432a45b54725e0f8fd2015a074ca507bdd7dc"
        }
       ) {
    id
    transactionHash
    gasPrice
    timestamp
    type
  }
}
yukiwaki commented 1 year ago

2 active streams

Sender 0x54DC214722bB592e0f46a9a4a724Eb464AeA6b62

Receiver 0xaD26A4E7ef85EDccD48451B64029B8082ffDeF18

yukiwaki commented 1 year ago

Comment : We just need to save their salary history as loan detail on chain