Skip to content

Commit

Permalink
CK: Add Switchboard Feeds (#27)
Browse files Browse the repository at this point in the history
- Added Feeds to permissionlessly set weights
- Changed TrackedMints -> VaultRegistry
- Renamed some instructions to identify what needs an admin
  • Loading branch information
coachchucksol authored Dec 19, 2024
1 parent 9b15dda commit a0a5471
Show file tree
Hide file tree
Showing 133 changed files with 7,951 additions and 3,367 deletions.
530 changes: 498 additions & 32 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ solana-rpc-client-api = "~1.18"
solana-security-txt = "1.1.1"
spl-associated-token-account = { version = "2.2.0", features = ["no-entrypoint"] }
spl-token = { version = "4.0.0", features = ["no-entrypoint"] }
switchboard-on-demand = "0.1.0"
syn = "2.0.72"
thiserror = "1.0.57"
tokio = { version = "1.36.0", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion clients/js/jito_tip_router/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export * from './epochSnapshot';
export * from './ncnConfig';
export * from './ncnRewardRouter';
export * from './operatorSnapshot';
export * from './trackedMints';
export * from './vaultRegistry';
export * from './weightTable';
Original file line number Diff line number Diff line change
Expand Up @@ -35,101 +35,116 @@ import {
type MaybeEncodedAccount,
} from '@solana/web3.js';
import {
getMintEntryDecoder,
getMintEntryEncoder,
type MintEntry,
type MintEntryArgs,
getStMintEntryDecoder,
getStMintEntryEncoder,
getVaultEntryDecoder,
getVaultEntryEncoder,
type StMintEntry,
type StMintEntryArgs,
type VaultEntry,
type VaultEntryArgs,
} from '../types';

export type TrackedMints = {
export type VaultRegistry = {
discriminator: bigint;
ncn: Address;
bump: number;
reserved: Array<number>;
stMintList: Array<MintEntry>;
stMintList: Array<StMintEntry>;
vaultList: Array<VaultEntry>;
};

export type TrackedMintsArgs = {
export type VaultRegistryArgs = {
discriminator: number | bigint;
ncn: Address;
bump: number;
reserved: Array<number>;
stMintList: Array<MintEntryArgs>;
stMintList: Array<StMintEntryArgs>;
vaultList: Array<VaultEntryArgs>;
};

export function getTrackedMintsEncoder(): Encoder<TrackedMintsArgs> {
export function getVaultRegistryEncoder(): Encoder<VaultRegistryArgs> {
return getStructEncoder([
['discriminator', getU64Encoder()],
['ncn', getAddressEncoder()],
['bump', getU8Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 127 })],
['stMintList', getArrayEncoder(getMintEntryEncoder(), { size: 64 })],
['stMintList', getArrayEncoder(getStMintEntryEncoder(), { size: 64 })],
['vaultList', getArrayEncoder(getVaultEntryEncoder(), { size: 64 })],
]);
}

export function getTrackedMintsDecoder(): Decoder<TrackedMints> {
export function getVaultRegistryDecoder(): Decoder<VaultRegistry> {
return getStructDecoder([
['discriminator', getU64Decoder()],
['ncn', getAddressDecoder()],
['bump', getU8Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 127 })],
['stMintList', getArrayDecoder(getMintEntryDecoder(), { size: 64 })],
['stMintList', getArrayDecoder(getStMintEntryDecoder(), { size: 64 })],
['vaultList', getArrayDecoder(getVaultEntryDecoder(), { size: 64 })],
]);
}

export function getTrackedMintsCodec(): Codec<TrackedMintsArgs, TrackedMints> {
return combineCodec(getTrackedMintsEncoder(), getTrackedMintsDecoder());
export function getVaultRegistryCodec(): Codec<
VaultRegistryArgs,
VaultRegistry
> {
return combineCodec(getVaultRegistryEncoder(), getVaultRegistryDecoder());
}

export function decodeTrackedMints<TAddress extends string = string>(
export function decodeVaultRegistry<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress>
): Account<TrackedMints, TAddress>;
export function decodeTrackedMints<TAddress extends string = string>(
): Account<VaultRegistry, TAddress>;
export function decodeVaultRegistry<TAddress extends string = string>(
encodedAccount: MaybeEncodedAccount<TAddress>
): MaybeAccount<TrackedMints, TAddress>;
export function decodeTrackedMints<TAddress extends string = string>(
): MaybeAccount<VaultRegistry, TAddress>;
export function decodeVaultRegistry<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>
): Account<TrackedMints, TAddress> | MaybeAccount<TrackedMints, TAddress> {
): Account<VaultRegistry, TAddress> | MaybeAccount<VaultRegistry, TAddress> {
return decodeAccount(
encodedAccount as MaybeEncodedAccount<TAddress>,
getTrackedMintsDecoder()
getVaultRegistryDecoder()
);
}

export async function fetchTrackedMints<TAddress extends string = string>(
export async function fetchVaultRegistry<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<Account<TrackedMints, TAddress>> {
const maybeAccount = await fetchMaybeTrackedMints(rpc, address, config);
): Promise<Account<VaultRegistry, TAddress>> {
const maybeAccount = await fetchMaybeVaultRegistry(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}

export async function fetchMaybeTrackedMints<TAddress extends string = string>(
export async function fetchMaybeVaultRegistry<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<MaybeAccount<TrackedMints, TAddress>> {
): Promise<MaybeAccount<VaultRegistry, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeTrackedMints(maybeAccount);
return decodeVaultRegistry(maybeAccount);
}

export async function fetchAllTrackedMints(
export async function fetchAllVaultRegistry(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<Account<TrackedMints>[]> {
const maybeAccounts = await fetchAllMaybeTrackedMints(rpc, addresses, config);
): Promise<Account<VaultRegistry>[]> {
const maybeAccounts = await fetchAllMaybeVaultRegistry(
rpc,
addresses,
config
);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}

export async function fetchAllMaybeTrackedMints(
export async function fetchAllMaybeVaultRegistry(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<MaybeAccount<TrackedMints>[]> {
): Promise<MaybeAccount<VaultRegistry>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeTrackedMints(maybeAccount));
return maybeAccounts.map((maybeAccount) => decodeVaultRegistry(maybeAccount));
}
20 changes: 16 additions & 4 deletions clients/js/jito_tip_router/accounts/weightTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,50 @@ import {
type MaybeEncodedAccount,
} from '@solana/web3.js';
import {
getVaultEntryDecoder,
getVaultEntryEncoder,
getWeightEntryDecoder,
getWeightEntryEncoder,
type VaultEntry,
type VaultEntryArgs,
type WeightEntry,
type WeightEntryArgs,
} from '../types';

export type WeightTable = {
discriminator: bigint;
ncn: Address;
ncnEpoch: bigint;
epoch: bigint;
slotCreated: bigint;
vaultCount: bigint;
bump: number;
reserved: Array<number>;
vaultRegistry: Array<VaultEntry>;
table: Array<WeightEntry>;
};

export type WeightTableArgs = {
discriminator: number | bigint;
ncn: Address;
ncnEpoch: number | bigint;
epoch: number | bigint;
slotCreated: number | bigint;
vaultCount: number | bigint;
bump: number;
reserved: Array<number>;
vaultRegistry: Array<VaultEntryArgs>;
table: Array<WeightEntryArgs>;
};

export function getWeightTableEncoder(): Encoder<WeightTableArgs> {
return getStructEncoder([
['discriminator', getU64Encoder()],
['ncn', getAddressEncoder()],
['ncnEpoch', getU64Encoder()],
['epoch', getU64Encoder()],
['slotCreated', getU64Encoder()],
['vaultCount', getU64Encoder()],
['bump', getU8Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })],
['vaultRegistry', getArrayEncoder(getVaultEntryEncoder(), { size: 64 })],
['table', getArrayEncoder(getWeightEntryEncoder(), { size: 64 })],
]);
}
Expand All @@ -77,10 +87,12 @@ export function getWeightTableDecoder(): Decoder<WeightTable> {
return getStructDecoder([
['discriminator', getU64Decoder()],
['ncn', getAddressDecoder()],
['ncnEpoch', getU64Decoder()],
['epoch', getU64Decoder()],
['slotCreated', getU64Decoder()],
['vaultCount', getU64Decoder()],
['bump', getU8Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })],
['vaultRegistry', getArrayDecoder(getVaultEntryDecoder(), { size: 64 })],
['table', getArrayDecoder(getWeightEntryDecoder(), { size: 64 })],
]);
}
Expand Down
Loading

0 comments on commit a0a5471

Please sign in to comment.