Skip to content

Commit

Permalink
Added SDK integration, flexible policy accounts, and general security…
Browse files Browse the repository at this point in the history
… updates (#41) (#42)

* make policy account resizable

* resiable idenitty accounts (#35)

* resiable idenitty accounts

* update tests, init more tests

* remove commented files

* update signer checks + hash policy account (#36)

* update signer checks to use only authority or delegate

* policy hash + patches (#38)

* generic security fixes

* use hash to identify policies (#39)

* use hash to identify policies

* use policy account in hash

* Merged resizable policies and dashboards

* Updated clients rwa-token-sdk for resizable policy

* Added program

* update anchor binary

* update idls

* Rename IDL types in client

* use camel case + fix eslint + fix tests partially + update anchor repo

* fix tests

* Added @bridgesplit/sdk update to example

* Updated to support new PolicyType

* Updated policy enum types

* Updated examples

* fix typedoc issues

* fix typedoc issues

* Update instructions

* Updated instructions

* Convention update

* Updated typedoc json

* Updated testing path

* Removed examples

* fix build yaml

* update package + add lint to actions

* update package naming across file

* rm untracked file

* Added conventions

* Updated client to be coral anchor.

* clear github cache

* Deleted old idls

* update file names

* fix tests

---------

Co-authored-by: Chris Hagedorn <[email protected]>
Co-authored-by: Bhargava Sai Macha <[email protected]>
  • Loading branch information
3 people authored Apr 17, 2024
1 parent 3854d5b commit 9632bac
Show file tree
Hide file tree
Showing 129 changed files with 7,454 additions and 7,416 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: build
env:
cli-id: anchor-v0.29.2-solana-1.17.0
cli-id: anchor-v0.30.0-solana-1.18.8
on:
push:
branches:
- '*'
pull_request:
branches:
- 'main'
- '*'
jobs:
build-cli-deps:
runs-on: ubicloud-standard-8
Expand All @@ -15,17 +18,22 @@ jobs:
key: $${{ env.cli-id }}
path: |
~/.local/share/solana
~/.cargo/bin/anchor
- id: install-os-deps
if: steps.cache-cli-deps.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev

- id: install-solana-tools
if: steps.cache-cli-deps.outputs.cache-hit != 'true'
run: sh -c "$(curl -sSfL https://release.solana.com/v1.17.0/install)"
run: sh -c "$(curl -sSfL https://release.solana.com/v1.18.8/install)"

- run: echo "PATH=$HOME/.local/share/solana/install/active_release/bin:$PATH" >> $GITHUB_ENV

tests:
- id: install-anchor-cli
if: steps.cache-cli-deps.outputs.cache-hit != 'true'
run: cargo install --git https://github.com/bridgesplit/anchor anchor-cli --locked

build:
runs-on: ubicloud-standard-8
needs: [build-cli-deps]
steps:
Expand All @@ -35,20 +43,23 @@ jobs:
key: $${{ env.cli-id }}
path: |
~/.local/share/solana
~/.cargo/bin/anchor
- id: install-os-deps
run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev

- run: echo "PATH=$HOME/.local/share/solana/install/active_release/bin:$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV
- uses: actions/setup-node@v2
with:
node-version: '18'
node-version: '20'

- uses: actions/checkout@v2
with:
fetch-depth: 0

- run: cd clients/rwa-sdk && yarn install
- run: cd clients/rwa-token-sdk && yarn install
- run: cd clients/rwa-token-sdk && yarn lint
- run: solana-keygen new --no-bip39-passphrase
- run: cd programs && cargo fmt -- --check
- run: cd programs && cargo clippy -- -D warnings
- run: cd programs && ./anchor build
- run: cd programs && ./anchor test
- run: cd programs && anchor build
- run: cd programs && anchor test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ node_modules
test-ledger
.yarn
dist
.env
.env
yarn-error.log
docs
27 changes: 27 additions & 0 deletions CONVENTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# RWA Conventions

## Folder and File Naming Conventions

### Folder Naming Convention

- All folders within the clients follow the kebab-case naming convention. This means folder names are lowercase with words separated by hyphens ("-").
- All folders within the programs follow the snake*case naming convention. This means folder names are lowercase with words separated by underscores ("*").

### Component File Naming Convention

- Component files within the project follow the TitleCase naming convention. This means that the first letter of each word in the filename is capitalized, and there are no spaces or special characters. For example: `MyComponent.jsx`

### Helper File Naming Convention

- Helper files within the project follow the lowercase naming convention. This includes files such as index files, types files, and utility files. For example: `index.ts`, `types.ts`, `utils.ts`

## Folder Structure

- **clients/**
- Contains all RWA typescript sdk code.
- **programs/**
- Contains all programs deployed on the solana blockchain.

## Usage

To maintain consistency across the project, please adhere to the following naming conventions when creating new folders and files. This helps keep the project organized and makes it easier for team members to navigate and understand the codebase.
26 changes: 0 additions & 26 deletions README.md

This file was deleted.

1 change: 0 additions & 1 deletion cli/README.md

This file was deleted.

145 changes: 142 additions & 3 deletions clients/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,142 @@
## Client implementations
### TODO: Break out TS functions into Typescript SDK
### TODO: Add Rust SDK
# Medici SDK Quickstart

## Install Package

**Step 1:** Install Medici

```typescript
yarn add @bridgesplit/rwa-token-sdk
```

## Initialize RWA Client

**Step 2:** Begin by importing the RWA client and instantiating it with its respective parameters.

```typescript
const connectionUrl = process.env.RPC_URL ?? "http://localhost:8899";
const connection = new Connection(connectionUrl);

const confirmationOptions: ConfirmOptions = {
skipPreflight: false,
maxRetries: 3,
commitment: "processed",
};

const config: Config = {
connection: connection,
rpcUrl: connectionUrl,
confirmationOptions: confirmationOptions,
};

/* Setup: payerKp, is just the keypair who will pay for the tx. */
const rwaClient = new RwaClient(config, new Wallet(setup.payerKp));
```

## Initialize an Asset Controller

**Step 3:** Initialize an asset controller on chain.

```typescript
const SetupAssetControllerArgs = {
decimals /* Token decimals */,
payer: setup.payer.toString() /* The wallet who will pay */,
authority: setup.authority.toString() /* Token decimals */,
name: "Test Class Asset",
uri: "https://test.com",
symbol: "TFT",
/*
You can always update name, uri, symbol later via
rwaClient.dataRegistry.updateAssetsDataAccountInfoIxns()
*/
};

const setupIx = await rwaClient.assetController.setUpNewRegistry(
SetupAssetControllerArgs
);
const txnId = await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(...setupIx.ixs),
[setup.payerKp, ...setupIx.signers]
);
const mint =
setupIx.signers[0].publicKey.toString(); /* Make sure to record assets mint */
```

## Setup Data Registry

**Step 4:** Create the data registry account.

```typescript
const createDataAccountArgs: CreateDataAccountArgs = {
type: {
legal: {},
} /* This is where your record of legal documentation will go */,
name: "Test Data Account",
uri: "https://test.com",
payer: setup.payer.toString(),
assetMint: mint,
};

/* Note: you can update the data registry later with rwaClient.dataRegistry.updateAssetsDataAccountInfoIxns() */
const createDataAccountIx = await rwaClient.dataRegistry.setupDataAccount(
createDataAccountArgs
);

const txnId = await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(...createDataAccountIx.ixs),
[setup.payerKp, createDataAccountIx.signers[0]]
);
const dataAccount = createDataAccountIx.signers[0].publicKey.toString();
```

## Attach a Policy

**Step 5:** Use the policy engine to attach policies to the asset.

```typescript
const policyArgs: AttachPolicyArgs = {
authority: setup.authority.toString(),
owner: setup.authority.toString(),
assetMint: mint,
payer: setup.payer.toString(),
/* Identity filter is used for group specific policies */
identityFilter: {
identityLevels: [1],
comparisionType: { or: {} },
},
policy: {
identityApproval: {},
/*
The following are example policy's you can pass instead of identity approval:
transactionAmountLimit: {
limit: new BN(100),
}
transactionAmountVelocity: {
limit: new BN(100000)
timeframe: new BN(60)
}
transactionCountVelocity: {
limit: new BN(100),
timeframe: new BN(60),
}
,*/
},
};

const policyIx = await rwaClient.policyEngine.attachPolicy(policyArgs);
const txnId = await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(...policyIx.ixs),
[setup.payerKp, ...policyIx.signers]
);

remainingAccounts.push(policyIx.signers[0].publicKey.toString());
```
37 changes: 0 additions & 37 deletions clients/rwa-sdk/.eslintrc.js

This file was deleted.

24 changes: 0 additions & 24 deletions clients/rwa-sdk/package.json

This file was deleted.

21 changes: 0 additions & 21 deletions clients/rwa-sdk/src/asset_controller/data.ts

This file was deleted.

4 changes: 0 additions & 4 deletions clients/rwa-sdk/src/asset_controller/index.ts

This file was deleted.

Loading

0 comments on commit 9632bac

Please sign in to comment.