@sudobility/contracts 1.17.28 → 1.17.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-native/src/evm/evm-mailer-client.d.ts +1277 -0
- package/dist/react-native/src/evm/evm-mailer-client.d.ts.map +1 -0
- package/dist/react-native/src/evm/evm-mailer-client.js +968 -0
- package/dist/react-native/src/evm/evm-mailer-client.js.map +1 -0
- package/dist/react-native/src/evm/index.d.ts +4 -0
- package/dist/react-native/src/evm/index.d.ts.map +1 -0
- package/dist/react-native/src/evm/index.js +5 -0
- package/dist/react-native/src/evm/index.js.map +1 -0
- package/dist/react-native/src/react-native/index.d.ts +23 -0
- package/dist/react-native/src/react-native/index.d.ts.map +1 -0
- package/dist/react-native/src/react-native/index.js +23 -0
- package/dist/react-native/src/react-native/index.js.map +1 -0
- package/dist/react-native/src/react-native/polyfills.d.ts +39 -0
- package/dist/react-native/src/react-native/polyfills.d.ts.map +1 -0
- package/dist/react-native/src/react-native/polyfills.js +75 -0
- package/dist/react-native/src/react-native/polyfills.js.map +1 -0
- package/dist/react-native/src/solana/index.d.ts +3 -0
- package/dist/react-native/src/solana/index.d.ts.map +1 -0
- package/dist/react-native/src/solana/index.js +4 -0
- package/dist/react-native/src/solana/index.js.map +1 -0
- package/dist/react-native/src/solana/solana-mailer-client.d.ts +213 -0
- package/dist/react-native/src/solana/solana-mailer-client.d.ts.map +1 -0
- package/dist/react-native/src/solana/solana-mailer-client.js +1055 -0
- package/dist/react-native/src/solana/solana-mailer-client.js.map +1 -0
- package/dist/react-native/src/solana/types.d.ts +29 -0
- package/dist/react-native/src/solana/types.d.ts.map +1 -0
- package/dist/react-native/src/solana/types.js +16 -0
- package/dist/react-native/src/solana/types.js.map +1 -0
- package/dist/react-native/src/unified/index.d.ts +4 -0
- package/dist/react-native/src/unified/index.d.ts.map +1 -0
- package/dist/react-native/src/unified/index.js +4 -0
- package/dist/react-native/src/unified/index.js.map +1 -0
- package/dist/react-native/src/unified/onchain-mailer-client.d.ts +280 -0
- package/dist/react-native/src/unified/onchain-mailer-client.d.ts.map +1 -0
- package/dist/react-native/src/unified/onchain-mailer-client.js +837 -0
- package/dist/react-native/src/unified/onchain-mailer-client.js.map +1 -0
- package/dist/react-native/src/unified/types.d.ts +54 -0
- package/dist/react-native/src/unified/types.d.ts.map +1 -0
- package/dist/react-native/src/unified/types.js +2 -0
- package/dist/react-native/src/unified/types.js.map +1 -0
- package/dist/react-native/src/unified/wallet-detector.d.ts +28 -0
- package/dist/react-native/src/unified/wallet-detector.d.ts.map +1 -0
- package/dist/react-native/src/unified/wallet-detector.js +59 -0
- package/dist/react-native/src/unified/wallet-detector.js.map +1 -0
- package/dist/react-native/src/utils/chain-config.d.ts +75 -0
- package/dist/react-native/src/utils/chain-config.d.ts.map +1 -0
- package/dist/react-native/src/utils/chain-config.js +199 -0
- package/dist/react-native/src/utils/chain-config.js.map +1 -0
- package/dist/react-native/src/utils/currency.d.ts +26 -0
- package/dist/react-native/src/utils/currency.d.ts.map +1 -0
- package/dist/react-native/src/utils/currency.js +31 -0
- package/dist/react-native/src/utils/currency.js.map +1 -0
- package/dist/react-native/src/utils/index.d.ts +4 -0
- package/dist/react-native/src/utils/index.d.ts.map +1 -0
- package/dist/react-native/src/utils/index.js +4 -0
- package/dist/react-native/src/utils/index.js.map +1 -0
- package/dist/react-native/src/utils/validation.d.ts +10 -0
- package/dist/react-native/src/utils/validation.d.ts.map +1 -0
- package/dist/react-native/src/utils/validation.js +96 -0
- package/dist/react-native/src/utils/validation.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/index.d.ts +7 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/IERC1967.d.ts +66 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/IERC1967.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/IERC1967.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/IERC1967.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable.d.ts +26 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.d.ts +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/index.d.ts +4 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/interfaces/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.d.ts +21 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/index.d.ts +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/ERC1967/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/IBeacon.d.ts +26 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/IBeacon.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/IBeacon.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/IBeacon.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/index.d.ts +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/beacon/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/index.d.ts +5 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/proxy/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Address.d.ts +21 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Address.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Address.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Address.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Errors.d.ts +21 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Errors.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Errors.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/Errors.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/index.d.ts +3 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts/utils/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.d.ts +69 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/index.d.ts +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/access/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/index.d.ts +7 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/index.d.ts +3 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.d.ts +37 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.d.ts +74 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/index.d.ts +3 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/proxy/utils/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.d.ts +37 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/index.d.ts +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/contracts-upgradeable/utils/index.js.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/index.d.ts +5 -0
- package/dist/react-native/typechain-types/@openzeppelin/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/@openzeppelin/index.js +2 -0
- package/dist/react-native/typechain-types/@openzeppelin/index.js.map +1 -0
- package/dist/react-native/typechain-types/common.d.ts +51 -0
- package/dist/react-native/typechain-types/common.d.ts.map +1 -0
- package/dist/react-native/typechain-types/common.js +2 -0
- package/dist/react-native/typechain-types/common.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/Mailer.d.ts +845 -0
- package/dist/react-native/typechain-types/contracts/Mailer.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/Mailer.js +2 -0
- package/dist/react-native/typechain-types/contracts/Mailer.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/MockUSDC.d.ts +118 -0
- package/dist/react-native/typechain-types/contracts/MockUSDC.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/MockUSDC.js +2 -0
- package/dist/react-native/typechain-types/contracts/MockUSDC.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/examples/MailerIntegrationExample.d.ts +170 -0
- package/dist/react-native/typechain-types/contracts/examples/MailerIntegrationExample.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/examples/MailerIntegrationExample.js +2 -0
- package/dist/react-native/typechain-types/contracts/examples/MailerIntegrationExample.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/examples/index.d.ts +2 -0
- package/dist/react-native/typechain-types/contracts/examples/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/examples/index.js +2 -0
- package/dist/react-native/typechain-types/contracts/examples/index.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/index.d.ts +7 -0
- package/dist/react-native/typechain-types/contracts/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/index.js +2 -0
- package/dist/react-native/typechain-types/contracts/index.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IERC20.d.ts +70 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IERC20.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IERC20.js +2 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IERC20.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IMailer.d.ts +118 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IMailer.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IMailer.js +2 -0
- package/dist/react-native/typechain-types/contracts/interfaces/IMailer.js.map +1 -0
- package/dist/react-native/typechain-types/contracts/interfaces/index.d.ts +3 -0
- package/dist/react-native/typechain-types/contracts/interfaces/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/contracts/interfaces/index.js +2 -0
- package/dist/react-native/typechain-types/contracts/interfaces/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/index.d.ts +4 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/index.js +7 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1967__factory.d.ts +43 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1967__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1967__factory.js +61 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1967__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable__factory.d.ts +18 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable__factory.js +29 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.d.ts +2 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.js +5 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/index.d.ts +3 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/index.js +6 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/interfaces/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils__factory.d.ts +51 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils__factory.js +74 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/index.d.ts +2 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/index.js +5 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/ERC1967/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/IBeacon__factory.d.ts +18 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/IBeacon__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/IBeacon__factory.js +29 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/IBeacon__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/index.d.ts +2 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/index.js +5 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/beacon/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/index.d.ts +3 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/index.js +6 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/proxy/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Address__factory.d.ts +31 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Address__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Address__factory.js +47 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Address__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Errors__factory.d.ts +51 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Errors__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Errors__factory.js +73 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/Errors__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/index.d.ts +3 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/index.js +6 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts/utils/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable__factory.d.ts +83 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable__factory.js +113 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/index.d.ts +2 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/index.js +5 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/access/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/index.d.ts +4 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/index.js +7 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/index.d.ts +2 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/index.js +5 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable__factory.d.ts +26 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable__factory.js +39 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable__factory.d.ts +106 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable__factory.js +144 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/index.d.ts +3 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/index.js +6 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/proxy/utils/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable__factory.d.ts +26 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable__factory.js +39 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/index.d.ts +2 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/index.js +5 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/contracts-upgradeable/utils/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/index.d.ts +3 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/index.js +6 -0
- package/dist/react-native/typechain-types/factories/@openzeppelin/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/Mailer__factory.d.ts +1086 -0
- package/dist/react-native/typechain-types/factories/contracts/Mailer__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/Mailer__factory.js +1390 -0
- package/dist/react-native/typechain-types/factories/contracts/Mailer__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/MockUSDC__factory.d.ts +193 -0
- package/dist/react-native/typechain-types/factories/contracts/MockUSDC__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/MockUSDC__factory.js +259 -0
- package/dist/react-native/typechain-types/factories/contracts/MockUSDC__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/MailerIntegrationExample__factory.d.ts +209 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/MailerIntegrationExample__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/MailerIntegrationExample__factory.js +274 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/MailerIntegrationExample__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/index.d.ts +2 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/index.js +5 -0
- package/dist/react-native/typechain-types/factories/contracts/examples/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/index.d.ts +5 -0
- package/dist/react-native/typechain-types/factories/contracts/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/index.js +8 -0
- package/dist/react-native/typechain-types/factories/contracts/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IERC20__factory.d.ts +80 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IERC20__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IERC20__factory.js +112 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IERC20__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IMailer__factory.d.ts +130 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IMailer__factory.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IMailer__factory.js +171 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/IMailer__factory.js.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/index.d.ts +3 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/index.js +6 -0
- package/dist/react-native/typechain-types/factories/contracts/interfaces/index.js.map +1 -0
- package/dist/react-native/typechain-types/factories/index.d.ts +3 -0
- package/dist/react-native/typechain-types/factories/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/factories/index.js +6 -0
- package/dist/react-native/typechain-types/factories/index.js.map +1 -0
- package/dist/react-native/typechain-types/index.d.ts +36 -0
- package/dist/react-native/typechain-types/index.d.ts.map +1 -0
- package/dist/react-native/typechain-types/index.js +17 -0
- package/dist/react-native/typechain-types/index.js.map +1 -0
- package/package.json +43 -5
|
@@ -0,0 +1,1055 @@
|
|
|
1
|
+
import { Connection, PublicKey, Transaction, TransactionInstruction, SystemProgram, ComputeBudgetProgram, } from '@solana/web3.js';
|
|
2
|
+
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, createAssociatedTokenAccountInstruction, } from '@solana/spl-token';
|
|
3
|
+
/**
|
|
4
|
+
* Native Solana Program instruction types
|
|
5
|
+
*/
|
|
6
|
+
var InstructionType;
|
|
7
|
+
(function (InstructionType) {
|
|
8
|
+
InstructionType[InstructionType["Initialize"] = 0] = "Initialize";
|
|
9
|
+
InstructionType[InstructionType["Send"] = 1] = "Send";
|
|
10
|
+
InstructionType[InstructionType["SendPrepared"] = 2] = "SendPrepared";
|
|
11
|
+
InstructionType[InstructionType["SendToEmail"] = 3] = "SendToEmail";
|
|
12
|
+
InstructionType[InstructionType["SendPreparedToEmail"] = 4] = "SendPreparedToEmail";
|
|
13
|
+
InstructionType[InstructionType["SendThroughWebhook"] = 5] = "SendThroughWebhook";
|
|
14
|
+
InstructionType[InstructionType["ClaimRecipientShare"] = 6] = "ClaimRecipientShare";
|
|
15
|
+
InstructionType[InstructionType["ClaimOwnerShare"] = 7] = "ClaimOwnerShare";
|
|
16
|
+
InstructionType[InstructionType["SetFee"] = 8] = "SetFee";
|
|
17
|
+
InstructionType[InstructionType["DelegateTo"] = 9] = "DelegateTo";
|
|
18
|
+
InstructionType[InstructionType["RejectDelegation"] = 10] = "RejectDelegation";
|
|
19
|
+
InstructionType[InstructionType["SetDelegationFee"] = 11] = "SetDelegationFee";
|
|
20
|
+
InstructionType[InstructionType["SetCustomFeePercentage"] = 12] = "SetCustomFeePercentage";
|
|
21
|
+
InstructionType[InstructionType["ClearCustomFeePercentage"] = 13] = "ClearCustomFeePercentage";
|
|
22
|
+
InstructionType[InstructionType["Pause"] = 14] = "Pause";
|
|
23
|
+
InstructionType[InstructionType["Unpause"] = 15] = "Unpause";
|
|
24
|
+
InstructionType[InstructionType["DistributeClaimableFunds"] = 16] = "DistributeClaimableFunds";
|
|
25
|
+
InstructionType[InstructionType["ClaimExpiredShares"] = 17] = "ClaimExpiredShares";
|
|
26
|
+
InstructionType[InstructionType["EmergencyUnpause"] = 18] = "EmergencyUnpause";
|
|
27
|
+
InstructionType[InstructionType["SetFeePaused"] = 19] = "SetFeePaused";
|
|
28
|
+
})(InstructionType || (InstructionType = {}));
|
|
29
|
+
const CLAIM_PDA_SEED = Buffer.from('claim');
|
|
30
|
+
const DELEGATION_PDA_SEED = Buffer.from('delegation');
|
|
31
|
+
const DISCOUNT_PDA_SEED = Buffer.from('discount');
|
|
32
|
+
const CLAIM_PERIOD_SECONDS = 60 * 24 * 60 * 60;
|
|
33
|
+
// Instruction data encoding functions
|
|
34
|
+
function encodeInitialize(usdcMint) {
|
|
35
|
+
const data = Buffer.alloc(1 + 32);
|
|
36
|
+
data.writeUInt8(InstructionType.Initialize, 0);
|
|
37
|
+
usdcMint.toBuffer().copy(data, 1);
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
function encodeSend(to, subject, body, revenueShareToReceiver, resolveSenderToName = false) {
|
|
41
|
+
const subjectBytes = Buffer.from(subject, 'utf8');
|
|
42
|
+
const bodyBytes = Buffer.from(body, 'utf8');
|
|
43
|
+
const data = Buffer.alloc(1 + 32 + 4 + subjectBytes.length + 4 + bodyBytes.length + 1 + 1);
|
|
44
|
+
let offset = 0;
|
|
45
|
+
data.writeUInt8(InstructionType.Send, offset);
|
|
46
|
+
offset += 1;
|
|
47
|
+
to.toBuffer().copy(data, offset);
|
|
48
|
+
offset += 32;
|
|
49
|
+
data.writeUInt32LE(subjectBytes.length, offset);
|
|
50
|
+
offset += 4;
|
|
51
|
+
subjectBytes.copy(data, offset);
|
|
52
|
+
offset += subjectBytes.length;
|
|
53
|
+
data.writeUInt32LE(bodyBytes.length, offset);
|
|
54
|
+
offset += 4;
|
|
55
|
+
bodyBytes.copy(data, offset);
|
|
56
|
+
offset += bodyBytes.length;
|
|
57
|
+
data.writeUInt8(revenueShareToReceiver ? 1 : 0, offset);
|
|
58
|
+
offset += 1;
|
|
59
|
+
data.writeUInt8(resolveSenderToName ? 1 : 0, offset);
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
function encodeSendPrepared(to, mailId, revenueShareToReceiver, resolveSenderToName = false) {
|
|
63
|
+
const mailIdBytes = Buffer.from(mailId, 'utf8');
|
|
64
|
+
const data = Buffer.alloc(1 + 32 + 4 + mailIdBytes.length + 1 + 1);
|
|
65
|
+
let offset = 0;
|
|
66
|
+
data.writeUInt8(InstructionType.SendPrepared, offset);
|
|
67
|
+
offset += 1;
|
|
68
|
+
to.toBuffer().copy(data, offset);
|
|
69
|
+
offset += 32;
|
|
70
|
+
data.writeUInt32LE(mailIdBytes.length, offset);
|
|
71
|
+
offset += 4;
|
|
72
|
+
mailIdBytes.copy(data, offset);
|
|
73
|
+
offset += mailIdBytes.length;
|
|
74
|
+
data.writeUInt8(revenueShareToReceiver ? 1 : 0, offset);
|
|
75
|
+
offset += 1;
|
|
76
|
+
data.writeUInt8(resolveSenderToName ? 1 : 0, offset);
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
function encodeSendThroughWebhook(to, webhookId, revenueShareToReceiver, resolveSenderToName = false) {
|
|
80
|
+
const webhookIdBytes = Buffer.from(webhookId, 'utf8');
|
|
81
|
+
const data = Buffer.alloc(1 + 32 + 4 + webhookIdBytes.length + 1 + 1);
|
|
82
|
+
let offset = 0;
|
|
83
|
+
data.writeUInt8(InstructionType.SendThroughWebhook, offset);
|
|
84
|
+
offset += 1;
|
|
85
|
+
to.toBuffer().copy(data, offset);
|
|
86
|
+
offset += 32;
|
|
87
|
+
data.writeUInt32LE(webhookIdBytes.length, offset);
|
|
88
|
+
offset += 4;
|
|
89
|
+
webhookIdBytes.copy(data, offset);
|
|
90
|
+
offset += webhookIdBytes.length;
|
|
91
|
+
data.writeUInt8(revenueShareToReceiver ? 1 : 0, offset);
|
|
92
|
+
offset += 1;
|
|
93
|
+
data.writeUInt8(resolveSenderToName ? 1 : 0, offset);
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
function encodeSendToEmail(toEmail, subject, body) {
|
|
97
|
+
const emailBytes = Buffer.from(toEmail, 'utf8');
|
|
98
|
+
const subjectBytes = Buffer.from(subject, 'utf8');
|
|
99
|
+
const bodyBytes = Buffer.from(body, 'utf8');
|
|
100
|
+
const data = Buffer.alloc(1 + 4 + emailBytes.length + 4 + subjectBytes.length + 4 + bodyBytes.length);
|
|
101
|
+
let offset = 0;
|
|
102
|
+
data.writeUInt8(InstructionType.SendToEmail, offset);
|
|
103
|
+
offset += 1;
|
|
104
|
+
data.writeUInt32LE(emailBytes.length, offset);
|
|
105
|
+
offset += 4;
|
|
106
|
+
emailBytes.copy(data, offset);
|
|
107
|
+
offset += emailBytes.length;
|
|
108
|
+
data.writeUInt32LE(subjectBytes.length, offset);
|
|
109
|
+
offset += 4;
|
|
110
|
+
subjectBytes.copy(data, offset);
|
|
111
|
+
offset += subjectBytes.length;
|
|
112
|
+
data.writeUInt32LE(bodyBytes.length, offset);
|
|
113
|
+
offset += 4;
|
|
114
|
+
bodyBytes.copy(data, offset);
|
|
115
|
+
offset += bodyBytes.length;
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
118
|
+
function encodeSendPreparedToEmail(toEmail, mailId) {
|
|
119
|
+
const emailBytes = Buffer.from(toEmail, 'utf8');
|
|
120
|
+
const mailIdBytes = Buffer.from(mailId, 'utf8');
|
|
121
|
+
const data = Buffer.alloc(1 + 4 + emailBytes.length + 4 + mailIdBytes.length);
|
|
122
|
+
let offset = 0;
|
|
123
|
+
data.writeUInt8(InstructionType.SendPreparedToEmail, offset);
|
|
124
|
+
offset += 1;
|
|
125
|
+
data.writeUInt32LE(emailBytes.length, offset);
|
|
126
|
+
offset += 4;
|
|
127
|
+
emailBytes.copy(data, offset);
|
|
128
|
+
offset += emailBytes.length;
|
|
129
|
+
data.writeUInt32LE(mailIdBytes.length, offset);
|
|
130
|
+
offset += 4;
|
|
131
|
+
mailIdBytes.copy(data, offset);
|
|
132
|
+
offset += mailIdBytes.length;
|
|
133
|
+
return data;
|
|
134
|
+
}
|
|
135
|
+
function encodeSetFee(sendFee) {
|
|
136
|
+
const data = Buffer.alloc(1 + 8);
|
|
137
|
+
data.writeUInt8(InstructionType.SetFee, 0);
|
|
138
|
+
data.writeBigUInt64LE(sendFee, 1);
|
|
139
|
+
return data;
|
|
140
|
+
}
|
|
141
|
+
function encodeSetDelegationFee(delegationFee) {
|
|
142
|
+
const data = Buffer.alloc(1 + 8);
|
|
143
|
+
data.writeUInt8(InstructionType.SetDelegationFee, 0);
|
|
144
|
+
data.writeBigUInt64LE(delegationFee, 1);
|
|
145
|
+
return data;
|
|
146
|
+
}
|
|
147
|
+
function encodeDelegateTo(delegate) {
|
|
148
|
+
const data = Buffer.alloc(1 + 1 + (delegate ? 32 : 0));
|
|
149
|
+
data.writeUInt8(InstructionType.DelegateTo, 0);
|
|
150
|
+
data.writeUInt8(delegate ? 1 : 0, 1);
|
|
151
|
+
if (delegate) {
|
|
152
|
+
delegate.toBuffer().copy(data, 2);
|
|
153
|
+
}
|
|
154
|
+
return data;
|
|
155
|
+
}
|
|
156
|
+
function encodeRejectDelegation() {
|
|
157
|
+
const data = Buffer.alloc(1);
|
|
158
|
+
data.writeUInt8(InstructionType.RejectDelegation, 0);
|
|
159
|
+
return data;
|
|
160
|
+
}
|
|
161
|
+
function encodeSetCustomFeePercentage(account, percentage) {
|
|
162
|
+
if (percentage < 0 || percentage > 100) {
|
|
163
|
+
throw new Error('Percentage must be between 0 and 100');
|
|
164
|
+
}
|
|
165
|
+
const data = Buffer.alloc(1 + 32 + 1);
|
|
166
|
+
data.writeUInt8(InstructionType.SetCustomFeePercentage, 0);
|
|
167
|
+
account.toBuffer().copy(data, 1);
|
|
168
|
+
data.writeUInt8(percentage, 33);
|
|
169
|
+
return data;
|
|
170
|
+
}
|
|
171
|
+
function encodeClearCustomFeePercentage(account) {
|
|
172
|
+
const data = Buffer.alloc(1 + 32);
|
|
173
|
+
data.writeUInt8(InstructionType.ClearCustomFeePercentage, 0);
|
|
174
|
+
account.toBuffer().copy(data, 1);
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
function encodeClaimExpiredShares(recipient) {
|
|
178
|
+
const data = Buffer.alloc(1 + 32);
|
|
179
|
+
data.writeUInt8(InstructionType.ClaimExpiredShares, 0);
|
|
180
|
+
recipient.toBuffer().copy(data, 1);
|
|
181
|
+
return data;
|
|
182
|
+
}
|
|
183
|
+
function encodeDistributeClaimableFunds(recipient) {
|
|
184
|
+
const data = Buffer.alloc(1 + 32);
|
|
185
|
+
data.writeUInt8(InstructionType.DistributeClaimableFunds, 0);
|
|
186
|
+
recipient.toBuffer().copy(data, 1);
|
|
187
|
+
return data;
|
|
188
|
+
}
|
|
189
|
+
function encodeSetFeePaused(feePaused) {
|
|
190
|
+
const data = Buffer.alloc(1 + 1);
|
|
191
|
+
data.writeUInt8(InstructionType.SetFeePaused, 0);
|
|
192
|
+
data.writeUInt8(feePaused ? 1 : 0, 1);
|
|
193
|
+
return data;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Stateless Solana Mailer client.
|
|
197
|
+
* All methods take wallet and chainInfo as parameters.
|
|
198
|
+
* No state is stored in the instance.
|
|
199
|
+
*/
|
|
200
|
+
export class SolanaMailerClient {
|
|
201
|
+
constructor() {
|
|
202
|
+
this.defaultComputeUnitMultiplier = 1.2; // 20% buffer by default
|
|
203
|
+
// Default compute unit limits for common operations
|
|
204
|
+
this.defaultComputeUnits = {
|
|
205
|
+
send: 200000,
|
|
206
|
+
sendPrepared: 150000,
|
|
207
|
+
sendToEmail: 250000,
|
|
208
|
+
claimRevenue: 100000,
|
|
209
|
+
claimOwnerShare: 100000,
|
|
210
|
+
delegateTo: 80000,
|
|
211
|
+
setFees: 60000,
|
|
212
|
+
pause: 50000,
|
|
213
|
+
unpause: 50000,
|
|
214
|
+
initialize: 100000,
|
|
215
|
+
distributeClaimableFunds: 150000,
|
|
216
|
+
};
|
|
217
|
+
// Priority fee recommendations based on network congestion
|
|
218
|
+
this.priorityFeeRecommendations = {
|
|
219
|
+
low: 1000, // 1,000 microLamports - for low priority transactions
|
|
220
|
+
normal: 10000, // 10,000 microLamports - for normal priority
|
|
221
|
+
high: 50000, // 50,000 microLamports - for high priority
|
|
222
|
+
urgent: 100000, // 100,000 microLamports - for urgent transactions
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Create or get connection from wallet/chainInfo
|
|
227
|
+
*/
|
|
228
|
+
async getOrCreateConnection(chainInfo, connection) {
|
|
229
|
+
if (connection) {
|
|
230
|
+
return connection;
|
|
231
|
+
}
|
|
232
|
+
// Build RPC URL from ChainInfo
|
|
233
|
+
let rpcUrl;
|
|
234
|
+
if (chainInfo.alchemyNetwork) {
|
|
235
|
+
rpcUrl = `https://${chainInfo.alchemyNetwork}.g.alchemy.com/v2/demo`;
|
|
236
|
+
}
|
|
237
|
+
else if (chainInfo.ankrNetwork) {
|
|
238
|
+
rpcUrl = `https://rpc.ankr.com/${chainInfo.ankrNetwork}`;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
// Default Solana endpoints
|
|
242
|
+
rpcUrl = chainInfo.isTestNet
|
|
243
|
+
? 'https://api.devnet.solana.com'
|
|
244
|
+
: 'https://api.mainnet-beta.solana.com';
|
|
245
|
+
}
|
|
246
|
+
return new Connection(rpcUrl, 'confirmed');
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get program and state PDAs from chainInfo
|
|
250
|
+
*/
|
|
251
|
+
getProgramAddresses(chainInfo) {
|
|
252
|
+
if (!chainInfo.mailerAddress) {
|
|
253
|
+
throw new Error(`No mailer program deployed on ${chainInfo.name}`);
|
|
254
|
+
}
|
|
255
|
+
const programId = new PublicKey(chainInfo.mailerAddress);
|
|
256
|
+
const [mailerPda, bump] = PublicKey.findProgramAddressSync([Buffer.from('mailer')], programId);
|
|
257
|
+
return {
|
|
258
|
+
programId,
|
|
259
|
+
mailerStatePda: mailerPda,
|
|
260
|
+
mailerBump: bump,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Optimize compute units for a transaction
|
|
265
|
+
*/
|
|
266
|
+
async optimizeComputeUnits(transaction, wallet, connection, options, defaultComputeUnits) {
|
|
267
|
+
// Skip if explicitly disabled
|
|
268
|
+
if (options?.skipComputeUnits) {
|
|
269
|
+
return { transaction };
|
|
270
|
+
}
|
|
271
|
+
let simulatedUnits;
|
|
272
|
+
let computeUnitLimit = options?.computeUnitLimit;
|
|
273
|
+
// Auto-optimize by simulating transaction
|
|
274
|
+
if (options?.autoOptimize && !computeUnitLimit) {
|
|
275
|
+
let retryCount = 0;
|
|
276
|
+
const maxRetries = 2;
|
|
277
|
+
while (retryCount <= maxRetries) {
|
|
278
|
+
try {
|
|
279
|
+
// Set a high limit for simulation
|
|
280
|
+
const simTransaction = new Transaction().add(...transaction.instructions);
|
|
281
|
+
simTransaction.add(ComputeBudgetProgram.setComputeUnitLimit({
|
|
282
|
+
units: 1400000, // Max for simulation
|
|
283
|
+
}));
|
|
284
|
+
simTransaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
285
|
+
simTransaction.feePayer = wallet.publicKey;
|
|
286
|
+
const simulation = await connection.simulateTransaction(simTransaction);
|
|
287
|
+
if (simulation.value.err === null && simulation.value.unitsConsumed) {
|
|
288
|
+
simulatedUnits = simulation.value.unitsConsumed;
|
|
289
|
+
const multiplier = options.computeUnitMultiplier ?? this.defaultComputeUnitMultiplier;
|
|
290
|
+
let estimatedLimit = Math.ceil(simulatedUnits * multiplier);
|
|
291
|
+
// If we have a default and the estimate is suspiciously low, use the default
|
|
292
|
+
// This handles cases where simulation returns incorrect low values
|
|
293
|
+
if (defaultComputeUnits && estimatedLimit < defaultComputeUnits) {
|
|
294
|
+
console.warn(`Estimated compute units ${estimatedLimit} is below default ${defaultComputeUnits}, using default`);
|
|
295
|
+
estimatedLimit = defaultComputeUnits;
|
|
296
|
+
}
|
|
297
|
+
computeUnitLimit = Math.min(estimatedLimit, 1400000);
|
|
298
|
+
break; // Success
|
|
299
|
+
}
|
|
300
|
+
else if (simulation.value.err) {
|
|
301
|
+
throw new Error(`Simulation failed: ${JSON.stringify(simulation.value.err)}`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
retryCount++;
|
|
306
|
+
if (retryCount > maxRetries) {
|
|
307
|
+
console.warn(`Failed to auto-optimize compute units after ${maxRetries} retries:`, error);
|
|
308
|
+
// Use default if provided
|
|
309
|
+
if (defaultComputeUnits) {
|
|
310
|
+
computeUnitLimit = defaultComputeUnits;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
// Wait before retry
|
|
315
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * retryCount));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// Use default compute units if no limit is set yet
|
|
321
|
+
if (!computeUnitLimit && defaultComputeUnits) {
|
|
322
|
+
computeUnitLimit = defaultComputeUnits;
|
|
323
|
+
}
|
|
324
|
+
// Apply compute budget instructions
|
|
325
|
+
const optimizedTx = new Transaction();
|
|
326
|
+
// Add compute unit limit if specified
|
|
327
|
+
if (computeUnitLimit) {
|
|
328
|
+
optimizedTx.add(ComputeBudgetProgram.setComputeUnitLimit({
|
|
329
|
+
units: computeUnitLimit,
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
// Add priority fee if specified (or use recommended normal priority)
|
|
333
|
+
const priorityFee = options?.computeUnitPrice ??
|
|
334
|
+
(options?.autoOptimize ? this.priorityFeeRecommendations.normal : undefined);
|
|
335
|
+
if (priorityFee) {
|
|
336
|
+
optimizedTx.add(ComputeBudgetProgram.setComputeUnitPrice({
|
|
337
|
+
microLamports: priorityFee,
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
// Add original instructions
|
|
341
|
+
optimizedTx.add(...transaction.instructions);
|
|
342
|
+
return {
|
|
343
|
+
transaction: optimizedTx,
|
|
344
|
+
simulatedUnits,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Send and confirm transaction
|
|
349
|
+
*/
|
|
350
|
+
async sendTransaction(transaction, wallet, connection, options, computeOptions, defaultComputeUnits) {
|
|
351
|
+
// Optimize compute units
|
|
352
|
+
const { transaction: optimizedTx, simulatedUnits } = await this.optimizeComputeUnits(transaction, wallet, connection, computeOptions, defaultComputeUnits);
|
|
353
|
+
// Get latest blockhash
|
|
354
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
355
|
+
optimizedTx.recentBlockhash = blockhash;
|
|
356
|
+
optimizedTx.feePayer = wallet.publicKey;
|
|
357
|
+
// Sign transaction
|
|
358
|
+
const signed = await wallet.signTransaction(optimizedTx);
|
|
359
|
+
// Send and confirm
|
|
360
|
+
const signature = await connection.sendRawTransaction(signed.serialize(), {
|
|
361
|
+
skipPreflight: options?.skipPreflight ?? false,
|
|
362
|
+
preflightCommitment: options?.preflightCommitment ?? 'confirmed',
|
|
363
|
+
});
|
|
364
|
+
await connection.confirmTransaction(signature, options?.commitment ?? 'confirmed');
|
|
365
|
+
return {
|
|
366
|
+
signature,
|
|
367
|
+
transactionHash: signature,
|
|
368
|
+
simulatedUnits,
|
|
369
|
+
computeUnitLimit: computeOptions?.computeUnitLimit,
|
|
370
|
+
computeUnitPrice: computeOptions?.computeUnitPrice,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Initialize the mailer program (owner only)
|
|
375
|
+
*/
|
|
376
|
+
async initialize(connectedWallet, chainInfo, computeOptions) {
|
|
377
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
378
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
379
|
+
if (!chainInfo.usdcAddress) {
|
|
380
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
381
|
+
}
|
|
382
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
383
|
+
const instruction = new TransactionInstruction({
|
|
384
|
+
programId,
|
|
385
|
+
keys: [
|
|
386
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
387
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
388
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
389
|
+
],
|
|
390
|
+
data: encodeInitialize(usdcMint),
|
|
391
|
+
});
|
|
392
|
+
const transaction = new Transaction().add(instruction);
|
|
393
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Send a message with optional revenue sharing
|
|
397
|
+
*/
|
|
398
|
+
async send(connectedWallet, chainInfo, to, subject, body, revenueShareToReceiver, resolveSenderToName = false, computeOptions) {
|
|
399
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
400
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
401
|
+
if (!chainInfo.usdcAddress) {
|
|
402
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
403
|
+
}
|
|
404
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
405
|
+
const toPubkey = typeof to === 'string' ? new PublicKey(to) : to;
|
|
406
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
407
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
408
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
409
|
+
const [recipientClaimPda] = PublicKey.findProgramAddressSync([CLAIM_PDA_SEED, toPubkey.toBuffer()], programId);
|
|
410
|
+
const keys = [
|
|
411
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
412
|
+
{ pubkey: recipientClaimPda, isSigner: false, isWritable: true },
|
|
413
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
414
|
+
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
415
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
416
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
417
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
418
|
+
{ pubkey: discountPda, isSigner: false, isWritable: false },
|
|
419
|
+
];
|
|
420
|
+
const instruction = new TransactionInstruction({
|
|
421
|
+
programId,
|
|
422
|
+
keys,
|
|
423
|
+
data: encodeSend(toPubkey, subject, body, revenueShareToReceiver, resolveSenderToName),
|
|
424
|
+
});
|
|
425
|
+
const transaction = new Transaction().add(instruction);
|
|
426
|
+
// Check if mailer token account exists, create if not
|
|
427
|
+
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
428
|
+
if (!accountInfo) {
|
|
429
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
430
|
+
}
|
|
431
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Send a prepared message
|
|
435
|
+
*/
|
|
436
|
+
async sendPrepared(connectedWallet, chainInfo, to, mailId, revenueShareToReceiver, resolveSenderToName = false, computeOptions) {
|
|
437
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
438
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
439
|
+
if (!chainInfo.usdcAddress) {
|
|
440
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
441
|
+
}
|
|
442
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
443
|
+
const toPubkey = typeof to === 'string' ? new PublicKey(to) : to;
|
|
444
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
445
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
446
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
447
|
+
const [recipientClaimPda] = PublicKey.findProgramAddressSync([CLAIM_PDA_SEED, toPubkey.toBuffer()], programId);
|
|
448
|
+
const keys = [
|
|
449
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
450
|
+
{ pubkey: recipientClaimPda, isSigner: false, isWritable: true },
|
|
451
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
452
|
+
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
453
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
454
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
455
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
456
|
+
{ pubkey: discountPda, isSigner: false, isWritable: false },
|
|
457
|
+
];
|
|
458
|
+
const instruction = new TransactionInstruction({
|
|
459
|
+
programId,
|
|
460
|
+
keys,
|
|
461
|
+
data: encodeSendPrepared(toPubkey, mailId, revenueShareToReceiver, resolveSenderToName),
|
|
462
|
+
});
|
|
463
|
+
const transaction = new Transaction().add(instruction);
|
|
464
|
+
// Check if mailer token account exists, create if not
|
|
465
|
+
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
466
|
+
if (!accountInfo) {
|
|
467
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
468
|
+
}
|
|
469
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Send through webhook
|
|
473
|
+
*/
|
|
474
|
+
async sendThroughWebhook(connectedWallet, chainInfo, to, webhookId, revenueShareToReceiver, resolveSenderToName = false, computeOptions) {
|
|
475
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
476
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
477
|
+
if (!chainInfo.usdcAddress) {
|
|
478
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
479
|
+
}
|
|
480
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
481
|
+
const toPubkey = typeof to === 'string' ? new PublicKey(to) : to;
|
|
482
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
483
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
484
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
485
|
+
const [recipientClaimPda] = PublicKey.findProgramAddressSync([CLAIM_PDA_SEED, toPubkey.toBuffer()], programId);
|
|
486
|
+
const keys = [
|
|
487
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
488
|
+
{ pubkey: recipientClaimPda, isSigner: false, isWritable: true },
|
|
489
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
490
|
+
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
491
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
492
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
493
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
494
|
+
{ pubkey: discountPda, isSigner: false, isWritable: false },
|
|
495
|
+
];
|
|
496
|
+
const instruction = new TransactionInstruction({
|
|
497
|
+
programId,
|
|
498
|
+
keys,
|
|
499
|
+
data: encodeSendThroughWebhook(toPubkey, webhookId, revenueShareToReceiver, resolveSenderToName),
|
|
500
|
+
});
|
|
501
|
+
const transaction = new Transaction().add(instruction);
|
|
502
|
+
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
503
|
+
if (!accountInfo) {
|
|
504
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
505
|
+
}
|
|
506
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Send to email address
|
|
510
|
+
*/
|
|
511
|
+
async sendToEmail(emailHash, subject, body, _payer, _revenueShareToReceiver, connectedWallet, chainInfo, computeOptions) {
|
|
512
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
513
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
514
|
+
if (!chainInfo.usdcAddress) {
|
|
515
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
516
|
+
}
|
|
517
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
518
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
519
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
520
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
521
|
+
const keys = [
|
|
522
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
523
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
524
|
+
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
525
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
526
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
527
|
+
{ pubkey: discountPda, isSigner: false, isWritable: false },
|
|
528
|
+
];
|
|
529
|
+
const instruction = new TransactionInstruction({
|
|
530
|
+
programId,
|
|
531
|
+
keys,
|
|
532
|
+
data: encodeSendToEmail(emailHash, subject, body),
|
|
533
|
+
});
|
|
534
|
+
const transaction = new Transaction().add(instruction);
|
|
535
|
+
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
536
|
+
if (!accountInfo) {
|
|
537
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
538
|
+
}
|
|
539
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Send prepared to email address
|
|
543
|
+
*/
|
|
544
|
+
async sendPreparedToEmail(emailHash, mailId, _payer, _revenueShareToReceiver, connectedWallet, chainInfo, computeOptions) {
|
|
545
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
546
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
547
|
+
if (!chainInfo.usdcAddress) {
|
|
548
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
549
|
+
}
|
|
550
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
551
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
552
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
553
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
554
|
+
const keys = [
|
|
555
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
556
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
557
|
+
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
558
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
559
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
560
|
+
{ pubkey: discountPda, isSigner: false, isWritable: false },
|
|
561
|
+
];
|
|
562
|
+
const instruction = new TransactionInstruction({
|
|
563
|
+
programId,
|
|
564
|
+
keys,
|
|
565
|
+
data: encodeSendPreparedToEmail(emailHash, mailId),
|
|
566
|
+
});
|
|
567
|
+
const transaction = new Transaction().add(instruction);
|
|
568
|
+
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
569
|
+
if (!accountInfo) {
|
|
570
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
571
|
+
}
|
|
572
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Claim recipient share
|
|
576
|
+
*/
|
|
577
|
+
async claimRecipientShare(connectedWallet, chainInfo, computeOptions) {
|
|
578
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
579
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
580
|
+
if (!chainInfo.usdcAddress) {
|
|
581
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
582
|
+
}
|
|
583
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
584
|
+
const recipientTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
585
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
586
|
+
const [recipientClaimPda] = PublicKey.findProgramAddressSync([CLAIM_PDA_SEED, connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
587
|
+
const keys = [
|
|
588
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
589
|
+
{ pubkey: recipientClaimPda, isSigner: false, isWritable: true },
|
|
590
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
591
|
+
{ pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
|
|
592
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
593
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
594
|
+
];
|
|
595
|
+
const instruction = new TransactionInstruction({
|
|
596
|
+
programId,
|
|
597
|
+
keys,
|
|
598
|
+
data: Buffer.from([InstructionType.ClaimRecipientShare]),
|
|
599
|
+
});
|
|
600
|
+
const transaction = new Transaction().add(instruction);
|
|
601
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Claim owner share (owner only)
|
|
605
|
+
*/
|
|
606
|
+
async claimOwnerShare(connectedWallet, chainInfo, computeOptions) {
|
|
607
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
608
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
609
|
+
if (!chainInfo.usdcAddress) {
|
|
610
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
611
|
+
}
|
|
612
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
613
|
+
const ownerTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
614
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
615
|
+
const keys = [
|
|
616
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
617
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
618
|
+
{ pubkey: ownerTokenAccount, isSigner: false, isWritable: true },
|
|
619
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
620
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
621
|
+
];
|
|
622
|
+
const instruction = new TransactionInstruction({
|
|
623
|
+
programId,
|
|
624
|
+
keys,
|
|
625
|
+
data: Buffer.from([InstructionType.ClaimOwnerShare]),
|
|
626
|
+
});
|
|
627
|
+
const transaction = new Transaction().add(instruction);
|
|
628
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Claim expired shares (owner only)
|
|
632
|
+
*/
|
|
633
|
+
async claimExpiredShares(connectedWallet, chainInfo, recipient, computeOptions) {
|
|
634
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
635
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
636
|
+
const recipientPubkey = typeof recipient === 'string' ? new PublicKey(recipient) : recipient;
|
|
637
|
+
const [recipientClaimPda] = PublicKey.findProgramAddressSync([CLAIM_PDA_SEED, recipientPubkey.toBuffer()], programId);
|
|
638
|
+
const keys = [
|
|
639
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
640
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
641
|
+
{ pubkey: recipientClaimPda, isSigner: false, isWritable: true },
|
|
642
|
+
];
|
|
643
|
+
const instruction = new TransactionInstruction({
|
|
644
|
+
programId,
|
|
645
|
+
keys,
|
|
646
|
+
data: encodeClaimExpiredShares(recipientPubkey),
|
|
647
|
+
});
|
|
648
|
+
const transaction = new Transaction().add(instruction);
|
|
649
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Delegate to another address
|
|
653
|
+
*/
|
|
654
|
+
async delegateTo(connectedWallet, chainInfo, delegate, computeOptions) {
|
|
655
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
656
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
657
|
+
if (!chainInfo.usdcAddress) {
|
|
658
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
659
|
+
}
|
|
660
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
661
|
+
const delegatePubkey = delegate
|
|
662
|
+
? (typeof delegate === 'string' ? new PublicKey(delegate) : delegate)
|
|
663
|
+
: null;
|
|
664
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
665
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
666
|
+
const [delegationPda] = PublicKey.findProgramAddressSync([DELEGATION_PDA_SEED, connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
667
|
+
const keys = [
|
|
668
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
669
|
+
{ pubkey: delegationPda, isSigner: false, isWritable: true },
|
|
670
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
671
|
+
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
672
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
673
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
674
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
675
|
+
];
|
|
676
|
+
const instruction = new TransactionInstruction({
|
|
677
|
+
programId,
|
|
678
|
+
keys,
|
|
679
|
+
data: encodeDelegateTo(delegatePubkey),
|
|
680
|
+
});
|
|
681
|
+
const transaction = new Transaction().add(instruction);
|
|
682
|
+
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
683
|
+
if (!accountInfo) {
|
|
684
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
685
|
+
}
|
|
686
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Reject delegation
|
|
690
|
+
*/
|
|
691
|
+
async rejectDelegation(connectedWallet, chainInfo, delegatingAddress, computeOptions) {
|
|
692
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
693
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
694
|
+
const delegatorPubkey = typeof delegatingAddress === 'string' ? new PublicKey(delegatingAddress) : delegatingAddress;
|
|
695
|
+
const [delegationPda] = PublicKey.findProgramAddressSync([DELEGATION_PDA_SEED, delegatorPubkey.toBuffer()], programId);
|
|
696
|
+
const keys = [
|
|
697
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
698
|
+
{ pubkey: delegationPda, isSigner: false, isWritable: true },
|
|
699
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: false },
|
|
700
|
+
];
|
|
701
|
+
const instruction = new TransactionInstruction({
|
|
702
|
+
programId,
|
|
703
|
+
keys,
|
|
704
|
+
data: encodeRejectDelegation(),
|
|
705
|
+
});
|
|
706
|
+
const transaction = new Transaction().add(instruction);
|
|
707
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Set fees (owner only)
|
|
711
|
+
*/
|
|
712
|
+
async setFees(connectedWallet, chainInfo, sendFee, delegationFee, computeOptions) {
|
|
713
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
714
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
715
|
+
const ownerKey = connectedWallet.wallet.publicKey;
|
|
716
|
+
const setSendFeeIx = new TransactionInstruction({
|
|
717
|
+
programId,
|
|
718
|
+
keys: [
|
|
719
|
+
{ pubkey: ownerKey, isSigner: true, isWritable: false },
|
|
720
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
721
|
+
],
|
|
722
|
+
data: encodeSetFee(BigInt(sendFee)),
|
|
723
|
+
});
|
|
724
|
+
const setDelegationFeeIx = new TransactionInstruction({
|
|
725
|
+
programId,
|
|
726
|
+
keys: [
|
|
727
|
+
{ pubkey: ownerKey, isSigner: true, isWritable: false },
|
|
728
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
729
|
+
],
|
|
730
|
+
data: encodeSetDelegationFee(BigInt(delegationFee)),
|
|
731
|
+
});
|
|
732
|
+
const transaction = new Transaction().add(setSendFeeIx, setDelegationFeeIx);
|
|
733
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Set custom fee percentage
|
|
737
|
+
*/
|
|
738
|
+
async setCustomFeePercentage(account, percentage, connectedWallet, chainInfo, computeOptions) {
|
|
739
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
740
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
741
|
+
const accountPubkey = typeof account === 'string' ? new PublicKey(account) : account;
|
|
742
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, accountPubkey.toBuffer()], programId);
|
|
743
|
+
const ownerKey = connectedWallet.wallet.publicKey;
|
|
744
|
+
const keys = [
|
|
745
|
+
{ pubkey: ownerKey, isSigner: true, isWritable: false },
|
|
746
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: false },
|
|
747
|
+
{ pubkey: discountPda, isSigner: false, isWritable: true },
|
|
748
|
+
{ pubkey: accountPubkey, isSigner: false, isWritable: false },
|
|
749
|
+
{ pubkey: ownerKey, isSigner: true, isWritable: true },
|
|
750
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
751
|
+
];
|
|
752
|
+
const instruction = new TransactionInstruction({
|
|
753
|
+
programId,
|
|
754
|
+
keys,
|
|
755
|
+
data: encodeSetCustomFeePercentage(accountPubkey, percentage),
|
|
756
|
+
});
|
|
757
|
+
const transaction = new Transaction().add(instruction);
|
|
758
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Clear custom fee percentage
|
|
762
|
+
*/
|
|
763
|
+
async clearCustomFeePercentage(account, connectedWallet, chainInfo, computeOptions) {
|
|
764
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
765
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
766
|
+
const accountPubkey = typeof account === 'string' ? new PublicKey(account) : account;
|
|
767
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, accountPubkey.toBuffer()], programId);
|
|
768
|
+
const keys = [
|
|
769
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
770
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: false },
|
|
771
|
+
{ pubkey: discountPda, isSigner: false, isWritable: true },
|
|
772
|
+
];
|
|
773
|
+
const instruction = new TransactionInstruction({
|
|
774
|
+
programId,
|
|
775
|
+
keys,
|
|
776
|
+
data: encodeClearCustomFeePercentage(accountPubkey),
|
|
777
|
+
});
|
|
778
|
+
const transaction = new Transaction().add(instruction);
|
|
779
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Pause the program (owner only)
|
|
783
|
+
*/
|
|
784
|
+
async pause(connectedWallet, chainInfo, computeOptions) {
|
|
785
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
786
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
787
|
+
if (!chainInfo.usdcAddress) {
|
|
788
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
789
|
+
}
|
|
790
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
791
|
+
const ownerTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
792
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
793
|
+
const transaction = new Transaction();
|
|
794
|
+
const mailerTokenInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
795
|
+
if (!mailerTokenInfo) {
|
|
796
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
797
|
+
}
|
|
798
|
+
const ownerTokenInfo = await connection.getAccountInfo(ownerTokenAccount);
|
|
799
|
+
if (!ownerTokenInfo) {
|
|
800
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, ownerTokenAccount, connectedWallet.wallet.publicKey, usdcMint));
|
|
801
|
+
}
|
|
802
|
+
const keys = [
|
|
803
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
804
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
805
|
+
{ pubkey: ownerTokenAccount, isSigner: false, isWritable: true },
|
|
806
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
807
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
808
|
+
];
|
|
809
|
+
transaction.add(new TransactionInstruction({
|
|
810
|
+
programId,
|
|
811
|
+
keys,
|
|
812
|
+
data: Buffer.from([InstructionType.Pause]),
|
|
813
|
+
}));
|
|
814
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Unpause the program (owner only)
|
|
818
|
+
*/
|
|
819
|
+
async unpause(connectedWallet, chainInfo, computeOptions) {
|
|
820
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
821
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
822
|
+
const keys = [
|
|
823
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
824
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
825
|
+
];
|
|
826
|
+
const instruction = new TransactionInstruction({
|
|
827
|
+
programId,
|
|
828
|
+
keys,
|
|
829
|
+
data: Buffer.from([InstructionType.Unpause]),
|
|
830
|
+
});
|
|
831
|
+
const transaction = new Transaction().add(instruction);
|
|
832
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Emergency unpause (owner only)
|
|
836
|
+
*/
|
|
837
|
+
async emergencyUnpause(connectedWallet, chainInfo, computeOptions) {
|
|
838
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
839
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
840
|
+
const keys = [
|
|
841
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
842
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
843
|
+
];
|
|
844
|
+
const instruction = new TransactionInstruction({
|
|
845
|
+
programId,
|
|
846
|
+
keys,
|
|
847
|
+
data: Buffer.from([InstructionType.EmergencyUnpause]),
|
|
848
|
+
});
|
|
849
|
+
const transaction = new Transaction().add(instruction);
|
|
850
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Set fee paused state (owner only)
|
|
854
|
+
*/
|
|
855
|
+
async setFeePaused(feePaused, connectedWallet, chainInfo, computeOptions) {
|
|
856
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
857
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
858
|
+
const keys = [
|
|
859
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
860
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
861
|
+
];
|
|
862
|
+
const instruction = new TransactionInstruction({
|
|
863
|
+
programId,
|
|
864
|
+
keys,
|
|
865
|
+
data: encodeSetFeePaused(feePaused),
|
|
866
|
+
});
|
|
867
|
+
const transaction = new Transaction().add(instruction);
|
|
868
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Distribute claimable funds when paused
|
|
872
|
+
*/
|
|
873
|
+
async distributeClaimableFunds(connectedWallet, chainInfo, recipients, computeOptions) {
|
|
874
|
+
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
875
|
+
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
876
|
+
if (!chainInfo.usdcAddress) {
|
|
877
|
+
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
878
|
+
}
|
|
879
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
880
|
+
const recipientPubkeys = recipients.map(r => typeof r === 'string' ? new PublicKey(r) : r);
|
|
881
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
882
|
+
const transaction = new Transaction();
|
|
883
|
+
const mailerTokenInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
884
|
+
if (!mailerTokenInfo) {
|
|
885
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
886
|
+
}
|
|
887
|
+
for (const recipient of recipientPubkeys) {
|
|
888
|
+
const [recipientClaimPda] = PublicKey.findProgramAddressSync([CLAIM_PDA_SEED, recipient.toBuffer()], programId);
|
|
889
|
+
const recipientTokenAccount = getAssociatedTokenAddressSync(usdcMint, recipient, false, TOKEN_PROGRAM_ID);
|
|
890
|
+
const recipientTokenInfo = await connection.getAccountInfo(recipientTokenAccount);
|
|
891
|
+
if (!recipientTokenInfo) {
|
|
892
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, recipientTokenAccount, recipient, usdcMint));
|
|
893
|
+
}
|
|
894
|
+
transaction.add(new TransactionInstruction({
|
|
895
|
+
programId,
|
|
896
|
+
keys: [
|
|
897
|
+
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
898
|
+
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
899
|
+
{ pubkey: recipientClaimPda, isSigner: false, isWritable: true },
|
|
900
|
+
{ pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
|
|
901
|
+
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
902
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
903
|
+
],
|
|
904
|
+
data: encodeDistributeClaimableFunds(recipient),
|
|
905
|
+
}));
|
|
906
|
+
}
|
|
907
|
+
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
908
|
+
}
|
|
909
|
+
// ============= Read Methods =============
|
|
910
|
+
/**
|
|
911
|
+
* Get fees configuration
|
|
912
|
+
*/
|
|
913
|
+
async getFees(chainInfo, connection) {
|
|
914
|
+
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
915
|
+
const { mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
916
|
+
const accountInfo = await conn.getAccountInfo(mailerStatePda);
|
|
917
|
+
if (!accountInfo || !accountInfo.data) {
|
|
918
|
+
throw new Error('Mailer not initialized');
|
|
919
|
+
}
|
|
920
|
+
// Parse the state data
|
|
921
|
+
const data = accountInfo.data;
|
|
922
|
+
const sendFee = data.readBigUInt64LE(8 + 32 + 32); // After discriminator + owner + mint
|
|
923
|
+
const delegationFee = data.readBigUInt64LE(8 + 32 + 32 + 8);
|
|
924
|
+
return {
|
|
925
|
+
sendFee,
|
|
926
|
+
delegationFee,
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Get send fee only
|
|
931
|
+
*/
|
|
932
|
+
async getSendFee(chainInfo, connection) {
|
|
933
|
+
const fees = await this.getFees(chainInfo, connection);
|
|
934
|
+
return fees.sendFee;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Get delegation fee only
|
|
938
|
+
*/
|
|
939
|
+
async getDelegationFee(chainInfo, connection) {
|
|
940
|
+
const fees = await this.getFees(chainInfo, connection);
|
|
941
|
+
return fees.delegationFee;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Get recipient claimable info
|
|
945
|
+
*/
|
|
946
|
+
async getRecipientClaimable(recipient, chainInfo, connection) {
|
|
947
|
+
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
948
|
+
const { programId } = this.getProgramAddresses(chainInfo);
|
|
949
|
+
const recipientPubkey = typeof recipient === 'string' ? new PublicKey(recipient) : recipient;
|
|
950
|
+
const [recipientClaimPda] = PublicKey.findProgramAddressSync([CLAIM_PDA_SEED, recipientPubkey.toBuffer()], programId);
|
|
951
|
+
const accountInfo = await conn.getAccountInfo(recipientClaimPda);
|
|
952
|
+
if (!accountInfo || !accountInfo.data) {
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
// Parse the recipient info data
|
|
956
|
+
const data = accountInfo.data;
|
|
957
|
+
const amount = data.readBigUInt64LE(8 + 32); // discriminator + recipient
|
|
958
|
+
const timestamp = Number(data.readBigInt64LE(8 + 32 + 8)); // after amount
|
|
959
|
+
const expiresAt = timestamp + CLAIM_PERIOD_SECONDS;
|
|
960
|
+
const now = Math.floor(Date.now() / 1000);
|
|
961
|
+
const isExpired = timestamp > 0 && now > expiresAt;
|
|
962
|
+
return {
|
|
963
|
+
amount: Number(amount),
|
|
964
|
+
timestamp,
|
|
965
|
+
expiresAt,
|
|
966
|
+
recipient: recipient instanceof PublicKey ? recipient.toBase58() : recipient,
|
|
967
|
+
isExpired,
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Get owner claimable amount
|
|
972
|
+
*/
|
|
973
|
+
async getOwnerClaimable(chainInfo, connection) {
|
|
974
|
+
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
975
|
+
const { mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
976
|
+
const accountInfo = await conn.getAccountInfo(mailerStatePda);
|
|
977
|
+
if (!accountInfo || !accountInfo.data) {
|
|
978
|
+
throw new Error('Mailer not initialized');
|
|
979
|
+
}
|
|
980
|
+
// Parse the state data
|
|
981
|
+
const data = accountInfo.data;
|
|
982
|
+
const ownerClaimable = data.readBigUInt64LE(8 + 32 + 32 + 8 + 8); // After discriminator + owner + mint + sendFee + delegationFee
|
|
983
|
+
return Number(ownerClaimable);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Get delegation for an address
|
|
987
|
+
*/
|
|
988
|
+
async getDelegation(address, chainInfo, connection) {
|
|
989
|
+
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
990
|
+
const { programId } = this.getProgramAddresses(chainInfo);
|
|
991
|
+
const addressPubkey = typeof address === 'string' ? new PublicKey(address) : address;
|
|
992
|
+
const [delegationPda] = PublicKey.findProgramAddressSync([DELEGATION_PDA_SEED, addressPubkey.toBuffer()], programId);
|
|
993
|
+
const accountInfo = await conn.getAccountInfo(delegationPda);
|
|
994
|
+
if (!accountInfo || !accountInfo.data) {
|
|
995
|
+
return null;
|
|
996
|
+
}
|
|
997
|
+
// Parse the delegatingAddress info data
|
|
998
|
+
const data = accountInfo.data;
|
|
999
|
+
const hasDelegate = data.readUInt8(8 + 32) === 1; // After discriminator + delegator
|
|
1000
|
+
if (!hasDelegate) {
|
|
1001
|
+
return null;
|
|
1002
|
+
}
|
|
1003
|
+
// Read delegate pubkey
|
|
1004
|
+
const delegateBytes = data.slice(8 + 32 + 1, 8 + 32 + 1 + 32); // 32 bytes for pubkey
|
|
1005
|
+
return new PublicKey(delegateBytes);
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Get custom fee percentage for an account
|
|
1009
|
+
*/
|
|
1010
|
+
async getCustomFeePercentage(account, chainInfo, connection) {
|
|
1011
|
+
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
1012
|
+
const { programId } = this.getProgramAddresses(chainInfo);
|
|
1013
|
+
const accountPubkey = typeof account === 'string' ? new PublicKey(account) : account;
|
|
1014
|
+
const [discountPda] = PublicKey.findProgramAddressSync([DISCOUNT_PDA_SEED, accountPubkey.toBuffer()], programId);
|
|
1015
|
+
const accountInfo = await conn.getAccountInfo(discountPda);
|
|
1016
|
+
if (!accountInfo || !accountInfo.data) {
|
|
1017
|
+
return 100; // Default to 100% if no custom fee set
|
|
1018
|
+
}
|
|
1019
|
+
// Parse the custom fee data
|
|
1020
|
+
const data = accountInfo.data;
|
|
1021
|
+
const discount = data.readUInt8(8 + 32); // After discriminator + account pubkey
|
|
1022
|
+
return 100 - discount;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Check if the program is paused
|
|
1026
|
+
*/
|
|
1027
|
+
async isPaused(chainInfo, connection) {
|
|
1028
|
+
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
1029
|
+
const { mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
1030
|
+
const accountInfo = await conn.getAccountInfo(mailerStatePda);
|
|
1031
|
+
if (!accountInfo || !accountInfo.data) {
|
|
1032
|
+
throw new Error('Mailer not initialized');
|
|
1033
|
+
}
|
|
1034
|
+
// Parse the state data
|
|
1035
|
+
const data = accountInfo.data;
|
|
1036
|
+
const paused = data.readUInt8(8 + 32 + 32 + 8 + 8 + 8); // After all state fields up to owner_claimable
|
|
1037
|
+
return paused === 1;
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Get the contract owner
|
|
1041
|
+
*/
|
|
1042
|
+
async getOwner(chainInfo, connection) {
|
|
1043
|
+
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
1044
|
+
const { mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
1045
|
+
const accountInfo = await conn.getAccountInfo(mailerStatePda);
|
|
1046
|
+
if (!accountInfo || !accountInfo.data) {
|
|
1047
|
+
throw new Error('Mailer not initialized');
|
|
1048
|
+
}
|
|
1049
|
+
// Parse the state data
|
|
1050
|
+
const data = accountInfo.data;
|
|
1051
|
+
const ownerBytes = data.slice(8, 40); // After discriminator(8)
|
|
1052
|
+
return new PublicKey(ownerBytes);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
//# sourceMappingURL=solana-mailer-client.js.map
|