UNPKG

@tokenlon/contracts-lib

Version:

Common utility functions (e.g., signing order, encoding data) to interact with [Tokenlon contracts](https://github.com/consenlabs/tokenlon-contracts).

219 lines 9.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SigningHelper = void 0; const signing_1 = require("../signing"); class SigningHelper extends signing_1.SigningHelper { constructor() { super({ name: "Tokenlon", version: "v5", }); } /* AMM */ getAMMOrderEIP712Types() { return { tradeWithPermit: [ { name: "makerAddr", type: "address" }, { name: "takerAssetAddr", type: "address" }, { name: "makerAssetAddr", type: "address" }, { name: "takerAssetAmount", type: "uint256" }, { name: "makerAssetAmount", type: "uint256" }, { name: "userAddr", type: "address" }, { name: "receiverAddr", type: "address" }, { name: "salt", type: "uint256" }, { name: "deadline", type: "uint256" }, ], }; } getAMMOrderEIP712Digest(order, options) { return __awaiter(this, void 0, void 0, function* () { const domain = yield this.getEIP712Domain(options); const types = this.getAMMOrderEIP712Types(); return this.getEIP712Digest(domain, types, order); }); } getAMMOrderEIP712StructHash(order) { return this.getEIP712StructHash("tradeWithPermit", this.getAMMOrderEIP712Types(), order); } signAMMOrder(order, options) { return this.signEIP712(this.getAMMOrderEIP712Types(), order, options); } /* Limit Order */ getLimitOrderEIP712Types() { return { Order: [ { name: "makerToken", type: "address" }, { name: "takerToken", type: "address" }, { name: "makerTokenAmount", type: "uint256" }, { name: "takerTokenAmount", type: "uint256" }, { name: "maker", type: "address" }, { name: "taker", type: "address" }, { name: "salt", type: "uint256" }, { name: "expiry", type: "uint64" }, ], }; } getLimitOrderEIP712Digest(order, options) { return __awaiter(this, void 0, void 0, function* () { const domain = yield this.getEIP712Domain(options); const types = this.getLimitOrderEIP712Types(); return this.getEIP712Digest(domain, types, order); }); } getLimitOrderEIP712StructHash(order) { return this.getEIP712StructHash("Order", this.getLimitOrderEIP712Types(), order); } signLimitOrder(order, options) { return this.signEIP712(this.getLimitOrderEIP712Types(), order, options); } /* Limit Order - Fill */ getLimitOrderFillEIP712Types() { return { Fill: [ { name: "orderHash", type: "bytes32" }, { name: "taker", type: "address" }, { name: "recipient", type: "address" }, { name: "takerTokenAmount", type: "uint256" }, { name: "takerSalt", type: "uint256" }, { name: "expiry", type: "uint64" }, ], }; } getLimitOrderFillEIP712Digest(fill, options) { return __awaiter(this, void 0, void 0, function* () { const domain = yield this.getEIP712Domain(options); const types = this.getLimitOrderFillEIP712Types(); return this.getEIP712Digest(domain, types, fill); }); } getLimitOrderFillEIP712StructHash(fill) { return this.getEIP712StructHash("Fill", this.getLimitOrderFillEIP712Types(), fill); } signLimitOrderFill(fill, options) { return this.signEIP712(this.getLimitOrderFillEIP712Types(), fill, options); } /* Limit Order - Allow Fill */ getLimitOrderAllowFillEIP712Types() { return { AllowFill: [ { name: "orderHash", type: "bytes32" }, { name: "executor", type: "address" }, { name: "fillAmount", type: "uint256" }, { name: "salt", type: "uint256" }, { name: "expiry", type: "uint64" }, ], }; } getLimitOrderAllowFillEIP712Digest(allowFill, options) { return __awaiter(this, void 0, void 0, function* () { const domain = yield this.getEIP712Domain(options); const types = this.getLimitOrderAllowFillEIP712Types(); return this.getEIP712Digest(domain, types, allowFill); }); } getLimitOrderAllowFillEIP712StructHash(allowFill) { return this.getEIP712StructHash("AllowFill", this.getLimitOrderAllowFillEIP712Types(), allowFill); } signLimitOrderAllowFill(allowFill, options) { return this.signEIP712(this.getLimitOrderAllowFillEIP712Types(), allowFill, options); } /* RFQ - Order (for maker) */ getRFQOrderEIP712Types() { return { Order: [ { name: "takerAddr", type: "address" }, { name: "makerAddr", type: "address" }, { name: "takerAssetAddr", type: "address" }, { name: "makerAssetAddr", type: "address" }, { name: "takerAssetAmount", type: "uint256" }, { name: "makerAssetAmount", type: "uint256" }, { name: "salt", type: "uint256" }, { name: "deadline", type: "uint256" }, { name: "feeFactor", type: "uint256" }, ], }; } getRFQOrderEIP712Digest(order, options) { return __awaiter(this, void 0, void 0, function* () { const domain = yield this.getEIP712Domain(options); const types = this.getRFQOrderEIP712Types(); return this.getEIP712Digest(domain, types, order); }); } getRFQOrderEIP712StructHash(order) { return this.getEIP712StructHash("Order", this.getRFQOrderEIP712Types(), order); } signRFQOrder(order, options) { return this.signEIP712(this.getRFQOrderEIP712Types(), order, options); } /* RFQ - Fill (for taker) */ getRFQFillEIP712Types() { return { fillWithPermit: [ { name: "makerAddr", type: "address" }, { name: "takerAssetAddr", type: "address" }, { name: "makerAssetAddr", type: "address" }, { name: "takerAssetAmount", type: "uint256" }, { name: "makerAssetAmount", type: "uint256" }, { name: "takerAddr", type: "address" }, { name: "receiverAddr", type: "address" }, { name: "salt", type: "uint256" }, { name: "deadline", type: "uint256" }, { name: "feeFactor", type: "uint256" }, ], }; } getRFQFillEIP712Digest(fill, options) { return __awaiter(this, void 0, void 0, function* () { const domain = yield this.getEIP712Domain(options); const types = this.getRFQFillEIP712Types(); return this.getEIP712Digest(domain, types, fill); }); } getRFQFillEIP712StructHash(order) { return this.getEIP712StructHash("fillWithPermit", this.getRFQFillEIP712Types(), order); } signRFQFillOrder(fill, options) { return this.signEIP712(this.getRFQFillEIP712Types(), fill, options); } /* L2 Deposit */ getL2DepositEIP712Types() { return { Deposit: [ { name: "l2Identifier", type: "uint8" }, { name: "l1TokenAddr", type: "address" }, { name: "l2TokenAddr", type: "address" }, { name: "sender", type: "address" }, { name: "recipient", type: "address" }, { name: "amount", type: "uint256" }, { name: "salt", type: "uint256" }, { name: "expiry", type: "uint256" }, { name: "data", type: "bytes" }, ], }; } getL2DepositEIP712Digest(deposit, options) { return __awaiter(this, void 0, void 0, function* () { const domain = yield this.getEIP712Domain(options); const types = this.getL2DepositEIP712Types(); return this.getEIP712Digest(domain, types, deposit); }); } getL2DepositEIP712StructHash(deposit) { return this.getEIP712StructHash("Deposit", this.getL2DepositEIP712Types(), deposit); } signL2Deposit(deposit, options) { return this.signEIP712(this.getL2DepositEIP712Types(), deposit, options); } } exports.SigningHelper = SigningHelper; //# sourceMappingURL=signing.js.map