@folks-router/js-sdk 0.2.0 → 0.3.1

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.
Files changed (65) hide show
  1. package/dist/FolksRouterClient.js +6 -5
  2. package/dist/FolksRouterClient.js.map +1 -1
  3. package/dist/FolksRouterClient.mjs +5 -4
  4. package/dist/checks.d.mts +6 -0
  5. package/dist/checks.d.ts +6 -0
  6. package/dist/checks.js +12 -0
  7. package/dist/checks.js.map +1 -0
  8. package/dist/checks.mjs +12 -0
  9. package/dist/checks.mjs.map +1 -0
  10. package/dist/chunk-6KRDI2UT.mjs +76 -0
  11. package/dist/chunk-6KRDI2UT.mjs.map +1 -0
  12. package/dist/{chunk-7E3GCPFW.js → chunk-BVY7JBOW.js} +4 -4
  13. package/dist/{chunk-7E3GCPFW.js.map → chunk-BVY7JBOW.js.map} +1 -1
  14. package/dist/{chunk-FEVMPFNU.mjs → chunk-GQO2R6ON.mjs} +2 -2
  15. package/dist/{chunk-QLPM3CZI.js → chunk-GRBEXEIP.js} +6 -6
  16. package/dist/{chunk-QLPM3CZI.js.map → chunk-GRBEXEIP.js.map} +1 -1
  17. package/dist/{chunk-HEZCGFMA.js → chunk-GTEUZNDL.js} +8 -2
  18. package/dist/chunk-GTEUZNDL.js.map +1 -0
  19. package/dist/{chunk-JTE7EZPO.mjs → chunk-GWQ2U3UO.mjs} +2 -2
  20. package/dist/chunk-I4CVNOLL.js +76 -0
  21. package/dist/chunk-I4CVNOLL.js.map +1 -0
  22. package/dist/{chunk-ISR3LBP6.js → chunk-IVNVWRCM.js} +2 -2
  23. package/dist/{chunk-ISR3LBP6.js.map → chunk-IVNVWRCM.js.map} +1 -1
  24. package/dist/chunk-JULEKH73.js +73 -0
  25. package/dist/chunk-JULEKH73.js.map +1 -0
  26. package/dist/{chunk-UBBN3ZYC.mjs → chunk-LE66KKNU.mjs} +10 -4
  27. package/dist/chunk-LE66KKNU.mjs.map +1 -0
  28. package/dist/chunk-VGT24JDM.mjs +7 -0
  29. package/dist/{chunk-NW2Q4643.mjs.map → chunk-VGT24JDM.mjs.map} +1 -1
  30. package/dist/chunk-VUENG3B7.mjs +73 -0
  31. package/dist/chunk-VUENG3B7.mjs.map +1 -0
  32. package/dist/{chunk-ELIL4EDW.js → chunk-WSXBJBEU.js} +2 -2
  33. package/dist/{chunk-ELIL4EDW.js.map → chunk-WSXBJBEU.js.map} +1 -1
  34. package/dist/chunk-YMVA5ZDD.mjs +7 -0
  35. package/dist/{chunk-65ESKMQQ.mjs.map → chunk-YMVA5ZDD.mjs.map} +1 -1
  36. package/dist/constants/mainnetConstants.d.mts +1 -1
  37. package/dist/constants/mainnetConstants.d.ts +1 -1
  38. package/dist/constants/mainnetConstants.js +2 -2
  39. package/dist/constants/mainnetConstants.mjs +1 -1
  40. package/dist/constants/testnetConstants.d.mts +1 -1
  41. package/dist/constants/testnetConstants.d.ts +1 -1
  42. package/dist/constants/testnetConstants.js +2 -2
  43. package/dist/constants/testnetConstants.mjs +1 -1
  44. package/dist/index.d.mts +1 -0
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.js +12 -8
  47. package/dist/index.js.map +1 -1
  48. package/dist/index.mjs +12 -8
  49. package/dist/referrer.js +3 -3
  50. package/dist/referrer.mjs +2 -2
  51. package/dist/swap.js +3 -3
  52. package/dist/swap.mjs +2 -2
  53. package/dist/utils.js +2 -2
  54. package/dist/utils.mjs +1 -1
  55. package/package.json +1 -1
  56. package/dist/chunk-65ESKMQQ.mjs +0 -7
  57. package/dist/chunk-CZIXLHLO.mjs +0 -132
  58. package/dist/chunk-CZIXLHLO.mjs.map +0 -1
  59. package/dist/chunk-HEZCGFMA.js.map +0 -1
  60. package/dist/chunk-NW2Q4643.mjs +0 -7
  61. package/dist/chunk-UBBN3ZYC.mjs.map +0 -1
  62. package/dist/chunk-VYXUOE5L.js +0 -132
  63. package/dist/chunk-VYXUOE5L.js.map +0 -1
  64. /package/dist/{chunk-FEVMPFNU.mjs.map → chunk-GQO2R6ON.mjs.map} +0 -0
  65. /package/dist/{chunk-JTE7EZPO.mjs.map → chunk-GWQ2U3UO.mjs.map} +0 -0
