@gelatonetwork/relay-sdk
Advanced tools
Comparing version 1.0.1-beta to 1.0.1-beta.0
@@ -1,5 +0,7 @@ | ||
export declare const GELATO_RELAY_URL = "http://localhost:8080"; | ||
export declare const GELATO_RELAY_URL = "https://relay.gelato.digital"; | ||
export declare const SIGN_TYPED_DATA_V4 = "eth_signTypedData_v4"; | ||
export declare const DEFAULT_INTERNAL_ERROR_MESSAGE = "Internal Error"; | ||
export declare const getRelayAddress: (chainId: number) => string; | ||
export declare const getRelayWithTransferFromAddress: (chainId: number) => string; | ||
export declare const DEFAULT_DEADLINE_GAP = 86400; | ||
export declare const ABI: string[]; | ||
export declare const USER_NONCE_ABI: string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ABI = exports.DEFAULT_DEADLINE_GAP = exports.getRelayAddress = exports.SIGN_TYPED_DATA_V4 = exports.GELATO_RELAY_URL = void 0; | ||
exports.USER_NONCE_ABI = exports.DEFAULT_DEADLINE_GAP = exports.getRelayWithTransferFromAddress = exports.getRelayAddress = exports.DEFAULT_INTERNAL_ERROR_MESSAGE = exports.SIGN_TYPED_DATA_V4 = exports.GELATO_RELAY_URL = void 0; | ||
const ethers_1 = require("ethers"); | ||
exports.GELATO_RELAY_URL = "http://localhost:8080"; //"https://relay.gelato.digital"; | ||
exports.GELATO_RELAY_URL = "https://relay.gelato.digital"; //Relay GW | ||
exports.SIGN_TYPED_DATA_V4 = "eth_signTypedData_v4"; | ||
exports.DEFAULT_INTERNAL_ERROR_MESSAGE = "Internal Error"; | ||
const getRelayAddress = (chainId) => { | ||
@@ -16,5 +17,14 @@ switch (chainId) { | ||
exports.getRelayAddress = getRelayAddress; | ||
exports.DEFAULT_DEADLINE_GAP = 86400; | ||
exports.ABI = [ | ||
const getRelayWithTransferFromAddress = (chainId) => { | ||
switch (chainId) { | ||
case 80001: | ||
return ethers_1.utils.getAddress("0xaBcC9b596420A9E9172FD5938620E265a0f9Df92"); | ||
default: | ||
throw new Error(`getRelayWithTransferFromAddress: chainId [${chainId}] is not supported`); | ||
} | ||
}; | ||
exports.getRelayWithTransferFromAddress = getRelayWithTransferFromAddress; | ||
exports.DEFAULT_DEADLINE_GAP = 86400; //24H | ||
exports.USER_NONCE_ABI = [ | ||
"function userNonce(address account) external view returns (uint256)", | ||
]; |
@@ -18,2 +18,3 @@ "use strict"; | ||
const constants_1 = require("../../constants"); | ||
const utils_1 = require("../../utils"); | ||
/** | ||
@@ -26,3 +27,2 @@ * @param {CallWithSyncFeeRequest} request - CallWithSyncFee request to be relayed by Gelato Executors | ||
const relayWithSyncFee = (request, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a; | ||
try { | ||
@@ -33,6 +33,5 @@ const response = yield axios_1.default.post(`${constants_1.GELATO_RELAY_URL}/relays/v2/call-with-sync-fee`, Object.assign(Object.assign({}, request), options)); | ||
catch (error) { | ||
const errorMessage = (_a = error.message) !== null && _a !== void 0 ? _a : String(error); | ||
throw new Error(`GelatoRelaySDK/relayWithSyncFee: Failed with error: ${errorMessage}`); | ||
throw new Error(`GelatoRelaySDK/relayWithSyncFee: Failed with error: ${(0, utils_1.getHttpErrorMessage)(error)}`); | ||
} | ||
}); | ||
exports.relayWithSyncFee = relayWithSyncFee; |
export { relayWithUserSignature } from "./userAuthCall"; | ||
export { relayWithSyncFee } from "./callWithSyncFee"; | ||
export { PaymentType } from "./types"; | ||
export { generateSponsorSignature } from "./sponsorAuthCall"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PaymentType = exports.relayWithSyncFee = exports.relayWithUserSignature = void 0; | ||
exports.generateSponsorSignature = exports.PaymentType = exports.relayWithSyncFee = exports.relayWithUserSignature = void 0; | ||
var userAuthCall_1 = require("./userAuthCall"); | ||
@@ -10,1 +10,3 @@ Object.defineProperty(exports, "relayWithUserSignature", { enumerable: true, get: function () { return userAuthCall_1.relayWithUserSignature; } }); | ||
Object.defineProperty(exports, "PaymentType", { enumerable: true, get: function () { return types_1.PaymentType; } }); | ||
var sponsorAuthCall_1 = require("./sponsorAuthCall"); | ||
Object.defineProperty(exports, "generateSponsorSignature", { enumerable: true, get: function () { return sponsorAuthCall_1.generateSponsorSignature; } }); |
import { BigNumberish } from "ethers"; | ||
export declare enum RelayContract { | ||
GelatoRelay = "GelatoRelay", | ||
GelatoRelayWithTransferFrom = "GelatoRelayWithTransferFrom" | ||
} | ||
export declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | ||
@@ -3,0 +7,0 @@ export declare enum PaymentType { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PaymentType = void 0; | ||
exports.PaymentType = exports.RelayContract = void 0; | ||
var RelayContract; | ||
(function (RelayContract) { | ||
RelayContract["GelatoRelay"] = "GelatoRelay"; | ||
RelayContract["GelatoRelayWithTransferFrom"] = "GelatoRelayWithTransferFrom"; | ||
})(RelayContract = exports.RelayContract || (exports.RelayContract = {})); | ||
var PaymentType; | ||
@@ -5,0 +10,0 @@ (function (PaymentType) { |
@@ -21,7 +21,5 @@ "use strict"; | ||
const types_1 = require("../../types"); | ||
const getFeeToken_1 = require("../../../utils/getFeeToken"); | ||
const types_2 = require("./types"); | ||
const getPayloadToSign = (struct) => { | ||
const verifyingContract = (0, constants_1.getRelayAddress)(struct.chainId); | ||
const domain = (0, utils_2.getEIP712Domain)("GelatoRelay", "1", struct.chainId, verifyingContract); | ||
const domain = (0, utils_2.getEIP712Domain)(struct.chainId, types_1.RelayContract.GelatoRelay); | ||
return { | ||
@@ -52,3 +50,3 @@ domain, | ||
paymentType: types_1.PaymentType.OneBalance, | ||
feeToken: yield (0, getFeeToken_1.getFeeToken)(request.chainId, request.user), | ||
feeToken: (0, utils_1.getAddress)(yield (0, utils_2.getFeeToken)(request.chainId, request.user)), | ||
oneBalanceChainId: request.oneBalanceChainId, | ||
@@ -58,3 +56,2 @@ }; | ||
const post = (request) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _c; | ||
try { | ||
@@ -65,19 +62,8 @@ const response = yield axios_1.default.post(`${constants_1.GELATO_RELAY_URL}/relays/v2/user-auth-call`, request); | ||
catch (error) { | ||
const errorMessage = (_c = error.message) !== null && _c !== void 0 ? _c : String(error); | ||
throw new Error(`GelatoRelaySDK/userAuthCall/1balance/post: Failed with error: ${errorMessage}`); | ||
throw new Error((0, utils_2.getHttpErrorMessage)(error)); | ||
} | ||
}); | ||
const populateOptionalParameters = (request, provider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const parametersToOverride = {}; | ||
if (!request.userDeadline) { | ||
parametersToOverride.userDeadline = (0, utils_2.calculateDeadline)(constants_1.DEFAULT_DEADLINE_GAP); | ||
} | ||
if (!request.userNonce) { | ||
parametersToOverride.userNonce = (yield (0, utils_2.getUserNonce)(request.chainId, request.user, provider)).toNumber(); | ||
} | ||
return parametersToOverride; | ||
}); | ||
const userAuthCallWith1Balance = (request, provider, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const parametersToOverride = yield populateOptionalParameters(request, provider); | ||
const parametersToOverride = yield (0, utils_2.populateOptionalUserParameters)(request, provider); | ||
const struct = yield mapRequestToStruct(request, parametersToOverride); | ||
@@ -84,0 +70,0 @@ const signature = yield (0, utils_2.signTypedDataV4)(provider, request.user, JSON.stringify(getPayloadToSign(struct))); |
@@ -23,4 +23,3 @@ "use strict"; | ||
const getPayloadToSign = (struct) => { | ||
const verifyingContract = (0, constants_1.getRelayAddress)(struct.chainId); | ||
const domain = (0, utils_2.getEIP712Domain)("GelatoRelayWithTransferFrom", "1", struct.chainId, verifyingContract); | ||
const domain = (0, utils_2.getEIP712Domain)(struct.chainId, types_1.RelayContract.GelatoRelayWithTransferFrom); | ||
return { | ||
@@ -56,3 +55,2 @@ domain, | ||
const post = (request) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a, _b, _c, _d; | ||
try { | ||
@@ -63,19 +61,8 @@ const response = yield axios_1.default.post(`${constants_1.GELATO_RELAY_URL}/relays/v2/user-auth-call`, request); | ||
catch (error) { | ||
const defaultErrorMessage = (_a = error.message) !== null && _a !== void 0 ? _a : String(error); | ||
throw new Error((_d = (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : defaultErrorMessage); | ||
throw new Error((0, utils_2.getHttpErrorMessage)(error)); | ||
} | ||
}); | ||
const populateOptionalParameters = (request, provider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const parametersToOverride = {}; | ||
if (!request.userDeadline) { | ||
parametersToOverride.userDeadline = (0, utils_2.calculateDeadline)(constants_1.DEFAULT_DEADLINE_GAP); | ||
} | ||
if (!request.userNonce) { | ||
parametersToOverride.userNonce = (yield (0, utils_2.getUserNonce)(request.chainId, request.user, provider)).toNumber(); | ||
} | ||
return parametersToOverride; | ||
}); | ||
const userAuthCallWithTransferFrom = (request, provider, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const parametersToOverride = yield populateOptionalParameters(request, provider); | ||
const parametersToOverride = yield (0, utils_2.populateOptionalUserParameters)(request, provider); | ||
const struct = mapRequestToStruct(request, parametersToOverride); | ||
@@ -88,5 +75,5 @@ const signature = yield (0, utils_2.signTypedDataV4)(provider, request.user, JSON.stringify(getPayloadToSign(struct))); | ||
const errorMessage = error.message; | ||
throw new Error(`GelatoRelaySDK/userAuthCall/transferFrom: ${errorMessage}`); | ||
throw new Error(`GelatoRelaySDK/userAuthCall/transferFrom: Failed with error: ${errorMessage}`); | ||
} | ||
}); | ||
exports.userAuthCallWithTransferFrom = userAuthCallWithTransferFrom; |
@@ -1,2 +0,2 @@ | ||
import { EIP712Domain } from "../lib/types"; | ||
export declare const getEIP712Domain: (name: string, version: string, chainId: number, verifyingContract: string) => EIP712Domain; | ||
import { EIP712Domain, RelayContract } from "../lib/types"; | ||
export declare const getEIP712Domain: (chainId: number, relayContract: RelayContract) => EIP712Domain; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEIP712Domain = void 0; | ||
const getEIP712Domain = (name, version, chainId, verifyingContract) => { | ||
return { | ||
name, | ||
version, | ||
chainId, | ||
verifyingContract, | ||
}; | ||
const constants_1 = require("../constants"); | ||
const types_1 = require("../lib/types"); | ||
const getEIP712Domain = (chainId, relayContract) => { | ||
switch (relayContract) { | ||
case types_1.RelayContract.GelatoRelay: | ||
return { | ||
name: "GelatoRelay", | ||
version: "1", | ||
chainId, | ||
verifyingContract: (0, constants_1.getRelayAddress)(chainId), | ||
}; | ||
case types_1.RelayContract.GelatoRelayWithTransferFrom: | ||
return { | ||
name: "GelatoRelayWithTransferFrom", | ||
version: "1", | ||
chainId, | ||
verifyingContract: (0, constants_1.getRelayWithTransferFromAddress)(chainId), | ||
}; | ||
default: { | ||
const _exhaustiveCheck = relayContract; | ||
return _exhaustiveCheck; | ||
} | ||
} | ||
}; | ||
exports.getEIP712Domain = getEIP712Domain; |
@@ -1,2 +0,2 @@ | ||
import { providers } from "ethers"; | ||
export declare const getUserNonce: (chainId: number, account: string, provider: providers.Web3Provider) => Promise<any>; | ||
import { ethers, providers } from "ethers"; | ||
export declare const getUserNonce: (chainId: number, account: string, provider: providers.Web3Provider | ethers.providers.Provider) => Promise<any>; |
@@ -16,5 +16,5 @@ "use strict"; | ||
const getUserNonce = (chainId, account, provider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const contract = new ethers_1.ethers.Contract((0, constants_1.getRelayAddress)(chainId), constants_1.ABI, provider); | ||
const contract = new ethers_1.ethers.Contract((0, constants_1.getRelayAddress)(chainId), constants_1.USER_NONCE_ABI, provider); | ||
return yield contract.userNonce(account); | ||
}); | ||
exports.getUserNonce = getUserNonce; |
@@ -6,1 +6,3 @@ export * from "./signTypedDataV4"; | ||
export * from "./getFeeToken"; | ||
export * from "./getHttpErrorMessage"; | ||
export * from "./populateOptionalUserParameters"; |
@@ -18,1 +18,3 @@ "use strict"; | ||
__exportStar(require("./getFeeToken"), exports); | ||
__exportStar(require("./getHttpErrorMessage"), exports); | ||
__exportStar(require("./populateOptionalUserParameters"), exports); |
{ | ||
"name": "@gelatonetwork/relay-sdk", | ||
"version": "1.0.1-beta", | ||
"version": "1.0.1-beta.0", | ||
"description": "SDK to integrate with Gelato Relay", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61691
66
1165