@folks-router/js-sdk 0.3.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.
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkV4ANJGMAjs = require('./chunk-V4ANJGMA.js');
4
- require('./chunk-SADXHAXY.js');
3
+ var _chunkI4CVNOLLjs = require('./chunk-I4CVNOLL.js');
4
+ require('./chunk-JULEKH73.js');
5
5
  require('./chunk-WSXBJBEU.js');
6
6
  require('./chunk-IVNVWRCM.js');
7
7
  require('./chunk-MEC4OKES.js');
@@ -9,5 +9,5 @@ require('./chunk-GTEUZNDL.js');
9
9
  require('./chunk-WKV4G7E6.js');
10
10
 
11
11
 
12
- exports.FolksRouterClient = _chunkV4ANJGMAjs.FolksRouterClient;
12
+ exports.FolksRouterClient = _chunkI4CVNOLLjs.FolksRouterClient;
13
13
  //# sourceMappingURL=FolksRouterClient.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FolksRouterClient
3
- } from "./chunk-WPZIOEUM.mjs";
4
- import "./chunk-DHU34JLH.mjs";
3
+ } from "./chunk-6KRDI2UT.mjs";
4
+ import "./chunk-VUENG3B7.mjs";
5
5
  import "./chunk-VGT24JDM.mjs";
6
6
  import "./chunk-YMVA5ZDD.mjs";
7
7
  import "./chunk-CV77XZT3.mjs";
package/dist/checks.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkSADXHAXYjs = require('./chunk-SADXHAXY.js');
3
+ var _chunkJULEKH73js = require('./chunk-JULEKH73.js');
4
4
  require('./chunk-WSXBJBEU.js');
5
5
  require('./chunk-IVNVWRCM.js');
6
6
  require('./chunk-MEC4OKES.js');
@@ -8,5 +8,5 @@ require('./chunk-GTEUZNDL.js');
8
8
  require('./chunk-WKV4G7E6.js');
9
9
 
10
10
 
11
- exports.checkSwapTransactions = _chunkSADXHAXYjs.checkSwapTransactions;
11
+ exports.checkSwapTransactions = _chunkJULEKH73js.checkSwapTransactions;
12
12
  //# sourceMappingURL=checks.js.map
package/dist/checks.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  checkSwapTransactions
3
- } from "./chunk-DHU34JLH.mjs";
3
+ } from "./chunk-VUENG3B7.mjs";
4
4
  import "./chunk-VGT24JDM.mjs";
5
5
  import "./chunk-YMVA5ZDD.mjs";
6
6
  import "./chunk-CV77XZT3.mjs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  checkSwapTransactions
3
- } from "./chunk-DHU34JLH.mjs";
3
+ } from "./chunk-VUENG3B7.mjs";
4
4
 
5
5
  // src/FolksRouterClient.ts
