Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./program/programs/ExpenseSplitter/Cargo.toml"
]
}
43 changes: 43 additions & 0 deletions examples/solana_anchor/expenses_splitting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Expenses splitting

This program does expenses splitting on Solana. The program manages group accounts.
Anyone can create a group by providing addresses and initial balances. The group account holds balances for each of its members.
The sum of balances of a group always sum zero.
Members can log payments by providing addresses, payments and participation factors.
Group members can add and remove members.

# Program template

Template that includes the CIDL, and the generated code with its business logic.

Creates a user, and tracks the income and outcome amount per user

## Generate code

```shell
codigo solana generate cidl.yaml -a
```

## Build contract

From within the program directory

```shell
anchor build
```

## Install program client dependencies

From within the program_client directory

```shell
npm install
```

## Test contract

From within the program directory

```shell
anchor test
```
112 changes: 112 additions & 0 deletions examples/solana_anchor/expenses_splitting/cidl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
cidl: "0.9"
info:
name: ExpenseSplitter
title: Expense Splitter Contract
version: "1.0.0"
summary: A contract for managing group expenses, allowing members to split costs fairly.
contact:
name: "Developer Name"
web: "https://developerwebsite.com"
email: "contact@developerwebsite.com"
git: "https://github.com/developer/ExpenseSplitter"
license:
name: "MIT License"
identifier: "MIT"
url: "https://opensource.org/licenses/MIT"

solana:
seeds:
groupAccount:
items:
- name: "group_name"
type: "string"

types:
GroupAccount:
summary: Represents a group account with members and their balances.
fields:
- name: "group_name"
type: "string"
description: "The name of the group."
attributes: [cap=100]
- name: "members"
type: "array<sol:pubkey>"
description: "Array of member public keys."
attributes: [cap=100]
- name: "balances"
type: "array<i64>"
description: "Array of member balances in lamports."
attributes: [cap=100]

methods:
- name: "createGroup"
summary: "Creates a new group with initial members and balances."
inputs:
- name: "group_account"
type: sol:account<GroupAccount, seeds.groupAccount(signer=fee_payer)>
attributes: [ sol:init ]
- name: "group_name"
type: "string"
description: "The name of the group."
- name: "members"
type: "array<sol:pubkey>"
description: "Array of member public keys."
attributes: [cap=100]
- name: "initial_balances"
type: "array<i64>"
description: "Array of initial balances for each member."
attributes: [cap=100]
solana:
default-payer: true

- name: "addMember"
summary: "Adds a new member to the group."
inputs:
- name: "group_account"
type: sol:account<GroupAccount, seeds.groupAccount(signer=fee_payer)>
attributes: [sol:writable]
- name: "new_member"
type: "sol:pubkey"
description: "Public key of the new member."

- name: "removeMember"
summary: "Removes a member from the group."
inputs:
- name: "group_account"
type: sol:account<GroupAccount, seeds.groupAccount(signer=fee_payer)>
attributes: [sol:writable]
- name: "member"
type: "sol:pubkey"
description: "Public key of the member to remove."

- name: "logPayment"
summary: "Logs a payment made by or for group members, updating balances accordingly."
inputs:
- name: "group_account"
type: sol:account<GroupAccount, seeds.groupAccount(signer=fee_payer)>
attributes: [sol:writable]
- name: "title"
type: "string"
description: "Title or description of the payment."
- name: "participants"
type: "array<sol:pubkey>"
description: "Array of participating member public keys."
attributes: [cap=100]
- name: "amounts"
type: "array<u64>"
description: "Array of amounts each participant gave to the group."
attributes: [cap=100]
- name: "participation_factors"
type: "array<u64>"
description: "Array of participation factors for each participant."
attributes: [cap=100]

errors:
- id: "GroupBalanceError"
msg: "The sum of balances in the group must always sum to zero."
- id: "InvalidMemberError"
msg: "The specified member does not exist in the group."
- id: "InvalidGroupError"
msg: "The specified group does not exist."
- id: "BalanceMismatchError"
msg: "The sum of initial balances does not sum to zero."
10 changes: 10 additions & 0 deletions examples/solana_anchor/expenses_splitting/program/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is auto-generated from the CIDL source.
# Editing this file directly is not recommended as it may be overwritten.

.anchor
.DS_Store
target
**/*.rs.bk
node_modules
test-ledger
.yarn
10 changes: 10 additions & 0 deletions examples/solana_anchor/expenses_splitting/program/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is auto-generated from the CIDL source.
# Editing this file directly is not recommended as it may be overwritten.

.anchor
.DS_Store
target
node_modules
dist
build
test-ledger
21 changes: 21 additions & 0 deletions examples/solana_anchor/expenses_splitting/program/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is auto-generated from the CIDL source.
# Editing this file directly is not recommended as it may be overwritten.

[toolchain]

[features]
seeds = false
skip-lint = false

[programs.localnet]
workspace = "CBdZHhteKeEySFipeE9w2zRsigs3CsGyFEQ9UKwEpfJ5"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
Loading