@keetanetwork/anchor 0.0.11 → 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 +5 -11
- package/package.json +2 -3
- package/services/fx/client.d.ts +1 -0
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +72 -74
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.d.ts +24 -34
- package/services/fx/common.d.ts.map +1 -1
- package/services/fx/common.js +174 -41
- 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 +59 -154
- 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
|
-
"@keetanetwork/keetanet-client": "0.14.
|
|
14
|
-
"decimal.js": "10.6.0",
|
|
13
|
+
"@keetanetwork/keetanet-client": "0.14.8",
|
|
15
14
|
"typia": "9.5.0"
|
|
16
15
|
},
|
|
17
16
|
"engines": {
|
|
@@ -186,8 +185,8 @@
|
|
|
186
185
|
"license": "ISC"
|
|
187
186
|
},
|
|
188
187
|
"node_modules/@keetanetwork/keetanet-client": {
|
|
189
|
-
"version": "0.14.
|
|
190
|
-
"integrity": "sha512-
|
|
188
|
+
"version": "0.14.8",
|
|
189
|
+
"integrity": "sha512-euT801QtPzcCM7XFzj/F9Ldznah3WqoUwU1sBS4JGDm83rlhSnuw2yC9hIMo80pm0CWZjOOeYlMDkjson2EeKQ==",
|
|
191
190
|
"license": "see LICENSE",
|
|
192
191
|
"dependencies": {
|
|
193
192
|
"secp256k1": "5.0.1"
|
|
@@ -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": {
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@keetanetwork/currency-info": "1.2.5",
|
|
26
|
-
"@keetanetwork/keetanet-client": "0.14.
|
|
27
|
-
"decimal.js": "10.6.0",
|
|
26
|
+
"@keetanetwork/keetanet-client": "0.14.8",
|
|
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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AAiB;;IAClD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAIR,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAE,yBAA8B;YAwBhE,4BAA4B;YAmC5B,2BAA2B;IAoBnC,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,4BAA4B,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC;IAyC5K,6BAA6B,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,yBAAyB,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,37 +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';
|
|
9
|
-
import {
|
|
6
|
+
import { assertKeetaNetTokenPublicKeyString, isKeetaFXAnchorEstimateResponse, isKeetaFXAnchorExchangeResponse, isKeetaFXAnchorQuoteResponse } from './common.js';
|
|
10
7
|
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
11
8
|
function typedFxServiceEntries(obj) {
|
|
12
9
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
13
10
|
return Object.entries(obj);
|
|
14
11
|
}
|
|
15
12
|
const KeetaFXAnchorClientAccessToken = Symbol('KeetaFXAnchorClientAccessToken');
|
|
16
|
-
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) => {
|
|
17
|
-
if (false === __is(input)) {
|
|
18
|
-
_errorFactory = errorFactory;
|
|
19
|
-
((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, {
|
|
20
|
-
method: "createAssert",
|
|
21
|
-
path: _path + "",
|
|
22
|
-
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}`)",
|
|
23
|
-
value: input
|
|
24
|
-
}, _errorFactory))(input, "$input", true);
|
|
25
|
-
}
|
|
26
|
-
return input;
|
|
27
|
-
}; })();
|
|
28
13
|
async function getEndpoints(resolver, request, _ignored_account) {
|
|
29
14
|
const criteria = {};
|
|
30
15
|
if (request.from !== undefined) {
|
|
31
|
-
criteria.inputCurrencyCode = request.from;
|
|
16
|
+
criteria.inputCurrencyCode = request.from.publicKeyString.get();
|
|
32
17
|
}
|
|
33
18
|
if (request.to !== undefined) {
|
|
34
|
-
criteria.outputCurrencyCode = request.to;
|
|
19
|
+
criteria.outputCurrencyCode = request.to.publicKeyString.get();
|
|
35
20
|
}
|
|
36
21
|
const response = await resolver.lookup('fx', {
|
|
37
22
|
...criteria
|
|
@@ -101,30 +86,6 @@ async function getEndpoints(resolver, request, _ignored_account) {
|
|
|
101
86
|
const retval = Object.fromEntries(await Promise.all(serviceInfoPromises));
|
|
102
87
|
return (retval);
|
|
103
88
|
}
|
|
104
|
-
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 => (() => {
|
|
105
|
-
if (true === input.ok)
|
|
106
|
-
return _io0(input);
|
|
107
|
-
else if (false === input.ok)
|
|
108
|
-
return _io4(input);
|
|
109
|
-
else
|
|
110
|
-
return false;
|
|
111
|
-
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
112
|
-
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 => (() => {
|
|
113
|
-
if (true === input.ok)
|
|
114
|
-
return _io0(input);
|
|
115
|
-
else if (false === input.ok)
|
|
116
|
-
return _io5(input);
|
|
117
|
-
else
|
|
118
|
-
return false;
|
|
119
|
-
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
120
|
-
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 => (() => {
|
|
121
|
-
if (true === input.ok)
|
|
122
|
-
return _io0(input);
|
|
123
|
-
else if (false === input.ok)
|
|
124
|
-
return _io1(input);
|
|
125
|
-
else
|
|
126
|
-
return false;
|
|
127
|
-
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
128
89
|
class KeetaFXAnchorBase {
|
|
129
90
|
logger;
|
|
130
91
|
client;
|
|
@@ -146,6 +107,14 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
146
107
|
this.conversion = conversion;
|
|
147
108
|
this.parent = parent;
|
|
148
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
|
+
}
|
|
149
118
|
async getEstimate() {
|
|
150
119
|
const serviceURL = await this.serviceInfo.operations.getEstimate;
|
|
151
120
|
if (serviceURL !== undefined) {
|
|
@@ -157,7 +126,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
157
126
|
'Accept': 'application/json'
|
|
158
127
|
},
|
|
159
128
|
body: JSON.stringify({
|
|
160
|
-
request: this.conversion
|
|
129
|
+
request: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)
|
|
161
130
|
})
|
|
162
131
|
});
|
|
163
132
|
const requestInformationJSON = await requestInformation.json();
|
|
@@ -167,8 +136,17 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
167
136
|
if (!requestInformationJSON.ok) {
|
|
168
137
|
throw (new Error(`FX estimate request failed: ${requestInformationJSON.error}`));
|
|
169
138
|
}
|
|
170
|
-
this.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(this.conversion)}`);
|
|
171
|
-
|
|
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
|
+
});
|
|
172
150
|
}
|
|
173
151
|
else {
|
|
174
152
|
throw (new Error('Service getEstimate does not exist'));
|
|
@@ -195,7 +173,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
195
173
|
'Accept': 'application/json'
|
|
196
174
|
},
|
|
197
175
|
body: JSON.stringify({
|
|
198
|
-
request: this.conversion
|
|
176
|
+
request: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)
|
|
199
177
|
})
|
|
200
178
|
});
|
|
201
179
|
const requestInformationJSON = await requestInformation.json();
|
|
@@ -206,33 +184,53 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
206
184
|
throw (new Error(`FX quote request failed: ${requestInformationJSON.error}`));
|
|
207
185
|
}
|
|
208
186
|
if (estimate !== undefined && tolerance !== undefined) {
|
|
209
|
-
const quoteAmount =
|
|
210
|
-
const estimateAmount =
|
|
211
|
-
const
|
|
212
|
-
|
|
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) {
|
|
213
192
|
throw (new Error(`FX Quote amount: ${requestInformationJSON.quote.convertedAmount} differs more than tolerance limit: ${tolerance} from estimate`));
|
|
214
193
|
}
|
|
215
194
|
}
|
|
216
|
-
this.logger?.debug(`FX quote request successful, to provider ${serviceURL} for ${JSON.stringify(this.conversion)}`);
|
|
217
|
-
|
|
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
|
+
});
|
|
218
207
|
}
|
|
219
208
|
async createExchange(quote, block) {
|
|
220
209
|
let swapBlock = block;
|
|
221
210
|
if (swapBlock === undefined) {
|
|
222
211
|
/* Liquidity Provider that will complete the swap */
|
|
223
|
-
const liquidityProvider =
|
|
212
|
+
const liquidityProvider = quote.account;
|
|
224
213
|
/* Assume affinity is 'from' and assign appropriate variables */
|
|
225
|
-
let sendAmount =
|
|
226
|
-
let receiveAmount =
|
|
214
|
+
let sendAmount = quote.request.amount;
|
|
215
|
+
let receiveAmount = quote.convertedAmount;
|
|
227
216
|
/* If affinity is 'to' then reverse amounts */
|
|
228
217
|
if (quote.request.affinity === 'to') {
|
|
229
|
-
sendAmount =
|
|
230
|
-
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'));
|
|
231
232
|
}
|
|
232
|
-
|
|
233
|
-
const to = { account: liquidityProvider, token: KeetaNetLib.Account.fromPublicKeyString(quote.request.to), amount: receiveAmount };
|
|
234
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
235
|
-
swapBlock = await createSwapRequest(this.client, from, to);
|
|
233
|
+
swapBlock = blocks.blocks[0];
|
|
236
234
|
}
|
|
237
235
|
if (swapBlock == undefined) {
|
|
238
236
|
throw (new Error('User Swap Block is undefined'));
|
|
@@ -246,7 +244,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
246
244
|
},
|
|
247
245
|
body: JSON.stringify({
|
|
248
246
|
request: {
|
|
249
|
-
quote: quote,
|
|
247
|
+
quote: KeetaNetLib.Utils.Conversion.toJSONSerializable(quote),
|
|
250
248
|
block: Buffer.from(swapBlock.toBytes()).toString('base64')
|
|
251
249
|
}
|
|
252
250
|
})
|
|
@@ -365,7 +363,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
365
363
|
if (input.from !== undefined) {
|
|
366
364
|
let fromToken;
|
|
367
365
|
if (KeetaNetLib.Account.isInstance(input.from) && input.from.isToken()) {
|
|
368
|
-
fromToken = input.from
|
|
366
|
+
fromToken = input.from;
|
|
369
367
|
}
|
|
370
368
|
else {
|
|
371
369
|
const tokenLookup = await this.resolver.lookupToken(input.from);
|
|
@@ -373,7 +371,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
373
371
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
374
372
|
throw (new Error(`Could not convert from: ${input.from} to a token address`));
|
|
375
373
|
}
|
|
376
|
-
fromToken = tokenLookup.token;
|
|
374
|
+
fromToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);
|
|
377
375
|
}
|
|
378
376
|
from = { from: fromToken };
|
|
379
377
|
}
|
|
@@ -381,7 +379,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
381
379
|
if (input.to !== undefined) {
|
|
382
380
|
let toToken;
|
|
383
381
|
if (KeetaNetLib.Account.isInstance(input.to) && input.to.isToken()) {
|
|
384
|
-
toToken = input.to
|
|
382
|
+
toToken = input.to;
|
|
385
383
|
}
|
|
386
384
|
else {
|
|
387
385
|
const tokenLookup = await this.resolver.lookupToken(input.to);
|
|
@@ -389,16 +387,16 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
389
387
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
390
388
|
throw (new Error(`Could not convert to: ${input.to} to a token address`));
|
|
391
389
|
}
|
|
392
|
-
toToken = tokenLookup.token;
|
|
390
|
+
toToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);
|
|
393
391
|
}
|
|
394
392
|
to = { to: toToken };
|
|
395
393
|
}
|
|
396
394
|
return ({ ...from, ...to });
|
|
397
395
|
}
|
|
398
396
|
async canonicalizeConversionInput(input) {
|
|
399
|
-
const amount =
|
|
400
|
-
if (amount
|
|
401
|
-
throw (new Error('
|
|
397
|
+
const amount = BigInt(input.amount);
|
|
398
|
+
if (amount < 0) {
|
|
399
|
+
throw (new Error('Invalid Conversion Amount'));
|
|
402
400
|
}
|
|
403
401
|
const { from, to } = await this.canonicalizeConversionTokens(input);
|
|
404
402
|
if (from === undefined || to === undefined) {
|
|
@@ -407,7 +405,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
407
405
|
return ({
|
|
408
406
|
from,
|
|
409
407
|
to,
|
|
410
|
-
amount: amount
|
|
408
|
+
amount: amount,
|
|
411
409
|
affinity: input.affinity
|
|
412
410
|
});
|
|
413
411
|
}
|
|
@@ -429,18 +427,18 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
429
427
|
for (const [_ignored_providerID, serviceInfo] of typedFxServiceEntries(providerEndpoints)) {
|
|
430
428
|
for (const conversionPair of serviceInfo.from) {
|
|
431
429
|
if (conversion.from !== undefined) {
|
|
432
|
-
if (conversionPair.currencyCodes.includes(conversion.from)) {
|
|
430
|
+
if (conversionPair.currencyCodes.includes(conversion.from.publicKeyString.get())) {
|
|
433
431
|
conversionPair.to.forEach((token) => {
|
|
434
|
-
if (conversion.from !== token) {
|
|
432
|
+
if (conversion.from?.publicKeyString.get() !== token) {
|
|
435
433
|
conversions.add(token);
|
|
436
434
|
}
|
|
437
435
|
});
|
|
438
436
|
}
|
|
439
437
|
}
|
|
440
438
|
else if (conversion.to !== undefined) {
|
|
441
|
-
if (conversionPair.to.includes(conversion.to)) {
|
|
439
|
+
if (conversionPair.to.includes(conversion.to.publicKeyString.get())) {
|
|
442
440
|
conversionPair.currencyCodes.forEach((token) => {
|
|
443
|
-
if (conversion.to !== token) {
|
|
441
|
+
if (conversion.to?.publicKeyString.get() !== token) {
|
|
444
442
|
conversions.add(token);
|
|
445
443
|
}
|
|
446
444
|
});
|