Solana-Workshops / .contributing

Details about contributing to new or existing workshops
1 stars 0 forks source link

Bank Simulator With Interest Returns #3

Closed GitBolt closed 1 year ago

GitBolt commented 1 year ago

Link: https://github.com/GitBolt/solana-bank-workshop

I'm adding it to SolPg right now. In the meantime, you can review this one as well!

This is a simple bank simulator workshop, which uses Clockwork to automate interest returns and update user's balance every 10 seconds at the rate of 5% return every minute.

Users can:

Since this is a simulation. The interest returns are lot, because we obviously wouldn't want someone to wait for a year to see 5% increment in their initial amount like real world haha

GitBolt commented 1 year ago

@buffalojoec you can review this one as well! also close the previous expense tracker one. i've been waiting for acheron to review the tutorial, but seems like he is too busy, its been 3 weeks now

buffalojoec commented 1 year ago

Hey there, finally got around to reviewing this. Here's my feedback:

// Clockwork Target Instruction
let target_ix = Instruction {
     program_id: ID,
     accounts: crate::accounts::AddInterest {
          bank_account: bank_account.key(),
          thread: thread.key(),
           thread_authority: thread_authority.key(),
     }.to_account_metas(Some(true)),
     data: crate::instruction::AddInterest {
           _thread_id: thread_id.clone(),
     }.data(),
 };
anchor.setProvider(anchor.AnchorProvider.env());
const provider = anchor.AnchorProvider.local();

const program = anchor.workspace.Etracker as Program<Bank>;
const wallet = provider.wallet as anchor.Wallet;

const clockworkProvider = ClockworkProvider.fromAnchorProvider(
  program.provider as AnchorProvider
);
"dependencies": {
    "@clockwork-xyz/sdk": "^0.3.3",
    "@coral-xyz/anchor": "^0.27.0",
    "@project-serum/anchor": "^0.26.0"
},
import { ClockworkProvider } from "@clockwork-xyz/sdk";
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { Bank } from "../target/types/bank";
import { AnchorProvider } from "@coral-xyz/anchor";
[test.validator]
url = "https://api.mainnet-beta.solana.com"

[[test.validator.clone]]
address = "CLoCKyJ6DXBJqqu2VWx9RLbgnwwR6BMHHuyasVmfMzBh"

Please address all above feedback, upgrade to Anchor v0.28, and fix the tests so they run for anyone who clones the repo.

Here's what I see when I run the tests:

Screenshot 2023-06-12 at 2 57 02 PM
GitBolt commented 1 year ago

hey, appreciate it! yeah clearly i missed certain stuff. i used solpg to code it, so the proper local setup was missed as well. fixing them right now.

about versions. right now clockwork does not support solana v1.16.0 (https://github.com/clockwork-xyz/clockwork/releases) so we can't use it right now, and hence, anchor v0.28 won't be required either. I'll fix dependency versions so that it works out of the box for Solana v1.14.16 or v1.14.17

GitBolt commented 1 year ago

Hey @buffalojoec. Can you check now? I've added detailed instruction of running it locally at the end of the Readme. Also, we don't need to clone the clockwork test validator right? The CLI tool has everything for us and works out of the box

buffalojoec commented 1 year ago

Thanks for addressing my feedback!

Couple more requests, then we should be good to go:

GitBolt commented 1 year ago

Fixed! Here is the SolPg tutorial PR - https://github.com/solana-playground/solana-playground/pull/137

buffalojoec commented 1 year ago

Here's the new repo for ya https://github.com/Solana-Workshops/Bank-Simulator

buffalojoec commented 1 year ago

Thank you!