Skip to content

Commit

Permalink
Add aerodrome gauge address (#338)
Browse files Browse the repository at this point in the history
* add gauge address to slipstream pools

* package version update
  • Loading branch information
jiaqi-aperture authored Sep 13, 2024
1 parent a2fed01 commit 3459462
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aperture_finance/uniswap-v3-automation-sdk",
"version": "3.10.3",
"version": "3.10.4",
"description": "SDK for Aperture's CLMM automation platform",
"author": "Aperture Finance <[email protected]>",
"license": "MIT",
Expand Down
21 changes: 21 additions & 0 deletions src/viem/pool/getSlipStreamPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type SlipStreamPool = {
token1: Address;
fee: number;
tickSpacing: number;
gaugeAddress: Address;
};

export async function getSlipStreamPools(
Expand Down Expand Up @@ -59,6 +60,25 @@ export async function getSlipStreamPools(
})
).map(({ result }) => result!);

const gaugeAddresses = (
await publicClient.multicall({
contracts: poolAddresses.map((address) => ({
address,
abi: [
{
inputs: [],
name: 'gauge',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
] as const,
functionName: 'gauge',
...opt,
})),
})
).map(({ result }) => result!);

const getPoolKeys = (address: Address) => {
const poolOpt = {
address,
Expand Down Expand Up @@ -91,6 +111,7 @@ export async function getSlipStreamPools(
token1,
fee,
tickSpacing,
gaugeAddress: gaugeAddresses[i],
});
}

Expand Down
34 changes: 9 additions & 25 deletions src/viem/position/getSlipStreamStakePositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,22 @@ import { Address, PublicClient } from 'viem';

import { getSlipStreamPools } from '../pool';

export type SlipStreamPosition = {
address: Address;
gaugeAddress: Address;
};

export async function getSlipStreamStakePositions(
owner: Address,
publicClient: PublicClient,
blockNumber?: bigint,
) {
const pools = await getSlipStreamPools(publicClient, blockNumber);
const gaugeAddresses = pools.map((pool) => pool.gaugeAddress);
const opt = {
blockNumber,
};

const gaugeAddresses = (
await publicClient.multicall({
contracts: pools.map((pool) => ({
address: pool.address,
abi: [
{
inputs: [],
name: 'gauge',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
] as const,
functionName: 'gauge',
...opt,
})),
})
).map(({ result }) => result!);

const stakedPositions = (
await publicClient.multicall({
contracts: gaugeAddresses.map((address) => ({
Expand All @@ -55,11 +42,8 @@ export async function getSlipStreamStakePositions(
})
).map(({ result }) => result! ?? []);

const result: Map<bigint, string> = new Map();
stakedPositions.map((positionList, index) =>
positionList.forEach((position) =>
result.set(position, gaugeAddresses[index]),
),
return stakedPositions.reduce(
(accumulator, value) => accumulator.concat(value),
[],
);
return result;
}
6 changes: 1 addition & 5 deletions test/hardhat/hardhat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,7 @@ describe('Stake position tests', function () {
client,
blockNumber,
);
expect(stakedPositions.size).to.be.equal(1);
expect(stakedPositions.keys().next().value).to.be.equal(436963n);
expect(stakedPositions.values().next().value).to.be.equal(
'0xF33a96b5932D9E9B9A0eDA447AbD8C9d48d2e0c8',
);
expect(stakedPositions.length).to.be.equal(1);
});
});

Expand Down

0 comments on commit 3459462

Please sign in to comment.