Skip to content

Commit 246ee27

Browse files
Add Support for swapUsdcAndstake Contract Implementation (#1191)
* add: swapAndstake * add: utils and * add: export * Fix broken testcases - lib/agent/fixtures/swap-usdc/getEstimatedDevForUsdc.spec.ts: Remove unnecessary test case - lib/agent/fixtures/swap-usdc/getEstimatedUsdcForDev.spec.ts: Add missing callStatic key * add : unit test * follows the latest structures * impl positionsCreateWithArbitraryTokens * fix broken testcases * bugfix for `overrides` --------- Co-authored-by: aggre <[email protected]>
1 parent bd1b19e commit 246ee27

15 files changed

+1303
-0
lines changed

lib/agent/common/agentAddresses.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ export const agentAddresses = {
2424
v2: undefined,
2525
v3: '0x9265Cf9e6Dc5B163bDB75d51661Ca8EA3b6150c4',
2626
},
27+
swapArbitraryTokens: {
28+
swap: '0x0000000',
29+
},
30+
usdc: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
2731
weth: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
2832
},
2933
mumbai: {
3034
swap: {
3135
v2: undefined,
3236
v3: '0x60650E5a95864b989C8b7B0357a2d4979a34c6AF',
3337
},
38+
swapArbitraryTokens: {
39+
swap: '0x0000000',
40+
},
41+
usdc: '0x0000000',
3442
weth: '0x3c8d6A6420C922c88577352983aFFdf7b0F977cA',
3543
},
3644
},
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { AgentAvailableNetworks } from '../const'
2+
import type { UndefinedOr } from '@devprotocol/util-ts'
3+
import {
4+
createSwapArbitraryTokensContract,
5+
SwapArbitraryTokensContract,
6+
} from '../../fixtures/swap-arbitrary-tokens'
7+
import type { ContractRunner } from 'ethers'
8+
9+
type Results = readonly [undefined, UndefinedOr<SwapArbitraryTokensContract>]
10+
11+
const cache: WeakMap<ContractRunner, Results> = new WeakMap()
12+
13+
export const clientsUtilsSwapTokensForStake = async (
14+
provider: ContractRunner,
15+
): Promise<Results> => {
16+
const res =
17+
cache.get(provider) ??
18+
(await (async () => {
19+
const net = await provider.provider?.getNetwork()
20+
const detectedNetwork = AgentAvailableNetworks.find(
21+
({ chainId }) => chainId === Number(net?.chainId),
22+
)
23+
const cont = detectedNetwork
24+
? createSwapArbitraryTokensContract(provider)(
25+
detectedNetwork.map.swapArbitraryTokens?.swap || '',
26+
)
27+
: undefined
28+
const results: Results = [undefined, cont]
29+
// eslint-disable-next-line functional/no-expression-statement
30+
cache.set(provider, results)
31+
return results
32+
})())
33+
return res
34+
}

lib/agent/common/const.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export type AgentAvailableNetwork = {
4848
readonly v2: undefined
4949
readonly v3: string
5050
}
51+
readonly swapArbitraryTokens?: {
52+
readonly swap: string
53+
}
54+
readonly usdc?: string
5155
readonly weth?: string
5256
}
5357
}

0 commit comments

Comments
 (0)