-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from Define101/master
add USDM adapter
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const sdk = require("@defillama/sdk"); | ||
import { sumSingleBalance } from "../helper/generalUtil"; | ||
import { | ||
ChainBlocks, | ||
PeggedIssuanceAdapter, | ||
Balances, | ||
} from "../peggedAsset.type"; | ||
|
||
type ChainContracts = { | ||
[chain: string]: { | ||
issued: string; | ||
unreleased: string[]; | ||
}; | ||
}; | ||
|
||
const chainContracts: ChainContracts = { | ||
ethereum: { | ||
issued: "0x59d9356e565ab3a36dd77763fc0d87feaf85508c", | ||
unreleased: [], | ||
}, | ||
}; | ||
|
||
async function chainMinted(chain: string, decimals: number) { | ||
return async function ( | ||
_timestamp: number, | ||
_ethBlock: number, | ||
_chainBlocks: ChainBlocks | ||
) { | ||
let balances = {} as Balances; | ||
const totalSupply = ( | ||
await sdk.api.abi.call({ | ||
abi: "erc20:totalSupply", | ||
target: chainContracts[chain].issued, | ||
block: _chainBlocks?.[chain], | ||
chain: chain, | ||
}) | ||
).output; | ||
sumSingleBalance( | ||
balances, | ||
"peggedUSD", | ||
totalSupply / 10 ** decimals, | ||
"issued", | ||
false | ||
); | ||
return balances; | ||
}; | ||
} | ||
|
||
async function chainUnreleased(chain: string, decimals: number) { | ||
return async function ( | ||
_timestamp: number, | ||
_ethBlock: number, | ||
_chainBlocks: ChainBlocks | ||
) { | ||
let balances = {} as Balances; | ||
for (let unreleased of chainContracts[chain].unreleased) { | ||
const unreleasedBalance = ( | ||
await sdk.api.abi.call({ | ||
abi: "erc20:balanceOf", | ||
target: chainContracts[chain].issued, | ||
params: [unreleased], | ||
block: _chainBlocks?.[chain], | ||
chain: chain, | ||
}) | ||
).output; | ||
sumSingleBalance( | ||
balances, | ||
"peggedUSD", | ||
unreleasedBalance / 10 ** decimals, | ||
"unreleased", | ||
false | ||
); | ||
} | ||
return balances; | ||
}; | ||
} | ||
|
||
const adapter: PeggedIssuanceAdapter = { | ||
ethereum: { | ||
minted: chainMinted("ethereum", 18), | ||
unreleased: async () => ({}), | ||
}, | ||
}; | ||
|
||
export default adapter; |