@@ -0,0 +1,73 @@
1
+ import {
2
+ MainnetFolksRouterAppId
3
+ } from "./chunk-VGT24JDM.mjs";
4
+ import {
5
+ TestnetFolksRouterAppId
6
+ } from "./chunk-YMVA5ZDD.mjs";
7
+ import {
8
+ ONE_4_DP,
9
+ mulScale
10
+ } from "./chunk-LE66KKNU.mjs";
11
+ import {
12
+ routerABIContract
13
+ } from "./chunk-EYGQH356.mjs";
14
+
15
+ // src/checks.ts
16
+ import {
17
+ ABIType,
18
+ encodeAddress,
19
+ getApplicationAddress,
20
+ OnApplicationComplete,
21
+ TransactionType
22
+ } from "algosdk";
23
+ function checkSwapTransactions(network, unsignedTxns, params, userAddress, slippageBps, swapQuote) {
24
+ const { fromAssetId, toAssetId, amount, swapMode } = params;
25
+ const folksRouterAppId = network == "mainnet" /* MAINNET */ ? MainnetFolksRouterAppId : TestnetFolksRouterAppId;
26
+ const folksRouterAddr = getApplicationAddress(folksRouterAppId);
27
+ const getHexSelector = (method) => Buffer.from(routerABIContract.getMethodByName(method).getSelector()).toString("hex");
28
+ const uint8ArrayToHex = (uint8Array) => Buffer.from(uint8Array).toString("hex");
29
+ const sendAssetTxn = unsignedTxns[0];
30
+ const swapForwardTxns = unsignedTxns.slice(1, -1);
31
+ const swapEndTxn = unsignedTxns[unsignedTxns.length - 1];
32
+ if (sendAssetTxn.reKeyTo !== void 0) throw Error("Unexpected rekey");
33
+ if (sendAssetTxn.closeRemainderTo !== void 0) throw Error("Unexpected close remainder to");
34
+ if (encodeAddress(sendAssetTxn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
35
+ if (encodeAddress(sendAssetTxn.to.publicKey) !== folksRouterAddr) throw Error("Incorrect receiver");
36
+ if (!(fromAssetId === 0 && sendAssetTxn.type == TransactionType.pay) && !(fromAssetId === sendAssetTxn.assetIndex && sendAssetTxn.type === TransactionType.axfer))
37
+ throw Error("Sending incorrect algo/asset");
38
+ const sendAmount = BigInt(sendAssetTxn.amount);
39
+ swapForwardTxns.forEach((txn, i) => {
40
+ if (encodeAddress(txn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
41
+ if (txn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
42
+ if (txn.type !== TransactionType.appl && txn.appOnComplete !== OnApplicationComplete.NoOpOC)
43
+ throw Error("Incorrect transaction type");
44
+ const swapForwardSelector = uint8ArrayToHex(txn.appArgs.at(0));
45
+ if (swapForwardSelector !== getHexSelector("swap_forward")) throw Error("Incorrect selector");
46
+ });
47
+ if (encodeAddress(swapEndTxn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
48
+ if (swapEndTxn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
49
+ if (swapEndTxn.type !== TransactionType.appl && swapEndTxn.appOnComplete !== OnApplicationComplete.NoOpOC)
50
+ throw Error("Incorrect transaction type");
51
+ const swapEndSelector = uint8ArrayToHex(swapEndTxn.appArgs.at(0));
52
+ const isFixedInput = swapEndSelector === getHexSelector("fi_end_swap");
53
+ const isFixedOutput = swapEndSelector === getHexSelector("fo_end_swap");
54
+ if (isFixedInput && swapMode !== "FIXED_INPUT" /* FIXED_INPUT */ || isFixedOutput && swapMode !== "FIXED_OUTPUT" /* FIXED_OUTPUT */)
55
+ throw Error("Incorrect swap mode");
56
+ if (ABIType.from("uint64").decode(swapEndTxn.appArgs.at(1)) !== BigInt(toAssetId))
57
+ throw Error("Receiving incorrect algo/asset");
58
+ const receiveAmount = ABIType.from("uint64").decode(swapEndTxn.appArgs.at(2));
59
+ const slippageAmount = mulScale(swapQuote.quoteAmount, BigInt(slippageBps), ONE_4_DP);
60
+ if (isFixedInput) {
61
+ if (amount !== sendAmount) throw Error("Sending incorrect fixed input amount");
62
+ if (swapQuote.quoteAmount - slippageAmount !== receiveAmount) throw Error("Receiving incorrect fixed input amount");
63
+ }
64
+ if (isFixedOutput) {
65
+ if (swapQuote.quoteAmount + slippageAmount !== sendAmount) throw Error("Sending incorrect fixed output amount");
66
+ if (amount !== receiveAmount) throw Error("Receiving incorrect fixed output amount");
67
+ }
68
+ }
69
+
70
+ export {
71
+ checkSwapTransactions
72
+ };
73
+ //# sourceMappingURL=chunk-VUENG3B7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/checks.ts"],"sourcesContent":["import {\n ABIType,\n decodeAddress,\n encodeAddress,\n getApplicationAddress,\n OnApplicationComplete,\n Transaction,\n TransactionType,\n} from \"algosdk\";\nimport { routerABIContract } from \"./abiContracts\";\nimport { MainnetFolksRouterAppId } from \"./constants/mainnetConstants\";\nimport { TestnetFolksRouterAppId } from \"./constants/testnetConstants\";\nimport { Network, SwapMode, SwapParams, SwapQuote } from \"./types\";\nimport { mulScale, ONE_4_DP } from \"./utils\";\n\nexport function checkSwapTransactions(\n network: Network,\n unsignedTxns: Transaction[],\n params: SwapParams,\n userAddress: string,\n slippageBps: number | bigint,\n swapQuote: SwapQuote,\n) {\n const { fromAssetId, toAssetId, amount, swapMode } = params;\n const folksRouterAppId = network == Network.MAINNET ? MainnetFolksRouterAppId : TestnetFolksRouterAppId;\n const folksRouterAddr = getApplicationAddress(folksRouterAppId);\n const getHexSelector = (method: string) =>\n Buffer.from(routerABIContract.getMethodByName(method).getSelector()).toString(\"hex\");\n const uint8ArrayToHex = (uint8Array: Uint8Array) => Buffer.from(uint8Array).toString(\"hex\");\n\n const sendAssetTxn = unsignedTxns[0]!;\n const swapForwardTxns = unsignedTxns.slice(1, -1)!;\n const swapEndTxn = unsignedTxns[unsignedTxns.length - 1]!;\n\n // send algo/asset\n if (sendAssetTxn.reKeyTo !== undefined) throw Error(\"Unexpected rekey\");\n if (sendAssetTxn.closeRemainderTo !== undefined) throw Error(\"Unexpected close remainder to\");\n if (encodeAddress(sendAssetTxn.from.publicKey) !== userAddress) throw Error(\"Incorrect sender\");\n if (encodeAddress(sendAssetTxn.to.publicKey) !== folksRouterAddr) throw Error(\"Incorrect receiver\");\n if (\n !(fromAssetId === 0 && sendAssetTxn.type == TransactionType.pay) &&\n !(fromAssetId === sendAssetTxn.assetIndex && sendAssetTxn.type === TransactionType.axfer)\n )\n throw Error(\"Sending incorrect algo/asset\");\n const sendAmount = BigInt(sendAssetTxn.amount);\n\n // swap forward txns\n swapForwardTxns.forEach((txn, i) => {\n if (encodeAddress(txn.from.publicKey) !== userAddress) throw Error(\"Incorrect sender\");\n if (txn.appIndex !== folksRouterAppId) throw Error(\"Incorrect application index\");\n if (txn.type !== TransactionType.appl && txn.appOnComplete !== OnApplicationComplete.NoOpOC)\n throw Error(\"Incorrect transaction type\");\n const swapForwardSelector = uint8ArrayToHex(txn.appArgs!.at(0)!);\n if (swapForwardSelector !== getHexSelector(\"swap_forward\")) throw Error(\"Incorrect selector\");\n });\n\n // receive algo/asset\n if (encodeAddress(swapEndTxn.from.publicKey) !== userAddress) throw Error(\"Incorrect sender\");\n if (swapEndTxn.appIndex !== folksRouterAppId) throw Error(\"Incorrect application index\");\n if (swapEndTxn.type !== TransactionType.appl && swapEndTxn.appOnComplete !== OnApplicationComplete.NoOpOC)\n throw Error(\"Incorrect transaction type\");\n const swapEndSelector = uint8ArrayToHex(swapEndTxn.appArgs!.at(0)!);\n const isFixedInput = swapEndSelector === getHexSelector(\"fi_end_swap\");\n const isFixedOutput = swapEndSelector === getHexSelector(\"fo_end_swap\");\n if ((isFixedInput && swapMode !== SwapMode.FIXED_INPUT) || (isFixedOutput && swapMode !== SwapMode.FIXED_OUTPUT))\n throw Error(\"Incorrect swap mode\");\n if (ABIType.from(\"uint64\").decode(swapEndTxn.appArgs!.at(1)!) !== BigInt(toAssetId))\n throw Error(\"Receiving incorrect algo/asset\");\n const receiveAmount = ABIType.from(\"uint64\").decode(swapEndTxn.appArgs!.at(2)!) as bigint;\n\n // check amounts\n const slippageAmount = mulScale(swapQuote.quoteAmount, BigInt(slippageBps), ONE_4_DP);\n if (isFixedInput) {\n if (amount !== sendAmount) throw Error(\"Sending incorrect fixed input amount\");\n if (swapQuote.quoteAmount - slippageAmount !== receiveAmount) throw Error(\"Receiving incorrect fixed input amount\");\n }\n if (isFixedOutput) {\n if (swapQuote.quoteAmount + slippageAmount !== sendAmount) throw Error(\"Sending incorrect fixed output amount\");\n if (amount !== receiveAmount) throw Error(\"Receiving incorrect fixed output amount\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAOA,SAAS,sBACd,SACA,cACA,QACA,aACA,aACA,WACA;AACA,QAAM,EAAE,aAAa,WAAW,QAAQ,SAAS,IAAI;AACrD,QAAM,mBAAmB,qCAA6B,0BAA0B;AAChF,QAAM,kBAAkB,sBAAsB,gBAAgB;AAC9D,QAAM,iBAAiB,CAAC,WACtB,OAAO,KAAK,kBAAkB,gBAAgB,MAAM,EAAE,YAAY,CAAC,EAAE,SAAS,KAAK;AACrF,QAAM,kBAAkB,CAAC,eAA2B,OAAO,KAAK,UAAU,EAAE,SAAS,KAAK;AAE1F,QAAM,eAAe,aAAa,CAAC;AACnC,QAAM,kBAAkB,aAAa,MAAM,GAAG,EAAE;AAChD,QAAM,aAAa,aAAa,aAAa,SAAS,CAAC;AAGvD,MAAI,aAAa,YAAY,OAAW,OAAM,MAAM,kBAAkB;AACtE,MAAI,aAAa,qBAAqB,OAAW,OAAM,MAAM,+BAA+B;AAC5F,MAAI,cAAc,aAAa,KAAK,SAAS,MAAM,YAAa,OAAM,MAAM,kBAAkB;AAC9F,MAAI,cAAc,aAAa,GAAG,SAAS,MAAM,gBAAiB,OAAM,MAAM,oBAAoB;AAClG,MACE,EAAE,gBAAgB,KAAK,aAAa,QAAQ,gBAAgB,QAC5D,EAAE,gBAAgB,aAAa,cAAc,aAAa,SAAS,gBAAgB;AAEnF,UAAM,MAAM,8BAA8B;AAC5C,QAAM,aAAa,OAAO,aAAa,MAAM;AAG7C,kBAAgB,QA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,mBAAmB,WAAY,OAAM,MAAM,uCAAuC;AAC9G,QAAI,WAAW,cAAe,OAAM,MAAM,yCAAyC;AAAA,EACrF;AACF;","names":[]}
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/constants/mainnetConstants.ts
2
- var MainnetFolksRouterAppId = 3179305757;
2
+ var MainnetFolksRouterAppId = 3279848327;
3
3
 
4
4
 
5
5
 
6
6
  exports.MainnetFolksRouterAppId = MainnetFolksRouterAppId;
7
- //# sourceMappingURL=chunk-ELIL4EDW.js.map
7
+ //# sourceMappingURL=chunk-WSXBJBEU.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-ELIL4EDW.js","../src/constants/mainnetConstants.ts"],"names":[],"mappings":"AAAA;ACAA,IAAM,wBAAA,EAA0B,UAAA;ADEhC;AACA;AACE;AACF,0DAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-ELIL4EDW.js","sourcesContent":[null,"const MainnetFolksRouterAppId = 3179305757;\n\nexport { MainnetFolksRouterAppId };\n"]}
1
+ {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-WSXBJBEU.js","../src/constants/mainnetConstants.ts"],"names":[],"mappings":"AAAA;ACAA,IAAM,wBAAA,EAA0B,UAAA;ADEhC;AACA;AACE;AACF,0DAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-WSXBJBEU.js","sourcesContent":[null,"const MainnetFolksRouterAppId = 3279848327;\n\nexport { MainnetFolksRouterAppId };\n"]}
@@ -0,0 +1,7 @@
1
+ // src/constants/testnetConstants.ts
2
+ var TestnetFolksRouterAppId = 748314673;
3
+
4
+ export {
5
+ TestnetFolksRouterAppId
6
+ };
7
+ //# sourceMappingURL=chunk-YMVA5ZDD.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants/testnetConstants.ts"],"sourcesContent":["const TestnetFolksRouterAppId = 744572070;\n\nexport { TestnetFolksRouterAppId };\n"],"mappings":";AAAA,IAAM,0BAA0B;","names":[]}
1
+ {"version":3,"sources":["../src/constants/testnetConstants.ts"],"sourcesContent":["const TestnetFolksRouterAppId = 748314673;\n\nexport { TestnetFolksRouterAppId };\n"],"mappings":";AAAA,IAAM,0BAA0B;","names":[]}
@@ -1,3 +1,3 @@
1
- declare const MainnetFolksRouterAppId = 3179305757;
1
+ declare const MainnetFolksRouterAppId = 3279848327;
2
2
 
3
3
  export { MainnetFolksRouterAppId };
@@ -1,3 +1,3 @@
1
- declare const MainnetFolksRouterAppId = 3179305757;
1
+ declare const MainnetFolksRouterAppId = 3279848327;
2
2
 
3
3
  export { MainnetFolksRouterAppId };
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkELIL4EDWjs = require('../chunk-ELIL4EDW.js');
3
+ var _chunkWSXBJBEUjs = require('../chunk-WSXBJBEU.js');
4
4
 
5
5
 
6
- exports.MainnetFolksRouterAppId = _chunkELIL4EDWjs.MainnetFolksRouterAppId;
6
+ exports.MainnetFolksRouterAppId = _chunkWSXBJBEUjs.MainnetFolksRouterAppId;
7
7
  //# sourceMappingURL=mainnetConstants.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MainnetFolksRouterAppId
3
- } from "../chunk-NW2Q4643.mjs";
3
+ } from "../chunk-VGT24JDM.mjs";
4
4
  export {
5
5
  MainnetFolksRouterAppId
6
6
  };
@@ -1,3 +1,3 @@
1
- declare const TestnetFolksRouterAppId = 744572070;
1
+ declare const TestnetFolksRouterAppId = 748314673;
2
2
 
3
3
  export { TestnetFolksRouterAppId };
@@ -1,3 +1,3 @@
1
- declare const TestnetFolksRouterAppId = 744572070;
1
+ declare const TestnetFolksRouterAppId = 748314673;
2
2
 
3
3
  export { TestnetFolksRouterAppId };
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkISR3LBP6js = require('../chunk-ISR3LBP6.js');
3
+ var _chunkIVNVWRCMjs = require('../chunk-IVNVWRCM.js');
4
4
 
5
5
 
6
- exports.TestnetFolksRouterAppId = _chunkISR3LBP6js.TestnetFolksRouterAppId;
6
+ exports.TestnetFolksRouterAppId = _chunkIVNVWRCMjs.TestnetFolksRouterAppId;
7
7
  //# sourceMappingURL=testnetConstants.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TestnetFolksRouterAppId
3
- } from "../chunk-65ESKMQQ.mjs";
3
+ } from "../chunk-YMVA5ZDD.mjs";
4
4
  export {
5
5
  TestnetFolksRouterAppId
6
6
  };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ export { checkSwapTransactions } from './checks.mjs';
1
2
  export { getReferrerLogicSig, prepareClaimReferrerFees, prepareReferrerOptIntoAsset } from './referrer.mjs';
2
3
  export { prepareEnableAssetToBeSwapped } from './swap.mjs';
3
4
  export { Network, ReferrerGroupTransaction, SwapMode, SwapParams, SwapQuote, SwapTransactions } from './types.mjs';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { checkSwapTransactions } from './checks.js';
1
2
  export { getReferrerLogicSig, prepareClaimReferrerFees, prepareReferrerOptIntoAsset } from './referrer.js';
2
3
  export { prepareEnableAssetToBeSwapped } from './swap.js';
3
4
  export { Network, ReferrerGroupTransaction, SwapMode, SwapParams, SwapQuote, SwapTransactions } from './types.js';
package/dist/index.js CHANGED
@@ -1,29 +1,33 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVYXUOE5Ljs = require('./chunk-VYXUOE5L.js');
3
+ var _chunkI4CVNOLLjs = require('./chunk-I4CVNOLL.js');
4
4
 
5
5
 
6
- var _chunkISR3LBP6js = require('./chunk-ISR3LBP6.js');
6
+ var _chunkJULEKH73js = require('./chunk-JULEKH73.js');
7
7
 
8
8
 
9
+ var _chunkWSXBJBEUjs = require('./chunk-WSXBJBEU.js');
9
10
 
10
11
 
11
- var _chunkQLPM3CZIjs = require('./chunk-QLPM3CZI.js');
12
+ var _chunkIVNVWRCMjs = require('./chunk-IVNVWRCM.js');
12
13
 
13
14
 
14
- var _chunk7E3GCPFWjs = require('./chunk-7E3GCPFW.js');
15
+
16
+
17
+ var _chunkGRBEXEIPjs = require('./chunk-GRBEXEIP.js');
18
+
19
+
20
+ var _chunkBVY7JBOWjs = require('./chunk-BVY7JBOW.js');
15
21
 
16
22
 
17
23
 
18
24
  var _chunkMEC4OKESjs = require('./chunk-MEC4OKES.js');
19
- require('./chunk-HEZCGFMA.js');
25
+ require('./chunk-GTEUZNDL.js');
20
26
 
21
27
 
22
28
  var _chunkWKV4G7E6js = require('./chunk-WKV4G7E6.js');
23
29
 
24
30
 
25
- var _chunkELIL4EDWjs = require('./chunk-ELIL4EDW.js');
26
-
27
31
 
28
32
 
29
33
 
@@ -34,5 +38,5 @@ var _chunkELIL4EDWjs = require('./chunk-ELIL4EDW.js');
34
38
 
35
39
 
36
40
 
37
- exports.FolksRouterClient = _chunkVYXUOE5Ljs.FolksRouterClient; exports.MainnetFolksRouterAppId = _chunkELIL4EDWjs.MainnetFolksRouterAppId; exports.Network = _chunkMEC4OKESjs.Network; exports.SwapMode = _chunkMEC4OKESjs.SwapMode; exports.TestnetFolksRouterAppId = _chunkISR3LBP6js.TestnetFolksRouterAppId; exports.getReferrerLogicSig = _chunkQLPM3CZIjs.getReferrerLogicSig; exports.prepareClaimReferrerFees = _chunkQLPM3CZIjs.prepareClaimReferrerFees; exports.prepareEnableAssetToBeSwapped = _chunk7E3GCPFWjs.prepareEnableAssetToBeSwapped; exports.prepareReferrerOptIntoAsset = _chunkQLPM3CZIjs.prepareReferrerOptIntoAsset; exports.routerABIContract = _chunkWKV4G7E6js.routerABIContract;
41
+ exports.FolksRouterClient = _chunkI4CVNOLLjs.FolksRouterClient; exports.MainnetFolksRouterAppId = _chunkWSXBJBEUjs.MainnetFolksRouterAppId; exports.Network = _chunkMEC4OKESjs.Network; exports.SwapMode = _chunkMEC4OKESjs.SwapMode; exports.TestnetFolksRouterAppId = _chunkIVNVWRCMjs.TestnetFolksRouterAppId; exports.checkSwapTransactions = _chunkJULEKH73js.checkSwapTransactions; exports.getReferrerLogicSig = _chunkGRBEXEIPjs.getReferrerLogicSig; exports.prepareClaimReferrerFees = _chunkGRBEXEIPjs.prepareClaimReferrerFees; exports.prepareEnableAssetToBeSwapped = _chunkBVY7JBOWjs.prepareEnableAssetToBeSwapped; exports.prepareReferrerOptIntoAsset = _chunkGRBEXEIPjs.prepareReferrerOptIntoAsset; exports.routerABIContract = _chunkWKV4G7E6js.routerABIContract;
38
42
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/index.js"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,+qBAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/index.js"}
1
+ {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/index.js"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uvBAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/index.js"}
package/dist/index.mjs CHANGED
@@ -1,34 +1,38 @@
1
1
  import {
2
2
  FolksRouterClient
3
- } from "./chunk-CZIXLHLO.mjs";
3
+ } from "./chunk-6KRDI2UT.mjs";
4
+ import {
5
+ checkSwapTransactions
6
+ } from "./chunk-VUENG3B7.mjs";
7
+ import {
8
+ MainnetFolksRouterAppId
9
+ } from "./chunk-VGT24JDM.mjs";
4
10
  import {
5
11
  TestnetFolksRouterAppId
6
- } from "./chunk-65ESKMQQ.mjs";
12
+ } from "./chunk-YMVA5ZDD.mjs";
7
13
  import {
8
14
  getReferrerLogicSig,
9
15
  prepareClaimReferrerFees,
10
16
  prepareReferrerOptIntoAsset
11
- } from "./chunk-FEVMPFNU.mjs";
17
+ } from "./chunk-GQO2R6ON.mjs";
12
18
  import {
13
19
  prepareEnableAssetToBeSwapped
14
- } from "./chunk-JTE7EZPO.mjs";
20
+ } from "./chunk-GWQ2U3UO.mjs";
15
21
  import {
16
22
  Network,
17
23
  SwapMode
18
24
  } from "./chunk-CV77XZT3.mjs";
