Some checks failed
deploy / deploy (push) Failing after 37s
Proof: npm test (138 passing); npm run operator-dashboard:build; git diff --cached --check. Assumptions: Bridge deposits expose near_token_id/intents_token_id for credited asset attribution; nBTC is the solver trading reserve while btc.omft.near remains a tracked legacy BTC wrapper. Still fake: No live asset migration was submitted; existing btc.omft.near balance is only tracked and withdrawable until a separately approved conversion or withdrawal is executed.
117 lines
4 KiB
JavaScript
117 lines
4 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { buildBridgeWithdrawalPlan } from '../src/core/liquidity-withdrawals.mjs';
|
|
|
|
const config = {
|
|
assetRegistry: new Map([
|
|
['nep141:nbtc.bridge.near', {
|
|
assetId: 'nep141:nbtc.bridge.near',
|
|
chain: 'btc:mainnet',
|
|
withdrawAddress: '',
|
|
}],
|
|
['nep141:btc.omft.near', {
|
|
assetId: 'nep141:btc.omft.near',
|
|
chain: 'btc:mainnet',
|
|
withdrawAddress: '',
|
|
}],
|
|
['nep141:gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near', {
|
|
assetId: 'nep141:gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
chain: 'eth:100',
|
|
withdrawAddress: '0x6C40267e03A97B2132e7a7d3159C88534eBEfdFb',
|
|
}],
|
|
]),
|
|
};
|
|
|
|
test('buildBridgeWithdrawalPlan creates an external-chain EURe withdrawal plan', () => {
|
|
const plan = buildBridgeWithdrawalPlan({
|
|
assetId: 'nep141:gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
amount: '5000000000000000000',
|
|
destinationAddress: '0x62bda91ac00CCa4e87cE3915Db56DF06773A1747',
|
|
supportedTokens: {
|
|
eure: {
|
|
near_token_id: 'gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
defuse_asset_identifier: 'eth:100:0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430',
|
|
min_withdrawal_amount: '1',
|
|
withdrawal_fee: '200000000000',
|
|
},
|
|
},
|
|
config,
|
|
});
|
|
|
|
assert.deepEqual(plan, {
|
|
asset_id: 'nep141:gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
amount: '5000000000000000000',
|
|
chain: 'eth:100',
|
|
destination_address: '0x62bda91ac00CCa4e87cE3915Db56DF06773A1747',
|
|
near_token_id: 'gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
defuse_asset_identifier: 'eth:100:0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430',
|
|
receiver_id: 'gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
memo: 'WITHDRAW_TO:0x62bda91ac00CCa4e87cE3915Db56DF06773A1747',
|
|
min_withdrawal_amount: '1',
|
|
withdrawal_fee: '200000000000',
|
|
});
|
|
});
|
|
|
|
test('buildBridgeWithdrawalPlan distinguishes nBTC and legacy BTC bridge tokens', () => {
|
|
const plan = buildBridgeWithdrawalPlan({
|
|
assetId: 'nep141:nbtc.bridge.near',
|
|
amount: '10000',
|
|
destinationAddress: 'bc1qexample',
|
|
supportedTokens: {
|
|
legacyBtc: {
|
|
near_token_id: 'btc.omft.near',
|
|
defuse_asset_identifier: 'btc:mainnet:native',
|
|
min_withdrawal_amount: '700',
|
|
withdrawal_fee: '1500',
|
|
},
|
|
nbtc: {
|
|
near_token_id: 'nbtc.bridge.near',
|
|
defuse_asset_identifier: 'btc:mainnet:native',
|
|
min_withdrawal_amount: '700',
|
|
withdrawal_fee: '1500',
|
|
},
|
|
},
|
|
config,
|
|
});
|
|
|
|
assert.equal(plan.asset_id, 'nep141:nbtc.bridge.near');
|
|
assert.equal(plan.near_token_id, 'nbtc.bridge.near');
|
|
assert.equal(plan.defuse_asset_identifier, 'btc:mainnet:native');
|
|
});
|
|
|
|
test('buildBridgeWithdrawalPlan rejects amounts below the bridge minimum', () => {
|
|
assert.throws(() => buildBridgeWithdrawalPlan({
|
|
assetId: 'nep141:btc.omft.near',
|
|
amount: '9999',
|
|
destinationAddress: 'bc1qexample',
|
|
supportedTokens: {
|
|
btc: {
|
|
near_token_id: 'btc.omft.near',
|
|
defuse_asset_identifier: 'btc:mainnet:native',
|
|
min_withdrawal_amount: '10000',
|
|
withdrawal_fee: '1500',
|
|
},
|
|
},
|
|
config,
|
|
}), /amount below minimum withdrawal: 10000/);
|
|
});
|
|
|
|
test('buildBridgeWithdrawalPlan falls back to configured asset withdrawal address', () => {
|
|
const plan = buildBridgeWithdrawalPlan({
|
|
assetId: 'nep141:gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
amount: '1000000000000000000',
|
|
destinationAddress: '',
|
|
supportedTokens: {
|
|
eure: {
|
|
near_token_id: 'gnosis-0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430.omft.near',
|
|
defuse_asset_identifier: 'eth:100:0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430',
|
|
min_withdrawal_amount: '1',
|
|
withdrawal_fee: '200000000000',
|
|
},
|
|
},
|
|
config,
|
|
});
|
|
|
|
assert.equal(plan.destination_address, '0x6C40267e03A97B2132e7a7d3159C88534eBEfdFb');
|
|
});
|