@f5i23q999d/cow-sdk
Version:
<p align="center"> <img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" /> </p>
58 lines • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformOrder = void 0;
const contracts_1 = require("../common/consts/contracts.js");
/**
* Apply programmatic transformations to an order.
*
* For example, transformations may be applied to an order to recognise it as a Native EthFlow order.
* @param order to apply transformations to
* @returns An order with the total fee added.
*/
function transformOrder(order) {
return transformEthFlowOrder(addTotalFeeToOrder(order));
}
exports.transformOrder = transformOrder;
/**
* Add the total fee to the order.
*
* The total fee of the order will be represented by the `totalFee` field, which is the sum of `executedFee`
* and `executedFeeAmount`.
*
* Note that either `executedFee` or `executedFeeAmount` may be `0`, or both might have a non `0` value.
*
* See https://cowservices.slack.com/archives/C036G0J90BU/p1705322037866779?thread_ts=1705083817.684659&cid=C036G0J90BU
*
* @param dto The order to add the total fee to.
* @returns The order with the total fee added.
*/
function addTotalFeeToOrder(dto) {
const { executedFeeAmount, executedFee } = dto;
const _executedFeeAmount = BigInt(executedFeeAmount || '0');
const _executedFee = BigInt(executedFee || '0');
const totalFee = String(_executedFeeAmount + _executedFee);
return {
...dto,
totalFee,
};
}
/**
* Transform order field for Native EthFlow orders
*
* A no-op for regular orders
* For Native EthFlow, due to how the contract is setup:
* - sellToken set to Native token address
* - owner set to `onchainUser`
* - validTo set to `ethflowData.userValidTo`
*/
function transformEthFlowOrder(order) {
const { ethflowData } = order;
if (!ethflowData) {
return order;
}
const { userValidTo: validTo } = ethflowData;
const owner = order.onchainUser || order.owner;
const sellToken = contracts_1.ETH_ADDRESS;
return { ...order, validTo, owner, sellToken };
}
//# sourceMappingURL=transformOrder.js.map