near/p3: Fix P3
This commit is contained in:
parent
58cd430541
commit
d48b13ceee
|
@ -2,6 +2,15 @@ const algosdk = require("@certusone/wormhole-sdk/node_modules/algosdk");
|
||||||
|
|
||||||
import { calcLogicSigAccount } from "@certusone/wormhole-sdk/lib/cjs/algorand";
|
import { calcLogicSigAccount } from "@certusone/wormhole-sdk/lib/cjs/algorand";
|
||||||
|
|
||||||
|
import {
|
||||||
|
coalesceChainName,
|
||||||
|
ChainId,
|
||||||
|
coalesceChainId,
|
||||||
|
uint8ArrayToHex,
|
||||||
|
toChainName,
|
||||||
|
getOriginalAssetAlgorand,
|
||||||
|
} from "@certusone/wormhole-sdk";
|
||||||
|
|
||||||
export async function getNativeAlgoAddress(
|
export async function getNativeAlgoAddress(
|
||||||
algoClient: any,
|
algoClient: any,
|
||||||
token_bridge: any,
|
token_bridge: any,
|
||||||
|
@ -25,7 +34,7 @@ async function firstTransaction() {
|
||||||
let token;
|
let token;
|
||||||
let appid;
|
let appid;
|
||||||
|
|
||||||
const mainnet = false;
|
const mainnet = true;
|
||||||
|
|
||||||
if (mainnet) {
|
if (mainnet) {
|
||||||
appid = 842126029;
|
appid = 842126029;
|
||||||
|
@ -93,12 +102,20 @@ async function firstTransaction() {
|
||||||
let algoInfo = await algodClient.accountInformation(nativeAlgoAddr).do();
|
let algoInfo = await algodClient.accountInformation(nativeAlgoAddr).do();
|
||||||
console.log("ALGO locked: " + (algoInfo["amount"] - 1002001));
|
console.log("ALGO locked: " + (algoInfo["amount"] - 1002001));
|
||||||
|
|
||||||
console.log("wormhole assets");
|
console.log("wormhole assets (bridged in)");
|
||||||
for (let i = 0; i < wormholeAssets.length; i++) {
|
for (let i = 0; i < wormholeAssets.length; i++) {
|
||||||
console.log(wormholeAssets[i]);
|
let orig = await getOriginalAssetAlgorand(
|
||||||
console.log(
|
algodClient,
|
||||||
await algodClient.getAssetByID(wormholeAssets[i]["asset-id"]).do()
|
BigInt(appid),
|
||||||
|
wormholeAssets[i]["asset-id"]
|
||||||
);
|
);
|
||||||
|
let v = [
|
||||||
|
coalesceChainName(orig["chainId"]),
|
||||||
|
uint8ArrayToHex(orig["assetAddress"]),
|
||||||
|
wormholeAssets[i],
|
||||||
|
await algodClient.getAssetByID(wormholeAssets[i]["asset-id"]).do(),
|
||||||
|
];
|
||||||
|
console.log(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("native assets");
|
console.log("native assets");
|
||||||
|
|
|
@ -75,17 +75,17 @@ clean:
|
||||||
.PHONY: reset-force
|
.PHONY: reset-force
|
||||||
reset-force: build
|
reset-force: build
|
||||||
-echo cleaning and restarting state
|
-echo cleaning and restarting state
|
||||||
-kubectl delete pod guardian-0 --force &
|
-minikube kubectl -- delete pod guardian-0 --force &
|
||||||
-kubectl delete pod algorand-0 --force &
|
-minikube kubectl -- delete pod algorand-0 --force &
|
||||||
-kubectl delete pod near-0 --force &
|
-minikube kubectl -- delete pod near-0 --force &
|
||||||
-echo done
|
-echo done
|
||||||
|
|
||||||
.PHONY: reset
|
.PHONY: reset
|
||||||
reset: build
|
reset: build
|
||||||
-echo cleaning and restarting state
|
-echo cleaning and restarting state
|
||||||
-kubectl delete pod guardian-0 &
|
-minikube kubectl -- delete pod guardian-0 &
|
||||||
-kubectl delete pod algorand-0 &
|
-minikube kubectl -- delete pod algorand-0 &
|
||||||
-kubectl delete pod near-0 &
|
-minikube kubectl -- delete pod near-0 &
|
||||||
-echo done
|
-echo done
|
||||||
|
|
||||||
.PHONY: cycle
|
.PHONY: cycle
|
||||||
|
|
|
@ -105,6 +105,76 @@ impl FTContract {
|
||||||
self.meta.replace(&meta);
|
self.meta.replace(&meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[payable]
|
||||||
|
pub fn wh_burn(&mut self, from: AccountId, amount: u128) {
|
||||||
|
assert_one_yocto();
|
||||||
|
|
||||||
|
if env::predecessor_account_id() != self.controller {
|
||||||
|
env::panic_str("CrossContractInvalidCaller");
|
||||||
|
}
|
||||||
|
|
||||||
|
self.token.internal_withdraw(&from, amount);
|
||||||
|
|
||||||
|
near_contract_standards::fungible_token::events::FtBurn {
|
||||||
|
owner_id: &from,
|
||||||
|
amount: &U128::from(amount),
|
||||||
|
memo: Some("Wormhole burn"),
|
||||||
|
}
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[payable]
|
||||||
|
pub fn wh_mint(
|
||||||
|
&mut self,
|
||||||
|
account_id: AccountId,
|
||||||
|
refund_to: AccountId,
|
||||||
|
amount: u128,
|
||||||
|
) -> Promise {
|
||||||
|
if env::predecessor_account_id() != self.controller {
|
||||||
|
env::panic_str("CrossContractInvalidCaller");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut deposit: Balance = env::attached_deposit();
|
||||||
|
|
||||||
|
if deposit == 0 {
|
||||||
|
env::panic_str("ZeroDepositNotAllowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.token.accounts.contains_key(&account_id) {
|
||||||
|
let min_balance = self.storage_balance_bounds().min.0;
|
||||||
|
if deposit < min_balance {
|
||||||
|
env::panic_str("The attached deposit is less than the minimum storage balance");
|
||||||
|
}
|
||||||
|
|
||||||
|
self.token.internal_register_account(&account_id);
|
||||||
|
|
||||||
|
deposit -= min_balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.token.internal_deposit(&account_id, amount);
|
||||||
|
|
||||||
|
near_contract_standards::fungible_token::events::FtMint {
|
||||||
|
owner_id: &account_id,
|
||||||
|
amount: &U128::from(amount),
|
||||||
|
memo: Some("wormhole minted tokens"),
|
||||||
|
}
|
||||||
|
.emit();
|
||||||
|
|
||||||
|
Promise::new(refund_to).transfer(deposit)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[payable]
|
||||||
|
pub fn wh_update(&mut self, v: Vec<u8>) -> Promise {
|
||||||
|
assert_one_yocto();
|
||||||
|
|
||||||
|
if env::predecessor_account_id() != self.controller {
|
||||||
|
env::panic_str("CrossContractInvalidCaller");
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise::new(env::current_account_id())
|
||||||
|
.deploy_contract(v.to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
#[payable]
|
#[payable]
|
||||||
pub fn vaa_withdraw(
|
pub fn vaa_withdraw(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -161,7 +231,9 @@ impl FTContract {
|
||||||
env::panic_str("Payload3 does not support fees");
|
env::panic_str("Payload3 does not support fees");
|
||||||
}
|
}
|
||||||
|
|
||||||
p = [p, hex::decode(&payload).unwrap()].concat();
|
let account_hash = env::sha256(from.as_bytes());
|
||||||
|
|
||||||
|
p = [p, account_hash, hex::decode(&payload).unwrap()].concat();
|
||||||
if p.len() != (133 + (payload.len() / 2)) {
|
if p.len() != (133 + (payload.len() / 2)) {
|
||||||
env::panic_str(&format!("payload3 formatting error len = {}", p.len()));
|
env::panic_str(&format!("payload3 formatting error len = {}", p.len()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,10 +404,15 @@ impl TokenBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
env::log_str(&format!(
|
env::log_str(&format!(
|
||||||
"token-bridge/{}#{}: vaa_transfer {} {} {} {} {}",
|
"token-bridge/{}#{}: vaa_transfer {} {} {} {} {}",
|
||||||
file!(),
|
file!(),
|
||||||
line!(),
|
line!(),
|
||||||
amount.1, fee.1, namount, nfee, near_mult));
|
amount.1,
|
||||||
|
fee.1,
|
||||||
|
namount,
|
||||||
|
nfee,
|
||||||
|
near_mult
|
||||||
|
));
|
||||||
|
|
||||||
env::log_str(&format!(
|
env::log_str(&format!(
|
||||||
"token-bridge/{}#{}: vaa_transfer calling ft_transfer against {} for {} from {} to {}",
|
"token-bridge/{}#{}: vaa_transfer calling ft_transfer against {} for {} from {} to {}",
|
||||||
|
@ -618,7 +623,6 @@ impl TokenBridge {
|
||||||
Promise::new(asset_token_account.clone())
|
Promise::new(asset_token_account.clone())
|
||||||
.create_account()
|
.create_account()
|
||||||
.transfer(cost)
|
.transfer(cost)
|
||||||
.add_full_access_key(self.owner_pk.clone())
|
|
||||||
.deploy_contract(BRIDGE_TOKEN_BINARY.to_vec())
|
.deploy_contract(BRIDGE_TOKEN_BINARY.to_vec())
|
||||||
.function_call(
|
.function_call(
|
||||||
"new".to_string(),
|
"new".to_string(),
|
||||||
|
@ -1021,7 +1025,18 @@ impl TokenBridge {
|
||||||
env::panic_str("Payload1 formatting error");
|
env::panic_str("Payload1 formatting error");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p = [p, hex::decode(&payload).unwrap()].concat();
|
let account_hash = env::sha256(env::predecessor_account_id().as_bytes());
|
||||||
|
if !self.hash_map.contains_key(&account_hash) {
|
||||||
|
env::log_str(&format!(
|
||||||
|
"token-bridge/{}#{}: default(): {}",
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
env::predecessor_account_id()
|
||||||
|
));
|
||||||
|
env::panic_str("UnregisteredSender1");
|
||||||
|
}
|
||||||
|
|
||||||
|
p = [p, account_hash, hex::decode(&payload).unwrap()].concat();
|
||||||
if p.len() != (133 + (payload.len() / 2)) {
|
if p.len() != (133 + (payload.len() / 2)) {
|
||||||
env::panic_str("Payload3 formatting error");
|
env::panic_str("Payload3 formatting error");
|
||||||
}
|
}
|
||||||
|
@ -1066,6 +1081,17 @@ impl TokenBridge {
|
||||||
);
|
);
|
||||||
|
|
||||||
if self.is_wormhole(&token) {
|
if self.is_wormhole(&token) {
|
||||||
|
let account_hash = env::sha256(env::predecessor_account_id().as_bytes());
|
||||||
|
if !self.hash_map.contains_key(&account_hash) {
|
||||||
|
env::log_str(&format!(
|
||||||
|
"token-bridge/{}#{}: default(): {}",
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
env::predecessor_account_id()
|
||||||
|
));
|
||||||
|
env::panic_str("UnregisteredSender2");
|
||||||
|
}
|
||||||
|
|
||||||
ext_ft_contract::ext(AccountId::try_from(token).unwrap())
|
ext_ft_contract::ext(AccountId::try_from(token).unwrap())
|
||||||
.with_attached_deposit(1)
|
.with_attached_deposit(1)
|
||||||
.with_static_gas(Gas(30_000_000_000_000))
|
.with_static_gas(Gas(30_000_000_000_000))
|
||||||
|
@ -1546,7 +1572,18 @@ impl TokenBridge {
|
||||||
env::panic_str(&format!("payload1 formatting error len = {}", p.len()));
|
env::panic_str(&format!("payload1 formatting error len = {}", p.len()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p = [p, hex::decode(&tp.payload).unwrap()].concat();
|
let account_hash = env::sha256(sender_id.as_bytes());
|
||||||
|
if !self.hash_map.contains_key(&account_hash) {
|
||||||
|
env::log_str(&format!(
|
||||||
|
"token-bridge/{}#{}: default(): {}",
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
sender_id
|
||||||
|
));
|
||||||
|
env::panic_str("UnregisteredSender3");
|
||||||
|
}
|
||||||
|
|
||||||
|
p = [p, account_hash, hex::decode(&tp.payload).unwrap()].concat();
|
||||||
if p.len() != (133 + (tp.payload.len() / 2)) {
|
if p.len() != (133 + (tp.payload.len() / 2)) {
|
||||||
env::panic_str(&format!("payload3 formatting error len = {}", p.len()));
|
env::panic_str(&format!("payload3 formatting error len = {}", p.len()));
|
||||||
}
|
}
|
||||||
|
@ -1692,23 +1729,23 @@ impl TokenBridge {
|
||||||
let state: TokenBridge = env::state_read().expect("failed");
|
let state: TokenBridge = env::state_read().expect("failed");
|
||||||
state
|
state
|
||||||
|
|
||||||
// let old_state: OldPortal = env::state_read().expect("failed");
|
// let old_state: OldPortal = env::state_read().expect("failed");
|
||||||
// Self {
|
// Self {
|
||||||
// booted: old_state.booted,
|
// booted: old_state.booted,
|
||||||
// core: old_state.core,
|
// core: old_state.core,
|
||||||
// gov_idx: old_state.gov_idx,
|
// gov_idx: old_state.gov_idx,
|
||||||
// dups: old_state.dups,
|
// dups: old_state.dups,
|
||||||
// owner_pk: old_state.owner_pk,
|
// owner_pk: old_state.owner_pk,
|
||||||
// emitter_registration: old_state.emitter_registration,
|
// emitter_registration: old_state.emitter_registration,
|
||||||
// last_asset: old_state.last_asset,
|
// last_asset: old_state.last_asset,
|
||||||
// upgrade_hash: old_state.upgrade_hash,
|
// upgrade_hash: old_state.upgrade_hash,
|
||||||
//
|
//
|
||||||
// tokens: old_state.tokens,
|
// tokens: old_state.tokens,
|
||||||
// key_map: old_state.key_map,
|
// key_map: old_state.key_map,
|
||||||
// hash_map: old_state.hash_map,
|
// hash_map: old_state.hash_map,
|
||||||
//
|
//
|
||||||
// bank: old_state.bank,
|
// bank: old_state.bank,
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,13 +327,13 @@ async function testNearSDK() {
|
||||||
|
|
||||||
console.log("for norium, createWrappedOnNear returned");
|
console.log("for norium, createWrappedOnNear returned");
|
||||||
|
|
||||||
let account_hash = await userAccount.viewFunction(
|
let account_hash = await userAccount.viewFunction({
|
||||||
token_bridge,
|
contractId: token_bridge,
|
||||||
"hash_account",
|
methodName: "hash_account",
|
||||||
{
|
args: {
|
||||||
account: userAccount.accountId,
|
account: userAccount.accountId,
|
||||||
}
|
},
|
||||||
);
|
});
|
||||||
|
|
||||||
console.log(account_hash);
|
console.log(account_hash);
|
||||||
|
|
||||||
|
@ -705,14 +705,22 @@ async function testNearSDK() {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: userAccount.accountId,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: userAccount.accountId,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: token_bridge,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: token_bridge,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -757,14 +765,22 @@ async function testNearSDK() {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: userAccount.accountId,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: userAccount.accountId,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: token_bridge,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: token_bridge,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -986,14 +1002,22 @@ async function testNearSDK() {
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: userAccount.accountId,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: userAccount.accountId,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: token_bridge,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: token_bridge,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1008,14 +1032,22 @@ async function testNearSDK() {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: userAccount.accountId,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: userAccount.accountId,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: token_bridge,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: token_bridge,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1134,14 +1166,22 @@ async function testNearSDK() {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: userAccount.accountId,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: userAccount.accountId,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
await userAccount.viewFunction(randoToken, "ft_balance_of", {
|
await userAccount.viewFunction({
|
||||||
account_id: token_bridge,
|
contractId: randoToken,
|
||||||
|
methodName: "ft_balance_of",
|
||||||
|
args: {
|
||||||
|
account_id: token_bridge,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue