Skip to content

Commit

Permalink
do not allow Token22 with transfer fee extension enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
makarychev committed Nov 19, 2024
1 parent 25fcd83 commit 5fa5cbd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 58 deletions.
12 changes: 2 additions & 10 deletions programs/dividends/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ use crate::errors::DividendsErrorCode;

pub fn validate_transfer_fee_mint_extension(mint_data: &AccountInfo) -> Result<()> {
let transfer_fee_extension = get_mint_extension_data::<TransferFeeConfig>(mint_data);
if let Ok(extension) = transfer_fee_extension {
let clock = Clock::get()?;
let transfer_fee_basis_points = u16::from(
extension
.get_epoch_fee(clock.epoch)
.transfer_fee_basis_points,
) as u128;
if transfer_fee_basis_points > 0 {
return Err(DividendsErrorCode::TransferFeeIsNotAllowedForPaymentMint.into());
}
if let Ok(_extension) = transfer_fee_extension {
return Err(DividendsErrorCode::TransferFeeIsNotAllowedForPaymentMint.into());
}

Ok(())
Expand Down
87 changes: 39 additions & 48 deletions tests/dividends/new-distributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe("new-distributor with transferFeeConfig", () => {

it("fails to initialize new distributor with non-zero transferFee", async () => {
const feeBasicPoints = 1000;
const paymentMintObjects = await createMockTokenWithTransferFee(
const { mint: paymentMintPubkey } = await createMockTokenWithTransferFee(
connection,
decimals,
feeBasicPoints
Expand All @@ -333,7 +333,7 @@ describe("new-distributor with transferFeeConfig", () => {
.accountsStrict({
base: baseKey.publicKey,
distributor,
mint: paymentMintObjects.mint,
mint: paymentMintPubkey,
authorityWalletRole:
testEnvironment.accessControlHelper.walletRolePDA(
signer.publicKey
Expand All @@ -359,7 +359,7 @@ describe("new-distributor with transferFeeConfig", () => {
}
});

it("initializes new distributor with zero transferFee", async () => {
it("failse to initializes new distributor with zero transferFee", async () => {
const feeBasicPoints = 0;
const { mint: paymentMintPubkey } = await createMockTokenWithTransferFee(
connection,
Expand All @@ -372,50 +372,41 @@ describe("new-distributor with transferFeeConfig", () => {
dividendsProgram.programId
);

await dividendsProgram.methods
.newDistributor(
bump,
toBytes32Array(root),
totalClaimAmount,
numNodes,
ipfsHash
)
.accountsStrict({
base: baseKey.publicKey,
distributor,
mint: paymentMintPubkey,
authorityWalletRole: testEnvironment.accessControlHelper.walletRolePDA(
signer.publicKey
)[0],
accessControl: testEnvironment.accessControlHelper.accessControlPubkey,
securityMint: testEnvironment.mintKeypair.publicKey,
payer: signer.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([signer, baseKey])
.rpc({ commitment });

const distributorData =
await dividendsProgram.account.merkleDistributor.fetch(distributor);
assert.equal(distributorData.bump, bump);
assert.equal(distributorData.numNodes.toString(), NUM_NODES.toString());
assert.equal(
distributorData.totalClaimAmount.toString(),
TOTAL_CLAIM_AMOUNT.toString()
);
assert.deepEqual(distributorData.base, baseKey.publicKey);
assert.deepEqual(distributorData.mint, paymentMintPubkey);
assert.deepEqual(
distributorData.accessControl,
testEnvironment.accessControlHelper.accessControlPubkey
);
assert.isFalse(distributorData.paused);
assert.equal(distributorData.numNodesClaimed.toNumber(), 0);
assert.deepEqual(
distributorData.root,
Array.from(new Uint8Array(ZERO_BYTES32))
);
assert.equal(distributorData.totalAmountClaimed.toNumber(), 0);
assert.isFalse(distributorData.readyToClaim);
try {
await dividendsProgram.methods
.newDistributor(
bump,
toBytes32Array(root),
totalClaimAmount,
numNodes,
ipfsHash
)
.accountsStrict({
base: baseKey.publicKey,
distributor,
mint: paymentMintPubkey,
authorityWalletRole:
testEnvironment.accessControlHelper.walletRolePDA(
signer.publicKey
)[0],
accessControl:
testEnvironment.accessControlHelper.accessControlPubkey,
securityMint: testEnvironment.mintKeypair.publicKey,
payer: signer.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([signer, baseKey])
.rpc({ commitment });
assert.fail("Expected to throw an error");
} catch ({ error }) {
assert.equal(
error.errorCode.code,
"TransferFeeIsNotAllowedForPaymentMint"
);
assert.equal(
error.errorMessage,
"Transfer fee is not allowed for payment mint"
);
}
});
});

0 comments on commit 5fa5cbd

Please sign in to comment.