Skip to content

Commit 5334b4c

Browse files
feat: support MintCloseAuthority token 2022 extension (#114)
* feat: support MintCloseAuthority token 2022 extension * fix: bankrun tests
1 parent 334a04b commit 5334b4c

File tree

3 files changed

+157
-161
lines changed

3 files changed

+157
-161
lines changed

shared/src/utils/token_util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl TokenUtil {
2020
/// correct at the moment our smart contract interacts with these tokens.
2121
///
2222
/// If the config change, we the DTF creator/owner must remove the tokens/take necessary actions.
23-
pub const ALLOWED_MINT_EXTENSION_TYPES: [ExtensionType; 13] = [
23+
pub const ALLOWED_MINT_EXTENSION_TYPES: [ExtensionType; 14] = [
2424
ExtensionType::Uninitialized,
2525
ExtensionType::InterestBearingConfig,
2626
ExtensionType::MetadataPointer,
@@ -36,6 +36,8 @@ impl TokenUtil {
3636
ExtensionType::ConfidentialTransferMint,
3737
// Only if the program_id is None.
3838
ExtensionType::TransferHook,
39+
// Supported as it is used by some of the stable coins, like PYUSD, USDG, AUSD
40+
ExtensionType::MintCloseAuthority,
3941
];
4042

4143
/// The allowed token extension types.

tests-ts/bankrun/tests/tests-folio-basket.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -237,40 +237,38 @@ describe("Bankrun - Folio basket", () => {
237237
expectedInitialBalanceSharesChange: new BN(0),
238238
},
239239

240-
...[
241-
ExtensionType.TransferFeeConfig,
242-
ExtensionType.MintCloseAuthority,
243-
ExtensionType.NonTransferable,
244-
].map((extension) => {
245-
return {
246-
desc: `Should fail if ${ExtensionType[extension]} is present on mint`,
247-
expectedError: "UnsupportedSPLToken",
248-
initialShares: null,
249-
tokens: [
250-
{ mint: MINTS_2022[0].publicKey, amount: new BN(1_000_000_000) },
251-
],
252-
addMintExtension: async (ctx: LiteSVM, mint: PublicKey) => {
253-
const accountLen = getMintLen([extension]);
254-
const existingAccount = await ctx.getAccount(mint);
255-
const existingData = Buffer.from(existingAccount.data);
256-
const lengthRequired = accountLen - existingData.length;
257-
const additionalData = Buffer.alloc(lengthRequired);
258-
const startForExtensions = ACCOUNT_SIZE - existingData.length;
259-
additionalData.writeUInt8(AccountType.Mint, startForExtensions);
260-
let offset = startForExtensions + 1;
261-
additionalData.writeUInt16LE(extension, offset);
262-
offset += 2;
263-
additionalData.writeUInt16LE(getTypeLen(extension), offset);
264-
offset += 2;
265-
266-
const finalData = Buffer.concat([existingData, additionalData]);
267-
ctx.setAccount(mint, {
268-
...existingAccount,
269-
data: finalData,
270-
});
271-
},
272-
};
273-
}),
240+
...[ExtensionType.TransferFeeConfig, ExtensionType.NonTransferable].map(
241+
(extension) => {
242+
return {
243+
desc: `Should fail if ${ExtensionType[extension]} is present on mint`,
244+
expectedError: "UnsupportedSPLToken",
245+
initialShares: null,
246+
tokens: [
247+
{ mint: MINTS_2022[0].publicKey, amount: new BN(1_000_000_000) },
248+
],
249+
addMintExtension: async (ctx: LiteSVM, mint: PublicKey) => {
250+
const accountLen = getMintLen([extension]);
251+
const existingAccount = await ctx.getAccount(mint);
252+
const existingData = Buffer.from(existingAccount.data);
253+
const lengthRequired = accountLen - existingData.length;
254+
const additionalData = Buffer.alloc(lengthRequired);
255+
const startForExtensions = ACCOUNT_SIZE - existingData.length;
256+
additionalData.writeUInt8(AccountType.Mint, startForExtensions);
257+
let offset = startForExtensions + 1;
258+
additionalData.writeUInt16LE(extension, offset);
259+
offset += 2;
260+
additionalData.writeUInt16LE(getTypeLen(extension), offset);
261+
offset += 2;
262+
263+
const finalData = Buffer.concat([existingData, additionalData]);
264+
ctx.setAccount(mint, {
265+
...existingAccount,
266+
data: finalData,
267+
});
268+
},
269+
};
270+
}
271+
),
274272
];
275273

276274
const TEST_CASES_REMOVE_FROM_BASKET = [

tests-ts/bankrun/tests/tests-rebalance.ts

Lines changed: 122 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -586,72 +586,70 @@ describe("Bankrun - Rebalance", () => {
586586
mints: [DEFAULT_BUY_MINT.publicKey, DEFAULT_SELL_MINT.publicKey],
587587
},
588588

589-
...[
590-
ExtensionType.TransferFeeConfig,
591-
ExtensionType.MintCloseAuthority,
592-
ExtensionType.NonTransferable,
593-
].map((extension) => {
594-
return {
595-
desc: `Should fail if ${ExtensionType[extension]} is present on mint`,
596-
expectedError: "UnsupportedSPLToken",
597-
allRebalanceDetailsAdded: true,
598-
addMintExtension: async (ctx: LiteSVM, buyMint: PublicKey) => {
599-
const accountLen = getMintLen([extension]);
600-
const existingAccount = await ctx.getAccount(buyMint);
601-
const existingData = Buffer.from(existingAccount.data);
602-
const lengthRequired = accountLen - existingData.length;
603-
const additionalData = Buffer.alloc(lengthRequired);
604-
const startForExtensions = ACCOUNT_SIZE - existingData.length;
605-
additionalData.writeUInt8(AccountType.Mint, startForExtensions);
606-
let offset = startForExtensions + 1;
607-
additionalData.writeUInt16LE(extension, offset);
608-
offset += 2;
609-
additionalData.writeUInt16LE(getTypeLen(extension), offset);
610-
offset += 2;
611-
612-
const finalData = Buffer.concat([existingData, additionalData]);
613-
ctx.setAccount(buyMint, {
614-
...existingAccount,
615-
data: finalData,
616-
});
617-
},
618-
existingRebalanceParams: {
619-
nonce: new BN(10),
620-
currentAuctionId: new BN(1),
621-
allRebalanceDetailsAdded: false,
622-
auctionLauncherWindow: 100,
623-
ttl: 100,
624-
startedAt: new BN(100),
625-
restrictedUntil: new BN(100),
626-
availableUntil: new BN(100),
627-
},
628-
pricesAndLimits: [
629-
{
630-
prices: {
631-
low: new BN(1),
632-
high: new BN(2),
633-
},
634-
limits: {
635-
spot: new BN(1),
636-
low: new BN(1),
637-
high: new BN(2),
638-
},
589+
...[ExtensionType.TransferFeeConfig, ExtensionType.NonTransferable].map(
590+
(extension) => {
591+
return {
592+
desc: `Should fail if ${ExtensionType[extension]} is present on mint`,
593+
expectedError: "UnsupportedSPLToken",
594+
allRebalanceDetailsAdded: true,
595+
addMintExtension: async (ctx: LiteSVM, buyMint: PublicKey) => {
596+
const accountLen = getMintLen([extension]);
597+
const existingAccount = await ctx.getAccount(buyMint);
598+
const existingData = Buffer.from(existingAccount.data);
599+
const lengthRequired = accountLen - existingData.length;
600+
const additionalData = Buffer.alloc(lengthRequired);
601+
const startForExtensions = ACCOUNT_SIZE - existingData.length;
602+
additionalData.writeUInt8(AccountType.Mint, startForExtensions);
603+
let offset = startForExtensions + 1;
604+
additionalData.writeUInt16LE(extension, offset);
605+
offset += 2;
606+
additionalData.writeUInt16LE(getTypeLen(extension), offset);
607+
offset += 2;
608+
609+
const finalData = Buffer.concat([existingData, additionalData]);
610+
ctx.setAccount(buyMint, {
611+
...existingAccount,
612+
data: finalData,
613+
});
639614
},
640-
{
641-
prices: {
642-
low: new BN(1),
643-
high: new BN(2),
615+
existingRebalanceParams: {
616+
nonce: new BN(10),
617+
currentAuctionId: new BN(1),
618+
allRebalanceDetailsAdded: false,
619+
auctionLauncherWindow: 100,
620+
ttl: 100,
621+
startedAt: new BN(100),
622+
restrictedUntil: new BN(100),
623+
availableUntil: new BN(100),
624+
},
625+
pricesAndLimits: [
626+
{
627+
prices: {
628+
low: new BN(1),
629+
high: new BN(2),
630+
},
631+
limits: {
632+
spot: new BN(1),
633+
low: new BN(1),
634+
high: new BN(2),
635+
},
644636
},
645-
limits: {
646-
spot: new BN(2),
647-
low: new BN(1),
648-
high: new BN(2),
637+
{
638+
prices: {
639+
low: new BN(1),
640+
high: new BN(2),
641+
},
642+
limits: {
643+
spot: new BN(2),
644+
low: new BN(1),
645+
high: new BN(2),
646+
},
649647
},
650-
},
651-
],
652-
mints: [BUY_MINTS_2022[0].publicKey, DEFAULT_SELL_MINT.publicKey],
653-
};
654-
}),
648+
],
649+
mints: [BUY_MINTS_2022[0].publicKey, DEFAULT_SELL_MINT.publicKey],
650+
};
651+
}
652+
),
655653

656654
...[
657655
ExtensionType.Uninitialized,
@@ -1096,72 +1094,70 @@ describe("Bankrun - Rebalance", () => {
10961094
mints: [DEFAULT_BUY_MINT.publicKey, DEFAULT_SELL_MINT.publicKey],
10971095
},
10981096

1099-
...[
1100-
ExtensionType.TransferFeeConfig,
1101-
ExtensionType.MintCloseAuthority,
1102-
ExtensionType.NonTransferable,
1103-
].map((extension) => {
1104-
return {
1105-
desc: `Should fail if ${ExtensionType[extension]} is present on mint`,
1106-
expectedError: "UnsupportedSPLToken",
1107-
allRebalanceDetailsAdded: true,
1108-
addMintExtension: async (ctx: LiteSVM, buyMint: PublicKey) => {
1109-
const accountLen = getMintLen([extension]);
1110-
const existingAccount = await ctx.getAccount(buyMint);
1111-
const existingData = Buffer.from(existingAccount.data);
1112-
const lengthRequired = accountLen - existingData.length;
1113-
const additionalData = Buffer.alloc(lengthRequired);
1114-
const startForExtensions = ACCOUNT_SIZE - existingData.length;
1115-
additionalData.writeUInt8(AccountType.Mint, startForExtensions);
1116-
let offset = startForExtensions + 1;
1117-
additionalData.writeUInt16LE(extension, offset);
1118-
offset += 2;
1119-
additionalData.writeUInt16LE(getTypeLen(extension), offset);
1120-
offset += 2;
1121-
1122-
const finalData = Buffer.concat([existingData, additionalData]);
1123-
ctx.setAccount(buyMint, {
1124-
...existingAccount,
1125-
data: finalData,
1126-
});
1127-
},
1128-
existingRebalanceParams: {
1129-
nonce: new BN(10),
1130-
currentAuctionId: new BN(1),
1131-
allRebalanceDetailsAdded: false,
1132-
auctionLauncherWindow: 100,
1133-
ttl: 100,
1134-
startedAt: new BN(100),
1135-
restrictedUntil: new BN(100),
1136-
availableUntil: new BN(100),
1137-
},
1138-
pricesAndLimits: [
1139-
{
1140-
prices: {
1141-
low: new BN(1),
1142-
high: new BN(2),
1143-
},
1144-
limits: {
1145-
spot: new BN(1),
1146-
low: new BN(1),
1147-
high: new BN(2),
1148-
},
1097+
...[ExtensionType.TransferFeeConfig, ExtensionType.NonTransferable].map(
1098+
(extension) => {
1099+
return {
1100+
desc: `Should fail if ${ExtensionType[extension]} is present on mint`,
1101+
expectedError: "UnsupportedSPLToken",
1102+
allRebalanceDetailsAdded: true,
1103+
addMintExtension: async (ctx: LiteSVM, buyMint: PublicKey) => {
1104+
const accountLen = getMintLen([extension]);
1105+
const existingAccount = await ctx.getAccount(buyMint);
1106+
const existingData = Buffer.from(existingAccount.data);
1107+
const lengthRequired = accountLen - existingData.length;
1108+
const additionalData = Buffer.alloc(lengthRequired);
1109+
const startForExtensions = ACCOUNT_SIZE - existingData.length;
1110+
additionalData.writeUInt8(AccountType.Mint, startForExtensions);
1111+
let offset = startForExtensions + 1;
1112+
additionalData.writeUInt16LE(extension, offset);
1113+
offset += 2;
1114+
additionalData.writeUInt16LE(getTypeLen(extension), offset);
1115+
offset += 2;
1116+
1117+
const finalData = Buffer.concat([existingData, additionalData]);
1118+
ctx.setAccount(buyMint, {
1119+
...existingAccount,
1120+
data: finalData,
1121+
});
11491122
},
1150-
{
1151-
prices: {
1152-
low: new BN(1),
1153-
high: new BN(2),
1123+
existingRebalanceParams: {
1124+
nonce: new BN(10),
1125+
currentAuctionId: new BN(1),
1126+
allRebalanceDetailsAdded: false,
1127+
auctionLauncherWindow: 100,
1128+
ttl: 100,
1129+
startedAt: new BN(100),
1130+
restrictedUntil: new BN(100),
1131+
availableUntil: new BN(100),
1132+
},
1133+
pricesAndLimits: [
1134+
{
1135+
prices: {
1136+
low: new BN(1),
1137+
high: new BN(2),
1138+
},
1139+
limits: {
1140+
spot: new BN(1),
1141+
low: new BN(1),
1142+
high: new BN(2),
1143+
},
11541144
},
1155-
limits: {
1156-
spot: new BN(2),
1157-
low: new BN(1),
1158-
high: new BN(2),
1145+
{
1146+
prices: {
1147+
low: new BN(1),
1148+
high: new BN(2),
1149+
},
1150+
limits: {
1151+
spot: new BN(2),
1152+
low: new BN(1),
1153+
high: new BN(2),
1154+
},
11591155
},
1160-
},
1161-
],
1162-
mints: [BUY_MINTS_2022[0].publicKey, DEFAULT_SELL_MINT.publicKey],
1163-
};
1164-
}),
1156+
],
1157+
mints: [BUY_MINTS_2022[0].publicKey, DEFAULT_SELL_MINT.publicKey],
1158+
};
1159+
}
1160+
),
11651161

11661162
...[
11671163
ExtensionType.Uninitialized,

0 commit comments

Comments
 (0)