Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SERVICES-1902] fix token derived EGLD price #1216

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
331 changes: 331 additions & 0 deletions src/modules/pair/mocks/pair.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@ export const Tokens = (tokenID: string): EsdtToken => {
price: '1',
roles: new RolesModel(),
});
case 'USDT-123456':
return new EsdtToken({
identifier: 'USDT-123456',
name: 'TetherUSD',
ticker: 'USDT',
owner: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000001',
).bech32(),
supply: '1000000000000',
decimals: 6,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
type: 'Core',
minted: '1',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
initialMinted: '1',
price: '1',
roles: new RolesModel(),
});
case 'TOK4-123456':
return new EsdtToken({
identifier: 'TOK4-123456',
Expand All @@ -120,6 +149,58 @@ export const Tokens = (tokenID: string): EsdtToken => {
transactions: 1,
assets: new AssetsModel(),
});
case 'TOK5-123456':
return new EsdtToken({
identifier: 'TOK5-123456',
name: 'Token5',
owner: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000001',
).bech32(),
ticker: 'TOK5',
supply: '1000000000000000000',
decimals: 18,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
type: 'Experimental',
minted: '1',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
});
case 'TOK6-123456':
return new EsdtToken({
identifier: 'TOK6-123456',
name: 'Token6',
owner: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000001',
).bech32(),
ticker: 'TOK6',
supply: '1000000000000000000',
decimals: 18,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
type: 'Experimental',
minted: '1',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
});
case 'EGLDUSDCLP-abcdef':
return new EsdtToken({
identifier: 'EGLDUSDCLP-abcdef',
Expand Down Expand Up @@ -198,6 +279,141 @@ export const Tokens = (tokenID: string): EsdtToken => {
price: '10',
roles: new RolesModel(),
});
case 'EGLDTOK5LP-abcdef':
return new EsdtToken({
identifier: 'EGLDTOK5LP-abcdef',
name: 'EGLDTOK5LP',
ticker: 'EGLDTOK5LP',
type: 'FungibleESDT',
owner: scAddress.routerAddress,
supply: '1000000000000000000000000',
decimals: 18,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
minted: '900000000000000000000000',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
initialMinted: '1',
price: '10',
roles: new RolesModel(),
});
case 'TOK5TOK6LP-abcdef':
return new EsdtToken({
identifier: 'TOK5TOK6LP-abcdef',
name: 'TOK5TOK6LP',
ticker: 'TOK5TOK6LP',
type: 'FungibleESDT',
owner: scAddress.routerAddress,
supply: '1000000000000000000000000',
decimals: 18,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
minted: '900000000000000000000000',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
initialMinted: '1',
price: '10',
roles: new RolesModel(),
});
case 'TOK5USDCLP-abcdef':
return new EsdtToken({
identifier: 'TOK5USDCLP-abcdef',
name: 'TOK5USDCLP',
ticker: 'TOK5USDCLP',
type: 'FungibleESDT',
owner: scAddress.routerAddress,
supply: '1000000000000000000000000',
decimals: 18,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
minted: '900000000000000000000000',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
initialMinted: '1',
price: '10',
roles: new RolesModel(),
});
case 'TOK5USDTLP-abcdef':
return new EsdtToken({
identifier: 'TOK5USDTLP-abcdef',
name: 'TOK5USDTLP',
ticker: 'TOK5USDTLP',
type: 'FungibleESDT',
owner: scAddress.routerAddress,
supply: '1000000000000000000000000',
decimals: 18,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
minted: '900000000000000000000000',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
initialMinted: '1',
price: '10',
roles: new RolesModel(),
});
case 'EGLDUSDTLP-abcdef':
return new EsdtToken({
identifier: 'EGLDUSDTLP-abcdef',
name: 'EGLDUSDTLP',
ticker: 'EGLDUSDTLP',
type: 'FungibleESDT',
owner: scAddress.routerAddress,
supply: '1000000000000000000000000',
decimals: 18,
isPaused: false,
canUpgrade: true,
canMint: true,
canBurn: true,
canChangeOwner: true,
canPause: true,
canFreeze: true,
canWipe: true,
minted: '900000000000000000000000',
burnt: '1',
circulatingSupply: '1',
accounts: 1,
transactions: 1,
assets: new AssetsModel(),
initialMinted: '1',
price: '10',
roles: new RolesModel(),
});
case 'EGLDMEXFL-abcdef':
return {
identifier: 'EGLDMEXFL-abcdef',
Expand Down Expand Up @@ -393,6 +609,121 @@ export const pairs = [
totalFeePercent: 0.003,
state: 'Active',
},
{
address: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000015',
).bech32(),
firstToken: Tokens('WEGLD-123456'),
secondToken: Tokens('TOK5-123456'),
liquidityPoolToken: Tokens('EGLDTOK5LP-abcdef'),
info: {
reserves0: '1000000000000000000000',
reserves1: '100000000000000000000000',
totalSupply: '1000000000000000000000',
},
firstTokenPrice: '100',
firstTokenPriceUSD: '10',
secondTokenPrice: '0.01',
secondTokenPriceUSD: '0.1',
liquidityPoolTokenPriceUSD: '20',
firstTokenLockedValueUSD: '10000',
secondTokenLockedValueUSD: '10000',
lockedValueUSD: '20000',
totalFeePercent: 0.003,
state: 'Active',
},
{
address: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000016',
).bech32(),
firstToken: Tokens('TOK6-123456'),
secondToken: Tokens('TOK5-123456'),
liquidityPoolToken: Tokens('TOK5TOK6LP-abcdef'),
info: {
reserves0: '1000000000000000000000',
reserves1: '1000000000000000000000',
totalSupply: '1000000000000000000000',
},
firstTokenPrice: '1',
firstTokenPriceUSD: '0.1',
secondTokenPrice: '1',
secondTokenPriceUSD: '0.1',
liquidityPoolTokenPriceUSD: '0.2',
firstTokenLockedValueUSD: '100',
secondTokenLockedValueUSD: '100',
lockedValueUSD: '200',
totalFeePercent: 0.003,
state: 'Active',
},
{
address: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000017',
).bech32(),
firstToken: Tokens('TOK5-123456'),
secondToken: Tokens('USDC-123456'),
liquidityPoolToken: Tokens('TOK5USDCLP-abcdef'),
info: {
reserves0: '10000000000000000000',
reserves1: '1000000',
totalSupply: '1000000000000000000000',
},
firstTokenPrice: '0.1',
firstTokenPriceUSD: '0.1',
secondTokenPrice: '10',
secondTokenPriceUSD: '1',
liquidityPoolTokenPriceUSD: '20',
firstTokenLockedValueUSD: '10000',
secondTokenLockedValueUSD: '10000',
lockedValueUSD: '20000',
totalFeePercent: 0.003,
state: 'Active',
},
{
address: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000018',
).bech32(),
firstToken: Tokens('TOK5-123456'),
secondToken: Tokens('USDT-123456'),
liquidityPoolToken: Tokens('TOK5USDTLP-abcdef'),
info: {
reserves0: '990000000000000000000000',
reserves1: '100000000000',
totalSupply: '1000000000000000000000',
},
firstTokenPrice: '0.1010101010101010101010101',
firstTokenPriceUSD: '0.101',
secondTokenPrice: '9.9',
secondTokenPriceUSD: '1',
liquidityPoolTokenPriceUSD: '20',
firstTokenLockedValueUSD: '10000',
secondTokenLockedValueUSD: '10000',
lockedValueUSD: '20000',
totalFeePercent: 0.003,
state: 'Active',
},
{
address: Address.fromHex(
'0000000000000000000000000000000000000000000000000000000000000019',
).bech32(),
firstToken: Tokens('WEGLD-123456'),
secondToken: Tokens('USDT-123456'),
liquidityPoolToken: Tokens('EGLDUSDTLP-abcdef'),
info: {
reserves0: '1000000000000000000000',
reserves1: '10000000000',
totalSupply: '10000000000',
},
firstTokenPrice: '10',
firstTokenPriceUSD: '10',
secondTokenPrice: '0.1',
secondTokenPriceUSD: '1',
liquidityPoolTokenPriceUSD: '20',
firstTokenLockedValueUSD: '10000',
secondTokenLockedValueUSD: '10000',
lockedValueUSD: '20000',
totalFeePercent: 0.003,
state: 'Active',
},
];

export async function PairsMap(): Promise<Map<string, string[]>> {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/rabbitmq/handlers/pair.swap.handler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class SwapEventHandler {
private async updateTokenPrices(tokenID: string): Promise<void> {
const [tokenPriceDerivedEGLD, tokenPriceDerivedUSD] = await Promise.all(
[
this.tokenCompute.computeTokenPriceDerivedEGLD(tokenID),
this.tokenCompute.computeTokenPriceDerivedEGLD(tokenID, []),
this.tokenCompute.computeTokenPriceDerivedUSD(tokenID),
],
);
Expand Down
Loading
Loading