-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more helpers to get init instructions for extensions (#15)
* Add more helpers to get init instructions for extensions * Add memo transfer to post init helper * Refactor tests
- Loading branch information
1 parent
1f85414
commit 872081d
Showing
10 changed files
with
146 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Address, IInstruction, TransactionSigner } from '@solana/web3.js'; | ||
import { | ||
ExtensionArgs, | ||
getDisableMemoTransfersInstruction, | ||
getEnableMemoTransfersInstruction, | ||
getInitializeConfidentialTransferMintInstruction, | ||
getInitializeDefaultAccountStateInstruction, | ||
getInitializeTransferFeeConfigInstruction, | ||
} from './generated'; | ||
|
||
/** | ||
* Given a mint address and a list of mint extensions, returns a list of | ||
* instructions that MUST be run _before_ the `initializeMint` instruction | ||
* to properly initialize the given extensions on the mint account. | ||
*/ | ||
export function getPreInitializeInstructionsForMintExtensions( | ||
mint: Address, | ||
extensions: ExtensionArgs[] | ||
): IInstruction[] { | ||
return extensions.flatMap((extension) => { | ||
switch (extension.__kind) { | ||
case 'ConfidentialTransferMint': | ||
return [ | ||
getInitializeConfidentialTransferMintInstruction({ | ||
mint, | ||
...extension, | ||
}), | ||
]; | ||
case 'DefaultAccountState': | ||
return [ | ||
getInitializeDefaultAccountStateInstruction({ | ||
mint, | ||
state: extension.state, | ||
}), | ||
]; | ||
case 'TransferFeeConfig': | ||
return [ | ||
getInitializeTransferFeeConfigInstruction({ | ||
mint, | ||
transferFeeConfigAuthority: extension.transferFeeConfigAuthority, | ||
withdrawWithheldAuthority: extension.withdrawWithheldAuthority, | ||
transferFeeBasisPoints: | ||
extension.newerTransferFee.transferFeeBasisPoints, | ||
maximumFee: extension.newerTransferFee.maximumFee, | ||
}), | ||
]; | ||
default: | ||
return []; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Given a mint address and a list of mint extensions, returns a list of | ||
* instructions that MUST be run _after_ the `initializeMint` instruction | ||
* to properly initialize the given extensions on the mint account. | ||
*/ | ||
export function getPostInitializeInstructionsForMintExtensions( | ||
_mint: Address, | ||
extensions: ExtensionArgs[] | ||
): IInstruction[] { | ||
return extensions.flatMap((extension) => { | ||
switch (extension.__kind) { | ||
default: | ||
return []; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Given a token address, its owner and a list of token extensions, returns a list | ||
* of instructions that MUST be run _after_ the `initializeAccount` instruction | ||
* to properly initialize the given extensions on the token account. | ||
*/ | ||
export function getPostInitializeInstructionsForTokenExtensions( | ||
token: Address, | ||
owner: TransactionSigner, | ||
extensions: ExtensionArgs[] | ||
): IInstruction[] { | ||
return extensions.flatMap((extension) => { | ||
switch (extension.__kind) { | ||
case 'MemoTransfer': | ||
return [ | ||
extension.requireIncomingTransferMemos | ||
? getEnableMemoTransfersInstruction({ owner, token }) | ||
: getDisableMemoTransfersInstruction({ owner, token }), | ||
]; | ||
default: | ||
return []; | ||
} | ||
}); | ||
} |
44 changes: 0 additions & 44 deletions
44
clients/js/src/getInitializeInstructionsForMintExtensions.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './generated'; | ||
|
||
export * from './getInitializeInstructionsForMintExtensions'; | ||
export * from './getInitializeInstructionsForExtensions'; | ||
export * from './getTokenSize'; | ||
export * from './getMintSize'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters