@keetanetwork/anchor 0.0.12 → 0.0.13
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/lib/utils/json.d.ts +2 -2
- package/lib/utils/json.d.ts.map +1 -1
- package/lib/utils/json.js.map +1 -1
- package/npm-shrinkwrap.json +2 -8
- package/package.json +1 -2
- package/services/fx/client.d.ts +1 -0
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +72 -72
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.d.ts +23 -14
- package/services/fx/common.d.ts.map +1 -1
- package/services/fx/common.js +177 -1
- package/services/fx/common.js.map +1 -1
- package/services/fx/server.d.ts +13 -4
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +58 -151
- package/services/fx/server.js.map +1 -1
package/lib/utils/json.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { JSONSerializable } from '@keetanetwork/keetanet-client/lib/utils/conversion.js';
|
|
2
|
-
export type { JSONSerializable };
|
|
1
|
+
import type { JSONSerializable, ToJSONSerializable } from '@keetanetwork/keetanet-client/lib/utils/conversion.js';
|
|
2
|
+
export type { JSONSerializable, ToJSONSerializable };
|
|
3
3
|
type ConvertToJSONOptions = {
|
|
4
4
|
searchable?: boolean;
|
|
5
5
|
};
|
package/lib/utils/json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/json.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uDAAuD,CAAC;
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/json.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,uDAAuD,CAAC;AAClH,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC;AA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CAAC;AACN,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,qBAAqB;CACrB,CAAC","sourcesContent":["import { types as nodeUtilsTypes } from 'util';\nimport { Buffer } from './buffer.js';\nimport type { JSONSerializable } from '@keetanetwork/keetanet-client/lib/utils/conversion.js';\nexport type { JSONSerializable };\n\ntype ConvertToJSONOptions = {\n\tsearchable?: boolean;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction convertToJSONReplacer(this: any, key: string, jsonItem: unknown, options: ConvertToJSONOptions = { searchable: false }): JSONSerializable {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n\tconst item = this[key];\n\n\tswitch (typeof item) {\n\t\tcase 'string':\n\t\tcase 'boolean':\n\t\t\treturn(item);\n\t\tcase 'undefined':\n\t\t\treturn(String(item));\n\t\tcase 'symbol':\n\t\t\treturn(`[${item.toString()}]`);\n\t\tcase 'function':\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tif ('toString' in item && typeof item.toString === 'function') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n\t\t\t\tconst itemString: string = item.toString();\n\t\t\t\tif (itemString.toString().startsWith('class ')) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\treturn(`[Class ${item.name}]`);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\treturn(`[Function ${item.name}]`);\n\t\tcase 'bigint':\n\t\t\tif (item < BigInt(Number.MAX_SAFE_INTEGER) && item > BigInt(Number.MIN_SAFE_INTEGER)) {\n\t\t\t\treturn(Number(item.toString()));\n\t\t\t} else {\n\t\t\t\tif (item < 0n) {\n\t\t\t\t\tconst absItem = item * -1n;\n\t\t\t\t\tif (options.searchable) {\n\t\t\t\t\t\treturn(`-0x${absItem.toString(16)}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn(`-0x${absItem.toString(16)}[=>${item.toString(10)}]`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (options.searchable) {\n\t\t\t\t\t\treturn(`0x${item.toString(16)}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn(`0x${item.toString(16)}[=>${item.toString(10)}]`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tcase 'number':\n\t\t\tif (options.searchable) {\n\t\t\t\tif (isNaN(item)) {\n\t\t\t\t\treturn('#NaN');\n\t\t\t\t}\n\n\t\t\t\tif (item === -Infinity) {\n\t\t\t\t\treturn('#-Inf');\n\t\t\t\t}\n\n\t\t\t\tif (item === Infinity) {\n\t\t\t\t\treturn('#Inf');\n\t\t\t\t}\n\n\t\t\t\treturn(item);\n\t\t\t}\n\n\t\t\tif (item === -Infinity) {\n\t\t\t\treturn('-∞');\n\t\t\t}\n\t\t\tif (item === Infinity) {\n\t\t\t\treturn('∞');\n\t\t\t}\n\n\t\t\tif (isNaN(item)) {\n\t\t\t\treturn('#NaN');\n\t\t\t}\n\n\t\t\treturn(item);\n\t\tdefault:\n\t\t\t/* We handle other cases outside of this switch */\n\t\t\tbreak;\n\t}\n\n\tif (item === undefined) {\n\t\treturn(String(item));\n\t}\n\n\tif (item === null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn(item);\n\t}\n\n\tif (Array.isArray(item)) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn(item);\n\t}\n\n\tif (nodeUtilsTypes.isDate(item)) {\n\t\tif (options.searchable) {\n\t\t\treturn(item.toISOString());\n\t\t}\n\n\t\treturn(`[Date ${item.toISOString()}]`);\n\t}\n\n\tif (Buffer.isBuffer(item)) {\n\t\treturn(item.toString('base64'));\n\t}\n\n\tif (nodeUtilsTypes.isArrayBuffer(item)) {\n\t\treturn(Buffer.from(item).toString('base64'));\n\t}\n\n\tif (item instanceof Promise) {\n\t\treturn('[Promise]');\n\t}\n\n\tif (!(item instanceof Object)) {\n\t\tthrow(new Error(`internal error: Unknown type ${typeof item}`));\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-member-access\n\tif ('publicKeyString' in item && typeof item.publicKeyString === 'object' && item.publicKeyString !== null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-member-access\n\t\tif ('get' in item.publicKeyString && item.publicKeyString.get !== undefined) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tif (typeof item.publicKeyString.get === 'function') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-inferrable-types\n\t\t\t\tlet addToString: string = 'UNKNOWN';\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\tif ('hasPrivateKey' in item && typeof item.hasPrivateKey === 'boolean') {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst hasPrivateKey = item.hasPrivateKey;\n\t\t\t\t\tif (hasPrivateKey) {\n\t\t\t\t\t\taddToString = 'PRIVATE';\n\t\t\t\t\t} else {\n\t\t\t\t\t\taddToString = 'PUBLIC';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n\t\t\t\treturn(`[Account ${item.publicKeyString.get()} ${addToString}]`);\n\t\t\t}\n\t\t}\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\tif ('toJSON' in item && typeof item.toJSON === 'function') {\n\t\t/*\n\t\t * No need to call toJSON() if it's a function, as it will\n\t\t * be called by the JSON.stringify() function and passed in\n\t\t * as the second argument to this function (jsonItem).\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-explicit-any,@typescript-eslint/consistent-type-assertions\n\t\treturn(jsonItem as any);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\tif ('constructor' in item && typeof item.constructor === 'function') {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-member-access\n\t\tif ('name' in item.constructor && typeof item.constructor.name === 'string') {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n\t\t\tconst typeID = item.constructor.name;\n\t\t\tif (typeID !== 'Object') {\n\t\t\t\treturn(`[Instance ${typeID}]`);\n\t\t\t}\n\t\t}\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\treturn(item);\n}\n\nexport function convertToJSON(input: unknown, options?: Parameters<typeof convertToJSONReplacer>[2]): JSONSerializable {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-explicit-any\n\treturn(JSON.parse(JSON.stringify(input, function(this: any, key: string, value: unknown) {\n\t\treturn(convertToJSONReplacer.call(this, key, value, options));\n\t})));\n}\n\n/** @internal */\nexport const _Testing = {\n\tconvertToJSONReplacer\n};\n"]}
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/lib/utils/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAQrC,8DAA8D;AAC9D,SAAS,qBAAqB,CAAY,GAAW,EAAE,QAAiB,EAAE,UAAgC,EAAE,UAAU,EAAE,KAAK,EAAE;IAC9H,8GAA8G;IAC9G,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAEvB,QAAQ,OAAO,IAAI,EAAE,CAAC;QAC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AAM,GAAG,CAAC,CAAC;YAChC,CAAC;QACF,CAAC;IACF,CAAC;IAED,+DAA+D;IAC/D,OAAM,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,OAAqD;IAClG,kGAAkG;IAClG,OAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,UAAoB,GAAW,EAAE,KAAc;QACtF,OAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC,CAAC,CAAC;AACN,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,qBAAqB;CACrB,CAAC","sourcesContent":["import { types as nodeUtilsTypes } from 'util';\nimport { Buffer } from './buffer.js';\nimport type { JSONSerializable, ToJSONSerializable } from '@keetanetwork/keetanet-client/lib/utils/conversion.js';\nexport type { JSONSerializable, ToJSONSerializable };\n\ntype ConvertToJSONOptions = {\n\tsearchable?: boolean;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction convertToJSONReplacer(this: any, key: string, jsonItem: unknown, options: ConvertToJSONOptions = { searchable: false }): JSONSerializable {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n\tconst item = this[key];\n\n\tswitch (typeof item) {\n\t\tcase 'string':\n\t\tcase 'boolean':\n\t\t\treturn(item);\n\t\tcase 'undefined':\n\t\t\treturn(String(item));\n\t\tcase 'symbol':\n\t\t\treturn(`[${item.toString()}]`);\n\t\tcase 'function':\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tif ('toString' in item && typeof item.toString === 'function') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n\t\t\t\tconst itemString: string = item.toString();\n\t\t\t\tif (itemString.toString().startsWith('class ')) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\treturn(`[Class ${item.name}]`);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\treturn(`[Function ${item.name}]`);\n\t\tcase 'bigint':\n\t\t\tif (item < BigInt(Number.MAX_SAFE_INTEGER) && item > BigInt(Number.MIN_SAFE_INTEGER)) {\n\t\t\t\treturn(Number(item.toString()));\n\t\t\t} else {\n\t\t\t\tif (item < 0n) {\n\t\t\t\t\tconst absItem = item * -1n;\n\t\t\t\t\tif (options.searchable) {\n\t\t\t\t\t\treturn(`-0x${absItem.toString(16)}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn(`-0x${absItem.toString(16)}[=>${item.toString(10)}]`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (options.searchable) {\n\t\t\t\t\t\treturn(`0x${item.toString(16)}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn(`0x${item.toString(16)}[=>${item.toString(10)}]`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tcase 'number':\n\t\t\tif (options.searchable) {\n\t\t\t\tif (isNaN(item)) {\n\t\t\t\t\treturn('#NaN');\n\t\t\t\t}\n\n\t\t\t\tif (item === -Infinity) {\n\t\t\t\t\treturn('#-Inf');\n\t\t\t\t}\n\n\t\t\t\tif (item === Infinity) {\n\t\t\t\t\treturn('#Inf');\n\t\t\t\t}\n\n\t\t\t\treturn(item);\n\t\t\t}\n\n\t\t\tif (item === -Infinity) {\n\t\t\t\treturn('-∞');\n\t\t\t}\n\t\t\tif (item === Infinity) {\n\t\t\t\treturn('∞');\n\t\t\t}\n\n\t\t\tif (isNaN(item)) {\n\t\t\t\treturn('#NaN');\n\t\t\t}\n\n\t\t\treturn(item);\n\t\tdefault:\n\t\t\t/* We handle other cases outside of this switch */\n\t\t\tbreak;\n\t}\n\n\tif (item === undefined) {\n\t\treturn(String(item));\n\t}\n\n\tif (item === null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn(item);\n\t}\n\n\tif (Array.isArray(item)) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn(item);\n\t}\n\n\tif (nodeUtilsTypes.isDate(item)) {\n\t\tif (options.searchable) {\n\t\t\treturn(item.toISOString());\n\t\t}\n\n\t\treturn(`[Date ${item.toISOString()}]`);\n\t}\n\n\tif (Buffer.isBuffer(item)) {\n\t\treturn(item.toString('base64'));\n\t}\n\n\tif (nodeUtilsTypes.isArrayBuffer(item)) {\n\t\treturn(Buffer.from(item).toString('base64'));\n\t}\n\n\tif (item instanceof Promise) {\n\t\treturn('[Promise]');\n\t}\n\n\tif (!(item instanceof Object)) {\n\t\tthrow(new Error(`internal error: Unknown type ${typeof item}`));\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-member-access\n\tif ('publicKeyString' in item && typeof item.publicKeyString === 'object' && item.publicKeyString !== null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-member-access\n\t\tif ('get' in item.publicKeyString && item.publicKeyString.get !== undefined) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tif (typeof item.publicKeyString.get === 'function') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-inferrable-types\n\t\t\t\tlet addToString: string = 'UNKNOWN';\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\tif ('hasPrivateKey' in item && typeof item.hasPrivateKey === 'boolean') {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst hasPrivateKey = item.hasPrivateKey;\n\t\t\t\t\tif (hasPrivateKey) {\n\t\t\t\t\t\taddToString = 'PRIVATE';\n\t\t\t\t\t} else {\n\t\t\t\t\t\taddToString = 'PUBLIC';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n\t\t\t\treturn(`[Account ${item.publicKeyString.get()} ${addToString}]`);\n\t\t\t}\n\t\t}\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\tif ('toJSON' in item && typeof item.toJSON === 'function') {\n\t\t/*\n\t\t * No need to call toJSON() if it's a function, as it will\n\t\t * be called by the JSON.stringify() function and passed in\n\t\t * as the second argument to this function (jsonItem).\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-explicit-any,@typescript-eslint/consistent-type-assertions\n\t\treturn(jsonItem as any);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\tif ('constructor' in item && typeof item.constructor === 'function') {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-member-access\n\t\tif ('name' in item.constructor && typeof item.constructor.name === 'string') {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n\t\t\tconst typeID = item.constructor.name;\n\t\t\tif (typeID !== 'Object') {\n\t\t\t\treturn(`[Instance ${typeID}]`);\n\t\t\t}\n\t\t}\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\treturn(item);\n}\n\nexport function convertToJSON(input: unknown, options?: Parameters<typeof convertToJSONReplacer>[2]): JSONSerializable {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-explicit-any\n\treturn(JSON.parse(JSON.stringify(input, function(this: any, key: string, value: unknown) {\n\t\treturn(convertToJSONReplacer.call(this, key, value, options));\n\t})));\n}\n\n/** @internal */\nexport const _Testing = {\n\tconvertToJSONReplacer\n};\n"]}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@keetanetwork/anchor",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.13",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@keetanetwork/currency-info": "1.2.5",
|
|
13
13
|
"@keetanetwork/keetanet-client": "0.14.8",
|
|
14
|
-
"decimal.js": "10.6.0",
|
|
15
14
|
"typia": "9.5.0"
|
|
16
15
|
},
|
|
17
16
|
"engines": {
|
|
@@ -693,11 +692,6 @@
|
|
|
693
692
|
"license": "MIT",
|
|
694
693
|
"optional": true
|
|
695
694
|
},
|
|
696
|
-
"node_modules/decimal.js": {
|
|
697
|
-
"version": "10.6.0",
|
|
698
|
-
"integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==",
|
|
699
|
-
"license": "MIT"
|
|
700
|
-
},
|
|
701
695
|
"node_modules/defaults": {
|
|
702
696
|
"version": "1.0.4",
|
|
703
697
|
"integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "KeetaNetwork Network Anchor",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@keetanetwork/currency-info": "1.2.5",
|
|
26
26
|
"@keetanetwork/keetanet-client": "0.14.8",
|
|
27
|
-
"decimal.js": "10.6.0",
|
|
28
27
|
"typia": "9.5.0"
|
|
29
28
|
},
|
|
30
29
|
"engines": {
|
package/services/fx/client.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ declare class KeetaFXAnchorBase {
|
|
|
79
79
|
constructor(config: KeetaFXAnchorBaseConfig);
|
|
80
80
|
}
|
|
81
81
|
declare class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
82
|
+
#private;
|
|
82
83
|
readonly serviceInfo: KeetaFXServiceInfo;
|
|
83
84
|
readonly providerID: ProviderID;
|
|
84
85
|
readonly conversion: ConversionInputCanonical;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/fx/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/fx/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EACX,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,uBAAuB,CAAC;AAIpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAO9D,OAAO,KAAK,EACX,eA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AAyB,EAAE,GAAG,IAAI,CAAC;IAelI,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,iCAAiC,EAAE,GAAG,IAAI,CAAC;IAyBzH,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,8BAA8B,EAAE,GAAG,IAAI,CAAC;CAwCzH;AAED,eAAe,mBAAmB,CAAC"}
|
package/services/fx/client.js
CHANGED
|
@@ -1,36 +1,22 @@
|
|
|
1
|
-
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
2
1
|
import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
|
|
3
|
-
import { createAssert, createIs } from 'typia';
|
|
4
|
-
import { Decimal } from 'decimal.js';
|
|
5
2
|
import { getDefaultResolver } from '../../config.js';
|
|
6
3
|
import { Buffer } from '../../lib/utils/buffer.js';
|
|
7
4
|
import crypto from '../../lib/utils/crypto.js';
|
|
8
5
|
import { validateURL } from '../../lib/utils/url.js';
|
|
6
|
+
import { assertKeetaNetTokenPublicKeyString, isKeetaFXAnchorEstimateResponse, isKeetaFXAnchorExchangeResponse, isKeetaFXAnchorQuoteResponse } from './common.js';
|
|
9
7
|
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
10
8
|
function typedFxServiceEntries(obj) {
|
|
11
9
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
12
10
|
return Object.entries(obj);
|
|
13
11
|
}
|
|
14
12
|
const KeetaFXAnchorClientAccessToken = Symbol('KeetaFXAnchorClientAccessToken');
|
|
15
|
-
const assertKeetaNetTokenPublicKeyString = (() => { const __is = input => "string" === typeof input && (RegExp(/^keeta_am(.*)/).test(input) || RegExp(/^keeta_an(.*)/).test(input) || RegExp(/^keeta_ao(.*)/).test(input) || RegExp(/^keeta_ap(.*)/).test(input) || RegExp(/^tyblocks_am(.*)/).test(input) || RegExp(/^tyblocks_an(.*)/).test(input) || RegExp(/^tyblocks_ao(.*)/).test(input) || RegExp(/^tyblocks_ap(.*)/).test(input)); let _errorFactory; return (input, errorFactory) => {
|
|
16
|
-
if (false === __is(input)) {
|
|
17
|
-
_errorFactory = errorFactory;
|
|
18
|
-
((input, _path, _exceptionable = true) => "string" === typeof input && (RegExp(/^keeta_am(.*)/).test(input) || RegExp(/^keeta_an(.*)/).test(input) || RegExp(/^keeta_ao(.*)/).test(input) || RegExp(/^keeta_ap(.*)/).test(input) || RegExp(/^tyblocks_am(.*)/).test(input) || RegExp(/^tyblocks_an(.*)/).test(input) || RegExp(/^tyblocks_ao(.*)/).test(input) || RegExp(/^tyblocks_ap(.*)/).test(input)) || __typia_transform__assertGuard._assertGuard(true, {
|
|
19
|
-
method: "createAssert",
|
|
20
|
-
path: _path + "",
|
|
21
|
-
expected: "(`keeta_am${string}` | `keeta_an${string}` | `keeta_ao${string}` | `keeta_ap${string}` | `tyblocks_am${string}` | `tyblocks_an${string}` | `tyblocks_ao${string}` | `tyblocks_ap${string}`)",
|
|
22
|
-
value: input
|
|
23
|
-
}, _errorFactory))(input, "$input", true);
|
|
24
|
-
}
|
|
25
|
-
return input;
|
|
26
|
-
}; })();
|
|
27
13
|
async function getEndpoints(resolver, request, _ignored_account) {
|
|
28
14
|
const criteria = {};
|
|
29
15
|
if (request.from !== undefined) {
|
|
30
|
-
criteria.inputCurrencyCode = request.from;
|
|
16
|
+
criteria.inputCurrencyCode = request.from.publicKeyString.get();
|
|
31
17
|
}
|
|
32
18
|
if (request.to !== undefined) {
|
|
33
|
-
criteria.outputCurrencyCode = request.to;
|
|
19
|
+
criteria.outputCurrencyCode = request.to.publicKeyString.get();
|
|
34
20
|
}
|
|
35
21
|
const response = await resolver.lookup('fx', {
|
|
36
22
|
...criteria
|
|
@@ -100,30 +86,6 @@ async function getEndpoints(resolver, request, _ignored_account) {
|
|
|
100
86
|
const retval = Object.fromEntries(await Promise.all(serviceInfoPromises));
|
|
101
87
|
return (retval);
|
|
102
88
|
}
|
|
103
|
-
const isKeetaFXAnchorEstimateResponse = (() => { const _io0 = input => true === input.ok && ("object" === typeof input.estimate && null !== input.estimate && _io1(input.estimate)); const _io1 = input => "object" === typeof input.request && null !== input.request && _io2(input.request) && "string" === typeof input.convertedAmount && ("object" === typeof input.expectedCost && null !== input.expectedCost && _io3(input.expectedCost)); const _io2 = input => "string" === typeof input.from && (RegExp(/^keeta_am(.*)/).test(input.from) || RegExp(/^keeta_an(.*)/).test(input.from) || RegExp(/^keeta_ao(.*)/).test(input.from) || RegExp(/^keeta_ap(.*)/).test(input.from) || RegExp(/^tyblocks_am(.*)/).test(input.from) || RegExp(/^tyblocks_an(.*)/).test(input.from) || RegExp(/^tyblocks_ao(.*)/).test(input.from) || RegExp(/^tyblocks_ap(.*)/).test(input.from)) && ("string" === typeof input.to && (RegExp(/^keeta_am(.*)/).test(input.to) || RegExp(/^keeta_an(.*)/).test(input.to) || RegExp(/^keeta_ao(.*)/).test(input.to) || RegExp(/^keeta_ap(.*)/).test(input.to) || RegExp(/^tyblocks_am(.*)/).test(input.to) || RegExp(/^tyblocks_an(.*)/).test(input.to) || RegExp(/^tyblocks_ao(.*)/).test(input.to) || RegExp(/^tyblocks_ap(.*)/).test(input.to))) && "string" === typeof input.amount && ("from" === input.affinity || "to" === input.affinity); const _io3 = input => "string" === typeof input.min && "string" === typeof input.max && ("string" === typeof input.token && (RegExp(/^keeta_am(.*)/).test(input.token) || RegExp(/^keeta_an(.*)/).test(input.token) || RegExp(/^keeta_ao(.*)/).test(input.token) || RegExp(/^keeta_ap(.*)/).test(input.token) || RegExp(/^tyblocks_am(.*)/).test(input.token) || RegExp(/^tyblocks_an(.*)/).test(input.token) || RegExp(/^tyblocks_ao(.*)/).test(input.token) || RegExp(/^tyblocks_ap(.*)/).test(input.token))); const _io4 = input => false === input.ok && "string" === typeof input.error; const _iu0 = input => (() => {
|
|
104
|
-
if (true === input.ok)
|
|
105
|
-
return _io0(input);
|
|
106
|
-
else if (false === input.ok)
|
|
107
|
-
return _io4(input);
|
|
108
|
-
else
|
|
109
|
-
return false;
|
|
110
|
-
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
111
|
-
const isKeetaFXAnchorQuoteResponse = (() => { const _io0 = input => true === input.ok && ("object" === typeof input.quote && null !== input.quote && _io1(input.quote)); const _io1 = input => "object" === typeof input.request && null !== input.request && _io2(input.request) && "string" === typeof input.account && "string" === typeof input.convertedAmount && ("object" === typeof input.cost && null !== input.cost && _io3(input.cost)) && ("object" === typeof input.signed && null !== input.signed && _io4(input.signed)); const _io2 = input => "string" === typeof input.from && (RegExp(/^keeta_am(.*)/).test(input.from) || RegExp(/^keeta_an(.*)/).test(input.from) || RegExp(/^keeta_ao(.*)/).test(input.from) || RegExp(/^keeta_ap(.*)/).test(input.from) || RegExp(/^tyblocks_am(.*)/).test(input.from) || RegExp(/^tyblocks_an(.*)/).test(input.from) || RegExp(/^tyblocks_ao(.*)/).test(input.from) || RegExp(/^tyblocks_ap(.*)/).test(input.from)) && ("string" === typeof input.to && (RegExp(/^keeta_am(.*)/).test(input.to) || RegExp(/^keeta_an(.*)/).test(input.to) || RegExp(/^keeta_ao(.*)/).test(input.to) || RegExp(/^keeta_ap(.*)/).test(input.to) || RegExp(/^tyblocks_am(.*)/).test(input.to) || RegExp(/^tyblocks_an(.*)/).test(input.to) || RegExp(/^tyblocks_ao(.*)/).test(input.to) || RegExp(/^tyblocks_ap(.*)/).test(input.to))) && "string" === typeof input.amount && ("from" === input.affinity || "to" === input.affinity); const _io3 = input => "string" === typeof input.amount && ("string" === typeof input.token && (RegExp(/^keeta_am(.*)/).test(input.token) || RegExp(/^keeta_an(.*)/).test(input.token) || RegExp(/^keeta_ao(.*)/).test(input.token) || RegExp(/^keeta_ap(.*)/).test(input.token) || RegExp(/^tyblocks_am(.*)/).test(input.token) || RegExp(/^tyblocks_an(.*)/).test(input.token) || RegExp(/^tyblocks_ao(.*)/).test(input.token) || RegExp(/^tyblocks_ap(.*)/).test(input.token))); const _io4 = input => "string" === typeof input.nonce && "string" === typeof input.timestamp && "string" === typeof input.signature; const _io5 = input => false === input.ok && "string" === typeof input.error; const _iu0 = input => (() => {
|
|
112
|
-
if (true === input.ok)
|
|
113
|
-
return _io0(input);
|
|
114
|
-
else if (false === input.ok)
|
|
115
|
-
return _io5(input);
|
|
116
|
-
else
|
|
117
|
-
return false;
|
|
118
|
-
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
119
|
-
const isKeetaFXAnchorExchangeResponse = (() => { const _io0 = input => "string" === typeof input.exchangeID && true === input.ok; const _io1 = input => "string" === typeof input.exchangeID && false === input.ok && "string" === typeof input.error; const _iu0 = input => (() => {
|
|
120
|
-
if (true === input.ok)
|
|
121
|
-
return _io0(input);
|
|
122
|
-
else if (false === input.ok)
|
|
123
|
-
return _io1(input);
|
|
124
|
-
else
|
|
125
|
-
return false;
|
|
126
|
-
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
127
89
|
class KeetaFXAnchorBase {
|
|
128
90
|
logger;
|
|
129
91
|
client;
|
|
@@ -145,6 +107,14 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
145
107
|
this.conversion = conversion;
|
|
146
108
|
this.parent = parent;
|
|
147
109
|
}
|
|
110
|
+
#parseConversionRequest(input) {
|
|
111
|
+
return ({
|
|
112
|
+
from: KeetaNetLib.Account.fromPublicKeyString(input.from),
|
|
113
|
+
to: KeetaNetLib.Account.fromPublicKeyString(input.to),
|
|
114
|
+
amount: BigInt(input.amount),
|
|
115
|
+
affinity: input.affinity
|
|
116
|
+
});
|
|
117
|
+
}
|
|
148
118
|
async getEstimate() {
|
|
149
119
|
const serviceURL = await this.serviceInfo.operations.getEstimate;
|
|
150
120
|
if (serviceURL !== undefined) {
|
|
@@ -156,7 +126,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
156
126
|
'Accept': 'application/json'
|
|
157
127
|
},
|
|
158
128
|
body: JSON.stringify({
|
|
159
|
-
request: this.conversion
|
|
129
|
+
request: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)
|
|
160
130
|
})
|
|
161
131
|
});
|
|
162
132
|
const requestInformationJSON = await requestInformation.json();
|
|
@@ -166,8 +136,17 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
166
136
|
if (!requestInformationJSON.ok) {
|
|
167
137
|
throw (new Error(`FX estimate request failed: ${requestInformationJSON.error}`));
|
|
168
138
|
}
|
|
169
|
-
this.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(this.conversion)}`);
|
|
170
|
-
|
|
139
|
+
this.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);
|
|
140
|
+
const estimateJSON = requestInformationJSON.estimate;
|
|
141
|
+
return ({
|
|
142
|
+
request: this.#parseConversionRequest(estimateJSON.request),
|
|
143
|
+
convertedAmount: BigInt(estimateJSON.convertedAmount),
|
|
144
|
+
expectedCost: {
|
|
145
|
+
min: BigInt(estimateJSON.expectedCost.min),
|
|
146
|
+
max: BigInt(estimateJSON.expectedCost.max),
|
|
147
|
+
token: KeetaNetLib.Account.fromPublicKeyString(estimateJSON.expectedCost.token)
|
|
148
|
+
}
|
|
149
|
+
});
|
|
171
150
|
}
|
|
172
151
|
else {
|
|
173
152
|
throw (new Error('Service getEstimate does not exist'));
|
|
@@ -194,7 +173,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
194
173
|
'Accept': 'application/json'
|
|
195
174
|
},
|
|
196
175
|
body: JSON.stringify({
|
|
197
|
-
request: this.conversion
|
|
176
|
+
request: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)
|
|
198
177
|
})
|
|
199
178
|
});
|
|
200
179
|
const requestInformationJSON = await requestInformation.json();
|
|
@@ -205,32 +184,53 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
205
184
|
throw (new Error(`FX quote request failed: ${requestInformationJSON.error}`));
|
|
206
185
|
}
|
|
207
186
|
if (estimate !== undefined && tolerance !== undefined) {
|
|
208
|
-
const quoteAmount =
|
|
209
|
-
const estimateAmount =
|
|
210
|
-
const
|
|
211
|
-
|
|
187
|
+
const quoteAmount = BigInt(requestInformationJSON.quote.convertedAmount);
|
|
188
|
+
const estimateAmount = BigInt(estimate.convertedAmount);
|
|
189
|
+
const lowerBound = estimateAmount * BigInt(Math.round((1 - tolerance) * 100)) / 100n;
|
|
190
|
+
const upperBound = estimateAmount * BigInt(Math.round((1 + tolerance) * 100)) / 100n;
|
|
191
|
+
if (quoteAmount > upperBound || quoteAmount < lowerBound) {
|
|
212
192
|
throw (new Error(`FX Quote amount: ${requestInformationJSON.quote.convertedAmount} differs more than tolerance limit: ${tolerance} from estimate`));
|
|
213
193
|
}
|
|
214
194
|
}
|
|
215
|
-
this.logger?.debug(`FX quote request successful, to provider ${serviceURL} for ${JSON.stringify(this.conversion)}`);
|
|
216
|
-
|
|
195
|
+
this.logger?.debug(`FX quote request successful, to provider ${serviceURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);
|
|
196
|
+
const quoteJSON = requestInformationJSON.quote;
|
|
197
|
+
return ({
|
|
198
|
+
request: this.#parseConversionRequest(quoteJSON.request),
|
|
199
|
+
account: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.account),
|
|
200
|
+
convertedAmount: BigInt(quoteJSON.convertedAmount),
|
|
201
|
+
cost: {
|
|
202
|
+
amount: BigInt(quoteJSON.cost.amount),
|
|
203
|
+
token: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.cost.token)
|
|
204
|
+
},
|
|
205
|
+
signed: quoteJSON.signed
|
|
206
|
+
});
|
|
217
207
|
}
|
|
218
208
|
async createExchange(quote, block) {
|
|
219
209
|
let swapBlock = block;
|
|
220
210
|
if (swapBlock === undefined) {
|
|
221
211
|
/* Liquidity Provider that will complete the swap */
|
|
222
|
-
const liquidityProvider =
|
|
212
|
+
const liquidityProvider = quote.account;
|
|
223
213
|
/* Assume affinity is 'from' and assign appropriate variables */
|
|
224
|
-
let sendAmount =
|
|
225
|
-
let receiveAmount =
|
|
214
|
+
let sendAmount = quote.request.amount;
|
|
215
|
+
let receiveAmount = quote.convertedAmount;
|
|
226
216
|
/* If affinity is 'to' then reverse amounts */
|
|
227
217
|
if (quote.request.affinity === 'to') {
|
|
228
|
-
sendAmount =
|
|
229
|
-
receiveAmount =
|
|
218
|
+
sendAmount = quote.convertedAmount;
|
|
219
|
+
receiveAmount = quote.request.amount;
|
|
220
|
+
}
|
|
221
|
+
/* Construct the required operations for the swap request */
|
|
222
|
+
const builder = this.client.initBuilder();
|
|
223
|
+
builder.send(liquidityProvider, sendAmount, quote.request.from);
|
|
224
|
+
builder.receive(liquidityProvider, receiveAmount, quote.request.to, true);
|
|
225
|
+
/* If cost is required then send the required amount as well */
|
|
226
|
+
if (quote.cost.amount > 0) {
|
|
227
|
+
builder.send(liquidityProvider, quote.cost.amount, quote.cost.token);
|
|
228
|
+
}
|
|
229
|
+
const blocks = await builder.computeBlocks();
|
|
230
|
+
if (blocks.blocks.length !== 1) {
|
|
231
|
+
throw (new Error('Creating Swap Generated more than 1 block'));
|
|
230
232
|
}
|
|
231
|
-
|
|
232
|
-
const to = { account: liquidityProvider, token: KeetaNetLib.Account.fromPublicKeyString(quote.request.to), amount: receiveAmount };
|
|
233
|
-
swapBlock = await this.client.createSwapRequest({ from, to });
|
|
233
|
+
swapBlock = blocks.blocks[0];
|
|
234
234
|
}
|
|
235
235
|
if (swapBlock == undefined) {
|
|
236
236
|
throw (new Error('User Swap Block is undefined'));
|
|
@@ -244,7 +244,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
244
244
|
},
|
|
245
245
|
body: JSON.stringify({
|
|
246
246
|
request: {
|
|
247
|
-
quote: quote,
|
|
247
|
+
quote: KeetaNetLib.Utils.Conversion.toJSONSerializable(quote),
|
|
248
248
|
block: Buffer.from(swapBlock.toBytes()).toString('base64')
|
|
249
249
|
}
|
|
250
250
|
})
|
|
@@ -363,7 +363,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
363
363
|
if (input.from !== undefined) {
|
|
364
364
|
let fromToken;
|
|
365
365
|
if (KeetaNetLib.Account.isInstance(input.from) && input.from.isToken()) {
|
|
366
|
-
fromToken = input.from
|
|
366
|
+
fromToken = input.from;
|
|
367
367
|
}
|
|
368
368
|
else {
|
|
369
369
|
const tokenLookup = await this.resolver.lookupToken(input.from);
|
|
@@ -371,7 +371,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
371
371
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
372
372
|
throw (new Error(`Could not convert from: ${input.from} to a token address`));
|
|
373
373
|
}
|
|
374
|
-
fromToken = tokenLookup.token;
|
|
374
|
+
fromToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);
|
|
375
375
|
}
|
|
376
376
|
from = { from: fromToken };
|
|
377
377
|
}
|
|
@@ -379,7 +379,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
379
379
|
if (input.to !== undefined) {
|
|
380
380
|
let toToken;
|
|
381
381
|
if (KeetaNetLib.Account.isInstance(input.to) && input.to.isToken()) {
|
|
382
|
-
toToken = input.to
|
|
382
|
+
toToken = input.to;
|
|
383
383
|
}
|
|
384
384
|
else {
|
|
385
385
|
const tokenLookup = await this.resolver.lookupToken(input.to);
|
|
@@ -387,16 +387,16 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
387
387
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
388
388
|
throw (new Error(`Could not convert to: ${input.to} to a token address`));
|
|
389
389
|
}
|
|
390
|
-
toToken = tokenLookup.token;
|
|
390
|
+
toToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);
|
|
391
391
|
}
|
|
392
392
|
to = { to: toToken };
|
|
393
393
|
}
|
|
394
394
|
return ({ ...from, ...to });
|
|
395
395
|
}
|
|
396
396
|
async canonicalizeConversionInput(input) {
|
|
397
|
-
const amount =
|
|
398
|
-
if (amount
|
|
399
|
-
throw (new Error('
|
|
397
|
+
const amount = BigInt(input.amount);
|
|
398
|
+
if (amount < 0) {
|
|
399
|
+
throw (new Error('Invalid Conversion Amount'));
|
|
400
400
|
}
|
|
401
401
|
const { from, to } = await this.canonicalizeConversionTokens(input);
|
|
402
402
|
if (from === undefined || to === undefined) {
|
|
@@ -405,7 +405,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
405
405
|
return ({
|
|
406
406
|
from,
|
|
407
407
|
to,
|
|
408
|
-
amount: amount
|
|
408
|
+
amount: amount,
|
|
409
409
|
affinity: input.affinity
|
|
410
410
|
});
|
|
411
411
|
}
|
|
@@ -427,18 +427,18 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
427
427
|
for (const [_ignored_providerID, serviceInfo] of typedFxServiceEntries(providerEndpoints)) {
|
|
428
428
|
for (const conversionPair of serviceInfo.from) {
|
|
429
429
|
if (conversion.from !== undefined) {
|
|
430
|
-
if (conversionPair.currencyCodes.includes(conversion.from)) {
|
|
430
|
+
if (conversionPair.currencyCodes.includes(conversion.from.publicKeyString.get())) {
|
|
431
431
|
conversionPair.to.forEach((token) => {
|
|
432
|
-
if (conversion.from !== token) {
|
|
432
|
+
if (conversion.from?.publicKeyString.get() !== token) {
|
|
433
433
|
conversions.add(token);
|
|
434
434
|
}
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
438
|
else if (conversion.to !== undefined) {
|
|
439
|
-
if (conversionPair.to.includes(conversion.to)) {
|
|
439
|
+
if (conversionPair.to.includes(conversion.to.publicKeyString.get())) {
|
|
440
440
|
conversionPair.currencyCodes.forEach((token) => {
|
|
441
|
-
if (conversion.to !== token) {
|
|
441
|
+
if (conversion.to?.publicKeyString.get() !== token) {
|
|
442
442
|
conversions.add(token);
|
|
443
443
|
}
|
|
444
444
|
});
|