19
- import "./chunk-UBBN3ZYC.mjs";
25
+ import "./chunk-LE66KKNU.mjs";
20
26
  import {
21
27
  routerABIContract
22
28
  } from "./chunk-EYGQH356.mjs";
23
- import {
24
- MainnetFolksRouterAppId
25
- } from "./chunk-NW2Q4643.mjs";
26
29
  export {
27
30
  FolksRouterClient,
28
31
  MainnetFolksRouterAppId,
29
32
  Network,
30
33
  SwapMode,
31
34
  TestnetFolksRouterAppId,
35
+ checkSwapTransactions,
32
36
  getReferrerLogicSig,
33
37
  prepareClaimReferrerFees,
34
38
  prepareEnableAssetToBeSwapped,
package/dist/referrer.js CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkQLPM3CZIjs = require('./chunk-QLPM3CZI.js');
6
- require('./chunk-HEZCGFMA.js');
5
+ var _chunkGRBEXEIPjs = require('./chunk-GRBEXEIP.js');
6
+ require('./chunk-GTEUZNDL.js');
7
7
 
8
8
 
9
9
 
10
10
 
11
- exports.getReferrerLogicSig = _chunkQLPM3CZIjs.getReferrerLogicSig; exports.prepareClaimReferrerFees = _chunkQLPM3CZIjs.prepareClaimReferrerFees; exports.prepareReferrerOptIntoAsset = _chunkQLPM3CZIjs.prepareReferrerOptIntoAsset;
11
+ exports.getReferrerLogicSig = _chunkGRBEXEIPjs.getReferrerLogicSig; exports.prepareClaimReferrerFees = _chunkGRBEXEIPjs.prepareClaimReferrerFees; exports.prepareReferrerOptIntoAsset = _chunkGRBEXEIPjs.prepareReferrerOptIntoAsset;
12
12
  //# sourceMappingURL=referrer.js.map
package/dist/referrer.mjs CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  getReferrerLogicSig,
3
3
  prepareClaimReferrerFees,
4
4
  prepareReferrerOptIntoAsset
5
- } from "./chunk-FEVMPFNU.mjs";
6
- import "./chunk-UBBN3ZYC.mjs";
5
+ } from "./chunk-GQO2R6ON.mjs";
6
+ import "./chunk-LE66KKNU.mjs";
7
7
  export {
8
8
  getReferrerLogicSig,
9
9
  prepareClaimReferrerFees,
package/dist/swap.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk7E3GCPFWjs = require('./chunk-7E3GCPFW.js');
4
- require('./chunk-HEZCGFMA.js');
3
+ var _chunkBVY7JBOWjs = require('./chunk-BVY7JBOW.js');
4
+ require('./chunk-GTEUZNDL.js');
5
5
  require('./chunk-WKV4G7E6.js');
6
6
 
7
7
 
8
- exports.prepareEnableAssetToBeSwapped = _chunk7E3GCPFWjs.prepareEnableAssetToBeSwapped;
8
+ exports.prepareEnableAssetToBeSwapped = _chunkBVY7JBOWjs.prepareEnableAssetToBeSwapped;
9
9
  //# sourceMappingURL=swap.js.map
package/dist/swap.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  prepareEnableAssetToBeSwapped
3
- } from "./chunk-JTE7EZPO.mjs";
4
- import "./chunk-UBBN3ZYC.mjs";
3
+ } from "./chunk-GWQ2U3UO.mjs";
4
+ import "./chunk-LE66KKNU.mjs";
5
5
  import "./chunk-EYGQH356.mjs";
