Skip to content

Commit

Permalink
feat: update earn addresses and abis (#639)
Browse files Browse the repository at this point in the history
* feat: update earn addresses and abis

* chore: remove comments

* feat: convert supportedDepositTokens addresses to lowercase
  • Loading branch information
0xKoaj authored Jan 7, 2025
1 parent 970e35d commit 6259786
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 194 deletions.
20 changes: 5 additions & 15 deletions src/services/earn/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ import { Chains } from '@chains';
import { PERMIT2_ADAPTER_CONTRACT } from '@services/permit2/utils/config';
import { Contract } from '@shared/contracts';

export const EARN_VAULT = Contract.with({ defaultAddress: '0x58e5d76fbbd7e1b51f0fc0f66b7734e108be0461' }) // Polygon
.and({ address: '0x9324a1f92a82b539f8fb1194a0b894025581ec33', onChain: Chains.BASE })
.build();
export const EARN_VAULT = Contract.with({ defaultAddress: '0x9332b2ceCcb56beD1d727c5e350E174699f96cCA' }).build();

export const EARN_VAULT_COMPANION = Contract.with({ defaultAddress: '0x814CE82aCDE3D99aB6f92e2722A87d8daa20d6cB' }) // Polygon
.and({ address: '0x260B192b9A5679121FF7f9F0Cf3FED3238753A48', onChain: Chains.BASE })
.build();
export const EARN_VAULT_COMPANION = Contract.with({ defaultAddress: '0xAbbFc43F00e88d0ab836c8c630A98E6a27094Bb5' }).build();

export const EARN_STRATEGY_REGISTRY = Contract.with({ defaultAddress: '0xb034a43d1ffe0f88ed3a50fc096179f543fd3f3a' }) // Polygon
.and({ address: '0x04a3bd5cc16435f27e7b31e44e4e522c0bc413e9', onChain: Chains.BASE })
.build();
export const EARN_STRATEGY_REGISTRY = Contract.with({ defaultAddress: '0x020ebf53F4e5Ef859e18e2973bd8d8b9AF5C9c9F' }).build();

export const COMPANION_SWAPPER_CONTRACT = PERMIT2_ADAPTER_CONTRACT;

export const DELAYED_WITHDRAWAL_MANAGER = Contract.with({ defaultAddress: '0x92fdb7604ca7e5635421332d4c9a00680dfa53e6' }) // Polygon
.and({ address: '0x9b5004c016fe00bb81c90e2e2beaa128d1815108', onChain: Chains.BASE })
.build();
export const DELAYED_WITHDRAWAL_MANAGER = Contract.with({ defaultAddress: '0x0ed7f185b12f8C5Cb91daA16edDb1778E404d5D0' }).build();

export const EXTERNAL_FIREWALL = Contract.with({ defaultAddress: '0x6B35d4869C2E72F29fbc9a2EE3a29B5502DC1e10' }) // Polygon
.and({ address: '0x0aDa65e309d609294ADC39Add02aA52331e372Ee', onChain: Chains.BASE })
.build();
export const EXTERNAL_FIREWALL = Contract.with({ defaultAddress: '0xDFaF88Ee13CECF3d854F5A4eebffe99a242bbe8A' }).build();
18 changes: 5 additions & 13 deletions src/services/earn/earn-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export class EarnService implements IEarnService {

const [, , tokenId] = positionId.split('-');
const bigIntPositionId = BigInt(tokenId);
const [positionOwner, strategyId] = await this.providerService.getViemPublicClient({ chainId }).multicall({
const [positionOwner, [strategyId]] = await this.providerService.getViemPublicClient({ chainId }).multicall({
contracts: [
{
abi: vaultAbi,
Expand Down Expand Up @@ -636,20 +636,13 @@ export class EarnService implements IEarnService {
const vault = EARN_VAULT.address(chainId);
const [, , tokenId] = positionId.split('-');
const bigIntPositionId = BigInt(tokenId);
const strategyId = await this.providerService.getViemPublicClient({ chainId }).readContract({
const [strategyId, strategyAddress] = await this.providerService.getViemPublicClient({ chainId }).readContract({
address: vault,
abi: vaultAbi,
functionName: 'positionsStrategy',
args: [bigIntPositionId],
});

const strategyAddress = await this.providerService.getViemPublicClient({ chainId }).readContract({
address: EARN_STRATEGY_REGISTRY.address(chainId),
abi: strategyRegistryAbi,
functionName: 'getStrategy',
args: [strategyId],
});

let amountToWithdraw = BigInt(amount);
if (amount == Uint.MAX_256) {
const [, balance] = await this.providerService.getViemPublicClient({ chainId }).readContract({
Expand Down Expand Up @@ -975,22 +968,21 @@ export class EarnService implements IEarnService {
});

// Check if the deposit token is supported by the strategy and get the asset
const [asset, isDepositTokenSupported] = await this.providerService.getViemPublicClient({ chainId }).multicall({
const [asset, supportedDepositTokens] = await this.providerService.getViemPublicClient({ chainId }).multicall({
contracts: [
{ abi: strategyAbi, address: strategy, functionName: 'asset' },
{
abi: strategyAbi,
address: strategy,
functionName: 'isDepositTokenSupported',
args: [depositToken as ViemAddress],
functionName: 'supportedDepositTokens',
},
],
allowFailure: false,
multicallAddress: MULTICALL_CONTRACT.address(chainId),
batchSize: 0,
});

return { needsSwap: !isDepositTokenSupported, asset };
return { needsSwap: !supportedDepositTokens.map(toLower).includes(toLower(depositToken)), asset };
}

private async buildCompanionMulticall({
Expand Down
76 changes: 15 additions & 61 deletions src/shared/abis/earn-delayed-withdrawal-manager.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,33 @@
export default [
{
type: 'function',
name: 'withdrawableFunds',
inputs: [
{
name: 'positionId',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'token',
type: 'address',
internalType: 'address',
},
],
outputs: [
{
name: 'funds',
type: 'uint256',
internalType: 'uint256',
},
{ internalType: 'uint256', name: 'positionId', type: 'uint256' },
{ internalType: 'address', name: 'token', type: 'address' },
],
name: 'withdrawableFunds',
outputs: [{ internalType: 'uint256', name: 'funds', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
type: 'function',
name: 'withdraw',
inputs: [
{
name: 'positionId',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'token',
type: 'address',
internalType: 'address',
},
{
name: 'recipient',
type: 'address',
internalType: 'address',
},
{ internalType: 'uint256', name: 'positionId', type: 'uint256' },
{ internalType: 'address', name: 'token', type: 'address' },
{ internalType: 'address', name: 'recipient', type: 'address' },
],
name: 'withdraw',
outputs: [
{
name: 'withdrawn',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'stillPending',
type: 'uint256',
internalType: 'uint256',
},
{ internalType: 'uint256', name: 'withdrawn', type: 'uint256' },
{ internalType: 'uint256', name: 'stillPending', type: 'uint256' },
],
stateMutability: 'nonpayable',
type: 'function',
},
{
type: 'function',
inputs: [{ internalType: 'bytes[]', name: 'data', type: 'bytes[]' }],
name: 'multicall',
inputs: [
{
name: 'data',
type: 'bytes[]',
internalType: 'bytes[]',
},
],
outputs: [
{
name: 'results',
type: 'bytes[]',
internalType: 'bytes[]',
},
],
outputs: [{ internalType: 'bytes[]', name: 'results', type: 'bytes[]' }],
stateMutability: 'payable',
type: 'function',
},
] as const;
6 changes: 3 additions & 3 deletions src/shared/abis/earn-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default [
{ inputs: [], name: 'asset', outputs: [{ internalType: 'address', name: '', type: 'address' }], stateMutability: 'view', type: 'function' },
{
inputs: [{ internalType: 'address', name: 'depositToken', type: 'address' }],
name: 'isDepositTokenSupported',
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
inputs: [],
name: 'supportedDepositTokens',
outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
stateMutability: 'view',
type: 'function',
},
Expand Down
116 changes: 22 additions & 94 deletions src/shared/abis/earn-vault-companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default [
stateMutability: 'payable',
type: 'function',
},

{
inputs: [
{ internalType: 'address', name: 'token', type: 'address' },
Expand Down Expand Up @@ -121,115 +120,44 @@ export default [
{ internalType: 'address', name: 'recipient', type: 'address' },
],
name: 'withdraw',
outputs: [
{ internalType: 'uint256[]', name: '', type: 'uint256[]' },
{ internalType: 'enum IEarnStrategy.WithdrawalType[]', name: '', type: 'uint8[]' },
],
outputs: [{ internalType: 'uint256[]', name: '', type: 'uint256[]' }],
stateMutability: 'payable',
type: 'function',
},
{
type: 'function',
name: 'claimDelayedWithdraw',
inputs: [
{
name: 'manager',
type: 'address',
internalType: 'contract IDelayedWithdrawalManager',
},
{
name: 'positionId',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'token',
type: 'address',
internalType: 'address',
},
{
name: 'recipient',
type: 'address',
internalType: 'address',
},
{ internalType: 'contract IDelayedWithdrawalManager', name: 'manager', type: 'address' },
{ internalType: 'uint256', name: 'positionId', type: 'uint256' },
{ internalType: 'address', name: 'token', type: 'address' },
{ internalType: 'address', name: 'recipient', type: 'address' },
],
name: 'claimDelayedWithdraw',
outputs: [
{
name: '',
type: 'uint256',
internalType: 'uint256',
},
{
name: '',
type: 'uint256',
internalType: 'uint256',
},
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
],
stateMutability: 'payable',
type: 'function',
},
{
type: 'function',
name: 'specialWithdraw',
inputs: [
{
name: 'vault',
type: 'address',
internalType: 'contract IEarnVault',
},
{
name: 'positionId',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'withdrawalCode',
type: 'uint256',
internalType: 'SpecialWithdrawalCode',
},
{
name: 'toWithdraw',
type: 'uint256[]',
internalType: 'uint256[]',
},
{
name: 'withdrawalData',
type: 'bytes',
internalType: 'bytes',
},
{
name: 'recipient',
type: 'address',
internalType: 'address',
},
{ internalType: 'contract IEarnVault', name: 'vault', type: 'address' },
{ internalType: 'uint256', name: 'positionId', type: 'uint256' },
{ internalType: 'SpecialWithdrawalCode', name: 'withdrawalCode', type: 'uint256' },
{ internalType: 'uint256[]', name: 'toWithdraw', type: 'uint256[]' },
{ internalType: 'bytes', name: 'withdrawalData', type: 'bytes' },
{ internalType: 'address', name: 'recipient', type: 'address' },
],
name: 'specialWithdraw',
outputs: [
{
name: 'tokens',
type: 'address[]',
internalType: 'address[]',
},
{
name: 'balanceChanges',
type: 'uint256[]',
internalType: 'uint256[]',
},
{
name: 'actualWithdrawnTokens',
type: 'address[]',
internalType: 'address[]',
},
{
name: 'actualWithdrawnAmounts',
type: 'uint256[]',
internalType: 'uint256[]',
},
{
name: 'result',
type: 'bytes',
internalType: 'bytes',
},
{ internalType: 'address[]', name: 'tokens', type: 'address[]' },
{ internalType: 'uint256[]', name: 'balanceChanges', type: 'uint256[]' },
{ internalType: 'address[]', name: 'actualWithdrawnTokens', type: 'address[]' },
{ internalType: 'uint256[]', name: 'actualWithdrawnAmounts', type: 'uint256[]' },
{ internalType: 'bytes', name: 'result', type: 'bytes' },
],
stateMutability: 'payable',
type: 'function',
},
{
inputs: [
Expand Down
17 changes: 9 additions & 8 deletions src/shared/abis/earn-vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default [
],
name: 'createPosition',
outputs: [
{ internalType: 'uint256', name: 'positionId', type: 'uint256' },
{ internalType: 'uint256', name: 'assetsDeposited', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
],
stateMutability: 'payable',
type: 'function',
Expand All @@ -32,7 +32,7 @@ export default [
{ internalType: 'uint256', name: 'depositAmount', type: 'uint256' },
],
name: 'increasePosition',
outputs: [{ internalType: 'uint256', name: 'assetsDeposited', type: 'uint256' }],
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'payable',
type: 'function',
},
Expand All @@ -51,10 +51,7 @@ export default [
{ internalType: 'address', name: 'recipient', type: 'address' },
],
name: 'withdraw',
outputs: [
{ internalType: 'uint256[]', name: 'withdrawn', type: 'uint256[]' },
{ internalType: 'enum IEarnStrategy.WithdrawalType[]', name: 'withdrawalTypes', type: 'uint8[]' },
],
outputs: [{ internalType: 'uint256[]', name: 'withdrawn', type: 'uint256[]' }],
stateMutability: 'payable',
type: 'function',
},
Expand All @@ -65,6 +62,7 @@ export default [
outputs: [
{ internalType: 'address[]', name: '', type: 'address[]' },
{ internalType: 'uint256[]', name: '', type: 'uint256[]' },
{ internalType: 'StrategyId', name: '', type: 'uint96' },
{ internalType: 'contract IEarnStrategy', name: '', type: 'address' },
],
stateMutability: 'view',
Expand All @@ -73,7 +71,10 @@ export default [
{
inputs: [{ internalType: 'uint256', name: 'positionId', type: 'uint256' }],
name: 'positionsStrategy',
outputs: [{ internalType: 'StrategyId', name: 'strategyId', type: 'uint96' }],
outputs: [
{ internalType: 'StrategyId', name: 'strategyId', type: 'uint96' },
{ internalType: 'contract IEarnStrategy', name: 'strategy', type: 'address' },
],
stateMutability: 'view',
type: 'function',
},
Expand Down

0 comments on commit 6259786

Please sign in to comment.