Version not found. Please check the version and try again.
@velora-dex/sdk 9.5.2-dev.0 → 9.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/methods/delta/deltaTokenModule.d.ts +0 -1
- package/dist/methods/delta/deltaTokenModule.d.ts.map +1 -1
- package/dist/methods/delta/helpers/types.d.ts +5 -54
- package/dist/methods/delta/helpers/types.d.ts.map +1 -1
- package/dist/sdk.cjs.development.js +70 -569
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +71 -569
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +0 -17
- package/src/methods/delta/deltaTokenModule.ts +80 -128
- package/src/methods/delta/helpers/types.ts +7 -73
- package/dist/methods/delta/helpers/orders.d.ts +0 -248
- package/dist/methods/delta/helpers/orders.d.ts.map +0 -1
- package/src/constants.js +0 -3
- package/src/gas.js +0 -1
- package/src/index.js +0 -73
- package/src/methods/delta/helpers/orders.ts +0 -648
- package/src/types.js +0 -1
|
@@ -5629,112 +5629,86 @@ var DeltaTokenModuleAbi = [{
|
|
|
5629
5629
|
type: 'function',
|
|
5630
5630
|
name: 'cancelAndWithdraw',
|
|
5631
5631
|
inputs: [{
|
|
5632
|
-
name: '
|
|
5632
|
+
name: 'order',
|
|
5633
5633
|
type: 'tuple',
|
|
5634
|
-
internalType: 'struct
|
|
5634
|
+
internalType: 'struct Order',
|
|
5635
5635
|
components: [{
|
|
5636
|
-
name: '
|
|
5637
|
-
type: '
|
|
5638
|
-
internalType: '
|
|
5639
|
-
components: [{
|
|
5640
|
-
name: 'owner',
|
|
5641
|
-
type: 'address',
|
|
5642
|
-
internalType: 'address'
|
|
5643
|
-
}, {
|
|
5644
|
-
name: 'beneficiary',
|
|
5645
|
-
type: 'address',
|
|
5646
|
-
internalType: 'address'
|
|
5647
|
-
}, {
|
|
5648
|
-
name: 'srcToken',
|
|
5649
|
-
type: 'address',
|
|
5650
|
-
internalType: 'address'
|
|
5651
|
-
}, {
|
|
5652
|
-
name: 'destToken',
|
|
5653
|
-
type: 'address',
|
|
5654
|
-
internalType: 'address'
|
|
5655
|
-
}, {
|
|
5656
|
-
name: 'srcAmount',
|
|
5657
|
-
type: 'uint256',
|
|
5658
|
-
internalType: 'uint256'
|
|
5659
|
-
}, {
|
|
5660
|
-
name: 'destAmount',
|
|
5661
|
-
type: 'uint256',
|
|
5662
|
-
internalType: 'uint256'
|
|
5663
|
-
}, {
|
|
5664
|
-
name: 'expectedAmount',
|
|
5665
|
-
type: 'uint256',
|
|
5666
|
-
internalType: 'uint256'
|
|
5667
|
-
}, {
|
|
5668
|
-
name: 'deadline',
|
|
5669
|
-
type: 'uint256',
|
|
5670
|
-
internalType: 'uint256'
|
|
5671
|
-
}, {
|
|
5672
|
-
name: 'kind',
|
|
5673
|
-
type: 'uint8',
|
|
5674
|
-
internalType: 'enum OrderKind'
|
|
5675
|
-
}, {
|
|
5676
|
-
name: 'nonce',
|
|
5677
|
-
type: 'uint256',
|
|
5678
|
-
internalType: 'uint256'
|
|
5679
|
-
}, {
|
|
5680
|
-
name: 'partnerAndFee',
|
|
5681
|
-
type: 'uint256',
|
|
5682
|
-
internalType: 'uint256'
|
|
5683
|
-
}, {
|
|
5684
|
-
name: 'permit',
|
|
5685
|
-
type: 'bytes',
|
|
5686
|
-
internalType: 'bytes'
|
|
5687
|
-
}, {
|
|
5688
|
-
name: 'metadata',
|
|
5689
|
-
type: 'bytes',
|
|
5690
|
-
internalType: 'bytes'
|
|
5691
|
-
}, {
|
|
5692
|
-
name: 'bridge',
|
|
5693
|
-
type: 'tuple',
|
|
5694
|
-
internalType: 'struct Bridge',
|
|
5695
|
-
components: [{
|
|
5696
|
-
name: 'protocolSelector',
|
|
5697
|
-
type: 'bytes4',
|
|
5698
|
-
internalType: 'bytes4'
|
|
5699
|
-
}, {
|
|
5700
|
-
name: 'destinationChainId',
|
|
5701
|
-
type: 'uint256',
|
|
5702
|
-
internalType: 'uint256'
|
|
5703
|
-
}, {
|
|
5704
|
-
name: 'outputToken',
|
|
5705
|
-
type: 'address',
|
|
5706
|
-
internalType: 'address'
|
|
5707
|
-
}, {
|
|
5708
|
-
name: 'scalingFactor',
|
|
5709
|
-
type: 'int8',
|
|
5710
|
-
internalType: 'int8'
|
|
5711
|
-
}, {
|
|
5712
|
-
name: 'protocolData',
|
|
5713
|
-
type: 'bytes',
|
|
5714
|
-
internalType: 'bytes'
|
|
5715
|
-
}]
|
|
5716
|
-
}]
|
|
5636
|
+
name: 'owner',
|
|
5637
|
+
type: 'address',
|
|
5638
|
+
internalType: 'address'
|
|
5717
5639
|
}, {
|
|
5718
|
-
name: '
|
|
5640
|
+
name: 'beneficiary',
|
|
5641
|
+
type: 'address',
|
|
5642
|
+
internalType: 'address'
|
|
5643
|
+
}, {
|
|
5644
|
+
name: 'srcToken',
|
|
5645
|
+
type: 'address',
|
|
5646
|
+
internalType: 'address'
|
|
5647
|
+
}, {
|
|
5648
|
+
name: 'destToken',
|
|
5649
|
+
type: 'address',
|
|
5650
|
+
internalType: 'address'
|
|
5651
|
+
}, {
|
|
5652
|
+
name: 'srcAmount',
|
|
5653
|
+
type: 'uint256',
|
|
5654
|
+
internalType: 'uint256'
|
|
5655
|
+
}, {
|
|
5656
|
+
name: 'destAmount',
|
|
5657
|
+
type: 'uint256',
|
|
5658
|
+
internalType: 'uint256'
|
|
5659
|
+
}, {
|
|
5660
|
+
name: 'expectedAmount',
|
|
5661
|
+
type: 'uint256',
|
|
5662
|
+
internalType: 'uint256'
|
|
5663
|
+
}, {
|
|
5664
|
+
name: 'deadline',
|
|
5665
|
+
type: 'uint256',
|
|
5666
|
+
internalType: 'uint256'
|
|
5667
|
+
}, {
|
|
5668
|
+
name: 'kind',
|
|
5669
|
+
type: 'uint8',
|
|
5670
|
+
internalType: 'enum OrderKind'
|
|
5671
|
+
}, {
|
|
5672
|
+
name: 'nonce',
|
|
5673
|
+
type: 'uint256',
|
|
5674
|
+
internalType: 'uint256'
|
|
5675
|
+
}, {
|
|
5676
|
+
name: 'partnerAndFee',
|
|
5677
|
+
type: 'uint256',
|
|
5678
|
+
internalType: 'uint256'
|
|
5679
|
+
}, {
|
|
5680
|
+
name: 'permit',
|
|
5719
5681
|
type: 'bytes',
|
|
5720
5682
|
internalType: 'bytes'
|
|
5721
5683
|
}, {
|
|
5722
|
-
name: '
|
|
5684
|
+
name: 'metadata',
|
|
5685
|
+
type: 'bytes',
|
|
5686
|
+
internalType: 'bytes'
|
|
5687
|
+
}, {
|
|
5688
|
+
name: 'bridge',
|
|
5723
5689
|
type: 'tuple',
|
|
5724
|
-
internalType: 'struct
|
|
5690
|
+
internalType: 'struct Bridge',
|
|
5725
5691
|
components: [{
|
|
5726
5692
|
name: 'protocolSelector',
|
|
5727
5693
|
type: 'bytes4',
|
|
5728
5694
|
internalType: 'bytes4'
|
|
5695
|
+
}, {
|
|
5696
|
+
name: 'destinationChainId',
|
|
5697
|
+
type: 'uint256',
|
|
5698
|
+
internalType: 'uint256'
|
|
5699
|
+
}, {
|
|
5700
|
+
name: 'outputToken',
|
|
5701
|
+
type: 'address',
|
|
5702
|
+
internalType: 'address'
|
|
5703
|
+
}, {
|
|
5704
|
+
name: 'scalingFactor',
|
|
5705
|
+
type: 'int8',
|
|
5706
|
+
internalType: 'int8'
|
|
5729
5707
|
}, {
|
|
5730
5708
|
name: 'protocolData',
|
|
5731
5709
|
type: 'bytes',
|
|
5732
5710
|
internalType: 'bytes'
|
|
5733
5711
|
}]
|
|
5734
|
-
}, {
|
|
5735
|
-
name: 'cosignature',
|
|
5736
|
-
type: 'bytes',
|
|
5737
|
-
internalType: 'bytes'
|
|
5738
5712
|
}]
|
|
5739
5713
|
}, {
|
|
5740
5714
|
name: 'isFillable',
|
|
@@ -5948,11 +5922,11 @@ var constructDeltaTokenModule = function constructDeltaTokenModule(options) {
|
|
|
5948
5922
|
getDeltaContract = _constructGetDeltaCon.getDeltaContract;
|
|
5949
5923
|
var cancelAndWithdrawDeltaOrder = /*#__PURE__*/function () {
|
|
5950
5924
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, overrides, requestParams) {
|
|
5951
|
-
var order,
|
|
5925
|
+
var order, _ref$isFillable, isFillable, ParaswapDelta, res;
|
|
5952
5926
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
5953
5927
|
while (1) switch (_context.prev = _context.next) {
|
|
5954
5928
|
case 0:
|
|
5955
|
-
order = _ref.order,
|
|
5929
|
+
order = _ref.order, _ref$isFillable = _ref.isFillable, isFillable = _ref$isFillable === void 0 ? false : _ref$isFillable;
|
|
5956
5930
|
if (overrides === void 0) {
|
|
5957
5931
|
overrides = {};
|
|
5958
5932
|
}
|
|
@@ -5966,29 +5940,18 @@ var constructDeltaTokenModule = function constructDeltaTokenModule(options) {
|
|
|
5966
5940
|
}
|
|
5967
5941
|
throw new Error("Delta is not available on chain " + options.chainId);
|
|
5968
5942
|
case 7:
|
|
5969
|
-
|
|
5970
|
-
order: sanitizeDeltaOrderData(order),
|
|
5971
|
-
signature: signature,
|
|
5972
|
-
// bridgeOverride and cosignature are not used by the contract,
|
|
5973
|
-
// can always provide defaults
|
|
5974
|
-
bridgeOverride: {
|
|
5975
|
-
protocolData: DEFAULT_BRIDGE.protocolData,
|
|
5976
|
-
protocolSelector: DEFAULT_BRIDGE.protocolSelector
|
|
5977
|
-
},
|
|
5978
|
-
cosignature: '0x'
|
|
5979
|
-
};
|
|
5980
|
-
_context.next = 10;
|
|
5943
|
+
_context.next = 9;
|
|
5981
5944
|
return options.contractCaller.transactCall({
|
|
5982
5945
|
address: ParaswapDelta,
|
|
5983
5946
|
abi: DeltaTokenModuleAbi,
|
|
5984
5947
|
contractMethod: 'cancelAndWithdraw',
|
|
5985
|
-
args: [
|
|
5948
|
+
args: [sanitizeDeltaOrderData(order), isFillable],
|
|
5986
5949
|
overrides: overrides
|
|
5987
5950
|
});
|
|
5988
|
-
case
|
|
5951
|
+
case 9:
|
|
5989
5952
|
res = _context.sent;
|
|
5990
5953
|
return _context.abrupt("return", res);
|
|
5991
|
-
case
|
|
5954
|
+
case 11:
|
|
5992
5955
|
case "end":
|
|
5993
5956
|
return _context.stop();
|
|
5994
5957
|
}
|
|
@@ -6837,467 +6800,6 @@ function constructSimpleContractCaller(providerOptions) {
|
|
|
6837
6800
|
};
|
|
6838
6801
|
}
|
|
6839
6802
|
|
|
6840
|
-
var _OrderKindToSwapSide;
|
|
6841
|
-
///// CHECKS //////
|
|
6842
|
-
/**
|
|
6843
|
-
* @description Checks whether an order is a TWAP Sell or TWAP Buy order.
|
|
6844
|
-
*/
|
|
6845
|
-
function isTWAPOrder(order) {
|
|
6846
|
-
return 'numSlices' in order && typeof order.numSlices === 'number';
|
|
6847
|
-
}
|
|
6848
|
-
/**
|
|
6849
|
-
* @description Checks whether an order is a TWAP Sell order.
|
|
6850
|
-
*/
|
|
6851
|
-
function isTWAPSellOrder(order) {
|
|
6852
|
-
return isTWAPOrder(order) && 'totalSrcAmount' in order && typeof order.totalSrcAmount === 'string';
|
|
6853
|
-
}
|
|
6854
|
-
/**
|
|
6855
|
-
* @description Checks whether an order is a TWAP Buy order.
|
|
6856
|
-
*/
|
|
6857
|
-
function isTWAPBuyOrder(order) {
|
|
6858
|
-
return isTWAPOrder(order) && 'totalDestAmount' in order && typeof order.totalDestAmount === 'string';
|
|
6859
|
-
}
|
|
6860
|
-
/**
|
|
6861
|
-
* @description Checks whether an order is an External order.
|
|
6862
|
-
*/
|
|
6863
|
-
function isExternalOrder(order) {
|
|
6864
|
-
return 'handler' in order;
|
|
6865
|
-
}
|
|
6866
|
-
/**
|
|
6867
|
-
* @description Checks whether an order is a regular Delta auction order.
|
|
6868
|
-
*/
|
|
6869
|
-
function isDeltaOrder(order) {
|
|
6870
|
-
return !isExternalOrder(order) && 'kind' in order && typeof order.kind === 'number';
|
|
6871
|
-
}
|
|
6872
|
-
/**
|
|
6873
|
-
* @description Checks whether an auction is a TWAP auction.
|
|
6874
|
-
*/
|
|
6875
|
-
function isTWAPAuction(auction) {
|
|
6876
|
-
return isTWAPSellAuction(auction) || isTWAPBuyAuction(auction);
|
|
6877
|
-
}
|
|
6878
|
-
/**
|
|
6879
|
-
* @description Checks whether an auction is a TWAP Sell auction.
|
|
6880
|
-
*/
|
|
6881
|
-
function isTWAPSellAuction(auction) {
|
|
6882
|
-
return auction.onChainOrderType === 'TWAPOrder';
|
|
6883
|
-
}
|
|
6884
|
-
/**
|
|
6885
|
-
* @description Checks whether an auction is a TWAP Buy auction.
|
|
6886
|
-
*/
|
|
6887
|
-
function isTWAPBuyAuction(auction) {
|
|
6888
|
-
return auction.onChainOrderType === 'TWAPBuyOrder';
|
|
6889
|
-
}
|
|
6890
|
-
/**
|
|
6891
|
-
* @description Checks whether an auction is a Delta auction.
|
|
6892
|
-
*/
|
|
6893
|
-
function isDeltaAuction(auction) {
|
|
6894
|
-
return auction.onChainOrderType === 'Order';
|
|
6895
|
-
}
|
|
6896
|
-
/**
|
|
6897
|
-
* @description Checks whether an auction is an External auction.
|
|
6898
|
-
*/
|
|
6899
|
-
function isExternalAuction(auction) {
|
|
6900
|
-
return auction.onChainOrderType === 'ExternalOrder';
|
|
6901
|
-
}
|
|
6902
|
-
var checks = {
|
|
6903
|
-
isTWAPOrder: isTWAPOrder,
|
|
6904
|
-
isTWAPSellOrder: isTWAPSellOrder,
|
|
6905
|
-
isTWAPBuyOrder: isTWAPBuyOrder,
|
|
6906
|
-
isExternalOrder: isExternalOrder,
|
|
6907
|
-
isDeltaOrder: isDeltaOrder,
|
|
6908
|
-
isTWAPAuction: isTWAPAuction,
|
|
6909
|
-
isTWAPSellAuction: isTWAPSellAuction,
|
|
6910
|
-
isTWAPBuyAuction: isTWAPBuyAuction,
|
|
6911
|
-
isDeltaAuction: isDeltaAuction,
|
|
6912
|
-
isExternalAuction: isExternalAuction,
|
|
6913
|
-
isOrderCrosschain: isOrderCrosschain,
|
|
6914
|
-
isExecutedAuction: isExecutedAuction,
|
|
6915
|
-
isPartiallyExecutedAuction: isPartiallyExecutedAuction,
|
|
6916
|
-
isFailedAuction: isFailedAuction,
|
|
6917
|
-
isCanceledAuction: isCanceledAuction,
|
|
6918
|
-
isExpiredAuction: isExpiredAuction,
|
|
6919
|
-
isPendingAuction: isPendingAuction
|
|
6920
|
-
};
|
|
6921
|
-
///// GETTERS //////
|
|
6922
|
-
/**
|
|
6923
|
-
* @description Returns the expected source amount for a TWAP order.
|
|
6924
|
-
*/
|
|
6925
|
-
function getExpectedTwapSrcAmount(order) {
|
|
6926
|
-
if ('totalSrcAmount' in order) {
|
|
6927
|
-
// SELL
|
|
6928
|
-
return order.totalSrcAmount;
|
|
6929
|
-
}
|
|
6930
|
-
return order.maxSrcAmount; // BUY
|
|
6931
|
-
}
|
|
6932
|
-
/**
|
|
6933
|
-
* @description Returns the expected destination amount for a TWAP order.
|
|
6934
|
-
*/
|
|
6935
|
-
function getExpectedTwapDestAmount(order) {
|
|
6936
|
-
var destAmount = 'destAmountPerSlice' in order ? BigInt(order.destAmountPerSlice) * BigInt(order.numSlices) // SELL
|
|
6937
|
-
: BigInt(order.totalDestAmount); // BUY
|
|
6938
|
-
if (isOrderCrosschain(order)) {
|
|
6939
|
-
return scaleByFactor(destAmount, order.bridge.scalingFactor).toString();
|
|
6940
|
-
}
|
|
6941
|
-
return destAmount.toString();
|
|
6942
|
-
}
|
|
6943
|
-
/**
|
|
6944
|
-
* @description Returns expected source and destination amounts for a TWAP order.
|
|
6945
|
-
*/
|
|
6946
|
-
function getExpectedTwapOrderAmounts(order) {
|
|
6947
|
-
var srcAmount = getExpectedTwapSrcAmount(order);
|
|
6948
|
-
var destAmount = getExpectedTwapDestAmount(order);
|
|
6949
|
-
return {
|
|
6950
|
-
srcAmount: srcAmount,
|
|
6951
|
-
destAmount: destAmount
|
|
6952
|
-
};
|
|
6953
|
-
}
|
|
6954
|
-
/**
|
|
6955
|
-
* @description Returns expected and, when available, final amounts for a TWAP auction.
|
|
6956
|
-
*/
|
|
6957
|
-
function getTwapAuctionAmounts(twapAuction) {
|
|
6958
|
-
var isExecuted = isExecutedAuction(twapAuction);
|
|
6959
|
-
var expected = getExpectedTwapOrderAmounts(twapAuction.order);
|
|
6960
|
-
if (isExecuted) {
|
|
6961
|
-
var _final = getTransactionAmounts(twapAuction.transactions);
|
|
6962
|
-
return {
|
|
6963
|
-
"final": _final,
|
|
6964
|
-
expected: expected
|
|
6965
|
-
};
|
|
6966
|
-
}
|
|
6967
|
-
return {
|
|
6968
|
-
expected: expected
|
|
6969
|
-
};
|
|
6970
|
-
}
|
|
6971
|
-
var getters = {
|
|
6972
|
-
getUnifiedDeltaOrderData: getUnifiedDeltaOrderData,
|
|
6973
|
-
getExpectedTwapSrcAmount: getExpectedTwapSrcAmount,
|
|
6974
|
-
getExpectedTwapDestAmount: getExpectedTwapDestAmount,
|
|
6975
|
-
getExpectedTwapOrderAmounts: getExpectedTwapOrderAmounts,
|
|
6976
|
-
getTwapAuctionAmounts: getTwapAuctionAmounts,
|
|
6977
|
-
getAuctionDestChainId: getAuctionDestChainId,
|
|
6978
|
-
getSwapSideFromDeltaOrder: getSwapSideFromDeltaOrder,
|
|
6979
|
-
getSwapSideFromTwapOrderType: getSwapSideFromTwapOrderType,
|
|
6980
|
-
getAuctionSwapSide: getAuctionSwapSide,
|
|
6981
|
-
getOrderTokenAddresses: getOrderTokenAddresses,
|
|
6982
|
-
getTransactionAmounts: getTransactionAmounts,
|
|
6983
|
-
getAuctionAmounts: getAuctionAmounts,
|
|
6984
|
-
getFilledPercent: getFilledPercent
|
|
6985
|
-
};
|
|
6986
|
-
var OrderHelpers = {
|
|
6987
|
-
checks: checks,
|
|
6988
|
-
getters: getters
|
|
6989
|
-
};
|
|
6990
|
-
// -------------------- Auction Unified Data --------------------
|
|
6991
|
-
/**
|
|
6992
|
-
* @description Returns the destination chain id for the auction.
|
|
6993
|
-
*/
|
|
6994
|
-
function getAuctionDestChainId(_ref) {
|
|
6995
|
-
var order = _ref.order,
|
|
6996
|
-
chainId = _ref.chainId;
|
|
6997
|
-
return isOrderCrosschain(order) ? order.bridge.destinationChainId : chainId;
|
|
6998
|
-
}
|
|
6999
|
-
var OrderKindToSwapSide = (_OrderKindToSwapSide = {}, _OrderKindToSwapSide[OrderKind.Sell] = 'SELL', _OrderKindToSwapSide[OrderKind.Buy] = 'BUY', _OrderKindToSwapSide);
|
|
7000
|
-
/**
|
|
7001
|
-
* @description Returns swap side from a Delta or External order kind.
|
|
7002
|
-
*/
|
|
7003
|
-
function getSwapSideFromDeltaOrder(order) {
|
|
7004
|
-
return OrderKindToSwapSide[order.kind];
|
|
7005
|
-
}
|
|
7006
|
-
var TwapTypeToSwapSide = {
|
|
7007
|
-
TWAPOrder: 'SELL',
|
|
7008
|
-
TWAPBuyOrder: 'BUY'
|
|
7009
|
-
};
|
|
7010
|
-
/**
|
|
7011
|
-
* @description Returns swap side from TWAP on-chain order type.
|
|
7012
|
-
*/
|
|
7013
|
-
function getSwapSideFromTwapOrderType(onChainOrderType) {
|
|
7014
|
-
return TwapTypeToSwapSide[onChainOrderType];
|
|
7015
|
-
}
|
|
7016
|
-
/**
|
|
7017
|
-
* @description Returns swap side for any auction type.
|
|
7018
|
-
*/
|
|
7019
|
-
function getAuctionSwapSide(auction) {
|
|
7020
|
-
if (isTWAPAuction(auction)) {
|
|
7021
|
-
// TWAP orders have onChainOrderType instead of kind
|
|
7022
|
-
return getSwapSideFromTwapOrderType(auction.onChainOrderType);
|
|
7023
|
-
}
|
|
7024
|
-
return getSwapSideFromDeltaOrder(auction.order);
|
|
7025
|
-
}
|
|
7026
|
-
/**
|
|
7027
|
-
* @description Returns unified order data with normalized amounts, tokens, and side.
|
|
7028
|
-
*/
|
|
7029
|
-
function getUnifiedDeltaOrderData(auction) {
|
|
7030
|
-
var order = auction.order,
|
|
7031
|
-
chainId = auction.chainId;
|
|
7032
|
-
var _getOrderTokenAddress = getOrderTokenAddresses(order),
|
|
7033
|
-
srcToken = _getOrderTokenAddress.srcToken,
|
|
7034
|
-
destToken = _getOrderTokenAddress.destToken;
|
|
7035
|
-
var _getAuctionAmounts = getAuctionAmounts(auction),
|
|
7036
|
-
expected = _getAuctionAmounts.expected,
|
|
7037
|
-
_final2 = _getAuctionAmounts["final"];
|
|
7038
|
-
var srcChainId = chainId;
|
|
7039
|
-
var destChainId = getAuctionDestChainId({
|
|
7040
|
-
order: order,
|
|
7041
|
-
chainId: chainId
|
|
7042
|
-
});
|
|
7043
|
-
var swapSide = getAuctionSwapSide(auction);
|
|
7044
|
-
var filledPercent = getFilledPercent(auction);
|
|
7045
|
-
return {
|
|
7046
|
-
srcChainId: srcChainId,
|
|
7047
|
-
destChainId: destChainId,
|
|
7048
|
-
srcAmount: (_final2 == null ? void 0 : _final2.srcAmount) || expected.srcAmount,
|
|
7049
|
-
destAmount: (_final2 == null ? void 0 : _final2.destAmount) || expected.destAmount,
|
|
7050
|
-
amounts: {
|
|
7051
|
-
expected: expected,
|
|
7052
|
-
"final": _final2
|
|
7053
|
-
},
|
|
7054
|
-
srcToken: srcToken,
|
|
7055
|
-
destToken: destToken,
|
|
7056
|
-
swapSide: swapSide,
|
|
7057
|
-
filledPercent: filledPercent
|
|
7058
|
-
};
|
|
7059
|
-
}
|
|
7060
|
-
/**
|
|
7061
|
-
* @description Returns source and destination token addresses for an order.
|
|
7062
|
-
*/
|
|
7063
|
-
function getOrderTokenAddresses(order) {
|
|
7064
|
-
var srcToken = order.srcToken;
|
|
7065
|
-
var destToken = isOrderCrosschain(order) ? order.bridge.outputToken : order.destToken;
|
|
7066
|
-
return {
|
|
7067
|
-
srcToken: srcToken,
|
|
7068
|
-
destToken: destToken
|
|
7069
|
-
};
|
|
7070
|
-
}
|
|
7071
|
-
/**
|
|
7072
|
-
* @description Aggregates transaction amounts into total source and destination values.
|
|
7073
|
-
*/
|
|
7074
|
-
function getTransactionAmounts(transactions) {
|
|
7075
|
-
var _transactions$reduce = transactions.reduce(function (acc, _ref2) {
|
|
7076
|
-
var spentAmount = _ref2.spentAmount,
|
|
7077
|
-
receivedAmount = _ref2.receivedAmount,
|
|
7078
|
-
bridgeMetadata = _ref2.bridgeMetadata;
|
|
7079
|
-
return {
|
|
7080
|
-
srcAmount: acc.srcAmount + BigInt(spentAmount),
|
|
7081
|
-
destAmount: acc.destAmount + BigInt(bridgeMetadata ? bridgeMetadata.outputAmount : receivedAmount)
|
|
7082
|
-
};
|
|
7083
|
-
}, {
|
|
7084
|
-
srcAmount: 0n,
|
|
7085
|
-
destAmount: 0n
|
|
7086
|
-
}),
|
|
7087
|
-
srcAmount = _transactions$reduce.srcAmount,
|
|
7088
|
-
destAmount = _transactions$reduce.destAmount;
|
|
7089
|
-
return {
|
|
7090
|
-
srcAmount: srcAmount.toString(),
|
|
7091
|
-
destAmount: destAmount.toString()
|
|
7092
|
-
};
|
|
7093
|
-
}
|
|
7094
|
-
/**
|
|
7095
|
-
* @description Returns expected and, when available, final amounts for an auction.
|
|
7096
|
-
*/
|
|
7097
|
-
function getAuctionAmounts(auction) {
|
|
7098
|
-
var isTwap = checks.isTWAPAuction(auction);
|
|
7099
|
-
if (isTwap) {
|
|
7100
|
-
return getTwapAuctionAmounts(auction);
|
|
7101
|
-
}
|
|
7102
|
-
var expected = {
|
|
7103
|
-
srcAmount: auction.order.srcAmount,
|
|
7104
|
-
destAmount: auction.order.expectedAmount || auction.order.destAmount
|
|
7105
|
-
};
|
|
7106
|
-
var order = auction.order;
|
|
7107
|
-
if (isOrderCrosschain(order)) {
|
|
7108
|
-
expected = {
|
|
7109
|
-
srcAmount: expected.srcAmount,
|
|
7110
|
-
destAmount: scaleByFactor(BigInt(expected.destAmount), order.bridge.scalingFactor).toString()
|
|
7111
|
-
};
|
|
7112
|
-
}
|
|
7113
|
-
var isExecuted = isExecutedAuction(auction);
|
|
7114
|
-
if (isExecuted) {
|
|
7115
|
-
var _final3 = getTransactionAmounts(auction.transactions);
|
|
7116
|
-
return {
|
|
7117
|
-
"final": _final3,
|
|
7118
|
-
expected: expected
|
|
7119
|
-
};
|
|
7120
|
-
}
|
|
7121
|
-
return {
|
|
7122
|
-
expected: expected
|
|
7123
|
-
};
|
|
7124
|
-
}
|
|
7125
|
-
/**
|
|
7126
|
-
* @description Checks whether an order includes valid cross-chain bridge details.
|
|
7127
|
-
*/
|
|
7128
|
-
function isOrderCrosschain(order
|
|
7129
|
-
// Extract<ExternalOrder, { bridge?: Bridge }> == never
|
|
7130
|
-
) {
|
|
7131
|
-
return 'bridge' in order && !!order.bridge && order.bridge.destinationChainId !== 0;
|
|
7132
|
-
}
|
|
7133
|
-
function scaleByFactor(amount, scalingFactor) {
|
|
7134
|
-
if (!amount) return 0n;
|
|
7135
|
-
if (scalingFactor === undefined) return amount;
|
|
7136
|
-
var base = 10n;
|
|
7137
|
-
return scalingFactor < 0 ? amount / Math.pow(base, BigInt(-scalingFactor)) : amount * Math.pow(base, BigInt(scalingFactor));
|
|
7138
|
-
}
|
|
7139
|
-
/**
|
|
7140
|
-
* @description Checks whether an auction is fully executed.
|
|
7141
|
-
*/
|
|
7142
|
-
function isExecutedAuction(auction) {
|
|
7143
|
-
if (auction.status !== 'EXECUTED') return false;
|
|
7144
|
-
if (isOrderCrosschain(auction.order)) {
|
|
7145
|
-
var filledPercent = getFilledPercent(auction);
|
|
7146
|
-
return filledPercent === 100;
|
|
7147
|
-
}
|
|
7148
|
-
return true;
|
|
7149
|
-
}
|
|
7150
|
-
var failedAuctionStatuses = ['FAILED', 'EXPIRED', 'CANCELLED', 'REFUNDED'];
|
|
7151
|
-
var failedAuctionStatusesSet = /*#__PURE__*/new Set(failedAuctionStatuses);
|
|
7152
|
-
/**
|
|
7153
|
-
* @description Checks whether an auction is failed on source or destination chain.
|
|
7154
|
-
*/
|
|
7155
|
-
function isFailedAuction(auction) {
|
|
7156
|
-
// already failed on srcChain, whether Order is crosschain or not
|
|
7157
|
-
if (failedAuctionStatusesSet.has(auction.status)) return true;
|
|
7158
|
-
// crosschain Order is executed on srcChain, but failed on destChain
|
|
7159
|
-
if (auction.status === 'EXECUTED' && isOrderCrosschain(auction.order)) {
|
|
7160
|
-
return auction.bridgeStatus === 'expired' || auction.bridgeStatus === 'refunded';
|
|
7161
|
-
}
|
|
7162
|
-
return false;
|
|
7163
|
-
}
|
|
7164
|
-
/**
|
|
7165
|
-
* @description Checks whether an auction status is cancelled.
|
|
7166
|
-
*/
|
|
7167
|
-
function isCanceledAuction(auction) {
|
|
7168
|
-
return auction.status === 'CANCELLED';
|
|
7169
|
-
}
|
|
7170
|
-
/**
|
|
7171
|
-
* @description Checks whether an auction status is expired.
|
|
7172
|
-
*/
|
|
7173
|
-
function isExpiredAuction(auction) {
|
|
7174
|
-
return auction.status === 'EXPIRED';
|
|
7175
|
-
}
|
|
7176
|
-
var pendingAuctionStatuses = ['NOT_STARTED', 'AWAITING_PRE_SIGNATURE', 'RUNNING', 'EXECUTING'];
|
|
7177
|
-
var pendingAuctionStatusesSet = /*#__PURE__*/new Set(pendingAuctionStatuses);
|
|
7178
|
-
/**
|
|
7179
|
-
* @description Checks whether an auction status is in pending execution states.
|
|
7180
|
-
*/
|
|
7181
|
-
function isPendingAuction(auction) {
|
|
7182
|
-
return pendingAuctionStatusesSet.has(auction.status);
|
|
7183
|
-
}
|
|
7184
|
-
/**
|
|
7185
|
-
* @description Auction can be cancelled in the middle of execution,
|
|
7186
|
-
* or crosschain-TWAP slices may not all be bridged,
|
|
7187
|
-
* or order can be suspended if it runs out of user balance/allowance.
|
|
7188
|
-
* Orders in the middle of normal execution can also be considered partially executed if they have any transactions.
|
|
7189
|
-
*/
|
|
7190
|
-
function isPartiallyExecutedAuction(auction) {
|
|
7191
|
-
if (auction.transactions.length === 0) return false;
|
|
7192
|
-
var filledPercent = getFilledPercent(auction);
|
|
7193
|
-
return filledPercent > 0 && filledPercent < 100;
|
|
7194
|
-
}
|
|
7195
|
-
/**
|
|
7196
|
-
* @description Calculates filled percentage from auction transaction filled bps values.
|
|
7197
|
-
*/
|
|
7198
|
-
function getFilledPercent(auction) {
|
|
7199
|
-
var transaction = !isOrderCrosschain(auction.order) ? auction.transactions : auction.transactions.filter(function (transaction) {
|
|
7200
|
-
return transaction.bridgeStatus === 'filled';
|
|
7201
|
-
});
|
|
7202
|
-
var filledPercentBps = transaction.reduce(function (acc, _ref3) {
|
|
7203
|
-
var filledPercent = _ref3.filledPercent;
|
|
7204
|
-
return acc + filledPercent;
|
|
7205
|
-
}, 0);
|
|
7206
|
-
var filledPercent = filledPercentBps / 100;
|
|
7207
|
-
return filledPercent;
|
|
7208
|
-
}
|
|
7209
|
-
///// TESTS //////
|
|
7210
|
-
// @TODO remove
|
|
7211
|
-
var auction = {};
|
|
7212
|
-
var minAuction = {
|
|
7213
|
-
onChainOrderType: 'TWAPOrder',
|
|
7214
|
-
gas: 6
|
|
7215
|
-
};
|
|
7216
|
-
if (isTWAPAuction(minAuction)) {
|
|
7217
|
-
console.log('🚀 ~ auction:', minAuction);
|
|
7218
|
-
/**
|
|
7219
|
-
* {
|
|
7220
|
-
onChainOrderType: OnChainOrderType;
|
|
7221
|
-
gas: number;
|
|
7222
|
-
} & {
|
|
7223
|
-
onChainOrderType: "TWAPOrder" | "TWAPBuyOrder";
|
|
7224
|
-
}
|
|
7225
|
-
*/
|
|
7226
|
-
}
|
|
7227
|
-
if (isTWAPAuction(auction)) {
|
|
7228
|
-
console.log('🚀 ~ auction:', auction);
|
|
7229
|
-
/**
|
|
7230
|
-
(DeltaAuctionBase & {
|
|
7231
|
-
onChainOrderType: "TWAPOrder";
|
|
7232
|
-
order: TWAPDeltaOrder;
|
|
7233
|
-
}) | (DeltaAuctionBase & {
|
|
7234
|
-
onChainOrderType: "TWAPBuyOrder";
|
|
7235
|
-
order: TWAPBuyDeltaOrder;
|
|
7236
|
-
})
|
|
7237
|
-
*/
|
|
7238
|
-
}
|
|
7239
|
-
if (isTWAPSellAuction(auction)) {
|
|
7240
|
-
console.log('🚀 ~ auction:', auction);
|
|
7241
|
-
/**
|
|
7242
|
-
* DeltaAuctionBase & {
|
|
7243
|
-
onChainOrderType: "TWAPOrder";
|
|
7244
|
-
order: TWAPDeltaOrder;
|
|
7245
|
-
}
|
|
7246
|
-
*/
|
|
7247
|
-
}
|
|
7248
|
-
if (isTWAPBuyAuction(auction)) {
|
|
7249
|
-
console.log('🚀 ~ auction:', auction);
|
|
7250
|
-
/**
|
|
7251
|
-
* DeltaAuctionBase & {
|
|
7252
|
-
onChainOrderType: "TWAPBuyOrder";
|
|
7253
|
-
order: TWAPBuyDeltaOrder;
|
|
7254
|
-
}
|
|
7255
|
-
*/
|
|
7256
|
-
}
|
|
7257
|
-
if (isDeltaAuction(auction)) {
|
|
7258
|
-
console.log('🚀 ~ auction:', auction);
|
|
7259
|
-
/**
|
|
7260
|
-
* DeltaAuctionBase & {
|
|
7261
|
-
onChainOrderType: "Order";
|
|
7262
|
-
order: DeltaAuctionOrder;
|
|
7263
|
-
}
|
|
7264
|
-
*/
|
|
7265
|
-
}
|
|
7266
|
-
if (isExternalAuction(auction)) {
|
|
7267
|
-
console.log('🚀 ~ auction:', auction);
|
|
7268
|
-
/**
|
|
7269
|
-
* DeltaAuctionBase & {
|
|
7270
|
-
onChainOrderType: "ExternalOrder";
|
|
7271
|
-
order: ExternalDeltaOrder;
|
|
7272
|
-
}
|
|
7273
|
-
*/
|
|
7274
|
-
}
|
|
7275
|
-
// ------------------------------------------------------------ //
|
|
7276
|
-
var orderAny = {};
|
|
7277
|
-
if (isOrderCrosschain(orderAny)) {
|
|
7278
|
-
console.log('🚀 ~ order:', orderAny);
|
|
7279
|
-
/**
|
|
7280
|
-
DeltaAuctionOrder | TWAPDeltaOrder | TWAPBuyDeltaOrder
|
|
7281
|
-
*/
|
|
7282
|
-
}
|
|
7283
|
-
var orderExternal = {};
|
|
7284
|
-
if (isOrderCrosschain(orderExternal)) {
|
|
7285
|
-
console.log('🚀 ~ order:', orderExternal);
|
|
7286
|
-
/**
|
|
7287
|
-
never
|
|
7288
|
-
*/
|
|
7289
|
-
}
|
|
7290
|
-
var orderLike = {};
|
|
7291
|
-
if (isOrderCrosschain(orderLike)) {
|
|
7292
|
-
console.log('🚀 ~ order:', orderLike);
|
|
7293
|
-
/**
|
|
7294
|
-
* {
|
|
7295
|
-
bridge: Bridge;
|
|
7296
|
-
a: 2;
|
|
7297
|
-
}
|
|
7298
|
-
*/
|
|
7299
|
-
}
|
|
7300
|
-
|
|
7301
6803
|
Object.defineProperty(exports, 'ContractMethod', {
|
|
7302
6804
|
enumerable: true,
|
|
7303
6805
|
get: function () { return core.ContractMethod; }
|
|
@@ -7317,7 +6819,6 @@ Object.defineProperty(exports, 'SwapSide', {
|
|
|
7317
6819
|
exports.API_URL = API_URL;
|
|
7318
6820
|
exports.AssetType = AssetType;
|
|
7319
6821
|
exports.DEFAULT_VERSION = DEFAULT_VERSION;
|
|
7320
|
-
exports.OrderHelpers = OrderHelpers;
|
|
7321
6822
|
exports.constructAllDeltaOrdersHandlers = constructAllDeltaOrdersHandlers;
|
|
7322
6823
|
exports.constructAllLimitOrdersHandlers = constructAllLimitOrdersHandlers;
|
|
7323
6824
|
exports.constructAllNFTOrdersHandlers = constructAllNFTOrdersHandlers;
|