6
6
  export {
7
7
  prepareEnableAssetToBeSwapped
package/dist/utils.js CHANGED
@@ -3,11 +3,11 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkHEZCGFMAjs = require('./chunk-HEZCGFMA.js');
6
+ var _chunkGTEUZNDLjs = require('./chunk-GTEUZNDL.js');
7
7
 
8
8
 
9
9
 
10
10
 
11
11
 
12
- exports.ONE_4_DP = _chunkHEZCGFMAjs.ONE_4_DP; exports.mulScale = _chunkHEZCGFMAjs.mulScale; exports.signer = _chunkHEZCGFMAjs.signer; exports.transferAlgoOrAsset = _chunkHEZCGFMAjs.transferAlgoOrAsset;
12
+ exports.ONE_4_DP = _chunkGTEUZNDLjs.ONE_4_DP; exports.mulScale = _chunkGTEUZNDLjs.mulScale; exports.signer = _chunkGTEUZNDLjs.signer; exports.transferAlgoOrAsset = _chunkGTEUZNDLjs.transferAlgoOrAsset;
13
13
  //# sourceMappingURL=utils.js.map
package/dist/utils.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  mulScale,
4
4
  signer,
5
5
  transferAlgoOrAsset
6
- } from "./chunk-UBBN3ZYC.mjs";
6
+ } from "./chunk-LE66KKNU.mjs";
7
7
  export {
8
8
  ONE_4_DP,
9
9
  mulScale,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folks-router/js-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +0,0 @@
1
- // src/constants/testnetConstants.ts
2
- var TestnetFolksRouterAppId = 744572070;
3
-
4
- export {
5
- TestnetFolksRouterAppId
6
- };
7
- //# sourceMappingURL=chunk-65ESKMQQ.mjs.map
@@ -1,132 +0,0 @@
1
- import {
2
- TestnetFolksRouterAppId
3
- } from "./chunk-65ESKMQQ.mjs";
4
- import {
5
- ONE_4_DP,
6
- mulScale
7
- } from "./chunk-UBBN3ZYC.mjs";
8
- import {
9
- routerABIContract
10
- } from "./chunk-EYGQH356.mjs";
11
- import {
12
- MainnetFolksRouterAppId
13
- } from "./chunk-NW2Q4643.mjs";
14
-
15
- // src/FolksRouterClient.ts
16
- import {
17
- ABIType,
18
- decodeUnsignedTransaction,
19
- encodeAddress,
20
- getApplicationAddress,
21
- OnApplicationComplete,
22
- TransactionType
23
- } from "algosdk";
24
- import axios from "axios";
25
- var BASE_URL = "https://api.folksrouter.io";
26
- var FolksRouterClient = class {
27
- constructor(network, apiKey) {
28
- let url = BASE_URL;
29
- if (network === "testnet" /* TESTNET */) url += "/testnet";
30
- url += "/v2";
31
- if (apiKey !== void 0) {
32
- url += "/pro";
33
- }
34
- this.network = network;
35
- this.api = axios.create({ baseURL: url, headers: { "x-api-key": apiKey } });
36
- }
37
- async fetchUserDiscount(userAddress) {
38
- const { data } = await this.api.get("/fetch/discount", {
39
- params: {
40
- network: this.network,
41
- userAddress
42
- }
43
- });
44
- if (!data.success) throw Error(data.errors);
45
- return data.result;
46
- }
47
- async fetchSwapQuote(params, maxGroupSize, feeBps, userFeeDiscount, referrer) {
48
- const { fromAssetId, toAssetId, amount, swapMode } = params;
49
- const { data } = await this.api.get("/fetch/quote", {
50
- params: {
51
- network: this.network,
52
- fromAsset: fromAssetId,
53
- toAsset: toAssetId,
54
- amount,
55
- type: swapMode,
56
- maxGroupSize,
57
- feeBps,
58
- userFeeDiscount,
59
- referrer
60
- }
61
- });
62
- if (!data.success) throw Error(data.errors);
63
- const { quoteAmount, priceImpact, microalgoTxnsFee, txnPayload } = data.result;
64
- return {
65
- quoteAmount: BigInt(quoteAmount),
66
- priceImpact,
67
- microalgoTxnsFee,
68
- txnPayload
69
- };
70
- }
71
- async prepareSwapTransactions(params, userAddress, slippageBps, swapQuote) {
72
- const { fromAssetId, toAssetId, amount, swapMode } = params;
73
- const { data } = await this.api.get("/prepare/swap", {
74
- params: {
75
- userAddress,
76
- slippageBps,
77
- txnPayload: swapQuote.txnPayload
78
- }
79
- });
80
- if (!data.success) throw Error(data.errors);
81
- const unsignedTxns = data.result.map(
82
- (txn) => decodeUnsignedTransaction(Buffer.from(txn, "base64"))
83
- );
84
- const folksRouterAppId = this.network == "mainnet" /* MAINNET */ ? MainnetFolksRouterAppId : TestnetFolksRouterAppId;
85
- const folksRouterAddr = getApplicationAddress(folksRouterAppId);
86
- const getHexSelector = (method) => Buffer.from(routerABIContract.getMethodByName(method).getSelector()).toString("hex");
87
- const uint8ArrayToHex = (uint8Array) => Buffer.from(uint8Array).toString("hex");
88
- const sendAssetTxn = unsignedTxns[0];
89
- const swapForwardTxns = unsignedTxns.slice(1, -1);
90
- const swapEndTxn = unsignedTxns[unsignedTxns.length - 1];
91
- if (sendAssetTxn.reKeyTo !== void 0) throw Error("Unexpected rekey");
92
- if (sendAssetTxn.closeRemainderTo !== void 0) throw Error("Unexpected close remainder to");
93
- if (encodeAddress(sendAssetTxn.to.publicKey) !== folksRouterAddr) throw Error("Incorrect receiver");
94
- if (!(fromAssetId === 0 && sendAssetTxn.type == TransactionType.pay) && !(fromAssetId === sendAssetTxn.assetIndex && sendAssetTxn.type === TransactionType.axfer))
95
- throw Error("Sending incorrect algo/asset");
96
- const sendAmount = BigInt(sendAssetTxn.amount);
97
- swapForwardTxns.forEach((txn, i) => {
98
- if (txn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
99
- if (txn.type !== TransactionType.appl && txn.appOnComplete !== OnApplicationComplete.NoOpOC)
100
- throw Error("Incorrect transaction type");
101
- const swapForwardSelector = uint8ArrayToHex(txn.appArgs.at(0));
102
- if (swapForwardSelector !== getHexSelector("swap_forward")) throw Error("Incorrect selector");
103
- });
104
- if (swapEndTxn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
105
- if (swapEndTxn.type !== TransactionType.appl && swapEndTxn.appOnComplete !== OnApplicationComplete.NoOpOC)
106
- throw Error("Incorrect transaction type");
107
- const swapEndSelector = uint8ArrayToHex(swapEndTxn.appArgs.at(0));
108
- const isFixedInput = swapEndSelector === getHexSelector("fi_end_swap");
109
- const isFixedOutput = swapEndSelector === getHexSelector("fo_end_swap");
110
- if (isFixedInput && swapMode !== "FIXED_INPUT" /* FIXED_INPUT */ || isFixedOutput && swapMode !== "FIXED_OUTPUT" /* FIXED_OUTPUT */)
111
- throw Error("Incorrect swap mode");
112
- if (ABIType.from("uint64").decode(swapEndTxn.appArgs.at(1)) !== BigInt(toAssetId))
113
- throw Error("Receiving incorrect algo/asset");
114
- const receiveAmount = ABIType.from("uint64").decode(swapEndTxn.appArgs.at(2));
115
- const slippageAmount = mulScale(swapQuote.quoteAmount, BigInt(slippageBps), ONE_4_DP);
116
- if (isFixedInput) {
117
- if (amount !== sendAmount) throw Error("Sending incorrect fixed input amount");
118
- if (swapQuote.quoteAmount - slippageAmount !== receiveAmount)
119
- throw Error("Receiving incorrect fixed input amount");
120
- }
121
- if (isFixedOutput) {
122
- if (swapQuote.quoteAmount + slippageAmount !== sendAmount) throw Error("Sending incorrect fixed output amount");
123
- if (amount !== receiveAmount) throw Error("Receiving incorrect fixed output amount");
124
- }
125
- return data.result;
126
- }
127
- };
128
-
129
- export {
130
- FolksRouterClient
131
- };
132
- //# sourceMappingURL=chunk-CZIXLHLO.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/FolksRouterClient.ts"],"sourcesContent":["import {\n ABIType,\n decodeUnsignedTransaction,\n encodeAddress,\n getApplicationAddress,\n OnApplicationComplete,\n Transaction,\n TransactionType,\n} from \"algosdk\";\nimport axios, { AxiosInstance } from \"axios\";\nimport { MainnetFolksRouterAppId } from \"./constants/mainnetConstants\";\nimport { TestnetFolksRouterAppId } from \"./constants/testnetConstants\";\nimport { Network, SwapMode, SwapParams, SwapQuote, SwapTransactions } from \"./types\";\nimport { routerABIContract } from \"./abiContracts\";\nimport { mulScale, ONE_4_DP } from \"./utils\";\n\nconst BASE_URL = \"https://api.folksrouter.io\";\n\nexport class FolksRouterClient {\n private readonly network: Network;\n private readonly api: AxiosInstance;\n\n constructor(network: Network, apiKey?: string) {\n // construct url\n let url = BASE_URL;\n if (network === Network.TESTNET) url += \"/testnet\";\n url += \"/v2\";\n if (apiKey !== undefined) {\n url += \"/pro\";\n }\n\n // set\n this.network = network;\n this.api = axios.create({ baseURL: url, headers: { \"x-api-key\": apiKey } });\n }\n\n public async fetchUserDiscount(userAddress: string): Promise<number> {\n const { data } = await this.api.get(\"/fetch/discount\", {\n params: {\n network: this.network,\n userAddress,\n },\n });\n if (!data.success) throw Error(data.errors);\n\n return data.result;\n }\n\n public async fetchSwapQuote(\n params: SwapParams,\n maxGroupSize?: number,\n feeBps?: number | bigint,\n userFeeDiscount?: number | bigint,\n referrer?: string,\n ): Promise<SwapQuote> {\n const { fromAssetId, toAssetId, amount, swapMode } = params;\n\n const { data } = await this.api.get(\"/fetch/quote\", {\n params: {\n network: this.network,\n fromAsset: fromAssetId,\n toAsset: toAssetId,\n amount,\n type: swapMode,\n maxGroupSize,\n feeBps,\n userFeeDiscount,\n referrer,\n },\n });\n if (!data.success) throw Error(data.errors);\n\n const { quoteAmount, priceImpact, microalgoTxnsFee, txnPayload } = data.result;\n\n return {\n quoteAmount: BigInt(quoteAmount),\n priceImpact,\n microalgoTxnsFee,\n txnPayload,\n };\n }\n\n public async prepareSwapTransactions(\n params: SwapParams,\n userAddress: string,\n slippageBps: number | bigint,\n swapQuote: SwapQuote,\n ): Promise<SwapTransactions> {\n const { fromAssetId, toAssetId, amount, swapMode } = params;\n\n // fetch transactions\n const { data } = await this.api.get(\"/prepare/swap\", {\n params: {\n userAddress,\n slippageBps,\n txnPayload: swapQuote.txnPayload,\n },\n });\n if (!data.success) throw Error(data.errors);\n\n // check transactions\n const unsignedTxns: Transaction[] = data.result.map((txn: string) =>\n decodeUnsignedTransaction(Buffer.from(txn, \"base64\")),\n );\n const folksRouterAppId = this.network == Network.MAINNET ? MainnetFolksRouterAppId : TestnetFolksRouterAppId;\n const folksRouterAddr = getApplicationAddress(folksRouterAppId);\n const getHexSelector = (method: string) =>\n Buffer.from(routerABIContract.getMethodByName(method).getSelector()).toString(\"hex\");\n const uint8ArrayToHex = (uint8Array: Uint8Array) => Buffer.from(uint8Array).toString(\"hex\");\n\n const sendAssetTxn = unsignedTxns[0]!;\n const swapForwardTxns = unsignedTxns.slice(1, -1)!;\n const swapEndTxn = unsignedTxns[unsignedTxns.length - 1]!;\n\n // send algo/asset\n if (sendAssetTxn.reKeyTo !== undefined) throw Error(\"Unexpected rekey\");\n if (sendAssetTxn.closeRemainderTo !== undefined) throw Error(\"Unexpected close remainder to\");\n if (encodeAddress(sendAssetTxn.to.publicKey) !== folksRouterAddr) throw Error(\"Incorrect receiver\");\n if (\n !(fromAssetId === 0 && sendAssetTxn.type == TransactionType.pay) &&\n !(fromAssetId === sendAssetTxn.assetIndex && sendAssetTxn.type === TransactionType.axfer)\n )\n throw Error(\"Sending incorrect algo/asset\");\n const sendAmount = BigInt(sendAssetTxn.amount);\n\n // swap forward txns\n swapForwardTxns.forEach((txn, i) => {\n if (txn.appIndex !== folksRouterAppId) throw Error(\"Incorrect application index\");\n if (txn.type !== TransactionType.appl && txn.appOnComplete !== OnApplicationComplete.NoOpOC)\n throw Error(\"Incorrect transaction type\");\n const swapForwardSelector = uint8ArrayToHex(txn.appArgs!.at(0)!);\n if (swapForwardSelector !== getHexSelector(\"swap_forward\")) throw Error(\"Incorrect selector\");\n });\n\n // receive algo/asset\n if (swapEndTxn.appIndex !== folksRouterAppId) throw Error(\"Incorrect application index\");\n if (swapEndTxn.type !== TransactionType.appl && swapEndTxn.appOnComplete !== OnApplicationComplete.NoOpOC)\n throw Error(\"Incorrect transaction type\");\n const swapEndSelector = uint8ArrayToHex(swapEndTxn.appArgs!.at(0)!);\n const isFixedInput = swapEndSelector === getHexSelector(\"fi_end_swap\");\n const isFixedOutput = swapEndSelector === getHexSelector(\"fo_end_swap\");\n if ((isFixedInput && swapMode !== SwapMode.FIXED_INPUT) || (isFixedOutput && swapMode !== SwapMode.FIXED_OUTPUT))\n throw Error(\"Incorrect swap mode\");\n if (ABIType.from(\"uint64\").decode(swapEndTxn.appArgs!.at(1)!) !== BigInt(toAssetId))\n throw Error(\"Receiving incorrect algo/asset\");\n const receiveAmount = ABIType.from(\"uint64\").decode(swapEndTxn.appArgs!.at(2)!) as bigint;\n\n // check amounts\n const slippageAmount = mulScale(swapQuote.quoteAmount, BigInt(slippageBps), ONE_4_DP);\n if (isFixedInput) {\n if (amount !== sendAmount) throw Error(\"Sending incorrect fixed input amount\");\n if (swapQuote.quoteAmount - slippageAmount !== receiveAmount)\n throw Error(\"Receiving incorrect fixed input amount\");\n }\n if (isFixedOutput) {\n if (swapQuote.quoteAmount + slippageAmount !== sendAmount) throw Error(\"Sending incorrect fixed output amount\");\n if (amount !== receiveAmount) throw Error(\"Receiving incorrect fixed output amount\");\n }\n\n // return\n return data.result;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,OAAO,WAA8B;AAOrC,IAAM,WAAW;AAEV,IAAM,oBAAN,MAAwB;AAAA,EAI7B,YAAY,SAAkB,QAAiB;AAE7C,QAAI,MAAM;AACV,QAAI,oCAA6B,QAAO;AACxC,WAAO;AACP,QAAI,WAAW,QAAW;AACxB,aAAO;AAAA,IACT;AAGA,SAAK,UAAU;AACf,SAAK,MAAM,MAAM,OAAO,EAAE,SAAS,KAAK,SAAS,EAAE,aAAa,OAAO,EAAE,CAAC;AAAA,EAC5E;AAAA,EAEA,MAAa,kBAAkB,aAAsC;AACnE,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,mBAAmB;AAAA,MACr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,iBAAiB;AAC3E,YAAM,MAAM,qBAAqB;AACnC,QAAI,QAAQ,KAAK,QAAQ,EAAE,OAAO,WAAW,QAAS,GAAG,CAAC,CAAE,MAAM,OAAO,SAAS;AAChF,YAAM,MAAM,gCAAgC;AAC9C,UAAM,gBAAgB,QAAQ,KAAK,QAAQ,EAAE,OAAO,WAAW,QAAS,GAAG,CAAC,CAAE;AAG9E,UAAM,iBAAiB,SAAS,UAAU,aAAa,OAAO,WAAW,GAAG,QAAQ;AACpF,QAAI,cAAc;AAChB,UAAI,WAAW,WAAY,OAAM,MAAM,sCAAsC;AAC7E,UAAI,UAAU,cAAc,mBAAmB;AAC7C,cAAM,MAAM,wCAAwC;AAAA,IACxD;AACA,QAAI,eAAe;AACjB,UAAI,UAAU,cAAc,mBAAmB,WAAY,OAAM,MAAM,uCAAuC;AAC9G,UAAI,WAAW,cAAe,OAAM,MAAM,yCAAyC;AAAA,IACrF;AAGA,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-HEZCGFMA.js","../src/utils.ts"],"names":[],"mappings":"AAAA;ACAA;AACE;AACA;AAAA,kCAGK;AAEP,IAAM,OAAA,EAAS,MAAA,CAAA,EAAA,GAAY,CAAC,CAAA;AAK5B,SAAS,mBAAA,CACP,OAAA,EACA,IAAA,EACA,EAAA,EACA,MAAA,EACA,MAAA,EACa;AACb,EAAA,OAAO,QAAA,IAAY,EAAA,EACf,8DAAA,IAAwC,EAAM,EAAA,EAAI,KAAA,CAAA,EAAW,KAAA,CAAA,EAAW,MAAA,EAAQ,KAAA,CAAA,EAAW,OAAA,EAAS,MAAM,EAAA,EAC1G,wDAAA,IAAkC,EAAM,EAAA,EAAI,MAAA,EAAQ,KAAA,CAAA,EAAW,KAAA,CAAA,EAAW,MAAM,CAAA;AACtF;AAEA,IAAM,SAAA,EAAW,MAAA,CAAO,GAAG,CAAA;AAE3B,SAAS,QAAA,CAAS,EAAA,EAAY,EAAA,EAAY,KAAA,EAAuB;AAC/D,EAAA,OAAQ,GAAA,EAAK,GAAA,EAAM,KAAA;AACrB;ADfA;AACA;AACE;AACA;AACA;AACA;AACF,qIAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-HEZCGFMA.js","sourcesContent":[null,"import {\n makeAssetTransferTxnWithSuggestedParams,\n makePaymentTxnWithSuggestedParams,\n SuggestedParams,\n Transaction,\n} from \"algosdk\";\n\nconst signer = async () => [];\n\n/**\n * Transfer algo or asset. 0 assetId indicates algo transfer, else asset transfer.\n */\nfunction transferAlgoOrAsset(\n assetId: number,\n from: string,\n to: string,\n amount: number | bigint,\n params: SuggestedParams,\n): Transaction {\n return assetId !== 0\n ? makeAssetTransferTxnWithSuggestedParams(from, to, undefined, undefined, amount, undefined, assetId, params)\n : makePaymentTxnWithSuggestedParams(from, to, amount, undefined, undefined, params);\n}\n\nconst ONE_4_DP = BigInt(1e4);\n\nfunction mulScale(n1: bigint, n2: bigint, scale: bigint): bigint {\n return (n1 * n2) / scale;\n}\n\nexport { signer, transferAlgoOrAsset, ONE_4_DP, mulScale };\n"]}
@@ -1,7 +0,0 @@
1
- // src/constants/mainnetConstants.ts
2
- var MainnetFolksRouterAppId = 3179305757;
3
-
4
- export {
5
- MainnetFolksRouterAppId
6
- };
7
- //# sourceMappingURL=chunk-NW2Q4643.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import {\n makeAssetTransferTxnWithSuggestedParams,\n makePaymentTxnWithSuggestedParams,\n SuggestedParams,\n Transaction,\n} from \"algosdk\";\n\nconst signer = async () => [];\n\n/**\n * Transfer algo or asset. 0 assetId indicates algo transfer, else asset transfer.\n */\nfunction transferAlgoOrAsset(\n assetId: number,\n from: string,\n to: string,\n amount: number | bigint,\n params: SuggestedParams,\n): Transaction {\n return assetId !== 0\n ? makeAssetTransferTxnWithSuggestedParams(from, to, undefined, undefined, amount, undefined, assetId, params)\n : makePaymentTxnWithSuggestedParams(from, to, amount, undefined, undefined, params);\n}\n\nconst ONE_4_DP = BigInt(1e4);\n\nfunction mulScale(n1: bigint, n2: bigint, scale: bigint): bigint {\n return (n1 * n2) / scale;\n}\n\nexport { signer, transferAlgoOrAsset, ONE_4_DP, mulScale };\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,IAAM,SAAS,YAAY,CAAC;AAK5B,SAAS,oBACP,SACA,MACA,IACA,QACA,QACa;AACb,SAAO,YAAY,IACf,wCAAwC,MAAM,IAAI,QAAW,QAAW,QAAQ,QAAW,SAAS,MAAM,IAC1G,kCAAkC,MAAM,IAAI,QAAQ,QAAW,QAAW,MAAM;AACtF;AAEA,IAAM,WAAW,OAAO,GAAG;AAE3B,SAAS,SAAS,IAAY,IAAY,OAAuB;AAC/D,SAAQ,KAAK,KAAM;AACrB;","names":[]}