Skip to content

Commit 602cc4b

Browse files
committed
V2
1 parent 6b9d1a6 commit 602cc4b

28 files changed

+450
-557
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
- tests/voter-stake-registry.ts
150150
- tests/fanout.ts
151151
- tests/sus.ts
152-
- tests/dc-conversion-escrow.ts
152+
- tests/conversion-escrow.ts
153153
steps:
154154
- uses: actions/checkout@v3
155155
- uses: ./.github/actions/build-anchor/

Anchor.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fanout = "fanqeMu3fw8R4LwKNbahPtYXJsyLL6NXyfe2BqzhfB6"
1717
mobile_entity_manager = "memMa1HG4odAFmUbGWfPwS1WWfK95k99F2YTkGvyxZr"
1818
hexboosting = "hexbnKYoA2GercNNhHUCCfrTRWrHjT6ujKPXTa5NPqJ"
1919
no_emit = "noEmmgLmQdk6DLiPV8CSwQv3qQDyGEhz9m5A4zhtByv"
20-
dc_conversion_escrow = "dce4jeLBpfaFsNAKMAmVt5Py4E1R4mZcrVvMB5ejvGu"
20+
conversion_escrow = "dce4jeLBpfaFsNAKMAmVt5Py4E1R4mZcrVvMB5ejvGu"
2121

2222
[workspace]
2323
members = [
@@ -35,7 +35,7 @@ members = [
3535
"programs/mobile-entity-manager",
3636
"programs/hexboosting",
3737
"programs/no-emit",
38-
"programs/dc-conversion-escrow",
38+
"programs/conversion-escrow",
3939
]
4040

4141
[registry]

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dc-conversion-escrow-sdk/package.json renamed to packages/conversion-escrow-sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "@helium/dc-conversion-escrow-sdk",
2+
"name": "@helium/conversion-escrow-sdk",
33
"publishConfig": {
44
"access": "public",
55
"registry": "https://registry.npmjs.org/"
66
},
77
"license": "Apache-2.0",
88
"version": "0.6.41",
9-
"description": "Interface to the dc-conversion-escrow smart contract",
9+
"description": "Interface to the conversion-escrow smart contract",
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/helium/helium-program-libary"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { DcConversionEscrow } from "@helium/idls/lib/types/dc_conversion_escrow";
1+
import { ConversionEscrow } from "@helium/idls/lib/types/conversion_escrow";
22
import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
33
import { PublicKey } from "@solana/web3.js";
44
import { PROGRAM_ID } from "./constants";
5-
import { dcConversionEscrowResolvers } from "./resolvers";
5+
import { conversionEscrowResolvers } from "./resolvers";
66

77

88
export * from "./constants";
@@ -12,18 +12,18 @@ export async function init(
1212
provider: AnchorProvider,
1313
programId: PublicKey = PROGRAM_ID,
1414
idl?: Idl | null
15-
): Promise<Program<DcConversionEscrow>> {
15+
): Promise<Program<ConversionEscrow>> {
1616
if (!idl) {
1717
idl = await Program.fetchIdl(programId, provider);
1818
}
1919

20-
const dcConversionEscrow = new Program<DcConversionEscrow>(
21-
idl as DcConversionEscrow,
20+
const conversionEscrow = new Program<ConversionEscrow>(
21+
idl as ConversionEscrow,
2222
programId,
2323
provider,
2424
undefined,
25-
() => dcConversionEscrowResolvers
26-
) as Program<DcConversionEscrow>;
25+
() => conversionEscrowResolvers
26+
) as Program<ConversionEscrow>;
2727

28-
return dcConversionEscrow;
28+
return conversionEscrow;
2929
}

packages/dc-conversion-escrow-sdk/src/resolvers.ts renamed to packages/conversion-escrow-sdk/src/resolvers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
heliumCommonResolver
55
} from "@helium/anchor-resolvers";
66

