Skip to content

Commit cffc082

Browse files
authored
Merge pull request #165 from gnosischain/feat/usds-upgrade-step1
feat: USDS upgrade, step 1
2 parents 983ba7a + c5e53e8 commit cffc082

30 files changed

Lines changed: 503 additions & 107 deletions

app/pages/api/tokens.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { NextApiRequest, NextApiResponse } from 'next'
22

3-
import { NATIVE_TOKEN_ADDRESS } from '@/src/constants/config/common'
3+
import { NATIVE_TOKEN_ADDRESS, USDS_ADDRESS } from '@/src/constants/config/common'
44
import { isSameString } from '@/src/utils/tools'
55
import { Token as BaseToken } from '@/types/token'
66
import bridgedTokens from '@/src/constants/bridged_tokens.json'
@@ -35,6 +35,7 @@ export default function handler(_: NextApiRequest, res: NextApiResponse<Array<To
3535
const { address, decimals, foreign_address, icon_url, name, origin_chain_id, symbol } = token
3636
const isWethOnXdai = isSameString(address, WETH_ON_XDAI)
3737
const isDaiOnMainnet = isSameString(foreign_address, DAI_ON_MAINNET)
38+
const isUsdsOnMainnet = isSameString(foreign_address, USDS_ADDRESS)
3839
let extraTokens: Array<Token> = []
3940

4041
if (isDaiOnMainnet) {
@@ -107,6 +108,41 @@ export default function handler(_: NextApiRequest, res: NextApiResponse<Array<To
107108
]
108109
}
109110

111+
if (isUsdsOnMainnet) {
112+
extraTokens = [
113+
{
114+
chainId: Number(origin_chain_id),
115+
address: foreign_address,
116+
decimals: Number(decimals),
117+
logoURI: icon_url ?? undefined,
118+
name: name.replace(bridgedTokenName, ''),
119+
symbol,
120+
extensions: {
121+
bridgeInfo: {
122+
100: {
123+
tokenAddress: NATIVE_TOKEN_ADDRESS,
124+
},
125+
},
126+
},
127+
},
128+
{
129+
chainId: 100,
130+
address: NATIVE_TOKEN_ADDRESS,
131+
decimals: Number(decimals),
132+
logoURI: icon_url ?? undefined,
133+
name: 'xDai',
134+
symbol: 'xDAI',
135+
extensions: {
136+
bridgeInfo: {
137+
[origin_chain_id]: {
138+
tokenAddress: foreign_address,
139+
},
140+
},
141+
},
142+
},
143+
]
144+
}
145+
110146
return [
111147
{
112148
chainId: Number(origin_chain_id),
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
[
2+
{ "inputs": [], "stateMutability": "nonpayable", "type": "constructor" },
3+
{ "inputs": [], "name": "ClaimUsdsNotSupported", "type": "error" },
4+
{ "inputs": [], "name": "InvalidInitialization", "type": "error" },
5+
{ "inputs": [], "name": "NotInitializing", "type": "error" },
6+
{
7+
"inputs": [{ "internalType": "address", "name": "owner", "type": "address" }],
8+
"name": "OwnableInvalidOwner",
9+
"type": "error"
10+
},
11+
{
12+
"inputs": [{ "internalType": "address", "name": "account", "type": "address" }],
13+
"name": "OwnableUnauthorizedAccount",
14+
"type": "error"
15+
},
16+
{
17+
"anonymous": false,
18+
"inputs": [{ "indexed": false, "internalType": "uint64", "name": "version", "type": "uint64" }],
19+
"name": "Initialized",
20+
"type": "event"
21+
},
22+
{
23+
"anonymous": false,
24+
"inputs": [
25+
{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" },
26+
{ "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
27+
],
28+
"name": "OwnershipTransferred",
29+
"type": "event"
30+
},
31+
{
32+
"inputs": [],
33+
"name": "DAI",
34+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
35+
"stateMutability": "view",
36+
"type": "function"
37+
},
38+
{
39+
"inputs": [],
40+
"name": "FOREIGN_AMB",
41+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
42+
"stateMutability": "view",
43+
"type": "function"
44+
},
45+
{
46+
"inputs": [],
47+
"name": "FOREIGN_OMNIBRIDGE",
48+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
49+
"stateMutability": "view",
50+
"type": "function"
51+
},
52+
{
53+
"inputs": [],
54+
"name": "FOREIGN_XDAIBRIDGE",
55+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
56+
"stateMutability": "view",
57+
"type": "function"
58+
},
59+
{
60+
"inputs": [],
61+
"name": "USDS",
62+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
63+
"stateMutability": "view",
64+
"type": "function"
65+
},
66+
{
67+
"inputs": [],
68+
"name": "WETH_OMNIBRIDGE_ROUTER",
69+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
70+
"stateMutability": "view",
71+
"type": "function"
72+
},
73+
{
74+
"inputs": [
75+
{ "internalType": "bytes", "name": "message", "type": "bytes" },
76+
{ "internalType": "bytes", "name": "signatures", "type": "bytes" }
77+
],
78+
"name": "executeSignatures",
79+
"outputs": [],
80+
"stateMutability": "nonpayable",
81+
"type": "function"
82+
},
83+
{
84+
"inputs": [
85+
{ "internalType": "bytes", "name": "message", "type": "bytes" },
86+
{ "internalType": "bytes", "name": "signatures", "type": "bytes" }
87+
],
88+
"name": "executeSignaturesUSDS",
89+
"outputs": [],
90+
"stateMutability": "nonpayable",
91+
"type": "function"
92+
},
93+
{
94+
"inputs": [{ "internalType": "address", "name": "owner", "type": "address" }],
95+
"name": "initialize",
96+
"outputs": [],
97+
"stateMutability": "nonpayable",
98+
"type": "function"
99+
},
100+
{
101+
"inputs": [],
102+
"name": "owner",
103+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
104+
"stateMutability": "view",
105+
"type": "function"
106+
},
107+
{
108+
"inputs": [
109+
{ "internalType": "address", "name": "token", "type": "address" },
110+
{ "internalType": "address", "name": "recipient", "type": "address" },
111+
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
112+
],
113+
"name": "recoverLockedFund",
114+
"outputs": [],
115+
"stateMutability": "nonpayable",
116+
"type": "function"
117+
},
118+
{
119+
"inputs": [
120+
{ "internalType": "address", "name": "_token", "type": "address" },
121+
{ "internalType": "address", "name": "_receiver", "type": "address" },
122+
{ "internalType": "uint256", "name": "_amount", "type": "uint256" }
123+
],
124+
"name": "relayTokens",
125+
"outputs": [],
126+
"stateMutability": "payable",
127+
"type": "function"
128+
},
129+
{
130+
"inputs": [],
131+
"name": "renounceOwnership",
132+
"outputs": [],
133+
"stateMutability": "nonpayable",
134+
"type": "function"
135+
},
136+
{
137+
"inputs": [
138+
{ "internalType": "bytes", "name": "message", "type": "bytes" },
139+
{ "internalType": "bytes", "name": "signatures", "type": "bytes" }
140+
],
141+
"name": "safeExecuteSignaturesWithAutoGasLimit",
142+
"outputs": [],
143+
"stateMutability": "nonpayable",
144+
"type": "function"
145+
},
146+
{
147+
"inputs": [
148+
{ "internalType": "address", "name": "_token", "type": "address" },
149+
{ "internalType": "address", "name": "_route", "type": "address" }
150+
],
151+
"name": "setRoute",
152+
"outputs": [],
153+
"stateMutability": "nonpayable",
154+
"type": "function"
155+
},
156+
{
157+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
158+
"name": "tokenRoutes",
159+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
160+
"stateMutability": "view",
161+
"type": "function"
162+
},
163+
{
164+
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
165+
"name": "transferOwnership",
166+
"outputs": [],
167+
"stateMutability": "nonpayable",
168+
"type": "function"
169+
}
170+
]

app/src/constants/bridged_tokens.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9762,6 +9762,22 @@
97629762
"symbol": "UDT",
97639763
"total_supply": "9936213363153110036806",
97649764
"type": "ERC-20"
9765+
},
9766+
{
9767+
"bridge_type": "xdai",
9768+
"foreign_address": "0xdC035D45d973E3EC169d2276DDab16f1e407384F",
9769+
"origin_chain_id": "1",
9770+
"address": "",
9771+
"circulating_market_cap": null,
9772+
"decimals": "18",
9773+
"exchange_rate": null,
9774+
"holders": "2281",
9775+
"icon_url": null,
9776+
"is_bridged": true,
9777+
"name": "USDS",
9778+
"symbol": "USDS",
9779+
"total_supply": "3854025994000000000000000000",
9780+
"type": "ERC-20"
97659781
}
97669782
]
97679783
}

app/src/constants/config/chains.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const chainsConfig: Record<ChainsValues, ChainConfig> = {
2424
bridge: {
2525
DAI: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
2626
wForeignNative: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH
27+
USDS: '0xdc035d45d973e3ec169d2276ddab16f1e407384f',
2728
},
2829
},
2930
// [Chains.chiado]: {

app/src/constants/config/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export const WALLET_CONNECT_DAPP_URL = process.env.NEXT_PUBLIC_WALLET_CONNECT_DA
1111
export const WALLET_CONNECT_PROJECT_ID = process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID || ''
1212

1313
export const NATIVE_TOKEN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
14+
15+
export const USDS_ADDRESS = '0xdC035D45d973E3EC169d2276DDab16f1e407384F'

app/src/constants/config/contracts.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export const contracts = {
6767
},
6868
abi: AMBBridgeHelper_abi,
6969
},
70+
BridgeRouter: {
71+
address: {
72+
[Chains.mainnet]: '0x9a873656c19Efecbfb4f9FAb5B7acdeAb466a0B0',
73+
[Chains.gnosis]: '',
74+
},
75+
},
7076
} as const
7177

