Skip to content

Commit

Permalink
change to USDC
Browse files Browse the repository at this point in the history
  • Loading branch information
Freddy Li authored and Freddy Li committed Jul 31, 2024
1 parent 2cba9b5 commit 53b8dce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
43 changes: 24 additions & 19 deletions scripts/standalone/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ const supportedDestDomains = [
domainID: 1,
chainID: 1
},
{
domainID: 2,
chainID: 2
}
// {
// domainID: 2,
// chainID: 2
// }
]

// those account are configured in the substrate-node runtime, and are only applicable for sygma pallet standalone node,
// other parachain might have different runtime config so those account address need to be adjusted accordingly
const FeeReserveAccountAddress = "5ELLU7ibt5ZrNEYRwohtaRBDBa3TzcWwwPELBPSWWd2mbgv3";
const TransferReserveAccount = "5EMepC39b7E2zfM9g6CkPp8KCAxGTh7D4w4T2tFjmjpd4tPw";
const TransferReserveNativeAccount = "5EYCAe5jLbHcAAMKvLFSXgCTbPrLgBJusvPwfKcaKzuf5X5e";
const TransferReserveOtherAccount = "5EYCAe5jLbHcAAMKvLFiGhk3htXY8jQncbLTDGJQnpnPMAVp";

async function main() {
const sygmaPalletProvider = new WsProvider(process.env.PALLETWSENDPOINT || 'ws://127.0.0.1:9944');
const sygmaPalletProvider = new WsProvider(process.env.PALLETWSENDPOINT || 'ws://127.0.0.1:9900');
const api = await ApiPromise.create({
provider: sygmaPalletProvider,
});
Expand Down Expand Up @@ -86,6 +87,7 @@ async function main() {
await createAsset(api, usdcAssetID, usdcAdmin, usdcMinBalance, true, sudo);
await setAssetMetadata(api, usdcAssetID, usdcName, usdcSymbol, usdcDecimal, true, sudo);
await mintAsset(api, usdcAssetID, usdcAdmin, bn1e12.mul(new BN(100)), true, sudo); // mint 100 USDC to Alice
await mintAsset(api, usdcAssetID, TransferReserveOtherAccount, bn1e12.mul(new BN(100)), true, sudo); // mint 100 USDC to OtherTokenReserved account

// create ERC20TST test asset (foreign asset)
const erc20tstAssetID = 2001;
Expand All @@ -94,9 +96,10 @@ async function main() {
const erc20tstName = "erc20tst test asset";
const erc20tstSymbol = "ERC20TST";
const erc20tstDecimal = 18;
await createAsset(api, erc20tstAssetID, erc20tstAdmin, erc20tstMinBalance, true, sudo);
await setAssetMetadata(api, erc20tstAssetID, erc20tstName, erc20tstSymbol, erc20tstDecimal, true, sudo);
await mintAsset(api, erc20tstAssetID, erc20tstAdmin, bn1e18.mul(new BN(100)), true, sudo); // mint 100 ERC20TST to Alice
// await createAsset(api, erc20tstAssetID, erc20tstAdmin, erc20tstMinBalance, true, sudo);
// await setAssetMetadata(api, erc20tstAssetID, erc20tstName, erc20tstSymbol, erc20tstDecimal, true, sudo);
// await mintAsset(api, erc20tstAssetID, erc20tstAdmin, bn1e18.mul(new BN(100)), true, sudo); // mint 100 ERC20TST to Alice
// await mintAsset(api, erc20tstAssetID, TransferReserveOtherAccount, bn1e12.mul(new BN(100)), true, sudo); // mint 100 ERC20TST to OtherTokenReserved account

// create ERC20TSTD20 test asset (foreign asset)
const erc20tstd20AssetID = 2002;
Expand All @@ -105,25 +108,27 @@ async function main() {
const erc20tstd20Name = "erc20tstd20 test asset";
const erc20tstd20Symbol = "ERC20TSTD20";
const erc20tstd20Decimal = 20;
await createAsset(api, erc20tstd20AssetID, erc20tstd20Admin, erc20tstd20MinBalance, true, sudo);
await setAssetMetadata(api, erc20tstd20AssetID, erc20tstd20Name, erc20tstd20Symbol, erc20tstd20Decimal, true, sudo);
await mintAsset(api, erc20tstd20AssetID, erc20tstd20Admin, bn1e20.mul(new BN(100)), true, sudo); // mint 100 ERC20TSTD20 to Alice
// await createAsset(api, erc20tstd20AssetID, erc20tstd20Admin, erc20tstd20MinBalance, true, sudo);
// await setAssetMetadata(api, erc20tstd20AssetID, erc20tstd20Name, erc20tstd20Symbol, erc20tstd20Decimal, true, sudo);
// await mintAsset(api, erc20tstd20AssetID, erc20tstd20Admin, bn1e20.mul(new BN(100)), true, sudo); // mint 100 ERC20TSTD20 to Alice
// await mintAsset(api, erc20tstd20AssetID, TransferReserveOtherAccount, bn1e12.mul(new BN(100)), true, sudo); // mint 100 ERC20TSTD20 to OtherTokenReserved account

// set fee for tokens with domains
for (const domain of supportedDestDomains) {
await setFeeHandler(api, domain.domainID, getUSDCAssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo)
await setFeeRate(api, domain.domainID, getUSDCAssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo);

await setFeeHandler(api, domain.domainID, getERC20TSTAssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo)
await setFeeRate(api, domain.domainID, getERC20TSTAssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo);

await setFeeHandler(api, domain.domainID, getERC20TSTD20AssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo)
await setFeeRate(api, domain.domainID, getERC20TSTD20AssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo);
// await setFeeHandler(api, domain.domainID, getERC20TSTAssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo)
// await setFeeRate(api, domain.domainID, getERC20TSTAssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo);
//
// await setFeeHandler(api, domain.domainID, getERC20TSTD20AssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo)
// await setFeeRate(api, domain.domainID, getERC20TSTD20AssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo);
}

// transfer some native asset to FeeReserveAccount and TransferReserveAccount as Existential Deposit(aka ED)
// transfer some native asset to FeeReserveAccount and TransferReserveAccounts as Existential Deposit(aka ED)
await setBalance(api, FeeReserveAccountAddress, bn1e12.mul(new BN(10000)), true, sudo); // set balance to 10000 native asset
await setBalance(api, TransferReserveAccount, bn1e12.mul(new BN(10000)), true, sudo); // set balance to 10000 native asset
await setBalance(api, TransferReserveNativeAccount, bn1e12.mul(new BN(10000)), true, sudo); // set balance to 10000 native asset
await setBalance(api, TransferReserveOtherAccount, bn1e12.mul(new BN(10000)), true, sudo); // set balance to 10000 native asset

// set up MPC address(will also unpause all registered domains)
if (mpcAddr) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/standalone/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function getUSDCAssetId(api) {
interior: api.createType('StagingXcmV3Junctions', {
X3: [
api.createType('StagingXcmV3Junction', {
Parachain: api.createType('Compact<U32>', 2004)
Parachain: api.createType('Compact<U32>', 2005)
}),
api.createType('StagingXcmV3Junction', {
// 0x7379676d61 is general key of USDC defined in sygma substrate pallet runtime for testing
Expand Down Expand Up @@ -359,7 +359,7 @@ function getERC20TSTAssetId(api) {
interior: api.createType('StagingXcmV3Junctions', {
X3: [
api.createType('StagingXcmV3Junction', {
Parachain: api.createType('Compact<U32>', 2004)
Parachain: api.createType('Compact<U32>', 2005)
}),
api.createType('StagingXcmV3Junction', {
GeneralKey: {
Expand All @@ -386,7 +386,7 @@ function getERC20TSTD20AssetId(api) {
interior: api.createType('StagingXcmV3Junctions', {
X3: [
api.createType('StagingXcmV3Junction', {
Parachain: api.createType('Compact<U32>', 2004)
Parachain: api.createType('Compact<U32>', 2005)
}),
api.createType('StagingXcmV3Junction', {
GeneralKey: {
Expand Down
31 changes: 17 additions & 14 deletions substrate-node/standalone/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ const DEST_VERIFYING_CONTRACT_ADDRESS: &str = "6CdE2Cd82a4F8B74693Ff5e194c19CA08
fn bridge_accounts_generator() -> BTreeMap<XcmAssetId, AccountId32> {
let mut account_map: BTreeMap<XcmAssetId, AccountId32> = BTreeMap::new();
account_map.insert(NativeLocation::get().into(), BridgeAccountNative::get());
account_map.insert(UsdtLocation::get().into(), BridgeAccountOtherToken::get());
account_map.insert(UsdcLocation::get().into(), BridgeAccountOtherToken::get());
account_map.insert(ERC20TSTLocation::get().into(), BridgeAccountOtherToken::get());
account_map.insert(ERC20TSTD20Location::get().into(), BridgeAccountOtherToken::get());
account_map
Expand Down Expand Up @@ -426,16 +426,18 @@ parameter_types! {
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
// NativeLocation is the representation of the current parachain's native asset location in substrate, it can be various on different parachains
pub NativeLocation: MultiLocation = MultiLocation::here();
// UsdtLocation is the representation of the USDT asset location in substrate
// USDT is a foreign asset, and in our local testing env, it's being registered on Parachain 2004 with the following location
pub UsdtLocation: MultiLocation = MultiLocation::new(
// UsdcLocation is the representation of the USDC asset location in substrate
// USDC is a foreign asset, and in our local testing env, it's being registered on Parachain 2004 with the following location
// USDC is a reserved token
pub UsdcLocation: MultiLocation = MultiLocation::new(
1,
X3(
Parachain(2005),
Parachain(1000),
slice_to_generalkey(b"sygma"),
slice_to_generalkey(b"usdt"),
slice_to_generalkey(b"usdc"),
),
);
// ERC20TSTLocation is a reserved token
pub ERC20TSTLocation: MultiLocation = MultiLocation::new(
1,
X3(
Expand All @@ -444,6 +446,7 @@ parameter_types! {
slice_to_generalkey(b"erc20tst"),
),
);
// ERC20TSTD20Location is a reserved token
pub ERC20TSTD20Location: MultiLocation = MultiLocation::new(
1,
X3(
Expand All @@ -452,23 +455,23 @@ parameter_types! {
slice_to_generalkey(b"erc20tstd20"),
),
);
// UsdtAssetId is the substrate assetID of USDT
pub UsdtAssetId: AssetId = 2000;
// UsdcAssetId is the substrate assetID of USDC
pub UsdcAssetId: AssetId = 2000;
pub ERC20TSTAssetId: AssetId = 2001;
pub ERC20TSTD20AssetId: AssetId = 2002;
// NativeResourceId is the resourceID that mapping with the current parachain native asset
pub NativeResourceId: ResourceId = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000001");
// UsdtResourceId is the resourceID that mapping with the foreign asset USDT
pub UsdtResourceId: ResourceId = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000300");
// UsdcResourceId is the resourceID that mapping with the foreign asset USDC
pub UsdcResourceId: ResourceId = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000300");
pub ERC20TSTResourceId: ResourceId = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000000");
pub ERC20TSTD20ResourceId: ResourceId = hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000900");

// ResourcePairs is where all supported assets and their associated resourceID are binding
pub ResourcePairs: Vec<(XcmAssetId, ResourceId)> = vec![(NativeLocation::get().into(), NativeResourceId::get()), (UsdtLocation::get().into(), UsdtResourceId::get()), (ERC20TSTLocation::get().into(), ERC20TSTResourceId::get()), (ERC20TSTD20Location::get().into(), ERC20TSTD20ResourceId::get())];
pub ResourcePairs: Vec<(XcmAssetId, ResourceId)> = vec![(NativeLocation::get().into(), NativeResourceId::get()), (UsdcLocation::get().into(), UsdcResourceId::get()), (ERC20TSTLocation::get().into(), ERC20TSTResourceId::get()), (ERC20TSTD20Location::get().into(), ERC20TSTD20ResourceId::get())];
// SygmaBridgePalletId is the palletIDl
// this is used as the replacement of handler address in the ProposalExecution event
pub const SygmaBridgePalletId: PalletId = PalletId(*b"sygma/01");
pub AssetDecimalPairs: Vec<(XcmAssetId, u8)> = vec![(NativeLocation::get().into(), 12u8), (UsdtLocation::get().into(), 12u8), (ERC20TSTLocation::get().into(), 18u8), (ERC20TSTD20Location::get().into(), 20u8)];
pub AssetDecimalPairs: Vec<(XcmAssetId, u8)> = vec![(NativeLocation::get().into(), 12u8), (UsdcLocation::get().into(), 12u8), (ERC20TSTLocation::get().into(), 18u8), (ERC20TSTD20Location::get().into(), 20u8)];
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -505,8 +508,8 @@ impl MatchesFungibles<AssetId, Balance> for SimpleForeignAssetConverter {
fn matches_fungibles(a: &MultiAsset) -> result::Result<(AssetId, Balance), ExecutionError> {
match (&a.fun, &a.id) {
(Fungible(ref amount), Concrete(ref id)) => {
if id == &UsdtLocation::get() {
Ok((UsdtAssetId::get(), *amount))
if id == &UsdcLocation::get() {
Ok((UsdcAssetId::get(), *amount))
} else if id == &ERC20TSTLocation::get() {
Ok((ERC20TSTAssetId::get(), *amount))
} else if id == &ERC20TSTD20Location::get() {
Expand Down

0 comments on commit 53b8dce

Please sign in to comment.