Skip to content
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
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions clients/js-v1/src/generated/errors/monoswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ export class InvalidNiftyAssetError extends ProgramError {
codeToErrorMap.set(0x12, InvalidNiftyAssetError);
nameToErrorMap.set('InvalidNiftyAsset', InvalidNiftyAssetError);

/** InvalidSigner: Invalid Signer */
export class InvalidSignerError extends ProgramError {
override readonly name: string = 'InvalidSigner';

readonly code: number = 0x13; // 19

constructor(program: Program, cause?: Error) {
super('Invalid Signer', program, cause);
}
}
codeToErrorMap.set(0x13, InvalidSignerError);
nameToErrorMap.set('InvalidSigner', InvalidSignerError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
4 changes: 2 additions & 2 deletions clients/js-v1/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
*/

export * from './createSwap';
export * from './swapNifty';
export * from './swapNiftySPL';
export * from './swapAsset';
export * from './swapAssetSPL';
export * from './swapSPL';
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from '../shared';

// Accounts.
export type SwapNiftyInstructionAccounts = {
export type SwapAssetInstructionAccounts = {
/** Authority to transfer incoming asset */
authority?: Signer;
/** Escrows the asset and encodes state about the swap */
Expand All @@ -40,35 +40,35 @@ export type SwapNiftyInstructionAccounts = {
escrowedAssetGroup?: PublicKey | Pda;
/** Group account for the incoming asset, if applicable */
incomingAssetGroup?: PublicKey | Pda;
/** Nifty asset program account */
niftyAssetProgram: PublicKey | Pda;
/** Asset program account */
assetProgram: PublicKey | Pda;
};

// Data.
export type SwapNiftyInstructionData = { discriminator: number };
export type SwapAssetInstructionData = { discriminator: number };

export type SwapNiftyInstructionDataArgs = {};
export type SwapAssetInstructionDataArgs = {};

export function getSwapNiftyInstructionDataSerializer(): Serializer<
SwapNiftyInstructionDataArgs,
SwapNiftyInstructionData
export function getSwapAssetInstructionDataSerializer(): Serializer<
SwapAssetInstructionDataArgs,
SwapAssetInstructionData
> {
return mapSerializer<
SwapNiftyInstructionDataArgs,
SwapAssetInstructionDataArgs,
any,
SwapNiftyInstructionData
SwapAssetInstructionData
>(
struct<SwapNiftyInstructionData>([['discriminator', u8()]], {
description: 'SwapNiftyInstructionData',
struct<SwapAssetInstructionData>([['discriminator', u8()]], {
description: 'SwapAssetInstructionData',
}),
(value) => ({ ...value, discriminator: 2 })
) as Serializer<SwapNiftyInstructionDataArgs, SwapNiftyInstructionData>;
) as Serializer<SwapAssetInstructionDataArgs, SwapAssetInstructionData>;
}

// Instruction.
export function swapNifty(
export function swapAsset(
context: Pick<Context, 'identity' | 'programs'>,
input: SwapNiftyInstructionAccounts
input: SwapAssetInstructionAccounts
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -108,10 +108,10 @@ export function swapNifty(
isWritable: true as boolean,
value: input.incomingAssetGroup ?? null,
},
niftyAssetProgram: {
assetProgram: {
index: 6,
isWritable: false as boolean,
value: input.niftyAssetProgram ?? null,
value: input.assetProgram ?? null,
},
} satisfies ResolvedAccountsWithIndices;

Expand All @@ -133,7 +133,7 @@ export function swapNifty(
);

// Data.
const data = getSwapNiftyInstructionDataSerializer().serialize({});
const data = getSwapAssetInstructionDataSerializer().serialize({});

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from '../shared';

// Accounts.
export type SwapNiftySPLInstructionAccounts = {
export type SwapAssetSPLInstructionAccounts = {
/** Account to pay for ATA creation */
payer?: Signer;
/** Authority to transfer incoming asset */
Expand All @@ -39,7 +39,7 @@ export type SwapNiftySPLInstructionAccounts = {
/** External asset being swapped for the escrowed asset */
incomingAsset: PublicKey | Pda;
/** Group account for the nifty asset, if applicable */
niftyAssetGroup?: PublicKey | Pda;
assetGroup?: PublicKey | Pda;
/** ATA account for the swap marker, if applicable */
swapMarkerAta: PublicKey | Pda;
/** ATA account for the authority, if applicable */
Expand All @@ -55,30 +55,30 @@ export type SwapNiftySPLInstructionAccounts = {
};

// Data.
export type SwapNiftySPLInstructionData = { discriminator: number };
export type SwapAssetSPLInstructionData = { discriminator: number };

export type SwapNiftySPLInstructionDataArgs = {};
export type SwapAssetSPLInstructionDataArgs = {};

export function getSwapNiftySPLInstructionDataSerializer(): Serializer<
SwapNiftySPLInstructionDataArgs,
SwapNiftySPLInstructionData
export function getSwapAssetSPLInstructionDataSerializer(): Serializer<
SwapAssetSPLInstructionDataArgs,
SwapAssetSPLInstructionData
> {
return mapSerializer<
SwapNiftySPLInstructionDataArgs,
SwapAssetSPLInstructionDataArgs,
any,
SwapNiftySPLInstructionData
SwapAssetSPLInstructionData
>(
struct<SwapNiftySPLInstructionData>([['discriminator', u8()]], {
description: 'SwapNiftySPLInstructionData',
struct<SwapAssetSPLInstructionData>([['discriminator', u8()]], {
description: 'SwapAssetSPLInstructionData',
}),
(value) => ({ ...value, discriminator: 3 })
) as Serializer<SwapNiftySPLInstructionDataArgs, SwapNiftySPLInstructionData>;
) as Serializer<SwapAssetSPLInstructionDataArgs, SwapAssetSPLInstructionData>;
}

// Instruction.
export function swapNiftySPL(
export function swapAssetSPL(
context: Pick<Context, 'identity' | 'payer' | 'programs'>,
input: SwapNiftySPLInstructionAccounts
input: SwapAssetSPLInstructionAccounts
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -113,10 +113,10 @@ export function swapNiftySPL(
isWritable: true as boolean,
value: input.incomingAsset ?? null,
},
niftyAssetGroup: {
assetGroup: {
index: 5,
isWritable: true as boolean,
value: input.niftyAssetGroup ?? null,
value: input.assetGroup ?? null,
},
swapMarkerAta: {
index: 6,
Expand Down Expand Up @@ -178,7 +178,7 @@ export function swapNiftySPL(
);

// Data.
const data = getSwapNiftySPLInstructionDataSerializer().serialize({});
const data = getSwapAssetSPLInstructionDataSerializer().serialize({});

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;
Expand Down
20 changes: 10 additions & 10 deletions clients/js-v1/test/swap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
createSwap,
fetchSwapMarker,
findSwapMarkerPda,
swapNifty,
swapNiftySPL,
swapAsset,
swapAssetSPL,
swapSPL,
} from '../src';

Expand Down Expand Up @@ -105,12 +105,12 @@ test('it can swap nifty-to-nifty and back', async (t) => {
t.is(assetAccount.owner, user.publicKey);

// Swap them.
await swapNifty(umi, {
await swapAsset(umi, {
authority: user,
swapMarker,
incomingAsset: asset1.publicKey,
escrowedAsset: asset2.publicKey,
niftyAssetProgram: ASSET_PROGRAM_ID,
assetProgram: ASSET_PROGRAM_ID,
}).sendAndConfirm(umi);

// Assets are reversed.
Expand All @@ -131,12 +131,12 @@ test('it can swap nifty-to-nifty and back', async (t) => {
});

// Swap back.
await swapNifty(umi, {
await swapAsset(umi, {
authority: user,
swapMarker,
incomingAsset: asset2.publicKey,
escrowedAsset: asset1.publicKey,
niftyAssetProgram: ASSET_PROGRAM_ID,
assetProgram: ASSET_PROGRAM_ID,
}).sendAndConfirm(umi);

// Back to the original state.
Expand Down Expand Up @@ -455,7 +455,7 @@ test('it can swap nifty-to-fungible and back', async (t) => {

// Swap the fungibles back to the user in exchange for the Nifty asset.

await swapNiftySPL(umi, {
await swapAssetSPL(umi, {
payer: umi.identity,
authority: user,
swapMarker,
Expand Down Expand Up @@ -486,7 +486,7 @@ test('it can swap nifty-to-fungible and back', async (t) => {
});

// Swap back.
await swapNiftySPL(umi, {
await swapAssetSPL(umi, {
payer: umi.identity,
authority: user,
swapMarker,
Expand Down Expand Up @@ -618,7 +618,7 @@ test('it can swap nifty-to-mplx-legacy and back', async (t) => {

// Swap the fungibles back to the user in exchange for the Nifty asset.

await swapNiftySPL(umi, {
await swapAssetSPL(umi, {
payer: umi.identity,
authority: user,
swapMarker,
Expand Down Expand Up @@ -649,7 +649,7 @@ test('it can swap nifty-to-mplx-legacy and back', async (t) => {
});

// Swap back.
await swapNiftySPL(umi, {
await swapAssetSPL(umi, {
payer: umi.identity,
authority: user,
swapMarker,
Expand Down
6 changes: 6 additions & 0 deletions clients/js-v2/src/generated/errors/monoswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const enum MonoswapProgramErrorCode {
INVALID_TOKEN_PROGRAM = 0x11, // 17
/** InvalidNiftyAsset: Invalid Nifty Asset */
INVALID_NIFTY_ASSET = 0x12, // 18
/** InvalidSigner: Invalid Signer */
INVALID_SIGNER = 0x13, // 19
}

export class MonoswapProgramError extends Error {
Expand Down Expand Up @@ -147,6 +149,10 @@ if (__DEV__) {
'InvalidNiftyAsset',
`Invalid Nifty Asset`,
],
[MonoswapProgramErrorCode.INVALID_SIGNER]: [
'InvalidSigner',
`Invalid Signer`,
],
};
}

Expand Down
4 changes: 2 additions & 2 deletions clients/js-v2/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
*/

export * from './createSwap';
export * from './swapNifty';
export * from './swapNiftySPL';
export * from './swapAsset';
export * from './swapAssetSPL';
export * from './swapSPL';
Loading