UNPKG

@f5i23q999d/cow-sdk

Version:

<p align="center"> <img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" /> </p>

75 lines 3.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWeirollLibrary = exports.createWeirollContract = exports.createWeirollDelegateCall = exports.WeirollCommandFlags = exports.WeirollPlanner = exports.WeirollContract = void 0; const weiroll_js_1 = require("@weiroll/weiroll.js"); const abi_1 = require("@ethersproject/abi"); var weiroll_js_2 = require("@weiroll/weiroll.js"); Object.defineProperty(exports, "WeirollContract", { enumerable: true, get: function () { return weiroll_js_2.Contract; } }); Object.defineProperty(exports, "WeirollPlanner", { enumerable: true, get: function () { return weiroll_js_2.Planner; } }); var WeirollCommandFlags; (function (WeirollCommandFlags) { WeirollCommandFlags[WeirollCommandFlags["DELEGATECALL"] = 0] = "DELEGATECALL"; WeirollCommandFlags[WeirollCommandFlags["CALL"] = 1] = "CALL"; WeirollCommandFlags[WeirollCommandFlags["STATICCALL"] = 2] = "STATICCALL"; WeirollCommandFlags[WeirollCommandFlags["CALL_WITH_VALUE"] = 3] = "CALL_WITH_VALUE"; WeirollCommandFlags[WeirollCommandFlags["CALLTYPE_MASK"] = 3] = "CALLTYPE_MASK"; WeirollCommandFlags[WeirollCommandFlags["EXTENDED_COMMAND"] = 64] = "EXTENDED_COMMAND"; WeirollCommandFlags[WeirollCommandFlags["TUPLE_RETURN"] = 128] = "TUPLE_RETURN"; })(WeirollCommandFlags = exports.WeirollCommandFlags || (exports.WeirollCommandFlags = {})); const WEIROLL_ADDRESS = '0x9585c3062Df1C247d5E373Cfca9167F7dC2b5963'; const WEIROLL_ABI = [ { inputs: [ { internalType: 'uint256', name: 'command_index', type: 'uint256' }, { internalType: 'address', name: 'target', type: 'address' }, { internalType: 'string', name: 'message', type: 'string' }, ], name: 'ExecutionFailed', type: 'error', }, { inputs: [ { internalType: 'bytes32[]', name: 'commands', type: 'bytes32[]' }, { internalType: 'bytes[]', name: 'state', type: 'bytes[]' }, ], name: 'execute', outputs: [{ internalType: 'bytes[]', name: '', type: 'bytes[]' }], stateMutability: 'payable', type: 'function', }, ]; function getWeirollCalldata(planner) { const planResult = planner.plan(); const { commands, state } = planResult; const weirollInterface = new abi_1.Interface(WEIROLL_ABI); return weirollInterface.encodeFunctionData('execute', [commands, state]); } /** * Create a weiroll transaction * * @param addToPlanner - A function that adds the commands to the planner * * @returns An EVM call */ function createWeirollDelegateCall(addToPlanner) { // Create a new planner const planner = new weiroll_js_1.Planner(); // Add the commands to the planner addToPlanner(planner); // Get the EVM call return { to: WEIROLL_ADDRESS, value: BigInt(0), data: getWeirollCalldata(planner), }; } exports.createWeirollDelegateCall = createWeirollDelegateCall; function createWeirollContract(contract, commandflags) { return weiroll_js_1.Contract.createContract(contract, commandflags); } exports.createWeirollContract = createWeirollContract; function createWeirollLibrary(contract) { return weiroll_js_1.Contract.createLibrary(contract); } exports.createWeirollLibrary = createWeirollLibrary; //# sourceMappingURL=index.js.map