Skip to content

Commit

Permalink
Add getMaxSpendable
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Jan 14, 2025
1 parent 0346b2f commit 602c3df
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- added: Add SUI
- fixed: Ignore incorrect fees sent by the Midgard server, and instead just use 0.02 RUNE for Thorchain native transactions.

## 4.32.4 (2024-12-25)
Expand Down
27 changes: 27 additions & 0 deletions src/sui/SuiEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,33 @@ export class SuiEngine extends CurrencyEngine<SuiTools, SafeCommonWalletInfo> {
await this.startEngine()
}

async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise<string> {
const { tokenId } = spendInfo
const balance = this.getBalance({
tokenId
})
const publicAddress = spendInfo.spendTargets[0]?.publicAddress
if (publicAddress == null) {
throw new Error('Missing publicAddress')
}

let maxAmount = '0'
if (tokenId == null) {
// We can actually send the whole balance but it requires a small change
// to the transaction creation which cannot be nicely special-cased. We
// can actually empty the wallet with upcoming makeMaxSpend API. For now
// we leave 0.1 SUI behind.
maxAmount = sub(balance, '100000000')
} else {
maxAmount = balance
}

spendInfo.spendTargets[0].nativeAmount = maxAmount
// Use makeSpend to test for insufficient funds
await this.makeSpend(spendInfo)
return maxAmount
}

async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise<EdgeTransaction> {
const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn)
const { memos = [], tokenId } = edgeSpendInfo
Expand Down

0 comments on commit 602c3df

Please sign in to comment.