6
6
  import {
@@ -73,4 +73,4 @@ var FolksRouterClient = class {
73
73
  export {
74
74
  FolksRouterClient
75
75
  };
76
- //# sourceMappingURL=chunk-WPZIOEUM.mjs.map
76
+ //# sourceMappingURL=chunk-6KRDI2UT.mjs.map
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
2
 
3
- var _chunkSADXHAXYjs = require('./chunk-SADXHAXY.js');
3
+ var _chunkJULEKH73js = require('./chunk-JULEKH73.js');
4
4
 
5
5
  // src/FolksRouterClient.ts
6
6
 
@@ -65,7 +65,7 @@ var FolksRouterClient = class {
65
65
  const unsignedTxns = data.result.map(
66
66
  (txn) => _algosdk.decodeUnsignedTransaction.call(void 0, Buffer.from(txn, "base64"))
67
67
  );
68
- _chunkSADXHAXYjs.checkSwapTransactions.call(void 0, this.network, unsignedTxns, params, userAddress, slippageBps, swapQuote);
68
+ _chunkJULEKH73js.checkSwapTransactions.call(void 0, this.network, unsignedTxns, params, userAddress, slippageBps, swapQuote);
69
69
  return data.result;
70
70
  }
71
71
  };
@@ -73,4 +73,4 @@ var FolksRouterClient = class {
73
73
 
74
74
 
75
75
  exports.FolksRouterClient = FolksRouterClient;
76
- //# sourceMappingURL=chunk-V4ANJGMA.js.map
76
+ //# sourceMappingURL=chunk-I4CVNOLL.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-V4ANJGMA.js","../src/FolksRouterClient.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACJA;AAGE;AAAA,kCAMK;AACP,4EAAqC;AAQrC,IAAM,SAAA,EAAW,4BAAA;AAEV,IAAM,kBAAA,EAAN,MAAwB;AAAA,EAI7B,WAAA,CAAY,OAAA,EAAkB,MAAA,EAAiB;AAE7C,IAAA,IAAI,IAAA,EAAM,QAAA;AACV,IAAA,GAAA,CAAI,QAAA,IAAA,uBAAA,EAA6B,IAAA,GAAO,UAAA;AACxC,IAAA,IAAA,GAAO,KAAA;AACP,IAAA,GAAA,CAAI,OAAA,IAAW,KAAA,CAAA,EAAW;AACxB,MAAA,IAAA,GAAO,MAAA;AAAA,IACT;AAGA,IAAA,IAAA,CAAK,QAAA,EAAU,OAAA;AACf,IAAA,IAAA,CAAK,IAAA,EAAM,eAAA,CAAM,MAAA,CAAO,EAAE,OAAA,EAAS,GAAA,EAAK,OAAA,EAAS,EAAE,WAAA,EAAa,OAAO,EAAE,CAAC,CAAA;AAAA,EAC5E;AAAA,EAEA,MAAa,iBAAA,CAAkB,WAAA,EAAsC;AACnE,IAAA,MAAM,EAAE,KAAK,EAAA,EAAI,MAAM,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,iBAAA,EAAmB;AAAA,MACrD,MAAA,EAAQ;AAAA,QACN,OAAA,EAAS,IAAA,CAAK,OAAA;AAAA,QACd;AAAA,MACF;AAAA,IACF,CAAC,CAAA;AACD,IAAA,GAAA,CAAI,CAAC,IAAA,CAAK,OAAA,EAAS,MAAM,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA;AAE1C,IAAA,OAAO,IAAA,C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,OAAA,EAAS,MAAM,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA;AAG1C,IAAA,MAAM,aAAA,EAA8B,IAAA,CAAK,MAAA,CAAO,GAAA;AAAA,MAAI,CAAC,GAAA,EAAA,GACnD,gDAAA,MAA0B,CAAO,IAAA,CAAK,GAAA,EAAK,QAAQ,CAAC;AAAA,IACtD,CAAA;AACA,IAAA,oDAAA,IAAsB,CAAK,OAAA,EAAS,YAAA,EAAc,MAAA,EAAQ,WAAA,EAAa,WAAA,EAAa,SAAS,CAAA;AAG7F,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AACF,CAAA;ADtCA;AACA;AACE;AACF,8CAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-V4ANJGMA.js","sourcesContent":[null,"import {\n ABIType,\n decodeAddress,\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\";\nimport {checkSwapTransactions} from \"./checks\";\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 // 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 checkSwapTransactions(this.network, unsignedTxns, params, userAddress, slippageBps, swapQuote);\n\n // return\n return data.result;\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-I4CVNOLL.js","../src/FolksRouterClient.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACJA;AAGE;AAAA,kCAMK;AACP,4EAAqC;AAQrC,IAAM,SAAA,EAAW,4BAAA;AAEV,IAAM,kBAAA,EAAN,MAAwB;AAAA,EAI7B,WAAA,CAAY,OAAA,EAAkB,MAAA,EAAiB;AAE7C,IAAA,IAAI,IAAA,EAAM,QAAA;AACV,IAAA,GAAA,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.js","sourcesContent":[null,"import {\n ABIType,\n decodeAddress,\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\";\nimport {checkSwapTransactions} from \"./checks\";\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 // 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 checkSwapTransactions(this.network, unsignedTxns, params, userAddress, slippageBps, swapQuote);\n\n // return\n return data.result;\n }\n}\n"]}
@@ -19,7 +19,6 @@ var _chunkWKV4G7E6js = require('./chunk-WKV4G7E6.js');
19
19
 
20
20
 
21
21
 
22
-
23
22
  var _algosdk = require('algosdk');
24
23
  function checkSwapTransactions(network, unsignedTxns, params, userAddress, slippageBps, swapQuote) {
25
24
  const { fromAssetId, toAssetId, amount, swapMode } = params;
@@ -32,20 +31,20 @@ function checkSwapTransactions(network, unsignedTxns, params, userAddress, slipp
32
31
  const swapEndTxn = unsignedTxns[unsignedTxns.length - 1];
33
32
  if (sendAssetTxn.reKeyTo !== void 0) throw Error("Unexpected rekey");
34
33
  if (sendAssetTxn.closeRemainderTo !== void 0) throw Error("Unexpected close remainder to");
35
- if (sendAssetTxn.from.publicKey !== _algosdk.decodeAddress.call(void 0, userAddress).publicKey) throw Error("Incorrect sender");
34
+ if (_algosdk.encodeAddress.call(void 0, sendAssetTxn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
36
35
  if (_algosdk.encodeAddress.call(void 0, sendAssetTxn.to.publicKey) !== folksRouterAddr) throw Error("Incorrect receiver");
37
36
  if (!(fromAssetId === 0 && sendAssetTxn.type == _algosdk.TransactionType.pay) && !(fromAssetId === sendAssetTxn.assetIndex && sendAssetTxn.type === _algosdk.TransactionType.axfer))
38
37
  throw Error("Sending incorrect algo/asset");
39
38
  const sendAmount = BigInt(sendAssetTxn.amount);
40
39
  swapForwardTxns.forEach((txn, i) => {
41
- if (txn.from.publicKey !== _algosdk.decodeAddress.call(void 0, userAddress).publicKey) throw Error("Incorrect sender");
40
+ if (_algosdk.encodeAddress.call(void 0, txn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
42
41
  if (txn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
43
42
  if (txn.type !== _algosdk.TransactionType.appl && txn.appOnComplete !== _algosdk.OnApplicationComplete.NoOpOC)
44
43
  throw Error("Incorrect transaction type");
45
44
  const swapForwardSelector = uint8ArrayToHex(txn.appArgs.at(0));
46
45
  if (swapForwardSelector !== getHexSelector("swap_forward")) throw Error("Incorrect selector");
47
46
  });
48
- if (swapEndTxn.from.publicKey !== _algosdk.decodeAddress.call(void 0, userAddress).publicKey) throw Error("Incorrect sender");
47
+ if (_algosdk.encodeAddress.call(void 0, swapEndTxn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
49
48
  if (swapEndTxn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
50
49
  if (swapEndTxn.type !== _algosdk.TransactionType.appl && swapEndTxn.appOnComplete !== _algosdk.OnApplicationComplete.NoOpOC)
51
50
  throw Error("Incorrect transaction type");
@@ -71,4 +70,4 @@ function checkSwapTransactions(network, unsignedTxns, params, userAddress, slipp
71
70
 
72
71
 
73
72
  exports.checkSwapTransactions = checkSwapTransactions;
74
- //# sourceMappingURL=chunk-SADXHAXY.js.map
73
+ //# sourceMappingURL=chunk-JULEKH73.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-JULEKH73.js","../src/checks.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACdA;AACE;AAEA;AACA;AACA;AAEA;AAAA,kCACK;AAOA,SAAS,qBAAA,CACd,OAAA,EACA,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CAAA;AAAA,EACpH;AACA,EAAA,GAAA,CAAI,aAAA,EAAe;AACjB,IAAA,GAAA,CAAI,SAAA,CAAU,YAAA,EAAc,eAAA,IAAmB,UAAA,EAAY,MAAM,KAAA,CAAM,uCAAuC,CAAA;AAC9G,IAAA,GAAA,CAAI,OAAA,IAAW,aAAA,EAAe,MAAM,KAAA,CAAM,yCAAyC,CAAA;AAAA,EACrF;AACF;ADZA;AACA;AACE;AACF,sDAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-JULEKH73.js","sourcesContent":[null,"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"]}
@@ -15,7 +15,6 @@ import {
15
15
  // src/checks.ts
16
16
  import {
17
17
  ABIType,
18
- decodeAddress,
19
18
  encodeAddress,
20
19
  getApplicationAddress,
21
20
  OnApplicationComplete,
@@ -32,20 +31,20 @@ function checkSwapTransactions(network, unsignedTxns, params, userAddress, slipp
32
31
  const swapEndTxn = unsignedTxns[unsignedTxns.length - 1];
33
32
  if (sendAssetTxn.reKeyTo !== void 0) throw Error("Unexpected rekey");
34
33
  if (sendAssetTxn.closeRemainderTo !== void 0) throw Error("Unexpected close remainder to");
35
- if (sendAssetTxn.from.publicKey !== decodeAddress(userAddress).publicKey) throw Error("Incorrect sender");
34
+ if (encodeAddress(sendAssetTxn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
36
35
  if (encodeAddress(sendAssetTxn.to.publicKey) !== folksRouterAddr) throw Error("Incorrect receiver");
37
36
  if (!(fromAssetId === 0 && sendAssetTxn.type == TransactionType.pay) && !(fromAssetId === sendAssetTxn.assetIndex && sendAssetTxn.type === TransactionType.axfer))
38
37
  throw Error("Sending incorrect algo/asset");
39
38
  const sendAmount = BigInt(sendAssetTxn.amount);
40
39
  swapForwardTxns.forEach((txn, i) => {
41
- if (txn.from.publicKey !== decodeAddress(userAddress).publicKey) throw Error("Incorrect sender");
40
+ if (encodeAddress(txn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
42
41
  if (txn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
43
42
  if (txn.type !== TransactionType.appl && txn.appOnComplete !== OnApplicationComplete.NoOpOC)
44
43
  throw Error("Incorrect transaction type");
45
44
  const swapForwardSelector = uint8ArrayToHex(txn.appArgs.at(0));
46
45
  if (swapForwardSelector !== getHexSelector("swap_forward")) throw Error("Incorrect selector");
47
46
  });
48
- if (swapEndTxn.from.publicKey !== decodeAddress(userAddress).publicKey) throw Error("Incorrect sender");
47
+ if (encodeAddress(swapEndTxn.from.publicKey) !== userAddress) throw Error("Incorrect sender");
49
48
  if (swapEndTxn.appIndex !== folksRouterAppId) throw Error("Incorrect application index");
50
49
  if (swapEndTxn.type !== TransactionType.appl && swapEndTxn.appOnComplete !== OnApplicationComplete.NoOpOC)
51
50
  throw Error("Incorrect transaction type");
@@ -71,4 +70,4 @@ function checkSwapTransactions(network, unsignedTxns, params, userAddress, slipp
71
70
  export {
72
71
  checkSwapTransactions
73
72
  };
74
- //# sourceMappingURL=chunk-DHU34JLH.mjs.map
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,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AAqB;AACnC,MAAI,QAAQ,KAAK,QAAQ,EAAE,OAAO,WAAW,QAAS,GAAG,CAAC,CAAE,MAAM,OAAO,SAAS;AAChF,UAAM,MAAM,gCAAgC;AAC9C,QAAM,gBAAgB,QAAQ,KAAK,QAAQ,EAAE,OAAO,WAAW,QAAS,GAAG,CAAC,CAAE;AAG9E,QAAM,iBAAiB,SAAS,UAAU,aAAa,OAAO,WAAW,GAAG,QAAQ;AACpF,MAAI,cAAc;AAChB,QAAI,WAAW,WAAY,OAAM,MAAM,sCAAsC;AAC7E,QAAI,UAAU,cAAc,mBAAmB,cAAe,OAAM,MAAM,wCAAwC;AAAA,EACpH;AACA,MAAI,eAAe;AACjB,QAAI,UAAU,cAAc,mBAAmB,WAAY,OAAM,MAAM,uCAAuC;AAC9G,QAAI,WAAW,cAAe,OAAM,MAAM,yCAAyC;AAAA,EACrF;AACF;","names":[]}
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkV4ANJGMAjs = require('./chunk-V4ANJGMA.js');
3
+ var _chunkI4CVNOLLjs = require('./chunk-I4CVNOLL.js');
4
4
 
5
5
 
6
- var _chunkSADXHAXYjs = require('./chunk-SADXHAXY.js');
6
+ var _chunkJULEKH73js = require('./chunk-JULEKH73.js');
7
7
 
8
8
 
9
9
  var _chunkWSXBJBEUjs = require('./chunk-WSXBJBEU.js');
@@ -38,5 +38,5 @@ var _chunkWKV4G7E6js = require('./chunk-WKV4G7E6.js');
38
38
 
39
39
 
40
40
 
41
- exports.FolksRouterClient = _chunkV4ANJGMAjs.FolksRouterClient; exports.MainnetFolksRouterAppId = _chunkWSXBJBEUjs.MainnetFolksRouterAppId; exports.Network = _chunkMEC4OKESjs.Network; exports.SwapMode = _chunkMEC4OKESjs.SwapMode; exports.TestnetFolksRouterAppId = _chunkIVNVWRCMjs.TestnetFolksRouterAppId; exports.checkSwapTransactions = _chunkSADXHAXYjs.checkSwapTransactions; exports.getReferrerLogicSig = _chunkGRBEXEIPjs.getReferrerLogicSig; exports.prepareClaimReferrerFees = _chunkGRBEXEIPjs.prepareClaimReferrerFees; exports.prepareEnableAssetToBeSwapped = _chunkBVY7JBOWjs.prepareEnableAssetToBeSwapped; exports.prepareReferrerOptIntoAsset = _chunkGRBEXEIPjs.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;
42
42
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  FolksRouterClient
3
- } from "./chunk-WPZIOEUM.mjs";
3
+ } from "./chunk-6KRDI2UT.mjs";
4
4
  import {
5
5
  checkSwapTransactions
6
- } from "./chunk-DHU34JLH.mjs";
6
+ } from "./chunk-VUENG3B7.mjs";
7
7
  import {
8
8
  MainnetFolksRouterAppId
9
9
  } from "./chunk-VGT24JDM.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folks-router/js-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
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 (sendAssetTxn.from.publicKey !== decodeAddress(userAddress).publicKey) 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 (txn.from.publicKey !== decodeAddress(userAddress).publicKey) 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 (swapEndTxn.from.publicKey !== decodeAddress(userAddress).publicKey) 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 f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,EAAA,MAAM,eAAA,EAAiB,uCAAA,SAAS,CAAU,WAAA,EAAa,MAAA,CAAO,WAAW,CAAA,EAAG,yBAAQ,CAAA;AACpF,EAAA,GAAA,CAAI,YAAA,EAAc;AAChB,IAAA,GAAA,CAAI,OAAA,IAAW,UAAA,EAAY,MAAM,KAAA,CAAM,sCAAsC,CAAA;AAC7E,IAAA,GAAA,CAAI,SAAA,CAAU,YAAA,EAAc,eAAA,IAAmB,aAAA,EAAe,MAAM,KAAA,CAAM,wCAAwC,CAAA;AAAA,EACpH;AACA,EAAA,GAAA,CAAI,aAAA,EAAe;AACjB,IAAA,GAAA,CAAI,SAAA,CAAU,YAAA,EAAc,eAAA,IAAmB,UAAA,EAAY,MAAM,KAAA,CAAM,uCAAuC,CAAA;AAC9G,IAAA,GAAA,CAAI,OAAA,IAAW,aAAA,EAAe,MAAM,KAAA,CAAM,yCAAyC,CAAA;AAAA,EACrF;AACF;ADXA;AACA;AACE;AACF,sDAAC","file":"/home/runner/work/folks-router/folks-router/packages/folks-router-js-sdk/dist/chunk-SADXHAXY.js","sourcesContent":[null,"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 (sendAssetTxn.from.publicKey !== decodeAddress(userAddress).publicKey) 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 (txn.from.publicKey !== decodeAddress(userAddress).publicKey) 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 (swapEndTxn.from.publicKey !== decodeAddress(userAddress).publicKey) 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"]}