Skip to content

Commit

Permalink
V2
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Mar 20, 2024
1 parent 6b9d1a6 commit 602cc4b
Show file tree
Hide file tree
Showing 28 changed files with 450 additions and 557 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:
- tests/voter-stake-registry.ts
- tests/fanout.ts
- tests/sus.ts
- tests/dc-conversion-escrow.ts
- tests/conversion-escrow.ts
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/build-anchor/
Expand Down
4 changes: 2 additions & 2 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fanout = "fanqeMu3fw8R4LwKNbahPtYXJsyLL6NXyfe2BqzhfB6"
mobile_entity_manager = "memMa1HG4odAFmUbGWfPwS1WWfK95k99F2YTkGvyxZr"
hexboosting = "hexbnKYoA2GercNNhHUCCfrTRWrHjT6ujKPXTa5NPqJ"
no_emit = "noEmmgLmQdk6DLiPV8CSwQv3qQDyGEhz9m5A4zhtByv"
dc_conversion_escrow = "dce4jeLBpfaFsNAKMAmVt5Py4E1R4mZcrVvMB5ejvGu"
conversion_escrow = "dce4jeLBpfaFsNAKMAmVt5Py4E1R4mZcrVvMB5ejvGu"

[workspace]
members = [
Expand All @@ -35,7 +35,7 @@ members = [
"programs/mobile-entity-manager",
"programs/hexboosting",
"programs/no-emit",
"programs/dc-conversion-escrow",
"programs/conversion-escrow",
]

[registry]
Expand Down
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@helium/dc-conversion-escrow-sdk",
"name": "@helium/conversion-escrow-sdk",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"license": "Apache-2.0",
"version": "0.6.41",
"description": "Interface to the dc-conversion-escrow smart contract",
"description": "Interface to the conversion-escrow smart contract",
"repository": {
"type": "git",
"url": "https://github.com/helium/helium-program-libary"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DcConversionEscrow } from "@helium/idls/lib/types/dc_conversion_escrow";
import { ConversionEscrow } from "@helium/idls/lib/types/conversion_escrow";
import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import { PROGRAM_ID } from "./constants";
import { dcConversionEscrowResolvers } from "./resolvers";
import { conversionEscrowResolvers } from "./resolvers";


export * from "./constants";
Expand All @@ -12,18 +12,18 @@ export async function init(
provider: AnchorProvider,
programId: PublicKey = PROGRAM_ID,
idl?: Idl | null
): Promise<Program<DcConversionEscrow>> {
): Promise<Program<ConversionEscrow>> {
if (!idl) {
idl = await Program.fetchIdl(programId, provider);
}

const dcConversionEscrow = new Program<DcConversionEscrow>(
idl as DcConversionEscrow,
const conversionEscrow = new Program<ConversionEscrow>(
idl as ConversionEscrow,
programId,
provider,
undefined,
() => dcConversionEscrowResolvers
) as Program<DcConversionEscrow>;
() => conversionEscrowResolvers
) as Program<ConversionEscrow>;

return dcConversionEscrow;
return conversionEscrow;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
heliumCommonResolver
} from "@helium/anchor-resolvers";

export const dcConversionEscrowResolvers = combineResolvers(
export const conversionEscrowResolvers = combineResolvers(
heliumCommonResolver,
ataResolver({
instruction: "initializeEscrowV0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ __metadata:
languageName: unknown
linkType: soft

"@helium/dc-conversion-escrow-sdk@workspace:.":
"@helium/conversion-escrow-sdk@workspace:.":
version: 0.0.0-use.local
resolution: "@helium/dc-conversion-escrow-sdk@workspace:."
resolution: "@helium/conversion-escrow-sdk@workspace:."
dependencies:
"@coral-xyz/anchor": ^0.28.0
"@helium/anchor-resolvers": ^0.6.41
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "dc-conversion-escrow"
name = "conversion-escrow"
version = "0.0.1"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "dc_conversion_escrow"
name = "conversion_escrow"

[features]
devnet = []
Expand All @@ -23,8 +23,8 @@ overflow-checks = true
[dependencies]
anchor-lang = { workspace = true }
anchor-spl = { workspace = true }
spl-token = "3.5.0"
shared-utils = { workspace = true }
solana-security-txt = { workspace = true }
data-credits = { path = "../data-credits", features = ["cpi"] }
default-env = { workspace = true }
pyth-sdk-solana = { version = "0.8.0" }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
use crate::errors::ErrorCode;
use crate::ConversionTargetV0;
use anchor_lang::prelude::*;
use anchor_spl::{
associated_token::AssociatedToken,
token::{Mint, Token, TokenAccount},
};
use data_credits::DataCreditsV0;
use pyth_sdk_solana::load_price_feed_from_account_info;

use crate::ConversionEscrowV0;

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct InitializeEscrowArgsV0 {
pub oracle: Pubkey,
pub targets: Vec<ConversionTargetArgV0>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct ConversionTargetArgV0 {
pub mint: Pubkey,
pub oracle: Pubkey,
/// How much slippage to allow from the oracle price
pub slippage_bps: u16,
}

#[derive(Accounts)]
#[instruction(args: InitializeEscrowArgsV0)]
pub struct InitializeEscrowV0<'info> {
pub data_credits: Box<Account<'info, DataCreditsV0>>,
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: The owner of this account. Can fully withdraw
pub owner: Signer<'info>,
#[account(
init,
payer = payer,
seeds = [b"conversion_escrow", data_credits.key().as_ref(), mint.key().as_ref(), owner.key().as_ref()],
seeds = [b"conversion_escrow", mint.key().as_ref(), owner.key().as_ref()],
bump,
space = ConversionEscrowV0::INIT_SPACE + 60,
space = std::mem::size_of::<ConversionEscrowV0>() + 60 + std::mem::size_of::<ConversionTargetV0>() * args.targets.len(),
)]
pub conversion_escrow: Box<Account<'info, ConversionEscrowV0>>,
pub mint: Box<Account<'info, Mint>>,
Expand All @@ -39,27 +46,28 @@ pub struct InitializeEscrowV0<'info> {
pub escrow: Box<Account<'info, TokenAccount>>,
pub system_program: Program<'info, System>,
pub associated_token_program: Program<'info, AssociatedToken>,
/// CHECK: Checked with load_price_feed_from_account_info
pub oracle: AccountInfo<'info>,
pub token_program: Program<'info, Token>,
}

pub fn handler(ctx: Context<InitializeEscrowV0>, args: InitializeEscrowArgsV0) -> Result<()> {
load_price_feed_from_account_info(&ctx.accounts.oracle).map_err(|e| {
msg!("Pyth error {}", e);
error!(ErrorCode::PythError)
})?;

ctx
.accounts
.conversion_escrow
.set_inner(ConversionEscrowV0 {
oracle: ctx.accounts.oracle.key(),
oracle: args.oracle,
escrow: ctx.accounts.escrow.key(),
mint: ctx.accounts.mint.key(),
slipage_bps: args.slippage_bps,
targets: args
.targets
.iter()
.map(|t| ConversionTargetV0 {
reserverd: [0; 8],
mint: t.mint,
oracle: t.oracle,
slipage_bps: t.slippage_bps,
})
.collect(),
owner: ctx.accounts.owner.key(),
data_credits: ctx.accounts.data_credits.key(),
bump_seed: ctx.bumps["conversion_escrow"],
});

Expand Down
Loading

0 comments on commit 602cc4b

Please sign in to comment.