@debridge-finance/solana-utils 5.4.0 → 5.4.1
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/LICENSE +100 -100
- package/dist/browser/index.js +1320 -1430
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/accounts.js +3 -3
- package/dist/cjs/spl.js +38 -3
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/accounts.js +3 -3
- package/dist/esm/spl.js +39 -3
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/accounts.d.ts +1 -1
- package/dist/types/spl.d.ts.map +1 -1
- package/package.json +84 -83
package/dist/browser/index.js
CHANGED
|
@@ -7434,24 +7434,24 @@ var memoize = microMemoize.exports;
|
|
|
7434
7434
|
|
|
7435
7435
|
const TOKEN_2022_PROGRAM_ID = new PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
7436
7436
|
const TOKEN_METADATA_PROGRAM_ID = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
7437
|
-
const TOKEN_PROGRAM_ID = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
7437
|
+
const TOKEN_PROGRAM_ID$1 = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
7438
7438
|
const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
7439
7439
|
const WRAPPED_SOL_MINT = new PublicKey("So11111111111111111111111111111111111111112");
|
|
7440
|
-
function findAssociatedTokenAddress(wallet, tokenMint, tokenProgramId = TOKEN_PROGRAM_ID, associatedTokenProramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
7440
|
+
function findAssociatedTokenAddress(wallet, tokenMint, tokenProgramId = TOKEN_PROGRAM_ID$1, associatedTokenProramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
7441
7441
|
return PublicKey.findProgramAddressSync([wallet.toBytes(), tokenProgramId.toBytes(), tokenMint.toBytes()], associatedTokenProramId);
|
|
7442
7442
|
}
|
|
7443
7443
|
/**
|
|
7444
7444
|
* @deprecated same as findAssociatedTokenAddress
|
|
7445
7445
|
*/
|
|
7446
|
-
function findAssociatedTokenAddressSync(wallet, tokenMint, tokenProgramId = TOKEN_PROGRAM_ID, associatedTokenProramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
7446
|
+
function findAssociatedTokenAddressSync(wallet, tokenMint, tokenProgramId = TOKEN_PROGRAM_ID$1, associatedTokenProramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
7447
7447
|
return PublicKey.findProgramAddressSync([wallet.toBytes(), tokenProgramId.toBytes(), tokenMint.toBytes()], associatedTokenProramId);
|
|
7448
7448
|
}
|
|
7449
|
-
function getTokenMetadataAddress(tokenMint,
|
|
7449
|
+
function getTokenMetadataAddress(tokenMint, tokenMetadataProgramId) {
|
|
7450
7450
|
return PublicKey.findProgramAddressSync([
|
|
7451
7451
|
buffer.Buffer.from("metadata"),
|
|
7452
|
-
|
|
7452
|
+
tokenMetadataProgramId.toBytes(),
|
|
7453
7453
|
tokenMint.toBytes(),
|
|
7454
|
-
],
|
|
7454
|
+
], tokenMetadataProgramId);
|
|
7455
7455
|
}
|
|
7456
7456
|
const deBridge$1 = {
|
|
7457
7457
|
getClaimMarkerAddress: (DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridge$2.Seeds.CLAIM_MARKER)], DEBRIDGE_PROGRAM_ID),
|
|
@@ -7593,6 +7593,17 @@ const dlnDstResolver = (programId) => {
|
|
|
7593
7593
|
return new Resolver(programId, DlnDst, dstMemoizeList);
|
|
7594
7594
|
};
|
|
7595
7595
|
|
|
7596
|
+
/** Address of the SPL Token program */
|
|
7597
|
+
const TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
|
|
7598
|
+
/** Address of the SPL Token 2022 program */
|
|
7599
|
+
new PublicKey('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb');
|
|
7600
|
+
/** Address of the SPL Associated Token Account program */
|
|
7601
|
+
new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
7602
|
+
/** Address of the special mint for wrapped native SOL in spl-token */
|
|
7603
|
+
new PublicKey('So11111111111111111111111111111111111111112');
|
|
7604
|
+
/** Address of the special mint for wrapped native SOL in spl-token-2022 */
|
|
7605
|
+
new PublicKey('9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP');
|
|
7606
|
+
|
|
7596
7607
|
var Layout$4 = {};
|
|
7597
7608
|
|
|
7598
7609
|
/* The MIT License (MIT)
|
|
@@ -9992,889 +10003,562 @@ const publicKey$4 = (property) => {
|
|
|
9992
10003
|
return publicKeyLayout;
|
|
9993
10004
|
};
|
|
9994
10005
|
|
|
10006
|
+
/** Base class for errors */
|
|
10007
|
+
class TokenError extends Error {
|
|
10008
|
+
constructor(message) {
|
|
10009
|
+
super(message);
|
|
10010
|
+
}
|
|
10011
|
+
}
|
|
10012
|
+
/** Thrown if an account is not found at the expected address */
|
|
10013
|
+
class TokenAccountNotFoundError extends TokenError {
|
|
10014
|
+
constructor() {
|
|
10015
|
+
super(...arguments);
|
|
10016
|
+
this.name = 'TokenAccountNotFoundError';
|
|
10017
|
+
}
|
|
10018
|
+
}
|
|
10019
|
+
/** Thrown if a program state account is not owned by the expected token program */
|
|
10020
|
+
class TokenInvalidAccountOwnerError extends TokenError {
|
|
10021
|
+
constructor() {
|
|
10022
|
+
super(...arguments);
|
|
10023
|
+
this.name = 'TokenInvalidAccountOwnerError';
|
|
10024
|
+
}
|
|
10025
|
+
}
|
|
10026
|
+
/** Thrown if the byte length of an program state account doesn't match the expected size */
|
|
10027
|
+
class TokenInvalidAccountSizeError extends TokenError {
|
|
10028
|
+
constructor() {
|
|
10029
|
+
super(...arguments);
|
|
10030
|
+
this.name = 'TokenInvalidAccountSizeError';
|
|
10031
|
+
}
|
|
10032
|
+
}
|
|
10033
|
+
/** Thrown if the mint of a token account doesn't match the expected mint */
|
|
10034
|
+
class TokenInvalidMintError extends TokenError {
|
|
10035
|
+
constructor() {
|
|
10036
|
+
super(...arguments);
|
|
10037
|
+
this.name = 'TokenInvalidMintError';
|
|
10038
|
+
}
|
|
10039
|
+
}
|
|
10040
|
+
|
|
10041
|
+
/** Instructions defined by the program */
|
|
10042
|
+
var TokenInstruction;
|
|
10043
|
+
(function (TokenInstruction) {
|
|
10044
|
+
TokenInstruction[TokenInstruction["InitializeMint"] = 0] = "InitializeMint";
|
|
10045
|
+
TokenInstruction[TokenInstruction["InitializeAccount"] = 1] = "InitializeAccount";
|
|
10046
|
+
TokenInstruction[TokenInstruction["InitializeMultisig"] = 2] = "InitializeMultisig";
|
|
10047
|
+
TokenInstruction[TokenInstruction["Transfer"] = 3] = "Transfer";
|
|
10048
|
+
TokenInstruction[TokenInstruction["Approve"] = 4] = "Approve";
|
|
10049
|
+
TokenInstruction[TokenInstruction["Revoke"] = 5] = "Revoke";
|
|
10050
|
+
TokenInstruction[TokenInstruction["SetAuthority"] = 6] = "SetAuthority";
|
|
10051
|
+
TokenInstruction[TokenInstruction["MintTo"] = 7] = "MintTo";
|
|
10052
|
+
TokenInstruction[TokenInstruction["Burn"] = 8] = "Burn";
|
|
10053
|
+
TokenInstruction[TokenInstruction["CloseAccount"] = 9] = "CloseAccount";
|
|
10054
|
+
TokenInstruction[TokenInstruction["FreezeAccount"] = 10] = "FreezeAccount";
|
|
10055
|
+
TokenInstruction[TokenInstruction["ThawAccount"] = 11] = "ThawAccount";
|
|
10056
|
+
TokenInstruction[TokenInstruction["TransferChecked"] = 12] = "TransferChecked";
|
|
10057
|
+
TokenInstruction[TokenInstruction["ApproveChecked"] = 13] = "ApproveChecked";
|
|
10058
|
+
TokenInstruction[TokenInstruction["MintToChecked"] = 14] = "MintToChecked";
|
|
10059
|
+
TokenInstruction[TokenInstruction["BurnChecked"] = 15] = "BurnChecked";
|
|
10060
|
+
TokenInstruction[TokenInstruction["InitializeAccount2"] = 16] = "InitializeAccount2";
|
|
10061
|
+
TokenInstruction[TokenInstruction["SyncNative"] = 17] = "SyncNative";
|
|
10062
|
+
TokenInstruction[TokenInstruction["InitializeAccount3"] = 18] = "InitializeAccount3";
|
|
10063
|
+
TokenInstruction[TokenInstruction["InitializeMultisig2"] = 19] = "InitializeMultisig2";
|
|
10064
|
+
TokenInstruction[TokenInstruction["InitializeMint2"] = 20] = "InitializeMint2";
|
|
10065
|
+
TokenInstruction[TokenInstruction["GetAccountDataSize"] = 21] = "GetAccountDataSize";
|
|
10066
|
+
TokenInstruction[TokenInstruction["InitializeImmutableOwner"] = 22] = "InitializeImmutableOwner";
|
|
10067
|
+
TokenInstruction[TokenInstruction["AmountToUiAmount"] = 23] = "AmountToUiAmount";
|
|
10068
|
+
TokenInstruction[TokenInstruction["UiAmountToAmount"] = 24] = "UiAmountToAmount";
|
|
10069
|
+
TokenInstruction[TokenInstruction["InitializeMintCloseAuthority"] = 25] = "InitializeMintCloseAuthority";
|
|
10070
|
+
TokenInstruction[TokenInstruction["TransferFeeExtension"] = 26] = "TransferFeeExtension";
|
|
10071
|
+
TokenInstruction[TokenInstruction["ConfidentialTransferExtension"] = 27] = "ConfidentialTransferExtension";
|
|
10072
|
+
TokenInstruction[TokenInstruction["DefaultAccountStateExtension"] = 28] = "DefaultAccountStateExtension";
|
|
10073
|
+
TokenInstruction[TokenInstruction["Reallocate"] = 29] = "Reallocate";
|
|
10074
|
+
TokenInstruction[TokenInstruction["MemoTransferExtension"] = 30] = "MemoTransferExtension";
|
|
10075
|
+
TokenInstruction[TokenInstruction["CreateNativeMint"] = 31] = "CreateNativeMint";
|
|
10076
|
+
TokenInstruction[TokenInstruction["InitializeNonTransferableMint"] = 32] = "InitializeNonTransferableMint";
|
|
10077
|
+
TokenInstruction[TokenInstruction["InterestBearingMintExtension"] = 33] = "InterestBearingMintExtension";
|
|
10078
|
+
TokenInstruction[TokenInstruction["CpiGuardExtension"] = 34] = "CpiGuardExtension";
|
|
10079
|
+
TokenInstruction[TokenInstruction["InitializePermanentDelegate"] = 35] = "InitializePermanentDelegate";
|
|
10080
|
+
TokenInstruction[TokenInstruction["TransferHookExtension"] = 36] = "TransferHookExtension";
|
|
10081
|
+
// ConfidentialTransferFeeExtension = 37,
|
|
10082
|
+
// WithdrawalExcessLamports = 38,
|
|
10083
|
+
TokenInstruction[TokenInstruction["MetadataPointerExtension"] = 39] = "MetadataPointerExtension";
|
|
10084
|
+
TokenInstruction[TokenInstruction["GroupPointerExtension"] = 40] = "GroupPointerExtension";
|
|
10085
|
+
TokenInstruction[TokenInstruction["GroupMemberPointerExtension"] = 41] = "GroupMemberPointerExtension";
|
|
10086
|
+
// ConfidentialMintBurnExtension = 42,
|
|
10087
|
+
TokenInstruction[TokenInstruction["ScaledUiAmountExtension"] = 43] = "ScaledUiAmountExtension";
|
|
10088
|
+
TokenInstruction[TokenInstruction["PausableExtension"] = 44] = "PausableExtension";
|
|
10089
|
+
})(TokenInstruction || (TokenInstruction = {}));
|
|
10090
|
+
|
|
10091
|
+
/** TODO: docs */
|
|
10092
|
+
struct$1([
|
|
10093
|
+
u8$1('instruction'),
|
|
10094
|
+
u64$1('amount'),
|
|
10095
|
+
]);
|
|
10096
|
+
|
|
10097
|
+
var AccountType$1;
|
|
10098
|
+
(function (AccountType) {
|
|
10099
|
+
AccountType[AccountType["Uninitialized"] = 0] = "Uninitialized";
|
|
10100
|
+
AccountType[AccountType["Mint"] = 1] = "Mint";
|
|
10101
|
+
AccountType[AccountType["Account"] = 2] = "Account";
|
|
10102
|
+
})(AccountType$1 || (AccountType$1 = {}));
|
|
10103
|
+
const ACCOUNT_TYPE_SIZE = 1;
|
|
10104
|
+
|
|
10105
|
+
/** Buffer layout for de/serializing a multisig */
|
|
10106
|
+
const MultisigLayout = struct$1([
|
|
10107
|
+
u8$1('m'),
|
|
10108
|
+
u8$1('n'),
|
|
10109
|
+
bool$1('isInitialized'),
|
|
10110
|
+
publicKey$4('signer1'),
|
|
10111
|
+
publicKey$4('signer2'),
|
|
10112
|
+
publicKey$4('signer3'),
|
|
10113
|
+
publicKey$4('signer4'),
|
|
10114
|
+
publicKey$4('signer5'),
|
|
10115
|
+
publicKey$4('signer6'),
|
|
10116
|
+
publicKey$4('signer7'),
|
|
10117
|
+
publicKey$4('signer8'),
|
|
10118
|
+
publicKey$4('signer9'),
|
|
10119
|
+
publicKey$4('signer10'),
|
|
10120
|
+
publicKey$4('signer11'),
|
|
10121
|
+
]);
|
|
10122
|
+
/** Byte length of a multisig */
|
|
10123
|
+
const MULTISIG_SIZE = MultisigLayout.span;
|
|
10124
|
+
|
|
10125
|
+
/** Token account state as stored by the program */
|
|
9995
10126
|
var AccountState$1;
|
|
9996
10127
|
(function (AccountState) {
|
|
9997
10128
|
AccountState[AccountState["Uninitialized"] = 0] = "Uninitialized";
|
|
9998
10129
|
AccountState[AccountState["Initialized"] = 1] = "Initialized";
|
|
9999
10130
|
AccountState[AccountState["Frozen"] = 2] = "Frozen";
|
|
10000
10131
|
})(AccountState$1 || (AccountState$1 = {}));
|
|
10132
|
+
/** Buffer layout for de/serializing a token account */
|
|
10001
10133
|
const AccountLayout$1 = struct$1([
|
|
10002
|
-
publicKey$4(
|
|
10003
|
-
publicKey$4(
|
|
10004
|
-
u64$1(
|
|
10005
|
-
u32$1(
|
|
10006
|
-
publicKey$4(
|
|
10007
|
-
u8$1(
|
|
10008
|
-
u32$1(
|
|
10009
|
-
u64$1(
|
|
10010
|
-
u64$1(
|
|
10011
|
-
u32$1(
|
|
10012
|
-
publicKey$4(
|
|
10134
|
+
publicKey$4('mint'),
|
|
10135
|
+
publicKey$4('owner'),
|
|
10136
|
+
u64$1('amount'),
|
|
10137
|
+
u32$1('delegateOption'),
|
|
10138
|
+
publicKey$4('delegate'),
|
|
10139
|
+
u8$1('state'),
|
|
10140
|
+
u32$1('isNativeOption'),
|
|
10141
|
+
u64$1('isNative'),
|
|
10142
|
+
u64$1('delegatedAmount'),
|
|
10143
|
+
u32$1('closeAuthorityOption'),
|
|
10144
|
+
publicKey$4('closeAuthority'),
|
|
10013
10145
|
]);
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
10017
|
-
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
|
|
10021
|
-
})(
|
|
10022
|
-
/**
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
10050
|
-
|
|
10051
|
-
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
|
|
10072
|
-
|
|
10146
|
+
/** Byte length of a token account */
|
|
10147
|
+
const ACCOUNT_SIZE = AccountLayout$1.span;
|
|
10148
|
+
|
|
10149
|
+
var CpiGuardInstruction;
|
|
10150
|
+
(function (CpiGuardInstruction) {
|
|
10151
|
+
CpiGuardInstruction[CpiGuardInstruction["Enable"] = 0] = "Enable";
|
|
10152
|
+
CpiGuardInstruction[CpiGuardInstruction["Disable"] = 1] = "Disable";
|
|
10153
|
+
})(CpiGuardInstruction || (CpiGuardInstruction = {}));
|
|
10154
|
+
/** TODO: docs */
|
|
10155
|
+
struct$1([u8$1('instruction'), u8$1('cpiGuardInstruction')]);
|
|
10156
|
+
|
|
10157
|
+
/** Buffer layout for de/serializing a CPI Guard extension */
|
|
10158
|
+
const CpiGuardLayout = struct$1([bool$1('lockCpi')]);
|
|
10159
|
+
CpiGuardLayout.span;
|
|
10160
|
+
|
|
10161
|
+
var DefaultAccountStateInstruction;
|
|
10162
|
+
(function (DefaultAccountStateInstruction) {
|
|
10163
|
+
DefaultAccountStateInstruction[DefaultAccountStateInstruction["Initialize"] = 0] = "Initialize";
|
|
10164
|
+
DefaultAccountStateInstruction[DefaultAccountStateInstruction["Update"] = 1] = "Update";
|
|
10165
|
+
})(DefaultAccountStateInstruction || (DefaultAccountStateInstruction = {}));
|
|
10166
|
+
/** TODO: docs */
|
|
10167
|
+
struct$1([
|
|
10168
|
+
u8$1('instruction'),
|
|
10169
|
+
u8$1('defaultAccountStateInstruction'),
|
|
10170
|
+
u8$1('accountState'),
|
|
10171
|
+
]);
|
|
10172
|
+
|
|
10173
|
+
/** Buffer layout for de/serializing a transfer fee config extension */
|
|
10174
|
+
const DefaultAccountStateLayout = struct$1([u8$1('state')]);
|
|
10175
|
+
DefaultAccountStateLayout.span;
|
|
10176
|
+
|
|
10177
|
+
// src/codes.ts
|
|
10178
|
+
var SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY$1 = 8078e3;
|
|
10179
|
+
var SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH$1 = 8078001;
|
|
10180
|
+
var SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH$1 = 8078004;
|
|
10181
|
+
var SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH$1 = 8078005;
|
|
10182
|
+
var SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH$1 = 8078006;
|
|
10183
|
+
var SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS$1 = 8078007;
|
|
10184
|
+
var SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE$1 = 8078011;
|
|
10185
|
+
|
|
10186
|
+
// src/context.ts
|
|
10187
|
+
function encodeValue$1(value) {
|
|
10188
|
+
if (Array.isArray(value)) {
|
|
10189
|
+
const commaSeparatedValues = value.map(encodeValue$1).join(
|
|
10190
|
+
"%2C%20"
|
|
10191
|
+
/* ", " */
|
|
10192
|
+
);
|
|
10193
|
+
return "%5B" + commaSeparatedValues + /* "]" */
|
|
10194
|
+
"%5D";
|
|
10195
|
+
} else if (typeof value === "bigint") {
|
|
10196
|
+
return `${value}n`;
|
|
10197
|
+
} else {
|
|
10198
|
+
return encodeURIComponent(
|
|
10199
|
+
String(
|
|
10200
|
+
value != null && Object.getPrototypeOf(value) === null ? (
|
|
10201
|
+
// Plain objects with no prototype don't have a `toString` method.
|
|
10202
|
+
// Convert them before stringifying them.
|
|
10203
|
+
{ ...value }
|
|
10204
|
+
) : value
|
|
10205
|
+
)
|
|
10206
|
+
);
|
|
10207
|
+
}
|
|
10073
10208
|
}
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
* @param tokenMint mint account of SPL-token
|
|
10077
|
-
* @param associatedAccount associated account address
|
|
10078
|
-
* @param owner owner of the associated account
|
|
10079
|
-
* @param payer who pays for account creation
|
|
10080
|
-
*/
|
|
10081
|
-
function createAssociatedWalletInstruction(tokenMint, associatedAccount, owner, payer, associatedTokenProramId) {
|
|
10082
|
-
tokenMint = new PublicKey(tokenMint);
|
|
10083
|
-
payer = new PublicKey(payer);
|
|
10084
|
-
owner = new PublicKey(owner);
|
|
10085
|
-
return new TransactionInstruction({
|
|
10086
|
-
programId: associatedTokenProramId || ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
10087
|
-
data: buffer.Buffer.from([1]),
|
|
10088
|
-
keys: [
|
|
10089
|
-
{
|
|
10090
|
-
pubkey: payer,
|
|
10091
|
-
isSigner: true,
|
|
10092
|
-
isWritable: true,
|
|
10093
|
-
},
|
|
10094
|
-
{
|
|
10095
|
-
pubkey: associatedAccount,
|
|
10096
|
-
isSigner: false,
|
|
10097
|
-
isWritable: true,
|
|
10098
|
-
},
|
|
10099
|
-
{
|
|
10100
|
-
pubkey: owner,
|
|
10101
|
-
isSigner: false,
|
|
10102
|
-
isWritable: false,
|
|
10103
|
-
},
|
|
10104
|
-
{
|
|
10105
|
-
pubkey: tokenMint,
|
|
10106
|
-
isSigner: false,
|
|
10107
|
-
isWritable: false,
|
|
10108
|
-
},
|
|
10109
|
-
{
|
|
10110
|
-
pubkey: SystemProgram.programId,
|
|
10111
|
-
isSigner: false,
|
|
10112
|
-
isWritable: false,
|
|
10113
|
-
},
|
|
10114
|
-
{
|
|
10115
|
-
pubkey: TOKEN_PROGRAM_ID,
|
|
10116
|
-
isSigner: false,
|
|
10117
|
-
isWritable: false,
|
|
10118
|
-
},
|
|
10119
|
-
],
|
|
10120
|
-
});
|
|
10209
|
+
function encodeObjectContextEntry$1([key, value]) {
|
|
10210
|
+
return `${key}=${encodeValue$1(value)}`;
|
|
10121
10211
|
}
|
|
10122
|
-
function
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10212
|
+
function encodeContextObject$1(context) {
|
|
10213
|
+
const searchParamsString = Object.entries(context).map(encodeObjectContextEntry$1).join("&");
|
|
10214
|
+
return btoa(searchParamsString);
|
|
10215
|
+
}
|
|
10216
|
+
function getErrorMessage$1(code, context = {}) {
|
|
10217
|
+
{
|
|
10218
|
+
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode -- ${code}`;
|
|
10219
|
+
if (Object.keys(context).length) {
|
|
10220
|
+
decodingAdviceMessage += ` '${encodeContextObject$1(context)}'`;
|
|
10131
10221
|
}
|
|
10132
|
-
|
|
10133
|
-
|
|
10222
|
+
return `${decodingAdviceMessage}\``;
|
|
10223
|
+
}
|
|
10224
|
+
}
|
|
10225
|
+
var SolanaError$1 = class extends Error {
|
|
10226
|
+
cause = this.cause;
|
|
10227
|
+
context;
|
|
10228
|
+
constructor(...[code, contextAndErrorOptions]) {
|
|
10229
|
+
let context;
|
|
10230
|
+
let errorOptions;
|
|
10231
|
+
if (contextAndErrorOptions) {
|
|
10232
|
+
const { cause, ...contextRest } = contextAndErrorOptions;
|
|
10233
|
+
if (cause) {
|
|
10234
|
+
errorOptions = { cause };
|
|
10235
|
+
}
|
|
10236
|
+
if (Object.keys(contextRest).length > 0) {
|
|
10237
|
+
context = contextRest;
|
|
10238
|
+
}
|
|
10134
10239
|
}
|
|
10135
|
-
|
|
10240
|
+
const message = getErrorMessage$1(code, context);
|
|
10241
|
+
super(message, errorOptions);
|
|
10242
|
+
this.context = {
|
|
10243
|
+
__code: code,
|
|
10244
|
+
...context
|
|
10245
|
+
};
|
|
10246
|
+
this.name = "SolanaError";
|
|
10247
|
+
}
|
|
10248
|
+
};
|
|
10249
|
+
|
|
10250
|
+
var padBytes$1 = (bytes, length) => {
|
|
10251
|
+
if (bytes.length >= length) return bytes;
|
|
10252
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
10253
|
+
paddedBytes.set(bytes);
|
|
10254
|
+
return paddedBytes;
|
|
10255
|
+
};
|
|
10256
|
+
var fixBytes$1 = (bytes, length) => padBytes$1(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
10257
|
+
function getEncodedSize$1(value, encoder) {
|
|
10258
|
+
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
|
|
10136
10259
|
}
|
|
10137
|
-
function
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
10260
|
+
function createEncoder$1(encoder) {
|
|
10261
|
+
return Object.freeze({
|
|
10262
|
+
...encoder,
|
|
10263
|
+
encode: (value) => {
|
|
10264
|
+
const bytes = new Uint8Array(getEncodedSize$1(value, encoder));
|
|
10265
|
+
encoder.write(value, bytes, 0);
|
|
10266
|
+
return bytes;
|
|
10267
|
+
}
|
|
10268
|
+
});
|
|
10143
10269
|
}
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
function getAccountWithType(connection, account) {
|
|
10150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10151
|
-
account = new PublicKey(account);
|
|
10152
|
-
const accountData = yield getAccountInfo(connection, account);
|
|
10153
|
-
if (!accountData)
|
|
10154
|
-
return [null, AccountType$1.NotExists];
|
|
10155
|
-
if (accountData.owner.equals(TOKEN_PROGRAM_ID)) {
|
|
10156
|
-
return isWalletCorrectATA(account, accountData.data)
|
|
10157
|
-
? [accountData, AccountType$1.CorrectATA]
|
|
10158
|
-
: [accountData, AccountType$1.Token];
|
|
10159
|
-
}
|
|
10160
|
-
if (accountData.owner.equals(SystemProgram.programId))
|
|
10161
|
-
return [accountData, AccountType$1.System];
|
|
10162
|
-
return [accountData, AccountType$1.Unknown];
|
|
10163
|
-
});
|
|
10270
|
+
function createDecoder$1(decoder) {
|
|
10271
|
+
return Object.freeze({
|
|
10272
|
+
...decoder,
|
|
10273
|
+
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
|
|
10274
|
+
});
|
|
10164
10275
|
}
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
* @param wallet wallet to inspect
|
|
10168
|
-
*/
|
|
10169
|
-
function getNativeWalletBalance(connection, wallet) {
|
|
10170
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10171
|
-
wallet = new PublicKey(wallet);
|
|
10172
|
-
const result = yield connection.getBalance(wallet);
|
|
10173
|
-
return new BN(result.toString());
|
|
10174
|
-
});
|
|
10276
|
+
function isFixedSize$1(codec) {
|
|
10277
|
+
return "fixedSize" in codec && typeof codec.fixedSize === "number";
|
|
10175
10278
|
}
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
tokenMint = new PublicKey(tokenMint);
|
|
10185
|
-
const [wallet] = findAssociatedTokenAddress(originalWallet, tokenMint);
|
|
10186
|
-
const result = yield connection.getTokenAccountBalance(wallet, "finalized");
|
|
10187
|
-
return new BN(result.value.amount);
|
|
10279
|
+
function combineCodec$1(encoder, decoder) {
|
|
10280
|
+
if (isFixedSize$1(encoder) !== isFixedSize$1(decoder)) {
|
|
10281
|
+
throw new SolanaError$1(SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH$1);
|
|
10282
|
+
}
|
|
10283
|
+
if (isFixedSize$1(encoder) && isFixedSize$1(decoder) && encoder.fixedSize !== decoder.fixedSize) {
|
|
10284
|
+
throw new SolanaError$1(SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH$1, {
|
|
10285
|
+
decoderFixedSize: decoder.fixedSize,
|
|
10286
|
+
encoderFixedSize: encoder.fixedSize
|
|
10188
10287
|
});
|
|
10189
|
-
}
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
function getSPLWalletBalance(connection, wallet) {
|
|
10195
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10196
|
-
wallet = new PublicKey(wallet);
|
|
10197
|
-
const result = yield connection.getTokenAccountBalance(wallet, "finalized");
|
|
10198
|
-
return new BN(result.value.amount);
|
|
10288
|
+
}
|
|
10289
|
+
if (!isFixedSize$1(encoder) && !isFixedSize$1(decoder) && encoder.maxSize !== decoder.maxSize) {
|
|
10290
|
+
throw new SolanaError$1(SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH$1, {
|
|
10291
|
+
decoderMaxSize: decoder.maxSize,
|
|
10292
|
+
encoderMaxSize: encoder.maxSize
|
|
10199
10293
|
});
|
|
10294
|
+
}
|
|
10295
|
+
return {
|
|
10296
|
+
...decoder,
|
|
10297
|
+
...encoder,
|
|
10298
|
+
decode: decoder.decode,
|
|
10299
|
+
encode: encoder.encode,
|
|
10300
|
+
read: decoder.read,
|
|
10301
|
+
write: encoder.write
|
|
10302
|
+
};
|
|
10200
10303
|
}
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
*/
|
|
10206
|
-
function getAllTokenAccountsWithBalances(connection, owner) {
|
|
10207
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10208
|
-
const walletsData = yield connection.getParsedTokenAccountsByOwner(new PublicKey(owner), { programId: TOKEN_PROGRAM_ID });
|
|
10209
|
-
const wallets = walletsData.value;
|
|
10210
|
-
return wallets.map((wallet) => {
|
|
10211
|
-
const tokenInfo = wallet.account.data.parsed;
|
|
10212
|
-
return {
|
|
10213
|
-
address: wallet.pubkey,
|
|
10214
|
-
mint: new PublicKey(tokenInfo.info.mint),
|
|
10215
|
-
amount: new BN(tokenInfo.info.tokenAmount.amount),
|
|
10216
|
-
decimals: tokenInfo.info.tokenAmount.decimals,
|
|
10217
|
-
isInitialized: true,
|
|
10218
|
-
isNative: tokenInfo.info.isNative,
|
|
10219
|
-
owner: new PublicKey(tokenInfo.info.owner),
|
|
10220
|
-
};
|
|
10221
|
-
});
|
|
10304
|
+
function assertByteArrayIsNotEmptyForCodec$1(codecDescription, bytes, offset = 0) {
|
|
10305
|
+
if (bytes.length - offset <= 0) {
|
|
10306
|
+
throw new SolanaError$1(SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY$1, {
|
|
10307
|
+
codecDescription
|
|
10222
10308
|
});
|
|
10309
|
+
}
|
|
10223
10310
|
}
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10230
|
-
|
|
10231
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10232
|
-
const walletsData = yield connection.getParsedTokenAccountsByOwner(new PublicKey(owner), { mint: new PublicKey(tokenMint) });
|
|
10233
|
-
const wallets = walletsData.value;
|
|
10234
|
-
return wallets.map((wallet) => {
|
|
10235
|
-
const tokenInfo = wallet.account.data.parsed;
|
|
10236
|
-
return {
|
|
10237
|
-
address: wallet.pubkey,
|
|
10238
|
-
mint: new PublicKey(tokenInfo.info.mint),
|
|
10239
|
-
amount: new BN(tokenInfo.info.tokenAmount.amount),
|
|
10240
|
-
decimals: tokenInfo.info.tokenAmount.decimals,
|
|
10241
|
-
isInitialized: true,
|
|
10242
|
-
isNative: tokenInfo.info.isNative,
|
|
10243
|
-
owner: new PublicKey(tokenInfo.info.owner),
|
|
10244
|
-
};
|
|
10245
|
-
});
|
|
10311
|
+
function assertByteArrayHasEnoughBytesForCodec$1(codecDescription, expected, bytes, offset = 0) {
|
|
10312
|
+
const bytesLength = bytes.length - offset;
|
|
10313
|
+
if (bytesLength < expected) {
|
|
10314
|
+
throw new SolanaError$1(SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH$1, {
|
|
10315
|
+
bytesLength,
|
|
10316
|
+
codecDescription,
|
|
10317
|
+
expected
|
|
10246
10318
|
});
|
|
10319
|
+
}
|
|
10247
10320
|
}
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
return tx;
|
|
10321
|
+
|
|
10322
|
+
// src/add-codec-size-prefix.ts
|
|
10323
|
+
function addEncoderSizePrefix(encoder, prefix) {
|
|
10324
|
+
const write = (value, bytes, offset) => {
|
|
10325
|
+
const encoderBytes = encoder.encode(value);
|
|
10326
|
+
offset = prefix.write(encoderBytes.length, bytes, offset);
|
|
10327
|
+
bytes.set(encoderBytes, offset);
|
|
10328
|
+
return offset + encoderBytes.length;
|
|
10329
|
+
};
|
|
10330
|
+
if (isFixedSize$1(prefix) && isFixedSize$1(encoder)) {
|
|
10331
|
+
return createEncoder$1({ ...encoder, fixedSize: prefix.fixedSize + encoder.fixedSize, write });
|
|
10332
|
+
}
|
|
10333
|
+
const prefixMaxSize = isFixedSize$1(prefix) ? prefix.fixedSize : prefix.maxSize ?? null;
|
|
10334
|
+
const encoderMaxSize = isFixedSize$1(encoder) ? encoder.fixedSize : encoder.maxSize ?? null;
|
|
10335
|
+
const maxSize = prefixMaxSize !== null && encoderMaxSize !== null ? prefixMaxSize + encoderMaxSize : null;
|
|
10336
|
+
return createEncoder$1({
|
|
10337
|
+
...encoder,
|
|
10338
|
+
...maxSize !== null ? { maxSize } : {},
|
|
10339
|
+
getSizeFromValue: (value) => {
|
|
10340
|
+
const encoderSize = getEncodedSize$1(value, encoder);
|
|
10341
|
+
return getEncodedSize$1(encoderSize, prefix) + encoderSize;
|
|
10342
|
+
},
|
|
10343
|
+
write
|
|
10344
|
+
});
|
|
10273
10345
|
}
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
throw new Error("WSol account exists, but failed to decode its content");
|
|
10293
|
-
const parsedAmount = new BN(parsed.amount.toString());
|
|
10294
|
-
if (amountToWrap.lte(parsedAmount))
|
|
10295
|
-
return null; // don't need to wrap
|
|
10296
|
-
amountToWrap = amountToWrap.sub(parsedAmount);
|
|
10297
|
-
}
|
|
10298
|
-
const replenishTx = buildReplenishWsolBalanceTransaction(amountToWrap, owner, wSolATA);
|
|
10299
|
-
tx.add(replenishTx);
|
|
10300
|
-
return tx;
|
|
10301
|
-
});
|
|
10346
|
+
function addDecoderSizePrefix(decoder, prefix) {
|
|
10347
|
+
const read = (bytes, offset) => {
|
|
10348
|
+
const [bigintSize, decoderOffset] = prefix.read(bytes, offset);
|
|
10349
|
+
const size = Number(bigintSize);
|
|
10350
|
+
offset = decoderOffset;
|
|
10351
|
+
if (offset > 0 || bytes.length > size) {
|
|
10352
|
+
bytes = bytes.slice(offset, offset + size);
|
|
10353
|
+
}
|
|
10354
|
+
assertByteArrayHasEnoughBytesForCodec$1("addDecoderSizePrefix", size, bytes);
|
|
10355
|
+
return [decoder.decode(bytes), offset + size];
|
|
10356
|
+
};
|
|
10357
|
+
if (isFixedSize$1(prefix) && isFixedSize$1(decoder)) {
|
|
10358
|
+
return createDecoder$1({ ...decoder, fixedSize: prefix.fixedSize + decoder.fixedSize, read });
|
|
10359
|
+
}
|
|
10360
|
+
const prefixMaxSize = isFixedSize$1(prefix) ? prefix.fixedSize : prefix.maxSize ?? null;
|
|
10361
|
+
const decoderMaxSize = isFixedSize$1(decoder) ? decoder.fixedSize : decoder.maxSize ?? null;
|
|
10362
|
+
const maxSize = prefixMaxSize !== null && decoderMaxSize !== null ? prefixMaxSize + decoderMaxSize : null;
|
|
10363
|
+
return createDecoder$1({ ...decoder, ...maxSize !== null ? { maxSize } : {}, read });
|
|
10302
10364
|
}
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
* @param mintAccount mint account of SPL-token
|
|
10306
|
-
* @param originalWallet account of solana wallet
|
|
10307
|
-
* @returns true if account exists
|
|
10308
|
-
*/
|
|
10309
|
-
function checkIfAssociatedWalletExists(connection, mintAccount, originalWallet) {
|
|
10310
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10311
|
-
const [walletAccount] = findAssociatedTokenAddress(originalWallet, mintAccount);
|
|
10312
|
-
const accountData = yield getAccountInfo(connection, walletAccount);
|
|
10313
|
-
return accountData !== null;
|
|
10314
|
-
});
|
|
10365
|
+
function addCodecSizePrefix(codec, prefix) {
|
|
10366
|
+
return combineCodec$1(addEncoderSizePrefix(codec, prefix), addDecoderSizePrefix(codec, prefix));
|
|
10315
10367
|
}
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
})
|
|
10329
|
-
: null)
|
|
10330
|
-
.filter((x) => x != null);
|
|
10331
|
-
const accGetter = tx.message.getAccountKeys({
|
|
10332
|
-
addressLookupTableAccounts: parsedALTs,
|
|
10333
|
-
});
|
|
10334
|
-
const staticWritableOrSignerAccounts = [];
|
|
10335
|
-
for (let idx = 0; idx < accGetter.staticAccountKeys.length; idx += 1) {
|
|
10336
|
-
if (tx.message.isAccountSigner(idx) || tx.message.isAccountWritable(idx))
|
|
10337
|
-
staticWritableOrSignerAccounts.push(accGetter.staticAccountKeys[idx]);
|
|
10338
|
-
}
|
|
10339
|
-
for (const acc of [
|
|
10340
|
-
...staticWritableOrSignerAccounts,
|
|
10341
|
-
...((_b = (_a = accGetter.accountKeysFromLookups) === null || _a === void 0 ? void 0 : _a.writable) !== null && _b !== void 0 ? _b : []),
|
|
10342
|
-
]) {
|
|
10343
|
-
result.add(acc.toBase58());
|
|
10344
|
-
}
|
|
10345
|
-
}
|
|
10346
|
-
else {
|
|
10347
|
-
const compiled = tx.compileMessage();
|
|
10348
|
-
for (let idx = 0; idx < compiled.accountKeys.length; idx += 1) {
|
|
10349
|
-
if (compiled.isAccountSigner(idx) || compiled.isAccountWritable(idx))
|
|
10350
|
-
result.add(compiled.staticAccountKeys[idx].toBase58());
|
|
10351
|
-
}
|
|
10352
|
-
}
|
|
10353
|
-
return Array.from(result);
|
|
10354
|
-
});
|
|
10368
|
+
|
|
10369
|
+
// src/fix-codec-size.ts
|
|
10370
|
+
function fixEncoderSize$1(encoder, fixedBytes) {
|
|
10371
|
+
return createEncoder$1({
|
|
10372
|
+
fixedSize: fixedBytes,
|
|
10373
|
+
write: (value, bytes, offset) => {
|
|
10374
|
+
const variableByteArray = encoder.encode(value);
|
|
10375
|
+
const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
|
|
10376
|
+
bytes.set(fixedByteArray, offset);
|
|
10377
|
+
return offset + fixedBytes;
|
|
10378
|
+
}
|
|
10379
|
+
});
|
|
10355
10380
|
}
|
|
10356
|
-
function
|
|
10357
|
-
|
|
10358
|
-
|
|
10359
|
-
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
|
|
10363
|
-
|
|
10364
|
-
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
|
|
10368
|
-
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
}
|
|
10372
|
-
const parsedAccount = {
|
|
10373
|
-
balance: (_a = account === null || account === void 0 ? void 0 : account.lamports) !== null && _a !== void 0 ? _a : 0,
|
|
10374
|
-
};
|
|
10375
|
-
if (parsedSplAccount) {
|
|
10376
|
-
parsedAccount.spl = {
|
|
10377
|
-
mint: parsedSplAccount.mint,
|
|
10378
|
-
owner: parsedSplAccount.owner,
|
|
10379
|
-
balance: (_b = parsedSplAccount.amount) !== null && _b !== void 0 ? _b : BigInt(0),
|
|
10380
|
-
};
|
|
10381
|
-
}
|
|
10382
|
-
return parsedAccount;
|
|
10383
|
-
});
|
|
10381
|
+
function fixDecoderSize$1(decoder, fixedBytes) {
|
|
10382
|
+
return createDecoder$1({
|
|
10383
|
+
fixedSize: fixedBytes,
|
|
10384
|
+
read: (bytes, offset) => {
|
|
10385
|
+
assertByteArrayHasEnoughBytesForCodec$1("fixCodecSize", fixedBytes, bytes, offset);
|
|
10386
|
+
if (offset > 0 || bytes.length > fixedBytes) {
|
|
10387
|
+
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
10388
|
+
}
|
|
10389
|
+
if (isFixedSize$1(decoder)) {
|
|
10390
|
+
bytes = fixBytes$1(bytes, decoder.fixedSize);
|
|
10391
|
+
}
|
|
10392
|
+
const [value] = decoder.read(bytes, 0);
|
|
10393
|
+
return [value, offset + fixedBytes];
|
|
10394
|
+
}
|
|
10395
|
+
});
|
|
10384
10396
|
}
|
|
10385
|
-
function
|
|
10386
|
-
|
|
10387
|
-
const preBalance = (_a = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
10388
|
-
const postBalance = (_b = post === null || post === void 0 ? void 0 : post.balance) !== null && _b !== void 0 ? _b : BigInt(0);
|
|
10389
|
-
return {
|
|
10390
|
-
mint: (_c = pre === null || pre === void 0 ? void 0 : pre.mint) !== null && _c !== void 0 ? _c : post === null || post === void 0 ? void 0 : post.mint,
|
|
10391
|
-
owner: (_d = pre === null || pre === void 0 ? void 0 : pre.owner) !== null && _d !== void 0 ? _d : post === null || post === void 0 ? void 0 : post.owner,
|
|
10392
|
-
preBalance: (_e = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _e !== void 0 ? _e : 0,
|
|
10393
|
-
postBalance: (_f = post === null || post === void 0 ? void 0 : post.balance) !== null && _f !== void 0 ? _f : 0,
|
|
10394
|
-
diff: postBalance - preBalance,
|
|
10395
|
-
};
|
|
10397
|
+
function fixCodecSize$1(codec, fixedBytes) {
|
|
10398
|
+
return combineCodec$1(fixEncoderSize$1(codec, fixedBytes), fixDecoderSize$1(codec, fixedBytes));
|
|
10396
10399
|
}
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
replaceRecentBlockhash: true,
|
|
10407
|
-
accounts: {
|
|
10408
|
-
encoding: "base64",
|
|
10409
|
-
addresses: accountsStrings,
|
|
10410
|
-
},
|
|
10411
|
-
}),
|
|
10412
|
-
]);
|
|
10413
|
-
if (simulatedTx.value.err !== null)
|
|
10414
|
-
throw new Error(JSON.stringify({
|
|
10415
|
-
err: simulatedTx.value.err,
|
|
10416
|
-
logs: simulatedTx.value.logs,
|
|
10417
|
-
}));
|
|
10418
|
-
const simulatesInfo = simulatedTx.value.accounts;
|
|
10419
|
-
const preBalances = parseMultipleAccounts(accountsInfo);
|
|
10420
|
-
const postBalances = parseMultipleAccounts(simulatesInfo);
|
|
10421
|
-
const balancesDiff = accountsPubKeys.reduce((map, pubKey, i) => {
|
|
10422
|
-
var _a;
|
|
10423
|
-
if ((_a = accountsInfo[i]) === null || _a === void 0 ? void 0 : _a.executable) {
|
|
10424
|
-
return map;
|
|
10425
|
-
}
|
|
10426
|
-
const preBalance = preBalances[i];
|
|
10427
|
-
const postBalance = postBalances[i];
|
|
10428
|
-
const diff = {
|
|
10429
|
-
pubKey: pubKey,
|
|
10430
|
-
preBalance: preBalance.balance,
|
|
10431
|
-
postBalance: postBalance.balance,
|
|
10432
|
-
diff: postBalance.balance - preBalance.balance,
|
|
10433
|
-
};
|
|
10434
|
-
if (preBalance.spl || postBalance.spl) {
|
|
10435
|
-
const splDiff = getSplDiff(preBalance.spl, postBalance.spl);
|
|
10436
|
-
if (splDiff.diff) {
|
|
10437
|
-
diff.spl = splDiff;
|
|
10438
|
-
}
|
|
10439
|
-
}
|
|
10440
|
-
if (diff.diff || diff.spl) {
|
|
10441
|
-
map.set(pubKey.toString(), diff);
|
|
10442
|
-
}
|
|
10443
|
-
return map;
|
|
10444
|
-
}, new Map());
|
|
10445
|
-
return balancesDiff;
|
|
10400
|
+
|
|
10401
|
+
// src/assertions.ts
|
|
10402
|
+
function assertNumberIsBetweenForCodec$1(codecDescription, min, max, value) {
|
|
10403
|
+
if (value < min || value > max) {
|
|
10404
|
+
throw new SolanaError$1(SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE$1, {
|
|
10405
|
+
codecDescription,
|
|
10406
|
+
max,
|
|
10407
|
+
min,
|
|
10408
|
+
value
|
|
10446
10409
|
});
|
|
10410
|
+
}
|
|
10447
10411
|
}
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
__proto__: null,
|
|
10451
|
-
get AccountType () { return AccountType$1; },
|
|
10452
|
-
getTokenInfo: getTokenInfo,
|
|
10453
|
-
createAssociatedWalletInstruction: createAssociatedWalletInstruction,
|
|
10454
|
-
parseSplAccount: parseSplAccount,
|
|
10455
|
-
isWalletCorrectATA: isWalletCorrectATA,
|
|
10456
|
-
getAccountWithType: getAccountWithType,
|
|
10457
|
-
getNativeWalletBalance: getNativeWalletBalance,
|
|
10458
|
-
getAssocSPLWalletBalance: getAssocSPLWalletBalance,
|
|
10459
|
-
getSPLWalletBalance: getSPLWalletBalance,
|
|
10460
|
-
getAllTokenAccountsWithBalances: getAllTokenAccountsWithBalances,
|
|
10461
|
-
getTokenAccountsWithBalance: getTokenAccountsWithBalance,
|
|
10462
|
-
buildReplenishWsolBalanceTransaction: buildReplenishWsolBalanceTransaction,
|
|
10463
|
-
updateWsolBalance: updateWsolBalance,
|
|
10464
|
-
checkIfAssociatedWalletExists: checkIfAssociatedWalletExists,
|
|
10465
|
-
getTransactionAccountsForSimulationDiff: getTransactionAccountsForSimulationDiff,
|
|
10466
|
-
parseMultipleAccounts: parseMultipleAccounts,
|
|
10467
|
-
getSplDiff: getSplDiff,
|
|
10468
|
-
getTransactionDiff: getTransactionDiff
|
|
10469
|
-
});
|
|
10470
|
-
|
|
10471
|
-
const deBridge = "DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh";
|
|
10472
|
-
const settings = "DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft";
|
|
10473
|
-
const dlnSrc = "src5qyZHqTqecJV4aY6Cb6zDZLMDzrDKKezs22MPHr4";
|
|
10474
|
-
const dlnDst = "dst5MGcFPoBeREFAA5E3tU5ij8m5uVYwkzkSAbsLbNo";
|
|
10475
|
-
const dlnExecutor = "exe59FS5cojZkPJVDFDV8RnXCC7wd6yoBjsUtqH7Zai";
|
|
10476
|
-
|
|
10477
|
-
var programs = /*#__PURE__*/Object.freeze({
|
|
10478
|
-
__proto__: null,
|
|
10479
|
-
deBridge: deBridge,
|
|
10480
|
-
settings: settings,
|
|
10481
|
-
dlnSrc: dlnSrc,
|
|
10482
|
-
dlnDst: dlnDst,
|
|
10483
|
-
dlnExecutor: dlnExecutor
|
|
10484
|
-
});
|
|
10485
|
-
|
|
10486
|
-
/** Address of the SPL Token program */
|
|
10487
|
-
new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
|
|
10488
|
-
/** Address of the SPL Token 2022 program */
|
|
10489
|
-
new PublicKey('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb');
|
|
10490
|
-
/** Address of the SPL Associated Token Account program */
|
|
10491
|
-
new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
10492
|
-
/** Address of the special mint for wrapped native SOL in spl-token */
|
|
10493
|
-
new PublicKey('So11111111111111111111111111111111111111112');
|
|
10494
|
-
/** Address of the special mint for wrapped native SOL in spl-token-2022 */
|
|
10495
|
-
new PublicKey('9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP');
|
|
10496
|
-
|
|
10497
|
-
/** Instructions defined by the program */
|
|
10498
|
-
var TokenInstruction;
|
|
10499
|
-
(function (TokenInstruction) {
|
|
10500
|
-
TokenInstruction[TokenInstruction["InitializeMint"] = 0] = "InitializeMint";
|
|
10501
|
-
TokenInstruction[TokenInstruction["InitializeAccount"] = 1] = "InitializeAccount";
|
|
10502
|
-
TokenInstruction[TokenInstruction["InitializeMultisig"] = 2] = "InitializeMultisig";
|
|
10503
|
-
TokenInstruction[TokenInstruction["Transfer"] = 3] = "Transfer";
|
|
10504
|
-
TokenInstruction[TokenInstruction["Approve"] = 4] = "Approve";
|
|
10505
|
-
TokenInstruction[TokenInstruction["Revoke"] = 5] = "Revoke";
|
|
10506
|
-
TokenInstruction[TokenInstruction["SetAuthority"] = 6] = "SetAuthority";
|
|
10507
|
-
TokenInstruction[TokenInstruction["MintTo"] = 7] = "MintTo";
|
|
10508
|
-
TokenInstruction[TokenInstruction["Burn"] = 8] = "Burn";
|
|
10509
|
-
TokenInstruction[TokenInstruction["CloseAccount"] = 9] = "CloseAccount";
|
|
10510
|
-
TokenInstruction[TokenInstruction["FreezeAccount"] = 10] = "FreezeAccount";
|
|
10511
|
-
TokenInstruction[TokenInstruction["ThawAccount"] = 11] = "ThawAccount";
|
|
10512
|
-
TokenInstruction[TokenInstruction["TransferChecked"] = 12] = "TransferChecked";
|
|
10513
|
-
TokenInstruction[TokenInstruction["ApproveChecked"] = 13] = "ApproveChecked";
|
|
10514
|
-
TokenInstruction[TokenInstruction["MintToChecked"] = 14] = "MintToChecked";
|
|
10515
|
-
TokenInstruction[TokenInstruction["BurnChecked"] = 15] = "BurnChecked";
|
|
10516
|
-
TokenInstruction[TokenInstruction["InitializeAccount2"] = 16] = "InitializeAccount2";
|
|
10517
|
-
TokenInstruction[TokenInstruction["SyncNative"] = 17] = "SyncNative";
|
|
10518
|
-
TokenInstruction[TokenInstruction["InitializeAccount3"] = 18] = "InitializeAccount3";
|
|
10519
|
-
TokenInstruction[TokenInstruction["InitializeMultisig2"] = 19] = "InitializeMultisig2";
|
|
10520
|
-
TokenInstruction[TokenInstruction["InitializeMint2"] = 20] = "InitializeMint2";
|
|
10521
|
-
TokenInstruction[TokenInstruction["GetAccountDataSize"] = 21] = "GetAccountDataSize";
|
|
10522
|
-
TokenInstruction[TokenInstruction["InitializeImmutableOwner"] = 22] = "InitializeImmutableOwner";
|
|
10523
|
-
TokenInstruction[TokenInstruction["AmountToUiAmount"] = 23] = "AmountToUiAmount";
|
|
10524
|
-
TokenInstruction[TokenInstruction["UiAmountToAmount"] = 24] = "UiAmountToAmount";
|
|
10525
|
-
TokenInstruction[TokenInstruction["InitializeMintCloseAuthority"] = 25] = "InitializeMintCloseAuthority";
|
|
10526
|
-
TokenInstruction[TokenInstruction["TransferFeeExtension"] = 26] = "TransferFeeExtension";
|
|
10527
|
-
TokenInstruction[TokenInstruction["ConfidentialTransferExtension"] = 27] = "ConfidentialTransferExtension";
|
|
10528
|
-
TokenInstruction[TokenInstruction["DefaultAccountStateExtension"] = 28] = "DefaultAccountStateExtension";
|
|
10529
|
-
TokenInstruction[TokenInstruction["Reallocate"] = 29] = "Reallocate";
|
|
10530
|
-
TokenInstruction[TokenInstruction["MemoTransferExtension"] = 30] = "MemoTransferExtension";
|
|
10531
|
-
TokenInstruction[TokenInstruction["CreateNativeMint"] = 31] = "CreateNativeMint";
|
|
10532
|
-
TokenInstruction[TokenInstruction["InitializeNonTransferableMint"] = 32] = "InitializeNonTransferableMint";
|
|
10533
|
-
TokenInstruction[TokenInstruction["InterestBearingMintExtension"] = 33] = "InterestBearingMintExtension";
|
|
10534
|
-
TokenInstruction[TokenInstruction["CpiGuardExtension"] = 34] = "CpiGuardExtension";
|
|
10535
|
-
TokenInstruction[TokenInstruction["InitializePermanentDelegate"] = 35] = "InitializePermanentDelegate";
|
|
10536
|
-
TokenInstruction[TokenInstruction["TransferHookExtension"] = 36] = "TransferHookExtension";
|
|
10537
|
-
// ConfidentialTransferFeeExtension = 37,
|
|
10538
|
-
// WithdrawalExcessLamports = 38,
|
|
10539
|
-
TokenInstruction[TokenInstruction["MetadataPointerExtension"] = 39] = "MetadataPointerExtension";
|
|
10540
|
-
TokenInstruction[TokenInstruction["GroupPointerExtension"] = 40] = "GroupPointerExtension";
|
|
10541
|
-
TokenInstruction[TokenInstruction["GroupMemberPointerExtension"] = 41] = "GroupMemberPointerExtension";
|
|
10542
|
-
// ConfidentialMintBurnExtension = 42,
|
|
10543
|
-
TokenInstruction[TokenInstruction["ScaledUiAmountExtension"] = 43] = "ScaledUiAmountExtension";
|
|
10544
|
-
TokenInstruction[TokenInstruction["PausableExtension"] = 44] = "PausableExtension";
|
|
10545
|
-
})(TokenInstruction || (TokenInstruction = {}));
|
|
10546
|
-
|
|
10547
|
-
/** TODO: docs */
|
|
10548
|
-
struct$1([
|
|
10549
|
-
u8$1('instruction'),
|
|
10550
|
-
u64$1('amount'),
|
|
10551
|
-
]);
|
|
10552
|
-
|
|
10553
|
-
var AccountType;
|
|
10554
|
-
(function (AccountType) {
|
|
10555
|
-
AccountType[AccountType["Uninitialized"] = 0] = "Uninitialized";
|
|
10556
|
-
AccountType[AccountType["Mint"] = 1] = "Mint";
|
|
10557
|
-
AccountType[AccountType["Account"] = 2] = "Account";
|
|
10558
|
-
})(AccountType || (AccountType = {}));
|
|
10559
|
-
|
|
10560
|
-
/** Buffer layout for de/serializing a multisig */
|
|
10561
|
-
const MultisigLayout = struct$1([
|
|
10562
|
-
u8$1('m'),
|
|
10563
|
-
u8$1('n'),
|
|
10564
|
-
bool$1('isInitialized'),
|
|
10565
|
-
publicKey$4('signer1'),
|
|
10566
|
-
publicKey$4('signer2'),
|
|
10567
|
-
publicKey$4('signer3'),
|
|
10568
|
-
publicKey$4('signer4'),
|
|
10569
|
-
publicKey$4('signer5'),
|
|
10570
|
-
publicKey$4('signer6'),
|
|
10571
|
-
publicKey$4('signer7'),
|
|
10572
|
-
publicKey$4('signer8'),
|
|
10573
|
-
publicKey$4('signer9'),
|
|
10574
|
-
publicKey$4('signer10'),
|
|
10575
|
-
publicKey$4('signer11'),
|
|
10576
|
-
]);
|
|
10577
|
-
/** Byte length of a multisig */
|
|
10578
|
-
MultisigLayout.span;
|
|
10579
|
-
|
|
10580
|
-
/** Token account state as stored by the program */
|
|
10581
|
-
var AccountState;
|
|
10582
|
-
(function (AccountState) {
|
|
10583
|
-
AccountState[AccountState["Uninitialized"] = 0] = "Uninitialized";
|
|
10584
|
-
AccountState[AccountState["Initialized"] = 1] = "Initialized";
|
|
10585
|
-
AccountState[AccountState["Frozen"] = 2] = "Frozen";
|
|
10586
|
-
})(AccountState || (AccountState = {}));
|
|
10587
|
-
/** Buffer layout for de/serializing a token account */
|
|
10588
|
-
const AccountLayout = struct$1([
|
|
10589
|
-
publicKey$4('mint'),
|
|
10590
|
-
publicKey$4('owner'),
|
|
10591
|
-
u64$1('amount'),
|
|
10592
|
-
u32$1('delegateOption'),
|
|
10593
|
-
publicKey$4('delegate'),
|
|
10594
|
-
u8$1('state'),
|
|
10595
|
-
u32$1('isNativeOption'),
|
|
10596
|
-
u64$1('isNative'),
|
|
10597
|
-
u64$1('delegatedAmount'),
|
|
10598
|
-
u32$1('closeAuthorityOption'),
|
|
10599
|
-
publicKey$4('closeAuthority'),
|
|
10600
|
-
]);
|
|
10601
|
-
/** Byte length of a token account */
|
|
10602
|
-
AccountLayout.span;
|
|
10603
|
-
|
|
10604
|
-
var CpiGuardInstruction;
|
|
10605
|
-
(function (CpiGuardInstruction) {
|
|
10606
|
-
CpiGuardInstruction[CpiGuardInstruction["Enable"] = 0] = "Enable";
|
|
10607
|
-
CpiGuardInstruction[CpiGuardInstruction["Disable"] = 1] = "Disable";
|
|
10608
|
-
})(CpiGuardInstruction || (CpiGuardInstruction = {}));
|
|
10609
|
-
/** TODO: docs */
|
|
10610
|
-
struct$1([u8$1('instruction'), u8$1('cpiGuardInstruction')]);
|
|
10611
|
-
|
|
10612
|
-
/** Buffer layout for de/serializing a CPI Guard extension */
|
|
10613
|
-
const CpiGuardLayout = struct$1([bool$1('lockCpi')]);
|
|
10614
|
-
CpiGuardLayout.span;
|
|
10615
|
-
|
|
10616
|
-
var DefaultAccountStateInstruction;
|
|
10617
|
-
(function (DefaultAccountStateInstruction) {
|
|
10618
|
-
DefaultAccountStateInstruction[DefaultAccountStateInstruction["Initialize"] = 0] = "Initialize";
|
|
10619
|
-
DefaultAccountStateInstruction[DefaultAccountStateInstruction["Update"] = 1] = "Update";
|
|
10620
|
-
})(DefaultAccountStateInstruction || (DefaultAccountStateInstruction = {}));
|
|
10621
|
-
/** TODO: docs */
|
|
10622
|
-
struct$1([
|
|
10623
|
-
u8$1('instruction'),
|
|
10624
|
-
u8$1('defaultAccountStateInstruction'),
|
|
10625
|
-
u8$1('accountState'),
|
|
10626
|
-
]);
|
|
10627
|
-
|
|
10628
|
-
/** Buffer layout for de/serializing a transfer fee config extension */
|
|
10629
|
-
const DefaultAccountStateLayout = struct$1([u8$1('state')]);
|
|
10630
|
-
DefaultAccountStateLayout.span;
|
|
10631
|
-
|
|
10632
|
-
// src/codes.ts
|
|
10633
|
-
var SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY$2 = 8078e3;
|
|
10634
|
-
var SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH$2 = 8078001;
|
|
10635
|
-
var SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH$2 = 8078004;
|
|
10636
|
-
var SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH$2 = 8078005;
|
|
10637
|
-
var SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH$2 = 8078006;
|
|
10638
|
-
var SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE$2 = 8078011;
|
|
10639
|
-
|
|
10640
|
-
// src/context.ts
|
|
10641
|
-
function encodeValue$2(value) {
|
|
10642
|
-
if (Array.isArray(value)) {
|
|
10643
|
-
const commaSeparatedValues = value.map(encodeValue$2).join(
|
|
10644
|
-
"%2C%20"
|
|
10645
|
-
/* ", " */
|
|
10646
|
-
);
|
|
10647
|
-
return "%5B" + commaSeparatedValues + /* "]" */
|
|
10648
|
-
"%5D";
|
|
10649
|
-
} else if (typeof value === "bigint") {
|
|
10650
|
-
return `${value}n`;
|
|
10651
|
-
} else {
|
|
10652
|
-
return encodeURIComponent(
|
|
10653
|
-
String(
|
|
10654
|
-
value != null && Object.getPrototypeOf(value) === null ? (
|
|
10655
|
-
// Plain objects with no prototype don't have a `toString` method.
|
|
10656
|
-
// Convert them before stringifying them.
|
|
10657
|
-
{ ...value }
|
|
10658
|
-
) : value
|
|
10659
|
-
)
|
|
10660
|
-
);
|
|
10661
|
-
}
|
|
10662
|
-
}
|
|
10663
|
-
function encodeObjectContextEntry$2([key, value]) {
|
|
10664
|
-
return `${key}=${encodeValue$2(value)}`;
|
|
10665
|
-
}
|
|
10666
|
-
function encodeContextObject$2(context) {
|
|
10667
|
-
const searchParamsString = Object.entries(context).map(encodeObjectContextEntry$2).join("&");
|
|
10668
|
-
return btoa(searchParamsString);
|
|
10669
|
-
}
|
|
10670
|
-
function getErrorMessage$2(code, context = {}) {
|
|
10671
|
-
{
|
|
10672
|
-
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode -- ${code}`;
|
|
10673
|
-
if (Object.keys(context).length) {
|
|
10674
|
-
decodingAdviceMessage += ` '${encodeContextObject$2(context)}'`;
|
|
10675
|
-
}
|
|
10676
|
-
return `${decodingAdviceMessage}\``;
|
|
10677
|
-
}
|
|
10412
|
+
function isLittleEndian$1(config) {
|
|
10413
|
+
return config?.endian === 1 /* Big */ ? false : true;
|
|
10678
10414
|
}
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
if (contextAndErrorOptions) {
|
|
10686
|
-
const { cause, ...contextRest } = contextAndErrorOptions;
|
|
10687
|
-
if (cause) {
|
|
10688
|
-
errorOptions = { cause };
|
|
10689
|
-
}
|
|
10690
|
-
if (Object.keys(contextRest).length > 0) {
|
|
10691
|
-
context = contextRest;
|
|
10415
|
+
function numberEncoderFactory$1(input) {
|
|
10416
|
+
return createEncoder$1({
|
|
10417
|
+
fixedSize: input.size,
|
|
10418
|
+
write(value, bytes, offset) {
|
|
10419
|
+
if (input.range) {
|
|
10420
|
+
assertNumberIsBetweenForCodec$1(input.name, input.range[0], input.range[1], value);
|
|
10692
10421
|
}
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
__code: code,
|
|
10698
|
-
...context
|
|
10699
|
-
};
|
|
10700
|
-
this.name = "SolanaError";
|
|
10701
|
-
}
|
|
10702
|
-
};
|
|
10703
|
-
|
|
10704
|
-
var padBytes$2 = (bytes, length) => {
|
|
10705
|
-
if (bytes.length >= length) return bytes;
|
|
10706
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
10707
|
-
paddedBytes.set(bytes);
|
|
10708
|
-
return paddedBytes;
|
|
10709
|
-
};
|
|
10710
|
-
var fixBytes$2 = (bytes, length) => padBytes$2(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
10711
|
-
function getEncodedSize$2(value, encoder) {
|
|
10712
|
-
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
|
|
10713
|
-
}
|
|
10714
|
-
function createEncoder$2(encoder) {
|
|
10715
|
-
return Object.freeze({
|
|
10716
|
-
...encoder,
|
|
10717
|
-
encode: (value) => {
|
|
10718
|
-
const bytes = new Uint8Array(getEncodedSize$2(value, encoder));
|
|
10719
|
-
encoder.write(value, bytes, 0);
|
|
10720
|
-
return bytes;
|
|
10422
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
10423
|
+
input.set(new DataView(arrayBuffer), value, isLittleEndian$1(input.config));
|
|
10424
|
+
bytes.set(new Uint8Array(arrayBuffer), offset);
|
|
10425
|
+
return offset + input.size;
|
|
10721
10426
|
}
|
|
10722
10427
|
});
|
|
10723
10428
|
}
|
|
10724
|
-
function
|
|
10725
|
-
return
|
|
10726
|
-
|
|
10727
|
-
|
|
10429
|
+
function numberDecoderFactory$1(input) {
|
|
10430
|
+
return createDecoder$1({
|
|
10431
|
+
fixedSize: input.size,
|
|
10432
|
+
read(bytes, offset = 0) {
|
|
10433
|
+
assertByteArrayIsNotEmptyForCodec$1(input.name, bytes, offset);
|
|
10434
|
+
assertByteArrayHasEnoughBytesForCodec$1(input.name, input.size, bytes, offset);
|
|
10435
|
+
const view = new DataView(toArrayBuffer$1(bytes, offset, input.size));
|
|
10436
|
+
return [input.get(view, isLittleEndian$1(input.config)), offset + input.size];
|
|
10437
|
+
}
|
|
10728
10438
|
});
|
|
10729
10439
|
}
|
|
10730
|
-
function
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
if (isFixedSize$2(encoder) !== isFixedSize$2(decoder)) {
|
|
10735
|
-
throw new SolanaError$2(SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH$2);
|
|
10736
|
-
}
|
|
10737
|
-
if (isFixedSize$2(encoder) && isFixedSize$2(decoder) && encoder.fixedSize !== decoder.fixedSize) {
|
|
10738
|
-
throw new SolanaError$2(SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH$2, {
|
|
10739
|
-
decoderFixedSize: decoder.fixedSize,
|
|
10740
|
-
encoderFixedSize: encoder.fixedSize
|
|
10741
|
-
});
|
|
10742
|
-
}
|
|
10743
|
-
if (!isFixedSize$2(encoder) && !isFixedSize$2(decoder) && encoder.maxSize !== decoder.maxSize) {
|
|
10744
|
-
throw new SolanaError$2(SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH$2, {
|
|
10745
|
-
decoderMaxSize: decoder.maxSize,
|
|
10746
|
-
encoderMaxSize: encoder.maxSize
|
|
10747
|
-
});
|
|
10748
|
-
}
|
|
10749
|
-
return {
|
|
10750
|
-
...decoder,
|
|
10751
|
-
...encoder,
|
|
10752
|
-
decode: decoder.decode,
|
|
10753
|
-
encode: encoder.encode,
|
|
10754
|
-
read: decoder.read,
|
|
10755
|
-
write: encoder.write
|
|
10756
|
-
};
|
|
10757
|
-
}
|
|
10758
|
-
function assertByteArrayIsNotEmptyForCodec$2(codecDescription, bytes, offset = 0) {
|
|
10759
|
-
if (bytes.length - offset <= 0) {
|
|
10760
|
-
throw new SolanaError$2(SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY$2, {
|
|
10761
|
-
codecDescription
|
|
10762
|
-
});
|
|
10763
|
-
}
|
|
10440
|
+
function toArrayBuffer$1(bytes, offset, length) {
|
|
10441
|
+
const bytesOffset = bytes.byteOffset + (offset ?? 0);
|
|
10442
|
+
const bytesLength = length ?? bytes.byteLength;
|
|
10443
|
+
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
10764
10444
|
}
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10445
|
+
var getU32Encoder$1 = (config = {}) => numberEncoderFactory$1({
|
|
10446
|
+
config,
|
|
10447
|
+
name: "u32",
|
|
10448
|
+
range: [0, Number("0xffffffff")],
|
|
10449
|
+
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
10450
|
+
size: 4
|
|
10451
|
+
});
|
|
10452
|
+
var getU32Decoder$1 = (config = {}) => numberDecoderFactory$1({
|
|
10453
|
+
config,
|
|
10454
|
+
get: (view, le) => view.getUint32(0, le),
|
|
10455
|
+
name: "u32",
|
|
10456
|
+
size: 4
|
|
10457
|
+
});
|
|
10458
|
+
var getU32Codec = (config = {}) => combineCodec$1(getU32Encoder$1(config), getU32Decoder$1(config));
|
|
10459
|
+
var getU64Encoder$1 = (config = {}) => numberEncoderFactory$1({
|
|
10460
|
+
config,
|
|
10461
|
+
name: "u64",
|
|
10462
|
+
range: [0n, BigInt("0xffffffffffffffff")],
|
|
10463
|
+
set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),
|
|
10464
|
+
size: 8
|
|
10465
|
+
});
|
|
10466
|
+
var getU64Decoder$1 = (config = {}) => numberDecoderFactory$1({
|
|
10467
|
+
config,
|
|
10468
|
+
get: (view, le) => view.getBigUint64(0, le),
|
|
10469
|
+
name: "u64",
|
|
10470
|
+
size: 8
|
|
10471
|
+
});
|
|
10472
|
+
var getU64Codec$1 = (config = {}) => combineCodec$1(getU64Encoder$1(config), getU64Decoder$1(config));
|
|
10473
|
+
|
|
10474
|
+
// src/array.ts
|
|
10475
|
+
function assertValidNumberOfItemsForCodec$1(codecDescription, expected, actual) {
|
|
10476
|
+
if (expected !== actual) {
|
|
10477
|
+
throw new SolanaError$1(SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS$1, {
|
|
10478
|
+
actual,
|
|
10770
10479
|
codecDescription,
|
|
10771
10480
|
expected
|
|
10772
10481
|
});
|
|
10773
10482
|
}
|
|
10774
10483
|
}
|
|
10484
|
+
function sumCodecSizes$1(sizes) {
|
|
10485
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
10486
|
+
}
|
|
10487
|
+
function getFixedSize$1(codec) {
|
|
10488
|
+
return isFixedSize$1(codec) ? codec.fixedSize : null;
|
|
10489
|
+
}
|
|
10490
|
+
function getMaxSize$1(codec) {
|
|
10491
|
+
return isFixedSize$1(codec) ? codec.fixedSize : codec.maxSize ?? null;
|
|
10492
|
+
}
|
|
10775
10493
|
|
|
10776
|
-
// src/
|
|
10777
|
-
function
|
|
10778
|
-
|
|
10779
|
-
|
|
10780
|
-
|
|
10781
|
-
|
|
10782
|
-
|
|
10783
|
-
|
|
10784
|
-
|
|
10494
|
+
// src/array.ts
|
|
10495
|
+
function getArrayEncoder$1(item, config = {}) {
|
|
10496
|
+
const size = config.size ?? getU32Encoder$1();
|
|
10497
|
+
const fixedSize = computeArrayLikeCodecSize$1(size, getFixedSize$1(item));
|
|
10498
|
+
const maxSize = computeArrayLikeCodecSize$1(size, getMaxSize$1(item)) ?? void 0;
|
|
10499
|
+
return createEncoder$1({
|
|
10500
|
+
...fixedSize !== null ? { fixedSize } : {
|
|
10501
|
+
getSizeFromValue: (array) => {
|
|
10502
|
+
const prefixSize = typeof size === "object" ? getEncodedSize$1(array.length, size) : 0;
|
|
10503
|
+
return prefixSize + [...array].reduce((all, value) => all + getEncodedSize$1(value, item), 0);
|
|
10504
|
+
},
|
|
10505
|
+
maxSize
|
|
10506
|
+
},
|
|
10507
|
+
write: (array, bytes, offset) => {
|
|
10508
|
+
if (typeof size === "number") {
|
|
10509
|
+
assertValidNumberOfItemsForCodec$1("array", size, array.length);
|
|
10510
|
+
}
|
|
10511
|
+
if (typeof size === "object") {
|
|
10512
|
+
offset = size.write(array.length, bytes, offset);
|
|
10513
|
+
}
|
|
10514
|
+
array.forEach((value) => {
|
|
10515
|
+
offset = item.write(value, bytes, offset);
|
|
10516
|
+
});
|
|
10517
|
+
return offset;
|
|
10785
10518
|
}
|
|
10786
10519
|
});
|
|
10787
10520
|
}
|
|
10788
|
-
function
|
|
10789
|
-
|
|
10790
|
-
|
|
10521
|
+
function getArrayDecoder$1(item, config = {}) {
|
|
10522
|
+
const size = config.size ?? getU32Decoder$1();
|
|
10523
|
+
const itemSize = getFixedSize$1(item);
|
|
10524
|
+
const fixedSize = computeArrayLikeCodecSize$1(size, itemSize);
|
|
10525
|
+
const maxSize = computeArrayLikeCodecSize$1(size, getMaxSize$1(item)) ?? void 0;
|
|
10526
|
+
return createDecoder$1({
|
|
10527
|
+
...fixedSize !== null ? { fixedSize } : { maxSize },
|
|
10791
10528
|
read: (bytes, offset) => {
|
|
10792
|
-
|
|
10793
|
-
if (
|
|
10794
|
-
|
|
10529
|
+
const array = [];
|
|
10530
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
10531
|
+
return [array, offset];
|
|
10795
10532
|
}
|
|
10796
|
-
if (
|
|
10797
|
-
|
|
10533
|
+
if (size === "remainder") {
|
|
10534
|
+
while (offset < bytes.length) {
|
|
10535
|
+
const [value, newOffset2] = item.read(bytes, offset);
|
|
10536
|
+
offset = newOffset2;
|
|
10537
|
+
array.push(value);
|
|
10538
|
+
}
|
|
10539
|
+
return [array, offset];
|
|
10798
10540
|
}
|
|
10799
|
-
const [
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
return combineCodec$2(fixEncoderSize$2(codec, fixedBytes), fixDecoderSize$2(codec, fixedBytes));
|
|
10806
|
-
}
|
|
10807
|
-
|
|
10808
|
-
// src/assertions.ts
|
|
10809
|
-
function assertNumberIsBetweenForCodec$2(codecDescription, min, max, value) {
|
|
10810
|
-
if (value < min || value > max) {
|
|
10811
|
-
throw new SolanaError$2(SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE$2, {
|
|
10812
|
-
codecDescription,
|
|
10813
|
-
max,
|
|
10814
|
-
min,
|
|
10815
|
-
value
|
|
10816
|
-
});
|
|
10817
|
-
}
|
|
10818
|
-
}
|
|
10819
|
-
function isLittleEndian$2(config) {
|
|
10820
|
-
return config?.endian === 1 /* Big */ ? false : true;
|
|
10821
|
-
}
|
|
10822
|
-
function numberEncoderFactory$2(input) {
|
|
10823
|
-
return createEncoder$2({
|
|
10824
|
-
fixedSize: input.size,
|
|
10825
|
-
write(value, bytes, offset) {
|
|
10826
|
-
if (input.range) {
|
|
10827
|
-
assertNumberIsBetweenForCodec$2(input.name, input.range[0], input.range[1], value);
|
|
10541
|
+
const [resolvedSize, newOffset] = typeof size === "number" ? [size, offset] : size.read(bytes, offset);
|
|
10542
|
+
offset = newOffset;
|
|
10543
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
10544
|
+
const [value, newOffset2] = item.read(bytes, offset);
|
|
10545
|
+
offset = newOffset2;
|
|
10546
|
+
array.push(value);
|
|
10828
10547
|
}
|
|
10829
|
-
|
|
10830
|
-
input.set(new DataView(arrayBuffer), value, isLittleEndian$2(input.config));
|
|
10831
|
-
bytes.set(new Uint8Array(arrayBuffer), offset);
|
|
10832
|
-
return offset + input.size;
|
|
10833
|
-
}
|
|
10834
|
-
});
|
|
10835
|
-
}
|
|
10836
|
-
function numberDecoderFactory$2(input) {
|
|
10837
|
-
return createDecoder$2({
|
|
10838
|
-
fixedSize: input.size,
|
|
10839
|
-
read(bytes, offset = 0) {
|
|
10840
|
-
assertByteArrayIsNotEmptyForCodec$2(input.name, bytes, offset);
|
|
10841
|
-
assertByteArrayHasEnoughBytesForCodec$2(input.name, input.size, bytes, offset);
|
|
10842
|
-
const view = new DataView(toArrayBuffer$2(bytes, offset, input.size));
|
|
10843
|
-
return [input.get(view, isLittleEndian$2(input.config)), offset + input.size];
|
|
10548
|
+
return [array, offset];
|
|
10844
10549
|
}
|
|
10845
10550
|
});
|
|
10846
10551
|
}
|
|
10847
|
-
function
|
|
10848
|
-
|
|
10849
|
-
const bytesLength = length ?? bytes.byteLength;
|
|
10850
|
-
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
10851
|
-
}
|
|
10852
|
-
var getU64Encoder$1 = (config = {}) => numberEncoderFactory$2({
|
|
10853
|
-
config,
|
|
10854
|
-
name: "u64",
|
|
10855
|
-
range: [0n, BigInt("0xffffffffffffffff")],
|
|
10856
|
-
set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),
|
|
10857
|
-
size: 8
|
|
10858
|
-
});
|
|
10859
|
-
var getU64Decoder$1 = (config = {}) => numberDecoderFactory$2({
|
|
10860
|
-
config,
|
|
10861
|
-
get: (view, le) => view.getBigUint64(0, le),
|
|
10862
|
-
name: "u64",
|
|
10863
|
-
size: 8
|
|
10864
|
-
});
|
|
10865
|
-
var getU64Codec$1 = (config = {}) => combineCodec$2(getU64Encoder$1(config), getU64Decoder$1(config));
|
|
10866
|
-
|
|
10867
|
-
function sumCodecSizes$2(sizes) {
|
|
10868
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
10869
|
-
}
|
|
10870
|
-
function getFixedSize$2(codec) {
|
|
10871
|
-
return isFixedSize$2(codec) ? codec.fixedSize : null;
|
|
10552
|
+
function getArrayCodec$1(item, config = {}) {
|
|
10553
|
+
return combineCodec$1(getArrayEncoder$1(item, config), getArrayDecoder$1(item, config));
|
|
10872
10554
|
}
|
|
10873
|
-
function
|
|
10874
|
-
|
|
10555
|
+
function computeArrayLikeCodecSize$1(size, itemSize) {
|
|
10556
|
+
if (typeof size !== "number") return null;
|
|
10557
|
+
if (size === 0) return 0;
|
|
10558
|
+
return itemSize === null ? null : itemSize * size;
|
|
10875
10559
|
}
|
|
10876
|
-
function getBytesEncoder$
|
|
10877
|
-
return createEncoder$
|
|
10560
|
+
function getBytesEncoder$1() {
|
|
10561
|
+
return createEncoder$1({
|
|
10878
10562
|
getSizeFromValue: (value) => value.length,
|
|
10879
10563
|
write: (value, bytes, offset) => {
|
|
10880
10564
|
bytes.set(value, offset);
|
|
@@ -10882,24 +10566,63 @@ function getBytesEncoder$2() {
|
|
|
10882
10566
|
}
|
|
10883
10567
|
});
|
|
10884
10568
|
}
|
|
10885
|
-
function getBytesDecoder$
|
|
10886
|
-
return createDecoder$
|
|
10569
|
+
function getBytesDecoder$1() {
|
|
10570
|
+
return createDecoder$1({
|
|
10887
10571
|
read: (bytes, offset) => {
|
|
10888
10572
|
const slice = bytes.slice(offset);
|
|
10889
10573
|
return [slice, offset + slice.length];
|
|
10890
10574
|
}
|
|
10891
10575
|
});
|
|
10892
10576
|
}
|
|
10893
|
-
function getBytesCodec$
|
|
10894
|
-
return combineCodec$
|
|
10577
|
+
function getBytesCodec$1() {
|
|
10578
|
+
return combineCodec$1(getBytesEncoder$1(), getBytesDecoder$1());
|
|
10579
|
+
}
|
|
10580
|
+
function getTupleEncoder$1(items) {
|
|
10581
|
+
const fixedSize = sumCodecSizes$1(items.map(getFixedSize$1));
|
|
10582
|
+
const maxSize = sumCodecSizes$1(items.map(getMaxSize$1)) ?? void 0;
|
|
10583
|
+
return createEncoder$1({
|
|
10584
|
+
...fixedSize === null ? {
|
|
10585
|
+
getSizeFromValue: (value) => items.map((item, index) => getEncodedSize$1(value[index], item)).reduce((all, one) => all + one, 0),
|
|
10586
|
+
maxSize
|
|
10587
|
+
} : { fixedSize },
|
|
10588
|
+
write: (value, bytes, offset) => {
|
|
10589
|
+
assertValidNumberOfItemsForCodec$1("tuple", items.length, value.length);
|
|
10590
|
+
items.forEach((item, index) => {
|
|
10591
|
+
offset = item.write(value[index], bytes, offset);
|
|
10592
|
+
});
|
|
10593
|
+
return offset;
|
|
10594
|
+
}
|
|
10595
|
+
});
|
|
10596
|
+
}
|
|
10597
|
+
function getTupleDecoder$1(items) {
|
|
10598
|
+
const fixedSize = sumCodecSizes$1(items.map(getFixedSize$1));
|
|
10599
|
+
const maxSize = sumCodecSizes$1(items.map(getMaxSize$1)) ?? void 0;
|
|
10600
|
+
return createDecoder$1({
|
|
10601
|
+
...fixedSize === null ? { maxSize } : { fixedSize },
|
|
10602
|
+
read: (bytes, offset) => {
|
|
10603
|
+
const values = [];
|
|
10604
|
+
items.forEach((item) => {
|
|
10605
|
+
const [newValue, newOffset] = item.read(bytes, offset);
|
|
10606
|
+
values.push(newValue);
|
|
10607
|
+
offset = newOffset;
|
|
10608
|
+
});
|
|
10609
|
+
return [values, offset];
|
|
10610
|
+
}
|
|
10611
|
+
});
|
|
10612
|
+
}
|
|
10613
|
+
function getTupleCodec$1(items) {
|
|
10614
|
+
return combineCodec$1(
|
|
10615
|
+
getTupleEncoder$1(items),
|
|
10616
|
+
getTupleDecoder$1(items)
|
|
10617
|
+
);
|
|
10895
10618
|
}
|
|
10896
|
-
function getStructEncoder$
|
|
10619
|
+
function getStructEncoder$1(fields) {
|
|
10897
10620
|
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
10898
|
-
const fixedSize = sumCodecSizes$
|
|
10899
|
-
const maxSize = sumCodecSizes$
|
|
10900
|
-
return createEncoder$
|
|
10621
|
+
const fixedSize = sumCodecSizes$1(fieldCodecs.map(getFixedSize$1));
|
|
10622
|
+
const maxSize = sumCodecSizes$1(fieldCodecs.map(getMaxSize$1)) ?? void 0;
|
|
10623
|
+
return createEncoder$1({
|
|
10901
10624
|
...fixedSize === null ? {
|
|
10902
|
-
getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize$
|
|
10625
|
+
getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize$1(value[key], codec)).reduce((all, one) => all + one, 0),
|
|
10903
10626
|
maxSize
|
|
10904
10627
|
} : { fixedSize },
|
|
10905
10628
|
write: (struct, bytes, offset) => {
|
|
@@ -10910,11 +10633,11 @@ function getStructEncoder$2(fields) {
|
|
|
10910
10633
|
}
|
|
10911
10634
|
});
|
|
10912
10635
|
}
|
|
10913
|
-
function getStructDecoder$
|
|
10636
|
+
function getStructDecoder$1(fields) {
|
|
10914
10637
|
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
10915
|
-
const fixedSize = sumCodecSizes$
|
|
10916
|
-
const maxSize = sumCodecSizes$
|
|
10917
|
-
return createDecoder$
|
|
10638
|
+
const fixedSize = sumCodecSizes$1(fieldCodecs.map(getFixedSize$1));
|
|
10639
|
+
const maxSize = sumCodecSizes$1(fieldCodecs.map(getMaxSize$1)) ?? void 0;
|
|
10640
|
+
return createDecoder$1({
|
|
10918
10641
|
...fixedSize === null ? { maxSize } : { fixedSize },
|
|
10919
10642
|
read: (bytes, offset) => {
|
|
10920
10643
|
const struct = {};
|
|
@@ -10927,24 +10650,57 @@ function getStructDecoder$2(fields) {
|
|
|
10927
10650
|
}
|
|
10928
10651
|
});
|
|
10929
10652
|
}
|
|
10930
|
-
function getStructCodec$
|
|
10931
|
-
return combineCodec$
|
|
10932
|
-
getStructEncoder$
|
|
10933
|
-
getStructDecoder$
|
|
10653
|
+
function getStructCodec$1(fields) {
|
|
10654
|
+
return combineCodec$1(
|
|
10655
|
+
getStructEncoder$1(fields),
|
|
10656
|
+
getStructDecoder$1(fields)
|
|
10934
10657
|
);
|
|
10935
10658
|
}
|
|
10936
10659
|
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10660
|
+
// src/null-characters.ts
|
|
10661
|
+
var removeNullCharacters$1 = (value) => (
|
|
10662
|
+
// eslint-disable-next-line no-control-regex
|
|
10663
|
+
value.replace(/\u0000/g, "")
|
|
10664
|
+
);
|
|
10665
|
+
|
|
10666
|
+
// ../text-encoding-impl/dist/index.browser.mjs
|
|
10667
|
+
var e$1 = globalThis.TextDecoder;
|
|
10668
|
+
var o$1 = globalThis.TextEncoder;
|
|
10669
|
+
|
|
10670
|
+
// src/utf8.ts
|
|
10671
|
+
var getUtf8Encoder$1 = () => {
|
|
10672
|
+
let textEncoder;
|
|
10673
|
+
return createEncoder$1({
|
|
10674
|
+
getSizeFromValue: (value) => (textEncoder ||= new o$1()).encode(value).length,
|
|
10675
|
+
write: (value, bytes, offset) => {
|
|
10676
|
+
const bytesToAdd = (textEncoder ||= new o$1()).encode(value);
|
|
10677
|
+
bytes.set(bytesToAdd, offset);
|
|
10678
|
+
return offset + bytesToAdd.length;
|
|
10679
|
+
}
|
|
10680
|
+
});
|
|
10681
|
+
};
|
|
10682
|
+
var getUtf8Decoder$1 = () => {
|
|
10683
|
+
let textDecoder;
|
|
10684
|
+
return createDecoder$1({
|
|
10685
|
+
read(bytes, offset) {
|
|
10686
|
+
const value = (textDecoder ||= new e$1()).decode(bytes.slice(offset));
|
|
10687
|
+
return [removeNullCharacters$1(value), bytes.length];
|
|
10688
|
+
}
|
|
10689
|
+
});
|
|
10690
|
+
};
|
|
10691
|
+
var getUtf8Codec$1 = () => combineCodec$1(getUtf8Encoder$1(), getUtf8Decoder$1());
|
|
10692
|
+
|
|
10693
|
+
const tokenGroupCodec = getStructCodec$1([
|
|
10694
|
+
['updateAuthority', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
10695
|
+
['mint', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
10940
10696
|
['size', getU64Codec$1()],
|
|
10941
10697
|
['maxSize', getU64Codec$1()],
|
|
10942
10698
|
]);
|
|
10943
10699
|
tokenGroupCodec.fixedSize;
|
|
10944
10700
|
|
|
10945
|
-
const tokenGroupMemberCodec = getStructCodec$
|
|
10946
|
-
['mint', fixCodecSize$
|
|
10947
|
-
['group', fixCodecSize$
|
|
10701
|
+
const tokenGroupMemberCodec = getStructCodec$1([
|
|
10702
|
+
['mint', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
10703
|
+
['group', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
10948
10704
|
['memberNumber', getU64Codec$1()],
|
|
10949
10705
|
]);
|
|
10950
10706
|
tokenGroupMemberCodec.fixedSize;
|
|
@@ -10997,6 +10753,20 @@ const MetadataPointerLayout = struct$1([
|
|
|
10997
10753
|
publicKey$4('metadataAddress'),
|
|
10998
10754
|
]);
|
|
10999
10755
|
MetadataPointerLayout.span;
|
|
10756
|
+
function getMetadataPointerState(mint) {
|
|
10757
|
+
const extensionData = getExtensionData(ExtensionType.MetadataPointer, mint.tlvData);
|
|
10758
|
+
if (extensionData !== null) {
|
|
10759
|
+
const { authority, metadataAddress } = MetadataPointerLayout.decode(extensionData);
|
|
10760
|
+
// Explicitly set None/Zero keys to null
|
|
10761
|
+
return {
|
|
10762
|
+
authority: authority.equals(PublicKey.default) ? null : authority,
|
|
10763
|
+
metadataAddress: metadataAddress.equals(PublicKey.default) ? null : metadataAddress,
|
|
10764
|
+
};
|
|
10765
|
+
}
|
|
10766
|
+
else {
|
|
10767
|
+
return null;
|
|
10768
|
+
}
|
|
10769
|
+
}
|
|
11000
10770
|
|
|
11001
10771
|
/** Buffer layout for de/serializing a mint */
|
|
11002
10772
|
const MintCloseAuthorityLayout = struct$1([publicKey$4('closeAuthority')]);
|
|
@@ -11237,6 +11007,35 @@ var ExtensionType;
|
|
|
11237
11007
|
ExtensionType[ExtensionType["PausableConfig"] = 26] = "PausableConfig";
|
|
11238
11008
|
ExtensionType[ExtensionType["PausableAccount"] = 27] = "PausableAccount";
|
|
11239
11009
|
})(ExtensionType || (ExtensionType = {}));
|
|
11010
|
+
const TYPE_SIZE = 2;
|
|
11011
|
+
const LENGTH_SIZE = 2;
|
|
11012
|
+
function addTypeAndLengthToLen(len) {
|
|
11013
|
+
return len + TYPE_SIZE + LENGTH_SIZE;
|
|
11014
|
+
}
|
|
11015
|
+
function getExtensionData(extension, tlvData) {
|
|
11016
|
+
let extensionTypeIndex = 0;
|
|
11017
|
+
while (addTypeAndLengthToLen(extensionTypeIndex) <= tlvData.length) {
|
|
11018
|
+
const entryType = tlvData.readUInt16LE(extensionTypeIndex);
|
|
11019
|
+
const entryLength = tlvData.readUInt16LE(extensionTypeIndex + TYPE_SIZE);
|
|
11020
|
+
const typeIndex = addTypeAndLengthToLen(extensionTypeIndex);
|
|
11021
|
+
if (entryType == extension) {
|
|
11022
|
+
return tlvData.slice(typeIndex, typeIndex + entryLength);
|
|
11023
|
+
}
|
|
11024
|
+
extensionTypeIndex = typeIndex + entryLength;
|
|
11025
|
+
}
|
|
11026
|
+
return null;
|
|
11027
|
+
}
|
|
11028
|
+
function getExtensionTypes(tlvData) {
|
|
11029
|
+
const extensionTypes = [];
|
|
11030
|
+
let extensionTypeIndex = 0;
|
|
11031
|
+
while (extensionTypeIndex < tlvData.length) {
|
|
11032
|
+
const entryType = tlvData.readUInt16LE(extensionTypeIndex);
|
|
11033
|
+
extensionTypes.push(entryType);
|
|
11034
|
+
const entryLength = tlvData.readUInt16LE(extensionTypeIndex + TYPE_SIZE);
|
|
11035
|
+
extensionTypeIndex += addTypeAndLengthToLen(entryLength);
|
|
11036
|
+
}
|
|
11037
|
+
return extensionTypes;
|
|
11038
|
+
}
|
|
11240
11039
|
|
|
11241
11040
|
/** Buffer layout for de/serializing a mint */
|
|
11242
11041
|
const MintLayout = struct$1([
|
|
@@ -11249,7 +11048,46 @@ const MintLayout = struct$1([
|
|
|
11249
11048
|
publicKey$4('freezeAuthority'),
|
|
11250
11049
|
]);
|
|
11251
11050
|
/** Byte length of a mint */
|
|
11252
|
-
MintLayout.span;
|
|
11051
|
+
const MINT_SIZE = MintLayout.span;
|
|
11052
|
+
/**
|
|
11053
|
+
* Unpack a mint
|
|
11054
|
+
*
|
|
11055
|
+
* @param address Mint account
|
|
11056
|
+
* @param info Mint account data
|
|
11057
|
+
* @param programId SPL Token program account
|
|
11058
|
+
*
|
|
11059
|
+
* @return Unpacked mint
|
|
11060
|
+
*/
|
|
11061
|
+
function unpackMint(address, info, programId = TOKEN_PROGRAM_ID) {
|
|
11062
|
+
if (!info)
|
|
11063
|
+
throw new TokenAccountNotFoundError();
|
|
11064
|
+
if (!info.owner.equals(programId))
|
|
11065
|
+
throw new TokenInvalidAccountOwnerError();
|
|
11066
|
+
if (info.data.length < MINT_SIZE)
|
|
11067
|
+
throw new TokenInvalidAccountSizeError();
|
|
11068
|
+
const rawMint = MintLayout.decode(info.data.slice(0, MINT_SIZE));
|
|
11069
|
+
let tlvData = Buffer.alloc(0);
|
|
11070
|
+
if (info.data.length > MINT_SIZE) {
|
|
11071
|
+
if (info.data.length <= ACCOUNT_SIZE)
|
|
11072
|
+
throw new TokenInvalidAccountSizeError();
|
|
11073
|
+
if (info.data.length === MULTISIG_SIZE)
|
|
11074
|
+
throw new TokenInvalidAccountSizeError();
|
|
11075
|
+
if (info.data[ACCOUNT_SIZE] != AccountType$1.Mint)
|
|
11076
|
+
throw new TokenInvalidMintError();
|
|
11077
|
+
tlvData = info.data.slice(ACCOUNT_SIZE + ACCOUNT_TYPE_SIZE);
|
|
11078
|
+
}
|
|
11079
|
+
return {
|
|
11080
|
+
address,
|
|
11081
|
+
mintAuthority: rawMint.mintAuthorityOption ? rawMint.mintAuthority : null,
|
|
11082
|
+
supply: rawMint.supply,
|
|
11083
|
+
decimals: rawMint.decimals,
|
|
11084
|
+
isInitialized: rawMint.isInitialized,
|
|
11085
|
+
freezeAuthority: rawMint.freezeAuthorityOption ? rawMint.freezeAuthority : null,
|
|
11086
|
+
tlvData,
|
|
11087
|
+
};
|
|
11088
|
+
}
|
|
11089
|
+
|
|
11090
|
+
new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
11253
11091
|
|
|
11254
11092
|
/** TODO: docs */
|
|
11255
11093
|
struct$1([u8$1('instruction'), u64$1('amount')]);
|
|
@@ -11398,591 +11236,643 @@ var InterestBearingMintInstruction;
|
|
|
11398
11236
|
InterestBearingMintInstruction[InterestBearingMintInstruction["Initialize"] = 0] = "Initialize";
|
|
11399
11237
|
InterestBearingMintInstruction[InterestBearingMintInstruction["UpdateRate"] = 1] = "UpdateRate";
|
|
11400
11238
|
})(InterestBearingMintInstruction || (InterestBearingMintInstruction = {}));
|
|
11401
|
-
struct$1([
|
|
11402
|
-
u8$1('instruction'),
|
|
11403
|
-
u8$1('interestBearingMintInstruction'),
|
|
11404
|
-
// TODO: Make this an optional public key
|
|
11405
|
-
publicKey$4('rateAuthority'),
|
|
11406
|
-
s16('rate'),
|
|
11407
|
-
]);
|
|
11408
|
-
struct$1([
|
|
11409
|
-
u8$1('instruction'),
|
|
11410
|
-
u8$1('interestBearingMintInstruction'),
|
|
11411
|
-
s16('rate'),
|
|
11412
|
-
]);
|
|
11413
|
-
|
|
11414
|
-
var MetadataPointerInstruction;
|
|
11415
|
-
(function (MetadataPointerInstruction) {
|
|
11416
|
-
MetadataPointerInstruction[MetadataPointerInstruction["Initialize"] = 0] = "Initialize";
|
|
11417
|
-
MetadataPointerInstruction[MetadataPointerInstruction["Update"] = 1] = "Update";
|
|
11418
|
-
})(MetadataPointerInstruction || (MetadataPointerInstruction = {}));
|
|
11419
|
-
struct$1([
|
|
11420
|
-
// prettier-ignore
|
|
11421
|
-
u8$1('instruction'),
|
|
11422
|
-
u8$1('metadataPointerInstruction'),
|
|
11423
|
-
publicKey$4('authority'),
|
|
11424
|
-
publicKey$4('metadataAddress'),
|
|
11425
|
-
]);
|
|
11426
|
-
struct$1([
|
|
11427
|
-
// prettier-ignore
|
|
11428
|
-
u8$1('instruction'),
|
|
11429
|
-
u8$1('metadataPointerInstruction'),
|
|
11430
|
-
publicKey$4('metadataAddress'),
|
|
11431
|
-
]);
|
|
11432
|
-
|
|
11433
|
-
// src/codes.ts
|
|
11434
|
-
var SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY$1 = 8078e3;
|
|
11435
|
-
var SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH$1 = 8078001;
|
|
11436
|
-
var SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH$1 = 8078004;
|
|
11437
|
-
var SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH$1 = 8078005;
|
|
11438
|
-
var SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH$1 = 8078006;
|
|
11439
|
-
var SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS$1 = 8078007;
|
|
11440
|
-
var SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE$1 = 8078011;
|
|
11441
|
-
|
|
11442
|
-
// src/context.ts
|
|
11443
|
-
function encodeValue$1(value) {
|
|
11444
|
-
if (Array.isArray(value)) {
|
|
11445
|
-
const commaSeparatedValues = value.map(encodeValue$1).join(
|
|
11446
|
-
"%2C%20"
|
|
11447
|
-
/* ", " */
|
|
11448
|
-
);
|
|
11449
|
-
return "%5B" + commaSeparatedValues + /* "]" */
|
|
11450
|
-
"%5D";
|
|
11451
|
-
} else if (typeof value === "bigint") {
|
|
11452
|
-
return `${value}n`;
|
|
11453
|
-
} else {
|
|
11454
|
-
return encodeURIComponent(
|
|
11455
|
-
String(
|
|
11456
|
-
value != null && Object.getPrototypeOf(value) === null ? (
|
|
11457
|
-
// Plain objects with no prototype don't have a `toString` method.
|
|
11458
|
-
// Convert them before stringifying them.
|
|
11459
|
-
{ ...value }
|
|
11460
|
-
) : value
|
|
11461
|
-
)
|
|
11462
|
-
);
|
|
11463
|
-
}
|
|
11464
|
-
}
|
|
11465
|
-
function encodeObjectContextEntry$1([key, value]) {
|
|
11466
|
-
return `${key}=${encodeValue$1(value)}`;
|
|
11467
|
-
}
|
|
11468
|
-
function encodeContextObject$1(context) {
|
|
11469
|
-
const searchParamsString = Object.entries(context).map(encodeObjectContextEntry$1).join("&");
|
|
11470
|
-
return btoa(searchParamsString);
|
|
11471
|
-
}
|
|
11472
|
-
function getErrorMessage$1(code, context = {}) {
|
|
11473
|
-
{
|
|
11474
|
-
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode -- ${code}`;
|
|
11475
|
-
if (Object.keys(context).length) {
|
|
11476
|
-
decodingAdviceMessage += ` '${encodeContextObject$1(context)}'`;
|
|
11477
|
-
}
|
|
11478
|
-
return `${decodingAdviceMessage}\``;
|
|
11479
|
-
}
|
|
11480
|
-
}
|
|
11481
|
-
var SolanaError$1 = class extends Error {
|
|
11482
|
-
cause = this.cause;
|
|
11483
|
-
context;
|
|
11484
|
-
constructor(...[code, contextAndErrorOptions]) {
|
|
11485
|
-
let context;
|
|
11486
|
-
let errorOptions;
|
|
11487
|
-
if (contextAndErrorOptions) {
|
|
11488
|
-
const { cause, ...contextRest } = contextAndErrorOptions;
|
|
11489
|
-
if (cause) {
|
|
11490
|
-
errorOptions = { cause };
|
|
11491
|
-
}
|
|
11492
|
-
if (Object.keys(contextRest).length > 0) {
|
|
11493
|
-
context = contextRest;
|
|
11494
|
-
}
|
|
11495
|
-
}
|
|
11496
|
-
const message = getErrorMessage$1(code, context);
|
|
11497
|
-
super(message, errorOptions);
|
|
11498
|
-
this.context = {
|
|
11499
|
-
__code: code,
|
|
11500
|
-
...context
|
|
11501
|
-
};
|
|
11502
|
-
this.name = "SolanaError";
|
|
11503
|
-
}
|
|
11504
|
-
};
|
|
11239
|
+
struct$1([
|
|
11240
|
+
u8$1('instruction'),
|
|
11241
|
+
u8$1('interestBearingMintInstruction'),
|
|
11242
|
+
// TODO: Make this an optional public key
|
|
11243
|
+
publicKey$4('rateAuthority'),
|
|
11244
|
+
s16('rate'),
|
|
11245
|
+
]);
|
|
11246
|
+
struct$1([
|
|
11247
|
+
u8$1('instruction'),
|
|
11248
|
+
u8$1('interestBearingMintInstruction'),
|
|
11249
|
+
s16('rate'),
|
|
11250
|
+
]);
|
|
11505
11251
|
|
|
11506
|
-
var
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
});
|
|
11525
|
-
}
|
|
11526
|
-
function createDecoder$1(decoder) {
|
|
11527
|
-
return Object.freeze({
|
|
11528
|
-
...decoder,
|
|
11529
|
-
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
|
|
11530
|
-
});
|
|
11531
|
-
}
|
|
11532
|
-
function isFixedSize$1(codec) {
|
|
11533
|
-
return "fixedSize" in codec && typeof codec.fixedSize === "number";
|
|
11534
|
-
}
|
|
11535
|
-
function combineCodec$1(encoder, decoder) {
|
|
11536
|
-
if (isFixedSize$1(encoder) !== isFixedSize$1(decoder)) {
|
|
11537
|
-
throw new SolanaError$1(SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH$1);
|
|
11538
|
-
}
|
|
11539
|
-
if (isFixedSize$1(encoder) && isFixedSize$1(decoder) && encoder.fixedSize !== decoder.fixedSize) {
|
|
11540
|
-
throw new SolanaError$1(SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH$1, {
|
|
11541
|
-
decoderFixedSize: decoder.fixedSize,
|
|
11542
|
-
encoderFixedSize: encoder.fixedSize
|
|
11543
|
-
});
|
|
11544
|
-
}
|
|
11545
|
-
if (!isFixedSize$1(encoder) && !isFixedSize$1(decoder) && encoder.maxSize !== decoder.maxSize) {
|
|
11546
|
-
throw new SolanaError$1(SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH$1, {
|
|
11547
|
-
decoderMaxSize: decoder.maxSize,
|
|
11548
|
-
encoderMaxSize: encoder.maxSize
|
|
11549
|
-
});
|
|
11550
|
-
}
|
|
11551
|
-
return {
|
|
11552
|
-
...decoder,
|
|
11553
|
-
...encoder,
|
|
11554
|
-
decode: decoder.decode,
|
|
11555
|
-
encode: encoder.encode,
|
|
11556
|
-
read: decoder.read,
|
|
11557
|
-
write: encoder.write
|
|
11558
|
-
};
|
|
11559
|
-
}
|
|
11560
|
-
function assertByteArrayIsNotEmptyForCodec$1(codecDescription, bytes, offset = 0) {
|
|
11561
|
-
if (bytes.length - offset <= 0) {
|
|
11562
|
-
throw new SolanaError$1(SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY$1, {
|
|
11563
|
-
codecDescription
|
|
11564
|
-
});
|
|
11565
|
-
}
|
|
11566
|
-
}
|
|
11567
|
-
function assertByteArrayHasEnoughBytesForCodec$1(codecDescription, expected, bytes, offset = 0) {
|
|
11568
|
-
const bytesLength = bytes.length - offset;
|
|
11569
|
-
if (bytesLength < expected) {
|
|
11570
|
-
throw new SolanaError$1(SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH$1, {
|
|
11571
|
-
bytesLength,
|
|
11572
|
-
codecDescription,
|
|
11573
|
-
expected
|
|
11574
|
-
});
|
|
11575
|
-
}
|
|
11576
|
-
}
|
|
11252
|
+
var MetadataPointerInstruction;
|
|
11253
|
+
(function (MetadataPointerInstruction) {
|
|
11254
|
+
MetadataPointerInstruction[MetadataPointerInstruction["Initialize"] = 0] = "Initialize";
|
|
11255
|
+
MetadataPointerInstruction[MetadataPointerInstruction["Update"] = 1] = "Update";
|
|
11256
|
+
})(MetadataPointerInstruction || (MetadataPointerInstruction = {}));
|
|
11257
|
+
struct$1([
|
|
11258
|
+
// prettier-ignore
|
|
11259
|
+
u8$1('instruction'),
|
|
11260
|
+
u8$1('metadataPointerInstruction'),
|
|
11261
|
+
publicKey$4('authority'),
|
|
11262
|
+
publicKey$4('metadataAddress'),
|
|
11263
|
+
]);
|
|
11264
|
+
struct$1([
|
|
11265
|
+
// prettier-ignore
|
|
11266
|
+
u8$1('instruction'),
|
|
11267
|
+
u8$1('metadataPointerInstruction'),
|
|
11268
|
+
publicKey$4('metadataAddress'),
|
|
11269
|
+
]);
|
|
11577
11270
|
|
|
11578
|
-
|
|
11579
|
-
function
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
11584
|
-
return offset + encoderBytes.length;
|
|
11585
|
-
};
|
|
11586
|
-
if (isFixedSize$1(prefix) && isFixedSize$1(encoder)) {
|
|
11587
|
-
return createEncoder$1({ ...encoder, fixedSize: prefix.fixedSize + encoder.fixedSize, write });
|
|
11588
|
-
}
|
|
11589
|
-
const prefixMaxSize = isFixedSize$1(prefix) ? prefix.fixedSize : prefix.maxSize ?? null;
|
|
11590
|
-
const encoderMaxSize = isFixedSize$1(encoder) ? encoder.fixedSize : encoder.maxSize ?? null;
|
|
11591
|
-
const maxSize = prefixMaxSize !== null && encoderMaxSize !== null ? prefixMaxSize + encoderMaxSize : null;
|
|
11592
|
-
return createEncoder$1({
|
|
11593
|
-
...encoder,
|
|
11594
|
-
...maxSize !== null ? { maxSize } : {},
|
|
11595
|
-
getSizeFromValue: (value) => {
|
|
11596
|
-
const encoderSize = getEncodedSize$1(value, encoder);
|
|
11597
|
-
return getEncodedSize$1(encoderSize, prefix) + encoderSize;
|
|
11598
|
-
},
|
|
11599
|
-
write
|
|
11600
|
-
});
|
|
11601
|
-
}
|
|
11602
|
-
function addDecoderSizePrefix(decoder, prefix) {
|
|
11603
|
-
const read = (bytes, offset) => {
|
|
11604
|
-
const [bigintSize, decoderOffset] = prefix.read(bytes, offset);
|
|
11605
|
-
const size = Number(bigintSize);
|
|
11606
|
-
offset = decoderOffset;
|
|
11607
|
-
if (offset > 0 || bytes.length > size) {
|
|
11608
|
-
bytes = bytes.slice(offset, offset + size);
|
|
11609
|
-
}
|
|
11610
|
-
assertByteArrayHasEnoughBytesForCodec$1("addDecoderSizePrefix", size, bytes);
|
|
11611
|
-
return [decoder.decode(bytes), offset + size];
|
|
11612
|
-
};
|
|
11613
|
-
if (isFixedSize$1(prefix) && isFixedSize$1(decoder)) {
|
|
11614
|
-
return createDecoder$1({ ...decoder, fixedSize: prefix.fixedSize + decoder.fixedSize, read });
|
|
11615
|
-
}
|
|
11616
|
-
const prefixMaxSize = isFixedSize$1(prefix) ? prefix.fixedSize : prefix.maxSize ?? null;
|
|
11617
|
-
const decoderMaxSize = isFixedSize$1(decoder) ? decoder.fixedSize : decoder.maxSize ?? null;
|
|
11618
|
-
const maxSize = prefixMaxSize !== null && decoderMaxSize !== null ? prefixMaxSize + decoderMaxSize : null;
|
|
11619
|
-
return createDecoder$1({ ...decoder, ...maxSize !== null ? { maxSize } : {}, read });
|
|
11620
|
-
}
|
|
11621
|
-
function addCodecSizePrefix(codec, prefix) {
|
|
11622
|
-
return combineCodec$1(addEncoderSizePrefix(codec, prefix), addDecoderSizePrefix(codec, prefix));
|
|
11623
|
-
}
|
|
11271
|
+
var Field;
|
|
11272
|
+
(function (Field) {
|
|
11273
|
+
Field[Field["Name"] = 0] = "Name";
|
|
11274
|
+
Field[Field["Symbol"] = 1] = "Symbol";
|
|
11275
|
+
Field[Field["Uri"] = 2] = "Uri";
|
|
11276
|
+
})(Field || (Field = {}));
|
|
11624
11277
|
|
|
11625
|
-
|
|
11626
|
-
function
|
|
11627
|
-
|
|
11628
|
-
fixedSize: fixedBytes,
|
|
11629
|
-
write: (value, bytes, offset) => {
|
|
11630
|
-
const variableByteArray = encoder.encode(value);
|
|
11631
|
-
const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
|
|
11632
|
-
bytes.set(fixedByteArray, offset);
|
|
11633
|
-
return offset + fixedBytes;
|
|
11634
|
-
}
|
|
11635
|
-
});
|
|
11278
|
+
Buffer.from([112, 132, 90, 90, 11, 88, 157, 87]);
|
|
11279
|
+
function getStringCodec() {
|
|
11280
|
+
return addCodecSizePrefix(getUtf8Codec$1(), getU32Codec());
|
|
11636
11281
|
}
|
|
11637
|
-
|
|
11638
|
-
|
|
11639
|
-
|
|
11640
|
-
|
|
11641
|
-
|
|
11642
|
-
|
|
11643
|
-
|
|
11644
|
-
|
|
11645
|
-
|
|
11646
|
-
|
|
11647
|
-
|
|
11648
|
-
|
|
11649
|
-
|
|
11282
|
+
const tokenMetadataCodec = getStructCodec$1([
|
|
11283
|
+
['updateAuthority', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
11284
|
+
['mint', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
11285
|
+
['name', getStringCodec()],
|
|
11286
|
+
['symbol', getStringCodec()],
|
|
11287
|
+
['uri', getStringCodec()],
|
|
11288
|
+
['additionalMetadata', getArrayCodec$1(getTupleCodec$1([getStringCodec(), getStringCodec()]))],
|
|
11289
|
+
]);
|
|
11290
|
+
// Checks if all elements in the array are 0
|
|
11291
|
+
function isNonePubkey(buffer) {
|
|
11292
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
11293
|
+
if (buffer[i] !== 0) {
|
|
11294
|
+
return false;
|
|
11295
|
+
}
|
|
11650
11296
|
}
|
|
11651
|
-
|
|
11297
|
+
return true;
|
|
11652
11298
|
}
|
|
11653
|
-
|
|
11654
|
-
|
|
11299
|
+
// unpack byte slab into TokenMetadata
|
|
11300
|
+
function unpack(buffer) {
|
|
11301
|
+
const data = tokenMetadataCodec.decode(buffer);
|
|
11302
|
+
return isNonePubkey(data.updateAuthority)
|
|
11303
|
+
? {
|
|
11304
|
+
mint: new PublicKey(data.mint),
|
|
11305
|
+
name: data.name,
|
|
11306
|
+
symbol: data.symbol,
|
|
11307
|
+
uri: data.uri,
|
|
11308
|
+
additionalMetadata: data.additionalMetadata,
|
|
11309
|
+
}
|
|
11310
|
+
: {
|
|
11311
|
+
updateAuthority: new PublicKey(data.updateAuthority),
|
|
11312
|
+
mint: new PublicKey(data.mint),
|
|
11313
|
+
name: data.name,
|
|
11314
|
+
symbol: data.symbol,
|
|
11315
|
+
uri: data.uri,
|
|
11316
|
+
additionalMetadata: data.additionalMetadata,
|
|
11317
|
+
};
|
|
11655
11318
|
}
|
|
11656
11319
|
|
|
11657
|
-
|
|
11658
|
-
|
|
11659
|
-
|
|
11660
|
-
|
|
11661
|
-
|
|
11662
|
-
|
|
11663
|
-
|
|
11664
|
-
|
|
11320
|
+
struct$1([
|
|
11321
|
+
u8$1('instruction'),
|
|
11322
|
+
publicKey$4('owner'),
|
|
11323
|
+
]);
|
|
11324
|
+
|
|
11325
|
+
struct$1([
|
|
11326
|
+
u8$1('instruction'),
|
|
11327
|
+
publicKey$4('owner'),
|
|
11328
|
+
]);
|
|
11329
|
+
|
|
11330
|
+
/** The struct that represents the instruction data as it is read by the program */
|
|
11331
|
+
struct$1([
|
|
11332
|
+
u8$1('instruction'),
|
|
11333
|
+
]);
|
|
11334
|
+
|
|
11335
|
+
/** TODO: docs */
|
|
11336
|
+
struct$1([
|
|
11337
|
+
u8$1('instruction'),
|
|
11338
|
+
new COptionPublicKeyLayout('closeAuthority'),
|
|
11339
|
+
]);
|
|
11340
|
+
|
|
11341
|
+
/** The struct that represents the instruction data as it is read by the program */
|
|
11342
|
+
struct$1([
|
|
11343
|
+
u8$1('instruction'),
|
|
11344
|
+
]);
|
|
11345
|
+
|
|
11346
|
+
/** TODO: docs */
|
|
11347
|
+
struct$1([
|
|
11348
|
+
u8$1('instruction'),
|
|
11349
|
+
publicKey$4('delegate'),
|
|
11350
|
+
]);
|
|
11351
|
+
|
|
11352
|
+
var AccountState;
|
|
11353
|
+
(function (AccountState) {
|
|
11354
|
+
AccountState[AccountState["Uninitialized"] = 0] = "Uninitialized";
|
|
11355
|
+
AccountState[AccountState["Initialized"] = 1] = "Initialized";
|
|
11356
|
+
AccountState[AccountState["Frozen"] = 2] = "Frozen";
|
|
11357
|
+
})(AccountState || (AccountState = {}));
|
|
11358
|
+
const AccountLayout = struct$1([
|
|
11359
|
+
publicKey$4("mint"),
|
|
11360
|
+
publicKey$4("owner"),
|
|
11361
|
+
u64$1("amount"),
|
|
11362
|
+
u32$1("delegateOption"),
|
|
11363
|
+
publicKey$4("delegate"),
|
|
11364
|
+
u8$1("state"),
|
|
11365
|
+
u32$1("isNativeOption"),
|
|
11366
|
+
u64$1("isNative"),
|
|
11367
|
+
u64$1("delegatedAmount"),
|
|
11368
|
+
u32$1("closeAuthorityOption"),
|
|
11369
|
+
publicKey$4("closeAuthority"),
|
|
11370
|
+
]);
|
|
11371
|
+
var AccountType;
|
|
11372
|
+
(function (AccountType) {
|
|
11373
|
+
AccountType[AccountType["System"] = 0] = "System";
|
|
11374
|
+
AccountType[AccountType["Token"] = 1] = "Token";
|
|
11375
|
+
AccountType[AccountType["CorrectATA"] = 2] = "CorrectATA";
|
|
11376
|
+
AccountType[AccountType["Unknown"] = 3] = "Unknown";
|
|
11377
|
+
AccountType[AccountType["NotExists"] = 4] = "NotExists";
|
|
11378
|
+
})(AccountType || (AccountType = {}));
|
|
11379
|
+
/**
|
|
11380
|
+
* Get name, symbol and decimals for provided token
|
|
11381
|
+
* @param connection solana web3 connection
|
|
11382
|
+
* @param tokenAddress address to get metaplex info for
|
|
11383
|
+
* @returns
|
|
11384
|
+
*/
|
|
11385
|
+
function getTokenInfo(connection, tokenAddress) {
|
|
11386
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11387
|
+
var _a;
|
|
11388
|
+
const tokenMetaProgramId = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
11389
|
+
const findMetaplexMetadataPda = (tokenMint) => PublicKey.findProgramAddressSync([
|
|
11390
|
+
buffer.Buffer.from("metadata", "utf-8"),
|
|
11391
|
+
tokenMetaProgramId.toBuffer(),
|
|
11392
|
+
tokenMint.toBuffer(),
|
|
11393
|
+
], tokenMetaProgramId)[0];
|
|
11394
|
+
const decodeMetaplexMetadataPartial = (data) => {
|
|
11395
|
+
const rawName = data.subarray(65 + 4, 65 + 36); // omit first 4 bytes, size is already hardcoded
|
|
11396
|
+
const rawSymbol = data.subarray(101 + 4, 115); // omit first 4 bytes, size is already hardcoded
|
|
11397
|
+
const rawUri = data.subarray(115 + 4, 204); // omit first 4 bytes, size is already hardcoded
|
|
11398
|
+
return {
|
|
11399
|
+
uri: rawUri.toString("utf-8").replace(/\u0000/g, ""),
|
|
11400
|
+
symbol: rawSymbol.toString("utf-8").replace(/\u0000/g, ""),
|
|
11401
|
+
name: rawName.toString("utf-8").replace(/\u0000/g, ""),
|
|
11402
|
+
};
|
|
11403
|
+
};
|
|
11404
|
+
const pda = findMetaplexMetadataPda(tokenAddress);
|
|
11405
|
+
const [tokenAccount, pdaAccount] = yield connection.getMultipleAccountsInfo([
|
|
11406
|
+
tokenAddress,
|
|
11407
|
+
pda,
|
|
11408
|
+
]);
|
|
11409
|
+
if (tokenAccount === null) {
|
|
11410
|
+
return null;
|
|
11411
|
+
}
|
|
11412
|
+
const mint2022 = unpackMint(tokenAddress, tokenAccount, tokenAccount.owner);
|
|
11413
|
+
const extTypes = getExtensionTypes((_a = mint2022.tlvData) !== null && _a !== void 0 ? _a : buffer.Buffer.alloc(0));
|
|
11414
|
+
const tokenMetaBuf = extTypes.includes(ExtensionType.TokenMetadata)
|
|
11415
|
+
? getExtensionData(ExtensionType.TokenMetadata, mint2022.tlvData)
|
|
11416
|
+
: null;
|
|
11417
|
+
if (tokenMetaBuf) {
|
|
11418
|
+
const meta = unpack(tokenMetaBuf);
|
|
11419
|
+
return {
|
|
11420
|
+
address: tokenAddress,
|
|
11421
|
+
decimals: mint2022.decimals,
|
|
11422
|
+
name: meta.name,
|
|
11423
|
+
symbol: meta.symbol,
|
|
11424
|
+
json: meta.uri,
|
|
11425
|
+
};
|
|
11426
|
+
}
|
|
11427
|
+
if (extTypes.includes(ExtensionType.MetadataPointer)) {
|
|
11428
|
+
const mpState = getMetadataPointerState(mint2022);
|
|
11429
|
+
if ((mpState === null || mpState === void 0 ? void 0 : mpState.metadataAddress) &&
|
|
11430
|
+
mpState.metadataAddress.equals(tokenAddress)) {
|
|
11431
|
+
const inlineMetaBuf = getExtensionData(ExtensionType.TokenMetadata, mint2022.tlvData);
|
|
11432
|
+
if (inlineMetaBuf) {
|
|
11433
|
+
const meta = unpack(inlineMetaBuf);
|
|
11434
|
+
return {
|
|
11435
|
+
address: tokenAddress,
|
|
11436
|
+
decimals: mint2022.decimals,
|
|
11437
|
+
name: meta.name,
|
|
11438
|
+
symbol: meta.symbol,
|
|
11439
|
+
json: meta.uri,
|
|
11440
|
+
};
|
|
11441
|
+
}
|
|
11442
|
+
}
|
|
11443
|
+
}
|
|
11444
|
+
if (pdaAccount === null || (pdaAccount === null || pdaAccount === void 0 ? void 0 : pdaAccount.lamports) === 0) {
|
|
11445
|
+
return null;
|
|
11446
|
+
}
|
|
11447
|
+
// parse token account
|
|
11448
|
+
// mint_authority - coption(pubkey) = 4 or 36
|
|
11449
|
+
// supply - u64 = 8
|
|
11450
|
+
// decimals - u8
|
|
11451
|
+
let decimalsOffset = 12;
|
|
11452
|
+
if (tokenAccount.data[0] === 1)
|
|
11453
|
+
decimalsOffset += 32;
|
|
11454
|
+
const decimals = tokenAccount.data[decimalsOffset];
|
|
11455
|
+
const { name, symbol, uri } = decodeMetaplexMetadataPartial(pdaAccount.data);
|
|
11456
|
+
return {
|
|
11457
|
+
address: tokenAddress,
|
|
11458
|
+
decimals,
|
|
11459
|
+
name,
|
|
11460
|
+
symbol,
|
|
11461
|
+
json: uri,
|
|
11462
|
+
};
|
|
11665
11463
|
});
|
|
11666
|
-
}
|
|
11667
11464
|
}
|
|
11668
|
-
|
|
11669
|
-
|
|
11465
|
+
/**
|
|
11466
|
+
* Builds instruction for creation of associated wallet for specified token
|
|
11467
|
+
* @param tokenMint mint account of SPL-token
|
|
11468
|
+
* @param associatedAccount associated account address
|
|
11469
|
+
* @param owner owner of the associated account
|
|
11470
|
+
* @param payer who pays for account creation
|
|
11471
|
+
*/
|
|
11472
|
+
function createAssociatedWalletInstruction(tokenMint, associatedAccount, owner, payer, associatedTokenProramId) {
|
|
11473
|
+
tokenMint = new PublicKey(tokenMint);
|
|
11474
|
+
payer = new PublicKey(payer);
|
|
11475
|
+
owner = new PublicKey(owner);
|
|
11476
|
+
return new TransactionInstruction({
|
|
11477
|
+
programId: associatedTokenProramId || ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
11478
|
+
data: buffer.Buffer.from([1]),
|
|
11479
|
+
keys: [
|
|
11480
|
+
{
|
|
11481
|
+
pubkey: payer,
|
|
11482
|
+
isSigner: true,
|
|
11483
|
+
isWritable: true,
|
|
11484
|
+
},
|
|
11485
|
+
{
|
|
11486
|
+
pubkey: associatedAccount,
|
|
11487
|
+
isSigner: false,
|
|
11488
|
+
isWritable: true,
|
|
11489
|
+
},
|
|
11490
|
+
{
|
|
11491
|
+
pubkey: owner,
|
|
11492
|
+
isSigner: false,
|
|
11493
|
+
isWritable: false,
|
|
11494
|
+
},
|
|
11495
|
+
{
|
|
11496
|
+
pubkey: tokenMint,
|
|
11497
|
+
isSigner: false,
|
|
11498
|
+
isWritable: false,
|
|
11499
|
+
},
|
|
11500
|
+
{
|
|
11501
|
+
pubkey: SystemProgram.programId,
|
|
11502
|
+
isSigner: false,
|
|
11503
|
+
isWritable: false,
|
|
11504
|
+
},
|
|
11505
|
+
{
|
|
11506
|
+
pubkey: TOKEN_PROGRAM_ID$1,
|
|
11507
|
+
isSigner: false,
|
|
11508
|
+
isWritable: false,
|
|
11509
|
+
},
|
|
11510
|
+
],
|
|
11511
|
+
});
|
|
11670
11512
|
}
|
|
11671
|
-
function
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
write(value, bytes, offset) {
|
|
11675
|
-
if (input.range) {
|
|
11676
|
-
assertNumberIsBetweenForCodec$1(input.name, input.range[0], input.range[1], value);
|
|
11677
|
-
}
|
|
11678
|
-
const arrayBuffer = new ArrayBuffer(input.size);
|
|
11679
|
-
input.set(new DataView(arrayBuffer), value, isLittleEndian$1(input.config));
|
|
11680
|
-
bytes.set(new Uint8Array(arrayBuffer), offset);
|
|
11681
|
-
return offset + input.size;
|
|
11513
|
+
function parseSplAccount(dataOrInfo) {
|
|
11514
|
+
if (dataOrInfo === null) {
|
|
11515
|
+
return null;
|
|
11682
11516
|
}
|
|
11683
|
-
|
|
11684
|
-
|
|
11685
|
-
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
read(bytes, offset = 0) {
|
|
11689
|
-
assertByteArrayIsNotEmptyForCodec$1(input.name, bytes, offset);
|
|
11690
|
-
assertByteArrayHasEnoughBytesForCodec$1(input.name, input.size, bytes, offset);
|
|
11691
|
-
const view = new DataView(toArrayBuffer$1(bytes, offset, input.size));
|
|
11692
|
-
return [input.get(view, isLittleEndian$1(input.config)), offset + input.size];
|
|
11517
|
+
const data = "executable" in dataOrInfo ? dataOrInfo.data : dataOrInfo;
|
|
11518
|
+
data.subarray(0, 165); // only use static part
|
|
11519
|
+
// if (data.length === 82) return null; // token mint
|
|
11520
|
+
try {
|
|
11521
|
+
return AccountLayout.decode(data);
|
|
11693
11522
|
}
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
function toArrayBuffer$1(bytes, offset, length) {
|
|
11697
|
-
const bytesOffset = bytes.byteOffset + (offset ?? 0);
|
|
11698
|
-
const bytesLength = length ?? bytes.byteLength;
|
|
11699
|
-
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
11700
|
-
}
|
|
11701
|
-
var getU32Encoder$1 = (config = {}) => numberEncoderFactory$1({
|
|
11702
|
-
config,
|
|
11703
|
-
name: "u32",
|
|
11704
|
-
range: [0, Number("0xffffffff")],
|
|
11705
|
-
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
11706
|
-
size: 4
|
|
11707
|
-
});
|
|
11708
|
-
var getU32Decoder$1 = (config = {}) => numberDecoderFactory$1({
|
|
11709
|
-
config,
|
|
11710
|
-
get: (view, le) => view.getUint32(0, le),
|
|
11711
|
-
name: "u32",
|
|
11712
|
-
size: 4
|
|
11713
|
-
});
|
|
11714
|
-
var getU32Codec = (config = {}) => combineCodec$1(getU32Encoder$1(config), getU32Decoder$1(config));
|
|
11715
|
-
|
|
11716
|
-
// src/array.ts
|
|
11717
|
-
function assertValidNumberOfItemsForCodec$1(codecDescription, expected, actual) {
|
|
11718
|
-
if (expected !== actual) {
|
|
11719
|
-
throw new SolanaError$1(SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS$1, {
|
|
11720
|
-
actual,
|
|
11721
|
-
codecDescription,
|
|
11722
|
-
expected
|
|
11723
|
-
});
|
|
11724
|
-
}
|
|
11725
|
-
}
|
|
11726
|
-
function sumCodecSizes$1(sizes) {
|
|
11727
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
11728
|
-
}
|
|
11729
|
-
function getFixedSize$1(codec) {
|
|
11730
|
-
return isFixedSize$1(codec) ? codec.fixedSize : null;
|
|
11731
|
-
}
|
|
11732
|
-
function getMaxSize$1(codec) {
|
|
11733
|
-
return isFixedSize$1(codec) ? codec.fixedSize : codec.maxSize ?? null;
|
|
11734
|
-
}
|
|
11735
|
-
|
|
11736
|
-
// src/array.ts
|
|
11737
|
-
function getArrayEncoder$1(item, config = {}) {
|
|
11738
|
-
const size = config.size ?? getU32Encoder$1();
|
|
11739
|
-
const fixedSize = computeArrayLikeCodecSize$1(size, getFixedSize$1(item));
|
|
11740
|
-
const maxSize = computeArrayLikeCodecSize$1(size, getMaxSize$1(item)) ?? void 0;
|
|
11741
|
-
return createEncoder$1({
|
|
11742
|
-
...fixedSize !== null ? { fixedSize } : {
|
|
11743
|
-
getSizeFromValue: (array) => {
|
|
11744
|
-
const prefixSize = typeof size === "object" ? getEncodedSize$1(array.length, size) : 0;
|
|
11745
|
-
return prefixSize + [...array].reduce((all, value) => all + getEncodedSize$1(value, item), 0);
|
|
11746
|
-
},
|
|
11747
|
-
maxSize
|
|
11748
|
-
},
|
|
11749
|
-
write: (array, bytes, offset) => {
|
|
11750
|
-
if (typeof size === "number") {
|
|
11751
|
-
assertValidNumberOfItemsForCodec$1("array", size, array.length);
|
|
11752
|
-
}
|
|
11753
|
-
if (typeof size === "object") {
|
|
11754
|
-
offset = size.write(array.length, bytes, offset);
|
|
11755
|
-
}
|
|
11756
|
-
array.forEach((value) => {
|
|
11757
|
-
offset = item.write(value, bytes, offset);
|
|
11758
|
-
});
|
|
11759
|
-
return offset;
|
|
11523
|
+
catch (e) {
|
|
11524
|
+
console.error(e);
|
|
11760
11525
|
}
|
|
11761
|
-
|
|
11526
|
+
return null;
|
|
11762
11527
|
}
|
|
11763
|
-
function
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11783
|
-
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
|
|
11790
|
-
return [array, offset];
|
|
11791
|
-
}
|
|
11792
|
-
});
|
|
11528
|
+
function isWalletCorrectATA(walletAddress, data) {
|
|
11529
|
+
const decoded = parseSplAccount(data);
|
|
11530
|
+
if (!decoded)
|
|
11531
|
+
return false;
|
|
11532
|
+
const [realAta] = findAssociatedTokenAddress(decoded.owner, decoded.mint);
|
|
11533
|
+
return realAta.equals(new PublicKey(walletAddress));
|
|
11534
|
+
}
|
|
11535
|
+
/**
|
|
11536
|
+
* Requests account from blockchain and returns result with account type
|
|
11537
|
+
* @param account address of account
|
|
11538
|
+
* @returns account info and account type
|
|
11539
|
+
*/
|
|
11540
|
+
function getAccountWithType(connection, account) {
|
|
11541
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11542
|
+
account = new PublicKey(account);
|
|
11543
|
+
const accountData = yield getAccountInfo(connection, account);
|
|
11544
|
+
if (!accountData)
|
|
11545
|
+
return [null, AccountType.NotExists];
|
|
11546
|
+
if (accountData.owner.equals(TOKEN_PROGRAM_ID$1)) {
|
|
11547
|
+
return isWalletCorrectATA(account, accountData.data)
|
|
11548
|
+
? [accountData, AccountType.CorrectATA]
|
|
11549
|
+
: [accountData, AccountType.Token];
|
|
11550
|
+
}
|
|
11551
|
+
if (accountData.owner.equals(SystemProgram.programId))
|
|
11552
|
+
return [accountData, AccountType.System];
|
|
11553
|
+
return [accountData, AccountType.Unknown];
|
|
11554
|
+
});
|
|
11793
11555
|
}
|
|
11794
|
-
|
|
11795
|
-
|
|
11556
|
+
/**
|
|
11557
|
+
* Returns balance of specified wallet in native tokens
|
|
11558
|
+
* @param wallet wallet to inspect
|
|
11559
|
+
*/
|
|
11560
|
+
function getNativeWalletBalance(connection, wallet) {
|
|
11561
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11562
|
+
wallet = new PublicKey(wallet);
|
|
11563
|
+
const result = yield connection.getBalance(wallet);
|
|
11564
|
+
return new BN(result.toString());
|
|
11565
|
+
});
|
|
11796
11566
|
}
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11567
|
+
/**
|
|
11568
|
+
* Returns balance of associated wallet in SPL-tokens
|
|
11569
|
+
* @param originalWallet native tokens wallet address
|
|
11570
|
+
* @param tokenMint mint of SPL-Token
|
|
11571
|
+
*/
|
|
11572
|
+
function getAssocSPLWalletBalance(connection, originalWallet, tokenMint) {
|
|
11573
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11574
|
+
originalWallet = new PublicKey(originalWallet);
|
|
11575
|
+
tokenMint = new PublicKey(tokenMint);
|
|
11576
|
+
const [wallet] = findAssociatedTokenAddress(originalWallet, tokenMint);
|
|
11577
|
+
const result = yield connection.getTokenAccountBalance(wallet, "finalized");
|
|
11578
|
+
return new BN(result.value.amount);
|
|
11579
|
+
});
|
|
11801
11580
|
}
|
|
11802
|
-
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
|
|
11806
|
-
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11581
|
+
/**
|
|
11582
|
+
* Returns balance of specified wallet in SPL-tokens
|
|
11583
|
+
* @param wallet spl-tokens wallet address
|
|
11584
|
+
*/
|
|
11585
|
+
function getSPLWalletBalance(connection, wallet) {
|
|
11586
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11587
|
+
wallet = new PublicKey(wallet);
|
|
11588
|
+
const result = yield connection.getTokenAccountBalance(wallet, "finalized");
|
|
11589
|
+
return new BN(result.value.amount);
|
|
11590
|
+
});
|
|
11810
11591
|
}
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
|
|
11814
|
-
|
|
11815
|
-
|
|
11816
|
-
|
|
11817
|
-
|
|
11592
|
+
/**
|
|
11593
|
+
* Gets list of user's SPL-token accounts
|
|
11594
|
+
* @param owner owner of the SPL wallets
|
|
11595
|
+
* @returns list of accounts with amount on them
|
|
11596
|
+
*/
|
|
11597
|
+
function getAllTokenAccountsWithBalances(connection, owner) {
|
|
11598
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11599
|
+
const walletsData = yield connection.getParsedTokenAccountsByOwner(new PublicKey(owner), { programId: TOKEN_PROGRAM_ID$1 });
|
|
11600
|
+
const wallets = walletsData.value;
|
|
11601
|
+
return wallets.map((wallet) => {
|
|
11602
|
+
const tokenInfo = wallet.account.data.parsed;
|
|
11603
|
+
return {
|
|
11604
|
+
address: wallet.pubkey,
|
|
11605
|
+
mint: new PublicKey(tokenInfo.info.mint),
|
|
11606
|
+
amount: new BN(tokenInfo.info.tokenAmount.amount),
|
|
11607
|
+
decimals: tokenInfo.info.tokenAmount.decimals,
|
|
11608
|
+
isInitialized: true,
|
|
11609
|
+
isNative: tokenInfo.info.isNative,
|
|
11610
|
+
owner: new PublicKey(tokenInfo.info.owner),
|
|
11611
|
+
};
|
|
11612
|
+
});
|
|
11613
|
+
});
|
|
11818
11614
|
}
|
|
11819
|
-
|
|
11820
|
-
|
|
11615
|
+
/**
|
|
11616
|
+
* Gets list of user's tokenMint token accounts
|
|
11617
|
+
* @param tokenMint
|
|
11618
|
+
* @param owner owner of the wallets
|
|
11619
|
+
* @returns list of accounts with amount on them
|
|
11620
|
+
*/
|
|
11621
|
+
function getTokenAccountsWithBalance(connection, tokenMint, owner) {
|
|
11622
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11623
|
+
const walletsData = yield connection.getParsedTokenAccountsByOwner(new PublicKey(owner), { mint: new PublicKey(tokenMint) });
|
|
11624
|
+
const wallets = walletsData.value;
|
|
11625
|
+
return wallets.map((wallet) => {
|
|
11626
|
+
const tokenInfo = wallet.account.data.parsed;
|
|
11627
|
+
return {
|
|
11628
|
+
address: wallet.pubkey,
|
|
11629
|
+
mint: new PublicKey(tokenInfo.info.mint),
|
|
11630
|
+
amount: new BN(tokenInfo.info.tokenAmount.amount),
|
|
11631
|
+
decimals: tokenInfo.info.tokenAmount.decimals,
|
|
11632
|
+
isInitialized: true,
|
|
11633
|
+
isNative: tokenInfo.info.isNative,
|
|
11634
|
+
owner: new PublicKey(tokenInfo.info.owner),
|
|
11635
|
+
};
|
|
11636
|
+
});
|
|
11637
|
+
});
|
|
11821
11638
|
}
|
|
11822
|
-
|
|
11823
|
-
|
|
11824
|
-
|
|
11825
|
-
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
11837
|
-
|
|
11639
|
+
/**
|
|
11640
|
+
* Builds transaction to transfer&wrap native sol from src wallet to dst wallet
|
|
11641
|
+
* @param amount number of lamports to transfer and wrap
|
|
11642
|
+
* @param transferFrom source native account
|
|
11643
|
+
* @param transferTo destination wallet
|
|
11644
|
+
* @returns transaction to transfer&wrap sol
|
|
11645
|
+
*/
|
|
11646
|
+
function buildReplenishWsolBalanceTransaction(amount, transferFrom, transferTo) {
|
|
11647
|
+
transferFrom = new PublicKey(transferFrom);
|
|
11648
|
+
transferTo = new PublicKey(transferTo);
|
|
11649
|
+
const tx = new Transaction();
|
|
11650
|
+
tx.add(SystemProgram.transfer({
|
|
11651
|
+
fromPubkey: transferFrom,
|
|
11652
|
+
toPubkey: transferTo,
|
|
11653
|
+
lamports: new BN(amount).toNumber(),
|
|
11654
|
+
}));
|
|
11655
|
+
tx.add(
|
|
11656
|
+
// sync native
|
|
11657
|
+
new TransactionInstruction({
|
|
11658
|
+
keys: [{ pubkey: transferTo, isSigner: false, isWritable: true }],
|
|
11659
|
+
programId: TOKEN_PROGRAM_ID$1,
|
|
11660
|
+
data: buffer.Buffer.from([17]),
|
|
11661
|
+
}));
|
|
11662
|
+
tx.feePayer = transferFrom;
|
|
11663
|
+
return tx;
|
|
11838
11664
|
}
|
|
11839
|
-
|
|
11840
|
-
|
|
11841
|
-
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
11845
|
-
|
|
11846
|
-
|
|
11847
|
-
const
|
|
11848
|
-
|
|
11849
|
-
|
|
11850
|
-
|
|
11851
|
-
|
|
11852
|
-
|
|
11853
|
-
|
|
11665
|
+
/**
|
|
11666
|
+
* Builds transaction that wraps specified amount of lamports into spl, if account is missing will create it
|
|
11667
|
+
* @param amount lamports to wrap, ATA will contain exact amount of lamports
|
|
11668
|
+
* @param owner owner of created wallet
|
|
11669
|
+
*/
|
|
11670
|
+
function updateWsolBalance(connection, amount, owner) {
|
|
11671
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11672
|
+
owner = new PublicKey(owner);
|
|
11673
|
+
const tx = new Transaction();
|
|
11674
|
+
const [wSolATA] = findAssociatedTokenAddress(owner, WRAPPED_SOL_MINT);
|
|
11675
|
+
const existingATA = yield getAccountInfo(connection, wSolATA);
|
|
11676
|
+
let amountToWrap = new BN(amount);
|
|
11677
|
+
if (existingATA === null) {
|
|
11678
|
+
tx.add(createAssociatedWalletInstruction(WRAPPED_SOL_MINT, wSolATA, owner, owner));
|
|
11679
|
+
}
|
|
11680
|
+
else {
|
|
11681
|
+
const parsed = parseSplAccount(existingATA.data);
|
|
11682
|
+
if (!parsed)
|
|
11683
|
+
throw new Error("WSol account exists, but failed to decode its content");
|
|
11684
|
+
const parsedAmount = new BN(parsed.amount.toString());
|
|
11685
|
+
if (amountToWrap.lte(parsedAmount))
|
|
11686
|
+
return null; // don't need to wrap
|
|
11687
|
+
amountToWrap = amountToWrap.sub(parsedAmount);
|
|
11688
|
+
}
|
|
11689
|
+
const replenishTx = buildReplenishWsolBalanceTransaction(amountToWrap, owner, wSolATA);
|
|
11690
|
+
tx.add(replenishTx);
|
|
11691
|
+
return tx;
|
|
11692
|
+
});
|
|
11854
11693
|
}
|
|
11855
|
-
|
|
11856
|
-
|
|
11857
|
-
|
|
11858
|
-
|
|
11859
|
-
|
|
11694
|
+
/**
|
|
11695
|
+
* Checks existance of associated wallet for specified token
|
|
11696
|
+
* @param mintAccount mint account of SPL-token
|
|
11697
|
+
* @param originalWallet account of solana wallet
|
|
11698
|
+
* @returns true if account exists
|
|
11699
|
+
*/
|
|
11700
|
+
function checkIfAssociatedWalletExists(connection, mintAccount, originalWallet) {
|
|
11701
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11702
|
+
const [walletAccount] = findAssociatedTokenAddress(originalWallet, mintAccount);
|
|
11703
|
+
const accountData = yield getAccountInfo(connection, walletAccount);
|
|
11704
|
+
return accountData !== null;
|
|
11705
|
+
});
|
|
11860
11706
|
}
|
|
11861
|
-
function
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
|
|
11870
|
-
|
|
11871
|
-
|
|
11872
|
-
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
|
|
11876
|
-
|
|
11707
|
+
function getTransactionAccountsForSimulationDiff(connection, tx) {
|
|
11708
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11709
|
+
var _a, _b;
|
|
11710
|
+
const result = new Set();
|
|
11711
|
+
if ("version" in tx) {
|
|
11712
|
+
const ALTs = tx.message.addressTableLookups.map((alt) => alt.accountKey);
|
|
11713
|
+
const fetchedALTs = yield connection.getMultipleAccountsInfo(ALTs);
|
|
11714
|
+
const parsedALTs = fetchedALTs
|
|
11715
|
+
.map((fetched, i) => fetched
|
|
11716
|
+
? new AddressLookupTableAccount({
|
|
11717
|
+
state: AddressLookupTableAccount.deserialize(fetched.data),
|
|
11718
|
+
key: ALTs[i],
|
|
11719
|
+
})
|
|
11720
|
+
: null)
|
|
11721
|
+
.filter((x) => x != null);
|
|
11722
|
+
const accGetter = tx.message.getAccountKeys({
|
|
11723
|
+
addressLookupTableAccounts: parsedALTs,
|
|
11724
|
+
});
|
|
11725
|
+
const staticWritableOrSignerAccounts = [];
|
|
11726
|
+
for (let idx = 0; idx < accGetter.staticAccountKeys.length; idx += 1) {
|
|
11727
|
+
if (tx.message.isAccountSigner(idx) || tx.message.isAccountWritable(idx))
|
|
11728
|
+
staticWritableOrSignerAccounts.push(accGetter.staticAccountKeys[idx]);
|
|
11729
|
+
}
|
|
11730
|
+
for (const acc of [
|
|
11731
|
+
...staticWritableOrSignerAccounts,
|
|
11732
|
+
...((_b = (_a = accGetter.accountKeysFromLookups) === null || _a === void 0 ? void 0 : _a.writable) !== null && _b !== void 0 ? _b : []),
|
|
11733
|
+
]) {
|
|
11734
|
+
result.add(acc.toBase58());
|
|
11735
|
+
}
|
|
11736
|
+
}
|
|
11737
|
+
else {
|
|
11738
|
+
const compiled = tx.compileMessage();
|
|
11739
|
+
for (let idx = 0; idx < compiled.accountKeys.length; idx += 1) {
|
|
11740
|
+
if (compiled.isAccountSigner(idx) || compiled.isAccountWritable(idx))
|
|
11741
|
+
result.add(compiled.staticAccountKeys[idx].toBase58());
|
|
11742
|
+
}
|
|
11743
|
+
}
|
|
11744
|
+
return Array.from(result);
|
|
11745
|
+
});
|
|
11877
11746
|
}
|
|
11878
|
-
function
|
|
11879
|
-
|
|
11880
|
-
|
|
11881
|
-
|
|
11882
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11747
|
+
function parseMultipleAccounts(accounts) {
|
|
11748
|
+
return accounts.map((account) => {
|
|
11749
|
+
var _a, _b;
|
|
11750
|
+
let parsedSplAccount;
|
|
11751
|
+
if (account) {
|
|
11752
|
+
const owner = new PublicKey(account.owner);
|
|
11753
|
+
if (owner.equals(TOKEN_PROGRAM_ID$1) ||
|
|
11754
|
+
owner.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
11755
|
+
if (account.data instanceof buffer.Buffer) {
|
|
11756
|
+
parsedSplAccount = parseSplAccount(account.data);
|
|
11757
|
+
}
|
|
11758
|
+
else if (account.data instanceof Array) {
|
|
11759
|
+
parsedSplAccount = parseSplAccount(buffer.Buffer.from(account.data[0], account.data[1]));
|
|
11760
|
+
}
|
|
11761
|
+
}
|
|
11762
|
+
}
|
|
11763
|
+
const parsedAccount = {
|
|
11764
|
+
balance: (_a = account === null || account === void 0 ? void 0 : account.lamports) !== null && _a !== void 0 ? _a : 0,
|
|
11765
|
+
};
|
|
11766
|
+
if (parsedSplAccount) {
|
|
11767
|
+
parsedAccount.spl = {
|
|
11768
|
+
mint: parsedSplAccount.mint,
|
|
11769
|
+
owner: parsedSplAccount.owner,
|
|
11770
|
+
balance: (_b = parsedSplAccount.amount) !== null && _b !== void 0 ? _b : BigInt(0),
|
|
11771
|
+
};
|
|
11772
|
+
}
|
|
11773
|
+
return parsedAccount;
|
|
11774
|
+
});
|
|
11894
11775
|
}
|
|
11895
|
-
function
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11776
|
+
function getSplDiff(pre, post) {
|
|
11777
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11778
|
+
const preBalance = (_a = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
11779
|
+
const postBalance = (_b = post === null || post === void 0 ? void 0 : post.balance) !== null && _b !== void 0 ? _b : BigInt(0);
|
|
11780
|
+
return {
|
|
11781
|
+
mint: (_c = pre === null || pre === void 0 ? void 0 : pre.mint) !== null && _c !== void 0 ? _c : post === null || post === void 0 ? void 0 : post.mint,
|
|
11782
|
+
owner: (_d = pre === null || pre === void 0 ? void 0 : pre.owner) !== null && _d !== void 0 ? _d : post === null || post === void 0 ? void 0 : post.owner,
|
|
11783
|
+
preBalance: (_e = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _e !== void 0 ? _e : 0,
|
|
11784
|
+
postBalance: (_f = post === null || post === void 0 ? void 0 : post.balance) !== null && _f !== void 0 ? _f : 0,
|
|
11785
|
+
diff: postBalance - preBalance,
|
|
11786
|
+
};
|
|
11900
11787
|
}
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
11904
|
-
|
|
11905
|
-
|
|
11906
|
-
);
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
|
|
11914
|
-
|
|
11915
|
-
|
|
11916
|
-
|
|
11917
|
-
|
|
11918
|
-
|
|
11919
|
-
|
|
11920
|
-
|
|
11921
|
-
|
|
11922
|
-
|
|
11923
|
-
|
|
11924
|
-
|
|
11925
|
-
|
|
11926
|
-
|
|
11927
|
-
|
|
11928
|
-
|
|
11929
|
-
|
|
11930
|
-
|
|
11931
|
-
|
|
11932
|
-
|
|
11933
|
-
|
|
11934
|
-
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11940
|
-
|
|
11941
|
-
|
|
11942
|
-
|
|
11943
|
-
|
|
11944
|
-
|
|
11788
|
+
function getTransactionDiff(connection, tx, txAccounts) {
|
|
11789
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11790
|
+
const accountsStrings = txAccounts
|
|
11791
|
+
? txAccounts.map((acc) => acc.toBase58())
|
|
11792
|
+
: yield getTransactionAccountsForSimulationDiff(connection, tx);
|
|
11793
|
+
const accountsPubKeys = txAccounts !== null && txAccounts !== void 0 ? txAccounts : accountsStrings.map((key) => new PublicKey(key));
|
|
11794
|
+
let [accountsInfo, simulatedTx] = yield Promise.all([
|
|
11795
|
+
connection.getMultipleAccountsInfo(accountsPubKeys),
|
|
11796
|
+
connection.simulateTransaction(tx, {
|
|
11797
|
+
replaceRecentBlockhash: true,
|
|
11798
|
+
accounts: {
|
|
11799
|
+
encoding: "base64",
|
|
11800
|
+
addresses: accountsStrings,
|
|
11801
|
+
},
|
|
11802
|
+
}),
|
|
11803
|
+
]);
|
|
11804
|
+
if (simulatedTx.value.err !== null)
|
|
11805
|
+
throw new Error(JSON.stringify({
|
|
11806
|
+
err: simulatedTx.value.err,
|
|
11807
|
+
logs: simulatedTx.value.logs,
|
|
11808
|
+
}));
|
|
11809
|
+
const simulatesInfo = simulatedTx.value.accounts;
|
|
11810
|
+
const preBalances = parseMultipleAccounts(accountsInfo);
|
|
11811
|
+
const postBalances = parseMultipleAccounts(simulatesInfo);
|
|
11812
|
+
const balancesDiff = accountsPubKeys.reduce((map, pubKey, i) => {
|
|
11813
|
+
var _a;
|
|
11814
|
+
if ((_a = accountsInfo[i]) === null || _a === void 0 ? void 0 : _a.executable) {
|
|
11815
|
+
return map;
|
|
11816
|
+
}
|
|
11817
|
+
const preBalance = preBalances[i];
|
|
11818
|
+
const postBalance = postBalances[i];
|
|
11819
|
+
const diff = {
|
|
11820
|
+
pubKey: pubKey,
|
|
11821
|
+
preBalance: preBalance.balance,
|
|
11822
|
+
postBalance: postBalance.balance,
|
|
11823
|
+
diff: postBalance.balance - preBalance.balance,
|
|
11824
|
+
};
|
|
11825
|
+
if (preBalance.spl || postBalance.spl) {
|
|
11826
|
+
const splDiff = getSplDiff(preBalance.spl, postBalance.spl);
|
|
11827
|
+
if (splDiff.diff) {
|
|
11828
|
+
diff.spl = splDiff;
|
|
11829
|
+
}
|
|
11830
|
+
}
|
|
11831
|
+
if (diff.diff || diff.spl) {
|
|
11832
|
+
map.set(pubKey.toString(), diff);
|
|
11833
|
+
}
|
|
11834
|
+
return map;
|
|
11835
|
+
}, new Map());
|
|
11836
|
+
return balancesDiff;
|
|
11837
|
+
});
|
|
11945
11838
|
}
|
|
11946
|
-
getStructCodec$1([
|
|
11947
|
-
['updateAuthority', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
11948
|
-
['mint', fixCodecSize$1(getBytesCodec$1(), 32)],
|
|
11949
|
-
['name', getStringCodec()],
|
|
11950
|
-
['symbol', getStringCodec()],
|
|
11951
|
-
['uri', getStringCodec()],
|
|
11952
|
-
['additionalMetadata', getArrayCodec$1(getTupleCodec$1([getStringCodec(), getStringCodec()]))],
|
|
11953
|
-
]);
|
|
11954
|
-
|
|
11955
|
-
struct$1([
|
|
11956
|
-
u8$1('instruction'),
|
|
11957
|
-
publicKey$4('owner'),
|
|
11958
|
-
]);
|
|
11959
|
-
|
|
11960
|
-
struct$1([
|
|
11961
|
-
u8$1('instruction'),
|
|
11962
|
-
publicKey$4('owner'),
|
|
11963
|
-
]);
|
|
11964
|
-
|
|
11965
|
-
/** The struct that represents the instruction data as it is read by the program */
|
|
11966
|
-
struct$1([
|
|
11967
|
-
u8$1('instruction'),
|
|
11968
|
-
]);
|
|
11969
11839
|
|
|
11970
|
-
|
|
11971
|
-
|
|
11972
|
-
|
|
11973
|
-
|
|
11974
|
-
|
|
11840
|
+
var spl = /*#__PURE__*/Object.freeze({
|
|
11841
|
+
__proto__: null,
|
|
11842
|
+
get AccountType () { return AccountType; },
|
|
11843
|
+
getTokenInfo: getTokenInfo,
|
|
11844
|
+
createAssociatedWalletInstruction: createAssociatedWalletInstruction,
|
|
11845
|
+
parseSplAccount: parseSplAccount,
|
|
11846
|
+
isWalletCorrectATA: isWalletCorrectATA,
|
|
11847
|
+
getAccountWithType: getAccountWithType,
|
|
11848
|
+
getNativeWalletBalance: getNativeWalletBalance,
|
|
11849
|
+
getAssocSPLWalletBalance: getAssocSPLWalletBalance,
|
|
11850
|
+
getSPLWalletBalance: getSPLWalletBalance,
|
|
11851
|
+
getAllTokenAccountsWithBalances: getAllTokenAccountsWithBalances,
|
|
11852
|
+
getTokenAccountsWithBalance: getTokenAccountsWithBalance,
|
|
11853
|
+
buildReplenishWsolBalanceTransaction: buildReplenishWsolBalanceTransaction,
|
|
11854
|
+
updateWsolBalance: updateWsolBalance,
|
|
11855
|
+
checkIfAssociatedWalletExists: checkIfAssociatedWalletExists,
|
|
11856
|
+
getTransactionAccountsForSimulationDiff: getTransactionAccountsForSimulationDiff,
|
|
11857
|
+
parseMultipleAccounts: parseMultipleAccounts,
|
|
11858
|
+
getSplDiff: getSplDiff,
|
|
11859
|
+
getTransactionDiff: getTransactionDiff
|
|
11860
|
+
});
|
|
11975
11861
|
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11862
|
+
const deBridge = "DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh";
|
|
11863
|
+
const settings = "DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft";
|
|
11864
|
+
const dlnSrc = "src5qyZHqTqecJV4aY6Cb6zDZLMDzrDKKezs22MPHr4";
|
|
11865
|
+
const dlnDst = "dst5MGcFPoBeREFAA5E3tU5ij8m5uVYwkzkSAbsLbNo";
|
|
11866
|
+
const dlnExecutor = "exe59FS5cojZkPJVDFDV8RnXCC7wd6yoBjsUtqH7Zai";
|
|
11980
11867
|
|
|
11981
|
-
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
|
|
11868
|
+
var programs = /*#__PURE__*/Object.freeze({
|
|
11869
|
+
__proto__: null,
|
|
11870
|
+
deBridge: deBridge,
|
|
11871
|
+
settings: settings,
|
|
11872
|
+
dlnSrc: dlnSrc,
|
|
11873
|
+
dlnDst: dlnDst,
|
|
11874
|
+
dlnExecutor: dlnExecutor
|
|
11875
|
+
});
|
|
11986
11876
|
|
|
11987
11877
|
var safeBuffer = {exports: {}};
|
|
11988
11878
|
|
|
@@ -14908,7 +14798,23 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
14908
14798
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14909
14799
|
};
|
|
14910
14800
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14911
|
-
exports.
|
|
14801
|
+
exports.struct = exports.f64 = exports.f32 = exports.i32 = exports.u32 = exports.i16 = exports.u16 = exports.i8 = exports.u8 = void 0;
|
|
14802
|
+
exports.u64 = u64;
|
|
14803
|
+
exports.i64 = i64;
|
|
14804
|
+
exports.u128 = u128;
|
|
14805
|
+
exports.i128 = i128;
|
|
14806
|
+
exports.u256 = u256;
|
|
14807
|
+
exports.i256 = i256;
|
|
14808
|
+
exports.publicKey = publicKey;
|
|
14809
|
+
exports.option = option;
|
|
14810
|
+
exports.bool = bool;
|
|
14811
|
+
exports.vec = vec;
|
|
14812
|
+
exports.tagged = tagged;
|
|
14813
|
+
exports.vecU8 = vecU8;
|
|
14814
|
+
exports.str = str;
|
|
14815
|
+
exports.rustEnum = rustEnum;
|
|
14816
|
+
exports.array = array;
|
|
14817
|
+
exports.map = map;
|
|
14912
14818
|
const buffer_layout_1 = Layout$2;
|
|
14913
14819
|
const web3_js_1 = require$$1;
|
|
14914
14820
|
const bn_js_1 = __importDefault(bn.exports);
|
|
@@ -14945,27 +14851,21 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
14945
14851
|
function u64(property) {
|
|
14946
14852
|
return new BNLayout(8, false, property);
|
|
14947
14853
|
}
|
|
14948
|
-
exports.u64 = u64;
|
|
14949
14854
|
function i64(property) {
|
|
14950
14855
|
return new BNLayout(8, true, property);
|
|
14951
14856
|
}
|
|
14952
|
-
exports.i64 = i64;
|
|
14953
14857
|
function u128(property) {
|
|
14954
14858
|
return new BNLayout(16, false, property);
|
|
14955
14859
|
}
|
|
14956
|
-
exports.u128 = u128;
|
|
14957
14860
|
function i128(property) {
|
|
14958
14861
|
return new BNLayout(16, true, property);
|
|
14959
14862
|
}
|
|
14960
|
-
exports.i128 = i128;
|
|
14961
14863
|
function u256(property) {
|
|
14962
14864
|
return new BNLayout(32, false, property);
|
|
14963
14865
|
}
|
|
14964
|
-
exports.u256 = u256;
|
|
14965
14866
|
function i256(property) {
|
|
14966
14867
|
return new BNLayout(32, true, property);
|
|
14967
14868
|
}
|
|
14968
|
-
exports.i256 = i256;
|
|
14969
14869
|
class WrappedLayout extends buffer_layout_1.Layout {
|
|
14970
14870
|
constructor(layout, decoder, encoder, property) {
|
|
14971
14871
|
super(layout.span, property);
|
|
@@ -14986,7 +14886,6 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
14986
14886
|
function publicKey(property) {
|
|
14987
14887
|
return new WrappedLayout((0, buffer_layout_1.blob)(32), (b) => new web3_js_1.PublicKey(b), (key) => key.toBuffer(), property);
|
|
14988
14888
|
}
|
|
14989
|
-
exports.publicKey = publicKey;
|
|
14990
14889
|
class OptionLayout extends buffer_layout_1.Layout {
|
|
14991
14890
|
constructor(layout, property) {
|
|
14992
14891
|
super(-1, property);
|
|
@@ -15024,11 +14923,9 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
15024
14923
|
function option(layout, property) {
|
|
15025
14924
|
return new OptionLayout(layout, property);
|
|
15026
14925
|
}
|
|
15027
|
-
exports.option = option;
|
|
15028
14926
|
function bool(property) {
|
|
15029
14927
|
return new WrappedLayout((0, buffer_layout_1.u8)(), decodeBool, encodeBool, property);
|
|
15030
14928
|
}
|
|
15031
|
-
exports.bool = bool;
|
|
15032
14929
|
function decodeBool(value) {
|
|
15033
14930
|
if (value === 0) {
|
|
15034
14931
|
return false;
|
|
@@ -15049,7 +14946,6 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
15049
14946
|
]);
|
|
15050
14947
|
return new WrappedLayout(layout, ({ values }) => values, (values) => ({ values }), property);
|
|
15051
14948
|
}
|
|
15052
|
-
exports.vec = vec;
|
|
15053
14949
|
function tagged(tag, layout, property) {
|
|
15054
14950
|
const wrappedLayout = (0, buffer_layout_1.struct)([
|
|
15055
14951
|
u64("tag"),
|
|
@@ -15066,7 +14962,6 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
15066
14962
|
}
|
|
15067
14963
|
return new WrappedLayout(wrappedLayout, decodeTag, (data) => ({ tag, data }), property);
|
|
15068
14964
|
}
|
|
15069
|
-
exports.tagged = tagged;
|
|
15070
14965
|
function vecU8(property) {
|
|
15071
14966
|
const length = (0, buffer_layout_1.u32)("length");
|
|
15072
14967
|
const layout = (0, buffer_layout_1.struct)([
|
|
@@ -15075,24 +14970,20 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
15075
14970
|
]);
|
|
15076
14971
|
return new WrappedLayout(layout, ({ data }) => data, (data) => ({ data }), property);
|
|
15077
14972
|
}
|
|
15078
|
-
exports.vecU8 = vecU8;
|
|
15079
14973
|
function str(property) {
|
|
15080
14974
|
return new WrappedLayout(vecU8(), (data) => data.toString("utf-8"), (s) => Buffer.from(s, "utf-8"), property);
|
|
15081
14975
|
}
|
|
15082
|
-
exports.str = str;
|
|
15083
14976
|
function rustEnum(variants, property, discriminant) {
|
|
15084
14977
|
const unionLayout = (0, buffer_layout_1.union)(discriminant !== null && discriminant !== void 0 ? discriminant : (0, buffer_layout_1.u8)(), property);
|
|
15085
14978
|
variants.forEach((variant, index) => unionLayout.addVariant(index, variant, variant.property));
|
|
15086
14979
|
return unionLayout;
|
|
15087
14980
|
}
|
|
15088
|
-
exports.rustEnum = rustEnum;
|
|
15089
14981
|
function array(elementLayout, length, property) {
|
|
15090
14982
|
const layout = (0, buffer_layout_1.struct)([
|
|
15091
14983
|
(0, buffer_layout_1.seq)(elementLayout, length, "values"),
|
|
15092
14984
|
]);
|
|
15093
14985
|
return new WrappedLayout(layout, ({ values }) => values, (values) => ({ values }), property);
|
|
15094
14986
|
}
|
|
15095
|
-
exports.array = array;
|
|
15096
14987
|
class MapEntryLayout extends buffer_layout_1.Layout {
|
|
15097
14988
|
constructor(keyLayout, valueLayout, property) {
|
|
15098
14989
|
super(keyLayout.span + valueLayout.span, property);
|
|
@@ -15123,7 +15014,6 @@ Layout$2.const = ((value, property) => new Constant(value, property));
|
|
|
15123
15014
|
]);
|
|
15124
15015
|
return new WrappedLayout(layout, ({ values }) => new Map(values), (values) => ({ values: Array.from(values.entries()) }), property);
|
|
15125
15016
|
}
|
|
15126
|
-
exports.map = map;
|
|
15127
15017
|
|
|
15128
15018
|
} (dist$1));
|
|
15129
15019
|
|
|
@@ -29246,7 +29136,7 @@ function simulateTransaction(connection, tx, simulateConfig) {
|
|
|
29246
29136
|
for (const [idx, simulatedAccountInfo] of ((_c = result.value.accounts) !== null && _c !== void 0 ? _c : []).entries()) {
|
|
29247
29137
|
const accountAddress = addressesToGetDiffFor[idx];
|
|
29248
29138
|
const oldAccountData = (_d = accountsToFetch.at(idx)) !== null && _d !== void 0 ? _d : null;
|
|
29249
|
-
const oldParsedMaybeSpl = (oldAccountData === null || oldAccountData === void 0 ? void 0 : oldAccountData.owner.equals(TOKEN_PROGRAM_ID))
|
|
29139
|
+
const oldParsedMaybeSpl = (oldAccountData === null || oldAccountData === void 0 ? void 0 : oldAccountData.owner.equals(TOKEN_PROGRAM_ID$1))
|
|
29250
29140
|
? parseSplAccount(oldAccountData)
|
|
29251
29141
|
: null;
|
|
29252
29142
|
const oldSolValue = (_e = oldAccountData === null || oldAccountData === void 0 ? void 0 : oldAccountData.lamports) !== null && _e !== void 0 ? _e : 0;
|
|
@@ -29263,7 +29153,7 @@ function simulateTransaction(connection, tx, simulateConfig) {
|
|
|
29263
29153
|
if (encoding !== "base64")
|
|
29264
29154
|
throw new Error("Expected bs64 account data");
|
|
29265
29155
|
const artificialAccountInfo = Object.assign(Object.assign({}, simulatedAccountInfo), { owner: new PublicKey(simulatedAccountInfo.owner), data: Buffer.from(rawData, "base64") });
|
|
29266
|
-
newParsedMaybeSpl = artificialAccountInfo.owner.equals(TOKEN_PROGRAM_ID)
|
|
29156
|
+
newParsedMaybeSpl = artificialAccountInfo.owner.equals(TOKEN_PROGRAM_ID$1)
|
|
29267
29157
|
? parseSplAccount(artificialAccountInfo)
|
|
29268
29158
|
: null;
|
|
29269
29159
|
}
|
|
@@ -29377,5 +29267,5 @@ var transaction = /*#__PURE__*/Object.freeze({
|
|
|
29377
29267
|
getErrorData: getErrorData
|
|
29378
29268
|
});
|
|
29379
29269
|
|
|
29380
|
-
export { ASSOCIATED_TOKEN_PROGRAM_ID, DeBridgeResolver, TOKEN_2022_PROGRAM_ID, TOKEN_METADATA_PROGRAM_ID, TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT, constants$1 as constants, crypto$1 as crypto, dlnDstResolver, dlnSrcResolver, findAssociatedTokenAddress, findAssociatedTokenAddressSync, getTokenMetadataAddress, helpers, interfaces, programs, spl, transaction as txs };
|
|
29270
|
+
export { ASSOCIATED_TOKEN_PROGRAM_ID, DeBridgeResolver, TOKEN_2022_PROGRAM_ID, TOKEN_METADATA_PROGRAM_ID, TOKEN_PROGRAM_ID$1 as TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT, constants$1 as constants, crypto$1 as crypto, dlnDstResolver, dlnSrcResolver, findAssociatedTokenAddress, findAssociatedTokenAddressSync, getTokenMetadataAddress, helpers, interfaces, programs, spl, transaction as txs };
|
|
29381
29271
|
//# sourceMappingURL=index.js.map
|