# Shakudo PoC
During the Shakudo PoC we will focus on 2 main areas of interest regarding the Kin data in Solana.
## 1: Kin Payments
We are interested in tracking the Kin payments made. One Kin Transaction can contain one ore more 'payments'.
A Kin Transaction might have a `memo` instruction.
If the `memo` instruction is found, we need to parse it and use that data to store with each of the 'payments' found in that transaction.
The data model for the `Payments` table is like this:
- [ ] id
- the `id` of a payment should be composed by the `transactionId` and the `instructionIdx`, separated by a colon `:`
- So if `txId1` has 3 payments, it will create `txId1:1`, `txId1:2`, `txId1:3`
- [ ] block
- the id of the block this payment was found in
- [ ] timestamp
- the Solana Block time
- [ ] date
- the date (without time) - extracted from timestamp - used for querying
- [ ] transactionId
- the id of the transaction
- [ ] instructionIdx
- the index of the instruction inside the transaction
- [ ] fromAccount
- the Kin Token Account that sends the payment
- [ ] fromAccountOwner
- the senders Kin Token Account Owner
- [ ] fromAccountBalance
- the PostBalance of the Kin Token Account
- [ ] toAccount
- the Kin Token Account that receives the payment
- [ ] toAccountOwner
- the recipients Kin Token Account Owner
- [ ] toAccountBalance
- the PostBalance of the recipients Kin Token Account
- [ ] amount
- the amount of Kin that got sent
- [ ] feePayer
- the account that paid the fees
- [ ] memo
- If a memo is found we want to store the raw value here
- [ ] appIndex (parsed from memo)
- If a memo is found and parsed: this field has the appIndex
- [ ] transactionType (parsed from memo)
- If a memo is found and parsed: this field has the transactionType
- [ ] foreignKey (parsed from memo)
- If a memo is found and parsed: this field has the foreighKey
## 2: Kin Account Balance
In order to do GC (Garbage Collection), we need to provide our Garbage Collection API with a list of accounts that it can connect. The GC API will go over each item in the list and try to close the account, and recovering the rent if it succeeds.
We want to be able to run a query along these lines:
- [ ] Give us all the Kin Token Accounts + their Owner
- [ ] Where the last known Kin Token Account Balance = 0
- [ ] And did not change for 1 Month
One thing to note here, is that this 1 Month is an example value.
We would like this to be a parameter we can set, because sometimes we want to be more agressive in our GC.
For instance, if we had an influx of empty accounts being created, we want to run this data for the period as short as 1 Day in order to recover the rent ASAP.
## Shakudo -> Kin Sync
### Postgres URL
We created a Postgres database with the following credentials:
```
postgres://ucnsvvc8esr1j6:pb9c1b0c89f8048a6086e8f43c295a5d159d44a552b875cdc7053d5c9d92a9bb5@ec2-44-205-47-199.compute-1.amazonaws.com:5432/d4bsq1nghq1np7
```
```
postgres://ucnsvvc8esr1j6:pb9c1b0c89f8048a6086e8f43c295a5d159d44a552b875cdc7053d5c9d92a9bb5@ec2-44-205-47-199.compute-1.amazonaws.com:5432/d4bsq1nghq1np7
```
### Postgres Table
There is one table called `KinTransaction`:
```
kin-data::DATABASE=> \dt
List of relations
Schema | Name | Type | Owner
--------+----------------+-------+----------------
public | KinTransaction | table | ucnsvvc8esr1j6
(1 row)
```
### Postgres Table Structure
The table `KinTransaction` has the following structure:
```
kin-data::DATABASE=> SELECT
table_name,
column_name,
data_type
FROM
information_schema.columns
WHERE
table_name = 'KinTransaction';
table_name | column_name | data_type
----------------+--------------------+-----------------------------
KinTransaction | id | text
KinTransaction | createdAt | timestamp without time zone
KinTransaction | updatedAt | timestamp without time zone
KinTransaction | amount | bigint
KinTransaction | appIndex | integer
KinTransaction | block | integer
KinTransaction | date | timestamp without time zone
KinTransaction | feePayer | text
KinTransaction | foreignKey | bytea
KinTransaction | fromAccount | text
KinTransaction | fromAccountBalance | text
KinTransaction | fromAccountOwner | text
KinTransaction | instructionIdx | integer
KinTransaction | memo | text
KinTransaction | mint | text
KinTransaction | timestamp | integer
KinTransaction | toAccount | text
KinTransaction | toAccountBalance | text
KinTransaction | toAccountOwner | text
KinTransaction | transactionId | text
KinTransaction | transactionType | text
(20 rows)
```
### Prisma Schema
The structure is created by this [Prisma](https://prisma.io) schema:
```prisma
model KinTransaction {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
amount BigInt
appIndex Int?
block Int
date DateTime
feePayer String
foreignKey Bytes?
fromAccount String
fromAccountBalance String
fromAccountOwner String
instructionIdx Int
memo String?
mint String
timestamp Int
toAccount String
toAccountBalance String
toAccountOwner String
transactionId String
transactionType String?
}
```
## Notes
- [x] Convert amount to BigInt?
- [ ] Fee payer should be mostly Agora (ags...)
- https://explorer.solana.com/tx/3EHRd7yWtXEwKwoxXSweSzuXMmXh6Zm4JZTymVFuKVsarcjdubX4Pfkyi2sAbw6DXmMSj2pB514KYeaeijHUsbWs
- https://explorer.solana.com/tx/5HUQwhPexGWLUrapj62oshT5mApzdzcuq82oUq1jx8ZKgSSyQJuDRfDDmqgpiu2ZRBv1VmxWP3WecKoKRTprEEQ7
- [ ] This txn is indexed and attributed to App 40
- there is no memo instruction - so it should be indexed, but not attributed!
- https://explorer.solana.com/tx/dRdojym3hvxg2x6t9ZeP4qZisw2XyGvi9pezdDaCAEMFEHmSucADjKaGqRYgxo4v6qqT194sYk5vWkoNQVn5pw7
- Similar: https://explorer.solana.com/tx/2GMRRTVmUvuNJV5APAuWWF6FtdRiDzQjHH8sknhDY6wATvWwDfS2eVvdZhz1FWPTxQrCpvsHCr2nHc3JhJmwsAuL
- Similar: https://explorer.solana.com/tx/3sVL6u6o6wrvHriTdxxWag2jg4rX8CTyRAMUsC3JC6mb8tDrwaRVvHd7wK9gcgkYZsLuwoDvSMAxGCbt3AhDNKdC
- [ ] This txn is also indexed and attributed to App 40
- there is no *memo* instruction, but another one (4MNPdKu9wFMvEeZBMt3Eipfs5ovVWTJb31pEXDJAAxX5). It should be indexed but **not** attributed!
- https://explorer.solana.com/tx/5W4dTcdYiLg1tgpTkVKFkwQHoN36gjBGkJKgECWHc2ysTvpKSLJ3BRvSYKtaT38eXUiFj2n1yPSVqgMep4f4onrz
- [ ] This txn has *no* appIndex, but should.
- there **is** a memo instruction, but it did **not** get attributed!
- https://explorer.solana.com/tx/zZZMd6F81U32QSbN6W7XQRUSs3DyNY6MASNbu7qgythmHwrHPqVGZBJVBn5JcCUzGeFaMdYBhCT6PfZrqmxxcmb
## Kin Metabase
https://kin-metabase.herokuapp.com/
- username: `info@shakudo.io`
- password: `DsBmzqV9BsHWHp`
##