Skip to content

Commit

Permalink
use IdlAccounts type to correctly infer accounts (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolley authored Jan 31, 2025
1 parent 881c66c commit e22bbb3
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"packages": [
"packages/*"
],
"version": "7.4.2",
"version": "7.4.3",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/common",
"version": "7.4.2",
"version": "7.4.3",
"description": "Common utilities and types used by streamflow packages.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "./dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/distributor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/distributor",
"version": "7.4.2",
"version": "7.4.3",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/eslint-config",
"version": "7.4.2",
"version": "7.4.3",
"license": "ISC",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/launchpad/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/launchpad",
"version": "7.4.2",
"version": "7.4.3",
"description": "JavaScript SDK to interact with Streamflow Launchpad protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/esm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/launchpad/solana/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, type IdlTypes } from "@coral-xyz/anchor";
import { Address, type IdlAccounts } from "@coral-xyz/anchor";
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
import { Keypair } from "@solana/web3.js";
import { ITransactionSolanaExt } from "@streamflow/common/solana";
Expand All @@ -7,8 +7,8 @@ import BN from "bn.js";

import { StreamflowLaunchpad } from "./descriptor/streamflow_launchpad.js";

export type Launchpad = IdlTypes<StreamflowLaunchpad>["launchpad"];
export type DepositAccount = IdlTypes<StreamflowLaunchpad>["depositAccount"];
export type Launchpad = IdlAccounts<StreamflowLaunchpad>["launchpad"];
export type DepositAccount = IdlAccounts<StreamflowLaunchpad>["depositAccount"];

export interface IInteractSolanaExt extends ITransactionSolanaExt {
invoker: SignerWalletAdapter | Keypair;
Expand Down
2 changes: 1 addition & 1 deletion packages/staking/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/staking",
"version": "7.4.2",
"version": "7.4.3",
"description": "JavaScript SDK to interact with Streamflow Staking protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/esm/index.js",
Expand Down
8 changes: 4 additions & 4 deletions packages/staking/solana/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AccountsCoder,
AnchorError,
Idl,
IdlTypes,
IdlAccounts,
Program,
ProgramAccount,
ProgramError,
Expand Down Expand Up @@ -496,8 +496,8 @@ export class SolanaStakingClient {
ProgramName extends keyof Programs = keyof Programs,
DecodingProgram = Programs[ProgramName],
DerivedIdl extends Idl = DecodingProgram extends Program<infer IDLType> ? IDLType : never,
AccountName extends keyof IdlTypes<DerivedIdl> = keyof IdlTypes<DerivedIdl>,
DecodedAccount = IdlTypes<DerivedIdl>[AccountName],
AccountName extends keyof IdlAccounts<DerivedIdl> = keyof IdlAccounts<DerivedIdl>,
DecodedAccount = IdlAccounts<DerivedIdl>[AccountName],
>(
programKey: ProgramName,
accountName: AccountName,
Expand All @@ -512,7 +512,7 @@ export class SolanaStakingClient {
ProgramName extends keyof Programs = keyof Programs,
DecodingProgram = Programs[ProgramName],
DerivedIdl extends Idl = DecodingProgram extends Program<infer IDLType> ? IDLType : never,
AccountName extends keyof IdlTypes<DerivedIdl> = keyof IdlTypes<DerivedIdl>,
AccountName extends keyof IdlAccounts<DerivedIdl> = keyof IdlAccounts<DerivedIdl>,
>(programKey: ProgramName, accountName: AccountName): number[] {
const decodingProgram = this.programs[programKey];
invariant(decodingProgram, `Decoding program with key ${programKey} is not available`);
Expand Down
14 changes: 7 additions & 7 deletions packages/staking/solana/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, type IdlTypes } from "@coral-xyz/anchor";
import { Address, type IdlAccounts } from "@coral-xyz/anchor";
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
import { Keypair } from "@solana/web3.js";
import { ITransactionSolanaExt } from "@streamflow/common/solana";
Expand All @@ -8,12 +8,12 @@ import { RewardPool as RewardPoolIDL } from "./descriptor/reward_pool.js";
import { StakePool as StakePoolIDL } from "./descriptor/stake_pool.js";
import { FeeManager as FeeManagerIDL } from "./descriptor/fee_manager.js";

export type StakePool = IdlTypes<StakePoolIDL>["stakePool"];
export type StakeEntry = IdlTypes<StakePoolIDL>["stakeEntry"];
export type RewardEntry = IdlTypes<RewardPoolIDL>["rewardEntry"];
export type RewardPool = IdlTypes<RewardPoolIDL>["rewardPool"];
export type FeeValue = IdlTypes<FeeManagerIDL>["feeValue"];
export type DefaultFeeValueConfig = IdlTypes<FeeManagerIDL>["config"];
export type StakePool = IdlAccounts<StakePoolIDL>["stakePool"];
export type StakeEntry = IdlAccounts<StakePoolIDL>["stakeEntry"];
export type RewardEntry = IdlAccounts<RewardPoolIDL>["rewardEntry"];
export type RewardPool = IdlAccounts<RewardPoolIDL>["rewardPool"];
export type FeeValue = IdlAccounts<FeeManagerIDL>["feeValue"];
export type DefaultFeeValueConfig = IdlAccounts<FeeManagerIDL>["config"];

export interface IInteractSolanaExt extends ITransactionSolanaExt {
invoker: SignerWalletAdapter | Keypair;
Expand Down
2 changes: 1 addition & 1 deletion packages/stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/stream",
"version": "7.4.2",
"version": "7.4.3",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "./dist/esm/index.js",
Expand Down
9 changes: 5 additions & 4 deletions packages/stream/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
import { AccountInfo, PublicKey, Keypair, VersionedTransaction, TransactionInstruction } from "@solana/web3.js";
import { ITransactionSolanaExt } from "@streamflow/common/solana";
import BN from "bn.js";
import { type IdlTypes } from "@coral-xyz/anchor";
import { type IdlAccounts, type IdlTypes } from "@coral-xyz/anchor";

import { buildStreamType, calculateUnlockedAmount, decodeEndTime } from "../common/contractUtils.js";
import { AlignedStream, IRecipient, LinearStream, OracleTypeName, StreamType } from "../common/types.js";
Expand All @@ -13,10 +13,11 @@ import { ALIGNED_PRECISION_FACTOR_POW } from "./constants.js";
export { IChain, ICluster, ContractError } from "@streamflow/common";

type AlignedUnlocksTypes = IdlTypes<AlignedUnlocksIDL>;
type AlignedUnlocksAccounts = IdlAccounts<AlignedUnlocksIDL>;

export type AlignedUnlocksContract = AlignedUnlocksTypes["contract"];
export type OracleType = AlignedUnlocksTypes["oracleType"];
export type TestOracle = AlignedUnlocksTypes["testOracle"];
export type AlignedUnlocksContract = AlignedUnlocksAccounts["contract"];
export type OracleType = IdlTypes<AlignedUnlocksIDL>["oracleType"];
export type TestOracle = AlignedUnlocksAccounts["testOracle"];

export type CreateParams = AlignedUnlocksTypes["createParams"];
export type ChangeOracleParams = AlignedUnlocksTypes["changeOracleParams"];
Expand Down

0 comments on commit e22bbb3

Please sign in to comment.