Merge pull request #215 from orionprotocol/swapinfo-usd

swapInfo usd
This commit is contained in:
kigastu
2023-11-28 07:37:22 +05:00
committed by GitHub
6 changed files with 32 additions and 4 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.23",
"version": "0.20.24",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.20.23",
"version": "0.20.24",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.23",
"version": "0.20.24-rc4",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -40,6 +40,13 @@ const swapInfoBase = z.object({
isThroughPoolOrCurve: z.boolean(),
}).array(),
assetNameMapping: z.record(z.string()).optional(), // address to ERC20 names
usd: z.object({ // USD info of this swap, nullable
aa: z.number().optional(), // available amount in, USD
aao: z.number().optional(), // available amount out, USD
mo: z.number().optional(), // market amount out, USD
mi: z.number().optional(), // market amount in, USD
d: z.string().optional(), // difference in available amount in/out (USD) and market amount out/in (USD) in percentage
}).optional(),
});
const swapInfoByAmountIn = swapInfoBase.extend({

View File

@@ -526,6 +526,13 @@ class AggregatorWS {
availableAmountOut: item.aao,
})),
assetsNameMapping: json.anm,
usdInfo: json.usd && {
availableAmountIn: json.usd.aa,
availableAmountOut: json.usd.aao,
marketAmountOut: json.usd.mo,
marketAmountIn: json.usd.mi,
difference: json.usd.d,
},
};
switch (json.k) { // kind

View File

@@ -40,7 +40,14 @@ const swapInfoSchemaBase = baseMessageSchema.extend({
ai: z.string().toUpperCase(), // asset in
ao: z.string().toUpperCase(), // asset out
f: factorySchema, // factory
}))
})),
usd: z.object({ // USD info of this swap, nullable
aa: z.number().optional(), // available amount in, USD
aao: z.number().optional(), // available amount out, USD
mo: z.number().optional(), // market amount out, USD
mi: z.number().optional(), // market amount in, USD
d: z.string().optional(), // difference in available amount in/out (USD) and market amount out/in (USD) in percentage
}).optional(),
});
const swapInfoSchemaByAmountIn = swapInfoSchemaBase.extend({

View File

@@ -197,6 +197,13 @@ export type SwapInfoBase = {
} | undefined
alternatives: SwapInfoAlternative[]
assetsNameMapping?: Partial<Record<string, string>> | undefined
usdInfo: {
availableAmountIn: number | undefined
availableAmountOut: number | undefined
marketAmountOut: number | undefined
marketAmountIn: number | undefined
difference: string | undefined
} | undefined
}
export type SwapInfoByAmountIn = SwapInfoBase & {