@debridge-finance/solana-utils 4.2.0 → 4.3.0
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/README.md +2 -2
- package/dist/browser/index.js +210 -125
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/accounts.js +62 -27
- package/dist/cjs/accounts.js.map +1 -1
- package/dist/cjs/constants.js +3 -3
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/crypto.js +7 -1
- package/dist/cjs/crypto.js.map +1 -1
- package/dist/cjs/helpers.js +71 -62
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces.js.map +1 -1
- package/dist/cjs/programs.js +9 -0
- package/dist/cjs/programs.js.map +1 -0
- package/dist/cjs/solidityPack.js +10 -8
- package/dist/cjs/solidityPack.js.map +1 -1
- package/dist/cjs/spl.js +31 -16
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/accounts.js +59 -24
- package/dist/esm/accounts.js.map +1 -1
- package/dist/esm/constants.js +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/crypto.js +8 -2
- package/dist/esm/crypto.js.map +1 -1
- package/dist/esm/helpers.js +75 -64
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/programs.js +6 -0
- package/dist/esm/programs.js.map +1 -0
- package/dist/esm/solidityPack.js +10 -8
- package/dist/esm/solidityPack.js.map +1 -1
- package/dist/esm/spl.js +33 -18
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/constants.d.ts +2 -2
- package/dist/types/crypto.d.ts.map +1 -1
- package/dist/types/helpers.d.ts +4 -5
- package/dist/types/helpers.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces.d.ts.map +1 -1
- package/dist/types/programs.d.ts +6 -0
- package/dist/types/programs.d.ts.map +1 -0
- package/dist/types/solidityPack.d.ts.map +1 -1
- package/dist/types/spl.d.ts.map +1 -1
- package/package.json +75 -73
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transaction,
|
|
1
|
+
import { Transaction, MessageV0, VersionedTransaction, PublicKey, TransactionInstruction, SystemProgram } from '@solana/web3.js';
|
|
2
2
|
|
|
3
3
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
4
|
|
|
@@ -6427,7 +6427,7 @@ const MAX_TX_SIZE = 1232;
|
|
|
6427
6427
|
const FAKE_BLOCKHASH = "1".repeat(32);
|
|
6428
6428
|
const DEPLOY_INFO_PREFIX = 2;
|
|
6429
6429
|
const SUBMISSION_PREFIX = 1;
|
|
6430
|
-
const deBridge$
|
|
6430
|
+
const deBridge$2 = {
|
|
6431
6431
|
Seeds: {
|
|
6432
6432
|
STATE: "DEBRIDGE_STATE",
|
|
6433
6433
|
BRIDGE: "BRIDGE",
|
|
@@ -6469,7 +6469,7 @@ const deBridgeSettings$1 = {
|
|
|
6469
6469
|
SEND_BRIDGE_MAP: "WRAPPER_TOKEN",
|
|
6470
6470
|
},
|
|
6471
6471
|
};
|
|
6472
|
-
const
|
|
6472
|
+
const dlnSrc$1 = {
|
|
6473
6473
|
Seeds: {
|
|
6474
6474
|
STATE: "STATE",
|
|
6475
6475
|
NONCE: "NONCE",
|
|
@@ -6480,7 +6480,7 @@ const pmmSrc = {
|
|
|
6480
6480
|
FEE_LEDGER: "FEE LEDGER",
|
|
6481
6481
|
},
|
|
6482
6482
|
};
|
|
6483
|
-
const
|
|
6483
|
+
const dlnDst$1 = {
|
|
6484
6484
|
Seeds: {
|
|
6485
6485
|
AUTHORIZED_SRC_CONTRACT: "AUTHORIZED_SRC_CONTRACT",
|
|
6486
6486
|
AUTHORIZED_DST_NATIVE_SENDER: "AUTHORIZED_DST_NATIVE_SENDER",
|
|
@@ -6497,10 +6497,10 @@ var constants = /*#__PURE__*/Object.freeze({
|
|
|
6497
6497
|
FAKE_BLOCKHASH: FAKE_BLOCKHASH,
|
|
6498
6498
|
DEPLOY_INFO_PREFIX: DEPLOY_INFO_PREFIX,
|
|
6499
6499
|
SUBMISSION_PREFIX: SUBMISSION_PREFIX,
|
|
6500
|
-
deBridge: deBridge$
|
|
6500
|
+
deBridge: deBridge$2,
|
|
6501
6501
|
deBridgeSettings: deBridgeSettings$1,
|
|
6502
|
-
|
|
6503
|
-
|
|
6502
|
+
dlnSrc: dlnSrc$1,
|
|
6503
|
+
dlnDst: dlnDst$1
|
|
6504
6504
|
});
|
|
6505
6505
|
|
|
6506
6506
|
function getAccountInfo(connection, account, commitment = "confirmed") {
|
|
@@ -6527,7 +6527,10 @@ function hexToBuffer(data, align) {
|
|
|
6527
6527
|
data = data.length % 2 ? "0" + data : data; // append leading zero if data is not aligned, eg "fff" => "0f ff"
|
|
6528
6528
|
align = align || 0;
|
|
6529
6529
|
if (align && bufferLen < align) {
|
|
6530
|
-
return buffer.Buffer.concat([
|
|
6530
|
+
return buffer.Buffer.concat([
|
|
6531
|
+
buffer.Buffer.from(Uint8Array.from({ length: align - bufferLen }).fill(0)),
|
|
6532
|
+
buffer.Buffer.from(data, "hex"),
|
|
6533
|
+
]);
|
|
6531
6534
|
}
|
|
6532
6535
|
return buffer.Buffer.from(data, "hex");
|
|
6533
6536
|
}
|
|
@@ -6550,11 +6553,15 @@ function sleep(milliSeconds) {
|
|
|
6550
6553
|
function getTransactionSize(transaction, feePayer) {
|
|
6551
6554
|
const clonedTransaction = new Transaction({
|
|
6552
6555
|
lastValidBlockHeight: 1234,
|
|
6553
|
-
feePayer: (transaction === null || transaction === void 0 ? void 0 : transaction.feePayer) ||
|
|
6556
|
+
feePayer: (transaction === null || transaction === void 0 ? void 0 : transaction.feePayer) ||
|
|
6557
|
+
feePayer ||
|
|
6558
|
+
transaction.instructions[0].programId,
|
|
6554
6559
|
blockhash: "CSymwgTNX1j3E4qhKfJAUE41nBWEwXufoYryPbkde5RR", // fake blockhash
|
|
6555
6560
|
}).add(transaction);
|
|
6556
6561
|
const serializedMessage = clonedTransaction.serializeMessage();
|
|
6557
|
-
const uniqueSigners = new Set(clonedTransaction.instructions.flatMap((ix) => ix.keys
|
|
6562
|
+
const uniqueSigners = new Set(clonedTransaction.instructions.flatMap((ix) => ix.keys
|
|
6563
|
+
.filter((meta) => meta.isSigner)
|
|
6564
|
+
.map((meta) => meta.pubkey.toBase58())));
|
|
6558
6565
|
// message length + signatures length (1 byte) + signatures count * signature size (64)
|
|
6559
6566
|
return serializedMessage.length + uniqueSigners.size * 64 + 1;
|
|
6560
6567
|
}
|
|
@@ -6581,7 +6588,9 @@ class Wallet {
|
|
|
6581
6588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6582
6589
|
const promises = [];
|
|
6583
6590
|
for (const [id, tx] of txs.entries()) {
|
|
6584
|
-
promises.push(this.signTransaction(tx, additionalSigners && additionalSigners.length > id
|
|
6591
|
+
promises.push(this.signTransaction(tx, additionalSigners && additionalSigners.length > id
|
|
6592
|
+
? additionalSigners[id]
|
|
6593
|
+
: []));
|
|
6585
6594
|
}
|
|
6586
6595
|
return Promise.all(promises);
|
|
6587
6596
|
});
|
|
@@ -6590,7 +6599,9 @@ class Wallet {
|
|
|
6590
6599
|
function sendWithRetries(connection, serialized, lastValidBlockHeight, timesToSend = 5, blockhashCommitment = "finalized") {
|
|
6591
6600
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6592
6601
|
const txId = yield connection.sendRawTransaction(serialized, {
|
|
6593
|
-
skipPreflight: false,
|
|
6602
|
+
skipPreflight: false,
|
|
6603
|
+
preflightCommitment: blockhashCommitment,
|
|
6604
|
+
maxRetries: 3,
|
|
6594
6605
|
});
|
|
6595
6606
|
let blockheight = yield connection.getBlockHeight();
|
|
6596
6607
|
let sent = 1;
|
|
@@ -6598,7 +6609,7 @@ function sendWithRetries(connection, serialized, lastValidBlockHeight, timesToSe
|
|
|
6598
6609
|
yield connection.sendRawTransaction(serialized, {
|
|
6599
6610
|
skipPreflight: true,
|
|
6600
6611
|
preflightCommitment: blockhashCommitment,
|
|
6601
|
-
maxRetries:
|
|
6612
|
+
maxRetries: 5,
|
|
6602
6613
|
});
|
|
6603
6614
|
yield sleep(300);
|
|
6604
6615
|
blockheight = yield connection.getBlockHeight();
|
|
@@ -6628,6 +6639,43 @@ function setBlockhash(transaction, blockhash) {
|
|
|
6628
6639
|
transaction.recentBlockhash = blockhash;
|
|
6629
6640
|
}
|
|
6630
6641
|
}
|
|
6642
|
+
function simulateTx(connection, tx, commitment, feePayer, convertToV0, alreadySigned) {
|
|
6643
|
+
var _a;
|
|
6644
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6645
|
+
let convert = convertToV0 && !alreadySigned;
|
|
6646
|
+
let txCopy = isVersionedTx(tx)
|
|
6647
|
+
? new VersionedTransaction(tx.message, tx.signatures)
|
|
6648
|
+
: new Transaction(tx);
|
|
6649
|
+
if (convert) {
|
|
6650
|
+
if (isVersionedTx(txCopy)) {
|
|
6651
|
+
txCopy.message.recentBlockhash = FAKE_BLOCKHASH;
|
|
6652
|
+
txCopy = tx;
|
|
6653
|
+
}
|
|
6654
|
+
else {
|
|
6655
|
+
txCopy = new VersionedTransaction(MessageV0.compile({
|
|
6656
|
+
addressLookupTableAccounts: [],
|
|
6657
|
+
instructions: txCopy.instructions,
|
|
6658
|
+
recentBlockhash: FAKE_BLOCKHASH,
|
|
6659
|
+
payerKey: feePayer,
|
|
6660
|
+
}));
|
|
6661
|
+
}
|
|
6662
|
+
}
|
|
6663
|
+
let result;
|
|
6664
|
+
if (isVersionedTx(txCopy)) {
|
|
6665
|
+
result = yield connection.simulateTransaction(txCopy, {
|
|
6666
|
+
commitment,
|
|
6667
|
+
sigVerify: alreadySigned,
|
|
6668
|
+
replaceRecentBlockhash: !alreadySigned,
|
|
6669
|
+
});
|
|
6670
|
+
}
|
|
6671
|
+
else {
|
|
6672
|
+
result = yield connection.simulateTransaction(txCopy.compileMessage());
|
|
6673
|
+
}
|
|
6674
|
+
if (result.value.err !== null) {
|
|
6675
|
+
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txCopy.serialize()).toString("base64")}\n Error: ${JSON.stringify(result.value.err)}, logs:\n ${(_a = result.value.logs) === null || _a === void 0 ? void 0 : _a.join("\n")}`);
|
|
6676
|
+
}
|
|
6677
|
+
});
|
|
6678
|
+
}
|
|
6631
6679
|
/**
|
|
6632
6680
|
*
|
|
6633
6681
|
* @param connection rpc connection
|
|
@@ -6639,9 +6687,11 @@ function setBlockhash(transaction, blockhash) {
|
|
|
6639
6687
|
function sendAll(connection, wallet, transactions, options) {
|
|
6640
6688
|
var _a, _b;
|
|
6641
6689
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6642
|
-
const
|
|
6690
|
+
const skipSign = (options === null || options === void 0 ? void 0 : options.skipSign) === undefined ? false : options.skipSign;
|
|
6691
|
+
const blockhashCommitment = (options === null || options === void 0 ? void 0 : options.blockhashCommitment) === undefined
|
|
6692
|
+
? (_a = connection.commitment) !== null && _a !== void 0 ? _a : "confirmed"
|
|
6693
|
+
: options.blockhashCommitment;
|
|
6643
6694
|
const convertIntoTxV0 = (options === null || options === void 0 ? void 0 : options.convertIntoTxV0) === undefined ? true : options.convertIntoTxV0;
|
|
6644
|
-
(options === null || options === void 0 ? void 0 : options.debug) === undefined ? false : options.debug;
|
|
6645
6695
|
const skipPreflight = (options === null || options === void 0 ? void 0 : options.skipPreflight) === undefined ? false : options.skipPreflight;
|
|
6646
6696
|
const rpcCalls = (options === null || options === void 0 ? void 0 : options.rpcCalls) === undefined ? 3 : options.rpcCalls;
|
|
6647
6697
|
if (!Array.isArray(transactions))
|
|
@@ -6651,37 +6701,14 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6651
6701
|
}
|
|
6652
6702
|
let txIds = [];
|
|
6653
6703
|
if ((options === null || options === void 0 ? void 0 : options.waitBetweenSend) === undefined || options.waitBetweenSend === 0) {
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
if (isVersionedTx(tx)) {
|
|
6658
|
-
tx.message.recentBlockhash = FAKE_BLOCKHASH;
|
|
6659
|
-
txV0 = tx;
|
|
6660
|
-
}
|
|
6661
|
-
else {
|
|
6662
|
-
tx.recentBlockhash = FAKE_BLOCKHASH;
|
|
6663
|
-
tx.feePayer = wallet.publicKey;
|
|
6664
|
-
txV0 = new VersionedTransaction(MessageV0.compile({
|
|
6665
|
-
addressLookupTableAccounts: [],
|
|
6666
|
-
instructions: tx.instructions,
|
|
6667
|
-
recentBlockhash: FAKE_BLOCKHASH,
|
|
6668
|
-
payerKey: tx.feePayer,
|
|
6669
|
-
}));
|
|
6670
|
-
}
|
|
6671
|
-
if (!skipPreflight) {
|
|
6672
|
-
const simulationResult = yield connection.simulateTransaction(txV0, {
|
|
6673
|
-
sigVerify: false,
|
|
6674
|
-
replaceRecentBlockhash: true,
|
|
6675
|
-
commitment: "confirmed",
|
|
6676
|
-
});
|
|
6677
|
-
if (simulationResult.value.err !== null) {
|
|
6678
|
-
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_c = simulationResult.value.logs) === null || _c === void 0 ? void 0 : _c.join("\n")}`);
|
|
6679
|
-
}
|
|
6680
|
-
}
|
|
6681
|
-
})));
|
|
6704
|
+
if (!skipPreflight) {
|
|
6705
|
+
yield Promise.all(transactions.map((tx) => simulateTx(connection, tx, blockhashCommitment, wallet.publicKey, convertIntoTxV0, skipSign)));
|
|
6706
|
+
}
|
|
6682
6707
|
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash({ commitment: blockhashCommitment });
|
|
6683
|
-
|
|
6684
|
-
|
|
6708
|
+
if (!skipSign) {
|
|
6709
|
+
// set real blockhash
|
|
6710
|
+
transactions.map((tx) => setBlockhash(tx, blockhash));
|
|
6711
|
+
}
|
|
6685
6712
|
// sign after setting correct blockhashes
|
|
6686
6713
|
const signed = yield wallet.signAllTransactions(transactions, options === null || options === void 0 ? void 0 : options.signers);
|
|
6687
6714
|
txIds = yield Promise.all(signed.map((signedTx) => {
|
|
@@ -6694,32 +6721,16 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6694
6721
|
else {
|
|
6695
6722
|
for (let i = 0; i < transactions.length; i++) {
|
|
6696
6723
|
const tx = transactions[i];
|
|
6697
|
-
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash({
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
tx.feePayer = wallet.publicKey;
|
|
6706
|
-
txV0 = new VersionedTransaction(MessageV0.compile({
|
|
6707
|
-
addressLookupTableAccounts: [],
|
|
6708
|
-
instructions: tx.instructions,
|
|
6709
|
-
recentBlockhash: blockhash,
|
|
6710
|
-
payerKey: tx.feePayer,
|
|
6711
|
-
}));
|
|
6712
|
-
}
|
|
6713
|
-
const signed = yield wallet.signTransaction(tx, (options === null || options === void 0 ? void 0 : options.signers) && (options === null || options === void 0 ? void 0 : options.signers.length) > i ? options.signers[i] : undefined);
|
|
6724
|
+
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash({
|
|
6725
|
+
commitment: blockhashCommitment,
|
|
6726
|
+
});
|
|
6727
|
+
const signed = skipSign
|
|
6728
|
+
? tx
|
|
6729
|
+
: yield wallet.signTransaction(tx, (options === null || options === void 0 ? void 0 : options.signers) && (options === null || options === void 0 ? void 0 : options.signers.length) > i
|
|
6730
|
+
? options.signers[i]
|
|
6731
|
+
: undefined);
|
|
6714
6732
|
if (!skipPreflight) {
|
|
6715
|
-
|
|
6716
|
-
sigVerify: false,
|
|
6717
|
-
replaceRecentBlockhash: true,
|
|
6718
|
-
commitment: "confirmed",
|
|
6719
|
-
});
|
|
6720
|
-
if (simulationResult.value.err !== null) {
|
|
6721
|
-
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_a = simulationResult.value.logs) === null || _a === void 0 ? void 0 : _a.join("\n")}`);
|
|
6722
|
-
}
|
|
6733
|
+
yield simulateTx(connection, tx, blockhashCommitment, wallet.publicKey, convertIntoTxV0, skipSign);
|
|
6723
6734
|
}
|
|
6724
6735
|
const serialized = buffer.Buffer.from(signed.serialize());
|
|
6725
6736
|
(_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.call(options, `Sending tx: ${serialized.toString("base64")}`);
|
|
@@ -6755,8 +6766,8 @@ var interfaces = /*#__PURE__*/Object.freeze({
|
|
|
6755
6766
|
* All functions are copied from ethers. This is optimization to reduce dependencies
|
|
6756
6767
|
*/
|
|
6757
6768
|
function concat(items) {
|
|
6758
|
-
const objects = items.map(item => arrayify(item));
|
|
6759
|
-
const length = objects.reduce((accum, item) =>
|
|
6769
|
+
const objects = items.map((item) => arrayify(item));
|
|
6770
|
+
const length = objects.reduce((accum, item) => accum + item.length, 0);
|
|
6760
6771
|
const result = new Uint8Array(length);
|
|
6761
6772
|
objects.reduce((offset, object) => {
|
|
6762
6773
|
result.set(object, offset);
|
|
@@ -6765,7 +6776,7 @@ function concat(items) {
|
|
|
6765
6776
|
return result;
|
|
6766
6777
|
}
|
|
6767
6778
|
function arrayify(value) {
|
|
6768
|
-
if (typeof
|
|
6779
|
+
if (typeof value === "number") {
|
|
6769
6780
|
const numValue = value;
|
|
6770
6781
|
const result = [];
|
|
6771
6782
|
while (value) {
|
|
@@ -6780,7 +6791,7 @@ function arrayify(value) {
|
|
|
6780
6791
|
if (BN.isBN(value)) {
|
|
6781
6792
|
value = `0x${value.toString("hex")}`;
|
|
6782
6793
|
}
|
|
6783
|
-
if (typeof
|
|
6794
|
+
if (typeof value === "string" && value.startsWith("0x")) {
|
|
6784
6795
|
return hexToBuffer(value);
|
|
6785
6796
|
}
|
|
6786
6797
|
if (Array.isArray(value) || ArrayBuffer.isView(value)) {
|
|
@@ -6830,7 +6841,7 @@ const zeroPad = (value, length) => {
|
|
|
6830
6841
|
result.set(bufValue, length - bufValue.length);
|
|
6831
6842
|
return result;
|
|
6832
6843
|
};
|
|
6833
|
-
const isHexString = (data) => typeof
|
|
6844
|
+
const isHexString = (data) => typeof data === "string" && data.startsWith("0x");
|
|
6834
6845
|
const _pack = (type, value, isArray) => {
|
|
6835
6846
|
const regexBytes = new RegExp("^bytes([0-9]+)$");
|
|
6836
6847
|
const regexNumber = new RegExp("^(u?int)([0-9]*)$");
|
|
@@ -6847,7 +6858,7 @@ const _pack = (type, value, isArray) => {
|
|
|
6847
6858
|
case "bytes":
|
|
6848
6859
|
return arrayify(value);
|
|
6849
6860
|
case "bool":
|
|
6850
|
-
value =
|
|
6861
|
+
value = value ? "0x01" : "0x00";
|
|
6851
6862
|
if (isArray) {
|
|
6852
6863
|
return zeroPad(value, 32);
|
|
6853
6864
|
}
|
|
@@ -6857,7 +6868,10 @@ const _pack = (type, value, isArray) => {
|
|
|
6857
6868
|
if (match) {
|
|
6858
6869
|
//let signed = (match[1] === "int")
|
|
6859
6870
|
let size = parseInt(match[2] || "256");
|
|
6860
|
-
if ((match[2] && String(size) !== match[2]) ||
|
|
6871
|
+
if ((match[2] && String(size) !== match[2]) ||
|
|
6872
|
+
size % 8 !== 0 ||
|
|
6873
|
+
size === 0 ||
|
|
6874
|
+
size > 256) {
|
|
6861
6875
|
throw new Error("invalid number type");
|
|
6862
6876
|
}
|
|
6863
6877
|
if (isArray) {
|
|
@@ -6931,7 +6945,13 @@ function normalizeChainId(chainId) {
|
|
|
6931
6945
|
function hashDeployInfo(params) {
|
|
6932
6946
|
const nameHash = solidityKeccak256(["string"], [params.tokenName]);
|
|
6933
6947
|
const symbolHash = solidityKeccak256(["string"], [params.tokenSymbol]);
|
|
6934
|
-
const deployInfoHash = solidityKeccak256(["uint256", "uint256", "uint256", "uint256", "uint8"], [
|
|
6948
|
+
const deployInfoHash = solidityKeccak256(["uint256", "uint256", "uint256", "uint256", "uint8"], [
|
|
6949
|
+
DEPLOY_INFO_PREFIX,
|
|
6950
|
+
params.debridgeId,
|
|
6951
|
+
nameHash,
|
|
6952
|
+
symbolHash,
|
|
6953
|
+
params.decimals,
|
|
6954
|
+
]);
|
|
6935
6955
|
return deployInfoHash;
|
|
6936
6956
|
}
|
|
6937
6957
|
/**
|
|
@@ -7034,49 +7054,84 @@ function findAssociatedTokenAddressSync(wallet, tokenMint, tokenProgramId = TOKE
|
|
|
7034
7054
|
return PublicKey.findProgramAddressSync([wallet.toBytes(), tokenProgramId.toBytes(), tokenMint.toBytes()], associatedTokenProramId);
|
|
7035
7055
|
}
|
|
7036
7056
|
function getTokenMetadataAddress(tokenMint, tokenMetedataProgramId) {
|
|
7037
|
-
return PublicKey.findProgramAddressSync([
|
|
7057
|
+
return PublicKey.findProgramAddressSync([
|
|
7058
|
+
buffer.Buffer.from("metadata"),
|
|
7059
|
+
tokenMetedataProgramId.toBytes(),
|
|
7060
|
+
tokenMint.toBytes(),
|
|
7061
|
+
], tokenMetedataProgramId);
|
|
7038
7062
|
}
|
|
7039
|
-
const deBridge = {
|
|
7040
|
-
getClaimMarkerAddress: (DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridge$
|
|
7063
|
+
const deBridge$1 = {
|
|
7064
|
+
getClaimMarkerAddress: (DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridge$2.Seeds.CLAIM_MARKER)], DEBRIDGE_PROGRAM_ID),
|
|
7041
7065
|
getExternalCallStorageAddress: (submissionId, executorPubkey, sourceChainId, DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7042
|
-
buffer.Buffer.from(deBridge$
|
|
7066
|
+
buffer.Buffer.from(deBridge$2.Seeds.EXTERNAL_CALL_STORAGE),
|
|
7043
7067
|
submissionId,
|
|
7044
7068
|
new PublicKey(executorPubkey).toBytes(),
|
|
7045
7069
|
normalizeChainId(sourceChainId),
|
|
7046
7070
|
], DEBRIDGE_PROGRAM_ID),
|
|
7047
|
-
getExternalCallMetaAddress: (externalCallStorage, DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7071
|
+
getExternalCallMetaAddress: (externalCallStorage, DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7072
|
+
buffer.Buffer.from(deBridge$2.Seeds.EXTERNAL_CALL_META),
|
|
7073
|
+
new PublicKey(externalCallStorage).toBytes(),
|
|
7074
|
+
], DEBRIDGE_PROGRAM_ID),
|
|
7075
|
+
getNonceAddress: (DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridge$2.Seeds.NONCE)], DEBRIDGE_PROGRAM_ID),
|
|
7076
|
+
getSubmissionAddress: (submissionId, DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridge$2.Seeds.SUBMISSION), submissionId], DEBRIDGE_PROGRAM_ID),
|
|
7077
|
+
getSubmissionAuthAddress: (submissionAddress, DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7078
|
+
buffer.Buffer.from(deBridge$2.Seeds.SUBMISSION_AUTH),
|
|
7079
|
+
new PublicKey(submissionAddress).toBytes(),
|
|
7080
|
+
], DEBRIDGE_PROGRAM_ID),
|
|
7081
|
+
getMintAuthorityAddress: (bridge, DEBRIDGE_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7082
|
+
buffer.Buffer.from(deBridge$2.Seeds.BRIDGE_MINTER),
|
|
7083
|
+
new PublicKey(bridge).toBytes(),
|
|
7084
|
+
], DEBRIDGE_PROGRAM_ID),
|
|
7052
7085
|
};
|
|
7053
7086
|
const deBridgeSettings = {
|
|
7054
7087
|
getTokenMetadataMasterAddress: (SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridgeSettings$1.Seeds.TOKEN_METADATA)], SETTINGS_PROGRAM_ID),
|
|
7055
7088
|
getTokenMintAddress: (debridgeId, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridgeSettings$1.Seeds.WRAPPER_TOKEN), debridgeId], SETTINGS_PROGRAM_ID),
|
|
7056
7089
|
getStateAddress: (SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridgeSettings$1.Seeds.STATE)], SETTINGS_PROGRAM_ID),
|
|
7057
|
-
getConfirmationsStorageAddress: (message, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7090
|
+
getConfirmationsStorageAddress: (message, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7091
|
+
buffer.Buffer.from(deBridgeSettings$1.Seeds.CONFIRMATION_STORAGE),
|
|
7092
|
+
message,
|
|
7093
|
+
], SETTINGS_PROGRAM_ID),
|
|
7094
|
+
getBridgeFeeAddress: (bridge, chainId, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7095
|
+
buffer.Buffer.from(deBridgeSettings$1.Seeds.BRIDGE_FEE_INFO),
|
|
7096
|
+
bridge.toBytes(),
|
|
7097
|
+
normalizeChainId(chainId),
|
|
7098
|
+
], SETTINGS_PROGRAM_ID),
|
|
7099
|
+
getChainSupportInfoAddress: (chainId, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7100
|
+
buffer.Buffer.from(deBridgeSettings$1.Seeds.CHAIN_SUPPORT_INFO),
|
|
7101
|
+
normalizeChainId(chainId),
|
|
7102
|
+
], SETTINGS_PROGRAM_ID),
|
|
7103
|
+
getDiscountInfoAddress: (user, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7104
|
+
buffer.Buffer.from(deBridgeSettings$1.Seeds.DISCOUNT_INFO),
|
|
7105
|
+
user.toBytes(),
|
|
7106
|
+
], SETTINGS_PROGRAM_ID),
|
|
7107
|
+
getBridgeAddress: (tokenMint, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7108
|
+
buffer.Buffer.from(deBridgeSettings$1.Seeds.BRIDGE),
|
|
7109
|
+
tokenMint.toBytes(),
|
|
7110
|
+
], SETTINGS_PROGRAM_ID),
|
|
7062
7111
|
getBridgeMapAddress: (bridgeId, SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridgeSettings$1.Seeds.SEND_BRIDGE_MAP), bridgeId], SETTINGS_PROGRAM_ID),
|
|
7063
7112
|
getNoDiscountAddress: (SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridgeSettings$1.Seeds.NO_DISCOUNT)], SETTINGS_PROGRAM_ID),
|
|
7064
7113
|
getNoBridgeFeeAddress: (SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridgeSettings$1.Seeds.NO_BRIDGE_FEE_INFO)], SETTINGS_PROGRAM_ID),
|
|
7065
7114
|
};
|
|
7066
|
-
const
|
|
7067
|
-
getStateAccount: (PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(
|
|
7068
|
-
getNonceAccount: (maker, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7115
|
+
const DlnSrc = {
|
|
7116
|
+
getStateAccount: (PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.STATE)], PMM_SRC_PROGRAM_ID),
|
|
7117
|
+
getNonceAccount: (maker, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7118
|
+
buffer.Buffer.from(dlnSrc$1.Seeds.NONCE),
|
|
7119
|
+
isBuffer(maker) ? maker : maker.toBuffer(),
|
|
7120
|
+
], PMM_SRC_PROGRAM_ID),
|
|
7121
|
+
getGiveOrderStateAccount: (orderId, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.ORDER_STATE), orderId], PMM_SRC_PROGRAM_ID),
|
|
7122
|
+
getAuthorizedNativeSenderAddress: (chainId, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.AUTHORIZED_NATIVE_SENDER), chainId], PMM_SRC_PROGRAM_ID),
|
|
7123
|
+
getGiveOrderWalletAddress: (orderId, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.GIVE_ORDER_WALLET), orderId], PMM_SRC_PROGRAM_ID),
|
|
7124
|
+
getFeeLedgerWalletAddress: (tokenMint, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([
|
|
7125
|
+
buffer.Buffer.from(dlnSrc$1.Seeds.FEE_LEDGER_WALLET),
|
|
7126
|
+
tokenMint.toBuffer(),
|
|
7127
|
+
], PMM_SRC_PROGRAM_ID),
|
|
7128
|
+
getFeeLedgerAddress: (PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.FEE_LEDGER)], PMM_SRC_PROGRAM_ID),
|
|
7074
7129
|
};
|
|
7075
|
-
const
|
|
7076
|
-
getAuthorizedSrcContractAddress: (chainId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(
|
|
7077
|
-
getAuthorizedDstNativeSenderAddress: (PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(
|
|
7078
|
-
getTakeOrderStateAddress: (orderId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(
|
|
7079
|
-
getTakePatchAddress: (orderId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(
|
|
7130
|
+
const DlnDst = {
|
|
7131
|
+
getAuthorizedSrcContractAddress: (chainId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.AUTHORIZED_SRC_CONTRACT), chainId], PMM_DST_PROGRAM_ID),
|
|
7132
|
+
getAuthorizedDstNativeSenderAddress: (PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.AUTHORIZED_DST_NATIVE_SENDER)], PMM_DST_PROGRAM_ID),
|
|
7133
|
+
getTakeOrderStateAddress: (orderId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.ORDER_STATE), orderId], PMM_DST_PROGRAM_ID),
|
|
7134
|
+
getTakePatchAddress: (orderId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.TAKE_PATCH), orderId], PMM_DST_PROGRAM_ID),
|
|
7080
7135
|
};
|
|
7081
7136
|
function wrapFn(fn, arg) {
|
|
7082
7137
|
return (...args) => fn(...args, arg);
|
|
@@ -7102,9 +7157,9 @@ class ResolverContainer2 {
|
|
|
7102
7157
|
this.methods = methods;
|
|
7103
7158
|
}
|
|
7104
7159
|
}
|
|
7105
|
-
const DeBridgeResolver = (programId, settingsProgramId) => new ResolverContainer2(new Resolver(programId, deBridge), new Resolver(settingsProgramId, deBridgeSettings));
|
|
7106
|
-
const
|
|
7107
|
-
const
|
|
7160
|
+
const DeBridgeResolver = (programId, settingsProgramId) => new ResolverContainer2(new Resolver(programId, deBridge$1), new Resolver(settingsProgramId, deBridgeSettings));
|
|
7161
|
+
const dlnSrcResolver = (programId) => new Resolver(programId, DlnSrc);
|
|
7162
|
+
const dlnDstResolver = (programId) => new Resolver(programId, DlnDst);
|
|
7108
7163
|
|
|
7109
7164
|
var Layout$1 = {};
|
|
7110
7165
|
|
|
@@ -9497,17 +9552,17 @@ var AccountState;
|
|
|
9497
9552
|
AccountState[AccountState["Frozen"] = 2] = "Frozen";
|
|
9498
9553
|
})(AccountState || (AccountState = {}));
|
|
9499
9554
|
const AccountLayout = struct([
|
|
9500
|
-
publicKey(
|
|
9501
|
-
publicKey(
|
|
9502
|
-
u64(
|
|
9503
|
-
u32(
|
|
9504
|
-
publicKey(
|
|
9505
|
-
u8(
|
|
9506
|
-
u32(
|
|
9507
|
-
u64(
|
|
9508
|
-
u64(
|
|
9509
|
-
u32(
|
|
9510
|
-
publicKey(
|
|
9555
|
+
publicKey("mint"),
|
|
9556
|
+
publicKey("owner"),
|
|
9557
|
+
u64("amount"),
|
|
9558
|
+
u32("delegateOption"),
|
|
9559
|
+
publicKey("delegate"),
|
|
9560
|
+
u8("state"),
|
|
9561
|
+
u32("isNativeOption"),
|
|
9562
|
+
u64("isNative"),
|
|
9563
|
+
u64("delegatedAmount"),
|
|
9564
|
+
u32("closeAuthorityOption"),
|
|
9565
|
+
publicKey("closeAuthority"),
|
|
9511
9566
|
]);
|
|
9512
9567
|
var AccountType;
|
|
9513
9568
|
(function (AccountType) {
|
|
@@ -9526,7 +9581,11 @@ var AccountType;
|
|
|
9526
9581
|
function getTokenInfo(connection, tokenAddress) {
|
|
9527
9582
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9528
9583
|
const tokenMetaProgramId = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
9529
|
-
const findMetaplexMetadataPda = (tokenMint) => PublicKey.findProgramAddressSync([
|
|
9584
|
+
const findMetaplexMetadataPda = (tokenMint) => PublicKey.findProgramAddressSync([
|
|
9585
|
+
buffer.Buffer.from("metadata", "utf-8"),
|
|
9586
|
+
tokenMetaProgramId.toBuffer(),
|
|
9587
|
+
tokenMint.toBuffer(),
|
|
9588
|
+
], tokenMetaProgramId)[0];
|
|
9530
9589
|
const decodeMetaplexMetadataPartial = (data) => {
|
|
9531
9590
|
const rawName = data.subarray(65 + 4, 65 + 36); // omit first 4 bytes, size is already hardcoded
|
|
9532
9591
|
const rawSymbol = data.subarray(101 + 4, 115); // omit first 4 bytes, size is already hardcoded
|
|
@@ -9538,8 +9597,13 @@ function getTokenInfo(connection, tokenAddress) {
|
|
|
9538
9597
|
};
|
|
9539
9598
|
};
|
|
9540
9599
|
const pda = findMetaplexMetadataPda(tokenAddress);
|
|
9541
|
-
const [tokenAccount, pdaAccount] = yield connection.getMultipleAccountsInfo([
|
|
9542
|
-
|
|
9600
|
+
const [tokenAccount, pdaAccount] = yield connection.getMultipleAccountsInfo([
|
|
9601
|
+
tokenAddress,
|
|
9602
|
+
pda,
|
|
9603
|
+
]);
|
|
9604
|
+
if (tokenAccount === null ||
|
|
9605
|
+
pdaAccount === null ||
|
|
9606
|
+
(pdaAccount === null || pdaAccount === void 0 ? void 0 : pdaAccount.lamports) === 0) {
|
|
9543
9607
|
return null;
|
|
9544
9608
|
}
|
|
9545
9609
|
// parse token account
|
|
@@ -9636,7 +9700,9 @@ function getAccountWithType(connection, account) {
|
|
|
9636
9700
|
if (!accountData)
|
|
9637
9701
|
return [null, AccountType.NotExists];
|
|
9638
9702
|
if (accountData.owner.equals(TOKEN_PROGRAM_ID)) {
|
|
9639
|
-
return isWalletCorrectATA(account, accountData.data)
|
|
9703
|
+
return isWalletCorrectATA(account, accountData.data)
|
|
9704
|
+
? [accountData, AccountType.CorrectATA]
|
|
9705
|
+
: [accountData, AccountType.Token];
|
|
9640
9706
|
}
|
|
9641
9707
|
if (accountData.owner.equals(SystemProgram.programId))
|
|
9642
9708
|
return [accountData, AccountType.System];
|
|
@@ -9737,7 +9803,11 @@ function buildReplenishWsolBalanceTransaction(amount, transferFrom, transferTo)
|
|
|
9737
9803
|
transferFrom = new PublicKey(transferFrom);
|
|
9738
9804
|
transferTo = new PublicKey(transferTo);
|
|
9739
9805
|
const tx = new Transaction();
|
|
9740
|
-
tx.add(SystemProgram.transfer({
|
|
9806
|
+
tx.add(SystemProgram.transfer({
|
|
9807
|
+
fromPubkey: transferFrom,
|
|
9808
|
+
toPubkey: transferTo,
|
|
9809
|
+
lamports: new BN(amount).toNumber(),
|
|
9810
|
+
}));
|
|
9741
9811
|
tx.add(
|
|
9742
9812
|
// sync native
|
|
9743
9813
|
new TransactionInstruction({
|
|
@@ -9809,5 +9879,20 @@ var spl = /*#__PURE__*/Object.freeze({
|
|
|
9809
9879
|
checkIfAssociatedWalletExists: checkIfAssociatedWalletExists
|
|
9810
9880
|
});
|
|
9811
9881
|
|
|
9812
|
-
|
|
9882
|
+
const deBridge = "DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh";
|
|
9883
|
+
const settings = "DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft";
|
|
9884
|
+
const dlnSrc = "src5qyZHqTqecJV4aY6Cb6zDZLMDzrDKKezs22MPHr4";
|
|
9885
|
+
const dlnDst = "dst5MGcFPoBeREFAA5E3tU5ij8m5uVYwkzkSAbsLbNo";
|
|
9886
|
+
const dlnExecutor = "exe59FS5cojZkPJVDFDV8RnXCC7wd6yoBjsUtqH7Zai";
|
|
9887
|
+
|
|
9888
|
+
var programs = /*#__PURE__*/Object.freeze({
|
|
9889
|
+
__proto__: null,
|
|
9890
|
+
deBridge: deBridge,
|
|
9891
|
+
settings: settings,
|
|
9892
|
+
dlnSrc: dlnSrc,
|
|
9893
|
+
dlnDst: dlnDst,
|
|
9894
|
+
dlnExecutor: dlnExecutor
|
|
9895
|
+
});
|
|
9896
|
+
|
|
9897
|
+
export { ASSOCIATED_TOKEN_PROGRAM_ID, DeBridgeResolver, TOKEN_METADATA_PROGRAM_ID, TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT, constants, crypto, dlnDstResolver, dlnSrcResolver, findAssociatedTokenAddress, findAssociatedTokenAddressSync, getTokenMetadataAddress, helpers, interfaces, programs, spl };
|
|
9813
9898
|
//# sourceMappingURL=index.js.map
|