Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sol Transfer Fee plugin #188

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions clients/js/src/generated/errors/mplCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,82 @@ export class CannotAddDataSectionError extends ProgramError {
codeToErrorMap.set(0x2f, CannotAddDataSectionError);
nameToErrorMap.set('CannotAddDataSection', CannotAddDataSectionError);

/** PluginNotAllowedOnAsset: Plugin is not allowed to be added to an Asset */
export class PluginNotAllowedOnAssetError extends ProgramError {
override readonly name: string = 'PluginNotAllowedOnAsset';

readonly code: number = 0x30; // 48

constructor(program: Program, cause?: Error) {
super('Plugin is not allowed to be added to an Asset', program, cause);
}
}
codeToErrorMap.set(0x30, PluginNotAllowedOnAssetError);
nameToErrorMap.set('PluginNotAllowedOnAsset', PluginNotAllowedOnAssetError);

/** PluginNotAllowedOnCollection: Plugin is not allowed to be added to a Collection */
export class PluginNotAllowedOnCollectionError extends ProgramError {
override readonly name: string = 'PluginNotAllowedOnCollection';

readonly code: number = 0x31; // 49

constructor(program: Program, cause?: Error) {
super('Plugin is not allowed to be added to a Collection', program, cause);
}
}
codeToErrorMap.set(0x31, PluginNotAllowedOnCollectionError);
nameToErrorMap.set(
'PluginNotAllowedOnCollection',
PluginNotAllowedOnCollectionError
);

/** InvalidTreasuryWithdrawn: Cannot add a treasury plugin with nonzero withdrawn amount */
export class InvalidTreasuryWithdrawnError extends ProgramError {
override readonly name: string = 'InvalidTreasuryWithdrawn';

readonly code: number = 0x32; // 50

constructor(program: Program, cause?: Error) {
super(
'Cannot add a treasury plugin with nonzero withdrawn amount',
program,
cause
);
}
}
codeToErrorMap.set(0x32, InvalidTreasuryWithdrawnError);
nameToErrorMap.set('InvalidTreasuryWithdrawn', InvalidTreasuryWithdrawnError);

/** CannotOverdraw: Cannot withdraw more than excess rent from treasury */
export class CannotOverdrawError extends ProgramError {
override readonly name: string = 'CannotOverdraw';

readonly code: number = 0x33; // 51

constructor(program: Program, cause?: Error) {
super(
'Cannot withdraw more than excess rent from treasury',
program,
cause
);
}
}
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>;
}
22 changes: 22 additions & 0 deletions clients/js/src/generated/types/baseTreasury.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 BaseTreasury = { withdrawn: bigint };

export type BaseTreasuryArgs = { withdrawn: number | bigint };

export function getBaseTreasurySerializer(): Serializer<
BaseTreasuryArgs,
BaseTreasury
> {
return struct<BaseTreasury>([['withdrawn', u64()]], {
description: 'BaseTreasury',
}) as Serializer<BaseTreasuryArgs, BaseTreasury>;
}
2 changes: 2 additions & 0 deletions clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export * from './basePluginAuthority';
export * from './baseRoyalties';
export * from './baseRuleSet';
export * from './baseSeed';
export * from './baseSolTransferFee';
export * from './baseTreasury';
export * from './baseUpdateAuthority';
export * from './baseValidationResultsOffset';
export * from './burnDelegate';
Expand Down
34 changes: 32 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,10 @@ import {
BaseMasterEditionArgs,
BaseRoyalties,
BaseRoyaltiesArgs,
BaseSolTransferFee,
BaseSolTransferFeeArgs,
BaseTreasury,
BaseTreasuryArgs,
BurnDelegate,
BurnDelegateArgs,
Edition,
Expand All @@ -50,6 +54,8 @@ import {
getAutographSerializer,
getBaseMasterEditionSerializer,
getBaseRoyaltiesSerializer,
getBaseSolTransferFeeSerializer,
getBaseTreasurySerializer,
getBurnDelegateSerializer,
getEditionSerializer,
getFreezeDelegateSerializer,
Expand Down Expand Up @@ -77,7 +83,9 @@ export type Plugin =
| { __kind: 'AddBlocker'; fields: [AddBlocker] }
| { __kind: 'ImmutableMetadata'; fields: [ImmutableMetadata] }
| { __kind: 'VerifiedCreators'; fields: [VerifiedCreators] }
| { __kind: 'Autograph'; fields: [Autograph] };
| { __kind: 'Autograph'; fields: [Autograph] }
| { __kind: 'Treasury'; fields: [BaseTreasury] }
| { __kind: 'SolTransferFee'; fields: [BaseSolTransferFee] };

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

export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
return dataEnum<Plugin>(
Expand Down Expand Up @@ -192,6 +202,18 @@ export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
['fields', tuple([getAutographSerializer()])],
]),
],
[
'Treasury',
struct<GetDataEnumKindContent<Plugin, 'Treasury'>>([
['fields', tuple([getBaseTreasurySerializer()])],
]),
],
[
'SolTransferFee',
struct<GetDataEnumKindContent<Plugin, 'SolTransferFee'>>([
['fields', tuple([getBaseSolTransferFeeSerializer()])],
]),
],
],
{ description: 'Plugin' }
) as Serializer<PluginArgs, Plugin>;
Expand Down Expand Up @@ -261,6 +283,14 @@ export function plugin(
kind: 'Autograph',
data: GetDataEnumKindContent<PluginArgs, 'Autograph'>['fields']
): GetDataEnumKind<PluginArgs, 'Autograph'>;
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
2 changes: 2 additions & 0 deletions clients/js/src/generated/types/pluginType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export enum PluginType {
ImmutableMetadata,
VerifiedCreators,
Autograph,
Treasury,
SolTransferFee,
}

