Skip to content

Commit

Permalink
WIP Sol Transfer fee plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Aug 18, 2024
1 parent c4fb33e commit e10b87a
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 3 deletions.
13 changes: 13 additions & 0 deletions clients/js/src/generated/errors/mplCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,19 @@ export class CannotOverdrawError extends ProgramError {
codeToErrorMap.set(0x33, CannotOverdrawError);
nameToErrorMap.set('CannotOverdraw', CannotOverdrawError);

/** PluginRequiresCollection: Plugin requires a collection */
export class PluginRequiresCollectionError extends ProgramError {
override readonly name: string = 'PluginRequiresCollection';

readonly code: number = 0x34; // 52

constructor(program: Program, cause?: Error) {
super('Plugin requires a collection', program, cause);
}
}
codeToErrorMap.set(0x34, PluginRequiresCollectionError);
nameToErrorMap.set('PluginRequiresCollection', PluginRequiresCollectionError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
22 changes: 22 additions & 0 deletions clients/js/src/generated/types/baseSolTransferFee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/metaplex-foundation/kinobi
*/

import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers';

export type BaseSolTransferFee = { feeAmount: bigint };

export type BaseSolTransferFeeArgs = { feeAmount: number | bigint };

export function getBaseSolTransferFeeSerializer(): Serializer<
BaseSolTransferFeeArgs,
BaseSolTransferFee
> {
return struct<BaseSolTransferFee>([['feeAmount', u64()]], {
description: 'BaseSolTransferFee',
}) as Serializer<BaseSolTransferFeeArgs, BaseSolTransferFee>;
}
1 change: 1 addition & 0 deletions clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export * from './basePluginAuthority';
export * from './baseRoyalties';
export * from './baseRuleSet';
export * from './baseSeed';
export * from './baseSolTransferFee';
export * from './baseTreasury';
export * from './baseUpdateAuthority';
export * from './baseValidationResultsOffset';
Expand Down
19 changes: 17 additions & 2 deletions clients/js/src/generated/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
BaseMasterEditionArgs,
BaseRoyalties,
BaseRoyaltiesArgs,
BaseSolTransferFee,
BaseSolTransferFeeArgs,
BaseTreasury,
BaseTreasuryArgs,
BurnDelegate,
Expand Down Expand Up @@ -52,6 +54,7 @@ import {
getAutographSerializer,
getBaseMasterEditionSerializer,
getBaseRoyaltiesSerializer,
getBaseSolTransferFeeSerializer,
getBaseTreasurySerializer,
getBurnDelegateSerializer,
getEditionSerializer,
Expand Down Expand Up @@ -81,7 +84,8 @@ export type Plugin =
| { __kind: 'ImmutableMetadata'; fields: [ImmutableMetadata] }
| { __kind: 'VerifiedCreators'; fields: [VerifiedCreators] }
| { __kind: 'Autograph'; fields: [Autograph] }
| { __kind: 'Treasury'; fields: [BaseTreasury] };
| { __kind: 'Treasury'; fields: [BaseTreasury] }
| { __kind: 'SolTransferFee'; fields: [BaseSolTransferFee] };

export type PluginArgs =
| { __kind: 'Royalties'; fields: [BaseRoyaltiesArgs] }
Expand All @@ -102,7 +106,8 @@ export type PluginArgs =
| { __kind: 'ImmutableMetadata'; fields: [ImmutableMetadataArgs] }
| { __kind: 'VerifiedCreators'; fields: [VerifiedCreatorsArgs] }
| { __kind: 'Autograph'; fields: [AutographArgs] }
| { __kind: 'Treasury'; fields: [BaseTreasuryArgs] };
| { __kind: 'Treasury'; fields: [BaseTreasuryArgs] }
| { __kind: 'SolTransferFee'; fields: [BaseSolTransferFeeArgs] };

export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
return dataEnum<Plugin>(
Expand Down Expand Up @@ -203,6 +208,12 @@ export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
['fields', tuple([getBaseTreasurySerializer()])],
]),
],
[
'SolTransferFee',
struct<GetDataEnumKindContent<Plugin, 'SolTransferFee'>>([
['fields', tuple([getBaseSolTransferFeeSerializer()])],
]),
],
],
{ description: 'Plugin' }
) as Serializer<PluginArgs, Plugin>;
Expand Down Expand Up @@ -276,6 +287,10 @@ export function plugin(
kind: 'Treasury',
data: GetDataEnumKindContent<PluginArgs, 'Treasury'>['fields']
): GetDataEnumKind<PluginArgs, 'Treasury'>;
export function plugin(
kind: 'SolTransferFee',
data: GetDataEnumKindContent<PluginArgs, 'SolTransferFee'>['fields']
): GetDataEnumKind<PluginArgs, 'SolTransferFee'>;
export function plugin<K extends PluginArgs['__kind']>(
kind: K,
data?: any
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/generated/types/pluginType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum PluginType {
VerifiedCreators,
Autograph,
Treasury,
SolTransferFee,
}

export type PluginTypeArgs = PluginType;
Expand Down
18 changes: 18 additions & 0 deletions clients/js/src/plugins/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { royaltiesFromBase, royaltiesToBase } from './royalties';
import { masterEditionFromBase, masterEditionToBase } from './masterEdition';
import { treasuryFromBase, treasuryToBase } from './treasury';
import { solTransferFeeFromBase, solTransferFeeToBase } from './solTransferFee';

export function formPluginHeaderV1(
pluginRegistryOffset: bigint
Expand Down Expand Up @@ -111,6 +112,13 @@ export function createPluginV2(args: AssetAllPluginArgsV2): BasePlugin {
};
}

if (type === 'SolTransferFee') {
return {
__kind: type,
fields: [solTransferFeeToBase(args)],
};
}

return {
__kind: type,
fields: [(args as any) || {}],
Expand Down Expand Up @@ -184,6 +192,16 @@ export function mapPlugin({
};
}

if (plug.__kind === 'SolTransferFee') {
return {
[pluginKey]: {
authority,
offset,
...solTransferFeeFromBase(plug.fields[0]),
},
};
}

return {
[pluginKey]: {
authority,
Expand Down
20 changes: 20 additions & 0 deletions clients/js/src/plugins/solTransferFee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { lamports, SolAmount } from '@metaplex-foundation/umi';
import { BaseSolTransferFee } from '../generated';

export type SolTransferFee = {
feeAmount: SolAmount;
};

export type SolTransferFeeArgs = SolTransferFee;

export function solTransferFeeToBase(s: SolTransferFee): BaseSolTransferFee {
return {
feeAmount: s.feeAmount.basisPoints,
};
}

export function solTransferFeeFromBase(s: BaseSolTransferFee): SolTransferFee {
return {
feeAmount: lamports(s.feeAmount),
};
}
13 changes: 12 additions & 1 deletion clients/js/src/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
Autograph,
VerifiedCreators,
BaseTreasuryArgs,
BaseSolTransferFeeArgs,
} from '../generated';
import { RoyaltiesArgs, RoyaltiesPlugin } from './royalties';
import { PluginAuthority } from './pluginAuthority';
import { MasterEdition, MasterEditionArgs } from './masterEdition';
import { Treasury, TreasuryArgs } from './treasury';
import { SolTransferFee, SolTransferFeeArgs } from './solTransferFee';

// for backwards compatibility
export { pluginAuthority, updateAuthority, ruleSet };
Expand Down Expand Up @@ -94,6 +96,10 @@ export type CreatePluginArgs =
| {
type: 'Treasury';
data: BaseTreasuryArgs;
}
| {
type: 'SolTransferFee';
data: BaseSolTransferFeeArgs;
};

export type AuthorityArgsV2 = {
Expand Down Expand Up @@ -152,7 +158,10 @@ export type AuthorityManagedPluginArgsV2 =
} & VerifiedCreatorsArgs)
| ({
type: 'Treasury';
} & TreasuryArgs);
} & TreasuryArgs)
| ({
type: 'SolTransferFee';
} & SolTransferFeeArgs);

export type AssetAddablePluginArgsV2 =
| OwnerManagedPluginArgsV2
Expand Down Expand Up @@ -191,6 +200,7 @@ export type ImmutableMetadataPlugin = BasePlugin & ImmutableMetadata;
export type VerifiedCreatorsPlugin = BasePlugin & VerifiedCreators;
export type AutographPlugin = BasePlugin & Autograph;
export type TreasuryPlugin = BasePlugin & Treasury;
export type SolTransferFeePlugin = BasePlugin & SolTransferFee;

export type CommonPluginsList = {
attributes?: AttributesPlugin;
Expand All @@ -210,6 +220,7 @@ export type AssetPluginsList = {
burnDelegate?: BurnDelegatePlugin;
transferDelegate?: TransferDelegatePlugin;
edition?: EditionPlugin;
solTransferFee?: SolTransferFeePlugin;
} & CommonPluginsList;

export type CollectionPluginsList = {
Expand Down
Loading

0 comments on commit e10b87a

Please sign in to comment.