Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bridgecontract
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
movabridge
bridgecontract
Commits
2a13fa70
Commit
2a13fa70
authored
Nov 14, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update scripts
parent
5d7762d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
305 deletions
+25
-305
addtokens.js
scripts/addtokens.js
+24
-64
deploy-bridge.js
scripts/deploy-bridge.js
+1
-1
deploy.json
scripts/deploy.json
+0
-22
getinfo.js
scripts/getinfo.js
+0
-55
setconfig.js
scripts/setconfig.js
+0
-163
No files found.
scripts/addtokens.js
View file @
2a13fa70
const
fs
=
require
(
"
fs
"
);
const
fs
=
require
(
"
fs
"
);
const
path
=
require
(
"
path
"
);
const
hre
=
require
(
"
hardhat
"
);
const
hre
=
require
(
"
hardhat
"
);
const
DEPLOY_FILE
=
path
.
join
(
__dirname
,
"
deploy.json
"
);
const
DEPLOY_FILE
=
"
deploy.json
"
;
const
DEPLOY_TOKENS
=
"
tokenpairs.json
"
async
function
mintToken
(
tokenA
,
tokenB
,
user
)
{
async
function
getTokenPairs
(
chainId
)
{
var
amount
=
hre
.
ethers
.
parseEther
(
"
1000000
"
)
if
(
!
fs
.
existsSync
(
DEPLOY_TOKENS
))
{
var
tx
=
await
tokenA
.
mint
(
user
,
amount
);
throw
new
Error
(
"
tokenpairs.json file not found
"
);
await
tx
.
wait
();
console
.
log
(
"
Minted TTA to user:
"
,
user
,
"
amount:
"
,
hre
.
ethers
.
formatEther
(
amount
));
tx
=
await
tokenB
.
mint
(
user
,
amount
);
await
tx
.
wait
();
console
.
log
(
"
Minted TTB to user:
"
,
user
,
"
amount:
"
,
hre
.
ethers
.
formatEther
(
amount
));
}
async
function
treasuryApprove
(
tokenA
,
tokenB
,
bridgeAddr
,
treasury
)
{
var
tx
=
await
tokenA
.
connect
(
treasury
).
approve
(
bridgeAddr
,
hre
.
ethers
.
MaxUint256
);
await
tx
.
wait
();
console
.
log
(
"
Approved TTA for bridge:
"
,
bridgeAddr
);
tx
=
await
tokenB
.
connect
(
treasury
).
approve
(
bridgeAddr
,
hre
.
ethers
.
MaxUint256
);
await
tx
.
wait
();
console
.
log
(
"
Approved TTB for bridge:
"
,
bridgeAddr
);
}
async
function
getTargetChain
(
chainId
)
{
if
(
!
fs
.
existsSync
(
DEPLOY_FILE
))
{
throw
new
Error
(
"
deploy.json file not found
"
);
}
}
const
deployData
=
JSON
.
parse
(
fs
.
readFileSync
(
DEPLOY_FILE
,
"
utf8
"
));
const
tokenData
=
JSON
.
parse
(
fs
.
readFileSync
(
DEPLOY_TOKENS
,
"
utf8
"
));
if
(
!
deploy
Data
[
chainId
])
{
if
(
!
token
Data
[
chainId
])
{
throw
new
Error
(
`No
deployment
data found for chainId
${
chainId
}
`
);
throw
new
Error
(
`No
token pair
data found for chainId
${
chainId
}
`
);
}
}
// iterator deployData to find the key not equal to chainId, chainId is number, and the key is string,
const
tokenAddrs
=
tokenData
[
chainId
];
// we need convert targetChainId from string to number before return.
return
tokenAddrs
for
(
const
key
in
deployData
)
{
if
(
key
!=
chainId
.
toString
())
{
return
Number
(
key
);
}
}
throw
new
Error
(
`No target chain found for chainId
${
chainId
}
`
);
}
}
async
function
getDeploy
(
chainId
)
{
async
function
getDeploy
(
chainId
)
{
...
@@ -60,37 +34,22 @@ async function getDeploy(chainId) {
...
@@ -60,37 +34,22 @@ async function getDeploy(chainId) {
return
{
bridge
}
return
{
bridge
}
}
}
async
function
setOutConfig
(
curTokenMap
,
targetTokenMap
,
targetChainId
,
bridge
)
{
async
function
setOutConfig
(
bridge
,
tokenPair
)
{
const
outConfig
A
=
{
const
outConfig
=
{
receiveToken
:
await
targetTokenMap
.
tokenA
.
getAddress
()
,
receiveToken
:
tokenPair
.
targetToken
,
fee
:
hre
.
ethers
.
parseEther
(
"
0.05
"
),
fee
:
hre
.
ethers
.
parseEther
(
tokenPair
.
fee
),
limit
:
hre
.
ethers
.
parseEther
(
"
1000
"
),
limit
:
hre
.
ethers
.
parseEther
(
tokenPair
.
limit
),
isBurn
:
false
,
isBurn
:
tokenPair
.
isBurn
,
enabled
:
true
,
enabled
:
true
,
};
};
const
outConfigB
=
{
receiveToken
:
await
targetTokenMap
.
tokenB
.
getAddress
(),
fee
:
hre
.
ethers
.
parseEther
(
"
0.04
"
),
limit
:
hre
.
ethers
.
parseEther
(
"
1000
"
),
isBurn
:
false
,
enabled
:
true
,
}
var
tx
=
await
bridge
.
changeOutConfig
(
var
tx
=
await
bridge
.
changeOutConfig
(
await
curTokenMap
.
tokenA
.
getAddress
()
,
tokenPair
.
token
,
t
argetChainId
,
// Target chain ID
t
okenPair
.
targetChain
,
outConfig
A
outConfig
);
);
await
tx
.
wait
();
await
tx
.
wait
();
console
.
log
(
"
Set out config for tokenA to chain
"
,
targetChainId
,
"
tx
"
,
tx
.
hash
);
console
.
log
(
"
set out config for token
"
,
tokenPair
.
token
,
"
to chain
"
,
tokenPair
.
targetChain
,
"
tx
"
,
tx
.
hash
);
tx
=
await
bridge
.
changeOutConfig
(
await
curTokenMap
.
tokenB
.
getAddress
(),
targetChainId
,
// Target chain ID
outConfigB
);
await
tx
.
wait
();
console
.
log
(
"
Set out config for tokenB to chain
"
,
targetChainId
,
"
tx
"
,
tx
.
hash
);
}
}
// Define the script
// Define the script
...
@@ -98,9 +57,10 @@ async function main() {
...
@@ -98,9 +57,10 @@ async function main() {
const
chainId
=
await
hre
.
ethers
.
provider
.
getNetwork
().
then
(
network
=>
network
.
chainId
);
const
chainId
=
await
hre
.
ethers
.
provider
.
getNetwork
().
then
(
network
=>
network
.
chainId
);
const
curChainDeploy
=
await
getDeploy
(
chainId
);
const
curChainDeploy
=
await
getDeploy
(
chainId
);
const
tokenPairs
=
await
getTokenPairs
(
chainId
);
await
setConfig
(
curChainDeploy
.
bridge
);
for
(
var
i
=
0
;
i
<
tokenPairs
.
length
;
i
++
)
{
console
.
log
(
"
Configuration set successfully for chain
"
,
chainId
);
await
setOutConfig
(
curChainDeploy
.
bridge
,
tokenPairs
[
i
]);
}
}
}
// Run the script
// Run the script
...
...
scripts/deploy-bridge.js
View file @
2a13fa70
...
@@ -2,7 +2,7 @@ const fs = require("fs");
...
@@ -2,7 +2,7 @@ const fs = require("fs");
const
path
=
require
(
"
path
"
);
const
path
=
require
(
"
path
"
);
const
{
ethers
,
upgrades
}
=
require
(
"
hardhat
"
);
const
{
ethers
,
upgrades
}
=
require
(
"
hardhat
"
);
const
DEPLOY_FILE
=
path
.
join
(
__dirname
,
"
deploy.json
"
)
;
const
DEPLOY_FILE
=
"
deploy.json
"
;
let
INITIAL_VALIDATORS
=
process
.
env
.
BRIDGE_VALIDATORS
let
INITIAL_VALIDATORS
=
process
.
env
.
BRIDGE_VALIDATORS
let
TREASURY
=
process
.
env
.
TREASURY
let
TREASURY
=
process
.
env
.
TREASURY
...
...
scripts/deploy.json
deleted
100644 → 0
View file @
5d7762d3
{
"97"
:
{
"tokenA"
:
"0x9B372e3e5666cc05aC48750DB9D277fD0b69364f"
,
"tokenB"
:
"0x6Fd62C3a41B46162919B6A7Be1455f511Ed7a9Cf"
,
"bridge"
:
"0x2D578F646e0334F3CBA9B17D00c7357372a63FEa"
},
"6174"
:
{
"tokenA"
:
"0xEC8e0c8255Fcef6b6c594b783817DfF7C99086E0"
,
"tokenB"
:
"0x218453ea15f6aC033D9A5b4Ba0D6d08180F25626"
,
"bridge"
:
"0x674e408c6Bc59e551912f118662732cddDc3d0c9"
},
"8891"
:
{
"tokenA"
:
"0xfCcF95F6E309Cd5f316704fC3a759a048FC08a4e"
,
"tokenB"
:
"0x1eea18e6797D002280b0A9B61d4ac8513e106D20"
,
"bridge"
:
"0xEC8e0c8255Fcef6b6c594b783817DfF7C99086E0"
},
"10323"
:
{
"tokenA"
:
"0x4Cd477d71BB971A0ab5d22AAea1D1E8B147a1777"
,
"tokenB"
:
"0xA43954798A770128d440A2D82BA039ADcCe1B224"
,
"bridge"
:
"0x9F225b7BCC4697414D4F6aC1CB985D07d34dAe0a"
}
}
\ No newline at end of file
scripts/getinfo.js
deleted
100644 → 0
View file @
5d7762d3
const
fs
=
require
(
"
fs
"
);
const
path
=
require
(
"
path
"
);
const
hre
=
require
(
"
hardhat
"
);
let
INITIAL_VALIDATORS
=
process
.
env
.
BRIDGE_VALIDATORS
let
TREASURY
=
process
.
env
.
TREASURY
const
DEPLOY_FILE
=
path
.
join
(
__dirname
,
"
deploy.json
"
);
async
function
getOutConfig
(
bridge
,
token
,
targetchain
)
{
const
config
=
await
bridge
.
outConfiguration
(
token
,
targetchain
)
console
.
log
(
"
OutConfig for token:
"
,
token
,
"
to chain:
"
,
targetchain
,
"
config:
"
,
config
)
}
async
function
getFeeReceiver
(
bridge
)
{
const
receiver
=
await
bridge
.
feeReceiver
();
console
.
log
(
"
Fee Receiver:
"
,
receiver
);
return
receiver
;
}
async
function
getDeploy
(
chainId
)
{
if
(
!
fs
.
existsSync
(
DEPLOY_FILE
))
{
throw
new
Error
(
"
deploy.json file not found
"
);
}
const
deployData
=
JSON
.
parse
(
fs
.
readFileSync
(
DEPLOY_FILE
,
"
utf8
"
));
if
(
!
deployData
[
chainId
])
{
throw
new
Error
(
`No deployment data found for chainId
${
chainId
}
`
);
}
const
addrs
=
deployData
[
chainId
];
const
tokenA
=
await
hre
.
ethers
.
getContractAt
(
"
TestToken
"
,
addrs
.
tokenA
);
const
tokenB
=
await
hre
.
ethers
.
getContractAt
(
"
TestToken
"
,
addrs
.
tokenB
);
const
bridge
=
await
hre
.
ethers
.
getContractAt
(
"
Bridge
"
,
addrs
.
bridge
);
return
{
tokenA
,
tokenB
,
bridge
}
}
// Define the script
async
function
main
()
{
const
chainId
=
await
hre
.
ethers
.
provider
.
getNetwork
().
then
(
network
=>
network
.
chainId
);
const
targetChainId
=
chainId
===
6174
n
?
8891
:
6174
;
console
.
log
(
"
Current chain ID:
"
,
chainId
,
"
Target chain ID:
"
,
targetChainId
);
const
curChainDeploy
=
await
getDeploy
(
chainId
);
await
getFeeReceiver
(
curChainDeploy
.
bridge
);
// await getOutConfig(curChainDeploy.bridge, await curChainDeploy.tokenA.getAddress(), targetChainId);
}
// Run the script
main
().
catch
((
error
)
=>
{
console
.
error
(
"
Error:
"
,
error
);
});
\ No newline at end of file
scripts/setconfig.js
deleted
100644 → 0
View file @
5d7762d3
const
fs
=
require
(
"
fs
"
);
const
path
=
require
(
"
path
"
);
const
hre
=
require
(
"
hardhat
"
);
let
INITIAL_VALIDATORS
=
process
.
env
.
BRIDGE_VALIDATORS
let
TREASURY
=
process
.
env
.
TREASURY
let
FEE_RECEIVER
=
process
.
env
.
FEE_RECEIVER
const
DEPLOY_FILE
=
path
.
join
(
__dirname
,
"
deploy.json
"
);
async
function
addValidators
(
contract
,
validators
)
{
let
validatorList
=
validators
.
split
(
'
,
'
)
for
(
let
i
=
0
;
i
<
validatorList
.
length
;
i
++
)
{
var
tx
=
await
contract
.
addValidator
(
validatorList
[
i
])
await
tx
.
wait
();
console
.
log
(
"
Added validator:
"
,
validatorList
[
i
]);
}
}
async
function
setValidatorRequired
(
contract
,
count
)
{
var
tx
=
await
contract
.
changeValidRequired
(
count
);
await
tx
.
wait
();
console
.
log
(
"
Set validator required to:
"
,
count
);
}
async
function
setTreasury
(
contract
,
treasury
)
{
var
tx
=
await
contract
.
setTreasury
(
treasury
);
await
tx
.
wait
();
console
.
log
(
"
Set treasury to:
"
,
treasury
);
}
async
function
setFeeReceiver
(
contract
,
receiver
)
{
var
tx
=
await
contract
.
setFeeReceiver
(
receiver
);
await
tx
.
wait
();
console
.
log
(
"
Set feeRecevier to:
"
,
receiver
);
}
async
function
mintToken
(
tokenA
,
tokenB
,
user
)
{
var
amount
=
hre
.
ethers
.
parseEther
(
"
1000000
"
)
var
tx
=
await
tokenA
.
mint
(
user
,
amount
);
await
tx
.
wait
();
console
.
log
(
"
Minted TTA to user:
"
,
user
,
"
amount:
"
,
hre
.
ethers
.
formatEther
(
amount
));
tx
=
await
tokenB
.
mint
(
user
,
amount
);
await
tx
.
wait
();
console
.
log
(
"
Minted TTB to user:
"
,
user
,
"
amount:
"
,
hre
.
ethers
.
formatEther
(
amount
));
}
async
function
treasuryApprove
(
tokenA
,
tokenB
,
bridgeAddr
,
treasury
)
{
var
tx
=
await
tokenA
.
connect
(
treasury
).
approve
(
bridgeAddr
,
hre
.
ethers
.
MaxUint256
);
await
tx
.
wait
();
console
.
log
(
"
Approved TTA for bridge:
"
,
bridgeAddr
);
tx
=
await
tokenB
.
connect
(
treasury
).
approve
(
bridgeAddr
,
hre
.
ethers
.
MaxUint256
);
await
tx
.
wait
();
console
.
log
(
"
Approved TTB for bridge:
"
,
bridgeAddr
);
}
async
function
setTokenTreasuryConfig
(
tokenA
,
tokenB
,
bridge
)
{
var
tokenAAddr
=
await
tokenA
.
getAddress
();
var
tx
=
await
bridge
.
setTreasuryConfig
(
tokenAAddr
,
hre
.
ethers
.
parseEther
(
'
50000
'
),
5000
,
true
);
await
tx
.
wait
();
console
.
log
(
"
Set treasury config for TTA
"
);
var
tokenBAddr
=
await
tokenB
.
getAddress
();
tx
=
await
bridge
.
setTreasuryConfig
(
tokenBAddr
,
hre
.
ethers
.
parseEther
(
'
50000
'
),
500
,
true
);
await
tx
.
wait
();
console
.
log
(
"
Set treasury config for TTB
"
);
}
async
function
setConfig
(
tokenA
,
tokenB
,
bridge
)
{
if
(
!
INITIAL_VALIDATORS
||
!
TREASURY
)
{
throw
new
Error
(
"
Environment variables BRIDGE_VALIDATORS or TREASURY are not set.
"
);
}
[
owner
,
treasury
]
=
await
hre
.
ethers
.
getSigners
();
await
setValidatorRequired
(
bridge
,
2
);
await
addValidators
(
bridge
,
INITIAL_VALIDATORS
);
await
setFeeReceiver
(
bridge
,
FEE_RECEIVER
);
await
setTreasury
(
bridge
,
TREASURY
);
await
setTokenTreasuryConfig
(
tokenA
,
tokenB
,
bridge
);
var
bridgeAddr
=
await
bridge
.
getAddress
();
await
mintToken
(
tokenA
,
tokenB
,
bridgeAddr
)
// if treasury is exist, do approve .
// if (treasury.address) {
// // test environment, mint token and approve.
// await mintToken(tokenA, tokenB, TREASURY);
// await treasuryApprove(tokenA, tokenB, bridgeAddr, treasury);
// }
}
async
function
getDeploy
(
chainId
)
{
if
(
!
fs
.
existsSync
(
DEPLOY_FILE
))
{
throw
new
Error
(
"
deploy.json file not found
"
);
}
const
deployData
=
JSON
.
parse
(
fs
.
readFileSync
(
DEPLOY_FILE
,
"
utf8
"
));
if
(
!
deployData
[
chainId
])
{
throw
new
Error
(
`No deployment data found for chainId
${
chainId
}
`
);
}
const
addrs
=
deployData
[
chainId
];
const
tokenA
=
await
hre
.
ethers
.
getContractAt
(
"
TestToken
"
,
addrs
.
tokenA
);
const
tokenB
=
await
hre
.
ethers
.
getContractAt
(
"
TestToken
"
,
addrs
.
tokenB
);
const
bridge
=
await
hre
.
ethers
.
getContractAt
(
"
Bridge
"
,
addrs
.
bridge
);
return
{
tokenA
,
tokenB
,
bridge
}
}
async
function
setOutConfig
(
curTokenMap
,
targetTokenMap
,
targetChainId
,
bridge
)
{
const
outConfigA
=
{
receiveToken
:
await
targetTokenMap
.
tokenA
.
getAddress
(),
fee
:
hre
.
ethers
.
parseEther
(
"
0.05
"
),
limit
:
hre
.
ethers
.
parseEther
(
"
1000
"
),
isBurn
:
false
,
enabled
:
true
,
};
const
outConfigB
=
{
receiveToken
:
await
targetTokenMap
.
tokenB
.
getAddress
(),
fee
:
hre
.
ethers
.
parseEther
(
"
0.04
"
),
limit
:
hre
.
ethers
.
parseEther
(
"
1000
"
),
isBurn
:
false
,
enabled
:
true
,
}
var
tx
=
await
bridge
.
changeOutConfig
(
await
curTokenMap
.
tokenA
.
getAddress
(),
targetChainId
,
// Target chain ID
outConfigA
);
await
tx
.
wait
();
console
.
log
(
"
Set out config for tokenA to chain
"
,
targetChainId
,
"
tx
"
,
tx
.
hash
);
tx
=
await
bridge
.
changeOutConfig
(
await
curTokenMap
.
tokenB
.
getAddress
(),
targetChainId
,
// Target chain ID
outConfigB
);
await
tx
.
wait
();
console
.
log
(
"
Set out config for tokenB to chain
"
,
targetChainId
,
"
tx
"
,
tx
.
hash
);
}
// Define the script
async
function
main
()
{
const
chainId
=
await
hre
.
ethers
.
provider
.
getNetwork
().
then
(
network
=>
network
.
chainId
);
const
targetChainId
=
chainId
===
97
n
?
10323
:
97
;
// const targetChainId = chainId === 6174n ? 8891 : 6174;
console
.
log
(
"
Current chain ID:
"
,
chainId
,
"
Target chain ID:
"
,
targetChainId
);
const
curChainDeploy
=
await
getDeploy
(
chainId
);
const
targetChainDeploy
=
await
getDeploy
(
targetChainId
);
await
setConfig
(
curChainDeploy
.
tokenA
,
curChainDeploy
.
tokenB
,
curChainDeploy
.
bridge
);
await
setOutConfig
(
curChainDeploy
,
targetChainDeploy
,
targetChainId
,
curChainDeploy
.
bridge
);
console
.
log
(
"
Configuration set successfully for chain
"
,
chainId
);
}
// Run the script
main
().
catch
((
error
)
=>
{
console
.
error
(
"
Error:
"
,
error
);
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment