@bitflowlabs/core-sdk 1.0.1 → 2.0.0
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/src/BitflowSDK.d.ts +23 -2
- package/dist/src/BitflowSDK.js +536 -82
- package/dist/src/BitflowSDK.js.map +1 -1
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.js +6 -4
- package/dist/src/config.js.map +1 -1
- package/dist/src/helpers/callReadOnlyHelper.js +10 -4
- package/dist/src/helpers/callReadOnlyHelper.js.map +1 -1
- package/dist/src/helpers/callSwapHelper.d.ts +2 -2
- package/dist/src/helpers/callSwapHelper.js +48 -7
- package/dist/src/helpers/callSwapHelper.js.map +1 -1
- package/dist/src/helpers/fetchDataHelper.d.ts +1 -1
- package/dist/src/helpers/fetchDataHelper.js +50 -17
- package/dist/src/helpers/fetchDataHelper.js.map +1 -1
- package/dist/src/helpers/fetchPossibleSwap.d.ts +2 -2
- package/dist/src/helpers/fetchPossibleSwap.js +10 -2
- package/dist/src/helpers/fetchPossibleSwap.js.map +1 -1
- package/dist/src/helpers/handleResultHelper.js +15 -15
- package/dist/src/helpers/handleResultHelper.js.map +1 -1
- package/dist/src/helpers/newPostConditionsHelper.d.ts +2 -0
- package/dist/src/helpers/newPostConditionsHelper.js +145 -0
- package/dist/src/helpers/newPostConditionsHelper.js.map +1 -0
- package/dist/src/helpers/postConditionsHelper.js +38 -13
- package/dist/src/helpers/postConditionsHelper.js.map +1 -1
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/keeper/keeperAPI.d.ts +10 -0
- package/dist/src/keeper/keeperAPI.js +332 -0
- package/dist/src/keeper/keeperAPI.js.map +1 -0
- package/dist/src/keeper/types.d.ts +253 -0
- package/dist/src/keeper/types.js +65 -0
- package/dist/src/keeper/types.js.map +1 -0
- package/dist/src/test-keeper-routes.d.ts +1 -0
- package/dist/src/test-keeper-routes.js +67 -0
- package/dist/src/test-keeper-routes.js.map +1 -0
- package/dist/src/test-raw-token-response.d.ts +1 -0
- package/dist/src/test-raw-token-response.js +79 -0
- package/dist/src/test-raw-token-response.js.map +1 -0
- package/dist/src/test-sdk.d.ts +1 -0
- package/dist/src/test-sdk.js +229 -0
- package/dist/src/test-sdk.js.map +1 -0
- package/dist/src/test-token.fetch.d.ts +1 -0
- package/dist/src/test-token.fetch.js +63 -0
- package/dist/src/test-token.fetch.js.map +1 -0
- package/dist/src/types.d.ts +27 -2
- package/package.json +6 -5
- package/src/BitflowSDK.ts +675 -97
- package/src/config.ts +9 -6
- package/src/helpers/callReadOnlyHelper.ts +12 -7
- package/src/helpers/callSwapHelper.ts +21 -7
- package/src/helpers/fetchDataHelper.ts +58 -19
- package/src/helpers/fetchPossibleSwap.ts +18 -4
- package/src/helpers/handleResultHelper.ts +17 -16
- package/src/helpers/newPostConditionsHelper.ts +172 -0
- package/src/helpers/postConditionsHelper.ts +71 -19
- package/src/index.ts +3 -2
- package/src/keeper/keeperAPI.ts +435 -0
- package/src/keeper/types.ts +293 -0
- package/src/test-keeper-routes.ts +76 -0
- package/src/test-raw-token-response.ts +124 -0
- package/src/test-sdk.ts +262 -0
- package/src/test-token.fetch.ts +72 -0
- package/src/types.ts +29 -2
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSwapPostConditions = void 0;
|
|
4
|
+
const transactions_1 = require("@stacks/transactions");
|
|
5
|
+
const isWSTXv2Token = (value) => typeof value === "string" &&
|
|
6
|
+
value.includes("SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-wstx-v2");
|
|
7
|
+
const checkForWSTXv2 = (obj) => {
|
|
8
|
+
if (typeof obj !== "object" || obj === null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
for (const key in obj) {
|
|
12
|
+
if (isWSTXv2Token(obj[key])) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (typeof obj[key] === "object" && checkForWSTXv2(obj[key])) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
const createSwapPostConditions = async (functionArgs, postConditionsData, senderAddress, tokenXDecimals, tokenYDecimals) => {
|
|
22
|
+
const postConditions = [];
|
|
23
|
+
const postConditionKeys = Object.keys(postConditionsData);
|
|
24
|
+
const isWSTXv2Involved = checkForWSTXv2(functionArgs);
|
|
25
|
+
for (let i = 0; i < postConditionKeys.length; i++) {
|
|
26
|
+
const key = postConditionKeys[i];
|
|
27
|
+
const pcData = postConditionsData[key];
|
|
28
|
+
const isFirst = i === 0;
|
|
29
|
+
const isLast = i === postConditionKeys.length - 1;
|
|
30
|
+
const isTxSender = pcData.senderAddress === "tx-sender";
|
|
31
|
+
const isSTX = pcData.tokenContract === "token-stx" || pcData.tokenName === "token-stx";
|
|
32
|
+
const isAutoAlexV3OrLqstx = pcData.tokenName === "auto-alex-v3" || pcData.tokenName === "lqstx";
|
|
33
|
+
let postConditionAmount;
|
|
34
|
+
let conditionCode;
|
|
35
|
+
if (isAutoAlexV3OrLqstx && (isFirst || isLast)) {
|
|
36
|
+
postConditionAmount = BigInt(0);
|
|
37
|
+
conditionCode = "willSendGte";
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (isFirst) {
|
|
41
|
+
postConditionAmount = functionArgs.dx;
|
|
42
|
+
conditionCode = "willSendEq";
|
|
43
|
+
}
|
|
44
|
+
else if (isLast) {
|
|
45
|
+
postConditionAmount = functionArgs["min-dy"];
|
|
46
|
+
conditionCode = "willSendGte";
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
postConditionAmount = BigInt(0);
|
|
50
|
+
conditionCode = "willSendGte";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (isSTX && isWSTXv2Involved) {
|
|
54
|
+
postConditionAmount = postConditionAmount / BigInt(100);
|
|
55
|
+
}
|
|
56
|
+
else if (!isSTX && (isFirst || isLast)) {
|
|
57
|
+
let decimalDifference;
|
|
58
|
+
if (isFirst) {
|
|
59
|
+
decimalDifference = tokenXDecimals - pcData.tokenDecimals;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
decimalDifference = tokenYDecimals - pcData.tokenDecimals;
|
|
63
|
+
}
|
|
64
|
+
if (decimalDifference > 0) {
|
|
65
|
+
postConditionAmount =
|
|
66
|
+
postConditionAmount / BigInt(10 ** decimalDifference);
|
|
67
|
+
}
|
|
68
|
+
else if (decimalDifference < 0) {
|
|
69
|
+
postConditionAmount =
|
|
70
|
+
postConditionAmount * BigInt(10 ** Math.abs(decimalDifference));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
if (isTxSender) {
|
|
75
|
+
if (isSTX) {
|
|
76
|
+
postConditions.push(conditionCode === "willSendEq"
|
|
77
|
+
? transactions_1.Pc.principal(senderAddress)
|
|
78
|
+
.willSendEq(postConditionAmount)
|
|
79
|
+
.ustx()
|
|
80
|
+
: transactions_1.Pc.principal(senderAddress)
|
|
81
|
+
.willSendGte(postConditionAmount)
|
|
82
|
+
.ustx());
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
postConditions.push(conditionCode === "willSendEq"
|
|
86
|
+
? transactions_1.Pc.principal(senderAddress)
|
|
87
|
+
.willSendEq(postConditionAmount)
|
|
88
|
+
.ft(pcData.tokenContract, pcData.tokenName)
|
|
89
|
+
: transactions_1.Pc.principal(senderAddress)
|
|
90
|
+
.willSendGte(postConditionAmount)
|
|
91
|
+
.ft(pcData.tokenContract, pcData.tokenName));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
if (isSTX) {
|
|
96
|
+
postConditions.push(conditionCode === "willSendEq"
|
|
97
|
+
? transactions_1.Pc.principal(pcData.senderAddress)
|
|
98
|
+
.willSendEq(postConditionAmount)
|
|
99
|
+
.ustx()
|
|
100
|
+
: transactions_1.Pc.principal(pcData.senderAddress)
|
|
101
|
+
.willSendGte(postConditionAmount)
|
|
102
|
+
.ustx());
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
postConditions.push(conditionCode === "willSendEq"
|
|
106
|
+
? transactions_1.Pc.principal(pcData.senderAddress)
|
|
107
|
+
.willSendEq(postConditionAmount)
|
|
108
|
+
.ft(pcData.tokenContract, pcData.tokenName)
|
|
109
|
+
: transactions_1.Pc.principal(pcData.senderAddress)
|
|
110
|
+
.willSendGte(postConditionAmount)
|
|
111
|
+
.ft(pcData.tokenContract, pcData.tokenName));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (pcData.shareFeeContract !== null) {
|
|
115
|
+
if (isSTX) {
|
|
116
|
+
postConditions.push(transactions_1.Pc.principal(pcData.shareFeeContract).willSendGte(0).ustx());
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
postConditions.push(transactions_1.Pc.principal(pcData.shareFeeContract)
|
|
120
|
+
.willSendGte(0)
|
|
121
|
+
.ft(pcData.tokenContract, pcData.tokenName));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (pcData.dikoStx !== null) {
|
|
125
|
+
if (isTxSender) {
|
|
126
|
+
postConditions.push(transactions_1.Pc.principal(senderAddress)
|
|
127
|
+
.willSendGte(0)
|
|
128
|
+
.ft(pcData.dikoStx, "wstx"));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
postConditions.push(transactions_1.Pc.principal(pcData.senderAddress)
|
|
132
|
+
.willSendGte(0)
|
|
133
|
+
.ft(pcData.dikoStx, "wstx"));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error(`Error creating post condition for ${key}:`, error);
|
|
139
|
+
throw new Error(`Failed to create post condition for ${key}: ${error.message}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return postConditions;
|
|
143
|
+
};
|
|
144
|
+
exports.createSwapPostConditions = createSwapPostConditions;
|
|
145
|
+
//# sourceMappingURL=newPostConditionsHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newPostConditionsHelper.js","sourceRoot":"","sources":["../../../src/helpers/newPostConditionsHelper.ts"],"names":[],"mappings":";;;AAAA,uDAAyD;AAEzD,MAAM,aAAa,GAAG,CAAC,KAAU,EAAW,EAAE,CAC5C,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,CAAC,QAAQ,CAAC,yDAAyD,CAAC,CAAC;AAE5E,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAW,EAAE;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC7D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEK,MAAM,wBAAwB,GAAG,KAAK,EAC3C,YAAiB,EACjB,kBAAuB,EACvB,aAAqB,EACrB,cAAsB,EACtB,cAAsB,EACI,EAAE;IAC5B,MAAM,cAAc,GAAoB,EAAE,CAAC;IAC3C,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAE1D,MAAM,gBAAgB,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;IAEtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,i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AAM,CAAC;oBACN,cAAc,CAAC,IAAI,CACjB,iBAAE,CAAC,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC;yBAClC,WAAW,CAAC,CAAC,CAAC;yBACd,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,CAC9C,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;gBAC5B,IAAI,UAAU,EAAE,CAAC;oBACf,cAAc,CAAC,IAAI,CACjB,iBAAE,CAAC,SAAS,CAAC,aAAa,CAAC;yBACxB,WAAW,CAAC,CAAC,CAAC;yBACd,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAC9B,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,cAAc,CAAC,IAAI,CACjB,iBAAE,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC;yBAC/B,WAAW,CAAC,CAAC,CAAC;yBACd,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAC9B,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;YAClE,MAAM,IAAI,KAAK,CACb,uCAAuC,GAAG,KACvC,KAAe,CAAC,OACnB,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AApJW,QAAA,wBAAwB,4BAoJnC"}
|
|
@@ -19,13 +19,38 @@ const checkForWSTXv2 = (obj) => {
|
|
|
19
19
|
return false;
|
|
20
20
|
};
|
|
21
21
|
const createSafeAssetInfo = (contractAddress, contractName, assetName) => {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
return {
|
|
23
|
+
contract: `${contractAddress}.${contractName}`,
|
|
24
|
+
tokenName: `${assetName}`,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const makeStandardSTXPostCondition = (senderAddress, conditionCode, postConditionAmount) => {
|
|
28
|
+
let initialPostCondition = transactions_1.Pc.principal(senderAddress);
|
|
29
|
+
let postCondition;
|
|
30
|
+
if (conditionCode === transactions_1.FungibleConditionCode.Equal) {
|
|
31
|
+
postCondition = initialPostCondition.willSendEq(postConditionAmount);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
postCondition = initialPostCondition.willSendGte(postConditionAmount);
|
|
35
|
+
}
|
|
36
|
+
return postCondition.ustx();
|
|
37
|
+
};
|
|
38
|
+
const makeStandardFungiblePostCondition = (senderAddress, conditionCode, postConditionAmount, asset) => {
|
|
39
|
+
let initialPostCondition = transactions_1.Pc.principal(senderAddress);
|
|
40
|
+
let postCondition;
|
|
41
|
+
if (conditionCode === transactions_1.FungibleConditionCode.Equal) {
|
|
42
|
+
postCondition = initialPostCondition.willSendEq(postConditionAmount);
|
|
24
43
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
throw new Error(`Invalid asset info: ${contractAddress}.${contractName}::${assetName}`);
|
|
44
|
+
else {
|
|
45
|
+
postCondition = initialPostCondition.willSendGte(postConditionAmount);
|
|
28
46
|
}
|
|
47
|
+
return postCondition.ft(asset.contract, asset.tokenName);
|
|
48
|
+
};
|
|
49
|
+
const makeContractSTXPostCondition = (contractAddress, contractName, conditionCode, postConditionAmount) => {
|
|
50
|
+
return makeStandardSTXPostCondition(`${contractAddress}.${contractName}`, conditionCode, postConditionAmount);
|
|
51
|
+
};
|
|
52
|
+
const makeContractFungiblePostCondition = (contractAddress, contractName, conditionCode, postConditionAmount, asset) => {
|
|
53
|
+
return makeStandardFungiblePostCondition(`${contractAddress}.${contractName}`, conditionCode, postConditionAmount, asset);
|
|
29
54
|
};
|
|
30
55
|
const createSwapPostConditions = async (functionArgs, postConditionsData, senderAddress, tokenXDecimals, tokenYDecimals) => {
|
|
31
56
|
const postConditions = [];
|
|
@@ -82,45 +107,45 @@ const createSwapPostConditions = async (functionArgs, postConditionsData, sender
|
|
|
82
107
|
try {
|
|
83
108
|
if (isTxSender) {
|
|
84
109
|
if (isSTX) {
|
|
85
|
-
postConditions.push(
|
|
110
|
+
postConditions.push(makeStandardSTXPostCondition(senderAddress, conditionCode, postConditionAmount));
|
|
86
111
|
}
|
|
87
112
|
else {
|
|
88
113
|
const [contractAddress, contractName] = pcData.tokenContract.split(".");
|
|
89
114
|
const assetInfo = createSafeAssetInfo(contractAddress, contractName, pcData.tokenName);
|
|
90
|
-
postConditions.push(
|
|
115
|
+
postConditions.push(makeStandardFungiblePostCondition(senderAddress, conditionCode, postConditionAmount, assetInfo));
|
|
91
116
|
}
|
|
92
117
|
}
|
|
93
118
|
else {
|
|
94
119
|
const [contractAddress, contractName] = pcData.senderAddress.split(".");
|
|
95
120
|
if (isSTX) {
|
|
96
|
-
postConditions.push(
|
|
121
|
+
postConditions.push(makeContractSTXPostCondition(contractAddress, contractName, conditionCode, postConditionAmount));
|
|
97
122
|
}
|
|
98
123
|
else {
|
|
99
124
|
const [tokenContractAddress, tokenContractName] = pcData.tokenContract.split(".");
|
|
100
125
|
const assetInfo = createSafeAssetInfo(tokenContractAddress, tokenContractName, pcData.tokenName);
|
|
101
|
-
postConditions.push(
|
|
126
|
+
postConditions.push(makeContractFungiblePostCondition(contractAddress, contractName, conditionCode, postConditionAmount, assetInfo));
|
|
102
127
|
}
|
|
103
128
|
}
|
|
104
129
|
if (pcData.shareFeeContract !== null) {
|
|
105
130
|
const [shareFeeContractAddress, shareFeeContractName] = pcData.shareFeeContract.split(".");
|
|
106
131
|
if (isSTX) {
|
|
107
|
-
postConditions.push(
|
|
132
|
+
postConditions.push(makeContractSTXPostCondition(shareFeeContractAddress, shareFeeContractName, transactions_1.FungibleConditionCode.GreaterEqual, BigInt(0)));
|
|
108
133
|
}
|
|
109
134
|
else {
|
|
110
135
|
const [tokenContractAddress, tokenContractName] = pcData.tokenContract.split(".");
|
|
111
136
|
const assetInfo = createSafeAssetInfo(tokenContractAddress, tokenContractName, pcData.tokenName);
|
|
112
|
-
postConditions.push(
|
|
137
|
+
postConditions.push(makeContractFungiblePostCondition(shareFeeContractAddress, shareFeeContractName, transactions_1.FungibleConditionCode.GreaterEqual, BigInt(0), assetInfo));
|
|
113
138
|
}
|
|
114
139
|
}
|
|
115
140
|
if (pcData.dikoStx !== null) {
|
|
116
141
|
const [dikoContractAddress, dikoContractName] = pcData.dikoStx.split(".");
|
|
117
142
|
const dikoAssetInfo = createSafeAssetInfo(dikoContractAddress, dikoContractName, "wstx");
|
|
118
143
|
if (isTxSender) {
|
|
119
|
-
postConditions.push(
|
|
144
|
+
postConditions.push(makeStandardFungiblePostCondition(senderAddress, transactions_1.FungibleConditionCode.GreaterEqual, BigInt(0), dikoAssetInfo));
|
|
120
145
|
}
|
|
121
146
|
else {
|
|
122
147
|
const [senderContractAddress, senderContractName] = pcData.senderAddress.split(".");
|
|
123
|
-
postConditions.push(
|
|
148
|
+
postConditions.push(makeContractFungiblePostCondition(senderContractAddress, senderContractName, transactions_1.FungibleConditionCode.GreaterEqual, BigInt(0), dikoAssetInfo));
|
|
124
149
|
}
|
|
125
150
|
}
|
|
126
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postConditionsHelper.js","sourceRoot":"","sources":["../../../src/helpers/postConditionsHelper.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"postConditionsHelper.js","sourceRoot":"","sources":["../../../src/helpers/postConditionsHelper.ts"],"names":[],"mappings":";;;AAAA,uDAAgF;AAEhF,MAAM,aAAa,GAAG,CAAC,KAAU,EAAW,EAAE,CAC5C,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,CAAC,QAAQ,CAAC,yDAAyD,CAAC,CAAC;AAE5E,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAW,EAAE;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG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;YACH,CAAC;YAED,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;gBAC5B,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,GAC3C,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC5B,MAAM,aAAa,GAAG,mBAAmB,CACvC,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,CACP,CAAC;gBAEF,IAAI,UAAU,EAAE,CAAC;oBACf,cAAc,CAAC,IAAI,CACjB,iCAAiC,CAC/B,aAAa,EACb,oCAAqB,CAAC,YAAY,EAClC,MAAM,CAAC,CAAC,CAAC,EACT,aAAa,CACd,CACF,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,GAC/C,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAClC,cAAc,CAAC,IAAI,CACjB,iCAAiC,CAC/B,qBAAqB,EACrB,kBAAkB,EAClB,oCAAqB,CAAC,YAAY,EAClC,MAAM,CAAC,CAAC,CAAC,EACT,aAAa,CACd,CACF,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;YAClE,MAAM,IAAI,KAAK,CACb,uCAAuC,GAAG,KACvC,KAAe,CAAC,OACnB,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AApMW,QAAA,wBAAwB,4BAoMnC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { BitflowSDK } from
|
|
2
|
-
export * from
|
|
1
|
+
export { BitflowSDK } from "./BitflowSDK";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./keeper/types";
|
package/dist/src/index.js
CHANGED
|
@@ -5,4 +5,5 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
var BitflowSDK_1 = require("./BitflowSDK");
|
|
6
6
|
Object.defineProperty(exports, "BitflowSDK", { enumerable: true, get: function () { return BitflowSDK_1.BitflowSDK; } });
|
|
7
7
|
tslib_1.__exportStar(require("./types"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./keeper/types"), exports);
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,kDAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,kDAAwB;AACxB,yDAA+B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CancelGroupOrderResponse, CancelOrderResponse, CreateGroupOrderParams, CreateGroupOrderResponse, CreateOrderParams, CreateOrderResponse, GetGroupOrderResponse, GetKeeperContractParams, GetKeeperContractResponse, GetOrderResponse, GetQuoteParams, GetQuoteResponse, GetUserResponse } from "./types";
|
|
2
|
+
export declare function getOrCreateKeeperContractAPI(params: GetKeeperContractParams): Promise<GetKeeperContractResponse>;
|
|
3
|
+
export declare function getOrderAPI(orderId: string): Promise<GetOrderResponse>;
|
|
4
|
+
export declare function getUserAPI(stacksAddress: string): Promise<GetUserResponse>;
|
|
5
|
+
export declare function createOrderAPI(params: CreateOrderParams): Promise<CreateOrderResponse>;
|
|
6
|
+
export declare function getQuoteAPI(params: GetQuoteParams): Promise<GetQuoteResponse>;
|
|
7
|
+
export declare function createGroupOrderAPI(params: CreateGroupOrderParams): Promise<CreateGroupOrderResponse>;
|
|
8
|
+
export declare function getGroupOrderAPI(groupId: string, includeOrders?: boolean): Promise<GetGroupOrderResponse>;
|
|
9
|
+
export declare function cancelOrderAPI(orderId: string): Promise<CancelOrderResponse>;
|
|
10
|
+
export declare function cancelGroupOrderAPI(groupId: string): Promise<CancelGroupOrderResponse>;
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrCreateKeeperContractAPI = getOrCreateKeeperContractAPI;
|
|
4
|
+
exports.getOrderAPI = getOrderAPI;
|
|
5
|
+
exports.getUserAPI = getUserAPI;
|
|
6
|
+
exports.createOrderAPI = createOrderAPI;
|
|
7
|
+
exports.getQuoteAPI = getQuoteAPI;
|
|
8
|
+
exports.createGroupOrderAPI = createGroupOrderAPI;
|
|
9
|
+
exports.getGroupOrderAPI = getGroupOrderAPI;
|
|
10
|
+
exports.cancelOrderAPI = cancelOrderAPI;
|
|
11
|
+
exports.cancelGroupOrderAPI = cancelGroupOrderAPI;
|
|
12
|
+
const types_1 = require("./types");
|
|
13
|
+
async function getOrCreateKeeperContractAPI(params) {
|
|
14
|
+
try {
|
|
15
|
+
const queryParams = new URLSearchParams({
|
|
16
|
+
stacksAddress: params.stacksAddress,
|
|
17
|
+
keeperType: params.keeperType,
|
|
18
|
+
});
|
|
19
|
+
if (params.bitcoinAddress) {
|
|
20
|
+
queryParams.append("bitcoinAddress", params.bitcoinAddress);
|
|
21
|
+
}
|
|
22
|
+
if (typeof params.deployContract === "boolean") {
|
|
23
|
+
queryParams.append("deployContract", params.deployContract.toString());
|
|
24
|
+
}
|
|
25
|
+
if (typeof params.allActionsApproved === "boolean") {
|
|
26
|
+
queryParams.append("allActionsApproved", params.allActionsApproved.toString());
|
|
27
|
+
}
|
|
28
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/getOrCreateKeeperContract?${queryParams.toString()}`;
|
|
29
|
+
const response = await fetch(url, {
|
|
30
|
+
method: "GET",
|
|
31
|
+
headers: {
|
|
32
|
+
Accept: "application/json",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
const errorData = await response.json();
|
|
37
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
38
|
+
}
|
|
39
|
+
const data = await response.json();
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error("Error in getOrCreateKeeperContract:", error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function getOrderAPI(orderId) {
|
|
48
|
+
try {
|
|
49
|
+
const queryParams = new URLSearchParams({
|
|
50
|
+
orderId: orderId,
|
|
51
|
+
});
|
|
52
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/getOrder?${queryParams.toString()}`;
|
|
53
|
+
const response = await fetch(url, {
|
|
54
|
+
method: "GET",
|
|
55
|
+
headers: {
|
|
56
|
+
Accept: "application/json",
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
const errorData = await response.json();
|
|
61
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
62
|
+
}
|
|
63
|
+
const data = await response.json();
|
|
64
|
+
if (data.order) {
|
|
65
|
+
data.order.creationDate = new Date(data.order.creationDate);
|
|
66
|
+
data.order.lastUpdated = new Date(data.order.lastUpdated);
|
|
67
|
+
}
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error("Error in getOrder:", error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function getUserAPI(stacksAddress) {
|
|
76
|
+
try {
|
|
77
|
+
const queryParams = new URLSearchParams({
|
|
78
|
+
stacksAddress: stacksAddress,
|
|
79
|
+
});
|
|
80
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/getUser?${queryParams.toString()}`;
|
|
81
|
+
const response = await fetch(url, {
|
|
82
|
+
method: "GET",
|
|
83
|
+
headers: {
|
|
84
|
+
Accept: "application/json",
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
const errorData = await response.json();
|
|
89
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
90
|
+
}
|
|
91
|
+
const data = (await response.json());
|
|
92
|
+
if (data.user) {
|
|
93
|
+
data.user.creationDate = new Date(data.user.creationDate);
|
|
94
|
+
data.user.lastUpdated = new Date(data.user.lastUpdated);
|
|
95
|
+
const contracts = data.user.keeperContracts;
|
|
96
|
+
for (const contractKey in contracts) {
|
|
97
|
+
const contract = contracts[contractKey];
|
|
98
|
+
if (contract.deploymentDate) {
|
|
99
|
+
contract.deploymentDate = new Date(contract.deploymentDate);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const orders = data.user.keeperOrders;
|
|
103
|
+
for (const orderKey in orders) {
|
|
104
|
+
const order = orders[orderKey];
|
|
105
|
+
order.creationDate = new Date(order.creationDate);
|
|
106
|
+
order.lastUpdated = new Date(order.lastUpdated);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return data;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error("Error in getUser:", error);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function createOrderAPI(params) {
|
|
117
|
+
try {
|
|
118
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/createOrder`;
|
|
119
|
+
const requestBody = {
|
|
120
|
+
stacksAddress: params.stacksAddress,
|
|
121
|
+
keeperType: params.keeperType,
|
|
122
|
+
contractIdentifier: params.contractIdentifier,
|
|
123
|
+
bitcoinAddress: params.bitcoinAddress || "",
|
|
124
|
+
actionAmount: params.actionAmount || "",
|
|
125
|
+
minReceived: params.minReceived || {
|
|
126
|
+
amount: "",
|
|
127
|
+
autoAdjust: false,
|
|
128
|
+
},
|
|
129
|
+
feeRecipient: params.feeRecipient || "",
|
|
130
|
+
tokenOrder: params.tokenOrder || [],
|
|
131
|
+
actionType: params.actionType,
|
|
132
|
+
bitcoinTxId: params.bitcoinTxId,
|
|
133
|
+
};
|
|
134
|
+
const response = await fetch(url, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: {
|
|
137
|
+
Accept: "application/json",
|
|
138
|
+
"Content-Type": "application/json",
|
|
139
|
+
},
|
|
140
|
+
body: JSON.stringify(requestBody),
|
|
141
|
+
});
|
|
142
|
+
if (!response.ok) {
|
|
143
|
+
const errorData = await response.json();
|
|
144
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
145
|
+
}
|
|
146
|
+
const data = (await response.json());
|
|
147
|
+
if (data.order) {
|
|
148
|
+
data.order.creationDate = new Date(data.order.creationDate);
|
|
149
|
+
data.order.lastUpdated = new Date(data.order.lastUpdated);
|
|
150
|
+
}
|
|
151
|
+
return data;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.error("Error in createOrder:", error);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async function getQuoteAPI(params) {
|
|
159
|
+
try {
|
|
160
|
+
const queryParams = new URLSearchParams();
|
|
161
|
+
// Add required params
|
|
162
|
+
queryParams.append("stacksAddress", params.stacksAddress);
|
|
163
|
+
queryParams.append("actionAmount", params.actionAmount);
|
|
164
|
+
queryParams.append("keeperType", params.keeperType);
|
|
165
|
+
// Add optional params
|
|
166
|
+
if (params.actionType) {
|
|
167
|
+
queryParams.append("actionType", params.actionType);
|
|
168
|
+
}
|
|
169
|
+
if (params.tokenXId && params.tokenYId) {
|
|
170
|
+
queryParams.append("tokenXId", params.tokenXId);
|
|
171
|
+
queryParams.append("tokenYId", params.tokenYId);
|
|
172
|
+
}
|
|
173
|
+
if (params.minReceived) {
|
|
174
|
+
queryParams.append("minReceived[amount]", params.minReceived.amount);
|
|
175
|
+
queryParams.append("minReceived[autoAdjust]", params.minReceived.autoAdjust.toString());
|
|
176
|
+
}
|
|
177
|
+
if (params.feeRecipient) {
|
|
178
|
+
queryParams.append("feeRecipient", params.feeRecipient);
|
|
179
|
+
}
|
|
180
|
+
if (params.bitcoinAddress) {
|
|
181
|
+
queryParams.append("bitcoinAddress", params.bitcoinAddress);
|
|
182
|
+
}
|
|
183
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/getQuote?${queryParams.toString()}`;
|
|
184
|
+
const response = await fetch(url);
|
|
185
|
+
const responseText = await response.text();
|
|
186
|
+
if (!response.ok) {
|
|
187
|
+
throw new Error(`Unable to get quote: ${responseText}`);
|
|
188
|
+
}
|
|
189
|
+
return JSON.parse(responseText);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
console.error("Error in getQuote:", error);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async function createGroupOrderAPI(params) {
|
|
197
|
+
var _a;
|
|
198
|
+
try {
|
|
199
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/createGroupOrder`;
|
|
200
|
+
const requestBody = {
|
|
201
|
+
stacksAddress: params.stacksAddress,
|
|
202
|
+
amountPerOrder: params.amountPerOrder,
|
|
203
|
+
minReceived: params.minReceived,
|
|
204
|
+
numberOfOrders: params.numberOfOrders,
|
|
205
|
+
executionFrequency: params.executionFrequency,
|
|
206
|
+
feeRecipient: params.feeRecipient,
|
|
207
|
+
fundingTokens: params.fundingTokens,
|
|
208
|
+
bitcoinTxId: params.bitcoinTxId,
|
|
209
|
+
stacksTxId: params.stacksTxId,
|
|
210
|
+
keeperType: params.keeperType,
|
|
211
|
+
actionType: params.actionType,
|
|
212
|
+
actionFunctionArgs: params.actionFunctionArgs,
|
|
213
|
+
actionPostConditions: params.actionPostConditions,
|
|
214
|
+
actionAggregatorTokens: params.actionAggregatorTokens,
|
|
215
|
+
bitcoinAddress: params.bitcoinAddress || "",
|
|
216
|
+
nextExecutionAfter: (_a = params.nextExecutionAfter) === null || _a === void 0 ? void 0 : _a.toISOString(),
|
|
217
|
+
};
|
|
218
|
+
if (params.priceRange) {
|
|
219
|
+
requestBody.priceRange = params.priceRange;
|
|
220
|
+
}
|
|
221
|
+
const response = await fetch(url, {
|
|
222
|
+
method: "POST",
|
|
223
|
+
headers: {
|
|
224
|
+
Accept: "application/json",
|
|
225
|
+
"Content-Type": "application/json",
|
|
226
|
+
},
|
|
227
|
+
body: JSON.stringify(requestBody),
|
|
228
|
+
});
|
|
229
|
+
if (!response.ok) {
|
|
230
|
+
const errorData = await response.json();
|
|
231
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
232
|
+
}
|
|
233
|
+
const data = await response.json();
|
|
234
|
+
if (data.groupOrder) {
|
|
235
|
+
data.groupOrder.creationDate = new Date(data.groupOrder.creationDate);
|
|
236
|
+
data.groupOrder.lastUpdated = new Date(data.groupOrder.lastUpdated);
|
|
237
|
+
if (data.groupOrder.orders) {
|
|
238
|
+
data.groupOrder.orders.forEach((order) => {
|
|
239
|
+
order.creationDate = new Date(order.creationDate);
|
|
240
|
+
order.lastUpdated = new Date(order.lastUpdated);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return data;
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
console.error("Error in createGroupOrder:", error);
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async function getGroupOrderAPI(groupId, includeOrders = false) {
|
|
252
|
+
try {
|
|
253
|
+
const queryParams = new URLSearchParams({
|
|
254
|
+
groupId: groupId,
|
|
255
|
+
includeOrders: includeOrders.toString(),
|
|
256
|
+
});
|
|
257
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/getGroupOrder?${queryParams.toString()}`;
|
|
258
|
+
const response = await fetch(url, {
|
|
259
|
+
method: "GET",
|
|
260
|
+
headers: {
|
|
261
|
+
Accept: "application/json",
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
if (!response.ok) {
|
|
265
|
+
const errorData = await response.json();
|
|
266
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
267
|
+
}
|
|
268
|
+
const data = await response.json();
|
|
269
|
+
// Convert date strings to Date objects
|
|
270
|
+
if (data.groupOrder) {
|
|
271
|
+
data.groupOrder.creationDate = new Date(data.groupOrder.creationDate);
|
|
272
|
+
data.groupOrder.lastUpdated = new Date(data.groupOrder.lastUpdated);
|
|
273
|
+
data.groupOrder.nextExecutionAfter = new Date(data.groupOrder.nextExecutionAfter);
|
|
274
|
+
}
|
|
275
|
+
if (data.groupOrders && Array.isArray(data.groupOrders)) {
|
|
276
|
+
data.groupOrders.forEach((order) => {
|
|
277
|
+
order.creationDate = new Date(order.creationDate);
|
|
278
|
+
order.lastUpdated = new Date(order.lastUpdated);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return data;
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
console.error("Error in getGroupOrder:", error);
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function cancelOrderAPI(orderId) {
|
|
289
|
+
try {
|
|
290
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/cancelOrder`;
|
|
291
|
+
const response = await fetch(url, {
|
|
292
|
+
method: "POST",
|
|
293
|
+
headers: {
|
|
294
|
+
Accept: "application/json",
|
|
295
|
+
"Content-Type": "application/json",
|
|
296
|
+
},
|
|
297
|
+
body: JSON.stringify({ orderId }),
|
|
298
|
+
});
|
|
299
|
+
if (!response.ok) {
|
|
300
|
+
const errorData = await response.json();
|
|
301
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
302
|
+
}
|
|
303
|
+
return (await response.json());
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.error("Error in cancelOrder:", error);
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async function cancelGroupOrderAPI(groupId) {
|
|
311
|
+
try {
|
|
312
|
+
const url = `${types_1.KEEPER_API_BASE_URL}/cancelGroupOrder`;
|
|
313
|
+
const response = await fetch(url, {
|
|
314
|
+
method: "POST",
|
|
315
|
+
headers: {
|
|
316
|
+
Accept: "application/json",
|
|
317
|
+
"Content-Type": "application/json",
|
|
318
|
+
},
|
|
319
|
+
body: JSON.stringify({ groupId }),
|
|
320
|
+
});
|
|
321
|
+
if (!response.ok) {
|
|
322
|
+
const errorData = await response.json();
|
|
323
|
+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
|
324
|
+
}
|
|
325
|
+
return (await response.json());
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
console.error("Error in cancelGroupOrder:", error);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=keeperAPI.js.map
|