@gelatonetwork/relay-sdk
Advanced tools
Comparing version 0.1.0 to 0.2.0
export * as utils from "./utils"; | ||
export * as RelaySDK from "./lib"; | ||
export * as RelayTransaction from "./types"; | ||
export * from "./types"; |
@@ -25,6 +25,9 @@ "use strict"; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RelayTransaction = exports.RelaySDK = exports.utils = void 0; | ||
exports.RelaySDK = exports.utils = void 0; | ||
exports.utils = __importStar(require("./utils")); | ||
exports.RelaySDK = __importStar(require("./lib")); | ||
exports.RelayTransaction = __importStar(require("./types")); | ||
__exportStar(require("./types"), exports); |
@@ -1,8 +0,9 @@ | ||
import RelayTransaction from "../types/RelayTransaction.interface"; | ||
import { RelayTransaction } from "../types/"; | ||
import { BigNumber } from "ethers"; | ||
declare const sendRelayTransaction: (chainId: number, dest: string, data: string, token: string, relayerFee: BigNumber) => Promise<RelayTransaction>; | ||
declare const isChainSupported: (chainId: number) => Promise<boolean>; | ||
declare const getEstimatedFee: (chainId: number, paymentToken: string, gasLimit: BigNumber, isHighPriority: boolean) => Promise<BigNumber>; | ||
declare const isOracleActive: (chainId: number) => Promise<boolean>; | ||
declare const getPaymentTokens: (chainId: number) => Promise<string[]>; | ||
export { isChainSupported, sendRelayTransaction, isOracleActive, getEstimatedFee, getPaymentTokens, }; | ||
declare const getEstimatedFee: (chainId: number, paymentToken: string, gasLimit: BigNumber, isHighPriority: boolean) => Promise<BigNumber>; | ||
declare const getTaskStatus: (taskId: string) => Promise<import("@gelatonetwork/core-sdk").TransactionStatus | undefined>; | ||
export { isChainSupported, sendRelayTransaction, isOracleActive, getPaymentTokens, getEstimatedFee, getTaskStatus, }; |
@@ -15,7 +15,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPaymentTokens = exports.getEstimatedFee = exports.isOracleActive = exports.sendRelayTransaction = exports.isChainSupported = void 0; | ||
exports.getTaskStatus = exports.getEstimatedFee = exports.getPaymentTokens = exports.isOracleActive = exports.sendRelayTransaction = exports.isChainSupported = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const ethers_1 = require("ethers"); | ||
const constants_1 = __importDefault(require("../utils/constants")); | ||
const { RELAY_URL } = constants_1.default; | ||
const core_sdk_1 = require("@gelatonetwork/core-sdk"); | ||
const sendRelayTransaction = (chainId, dest, data, token, relayerFee) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -26,3 +24,3 @@ var _a, _b; | ||
try { | ||
const res = yield axios_1.default.post(`${RELAY_URL}/relays/${chainId}`, params); | ||
const res = yield axios_1.default.post(`${core_sdk_1.RELAY_URL}/relays/${chainId}`, params); | ||
output = res.data; | ||
@@ -48,3 +46,3 @@ } | ||
try { | ||
const res = yield axios_1.default.get(`${RELAY_URL}/relays/`); | ||
const res = yield axios_1.default.get(`${core_sdk_1.RELAY_URL}/relays/`); | ||
result = res.data.relays; | ||
@@ -55,49 +53,9 @@ } | ||
}); | ||
const getEstimatedFee = (chainId, paymentToken, gasLimit, isHighPriority) => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield _getEstimatedFee(chainId, paymentToken, gasLimit.toString(), isHighPriority); | ||
return result; | ||
}); | ||
exports.getEstimatedFee = getEstimatedFee; | ||
const _getEstimatedFee = (chainId, paymentToken, gasLimit, isHighPriority) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _c, _d; | ||
const params = { paymentToken, gasLimit, isHighPriority }; | ||
let result; | ||
try { | ||
const res = yield axios_1.default.get(`${RELAY_URL}/oracles/${chainId}/estimate`, { | ||
params, | ||
}); | ||
result = ethers_1.BigNumber.from(res.data.estimatedFee); | ||
} | ||
catch (error) { | ||
let message = `RelaySdkError: ${error.message} `; | ||
if (axios_1.default.isAxiosError(error)) { | ||
message += (_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message; | ||
} | ||
throw new Error(message); | ||
} | ||
return result; | ||
}); | ||
const isOracleActive = (chainId) => __awaiter(void 0, void 0, void 0, function* () { | ||
const oracles = yield getGelatoOracles(); | ||
return oracles.includes(chainId.toString()); | ||
}); | ||
const isOracleActive = core_sdk_1.Oracle.isOracleActive; | ||
exports.isOracleActive = isOracleActive; | ||
const getGelatoOracles = () => __awaiter(void 0, void 0, void 0, function* () { | ||
let result = []; | ||
try { | ||
const res = yield axios_1.default.get(`${RELAY_URL}/oracles/`); | ||
result = res.data.oracles; | ||
} | ||
catch (error) { } // eslint-disable-line no-empty | ||
return result; | ||
}); | ||
const getPaymentTokens = (chainId) => __awaiter(void 0, void 0, void 0, function* () { | ||
let result = []; | ||
try { | ||
const res = yield axios_1.default.get(`${RELAY_URL}/oracles/${chainId}/paymentTokens/`); | ||
result = res.data.paymentTokens; | ||
} | ||
catch (error) { } // eslint-disable-line no-empty | ||
return result; | ||
}); | ||
const getPaymentTokens = core_sdk_1.Oracle.getPaymentTokens; | ||
exports.getPaymentTokens = getPaymentTokens; | ||
const getEstimatedFee = core_sdk_1.Oracle.getEstimatedFee; | ||
exports.getEstimatedFee = getEstimatedFee; | ||
const getTaskStatus = core_sdk_1.Status.getTaskStatus; | ||
exports.getTaskStatus = getTaskStatus; |
export * from "./RelayTransaction.interface"; | ||
export { TransactionStatus, TaskState } from "@gelatonetwork/core-sdk"; |
@@ -17,2 +17,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TaskState = void 0; | ||
__exportStar(require("./RelayTransaction.interface"), exports); | ||
var core_sdk_1 = require("@gelatonetwork/core-sdk"); | ||
Object.defineProperty(exports, "TaskState", { enumerable: true, get: function () { return core_sdk_1.TaskState; } }); |
@@ -1,4 +0,3 @@ | ||
interface RelayTransaction { | ||
export interface RelayTransaction { | ||
taskId: string; | ||
} | ||
export default RelayTransaction; |
{ | ||
"name": "@gelatonetwork/relay-sdk", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "SDK to integrate the Gelato Multichain Relay", | ||
@@ -32,2 +32,7 @@ "main": "dist/index.js", | ||
"@typescript-eslint/parser": "^5.6.0", | ||
"chai": "^4.3.6", | ||
"chai-arrays": "^2.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-bignumber": "^3.0.0", | ||
"chai-subset": "^1.6.0", | ||
"eslint": "^8.4.1", | ||
@@ -38,3 +43,6 @@ "eslint-config-prettier": "^8.3.0", | ||
"lint-staged": "^11.1.2", | ||
"mocha": "^9.2.0", | ||
"prettier": "^2.3.2", | ||
"sinon": "^13.0.1", | ||
"sinon-chai": "^3.7.0", | ||
"ts-generator": "^0.1.1", | ||
@@ -45,14 +53,7 @@ "ts-mocha": "^9.0.2", | ||
"dependencies": { | ||
"@gelatonetwork/core-sdk": "^0.1.0", | ||
"axios": "^0.24.0", | ||
"chai": "^4.3.6", | ||
"chai-arrays": "^2.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-bignumber": "^3.0.0", | ||
"chai-subset": "^1.6.0", | ||
"ethers": "^5.5.2", | ||
"mocha": "^9.2.0", | ||
"sinon": "^13.0.1", | ||
"sinon-chai": "^3.7.0" | ||
"ethers": "^5.5.2" | ||
}, | ||
"gitHead": "ba4c7d247743f1ef3a8b638e74d7ebc891f52b0f" | ||
"gitHead": "587072a94ff720253fa7eb2242907ae064f4693c" | ||
} |
@@ -46,8 +46,8 @@ # Gelato Multichain Relay SDK <!-- omit in toc --> | ||
if (!isActiveOracle) { | ||
console.log("Oracle is not active on this network"); | ||
console.log("Oracle is not active on this Oracle"); | ||
return; | ||
} | ||
// Estimates the transaction cost in the defined token for the inputted gasLimit | ||
// The paymentTokenAddress is the address of the token used to pay transaction fees | ||
// Estimate the Token cost now for the given GasLimit and it's the amount of Token | ||
// that the function should pay back to the caller | ||
const estimatedExecutionFeeInToken: BigNumber = await RelaySDK.getEstimatedFee( | ||
@@ -89,2 +89,28 @@ chainId, | ||
5. Check your transaction status: | ||
```typescript | ||
const status = await RelaySDK.getTaskStatus(taskId); | ||
if (status) { | ||
const state = (status as TransactionStatus).taskState; | ||
switch (state) { | ||
case TaskState.CheckPending: | ||
console.log(`> Task pending relayer verification`); | ||
break; | ||
case TaskState.ExecPending: | ||
console.log(`> Task queued for execution`); | ||
break; | ||
case TaskState.ExecSuccess: | ||
console.log(`> Task successfully executed, tx hash: ${status.execution?.transactionHash}`); | ||
break; | ||
case TaskState.ExecReverted: | ||
console.log(`> Task was reverted with message: ${status.lastCheck?.message}`); | ||
break; | ||
case TaskState.Cancelled: | ||
console.log(`> Task was cancelled with message: ${status.lastCheck?.message}`); | ||
break; | ||
default: | ||
console.log(`> Task status: ${state}`); | ||
} | ||
``` | ||
## Examples | ||
@@ -91,0 +117,0 @@ |
3
166
20058
27
257
+ Added@gelatonetwork/core-sdk@0.1.4(transitive)
- Removedchai@^4.3.6
- Removedchai-arrays@^2.2.0
- Removedchai-as-promised@^7.1.1
- Removedchai-bignumber@^3.0.0
- Removedchai-subset@^1.6.0
- Removedmocha@^9.2.0
- Removedsinon@^13.0.1
- Removedsinon-chai@^3.7.0
- Removed@sinonjs/commons@1.8.63.0.1(transitive)
- Removed@sinonjs/fake-timers@11.3.19.1.2(transitive)
- Removed@sinonjs/samsam@6.1.3(transitive)
- Removed@sinonjs/text-encoding@0.7.3(transitive)
- Removed@ungap/promise-all-settled@1.1.2(transitive)
- Removedansi-colors@4.1.1(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedanymatch@3.1.3(transitive)
- Removedargparse@2.0.1(transitive)
- Removedassertion-error@1.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbinary-extensions@2.3.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbraces@3.0.3(transitive)
- Removedbrowser-stdout@1.3.1(transitive)
- Removedcamelcase@6.3.0(transitive)
- Removedchai@4.5.0(transitive)
- Removedchai-arrays@2.2.0(transitive)
- Removedchai-as-promised@7.1.2(transitive)
- Removedchai-bignumber@3.1.0(transitive)
- Removedchai-subset@1.6.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcheck-error@1.0.3(transitive)
- Removedchokidar@3.5.3(transitive)
- Removedcliui@7.0.4(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddebug@4.3.3(transitive)
- Removeddecamelize@4.0.0(transitive)
- Removeddeep-eql@4.1.4(transitive)
- Removeddiff@5.0.0(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedescalade@3.2.0(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedfind-up@5.0.0(transitive)
- Removedflat@5.0.2(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfsevents@2.3.3(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedget-func-name@2.0.2(transitive)
- Removedglob@7.2.0(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedgrowl@1.10.5(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedhe@1.2.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedis-binary-path@2.1.0(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedis-plain-obj@2.1.0(transitive)
- Removedis-unicode-supported@0.1.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedjust-extend@6.2.0(transitive)
- Removedlocate-path@6.0.0(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedlog-symbols@4.1.0(transitive)
- Removedloupe@2.3.7(transitive)
- Removedminimatch@3.1.24.2.1(transitive)
- Removedmocha@9.2.2(transitive)
- Removedms@2.1.22.1.3(transitive)
- Removednanoid@3.3.1(transitive)
- Removednise@5.1.9(transitive)
- Removednormalize-path@3.0.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedp-locate@5.0.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-to-regexp@6.3.0(transitive)
- Removedpathval@1.1.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedreaddirp@3.6.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedserialize-javascript@6.0.0(transitive)
- Removedsinon@13.0.2(transitive)
- Removedsinon-chai@3.7.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedstrip-json-comments@3.1.1(transitive)
- Removedsupports-color@7.2.08.1.1(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtype-detect@4.0.84.1.0(transitive)
- Removedwhich@2.0.2(transitive)
- Removedworkerpool@6.2.0(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyargs@16.2.0(transitive)
- Removedyargs-parser@20.2.4(transitive)
- Removedyargs-unparser@2.0.0(transitive)
- Removedyocto-queue@0.1.0(transitive)