From 63b24e4475641a385358c6cacd8f715135ee78b9 Mon Sep 17 00:00:00 2001 From: Claudiu Lataretu Date: Mon, 30 Oct 2023 23:21:58 +0200 Subject: [PATCH 1/2] MEX-397: update proxy-dex-v2 abi to latest version Signed-off-by: Claudiu Lataretu --- src/abis/proxy-dex-v2.abi.json | 194 ++++++++++++++++++++++++++++----- 1 file changed, 166 insertions(+), 28 deletions(-) diff --git a/src/abis/proxy-dex-v2.abi.json b/src/abis/proxy-dex-v2.abi.json index 611901b87..50354ce89 100644 --- a/src/abis/proxy-dex-v2.abi.json +++ b/src/abis/proxy-dex-v2.abi.json @@ -1,45 +1,47 @@ { "buildInfo": { "rustc": { - "version": "1.66.0-nightly", - "commitHash": "b8c35ca26b191bb9a9ac669a4b3f4d3d52d97fb1", - "commitDate": "2022-10-15", + "version": "1.73.0-nightly", + "commitHash": "4c8bb79d9f565115637cc6da739f8389e79f3a29", + "commitDate": "2023-07-15", "channel": "Nightly", - "short": "rustc 1.66.0-nightly (b8c35ca26 2022-10-15)" + "short": "rustc 1.73.0-nightly (4c8bb79d9 2023-07-15)" }, "contractCrate": { "name": "proxy_dex", "version": "0.0.0", - "git_version": "v1.6.0-659-gbc15fd5b-modified" + "gitVersion": "v1.6.0-1530-g720dae7e" }, "framework": { - "name": "elrond-wasm", - "version": "0.36.0" + "name": "multiversx-sc", + "version": "0.43.3" } }, "name": "ProxyDexImpl", "constructor": { - "docs": [ - "asset_token_id: underlying asset token ID, which is used to interact with", - " pair/farm contracts", - "", - "locked_token_factory_address_pairs: pairs of (token ID, address)", - " token_id: the LOCKED token ID that is generated by the given factory address" - ], "inputs": [ { - "name": "asset_token_id", + "name": "old_locked_token_id", "type": "TokenIdentifier" }, { - "name": "locked_token_factory_address_pairs", - "type": "variadic>", - "multi_arg": true + "name": "old_factory_address", + "type": "Address" + }, + { + "name": "energy_factory_address", + "type": "Address" } ], "outputs": [] }, "endpoints": [ + { + "name": "upgrade", + "mutability": "mutable", + "inputs": [], + "outputs": [] + }, { "name": "registerProxyPair", "onlyOwner": true, @@ -63,6 +65,19 @@ ], "outputs": [] }, + { + "name": "setTransferRoleWrappedLpToken", + "onlyOwner": true, + "mutability": "mutable", + "inputs": [ + { + "name": "opt_address", + "type": "optional
", + "multi_arg": true + } + ], + "outputs": [] + }, { "name": "registerProxyFarm", "onlyOwner": true, @@ -86,6 +101,19 @@ ], "outputs": [] }, + { + "name": "setTransferRoleWrappedFarmToken", + "onlyOwner": true, + "mutability": "mutable", + "inputs": [ + { + "name": "opt_address", + "type": "optional
", + "multi_arg": true + } + ], + "outputs": [] + }, { "name": "getAssetTokenId", "mutability": "readonly", @@ -107,6 +135,26 @@ } ] }, + { + "name": "getOldLockedTokenId", + "mutability": "readonly", + "inputs": [], + "outputs": [ + { + "type": "TokenIdentifier" + } + ] + }, + { + "name": "getOldFactoryAddress", + "mutability": "readonly", + "inputs": [], + "outputs": [ + { + "type": "Address" + } + ] + }, { "name": "getWrappedLpTokenId", "mutability": "readonly", @@ -251,6 +299,24 @@ } ] }, + { + "name": "increaseProxyPairTokenEnergy", + "mutability": "mutable", + "payableInTokens": [ + "*" + ], + "inputs": [ + { + "name": "lock_epochs", + "type": "u64" + } + ], + "outputs": [ + { + "type": "EsdtTokenPayment" + } + ] + }, { "name": "enterFarmProxy", "mutability": "mutable", @@ -261,9 +327,17 @@ { "name": "farm_address", "type": "Address" + }, + { + "name": "opt_original_caller", + "type": "optional
", + "multi_arg": true } ], "outputs": [ + { + "type": "EsdtTokenPayment" + }, { "type": "EsdtTokenPayment" } @@ -276,22 +350,20 @@ "*" ], "inputs": [ - { - "name": "exit_amount", - "type": "BigUint" - }, { "name": "farm_address", "type": "Address" + }, + { + "name": "opt_original_caller", + "type": "optional
", + "multi_arg": true } ], "outputs": [ { "type": "EsdtTokenPayment" }, - { - "type": "EsdtTokenPayment" - }, { "type": "EsdtTokenPayment" } @@ -307,6 +379,11 @@ { "name": "farm_address", "type": "Address" + }, + { + "name": "opt_original_caller", + "type": "optional
", + "multi_arg": true } ], "outputs": [ @@ -319,15 +396,15 @@ ] }, { - "name": "compoundRewardsProxy", + "name": "increaseProxyFarmTokenEnergy", "mutability": "mutable", "payableInTokens": [ "*" ], "inputs": [ { - "name": "farm_address", - "type": "Address" + "name": "lock_epochs", + "type": "u64" } ], "outputs": [ @@ -366,6 +443,67 @@ "type": "EsdtTokenPayment" } ] + }, + { + "name": "setEnergyFactoryAddress", + "onlyOwner": true, + "mutability": "mutable", + "inputs": [ + { + "name": "sc_address", + "type": "Address" + } + ], + "outputs": [] + }, + { + "name": "getEnergyFactoryAddress", + "mutability": "readonly", + "inputs": [], + "outputs": [ + { + "type": "Address" + } + ] + }, + { + "name": "addSCAddressToWhitelist", + "onlyOwner": true, + "mutability": "mutable", + "inputs": [ + { + "name": "address", + "type": "Address" + } + ], + "outputs": [] + }, + { + "name": "removeSCAddressFromWhitelist", + "onlyOwner": true, + "mutability": "mutable", + "inputs": [ + { + "name": "address", + "type": "Address" + } + ], + "outputs": [] + }, + { + "name": "isSCAddressWhitelisted", + "mutability": "readonly", + "inputs": [ + { + "name": "address", + "type": "Address" + } + ], + "outputs": [ + { + "type": "bool" + } + ] } ], "events": [ From f9d849ba554ff0ad2d801f25fae32829c4fd851a Mon Sep 17 00:00:00 2001 From: Claudiu Lataretu Date: Mon, 30 Oct 2023 23:58:32 +0200 Subject: [PATCH 2/2] MEX-397: add query for increase proxy pair token energy transaction Signed-off-by: Claudiu Lataretu --- src/config/default.json | 3 +- src/modules/proxy/proxy.module.ts | 2 + .../proxy/proxy.transaction.resolver.ts | 44 +++++++++++++++++++ .../proxy.pair.transactions.service.ts | 28 ++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/config/default.json b/src/config/default.json index 91dbd8220..dce40981b 100644 --- a/src/config/default.json +++ b/src/config/default.json @@ -261,7 +261,8 @@ "withTokenMerge": 40000000 }, "removeLiquidity": 30000000, - "defaultMergeWLPT": 20000000 + "defaultMergeWLPT": 20000000, + "increaseEnergy": 20000000 }, "farms": { "v1.2": { diff --git a/src/modules/proxy/proxy.module.ts b/src/modules/proxy/proxy.module.ts index 36d87314e..4eb0cb090 100644 --- a/src/modules/proxy/proxy.module.ts +++ b/src/modules/proxy/proxy.module.ts @@ -16,6 +16,7 @@ import { ProxyQueryResolver } from './proxy.query.resolver'; import { ProxyResolver } from './proxy.resolver'; import { WrappedLpTokenAttributesResolverV2 } from './wrappedLp.token.v2.resolver'; import { WrappedFarmTokenResolverV2 } from './wrappedFarm.token.v2.resolver'; +import { EnergyModule } from '../energy/energy.module'; @Module({ imports: [ @@ -27,6 +28,7 @@ import { WrappedFarmTokenResolverV2 } from './wrappedFarm.token.v2.resolver'; forwardRef(() => ProxyFarmModule), forwardRef(() => ProxyModuleV2), FarmModule, + EnergyModule, ], providers: [ ProxyAbiService, diff --git a/src/modules/proxy/proxy.transaction.resolver.ts b/src/modules/proxy/proxy.transaction.resolver.ts index 7bca6af60..886637397 100644 --- a/src/modules/proxy/proxy.transaction.resolver.ts +++ b/src/modules/proxy/proxy.transaction.resolver.ts @@ -24,11 +24,15 @@ import { InputTokenModel } from 'src/models/inputToken.model'; import { LiquidityTokensValidationPipe } from './validators/add.liquidity.input.validator'; import { ProxyService } from './services/proxy.service'; import { scAddress } from 'src/config'; +import { GraphQLError } from 'graphql'; +import { ApolloServerErrorCode } from '@apollo/server/errors'; +import { EnergyAbiService } from '../energy/services/energy.abi.service'; @Resolver() export class ProxyTransactionResolver { constructor( private readonly proxyService: ProxyService, + private readonly energyAbi: EnergyAbiService, private readonly transactionsProxyPairService: ProxyPairTransactionsService, private readonly transactionsProxyFarmService: ProxyFarmTransactionsService, ) {} @@ -195,4 +199,44 @@ export class ProxyTransactionResolver { args, ); } + + @UseGuards(JwtOrNativeAuthGuard) + @Query(() => TransactionModel) + async increaseProxyPairTokenEnergy( + @Args('payment') payment: InputTokenModel, + @Args('lockEpochs') lockEpochs: number, + @AuthUser() user: UserAuthResult, + ): Promise { + let proxyAddress: string; + try { + proxyAddress = await this.proxyService.getProxyAddressByToken( + payment.tokenID, + ); + + if (proxyAddress !== scAddress.proxyDexAddress.v2) { + throw new Error('Wrapped lp token is not supported'); + } + + const lockOptions = await this.energyAbi.lockOptions(); + if ( + lockOptions.find( + (option) => option.lockEpochs === lockEpochs, + ) === undefined + ) { + throw new Error('Invalid lock epochs!'); + } + } catch (error) { + throw new GraphQLError(error.message, { + extensions: { + code: ApolloServerErrorCode.BAD_USER_INPUT, + }, + }); + } + return this.transactionsProxyPairService.increaseProxyPairTokenEnergy( + user.address, + proxyAddress, + payment, + lockEpochs, + ); + } } diff --git a/src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts b/src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts index b8dbf2c48..1026b2ea6 100644 --- a/src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts +++ b/src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts @@ -4,6 +4,7 @@ import { BigUIntValue, BytesValue, TypedValue, + U64Value, } from '@multiversx/sdk-core/out/smartcontracts/typesystem'; import { Address, TokenTransfer } from '@multiversx/sdk-core'; import { TransactionModel } from 'src/models/transaction.model'; @@ -236,6 +237,33 @@ export class ProxyPairTransactionsService { .toPlainObject(); } + async increaseProxyPairTokenEnergy( + sender: string, + proxyAddress: string, + payment: InputTokenModel, + lockEpochs: number, + ): Promise { + const contract = await this.mxProxy.getProxyDexSmartContract( + proxyAddress, + ); + return contract.methodsExplicit + .increaseProxyPairTokenEnergy([ + new U64Value(new BigNumber(lockEpochs)), + ]) + .withSingleESDTNFTTransfer( + TokenTransfer.metaEsdtFromBigInteger( + payment.tokenID, + payment.nonce, + new BigNumber(payment.amount), + ), + ) + .withSender(Address.fromString(sender)) + .withGasLimit(gasConfig.proxy.pairs.increaseEnergy) + .withChainID(mxConfig.chainID) + .buildTransaction() + .toPlainObject(); + } + private async convertInputTokenstoESDTTokens( tokens: InputTokenModel[], ): Promise {