Skip to content

Commit cdc619c

Browse files
[ENG-928] Add policy for slow deposits for all future users. (backport #3119) (#3132)
Co-authored-by: Kefan Cao <76069770+Kefancao@users.noreply.github.com>
1 parent cf48c16 commit cdc619c

File tree

1 file changed

+118
-176
lines changed

1 file changed

+118
-176
lines changed

indexer/services/comlink/src/lib/call-policies.ts

Lines changed: 118 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ const goFastHandlerProxyByChainId: Record<string, string> = {
1717
[mainnet.id.toString()]: '0xa11CC0eFb1B3AcD95a2B8cd316E8c132E16048b5',
1818
};
1919

20+
const ethCCTPRelayerProxyByChainId: Record<string, string> = {
21+
[mainnet.id.toString()]: '0xf33e750336e9C0D4E2f4c0D450d753030693CC71',
22+
[arbitrum.id.toString()]: '0x6d4d4A979D766e8b87C985a61B262cfCDf8d6446',
23+
[base.id.toString()]: '0xddAFc591Dda57dCF7b3E9Cf83e72c8591fC9cC24',
24+
[optimism.id.toString()]: '0x55e4Cf6a73ED8B3307bE610f516fB41BA000f1E5',
25+
[avalanche.id.toString()]: '0xB19Ff56BD455C2515207BDbdEDC68B57fBA9A78D',
26+
};
27+
2028
// this value limit is set to restrict usdc transfers less than 100k.
2129
const valueLimit = config.CALL_POLICY_VALUE_LIMIT;
2230

@@ -31,188 +39,122 @@ const valueLimit = config.CALL_POLICY_VALUE_LIMIT;
3139
*/
3240
function constructPolicy(chainId: string): (dydxAddress: string) => Promise<CallPolicyParams<Abi, `0x${string}`>> {
3341
const goFastHandlerProxy = goFastHandlerProxyByChainId[chainId] as `0x${string}`;
34-
return (dydxAddress: string) => Promise.resolve({
35-
policyVersion: CallPolicyVersion.V0_0_5,
36-
permissions: [
37-
{
38-
target: usdcAddressByChainId[chainId] as `0x${string}`, // usdc on chainId
39-
abi,
40-
valueLimit,
41-
functionName: 'approve',
42-
args: [
43-
{
44-
condition: ParamCondition.EQUAL,
45-
value: goFastHandlerProxy,
46-
},
47-
null,
48-
],
49-
},
50-
{
51-
target: goFastHandlerProxy,
52-
abi,
53-
valueLimit,
54-
functionName: 'submitOrder',
55-
args: [
56-
null,
57-
null,
58-
null,
59-
null,
60-
null,
61-
null,
62-
{
63-
condition: ParamCondition.SLICE_EQUAL,
64-
value: encodeToHexAndPad(dydxAddress),
65-
start: 277,
66-
length: 42,
67-
},
68-
],
69-
},
70-
{
71-
target: goFastHandlerProxy,
72-
abi,
73-
valueLimit,
74-
functionName: 'swapAndSubmitOrder',
75-
args: [
76-
null,
77-
null,
78-
null,
79-
null,
80-
null,
81-
null,
82-
null,
83-
null,
84-
null,
85-
{
86-
condition: ParamCondition.SLICE_EQUAL,
87-
value: encodeToHexAndPad(dydxAddress),
88-
start: 277,
89-
length: 42,
90-
},
91-
],
92-
},
93-
],
94-
});
95-
}
96-
97-
export async function getEthereumCallPolicy(dydxAddress: string): Promise<CallPolicyParams<Abi, `0x${string}`>> {
98-
const ethCCTPRelayerProxy = '0xf33e750336e9C0D4E2f4c0D450d753030693CC71';
99-
const goFastHandlerProxy = goFastHandlerProxyByChainId[mainnet.id.toString()] as `0x${string}`;
42+
const ethCCTPRelayerProxy = ethCCTPRelayerProxyByChainId[chainId] as `0x${string}`;
10043
// get the noble forwarding address.
10144
// cctp mints to a noble forwarding address which forwards to the dydx address.
102-
const nobleForwardingAddress = await getNobleForwardingAddress(dydxAddress);
103-
const nobleForwardingAddressEvm = nobleToHex(nobleForwardingAddress);
104-
// for go fast
105-
const destinationCallataAddr = encodeToHexAndPad(dydxAddress);
106-
return {
107-
policyVersion: CallPolicyVersion.V0_0_5,
108-
permissions: [
109-
// slow deposits, via CCTP Relayer. USDC Bridge
110-
{
111-
target: ethCCTPRelayerProxy,
112-
abi,
113-
valueLimit,
114-
functionName: 'requestCCTPTransferWithCaller', // for usdc bridges
115-
args: [
116-
null,
117-
null,
118-
{
119-
// mint recipient is the noble forwarding address.
120-
condition: ParamCondition.EQUAL,
121-
value: nobleForwardingAddressEvm,
122-
},
123-
null,
124-
null,
125-
null,
126-
],
127-
},
128-
// slow deposits, via CCTP Relayer. ETH Bridge
129-
{
130-
target: ethCCTPRelayerProxy,
131-
abi,
132-
valueLimit,
133-
functionName: 'swapAndRequestCCTPTransferWithCaller', // for eth bridges
134-
args: [
135-
null,
136-
null,
137-
null,
138-
null,
139-
{
140-
// mint recipient is the noble forwarding address.
141-
condition: ParamCondition.EQUAL,
142-
value: nobleForwardingAddressEvm,
143-
},
144-
null,
145-
null,
146-
null,
147-
],
148-
},
149-
// allow skip.go bridge smart contract permissions.
150-
{
151-
target: usdcAddressByChainId[mainnet.id.toString()] as `0x${string}`, // usdc on ethereum
152-
abi,
153-
valueLimit,
154-
functionName: 'approve',
155-
args: [
156-
{
157-
condition: ParamCondition.ONE_OF,
158-
value: [
159-
ethCCTPRelayerProxy,
160-
goFastHandlerProxy,
161-
],
162-
},
163-
null,
164-
],
165-
},
166-
// skip go fast bridges.
167-
{
168-
target: goFastHandlerProxy,
169-
abi,
170-
valueLimit,
171-
functionName: 'submitOrder',
172-
args: [
173-
null,
174-
null,
175-
null,
176-
null,
177-
null,
178-
null,
179-
{
180-
condition: ParamCondition.SLICE_EQUAL,
181-
value: destinationCallataAddr,
182-
start: 277,
183-
length: 42,
184-
},
185-
],
186-
},
187-
{
188-
target: goFastHandlerProxy,
189-
abi,
190-
valueLimit,
191-
functionName: 'swapAndSubmitOrder',
192-
args: [
193-
null,
194-
null,
195-
null,
196-
null,
197-
null,
198-
null,
199-
null,
200-
null,
201-
null,
202-
{
203-
condition: ParamCondition.SLICE_EQUAL,
204-
value: destinationCallataAddr,
205-
start: 277,
206-
length: 42,
207-
},
208-
],
209-
},
210-
],
45+
return async (dydxAddress: string) => {
46+
const nobleForwardingAddress = await getNobleForwardingAddress(dydxAddress);
47+
const nobleForwardingAddressEvm = nobleToHex(nobleForwardingAddress);
48+
const destinationCallataAddr = encodeToHexAndPad(dydxAddress);
49+
return Promise.resolve({
50+
policyVersion: CallPolicyVersion.V0_0_5,
51+
permissions: [
52+
// slow deposits, via CCTP Relayer. USDC Bridge
53+
{
54+
target: ethCCTPRelayerProxy,
55+
abi,
56+
valueLimit,
57+
functionName: 'requestCCTPTransferWithCaller', // for usdc bridges
58+
args: [
59+
null,
60+
null,
61+
{
62+
// mint recipient is the noble forwarding address.
63+
condition: ParamCondition.EQUAL,
64+
value: nobleForwardingAddressEvm,
65+
},
66+
null,
67+
null,
68+
null,
69+
],
70+
},
71+
// slow deposits, via CCTP Relayer. ETH Bridge
72+
{
73+
target: ethCCTPRelayerProxy,
74+
abi,
75+
valueLimit,
76+
functionName: 'swapAndRequestCCTPTransferWithCaller', // for eth bridges
77+
args: [
78+
null,
79+
null,
80+
null,
81+
null,
82+
{
83+
// mint recipient is the noble forwarding address.
84+
condition: ParamCondition.EQUAL,
85+
value: nobleForwardingAddressEvm,
86+
},
87+
null,
88+
null,
89+
null,
90+
],
91+
},
92+
{
93+
target: usdcAddressByChainId[chainId] as `0x${string}`, // usdc on chainId
94+
abi,
95+
valueLimit,
96+
functionName: 'approve',
97+
args: [
98+
{
99+
condition: ParamCondition.ONE_OF,
100+
value: [
101+
ethCCTPRelayerProxy,
102+
goFastHandlerProxy,
103+
],
104+
},
105+
null,
106+
],
107+
},
108+
{
109+
target: goFastHandlerProxy,
110+
abi,
111+
valueLimit,
112+
functionName: 'submitOrder',
113+
args: [
114+
null,
115+
null,
116+
null,
117+
null,
118+
null,
119+
null,
120+
{
121+
condition: ParamCondition.SLICE_EQUAL,
122+
value: destinationCallataAddr,
123+
start: 277,
124+
length: 42,
125+
},
126+
],
127+
},
128+
{
129+
target: goFastHandlerProxy,
130+
abi,
131+
valueLimit,
132+
functionName: 'swapAndSubmitOrder',
133+
args: [
134+
null,
135+
null,
136+
null,
137+
null,
138+
null,
139+
null,
140+
null,
141+
null,
142+
null,
143+
{
144+
condition: ParamCondition.SLICE_EQUAL,
145+
value: destinationCallataAddr,
146+
start: 277,
147+
length: 42,
148+
},
149+
],
150+
},
151+
],
152+
});
211153
};
212154
}
213155

214156
export const callPolicyByChainId: Record<string, (dydxAddress: string) => Promise<CallPolicyParams<Abi, `0x${string}`>>> = {
215-
[mainnet.id.toString()]: getEthereumCallPolicy,
157+
[mainnet.id.toString()]: constructPolicy(mainnet.id.toString()),
216158
[arbitrum.id.toString()]: constructPolicy(arbitrum.id.toString()),
217159
[avalanche.id.toString()]: constructPolicy(avalanche.id.toString()),
218160
[optimism.id.toString()]: constructPolicy(optimism.id.toString()),

0 commit comments

Comments
 (0)