@debridge-finance/solana-utils 3.0.0 → 4.0.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 +71 -645
- package/dist/browser/index.js +255 -1100
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/constants.js +4 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/crypto.js +18 -10
- package/dist/cjs/crypto.js.map +1 -1
- package/dist/cjs/helpers.js +9 -10
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/solidityPack.js +168 -0
- package/dist/cjs/solidityPack.js.map +1 -0
- package/dist/cjs/spl.js +2 -9
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/constants.js +3 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/crypto.js +15 -9
- package/dist/esm/crypto.js.map +1 -1
- package/dist/esm/helpers.js +9 -10
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/solidityPack.js +163 -0
- package/dist/esm/solidityPack.js.map +1 -0
- package/dist/esm/spl.js +2 -9
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/constants.d.ts +3 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/crypto.d.ts +2 -0
- package/dist/types/crypto.d.ts.map +1 -1
- package/dist/types/helpers.d.ts.map +1 -1
- package/dist/types/solidityPack.d.ts +2 -0
- package/dist/types/solidityPack.d.ts.map +1 -0
- package/dist/types/spl.d.ts.map +1 -1
- package/package.json +6 -5
package/dist/browser/index.js
CHANGED
|
@@ -5734,812 +5734,9 @@ var require$$0 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
|
|
|
5734
5734
|
})(module, commonjsGlobal);
|
|
5735
5735
|
} (bn));
|
|
5736
5736
|
|
|
5737
|
-
var BN
|
|
5737
|
+
var BN = bn.exports;
|
|
5738
5738
|
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
let _permanentCensorErrors = false;
|
|
5742
|
-
let _censorErrors = false;
|
|
5743
|
-
const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
5744
|
-
let _logLevel = LogLevels["default"];
|
|
5745
|
-
let _globalLogger = null;
|
|
5746
|
-
function _checkNormalize() {
|
|
5747
|
-
try {
|
|
5748
|
-
const missing = [];
|
|
5749
|
-
// Make sure all forms of normalization are supported
|
|
5750
|
-
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
5751
|
-
try {
|
|
5752
|
-
if ("test".normalize(form) !== "test") {
|
|
5753
|
-
throw new Error("bad normalize");
|
|
5754
|
-
}
|
|
5755
|
-
;
|
|
5756
|
-
}
|
|
5757
|
-
catch (error) {
|
|
5758
|
-
missing.push(form);
|
|
5759
|
-
}
|
|
5760
|
-
});
|
|
5761
|
-
if (missing.length) {
|
|
5762
|
-
throw new Error("missing " + missing.join(", "));
|
|
5763
|
-
}
|
|
5764
|
-
if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
|
|
5765
|
-
throw new Error("broken implementation");
|
|
5766
|
-
}
|
|
5767
|
-
}
|
|
5768
|
-
catch (error) {
|
|
5769
|
-
return error.message;
|
|
5770
|
-
}
|
|
5771
|
-
return null;
|
|
5772
|
-
}
|
|
5773
|
-
const _normalizeError = _checkNormalize();
|
|
5774
|
-
var LogLevel;
|
|
5775
|
-
(function (LogLevel) {
|
|
5776
|
-
LogLevel["DEBUG"] = "DEBUG";
|
|
5777
|
-
LogLevel["INFO"] = "INFO";
|
|
5778
|
-
LogLevel["WARNING"] = "WARNING";
|
|
5779
|
-
LogLevel["ERROR"] = "ERROR";
|
|
5780
|
-
LogLevel["OFF"] = "OFF";
|
|
5781
|
-
})(LogLevel || (LogLevel = {}));
|
|
5782
|
-
var ErrorCode;
|
|
5783
|
-
(function (ErrorCode) {
|
|
5784
|
-
///////////////////
|
|
5785
|
-
// Generic Errors
|
|
5786
|
-
// Unknown Error
|
|
5787
|
-
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
5788
|
-
// Not Implemented
|
|
5789
|
-
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
5790
|
-
// Unsupported Operation
|
|
5791
|
-
// - operation
|
|
5792
|
-
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
5793
|
-
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
5794
|
-
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
5795
|
-
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
5796
|
-
// Some sort of bad response from the server
|
|
5797
|
-
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
5798
|
-
// Timeout
|
|
5799
|
-
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
5800
|
-
///////////////////
|
|
5801
|
-
// Operational Errors
|
|
5802
|
-
// Buffer Overrun
|
|
5803
|
-
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
5804
|
-
// Numeric Fault
|
|
5805
|
-
// - operation: the operation being executed
|
|
5806
|
-
// - fault: the reason this faulted
|
|
5807
|
-
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
5808
|
-
///////////////////
|
|
5809
|
-
// Argument Errors
|
|
5810
|
-
// Missing new operator to an object
|
|
5811
|
-
// - name: The name of the class
|
|
5812
|
-
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
5813
|
-
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
5814
|
-
// - argument: The argument name that was invalid
|
|
5815
|
-
// - value: The value of the argument
|
|
5816
|
-
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
5817
|
-
// Missing argument to a function:
|
|
5818
|
-
// - count: The number of arguments received
|
|
5819
|
-
// - expectedCount: The number of arguments expected
|
|
5820
|
-
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
5821
|
-
// Too many arguments
|
|
5822
|
-
// - count: The number of arguments received
|
|
5823
|
-
// - expectedCount: The number of arguments expected
|
|
5824
|
-
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
5825
|
-
///////////////////
|
|
5826
|
-
// Blockchain Errors
|
|
5827
|
-
// Call exception
|
|
5828
|
-
// - transaction: the transaction
|
|
5829
|
-
// - address?: the contract address
|
|
5830
|
-
// - args?: The arguments passed into the function
|
|
5831
|
-
// - method?: The Solidity method signature
|
|
5832
|
-
// - errorSignature?: The EIP848 error signature
|
|
5833
|
-
// - errorArgs?: The EIP848 error parameters
|
|
5834
|
-
// - reason: The reason (only for EIP848 "Error(string)")
|
|
5835
|
-
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
5836
|
-
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
5837
|
-
// - transaction: the transaction attempted
|
|
5838
|
-
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
5839
|
-
// Nonce has already been used
|
|
5840
|
-
// - transaction: the transaction attempted
|
|
5841
|
-
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
5842
|
-
// The replacement fee for the transaction is too low
|
|
5843
|
-
// - transaction: the transaction attempted
|
|
5844
|
-
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
5845
|
-
// The gas limit could not be estimated
|
|
5846
|
-
// - transaction: the transaction passed to estimateGas
|
|
5847
|
-
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
5848
|
-
// The transaction was replaced by one with a higher gas price
|
|
5849
|
-
// - reason: "cancelled", "replaced" or "repriced"
|
|
5850
|
-
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
5851
|
-
// - hash: original transaction hash
|
|
5852
|
-
// - replacement: the full TransactionsResponse for the replacement
|
|
5853
|
-
// - receipt: the receipt of the replacement
|
|
5854
|
-
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
5855
|
-
///////////////////
|
|
5856
|
-
// Interaction Errors
|
|
5857
|
-
// The user rejected the action, such as signing a message or sending
|
|
5858
|
-
// a transaction
|
|
5859
|
-
ErrorCode["ACTION_REJECTED"] = "ACTION_REJECTED";
|
|
5860
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
5861
|
-
const HEX = "0123456789abcdef";
|
|
5862
|
-
class Logger {
|
|
5863
|
-
constructor(version) {
|
|
5864
|
-
Object.defineProperty(this, "version", {
|
|
5865
|
-
enumerable: true,
|
|
5866
|
-
value: version,
|
|
5867
|
-
writable: false
|
|
5868
|
-
});
|
|
5869
|
-
}
|
|
5870
|
-
_log(logLevel, args) {
|
|
5871
|
-
const level = logLevel.toLowerCase();
|
|
5872
|
-
if (LogLevels[level] == null) {
|
|
5873
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
5874
|
-
}
|
|
5875
|
-
if (_logLevel > LogLevels[level]) {
|
|
5876
|
-
return;
|
|
5877
|
-
}
|
|
5878
|
-
console.log.apply(console, args);
|
|
5879
|
-
}
|
|
5880
|
-
debug(...args) {
|
|
5881
|
-
this._log(Logger.levels.DEBUG, args);
|
|
5882
|
-
}
|
|
5883
|
-
info(...args) {
|
|
5884
|
-
this._log(Logger.levels.INFO, args);
|
|
5885
|
-
}
|
|
5886
|
-
warn(...args) {
|
|
5887
|
-
this._log(Logger.levels.WARNING, args);
|
|
5888
|
-
}
|
|
5889
|
-
makeError(message, code, params) {
|
|
5890
|
-
// Errors are being censored
|
|
5891
|
-
if (_censorErrors) {
|
|
5892
|
-
return this.makeError("censored error", code, {});
|
|
5893
|
-
}
|
|
5894
|
-
if (!code) {
|
|
5895
|
-
code = Logger.errors.UNKNOWN_ERROR;
|
|
5896
|
-
}
|
|
5897
|
-
if (!params) {
|
|
5898
|
-
params = {};
|
|
5899
|
-
}
|
|
5900
|
-
const messageDetails = [];
|
|
5901
|
-
Object.keys(params).forEach((key) => {
|
|
5902
|
-
const value = params[key];
|
|
5903
|
-
try {
|
|
5904
|
-
if (value instanceof Uint8Array) {
|
|
5905
|
-
let hex = "";
|
|
5906
|
-
for (let i = 0; i < value.length; i++) {
|
|
5907
|
-
hex += HEX[value[i] >> 4];
|
|
5908
|
-
hex += HEX[value[i] & 0x0f];
|
|
5909
|
-
}
|
|
5910
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
5911
|
-
}
|
|
5912
|
-
else {
|
|
5913
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
5914
|
-
}
|
|
5915
|
-
}
|
|
5916
|
-
catch (error) {
|
|
5917
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
5918
|
-
}
|
|
5919
|
-
});
|
|
5920
|
-
messageDetails.push(`code=${code}`);
|
|
5921
|
-
messageDetails.push(`version=${this.version}`);
|
|
5922
|
-
const reason = message;
|
|
5923
|
-
let url = "";
|
|
5924
|
-
switch (code) {
|
|
5925
|
-
case ErrorCode.NUMERIC_FAULT: {
|
|
5926
|
-
url = "NUMERIC_FAULT";
|
|
5927
|
-
const fault = message;
|
|
5928
|
-
switch (fault) {
|
|
5929
|
-
case "overflow":
|
|
5930
|
-
case "underflow":
|
|
5931
|
-
case "division-by-zero":
|
|
5932
|
-
url += "-" + fault;
|
|
5933
|
-
break;
|
|
5934
|
-
case "negative-power":
|
|
5935
|
-
case "negative-width":
|
|
5936
|
-
url += "-unsupported";
|
|
5937
|
-
break;
|
|
5938
|
-
case "unbound-bitwise-result":
|
|
5939
|
-
url += "-unbound-result";
|
|
5940
|
-
break;
|
|
5941
|
-
}
|
|
5942
|
-
break;
|
|
5943
|
-
}
|
|
5944
|
-
case ErrorCode.CALL_EXCEPTION:
|
|
5945
|
-
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
5946
|
-
case ErrorCode.MISSING_NEW:
|
|
5947
|
-
case ErrorCode.NONCE_EXPIRED:
|
|
5948
|
-
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
5949
|
-
case ErrorCode.TRANSACTION_REPLACED:
|
|
5950
|
-
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
5951
|
-
url = code;
|
|
5952
|
-
break;
|
|
5953
|
-
}
|
|
5954
|
-
if (url) {
|
|
5955
|
-
message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
|
|
5956
|
-
}
|
|
5957
|
-
if (messageDetails.length) {
|
|
5958
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
5959
|
-
}
|
|
5960
|
-
// @TODO: Any??
|
|
5961
|
-
const error = new Error(message);
|
|
5962
|
-
error.reason = reason;
|
|
5963
|
-
error.code = code;
|
|
5964
|
-
Object.keys(params).forEach(function (key) {
|
|
5965
|
-
error[key] = params[key];
|
|
5966
|
-
});
|
|
5967
|
-
return error;
|
|
5968
|
-
}
|
|
5969
|
-
throwError(message, code, params) {
|
|
5970
|
-
throw this.makeError(message, code, params);
|
|
5971
|
-
}
|
|
5972
|
-
throwArgumentError(message, name, value) {
|
|
5973
|
-
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
5974
|
-
argument: name,
|
|
5975
|
-
value: value
|
|
5976
|
-
});
|
|
5977
|
-
}
|
|
5978
|
-
assert(condition, message, code, params) {
|
|
5979
|
-
if (!!condition) {
|
|
5980
|
-
return;
|
|
5981
|
-
}
|
|
5982
|
-
this.throwError(message, code, params);
|
|
5983
|
-
}
|
|
5984
|
-
assertArgument(condition, message, name, value) {
|
|
5985
|
-
if (!!condition) {
|
|
5986
|
-
return;
|
|
5987
|
-
}
|
|
5988
|
-
this.throwArgumentError(message, name, value);
|
|
5989
|
-
}
|
|
5990
|
-
checkNormalize(message) {
|
|
5991
|
-
if (_normalizeError) {
|
|
5992
|
-
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
5993
|
-
operation: "String.prototype.normalize", form: _normalizeError
|
|
5994
|
-
});
|
|
5995
|
-
}
|
|
5996
|
-
}
|
|
5997
|
-
checkSafeUint53(value, message) {
|
|
5998
|
-
if (typeof (value) !== "number") {
|
|
5999
|
-
return;
|
|
6000
|
-
}
|
|
6001
|
-
if (message == null) {
|
|
6002
|
-
message = "value not safe";
|
|
6003
|
-
}
|
|
6004
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
6005
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
6006
|
-
operation: "checkSafeInteger",
|
|
6007
|
-
fault: "out-of-safe-range",
|
|
6008
|
-
value: value
|
|
6009
|
-
});
|
|
6010
|
-
}
|
|
6011
|
-
if (value % 1) {
|
|
6012
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
6013
|
-
operation: "checkSafeInteger",
|
|
6014
|
-
fault: "non-integer",
|
|
6015
|
-
value: value
|
|
6016
|
-
});
|
|
6017
|
-
}
|
|
6018
|
-
}
|
|
6019
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
6020
|
-
if (message) {
|
|
6021
|
-
message = ": " + message;
|
|
6022
|
-
}
|
|
6023
|
-
else {
|
|
6024
|
-
message = "";
|
|
6025
|
-
}
|
|
6026
|
-
if (count < expectedCount) {
|
|
6027
|
-
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
6028
|
-
count: count,
|
|
6029
|
-
expectedCount: expectedCount
|
|
6030
|
-
});
|
|
6031
|
-
}
|
|
6032
|
-
if (count > expectedCount) {
|
|
6033
|
-
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
6034
|
-
count: count,
|
|
6035
|
-
expectedCount: expectedCount
|
|
6036
|
-
});
|
|
6037
|
-
}
|
|
6038
|
-
}
|
|
6039
|
-
checkNew(target, kind) {
|
|
6040
|
-
if (target === Object || target == null) {
|
|
6041
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
6042
|
-
}
|
|
6043
|
-
}
|
|
6044
|
-
checkAbstract(target, kind) {
|
|
6045
|
-
if (target === kind) {
|
|
6046
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
6047
|
-
}
|
|
6048
|
-
else if (target === Object || target == null) {
|
|
6049
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
6050
|
-
}
|
|
6051
|
-
}
|
|
6052
|
-
static globalLogger() {
|
|
6053
|
-
if (!_globalLogger) {
|
|
6054
|
-
_globalLogger = new Logger(version$4);
|
|
6055
|
-
}
|
|
6056
|
-
return _globalLogger;
|
|
6057
|
-
}
|
|
6058
|
-
static setCensorship(censorship, permanent) {
|
|
6059
|
-
if (!censorship && permanent) {
|
|
6060
|
-
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
6061
|
-
operation: "setCensorship"
|
|
6062
|
-
});
|
|
6063
|
-
}
|
|
6064
|
-
if (_permanentCensorErrors) {
|
|
6065
|
-
if (!censorship) {
|
|
6066
|
-
return;
|
|
6067
|
-
}
|
|
6068
|
-
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
6069
|
-
operation: "setCensorship"
|
|
6070
|
-
});
|
|
6071
|
-
}
|
|
6072
|
-
_censorErrors = !!censorship;
|
|
6073
|
-
_permanentCensorErrors = !!permanent;
|
|
6074
|
-
}
|
|
6075
|
-
static setLogLevel(logLevel) {
|
|
6076
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
6077
|
-
if (level == null) {
|
|
6078
|
-
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
6079
|
-
return;
|
|
6080
|
-
}
|
|
6081
|
-
_logLevel = level;
|
|
6082
|
-
}
|
|
6083
|
-
static from(version) {
|
|
6084
|
-
return new Logger(version);
|
|
6085
|
-
}
|
|
6086
|
-
}
|
|
6087
|
-
Logger.errors = ErrorCode;
|
|
6088
|
-
Logger.levels = LogLevel;
|
|
6089
|
-
|
|
6090
|
-
const version$3 = "bytes/5.7.0";
|
|
6091
|
-
|
|
6092
|
-
const logger$3 = new Logger(version$3);
|
|
6093
|
-
///////////////////////////////
|
|
6094
|
-
function isHexable(value) {
|
|
6095
|
-
return !!(value.toHexString);
|
|
6096
|
-
}
|
|
6097
|
-
function addSlice(array) {
|
|
6098
|
-
if (array.slice) {
|
|
6099
|
-
return array;
|
|
6100
|
-
}
|
|
6101
|
-
array.slice = function () {
|
|
6102
|
-
const args = Array.prototype.slice.call(arguments);
|
|
6103
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
6104
|
-
};
|
|
6105
|
-
return array;
|
|
6106
|
-
}
|
|
6107
|
-
function isInteger(value) {
|
|
6108
|
-
return (typeof (value) === "number" && value == value && (value % 1) === 0);
|
|
6109
|
-
}
|
|
6110
|
-
function isBytes(value) {
|
|
6111
|
-
if (value == null) {
|
|
6112
|
-
return false;
|
|
6113
|
-
}
|
|
6114
|
-
if (value.constructor === Uint8Array) {
|
|
6115
|
-
return true;
|
|
6116
|
-
}
|
|
6117
|
-
if (typeof (value) === "string") {
|
|
6118
|
-
return false;
|
|
6119
|
-
}
|
|
6120
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
6121
|
-
return false;
|
|
6122
|
-
}
|
|
6123
|
-
for (let i = 0; i < value.length; i++) {
|
|
6124
|
-
const v = value[i];
|
|
6125
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
6126
|
-
return false;
|
|
6127
|
-
}
|
|
6128
|
-
}
|
|
6129
|
-
return true;
|
|
6130
|
-
}
|
|
6131
|
-
function arrayify(value, options) {
|
|
6132
|
-
if (!options) {
|
|
6133
|
-
options = {};
|
|
6134
|
-
}
|
|
6135
|
-
if (typeof (value) === "number") {
|
|
6136
|
-
logger$3.checkSafeUint53(value, "invalid arrayify value");
|
|
6137
|
-
const result = [];
|
|
6138
|
-
while (value) {
|
|
6139
|
-
result.unshift(value & 0xff);
|
|
6140
|
-
value = parseInt(String(value / 256));
|
|
6141
|
-
}
|
|
6142
|
-
if (result.length === 0) {
|
|
6143
|
-
result.push(0);
|
|
6144
|
-
}
|
|
6145
|
-
return addSlice(new Uint8Array(result));
|
|
6146
|
-
}
|
|
6147
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
6148
|
-
value = "0x" + value;
|
|
6149
|
-
}
|
|
6150
|
-
if (isHexable(value)) {
|
|
6151
|
-
value = value.toHexString();
|
|
6152
|
-
}
|
|
6153
|
-
if (isHexString(value)) {
|
|
6154
|
-
let hex = value.substring(2);
|
|
6155
|
-
if (hex.length % 2) {
|
|
6156
|
-
if (options.hexPad === "left") {
|
|
6157
|
-
hex = "0" + hex;
|
|
6158
|
-
}
|
|
6159
|
-
else if (options.hexPad === "right") {
|
|
6160
|
-
hex += "0";
|
|
6161
|
-
}
|
|
6162
|
-
else {
|
|
6163
|
-
logger$3.throwArgumentError("hex data is odd-length", "value", value);
|
|
6164
|
-
}
|
|
6165
|
-
}
|
|
6166
|
-
const result = [];
|
|
6167
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
6168
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
6169
|
-
}
|
|
6170
|
-
return addSlice(new Uint8Array(result));
|
|
6171
|
-
}
|
|
6172
|
-
if (isBytes(value)) {
|
|
6173
|
-
return addSlice(new Uint8Array(value));
|
|
6174
|
-
}
|
|
6175
|
-
return logger$3.throwArgumentError("invalid arrayify value", "value", value);
|
|
6176
|
-
}
|
|
6177
|
-
function concat(items) {
|
|
6178
|
-
const objects = items.map(item => arrayify(item));
|
|
6179
|
-
const length = objects.reduce((accum, item) => (accum + item.length), 0);
|
|
6180
|
-
const result = new Uint8Array(length);
|
|
6181
|
-
objects.reduce((offset, object) => {
|
|
6182
|
-
result.set(object, offset);
|
|
6183
|
-
return offset + object.length;
|
|
6184
|
-
}, 0);
|
|
6185
|
-
return addSlice(result);
|
|
6186
|
-
}
|
|
6187
|
-
function zeroPad(value, length) {
|
|
6188
|
-
value = arrayify(value);
|
|
6189
|
-
if (value.length > length) {
|
|
6190
|
-
logger$3.throwArgumentError("value out of range", "value", arguments[0]);
|
|
6191
|
-
}
|
|
6192
|
-
const result = new Uint8Array(length);
|
|
6193
|
-
result.set(value, length - value.length);
|
|
6194
|
-
return addSlice(result);
|
|
6195
|
-
}
|
|
6196
|
-
function isHexString(value, length) {
|
|
6197
|
-
if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
6198
|
-
return false;
|
|
6199
|
-
}
|
|
6200
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
6201
|
-
return false;
|
|
6202
|
-
}
|
|
6203
|
-
return true;
|
|
6204
|
-
}
|
|
6205
|
-
const HexCharacters = "0123456789abcdef";
|
|
6206
|
-
function hexlify(value, options) {
|
|
6207
|
-
if (!options) {
|
|
6208
|
-
options = {};
|
|
6209
|
-
}
|
|
6210
|
-
if (typeof (value) === "number") {
|
|
6211
|
-
logger$3.checkSafeUint53(value, "invalid hexlify value");
|
|
6212
|
-
let hex = "";
|
|
6213
|
-
while (value) {
|
|
6214
|
-
hex = HexCharacters[value & 0xf] + hex;
|
|
6215
|
-
value = Math.floor(value / 16);
|
|
6216
|
-
}
|
|
6217
|
-
if (hex.length) {
|
|
6218
|
-
if (hex.length % 2) {
|
|
6219
|
-
hex = "0" + hex;
|
|
6220
|
-
}
|
|
6221
|
-
return "0x" + hex;
|
|
6222
|
-
}
|
|
6223
|
-
return "0x00";
|
|
6224
|
-
}
|
|
6225
|
-
if (typeof (value) === "bigint") {
|
|
6226
|
-
value = value.toString(16);
|
|
6227
|
-
if (value.length % 2) {
|
|
6228
|
-
return ("0x0" + value);
|
|
6229
|
-
}
|
|
6230
|
-
return "0x" + value;
|
|
6231
|
-
}
|
|
6232
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
6233
|
-
value = "0x" + value;
|
|
6234
|
-
}
|
|
6235
|
-
if (isHexable(value)) {
|
|
6236
|
-
return value.toHexString();
|
|
6237
|
-
}
|
|
6238
|
-
if (isHexString(value)) {
|
|
6239
|
-
if (value.length % 2) {
|
|
6240
|
-
if (options.hexPad === "left") {
|
|
6241
|
-
value = "0x0" + value.substring(2);
|
|
6242
|
-
}
|
|
6243
|
-
else if (options.hexPad === "right") {
|
|
6244
|
-
value += "0";
|
|
6245
|
-
}
|
|
6246
|
-
else {
|
|
6247
|
-
logger$3.throwArgumentError("hex data is odd-length", "value", value);
|
|
6248
|
-
}
|
|
6249
|
-
}
|
|
6250
|
-
return value.toLowerCase();
|
|
6251
|
-
}
|
|
6252
|
-
if (isBytes(value)) {
|
|
6253
|
-
let result = "0x";
|
|
6254
|
-
for (let i = 0; i < value.length; i++) {
|
|
6255
|
-
let v = value[i];
|
|
6256
|
-
result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];
|
|
6257
|
-
}
|
|
6258
|
-
return result;
|
|
6259
|
-
}
|
|
6260
|
-
return logger$3.throwArgumentError("invalid hexlify value", "value", value);
|
|
6261
|
-
}
|
|
6262
|
-
|
|
6263
|
-
const version$2 = "bignumber/5.7.0";
|
|
6264
|
-
|
|
6265
|
-
var BN = BN$1.BN;
|
|
6266
|
-
const logger$2 = new Logger(version$2);
|
|
6267
|
-
const _constructorGuard = {};
|
|
6268
|
-
const MAX_SAFE = 0x1fffffffffffff;
|
|
6269
|
-
// Only warn about passing 10 into radix once
|
|
6270
|
-
let _warnedToStringRadix = false;
|
|
6271
|
-
class BigNumber {
|
|
6272
|
-
constructor(constructorGuard, hex) {
|
|
6273
|
-
if (constructorGuard !== _constructorGuard) {
|
|
6274
|
-
logger$2.throwError("cannot call constructor directly; use BigNumber.from", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
6275
|
-
operation: "new (BigNumber)"
|
|
6276
|
-
});
|
|
6277
|
-
}
|
|
6278
|
-
this._hex = hex;
|
|
6279
|
-
this._isBigNumber = true;
|
|
6280
|
-
Object.freeze(this);
|
|
6281
|
-
}
|
|
6282
|
-
fromTwos(value) {
|
|
6283
|
-
return toBigNumber(toBN(this).fromTwos(value));
|
|
6284
|
-
}
|
|
6285
|
-
toTwos(value) {
|
|
6286
|
-
return toBigNumber(toBN(this).toTwos(value));
|
|
6287
|
-
}
|
|
6288
|
-
abs() {
|
|
6289
|
-
if (this._hex[0] === "-") {
|
|
6290
|
-
return BigNumber.from(this._hex.substring(1));
|
|
6291
|
-
}
|
|
6292
|
-
return this;
|
|
6293
|
-
}
|
|
6294
|
-
add(other) {
|
|
6295
|
-
return toBigNumber(toBN(this).add(toBN(other)));
|
|
6296
|
-
}
|
|
6297
|
-
sub(other) {
|
|
6298
|
-
return toBigNumber(toBN(this).sub(toBN(other)));
|
|
6299
|
-
}
|
|
6300
|
-
div(other) {
|
|
6301
|
-
const o = BigNumber.from(other);
|
|
6302
|
-
if (o.isZero()) {
|
|
6303
|
-
throwFault("division-by-zero", "div");
|
|
6304
|
-
}
|
|
6305
|
-
return toBigNumber(toBN(this).div(toBN(other)));
|
|
6306
|
-
}
|
|
6307
|
-
mul(other) {
|
|
6308
|
-
return toBigNumber(toBN(this).mul(toBN(other)));
|
|
6309
|
-
}
|
|
6310
|
-
mod(other) {
|
|
6311
|
-
const value = toBN(other);
|
|
6312
|
-
if (value.isNeg()) {
|
|
6313
|
-
throwFault("division-by-zero", "mod");
|
|
6314
|
-
}
|
|
6315
|
-
return toBigNumber(toBN(this).umod(value));
|
|
6316
|
-
}
|
|
6317
|
-
pow(other) {
|
|
6318
|
-
const value = toBN(other);
|
|
6319
|
-
if (value.isNeg()) {
|
|
6320
|
-
throwFault("negative-power", "pow");
|
|
6321
|
-
}
|
|
6322
|
-
return toBigNumber(toBN(this).pow(value));
|
|
6323
|
-
}
|
|
6324
|
-
and(other) {
|
|
6325
|
-
const value = toBN(other);
|
|
6326
|
-
if (this.isNegative() || value.isNeg()) {
|
|
6327
|
-
throwFault("unbound-bitwise-result", "and");
|
|
6328
|
-
}
|
|
6329
|
-
return toBigNumber(toBN(this).and(value));
|
|
6330
|
-
}
|
|
6331
|
-
or(other) {
|
|
6332
|
-
const value = toBN(other);
|
|
6333
|
-
if (this.isNegative() || value.isNeg()) {
|
|
6334
|
-
throwFault("unbound-bitwise-result", "or");
|
|
6335
|
-
}
|
|
6336
|
-
return toBigNumber(toBN(this).or(value));
|
|
6337
|
-
}
|
|
6338
|
-
xor(other) {
|
|
6339
|
-
const value = toBN(other);
|
|
6340
|
-
if (this.isNegative() || value.isNeg()) {
|
|
6341
|
-
throwFault("unbound-bitwise-result", "xor");
|
|
6342
|
-
}
|
|
6343
|
-
return toBigNumber(toBN(this).xor(value));
|
|
6344
|
-
}
|
|
6345
|
-
mask(value) {
|
|
6346
|
-
if (this.isNegative() || value < 0) {
|
|
6347
|
-
throwFault("negative-width", "mask");
|
|
6348
|
-
}
|
|
6349
|
-
return toBigNumber(toBN(this).maskn(value));
|
|
6350
|
-
}
|
|
6351
|
-
shl(value) {
|
|
6352
|
-
if (this.isNegative() || value < 0) {
|
|
6353
|
-
throwFault("negative-width", "shl");
|
|
6354
|
-
}
|
|
6355
|
-
return toBigNumber(toBN(this).shln(value));
|
|
6356
|
-
}
|
|
6357
|
-
shr(value) {
|
|
6358
|
-
if (this.isNegative() || value < 0) {
|
|
6359
|
-
throwFault("negative-width", "shr");
|
|
6360
|
-
}
|
|
6361
|
-
return toBigNumber(toBN(this).shrn(value));
|
|
6362
|
-
}
|
|
6363
|
-
eq(other) {
|
|
6364
|
-
return toBN(this).eq(toBN(other));
|
|
6365
|
-
}
|
|
6366
|
-
lt(other) {
|
|
6367
|
-
return toBN(this).lt(toBN(other));
|
|
6368
|
-
}
|
|
6369
|
-
lte(other) {
|
|
6370
|
-
return toBN(this).lte(toBN(other));
|
|
6371
|
-
}
|
|
6372
|
-
gt(other) {
|
|
6373
|
-
return toBN(this).gt(toBN(other));
|
|
6374
|
-
}
|
|
6375
|
-
gte(other) {
|
|
6376
|
-
return toBN(this).gte(toBN(other));
|
|
6377
|
-
}
|
|
6378
|
-
isNegative() {
|
|
6379
|
-
return (this._hex[0] === "-");
|
|
6380
|
-
}
|
|
6381
|
-
isZero() {
|
|
6382
|
-
return toBN(this).isZero();
|
|
6383
|
-
}
|
|
6384
|
-
toNumber() {
|
|
6385
|
-
try {
|
|
6386
|
-
return toBN(this).toNumber();
|
|
6387
|
-
}
|
|
6388
|
-
catch (error) {
|
|
6389
|
-
throwFault("overflow", "toNumber", this.toString());
|
|
6390
|
-
}
|
|
6391
|
-
return null;
|
|
6392
|
-
}
|
|
6393
|
-
toBigInt() {
|
|
6394
|
-
try {
|
|
6395
|
-
return BigInt(this.toString());
|
|
6396
|
-
}
|
|
6397
|
-
catch (e) { }
|
|
6398
|
-
return logger$2.throwError("this platform does not support BigInt", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
6399
|
-
value: this.toString()
|
|
6400
|
-
});
|
|
6401
|
-
}
|
|
6402
|
-
toString() {
|
|
6403
|
-
// Lots of people expect this, which we do not support, so check (See: #889)
|
|
6404
|
-
if (arguments.length > 0) {
|
|
6405
|
-
if (arguments[0] === 10) {
|
|
6406
|
-
if (!_warnedToStringRadix) {
|
|
6407
|
-
_warnedToStringRadix = true;
|
|
6408
|
-
logger$2.warn("BigNumber.toString does not accept any parameters; base-10 is assumed");
|
|
6409
|
-
}
|
|
6410
|
-
}
|
|
6411
|
-
else if (arguments[0] === 16) {
|
|
6412
|
-
logger$2.throwError("BigNumber.toString does not accept any parameters; use bigNumber.toHexString()", Logger.errors.UNEXPECTED_ARGUMENT, {});
|
|
6413
|
-
}
|
|
6414
|
-
else {
|
|
6415
|
-
logger$2.throwError("BigNumber.toString does not accept parameters", Logger.errors.UNEXPECTED_ARGUMENT, {});
|
|
6416
|
-
}
|
|
6417
|
-
}
|
|
6418
|
-
return toBN(this).toString(10);
|
|
6419
|
-
}
|
|
6420
|
-
toHexString() {
|
|
6421
|
-
return this._hex;
|
|
6422
|
-
}
|
|
6423
|
-
toJSON(key) {
|
|
6424
|
-
return { type: "BigNumber", hex: this.toHexString() };
|
|
6425
|
-
}
|
|
6426
|
-
static from(value) {
|
|
6427
|
-
if (value instanceof BigNumber) {
|
|
6428
|
-
return value;
|
|
6429
|
-
}
|
|
6430
|
-
if (typeof (value) === "string") {
|
|
6431
|
-
if (value.match(/^-?0x[0-9a-f]+$/i)) {
|
|
6432
|
-
return new BigNumber(_constructorGuard, toHex(value));
|
|
6433
|
-
}
|
|
6434
|
-
if (value.match(/^-?[0-9]+$/)) {
|
|
6435
|
-
return new BigNumber(_constructorGuard, toHex(new BN(value)));
|
|
6436
|
-
}
|
|
6437
|
-
return logger$2.throwArgumentError("invalid BigNumber string", "value", value);
|
|
6438
|
-
}
|
|
6439
|
-
if (typeof (value) === "number") {
|
|
6440
|
-
if (value % 1) {
|
|
6441
|
-
throwFault("underflow", "BigNumber.from", value);
|
|
6442
|
-
}
|
|
6443
|
-
if (value >= MAX_SAFE || value <= -MAX_SAFE) {
|
|
6444
|
-
throwFault("overflow", "BigNumber.from", value);
|
|
6445
|
-
}
|
|
6446
|
-
return BigNumber.from(String(value));
|
|
6447
|
-
}
|
|
6448
|
-
const anyValue = value;
|
|
6449
|
-
if (typeof (anyValue) === "bigint") {
|
|
6450
|
-
return BigNumber.from(anyValue.toString());
|
|
6451
|
-
}
|
|
6452
|
-
if (isBytes(anyValue)) {
|
|
6453
|
-
return BigNumber.from(hexlify(anyValue));
|
|
6454
|
-
}
|
|
6455
|
-
if (anyValue) {
|
|
6456
|
-
// Hexable interface (takes priority)
|
|
6457
|
-
if (anyValue.toHexString) {
|
|
6458
|
-
const hex = anyValue.toHexString();
|
|
6459
|
-
if (typeof (hex) === "string") {
|
|
6460
|
-
return BigNumber.from(hex);
|
|
6461
|
-
}
|
|
6462
|
-
}
|
|
6463
|
-
else {
|
|
6464
|
-
// For now, handle legacy JSON-ified values (goes away in v6)
|
|
6465
|
-
let hex = anyValue._hex;
|
|
6466
|
-
// New-form JSON
|
|
6467
|
-
if (hex == null && anyValue.type === "BigNumber") {
|
|
6468
|
-
hex = anyValue.hex;
|
|
6469
|
-
}
|
|
6470
|
-
if (typeof (hex) === "string") {
|
|
6471
|
-
if (isHexString(hex) || (hex[0] === "-" && isHexString(hex.substring(1)))) {
|
|
6472
|
-
return BigNumber.from(hex);
|
|
6473
|
-
}
|
|
6474
|
-
}
|
|
6475
|
-
}
|
|
6476
|
-
}
|
|
6477
|
-
return logger$2.throwArgumentError("invalid BigNumber value", "value", value);
|
|
6478
|
-
}
|
|
6479
|
-
static isBigNumber(value) {
|
|
6480
|
-
return !!(value && value._isBigNumber);
|
|
6481
|
-
}
|
|
6482
|
-
}
|
|
6483
|
-
// Normalize the hex string
|
|
6484
|
-
function toHex(value) {
|
|
6485
|
-
// For BN, call on the hex string
|
|
6486
|
-
if (typeof (value) !== "string") {
|
|
6487
|
-
return toHex(value.toString(16));
|
|
6488
|
-
}
|
|
6489
|
-
// If negative, prepend the negative sign to the normalized positive value
|
|
6490
|
-
if (value[0] === "-") {
|
|
6491
|
-
// Strip off the negative sign
|
|
6492
|
-
value = value.substring(1);
|
|
6493
|
-
// Cannot have multiple negative signs (e.g. "--0x04")
|
|
6494
|
-
if (value[0] === "-") {
|
|
6495
|
-
logger$2.throwArgumentError("invalid hex", "value", value);
|
|
6496
|
-
}
|
|
6497
|
-
// Call toHex on the positive component
|
|
6498
|
-
value = toHex(value);
|
|
6499
|
-
// Do not allow "-0x00"
|
|
6500
|
-
if (value === "0x00") {
|
|
6501
|
-
return value;
|
|
6502
|
-
}
|
|
6503
|
-
// Negate the value
|
|
6504
|
-
return "-" + value;
|
|
6505
|
-
}
|
|
6506
|
-
// Add a "0x" prefix if missing
|
|
6507
|
-
if (value.substring(0, 2) !== "0x") {
|
|
6508
|
-
value = "0x" + value;
|
|
6509
|
-
}
|
|
6510
|
-
// Normalize zero
|
|
6511
|
-
if (value === "0x") {
|
|
6512
|
-
return "0x00";
|
|
6513
|
-
}
|
|
6514
|
-
// Make the string even length
|
|
6515
|
-
if (value.length % 2) {
|
|
6516
|
-
value = "0x0" + value.substring(2);
|
|
6517
|
-
}
|
|
6518
|
-
// Trim to smallest even-length string
|
|
6519
|
-
while (value.length > 4 && value.substring(0, 4) === "0x00") {
|
|
6520
|
-
value = "0x" + value.substring(4);
|
|
6521
|
-
}
|
|
6522
|
-
return value;
|
|
6523
|
-
}
|
|
6524
|
-
function toBigNumber(value) {
|
|
6525
|
-
return BigNumber.from(toHex(value));
|
|
6526
|
-
}
|
|
6527
|
-
function toBN(value) {
|
|
6528
|
-
const hex = BigNumber.from(value).toHexString();
|
|
6529
|
-
if (hex[0] === "-") {
|
|
6530
|
-
return (new BN("-" + hex.substring(3), 16));
|
|
6531
|
-
}
|
|
6532
|
-
return new BN(hex.substring(2), 16);
|
|
6533
|
-
}
|
|
6534
|
-
function throwFault(fault, operation, value) {
|
|
6535
|
-
const params = { fault: fault, operation: operation };
|
|
6536
|
-
if (value != null) {
|
|
6537
|
-
params.value = value;
|
|
6538
|
-
}
|
|
6539
|
-
return logger$2.throwError(fault, Logger.errors.NUMERIC_FAULT, params);
|
|
6540
|
-
}
|
|
6541
|
-
|
|
6542
|
-
var sha3$1 = {exports: {}};
|
|
5739
|
+
var sha3 = {exports: {}};
|
|
6543
5740
|
|
|
6544
5741
|
/**
|
|
6545
5742
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
@@ -7165,243 +6362,66 @@ var sha3$1 = {exports: {}};
|
|
|
7165
6362
|
s[26] = b26 ^ (~b28 & b20);
|
|
7166
6363
|
s[27] = b27 ^ (~b29 & b21);
|
|
7167
6364
|
s[36] = b36 ^ (~b38 & b30);
|
|
7168
|
-
s[37] = b37 ^ (~b39 & b31);
|
|
7169
|
-
s[46] = b46 ^ (~b48 & b40);
|
|
7170
|
-
s[47] = b47 ^ (~b49 & b41);
|
|
7171
|
-
s[8] = b8 ^ (~b0 & b2);
|
|
7172
|
-
s[9] = b9 ^ (~b1 & b3);
|
|
7173
|
-
s[18] = b18 ^ (~b10 & b12);
|
|
7174
|
-
s[19] = b19 ^ (~b11 & b13);
|
|
7175
|
-
s[28] = b28 ^ (~b20 & b22);
|
|
7176
|
-
s[29] = b29 ^ (~b21 & b23);
|
|
7177
|
-
s[38] = b38 ^ (~b30 & b32);
|
|
7178
|
-
s[39] = b39 ^ (~b31 & b33);
|
|
7179
|
-
s[48] = b48 ^ (~b40 & b42);
|
|
7180
|
-
s[49] = b49 ^ (~b41 & b43);
|
|
7181
|
-
|
|
7182
|
-
s[0] ^= RC[n];
|
|
7183
|
-
s[1] ^= RC[n + 1];
|
|
7184
|
-
}
|
|
7185
|
-
};
|
|
7186
|
-
|
|
7187
|
-
if (COMMON_JS) {
|
|
7188
|
-
module.exports = methods;
|
|
7189
|
-
} else {
|
|
7190
|
-
for (i = 0; i < methodNames.length; ++i) {
|
|
7191
|
-
root[methodNames[i]] = methods[methodNames[i]];
|
|
7192
|
-
}
|
|
7193
|
-
}
|
|
7194
|
-
})();
|
|
7195
|
-
} (sha3$1));
|
|
7196
|
-
|
|
7197
|
-
var sha3 = sha3$1.exports;
|
|
7198
|
-
|
|
7199
|
-
function keccak256$1(data) {
|
|
7200
|
-
return '0x' + sha3.keccak_256(arrayify(data));
|
|
7201
|
-
}
|
|
7202
|
-
|
|
7203
|
-
const version$1 = "strings/5.7.0";
|
|
7204
|
-
|
|
7205
|
-
const logger$1 = new Logger(version$1);
|
|
7206
|
-
///////////////////////////////
|
|
7207
|
-
var UnicodeNormalizationForm;
|
|
7208
|
-
(function (UnicodeNormalizationForm) {
|
|
7209
|
-
UnicodeNormalizationForm["current"] = "";
|
|
7210
|
-
UnicodeNormalizationForm["NFC"] = "NFC";
|
|
7211
|
-
UnicodeNormalizationForm["NFD"] = "NFD";
|
|
7212
|
-
UnicodeNormalizationForm["NFKC"] = "NFKC";
|
|
7213
|
-
UnicodeNormalizationForm["NFKD"] = "NFKD";
|
|
7214
|
-
})(UnicodeNormalizationForm || (UnicodeNormalizationForm = {}));
|
|
7215
|
-
var Utf8ErrorReason;
|
|
7216
|
-
(function (Utf8ErrorReason) {
|
|
7217
|
-
// A continuation byte was present where there was nothing to continue
|
|
7218
|
-
// - offset = the index the codepoint began in
|
|
7219
|
-
Utf8ErrorReason["UNEXPECTED_CONTINUE"] = "unexpected continuation byte";
|
|
7220
|
-
// An invalid (non-continuation) byte to start a UTF-8 codepoint was found
|
|
7221
|
-
// - offset = the index the codepoint began in
|
|
7222
|
-
Utf8ErrorReason["BAD_PREFIX"] = "bad codepoint prefix";
|
|
7223
|
-
// The string is too short to process the expected codepoint
|
|
7224
|
-
// - offset = the index the codepoint began in
|
|
7225
|
-
Utf8ErrorReason["OVERRUN"] = "string overrun";
|
|
7226
|
-
// A missing continuation byte was expected but not found
|
|
7227
|
-
// - offset = the index the continuation byte was expected at
|
|
7228
|
-
Utf8ErrorReason["MISSING_CONTINUE"] = "missing continuation byte";
|
|
7229
|
-
// The computed code point is outside the range for UTF-8
|
|
7230
|
-
// - offset = start of this codepoint
|
|
7231
|
-
// - badCodepoint = the computed codepoint; outside the UTF-8 range
|
|
7232
|
-
Utf8ErrorReason["OUT_OF_RANGE"] = "out of UTF-8 range";
|
|
7233
|
-
// UTF-8 strings may not contain UTF-16 surrogate pairs
|
|
7234
|
-
// - offset = start of this codepoint
|
|
7235
|
-
// - badCodepoint = the computed codepoint; inside the UTF-16 surrogate range
|
|
7236
|
-
Utf8ErrorReason["UTF16_SURROGATE"] = "UTF-16 surrogate";
|
|
7237
|
-
// The string is an overlong representation
|
|
7238
|
-
// - offset = start of this codepoint
|
|
7239
|
-
// - badCodepoint = the computed codepoint; already bounds checked
|
|
7240
|
-
Utf8ErrorReason["OVERLONG"] = "overlong representation";
|
|
7241
|
-
})(Utf8ErrorReason || (Utf8ErrorReason = {}));
|
|
7242
|
-
function errorFunc(reason, offset, bytes, output, badCodepoint) {
|
|
7243
|
-
return logger$1.throwArgumentError(`invalid codepoint at offset ${offset}; ${reason}`, "bytes", bytes);
|
|
7244
|
-
}
|
|
7245
|
-
function ignoreFunc(reason, offset, bytes, output, badCodepoint) {
|
|
7246
|
-
// If there is an invalid prefix (including stray continuation), skip any additional continuation bytes
|
|
7247
|
-
if (reason === Utf8ErrorReason.BAD_PREFIX || reason === Utf8ErrorReason.UNEXPECTED_CONTINUE) {
|
|
7248
|
-
let i = 0;
|
|
7249
|
-
for (let o = offset + 1; o < bytes.length; o++) {
|
|
7250
|
-
if (bytes[o] >> 6 !== 0x02) {
|
|
7251
|
-
break;
|
|
7252
|
-
}
|
|
7253
|
-
i++;
|
|
7254
|
-
}
|
|
7255
|
-
return i;
|
|
7256
|
-
}
|
|
7257
|
-
// This byte runs us past the end of the string, so just jump to the end
|
|
7258
|
-
// (but the first byte was read already read and therefore skipped)
|
|
7259
|
-
if (reason === Utf8ErrorReason.OVERRUN) {
|
|
7260
|
-
return bytes.length - offset - 1;
|
|
7261
|
-
}
|
|
7262
|
-
// Nothing to skip
|
|
7263
|
-
return 0;
|
|
7264
|
-
}
|
|
7265
|
-
function replaceFunc(reason, offset, bytes, output, badCodepoint) {
|
|
7266
|
-
// Overlong representations are otherwise "valid" code points; just non-deistingtished
|
|
7267
|
-
if (reason === Utf8ErrorReason.OVERLONG) {
|
|
7268
|
-
output.push(badCodepoint);
|
|
7269
|
-
return 0;
|
|
7270
|
-
}
|
|
7271
|
-
// Put the replacement character into the output
|
|
7272
|
-
output.push(0xfffd);
|
|
7273
|
-
// Otherwise, process as if ignoring errors
|
|
7274
|
-
return ignoreFunc(reason, offset, bytes);
|
|
7275
|
-
}
|
|
7276
|
-
// Common error handing strategies
|
|
7277
|
-
Object.freeze({
|
|
7278
|
-
error: errorFunc,
|
|
7279
|
-
ignore: ignoreFunc,
|
|
7280
|
-
replace: replaceFunc
|
|
7281
|
-
});
|
|
7282
|
-
// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
|
|
7283
|
-
function toUtf8Bytes(str, form = UnicodeNormalizationForm.current) {
|
|
7284
|
-
if (form != UnicodeNormalizationForm.current) {
|
|
7285
|
-
logger$1.checkNormalize();
|
|
7286
|
-
str = str.normalize(form);
|
|
7287
|
-
}
|
|
7288
|
-
let result = [];
|
|
7289
|
-
for (let i = 0; i < str.length; i++) {
|
|
7290
|
-
const c = str.charCodeAt(i);
|
|
7291
|
-
if (c < 0x80) {
|
|
7292
|
-
result.push(c);
|
|
7293
|
-
}
|
|
7294
|
-
else if (c < 0x800) {
|
|
7295
|
-
result.push((c >> 6) | 0xc0);
|
|
7296
|
-
result.push((c & 0x3f) | 0x80);
|
|
7297
|
-
}
|
|
7298
|
-
else if ((c & 0xfc00) == 0xd800) {
|
|
7299
|
-
i++;
|
|
7300
|
-
const c2 = str.charCodeAt(i);
|
|
7301
|
-
if (i >= str.length || (c2 & 0xfc00) !== 0xdc00) {
|
|
7302
|
-
throw new Error("invalid utf-8 string");
|
|
7303
|
-
}
|
|
7304
|
-
// Surrogate Pair
|
|
7305
|
-
const pair = 0x10000 + ((c & 0x03ff) << 10) + (c2 & 0x03ff);
|
|
7306
|
-
result.push((pair >> 18) | 0xf0);
|
|
7307
|
-
result.push(((pair >> 12) & 0x3f) | 0x80);
|
|
7308
|
-
result.push(((pair >> 6) & 0x3f) | 0x80);
|
|
7309
|
-
result.push((pair & 0x3f) | 0x80);
|
|
7310
|
-
}
|
|
7311
|
-
else {
|
|
7312
|
-
result.push((c >> 12) | 0xe0);
|
|
7313
|
-
result.push(((c >> 6) & 0x3f) | 0x80);
|
|
7314
|
-
result.push((c & 0x3f) | 0x80);
|
|
7315
|
-
}
|
|
7316
|
-
}
|
|
7317
|
-
return arrayify(result);
|
|
7318
|
-
}
|
|
6365
|
+
s[37] = b37 ^ (~b39 & b31);
|
|
6366
|
+
s[46] = b46 ^ (~b48 & b40);
|
|
6367
|
+
s[47] = b47 ^ (~b49 & b41);
|
|
6368
|
+
s[8] = b8 ^ (~b0 & b2);
|
|
6369
|
+
s[9] = b9 ^ (~b1 & b3);
|
|
6370
|
+
s[18] = b18 ^ (~b10 & b12);
|
|
6371
|
+
s[19] = b19 ^ (~b11 & b13);
|
|
6372
|
+
s[28] = b28 ^ (~b20 & b22);
|
|
6373
|
+
s[29] = b29 ^ (~b21 & b23);
|
|
6374
|
+
s[38] = b38 ^ (~b30 & b32);
|
|
6375
|
+
s[39] = b39 ^ (~b31 & b33);
|
|
6376
|
+
s[48] = b48 ^ (~b40 & b42);
|
|
6377
|
+
s[49] = b49 ^ (~b41 & b43);
|
|
7319
6378
|
|
|
7320
|
-
|
|
6379
|
+
s[0] ^= RC[n];
|
|
6380
|
+
s[1] ^= RC[n + 1];
|
|
6381
|
+
}
|
|
6382
|
+
};
|
|
7321
6383
|
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
}
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
value = BigNumber.from(value).toTwos(size);
|
|
7356
|
-
return zeroPad(value, size / 8);
|
|
7357
|
-
}
|
|
7358
|
-
match = type.match(regexBytes);
|
|
7359
|
-
if (match) {
|
|
7360
|
-
const size = parseInt(match[1]);
|
|
7361
|
-
if (String(size) !== match[1] || size === 0 || size > 32) {
|
|
7362
|
-
logger.throwArgumentError("invalid bytes type", "type", type);
|
|
7363
|
-
}
|
|
7364
|
-
if (arrayify(value).byteLength !== size) {
|
|
7365
|
-
logger.throwArgumentError(`invalid value for ${type}`, "value", value);
|
|
7366
|
-
}
|
|
7367
|
-
if (isArray) {
|
|
7368
|
-
return arrayify((value + Zeros).substring(0, 66));
|
|
7369
|
-
}
|
|
7370
|
-
return value;
|
|
7371
|
-
}
|
|
7372
|
-
match = type.match(regexArray);
|
|
7373
|
-
if (match && Array.isArray(value)) {
|
|
7374
|
-
const baseType = match[1];
|
|
7375
|
-
const count = parseInt(match[2] || String(value.length));
|
|
7376
|
-
if (count != value.length) {
|
|
7377
|
-
logger.throwArgumentError(`invalid array length for ${type}`, "value", value);
|
|
7378
|
-
}
|
|
7379
|
-
const result = [];
|
|
7380
|
-
value.forEach(function (value) {
|
|
7381
|
-
result.push(_pack(baseType, value, true));
|
|
7382
|
-
});
|
|
7383
|
-
return concat(result);
|
|
7384
|
-
}
|
|
7385
|
-
return logger.throwArgumentError("invalid type", "type", type);
|
|
7386
|
-
}
|
|
7387
|
-
// @TODO: Array Enum
|
|
7388
|
-
function pack(types, values) {
|
|
7389
|
-
if (types.length != values.length) {
|
|
7390
|
-
logger.throwArgumentError("wrong number of values; expected ${ types.length }", "values", values);
|
|
7391
|
-
}
|
|
7392
|
-
const tight = [];
|
|
7393
|
-
types.forEach(function (type, index) {
|
|
7394
|
-
tight.push(_pack(type, values[index]));
|
|
7395
|
-
});
|
|
7396
|
-
return hexlify(concat(tight));
|
|
7397
|
-
}
|
|
7398
|
-
function keccak256(types, values) {
|
|
7399
|
-
return keccak256$1(pack(types, values));
|
|
6384
|
+
if (COMMON_JS) {
|
|
6385
|
+
module.exports = methods;
|
|
6386
|
+
} else {
|
|
6387
|
+
for (i = 0; i < methodNames.length; ++i) {
|
|
6388
|
+
root[methodNames[i]] = methods[methodNames[i]];
|
|
6389
|
+
}
|
|
6390
|
+
}
|
|
6391
|
+
})();
|
|
6392
|
+
} (sha3));
|
|
6393
|
+
|
|
6394
|
+
/******************************************************************************
|
|
6395
|
+
Copyright (c) Microsoft Corporation.
|
|
6396
|
+
|
|
6397
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6398
|
+
purpose with or without fee is hereby granted.
|
|
6399
|
+
|
|
6400
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
6401
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
6402
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
6403
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
6404
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
6405
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
6406
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
6407
|
+
***************************************************************************** */
|
|
6408
|
+
|
|
6409
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
6410
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6411
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6412
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6413
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6414
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
6415
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
6416
|
+
});
|
|
7400
6417
|
}
|
|
7401
6418
|
|
|
7402
6419
|
const BPS_DENOMINATOR = 10000;
|
|
7403
6420
|
const SOLANA_CHAIN_ID = 7565164;
|
|
7404
6421
|
const MAX_TX_SIZE = 1232;
|
|
6422
|
+
const FAKE_BLOCKHASH = "1".repeat(32);
|
|
6423
|
+
const DEPLOY_INFO_PREFIX = 2;
|
|
6424
|
+
const SUBMISSION_PREFIX = 1;
|
|
7405
6425
|
const deBridge$1 = {
|
|
7406
6426
|
Seeds: {
|
|
7407
6427
|
STATE: "DEBRIDGE_STATE",
|
|
@@ -7428,7 +6448,6 @@ const deBridge$1 = {
|
|
|
7428
6448
|
SEND_HASHED_DATA: 8,
|
|
7429
6449
|
SEND_TO_ATA: Math.pow(2, 31),
|
|
7430
6450
|
},
|
|
7431
|
-
SUBMISSION_PREFIX: 1,
|
|
7432
6451
|
};
|
|
7433
6452
|
const deBridgeSettings$1 = {
|
|
7434
6453
|
Seeds: {
|
|
@@ -7470,43 +6489,21 @@ var constants = /*#__PURE__*/Object.freeze({
|
|
|
7470
6489
|
BPS_DENOMINATOR: BPS_DENOMINATOR,
|
|
7471
6490
|
SOLANA_CHAIN_ID: SOLANA_CHAIN_ID,
|
|
7472
6491
|
MAX_TX_SIZE: MAX_TX_SIZE,
|
|
6492
|
+
FAKE_BLOCKHASH: FAKE_BLOCKHASH,
|
|
6493
|
+
DEPLOY_INFO_PREFIX: DEPLOY_INFO_PREFIX,
|
|
6494
|
+
SUBMISSION_PREFIX: SUBMISSION_PREFIX,
|
|
7473
6495
|
deBridge: deBridge$1,
|
|
7474
6496
|
deBridgeSettings: deBridgeSettings$1,
|
|
7475
6497
|
pmmSrc: pmmSrc,
|
|
7476
6498
|
pmmDst: pmmDst
|
|
7477
6499
|
});
|
|
7478
6500
|
|
|
7479
|
-
/******************************************************************************
|
|
7480
|
-
Copyright (c) Microsoft Corporation.
|
|
7481
|
-
|
|
7482
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
7483
|
-
purpose with or without fee is hereby granted.
|
|
7484
|
-
|
|
7485
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
7486
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
7487
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
7488
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
7489
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
7490
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
7491
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
7492
|
-
***************************************************************************** */
|
|
7493
|
-
|
|
7494
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
7495
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7496
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7497
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7498
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7499
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7500
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
7501
|
-
});
|
|
7502
|
-
}
|
|
7503
|
-
|
|
7504
6501
|
function getAccountInfo(connection, account, commitment = "confirmed") {
|
|
7505
6502
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7506
6503
|
const info = yield connection.getAccountInfo(account, commitment);
|
|
7507
6504
|
if (info) {
|
|
7508
6505
|
// alchemy bug fix
|
|
7509
|
-
if (info.lamports === 0
|
|
6506
|
+
if (info.lamports === 0)
|
|
7510
6507
|
return null;
|
|
7511
6508
|
return info;
|
|
7512
6509
|
}
|
|
@@ -7588,11 +6585,10 @@ class Wallet {
|
|
|
7588
6585
|
function sendWithRetries(connection, serialized, lastValidBlockHeight, timesToSend = 5, blockhashCommitment = "finalized") {
|
|
7589
6586
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7590
6587
|
const txId = yield connection.sendRawTransaction(serialized, {
|
|
7591
|
-
skipPreflight:
|
|
7592
|
-
maxRetries: 1000,
|
|
6588
|
+
skipPreflight: false, // never skip preflight
|
|
7593
6589
|
});
|
|
7594
6590
|
let blockheight = yield connection.getBlockHeight();
|
|
7595
|
-
let sent =
|
|
6591
|
+
let sent = 1;
|
|
7596
6592
|
while (blockheight < lastValidBlockHeight && sent < timesToSend) {
|
|
7597
6593
|
yield connection.sendRawTransaction(serialized, {
|
|
7598
6594
|
skipPreflight: true,
|
|
@@ -7639,15 +6635,14 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
7639
6635
|
var _a;
|
|
7640
6636
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7641
6637
|
const blockhashCommitment = (options === null || options === void 0 ? void 0 : options.blockhashCommitment) === undefined ? "finalized" : options.blockhashCommitment;
|
|
7642
|
-
const fakeBlockHash = "1".repeat(32);
|
|
7643
6638
|
const convertIntoTxV0 = (options === null || options === void 0 ? void 0 : options.convertIntoTxV0) === undefined ? true : options.convertIntoTxV0;
|
|
7644
6639
|
const debug = (options === null || options === void 0 ? void 0 : options.debug) === undefined ? false : options.debug;
|
|
7645
6640
|
const skipPreflight = (options === null || options === void 0 ? void 0 : options.skipPreflight) === undefined ? false : options.skipPreflight;
|
|
7646
|
-
const rpcCalls = (options === null || options === void 0 ? void 0 : options.rpcCalls) === undefined ?
|
|
6641
|
+
const rpcCalls = (options === null || options === void 0 ? void 0 : options.rpcCalls) === undefined ? 3 : options.rpcCalls;
|
|
7647
6642
|
if (!Array.isArray(transactions))
|
|
7648
6643
|
transactions = [transactions];
|
|
7649
6644
|
if (convertIntoTxV0) {
|
|
7650
|
-
transactions = transactions.map((tx) => txToV0(tx, wallet.publicKey,
|
|
6645
|
+
transactions = transactions.map((tx) => txToV0(tx, wallet.publicKey, FAKE_BLOCKHASH));
|
|
7651
6646
|
}
|
|
7652
6647
|
let txIds = [];
|
|
7653
6648
|
if ((options === null || options === void 0 ? void 0 : options.waitBetweenSend) === undefined || options.waitBetweenSend === 0) {
|
|
@@ -7655,16 +6650,16 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
7655
6650
|
var _b;
|
|
7656
6651
|
let txV0;
|
|
7657
6652
|
if (isVersionedTx(tx)) {
|
|
7658
|
-
tx.message.recentBlockhash =
|
|
6653
|
+
tx.message.recentBlockhash = FAKE_BLOCKHASH;
|
|
7659
6654
|
txV0 = tx;
|
|
7660
6655
|
}
|
|
7661
6656
|
else {
|
|
7662
|
-
tx.recentBlockhash =
|
|
6657
|
+
tx.recentBlockhash = FAKE_BLOCKHASH;
|
|
7663
6658
|
tx.feePayer = wallet.publicKey;
|
|
7664
6659
|
txV0 = new VersionedTransaction(MessageV0.compile({
|
|
7665
6660
|
addressLookupTableAccounts: [],
|
|
7666
6661
|
instructions: tx.instructions,
|
|
7667
|
-
recentBlockhash:
|
|
6662
|
+
recentBlockhash: FAKE_BLOCKHASH,
|
|
7668
6663
|
payerKey: tx.feePayer,
|
|
7669
6664
|
}));
|
|
7670
6665
|
}
|
|
@@ -7752,12 +6747,177 @@ var interfaces = /*#__PURE__*/Object.freeze({
|
|
|
7752
6747
|
isBuffer: isBuffer
|
|
7753
6748
|
});
|
|
7754
6749
|
|
|
6750
|
+
/**
|
|
6751
|
+
* All functions are copied from ethers. This is optimization to reduce dependencies
|
|
6752
|
+
*/
|
|
6753
|
+
function concat(items) {
|
|
6754
|
+
const objects = items.map(item => arrayify(item));
|
|
6755
|
+
const length = objects.reduce((accum, item) => (accum + item.length), 0);
|
|
6756
|
+
const result = new Uint8Array(length);
|
|
6757
|
+
objects.reduce((offset, object) => {
|
|
6758
|
+
result.set(object, offset);
|
|
6759
|
+
return offset + object.length;
|
|
6760
|
+
}, 0);
|
|
6761
|
+
return result;
|
|
6762
|
+
}
|
|
6763
|
+
function arrayify(value) {
|
|
6764
|
+
if (typeof (value) === "number") {
|
|
6765
|
+
const numValue = value;
|
|
6766
|
+
const result = [];
|
|
6767
|
+
while (value) {
|
|
6768
|
+
result.unshift(numValue & 0xff);
|
|
6769
|
+
value = parseInt(String(numValue / 256));
|
|
6770
|
+
}
|
|
6771
|
+
if (result.length === 0) {
|
|
6772
|
+
result.push(0);
|
|
6773
|
+
}
|
|
6774
|
+
return new Uint8Array(result);
|
|
6775
|
+
}
|
|
6776
|
+
if (BN.isBN(value)) {
|
|
6777
|
+
value = `0x${value.toString("hex")}`;
|
|
6778
|
+
}
|
|
6779
|
+
if (typeof (value) === "string" && value.startsWith("0x")) {
|
|
6780
|
+
return hexToBuffer(value);
|
|
6781
|
+
}
|
|
6782
|
+
if (Array.isArray(value) || ArrayBuffer.isView(value)) {
|
|
6783
|
+
return new Uint8Array(value);
|
|
6784
|
+
}
|
|
6785
|
+
throw new Error(`unknown value: ${value}`);
|
|
6786
|
+
}
|
|
6787
|
+
// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
|
|
6788
|
+
function toUtf8Bytes(str) {
|
|
6789
|
+
let result = [];
|
|
6790
|
+
for (let i = 0; i < str.length; i++) {
|
|
6791
|
+
const c = str.charCodeAt(i);
|
|
6792
|
+
if (c < 0x80) {
|
|
6793
|
+
result.push(c);
|
|
6794
|
+
}
|
|
6795
|
+
else if (c < 0x800) {
|
|
6796
|
+
result.push((c >> 6) | 0xc0);
|
|
6797
|
+
result.push((c & 0x3f) | 0x80);
|
|
6798
|
+
}
|
|
6799
|
+
else if ((c & 0xfc00) == 0xd800) {
|
|
6800
|
+
i++;
|
|
6801
|
+
const c2 = str.charCodeAt(i);
|
|
6802
|
+
if (i >= str.length || (c2 & 0xfc00) !== 0xdc00) {
|
|
6803
|
+
throw new Error("invalid utf-8 string");
|
|
6804
|
+
}
|
|
6805
|
+
// Surrogate Pair
|
|
6806
|
+
const pair = 0x10000 + ((c & 0x03ff) << 10) + (c2 & 0x03ff);
|
|
6807
|
+
result.push((pair >> 18) | 0xf0);
|
|
6808
|
+
result.push(((pair >> 12) & 0x3f) | 0x80);
|
|
6809
|
+
result.push(((pair >> 6) & 0x3f) | 0x80);
|
|
6810
|
+
result.push((pair & 0x3f) | 0x80);
|
|
6811
|
+
}
|
|
6812
|
+
else {
|
|
6813
|
+
result.push((c >> 12) | 0xe0);
|
|
6814
|
+
result.push(((c >> 6) & 0x3f) | 0x80);
|
|
6815
|
+
result.push((c & 0x3f) | 0x80);
|
|
6816
|
+
}
|
|
6817
|
+
}
|
|
6818
|
+
return arrayify(result);
|
|
6819
|
+
}
|
|
6820
|
+
const zeroPad = (value, length) => {
|
|
6821
|
+
const bufValue = arrayify(value);
|
|
6822
|
+
if (bufValue.length > length) {
|
|
6823
|
+
throw new Error("value out of range");
|
|
6824
|
+
}
|
|
6825
|
+
const result = new Uint8Array(length);
|
|
6826
|
+
result.set(bufValue, length - bufValue.length);
|
|
6827
|
+
return result;
|
|
6828
|
+
};
|
|
6829
|
+
const isHexString = (data) => typeof (data) === "string" && data.startsWith("0x");
|
|
6830
|
+
const _pack = (type, value, isArray) => {
|
|
6831
|
+
const regexBytes = new RegExp("^bytes([0-9]+)$");
|
|
6832
|
+
const regexNumber = new RegExp("^(u?int)([0-9]*)$");
|
|
6833
|
+
const regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
|
|
6834
|
+
const Zeros = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
6835
|
+
switch (type) {
|
|
6836
|
+
case "address":
|
|
6837
|
+
if (isArray) {
|
|
6838
|
+
return zeroPad(value, 32);
|
|
6839
|
+
}
|
|
6840
|
+
return arrayify(value);
|
|
6841
|
+
case "string":
|
|
6842
|
+
return toUtf8Bytes(value);
|
|
6843
|
+
case "bytes":
|
|
6844
|
+
return arrayify(value);
|
|
6845
|
+
case "bool":
|
|
6846
|
+
value = (value ? "0x01" : "0x00");
|
|
6847
|
+
if (isArray) {
|
|
6848
|
+
return zeroPad(value, 32);
|
|
6849
|
+
}
|
|
6850
|
+
return arrayify(value);
|
|
6851
|
+
}
|
|
6852
|
+
let match = type.match(regexNumber);
|
|
6853
|
+
if (match) {
|
|
6854
|
+
//let signed = (match[1] === "int")
|
|
6855
|
+
let size = parseInt(match[2] || "256");
|
|
6856
|
+
if ((match[2] && String(size) !== match[2]) || (size % 8 !== 0) || size === 0 || size > 256) {
|
|
6857
|
+
throw new Error("invalid number type");
|
|
6858
|
+
}
|
|
6859
|
+
if (isArray) {
|
|
6860
|
+
size = 256;
|
|
6861
|
+
}
|
|
6862
|
+
if (isHexString(value)) {
|
|
6863
|
+
value = new BN(value.slice(2), "hex").toTwos(size);
|
|
6864
|
+
}
|
|
6865
|
+
else {
|
|
6866
|
+
value = new BN(value).toTwos(size);
|
|
6867
|
+
}
|
|
6868
|
+
return zeroPad(value, size / 8);
|
|
6869
|
+
}
|
|
6870
|
+
match = type.match(regexBytes);
|
|
6871
|
+
if (match) {
|
|
6872
|
+
const size = parseInt(match[1]);
|
|
6873
|
+
if (String(size) !== match[1] || size === 0 || size > 32) {
|
|
6874
|
+
throw new Error("invalid bytes type");
|
|
6875
|
+
}
|
|
6876
|
+
if (arrayify(value).byteLength !== size) {
|
|
6877
|
+
throw new Error(`invalid value for ${type}`);
|
|
6878
|
+
}
|
|
6879
|
+
if (isArray) {
|
|
6880
|
+
return arrayify((value + Zeros).substring(0, 66));
|
|
6881
|
+
}
|
|
6882
|
+
return value;
|
|
6883
|
+
}
|
|
6884
|
+
match = type.match(regexArray);
|
|
6885
|
+
if (match && Array.isArray(value)) {
|
|
6886
|
+
const baseType = match[1];
|
|
6887
|
+
const count = parseInt(match[2] || String(value.length));
|
|
6888
|
+
if (count != value.length) {
|
|
6889
|
+
throw new Error(`invalid array length for ${type}`);
|
|
6890
|
+
}
|
|
6891
|
+
const result = [];
|
|
6892
|
+
value.forEach(function (value) {
|
|
6893
|
+
result.push(_pack(baseType, value, true));
|
|
6894
|
+
});
|
|
6895
|
+
return concat(result);
|
|
6896
|
+
}
|
|
6897
|
+
throw new Error("invalid type");
|
|
6898
|
+
};
|
|
6899
|
+
function solidityPack(types, values) {
|
|
6900
|
+
if (types.length != values.length) {
|
|
6901
|
+
throw new Error("types and values length mismatch");
|
|
6902
|
+
}
|
|
6903
|
+
const tight = [];
|
|
6904
|
+
types.forEach((type, index) => {
|
|
6905
|
+
tight.push(_pack(type, values[index]));
|
|
6906
|
+
});
|
|
6907
|
+
return concat(tight);
|
|
6908
|
+
}
|
|
6909
|
+
|
|
6910
|
+
const keccak256 = (data) => `0x${sha3.exports.keccak256(data)}`;
|
|
6911
|
+
const solidityKeccak256 = (types, values) => {
|
|
6912
|
+
const packed = solidityPack(types, values);
|
|
6913
|
+
return keccak256(packed);
|
|
6914
|
+
};
|
|
7755
6915
|
function denormalizeAmount(amount, denominator) {
|
|
7756
|
-
const denominatorBN = new BN
|
|
6916
|
+
const denominatorBN = new BN(Math.pow(10, denominator));
|
|
7757
6917
|
return amount.mul(denominatorBN).toArrayLike(buffer.Buffer, "be", 32);
|
|
7758
6918
|
}
|
|
7759
6919
|
function normalizeChainId(chainId) {
|
|
7760
|
-
return hexToBuffer(`0x${isBuffer(chainId) ? chainId.toString("hex") : new BN
|
|
6920
|
+
return hexToBuffer(`0x${isBuffer(chainId) ? chainId.toString("hex") : new BN(chainId).toString(16)}`, 32);
|
|
7761
6921
|
}
|
|
7762
6922
|
/**
|
|
7763
6923
|
* Hashes deploy info
|
|
@@ -7765,9 +6925,9 @@ function normalizeChainId(chainId) {
|
|
|
7765
6925
|
* @returns keccak256 of deployInfo structure
|
|
7766
6926
|
*/
|
|
7767
6927
|
function hashDeployInfo(params) {
|
|
7768
|
-
const nameHash =
|
|
7769
|
-
const symbolHash =
|
|
7770
|
-
const deployInfoHash =
|
|
6928
|
+
const nameHash = solidityKeccak256(["string"], [params.tokenName]);
|
|
6929
|
+
const symbolHash = solidityKeccak256(["string"], [params.tokenSymbol]);
|
|
6930
|
+
const deployInfoHash = solidityKeccak256(["uint256", "uint256", "uint256", "uint256", "uint8"], [DEPLOY_INFO_PREFIX, params.debridgeId, nameHash, symbolHash, params.decimals]);
|
|
7771
6931
|
return deployInfoHash;
|
|
7772
6932
|
}
|
|
7773
6933
|
/**
|
|
@@ -7778,11 +6938,11 @@ function hashDeployInfo(params) {
|
|
|
7778
6938
|
*/
|
|
7779
6939
|
function hashDebridgeId(nativeChainId, nativeTokenAddress) {
|
|
7780
6940
|
const chainIdBuffer = normalizeChainId(nativeChainId);
|
|
7781
|
-
const bridgeId =
|
|
6941
|
+
const bridgeId = solidityKeccak256(["uint256", "bytes"], [chainIdBuffer, nativeTokenAddress]);
|
|
7782
6942
|
return bridgeId;
|
|
7783
6943
|
}
|
|
7784
6944
|
function hashExternalCallBytes(data) {
|
|
7785
|
-
return hexToBuffer(
|
|
6945
|
+
return hexToBuffer(solidityKeccak256(["bytes"], [data ? data : buffer.Buffer.from([])]), 32);
|
|
7786
6946
|
}
|
|
7787
6947
|
/**
|
|
7788
6948
|
* Hashes submission for provided data
|
|
@@ -7808,11 +6968,11 @@ function hashSubmissionIdRaw(params) {
|
|
|
7808
6968
|
: new PublicKey(params.receiver)
|
|
7809
6969
|
: new PublicKey(params.receiver).toBuffer();
|
|
7810
6970
|
let packData = [
|
|
7811
|
-
|
|
6971
|
+
SUBMISSION_PREFIX,
|
|
7812
6972
|
params.debridgeId,
|
|
7813
6973
|
normalizeChainId(params.sourceChainId),
|
|
7814
6974
|
normalizeChainId(params.targetChainId),
|
|
7815
|
-
new BN
|
|
6975
|
+
new BN(params.amount).toArray("be", 32),
|
|
7816
6976
|
receiver,
|
|
7817
6977
|
params.nonce, // nonce
|
|
7818
6978
|
];
|
|
@@ -7833,19 +6993,21 @@ function hashSubmissionIdRaw(params) {
|
|
|
7833
6993
|
? hexToBuffer(params.autoParams.fallbackAddress)
|
|
7834
6994
|
: new PublicKey(params.autoParams.fallbackAddress).toBuffer();
|
|
7835
6995
|
packData = packData.concat([
|
|
7836
|
-
new BN
|
|
7837
|
-
new BN
|
|
6996
|
+
new BN(((_c = params === null || params === void 0 ? void 0 : params.autoParams) === null || _c === void 0 ? void 0 : _c.executionFee) || 0).toArray("be", 32),
|
|
6997
|
+
new BN(((_d = params.autoParams) === null || _d === void 0 ? void 0 : _d.flags) || 0).toArray("be", 32),
|
|
7838
6998
|
hashExternalCallBytes(fallback),
|
|
7839
6999
|
shortcut,
|
|
7840
7000
|
hashExternalCallBytes(params.autoParams.nativeSender),
|
|
7841
7001
|
]);
|
|
7842
7002
|
}
|
|
7843
|
-
const submissionIdHash =
|
|
7003
|
+
const submissionIdHash = solidityKeccak256(packParams, packData);
|
|
7844
7004
|
return submissionIdHash;
|
|
7845
7005
|
}
|
|
7846
7006
|
|
|
7847
7007
|
var crypto = /*#__PURE__*/Object.freeze({
|
|
7848
7008
|
__proto__: null,
|
|
7009
|
+
keccak256: keccak256,
|
|
7010
|
+
solidityKeccak256: solidityKeccak256,
|
|
7849
7011
|
denormalizeAmount: denormalizeAmount,
|
|
7850
7012
|
normalizeChainId: normalizeChainId,
|
|
7851
7013
|
hashDeployInfo: hashDeployInfo,
|
|
@@ -10442,7 +9604,7 @@ function getNativeWalletBalance(connection, wallet) {
|
|
|
10442
9604
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10443
9605
|
wallet = new PublicKey(wallet);
|
|
10444
9606
|
const result = yield connection.getBalance(wallet);
|
|
10445
|
-
return new BN
|
|
9607
|
+
return new BN(result.toString());
|
|
10446
9608
|
});
|
|
10447
9609
|
}
|
|
10448
9610
|
/**
|
|
@@ -10456,7 +9618,7 @@ function getAssocSPLWalletBalance(connection, originalWallet, tokenMint) {
|
|
|
10456
9618
|
tokenMint = new PublicKey(tokenMint);
|
|
10457
9619
|
const [wallet] = findAssociatedTokenAddress(originalWallet, tokenMint);
|
|
10458
9620
|
const result = yield connection.getTokenAccountBalance(wallet, "finalized");
|
|
10459
|
-
return new BN
|
|
9621
|
+
return new BN(result.value.amount);
|
|
10460
9622
|
});
|
|
10461
9623
|
}
|
|
10462
9624
|
/**
|
|
@@ -10467,7 +9629,7 @@ function getSPLWalletBalance(connection, wallet) {
|
|
|
10467
9629
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10468
9630
|
wallet = new PublicKey(wallet);
|
|
10469
9631
|
const result = yield connection.getTokenAccountBalance(wallet, "finalized");
|
|
10470
|
-
return new BN
|
|
9632
|
+
return new BN(result.value.amount);
|
|
10471
9633
|
});
|
|
10472
9634
|
}
|
|
10473
9635
|
/**
|
|
@@ -10484,7 +9646,7 @@ function getAllTokenAccountsWithBalances(connection, owner) {
|
|
|
10484
9646
|
return {
|
|
10485
9647
|
address: wallet.pubkey,
|
|
10486
9648
|
mint: new PublicKey(tokenInfo.info.mint),
|
|
10487
|
-
amount: new BN
|
|
9649
|
+
amount: new BN(tokenInfo.info.tokenAmount.amount),
|
|
10488
9650
|
decimals: tokenInfo.info.tokenAmount.decimals,
|
|
10489
9651
|
isInitialized: true,
|
|
10490
9652
|
isNative: tokenInfo.info.isNative,
|
|
@@ -10508,7 +9670,7 @@ function getTokenAccountsWithBalance(connection, tokenMint, owner) {
|
|
|
10508
9670
|
return {
|
|
10509
9671
|
address: wallet.pubkey,
|
|
10510
9672
|
mint: new PublicKey(tokenInfo.info.mint),
|
|
10511
|
-
amount: new BN
|
|
9673
|
+
amount: new BN(tokenInfo.info.tokenAmount.amount),
|
|
10512
9674
|
decimals: tokenInfo.info.tokenAmount.decimals,
|
|
10513
9675
|
isInitialized: true,
|
|
10514
9676
|
isNative: tokenInfo.info.isNative,
|
|
@@ -10528,7 +9690,7 @@ function buildReplenishWsolBalanceTransaction(amount, transferFrom, transferTo)
|
|
|
10528
9690
|
transferFrom = new PublicKey(transferFrom);
|
|
10529
9691
|
transferTo = new PublicKey(transferTo);
|
|
10530
9692
|
const tx = new Transaction();
|
|
10531
|
-
tx.add(SystemProgram.transfer({ fromPubkey: transferFrom, toPubkey: transferTo, lamports: new BN
|
|
9693
|
+
tx.add(SystemProgram.transfer({ fromPubkey: transferFrom, toPubkey: transferTo, lamports: new BN(amount).toNumber() }));
|
|
10532
9694
|
tx.add(
|
|
10533
9695
|
// sync native
|
|
10534
9696
|
new TransactionInstruction({
|
|
@@ -10548,27 +9710,20 @@ function updateWsolBalance(connection, amount, owner) {
|
|
|
10548
9710
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10549
9711
|
owner = new PublicKey(owner);
|
|
10550
9712
|
const tx = new Transaction();
|
|
10551
|
-
const accountSize = 165;
|
|
10552
9713
|
const [wSolATA] = findAssociatedTokenAddress(owner, WRAPPED_SOL_MINT);
|
|
10553
9714
|
const existingATA = yield getAccountInfo(connection, wSolATA);
|
|
10554
|
-
let amountToWrap = new BN
|
|
9715
|
+
let amountToWrap = new BN(amount);
|
|
10555
9716
|
if (existingATA === null) {
|
|
10556
|
-
tx.add(
|
|
10557
|
-
fromPubkey: owner,
|
|
10558
|
-
space: accountSize,
|
|
10559
|
-
programId: TOKEN_PROGRAM_ID,
|
|
10560
|
-
newAccountPubkey: wSolATA,
|
|
10561
|
-
lamports: yield connection.getMinimumBalanceForRentExemption(accountSize),
|
|
10562
|
-
}));
|
|
9717
|
+
tx.add(createAssociatedWalletInstruction(WRAPPED_SOL_MINT, wSolATA, owner, owner));
|
|
10563
9718
|
}
|
|
10564
9719
|
else {
|
|
10565
9720
|
const parsed = parseSplAccount(existingATA.data);
|
|
10566
9721
|
if (!parsed)
|
|
10567
9722
|
throw new Error("WSol account exists, but failed to decode its content");
|
|
10568
|
-
const parsedAmount = new BN
|
|
9723
|
+
const parsedAmount = new BN(parsed.amount.toString());
|
|
10569
9724
|
if (amountToWrap.lte(parsedAmount))
|
|
10570
9725
|
return null; // don't need to wrap
|
|
10571
|
-
amountToWrap =
|
|
9726
|
+
amountToWrap = amountToWrap.sub(parsedAmount);
|
|
10572
9727
|
}
|
|
10573
9728
|
const replenishTx = buildReplenishWsolBalanceTransaction(amountToWrap, owner, wSolATA);
|
|
10574
9729
|
tx.add(replenishTx);
|