7278
export type ContractsKeys = keyof typeof contracts

app/src/constants/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type ChainConfig = {
2121
bridge: {
2222
DAI: string
2323
wForeignNative: string
24+
USDS?: string
2425
}
2526
}
2627

app/src/constants/xdaiToken.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Token } from '@/types/token'
2+
import { getIcon } from '@/src/utils/icons'
3+
import { NATIVE_TOKEN_ADDRESS, USDS_ADDRESS } from '@/src/constants/config/common'
4+
5+
export const xdaiToken: Token = {
6+
chainId: 100,
7+
address: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
8+
decimals: 18,
9+
logoURI: getIcon('xdai'),
10+
name: 'xDAI',
11+
symbol: 'xDAI',
12+
extensions: {
13+
bridgeInfo: {
14+
1: { tokenAddress: USDS_ADDRESS },
15+
100: { tokenAddress: NATIVE_TOKEN_ADDRESS },
16+
},
17+
},
18+
}

app/src/hooks/bridge/useBridgeContracts.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Chains, ChainsValues } from '@/src/constants/config/types'
44
import { JsonRpcBatchProvider } from '@ethersproject/providers'
55

66
import {
7-
ForeignBridgeErcToNative__factory,
7+
ForeignBridgeRouter__factory,
88
ForeignOmniMediator__factory,
99
HomeBridgeErcToNative__factory,
1010
HomeOmniMediator__factory,
@@ -29,10 +29,17 @@ export const getBridgeContract = (
2929
})
3030