7-
export const dcConversionEscrowResolvers = combineResolvers(
7+
export const conversionEscrowResolvers = combineResolvers(
88
heliumCommonResolver,
99
ataResolver({
1010
instruction: "initializeEscrowV0",

packages/dc-conversion-escrow-sdk/yarn.deploy.lock renamed to packages/conversion-escrow-sdk/yarn.deploy.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ __metadata:
7272
languageName: unknown
7373
linkType: soft
7474

75-
"@helium/dc-conversion-escrow-sdk@workspace:.":
75+
"@helium/conversion-escrow-sdk@workspace:.":
7676
version: 0.0.0-use.local
77-
resolution: "@helium/dc-conversion-escrow-sdk@workspace:."
77+
resolution: "@helium/conversion-escrow-sdk@workspace:."
7878
dependencies:
7979
"@coral-xyz/anchor": ^0.28.0
8080
"@helium/anchor-resolvers": ^0.6.41

programs/dc-conversion-escrow/Cargo.toml renamed to programs/conversion-escrow/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
2-
name = "dc-conversion-escrow"
2+
name = "conversion-escrow"
33
version = "0.0.1"
44
description = "Created with Anchor"
55
edition = "2021"
66

77
[lib]
88
crate-type = ["cdylib", "lib"]
9-
name = "dc_conversion_escrow"
9+
name = "conversion_escrow"
1010

1111
[features]
1212
devnet = []
@@ -23,8 +23,8 @@ overflow-checks = true
2323
[dependencies]
2424
anchor-lang = { workspace = true }
2525
anchor-spl = { workspace = true }
26+
spl-token = "3.5.0"
2627
shared-utils = { workspace = true }
2728
solana-security-txt = { workspace = true }
28-
data-credits = { path = "../data-credits", features = ["cpi"] }
2929
default-env = { workspace = true }
3030
pyth-sdk-solana = { version = "0.8.0" }

programs/dc-conversion-escrow/src/instructions/initialize_escrow_v0.rs renamed to programs/conversion-escrow/src/instructions/initialize_escrow_v0.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
use crate::errors::ErrorCode;
1+
use crate::ConversionTargetV0;
22
use anchor_lang::prelude::*;
33
use anchor_spl::{
44
associated_token::AssociatedToken,
55
token::{Mint, Token, TokenAccount},
66
};
7-
use data_credits::DataCreditsV0;
8-
use pyth_sdk_solana::load_price_feed_from_account_info;
97

108
use crate::ConversionEscrowV0;
119

1210
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
1311
pub struct InitializeEscrowArgsV0 {
12+
pub oracle: Pubkey,
13+
pub targets: Vec<ConversionTargetArgV0>,
14+
}
15+
16+
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
17+
pub struct ConversionTargetArgV0 {
18+
pub mint: Pubkey,
19+
pub oracle: Pubkey,
20+
/// How much slippage to allow from the oracle price
1421
pub slippage_bps: u16,
1522
}
1623

1724
#[derive(Accounts)]
25+
#[instruction(args: InitializeEscrowArgsV0)]
1826
pub struct InitializeEscrowV0<'info> {
19-
pub data_credits: Box<Account<'info, DataCreditsV0>>,
2027
#[account(mut)]
2128
pub payer: Signer<'info>,
2229
/// CHECK: The owner of this account. Can fully withdraw
2330
pub owner: Signer<'info>,
2431
#[account(
2532
init,
2633
payer = payer,
27-
seeds = [b"conversion_escrow", data_credits.key().as_ref(), mint.key().as_ref(), owner.key().as_ref()],
34+
seeds = [b"conversion_escrow", mint.key().as_ref(), owner.key().as_ref()],
2835
bump,
29-
space = ConversionEscrowV0::INIT_SPACE + 60,
36+
space = std::mem::size_of::<ConversionEscrowV0>() + 60 + std::mem::size_of::<ConversionTargetV0>() * args.targets.len(),
3037
)]
3138
pub conversion_escrow: Box<Account<'info, ConversionEscrowV0>>,
3239
pub mint: Box<Account<'info, Mint>>,
@@ -39,27 +46,28 @@ pub struct InitializeEscrowV0<'info> {
3946
pub escrow: Box<Account<'info, TokenAccount>>,
4047
pub system_program: Program<'info, System>,
4148
pub associated_token_program: Program<'info, AssociatedToken>,
42-
/// CHECK: Checked with load_price_feed_from_account_info
43-
pub oracle: AccountInfo<'info>,
4449
pub token_program: Program<'info, Token>,
4550
}
4651

4752
pub fn handler(ctx: Context<InitializeEscrowV0>, args: InitializeEscrowArgsV0) -> Result<()> {
48-
load_price_feed_from_account_info(&ctx.accounts.oracle).map_err(|e| {
49-
msg!("Pyth error {}", e);
50-
error!(ErrorCode::PythError)
51-
})?;
52-
5353
ctx
5454
.accounts
5555
.conversion_escrow
5656
.set_inner(ConversionEscrowV0 {
57-
oracle: ctx.accounts.oracle.key(),
57+
oracle: args.oracle,
5858
escrow: ctx.accounts.escrow.key(),
5959
mint: ctx.accounts.mint.key(),
60-
slipage_bps: args.slippage_bps,
60+
targets: args
61+
.targets
62+
.iter()
63+
.map(|t| ConversionTargetV0 {
64+
reserverd: [0; 8],
65+
mint: t.mint,
66+
oracle: t.oracle,
67+
slipage_bps: t.slippage_bps,
68+
})
69+
.collect(),
6170
owner: ctx.accounts.owner.key(),
62-
data_credits: ctx.accounts.data_credits.key(),
6371
bump_seed: ctx.bumps["conversion_escrow"],
6472
});
6573

0 commit comments

Comments
 (0)