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