3131
if (isNativeBridge) {
32-
return (isHome ? HomeBridgeErcToNative__factory : ForeignBridgeErcToNative__factory).connect(
33-
contracts.XDAIBridge.address[fromChainId],
34-
provider,
35-
)
32+
if (isHome) {
33+
return HomeBridgeErcToNative__factory.connect(
34+
contracts.XDAIBridge.address[fromChainId],
35+
provider,
36+
)
37+
} else {
38+
return ForeignBridgeRouter__factory.connect(
39+
contracts.BridgeRouter.address[fromChainId],
40+
provider,
41+
)
42+
}
3643
} else if (fromChainId !== Chains.gnosis && isNativeToken) {
3744
return NativeOmniBridgeMediator__factory.connect(
3845
contracts.omniBridgeNativeToken.address[fromChainId],

app/src/hooks/bridge/useBridgeLimits.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ const useBridgeLimits = (
154154
const isForeignDAI =
155155
_fromChainId != Chains.gnosis &&
156156
isSameString(_fromTokenAddress, chainsConfig[_fromChainId].bridge.DAI)
157+
const isForeignUSDS =
158+
_fromChainId != Chains.gnosis &&
159+
isSameString(_fromTokenAddress, chainsConfig[_fromChainId].bridge.USDS)
157160

158-
if (isGnosisXDai || isForeignDAI || overwrittenMediator) {
161+
if (isGnosisXDai || isForeignDAI || overwrittenMediator || isForeignUSDS) {
159162
const contractAddress = overwrittenMediator
160163
? TokenOverrideManager.getOverride(_fromTokenAddress).mediator // use the overridden mediator address.
161164
: contracts.XDAIBridge.address[_fromChainId]

0 commit comments

Comments
 (0)