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

[MEX-397] xmex position energy increase #1219

Merged
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
194 changes: 166 additions & 28 deletions src/abis/proxy-dex-v2.abi.json
Original file line number Diff line number Diff line change
@@ -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<TokenIdentifier,Address>>",
"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,
Expand All @@ -63,6 +65,19 @@
],
"outputs": []
},
{
"name": "setTransferRoleWrappedLpToken",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
{
"name": "opt_address",
"type": "optional<Address>",
"multi_arg": true
}
],
"outputs": []
},
{
"name": "registerProxyFarm",
"onlyOwner": true,
Expand All @@ -86,6 +101,19 @@
],
"outputs": []
},
{
"name": "setTransferRoleWrappedFarmToken",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
{
"name": "opt_address",
"type": "optional<Address>",
"multi_arg": true
}
],
"outputs": []
},
{
"name": "getAssetTokenId",
"mutability": "readonly",
Expand All @@ -107,6 +135,26 @@
}
]
},
{
"name": "getOldLockedTokenId",
"mutability": "readonly",
"inputs": [],
"outputs": [
{
"type": "TokenIdentifier"
}
]
},
{
"name": "getOldFactoryAddress",
"mutability": "readonly",
"inputs": [],
"outputs": [
{
"type": "Address"
}
]
},
{
"name": "getWrappedLpTokenId",
"mutability": "readonly",
Expand Down Expand Up @@ -251,6 +299,24 @@
}
]
},
{
"name": "increaseProxyPairTokenEnergy",
"mutability": "mutable",
"payableInTokens": [
"*"
],
"inputs": [
{
"name": "lock_epochs",
"type": "u64"
}
],
"outputs": [
{
"type": "EsdtTokenPayment"
}
]
},
{
"name": "enterFarmProxy",
"mutability": "mutable",
Expand All @@ -261,9 +327,17 @@
{
"name": "farm_address",
"type": "Address"
},
{
"name": "opt_original_caller",
"type": "optional<Address>",
"multi_arg": true
}
],
"outputs": [
{
"type": "EsdtTokenPayment"
},
{
"type": "EsdtTokenPayment"
}
Expand All @@ -276,22 +350,20 @@
"*"
],
"inputs": [
{
"name": "exit_amount",
"type": "BigUint"
},
{
"name": "farm_address",
"type": "Address"
},
{
"name": "opt_original_caller",
"type": "optional<Address>",
"multi_arg": true
}
],
"outputs": [
{
"type": "EsdtTokenPayment"
},
{
"type": "EsdtTokenPayment"
},
{
"type": "EsdtTokenPayment"
}
Expand All @@ -307,6 +379,11 @@
{
"name": "farm_address",
"type": "Address"
},
{
"name": "opt_original_caller",
"type": "optional<Address>",
"multi_arg": true
}
],
"outputs": [
Expand All @@ -319,15 +396,15 @@
]
},
{
"name": "compoundRewardsProxy",
"name": "increaseProxyFarmTokenEnergy",
"mutability": "mutable",
"payableInTokens": [
"*"
],
"inputs": [
{
"name": "farm_address",
"type": "Address"
"name": "lock_epochs",
"type": "u64"
}
],
"outputs": [
Expand Down Expand Up @@ -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": [
Expand Down
3 changes: 2 additions & 1 deletion src/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@
"withTokenMerge": 40000000
},
"removeLiquidity": 30000000,
"defaultMergeWLPT": 20000000
"defaultMergeWLPT": 20000000,
"increaseEnergy": 20000000
},
"farms": {
"v1.2": {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/proxy/proxy.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -27,6 +28,7 @@ import { WrappedFarmTokenResolverV2 } from './wrappedFarm.token.v2.resolver';
forwardRef(() => ProxyFarmModule),
forwardRef(() => ProxyModuleV2),
FarmModule,
EnergyModule,
],
providers: [
ProxyAbiService,
Expand Down
44 changes: 44 additions & 0 deletions src/modules/proxy/proxy.transaction.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {}
Expand Down Expand Up @@ -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<TransactionModel> {
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,
);
}
}
Loading
Loading