export type PluginTypeArgs = PluginType;
Expand Down
35 changes: 35 additions & 0 deletions clients/js/src/plugins/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
} from './pluginAuthority';
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 @@ -103,6 +105,19 @@ export function createPluginV2(args: AssetAllPluginArgsV2): BasePlugin {
fields: [masterEditionToBase(args)],
};
}
if (type === 'Treasury') {
return {
__kind: type,
fields: [treasuryToBase(args)],
};
}

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

return {
__kind: type,
Expand Down Expand Up @@ -167,6 +182,26 @@ export function mapPlugin({
};
}

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

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),
};
}
20 changes: 20 additions & 0 deletions clients/js/src/plugins/treasury.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { lamports, SolAmount } from '@metaplex-foundation/umi';
import { BaseTreasury } from '../generated';

export type Treasury = {
withdrawn: SolAmount;
};

export type TreasuryArgs = Treasury;

export function treasuryToBase(s: Treasury): BaseTreasury {
return {
withdrawn: s.withdrawn.basisPoints,
};
}

export function treasuryFromBase(s: BaseTreasury): Treasury {
return {
withdrawn: lamports(s.withdrawn),
};
}
24 changes: 23 additions & 1 deletion clients/js/src/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ import {
VerifiedCreatorsArgs,
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 @@ -88,6 +92,14 @@ export type CreatePluginArgs =
}
| {
type: 'AddBlocker';
}
| {
type: 'Treasury';
data: BaseTreasuryArgs;
}
| {
type: 'SolTransferFee';
data: BaseSolTransferFeeArgs;
};

export type AuthorityArgsV2 = {
Expand Down Expand Up @@ -143,7 +155,13 @@ export type AuthorityManagedPluginArgsV2 =
}
| ({
type: 'VerifiedCreators';
} & VerifiedCreatorsArgs);
} & VerifiedCreatorsArgs)
| ({
type: 'Treasury';
} & TreasuryArgs)
| ({
type: 'SolTransferFee';
} & SolTransferFeeArgs);

export type AssetAddablePluginArgsV2 =
| OwnerManagedPluginArgsV2
Expand Down Expand Up @@ -181,6 +199,8 @@ export type AddBlockerPlugin = BasePlugin & AddBlocker;
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 @@ -200,10 +220,12 @@ export type AssetPluginsList = {
burnDelegate?: BurnDelegatePlugin;
transferDelegate?: TransferDelegatePlugin;
edition?: EditionPlugin;
solTransferFee?: SolTransferFeePlugin;
} & CommonPluginsList;

export type CollectionPluginsList = {
masterEdition?: MasterEditionPlugin;
treasury?: TreasuryPlugin;
} & CommonPluginsList;

export type PluginsList = AssetPluginsList & CollectionPluginsList;
Loading
Loading